@dhedge/v2-sdk 1.9.6 → 1.9.7
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/README.md +213 -76
- package/dist/entities/pool.d.ts +12 -6
- package/dist/test/constants.d.ts +22 -0
- package/dist/v2-sdk.cjs.development.js +175 -71
- 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 +175 -71
- package/dist/v2-sdk.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/config.ts +1 -1
- package/src/entities/pool.ts +46 -6
- package/src/test/arrakis.test.ts +119 -75
- package/src/test/constants.ts +32 -4
- package/src/test/uniswap.test.ts +101 -72
- package/dist/utils/index.d.ts +0 -7
- package/dist/utils/merkle.d.ts +0 -22
- package/src/utils/index.ts +0 -38
- package/src/utils/merkle.ts +0 -172
package/package.json
CHANGED
package/src/config.ts
CHANGED
|
@@ -47,7 +47,7 @@ export const routerAddress: AddressDappNetworkMap = {
|
|
|
47
47
|
},
|
|
48
48
|
[Network.ARBITRUM]: {
|
|
49
49
|
[Dapp.ONEINCH]: "0x1111111254EEB25477B68fb85Ed929f73A960582",
|
|
50
|
-
[Dapp.UNISWAPV3]: "
|
|
50
|
+
[Dapp.UNISWAPV3]: "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45",
|
|
51
51
|
[Dapp.AAVEV3]: "0x794a61358D6845594F94dc1DB02A252b5b4814aD",
|
|
52
52
|
[Dapp.BALANCER]: "0xBA12222222228d8Ba445958a75a0704d566BF2C8",
|
|
53
53
|
[Dapp.RAMSES]: "0xaaa87963efeb6f7e0a2711f397663105acb1805e"
|
package/src/entities/pool.ts
CHANGED
|
@@ -119,14 +119,19 @@ export class Pool {
|
|
|
119
119
|
* @param {string} nasset Address of deposit asset
|
|
120
120
|
* @param {BigNumber | string} amount Amount to be approved
|
|
121
121
|
* @param {any} options Transaction options
|
|
122
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
122
123
|
* @returns {Promise<any>} Transaction
|
|
123
124
|
*/
|
|
124
125
|
async approveDeposit(
|
|
125
126
|
asset: string,
|
|
126
127
|
amount: BigNumber | string,
|
|
127
|
-
options: any = null
|
|
128
|
+
options: any = null,
|
|
129
|
+
estimateGas = false
|
|
128
130
|
): Promise<any> {
|
|
129
131
|
const iERC20 = new ethers.Contract(asset, IERC20.abi, this.signer);
|
|
132
|
+
if (estimateGas) {
|
|
133
|
+
return await iERC20.estimateGas.approve(this.address, amount, options);
|
|
134
|
+
}
|
|
130
135
|
const tx = await iERC20.approve(this.address, amount, options);
|
|
131
136
|
return tx;
|
|
132
137
|
}
|
|
@@ -136,13 +141,18 @@ export class Pool {
|
|
|
136
141
|
* @param {string} asset Address of asset
|
|
137
142
|
* @param {BigNumber | string} amount Amount to be deposited
|
|
138
143
|
* @param {any} options Transaction options
|
|
144
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
139
145
|
* @returns {Promise<any>} Transaction
|
|
140
146
|
*/
|
|
141
147
|
async deposit(
|
|
142
148
|
asset: string,
|
|
143
149
|
amount: string | BigNumber,
|
|
144
|
-
options: any = null
|
|
150
|
+
options: any = null,
|
|
151
|
+
estimateGas = false
|
|
145
152
|
): Promise<any> {
|
|
153
|
+
if (estimateGas) {
|
|
154
|
+
return await this.poolLogic.estimateGas.deposit(asset, amount, options);
|
|
155
|
+
}
|
|
146
156
|
const tx = await this.poolLogic.deposit(asset, amount, options);
|
|
147
157
|
return tx;
|
|
148
158
|
}
|
|
@@ -151,12 +161,20 @@ export class Pool {
|
|
|
151
161
|
* Withdraw assets from a pool
|
|
152
162
|
* @param fundTokenAmount Amount of pool tokens to be withdrawn
|
|
153
163
|
* @param {any} options Transaction options
|
|
164
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
154
165
|
* @returns {Promise<any>} Transaction
|
|
155
166
|
*/
|
|
156
167
|
async withdraw(
|
|
157
168
|
fundTokenAmount: string | BigNumber,
|
|
158
|
-
options: any = null
|
|
169
|
+
options: any = null,
|
|
170
|
+
estimateGas = false
|
|
159
171
|
): Promise<any> {
|
|
172
|
+
if (estimateGas) {
|
|
173
|
+
return await this.poolLogic.estimateGas.withdraw(
|
|
174
|
+
fundTokenAmount,
|
|
175
|
+
options
|
|
176
|
+
);
|
|
177
|
+
}
|
|
160
178
|
const tx = await this.poolLogic.withdraw(fundTokenAmount, options);
|
|
161
179
|
return tx;
|
|
162
180
|
}
|
|
@@ -742,11 +760,13 @@ export class Pool {
|
|
|
742
760
|
* Change enabled pool assets
|
|
743
761
|
* @param {AssetEnabled[]} assets New pool assets
|
|
744
762
|
* @param {any} options Transaction options
|
|
763
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
745
764
|
* @returns {Promise<any>} Transaction
|
|
746
765
|
*/
|
|
747
766
|
public async changeAssets(
|
|
748
767
|
assets: AssetEnabled[],
|
|
749
|
-
options: any = null
|
|
768
|
+
options: any = null,
|
|
769
|
+
estimateGas = false
|
|
750
770
|
): Promise<any> {
|
|
751
771
|
const currentAssetsEnabled = await this.getComposition();
|
|
752
772
|
const currentAssets = currentAssetsEnabled.map(e =>
|
|
@@ -755,6 +775,14 @@ export class Pool {
|
|
|
755
775
|
const newAssets = assets.map(e => e.asset.toLocaleLowerCase());
|
|
756
776
|
const removedAssets = currentAssets.filter(e => !newAssets.includes(e));
|
|
757
777
|
const changedAssets = assets.map(e => [e.asset, e.isDeposit]);
|
|
778
|
+
|
|
779
|
+
if (estimateGas) {
|
|
780
|
+
return await this.managerLogic.estimateGas.changeAssets(
|
|
781
|
+
changedAssets,
|
|
782
|
+
removedAssets,
|
|
783
|
+
options
|
|
784
|
+
);
|
|
785
|
+
}
|
|
758
786
|
const tx = await this.managerLogic.changeAssets(
|
|
759
787
|
changedAssets,
|
|
760
788
|
removedAssets,
|
|
@@ -767,9 +795,17 @@ export class Pool {
|
|
|
767
795
|
* Set a new trader with trading permissions
|
|
768
796
|
* @param {string} trader Address trader account
|
|
769
797
|
* @param {any} options Transaction options
|
|
798
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
770
799
|
* @returns {Promise<any>} Transaction
|
|
771
800
|
*/
|
|
772
|
-
async setTrader(
|
|
801
|
+
async setTrader(
|
|
802
|
+
trader: string,
|
|
803
|
+
options: any = null,
|
|
804
|
+
estimateGas = false
|
|
805
|
+
): Promise<any> {
|
|
806
|
+
if (estimateGas) {
|
|
807
|
+
return await this.managerLogic.estimateGas.setTrader(trader, options);
|
|
808
|
+
}
|
|
773
809
|
const tx = await this.managerLogic.setTrader(trader, options);
|
|
774
810
|
return tx;
|
|
775
811
|
}
|
|
@@ -1526,9 +1562,13 @@ export class Pool {
|
|
|
1526
1562
|
/**
|
|
1527
1563
|
* mintManagerFee
|
|
1528
1564
|
* @param {any} options Transaction options
|
|
1565
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
1529
1566
|
* @returns {Promise<any>} Transaction
|
|
1530
1567
|
*/
|
|
1531
|
-
async mintManagerFee(options: any = null): Promise<any> {
|
|
1568
|
+
async mintManagerFee(options: any = null, estimateGas = false): Promise<any> {
|
|
1569
|
+
if (estimateGas) {
|
|
1570
|
+
return await this.poolLogic.estimateGas.mintManagerFee(options);
|
|
1571
|
+
}
|
|
1532
1572
|
const tx = await this.poolLogic.mintManagerFee(options);
|
|
1533
1573
|
return tx;
|
|
1534
1574
|
}
|
package/src/test/arrakis.test.ts
CHANGED
|
@@ -1,95 +1,139 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
import BigNumber from "bignumber.js";
|
|
3
4
|
import { Dhedge, Pool } from "..";
|
|
4
5
|
import { routerAddress } from "../config";
|
|
5
|
-
import { Dapp, Network } from "../types";
|
|
6
|
+
import { AssetEnabled, Dapp, Network } from "../types";
|
|
6
7
|
import { CONTRACT_ADDRESS, MAX_AMOUNT, TEST_POOL } from "./constants";
|
|
8
|
+
import {
|
|
9
|
+
TestingRunParams,
|
|
10
|
+
setUSDCAmount,
|
|
11
|
+
testingHelper,
|
|
12
|
+
wait
|
|
13
|
+
} from "./utils/testingHelper";
|
|
7
14
|
import { allowanceDelta, balanceDelta } from "./utils/token";
|
|
8
15
|
|
|
9
|
-
import { wallet } from "./wallet";
|
|
10
|
-
|
|
11
16
|
//const network = Network.OPTIMISM;
|
|
12
17
|
const network = Network.POLYGON;
|
|
13
18
|
const USDC = CONTRACT_ADDRESS[network].USDC;
|
|
14
19
|
const WETH = CONTRACT_ADDRESS[network].WETH;
|
|
15
|
-
|
|
16
|
-
let dhedge: Dhedge;
|
|
17
|
-
let pool: Pool;
|
|
18
20
|
jest.setTimeout(100000);
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
pool = await dhedge.loadPool(TEST_POOL[network]);
|
|
24
|
-
await pool.approve(Dapp.ONEINCH, USDC, MAX_AMOUNT);
|
|
25
|
-
await pool.trade(Dapp.ONEINCH, USDC, WETH, "1000000", 0.5);
|
|
26
|
-
});
|
|
22
|
+
const testArrakis = ({ wallet, network, provider }: TestingRunParams) => {
|
|
23
|
+
let dhedge: Dhedge;
|
|
24
|
+
let pool: Pool;
|
|
27
25
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
pool.
|
|
32
|
-
USDC,
|
|
33
|
-
routerAddress[network].arrakis!,
|
|
34
|
-
pool.signer
|
|
35
|
-
);
|
|
36
|
-
await expect(usdcAllowanceDelta.gt(0));
|
|
37
|
-
});
|
|
26
|
+
describe("pool", () => {
|
|
27
|
+
beforeAll(async () => {
|
|
28
|
+
dhedge = new Dhedge(wallet, network);
|
|
29
|
+
pool = await dhedge.loadPool(TEST_POOL[network]);
|
|
38
30
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
31
|
+
// top up gas
|
|
32
|
+
await provider.send("hardhat_setBalance", [
|
|
33
|
+
wallet.address,
|
|
34
|
+
"0x10000000000000000"
|
|
35
|
+
]);
|
|
36
|
+
await provider.send("evm_mine", []);
|
|
37
|
+
await setUSDCAmount({
|
|
38
|
+
amount: new BigNumber(10000000).times(1e6).toFixed(0),
|
|
39
|
+
userAddress: pool.address,
|
|
40
|
+
network,
|
|
41
|
+
provider
|
|
42
|
+
});
|
|
49
43
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
44
|
+
const newAssets: AssetEnabled[] = [
|
|
45
|
+
{ asset: CONTRACT_ADDRESS[network].USDC, isDeposit: true },
|
|
46
|
+
{ asset: CONTRACT_ADDRESS[network].WETH, isDeposit: true },
|
|
47
|
+
{
|
|
48
|
+
asset: CONTRACT_ADDRESS[network].ARRAKIS_USDC_WETH_GAUGE,
|
|
49
|
+
isDeposit: false
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
asset: CONTRACT_ADDRESS[network].WMATIC, // reward token
|
|
53
|
+
isDeposit: false
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
asset: CONTRACT_ADDRESS[network].uniswapV3.nonfungiblePositionManager,
|
|
57
|
+
isDeposit: false
|
|
58
|
+
}
|
|
59
|
+
];
|
|
60
|
+
await pool.changeAssets(newAssets);
|
|
61
|
+
await pool.approve(Dapp.ONEINCH, USDC, MAX_AMOUNT);
|
|
62
|
+
await pool.trade(Dapp.ONEINCH, USDC, WETH, "10000000", 0.5, null, false);
|
|
63
|
+
});
|
|
66
64
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
65
|
+
it("approves unlimited USDC on Arrakis", async () => {
|
|
66
|
+
await pool.approve(Dapp.ARRAKIS, USDC, MAX_AMOUNT);
|
|
67
|
+
const usdcAllowanceDelta = await allowanceDelta(
|
|
68
|
+
pool.address,
|
|
69
|
+
USDC,
|
|
70
|
+
routerAddress[network].arrakis!,
|
|
71
|
+
pool.signer
|
|
72
|
+
);
|
|
73
|
+
await expect(usdcAllowanceDelta.gt(0));
|
|
74
|
+
await wait(5);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("approves unlimited WETH on Arrakis", async () => {
|
|
78
|
+
await pool.approve(Dapp.ARRAKIS, WETH, MAX_AMOUNT);
|
|
79
|
+
const wethAllowanceDelta = await allowanceDelta(
|
|
80
|
+
pool.address,
|
|
81
|
+
USDC,
|
|
82
|
+
routerAddress[network].arrakis!,
|
|
83
|
+
pool.signer
|
|
84
|
+
);
|
|
85
|
+
await expect(wethAllowanceDelta.gt(0));
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("should add liquidity and stake in an WETH/USDC Arrakis pool", async () => {
|
|
89
|
+
const usdcBalance = await pool.utils.getBalance(USDC, pool.address);
|
|
90
|
+
const wethBalance = await pool.utils.getBalance(WETH, pool.address);
|
|
91
|
+
await pool.increaseLiquidity(
|
|
92
|
+
Dapp.ARRAKIS,
|
|
93
|
+
CONTRACT_ADDRESS[network].ARRAKIS_USDC_WETH_GAUGE,
|
|
94
|
+
usdcBalance,
|
|
95
|
+
wethBalance
|
|
96
|
+
);
|
|
97
|
+
const lpBalanceDelta = await balanceDelta(
|
|
98
|
+
pool.address,
|
|
99
|
+
CONTRACT_ADDRESS[network].ARRAKIS_USDC_WETH_LP,
|
|
100
|
+
pool.signer
|
|
101
|
+
);
|
|
102
|
+
expect(lpBalanceDelta.gt(0));
|
|
103
|
+
});
|
|
81
104
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
105
|
+
it("approves unlimited LP staking Token before on Arrakis", async () => {
|
|
106
|
+
await pool.approve(
|
|
107
|
+
Dapp.ARRAKIS,
|
|
108
|
+
CONTRACT_ADDRESS[network].ARRAKIS_USDC_WETH_GAUGE,
|
|
109
|
+
MAX_AMOUNT
|
|
110
|
+
);
|
|
111
|
+
const gaugeAllowanceDelta = await allowanceDelta(
|
|
112
|
+
pool.address,
|
|
113
|
+
CONTRACT_ADDRESS[network].ARRAKIS_USDC_WETH_GAUGE,
|
|
114
|
+
routerAddress[network].arrakis!,
|
|
115
|
+
pool.signer
|
|
116
|
+
);
|
|
117
|
+
await expect(gaugeAllowanceDelta.gt(0));
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("should remove liquidity from an existing pool ", async () => {
|
|
121
|
+
await pool.decreaseLiquidity(
|
|
122
|
+
Dapp.ARRAKIS,
|
|
123
|
+
CONTRACT_ADDRESS[network].ARRAKIS_USDC_WETH_GAUGE,
|
|
124
|
+
100
|
|
125
|
+
);
|
|
126
|
+
const wethBalanceDelta = await balanceDelta(
|
|
127
|
+
pool.address,
|
|
128
|
+
CONTRACT_ADDRESS[network].WETH,
|
|
129
|
+
pool.signer
|
|
130
|
+
);
|
|
131
|
+
expect(wethBalanceDelta.gt(0));
|
|
132
|
+
});
|
|
94
133
|
});
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
testingHelper({
|
|
137
|
+
network: Network.POLYGON,
|
|
138
|
+
testingRun: testArrakis
|
|
95
139
|
});
|
package/src/test/constants.ts
CHANGED
|
@@ -52,15 +52,27 @@ export const CONTRACT_ADDRESS = {
|
|
|
52
52
|
WETH: "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619",
|
|
53
53
|
WBTC: "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6",
|
|
54
54
|
ARRAKIS_USDC_WETH_GAUGE: "0x33d1ad9Cd88A509397CD924C2d7613C285602C20",
|
|
55
|
-
ARRAKIS_USDC_WETH_LP: "0xa173340f1e942c2845bcbce8ebd411022e18eb13"
|
|
55
|
+
ARRAKIS_USDC_WETH_LP: "0xa173340f1e942c2845bcbce8ebd411022e18eb13",
|
|
56
|
+
WMATIC: "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270",
|
|
57
|
+
uniswapV3: {
|
|
58
|
+
nonfungiblePositionManager: "0xC36442b4a4522E871399CD717aBDD847Ab11FE88"
|
|
59
|
+
}
|
|
56
60
|
},
|
|
61
|
+
|
|
57
62
|
[Network.OPTIMISM]: {
|
|
58
63
|
USDC: "0x7F5c764cBc14f9669B88837ca1490cCa17c31607",
|
|
59
64
|
SUSD: "0x8c6f28f2f1a3c87f0f938b96d27520d9751ec8d9",
|
|
60
65
|
SWETH: "",
|
|
61
66
|
WETH: "0x4200000000000000000000000000000000000006",
|
|
62
67
|
WBTC: "0x68f180fcCe6836688e9084f035309E29Bf0A2095",
|
|
63
|
-
KWENTA_ETH_PERP_V2: "0x2b3bb4c683bfc5239b029131eef3b1d214478d93"
|
|
68
|
+
KWENTA_ETH_PERP_V2: "0x2b3bb4c683bfc5239b029131eef3b1d214478d93",
|
|
69
|
+
uniswapV3: {
|
|
70
|
+
nonfungiblePositionManager: "0xC36442b4a4522E871399CD717aBDD847Ab11FE88"
|
|
71
|
+
},
|
|
72
|
+
WMATIC: "",
|
|
73
|
+
//
|
|
74
|
+
ARRAKIS_USDC_WETH_GAUGE: "",
|
|
75
|
+
ARRAKIS_USDC_WETH_LP: ""
|
|
64
76
|
},
|
|
65
77
|
[Network.ARBITRUM]: {
|
|
66
78
|
USDC: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
@@ -69,13 +81,29 @@ export const CONTRACT_ADDRESS = {
|
|
|
69
81
|
WBTC: "0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f",
|
|
70
82
|
WSTETH: "0x5979d7b546e38e414f7e9822514be443a4800529",
|
|
71
83
|
BALANCER_WSTETH_WETH_POOL: "0x36bf227d6bac96e2ab1ebb5492ecec69c691943f",
|
|
72
|
-
BALANCER_WSTETH_WETH_GAUGE: "0x251e51b25afa40f2b6b9f05aaf1bc7eaa0551771"
|
|
84
|
+
BALANCER_WSTETH_WETH_GAUGE: "0x251e51b25afa40f2b6b9f05aaf1bc7eaa0551771",
|
|
85
|
+
|
|
86
|
+
uniswapV3: {
|
|
87
|
+
nonfungiblePositionManager: "0xC36442b4a4522E871399CD717aBDD847Ab11FE88"
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
//
|
|
91
|
+
ARRAKIS_USDC_WETH_GAUGE: "",
|
|
92
|
+
ARRAKIS_USDC_WETH_LP: "",
|
|
93
|
+
WMATIC: ""
|
|
73
94
|
},
|
|
74
95
|
[Network.BASE]: {
|
|
75
96
|
USDC: "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
|
|
76
97
|
WETH: "0x4200000000000000000000000000000000000006",
|
|
77
98
|
WBTC: "",
|
|
78
|
-
SWETH: ""
|
|
99
|
+
SWETH: "",
|
|
100
|
+
uniswapV3: {
|
|
101
|
+
nonfungiblePositionManager: ""
|
|
102
|
+
},
|
|
103
|
+
//
|
|
104
|
+
ARRAKIS_USDC_WETH_GAUGE: "",
|
|
105
|
+
ARRAKIS_USDC_WETH_LP: "",
|
|
106
|
+
WMATIC: ""
|
|
79
107
|
}
|
|
80
108
|
};
|
|
81
109
|
|
package/src/test/uniswap.test.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { FeeAmount } from "@uniswap/v3-sdk";
|
|
3
3
|
import { Dhedge, ethers, Pool } from "..";
|
|
4
4
|
import { routerAddress } from "../config";
|
|
5
|
-
import { Dapp, Network } from "../types";
|
|
5
|
+
import { AssetEnabled, Dapp, Network } from "../types";
|
|
6
6
|
import { CONTRACT_ADDRESS, TEST_POOL } from "./constants";
|
|
7
7
|
import { allowanceDelta, balanceDelta } from "./utils/token";
|
|
8
8
|
import {
|
|
@@ -11,12 +11,15 @@ import {
|
|
|
11
11
|
TestingRunParams
|
|
12
12
|
} from "./utils/testingHelper";
|
|
13
13
|
import BigNumber from "bignumber.js";
|
|
14
|
+
import INonfungiblePositionManager from "../abi/INonfungiblePositionManager.json";
|
|
14
15
|
|
|
15
16
|
const testUniswapV3 = ({ wallet, network, provider }: TestingRunParams) => {
|
|
16
17
|
let dhedge: Dhedge;
|
|
17
18
|
let pool: Pool;
|
|
19
|
+
let nonfungiblePositionManager: ethers.Contract;
|
|
20
|
+
let tokenId: ethers.BigNumber;
|
|
18
21
|
|
|
19
|
-
jest.setTimeout(
|
|
22
|
+
jest.setTimeout(600000);
|
|
20
23
|
describe(`testUniswapV3 on ${network}`, () => {
|
|
21
24
|
beforeAll(async () => {
|
|
22
25
|
dhedge = new Dhedge(wallet, network);
|
|
@@ -29,11 +32,27 @@ const testUniswapV3 = ({ wallet, network, provider }: TestingRunParams) => {
|
|
|
29
32
|
]);
|
|
30
33
|
await provider.send("evm_mine", []);
|
|
31
34
|
await setUSDCAmount({
|
|
32
|
-
amount: new BigNumber(
|
|
35
|
+
amount: new BigNumber(1000000).times(1e6).toFixed(0),
|
|
33
36
|
userAddress: pool.address,
|
|
34
37
|
network,
|
|
35
38
|
provider
|
|
36
39
|
});
|
|
40
|
+
|
|
41
|
+
const newAssets: AssetEnabled[] = [
|
|
42
|
+
{ asset: CONTRACT_ADDRESS[network].USDC, isDeposit: true },
|
|
43
|
+
{ asset: CONTRACT_ADDRESS[network].WETH, isDeposit: true },
|
|
44
|
+
{
|
|
45
|
+
asset: CONTRACT_ADDRESS[network].uniswapV3.nonfungiblePositionManager,
|
|
46
|
+
isDeposit: false
|
|
47
|
+
}
|
|
48
|
+
];
|
|
49
|
+
await pool.changeAssets(newAssets);
|
|
50
|
+
|
|
51
|
+
nonfungiblePositionManager = new ethers.Contract(
|
|
52
|
+
CONTRACT_ADDRESS[network].uniswapV3.nonfungiblePositionManager,
|
|
53
|
+
INonfungiblePositionManager.abi,
|
|
54
|
+
pool.signer
|
|
55
|
+
);
|
|
37
56
|
});
|
|
38
57
|
|
|
39
58
|
it("approves unlimited USDC on for trading on UniswapV3", async () => {
|
|
@@ -52,11 +71,11 @@ const testUniswapV3 = ({ wallet, network, provider }: TestingRunParams) => {
|
|
|
52
71
|
expect(UsdcAllowanceDelta.gte(0));
|
|
53
72
|
});
|
|
54
73
|
|
|
55
|
-
it("should swap
|
|
74
|
+
it("should swap 5000 USDC into WETH on UniswapV3", async () => {
|
|
56
75
|
await pool.tradeUniswapV3(
|
|
57
76
|
CONTRACT_ADDRESS[network].USDC,
|
|
58
77
|
CONTRACT_ADDRESS[network].WETH,
|
|
59
|
-
|
|
78
|
+
new BigNumber(5000).times(1e6).toFixed(0),
|
|
60
79
|
FeeAmount.LOW,
|
|
61
80
|
0.5
|
|
62
81
|
);
|
|
@@ -69,78 +88,88 @@ const testUniswapV3 = ({ wallet, network, provider }: TestingRunParams) => {
|
|
|
69
88
|
expect(wethAllowanceDelta.gt(0));
|
|
70
89
|
});
|
|
71
90
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
91
|
+
it("approves unlimited WETH on for UniswapV3 LP", async () => {
|
|
92
|
+
await pool.approveUniswapV3Liquidity(
|
|
93
|
+
CONTRACT_ADDRESS[network].USDC,
|
|
94
|
+
ethers.constants.MaxInt256
|
|
95
|
+
);
|
|
96
|
+
await pool.approveUniswapV3Liquidity(
|
|
97
|
+
CONTRACT_ADDRESS[network].WETH,
|
|
98
|
+
ethers.constants.MaxInt256
|
|
99
|
+
);
|
|
100
|
+
const UsdcAllowanceDelta = await allowanceDelta(
|
|
101
|
+
pool.address,
|
|
102
|
+
CONTRACT_ADDRESS[network].USDC,
|
|
103
|
+
pool.address,
|
|
104
|
+
pool.signer
|
|
105
|
+
);
|
|
83
106
|
|
|
84
|
-
|
|
85
|
-
|
|
107
|
+
expect(UsdcAllowanceDelta).not.toBe(null);
|
|
108
|
+
});
|
|
86
109
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
110
|
+
it("adds WETH and USDC to a new V3 pool", async () => {
|
|
111
|
+
let result = null;
|
|
112
|
+
const pool = await dhedge.loadPool(TEST_POOL[network]);
|
|
113
|
+
const usdcBalance = await dhedge.utils.getBalance(
|
|
114
|
+
CONTRACT_ADDRESS[network].USDC,
|
|
115
|
+
pool.address
|
|
116
|
+
);
|
|
117
|
+
const wethBalance = await dhedge.utils.getBalance(
|
|
118
|
+
CONTRACT_ADDRESS[network].WETH,
|
|
119
|
+
pool.address
|
|
120
|
+
);
|
|
92
121
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
122
|
+
try {
|
|
123
|
+
result = await pool.addLiquidityUniswapV3(
|
|
124
|
+
CONTRACT_ADDRESS[network].WETH,
|
|
125
|
+
CONTRACT_ADDRESS[network].USDC,
|
|
126
|
+
wethBalance,
|
|
127
|
+
usdcBalance,
|
|
128
|
+
2000,
|
|
129
|
+
3000,
|
|
130
|
+
null,
|
|
131
|
+
null,
|
|
132
|
+
FeeAmount.LOW
|
|
133
|
+
// options
|
|
134
|
+
);
|
|
135
|
+
await result.wait(1);
|
|
136
|
+
|
|
137
|
+
tokenId = await nonfungiblePositionManager.tokenOfOwnerByIndex(
|
|
138
|
+
pool.address,
|
|
139
|
+
0
|
|
140
|
+
);
|
|
141
|
+
} catch (e) {
|
|
142
|
+
console.log("e", e);
|
|
143
|
+
}
|
|
144
|
+
expect(result).not.toBe(null);
|
|
145
|
+
});
|
|
112
146
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
// expect(result).not.toBe(null);
|
|
123
|
-
// });
|
|
147
|
+
it("should remove liquidity from an existing pool ", async () => {
|
|
148
|
+
const result = await pool.decreaseLiquidity(
|
|
149
|
+
Dapp.UNISWAPV3,
|
|
150
|
+
tokenId.toString(),
|
|
151
|
+
50 // precent
|
|
152
|
+
);
|
|
153
|
+
// console.log("result", result);
|
|
154
|
+
expect(result).not.toBe(null);
|
|
155
|
+
});
|
|
124
156
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
// expect(result).not.toBe(null);
|
|
136
|
-
// });
|
|
157
|
+
it("should increase liquidity in the existing WETH/USDC pool", async () => {
|
|
158
|
+
const result = await pool.increaseLiquidity(
|
|
159
|
+
Dapp.UNISWAPV3,
|
|
160
|
+
tokenId.toString(),
|
|
161
|
+
new BigNumber(3000).times(1e6).toFixed(0), // usdc
|
|
162
|
+
new BigNumber(1).times(1e18).toFixed(0) // eth
|
|
163
|
+
);
|
|
164
|
+
// console.log("result", result);
|
|
165
|
+
expect(result).not.toBe(null);
|
|
166
|
+
});
|
|
137
167
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
// });
|
|
168
|
+
it("should claim fees an existing pool", async () => {
|
|
169
|
+
const result = await pool.claimFees(Dapp.UNISWAPV3, tokenId.toString());
|
|
170
|
+
// console.log("result", result);
|
|
171
|
+
expect(result).not.toBe(null);
|
|
172
|
+
});
|
|
144
173
|
|
|
145
174
|
// it("approves unlimited USDC to swap on UniswapV3", async () => {
|
|
146
175
|
// let result;
|
|
@@ -187,6 +216,6 @@ testingHelper({
|
|
|
187
216
|
});
|
|
188
217
|
|
|
189
218
|
testingHelper({
|
|
190
|
-
network: Network.
|
|
219
|
+
network: Network.ARBITRUM,
|
|
191
220
|
testingRun: testUniswapV3
|
|
192
221
|
});
|
package/dist/utils/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import BigNumber from "bignumber.js";
|
|
2
|
-
import { MerkleTree } from "./merkle";
|
|
3
|
-
export declare function scale(input: BigNumber | string, decimalPlaces: number): BigNumber;
|
|
4
|
-
export declare function loadTree(balances: {
|
|
5
|
-
[x: string]: string | BigNumber;
|
|
6
|
-
}, decimals?: number): MerkleTree;
|
|
7
|
-
export declare function bnum(val: string | number | BigNumber): BigNumber;
|