Skip to content

Commit cc2a55d

Browse files
committed
add YearnV2 deployed vault sDola-scrvUSD test, add fuzz tests
1 parent 16114e5 commit cc2a55d

File tree

4 files changed

+54
-42
lines changed

4 files changed

+54
-42
lines changed

test/marketForkTests/SDolascrvUSDYearnV2MarketForkTest.t.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ contract SDolascrvUSDYearnV2MarketForkTest is MarketBaseForkTest {
3535
address public constant sDolascrvUSD =
3636
address(0x76A962BA6770068bCF454D34dDE17175611e6637);
3737

38-
address yearn;
38+
address yearn = address(0x08c0833AF1331831759b8e0BFeF1BC5738436325);
3939
IYearnVaultFactory yearnFactory =
4040
IYearnVaultFactory(0x21b1FC8A52f179757bf555346130bF27c0C2A17A);
4141
address lpHolder = address(0x9D5Df30F475CEA915b1ed4C0CCa59255C897b61B);
4242
address gauge = address(0xDa0C79988b30d07857994e2C2650FCe644b690E1);
4343
function setUp() public virtual {
4444
//This will fail if there's no mainnet variable in foundry.toml
4545
string memory url = vm.rpcUrl("mainnet");
46-
vm.createSelectFork(url, 21386890);
46+
vm.createSelectFork(url, 21391176);
4747

4848
// Setup YearnVault if needed
4949
if (yearn == address(0)) {

test/marketForkTests/WethMarketForkTest.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ contract WethMarketForkTest is MarketBaseForkTest {
1212
function setUp() public {
1313
//This will fail if there's no mainnet variable in foundry.toml
1414
string memory url = vm.rpcUrl("mainnet");
15-
vm.createSelectFork(url);
15+
vm.createSelectFork(url, 21312974);
1616
//For non-deployed markets, instantiate market and feed after fork and use new contract addresses
1717
address marketAddr = 0x63Df5e23Db45a2066508318f172bA45B9CD37035;
1818
address feedAddr = 0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419;

test/util/aleTests/ALEBaseSDolaLPDyn.sol

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,16 @@ abstract contract ALEBaseSDolaLPDynTest is MarketForkTest {
9797
);
9898
}
9999

100-
function test_leveragePosition_buyDBR() public {
100+
function test_leveragePosition_buyDBR(uint256 amount) public {
101+
vm.assume(amount > 0.0001 ether);
102+
vm.assume(amount < 10000000 ether);
101103
vm.prank(gov);
102-
DOLA.mint(userPk, 10000 ether);
104+
DOLA.mint(userPk, amount);
103105

104106
vm.startPrank(userPk, userPk);
105-
DOLA.approve(address(helper), 10000 ether);
107+
DOLA.approve(address(helper), amount);
106108
helper.transformToCollateralAndDeposit(
107-
10000 ether,
109+
amount,
108110
userPk,
109111
abi.encode(address(market), 0)
110112
);
@@ -116,7 +118,7 @@ abstract contract ALEBaseSDolaLPDynTest is MarketForkTest {
116118

117119
// Calculate the amount of DOLA needed to borrow to buy the DBR needed to cover for the borrowing period
118120
(uint256 dolaForDBR, uint256 dbrAmount) = ale
119-
.approximateDolaAndDbrNeeded(maxBorrowAmount, 365 days, 8);
121+
.approximateDolaAndDbrNeeded(maxBorrowAmount, 15 days, 8);
120122

121123
// Sign Message for borrow on behalf
122124
bytes32 hash = keccak256(
@@ -145,7 +147,7 @@ abstract contract ALEBaseSDolaLPDynTest is MarketForkTest {
145147

146148
ALE.DBRHelper memory dbrData = ALE.DBRHelper(
147149
dolaForDBR,
148-
(dbrAmount * 97) / 100,
150+
(dbrAmount * 90) / 100,
149151
0
150152
);
151153

@@ -169,18 +171,20 @@ abstract contract ALEBaseSDolaLPDynTest is MarketForkTest {
169171
ConvexEscrowV2(address(userPkEscrow)).balance(),
170172
lpAmount + lpAmountAdded
171173
);
172-
assertGt(dbr.balanceOf(userPk), (dbrAmount * 97) / 100);
174+
assertGt(dbr.balanceOf(userPk), (dbrAmount * 90) / 100);
173175
}
174176

175-
function test_depositAndLeveragePosition_DOLA() public {
177+
function test_depositAndLeveragePosition_DOLA(uint amount) public {
178+
vm.assume(amount > 0.0001 ether);
179+
vm.assume(amount < 10000000 ether);
176180
vm.prank(gov);
177-
DOLA.mint(userPk, 11000 ether);
178-
uint256 initialDolaDeposit = 1000 ether;
181+
DOLA.mint(userPk, amount);
182+
uint256 initialDolaDeposit = amount / 10;
179183

180184
vm.startPrank(userPk, userPk);
181-
DOLA.approve(address(helper), 10000 ether);
185+
DOLA.approve(address(helper), amount - initialDolaDeposit);
182186
helper.transformToCollateralAndDeposit(
183-
10000 ether,
187+
amount - initialDolaDeposit,
184188
userPk,
185189
abi.encode(address(market), 0)
186190
);
@@ -245,18 +249,20 @@ abstract contract ALEBaseSDolaLPDynTest is MarketForkTest {
245249
);
246250
}
247251

248-
function test_depositAndLeveragePosition_LP() public {
252+
function test_depositAndLeveragePosition_LP(uint256 amount) public {
253+
vm.assume(amount > 0.0001 ether);
254+
vm.assume(amount < 10000000 ether);
249255
vm.prank(gov);
250-
DOLA.mint(userPk, 11000 ether);
251-
256+
DOLA.mint(userPk, amount);
257+
uint256 initialDolaForLP = amount / 10;
252258
vm.startPrank(userPk, userPk);
253-
DOLA.approve(address(helper), 11000 ether);
259+
DOLA.approve(address(helper), amount);
254260
uint256 initialLpAmount = helper.transformToCollateral(
255-
1000 ether,
261+
initialDolaForLP,
256262
abi.encode(address(market), 0)
257263
);
258264
helper.transformToCollateralAndDeposit(
259-
10000 ether,
265+
amount - initialDolaForLP,
260266
userPk,
261267
abi.encode(address(market), 0)
262268
);

test/util/aleTests/ALEBaseSDolaLPDynYearnV2.sol

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,16 @@ abstract contract ALEBaseSDolaLPDynYearnV2Test is MarketForkTest {
8484
assertEq(vault.balanceOf(userPkEscrow), sharesAmount + sharesAdded);
8585
}
8686

87-
function test_leveragePosition_buyDBR() public {
87+
function test_leveragePosition_buyDBR(uint256 amount) public {
88+
vm.assume(amount > 0.0001 ether);
89+
vm.assume(amount < 10000000 ether);
8890
vm.prank(gov);
89-
DOLA.mint(userPk, 10000 ether);
91+
DOLA.mint(userPk, amount);
9092

9193
vm.startPrank(userPk, userPk);
92-
DOLA.approve(address(helper), 10000 ether);
94+
DOLA.approve(address(helper), amount);
9395
helper.transformToCollateralAndDeposit(
94-
10000 ether,
96+
amount,
9597
userPk,
9698
abi.encode(address(market), 0)
9799
);
@@ -103,7 +105,7 @@ abstract contract ALEBaseSDolaLPDynYearnV2Test is MarketForkTest {
103105

104106
// Calculate the amount of DOLA needed to borrow to buy the DBR needed to cover for the borrowing period
105107
(uint256 dolaForDBR, uint256 dbrAmount) = ale
106-
.approximateDolaAndDbrNeeded(maxBorrowAmount, 365 days, 8);
108+
.approximateDolaAndDbrNeeded(maxBorrowAmount, 15 days, 8);
107109

108110
// Sign Message for borrow on behalf
109111
bytes32 hash = keccak256(
@@ -132,7 +134,7 @@ abstract contract ALEBaseSDolaLPDynYearnV2Test is MarketForkTest {
132134

133135
ALE.DBRHelper memory dbrData = ALE.DBRHelper(
134136
dolaForDBR,
135-
(dbrAmount * 98) / 100,
137+
(dbrAmount * 90) / 100,
136138
0
137139
);
138140

@@ -155,18 +157,20 @@ abstract contract ALEBaseSDolaLPDynYearnV2Test is MarketForkTest {
155157

156158
assertEq(DOLA.balanceOf(userPk), 0);
157159
assertEq(vault.balanceOf(userPkEscrow), sharesAmount + sharesAdded);
158-
assertGt(dbr.balanceOf(userPk), (dbrAmount * 98) / 100);
160+
assertGt(dbr.balanceOf(userPk), (dbrAmount * 90) / 100);
159161
}
160162

161-
function test_depositAndLeveragePosition_DOLA() public {
163+
function test_depositAndLeveragePosition_DOLA(uint256 amount) public {
164+
vm.assume(amount > 0.0001 ether);
165+
vm.assume(amount < 10000000 ether);
162166
vm.prank(gov);
163-
DOLA.mint(userPk, 11000 ether);
164-
uint256 initialDolaDeposit = 1000 ether;
167+
DOLA.mint(userPk, amount);
168+
uint256 initialDolaDeposit = amount / 10;
165169

166170
vm.startPrank(userPk, userPk);
167-
DOLA.approve(address(helper), 10000 ether);
171+
DOLA.approve(address(helper), amount - initialDolaDeposit);
168172
helper.transformToCollateralAndDeposit(
169-
10000 ether,
173+
amount - initialDolaDeposit,
170174
userPk,
171175
abi.encode(address(market), 0)
172176
);
@@ -231,18 +235,20 @@ abstract contract ALEBaseSDolaLPDynYearnV2Test is MarketForkTest {
231235
assertEq(vault.balanceOf(userPkEscrow), sharesAmount + sharesAdded);
232236
}
233237

234-
function test_depositAndLeveragePosition_LP() public {
238+
function test_depositAndLeveragePosition_LP(uint256 amount) public {
239+
vm.assume(amount > 0.0001 ether);
240+
vm.assume(amount < 10000000 ether);
235241
vm.prank(gov);
236-
DOLA.mint(userPk, 11000 ether);
237-
242+
DOLA.mint(userPk, amount);
243+
uint256 initialDolaForShares = amount / 10;
238244
vm.startPrank(userPk, userPk);
239-
DOLA.approve(address(helper), 11000 ether);
245+
DOLA.approve(address(helper), amount);
240246
uint256 initialSharesAmount = helper.transformToCollateral(
241-
1000 ether,
247+
initialDolaForShares,
242248
abi.encode(address(market), 0)
243249
);
244250
helper.transformToCollateralAndDeposit(
245-
10000 ether,
251+
amount - initialDolaForShares,
246252
userPk,
247253
abi.encode(address(market), 0)
248254
);
@@ -357,7 +363,6 @@ abstract contract ALEBaseSDolaLPDynYearnV2Test is MarketForkTest {
357363
abi.encode(address(market), uint(0)),
358364
dbrData
359365
);
360-
361366
assertEq(
362367
vault.balanceOf(userPkEscrow),
363368
totalSharesAmount - amountToWithdraw
@@ -449,10 +454,11 @@ abstract contract ALEBaseSDolaLPDynYearnV2Test is MarketForkTest {
449454
uint256 sharesAmount = vault.balanceOf(userPkEscrow);
450455
uint256 amountToWithdraw = sharesAmount / 2;
451456

452-
uint256 dolaRedeemed = curvePool.calc_withdraw_one_coin(
457+
uint256 sDolaRedeemed = curvePool.calc_withdraw_one_coin(
453458
YearnVaultV2Helper.collateralToAsset(vault, amountToWithdraw),
454-
0
459+
1
455460
);
461+
uint256 dolaRedeemed = sDOLA.convertToAssets(sDolaRedeemed);
456462
uint256 debt = market.debts(address(userPk));
457463

458464
assertGt(debt, 0);

0 commit comments

Comments
 (0)