@dhedge/v2-sdk 1.1.0 → 1.2.1
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 +37 -3
- package/dist/entities/utils.d.ts +4 -0
- package/dist/services/claim-balancer/claim.service.d.ts +17 -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 +3497 -690
- 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 +3497 -690
- 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 +21 -4
- package/src/entities/pool.ts +148 -5
- package/src/entities/utils.ts +135 -0
- package/src/services/claim-balancer/MultiTokenClaim.json +115 -0
- package/src/services/claim-balancer/claim.service.ts +262 -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 -244
- 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,118 +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 WETH on Quickswap", async () => {
|
|
50
|
-
// let result;
|
|
51
|
-
// const pool = await dhedge.loadPool(myPool);
|
|
52
|
-
// try {
|
|
53
|
-
// result = await pool.approve(Dapp.AAVE, weth, ethers.constants.MaxInt256);
|
|
54
|
-
// console.log(result);
|
|
55
|
-
// } catch (e) {
|
|
56
|
-
// console.log(e);
|
|
57
|
-
// }
|
|
58
|
-
// expect(result).not.toBe(null);
|
|
59
|
-
// });
|
|
60
|
-
|
|
61
|
-
// it("lends 1 USDC into Aave lending pool", async () => {
|
|
62
|
-
// let result;
|
|
63
|
-
// const pool = await dhedge.loadPool(myPool);
|
|
64
|
-
// try {
|
|
65
|
-
// result = await pool.lend(Dapp.AAVE, weth, "86567951006165", options);
|
|
66
|
-
// console.log(result);
|
|
67
|
-
// } catch (e) {
|
|
68
|
-
// console.log(e);
|
|
69
|
-
// }
|
|
70
|
-
// expect(result).not.toBe(null);
|
|
71
|
-
// });
|
|
72
|
-
|
|
73
|
-
// it("withdraws 1 USDC from Aave lending pool", async () => {
|
|
74
|
-
// let result;
|
|
75
|
-
// const pool = await dhedge.loadPool(myPool);
|
|
76
|
-
// try {
|
|
77
|
-
// result = await pool.withdrawDeposit(
|
|
78
|
-
// Dapp.AAVE,
|
|
79
|
-
// weth,
|
|
80
|
-
// "86567951006165",
|
|
81
|
-
// options
|
|
82
|
-
// );
|
|
83
|
-
// console.log(result);
|
|
84
|
-
// } catch (e) {
|
|
85
|
-
// console.log(e);
|
|
86
|
-
// }
|
|
87
|
-
// expect(result).not.toBe(null);
|
|
88
|
-
// });
|
|
89
|
-
|
|
90
|
-
// it("borrows 0.0001 WETH from Aave lending pool", async () => {
|
|
91
|
-
// let result;
|
|
92
|
-
// const pool = await dhedge.loadPool(myPool);
|
|
93
|
-
// try {
|
|
94
|
-
// result = await pool.borrow(Dapp.AAVE, weth, "100000000000000");
|
|
95
|
-
// console.log(result);
|
|
96
|
-
// } catch (e) {
|
|
97
|
-
// console.log(e);
|
|
98
|
-
// }
|
|
99
|
-
// expect(result).not.toBe(null);
|
|
100
|
-
// });
|
|
101
|
-
|
|
102
|
-
// it("reapys 0.0001 WETH to Aave lending pool", async () => {
|
|
103
|
-
// let result;
|
|
104
|
-
// const pool = await dhedge.loadPool(myPool);
|
|
105
|
-
// try {
|
|
106
|
-
// result = await pool.repay(Dapp.AAVE, weth, "100000000000000", options);
|
|
107
|
-
// console.log(result);
|
|
108
|
-
// } catch (e) {
|
|
109
|
-
// console.log(e);
|
|
110
|
-
// }
|
|
111
|
-
// expect(result).not.toBe(null);
|
|
112
|
-
// });
|
|
113
|
-
|
|
114
|
-
// it("trades 1 FRAX into WETH on quickswap", async () => {
|
|
115
|
-
// let result;
|
|
116
|
-
// const pool = await dhedge.loadPool(myPool);
|
|
117
|
-
// try {
|
|
118
|
-
// result = await pool.trade(
|
|
119
|
-
// Dapp.ONEINCH,
|
|
120
|
-
// usdc,
|
|
121
|
-
// weth,
|
|
122
|
-
// "300000",
|
|
123
|
-
// 0.5,
|
|
124
|
-
// options
|
|
125
|
-
// );
|
|
126
|
-
// console.log(result);
|
|
127
|
-
// } catch (e) {
|
|
128
|
-
// console.log(e);
|
|
129
|
-
// }
|
|
130
|
-
// expect(result).not.toBe(null);
|
|
131
|
-
// });
|
|
132
|
-
|
|
133
|
-
// it("trades 0.1 USDC into WETH on Sushi", async () => {
|
|
134
|
-
// let result;
|
|
135
|
-
// const pool = await dhedge.loadPool(myPool);
|
|
136
|
-
// try {
|
|
137
|
-
// result = await pool.trade(
|
|
138
|
-
// Dapp.SUSHISWAP,
|
|
139
|
-
// usdc,
|
|
140
|
-
// frax,
|
|
141
|
-
// "500000",
|
|
142
|
-
// 0.5,
|
|
143
|
-
// options
|
|
144
|
-
// );
|
|
145
|
-
// console.log("sushi", result);
|
|
146
|
-
// } catch (e) {
|
|
147
|
-
// console.log(e);
|
|
148
|
-
// }
|
|
149
|
-
// expect(result).not.toBe(null);
|
|
150
32
|
// });
|
|
151
33
|
|
|
152
34
|
// it("approve USDC balance of User for Deposit", async () => {
|
|
@@ -206,114 +88,6 @@ describe("pool", () => {
|
|
|
206
88
|
// expect(result).not.toBe(null);
|
|
207
89
|
// });
|
|
208
90
|
|
|
209
|
-
// it("adds Liquidity into a WETH/USDT pool on sushi", async () => {
|
|
210
|
-
// let result;
|
|
211
|
-
// const pool = await dhedge.loadPool(myPool);
|
|
212
|
-
// const liquidityAmountWETH = await dhedge.utils.getLpAmount(
|
|
213
|
-
// Dapp.SUSHISWAP,
|
|
214
|
-
// usdt,
|
|
215
|
-
// weth,
|
|
216
|
-
// liquidityAmountUsdt
|
|
217
|
-
// );
|
|
218
|
-
// try {
|
|
219
|
-
// result = await pool.addLiquidity(
|
|
220
|
-
// Dapp.SUSHISWAP,
|
|
221
|
-
// usdt,
|
|
222
|
-
// weth,
|
|
223
|
-
// liquidityAmountUsdt,
|
|
224
|
-
// liquidityAmountWETH
|
|
225
|
-
// );
|
|
226
|
-
// } catch (e) {
|
|
227
|
-
// console.log(e);
|
|
228
|
-
// }
|
|
229
|
-
// expect(result).not.toBe(null);
|
|
230
|
-
// });
|
|
231
|
-
|
|
232
|
-
// it("approves unlimited LP USDC/WETH on sushiswap for staking", async () => {
|
|
233
|
-
// let result;
|
|
234
|
-
// const pool = await dhedge.loadPool(myPool);
|
|
235
|
-
// try {
|
|
236
|
-
// result = await pool.approveStaking(
|
|
237
|
-
// Dapp.SUSHISWAP,
|
|
238
|
-
// lpUsdcDai,
|
|
239
|
-
// ethers.constants.MaxUint256
|
|
240
|
-
// );
|
|
241
|
-
// } catch (e) {
|
|
242
|
-
// console.log(e);
|
|
243
|
-
// }
|
|
244
|
-
// expect(result).not.toBe(null);
|
|
245
|
-
// });
|
|
246
|
-
|
|
247
|
-
// it("deposit 0.1 USDC into Pool", async () => {
|
|
248
|
-
// let result;
|
|
249
|
-
// const pool = await dhedge.loadPool(myPool);
|
|
250
|
-
// try {
|
|
251
|
-
// result = await pool.deposit(usdc, depositAmountUsdc);
|
|
252
|
-
// } catch (e) {
|
|
253
|
-
// console.log(e);
|
|
254
|
-
// }
|
|
255
|
-
// expect(result).not.toBe(null);
|
|
256
|
-
// });
|
|
257
|
-
|
|
258
|
-
// it("adds LpUSDCWETH to enabled assets", async () => {
|
|
259
|
-
// let result;
|
|
260
|
-
// const pool = await dhedge.loadPool(myPool);
|
|
261
|
-
// const newAssets: AssetEnabled[] = [
|
|
262
|
-
// { asset: usdc, isDeposit: true },
|
|
263
|
-
// { asset: weth, isDeposit: true },
|
|
264
|
-
// { asset: usdt, isDeposit: true },
|
|
265
|
-
// { asset: lpUsdcWeth, isDeposit: false }
|
|
266
|
-
// ];
|
|
267
|
-
// try {
|
|
268
|
-
// result = await pool.changeAssets(newAssets);
|
|
269
|
-
// console.log(result);
|
|
270
|
-
// } catch (e) {
|
|
271
|
-
// console.log(e);
|
|
272
|
-
// }
|
|
273
|
-
// expect(result).not.toBe(null);
|
|
274
|
-
// });
|
|
275
|
-
|
|
276
|
-
// it("unStakes USDC/DAI LP on sushi", async () => {
|
|
277
|
-
// let result;
|
|
278
|
-
// const pool = await dhedge.loadPool(myPool);
|
|
279
|
-
// const balance = "11013356749811";
|
|
280
|
-
// try {
|
|
281
|
-
// result = await pool.unStake(Dapp.SUSHISWAP, lpUsdcDai, balance);
|
|
282
|
-
// console.log(result);
|
|
283
|
-
// } catch (e) {
|
|
284
|
-
// console.log(e);
|
|
285
|
-
// }
|
|
286
|
-
// expect(result).not.toBe(null);
|
|
287
|
-
// });
|
|
288
|
-
|
|
289
|
-
// it("trades entire sushi balance into usdc", async () => {
|
|
290
|
-
// let result: FundComposition[] = [];
|
|
291
|
-
// let tx;
|
|
292
|
-
// const pool = await dhedge.loadPool(myPool);
|
|
293
|
-
// try {
|
|
294
|
-
// result = await pool.getComposition();
|
|
295
|
-
// const sushiBalance = result.find(e => e.asset === sushi)?.balance;
|
|
296
|
-
// if (sushiBalance) {
|
|
297
|
-
// tx = await pool.trade(Dapp.SUSHISWAP, sushi, usdc, sushiBalance);
|
|
298
|
-
// console.log(tx);
|
|
299
|
-
// }
|
|
300
|
-
// } catch (e) {
|
|
301
|
-
// console.log(e);
|
|
302
|
-
// }
|
|
303
|
-
// expect(result.length).toBeGreaterThan(0);
|
|
304
|
-
// });
|
|
305
|
-
|
|
306
|
-
// it("harvests USDC/DAI LP Farm on sushi", async () => {
|
|
307
|
-
// let result;
|
|
308
|
-
// const pool = await dhedge.loadPool(myPool);
|
|
309
|
-
// try {
|
|
310
|
-
// result = await pool.harvestRewards(Dapp.SUSHISWAP, lpUsdcdai);
|
|
311
|
-
// } catch (e) {
|
|
312
|
-
// console.log(e);
|
|
313
|
-
// }
|
|
314
|
-
// expect(result).not.toBe(null);
|
|
315
|
-
// });
|
|
316
|
-
|
|
317
91
|
// it("sets a trader account", async () => {
|
|
318
92
|
// let result;
|
|
319
93
|
// const newTrader = "0xC52D9a9D9b05a01887871216fF02bA4235e8503d";
|
|
@@ -326,17 +100,4 @@ describe("pool", () => {
|
|
|
326
100
|
// }
|
|
327
101
|
// expect(result).not.toBe(null);
|
|
328
102
|
// });
|
|
329
|
-
|
|
330
|
-
// it("removes liquidity from USDC/DAI LP on sushi", async () => {
|
|
331
|
-
// let result;
|
|
332
|
-
// const pool = await dhedge.loadPool(myPool);
|
|
333
|
-
// const balance = "11013356749811";
|
|
334
|
-
// try {
|
|
335
|
-
// result = await pool.removeLiquidity(Dapp.SUSHISWAP, usdc, dai, balance);
|
|
336
|
-
// console.log(result);
|
|
337
|
-
// } catch (e) {
|
|
338
|
-
// console.log(e);
|
|
339
|
-
// }
|
|
340
|
-
// expect(result).not.toBe(null);
|
|
341
|
-
// });
|
|
342
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
|
+
}
|