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/deposit-max-balance-savings #26

Merged
merged 11 commits into from
Aug 9, 2024
1 change: 1 addition & 0 deletions contracts/BaseRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ abstract contract BaseRouter is Initializable, IDepositWithReferral {
address to,
uint256 minSharesOut
) internal returns (uint256 sharesOut) {
if (amount == type(uint256).max) amount = IERC20(savingsRate.asset()).balanceOf(address(this));
0xtekgrinder marked this conversation as resolved.
Show resolved Hide resolved
0xtekgrinder marked this conversation as resolved.
Show resolved Hide resolved
0xtekgrinder marked this conversation as resolved.
Show resolved Hide resolved
_slippageCheck(sharesOut = savingsRate.deposit(amount, to), minSharesOut);
}

Expand Down
53 changes: 52 additions & 1 deletion test/foundry/AngeRouterMainnet.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,12 @@ contract AngleRouterMainnetTest is BaseTest {
assertEq(token.balanceOf(address(to)), 0);
}

function testMint4626ForgotFunds(uint256 initShares, uint256 shares, uint256 maxAmount, uint256 gainOrLoss) public {
function testMint4626ForgotFunds(
uint256 initShares,
uint256 shares,
uint256 maxAmount,
uint256 gainOrLoss
) public {
address to = address(router);
uint256 balanceUsers = BASE_TOKENS * 1 ether;
deal(address(token), address(_alice), balanceUsers);
Expand Down Expand Up @@ -189,6 +194,52 @@ contract AngleRouterMainnetTest is BaseTest {
assertEq(token.balanceOf(address(to)), 0);
}

0xtekgrinder marked this conversation as resolved.
Show resolved Hide resolved
function testDeposit4626MaxBalance(
uint256 initShares,
uint256 amount,
uint256 minSharesOut,
uint256 gainOrLoss
) public {
address to = address(router);

uint256 balanceUsers = BASE_TOKENS * 1 ether;
deal(address(token), address(_alice), balanceUsers);

_randomizeSavingsRate(gainOrLoss, initShares);

amount = bound(amount, 0, balanceUsers);
uint256 previewDeposit = savingsRate.previewDeposit(amount);

PermitType[] memory paramsPermit = new PermitType[](0);
ActionType[] memory actionType = new ActionType[](2);
bytes[] memory data = new bytes[](2);

actionType[0] = ActionType.transfer;
data[0] = abi.encode(token, router, amount);
actionType[1] = ActionType.deposit4626;
data[1] = abi.encode(token, savingsRate, type(uint256).max, to, minSharesOut);

uint256 mintedShares = savingsRate.convertToShares(amount);

vm.startPrank(_alice);
token.approve(address(router), type(uint256).max);
// as this is a mock vault, previewMint is exactly what is needed to mint
if (previewDeposit < minSharesOut) {
vm.expectRevert(BaseRouter.TooSmallAmountOut.selector);
router.mixer(paramsPermit, actionType, data);
return;
} else {
router.mixer(paramsPermit, actionType, data);
}
vm.stopPrank();

assertEq(savingsRate.balanceOf(address(to)), previewDeposit);
assertEq(savingsRate.balanceOf(address(to)), mintedShares);

assertEq(token.balanceOf(address(router)), 0);
assertEq(token.balanceOf(address(_alice)), balanceUsers - amount);
}

function testDeposit4626ForgotFunds(
uint256 initShares,
uint256 amount,
Expand Down
Loading