@dhedge/v2-sdk 1.3.0 → 1.4.2

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.
@@ -0,0 +1,89 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { Dhedge } from "..";
3
+ import { Dapp, Network } from "../types";
4
+ import { ARRAKIS_USDC_WETH_GAUGE, TEST_POOL } from "./constants";
5
+ import { getTxOptions } from "./txOptions";
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.POLYGON);
17
+ options = await getTxOptions();
18
+ });
19
+
20
+ // it("approves unlimited WETH on Arrakis", async () => {
21
+ // let result;
22
+ // const pool = await dhedge.loadPool(TEST_POOL);
23
+ // try {
24
+ // result = await pool.approve(
25
+ // Dapp.ARRAKIS,
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("should add liquidity and stake in an WETH/USDC Arrakis pool", async () => {
38
+ // const pool = await dhedge.loadPool(TEST_POOL);
39
+ // const result = await pool.increaseLiquidity(
40
+ // Dapp.ARRAKIS,
41
+ // "0x33d1ad9Cd88A509397CD924C2d7613C285602C20",
42
+ // "776000",
43
+ // "470000000000000",
44
+ // options
45
+ // );
46
+ // console.log("result", result);
47
+ // expect(result).not.toBe(null);
48
+ // });
49
+
50
+ // it("approves unlimited LP staking Token before on Arrakis", async () => {
51
+ // let result;
52
+ // const pool = await dhedge.loadPool(TEST_POOL);
53
+ // try {
54
+ // result = await pool.approve(
55
+ // Dapp.ARRAKIS,
56
+ // ARRAKIS_USDC_WETH_GAUGE,
57
+ // ethers.constants.MaxInt256,
58
+ // options
59
+ // );
60
+ // console.log(result);
61
+ // } catch (e) {
62
+ // console.log(e);
63
+ // }
64
+ // expect(result).not.toBe(null);
65
+ // });
66
+
67
+ it("should remove liquidity from an existing pool ", async () => {
68
+ const pool = await dhedge.loadPool(TEST_POOL);
69
+ const result = await pool.decreaseLiquidity(
70
+ Dapp.ARRAKIS,
71
+ ARRAKIS_USDC_WETH_GAUGE,
72
+ 100,
73
+ options
74
+ );
75
+ console.log("result", result);
76
+ expect(result).not.toBe(null);
77
+ });
78
+
79
+ // it("should claim fees an existing pool", async () => {
80
+ // const pool = await dhedge.loadPool(TEST_POOL);
81
+ // const result = await pool.claimFees(
82
+ // Dapp.ARRAKIS,
83
+ // ARRAKIS_USDC_WETH_GAUGE,
84
+ // options
85
+ // );
86
+ // console.log("result", result);
87
+ // expect(result).not.toBe(null);
88
+ // });
89
+ });
@@ -1,21 +1,19 @@
1
- import { Dhedge, ethers } from "..";
1
+ import { Dhedge } from "..";
2
2
  import { Network } from "../types";
3
- import { TEST_POOL } from "./constants";
3
+ import { STMATIC, TEST_POOL, WMATIC } from "./constants";
4
+ import { getTxOptions } from "./txOptions";
4
5
 
5
6
  import { wallet } from "./wallet";
6
7
 
7
8
  let dhedge: Dhedge;
9
+ let options: any;
8
10
 
9
11
  jest.setTimeout(100000);
10
12
 
