@@ -9,16 +9,12 @@ import {TestUtil} from "./utils/TestUtil.sol";
9
9
import {StabilityPoolBridge} from "../../../bridges/liquity/StabilityPoolBridge.sol " ;
10
10
11
11
contract StabilityPoolBridgeUnitTest is TestUtil {
12
- address public constant LQTY_ETH_POOL = 0xD1D5A4c0eA98971894772Dcd6D2f1dc71083C44E ; // 3000 bps fee tier
13
- address public constant USDC_ETH_POOL = 0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640 ; // 500 bps fee tier
14
- address public constant LUSD_USDC_POOL = 0x4e0924d3a751bE199C426d52fb1f2337fa96f736 ; // 500 bps fee tier
15
-
16
12
AztecTypes.AztecAsset internal emptyAsset;
17
13
StabilityPoolBridge private bridge;
18
14
19
15
function setUp () public {
16
+ _setUpTokensAndLabels ();
20
17
rollupProcessor = address (this );
21
- setUpTokens ();
22
18
23
19
bridge = new StabilityPoolBridge (rollupProcessor, address (0 ));
24
20
bridge.setApprovals ();
@@ -30,6 +26,9 @@ contract StabilityPoolBridgeUnitTest is TestUtil {
30
26
deal (tokens["LUSD " ].addr, address (bridge), 1 );
31
27
deal (tokens["LQTY " ].addr, address (bridge), 1 );
32
28
deal (tokens["WETH " ].addr, address (bridge), 1 );
29
+
30
+ // Reset ETH balance to 0 to make accounting easier
31
+ deal (address (bridge), 0 );
33
32
}
34
33
35
34
function testInitialERC20Params () public {
@@ -44,10 +43,14 @@ contract StabilityPoolBridgeUnitTest is TestUtil {
44
43
bridge.convert (emptyAsset, emptyAsset, emptyAsset, emptyAsset, 0 , 0 , 0 , address (0 ));
45
44
}
46
45
47
- function testFullDepositWithdrawalFlow () public {
48
- // I will deposit and withdraw 1 million LUSD
49
- uint256 inputValue = 1e24 ;
50
- _deposit (inputValue);
46
+ function testFullDepositWithdrawalFlow (
47
+ uint96 _depositAmount ,
48
+ uint96 _withdrawalAmount ,
49
+ uint64 _ethRewards ,
50
+ uint72 _lqtyRewards
51
+ ) public {
52
+ uint256 depositAmount = bound (_depositAmount, 10 , type (uint256 ).max);
53
+ uint256 spbReceived = _deposit (depositAmount);
51
54
52
55
AztecTypes.AztecAsset memory inputAssetA = AztecTypes.AztecAsset (
53
56
2 ,
@@ -61,104 +64,34 @@ contract StabilityPoolBridgeUnitTest is TestUtil {
61
64
);
62
65
63
66
// Transfer StabilityPoolBridge accounting token (SPB) back to the bridge
64
- IERC20 (inputAssetA.erc20Address).transfer (address (bridge), inputValue);
67
+ IERC20 (inputAssetA.erc20Address).transfer (address (bridge), spbReceived);
68
+
69
+ // Mint rewards to the bridge
70
+ deal (address (bridge), _ethRewards);
71
+ deal (tokens["LQTY " ].addr, address (bridge), _lqtyRewards);
65
72
66
73
// Withdraw LUSD from StabilityPool through the bridge
74
+ uint256 withdrawalAmount = bound (_withdrawalAmount, 10 , spbReceived);
75
+
67
76
(uint256 outputValueA , , ) = bridge.convert (
68
77
inputAssetA,
69
78
emptyAsset,
70
79
outputAssetA,
71
80
emptyAsset,
72
- inputValue ,
81
+ withdrawalAmount ,
73
82
1 ,
74
83
0 ,
75
84
address (0 )
76
85
);
77
86
78
- // Check the total supply of SPB token is 0
79
- assertEq (bridge.totalSupply (), 0 );
87
+ // Check the total supply of SPB token is spbReceived - withdrawalAmount
88
+ assertEq (bridge.totalSupply (), spbReceived - withdrawalAmount );
80
89
81
90
// Transfer the funds back from the bridge to the rollup processor
82
- IERC20 (outputAssetA.erc20Address).transferFrom (address (bridge), rollupProcessor, outputValueA);
83
-
84
- // Check the LUSD balance of rollupProcessor is greater or equal to the initial LUSD deposit
85
- assertGe (outputValueA, inputValue);
86
- }
87
-
88
- function testMultipleDepositsWithdrawals () public {
89
- uint256 i = 0 ;
90
- uint256 numIters = 2 ;
91
- uint256 depositAmount = 203 ;
92
- uint256 [] memory spbBalances = new uint256 [](numIters);
93
-
94
- AztecTypes.AztecAsset memory inputAssetA = AztecTypes.AztecAsset (
95
- 1 ,
96
- tokens["LUSD " ].addr,
97
- AztecTypes.AztecAssetType.ERC20
98
- );
99
- AztecTypes.AztecAsset memory outputAssetA = AztecTypes.AztecAsset (
100
- 2 ,
101
- address (bridge),
102
- AztecTypes.AztecAssetType.ERC20
91
+ assertTrue (
92
+ IERC20 (outputAssetA.erc20Address).transferFrom (address (bridge), rollupProcessor, outputValueA),
93
+ "Transfer failed "
103
94
);
104
-
105
- while (i < numIters) {
106
- depositAmount = rand (depositAmount);
107
- // 1. Mint deposit amount of LUSD directly to the bridge (to avoid transfer)
108
- deal (inputAssetA.erc20Address, address (bridge), depositAmount);
109
- // 2. Mint rewards to the bridge
110
- deal (tokens["LQTY " ].addr, address (bridge), 1e20 );
111
- deal (tokens["WETH " ].addr, address (bridge), 1e18 );
112
-
113
- // 3. Deposit LUSD to StabilityPool through the bridge
114
- (uint256 outputValueA , , ) = bridge.convert (
115
- inputAssetA,
116
- emptyAsset,
117
- outputAssetA,
118
- emptyAsset,
119
- depositAmount,
120
- i,
121
- 0 ,
122
- address (0 )
123
- );
124
-
125
- // 4. Transfer SPB back to RollupProcessor
126
- IERC20 (outputAssetA.erc20Address).transferFrom (address (bridge), rollupProcessor, outputValueA);
127
-
128
- spbBalances[i] = outputValueA;
129
- i++ ;
130
- }
131
-
132
- // 5. Swap input/output assets to execute withdraw flow in the next convert call
133
- (inputAssetA, outputAssetA) = (outputAssetA, inputAssetA);
134
-
135
- i = 0 ;
136
- while (i < numIters) {
137
- uint256 inputValue = spbBalances[i];
138
-
139
- // 6. Transfer SPB back to the bridge
140
- IERC20 (inputAssetA.erc20Address).transfer (address (bridge), inputValue);
141
-
142
- // 7. Withdraw LUSD from StabilityPool through the bridge
143
- (uint256 outputValueA , , ) = bridge.convert (
144
- inputAssetA,
145
- emptyAsset,
146
- outputAssetA,
147
- emptyAsset,
148
- inputValue,
149
- numIters + i,
150
- 0 ,
151
- address (0 )
152
- );
153
-
154
- // 8. Transfer LUSD back to RollupProcessor
155
- IERC20 (outputAssetA.erc20Address).transferFrom (address (bridge), rollupProcessor, outputValueA);
156
-
157
- i++ ;
158
- }
159
-
160
- // 5. Check the total supply of SPB token is 0
161
- assertEq (bridge.totalSupply (), 0 );
162
95
}
163
96
164
97
function testUrgentModeOffSwap1 () public {
@@ -239,7 +172,7 @@ contract StabilityPoolBridgeUnitTest is TestUtil {
239
172
);
240
173
}
241
174
242
- function _deposit (uint256 _depositAmount ) private {
175
+ function _deposit (uint256 _depositAmount ) private returns ( uint256 ) {
243
176
// 1. Mint the deposit amount of LUSD to the bridge
244
177
deal (tokens["LUSD " ].addr, address (bridge), _depositAmount);
245
178
@@ -268,5 +201,7 @@ contract StabilityPoolBridgeUnitTest is TestUtil {
268
201
// 6. Check the LUSD balance of the StabilityPoolBridge in the StabilityPool contract is greater than or equal
269
202
// to the amount of LUSD deposited
270
203
assertGe (bridge.STABILITY_POOL ().getCompoundedLUSDDeposit (address (bridge)), _depositAmount);
204
+
205
+ return outputValueA;
271
206
}
272
207
}
0 commit comments