Skip to content

Commit 6c05ba2

Browse files
committed
update CurveDolaLPHelper and tests
1 parent 3945ec0 commit 6c05ba2

File tree

8 files changed

+187
-216
lines changed

8 files changed

+187
-216
lines changed

src/util/CurveDolaLPHelper.sol

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pragma solidity ^0.8.13;
33

44
import {IMarket} from "src/interfaces/IMarket.sol";
55
import {Sweepable, SafeERC20, IERC20} from "src/util/Sweepable.sol";
6-
import {IMultiMarketTransformHelper} from "src/interfaces/IMultiMarketTransformHelper.sol";
6+
import {IMultiMarketConvertHelper} from "src/interfaces/IMultiMarketConvertHelper.sol";
77
import {ICurvePool} from "src/interfaces/ICurvePool.sol";
88
import {IYearnVaultV2} from "src/interfaces/IYearnVaultV2.sol";
99

@@ -14,7 +14,7 @@ import {IYearnVaultV2} from "src/interfaces/IYearnVaultV2.sol";
1414
* Can also be used by anyone to perform add/remove liquidity from and to DOLA and deposit/withdraw operations.
1515
**/
1616

17-
contract CurveDolaLPHelper is Sweepable, IMultiMarketTransformHelper {
17+
contract CurveDolaLPHelper is Sweepable, IMultiMarketConvertHelper {
1818
using SafeERC20 for IERC20;
1919

2020
error InsufficientLP();
@@ -61,11 +61,12 @@ contract CurveDolaLPHelper is Sweepable, IMultiMarketTransformHelper {
6161
* @param data The encoded address of the market.
6262
* @return collateralAmount The amount of LP token received.
6363
*/
64-
function transformToCollateral(
64+
function convertToCollateral(
65+
address,
6566
uint256 amount,
6667
bytes calldata data
6768
) external override returns (uint256 collateralAmount) {
68-
collateralAmount = transformToCollateral(amount, msg.sender, data);
69+
collateralAmount = convertToCollateral(amount, msg.sender, data);
6970
}
7071

7172
/**
@@ -76,7 +77,7 @@ contract CurveDolaLPHelper is Sweepable, IMultiMarketTransformHelper {
7677
* @param data The encoded address of the market.
7778
* @return collateralAmount The amount of LP or Yearn token received.
7879
*/
79-
function transformToCollateral(
80+
function convertToCollateral(
8081
uint256 amount,
8182
address recipient,
8283
bytes calldata data
@@ -115,11 +116,12 @@ contract CurveDolaLPHelper is Sweepable, IMultiMarketTransformHelper {
115116
* @param data The encoded address of the market.
116117
* @return dolaAmount The amount of DOLA redeemed.
117118
*/
118-
function transformFromCollateral(
119+
function convertFromCollateral(
120+
address,
119121
uint256 amount,
120122
bytes calldata data
121123
) external override returns (uint256 dolaAmount) {
122-
dolaAmount = transformFromCollateral(amount, msg.sender, data);
124+
dolaAmount = convertFromCollateral(amount, msg.sender, data);
123125
}
124126

125127
/**
@@ -130,7 +132,7 @@ contract CurveDolaLPHelper is Sweepable, IMultiMarketTransformHelper {
130132
* @param data The encoded address of the market.
131133
* @return dolaAmount The amount of DOLA redeemed.
132134
*/
133-
function transformFromCollateral(
135+
function convertFromCollateral(
134136
uint256 amount,
135137
address recipient,
136138
bytes calldata data
@@ -171,7 +173,7 @@ contract CurveDolaLPHelper is Sweepable, IMultiMarketTransformHelper {
171173
* @param data The encoded address of the market.
172174
* @return collateralAmount The amount of collateral deposited into the market.
173175
*/
174-
function transformToCollateralAndDeposit(
176+
function convertToCollateralAndDeposit(
175177
uint256 assets,
176178
address recipient,
177179
bytes calldata data
@@ -180,7 +182,7 @@ contract CurveDolaLPHelper is Sweepable, IMultiMarketTransformHelper {
180182
_revertIfMarketNotSet(market);
181183

182184
// Convert DOLA to LP or Yearn token
183-
uint256 amount = transformToCollateral(assets, address(this), data);
185+
uint256 amount = convertToCollateral(assets, address(this), data);
184186

185187
IYearnVaultV2 vault = markets[market].vault;
186188

@@ -212,7 +214,7 @@ contract CurveDolaLPHelper is Sweepable, IMultiMarketTransformHelper {
212214
* @param data The encoded address of the market.
213215
* @return dolaAmount The amount of DOLA redeemed.
214216
*/
215-
function withdrawAndTransformFromCollateral(
217+
function withdrawAndConvertFromCollateral(
216218
uint256 amount,
217219
address recipient,
218220
Permit calldata permit,

test/util/CurveDolaLPHelperDolaCrvUSD.t.sol

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {ICurvePool} from "src/interfaces/ICurvePool.sol";
44
import {CurveDolaLPHelper} from "src/util/CurveDolaLPHelper.sol";
55
import "test/marketForkTests/CrvUSDDolaConvexMarketForkTest.t.sol";
66
import {console} from "forge-std/console.sol";
7-
import {IMultiMarketTransformHelper} from "src/interfaces/IMultiMarketTransformHelper.sol";
7+
import {IMultiMarketConvertHelper} from "src/interfaces/IMultiMarketConvertHelper.sol";
88

99
contract CurveDolaLPHelperTest is CrvUSDDolaConvexMarketForkTest {
1010
CurveDolaLPHelper helper;
@@ -27,15 +27,16 @@ contract CurveDolaLPHelperTest is CrvUSDDolaConvexMarketForkTest {
2727
vm.stopPrank();
2828
}
2929

30-
function test_transformToCollateral() public {
30+
function test_convertToCollateral() public {
3131
uint256 amount = 100 ether;
3232
// Estimate LP amount
3333
uint256[2] memory amounts = [amount, 0];
3434
uint estLpAmount = dolaCrvUSD.calc_token_amount(amounts, true);
3535

3636
DOLA.approve(address(helper), amount);
37-
uint256 lpAmount = helper.transformToCollateral(
37+
uint256 lpAmount = helper.convertToCollateral(
3838
amount,
39+
address(this),
3940
abi.encode(address(market), uint(1))
4041
);
4142
assertEq(
@@ -45,14 +46,14 @@ contract CurveDolaLPHelperTest is CrvUSDDolaConvexMarketForkTest {
4546
assertEq(lpAmount, estLpAmount);
4647
}
4748

48-
function test_transformToCollateral_receiver() public {
49+
function test_convertToCollateral_receiver() public {
4950
uint256 amount = 100 ether;
5051
// Estimate LP amount
5152
uint256[2] memory amounts = [amount, 0];
5253
uint estLpAmount = dolaCrvUSD.calc_token_amount(amounts, true);
5354

5455
DOLA.approve(address(helper), amount);
55-
uint256 lpAmount = helper.transformToCollateral(
56+
uint256 lpAmount = helper.convertToCollateral(
5657
amount,
5758
receiver,
5859
abi.encode(address(market), uint(1))
@@ -61,14 +62,14 @@ contract CurveDolaLPHelperTest is CrvUSDDolaConvexMarketForkTest {
6162
assertEq(lpAmount, estLpAmount);
6263
}
6364

64-
function test_transformToCollateralAndDeposit() public {
65+
function test_convertToCollateralAndDeposit() public {
6566
uint256 amount = 100 ether;
6667
// Estimate LP amount
6768
uint256[2] memory amounts = [amount, 0];
6869
uint estLpAmount = dolaCrvUSD.calc_token_amount(amounts, true);
6970

7071
DOLA.approve(address(helper), amount);
71-
uint256 lpAmount = helper.transformToCollateralAndDeposit(
72+
uint256 lpAmount = helper.convertToCollateralAndDeposit(
7273
amount,
7374
address(this),
7475
abi.encode(address(market), uint(1))
@@ -82,14 +83,14 @@ contract CurveDolaLPHelperTest is CrvUSDDolaConvexMarketForkTest {
8283
assertEq(lpAmount, estLpAmount);
8384
}
8485

85-
function test_transformToCollateralAndDeposit_receiver() public {
86+
function test_convertToCollateralAndDeposit_receiver() public {
8687
uint256 amount = 100 ether;
8788
// Estimate LP amount
8889
uint256[2] memory amounts = [amount, 0];
8990
uint estLpAmount = dolaCrvUSD.calc_token_amount(amounts, true);
9091

9192
DOLA.approve(address(helper), amount);
92-
uint256 lpAmount = helper.transformToCollateralAndDeposit(
93+
uint256 lpAmount = helper.convertToCollateralAndDeposit(
9394
amount,
9495
receiver,
9596
abi.encode(address(market), uint(1))
@@ -102,14 +103,15 @@ contract CurveDolaLPHelperTest is CrvUSDDolaConvexMarketForkTest {
102103
assertEq(lpAmount, estLpAmount);
103104
}
104105

105-
function test_transformFromCollateral() public {
106-
test_transformToCollateral();
106+
function test_convertFromCollateral() public {
107+
test_convertToCollateral();
107108
uint256 amount = IERC20(address(dolaCrvUSD)).balanceOf(address(this));
108109
// Estimate DOLA amount
109110
uint estDolaAmount = dolaCrvUSD.calc_withdraw_one_coin(amount, 0);
110111
uint dolaBalBefore = DOLA.balanceOf(address(this));
111112
IERC20(address(dolaCrvUSD)).approve(address(helper), amount);
112-
uint256 dolaAmount = helper.transformFromCollateral(
113+
uint256 dolaAmount = helper.convertFromCollateral(
114+
address(0),
113115
amount,
114116
abi.encode(address(market), uint(1))
115117
);
@@ -118,14 +120,14 @@ contract CurveDolaLPHelperTest is CrvUSDDolaConvexMarketForkTest {
118120
assertEq(dolaAmount, estDolaAmount);
119121
}
120122

121-
function test_transformFromCollateral_receiver() public {
122-
test_transformToCollateral();
123+
function test_convertFromCollateral_receiver() public {
124+
test_convertToCollateral();
123125
uint256 amount = IERC20(address(dolaCrvUSD)).balanceOf(address(this));
124126
// Estimate DOLA amount
125127
uint estDolaAmount = dolaCrvUSD.calc_withdraw_one_coin(amount, 0);
126128

127129
IERC20(address(dolaCrvUSD)).approve(address(helper), amount);
128-
uint256 dolaAmount = helper.transformFromCollateral(
130+
uint256 dolaAmount = helper.convertFromCollateral(
129131
amount,
130132
receiver,
131133
abi.encode(address(market), uint(1))
@@ -135,8 +137,8 @@ contract CurveDolaLPHelperTest is CrvUSDDolaConvexMarketForkTest {
135137
assertEq(dolaAmount, estDolaAmount);
136138
}
137139

138-
function test_withdrawAndTransformFromCollateral() public {
139-
test_transformToCollateralAndDeposit_receiver();
140+
function test_withdrawAndConvertFromCollateral() public {
141+
test_convertToCollateralAndDeposit_receiver();
140142
uint256 amount = ConvexEscrowV2(address(market.predictEscrow(receiver)))
141143
.balance();
142144
// Estimate DOLA amount
@@ -163,15 +165,15 @@ contract CurveDolaLPHelperTest is CrvUSDDolaConvexMarketForkTest {
163165

164166
(uint8 v, bytes32 r, bytes32 s) = vm.sign(23, hash);
165167

166-
IMultiMarketTransformHelper.Permit
167-
memory permit = IMultiMarketTransformHelper.Permit(
168+
IMultiMarketConvertHelper.Permit
169+
memory permit = IMultiMarketConvertHelper.Permit(
168170
block.timestamp,
169171
v,
170172
r,
171173
s
172174
);
173175
vm.prank(receiver);
174-
uint256 dolaAmount = helper.withdrawAndTransformFromCollateral(
176+
uint256 dolaAmount = helper.withdrawAndConvertFromCollateral(
175177
amount,
176178
receiver,
177179
permit,
@@ -182,8 +184,8 @@ contract CurveDolaLPHelperTest is CrvUSDDolaConvexMarketForkTest {
182184
assertEq(dolaAmount, estDolaAmount);
183185
}
184186

185-
function test_withdrawAndTransformFromCollateral_other_receiver() public {
186-
test_transformToCollateralAndDeposit_receiver();
187+
function test_withdrawAndConvertFromCollateral_other_receiver() public {
188+
test_convertToCollateralAndDeposit_receiver();
187189
uint256 amount = ConvexEscrowV2(address(market.predictEscrow(receiver)))
188190
.balance();
189191
// Estimate DOLA amount
@@ -211,15 +213,15 @@ contract CurveDolaLPHelperTest is CrvUSDDolaConvexMarketForkTest {
211213

212214
(uint8 v, bytes32 r, bytes32 s) = vm.sign(23, hash);
213215

214-
IMultiMarketTransformHelper.Permit
215-
memory permit = IMultiMarketTransformHelper.Permit(
216+
IMultiMarketConvertHelper.Permit
217+
memory permit = IMultiMarketConvertHelper.Permit(
216218
block.timestamp,
217219
v,
218220
r,
219221
s
220222
);
221223
vm.prank(receiver);
222-
uint256 dolaAmount = helper.withdrawAndTransformFromCollateral(
224+
uint256 dolaAmount = helper.withdrawAndConvertFromCollateral(
223225
amount,
224226
address(this),
225227
permit,

0 commit comments

Comments
 (0)