diff --git a/src/Aggregator.sol b/src/Aggregator.sol index d766eef..6148d95 100644 --- a/src/Aggregator.sol +++ b/src/Aggregator.sol @@ -6,7 +6,7 @@ import {LibSort} from "solady/utils/LibSort.sol"; import {SafeTransferLib} from "solady/utils/SafeTransferLib.sol"; import {FixedPointMathLib} from "solady/utils/FixedPointMathLib.sol"; -import {Pool} from "../src/Pool.sol"; +import {PoolV2} from "../src/Poolv2.sol"; import {PoolToken} from "../src/PoolToken.sol"; import {Vault} from "../src/Vault.sol"; import {MockToken} from "../src/Mocks/MockToken.sol"; @@ -36,6 +36,25 @@ contract Aggregator { shares = Vault(vaultAddress).deposit(lpReceived, receiver); } + function depositFromRouter( + address[] calldata tokens, + uint256[] calldata tokenAmounts, + address receiver, + uint256 minLpAmount, + address poolAddress + ) external returns (uint256 shares) { + require(tokens.length == tokenAmounts.length, "tokens and tokenAmounts should be of same length"); + + for (uint256 i = 0; i < tokenAmounts.length; i++) { + ERC20(tokens[i]).approve(poolAddress, tokenAmounts[i]); + } + + address vaultAddress = Pool(poolAddress).vaultAddress(); + uint256 lpReceived = Pool(poolAddress).addLiquidity(tokenAmounts, minLpAmount, address(this)); + PoolToken(Pool(poolAddress).tokenAddress()).approve(vaultAddress, lpReceived); + shares = Vault(vaultAddress).deposit(lpReceived, receiver); + } + function depositSingle( uint256 tokenIndex, uint256 tokenAmount, @@ -56,6 +75,25 @@ contract Aggregator { shares = Vault(vaultAddress).deposit(lpReceived, receiver); } + function depositSingleFromRouter( + uint256 tokenIndex, + uint256 tokenAmount, + address receiver, + uint256 minLpAmount, + address poolAddress + ) external returns (uint256 shares) { + address token = Pool(poolAddress).tokens(tokenIndex); + ERC20(token).approve(poolAddress, tokenAmount); + + uint256 numTokens = Pool(poolAddress).numTokens(); + uint256[] memory addLiquidityAmounts = new uint256[](numTokens); + addLiquidityAmounts[tokenIndex] = tokenAmount; + address vaultAddress = Pool(poolAddress).vaultAddress(); + uint256 lpReceived = Pool(poolAddress).addLiquidity(addLiquidityAmounts, minLpAmount, address(this)); + PoolToken(Pool(poolAddress).tokenAddress()).approve(vaultAddress, lpReceived); + shares = Vault(vaultAddress).deposit(lpReceived, receiver); + } + function depositFor( address[] calldata tokens, uint256[] calldata tokenAmounts, diff --git a/src/Poolv2.sol b/src/Poolv2.sol index 37a47ce..b13eb38 100644 --- a/src/Poolv2.sol +++ b/src/Poolv2.sol @@ -472,6 +472,7 @@ contract Pool is OwnableRoles, ReentrancyGuard { /// @notice deposit tokens into the pool /// @param amounts_ array of the amount for each token to take from caller /// @param minLpAmount_ minimum amount of lp tokens to mint + /// @param owner_ address from which to add liquidity from /// @param receiver_ account to receive the lp tokens /// @return amount of LP tokens minted function addLiquidityFor(uint256[] calldata amounts_, uint256 minLpAmount_, address owner_, address receiver_)