@dhedge/v2-sdk 2.0.2 → 2.1.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/dhedge.d.ts +5 -2
- package/dist/services/kyberSwap/index.d.ts +7 -0
- package/dist/test/constants.d.ts +14 -0
- package/dist/test/wallet.d.ts +1 -0
- package/dist/types.d.ts +4 -2
- package/dist/v2-sdk.cjs.development.js +174 -54
- 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 +174 -54
- package/dist/v2-sdk.esm.js.map +1 -1
- package/package.json +3 -2
- package/src/abi/PoolFactory.json +15 -0
- package/src/config.ts +32 -12
- package/src/entities/dhedge.ts +11 -2
- package/src/entities/pool.ts +10 -0
- package/src/services/kyberSwap/index.ts +47 -0
- package/src/test/constants.ts +17 -3
- package/src/test/dhedge.test.ts +22 -39
- package/src/test/flatmoney.test.ts +22 -0
- package/src/test/kyberSwap.test.ts +100 -0
- package/src/test/pool.test.ts +56 -49
- package/src/test/wallet.ts +2 -1
- package/src/types.ts +4 -2
- package/src/utils/contract.ts +25 -5
package/src/test/pool.test.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { Dhedge, Pool } from "..";
|
|
2
2
|
import { Network } from "../types";
|
|
3
|
-
import { TEST_POOL } from "./constants";
|
|
3
|
+
import { CONTRACT_ADDRESS, TEST_POOL } from "./constants";
|
|
4
4
|
|
|
5
5
|
import { testingHelper, TestingRunParams } from "./utils/testingHelper";
|
|
6
|
+
import { balanceDelta } from "./utils/token";
|
|
6
7
|
|
|
7
|
-
const testPool = ({ wallet, network
|
|
8
|
+
const testPool = ({ wallet, network }: TestingRunParams) => {
|
|
8
9
|
let dhedge: Dhedge;
|
|
9
10
|
let pool: Pool;
|
|
10
11
|
|
|
12
|
+
const USDT = CONTRACT_ADDRESS[network].USDT;
|
|
13
|
+
|
|
11
14
|
jest.setTimeout(200000);
|
|
12
15
|
|
|
13
16
|
describe(`pool on ${network}`, () => {
|
|
@@ -15,62 +18,65 @@ const testPool = ({ wallet, network, provider }: TestingRunParams) => {
|
|
|
15
18
|
dhedge = new Dhedge(wallet, network);
|
|
16
19
|
pool = await dhedge.loadPool(TEST_POOL[network]);
|
|
17
20
|
|
|
18
|
-
await provider.send("hardhat_setBalance", [
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
]);
|
|
21
|
+
// await provider.send("hardhat_setBalance", [
|
|
22
|
+
// wallet.address,
|
|
23
|
+
// "0x10000000000000000"
|
|
24
|
+
// ]);
|
|
22
25
|
});
|
|
23
26
|
|
|
24
27
|
it("checks fund composition", async () => {
|
|
25
28
|
const result = await pool.getComposition();
|
|
29
|
+
console.log(result);
|
|
26
30
|
expect(result.length).toBeGreaterThan(0);
|
|
27
31
|
});
|
|
28
32
|
|
|
29
|
-
it("sets pool private", async () => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
});
|
|
33
|
+
// it("sets pool private", async () => {
|
|
34
|
+
// const result = await pool.setPrivate(true);
|
|
35
|
+
// expect(result).not.toBeNull();
|
|
36
|
+
// });
|
|
33
37
|
|
|
34
|
-
//
|
|
35
|
-
//
|
|
36
|
-
// CONTRACT_ADDRESS[network].USDC,
|
|
37
|
-
// ethers.constants.MaxUint256
|
|
38
|
-
// );
|
|
39
|
-
// const UsdcAllowanceDelta = await allowanceDelta(
|
|
40
|
-
// pool.signer.address,
|
|
41
|
-
// CONTRACT_ADDRESS[network].USDC,
|
|
42
|
-
// pool.address,
|
|
43
|
-
// pool.signer
|
|
44
|
-
// );
|
|
45
|
-
// expect(UsdcAllowanceDelta.gt(0));
|
|
46
|
-
// });
|
|
38
|
+
// it("adds WBTC to enabled assets", async () => {
|
|
39
|
+
// const assetsBefore = await pool.getComposition();
|
|
47
40
|
|
|
48
|
-
//
|
|
49
|
-
//
|
|
50
|
-
//
|
|
51
|
-
//
|
|
52
|
-
//
|
|
53
|
-
//
|
|
54
|
-
// );
|
|
55
|
-
// expect(poolTokenDelta.gt(0));
|
|
56
|
-
// });
|
|
57
|
-
|
|
58
|
-
// it("adds WBTC to enabled assets", async () => {
|
|
59
|
-
// const assetsBefore = await pool.getComposition();
|
|
60
|
-
|
|
61
|
-
// const newAssets: AssetEnabled[] = [
|
|
62
|
-
// { asset: CONTRACT_ADDRESS[network].USDC, isDeposit: true },
|
|
63
|
-
// { asset: CONTRACT_ADDRESS[network].WETH, isDeposit: false },
|
|
64
|
-
// { asset: CONTRACT_ADDRESS[network].WBTC, isDeposit: false }
|
|
65
|
-
// ];
|
|
66
|
-
// await pool.changeAssets(newAssets);
|
|
67
|
-
// const assetsAfter = await pool.getComposition();
|
|
68
|
-
// if (assetsBefore.length < newAssets.length) {
|
|
69
|
-
// expect(assetsAfter.length).toBeGreaterThan(assetsBefore.length);
|
|
70
|
-
// } else {
|
|
71
|
-
// expect(assetsAfter.length).toBeLessThanOrEqual(assetsBefore.length);
|
|
41
|
+
// const newAssets: AssetEnabled[] = [
|
|
42
|
+
// { asset: CONTRACT_ADDRESS[network].USDT, isDeposit: true },
|
|
43
|
+
// { asset: CONTRACT_ADDRESS[network].USDE, isDeposit: true },
|
|
44
|
+
// {
|
|
45
|
+
// asset: "0x925a2A7214Ed92428B5b1B090F80b25700095e12",
|
|
46
|
+
// isDeposit: false
|
|
72
47
|
// }
|
|
73
|
-
//
|
|
48
|
+
// ];
|
|
49
|
+
// await pool.changeAssets(newAssets);
|
|
50
|
+
// const assetsAfter = await pool.getComposition();
|
|
51
|
+
// expect(assetsAfter.length).toBeLessThanOrEqual(assetsBefore.length);
|
|
52
|
+
// });
|
|
53
|
+
|
|
54
|
+
// it("approves USDT balance of User for Deposit", async () => {
|
|
55
|
+
// await pool.approveDeposit(
|
|
56
|
+
// CONTRACT_ADDRESS[network].USDT,
|
|
57
|
+
// ethers.constants.MaxUint256
|
|
58
|
+
// );
|
|
59
|
+
// const usdtAllowanceDelta = await allowanceDelta(
|
|
60
|
+
// pool.signer.address,
|
|
61
|
+
// CONTRACT_ADDRESS[network].USDC,
|
|
62
|
+
// pool.address,
|
|
63
|
+
// pool.signer
|
|
64
|
+
// );
|
|
65
|
+
// expect(usdtAllowanceDelta.gt(0));
|
|
66
|
+
// });
|
|
67
|
+
|
|
68
|
+
it("deposits 200 USDT into Pool", async () => {
|
|
69
|
+
await pool.deposit(
|
|
70
|
+
CONTRACT_ADDRESS[network].USDT,
|
|
71
|
+
(200000000).toString()
|
|
72
|
+
);
|
|
73
|
+
const poolTokenDelta = await balanceDelta(
|
|
74
|
+
pool.address,
|
|
75
|
+
USDT,
|
|
76
|
+
pool.signer
|
|
77
|
+
);
|
|
78
|
+
expect(poolTokenDelta.gt(0));
|
|
79
|
+
});
|
|
74
80
|
|
|
75
81
|
// it("get available Manager Fee", async () => {
|
|
76
82
|
// const result = await pool.getAvailableManagerFee();
|
|
@@ -102,6 +108,7 @@ const testPool = ({ wallet, network, provider }: TestingRunParams) => {
|
|
|
102
108
|
// });
|
|
103
109
|
|
|
104
110
|
testingHelper({
|
|
105
|
-
network: Network.
|
|
111
|
+
network: Network.PLASMA,
|
|
112
|
+
onFork: false,
|
|
106
113
|
testingRun: testPool
|
|
107
114
|
});
|
package/src/test/wallet.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -6,7 +6,8 @@ export enum Network {
|
|
|
6
6
|
OPTIMISM = "optimism",
|
|
7
7
|
ARBITRUM = "arbitrum",
|
|
8
8
|
BASE = "base",
|
|
9
|
-
ETHEREUM = "ethereum"
|
|
9
|
+
ETHEREUM = "ethereum",
|
|
10
|
+
PLASMA = "plasma"
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
export enum Dapp {
|
|
@@ -31,7 +32,8 @@ export enum Dapp {
|
|
|
31
32
|
PANCAKECL = "pancakeCL",
|
|
32
33
|
COMPOUNDV3 = "compoundV3",
|
|
33
34
|
ODOS = "odos",
|
|
34
|
-
PENDLE = "pendle"
|
|
35
|
+
PENDLE = "pendle",
|
|
36
|
+
KYBERSWAP = "kyberswap"
|
|
35
37
|
}
|
|
36
38
|
|
|
37
39
|
export enum Transaction {
|
package/src/utils/contract.ts
CHANGED
|
@@ -4,6 +4,7 @@ import set from "lodash/set";
|
|
|
4
4
|
import { Interface } from "@ethersproject/abi";
|
|
5
5
|
import { multiCallAddress } from "../config";
|
|
6
6
|
import { ethers, Network, Pool, SDKOptions } from "..";
|
|
7
|
+
import { Signer } from "ethers";
|
|
7
8
|
|
|
8
9
|
export async function call(
|
|
9
10
|
provider: ethers.Signer,
|
|
@@ -95,14 +96,29 @@ export class Multicaller {
|
|
|
95
96
|
}
|
|
96
97
|
|
|
97
98
|
const getGasEstimateData = async (
|
|
99
|
+
pool: Pool,
|
|
98
100
|
estimateFunc: ethers.ContractFunction<ethers.BigNumber>,
|
|
99
101
|
txInfoData: { to: string; txData: string; minAmountOut: any },
|
|
100
|
-
txOptions: any = {}
|
|
102
|
+
txOptions: any = {},
|
|
103
|
+
sdkOptions: SDKOptions
|
|
101
104
|
) => {
|
|
102
105
|
let gas = null;
|
|
103
106
|
let gasEstimationError = null;
|
|
104
107
|
try {
|
|
105
|
-
|
|
108
|
+
if (
|
|
109
|
+
!pool.isDhedge ||
|
|
110
|
+
(!isSdkOptionsBoolean(sdkOptions) && sdkOptions.useTraderAddressAsFrom)
|
|
111
|
+
) {
|
|
112
|
+
// for pool.signer.estimateGas
|
|
113
|
+
gas = await (estimateFunc as Signer["estimateGas"])({
|
|
114
|
+
to: txInfoData.to,
|
|
115
|
+
data: txInfoData.txData,
|
|
116
|
+
...txOptions
|
|
117
|
+
});
|
|
118
|
+
} else {
|
|
119
|
+
// for pool.poolLogic.estimateGas.execTransaction
|
|
120
|
+
gas = await estimateFunc(txInfoData.to, txInfoData.txData, txOptions);
|
|
121
|
+
}
|
|
106
122
|
} catch (e) {
|
|
107
123
|
gasEstimationError = e;
|
|
108
124
|
}
|
|
@@ -145,9 +161,11 @@ export const getPoolTxOrGasEstimate = async (
|
|
|
145
161
|
(!isSdkOptionsBoolean(sdkOptions) && sdkOptions.estimateGas)
|
|
146
162
|
) {
|
|
147
163
|
return await getGasEstimateData(
|
|
148
|
-
pool
|
|
164
|
+
pool,
|
|
165
|
+
pool.signer.estimateGas.bind(pool.signer),
|
|
149
166
|
txInfoData,
|
|
150
|
-
txOptions
|
|
167
|
+
txOptions,
|
|
168
|
+
sdkOptions
|
|
151
169
|
);
|
|
152
170
|
} else {
|
|
153
171
|
return await pool.signer.sendTransaction({
|
|
@@ -162,9 +180,11 @@ export const getPoolTxOrGasEstimate = async (
|
|
|
162
180
|
(!isSdkOptionsBoolean(sdkOptions) && sdkOptions.estimateGas)
|
|
163
181
|
) {
|
|
164
182
|
return await getGasEstimateData(
|
|
183
|
+
pool,
|
|
165
184
|
pool.poolLogic.estimateGas.execTransaction,
|
|
166
185
|
txInfoData,
|
|
167
|
-
txOptions
|
|
186
|
+
txOptions,
|
|
187
|
+
sdkOptions
|
|
168
188
|
);
|
|
169
189
|
} else {
|
|
170
190
|
return await pool.poolLogic.execTransaction(
|