Skip to content

Commit

Permalink
feat: add function for deposit calls from multicall
Browse files Browse the repository at this point in the history
  • Loading branch information
0xethsign committed Jan 21, 2025
1 parent cb9c4de commit 6456d3d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
40 changes: 39 additions & 1 deletion src/Aggregator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/Poolv2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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_)
Expand Down

0 comments on commit 6456d3d

Please sign in to comment.