11
- const options = {
12
- gasLimit: 2000000,
13
- gasPrice: ethers.utils.parseUnits("1000", "gwei")
14
- };
15
-
16
13
  describe("pool", () => {
17
- beforeAll(() => {
14
+ beforeAll(async () => {
18
15
  dhedge = new Dhedge(wallet, Network.POLYGON);
16
+ options = await getTxOptions();
19
17
  });
20
18
 
21
19
  // it("approves unlimited USDC on Balancer", async () => {
@@ -95,11 +93,118 @@ describe("pool", () => {
95
93
  // expect(result).not.toBe(null);
96
94
  // });
97
95
 
98
- it("claims balancer rewards", async () => {
96
+ // it("claims balancer rewards", async () => {
97
+ // let result;
98
+ // const pool = await dhedge.loadPool(TEST_POOL);
99
+ // try {
100
+ // result = await pool.harvestBalancerRewards(options);
101
+ // console.log("result", result);
102
+ // } catch (e) {
103
+ // console.log(e);
104
+ // }
105
+ // expect(result).not.toBe(null);
106
+ // });
107
+
108
+ // it("adds 5 WMATIC to a WMATIC/stMATIC balancer pool", async () => {
109
+ // let result;
110
+ // const pool = await dhedge.loadPool(TEST_POOL);
111
+ // const assets = [WMATIC, STMATIC];
112
+ // const amounts = ["5000000000000000000", "0"];
113
+ // try {
114
+ // result = await pool.joinBalancerPool(
115
+ // "0xaf5e0b5425de1f5a630a8cb5aa9d97b8141c908d000200000000000000000366",
116
+ // assets,
117
+ // amounts,
118
+ // options
119
+ // );
120
+ // console.log("result", result);
121
+ // } catch (e) {
122
+ // console.log(e);
123
+ // }
124
+ // expect(result).not.toBe(null);
125
+ // });
126
+
127
+ // it("allows unlimited WMATIC-stMATIC LP on gauge", async () => {
128
+ // let result;
129
+ // const pool = await dhedge.loadPool(TEST_POOL);
130
+ // try {
131
+ // result = await pool.approveSpender(
132
+ // "0x9928340f9E1aaAd7dF1D95E27bd9A5c715202a56",
133
+ // WMATIC_STMATIC_LP,
134
+ // ethers.constants.MaxUint256,
135
+ // options
136
+ // );
137
+ // console.log("result", result);
138
+ // } catch (e) {
139
+ // console.log(e);
140
+ // }
141
+ // expect(result).not.toBe(null);
142
+ // });
143
+
144
+ // it("stakes WMATIC-stMATIC LP in gauge", async () => {
145
+ // let result;
146
+ // const pool = await dhedge.loadPool(TEST_POOL);
147
+ // try {
148
+ // result = await pool.stakeInGauge(
149
+ // "0x9928340f9E1aaAd7dF1D95E27bd9A5c715202a56",
150
+ // "4978534455005333156",
151
+ // options
152
+ // );
153
+ // console.log("result", result);
154
+ // } catch (e) {
155
+ // console.log(e);
156
+ // }
157
+ // expect(result).not.toBe(null);
158
+ // });
159
+
160
+ // it("claim fess pf staked WMATIC-stMATIC LP in gauge", async () => {
161
+ // let result;
162
+ // const pool = await dhedge.loadPool(TEST_POOL);
163
+ // try {
164
+ // result = await pool.claimFees(
165
+ // Dapp.BALANCER,
166
+ // "0x9928340f9E1aaAd7dF1D95E27bd9A5c715202a56",
167
+ // options
168
+ // );
169
+ // console.log("result", result);
170
+ // } catch (e) {
171
+ // console.log(e);
172
+ // }
173
+ // expect(result).not.toBe(null);
174
+ // });
175
+
176
+ // it("unstakes WMATIC-stMATIC LP from gauge", async () => {
177
+ // let result;
178
+ // const pool = await dhedge.loadPool(TEST_POOL);
179
+ // try {
180
+ // result = await pool.unstakeFromGauge(
181
+ // "0x9928340f9E1aaAd7dF1D95E27bd9A5c715202a56",
182
+ // "4978534455005333156",
183
+ // options
184
+ // );
185
+ // console.log("result", result);
186
+ // } catch (e) {
187
+ // console.log(e);
188
+ // }
189
+ // expect(result).not.toBe(null);
190
+ // });
191
+
192
+ it("exits from WMATIC-stMATIC LP into WMATIC", async () => {
99
193
  let result;
100
194
  const pool = await dhedge.loadPool(TEST_POOL);
195
+ const assets = [WMATIC, STMATIC];
196
+ const amount = await dhedge.utils.getBalance(
197
+ "0xaF5E0B5425dE1F5a630A8cB5AA9D97B8141C908D",
198
+ pool.address
199
+ );
101
200
  try {
102
- result = await pool.harvestBalancerRewards(options);
201
+ result = await pool.exitBalancerPool(
202
+ "0xaf5e0b5425de1f5a630a8cb5aa9d97b8141c908d000200000000000000000366",
203
+ assets,
204
+ amount,
205
+ 1,
206
+ options
207
+ );
103
208
  console.log("result", result);
104
209
  } catch (e) {
105
210
  console.log(e);
@@ -1,17 +1,23 @@
1
- //export const USDC = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174";
2
- //Optimism
3
- export const USDC = "0x7F5c764cBc14f9669B88837ca1490cCa17c31607";
4
- export const USDT = "0xc2132D05D31c914a87C6611C10748AEb04B58e8F";
5
- export const DAI = "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063";
6
- export const TUSD = "0x2e1ad108ff1d8c782fcbbb89aad783ac49586756";
7
- //export const WETH = "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619";
1
+ //Polygon
2
+ // export const USDC = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174";
3
+ // export const WETH = "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619";
4
+ // export const USDT = "0xc2132D05D31c914a87C6611C10748AEb04B58e8F";
5
+ // export const DAI = "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063";
6
+ // export const TUSD = "0x2e1ad108ff1d8c782fcbbb89aad783ac49586756";
7
+ // export const WBTC = "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6";
8
+ // export const SUSHI = "0x0b3f868e0be5597d5db7feb59e1cadbb0fdda50a";
9
+ // export const WMATIC = "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270";
10
+ // export const BAL = "0x9a71012B13CA4d3D0Cdc72A177DF3ef03b0E76A3";
11
+ // export const AMUSDC = "0x1a13f4ca1d028320a707d99520abfefca3998b7f";
12
+ // export const VDEBTWETH = "0xede17e9d79fc6f9ff9250d9eefbdb88cc18038b5";
13
+ // export const ARRAKIS_USDC_WETH_GAUGE =
14
+ // "0x33d1ad9Cd88A509397CD924C2d7613C285602C20";
15
+ // export const STMATIC = "0x3A58a54C066FdC0f2D55FC9C89F0415C92eBf3C4";
16
+ // export const WMATIC_STMATIC_LP = "0xaF5E0B5425dE1F5a630A8cB5AA9D97B8141C908D";
17
+
8
18
  //Optimism
9
19
  export const WETH = "0x4200000000000000000000000000000000000006";
10
- export const WBTC = "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6";
11
- export const SUSHI = "0x0b3f868e0be5597d5db7feb59e1cadbb0fdda50a";
12
- export const WMATIC = "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270";
13
- export const BAL = "0x9a71012B13CA4d3D0Cdc72A177DF3ef03b0E76A3";
14
- export const AMUSDC = "0x1a13f4ca1d028320a707d99520abfefca3998b7f";
15
- export const VDEBTWETH = "0xede17e9d79fc6f9ff9250d9eefbdb88cc18038b5";
20
+ export const USDC = "0x7F5c764cBc14f9669B88837ca1490cCa17c31607";
21
+ export const DAI = "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1";
16
22
 
17
- export const TEST_POOL = "0xf36f550907872faaa02477f791df3ce33fe38854";
23
+ export const TEST_POOL = "TEST_POOL_ADDRESS";
@@ -1,6 +1,6 @@
1
- import { Dhedge, ethers } from "..";
1
+ import { Dhedge } from "..";
2
2
  import { Dapp, Network } from "../types";
3
- import { TEST_POOL, USDC, WETH } from "./constants";
3
+ import { DAI, TEST_POOL, USDC } from "./constants";
4
4
 
5
5
  import { wallet } from "./wallet";
6
6
 
@@ -8,25 +8,24 @@ let dhedge: Dhedge;
8
8
 
9
9
  jest.setTimeout(100000);
10
10
 
11
- const options = {
12
- gasLimit: 5000000,
13
- gasPrice: ethers.utils.parseUnits("35", "gwei")
14
- };
11
+ // const options = {
12
+ // gasLimit: 5000000,
13
+ // gasPrice: ethers.utils.parseUnits("35", "gwei")
14
+ // };
15
15
 
16
16
  describe("pool", () => {
17
17
  beforeAll(() => {
18
- dhedge = new Dhedge(wallet, Network.POLYGON);
18
+ dhedge = new Dhedge(wallet, Network.OPTIMISM);
19
19
  });
20
20
 
21
- // it("approves unlimited USDC on 1Inch", async () => {
21
+ // it("approves unlimited DAI on 1Inch", async () => {
22
22
  // let result;
23
23
  // const pool = await dhedge.loadPool(TEST_POOL);
24
24
  // try {
25
25
  // result = await pool.approve(
26
26
  // Dapp.ONEINCH,
27
- // USDC,
28
- // ethers.constants.MaxInt256,
29
- // options
27
+ // DAI,
28
+ // ethers.constants.MaxInt256
30
29
  // );
31
30
  // console.log(result);
32
31
  // } catch (e) {
@@ -35,18 +34,12 @@ describe("pool", () => {
35
34
  // expect(result).not.toBe(null);
36
35
  // });
37
36
 
38
- it("trades 1 USDC into WETH on 1Inch", async () => {
37
+ it("trades 1 entire DAI balance into USDC on 1Inch", async () => {
39
38
  let result;
40
39
  const pool = await dhedge.loadPool(TEST_POOL);
41
40
  try {
42
- result = await pool.trade(
43
- Dapp.ONEINCH,
44
- USDC,
45
- WETH,
46
- "1000000",
47
- 0.5,
48
- options
49
- );
41
+ const balance = await dhedge.utils.getBalance(DAI, pool.address);
42
+ result = await pool.trade(Dapp.ONEINCH, DAI, USDC, balance, 0.5);
50
43
  console.log("1inch trade", result);
51
44
  } catch (e) {
52
45
  console.log(e);
@@ -15,7 +15,7 @@ jest.setTimeout(100000);
15
15
 
16
16
  describe("pool", () => {
17
17
  beforeAll(() => {
18
- dhedge = new Dhedge(wallet, Network.OPTIMISM);
18
+ dhedge = new Dhedge(wallet, Network.POLYGON);
19
19
  });
20
20
 
21
21
  it("checks fund composition", async () => {
@@ -1,15 +1,21 @@
1
1
  import axios from "axios";
2
2
  import BigNumber from "bignumber.js";
3
+ import { Network } from "../types";
3
4
 
4
5
  // 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
- };
6
+ export const getTxOptions = async (network: Network): Promise<any> => {
7
+ if (network === Network.POLYGON) {
8
+ const result = await axios("https://gasstation-mainnet.matic.network/v2");
9
+ return {
10
+ gasLimit: "3000000",
11
+ maxPriorityFeePerGas: new BigNumber(result.data.fast.maxPriorityFee)
12
+ .shiftedBy(9)
13
+ .toFixed(0),
14
+ maxFeePerGas: new BigNumber(result.data.fast.maxFee)
15
+ .shiftedBy(9)
16
+ .toFixed(0),
17
+ };
18
+ } else {
19
+ return { gasLimit: "3000000" };
20
+ }
15
21
  };
@@ -1,9 +1,8 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { FeeAmount } from "@uniswap/v3-sdk";
3
2
  import { Dhedge } from "..";
4
- import { Network } from "../types";
5
- import { TEST_POOL, USDC, WETH } from "./constants";
6
- //import { getTxOptions } from "./txOptions";
3
+ import { Dapp, Network } from "../types";
4
+ import { TEST_POOL } from "./constants";
5
+ import { getTxOptions } from "./txOptions";
7
6
 
8
7
  import { wallet } from "./wallet";
9
8
 
@@ -13,9 +12,9 @@ jest.setTimeout(100000);
13
12
 
14
13
  describe("pool", () => {
15
14
  beforeAll(async () => {
16
- dhedge = new Dhedge(wallet, Network.OPTIMISM);
17
- //options = await getTxOptions();
18
- options = { gasLimit: "3000000" };
15
+ dhedge = new Dhedge(wallet, Network.POLYGON);
16
+ options = await getTxOptions();
17
+ //options = { gasLimit: "3000000" };
19
18
  });
20
19
 
21
20
  // it("approves unlimited WETH on for UniswapV3 LP", async () => {
@@ -60,19 +59,25 @@ describe("pool", () => {
60
59
  // expect(result).not.toBe(null);
61
60
  // });
62
61
 
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
- // });
62
+ it("should remove liquidity from an existing pool ", async () => {
63
+ const pool = await dhedge.loadPool(TEST_POOL);
64
+ const result = await pool.decreaseLiquidity(
65
+ Dapp.UNISWAPV3,
66
+ "110507",
67
+ 100,
68
+ options
69
+ );
70
+ console.log("result", result);
71
+ expect(result).not.toBe(null);
72
+ });
69
73
 
70
74
  // it("should increase liquidity in an existing pool WETH/WBTC pool", async () => {
71
75
  // const pool = await dhedge.loadPool(TEST_POOL);
72
- // const result = await pool.increaseLiquidityUniswapV3(
73
- // "54929",
74
- // "1317",
75
- // "143980000000000",
76
+ // const result = await pool.increaseLiquidity(
77
+ // Dapp.UNISWAPV3,
78
+ // "110507",
79
+ // "244838",
80
+ // "258300000000000",
76
81
  // options
77
82
  // );
78
83
  // console.log("result", result);
@@ -86,13 +91,6 @@ describe("pool", () => {
86
91
  // expect(result).not.toBe(null);
87
92
  // });
88
93
 
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
94
  // it("approves unlimited USDC to swap on UniswapV3", async () => {
97
95
  // let result;
98
96
  // const pool = await dhedge.loadPool(TEST_POOL);
@@ -110,18 +108,18 @@ describe("pool", () => {
110
108
  // expect(result).not.toBe(null);
111
109
  // });
112
110
 
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
- );
111
+ // it("should swap USDC into WETH on UniswapV3 pool", async () => {
112
+ // const pool = await dhedge.loadPool(TEST_POOL);
113
+ // const result = await pool.tradeUniswapV3(
114
+ // USDC,
115
+ // WETH,
116
+ // "1000000",
117
+ // FeeAmount.LOW,
118
+ // 1,
119
+ // options
120
+ // );
123
121
 
124
- console.log(result);
125
- expect(result).not.toBe(null);
126
- });
122
+ // console.log(result);
123
+ // expect(result).not.toBe(null);
124
+ // });
127
125
  });
@@ -3,14 +3,14 @@ import { ethers } from "ethers";
3
3
  // eslint-disable-next-line @typescript-eslint/no-var-requires
4
4
  require("dotenv").config();
5
5
 
6
- const provider = new ethers.providers.JsonRpcProvider(
7
- `https://opt-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_PROJECT_ID}`
8
- );
9
-
10
6
  // const provider = new ethers.providers.JsonRpcProvider(
11
- // `https://polygon-mainnet.infura.io/v3/${process.env.INFURA_PROJECT_ID}`
7
+ // `https://opt-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_PROJECT_ID}`
12
8
  // );
13
9
 
10
+ const provider = new ethers.providers.JsonRpcProvider(
11
+ `https://polygon-mainnet.infura.io/v3/${process.env.INFURA_PROJECT_ID}`
12
+ );
13
+
14
14
  export const wallet = new ethers.Wallet(
15
15
  process.env.PRIVATE_KEY as string,
16
16
  provider
package/src/types.ts CHANGED
@@ -12,7 +12,9 @@ export enum Dapp {
12
12
  QUICKSWAP = "quickswap",
13
13
  BALANCER = "balancer",
14
14
  UNISWAPV3 = "uniswapV3",
15
- SYNTHETIX = "synthetix"
15
+ SYNTHETIX = "synthetix",
16
+ AAVEV3 = "aavev3",
17
+ ARRAKIS = "arrakis"
16
18
  }
17
19
 
18
20
  export enum Transaction {
@@ -32,19 +34,15 @@ export enum Transaction {
32
34
  WITHDRAW = "withdraw",
33
35
  MINT = "mint",
34
36
  BURN = "burn",
35
- SWAP_SYNTHS = "exchangeWithTracking"
37
+ SWAP_SYNTHS = "exchangeWithTracking",
38
+ ADD_LIQUIDITY_STAKE = "addLiquidityAndStake",
39
+ REMOVE_LIQUIDITY_UNSTAKE = "removeLiquidityAndUnstake"
36
40
  }
37
41
 
38
42
  export type AddressNetworkMap = Readonly<Record<Network, string>>;
39
43
 
40
44
  export type AddressDappMap = {
41
- [Dapp.SUSHISWAP]?: string;
42
- [Dapp.AAVE]?: string;
43
- [Dapp.ONEINCH]?: string;
44
- [Dapp.QUICKSWAP]?: string;
45
- [Dapp.BALANCER]?: string;
46
- [Dapp.UNISWAPV3]?: string;
47
- [Dapp.SYNTHETIX]?: string;
45
+ [key in Dapp]?: string;
48
46
  };
49
47
 
50
48
  export type AddressDappNetworkMap = Readonly<Record<Network, AddressDappMap>>;