@dhedge/v2-sdk 1.9.2 → 1.9.4

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,10 +1,11 @@
1
1
  import { ethers } from "ethers";
2
2
  import { Network } from "../../types";
3
- import { getWallet } from "../wallet";
3
+ import { getWalletData } from "../wallet";
4
4
 
5
5
  export type TestingRunParams = {
6
6
  network: Network;
7
7
  wallet: ethers.Wallet;
8
+ provider: ethers.providers.JsonRpcProvider;
8
9
  };
9
10
 
10
11
  type TestHelperParams = {
@@ -15,6 +16,27 @@ export const testingHelper = ({
15
16
  network,
16
17
  testingRun
17
18
  }: TestHelperParams): void => {
18
- const wallet = getWallet(network);
19
- testingRun({ network, wallet });
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
+ });
20
42
  };
@@ -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
- import { wallet } from "./wallet";
6
-
7
- const myPool = "0xe3528a438b94e64669def9b875c381c46ef713bf";
11
+ // const myPool = "0xe3528a438b94e64669def9b875c381c46ef713bf";
8
12
 
9
13
  // const usdt = "0xc2132D05D31c914a87C6611C10748AEb04B58e8F";
10
- const usdc = "0x2791bca1f2de4661ed88a30c99a7a9449aa84174";
11
- const weth = "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619";
12
- const wbtc = "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6";
14
+
13
15
  // const lpUsdcWeth = "0x34965ba0ac2451A34a0471F04CCa3F990b8dea27";
14
16
 
15
- let dhedge: Dhedge;
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("utils", () => {
20
- beforeAll(() => {
21
- dhedge = new Dhedge(wallet, Network.POLYGON);
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
- // it("gets lp ratio of the USDT/USDC pool", async () => {
25
- // const result = await dhedge.utils.getLpReserves(Dapp.SUSHISWAP, usdc, usdt);
26
- // expect(Number(result.assetA) / Number(result.assetB)).toBeGreaterThan(0.9);
27
- // });
28
-
29
- // it("gets pool id of sushi LP pool for USDC/WETH", async () => {
30
- // const result = await dhedge.utils.getLpPoolId(Dapp.SUSHISWAP, lpUsdcWeth);
31
- // expect(result).toBe(1);
32
- // });
33
-
34
- // it("gets USDC balance of a pool", async () => {
35
- // const result = await dhedge.utils.getBalance(usdc, myPool);
36
- // expect(result.gt(0));
37
- // });
38
- // it("gets minumum amount out of WETH for 1 USDC", async () => {
39
- // const result = await dhedge.utils.getMinAmountOut(
40
- // Dapp.SUSHISWAP,
41
- // usdc,
42
- // weth,
43
- // "1000000",
44
- // 0.5
45
- // );
46
- // expect(result.gt(0));
47
- // });
48
-
49
- it("gets Balancer pool tx data", async () => {
50
- const pool = await dhedge.loadPool(myPool);
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
  });
@@ -32,9 +32,17 @@ export const networkPortMap = {
32
32
  [Network.ARBITRUM]: 8540
33
33
  };
34
34
 
35
- export const getWallet = (network: Network): ethers.Wallet => {
35
+ export const getWalletData = (
36
+ network: Network
37
+ ): {
38
+ wallet: ethers.Wallet;
39
+ provider: ethers.providers.JsonRpcProvider;
40
+ } => {
36
41
  const provider = new ethers.providers.JsonRpcProvider(
37
42
  `http://127.0.0.1:${networkPortMap[network]}/`
38
43
  );
39
- return new ethers.Wallet(process.env.PRIVATE_KEY as string, provider);
44
+ return {
45
+ wallet: new ethers.Wallet(process.env.PRIVATE_KEY as string, provider),
46
+ provider
47
+ };
40
48
  };
package/src/types.ts CHANGED
@@ -4,7 +4,7 @@ import { BigNumber } from "ethers";
4
4
  export enum Network {
5
5
  POLYGON = "polygon",
6
6
  OPTIMISM = "optimism",
7
- ARBITRUM = "arbitrum"
7
+ ARBITRUM = "arbitrum",
8
8
  }
9
9
 
10
10
  export enum Dapp {
@@ -21,7 +21,8 @@ export enum Dapp {
21
21
  VELODROME = "velodrome",
22
22
  VELODROMEV2 = "velodromeV2",
23
23
  LYRA = "lyra",
24
- ZEROEX = "0x"
24
+ ZEROEX = "0x",
25
+ RAMSES = "ramses",
25
26
  }
26
27
 
27
28
  export enum Transaction {
@@ -43,7 +44,7 @@ export enum Transaction {
43
44
  BURN = "burn",
44
45
  SWAP_SYNTHS = "exchangeWithTracking",
45
46
  ADD_LIQUIDITY_STAKE = "addLiquidityAndStake",
46
- REMOVE_LIQUIDITY_UNSTAKE = "removeLiquidityAndUnstake"
47
+ REMOVE_LIQUIDITY_UNSTAKE = "removeLiquidityAndUnstake",
47
48
  }
48
49
 
49
50
  export type AddressNetworkMap = Readonly<Record<Network, string>>;