@dhedge/v2-sdk 1.10.5 → 1.10.7
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/README.md +20 -0
- package/dist/entities/pool.d.ts +17 -0
- package/dist/services/compound/rewards.d.ts +2 -0
- package/dist/services/oneInch/index.d.ts +4 -1
- package/dist/services/toros/easySwapper.d.ts +2 -1
- package/dist/test/constants.d.ts +7 -0
- package/dist/test/utils/testingHelper.d.ts +0 -1
- package/dist/types.d.ts +2 -1
- package/dist/v2-sdk.cjs.development.js +1330 -1640
- package/dist/v2-sdk.cjs.development.js.map +1 -1
- package/dist/v2-sdk.cjs.production.min.js +1 -1
- package/dist/v2-sdk.cjs.production.min.js.map +1 -1
- package/dist/v2-sdk.esm.js +1330 -1640
- package/dist/v2-sdk.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/abi/IDhedgeEasySwapper.json +184 -303
- package/src/abi/compound/ICometRewards.json +241 -0
- package/src/config.ts +11 -6
- package/src/entities/pool.ts +59 -3
- package/src/services/compound/rewards.ts +9 -0
- package/src/services/oneInch/index.ts +9 -6
- package/src/services/toros/easySwapper.ts +64 -22
- package/src/test/compoundV3.test.ts +4 -0
- package/src/test/constants.ts +11 -4
- package/src/test/toros.test.ts +81 -53
- package/src/test/utils/testingHelper.ts +3 -2
- package/src/types.ts +2 -1
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"inputs": [
|
|
4
|
+
{ "internalType": "address", "name": "governor_", "type": "address" }
|
|
5
|
+
],
|
|
6
|
+
"stateMutability": "nonpayable",
|
|
7
|
+
"type": "constructor"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"inputs": [{ "internalType": "address", "name": "", "type": "address" }],
|
|
11
|
+
"name": "AlreadyConfigured",
|
|
12
|
+
"type": "error"
|
|
13
|
+
},
|
|
14
|
+
{ "inputs": [], "name": "BadData", "type": "error" },
|
|
15
|
+
{
|
|
16
|
+
"inputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
|
|
17
|
+
"name": "InvalidUInt64",
|
|
18
|
+
"type": "error"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"inputs": [{ "internalType": "address", "name": "", "type": "address" }],
|
|
22
|
+
"name": "NotPermitted",
|
|
23
|
+
"type": "error"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"inputs": [{ "internalType": "address", "name": "", "type": "address" }],
|
|
27
|
+
"name": "NotSupported",
|
|
28
|
+
"type": "error"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"inputs": [
|
|
32
|
+
{ "internalType": "address", "name": "", "type": "address" },
|
|
33
|
+
{ "internalType": "uint256", "name": "", "type": "uint256" }
|
|
34
|
+
],
|
|
35
|
+
"name": "TransferOutFailed",
|
|
36
|
+
"type": "error"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"anonymous": false,
|
|
40
|
+
"inputs": [
|
|
41
|
+
{
|
|
42
|
+
"indexed": true,
|
|
43
|
+
"internalType": "address",
|
|
44
|
+
"name": "oldGovernor",
|
|
45
|
+
"type": "address"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"indexed": true,
|
|
49
|
+
"internalType": "address",
|
|
50
|
+
"name": "newGovernor",
|
|
51
|
+
"type": "address"
|
|
52
|
+
}
|
|
53
|
+
],
|
|
54
|
+
"name": "GovernorTransferred",
|
|
55
|
+
"type": "event"
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"anonymous": false,
|
|
59
|
+
"inputs": [
|
|
60
|
+
{
|
|
61
|
+
"indexed": true,
|
|
62
|
+
"internalType": "address",
|
|
63
|
+
"name": "src",
|
|
64
|
+
"type": "address"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"indexed": true,
|
|
68
|
+
"internalType": "address",
|
|
69
|
+
"name": "recipient",
|
|
70
|
+
"type": "address"
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"indexed": true,
|
|
74
|
+
"internalType": "address",
|
|
75
|
+
"name": "token",
|
|
76
|
+
"type": "address"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"indexed": false,
|
|
80
|
+
"internalType": "uint256",
|
|
81
|
+
"name": "amount",
|
|
82
|
+
"type": "uint256"
|
|
83
|
+
}
|
|
84
|
+
],
|
|
85
|
+
"name": "RewardClaimed",
|
|
86
|
+
"type": "event"
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
"anonymous": false,
|
|
90
|
+
"inputs": [
|
|
91
|
+
{
|
|
92
|
+
"indexed": true,
|
|
93
|
+
"internalType": "address",
|
|
94
|
+
"name": "user",
|
|
95
|
+
"type": "address"
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"indexed": true,
|
|
99
|
+
"internalType": "address",
|
|
100
|
+
"name": "comet",
|
|
101
|
+
"type": "address"
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"indexed": false,
|
|
105
|
+
"internalType": "uint256",
|
|
106
|
+
"name": "amount",
|
|
107
|
+
"type": "uint256"
|
|
108
|
+
}
|
|
109
|
+
],
|
|
110
|
+
"name": "RewardsClaimedSet",
|
|
111
|
+
"type": "event"
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"inputs": [
|
|
115
|
+
{ "internalType": "address", "name": "comet", "type": "address" },
|
|
116
|
+
{ "internalType": "address", "name": "src", "type": "address" },
|
|
117
|
+
{ "internalType": "bool", "name": "shouldAccrue", "type": "bool" }
|
|
118
|
+
],
|
|
119
|
+
"name": "claim",
|
|
120
|
+
"outputs": [],
|
|
121
|
+
"stateMutability": "nonpayable",
|
|
122
|
+
"type": "function"
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
"inputs": [
|
|
126
|
+
{ "internalType": "address", "name": "comet", "type": "address" },
|
|
127
|
+
{ "internalType": "address", "name": "src", "type": "address" },
|
|
128
|
+
{ "internalType": "address", "name": "to", "type": "address" },
|
|
129
|
+
{ "internalType": "bool", "name": "shouldAccrue", "type": "bool" }
|
|
130
|
+
],
|
|
131
|
+
"name": "claimTo",
|
|
132
|
+
"outputs": [],
|
|
133
|
+
"stateMutability": "nonpayable",
|
|
134
|
+
"type": "function"
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
"inputs": [
|
|
138
|
+
{ "internalType": "address", "name": "comet", "type": "address" },
|
|
139
|
+
{ "internalType": "address", "name": "account", "type": "address" }
|
|
140
|
+
],
|
|
141
|
+
"name": "getRewardOwed",
|
|
142
|
+
"outputs": [
|
|
143
|
+
{
|
|
144
|
+
"components": [
|
|
145
|
+
{ "internalType": "address", "name": "token", "type": "address" },
|
|
146
|
+
{ "internalType": "uint256", "name": "owed", "type": "uint256" }
|
|
147
|
+
],
|
|
148
|
+
"internalType": "struct CometRewards.RewardOwed",
|
|
149
|
+
"name": "",
|
|
150
|
+
"type": "tuple"
|
|
151
|
+
}
|
|
152
|
+
],
|
|
153
|
+
"stateMutability": "nonpayable",
|
|
154
|
+
"type": "function"
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
"inputs": [],
|
|
158
|
+
"name": "governor",
|
|
159
|
+
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
|
|
160
|
+
"stateMutability": "view",
|
|
161
|
+
"type": "function"
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
"inputs": [{ "internalType": "address", "name": "", "type": "address" }],
|
|
165
|
+
"name": "rewardConfig",
|
|
166
|
+
"outputs": [
|
|
167
|
+
{ "internalType": "address", "name": "token", "type": "address" },
|
|
168
|
+
{ "internalType": "uint64", "name": "rescaleFactor", "type": "uint64" },
|
|
169
|
+
{ "internalType": "bool", "name": "shouldUpscale", "type": "bool" },
|
|
170
|
+
{ "internalType": "uint256", "name": "multiplier", "type": "uint256" }
|
|
171
|
+
],
|
|
172
|
+
"stateMutability": "view",
|
|
173
|
+
"type": "function"
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
"inputs": [
|
|
177
|
+
{ "internalType": "address", "name": "", "type": "address" },
|
|
178
|
+
{ "internalType": "address", "name": "", "type": "address" }
|
|
179
|
+
],
|
|
180
|
+
"name": "rewardsClaimed",
|
|
181
|
+
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
|
|
182
|
+
"stateMutability": "view",
|
|
183
|
+
"type": "function"
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
"inputs": [
|
|
187
|
+
{ "internalType": "address", "name": "comet", "type": "address" },
|
|
188
|
+
{ "internalType": "address", "name": "token", "type": "address" }
|
|
189
|
+
],
|
|
190
|
+
"name": "setRewardConfig",
|
|
191
|
+
"outputs": [],
|
|
192
|
+
"stateMutability": "nonpayable",
|
|
193
|
+
"type": "function"
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
"inputs": [
|
|
197
|
+
{ "internalType": "address", "name": "comet", "type": "address" },
|
|
198
|
+
{ "internalType": "address", "name": "token", "type": "address" },
|
|
199
|
+
{ "internalType": "uint256", "name": "multiplier", "type": "uint256" }
|
|
200
|
+
],
|
|
201
|
+
"name": "setRewardConfigWithMultiplier",
|
|
202
|
+
"outputs": [],
|
|
203
|
+
"stateMutability": "nonpayable",
|
|
204
|
+
"type": "function"
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
"inputs": [
|
|
208
|
+
{ "internalType": "address", "name": "comet", "type": "address" },
|
|
209
|
+
{ "internalType": "address[]", "name": "users", "type": "address[]" },
|
|
210
|
+
{
|
|
211
|
+
"internalType": "uint256[]",
|
|
212
|
+
"name": "claimedAmounts",
|
|
213
|
+
"type": "uint256[]"
|
|
214
|
+
}
|
|
215
|
+
],
|
|
216
|
+
"name": "setRewardsClaimed",
|
|
217
|
+
"outputs": [],
|
|
218
|
+
"stateMutability": "nonpayable",
|
|
219
|
+
"type": "function"
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
"inputs": [
|
|
223
|
+
{ "internalType": "address", "name": "newGovernor", "type": "address" }
|
|
224
|
+
],
|
|
225
|
+
"name": "transferGovernor",
|
|
226
|
+
"outputs": [],
|
|
227
|
+
"stateMutability": "nonpayable",
|
|
228
|
+
"type": "function"
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
"inputs": [
|
|
232
|
+
{ "internalType": "address", "name": "token", "type": "address" },
|
|
233
|
+
{ "internalType": "address", "name": "to", "type": "address" },
|
|
234
|
+
{ "internalType": "uint256", "name": "amount", "type": "uint256" }
|
|
235
|
+
],
|
|
236
|
+
"name": "withdrawToken",
|
|
237
|
+
"outputs": [],
|
|
238
|
+
"stateMutability": "nonpayable",
|
|
239
|
+
"type": "function"
|
|
240
|
+
}
|
|
241
|
+
]
|
package/src/config.ts
CHANGED
|
@@ -30,7 +30,7 @@ export const routerAddress: AddressDappNetworkMap = {
|
|
|
30
30
|
[Dapp.BALANCER]: "0xBA12222222228d8Ba445958a75a0704d566BF2C8",
|
|
31
31
|
[Dapp.UNISWAPV3]: "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45",
|
|
32
32
|
[Dapp.ARRAKIS]: "0xc73fb100a995b33f9fa181d420f4c8d74506df66",
|
|
33
|
-
[Dapp.TOROS]: "
|
|
33
|
+
[Dapp.TOROS]: "0x45b90480D6F643dE2f128db091A357C3c90399f2",
|
|
34
34
|
[Dapp.ZEROEX]: "0xdef1c0ded9bec7f1a1670819833240f027b25eff"
|
|
35
35
|
},
|
|
36
36
|
[Network.OPTIMISM]: {
|
|
@@ -38,7 +38,7 @@ export const routerAddress: AddressDappNetworkMap = {
|
|
|
38
38
|
[Dapp.SYNTHETIX]: "0x8700dAec35aF8Ff88c16BdF0418774CB3D7599B4",
|
|
39
39
|
[Dapp.AAVEV3]: "0x794a61358D6845594F94dc1DB02A252b5b4814aD",
|
|
40
40
|
[Dapp.ONEINCH]: "0x111111125421ca6dc452d289314280a0f8842a65",
|
|
41
|
-
[Dapp.TOROS]: "
|
|
41
|
+
[Dapp.TOROS]: "0x2Ed1bd7f66e47113672f3870308b5E867C5bb743",
|
|
42
42
|
[Dapp.VELODROME]: "0x9c12939390052919aF3155f41Bf4160Fd3666A6f",
|
|
43
43
|
[Dapp.VELODROMEV2]: "0xa062ae8a9c5e11aaa026fc2670b0d65ccc8b2858",
|
|
44
44
|
[Dapp.LYRA]: "0xCCE7819d65f348c64B7Beb205BA367b3fE33763B",
|
|
@@ -51,13 +51,15 @@ export const routerAddress: AddressDappNetworkMap = {
|
|
|
51
51
|
[Dapp.AAVEV3]: "0x794a61358D6845594F94dc1DB02A252b5b4814aD",
|
|
52
52
|
[Dapp.BALANCER]: "0xBA12222222228d8Ba445958a75a0704d566BF2C8",
|
|
53
53
|
[Dapp.RAMSES]: "0xaaa87963efeb6f7e0a2711f397663105acb1805e",
|
|
54
|
-
[Dapp.ZEROEX]: "0xdef1c0ded9bec7f1a1670819833240f027b25eff"
|
|
54
|
+
[Dapp.ZEROEX]: "0xdef1c0ded9bec7f1a1670819833240f027b25eff",
|
|
55
|
+
[Dapp.TOROS]: "0xA5679C4272A056Bb83f039961fae7D99C48529F5"
|
|
55
56
|
},
|
|
56
57
|
[Network.BASE]: {
|
|
57
58
|
[Dapp.ONEINCH]: "0x111111125421ca6dc452d289314280a0f8842a65",
|
|
58
59
|
[Dapp.ZEROEX]: "0xdef1c0ded9bec7f1a1670819833240f027b25eff",
|
|
59
60
|
[Dapp.AERODROME]: "0xcF77a3Ba9A5CA399B7c97c74d54e5b1Beb874E43",
|
|
60
|
-
[Dapp.AAVEV3]: "0xA238Dd80C259a72e81d7e4664a9801593F98d1c5"
|
|
61
|
+
[Dapp.AAVEV3]: "0xA238Dd80C259a72e81d7e4664a9801593F98d1c5",
|
|
62
|
+
[Dapp.TOROS]: "0xf067575Eb60c7587C11e867907AA7284833704d1"
|
|
61
63
|
}
|
|
62
64
|
};
|
|
63
65
|
|
|
@@ -79,9 +81,12 @@ export const stakingAddress: AddressDappNetworkMap = {
|
|
|
79
81
|
[Dapp.AAVEV3]: "0x929EC64c34a17401F460460D4B9390518E5B473e"
|
|
80
82
|
},
|
|
81
83
|
[Network.OPTIMISM]: {
|
|
82
|
-
[Dapp.AAVEV3]: "0x929EC64c34a17401F460460D4B9390518E5B473e"
|
|
84
|
+
[Dapp.AAVEV3]: "0x929EC64c34a17401F460460D4B9390518E5B473e",
|
|
85
|
+
[Dapp.COMPOUNDV3]: "0x443ea0340cb75a160f31a440722dec7b5bc3c2e9"
|
|
86
|
+
},
|
|
87
|
+
[Network.ARBITRUM]: {
|
|
88
|
+
[Dapp.COMPOUNDV3]: "0x88730d254a2f7e6ac8388c3198afd694ba9f7fae"
|
|
83
89
|
},
|
|
84
|
-
[Network.ARBITRUM]: {},
|
|
85
90
|
[Network.BASE]: {}
|
|
86
91
|
};
|
|
87
92
|
|
package/src/entities/pool.ts
CHANGED
|
@@ -40,7 +40,10 @@ import {
|
|
|
40
40
|
getUniswapV3MintTxData
|
|
41
41
|
} from "../services/uniswap/V3Liquidity";
|
|
42
42
|
import { getUniswapV3SwapTxData } from "../services/uniswap/V3Trade";
|
|
43
|
-
import {
|
|
43
|
+
import {
|
|
44
|
+
getCompleteWithdrawalTxData,
|
|
45
|
+
getEasySwapperTxData
|
|
46
|
+
} from "../services/toros/easySwapper";
|
|
44
47
|
import { getAaveV3ClaimTxData } from "../services/aave/incentives";
|
|
45
48
|
import {
|
|
46
49
|
getVelodromeAddLiquidityTxData,
|
|
@@ -77,6 +80,7 @@ import {
|
|
|
77
80
|
getCompoundV3LendTxData,
|
|
78
81
|
getCompoundV3WithdrawTxData
|
|
79
82
|
} from "../services/compound/lending";
|
|
83
|
+
import { getCompoundV3ClaimTxData } from "../services/compound/rewards";
|
|
80
84
|
|
|
81
85
|
export class Pool {
|
|
82
86
|
public readonly poolLogic: Contract;
|
|
@@ -371,13 +375,13 @@ export class Pool {
|
|
|
371
375
|
);
|
|
372
376
|
break;
|
|
373
377
|
case Dapp.ONEINCH:
|
|
374
|
-
swapTxData = await getOneInchSwapTxData(
|
|
378
|
+
({ swapTxData } = await getOneInchSwapTxData(
|
|
375
379
|
this,
|
|
376
380
|
assetFrom,
|
|
377
381
|
assetTo,
|
|
378
382
|
amountIn,
|
|
379
383
|
slippage
|
|
380
|
-
);
|
|
384
|
+
));
|
|
381
385
|
break;
|
|
382
386
|
case Dapp.BALANCER:
|
|
383
387
|
swapTxData = await this.utils.getBalancerSwapTx(
|
|
@@ -1037,6 +1041,31 @@ export class Pool {
|
|
|
1037
1041
|
return tx;
|
|
1038
1042
|
}
|
|
1039
1043
|
|
|
1044
|
+
/**
|
|
1045
|
+
* Claim rewards from CompoundV3
|
|
1046
|
+
* @param {string} asset Compound lending asset
|
|
1047
|
+
* @param {any} options Transaction options
|
|
1048
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
1049
|
+
* @returns {Promise<any>} Transaction
|
|
1050
|
+
*/
|
|
1051
|
+
async harvestCompoundV3Rewards(
|
|
1052
|
+
asset: string,
|
|
1053
|
+
options: any = null,
|
|
1054
|
+
estimateGas = false
|
|
1055
|
+
): Promise<any> {
|
|
1056
|
+
const claimTxData = await getCompoundV3ClaimTxData(this, asset);
|
|
1057
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
1058
|
+
this,
|
|
1059
|
+
[
|
|
1060
|
+
stakingAddress[this.network][Dapp.COMPOUNDV3] as string,
|
|
1061
|
+
claimTxData,
|
|
1062
|
+
options
|
|
1063
|
+
],
|
|
1064
|
+
estimateGas
|
|
1065
|
+
);
|
|
1066
|
+
return tx;
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1040
1069
|
/**
|
|
1041
1070
|
* Create UniswapV3 liquidity pool
|
|
1042
1071
|
* @param {dapp} Platform UniswapV3, VelodromeCL, AerodromeCL or RamesesCL
|
|
@@ -1842,4 +1871,31 @@ export class Pool {
|
|
|
1842
1871
|
const tx = await cancelOrderViaFlatMoney(this, options, estimateGas);
|
|
1843
1872
|
return tx;
|
|
1844
1873
|
}
|
|
1874
|
+
|
|
1875
|
+
/**
|
|
1876
|
+
* Complete a Toros withdrawal to a single asset
|
|
1877
|
+
* @param {string} destinationToken Address of destination asset
|
|
1878
|
+
* @param {number} slippage Slippage tolerance in %
|
|
1879
|
+
* @param {any} options Transaction options
|
|
1880
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
1881
|
+
* @returns {Promise<any>} Transaction
|
|
1882
|
+
*/
|
|
1883
|
+
async completeTorosWithdrawal(
|
|
1884
|
+
destinationToken: string,
|
|
1885
|
+
slippage = 0.5,
|
|
1886
|
+
options: any = null,
|
|
1887
|
+
estimateGas = false
|
|
1888
|
+
): Promise<any> {
|
|
1889
|
+
const txData = await getCompleteWithdrawalTxData(
|
|
1890
|
+
this,
|
|
1891
|
+
destinationToken,
|
|
1892
|
+
slippage
|
|
1893
|
+
);
|
|
1894
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
1895
|
+
this,
|
|
1896
|
+
[routerAddress[this.network].toros, txData, options],
|
|
1897
|
+
estimateGas
|
|
1898
|
+
);
|
|
1899
|
+
return tx;
|
|
1900
|
+
}
|
|
1845
1901
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ethers } from "ethers";
|
|
2
|
+
import ICometRewards from "../../abi/compound/ICometRewards.json";
|
|
3
|
+
import { Pool } from "../..";
|
|
4
|
+
|
|
5
|
+
export function getCompoundV3ClaimTxData(pool: Pool, asset: string): string {
|
|
6
|
+
const iCometRewards = new ethers.utils.Interface(ICometRewards);
|
|
7
|
+
|
|
8
|
+
return iCometRewards.encodeFunctionData("claim", [asset, pool.address, true]);
|
|
9
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
import axios from "axios";
|
|
3
3
|
import { ApiError, ethers } from "../..";
|
|
4
|
-
import { networkChainIdMap } from "../../config";
|
|
4
|
+
import { networkChainIdMap, routerAddress } from "../../config";
|
|
5
5
|
import { Pool } from "../../entities";
|
|
6
6
|
|
|
7
7
|
const oneInchBaseUrl = "https://api.1inch.dev/swap/v6.0/";
|
|
@@ -11,8 +11,9 @@ export async function getOneInchSwapTxData(
|
|
|
11
11
|
assetFrom: string,
|
|
12
12
|
assetTo: string,
|
|
13
13
|
amountIn: ethers.BigNumber | string,
|
|
14
|
-
slippage: number
|
|
15
|
-
|
|
14
|
+
slippage: number,
|
|
15
|
+
forEasySwapper = false
|
|
16
|
+
): Promise<{ swapTxData: string; dstAmount: string }> {
|
|
16
17
|
if (!process.env.ONEINCH_API_KEY)
|
|
17
18
|
throw new Error("ONEINCH_API_KEY not configured in .env file");
|
|
18
19
|
|
|
@@ -22,8 +23,8 @@ export async function getOneInchSwapTxData(
|
|
|
22
23
|
src: assetFrom,
|
|
23
24
|
dst: assetTo,
|
|
24
25
|
amount: amountIn.toString(),
|
|
25
|
-
from: pool.address,
|
|
26
|
-
|
|
26
|
+
from: forEasySwapper ? routerAddress[pool.network].toros : pool.address,
|
|
27
|
+
receiver: forEasySwapper ? routerAddress[pool.network].toros : pool.address,
|
|
27
28
|
slippage: slippage,
|
|
28
29
|
disableEstimate: true,
|
|
29
30
|
usePermit2: false
|
|
@@ -35,7 +36,9 @@ export async function getOneInchSwapTxData(
|
|
|
35
36
|
},
|
|
36
37
|
params
|
|
37
38
|
});
|
|
38
|
-
|
|
39
|
+
const swapTxData = response.data.tx.data;
|
|
40
|
+
const dstAmount = response.data.dstAmount;
|
|
41
|
+
return { swapTxData, dstAmount };
|
|
39
42
|
} catch (e) {
|
|
40
43
|
throw new ApiError("Swap api request of 1inch failed");
|
|
41
44
|
}
|
|
@@ -5,6 +5,8 @@ import IDhedgeEasySwapper from "../../abi/IDhedgeEasySwapper.json";
|
|
|
5
5
|
import { routerAddress } from "../../config";
|
|
6
6
|
import { getChainlinkPriceInUsd } from "../chainLink/price";
|
|
7
7
|
import { isPool, loadPool } from "./pool";
|
|
8
|
+
import { getOneInchSwapTxData } from "../oneInch";
|
|
9
|
+
import { wait } from "../../test/utils/testingHelper";
|
|
8
10
|
|
|
9
11
|
export async function getPoolDepositAsset(
|
|
10
12
|
pool: Pool,
|
|
@@ -33,22 +35,15 @@ export async function getEasySwapperDepositQuote(
|
|
|
33
35
|
pool: Pool,
|
|
34
36
|
torosAsset: string,
|
|
35
37
|
investAsset: string,
|
|
36
|
-
depositAsset: string,
|
|
37
38
|
amountIn: ethers.BigNumber
|
|
38
39
|
): Promise<ethers.BigNumber> {
|
|
39
40
|
const easySwapper = new ethers.Contract(
|
|
40
41
|
routerAddress[pool.network][Dapp.TOROS] as string,
|
|
41
|
-
IDhedgeEasySwapper
|
|
42
|
+
IDhedgeEasySwapper,
|
|
42
43
|
pool.signer
|
|
43
44
|
);
|
|
44
45
|
|
|
45
|
-
return await easySwapper.depositQuote(
|
|
46
|
-
torosAsset,
|
|
47
|
-
investAsset,
|
|
48
|
-
amountIn,
|
|
49
|
-
depositAsset,
|
|
50
|
-
true
|
|
51
|
-
);
|
|
46
|
+
return await easySwapper.depositQuote(torosAsset, investAsset, amountIn);
|
|
52
47
|
}
|
|
53
48
|
|
|
54
49
|
export async function getEasySwapperWithdrawalQuote(
|
|
@@ -82,19 +77,12 @@ export async function getEasySwapperTxData(
|
|
|
82
77
|
const [torosAsset, investAsset] = isWithdrawal
|
|
83
78
|
? [assetFrom, assetTo]
|
|
84
79
|
: [assetTo, assetFrom];
|
|
85
|
-
const iDhedgeEasySwapper = new ethers.utils.Interface(IDhedgeEasySwapper
|
|
80
|
+
const iDhedgeEasySwapper = new ethers.utils.Interface(IDhedgeEasySwapper);
|
|
86
81
|
if (isWithdrawal) {
|
|
87
|
-
|
|
88
|
-
pool,
|
|
89
|
-
torosAsset,
|
|
90
|
-
investAsset,
|
|
91
|
-
amountIn
|
|
92
|
-
);
|
|
93
|
-
return iDhedgeEasySwapper.encodeFunctionData("withdraw", [
|
|
82
|
+
return iDhedgeEasySwapper.encodeFunctionData("initWithdrawal", [
|
|
94
83
|
torosAsset,
|
|
95
84
|
amountIn,
|
|
96
|
-
|
|
97
|
-
minAmountOut.mul(10000 - slippage * 100).div(10000)
|
|
85
|
+
slippage * 100
|
|
98
86
|
]);
|
|
99
87
|
} else {
|
|
100
88
|
const depositAsset = await getPoolDepositAsset(
|
|
@@ -103,19 +91,73 @@ export async function getEasySwapperTxData(
|
|
|
103
91
|
investAsset
|
|
104
92
|
);
|
|
105
93
|
if (!depositAsset) throw new Error("no deposit assets");
|
|
94
|
+
if (depositAsset.toLowerCase() !== investAsset.toLowerCase())
|
|
95
|
+
throw new Error("can only trade deposit asset");
|
|
106
96
|
const minAmountOut = await getEasySwapperDepositQuote(
|
|
107
97
|
pool,
|
|
108
98
|
torosAsset,
|
|
109
99
|
investAsset,
|
|
110
|
-
depositAsset,
|
|
111
100
|
amountIn
|
|
112
101
|
);
|
|
113
102
|
return iDhedgeEasySwapper.encodeFunctionData("depositWithCustomCooldown", [
|
|
114
103
|
torosAsset,
|
|
115
|
-
investAsset,
|
|
116
|
-
amountIn,
|
|
117
104
|
depositAsset,
|
|
105
|
+
amountIn,
|
|
118
106
|
minAmountOut.mul(10000 - slippage * 100).div(10000)
|
|
119
107
|
]);
|
|
120
108
|
}
|
|
121
109
|
}
|
|
110
|
+
|
|
111
|
+
export async function getCompleteWithdrawalTxData(
|
|
112
|
+
pool: Pool,
|
|
113
|
+
destToken: string,
|
|
114
|
+
slippage: number
|
|
115
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
116
|
+
): Promise<string> {
|
|
117
|
+
const easySwapper = new ethers.Contract(
|
|
118
|
+
routerAddress[pool.network][Dapp.TOROS] as string,
|
|
119
|
+
IDhedgeEasySwapper,
|
|
120
|
+
pool.signer
|
|
121
|
+
);
|
|
122
|
+
const trackedAssets: {
|
|
123
|
+
token: string;
|
|
124
|
+
balance: ethers.BigNumber;
|
|
125
|
+
}[] = await easySwapper.getTrackedAssets(pool.address);
|
|
126
|
+
const trackedAssetsExcludingDestToken = trackedAssets.filter(
|
|
127
|
+
({ token }) => token.toLowerCase() !== destToken.toLowerCase()
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
const srcData = [];
|
|
131
|
+
let minDestAmount = ethers.BigNumber.from(0);
|
|
132
|
+
for (const { token, balance } of trackedAssetsExcludingDestToken) {
|
|
133
|
+
const { swapTxData, dstAmount } = await getOneInchSwapTxData(
|
|
134
|
+
pool,
|
|
135
|
+
token,
|
|
136
|
+
destToken,
|
|
137
|
+
balance,
|
|
138
|
+
slippage,
|
|
139
|
+
true
|
|
140
|
+
);
|
|
141
|
+
srcData.push({
|
|
142
|
+
token,
|
|
143
|
+
amount: balance,
|
|
144
|
+
aggregatorData: {
|
|
145
|
+
routerKey: ethers.utils.formatBytes32String("ONE_INCH"),
|
|
146
|
+
swapData: swapTxData
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
minDestAmount = minDestAmount.add(dstAmount);
|
|
150
|
+
await wait(2);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return easySwapper.interface.encodeFunctionData("completeWithdrawal", [
|
|
154
|
+
{
|
|
155
|
+
srcData,
|
|
156
|
+
destData: {
|
|
157
|
+
destToken,
|
|
158
|
+
minDestAmount
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
minDestAmount.mul(10000 - slippage * 100).div(10000)
|
|
162
|
+
]);
|
|
163
|
+
}
|
|
@@ -81,6 +81,10 @@ const testCompoundV3 = ({ network, provider }: TestingRunParams) => {
|
|
|
81
81
|
const wethBalance = await balanceDelta(pool.address, WETH, pool.signer);
|
|
82
82
|
expect(wethBalance.gt(0));
|
|
83
83
|
});
|
|
84
|
+
|
|
85
|
+
it("harvests rewards from CompundV3", async () => {
|
|
86
|
+
await pool.harvestCompoundV3Rewards(COMPOUNDV3_WETH);
|
|
87
|
+
});
|
|
84
88
|
});
|
|
85
89
|
};
|
|
86
90
|
|
package/src/test/constants.ts
CHANGED
|
@@ -49,6 +49,7 @@ export const CONTRACT_ADDRESS = {
|
|
|
49
49
|
[Network.POLYGON]: {
|
|
50
50
|
USDC: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
|
|
51
51
|
USDT: "",
|
|
52
|
+
SUSD: "",
|
|
52
53
|
SWETH: "",
|
|
53
54
|
WETH: "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619",
|
|
54
55
|
WBTC: "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6",
|
|
@@ -60,7 +61,8 @@ export const CONTRACT_ADDRESS = {
|
|
|
60
61
|
},
|
|
61
62
|
VELODROME_CL_USDC_WETH_GAUGE: "",
|
|
62
63
|
VELO: "",
|
|
63
|
-
COMPOUNDV3_WETH: ""
|
|
64
|
+
COMPOUNDV3_WETH: "",
|
|
65
|
+
TOROS: ""
|
|
64
66
|
},
|
|
65
67
|
|
|
66
68
|
[Network.OPTIMISM]: {
|
|
@@ -81,11 +83,13 @@ export const CONTRACT_ADDRESS = {
|
|
|
81
83
|
ARRAKIS_USDC_WETH_LP: "",
|
|
82
84
|
VELODROME_CL_USDC_WETH_GAUGE: "0xa75127121d28a9BF848F3B70e7Eea26570aa7700",
|
|
83
85
|
VELO: "0x9560e827aF36c94D2Ac33a39bCE1Fe78631088Db",
|
|
84
|
-
COMPOUNDV3_WETH: ""
|
|
86
|
+
COMPOUNDV3_WETH: "",
|
|
87
|
+
TOROS: "0x49bf093277bf4dde49c48c6aa55a3bda3eedef68" //USDmny
|
|
85
88
|
},
|
|
86
89
|
[Network.ARBITRUM]: {
|
|
87
90
|
USDC: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
88
91
|
USDT: "",
|
|
92
|
+
SUSD: "",
|
|
89
93
|
SWETH: "0xbc011A12Da28e8F0f528d9eE5E7039E22F91cf18",
|
|
90
94
|
WETH: "0x82af49447d8a07e3bd95bd0d56f35241523fbab1",
|
|
91
95
|
WBTC: "0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f",
|
|
@@ -103,11 +107,13 @@ export const CONTRACT_ADDRESS = {
|
|
|
103
107
|
WMATIC: "",
|
|
104
108
|
VELODROME_CL_USDC_WETH_GAUGE: "",
|
|
105
109
|
VELO: "",
|
|
106
|
-
COMPOUNDV3_WETH: "0x6f7D514bbD4aFf3BcD1140B7344b32f063dEe486"
|
|
110
|
+
COMPOUNDV3_WETH: "0x6f7D514bbD4aFf3BcD1140B7344b32f063dEe486",
|
|
111
|
+
TOROS: ""
|
|
107
112
|
},
|
|
108
113
|
[Network.BASE]: {
|
|
109
114
|
USDC: "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
|
|
110
115
|
USDT: "0xfde4c96c8593536e31f229ea8f37b2ada2699bb2",
|
|
116
|
+
SUSD: "",
|
|
111
117
|
WETH: "0x4200000000000000000000000000000000000006",
|
|
112
118
|
WBTC: "",
|
|
113
119
|
SWETH: "",
|
|
@@ -120,7 +126,8 @@ export const CONTRACT_ADDRESS = {
|
|
|
120
126
|
WMATIC: "",
|
|
121
127
|
VELODROME_CL_USDC_WETH_GAUGE: "0xF33a96b5932D9E9B9A0eDA447AbD8C9d48d2e0c8",
|
|
122
128
|
VELO: "0x940181a94A35A4569E4529A3CDfB74e38FD98631",
|
|
123
|
-
COMPOUNDV3_WETH: ""
|
|
129
|
+
COMPOUNDV3_WETH: "",
|
|
130
|
+
TOROS: ""
|
|
124
131
|
}
|
|
125
132
|
};
|
|
126
133
|
|