@dhedge/v2-sdk 1.2.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.
@@ -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
+ });
@@ -4,9 +4,13 @@ import { ethers } from "ethers";
4
4
  require("dotenv").config();
5
5
 
6
6
  const provider = new ethers.providers.JsonRpcProvider(
7
- `https://polygon-mainnet.infura.io/v3/${process.env.INFURA_PROJECT_ID}`
7
+ `https://opt-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_PROJECT_ID}`
8
8
  );
9
9
 
10
+ // const provider = new ethers.providers.JsonRpcProvider(
11
+ // `https://polygon-mainnet.infura.io/v3/${process.env.INFURA_PROJECT_ID}`
12
+ // );
13
+
10
14
  export const wallet = new ethers.Wallet(
11
15
  process.env.PRIVATE_KEY as string,
12
16
  provider
package/src/types.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { ChainId } from "@sushiswap/sdk";
2
1
  import { BigNumber } from "ethers";
3
2
 
4
3
  export enum Network {
5
- POLYGON = "polygon"
4
+ POLYGON = "polygon",
5
+ OPTIMISM = "optimism"
6
6
  }
7
7
 
8
8
  export enum Dapp {
@@ -10,7 +10,9 @@ export enum Dapp {
10
10
  AAVE = "aave",
11
11
  ONEINCH = "1inch",
12
12
  QUICKSWAP = "quickswap",
13
- BALANCER = "balancer"
13
+ BALANCER = "balancer",
14
+ UNISWAPV3 = "uniswapV3",
15
+ SYNTHETIX = "synthetix"
14
16
  }
15
17
 
16
18
  export enum Transaction {
@@ -21,9 +23,16 @@ export enum Transaction {
21
23
  CLAIM_DISTRIBIUTIONS = "claimDistributions",
22
24
  CLAIM_REWARDS = "claimRewards",
23
25
  REMOVE_LIQUIDITY = "removeLiquidity",
26
+ DECREASE_LIQUIDITY = "decreaseLiquidity",
27
+ INCREASE_LIQUIDITY = "increaseLiquidity",
28
+ COLLECT = "collect",
29
+ MULTI_CALL = "multicall",
24
30
  BORROW = "borrow",
25
31
  REPAY = "repay",
26
- WITHDRAW = "withdraw"
32
+ WITHDRAW = "withdraw",
33
+ MINT = "mint",
34
+ BURN = "burn",
35
+ SWAP_SYNTHS = "exchangeWithTracking"
27
36
  }
28
37
 
29
38
  export type AddressNetworkMap = Readonly<Record<Network, string>>;
@@ -34,6 +43,8 @@ export type AddressDappMap = {
34
43
  [Dapp.ONEINCH]?: string;
35
44
  [Dapp.QUICKSWAP]?: string;
36
45
  [Dapp.BALANCER]?: string;
46
+ [Dapp.UNISWAPV3]?: string;
47
+ [Dapp.SYNTHETIX]?: string;
37
48
  };
38
49
 
39
50
  export type AddressDappNetworkMap = Readonly<Record<Network, AddressDappMap>>;
@@ -57,4 +68,4 @@ export type Reserves = {
57
68
  assetB: BigNumber;
58
69
  };
59
70
 
60
- export type NetworkChainIdMap = Readonly<Record<Network, ChainId>>;
71
+ export type NetworkChainIdMap = Readonly<Record<Network, number>>;