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

fix: remedy rounding issue in _deposit4626() by adding remainder to _deposit() call #657

Merged
merged 4 commits into from
Nov 25, 2024
Merged
Changes from all 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
10 changes: 8 additions & 2 deletions src/router-plus/SuperformRouterPlus.sol
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,7 @@ 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
/// @param arrayLength The length of the array of deposit4626 calls
function _deposit4626(address vault_, Deposit4626Args calldata args, uint256 arrayLength) internal {
_transferERC20In(IERC20(vault_), args.receiverAddressSP, args.amount);
IERC4626 vault = IERC4626(vault_);
Expand All @@ -639,10 +640,15 @@ contract SuperformRouterPlus is ISuperformRouterPlus, BaseSuperformRouterPlus {

uint256 amountIn = _validateAndGetAmountIn(args.depositCallData, amountRedeemed);

uint256 msgValue = msg.value / arrayLength;
address router = _getAddress(keccak256("SUPERFORM_ROUTER"));
uint256 valueToDeposit;
{
uint256 valuePerItem = (msg.value - (msg.value % arrayLength)) / arrayLength;
uint256 remainingValue = msg.value % arrayLength;
valueToDeposit = valuePerItem + remainingValue;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the remainingValue should only be used once - for one of the vaults (or discounted in another way, or neglected)

this calculation: uint256 valuePerItem = msg.value / arrayLength can stay as it was because it rounds down anyway

Perhaps do the calculation of the valueToDeposit in the calling function deposit4626() and add the remainingValue only for the last (or first) item in the loop.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

_deposit(router, asset, amountIn, msgValue, args.depositCallData);
_deposit(router, asset, amountIn, valueToDeposit, args.depositCallData);

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

Expand Down
Loading