@dhedge/v2-sdk 1.2.1 → 1.4.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.
Files changed (41) hide show
  1. package/dist/config.d.ts +5 -0
  2. package/dist/entities/pool.d.ts +98 -7
  3. package/dist/entities/utils.d.ts +7 -1
  4. package/dist/services/uniswap/V3Liquidity.d.ts +9 -0
  5. package/dist/services/uniswap/V3Trade.d.ts +4 -0
  6. package/dist/services/uniswap/types.d.ts +3 -0
  7. package/dist/test/constants.d.ts +5 -2
  8. package/dist/test/txOptions.d.ts +1 -0
  9. package/dist/types.d.ts +19 -10
  10. package/dist/v2-sdk.cjs.development.js +3796 -679
  11. package/dist/v2-sdk.cjs.development.js.map +1 -1
  12. package/dist/v2-sdk.cjs.production.min.js +1 -1
  13. package/dist/v2-sdk.cjs.production.min.js.map +1 -1
  14. package/dist/v2-sdk.esm.js +3797 -680
  15. package/dist/v2-sdk.esm.js.map +1 -1
  16. package/package.json +4 -1
  17. package/src/abi/IArrakisV1RouterStaking.json +107 -0
  18. package/src/abi/IBalancerRewardsGauge.json +239 -0
  19. package/src/abi/IERC20.json +15 -1
  20. package/src/abi/ILiquidityGaugeV4.json +153 -0
  21. package/src/abi/INonfungiblePositionManager.json +1221 -0
  22. package/src/abi/ISynthetix.json +139 -0
  23. package/src/abi/IUniswapV3Quoter.json +195 -0
  24. package/src/abi/IUniswapV3Router.json +221 -0
  25. package/src/config.ts +35 -8
  26. package/src/entities/dhedge.ts +4 -2
  27. package/src/entities/pool.ts +394 -33
  28. package/src/entities/utils.ts +25 -9
  29. package/src/services/uniswap/V3Liquidity.ts +134 -0
  30. package/src/services/uniswap/V3Trade.ts +47 -0
  31. package/src/services/uniswap/types.ts +16 -0
  32. package/src/test/aave.test.ts +53 -25
  33. package/src/test/arrakis.test.ts +89 -0
  34. package/src/test/balancer.test.ts +115 -10
  35. package/src/test/constants.ts +12 -2
  36. package/src/test/oneInch.test.ts +13 -20
  37. package/src/test/synthetix.test.ts +34 -0
  38. package/src/test/txOptions.ts +15 -0
  39. package/src/test/uniswap.test.ts +125 -0
  40. package/src/test/wallet.ts +4 -0
  41. package/src/types.ts +19 -10
