Skip to content

Commit

Permalink
Merge pull request #647 from superform-xyz/tamara-sup-9062-add-loop-v…
Browse files Browse the repository at this point in the history
…ersion-of-deposit4626

feat: add loop version of deposit4626() [sup-9062]
  • Loading branch information
TamaraRingas authored Oct 28, 2024
2 parents 3d85405 + 671d0d4 commit 6a010e7
Show file tree
Hide file tree
Showing 3 changed files with 205 additions and 24 deletions.
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
52 changes: 36 additions & 16 deletions src/router-plus/SuperformRouterPlus.sol
Original file line number Diff line number Diff line change
Expand Up @@ -356,26 +356,24 @@ 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);
function deposit4626(address[] calldata vaults_, Deposit4626Args[] calldata args) external payable {

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 length = vaults_.length;

if (length != args.length) {
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 (length == 0) {
revert Error.ZERO_INPUT_VALUE();
}

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

/// @inheritdoc ISuperformRouterPlus
Expand Down Expand Up @@ -603,4 +601,26 @@ 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);

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

0 comments on commit 6a010e7

Please sign in to comment.