Skip to content

Commit

Permalink
chore: add test_deposit4626_multipleVaults()
Browse files Browse the repository at this point in the history
  • Loading branch information
TamaraRingas committed Oct 25, 2024
1 parent 8d17fde commit 68b2747
Showing 1 changed file with 141 additions and 14 deletions.
155 changes: 141 additions & 14 deletions test/unit/router-plus/SuperformRouterPlus.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,8 @@ contract SuperformRouterPlusTest is ProtocolActions {

// Deploy a mock ERC4626 vault
VaultMock mockVault = new VaultMock(IERC20(getContract(SOURCE_CHAIN, "DAI")), "Mock Vault", "mVLT");
address[] calldata vaults = new address[](1);

address[] memory vaults = new address[](1);
vaults[0] = address(mockVault);

// Mint some DAI to the deployer
Expand All @@ -447,7 +448,8 @@ contract SuperformRouterPlusTest is ProtocolActions {
uint256 vaultTokenAmount = mockVault.deposit(daiAmount, deployer);

// Prepare deposit4626 args with an invalid deposit selector
Deposit4626Args[] calldata argsArray = new Deposit4626Args[](1);
ISuperformRouterPlus.Deposit4626Args[] memory argsArray = new ISuperformRouterPlus.Deposit4626Args[](1);

ISuperformRouterPlus.Deposit4626Args memory args = ISuperformRouterPlus.Deposit4626Args({
amount: vaultTokenAmount,
expectedOutputAmount: daiAmount,
Expand All @@ -467,10 +469,124 @@ contract SuperformRouterPlusTest is ProtocolActions {
vm.stopPrank();
}


function test_deposit4626_multipleVaults_arrayMismatch() public {
vm.startPrank(deployer);

// 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");

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

// Mint some DAI to the deployer
uint256 daiAmount = 1e18;

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

// Prepare deposit4626 args
ISuperformRouterPlus.Deposit4626Args[] memory argsArray = new ISuperformRouterPlus.Deposit4626Args[](1);

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

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

// Expect the function to revert with ARRAY_LENGTH_MISMATCH error
vm.expectRevert(Error.ARRAY_LENGTH_MISMATCH.selector);
SuperformRouterPlus(ROUTER_PLUS_SOURCE).deposit4626{ value: 1 ether }(vaults, argsArray);

vm.stopPrank();
}

function test_deposit4626_multipleVaults() public {
// TODO
vm.startPrank(deployer);

// 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");

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

// Mint some DAI to the deployer
uint256 daiAmount = 1e18;

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

// Approve and deposit DAI into the 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);

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

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

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

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

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

vm.stopPrank();

// Verify the results
assertGt(
SuperPositions(SUPER_POSITIONS_SOURCE).balanceOf(deployer, superformId2),
0,
"Superform balance should be greater than 0"
);

// Check that the vault tokens were transferred from the deployer
assertEq(mockVault1.balanceOf(deployer), 0, "Deployer's vault token balance should be 0");
assertEq(mockVault2.balanceOf(deployer), 0, "Deployer's vault token balance should be 0");

// Check that the RouterPlus contract doesn't hold any tokens
assertEq(mockVault1.balanceOf(ROUTER_PLUS_SOURCE), 0, "RouterPlus should not hold any vault tokens");
assertEq(mockVault2.balanceOf(ROUTER_PLUS_SOURCE), 0, "RouterPlus should not hold any vault tokens");

assertEq(
MockERC20(getContract(SOURCE_CHAIN, "DAI")).balanceOf(ROUTER_PLUS_SOURCE),
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 Expand Up @@ -539,7 +655,8 @@ contract SuperformRouterPlusTest is ProtocolActions {

// Deploy a mock ERC4626 vault
VaultMock mockVault = new VaultMock(IERC20(getContract(SOURCE_CHAIN, "DAI")), "Mock Vault", "mVLT");
address[] calldata vaults = new address[](1);

address[] memory vaults = new address[](1);
vaults[0] = address(mockVault);

// Mint some DAI to the deployer
Expand All @@ -550,7 +667,8 @@ contract SuperformRouterPlusTest is ProtocolActions {
uint256 vaultTokenAmount = mockVault.deposit(daiAmount, deployer);

// Prepare deposit4626 args
Deposit4626Args[] calldata argsArray = new Deposit4626Args[](1);
ISuperformRouterPlus.Deposit4626Args[] memory argsArray = new ISuperformRouterPlus.Deposit4626Args[](1);

ISuperformRouterPlus.Deposit4626Args memory args = ISuperformRouterPlus.Deposit4626Args({
amount: vaultTokenAmount,
expectedOutputAmount: daiAmount * 10, // Assuming a large value for revert
Expand All @@ -559,6 +677,7 @@ contract SuperformRouterPlusTest is ProtocolActions {
depositCallData: _buildDepositCallData(superformId1, daiAmount)
});
argsArray[0] = args;

// Approve RouterPlus to spend vault tokens
mockVault.approve(ROUTER_PLUS_SOURCE, vaultTokenAmount);

Expand All @@ -572,7 +691,8 @@ contract SuperformRouterPlusTest is ProtocolActions {

// Deploy a mock ERC4626 vault
VaultMock mockVault = new VaultMock(IERC20(getContract(SOURCE_CHAIN, "DAI")), "Mock Vault", "mVLT");
address[] calldata vaults = new address[](1);

address[] memory vaults = new address[](1);
vaults[0] = address(mockVault);

// Mint some DAI to the deployer
Expand All @@ -591,7 +711,8 @@ contract SuperformRouterPlusTest is ProtocolActions {
);

// Prepare deposit4626 args
Deposit4626Args[] calldata argsArray = new Deposit4626Args[](1);
ISuperformRouterPlus.Deposit4626Args[] memory argsArray = new ISuperformRouterPlus.Deposit4626Args[](1);

ISuperformRouterPlus.Deposit4626Args memory args = ISuperformRouterPlus.Deposit4626Args({
amount: vaultTokenAmount,
expectedOutputAmount: daiAmount,
Expand All @@ -617,7 +738,8 @@ contract SuperformRouterPlusTest is ProtocolActions {

// Deploy a mock ERC4626 vault
VaultMock mockVault = new VaultMock(IERC20(getContract(SOURCE_CHAIN, "DAI")), "Mock Vault", "mVLT");
address[] calldata vaults = new address[](1);

address[] memory vaults = new address[](1);
vaults[0] = address(mockVault);

// Mint some DAI to the deployer
Expand All @@ -636,7 +758,8 @@ contract SuperformRouterPlusTest is ProtocolActions {
);

// Prepare deposit4626 args
Deposit4626Args[] calldata argsArray = new Deposit4626Args[](1);
ISuperformRouterPlus.Deposit4626Args[] memory argsArray = new ISuperformRouterPlus.Deposit4626Args[](1);

ISuperformRouterPlus.Deposit4626Args memory args = ISuperformRouterPlus.Deposit4626Args({
amount: vaultTokenAmount,
expectedOutputAmount: daiAmount,
Expand All @@ -662,7 +785,8 @@ contract SuperformRouterPlusTest is ProtocolActions {

// Deploy a mock ERC4626 vault
VaultMock mockVault = new VaultMock(IERC20(getContract(SOURCE_CHAIN, "DAI")), "Mock Vault", "mVLT");
address[] calldata vaults = new address[](1);

address[] memory vaults = new address[](1);
vaults[0] = address(mockVault);

// Mint some DAI to the deployer
Expand All @@ -673,7 +797,8 @@ contract SuperformRouterPlusTest is ProtocolActions {
uint256 vaultTokenAmount = mockVault.deposit(daiAmount, deployer);

// Prepare deposit4626 args
Deposit4626Args[] calldata argsArray = new Deposit4626Args[](1);
ISuperformRouterPlus.Deposit4626Args[] memory argsArray = new ISuperformRouterPlus.Deposit4626Args[](1);

ISuperformRouterPlus.Deposit4626Args memory args = ISuperformRouterPlus.Deposit4626Args({
amount: vaultTokenAmount,
expectedOutputAmount: daiAmount, // Assuming 1:1 ratio for simplicity
Expand Down Expand Up @@ -2545,7 +2670,8 @@ contract SuperformRouterPlusTest is ProtocolActions {

// Deploy a mock ERC4626 vault
VaultMock mockVault = new VaultMock(IERC20(getContract(SOURCE_CHAIN, "DAI")), "Mock Vault", "mVLT");
address[] calldata vaults = new address[](1);

address[] memory vaults = new address[](1);
vaults[0] = address(mockVault);

// Mint some DAI to the deployer
Expand All @@ -2556,7 +2682,8 @@ contract SuperformRouterPlusTest is ProtocolActions {
uint256 vaultTokenAmount = mockVault.deposit(daiAmount, deployer);

// Prepare deposit4626 args
Deposit4626Args[] calldata argsArray = new Deposit4626Args[](1);
ISuperformRouterPlus.Deposit4626Args[] memory argsArray = new ISuperformRouterPlus.Deposit4626Args[](1);

ISuperformRouterPlus.Deposit4626Args memory args = ISuperformRouterPlus.Deposit4626Args({
amount: vaultTokenAmount,
expectedOutputAmount: daiAmount, // Assuming 1:1 ratio for simplicity
Expand Down

0 comments on commit 68b2747

Please sign in to comment.