@dhedge/v2-sdk 1.9.5 → 1.9.6

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.
@@ -7,7 +7,8 @@ import { CONTRACT_ADDRESS, MAX_AMOUNT, TEST_POOL } from "./constants";
7
7
  import {
8
8
  TestingRunParams,
9
9
  setUSDCAmount,
10
- testingHelper
10
+ testingHelper,
11
+ wait
11
12
  } from "./utils/testingHelper";
12
13
  import { allowanceDelta, balanceDelta } from "./utils/token";
13
14
  import { getTxOptions } from "./txOptions";
@@ -32,7 +33,7 @@ const testOneInch = ({ wallet, network, provider }: TestingRunParams) => {
32
33
  await provider.send("evm_mine", []);
33
34
  // top up USDC
34
35
  await setUSDCAmount({
35
- amount: new BigNumber(100).times(1e18).toFixed(0),
36
+ amount: new BigNumber(2).times(1e6).toFixed(0),
36
37
  userAddress: pool.address,
37
38
  network,
38
39
  provider
@@ -50,7 +51,38 @@ const testOneInch = ({ wallet, network, provider }: TestingRunParams) => {
50
51
  await expect(usdcAllowanceDelta.gt(0));
51
52
  });
52
53
 
54
+ it("gets gas estimation for 2 USDC into WETH on 1Inch", async () => {
55
+ const gasEstimate = await pool.trade(
56
+ Dapp.ONEINCH,
57
+ USDC,
58
+ WETH,
59
+ "2000000",
60
+ 0.5,
61
+ await getTxOptions(network),
62
+ true
63
+ );
64
+ expect(gasEstimate.gt(0));
65
+ });
66
+
67
+ it("gets error on gas estimation for 200 USDC into WETH on 1Inch", async () => {
68
+ await wait(1);
69
+ let gasEstimate = null;
70
+ try {
71
+ gasEstimate = await pool.trade(
72
+ Dapp.ONEINCH,
73
+ USDC,
74
+ WETH,
75
+ "200000000",
76
+ 0.5,
77
+ await getTxOptions(network),
78
+ true
79
+ );
80
+ } catch (err) {}
81
+ expect(gasEstimate).toBeNull();
82
+ });
83
+
53
84
  it("trades 2 USDC into WETH on 1Inch", async () => {
85
+ await wait(1);
54
86
  await pool.trade(
55
87
  Dapp.ONEINCH,
56
88
  USDC,
@@ -90,3 +90,7 @@ export const setUSDCAmount = async ({
90
90
  slot: USDC_BALANCEOF_SLOT[network]
91
91
  });
92
92
  };
93
+
94
+ export const wait = (seconds: number): Promise<void> => {
95
+ return new Promise(resolve => setTimeout(resolve, seconds * 1000));
96
+ };
@@ -3,7 +3,7 @@
3
3
  import set from "lodash/set";
4
4
  import { Interface } from "@ethersproject/abi";
5
5
  import { multiCallAddress } from "../config";
6
- import { ethers, Network } from "..";
6
+ import { ethers, Network, Pool } from "..";
7
7
 
8
8
  export async function call(
9
9
  provider: ethers.Signer,
@@ -93,3 +93,19 @@ export class Multicaller {
93
93
  return obj;
94
94
  }
95
95
  }
96
+
97
+ export const getPoolTxOrGasEstimate = async (
98
+ pool: Pool,
99
+ args: any[],
100
+ estimateGas: boolean
101
+ ): Promise<any> => {
102
+ if (estimateGas) {
103
+ return await pool.poolLogic.estimateGas.execTransaction(
104
+ args[0],
105
+ args[1],
106
+ args[2]
107
+ );
108
+ } else {
109
+ return await pool.poolLogic.execTransaction(args[0], args[1], args[2]);
110
+ }
111
+ };