@dhedge/v2-sdk 1.3.0 → 1.4.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/dist/entities/pool.d.ts +10 -7
- package/dist/test/constants.d.ts +4 -3
- package/dist/types.d.ts +7 -9
- package/dist/v2-sdk.cjs.development.js +443 -81
- 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 +441 -79
- package/dist/v2-sdk.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/abi/IArrakisV1RouterStaking.json +107 -0
- package/src/abi/ILiquidityGaugeV4.json +153 -0
- package/src/config.ts +6 -2
- package/src/entities/pool.ts +107 -53
- package/src/test/aave.test.ts +53 -25
- package/src/test/arrakis.test.ts +89 -0
- package/src/test/constants.ts +11 -7
- package/src/test/oneInch.test.ts +13 -20
- package/src/test/pool.test.ts +1 -1
- package/src/test/uniswap.test.ts +35 -37
- package/src/test/wallet.ts +5 -5
- package/src/types.ts +7 -9
|
@@ -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
|
+
});
|
package/src/test/constants.ts
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
export const
|
|
1
|
+
//Polygon
|
|
2
|
+
export const USDC = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174";
|
|
3
|
+
export const WETH = "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619";
|
|
4
4
|
export const USDT = "0xc2132D05D31c914a87C6611C10748AEb04B58e8F";
|
|
5
5
|
export const DAI = "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063";
|
|
6
6
|
export const TUSD = "0x2e1ad108ff1d8c782fcbbb89aad783ac49586756";
|
|
7
|
-
//export const WETH = "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619";
|
|
8
|
-
//Optimism
|
|
9
|
-
export const WETH = "0x4200000000000000000000000000000000000006";
|
|
10
7
|
export const WBTC = "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6";
|
|
11
8
|
export const SUSHI = "0x0b3f868e0be5597d5db7feb59e1cadbb0fdda50a";
|
|
12
9
|
export const WMATIC = "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270";
|
|
13
10
|
export const BAL = "0x9a71012B13CA4d3D0Cdc72A177DF3ef03b0E76A3";
|
|
14
11
|
export const AMUSDC = "0x1a13f4ca1d028320a707d99520abfefca3998b7f";
|
|
15
12
|
export const VDEBTWETH = "0xede17e9d79fc6f9ff9250d9eefbdb88cc18038b5";
|
|
13
|
+
export const ARRAKIS_USDC_WETH_GAUGE =
|
|
14
|
+
"0x33d1ad9Cd88A509397CD924C2d7613C285602C20";
|
|
15
|
+
|
|
16
|
+
//Optimism
|
|
17
|
+
// export const WETH = "0x4200000000000000000000000000000000000006";
|
|
18
|
+
// export const USDC = "0x7F5c764cBc14f9669B88837ca1490cCa17c31607";
|
|
19
|
+
// export const DAI = "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1";
|
|
16
20
|
|
|
17
|
-
export const TEST_POOL = "
|
|
21
|
+
export const TEST_POOL = "TEST_POOL_ADDRESS";
|
package/src/test/oneInch.test.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Dhedge
|
|
1
|
+
import { Dhedge } from "..";
|
|
2
2
|
import { Dapp, Network } from "../types";
|
|
3
|
-
import { TEST_POOL, USDC
|
|
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
|
-
|
|
13
|
-
|
|
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.
|
|
18
|
+
dhedge = new Dhedge(wallet, Network.OPTIMISM);
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
-
// it("approves unlimited
|
|
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
|
-
//
|
|
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
|
|
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
|
-
|
|
43
|
-
|
|
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);
|
package/src/test/pool.test.ts
CHANGED
package/src/test/uniswap.test.ts
CHANGED
|
@@ -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
|
|
6
|
-
|
|
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.
|
|
17
|
-
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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.
|
|
73
|
-
//
|
|
74
|
-
// "
|
|
75
|
-
// "
|
|
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
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
-
|
|
125
|
-
|
|
126
|
-
});
|
|
122
|
+
// console.log(result);
|
|
123
|
+
// expect(result).not.toBe(null);
|
|
124
|
+
// });
|
|
127
125
|
});
|
package/src/test/wallet.ts
CHANGED
|
@@ -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://
|
|
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
|
|
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>>;
|