Skip to content

Commit

Permalink
fix: update approvals in test_deposit4626_multipleVaults()
Browse files Browse the repository at this point in the history
  • Loading branch information
TamaraRingas committed Oct 25, 2024
1 parent 68b2747 commit af6ed66
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions test/unit/router-plus/SuperformRouterPlus.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -514,57 +514,57 @@ contract SuperformRouterPlusTest is ProtocolActions {

// Deploy two mock ERC4626 vaults
VaultMock mockVault1 = new VaultMock(IERC20(getContract(SOURCE_CHAIN, "DAI")), "Mock Vault 1", "mVLT1");
VaultMock mockVault2 = new VaultMock(IERC20(getContract(SOURCE_CHAIN, "USDC")), "Mock Vault 2", "mVLT2");
VaultMock mockVault2 = new VaultMock(IERC20(getContract(SOURCE_CHAIN, "DAI")), "Mock Vault 2", "mVLT2");

address[] memory vaults = new address[](2);
vaults[0] = address(mockVault1);
vaults[1] = address(mockVault2);

// Mint some DAI to the deployer
uint256 daiAmount = 1e18;
deal(getContract(SOURCE_CHAIN, "DAI"), deployer, 10e18);

// Mint some USDC to the deployer
uint256 usdcAmount = 1e18;

// Approve and deposit DAI into the mock vault
// Approve and deposit DAI into the first mock vault
MockERC20(getContract(SOURCE_CHAIN, "DAI")).approve(address(mockVault1), daiAmount);
uint256 vaultTokenAmount1 = mockVault1.deposit(daiAmount, deployer);

// Approve and deposit USDC into the mock vault
MockERC20(getContract(SOURCE_CHAIN, "USDC")).approve(address(mockVault2), usdcAmount);
uint256 vaultTokenAmount2 = mockVault2.deposit(usdcAmount, deployer);
uint256 vaultTokenAmount1 = mockVault1.deposit(daiAmount/2, deployer);

// Approve and deposit DAI into the secondmock vault
MockERC20(getContract(SOURCE_CHAIN, "DAI")).approve(address(mockVault2), daiAmount);
uint256 vaultTokenAmount2 = mockVault2.deposit(daiAmount/2, deployer);

// Prepare deposit4626 args for both deposits
ISuperformRouterPlus.Deposit4626Args[] memory argsArray = new ISuperformRouterPlus.Deposit4626Args[](2);

argsArray[0] = ISuperformRouterPlus.Deposit4626Args({
amount: vaultTokenAmount1,
expectedOutputAmount: daiAmount,
expectedOutputAmount: daiAmount/2,
maxSlippage: 100, // 1%
receiverAddressSP: deployer,
depositCallData: _buildDepositCallData(superformId1, daiAmount)
depositCallData: _buildDepositCallData(superformId1, daiAmount/2)
});

argsArray[1] = ISuperformRouterPlus.Deposit4626Args({
amount: vaultTokenAmount2,
expectedOutputAmount: usdcAmount,
expectedOutputAmount: daiAmount/2,
maxSlippage: 100, // 1%
receiverAddressSP: deployer,
depositCallData: _buildDepositCallData(superformId2, usdcAmount)
depositCallData: _buildDepositCallData(superformId1, daiAmount/2)
});

// Approve RouterPlus to spend vault tokens
mockVault1.approve(ROUTER_PLUS_SOURCE, vaultTokenAmount1);
mockVault2.approve(ROUTER_PLUS_SOURCE, vaultTokenAmount2);
mockVault1.approve(ROUTER_PLUS_SOURCE, daiAmount);
mockVault2.approve(ROUTER_PLUS_SOURCE, daiAmount);

// Execute deposit4626
SuperformRouterPlus(ROUTER_PLUS_SOURCE).deposit4626{ value: 1 ether }(vaults, argsArray);
vm.recordLogs();
SuperformRouterPlus(ROUTER_PLUS_SOURCE).deposit4626{ value: 2 ether }(vaults, argsArray);

vm.stopPrank();

// Verify the results
assertGt(
SuperPositions(SUPER_POSITIONS_SOURCE).balanceOf(deployer, superformId2),
SuperPositions(SUPER_POSITIONS_SOURCE).balanceOf(deployer, superformId1),
0,
"Superform balance should be greater than 0"
);
Expand All @@ -582,11 +582,6 @@ contract SuperformRouterPlusTest is ProtocolActions {
0,
"RouterPlus should not hold any DAI"
);
assertEq(
MockERC20(getContract(SOURCE_CHAIN, "USDC")).balanceOf(ROUTER_PLUS_SOURCE),
0,
"RouterPlus should not hold any USDC"
);
}

function test_rebalanceSinglePosition_zeroAddressInterimAsset() public {
Expand Down

0 comments on commit af6ed66

Please sign in to comment.