@@ -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,125 @@
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.POLYGON);
16
+ options = await getTxOptions();
17
+ //options = { gasLimit: "3000000" };
18
+ });
19
+
20
+ // it("approves unlimited WETH on for UniswapV3 LP", async () => {
21
+ // let result;
22
+ // const pool = await dhedge.loadPool(TEST_POOL);
23
+ // try {
24
+ // result = await pool.approveUniswapV3Liquidity(
25
+ // USDC,
26
+ // ethers.constants.MaxInt256,
27
+ // options
28
+ // );
29
+ // console.log(result);
30
+ // } catch (e) {
31
+ // console.log(e);
32
+ // }
33
+ // expect(result).not.toBe(null);
34
+ // });
35
+
36
+ // it("adds WETH and WBTC to a new V3 pool", async () => {
37
+ // let result;
38
+ // const pool = await dhedge.loadPool(TEST_POOL);
39
+ // const usdcBalance = await dhedge.utils.getBalance(USDC, pool.address);
40
+ // const wethBalance = await dhedge.utils.getBalance(WETH, pool.address);
41
+
42
+ // try {
43
+ // result = await pool.addLiquidityUniswapV3(
44
+ // USDC,
45
+ // WETH,
46
+ // usdcBalance,
47
+ // wethBalance,
48
+ // 0.0003,
49
+ // 0.0004,
50
+ // null,
51
+ // null,
52
+ // FeeAmount.LOW,
53
+ // options
54
+ // );
55
+ // console.log(result);
56
+ // } catch (e) {
57
+ // console.log(e);
58
+ // }
59
+ // expect(result).not.toBe(null);
60
+ // });
61
+
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
+ });
73
+
74
+ // it("should increase liquidity in an existing pool WETH/WBTC pool", async () => {
75
+ // const pool = await dhedge.loadPool(TEST_POOL);
76
+ // const result = await pool.increaseLiquidity(
77
+ // Dapp.UNISWAPV3,
78
+ // "110507",
79
+ // "244838",
80
+ // "258300000000000",
81
+ // options
82
+ // );
83
+ // console.log("result", result);
84
+ // expect(result).not.toBe(null);
85
+ // });
86
+
87
+ // it("should claim fees an existing pool", async () => {
88
+ // const pool = await dhedge.loadPool(TEST_POOL);
89
+ // const result = await pool.claimFeesUniswapV3("54929", options);
90
+ // console.log("result", result);
91
+ // expect(result).not.toBe(null);
92
+ // });
93
+
94
+ // it("approves unlimited USDC to swap on UniswapV3", async () => {
95
+ // let result;
96
+ // const pool = await dhedge.loadPool(TEST_POOL);
97
+ // try {
98
+ // result = await pool.approve(
99
+ // Dapp.UNISWAPV3,
100
+ // USDC,
101
+ // ethers.constants.MaxInt256,
102
+ // options
103
+ // );
104
+ // console.log(result);
105
+ // } catch (e) {
106
+ // console.log(e);
107
+ // }
108
+ // expect(result).not.toBe(null);
109
+ // });
110
+
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
+ // );
121
+
122
+ // console.log(result);
123
+ // expect(result).not.toBe(null);
124
+ // });
125
+ });
@@ -3,6 +3,10 @@ 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
+
6
10
  const provider = new ethers.providers.JsonRpcProvider(
7
11
  `https://polygon-mainnet.infura.io/v3/${process.env.INFURA_PROJECT_ID}`
8
12
  );
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,11 @@ 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",
16
+ AAVEV3 = "aavev3",
17
+ ARRAKIS = "arrakis"
14
18
  }
15
19
 
16
20
  export enum Transaction {
@@ -21,19 +25,24 @@ export enum Transaction {
21
25
  CLAIM_DISTRIBIUTIONS = "claimDistributions",
22
26
  CLAIM_REWARDS = "claimRewards",
23
27
  REMOVE_LIQUIDITY = "removeLiquidity",
28
+ DECREASE_LIQUIDITY = "decreaseLiquidity",
29
+ INCREASE_LIQUIDITY = "increaseLiquidity",
30
+ COLLECT = "collect",
31
+ MULTI_CALL = "multicall",
24
32
  BORROW = "borrow",
25
33
  REPAY = "repay",
26
- WITHDRAW = "withdraw"
34
+ WITHDRAW = "withdraw",
35
+ MINT = "mint",
36
+ BURN = "burn",
37
+ SWAP_SYNTHS = "exchangeWithTracking",
38
+ ADD_LIQUIDITY_STAKE = "addLiquidityAndStake",
39
+ REMOVE_LIQUIDITY_UNSTAKE = "removeLiquidityAndUnstake"
27
40
  }
28
41
 
29
42
  export type AddressNetworkMap = Readonly<Record<Network, string>>;
30
43
 
31
44
  export type AddressDappMap = {
32
- [Dapp.SUSHISWAP]?: string;
33
- [Dapp.AAVE]?: string;
34
- [Dapp.ONEINCH]?: string;
35
- [Dapp.QUICKSWAP]?: string;
36
- [Dapp.BALANCER]?: string;
45
+ [key in Dapp]?: string;
37
46
  };
38
47
 
39
48
  export type AddressDappNetworkMap = Readonly<Record<Network, AddressDappMap>>;
@@ -57,4 +66,4 @@ export type Reserves = {
57
66
  assetB: BigNumber;
58
67
  };
59
68
 
60
- export type NetworkChainIdMap = Readonly<Record<Network, ChainId>>;
69
+ export type NetworkChainIdMap = Readonly<Record<Network, number>>;