Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add loop version of deposit4626() [sup-9062] #647

Merged
merged 14 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/interfaces/ISuperformRouterPlus.sol
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@ interface ISuperformRouterPlus is IBaseSuperformRouterPlus {
function startCrossChainRebalanceMulti(InitiateXChainRebalanceMultiArgs memory args) external payable;

/// @notice deposits ERC4626 vault shares into superform
/// @param vault_ The ERC4626 vault to redeem from
/// @param vaults_ The ERC4626 vaults to redeem from
/// @param args Rest of the arguments to deposit 4626
function deposit4626(address vault_, Deposit4626Args calldata args) external payable;
function deposit4626(address[] calldata vaults_, Deposit4626Args[] calldata args) external payable;

/// @dev Forwards dust to Paymaster
/// @param token_ the token to forward
Expand Down
56 changes: 39 additions & 17 deletions src/router-plus/SuperformRouterPlus.sol
Original file line number Diff line number Diff line change
Expand Up @@ -356,26 +356,22 @@ contract SuperformRouterPlus is ISuperformRouterPlus, BaseSuperformRouterPlus {
}

/// @inheritdoc ISuperformRouterPlus
function deposit4626(address vault_, Deposit4626Args calldata args) external payable override {
_transferERC20In(IERC20(vault_), args.receiverAddressSP, args.amount);
IERC4626 vault = IERC4626(vault_);
address assetAdr = vault.asset();
IERC20 asset = IERC20(assetAdr);

uint256 balanceBefore = asset.balanceOf(address(this));

uint256 amountRedeemed = _redeemShare(vault, assetAdr, args.amount, args.expectedOutputAmount, args.maxSlippage);

if (!whitelistedSelectors[Actions.DEPOSIT][_parseSelectorMem(args.depositCallData)]) {
revert INVALID_DEPOSIT_SELECTOR();
function deposit4626(address[] calldata vaults_, Deposit4626Args[] calldata args) external payable {

if (vaults_.length != args.length) {
TamaraRingas marked this conversation as resolved.
Show resolved Hide resolved
revert Error.ARRAY_LENGTH_MISMATCH();
}

address router = _getAddress(keccak256("SUPERFORM_ROUTER"));
_deposit(router, asset, amountRedeemed, msg.value, args.depositCallData);

_tokenRefunds(router, assetAdr, args.receiverAddressSP, balanceBefore);
if (vaults_.length == 0) {
revert Error.ARRAY_LENGTH_MISMATCH();
}

emit Deposit4626Completed(args.receiverAddressSP, vault_);
for (uint256 i; i < vaults_.length; ++i) {
if (!whitelistedSelectors[Actions.DEPOSIT][_parseSelectorMem(args[i].depositCallData)]) {
revert INVALID_DEPOSIT_SELECTOR();
}
_deposit4626(vaults_[i], args[i], vaults_.length);
}
}

/// @inheritdoc ISuperformRouterPlus
Expand Down Expand Up @@ -603,4 +599,30 @@ contract SuperformRouterPlus is ISuperformRouterPlus, BaseSuperformRouterPlus {
}
}
}

/// @notice deposits ERC4626 vault shares into superform
/// @param vault_ The ERC4626 vault to redeem from
/// @param args Rest of the arguments to deposit 4626
function _deposit4626(address vault_, Deposit4626Args calldata args, uint256 arrayLength) internal {
_transferERC20In(IERC20(vault_), args.receiverAddressSP, args.amount);
IERC4626 vault = IERC4626(vault_);
address assetAdr = vault.asset();
IERC20 asset = IERC20(assetAdr);

uint256 balanceBefore = asset.balanceOf(address(this));

uint256 amountRedeemed = _redeemShare(vault, assetAdr, args.amount, args.expectedOutputAmount, args.maxSlippage);

if (!whitelistedSelectors[Actions.DEPOSIT][_parseSelectorMem(args.depositCallData)]) {
revert INVALID_DEPOSIT_SELECTOR();
}

uint256 msgValue = msg.value / arrayLength;
address router = _getAddress(keccak256("SUPERFORM_ROUTER"));
_deposit(router, asset, amountRedeemed, msgValue, args.depositCallData);

_tokenRefunds(router, assetAdr, args.receiverAddressSP, balanceBefore);

emit Deposit4626Completed(args.receiverAddressSP, vault_);
}
}
Loading
Loading