@gearbox-protocol/sdk 0.0.101 → 0.0.104
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +5 -0
- package/.eslintrc.js +52 -0
- package/.husky/pre-push +4 -0
- package/lib/apy/convexAPY.js +7 -9
- package/lib/apy/lidoAPY.js +35 -29
- package/lib/contracts/contracts.d.ts +5 -2
- package/lib/contracts/contracts.js +19 -18
- package/lib/contracts/contractsRegister.js +13 -1
- package/lib/core/constants.d.ts +5 -3
- package/lib/core/constants.js +8 -6
- package/lib/core/creditAccount.d.ts +2 -2
- package/lib/core/creditAccount.js +12 -11
- package/lib/core/creditManager.d.ts +1 -1
- package/lib/core/creditManager.js +4 -10
- package/lib/core/creditSession.js +14 -3
- package/lib/core/eventOrTx.d.ts +1 -1
- package/lib/core/events.d.ts +19 -19
- package/lib/core/events.js +23 -21
- package/lib/core/pool.d.ts +1 -1
- package/lib/core/pool.js +1 -7
- package/lib/core/price.d.ts +1 -3
- package/lib/core/price.js +9 -7
- package/lib/core/strategy.d.ts +8 -6
- package/lib/core/strategy.js +25 -25
- package/lib/core/tokenDistributor.js +1 -1
- package/lib/core/transactions.d.ts +18 -3
- package/lib/core/transactions.js +39 -3
- package/lib/index.d.ts +8 -2
- package/lib/index.js +8 -1
- package/lib/oracles/priceFeeds.js +1 -1
- package/lib/pathfinder/convexLP.d.ts +1 -1
- package/lib/pathfinder/convexLP.js +26 -29
- package/lib/pathfinder/curveLP.d.ts +1 -1
- package/lib/pathfinder/curveLP.js +5 -7
- package/lib/pathfinder/path.d.ts +1 -1
- package/lib/pathfinder/path.js +38 -42
- package/lib/pathfinder/trade.d.ts +1 -2
- package/lib/pathfinder/tradeTypes.d.ts +5 -5
- package/lib/pathfinder/yVault.d.ts +2 -2
- package/lib/pathfinder/yVault.js +22 -22
- package/lib/payload/creditAccount.d.ts +4 -4
- package/lib/payload/creditManager.d.ts +3 -13
- package/lib/payload/pool.d.ts +2 -2
- package/lib/strategies/convex.d.ts +12 -0
- package/lib/strategies/convex.js +74 -1
- package/lib/strategies/creditFacade.d.ts +1 -0
- package/lib/strategies/creditFacade.js +3 -0
- package/lib/strategies/curve.d.ts +15 -60
- package/lib/strategies/curve.js +74 -1
- package/lib/strategies/lido.d.ts +6 -0
- package/lib/strategies/lido.js +23 -1
- package/lib/strategies/uniswapV2.d.ts +1 -0
- package/lib/strategies/uniswapV2.js +6 -19
- package/lib/strategies/uniswapV3.d.ts +1 -0
- package/lib/strategies/uniswapV3.js +4 -1
- package/lib/strategies/yearn.d.ts +8 -0
- package/lib/strategies/yearn.js +92 -12
- package/lib/tokens/convex.d.ts +3 -3
- package/lib/tokens/curveLP.d.ts +7 -2
- package/lib/tokens/curveLP.js +8 -1
- package/lib/tokens/gear.d.ts +2 -2
- package/lib/tokens/gear.js +1 -1
- package/lib/tokens/normal.d.ts +1 -1
- package/lib/tokens/token.js +8 -8
- package/lib/tokens/tokenData.d.ts +3 -1
- package/lib/tokens/tokenData.js +10 -8
- package/lib/tokens/yearn.d.ts +6 -2
- package/lib/tokens/yearn.js +6 -0
- package/lib/utils/errors.d.ts +6 -0
- package/lib/utils/errors.js +13 -0
- package/lib/utils/formatter.d.ts +1 -1
- package/lib/utils/formatter.js +17 -14
- package/lib/utils/loading.d.ts +2 -1
- package/lib/utils/loading.js +9 -13
- package/lib/utils/mappers.js +2 -2
- package/lib/utils/network.js +2 -2
- package/lib/utils/repeater.js +12 -24
- package/lib/utils/validate.js +1 -1
- package/package.json +24 -7
- package/src/apy/convexAPY.ts +13 -12
- package/src/apy/lidoAPY.ts +35 -27
- package/src/contracts/contracts.ts +27 -17
- package/src/contracts/contractsRegister.ts +16 -1
- package/src/core/constants.ts +8 -5
- package/src/core/creditAccount.ts +42 -16
- package/src/core/creditManager.ts +33 -7
- package/src/core/creditOperation.ts +7 -7
- package/src/core/creditSession.ts +25 -5
- package/src/core/errors.ts +1 -0
- package/src/core/eventOrTx.ts +8 -5
- package/src/core/events.ts +85 -24
- package/src/core/history.ts +46 -46
- package/src/core/operations.ts +6 -0
- package/src/core/pool.ts +16 -4
- package/src/core/price.ts +10 -13
- package/src/core/strategy.ts +54 -43
- package/src/core/tokenDistributor.ts +2 -2
- package/src/core/transactions.ts +427 -350
- package/src/index.ts +10 -3
- package/src/oracles/priceFeeds.ts +523 -523
- package/src/pathfinder/contracts.ts +15 -13
- package/src/pathfinder/convexLP.ts +29 -25
- package/src/pathfinder/curveLP.ts +57 -53
- package/src/pathfinder/path.ts +17 -9
- package/src/pathfinder/priority.ts +11 -11
- package/src/pathfinder/trade.ts +84 -77
- package/src/pathfinder/tradeTypes.ts +98 -94
- package/src/pathfinder/yVault.ts +32 -17
- package/src/payload/creditAccount.ts +4 -4
- package/src/payload/creditManager.ts +3 -13
- package/src/payload/pool.ts +2 -2
- package/src/payload/token.ts +3 -3
- package/src/strategies/convex.ts +360 -186
- package/src/strategies/creditFacade.ts +74 -53
- package/src/strategies/curve.ts +400 -189
- package/src/strategies/lido.ts +70 -32
- package/src/strategies/uniswapV2.ts +93 -111
- package/src/strategies/uniswapV3.ts +118 -91
- package/src/strategies/yearn.ts +187 -60
- package/src/tokens/connectors.ts +6 -6
- package/src/tokens/convex.ts +297 -296
- package/src/tokens/curveLP.ts +176 -165
- package/src/tokens/gear.ts +47 -45
- package/src/tokens/normal.ts +801 -802
- package/src/tokens/token.ts +13 -9
- package/src/tokens/tokenData.ts +19 -9
- package/src/tokens/tokenType.ts +11 -11
- package/src/tokens/yearn.ts +130 -124
- package/src/utils/errors.ts +11 -0
- package/src/utils/formatter.ts +22 -18
- package/src/utils/loading.ts +14 -6
- package/src/utils/mappers.ts +8 -6
- package/src/utils/multicall.ts +2 -0
- package/src/utils/network.ts +21 -21
- package/src/utils/repeater.ts +2 -2
- package/src/utils/validate.ts +1 -1
- package/lib/utils/events.d.ts +0 -2
- package/lib/utils/events.js +0 -13
- package/src/utils/events.ts +0 -10
package/src/strategies/convex.ts
CHANGED
|
@@ -1,233 +1,407 @@
|
|
|
1
1
|
import { BigNumberish } from "ethers";
|
|
2
|
+
import {
|
|
3
|
+
contractParams,
|
|
4
|
+
contractsByNetwork,
|
|
5
|
+
ConvexPoolContract,
|
|
6
|
+
ConvexPoolParams
|
|
7
|
+
} from "src/contracts/contracts";
|
|
8
|
+
import { NetworkType } from "src/core/constants";
|
|
9
|
+
import { CreditManagerData } from "src/core/creditManager";
|
|
10
|
+
import { ConvexPhantomTokenData } from "src/tokens/convex";
|
|
11
|
+
import { CurveLPTokenData } from "src/tokens/curveLP";
|
|
12
|
+
import { supportedTokens, tokenDataByNetwork } from "src/tokens/token";
|
|
2
13
|
|
|
3
14
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from "../types"
|
|
15
|
+
ConvexV1BoosterAdapter__factory,
|
|
16
|
+
ConvexV1BaseRewardPoolAdapter__factory,
|
|
17
|
+
ConvexV1ClaimZapAdapter__factory
|
|
18
|
+
} from "../types";
|
|
8
19
|
|
|
9
20
|
import { MultiCallStruct } from "../types/contracts/interfaces/ICreditFacade.sol/ICreditFacade";
|
|
21
|
+
import { CurveStrategies } from "./curve";
|
|
22
|
+
import { UniswapV2Multicaller } from "./uniswapV2";
|
|
10
23
|
|
|
11
24
|
export class ConvexBoosterCalls {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
25
|
+
public static deposit(
|
|
26
|
+
pid: BigNumberish,
|
|
27
|
+
amount: BigNumberish,
|
|
28
|
+
stake: boolean
|
|
29
|
+
) {
|
|
30
|
+
return ConvexV1BoosterAdapter__factory.createInterface().encodeFunctionData(
|
|
31
|
+
"deposit",
|
|
32
|
+
[pid, amount, stake]
|
|
33
|
+
);
|
|
34
|
+
}
|
|
18
35
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
36
|
+
public static depositAll(pid: BigNumberish, stake: boolean) {
|
|
37
|
+
return ConvexV1BoosterAdapter__factory.createInterface().encodeFunctionData(
|
|
38
|
+
"depositAll",
|
|
39
|
+
[pid, stake]
|
|
40
|
+
);
|
|
41
|
+
}
|
|
25
42
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
43
|
+
public static withdraw(pid: BigNumberish, amount: BigNumberish) {
|
|
44
|
+
return ConvexV1BoosterAdapter__factory.createInterface().encodeFunctionData(
|
|
45
|
+
"withdraw",
|
|
46
|
+
[pid, amount]
|
|
47
|
+
);
|
|
48
|
+
}
|
|
32
49
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
50
|
+
public static withdrawAll(pid: BigNumberish) {
|
|
51
|
+
return ConvexV1BoosterAdapter__factory.createInterface().encodeFunctionData(
|
|
52
|
+
"withdrawAll",
|
|
53
|
+
[pid]
|
|
54
|
+
);
|
|
55
|
+
}
|
|
39
56
|
}
|
|
40
57
|
|
|
41
58
|
export class ConvexPoolCalls {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
59
|
+
public static stake(amount: BigNumberish) {
|
|
60
|
+
return ConvexV1BaseRewardPoolAdapter__factory.createInterface().encodeFunctionData(
|
|
61
|
+
"stake",
|
|
62
|
+
[amount]
|
|
63
|
+
);
|
|
64
|
+
}
|
|
48
65
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
66
|
+
public static stakeAll() {
|
|
67
|
+
return ConvexV1BaseRewardPoolAdapter__factory.createInterface().encodeFunctionData(
|
|
68
|
+
"stakeAll"
|
|
69
|
+
);
|
|
70
|
+
}
|
|
54
71
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
72
|
+
public static withdraw(amount: BigNumberish, claim: boolean) {
|
|
73
|
+
return ConvexV1BaseRewardPoolAdapter__factory.createInterface().encodeFunctionData(
|
|
74
|
+
"withdraw",
|
|
75
|
+
[amount, claim]
|
|
76
|
+
);
|
|
77
|
+
}
|
|
61
78
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
79
|
+
public static withdrawAll(claim: boolean) {
|
|
80
|
+
return ConvexV1BaseRewardPoolAdapter__factory.createInterface().encodeFunctionData(
|
|
81
|
+
"withdrawAll",
|
|
82
|
+
[claim]
|
|
83
|
+
);
|
|
84
|
+
}
|
|
68
85
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
86
|
+
public static withdrawAndUnwrap(amount: BigNumberish, claim: boolean) {
|
|
87
|
+
return ConvexV1BaseRewardPoolAdapter__factory.createInterface().encodeFunctionData(
|
|
88
|
+
"withdrawAndUnwrap",
|
|
89
|
+
[amount, claim]
|
|
90
|
+
);
|
|
91
|
+
}
|
|
75
92
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
93
|
+
public static withdrawAllAndUnwrap(claim: boolean) {
|
|
94
|
+
return ConvexV1BaseRewardPoolAdapter__factory.createInterface().encodeFunctionData(
|
|
95
|
+
"withdrawAllAndUnwrap",
|
|
96
|
+
[claim]
|
|
97
|
+
);
|
|
98
|
+
}
|
|
82
99
|
}
|
|
83
100
|
|
|
84
|
-
|
|
85
101
|
export class ConvexClaimZapCalls {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
102
|
+
public static claimRewards(
|
|
103
|
+
rewardContracts: Array<string>,
|
|
104
|
+
extraRewardContracts: Array<string>,
|
|
105
|
+
tokenRewardContracts: Array<string>,
|
|
106
|
+
tokenRewardTokens: Array<string>,
|
|
107
|
+
depositCrvMaxAmount: BigNumberish,
|
|
108
|
+
minAmountOut: BigNumberish,
|
|
109
|
+
depositCvxMaxAmount: BigNumberish,
|
|
110
|
+
spendCvxAmount: BigNumberish,
|
|
111
|
+
options: BigNumberish
|
|
112
|
+
) {
|
|
113
|
+
return ConvexV1ClaimZapAdapter__factory.createInterface().encodeFunctionData(
|
|
114
|
+
"claimRewards",
|
|
115
|
+
[
|
|
116
|
+
rewardContracts,
|
|
117
|
+
extraRewardContracts,
|
|
118
|
+
tokenRewardContracts,
|
|
119
|
+
tokenRewardTokens,
|
|
120
|
+
depositCrvMaxAmount,
|
|
121
|
+
minAmountOut,
|
|
122
|
+
depositCvxMaxAmount,
|
|
123
|
+
spendCvxAmount,
|
|
124
|
+
options
|
|
125
|
+
]
|
|
126
|
+
);
|
|
127
|
+
}
|
|
112
128
|
}
|
|
113
129
|
|
|
114
130
|
export class ConvexBoosterMulticaller {
|
|
115
|
-
|
|
131
|
+
private readonly _address: string;
|
|
116
132
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
133
|
+
constructor(address: string) {
|
|
134
|
+
this._address = address;
|
|
135
|
+
}
|
|
120
136
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
callData: ConvexBoosterCalls.deposit(pid, amount, stake)
|
|
125
|
-
}
|
|
126
|
-
}
|
|
137
|
+
static connect(address: string) {
|
|
138
|
+
return new ConvexBoosterMulticaller(address);
|
|
139
|
+
}
|
|
127
140
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
141
|
+
deposit(
|
|
142
|
+
pid: BigNumberish,
|
|
143
|
+
amount: BigNumberish,
|
|
144
|
+
stake: boolean
|
|
145
|
+
): MultiCallStruct {
|
|
146
|
+
return {
|
|
147
|
+
target: this._address,
|
|
148
|
+
callData: ConvexBoosterCalls.deposit(pid, amount, stake)
|
|
149
|
+
};
|
|
150
|
+
}
|
|
134
151
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
152
|
+
depositAll(pid: BigNumberish, stake: boolean): MultiCallStruct {
|
|
153
|
+
return {
|
|
154
|
+
target: this._address,
|
|
155
|
+
callData: ConvexBoosterCalls.depositAll(pid, stake)
|
|
156
|
+
};
|
|
157
|
+
}
|
|
141
158
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
159
|
+
withdraw(pid: BigNumberish, amount: BigNumberish): MultiCallStruct {
|
|
160
|
+
return {
|
|
161
|
+
target: this._address,
|
|
162
|
+
callData: ConvexBoosterCalls.withdraw(pid, amount)
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
withdrawAll(pid: BigNumberish): MultiCallStruct {
|
|
167
|
+
return {
|
|
168
|
+
target: this._address,
|
|
169
|
+
callData: ConvexBoosterCalls.withdrawAll(pid)
|
|
170
|
+
};
|
|
171
|
+
}
|
|
148
172
|
}
|
|
149
173
|
|
|
150
174
|
export class ConvexPoolMulticaller {
|
|
151
|
-
|
|
175
|
+
private readonly _address: string;
|
|
152
176
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
177
|
+
constructor(address: string) {
|
|
178
|
+
this._address = address;
|
|
179
|
+
}
|
|
156
180
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
callData: ConvexPoolCalls.stake(amount)
|
|
161
|
-
}
|
|
162
|
-
}
|
|
181
|
+
static connect(address: string) {
|
|
182
|
+
return new ConvexPoolMulticaller(address);
|
|
183
|
+
}
|
|
163
184
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
185
|
+
stake(amount: BigNumberish): MultiCallStruct {
|
|
186
|
+
return {
|
|
187
|
+
target: this._address,
|
|
188
|
+
callData: ConvexPoolCalls.stake(amount)
|
|
189
|
+
};
|
|
190
|
+
}
|
|
170
191
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
192
|
+
stakeAll(): MultiCallStruct {
|
|
193
|
+
return {
|
|
194
|
+
target: this._address,
|
|
195
|
+
callData: ConvexPoolCalls.stakeAll()
|
|
196
|
+
};
|
|
197
|
+
}
|
|
177
198
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
199
|
+
withdraw(amount: BigNumberish, claim: boolean): MultiCallStruct {
|
|
200
|
+
return {
|
|
201
|
+
target: this._address,
|
|
202
|
+
callData: ConvexPoolCalls.withdraw(amount, claim)
|
|
203
|
+
};
|
|
204
|
+
}
|
|
184
205
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
206
|
+
withdrawAll(claim: boolean): MultiCallStruct {
|
|
207
|
+
return {
|
|
208
|
+
target: this._address,
|
|
209
|
+
callData: ConvexPoolCalls.withdrawAll(claim)
|
|
210
|
+
};
|
|
211
|
+
}
|
|
191
212
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
213
|
+
withdrawAndUnwrap(amount: BigNumberish, claim: boolean): MultiCallStruct {
|
|
214
|
+
return {
|
|
215
|
+
target: this._address,
|
|
216
|
+
callData: ConvexPoolCalls.withdrawAndUnwrap(amount, claim)
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
withdrawAllAndUnwrap(claim: boolean) {
|
|
221
|
+
return {
|
|
222
|
+
target: this._address,
|
|
223
|
+
callData: ConvexPoolCalls.withdrawAllAndUnwrap(claim)
|
|
224
|
+
};
|
|
225
|
+
}
|
|
198
226
|
}
|
|
199
227
|
|
|
200
228
|
export class ConvexClaimZapMulticaller {
|
|
201
|
-
|
|
229
|
+
private readonly _address: string;
|
|
230
|
+
|
|
231
|
+
constructor(address: string) {
|
|
232
|
+
this._address = address;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
static connect(address: string) {
|
|
236
|
+
return new ConvexClaimZapMulticaller(address);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
claimRewards(
|
|
240
|
+
rewardContracts: Array<string>,
|
|
241
|
+
extraRewardContracts: Array<string>,
|
|
242
|
+
tokenRewardContracts: Array<string>,
|
|
243
|
+
tokenRewardTokens: Array<string>,
|
|
244
|
+
depositCrvMaxAmount: BigNumberish,
|
|
245
|
+
minAmountOut: BigNumberish,
|
|
246
|
+
depositCvxMaxAmount: BigNumberish,
|
|
247
|
+
spendCvxAmount: BigNumberish,
|
|
248
|
+
options: BigNumberish
|
|
249
|
+
): MultiCallStruct {
|
|
250
|
+
return {
|
|
251
|
+
target: this._address,
|
|
252
|
+
callData: ConvexClaimZapCalls.claimRewards(
|
|
253
|
+
rewardContracts,
|
|
254
|
+
extraRewardContracts,
|
|
255
|
+
tokenRewardContracts,
|
|
256
|
+
tokenRewardTokens,
|
|
257
|
+
depositCrvMaxAmount,
|
|
258
|
+
minAmountOut,
|
|
259
|
+
depositCvxMaxAmount,
|
|
260
|
+
spendCvxAmount,
|
|
261
|
+
options
|
|
262
|
+
)
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export class ConvexStrategies {
|
|
268
|
+
static underlyingToStakedConvex(
|
|
269
|
+
data: CreditManagerData,
|
|
270
|
+
network: NetworkType,
|
|
271
|
+
convexPool: ConvexPoolContract,
|
|
272
|
+
underlyingAmount: BigNumberish
|
|
273
|
+
) {
|
|
274
|
+
let calls: Array<MultiCallStruct> = [];
|
|
275
|
+
const convexParams = contractParams[convexPool] as ConvexPoolParams;
|
|
276
|
+
const { stakedToken } = convexParams;
|
|
277
|
+
const stakedTokenParams = supportedTokens[
|
|
278
|
+
stakedToken
|
|
279
|
+
] as ConvexPhantomTokenData;
|
|
280
|
+
const curveLpToken = stakedTokenParams.underlying;
|
|
281
|
+
const curveLpTokenData = supportedTokens[curveLpToken] as CurveLPTokenData;
|
|
282
|
+
const curvePool = curveLpTokenData.pool;
|
|
283
|
+
|
|
284
|
+
calls = CurveStrategies.underlyingToCurveLP(
|
|
285
|
+
data,
|
|
286
|
+
network,
|
|
287
|
+
curvePool,
|
|
288
|
+
underlyingAmount
|
|
289
|
+
);
|
|
290
|
+
|
|
291
|
+
calls.push(
|
|
292
|
+
ConvexBoosterMulticaller.connect(
|
|
293
|
+
data.adapters[contractsByNetwork[network].CONVEX_BOOSTER]
|
|
294
|
+
).depositAll(stakedTokenParams.pid, true)
|
|
295
|
+
);
|
|
296
|
+
|
|
297
|
+
return calls;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
static stakedConvexToUnderlying(
|
|
301
|
+
data: CreditManagerData,
|
|
302
|
+
network: NetworkType,
|
|
303
|
+
convexPool: ConvexPoolContract,
|
|
304
|
+
convexLpAmount: BigNumberish,
|
|
305
|
+
sellRewards: boolean
|
|
306
|
+
) {
|
|
307
|
+
const calls: Array<MultiCallStruct> = [];
|
|
308
|
+
const convexParams = contractParams[convexPool] as ConvexPoolParams;
|
|
309
|
+
const { stakedToken } = convexParams;
|
|
310
|
+
const stakedTokenParams = supportedTokens[
|
|
311
|
+
stakedToken
|
|
312
|
+
] as ConvexPhantomTokenData;
|
|
313
|
+
const curveLpToken = stakedTokenParams.underlying;
|
|
314
|
+
const curveLpTokenData = supportedTokens[curveLpToken] as CurveLPTokenData;
|
|
315
|
+
const curvePool = curveLpTokenData.pool;
|
|
202
316
|
|
|
203
|
-
|
|
204
|
-
|
|
317
|
+
calls.push(
|
|
318
|
+
ConvexPoolMulticaller.connect(
|
|
319
|
+
data.adapters[contractsByNetwork[network][convexPool]]
|
|
320
|
+
).withdrawAndUnwrap(convexLpAmount, true)
|
|
321
|
+
);
|
|
322
|
+
|
|
323
|
+
calls.push(
|
|
324
|
+
...CurveStrategies.allCurveLPToUnderlying(data, network, curvePool)
|
|
325
|
+
);
|
|
326
|
+
|
|
327
|
+
if (sellRewards) {
|
|
328
|
+
calls.push(...ConvexStrategies.sellRewards(data, network, convexPool));
|
|
205
329
|
}
|
|
206
330
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
331
|
+
return calls;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
static allStakedConvexToUnderlying(
|
|
335
|
+
data: CreditManagerData,
|
|
336
|
+
network: NetworkType,
|
|
337
|
+
convexPool: ConvexPoolContract,
|
|
338
|
+
sellRewards: boolean
|
|
339
|
+
) {
|
|
340
|
+
const calls: Array<MultiCallStruct> = [];
|
|
341
|
+
const convexParams = contractParams[convexPool] as ConvexPoolParams;
|
|
342
|
+
const { stakedToken } = convexParams;
|
|
343
|
+
const stakedTokenParams = supportedTokens[
|
|
344
|
+
stakedToken
|
|
345
|
+
] as ConvexPhantomTokenData;
|
|
346
|
+
const curveLpToken = stakedTokenParams.underlying;
|
|
347
|
+
const curveLpTokenData = supportedTokens[curveLpToken] as CurveLPTokenData;
|
|
348
|
+
const curvePool = curveLpTokenData.pool;
|
|
349
|
+
|
|
350
|
+
calls.push(
|
|
351
|
+
ConvexPoolMulticaller.connect(
|
|
352
|
+
data.adapters[contractsByNetwork[network][convexPool]]
|
|
353
|
+
).withdrawAllAndUnwrap(true)
|
|
354
|
+
);
|
|
355
|
+
|
|
356
|
+
calls.push(
|
|
357
|
+
...CurveStrategies.allCurveLPToUnderlying(data, network, curvePool)
|
|
358
|
+
);
|
|
359
|
+
|
|
360
|
+
if (sellRewards) {
|
|
361
|
+
calls.push(...ConvexStrategies.sellRewards(data, network, convexPool));
|
|
232
362
|
}
|
|
363
|
+
|
|
364
|
+
return calls;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
static sellRewards(
|
|
368
|
+
data: CreditManagerData,
|
|
369
|
+
network: NetworkType,
|
|
370
|
+
convexPool: ConvexPoolContract
|
|
371
|
+
) {
|
|
372
|
+
const calls: Array<MultiCallStruct> = [];
|
|
373
|
+
const convexParams = contractParams[convexPool] as ConvexPoolParams;
|
|
374
|
+
|
|
375
|
+
calls.push(
|
|
376
|
+
UniswapV2Multicaller.connect(
|
|
377
|
+
data.adapters[contractsByNetwork[network].UNISWAP_V2_ROUTER]
|
|
378
|
+
).swapAllTokensForTokens(
|
|
379
|
+
0,
|
|
380
|
+
[tokenDataByNetwork[network].CRV, data.underlyingToken],
|
|
381
|
+
Math.floor(new Date().getTime() / 1000) + 3600
|
|
382
|
+
),
|
|
383
|
+
UniswapV2Multicaller.connect(
|
|
384
|
+
data.adapters[contractsByNetwork[network].UNISWAP_V2_ROUTER]
|
|
385
|
+
).swapAllTokensForTokens(
|
|
386
|
+
0,
|
|
387
|
+
[tokenDataByNetwork[network].CVX, data.underlyingToken],
|
|
388
|
+
Math.floor(new Date().getTime() / 1000) + 3600
|
|
389
|
+
)
|
|
390
|
+
);
|
|
391
|
+
|
|
392
|
+
convexParams.extraRewards.forEach(extraReward => {
|
|
393
|
+
UniswapV2Multicaller.connect(
|
|
394
|
+
data.adapters[contractsByNetwork[network].UNISWAP_V2_ROUTER]
|
|
395
|
+
).swapAllTokensForTokens(
|
|
396
|
+
0,
|
|
397
|
+
[
|
|
398
|
+
tokenDataByNetwork[network][extraReward.rewardToken],
|
|
399
|
+
data.underlyingToken
|
|
400
|
+
],
|
|
401
|
+
Math.floor(new Date().getTime() / 1000) + 3600
|
|
402
|
+
);
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
return calls;
|
|
406
|
+
}
|
|
233
407
|
}
|