Skip to content

Commit af3dfef

Browse files
committed
feat: mellow 4626 and mellow claimer tests
1 parent f68bbf2 commit af3dfef

File tree

2 files changed

+476
-20
lines changed

2 files changed

+476
-20
lines changed

contracts/test/unit/adapters/mellow/Mellow4626VaultAdapter.unit.t.sol

Lines changed: 120 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
pragma solidity ^0.8.23;
55

66
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
7-
import {Mellow4626VaultAdapter} from "../../../../adapters/mellow/Mellow4626VaultAdapter.sol";
8-
import {IMellowSimpleLRTVault} from "../../../../integrations/mellow/IMellowSimpleLRTVault.sol";
97
import {IERC4626} from "@openzeppelin/contracts/interfaces/IERC4626.sol";
10-
import {IPhantomTokenAdapter} from "../../../../interfaces/IPhantomTokenAdapter.sol";
11-
import {AdapterUnitTestHelper} from "../AdapterUnitTestHelper.sol";
8+
import {Mellow4626VaultAdapter} from "../../../../adapters/mellow/Mellow4626VaultAdapter.sol";
9+
import {IMellowMultiVault} from "../../../../integrations/mellow/IMellowMultiVault.sol";
10+
import {IMellow4626VaultAdapter} from "../../../../interfaces/mellow/IMellow4626VaultAdapter.sol";
1211
import {MellowWithdrawalPhantomToken} from "../../../../helpers/mellow/MellowWithdrawalPhantomToken.sol";
12+
import {AdapterUnitTestHelper} from "../AdapterUnitTestHelper.sol";
1313

