@dhedge/v2-sdk 1.1.1 → 1.2.0
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 +60 -3
- package/dist/config.d.ts +2 -0
- package/dist/entities/pool.d.ts +32 -0
- package/dist/entities/utils.d.ts +4 -0
- package/dist/services/claim-balancer/claim.service.d.ts +21 -0
- package/dist/services/claim-balancer/claim.worker.d.ts +4 -0
- package/dist/services/claim-balancer/ipfs.service.d.ts +4 -0
- package/dist/services/claim-balancer/types.d.ts +54 -0
- package/dist/test/constants.d.ts +12 -0
- package/dist/types.d.ts +5 -2
- package/dist/utils/contract.d.ts +14 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/merkle.d.ts +22 -0
- package/dist/v2-sdk.cjs.development.js +3623 -672
- 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 +3623 -672
- package/dist/v2-sdk.esm.js.map +1 -1
- package/package.json +9 -2
- package/src/abi/IAaveIncentivesController.json +50 -0
- package/src/abi/IBalancerMerkleOrchard.json +353 -0
- package/src/abi/IBalancertV2Vault.json +938 -0
- package/src/config.ts +16 -3
- package/src/entities/pool.ts +140 -1
- package/src/entities/utils.ts +135 -0
- package/src/services/claim-balancer/MultiTokenClaim.json +115 -0
- package/src/services/claim-balancer/claim.service.ts +324 -0
- package/src/services/claim-balancer/claim.worker.ts +32 -0
- package/src/services/claim-balancer/ipfs.service.ts +12 -0
- package/src/services/claim-balancer/types.ts +66 -0
- package/src/test/aave.test.ts +73 -0
- package/src/test/balancer.test.ts +109 -0
- package/src/test/constants.ts +13 -0
- package/src/test/oneInch.test.ts +56 -0
- package/src/test/pool.test.ts +5 -249
- package/src/test/sushi.test.ts +173 -0
- package/src/test/utils.test.ts +41 -26
- package/src/types.ts +6 -3
- package/src/utils/contract.ts +95 -0
- package/src/utils/index.ts +38 -0
- package/src/utils/merkle.ts +172 -0
package/src/test/pool.test.ts
CHANGED
|
@@ -1,31 +1,15 @@
|
|
|
1
1
|
import { Dhedge } from "..";
|
|
2
2
|
import { Network } from "../types";
|
|
3
|
+
import { TEST_POOL } from "./constants";
|
|
3
4
|
|
|
4
5
|
import { wallet } from "./wallet";
|
|
5
6
|
|
|
6
|
-
const myPool = "0x279ac4c05154fd72a636fce1bc25c50966141fd0";
|
|
7
|
-
//const weth = "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619";
|
|
8
|
-
//const usdt = "0xc2132D05D31c914a87C6611C10748AEb04B58e8F";
|
|
9
|
-
//const dai = "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063";
|
|
10
|
-
//const usdc = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174";
|
|
11
|
-
|
|
12
|
-
// const sushi = "0x0b3F868E0BE5597D5DB7fEB59E1CADBb0fdDa50a";
|
|
13
|
-
// const wmatic = "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270";
|
|
14
|
-
// const lpUsdcWeth = "0x34965ba0ac2451A34a0471F04CCa3F990b8dea27";
|
|
15
|
-
//const lpUsdcDai = "0xCD578F016888B57F1b1e3f887f392F0159E26747";
|
|
16
|
-
//const amusdc = "0x1a13F4Ca1d028320A707D99520AbFefca3998b7F";
|
|
17
|
-
//const lpUsdcUsdt = "0x4b1f1e2435a9c96f7330faea190ef6a7c8d70001";
|
|
18
|
-
// const tradeAmountUsdc = "1000000";
|
|
19
|
-
// const liquidityAmountUsdt = "1000000";
|
|
20
|
-
// const lpUsdcWETHAmount = "10951027354";
|
|
21
|
-
// const depositAmountUsdc = "100000";
|
|
22
|
-
|
|
23
7
|
let dhedge: Dhedge;
|
|
24
8
|
|
|
25
9
|
jest.setTimeout(100000);
|
|
26
10
|
|
|
27
11
|
// const options = {
|
|
28
|
-
// gasLimit:
|
|
12
|
+
// gasLimit: 5000000,
|
|
29
13
|
// gasPrice: ethers.utils.parseUnits("35", "gwei")
|
|
30
14
|
// };
|
|
31
15
|
|
|
@@ -35,123 +19,16 @@ describe("pool", () => {
|
|
|
35
19
|
});
|
|
36
20
|
|
|
37
21
|
it("checks fund composition", async () => {
|
|
38
|
-
const pool = await dhedge.loadPool(
|
|
22
|
+
const pool = await dhedge.loadPool(TEST_POOL);
|
|
39
23
|
const result = await pool.getComposition();
|
|
24
|
+
console.log(result);
|
|
40
25
|
expect(result.length).toBeGreaterThan(0);
|
|
41
26
|
});
|
|
42
27
|
|
|
43
28
|
// it("withdraws 1.00002975 fund tokens", async () => {
|
|
44
|
-
// const pool = await dhedge.loadPool(myPool)
|
|
29
|
+
// const pool = await dhedge.loadPool(myPool);
|
|
45
30
|
// const result = await pool.withdraw("1000029750000000000");
|
|
46
31
|
// expect(result).toBeGreaterThan(0);
|
|
47
|
-
// })
|
|
48
|
-
|
|
49
|
-
// it("approves unlimited USDC on 1Inch", async () => {
|
|
50
|
-
// let result;
|
|
51
|
-
// const pool = await dhedge.loadPool(myPool);
|
|
52
|
-
// try {
|
|
53
|
-
// result = await pool.approve(
|
|
54
|
-
// Dapp.ONEINCH,
|
|
55
|
-
// usdc,
|
|
56
|
-
// ethers.constants.MaxInt256,
|
|
57
|
-
// options
|
|
58
|
-
// );
|
|
59
|
-
// console.log(result);
|
|
60
|
-
// } catch (e) {
|
|
61
|
-
// console.log(e);
|
|
62
|
-
// }
|
|
63
|
-
// expect(result).not.toBe(null);
|
|
64
|
-
// });
|
|
65
|
-
|
|
66
|
-
// it("trades 1 USDC into WETH on 1Inch", async () => {
|
|
67
|
-
// let result;
|
|
68
|
-
// const pool = await dhedge.loadPool(myPool);
|
|
69
|
-
// try {
|
|
70
|
-
// result = await pool.trade(
|
|
71
|
-
// Dapp.ONEINCH,
|
|
72
|
-
// usdc,
|
|
73
|
-
// weth,
|
|
74
|
-
// "1000000",
|
|
75
|
-
// 0.5,
|
|
76
|
-
// options
|
|
77
|
-
// );
|
|
78
|
-
// console.log("1inch trade", result);
|
|
79
|
-
// } catch (e) {
|
|
80
|
-
// console.log(e);
|
|
81
|
-
// }
|
|
82
|
-
// expect(result).not.toBe(null);
|
|
83
|
-
// });
|
|
84
|
-
|
|
85
|
-
// it("lends 1 USDC into Aave lending pool", async () => {
|
|
86
|
-
// let result;
|
|
87
|
-
// const pool = await dhedge.loadPool(myPool);
|
|
88
|
-
// try {
|
|
89
|
-
// result = await pool.lend(Dapp.AAVE, weth, "86567951006165", options);
|
|
90
|
-
// console.log(result);
|
|
91
|
-
// } catch (e) {
|
|
92
|
-
// console.log(e);
|
|
93
|
-
// }
|
|
94
|
-
// expect(result).not.toBe(null);
|
|
95
|
-
// });
|
|
96
|
-
|
|
97
|
-
// it("withdraws 1 USDC from Aave lending pool", async () => {
|
|
98
|
-
// let result;
|
|
99
|
-
// const pool = await dhedge.loadPool(myPool);
|
|
100
|
-
// try {
|
|
101
|
-
// result = await pool.withdrawDeposit(
|
|
102
|
-
// Dapp.AAVE,
|
|
103
|
-
// weth,
|
|
104
|
-
// "86567951006165",
|
|
105
|
-
// options
|
|
106
|
-
// );
|
|
107
|
-
// console.log(result);
|
|
108
|
-
// } catch (e) {
|
|
109
|
-
// console.log(e);
|
|
110
|
-
// }
|
|
111
|
-
// expect(result).not.toBe(null);
|
|
112
|
-
// });
|
|
113
|
-
|
|
114
|
-
// it("borrows 0.0001 WETH from Aave lending pool", async () => {
|
|
115
|
-
// let result;
|
|
116
|
-
// const pool = await dhedge.loadPool(myPool);
|
|
117
|
-
// try {
|
|
118
|
-
// result = await pool.borrow(Dapp.AAVE, weth, "100000000000000");
|
|
119
|
-
// console.log(result);
|
|
120
|
-
// } catch (e) {
|
|
121
|
-
// console.log(e);
|
|
122
|
-
// }
|
|
123
|
-
// expect(result).not.toBe(null);
|
|
124
|
-
// });
|
|
125
|
-
|
|
126
|
-
// it("reapys 0.0001 WETH to Aave lending pool", async () => {
|
|
127
|
-
// let result;
|
|
128
|
-
// const pool = await dhedge.loadPool(myPool);
|
|
129
|
-
// try {
|
|
130
|
-
// result = await pool.repay(Dapp.AAVE, weth, "100000000000000", options);
|
|
131
|
-
// console.log(result);
|
|
132
|
-
// } catch (e) {
|
|
133
|
-
// console.log(e);
|
|
134
|
-
// }
|
|
135
|
-
// expect(result).not.toBe(null);
|
|
136
|
-
// });
|
|
137
|
-
|
|
138
|
-
// it("trades 1 FRAX into WETH on quickswap", async () => {
|
|
139
|
-
// let result;
|
|
140
|
-
// const pool = await dhedge.loadPool(myPool);
|
|
141
|
-
// try {
|
|
142
|
-
// result = await pool.trade(
|
|
143
|
-
// Dapp.ONEINCH,
|
|
144
|
-
// usdc,
|
|
145
|
-
// weth,
|
|
146
|
-
// "300000",
|
|
147
|
-
// 0.5,
|
|
148
|
-
// options
|
|
149
|
-
// );
|
|
150
|
-
// console.log(result);
|
|
151
|
-
// } catch (e) {
|
|
152
|
-
// console.log(e);
|
|
153
|
-
// }
|
|
154
|
-
// expect(result).not.toBe(null);
|
|
155
32
|
// });
|
|
156
33
|
|
|
157
34
|
// it("approve USDC balance of User for Deposit", async () => {
|
|
@@ -211,114 +88,6 @@ describe("pool", () => {
|
|
|
211
88
|
// expect(result).not.toBe(null);
|
|
212
89
|
// });
|
|
213
90
|
|
|
214
|
-
// it("adds Liquidity into a WETH/USDT pool on sushi", async () => {
|
|
215
|
-
// let result;
|
|
216
|
-
// const pool = await dhedge.loadPool(myPool);
|
|
217
|
-
// const liquidityAmountWETH = await dhedge.utils.getLpAmount(
|
|
218
|
-
// Dapp.SUSHISWAP,
|
|
219
|
-
// usdt,
|
|
220
|
-
// weth,
|
|
221
|
-
// liquidityAmountUsdt
|
|
222
|
-
// );
|
|
223
|
-
// try {
|
|
224
|
-
// result = await pool.addLiquidity(
|
|
225
|
-
// Dapp.SUSHISWAP,
|
|
226
|
-
// usdt,
|
|
227
|
-
// weth,
|
|
228
|
-
// liquidityAmountUsdt,
|
|
229
|
-
// liquidityAmountWETH
|
|
230
|
-
// );
|
|
231
|
-
// } catch (e) {
|
|
232
|
-
// console.log(e);
|
|
233
|
-
// }
|
|
234
|
-
// expect(result).not.toBe(null);
|
|
235
|
-
// });
|
|
236
|
-
|
|
237
|
-
// it("approves unlimited LP USDC/WETH on sushiswap for staking", async () => {
|
|
238
|
-
// let result;
|
|
239
|
-
// const pool = await dhedge.loadPool(myPool);
|
|
240
|
-
// try {
|
|
241
|
-
// result = await pool.approveStaking(
|
|
242
|
-
// Dapp.SUSHISWAP,
|
|
243
|
-
// lpUsdcDai,
|
|
244
|
-
// ethers.constants.MaxUint256
|
|
245
|
-
// );
|
|
246
|
-
// } catch (e) {
|
|
247
|
-
// console.log(e);
|
|
248
|
-
// }
|
|
249
|
-
// expect(result).not.toBe(null);
|
|
250
|
-
// });
|
|
251
|
-
|
|
252
|
-
// it("deposit 0.1 USDC into Pool", async () => {
|
|
253
|
-
// let result;
|
|
254
|
-
// const pool = await dhedge.loadPool(myPool);
|
|
255
|
-
// try {
|
|
256
|
-
// result = await pool.deposit(usdc, depositAmountUsdc);
|
|
257
|
-
// } catch (e) {
|
|
258
|
-
// console.log(e);
|
|
259
|
-
// }
|
|
260
|
-
// expect(result).not.toBe(null);
|
|
261
|
-
// });
|
|
262
|
-
|
|
263
|
-
// it("adds LpUSDCWETH to enabled assets", async () => {
|
|
264
|
-
// let result;
|
|
265
|
-
// const pool = await dhedge.loadPool(myPool);
|
|
266
|
-
// const newAssets: AssetEnabled[] = [
|
|
267
|
-
// { asset: usdc, isDeposit: true },
|
|
268
|
-
// { asset: weth, isDeposit: true },
|
|
269
|
-
// { asset: usdt, isDeposit: true },
|
|
270
|
-
// { asset: lpUsdcWeth, isDeposit: false }
|
|
271
|
-
// ];
|
|
272
|
-
// try {
|
|
273
|
-
// result = await pool.changeAssets(newAssets);
|
|
274
|
-
// console.log(result);
|
|
275
|
-
// } catch (e) {
|
|
276
|
-
// console.log(e);
|
|
277
|
-
// }
|
|
278
|
-
// expect(result).not.toBe(null);
|
|
279
|
-
// });
|
|
280
|
-
|
|
281
|
-
// it("unStakes USDC/DAI LP on sushi", async () => {
|
|
282
|
-
// let result;
|
|
283
|
-
// const pool = await dhedge.loadPool(myPool);
|
|
284
|
-
// const balance = "11013356749811";
|
|
285
|
-
// try {
|
|
286
|
-
// result = await pool.unStake(Dapp.SUSHISWAP, lpUsdcDai, balance);
|
|
287
|
-
// console.log(result);
|
|
288
|
-
// } catch (e) {
|
|
289
|
-
// console.log(e);
|
|
290
|
-
// }
|
|
291
|
-
// expect(result).not.toBe(null);
|
|
292
|
-
// });
|
|
293
|
-
|
|
294
|
-
// it("trades entire sushi balance into usdc", async () => {
|
|
295
|
-
// let result: FundComposition[] = [];
|
|
296
|
-
// let tx;
|
|
297
|
-
// const pool = await dhedge.loadPool(myPool);
|
|
298
|
-
// try {
|
|
299
|
-
// result = await pool.getComposition();
|
|
300
|
-
// const sushiBalance = result.find(e => e.asset === sushi)?.balance;
|
|
301
|
-
// if (sushiBalance) {
|
|
302
|
-
// tx = await pool.trade(Dapp.SUSHISWAP, sushi, usdc, sushiBalance);
|
|
303
|
-
// console.log(tx);
|
|
304
|
-
// }
|
|
305
|
-
// } catch (e) {
|
|
306
|
-
// console.log(e);
|
|
307
|
-
// }
|
|
308
|
-
// expect(result.length).toBeGreaterThan(0);
|
|
309
|
-
// });
|
|
310
|
-
|
|
311
|
-
// it("harvests USDC/DAI LP Farm on sushi", async () => {
|
|
312
|
-
// let result;
|
|
313
|
-
// const pool = await dhedge.loadPool(myPool);
|
|
314
|
-
// try {
|
|
315
|
-
// result = await pool.harvestRewards(Dapp.SUSHISWAP, lpUsdcdai);
|
|
316
|
-
// } catch (e) {
|
|
317
|
-
// console.log(e);
|
|
318
|
-
// }
|
|
319
|
-
// expect(result).not.toBe(null);
|
|
320
|
-
// });
|
|
321
|
-
|
|
322
91
|
// it("sets a trader account", async () => {
|
|
323
92
|
// let result;
|
|
324
93
|
// const newTrader = "0xC52D9a9D9b05a01887871216fF02bA4235e8503d";
|
|
@@ -331,17 +100,4 @@ describe("pool", () => {
|
|
|
331
100
|
// }
|
|
332
101
|
// expect(result).not.toBe(null);
|
|
333
102
|
// });
|
|
334
|
-
|
|
335
|
-
// it("removes liquidity from USDC/DAI LP on sushi", async () => {
|
|
336
|
-
// let result;
|
|
337
|
-
// const pool = await dhedge.loadPool(myPool);
|
|
338
|
-
// const balance = "11013356749811";
|
|
339
|
-
// try {
|
|
340
|
-
// result = await pool.removeLiquidity(Dapp.SUSHISWAP, usdc, dai, balance);
|
|
341
|
-
// console.log(result);
|
|
342
|
-
// } catch (e) {
|
|
343
|
-
// console.log(e);
|
|
344
|
-
// }
|
|
345
|
-
// expect(result).not.toBe(null);
|
|
346
|
-
// });
|
|
347
103
|
});
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { Dhedge } from "..";
|
|
2
|
+
import { Dapp, Network } from "../types";
|
|
3
|
+
|
|
4
|
+
import { wallet } from "./wallet";
|
|
5
|
+
|
|
6
|
+
import { BAL, TEST_POOL, USDT } from "./constants";
|
|
7
|
+
|
|
8
|
+
const myPool = "0x3e5f7e9e7dc3bc3086ccebd5eb59a0a4a29d881b";
|
|
9
|
+
// const weth = "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619";
|
|
10
|
+
// //const usdt = "0xc2132D05D31c914a87C6611C10748AEb04B58e8F";
|
|
11
|
+
// //const dai = "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063";
|
|
12
|
+
// const usdc = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174";
|
|
13
|
+
// const wbtc = "0x1bfd67037b42cf73acf2047067bd4f2c47d9bfd6";
|
|
14
|
+
//const sushi = "0x0b3F868E0BE5597D5DB7fEB59E1CADBb0fdDa50a";
|
|
15
|
+
// const wmatic = "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270";
|
|
16
|
+
// const lpUsdcWeth = "0x34965ba0ac2451A34a0471F04CCa3F990b8dea27";
|
|
17
|
+
//const lpUsdcDai = "0xCD578F016888B57F1b1e3f887f392F0159E26747";
|
|
18
|
+
//const amusdc = "0x1a13F4Ca1d028320A707D99520AbFefca3998b7F";
|
|
19
|
+
//const lpUsdcUsdt = "0x4b1f1e2435a9c96f7330faea190ef6a7c8d70001";
|
|
20
|
+
// const tradeAmountUsdc = "1000000";
|
|
21
|
+
// const liquidityAmountUsdt = "1000000";
|
|
22
|
+
// const lpUsdcWETHAmount = "10951027354";
|
|
23
|
+
// const depositAmountUsdc = "100000";
|
|
24
|
+
|
|
25
|
+
let dhedge: Dhedge;
|
|
26
|
+
|
|
27
|
+
jest.setTimeout(100000);
|
|
28
|
+
|
|
29
|
+
// const options = {
|
|
30
|
+
// gasLimit: 5000000,
|
|
31
|
+
// gasPrice: ethers.utils.parseUnits("35", "gwei")
|
|
32
|
+
// };
|
|
33
|
+
|
|
34
|
+
describe("pool", () => {
|
|
35
|
+
beforeAll(() => {
|
|
36
|
+
dhedge = new Dhedge(wallet, Network.POLYGON);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("adds Liquidity into a WETH/USDT pool on sushi", async () => {
|
|
40
|
+
let result;
|
|
41
|
+
const pool = await dhedge.loadPool(myPool);
|
|
42
|
+
const liquidityAmountWETH = await dhedge.utils.getLpAmount(
|
|
43
|
+
Dapp.SUSHISWAP,
|
|
44
|
+
USDT,
|
|
45
|
+
WETH,
|
|
46
|
+
liquidityAmountUsdt
|
|
47
|
+
);
|
|
48
|
+
try {
|
|
49
|
+
result = await pool.addLiquidity(
|
|
50
|
+
Dapp.SUSHISWAP,
|
|
51
|
+
usdt,
|
|
52
|
+
weth,
|
|
53
|
+
liquidityAmountUsdt,
|
|
54
|
+
liquidityAmountWETH
|
|
55
|
+
);
|
|
56
|
+
} catch (e) {
|
|
57
|
+
console.log(e);
|
|
58
|
+
}
|
|
59
|
+
expect(result).not.toBe(null);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// it("approves unlimited LP USDC/WETH on sushiswap for staking", async () => {
|
|
63
|
+
// let result;
|
|
64
|
+
// const pool = await dhedge.loadPool(myPool);
|
|
65
|
+
// try {
|
|
66
|
+
// result = await pool.approveStaking(
|
|
67
|
+
// Dapp.SUSHISWAP,
|
|
68
|
+
// lpUsdcDai,
|
|
69
|
+
// ethers.constants.MaxUint256
|
|
70
|
+
// );
|
|
71
|
+
// } catch (e) {
|
|
72
|
+
// console.log(e);
|
|
73
|
+
// }
|
|
74
|
+
// expect(result).not.toBe(null);
|
|
75
|
+
// });
|
|
76
|
+
|
|
77
|
+
// it("deposit 0.1 USDC into Pool", async () => {
|
|
78
|
+
// let result;
|
|
79
|
+
// const pool = await dhedge.loadPool(myPool);
|
|
80
|
+
// try {
|
|
81
|
+
// result = await pool.deposit(usdc, depositAmountUsdc);
|
|
82
|
+
// } catch (e) {
|
|
83
|
+
// console.log(e);
|
|
84
|
+
// }
|
|
85
|
+
// expect(result).not.toBe(null);
|
|
86
|
+
// });
|
|
87
|
+
|
|
88
|
+
// it("adds LpUSDCWETH to enabled assets", async () => {
|
|
89
|
+
// let result;
|
|
90
|
+
// const pool = await dhedge.loadPool(myPool);
|
|
91
|
+
// const newAssets: AssetEnabled[] = [
|
|
92
|
+
// { asset: usdc, isDeposit: true },
|
|
93
|
+
// { asset: weth, isDeposit: true },
|
|
94
|
+
// { asset: usdt, isDeposit: true },
|
|
95
|
+
// { asset: lpUsdcWeth, isDeposit: false }
|
|
96
|
+
// ];
|
|
97
|
+
// try {
|
|
98
|
+
// result = await pool.changeAssets(newAssets);
|
|
99
|
+
// console.log(result);
|
|
100
|
+
// } catch (e) {
|
|
101
|
+
// console.log(e);
|
|
102
|
+
// }
|
|
103
|
+
// expect(result).not.toBe(null);
|
|
104
|
+
// });
|
|
105
|
+
|
|
106
|
+
// it("unStakes USDC/DAI LP on sushi", async () => {
|
|
107
|
+
// let result;
|
|
108
|
+
// const pool = await dhedge.loadPool(myPool);
|
|
109
|
+
// const balance = "11013356749811";
|
|
110
|
+
// try {
|
|
111
|
+
// result = await pool.unStake(Dapp.SUSHISWAP, lpUsdcDai, balance);
|
|
112
|
+
// console.log(result);
|
|
113
|
+
// } catch (e) {
|
|
114
|
+
// console.log(e);
|
|
115
|
+
// }
|
|
116
|
+
// expect(result).not.toBe(null);
|
|
117
|
+
// });
|
|
118
|
+
|
|
119
|
+
// it("trades entire sushi balance into usdc", async () => {
|
|
120
|
+
// let result: FundComposition[] = [];
|
|
121
|
+
// let tx;
|
|
122
|
+
// const pool = await dhedge.loadPool(myPool);
|
|
123
|
+
// try {
|
|
124
|
+
// result = await pool.getComposition();
|
|
125
|
+
// const sushiBalance = result.find(e => e.asset === sushi)?.balance;
|
|
126
|
+
// if (sushiBalance) {
|
|
127
|
+
// tx = await pool.trade(Dapp.SUSHISWAP, sushi, usdc, sushiBalance);
|
|
128
|
+
// console.log(tx);
|
|
129
|
+
// }
|
|
130
|
+
// } catch (e) {
|
|
131
|
+
// console.log(e);
|
|
132
|
+
// }
|
|
133
|
+
// expect(result.length).toBeGreaterThan(0);
|
|
134
|
+
// });
|
|
135
|
+
|
|
136
|
+
// it("harvests USDC/DAI LP Farm on sushi", async () => {
|
|
137
|
+
// let result;
|
|
138
|
+
// const pool = await dhedge.loadPool(myPool);
|
|
139
|
+
// try {
|
|
140
|
+
// result = await pool.harvestRewards(Dapp.SUSHISWAP, lpUsdcdai);
|
|
141
|
+
// } catch (e) {
|
|
142
|
+
// console.log(e);
|
|
143
|
+
// }
|
|
144
|
+
// expect(result).not.toBe(null);
|
|
145
|
+
// });
|
|
146
|
+
|
|
147
|
+
// it("sets a trader account", async () => {
|
|
148
|
+
// let result;
|
|
149
|
+
// const newTrader = "0xC52D9a9D9b05a01887871216fF02bA4235e8503d";
|
|
150
|
+
// const pool = await dhedge.loadPool(myPool);
|
|
151
|
+
// try {
|
|
152
|
+
// result = await pool.setTrader(newTrader);
|
|
153
|
+
// console.log(result);
|
|
154
|
+
// } catch (e) {
|
|
155
|
+
// console.log(e);
|
|
156
|
+
// }
|
|
157
|
+
// expect(result).not.toBe(null);
|
|
158
|
+
// });
|
|
159
|
+
|
|
160
|
+
// it("removes liquidity from USDC/DAI LP on sushi", async () => {
|
|
161
|
+
// let result;
|
|
162
|
+
// const pool = await dhedge.loadPool(myPool);
|
|
163
|
+
// const balance = "11013356749811";
|
|
164
|
+
// try {
|
|
165
|
+
// result = await pool.removeLiquidity(Dapp.SUSHISWAP, usdc, dai, balance);
|
|
166
|
+
// console.log(result);
|
|
167
|
+
// } catch (e) {
|
|
168
|
+
// console.log(e);
|
|
169
|
+
// }
|
|
170
|
+
// expect(result).not.toBe(null);
|
|
171
|
+
// });
|
|
172
|
+
|
|
173
|
+
});
|
package/src/test/utils.test.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
+
//import { ethers } from "ethers";
|
|
1
2
|
import { Dhedge } from "..";
|
|
2
|
-
import {
|
|
3
|
+
import { Network } from "../types";
|
|
3
4
|
|
|
4
5
|
import { wallet } from "./wallet";
|
|
5
6
|
|
|
6
|
-
const myPool = "
|
|
7
|
+
const myPool = "0xe3528a438b94e64669def9b875c381c46ef713bf";
|
|
7
8
|
|
|
8
|
-
const usdt = "0xc2132D05D31c914a87C6611C10748AEb04B58e8F";
|
|
9
|
+
// const usdt = "0xc2132D05D31c914a87C6611C10748AEb04B58e8F";
|
|
9
10
|
const usdc = "0x2791bca1f2de4661ed88a30c99a7a9449aa84174";
|
|
10
11
|
const weth = "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619";
|
|
11
|
-
const
|
|
12
|
+
const wbtc = "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6";
|
|
13
|
+
// const lpUsdcWeth = "0x34965ba0ac2451A34a0471F04CCa3F990b8dea27";
|
|
12
14
|
|
|
13
15
|
let dhedge: Dhedge;
|
|
14
16
|
|
|
@@ -19,28 +21,41 @@ describe("utils", () => {
|
|
|
19
21
|
dhedge = new Dhedge(wallet, Network.POLYGON);
|
|
20
22
|
});
|
|
21
23
|
|
|
22
|
-
it("gets lp ratio of the USDT/USDC pool", async () => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it("gets pool id of sushi LP pool for USDC/WETH", async () => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it("gets USDC balance of a pool", async () => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
});
|
|
36
|
-
it("gets minumum amount out of WETH for 1 USDC", async () => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
24
|
+
// it("gets lp ratio of the USDT/USDC pool", async () => {
|
|
25
|
+
// const result = await dhedge.utils.getLpReserves(Dapp.SUSHISWAP, usdc, usdt);
|
|
26
|
+
// expect(Number(result.assetA) / Number(result.assetB)).toBeGreaterThan(0.9);
|
|
27
|
+
// });
|
|
28
|
+
|
|
29
|
+
// it("gets pool id of sushi LP pool for USDC/WETH", async () => {
|
|
30
|
+
// const result = await dhedge.utils.getLpPoolId(Dapp.SUSHISWAP, lpUsdcWeth);
|
|
31
|
+
// expect(result).toBe(1);
|
|
32
|
+
// });
|
|
33
|
+
|
|
34
|
+
// it("gets USDC balance of a pool", async () => {
|
|
35
|
+
// const result = await dhedge.utils.getBalance(usdc, myPool);
|
|
36
|
+
// expect(result.gt(0));
|
|
37
|
+
// });
|
|
38
|
+
// it("gets minumum amount out of WETH for 1 USDC", async () => {
|
|
39
|
+
// const result = await dhedge.utils.getMinAmountOut(
|
|
40
|
+
// Dapp.SUSHISWAP,
|
|
41
|
+
// usdc,
|
|
42
|
+
// weth,
|
|
43
|
+
// "1000000",
|
|
44
|
+
// 0.5
|
|
45
|
+
// );
|
|
46
|
+
// expect(result.gt(0));
|
|
47
|
+
// });
|
|
48
|
+
|
|
49
|
+
it("gets Balancer pool tx data", async () => {
|
|
50
|
+
const pool = await dhedge.loadPool(myPool);
|
|
51
|
+
const assets = [wbtc, usdc, weth];
|
|
52
|
+
const amounts = ["0", "1000000", "0"];
|
|
53
|
+
const result = await dhedge.utils.getBalancerJoinPoolTx(
|
|
54
|
+
pool,
|
|
55
|
+
"0x03cd191f589d12b0582a99808cf19851e468e6b500010000000000000000000a",
|
|
56
|
+
assets,
|
|
57
|
+
amounts
|
|
43
58
|
);
|
|
44
|
-
expect(result
|
|
59
|
+
expect(result);
|
|
45
60
|
});
|
|
46
61
|
});
|
package/src/types.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { ChainId } from "@sushiswap/sdk";
|
|
|
2
2
|
import { BigNumber } from "ethers";
|
|
3
3
|
|
|
4
4
|
export enum Network {
|
|
5
|
-
POLYGON = "polygon"
|
|
5
|
+
POLYGON = "polygon"
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
export enum Dapp {
|
|
@@ -10,6 +10,7 @@ export enum Dapp {
|
|
|
10
10
|
AAVE = "aave",
|
|
11
11
|
ONEINCH = "1inch",
|
|
12
12
|
QUICKSWAP = "quickswap",
|
|
13
|
+
BALANCER = "balancer"
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
export enum Transaction {
|
|
@@ -17,11 +18,12 @@ export enum Transaction {
|
|
|
17
18
|
ADD_LIQUIDITY = "addLiquidity",
|
|
18
19
|
DEPOSIT = "deposit",
|
|
19
20
|
HARVEST = "harvest",
|
|
20
|
-
|
|
21
|
+
CLAIM_DISTRIBIUTIONS = "claimDistributions",
|
|
22
|
+
CLAIM_REWARDS = "claimRewards",
|
|
21
23
|
REMOVE_LIQUIDITY = "removeLiquidity",
|
|
22
24
|
BORROW = "borrow",
|
|
23
25
|
REPAY = "repay",
|
|
24
|
-
WITHDRAW = "withdraw"
|
|
26
|
+
WITHDRAW = "withdraw"
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
export type AddressNetworkMap = Readonly<Record<Network, string>>;
|
|
@@ -31,6 +33,7 @@ export type AddressDappMap = {
|
|
|
31
33
|
[Dapp.AAVE]?: string;
|
|
32
34
|
[Dapp.ONEINCH]?: string;
|
|
33
35
|
[Dapp.QUICKSWAP]?: string;
|
|
36
|
+
[Dapp.BALANCER]?: string;
|
|
34
37
|
};
|
|
35
38
|
|
|
36
39
|
export type AddressDappNetworkMap = Readonly<Record<Network, AddressDappMap>>;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
import set from "lodash/set";
|
|
4
|
+
import { Interface } from "@ethersproject/abi";
|
|
5
|
+
import { multiCallAddress } from "../config";
|
|
6
|
+
import { ethers, Network } from "..";
|
|
7
|
+
|
|
8
|
+
export async function call(
|
|
9
|
+
provider: ethers.Signer,
|
|
10
|
+
abi: any[],
|
|
11
|
+
call: any[],
|
|
12
|
+
options?: any
|
|
13
|
+
) {
|
|
14
|
+
const contract = new ethers.Contract(call[0], abi, provider);
|
|
15
|
+
try {
|
|
16
|
+
const params = call[2] || [];
|
|
17
|
+
return await contract[call[1]](...params, options || {});
|
|
18
|
+
} catch (e) {
|
|
19
|
+
return Promise.reject(e);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function multicall<T>(
|
|
24
|
+
network: Network,
|
|
25
|
+
provider: ethers.Signer,
|
|
26
|
+
abi: any[],
|
|
27
|
+
calls: any[],
|
|
28
|
+
options: any = {},
|
|
29
|
+
requireSuccess = false
|
|
30
|
+
): Promise<(T | null)[]> {
|
|
31
|
+
const multi = new ethers.Contract(
|
|
32
|
+
multiCallAddress[network],
|
|
33
|
+
[
|
|
34
|
+
"function tryAggregate(bool requireSuccess, tuple(address, bytes)[] memory calls) public view returns (tuple(bool, bytes)[] memory returnData)"
|
|
35
|
+
],
|
|
36
|
+
provider
|
|
37
|
+
);
|
|
38
|
+
const itf = new Interface(abi);
|
|
39
|
+
try {
|
|
40
|
+
const res: [boolean, string][] = await multi.tryAggregate(
|
|
41
|
+
// if false, allows individual calls to fail without causing entire multicall to fail
|
|
42
|
+
requireSuccess,
|
|
43
|
+
calls.map(call => [
|
|
44
|
+
call[0].toLowerCase(),
|
|
45
|
+
itf.encodeFunctionData(call[1], call[2])
|
|
46
|
+
]),
|
|
47
|
+
options
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
return res.map(([success, returnData], i) => {
|
|
51
|
+
if (!success) return null;
|
|
52
|
+
const decodedResult = itf.decodeFunctionResult(calls[i][1], returnData);
|
|
53
|
+
// Automatically unwrap any simple return values
|
|
54
|
+
return decodedResult.length > 1 ? decodedResult : decodedResult[0];
|
|
55
|
+
});
|
|
56
|
+
} catch (e) {
|
|
57
|
+
return Promise.reject(e);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export class Multicaller {
|
|
62
|
+
public network: Network;
|
|
63
|
+
public provider: ethers.Signer;
|
|
64
|
+
public abi: any[];
|
|
65
|
+
public options: any = {};
|
|
66
|
+
public calls: any[] = [];
|
|
67
|
+
public paths: any[] = [];
|
|
68
|
+
|
|
69
|
+
constructor(network: Network, provider: ethers.Signer, abi: any[]) {
|
|
70
|
+
this.network = network;
|
|
71
|
+
this.provider = provider;
|
|
72
|
+
this.abi = abi;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
call(path: any, address: any, fn: any, params?: any): Multicaller {
|
|
76
|
+
this.calls.push([address, fn, params]);
|
|
77
|
+
this.paths.push(path);
|
|
78
|
+
return this;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async execute(from?: any): Promise<any> {
|
|
82
|
+
const obj = from || {};
|
|
83
|
+
const result = await multicall(
|
|
84
|
+
this.network,
|
|
85
|
+
this.provider,
|
|
86
|
+
this.abi,
|
|
87
|
+
this.calls,
|
|
88
|
+
this.options
|
|
89
|
+
);
|
|
90
|
+
result.forEach((r, i) => set(obj, this.paths[i], r));
|
|
91
|
+
this.calls = [];
|
|
92
|
+
this.paths = [];
|
|
93
|
+
return obj;
|
|
94
|
+
}
|
|
95
|
+
}
|