@dhedge/v2-sdk 1.2.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/config.d.ts +5 -0
- package/dist/entities/pool.d.ts +72 -5
- package/dist/entities/utils.d.ts +6 -0
- package/dist/services/claim-balancer/claim.service.d.ts +1 -5
- 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 +3 -2
- package/dist/test/txOptions.d.ts +1 -0
- package/dist/types.d.ts +19 -10
- package/dist/v2-sdk.cjs.development.js +4172 -1593
- 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 +4175 -1596
- package/dist/v2-sdk.esm.js.map +1 -1
- package/package.json +4 -1
- package/src/abi/IArrakisV1RouterStaking.json +107 -0
- package/src/abi/IERC20.json +15 -1
- package/src/abi/ILiquidityGaugeV4.json +153 -0
- 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 +40 -9
- package/src/entities/dhedge.ts +4 -2
- package/src/entities/pool.ts +316 -30
- package/src/entities/utils.ts +12 -0
- package/src/services/claim-balancer/claim.service.ts +14 -76
- 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 +53 -25
- package/src/test/arrakis.test.ts +89 -0
- package/src/test/constants.ts +10 -2
- package/src/test/oneInch.test.ts +13 -20
- package/src/test/synthetix.test.ts +34 -0
- package/src/test/txOptions.ts +15 -0
- package/src/test/uniswap.test.ts +125 -0
- package/src/test/wallet.ts +4 -0
- package/src/types.ts +19 -10
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { Price, Token } from "@uniswap/sdk-core";
|
|
2
|
+
import {
|
|
3
|
+
encodeSqrtRatioX96,
|
|
4
|
+
FeeAmount,
|
|
5
|
+
nearestUsableTick,
|
|
6
|
+
priceToClosestTick,
|
|
7
|
+
TICK_SPACINGS,
|
|
8
|
+
TickMath
|
|
9
|
+
} from "@uniswap/v3-sdk";
|
|
10
|
+
import { ethers } from "ethers";
|
|
11
|
+
import JSBI from "jsbi";
|
|
12
|
+
import { Pool } from "../..";
|
|
13
|
+
import {
|
|
14
|
+
networkChainIdMap,
|
|
15
|
+
nonfungiblePositionManagerAddress
|
|
16
|
+
} from "../../config";
|
|
17
|
+
import { UniswapV3MintParams } from "./types";
|
|
18
|
+
import INonfungiblePositionManager from "../../abi/INonfungiblePositionManager.json";
|
|
19
|
+
|
|
20
|
+
export function tryParsePrice(
|
|
21
|
+
baseToken: Token,
|
|
22
|
+
quoteToken: Token,
|
|
23
|
+
value: string
|
|
24
|
+
): Price<Token, Token> {
|
|
25
|
+
const [whole, fraction] = value.split(".");
|
|
26
|
+
|
|
27
|
+
const decimals = fraction?.length ?? 0;
|
|
28
|
+
const withoutDecimals = JSBI.BigInt((whole ?? "") + (fraction ?? ""));
|
|
29
|
+
|
|
30
|
+
return new Price(
|
|
31
|
+
baseToken,
|
|
32
|
+
quoteToken,
|
|
33
|
+
JSBI.multiply(
|
|
34
|
+
JSBI.BigInt(10 ** decimals),
|
|
35
|
+
JSBI.BigInt(10 ** baseToken.decimals)
|
|
36
|
+
),
|
|
37
|
+
JSBI.multiply(withoutDecimals, JSBI.BigInt(10 ** quoteToken.decimals))
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function tryParseTick(
|
|
42
|
+
baseToken: Token,
|
|
43
|
+
quoteToken: Token,
|
|
44
|
+
feeAmount: FeeAmount,
|
|
45
|
+
value: string
|
|
46
|
+
): number {
|
|
47
|
+
const price = tryParsePrice(baseToken, quoteToken, value);
|
|
48
|
+
|
|
49
|
+
let tick: number;
|
|
50
|
+
|
|
51
|
+
// check price is within min/max bounds, if outside return min/max
|
|
52
|
+
const sqrtRatioX96 = encodeSqrtRatioX96(price.numerator, price.denominator);
|
|
53
|
+
|
|
54
|
+
if (JSBI.greaterThanOrEqual(sqrtRatioX96, TickMath.MAX_SQRT_RATIO)) {
|
|
55
|
+
tick = TickMath.MAX_TICK;
|
|
56
|
+
} else if (JSBI.lessThanOrEqual(sqrtRatioX96, TickMath.MIN_SQRT_RATIO)) {
|
|
57
|
+
tick = TickMath.MIN_TICK;
|
|
58
|
+
} else {
|
|
59
|
+
// this function is agnostic to the base, will always return the correct tick
|
|
60
|
+
tick = priceToClosestTick(price);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return nearestUsableTick(tick, TICK_SPACINGS[feeAmount]);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export async function getUniswapV3MintParams(
|
|
67
|
+
pool: Pool,
|
|
68
|
+
assetA: string,
|
|
69
|
+
assetB: string,
|
|
70
|
+
amountA: string | ethers.BigNumber,
|
|
71
|
+
amountB: string | ethers.BigNumber,
|
|
72
|
+
minPrice: number | null,
|
|
73
|
+
maxPrice: number | null,
|
|
74
|
+
minTick: number | null,
|
|
75
|
+
maxTick: number | null,
|
|
76
|
+
feeAmount: FeeAmount
|
|
77
|
+
): Promise<UniswapV3MintParams> {
|
|
78
|
+
let tickLower = 0;
|
|
79
|
+
let tickUpper = 0;
|
|
80
|
+
const chainId = networkChainIdMap[pool.network];
|
|
81
|
+
const decimals = await Promise.all(
|
|
82
|
+
[assetA, assetB].map(asset => pool.utils.getDecimals(asset))
|
|
83
|
+
);
|
|
84
|
+
const tokenA = new Token(chainId, assetA, decimals[0]);
|
|
85
|
+
const tokenB = new Token(chainId, assetB, decimals[1]);
|
|
86
|
+
const [token0, token1] = tokenA.sortsBefore(tokenB)
|
|
87
|
+
? [tokenA, tokenB]
|
|
88
|
+
: [tokenB, tokenA];
|
|
89
|
+
const invertPrice = !tokenA.equals(token0);
|
|
90
|
+
|
|
91
|
+
if (minPrice && maxPrice) {
|
|
92
|
+
tickLower = invertPrice
|
|
93
|
+
? tryParseTick(token1, token0, feeAmount, maxPrice.toString())
|
|
94
|
+
: tryParseTick(token0, token1, feeAmount, minPrice.toString());
|
|
95
|
+
tickUpper = invertPrice
|
|
96
|
+
? tryParseTick(token1, token0, feeAmount, minPrice.toString())
|
|
97
|
+
: tryParseTick(token0, token1, feeAmount, maxPrice.toString());
|
|
98
|
+
} else if (minTick && maxTick) {
|
|
99
|
+
tickLower = minTick;
|
|
100
|
+
tickUpper = maxTick;
|
|
101
|
+
}
|
|
102
|
+
const [amount0, amount1] = invertPrice
|
|
103
|
+
? [amountB, amountA]
|
|
104
|
+
: [amountA, amountB];
|
|
105
|
+
|
|
106
|
+
const deadline = Math.floor(Date.now() / 1000) + 60 * 20;
|
|
107
|
+
|
|
108
|
+
return [
|
|
109
|
+
token0.address,
|
|
110
|
+
token1.address,
|
|
111
|
+
feeAmount,
|
|
112
|
+
tickLower,
|
|
113
|
+
tickUpper,
|
|
114
|
+
amount0,
|
|
115
|
+
amount1,
|
|
116
|
+
"0",
|
|
117
|
+
"0",
|
|
118
|
+
pool.address,
|
|
119
|
+
deadline
|
|
120
|
+
];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export async function getUniswapV3Liquidity(
|
|
124
|
+
tokenId: string,
|
|
125
|
+
pool: Pool
|
|
126
|
+
): Promise<ethers.BigNumber> {
|
|
127
|
+
const iNonfungiblePositionManager = new ethers.Contract(
|
|
128
|
+
nonfungiblePositionManagerAddress[pool.network],
|
|
129
|
+
INonfungiblePositionManager.abi,
|
|
130
|
+
pool.signer
|
|
131
|
+
);
|
|
132
|
+
const result = await iNonfungiblePositionManager.positions(tokenId);
|
|
133
|
+
return result.liquidity;
|
|
134
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { FeeAmount } from "@uniswap/v3-sdk";
|
|
2
|
+
import { ethers } from "ethers";
|
|
3
|
+
import { Pool } from "../..";
|
|
4
|
+
|
|
5
|
+
import IUniswapV3Router from "../../abi/IUniswapV3Router.json";
|
|
6
|
+
import IUniswapV3Quoter from "../../abi/IUniswapV3Quoter.json";
|
|
7
|
+
import { UNISWAPV3_QUOTER_ADDRESS } from "../../config";
|
|
8
|
+
|
|
9
|
+
export async function getUniswapV3SwapTxData(
|
|
10
|
+
pool: Pool,
|
|
11
|
+
assetA: string,
|
|
12
|
+
assetB: string,
|
|
13
|
+
amountIn: string | ethers.BigNumber,
|
|
14
|
+
slippage: number,
|
|
15
|
+
feeAmount: FeeAmount
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
|
+
): Promise<any> {
|
|
18
|
+
const quoterContract = new ethers.Contract(
|
|
19
|
+
UNISWAPV3_QUOTER_ADDRESS,
|
|
20
|
+
IUniswapV3Quoter.abi,
|
|
21
|
+
pool.signer
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
const quotedAmountOut: ethers.BigNumber = await quoterContract.callStatic.quoteExactInputSingle(
|
|
25
|
+
assetA,
|
|
26
|
+
assetB,
|
|
27
|
+
feeAmount,
|
|
28
|
+
amountIn.toString(),
|
|
29
|
+
0
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const minAmountOut = quotedAmountOut.mul((100 - slippage) * 100).div(10000);
|
|
33
|
+
|
|
34
|
+
const iUniswapV3Router = new ethers.utils.Interface(IUniswapV3Router.abi);
|
|
35
|
+
const swapTx = iUniswapV3Router.encodeFunctionData("exactInputSingle", [
|
|
36
|
+
[
|
|
37
|
+
assetA,
|
|
38
|
+
assetB,
|
|
39
|
+
feeAmount,
|
|
40
|
+
pool.address,
|
|
41
|
+
amountIn.toString(),
|
|
42
|
+
minAmountOut.toString(),
|
|
43
|
+
0
|
|
44
|
+
]
|
|
45
|
+
]);
|
|
46
|
+
return swapTx;
|
|
47
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { FeeAmount } from "@uniswap/v3-sdk";
|
|
2
|
+
import { ethers } from "ethers";
|
|
3
|
+
|
|
4
|
+
export type UniswapV3MintParams = [
|
|
5
|
+
string,
|
|
6
|
+
string,
|
|
7
|
+
FeeAmount,
|
|
8
|
+
number,
|
|
9
|
+
number,
|
|
10
|
+
ethers.BigNumber | string,
|
|
11
|
+
ethers.BigNumber | string,
|
|
12
|
+
ethers.BigNumber | string,
|
|
13
|
+
ethers.BigNumber | string,
|
|
14
|
+
string,
|
|
15
|
+
number
|
|
16
|
+
];
|
package/src/test/aave.test.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Dhedge
|
|
2
|
-
import { Network } from "../types";
|
|
3
|
-
import {
|
|
1
|
+
import { Dhedge } from "..";
|
|
2
|
+
import { Dapp, Network } from "../types";
|
|
3
|
+
import { TEST_POOL, WETH } from "./constants";
|
|
4
4
|
|
|
5
5
|
import { wallet } from "./wallet";
|
|
6
6
|
|
|
@@ -8,16 +8,32 @@ 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("100", "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 USDC to Aave", async () => {
|
|
22
|
+
// let result;
|
|
23
|
+
// const pool = await dhedge.loadPool(TEST_POOL);
|
|
24
|
+
// try {
|
|
25
|
+
// result = await pool.approve(
|
|
26
|
+
// Dapp.AAVEV3,
|
|
27
|
+
// USDC,
|
|
28
|
+
// ethers.constants.MaxUint256
|
|
29
|
+
// );
|
|
30
|
+
// console.log(result);
|
|
31
|
+
// } catch (e) {
|
|
32
|
+
// console.log(e);
|
|
33
|
+
// }
|
|
34
|
+
// expect(result).not.toBe(null);
|
|
35
|
+
// });
|
|
36
|
+
|
|
21
37
|
// it("withdraws 1 USDC from Aave lending pool", async () => {
|
|
22
38
|
// let result;
|
|
23
39
|
// const pool = await dhedge.loadPool(myPool);
|
|
@@ -35,11 +51,23 @@ describe("pool", () => {
|
|
|
35
51
|
// expect(result).not.toBe(null);
|
|
36
52
|
// });
|
|
37
53
|
|
|
38
|
-
|
|
54
|
+
it("borrows 0.001 WETH from Aave lending pool", async () => {
|
|
55
|
+
let result;
|
|
56
|
+
const pool = await dhedge.loadPool(TEST_POOL);
|
|
57
|
+
try {
|
|
58
|
+
result = await pool.borrow(Dapp.AAVEV3, WETH, "1000000000000000");
|
|
59
|
+
console.log(result);
|
|
60
|
+
} catch (e) {
|
|
61
|
+
console.log(e);
|
|
62
|
+
}
|
|
63
|
+
expect(result).not.toBe(null);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// it("reapys 1USDC to Aave lending pool", async () => {
|
|
39
67
|
// let result;
|
|
40
|
-
// const pool = await dhedge.loadPool(
|
|
68
|
+
// const pool = await dhedge.loadPool(TEST_POOL);
|
|
41
69
|
// try {
|
|
42
|
-
// result = await pool.
|
|
70
|
+
// result = await pool.repay(Dapp.AAVEV3, USDC, "1380000");
|
|
43
71
|
// console.log(result);
|
|
44
72
|
// } catch (e) {
|
|
45
73
|
// console.log(e);
|
|
@@ -47,11 +75,11 @@ describe("pool", () => {
|
|
|
47
75
|
// expect(result).not.toBe(null);
|
|
48
76
|
// });
|
|
49
77
|
|
|
50
|
-
// it("
|
|
78
|
+
// it("claims rewards from Aave", async () => {
|
|
51
79
|
// let result;
|
|
52
|
-
// const pool = await dhedge.loadPool(
|
|
80
|
+
// const pool = await dhedge.loadPool(TEST_POOL);
|
|
53
81
|
// try {
|
|
54
|
-
// result = await pool.
|
|
82
|
+
// result = await pool.harvestAaveRewards([AMUSDC, VDEBTWETH], options);
|
|
55
83
|
// console.log(result);
|
|
56
84
|
// } catch (e) {
|
|
57
85
|
// console.log(e);
|
|
@@ -59,15 +87,15 @@ describe("pool", () => {
|
|
|
59
87
|
// expect(result).not.toBe(null);
|
|
60
88
|
// });
|
|
61
89
|
|
|
62
|
-
it("
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
});
|
|
90
|
+
// it("lends USDC to Aave", async () => {
|
|
91
|
+
// let result;
|
|
92
|
+
// const pool = await dhedge.loadPool(TEST_POOL);
|
|
93
|
+
// try {
|
|
94
|
+
// const balance = await dhedge.utils.getBalance(WETH, pool.address);
|
|
95
|
+
// result = await pool.lend(Dapp.AAVEV3, WETH, balance, 196);
|
|
96
|
+
// } catch (e) {
|
|
97
|
+
// console.log(e);
|
|
98
|
+
// }
|
|
99
|
+
// expect(result).not.toBe(null);
|
|
100
|
+
// });
|
|
73
101
|
});
|
|
@@ -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,13 +1,21 @@
|
|
|
1
|
+
//Polygon
|
|
1
2
|
export const USDC = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174";
|
|
3
|
+
export const WETH = "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619";
|
|
2
4
|
export const USDT = "0xc2132D05D31c914a87C6611C10748AEb04B58e8F";
|
|
3
5
|
export const DAI = "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063";
|
|
4
6
|
export const TUSD = "0x2e1ad108ff1d8c782fcbbb89aad783ac49586756";
|
|
5
|
-
export const WETH = "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619";
|
|
6
7
|
export const WBTC = "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6";
|
|
7
8
|
export const SUSHI = "0x0b3f868e0be5597d5db7feb59e1cadbb0fdda50a";
|
|
8
9
|
export const WMATIC = "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270";
|
|
9
10
|
export const BAL = "0x9a71012B13CA4d3D0Cdc72A177DF3ef03b0E76A3";
|
|
10
11
|
export const AMUSDC = "0x1a13f4ca1d028320a707d99520abfefca3998b7f";
|
|
11
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";
|
|
12
20
|
|
|
13
|
-
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);
|
|
@@ -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,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
|
+
});
|
package/src/test/wallet.ts
CHANGED
|
@@ -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
|
);
|