@dhedge/v2-sdk 1.1.1 → 1.3.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 +7 -0
- package/dist/entities/pool.d.ts +101 -5
- package/dist/entities/utils.d.ts +10 -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/services/uniswap/V3Liquidity.d.ts +9 -0
- package/dist/services/uniswap/V3Trade.d.ts +4 -0
- package/dist/services/uniswap/types.d.ts +3 -0
- package/dist/test/constants.d.ts +12 -0
- package/dist/test/txOptions.d.ts +1 -0
- package/dist/types.d.ts +20 -6
- 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 +6086 -918
- 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 +6090 -922
- package/dist/v2-sdk.esm.js.map +1 -1
- package/package.json +12 -2
- package/src/abi/IAaveIncentivesController.json +50 -0
- package/src/abi/IBalancerMerkleOrchard.json +353 -0
- package/src/abi/IBalancertV2Vault.json +938 -0
- package/src/abi/IERC20.json +15 -1
- package/src/abi/INonfungiblePositionManager.json +1221 -0
- package/src/abi/ISynthetix.json +139 -0
- package/src/abi/IUniswapV3Quoter.json +195 -0
- package/src/abi/IUniswapV3Router.json +221 -0
- package/src/config.ts +48 -8
- package/src/entities/dhedge.ts +4 -2
- package/src/entities/pool.ts +398 -27
- package/src/entities/utils.ts +147 -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/services/uniswap/V3Liquidity.ts +134 -0
- package/src/services/uniswap/V3Trade.ts +47 -0
- package/src/services/uniswap/types.ts +16 -0
- package/src/test/aave.test.ts +73 -0
- package/src/test/balancer.test.ts +109 -0
- package/src/test/constants.ts +17 -0
- package/src/test/oneInch.test.ts +56 -0
- package/src/test/pool.test.ts +6 -250
- package/src/test/sushi.test.ts +173 -0
- package/src/test/synthetix.test.ts +34 -0
- package/src/test/txOptions.ts +15 -0
- package/src/test/uniswap.test.ts +127 -0
- package/src/test/utils.test.ts +41 -26
- package/src/test/wallet.ts +5 -1
- package/src/types.ts +17 -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,157 +1,34 @@
|
|
|
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
|
|
|
32
16
|
describe("pool", () => {
|
|
33
17
|
beforeAll(() => {
|
|
34
|
-
dhedge = new Dhedge(wallet, Network.
|
|
18
|
+
dhedge = new Dhedge(wallet, Network.OPTIMISM);
|
|
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
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { Dhedge } from "..";
|
|
3
|
+
import { Dapp, Network } from "../types";
|
|
4
|
+
import { TEST_POOL } from "./constants";
|
|
5
|
+
//import { getTxOptions } from "./txOptions";
|
|
6
|
+
|
|
7
|
+
import { wallet } from "./wallet";
|
|
8
|
+
|
|
9
|
+
let dhedge: Dhedge;
|
|
10
|
+
let options: any;
|
|
11
|
+
jest.setTimeout(100000);
|
|
12
|
+
|
|
13
|
+
describe("pool", () => {
|
|
14
|
+
beforeAll(async () => {
|
|
15
|
+
dhedge = new Dhedge(wallet, Network.OPTIMISM);
|
|
16
|
+
//options = await getTxOptions();
|
|
17
|
+
options = { gasLimit: "3000000" };
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("should swap sETH into sUSD on Synthetix", async () => {
|
|
21
|
+
const pool = await dhedge.loadPool(TEST_POOL);
|
|
22
|
+
const result = await pool.trade(
|
|
23
|
+
Dapp.SYNTHETIX,
|
|
24
|
+
"sETH",
|
|
25
|
+
"sUSD",
|
|
26
|
+
"1000000000000000",
|
|
27
|
+
undefined,
|
|
28
|
+
options
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
console.log(result);
|
|
32
|
+
expect(result).not.toBe(null);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import BigNumber from "bignumber.js";
|
|
3
|
+
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
|
+
export const getTxOptions = async (): Promise<any> => {
|
|
6
|
+
const result = await axios("https://gasstation-mainnet.matic.network/v2");
|
|
7
|
+
|
|
8
|
+
return {
|
|
9
|
+
gasLimit: "3000000",
|
|
10
|
+
maxPriorityFeePerGas: new BigNumber(result.data.fast.maxPriorityFee)
|
|
11
|
+
.shiftedBy(9)
|
|
12
|
+
.toFixed(0),
|
|
13
|
+
maxFeePerGas: new BigNumber(result.data.fast.maxFee).shiftedBy(9).toFixed(0)
|
|
14
|
+
};
|
|
15
|
+
};
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { FeeAmount } from "@uniswap/v3-sdk";
|
|
3
|
+
import { Dhedge } from "..";
|
|
4
|
+
import { Network } from "../types";
|
|
5
|
+
import { TEST_POOL, USDC, WETH } from "./constants";
|
|
6
|
+
//import { getTxOptions } from "./txOptions";
|
|
7
|
+
|
|
8
|
+
import { wallet } from "./wallet";
|
|
9
|
+
|
|
10
|
+
let dhedge: Dhedge;
|
|
11
|
+
let options: any;
|
|
12
|
+
jest.setTimeout(100000);
|
|
13
|
+
|
|
14
|
+
describe("pool", () => {
|
|
15
|
+
beforeAll(async () => {
|
|
16
|
+
dhedge = new Dhedge(wallet, Network.OPTIMISM);
|
|
17
|
+
//options = await getTxOptions();
|
|
18
|
+
options = { gasLimit: "3000000" };
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// it("approves unlimited WETH on for UniswapV3 LP", async () => {
|
|
22
|
+
// let result;
|
|
23
|
+
// const pool = await dhedge.loadPool(TEST_POOL);
|
|
24
|
+
// try {
|
|
25
|
+
// result = await pool.approveUniswapV3Liquidity(
|
|
26
|
+
// USDC,
|
|
27
|
+
// ethers.constants.MaxInt256,
|
|
28
|
+
// options
|
|
29
|
+
// );
|
|
30
|
+
// console.log(result);
|
|
31
|
+
// } catch (e) {
|
|
32
|
+
// console.log(e);
|
|
33
|
+
// }
|
|
34
|
+
// expect(result).not.toBe(null);
|
|
35
|
+
// });
|
|
36
|
+
|
|
37
|
+
// it("adds WETH and WBTC to a new V3 pool", async () => {
|
|
38
|
+
// let result;
|
|
39
|
+
// const pool = await dhedge.loadPool(TEST_POOL);
|
|
40
|
+
// const usdcBalance = await dhedge.utils.getBalance(USDC, pool.address);
|
|
41
|
+
// const wethBalance = await dhedge.utils.getBalance(WETH, pool.address);
|
|
42
|
+
|
|
43
|
+
// try {
|
|
44
|
+
// result = await pool.addLiquidityUniswapV3(
|
|
45
|
+
// USDC,
|
|
46
|
+
// WETH,
|
|
47
|
+
// usdcBalance,
|
|
48
|
+
// wethBalance,
|
|
49
|
+
// 0.0003,
|
|
50
|
+
// 0.0004,
|
|
51
|
+
// null,
|
|
52
|
+
// null,
|
|
53
|
+
// FeeAmount.LOW,
|
|
54
|
+
// options
|
|
55
|
+
// );
|
|
56
|
+
// console.log(result);
|
|
57
|
+
// } catch (e) {
|
|
58
|
+
// console.log(e);
|
|
59
|
+
// }
|
|
60
|
+
// expect(result).not.toBe(null);
|
|
61
|
+
// });
|
|
62
|
+
|
|
63
|
+
// it("should remove liquidity from an existing pool ", async () => {
|
|
64
|
+
// const pool = await dhedge.loadPool(TEST_POOL);
|
|
65
|
+
// const result = await pool.removeLiquidityUniswapV3("84405", 100, options);
|
|
66
|
+
// console.log("result", result);
|
|
67
|
+
// expect(result).not.toBe(null);
|
|
68
|
+
// });
|
|
69
|
+
|
|
70
|
+
// it("should increase liquidity in an existing pool WETH/WBTC pool", async () => {
|
|
71
|
+
// const pool = await dhedge.loadPool(TEST_POOL);
|
|
72
|
+
// const result = await pool.increaseLiquidityUniswapV3(
|
|
73
|
+
// "54929",
|
|
74
|
+
// "1317",
|
|
75
|
+
// "143980000000000",
|
|
76
|
+
// options
|
|
77
|
+
// );
|
|
78
|
+
// console.log("result", result);
|
|
79
|
+
// expect(result).not.toBe(null);
|
|
80
|
+
// });
|
|
81
|
+
|
|
82
|
+
// it("should claim fees an existing pool", async () => {
|
|
83
|
+
// const pool = await dhedge.loadPool(TEST_POOL);
|
|
84
|
+
// const result = await pool.claimFeesUniswapV3("54929", options);
|
|
85
|
+
// console.log("result", result);
|
|
86
|
+
// expect(result).not.toBe(null);
|
|
87
|
+
// });
|
|
88
|
+
|
|
89
|
+
// it("should claim fees an existing pool", async () => {
|
|
90
|
+
// const pool = await dhedge.loadPool(TEST_POOL);
|
|
91
|
+
// const result = await pool.claimFeesUniswapV3("54929", options);
|
|
92
|
+
// console.log("result", result);
|
|
93
|
+
// expect(result).not.toBe(null);
|
|
94
|
+
// });
|
|
95
|
+
|
|
96
|
+
// it("approves unlimited USDC to swap on UniswapV3", async () => {
|
|
97
|
+
// let result;
|
|
98
|
+
// const pool = await dhedge.loadPool(TEST_POOL);
|
|
99
|
+
// try {
|
|
100
|
+
// result = await pool.approve(
|
|
101
|
+
// Dapp.UNISWAPV3,
|
|
102
|
+
// USDC,
|
|
103
|
+
// ethers.constants.MaxInt256,
|
|
104
|
+
// options
|
|
105
|
+
// );
|
|
106
|
+
// console.log(result);
|
|
107
|
+
// } catch (e) {
|
|
108
|
+
// console.log(e);
|
|
109
|
+
// }
|
|
110
|
+
// expect(result).not.toBe(null);
|
|
111
|
+
// });
|
|
112
|
+
|
|
113
|
+
it("should swap USDC into WETH on UniswapV3 pool", async () => {
|
|
114
|
+
const pool = await dhedge.loadPool(TEST_POOL);
|
|
115
|
+
const result = await pool.tradeUniswapV3(
|
|
116
|
+
USDC,
|
|
117
|
+
WETH,
|
|
118
|
+
"1000000",
|
|
119
|
+
FeeAmount.LOW,
|
|
120
|
+
1,
|
|
121
|
+
options
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
console.log(result);
|
|
125
|
+
expect(result).not.toBe(null);
|
|
126
|
+
});
|
|
127
|
+
});
|