1414
/// @title Mellow4626Vault adapter unit test
15-
/// @notice U:[MV]: Unit tests for Mellow4626Vault adapter
15+
/// @notice U:[M4626]: Unit tests for Mellow4626Vault adapter
1616
contract Mellow4626VaultAdapterUnitTest is AdapterUnitTestHelper {
1717
Mellow4626VaultAdapter adapter;
1818

@@ -33,8 +33,8 @@ contract Mellow4626VaultAdapterUnitTest is AdapterUnitTestHelper {
3333
adapter = new Mellow4626VaultAdapter(address(creditManager), vault, stakedPhantomToken);
3434
}
3535

36-
/// @notice U:[MV-1]: Constructor works as expected
37-
function test_U_MV_01_constructor_works_as_expected() public {
36+
/// @notice U:[M4626-1]: Constructor works as expected
37+
function test_U_M4626_01_constructor_works_as_expected() public {
3838
_readsTokenMask(asset);
3939
_readsTokenMask(vault);
4040
_readsTokenMask(stakedPhantomToken);
@@ -43,13 +43,107 @@ contract Mellow4626VaultAdapterUnitTest is AdapterUnitTestHelper {
4343

4444
assertEq(adapter.creditManager(), address(creditManager), "Incorrect creditManager");
4545
assertEq(adapter.targetContract(), vault, "Incorrect targetContract");
46+
assertEq(adapter.vault(), vault, "Incorrect vault");
4647
assertEq(adapter.asset(), asset, "Incorrect asset");
4748
}
4849

49-
function test_U_MV_05_inherited_withdraw_works_as_expected() public {
50+
/// @notice U:[M4626-2]: Constructor reverts on invalid multivault
51+
function test_U_M4626_02_constructor_reverts_on_invalid_multivault() public {
52+
address wrongVault = makeAddr("WRONG_VAULT");
53+
vm.mockCall(stakedPhantomToken, abi.encodeWithSignature("multivault()"), abi.encode(wrongVault));
54+
55+
vm.expectRevert(IMellow4626VaultAdapter.InvalidMultivaultException.selector);
56+
new Mellow4626VaultAdapter(address(creditManager), vault, stakedPhantomToken);
57+
}
58+
59+
/// @notice U:[M4626-3]: Wrapper functions revert on wrong caller
60+
function test_U_M4626_03_wrapper_functions_revert_on_wrong_caller() public {
61+
_revertsOnNonFacadeCaller();
62+
adapter.deposit(0, address(0));
63+
64+
_revertsOnNonFacadeCaller();
65+
adapter.depositDiff(0);
66+
67+
_revertsOnNonFacadeCaller();
68+
adapter.mint(0, address(0));
69+
5070
_revertsOnNonFacadeCaller();
51-
adapter.withdraw(1000, address(0), address(0));
71+
adapter.withdraw(0, address(0), address(0));
72+
73+
_revertsOnNonFacadeCaller();
74+
adapter.redeem(0, address(0), address(0));
75+
76+
_revertsOnNonFacadeCaller();
77+
adapter.redeemDiff(0);
78+
}
79+
80+
/// @notice U:[M4626-4]: `deposit` works as expected
81+
function test_U_M4626_04_deposit_works_as_expected() public {
82+
// Test normal deposit
83+
vm.mockCall(vault, abi.encodeCall(IMellowMultiVault.depositWhitelist, ()), abi.encode(false));
84+
_readsActiveAccount();
85+
_executesSwap({
86+
tokenIn: asset,
87+
callData: abi.encodeCall(IERC4626.deposit, (1000, creditAccount)),
88+
requiresApproval: true
89+
});
90+
vm.prank(creditFacade);
91+
bool useSafePrices = adapter.deposit(1000, address(0));
92+
assertFalse(useSafePrices);
93+
94+
// Test deposit with whitelist enabled
95+
vm.mockCall(vault, abi.encodeCall(IMellowMultiVault.depositWhitelist, ()), abi.encode(true));
96+
vm.expectRevert(IMellow4626VaultAdapter.DepositsWhitelistedException.selector);
97+
vm.prank(creditFacade);
98+
adapter.deposit(1000, address(0));
99+
}
100+
101+
/// @notice U:[M4626-5]: `depositDiff` works as expected
102+
function test_U_M4626_05_depositDiff_works_as_expected() public diffTestCases {
103+
deal({token: asset, to: creditAccount, give: diffMintedAmount});
52104

105+
// Test normal depositDiff
106+
vm.mockCall(vault, abi.encodeCall(IMellowMultiVault.depositWhitelist, ()), abi.encode(false));
107+
_readsActiveAccount();
108+
_executesSwap({
109+
tokenIn: asset,
110+
callData: abi.encodeCall(IERC4626.deposit, (diffInputAmount, creditAccount)),
111+
requiresApproval: true
112+
});
113+
vm.prank(creditFacade);
114+
bool useSafePrices = adapter.depositDiff(diffLeftoverAmount);
115+
assertFalse(useSafePrices);
116+
117+
// Test depositDiff with whitelist enabled
118+
vm.mockCall(vault, abi.encodeCall(IMellowMultiVault.depositWhitelist, ()), abi.encode(true));
119+
vm.expectRevert(IMellow4626VaultAdapter.DepositsWhitelistedException.selector);
120+
vm.prank(creditFacade);
121+
adapter.depositDiff(diffLeftoverAmount);
122+
}
123+
124+
/// @notice U:[M4626-6]: `mint` works as expected
125+
function test_U_M4626_06_mint_works_as_expected() public {
126+
// Test normal mint
127+
vm.mockCall(vault, abi.encodeCall(IMellowMultiVault.depositWhitelist, ()), abi.encode(false));
128+
_readsActiveAccount();
129+
_executesSwap({
130+
tokenIn: asset,
131+
callData: abi.encodeCall(IERC4626.mint, (1000, creditAccount)),
132+
requiresApproval: true
133+
});
134+
vm.prank(creditFacade);
135+
bool useSafePrices = adapter.mint(1000, address(0));
136+
assertFalse(useSafePrices);
137+
138+
// Test mint with whitelist enabled
139+
vm.mockCall(vault, abi.encodeCall(IMellowMultiVault.depositWhitelist, ()), abi.encode(true));
140+
vm.expectRevert(IMellow4626VaultAdapter.DepositsWhitelistedException.selector);
141+
vm.prank(creditFacade);
142+
adapter.mint(1000, address(0));
143+
}
144+
145+
/// @notice U:[M4626-7]: `withdraw` works as expected and returns true for safe prices
146+
function test_U_M4626_07_withdraw_works_as_expected() public {
53147
_readsActiveAccount();
54148
_executesSwap({
55149
tokenIn: vault,
@@ -58,13 +152,11 @@ contract Mellow4626VaultAdapterUnitTest is AdapterUnitTestHelper {
58152
});
59153
vm.prank(creditFacade);
60154
bool useSafePrices = adapter.withdraw(1000, address(0), address(0));
61-
assertTrue(useSafePrices);
155+
assertTrue(useSafePrices, "Should use safe prices for withdrawals");
62156
}
63157

64-
function test_U_MV_06_inherited_redeem_works_as_expected() public {
65-
_revertsOnNonFacadeCaller();
66-
adapter.redeem(1000, address(0), address(0));
67-
158+
/// @notice U:[M4626-8]: `redeem` works as expected and returns true for safe prices
159+
function test_U_M4626_08_redeem_works_as_expected() public {
68160
_readsActiveAccount();
69161
_executesSwap({
70162
tokenIn: vault,
@@ -73,13 +165,11 @@ contract Mellow4626VaultAdapterUnitTest is AdapterUnitTestHelper {
73165
});
74166
vm.prank(creditFacade);
75167
bool useSafePrices = adapter.redeem(1000, address(0), address(0));
76-
assertTrue(useSafePrices);
168+
assertTrue(useSafePrices, "Should use safe prices for redemptions");
77169
}
78170

79-
function test_U_MV_07_inherited_redeemDiff_works_as_expected() public diffTestCases {
80-
_revertsOnNonFacadeCaller();
81-
adapter.redeemDiff(1000);
82-
171+
/// @notice U:[M4626-9]: `redeemDiff` works as expected and returns true for safe prices
172+
function test_U_M4626_09_redeemDiff_works_as_expected() public diffTestCases {
83173
deal({token: vault, to: creditAccount, give: diffMintedAmount});
84174

85175
_readsActiveAccount();
@@ -90,6 +180,16 @@ contract Mellow4626VaultAdapterUnitTest is AdapterUnitTestHelper {
90180
});
91181
vm.prank(creditFacade);
92182
bool useSafePrices = adapter.redeemDiff(diffLeftoverAmount);
93-
assertTrue(useSafePrices);
183+
assertTrue(useSafePrices, "Should use safe prices for redemptions");
184+
}
185+
186+
/// @notice U:[M4626-10]: `serialize` works as expected
187+
function test_U_M4626_10_serialize_works_as_expected() public {
188+
bytes memory serialized = adapter.serialize();
189+
(address cm, address tc, address a) = abi.decode(serialized, (address, address, address));
190+
191+
assertEq(cm, address(creditManager), "Incorrect credit manager in serialized data");
192+
assertEq(tc, vault, "Incorrect target contract in serialized data");
193+
assertEq(a, asset, "Incorrect asset in serialized data");
94194
}
95195
}

0 commit comments

Comments
 (0)