@dhedge/v2-sdk 1.9.1 → 1.9.3
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 +2 -2
- package/dist/entities/pool.d.ts +11 -0
- package/dist/services/oneInch/index.d.ts +3 -0
- package/dist/test/constants.d.ts +1 -0
- package/dist/test/utils/testingHelper.d.ts +20 -0
- package/dist/test/wallet.d.ts +10 -0
- package/dist/v2-sdk.cjs.development.js +166 -107
- 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 +166 -107
- package/dist/v2-sdk.esm.js.map +1 -1
- package/package.json +4 -4
- package/src/entities/pool.ts +27 -22
- package/src/services/oneInch/index.ts +33 -0
- package/src/test/constants.ts +1 -0
- package/src/test/oneInch.test.ts +40 -32
- package/src/test/pool.test.ts +90 -46
- package/src/test/utils/testingHelper.ts +42 -0
- package/src/test/utils.test.ts +70 -49
- package/src/test/wallet.ts +22 -1
- package/src/test/zeroEx.test.ts +40 -32
- package/dist/services/oneInch/protocols.d.ts +0 -1
- package/src/services/oneInch/protocols.ts +0 -17
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dhedge/v2-sdk",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "🛠 An SDK for building applications on top of dHEDGE V2",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
"prepare": "tsdx build",
|
|
21
21
|
"size": "size-limit",
|
|
22
22
|
"analyze": "size-limit --why",
|
|
23
|
-
"fork:polygon": "hardhat node --fork $(grep POLYGON_URL .env | cut -d '=' -f2)",
|
|
24
|
-
"fork:optimism": "hardhat node --fork $(grep OPTIMISM_URL .env | cut -d '=' -f2)",
|
|
25
|
-
"fork:arbitrum": "hardhat node --fork $(grep ARBITRUM_URL .env | cut -d '=' -f2)"
|
|
23
|
+
"fork:polygon": "hardhat node --port 8542 --fork $(grep POLYGON_URL .env | cut -d '=' -f2)",
|
|
24
|
+
"fork:optimism": "hardhat node --port 8544 --fork $(grep OPTIMISM_URL .env | cut -d '=' -f2)",
|
|
25
|
+
"fork:arbitrum": "hardhat node --port 8540 --fork $(grep ARBITRUM_URL .env | cut -d '=' -f2)"
|
|
26
26
|
},
|
|
27
27
|
"husky": {
|
|
28
28
|
"hooks": {
|
package/src/entities/pool.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
-
import axios from "axios";
|
|
4
3
|
import { Contract, ethers, Wallet, BigNumber } from "ethers";
|
|
5
4
|
|
|
6
5
|
import IERC20 from "../abi/IERC20.json";
|
|
@@ -16,7 +15,6 @@ import IBalancerRewardsGauge from "../abi/IBalancerRewardsGauge.json";
|
|
|
16
15
|
|
|
17
16
|
import {
|
|
18
17
|
MaxUint128,
|
|
19
|
-
networkChainIdMap,
|
|
20
18
|
nonfungiblePositionManagerAddress,
|
|
21
19
|
routerAddress,
|
|
22
20
|
stakingAddress,
|
|
@@ -42,7 +40,6 @@ import {
|
|
|
42
40
|
import { FeeAmount } from "@uniswap/v3-sdk";
|
|
43
41
|
import { getUniswapV3SwapTxData } from "../services/uniswap/V3Trade";
|
|
44
42
|
import { getEasySwapperTxData } from "../services/toros/easySwapper";
|
|
45
|
-
import { getOneInchProtocols } from "../services/oneInch/protocols";
|
|
46
43
|
import { getAaveV3ClaimTxData } from "../services/aave/incentives";
|
|
47
44
|
import {
|
|
48
45
|
getVelodromeAddLiquidityTxData,
|
|
@@ -61,7 +58,7 @@ import {
|
|
|
61
58
|
} from "../services/futures";
|
|
62
59
|
import { getFuturesCancelOrderTxData } from "../services/futures/trade";
|
|
63
60
|
import { getZeroExTradeTxData } from "../services/zeroEx/zeroExTrade";
|
|
64
|
-
import {
|
|
61
|
+
import { getOneInchSwapTxData } from "../services/oneInch";
|
|
65
62
|
|
|
66
63
|
export class Pool {
|
|
67
64
|
public readonly poolLogic: Contract;
|
|
@@ -299,24 +296,13 @@ export class Pool {
|
|
|
299
296
|
);
|
|
300
297
|
break;
|
|
301
298
|
case Dapp.ONEINCH:
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
this.address
|
|
310
|
-
}&destReceiver=${
|
|
311
|
-
this.address
|
|
312
|
-
}&slippage=${slippage.toString()}&disableEstimate=true${protocols}`;
|
|
313
|
-
try {
|
|
314
|
-
const response = await axios.get(apiUrl);
|
|
315
|
-
swapTxData = response.data.tx.data;
|
|
316
|
-
} catch (e) {
|
|
317
|
-
throw new ApiError("Swap api request of 1inch failed");
|
|
318
|
-
}
|
|
319
|
-
|
|
299
|
+
swapTxData = await getOneInchSwapTxData(
|
|
300
|
+
this,
|
|
301
|
+
assetFrom,
|
|
302
|
+
assetTo,
|
|
303
|
+
amountIn,
|
|
304
|
+
slippage
|
|
305
|
+
);
|
|
320
306
|
break;
|
|
321
307
|
case Dapp.BALANCER:
|
|
322
308
|
swapTxData = await this.utils.getBalancerSwapTx(
|
|
@@ -1355,4 +1341,23 @@ export class Pool {
|
|
|
1355
1341
|
const tx = await this.poolLogic.execTransaction(market, txData, options);
|
|
1356
1342
|
return tx;
|
|
1357
1343
|
}
|
|
1344
|
+
|
|
1345
|
+
/**
|
|
1346
|
+
* mintManagerFee
|
|
1347
|
+
* @param {any} options Transaction options
|
|
1348
|
+
* @returns {Promise<any>} Transaction
|
|
1349
|
+
*/
|
|
1350
|
+
async mintManagerFee(options: any = null): Promise<any> {
|
|
1351
|
+
const tx = await this.poolLogic.mintManagerFee(options);
|
|
1352
|
+
return tx;
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
/**
|
|
1356
|
+
* getAvailableManagerFee
|
|
1357
|
+
* @returns {Promise<BigNumber>} fee
|
|
1358
|
+
*/
|
|
1359
|
+
async getAvailableManagerFee(): Promise<BigNumber> {
|
|
1360
|
+
const fee = await this.poolLogic.availableManagerFee();
|
|
1361
|
+
return BigNumber.from(fee);
|
|
1362
|
+
}
|
|
1358
1363
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
import { ApiError, ethers } from "../..";
|
|
4
|
+
import { networkChainIdMap } from "../../config";
|
|
5
|
+
import { Pool } from "../../entities";
|
|
6
|
+
|
|
7
|
+
const oneInchBaseUrl = "https://api.1inch.dev/swap/v5.2/";
|
|
8
|
+
|
|
9
|
+
export async function getOneInchSwapTxData(
|
|
10
|
+
pool: Pool,
|
|
11
|
+
assetFrom: string,
|
|
12
|
+
assetTo: string,
|
|
13
|
+
amountIn: ethers.BigNumber | string,
|
|
14
|
+
slippage: number
|
|
15
|
+
): Promise<string> {
|
|
16
|
+
if (!process.env.ONEINCH_API_KEY)
|
|
17
|
+
throw new Error("ONEINCH_API_KEY not configured in .env file");
|
|
18
|
+
|
|
19
|
+
const chainId = networkChainIdMap[pool.network];
|
|
20
|
+
const apiUrl = `${oneInchBaseUrl}${chainId}/swap?src=${assetFrom}&dst=${assetTo}&amount=${amountIn.toString()}&from=${
|
|
21
|
+
pool.address
|
|
22
|
+
}&slippage=${slippage.toString()}&disableEstimate=true`;
|
|
23
|
+
try {
|
|
24
|
+
const response = await axios.get(apiUrl, {
|
|
25
|
+
headers: {
|
|
26
|
+
Authorization: `Bearer ${process.env.ONEINCH_API_KEY}`
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return response.data.tx.data;
|
|
30
|
+
} catch (e) {
|
|
31
|
+
throw new ApiError("Swap api request of 1inch failed");
|
|
32
|
+
}
|
|
33
|
+
}
|
package/src/test/constants.ts
CHANGED
|
@@ -56,6 +56,7 @@ export const CONTRACT_ADDRESS = {
|
|
|
56
56
|
USDC: "0x7F5c764cBc14f9669B88837ca1490cCa17c31607",
|
|
57
57
|
SUSD: "0x8c6f28f2f1a3c87f0f938b96d27520d9751ec8d9",
|
|
58
58
|
WETH: "0x4200000000000000000000000000000000000006",
|
|
59
|
+
WBTC: "0x68f180fcCe6836688e9084f035309E29Bf0A2095",
|
|
59
60
|
KWENTA_ETH_PERP_V2: "0x2b3bb4c683bfc5239b029131eef3b1d214478d93"
|
|
60
61
|
},
|
|
61
62
|
[Network.ARBITRUM]: {
|
package/src/test/oneInch.test.ts
CHANGED
|
@@ -3,44 +3,52 @@ import { Dhedge, Pool } from "..";
|
|
|
3
3
|
import { routerAddress } from "../config";
|
|
4
4
|
import { Dapp, Network } from "../types";
|
|
5
5
|
import { CONTRACT_ADDRESS, MAX_AMOUNT, TEST_POOL } from "./constants";
|
|
6
|
+
import { TestingRunParams, testingHelper } from "./utils/testingHelper";
|
|
6
7
|
import { allowanceDelta, balanceDelta } from "./utils/token";
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
const testOneInch = ({ wallet, network }: TestingRunParams) => {
|
|
10
|
+
const USDC = CONTRACT_ADDRESS[network].USDC;
|
|
11
|
+
const WETH = CONTRACT_ADDRESS[network].WETH;
|
|
9
12
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const USDC = CONTRACT_ADDRESS[network].USDC;
|
|
14
|
-
const WETH = CONTRACT_ADDRESS[network].WETH;
|
|
13
|
+
let dhedge: Dhedge;
|
|
14
|
+
let pool: Pool;
|
|
15
|
+
jest.setTimeout(100000);
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
describe(`pool on ${network}`, () => {
|
|
18
|
+
beforeAll(async () => {
|
|
19
|
+
dhedge = new Dhedge(wallet, network);
|
|
20
|
+
pool = await dhedge.loadPool(TEST_POOL[network]);
|
|
21
|
+
});
|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
it("approves unlimited USDC on 1Inch", async () => {
|
|
24
|
+
await pool.approve(Dapp.ONEINCH, USDC, MAX_AMOUNT);
|
|
25
|
+
const usdcAllowanceDelta = await allowanceDelta(
|
|
26
|
+
pool.address,
|
|
27
|
+
USDC,
|
|
28
|
+
routerAddress[network]["1inch"]!,
|
|
29
|
+
pool.signer
|
|
30
|
+
);
|
|
31
|
+
await expect(usdcAllowanceDelta.gt(0));
|
|
32
|
+
});
|
|
25
33
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
it("trades 2 USDC into WETH on 1Inch", async () => {
|
|
35
|
+
await pool.trade(Dapp.ONEINCH, USDC, WETH, "2000000", 0.5);
|
|
36
|
+
const wethBalanceDelta = await balanceDelta(
|
|
37
|
+
pool.address,
|
|
38
|
+
WETH,
|
|
39
|
+
pool.signer
|
|
40
|
+
);
|
|
41
|
+
expect(wethBalanceDelta.gt(0));
|
|
42
|
+
});
|
|
35
43
|
});
|
|
44
|
+
};
|
|
36
45
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
});
|
|
46
|
+
testingHelper({
|
|
47
|
+
network: Network.OPTIMISM,
|
|
48
|
+
testingRun: testOneInch
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
testingHelper({
|
|
52
|
+
network: Network.POLYGON,
|
|
53
|
+
testingRun: testOneInch
|
|
46
54
|
});
|
package/src/test/pool.test.ts
CHANGED
|
@@ -1,60 +1,104 @@
|
|
|
1
|
+
import { BigNumber } from "ethers";
|
|
1
2
|
import { Dhedge, ethers, Pool } from "..";
|
|
2
3
|
import { AssetEnabled, Network } from "../types";
|
|
3
4
|
import { CONTRACT_ADDRESS, TEST_POOL } from "./constants";
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
beforeAfterReset,
|
|
8
|
+
testingHelper,
|
|
9
|
+
TestingRunParams
|
|
10
|
+
} from "./utils/testingHelper";
|
|
4
11
|
import { allowanceDelta, balanceDelta } from "./utils/token";
|
|
5
|
-
import { wallet } from "./wallet";
|
|
6
12
|
|
|
7
|
-
|
|
8
|
-
let
|
|
13
|
+
const testPool = ({ wallet, network, provider }: TestingRunParams) => {
|
|
14
|
+
let dhedge: Dhedge;
|
|
15
|
+
let pool: Pool;
|
|
9
16
|
|
|
10
|
-
jest.setTimeout(
|
|
17
|
+
jest.setTimeout(200000);
|
|
11
18
|
|
|
12
|
-
|
|
19
|
+
describe(`pool on ${network}`, () => {
|
|
20
|
+
beforeAll(async () => {
|
|
21
|
+
dhedge = new Dhedge(wallet, network);
|
|
22
|
+
pool = await dhedge.loadPool(TEST_POOL[network]);
|
|
23
|
+
});
|
|
24
|
+
beforeAfterReset({ beforeAll, afterAll, provider });
|
|
13
25
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
});
|
|
26
|
+
it("checks fund composition", async () => {
|
|
27
|
+
const result = await pool.getComposition();
|
|
28
|
+
expect(result.length).toBeGreaterThan(0);
|
|
29
|
+
});
|
|
19
30
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
31
|
+
it("approves USDC balance of User for Deposit", async () => {
|
|
32
|
+
await pool.approveDeposit(
|
|
33
|
+
CONTRACT_ADDRESS[network].USDC,
|
|
34
|
+
ethers.constants.MaxUint256
|
|
35
|
+
);
|
|
36
|
+
const UsdcAllowanceDelta = await allowanceDelta(
|
|
37
|
+
pool.signer.address,
|
|
38
|
+
CONTRACT_ADDRESS[network].USDC,
|
|
39
|
+
pool.address,
|
|
40
|
+
pool.signer
|
|
41
|
+
);
|
|
42
|
+
expect(UsdcAllowanceDelta.gt(0));
|
|
43
|
+
});
|
|
24
44
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
pool.signer
|
|
35
|
-
);
|
|
36
|
-
expect(UsdcAllowanceDelta.gt(0));
|
|
37
|
-
});
|
|
45
|
+
it("deposits 1 USDC into Pool", async () => {
|
|
46
|
+
await pool.deposit(CONTRACT_ADDRESS[network].USDC, (1e6).toString());
|
|
47
|
+
const poolTokenDelta = await balanceDelta(
|
|
48
|
+
pool.signer.address,
|
|
49
|
+
pool.address,
|
|
50
|
+
pool.signer
|
|
51
|
+
);
|
|
52
|
+
expect(poolTokenDelta.gt(0));
|
|
53
|
+
});
|
|
38
54
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const poolTokenDelta = await balanceDelta(
|
|
42
|
-
pool.signer.address,
|
|
43
|
-
pool.address,
|
|
44
|
-
pool.signer
|
|
45
|
-
);
|
|
46
|
-
expect(poolTokenDelta.gt(0));
|
|
47
|
-
});
|
|
55
|
+
it("adds WBTC to enabled assets", async () => {
|
|
56
|
+
const assetsBefore = await pool.getComposition();
|
|
48
57
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
const newAssets: AssetEnabled[] = [
|
|
59
|
+
{ asset: CONTRACT_ADDRESS[network].USDC, isDeposit: true },
|
|
60
|
+
{ asset: CONTRACT_ADDRESS[network].WETH, isDeposit: false },
|
|
61
|
+
{ asset: CONTRACT_ADDRESS[network].WBTC, isDeposit: false }
|
|
62
|
+
];
|
|
63
|
+
await pool.changeAssets(newAssets);
|
|
64
|
+
const assetsAfter = await pool.getComposition();
|
|
65
|
+
if (assetsBefore.length < newAssets.length) {
|
|
66
|
+
expect(assetsAfter.length).toBeGreaterThan(assetsBefore.length);
|
|
67
|
+
} else {
|
|
68
|
+
expect(assetsAfter.length).toBeLessThanOrEqual(assetsBefore.length);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("get available Manager Fee", async () => {
|
|
73
|
+
const result = await pool.getAvailableManagerFee();
|
|
74
|
+
expect(result).toBeInstanceOf(BigNumber);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("mintManagerFee; should not revert", async () => {
|
|
78
|
+
const tx = await pool.mintManagerFee();
|
|
79
|
+
expect(tx).toHaveProperty("wait");
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("withdraw 0.1 pool token into Pool", async () => {
|
|
83
|
+
await provider.send("evm_increaseTime", [24 * 60 * 60]);
|
|
84
|
+
await provider.send("evm_mine", []);
|
|
85
|
+
await pool.withdraw((0.1 * 1e18).toString());
|
|
86
|
+
const poolTokenDelta = await balanceDelta(
|
|
87
|
+
pool.signer.address,
|
|
88
|
+
pool.address,
|
|
89
|
+
pool.signer
|
|
90
|
+
);
|
|
91
|
+
expect(poolTokenDelta.lt(0));
|
|
92
|
+
});
|
|
59
93
|
});
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
testingHelper({
|
|
97
|
+
network: Network.POLYGON,
|
|
98
|
+
testingRun: testPool
|
|
60
99
|
});
|
|
100
|
+
|
|
101
|
+
// testingHelper({
|
|
102
|
+
// network: Network.OPTIMISM,
|
|
103
|
+
// testingRun: testPool
|
|
104
|
+
// });
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ethers } from "ethers";
|
|
2
|
+
import { Network } from "../../types";
|
|
3
|
+
import { getWalletData } from "../wallet";
|
|
4
|
+
|
|
5
|
+
export type TestingRunParams = {
|
|
6
|
+
network: Network;
|
|
7
|
+
wallet: ethers.Wallet;
|
|
8
|
+
provider: ethers.providers.JsonRpcProvider;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
type TestHelperParams = {
|
|
12
|
+
testingRun: (testingRunParams: TestingRunParams) => void;
|
|
13
|
+
} & { network: Network };
|
|
14
|
+
|
|
15
|
+
export const testingHelper = ({
|
|
16
|
+
network,
|
|
17
|
+
testingRun
|
|
18
|
+
}: TestHelperParams): void => {
|
|
19
|
+
const { wallet, provider } = getWalletData(network);
|
|
20
|
+
testingRun({ network, wallet, provider });
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const beforeAfterReset = ({
|
|
24
|
+
beforeAll,
|
|
25
|
+
afterAll,
|
|
26
|
+
provider
|
|
27
|
+
}: {
|
|
28
|
+
beforeAll: jest.Lifecycle;
|
|
29
|
+
afterAll: jest.Lifecycle;
|
|
30
|
+
provider: ethers.providers.JsonRpcProvider;
|
|
31
|
+
}): void => {
|
|
32
|
+
let snapshot = "";
|
|
33
|
+
beforeAll(async () => {
|
|
34
|
+
snapshot = (await provider.send("evm_snapshot", [])) as string;
|
|
35
|
+
await provider.send("evm_mine", []);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
afterAll(async () => {
|
|
39
|
+
await provider.send("evm_revert", [snapshot]);
|
|
40
|
+
await provider.send("evm_mine", []);
|
|
41
|
+
});
|
|
42
|
+
};
|
package/src/test/utils.test.ts
CHANGED
|
@@ -1,61 +1,82 @@
|
|
|
1
1
|
//import { ethers } from "ethers";
|
|
2
|
-
import { Dhedge } from "..";
|
|
2
|
+
import { Dhedge, Pool } from "..";
|
|
3
3
|
import { Network } from "../types";
|
|
4
|
+
import { CONTRACT_ADDRESS, TEST_POOL } from "./constants";
|
|
5
|
+
import {
|
|
6
|
+
TestingRunParams,
|
|
7
|
+
beforeAfterReset,
|
|
8
|
+
testingHelper
|
|
9
|
+
} from "./utils/testingHelper";
|
|
4
10
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const myPool = "0xe3528a438b94e64669def9b875c381c46ef713bf";
|
|
11
|
+
// const myPool = "0xe3528a438b94e64669def9b875c381c46ef713bf";
|
|
8
12
|
|
|
9
13
|
// const usdt = "0xc2132D05D31c914a87C6611C10748AEb04B58e8F";
|
|
10
|
-
|
|
11
|
-
const weth = "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619";
|
|
12
|
-
const wbtc = "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6";
|
|
14
|
+
|
|
13
15
|
// const lpUsdcWeth = "0x34965ba0ac2451A34a0471F04CCa3F990b8dea27";
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
const testUtils = ({ wallet, network, provider }: TestingRunParams) => {
|
|
18
|
+
let dhedge: Dhedge;
|
|
19
|
+
let pool: Pool;
|
|
20
|
+
const usdc = CONTRACT_ADDRESS[network].USDC;
|
|
21
|
+
const weth = CONTRACT_ADDRESS[network].WETH;
|
|
22
|
+
const wbtc = CONTRACT_ADDRESS[network].WBTC;
|
|
23
|
+
// const usdt = CONTRACT_ADDRESS[network].USDT;
|
|
16
24
|
|
|
17
|
-
jest.setTimeout(100000);
|
|
25
|
+
jest.setTimeout(100000);
|
|
18
26
|
|
|
19
|
-
describe(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
27
|
+
describe(`utils on ${network}`, () => {
|
|
28
|
+
beforeAll(async () => {
|
|
29
|
+
dhedge = new Dhedge(wallet, network);
|
|
30
|
+
pool = await dhedge.loadPool(TEST_POOL[network]);
|
|
31
|
+
});
|
|
32
|
+
beforeAfterReset({ beforeAll, afterAll, provider });
|
|
33
|
+
|
|
34
|
+
// it("gets lp ratio of the USDT/USDC pool", async () => {
|
|
35
|
+
// const result = await dhedge.utils.getLpReserves(Dapp.SUSHISWAP, usdc, usdt);
|
|
36
|
+
// expect(Number(result.assetA) / Number(result.assetB)).toBeGreaterThan(0.9);
|
|
37
|
+
// });
|
|
38
|
+
|
|
39
|
+
// it("gets pool id of sushi LP pool for USDC/WETH", async () => {
|
|
40
|
+
// const result = await dhedge.utils.getLpPoolId(Dapp.SUSHISWAP, lpUsdcWeth);
|
|
41
|
+
// expect(result).toBe(1);
|
|
42
|
+
// });
|
|
23
43
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const assets = [wbtc, usdc, weth];
|
|
52
|
-
const amounts = ["0", "1000000", "0"];
|
|
53
|
-
const result = await dhedge.utils.getBalancerJoinPoolTx(
|
|
54
|
-
pool,
|
|
55
|
-
"0x03cd191f589d12b0582a99808cf19851e468e6b500010000000000000000000a",
|
|
56
|
-
assets,
|
|
57
|
-
amounts
|
|
58
|
-
);
|
|
59
|
-
expect(result);
|
|
44
|
+
// it("gets USDC balance of a pool", async () => {
|
|
45
|
+
// const result = await dhedge.utils.getBalance(usdc, myPool);
|
|
46
|
+
// expect(result.gt(0));
|
|
47
|
+
// });
|
|
48
|
+
// it("gets minumum amount out of WETH for 1 USDC", async () => {
|
|
49
|
+
// const result = await dhedge.utils.getMinAmountOut(
|
|
50
|
+
// Dapp.SUSHISWAP,
|
|
51
|
+
// usdc,
|
|
52
|
+
// weth,
|
|
53
|
+
// "1000000",
|
|
54
|
+
// 0.5
|
|
55
|
+
// );
|
|
56
|
+
// expect(result.gt(0));
|
|
57
|
+
// });
|
|
58
|
+
|
|
59
|
+
it("gets Balancer pool tx data", async () => {
|
|
60
|
+
// pool = await dhedge.loadPool(pool);
|
|
61
|
+
const assets = [wbtc, usdc, weth];
|
|
62
|
+
const amounts = ["0", "1000000", "0"];
|
|
63
|
+
const result = await dhedge.utils.getBalancerJoinPoolTx(
|
|
64
|
+
pool,
|
|
65
|
+
"0x03cd191f589d12b0582a99808cf19851e468e6b500010000000000000000000a",
|
|
66
|
+
assets,
|
|
67
|
+
amounts
|
|
68
|
+
);
|
|
69
|
+
expect(result);
|
|
70
|
+
});
|
|
60
71
|
});
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
testingHelper({
|
|
75
|
+
network: Network.POLYGON,
|
|
76
|
+
testingRun: testUtils
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
testingHelper({
|
|
80
|
+
network: Network.OPTIMISM,
|
|
81
|
+
testingRun: testUtils
|
|
61
82
|
});
|
package/src/test/wallet.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ethers } from "ethers";
|
|
2
|
-
|
|
2
|
+
import { Network } from "../types";
|
|
3
3
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
4
4
|
require("dotenv").config();
|
|
5
5
|
|
|
@@ -25,3 +25,24 @@ export const wallet = new ethers.Wallet(
|
|
|
25
25
|
process.env.PRIVATE_KEY as string,
|
|
26
26
|
provider
|
|
27
27
|
);
|
|
28
|
+
|
|
29
|
+
export const networkPortMap = {
|
|
30
|
+
[Network.POLYGON]: 8542,
|
|
31
|
+
[Network.OPTIMISM]: 8544,
|
|
32
|
+
[Network.ARBITRUM]: 8540
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const getWalletData = (
|
|
36
|
+
network: Network
|
|
37
|
+
): {
|
|
38
|
+
wallet: ethers.Wallet;
|
|
39
|
+
provider: ethers.providers.JsonRpcProvider;
|
|
40
|
+
} => {
|
|
41
|
+
const provider = new ethers.providers.JsonRpcProvider(
|
|
42
|
+
`http://127.0.0.1:${networkPortMap[network]}/`
|
|
43
|
+
);
|
|
44
|
+
return {
|
|
45
|
+
wallet: new ethers.Wallet(process.env.PRIVATE_KEY as string, provider),
|
|
46
|
+
provider
|
|
47
|
+
};
|
|
48
|
+
};
|