@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.
@@ -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, provider }: TestingRunParams) => {
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
- wallet.address,
20
- "0x10000000000000000"
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
- const result = await pool.setPrivate(true);
31
- expect(result).not.toBeNull();
32
- });
33
+ // it("sets pool private", async () => {
34
+ // const result = await pool.setPrivate(true);
35
+ // expect(result).not.toBeNull();
36
+ // });
33
37
 
34
- // it("approves USDC balance of User for Deposit", async () => {
35
- // await pool.approveDeposit(
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
- // it("deposits 1 USDC into Pool", async () => {
49
- // await pool.deposit(CONTRACT_ADDRESS[network].USDC, (1e6).toString());
50
- // const poolTokenDelta = await balanceDelta(
51
- // pool.signer.address,
52
- // pool.address,
53
- // pool.signer
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.OPTIMISM,
111
+ network: Network.PLASMA,
112
+ onFork: false,
106
113
  testingRun: testPool
107
114
  });
@@ -8,7 +8,8 @@ export const networkPortMap = {
8
8
  [Network.OPTIMISM]: 8544,
9
9
  [Network.ARBITRUM]: 8540,
10
10
  [Network.BASE]: 8546,
11
- [Network.ETHEREUM]: 8547
11
+ [Network.ETHEREUM]: 8547,
12
+ [Network.PLASMA]: 8548
12
13
  };
13
14
 
14
15
  export const getWalletData = (
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 {
@@ -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
- gas = await estimateFunc(txInfoData.to, txInfoData.txData, txOptions);
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.signer.estimateGas,
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(