Skip to content

Commit ae9af3a

Browse files
authored
fix: msgValue Calculation (#661)
1 parent 7855e98 commit ae9af3a

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/router-plus/SuperformRouterPlus.sol

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -373,11 +373,16 @@ contract SuperformRouterPlus is ISuperformRouterPlus, BaseSuperformRouterPlus {
373373
revert Error.ZERO_INPUT_VALUE();
374374
}
375375

376+
uint256 valueToPass = msg.value / length;
377+
376378
for (uint256 i; i < length; ++i) {
377379
if (!whitelistedSelectors[Actions.DEPOSIT][_parseSelectorMem(args[i].depositCallData)]) {
378380
revert INVALID_DEPOSIT_SELECTOR();
379381
}
380-
_deposit4626(vaults_[i], args[i], length);
382+
if (i == length - 1) {
383+
valueToPass += msg.value % length;
384+
}
385+
_deposit4626(vaults_[i], args[i], length, valueToPass);
381386
}
382387
}
383388

@@ -628,7 +633,15 @@ contract SuperformRouterPlus is ISuperformRouterPlus, BaseSuperformRouterPlus {
628633
/// @param vault_ The ERC4626 vault to redeem from
629634
/// @param args Rest of the arguments to deposit 4626
630635
/// @param arrayLength The length of the array of deposit4626 calls
631-
function _deposit4626(address vault_, Deposit4626Args calldata args, uint256 arrayLength) internal {
636+
/// @param valueToPass The value to pass to the deposit function
637+
function _deposit4626(
638+
address vault_,
639+
Deposit4626Args calldata args,
640+
uint256 arrayLength,
641+
uint256 valueToPass
642+
)
643+
internal
644+
{
632645
_transferERC20In(IERC20(vault_), args.receiverAddressSP, args.amount);
633646
IERC4626 vault = IERC4626(vault_);
634647
address assetAdr = vault.asset();
@@ -641,14 +654,8 @@ contract SuperformRouterPlus is ISuperformRouterPlus, BaseSuperformRouterPlus {
641654
uint256 amountIn = _validateAndGetAmountIn(args.depositCallData, amountRedeemed);
642655

643656
address router = _getAddress(keccak256("SUPERFORM_ROUTER"));
644-
uint256 valueToDeposit;
645-
{
646-
uint256 valuePerItem = (msg.value - (msg.value % arrayLength)) / arrayLength;
647-
uint256 remainingValue = msg.value % arrayLength;
648-
valueToDeposit = valuePerItem + remainingValue;
649-
}
650657

651-
_deposit(router, asset, amountIn, valueToDeposit, args.depositCallData);
658+
_deposit(router, asset, amountIn, valueToPass, args.depositCallData);
652659

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

0 commit comments

Comments
 (0)