@dhedge/v2-sdk 1.10.5 → 1.10.7

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,69 +1,97 @@
1
1
  /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
+
3
3
  import { Dhedge, Pool } from "..";
4
4
  import { routerAddress } from "../config";
5
+
5
6
  import { Dapp, Network } from "../types";
6
7
  import { CONTRACT_ADDRESS, MAX_AMOUNT, TEST_POOL } from "./constants";
8
+ import {
9
+ TestingRunParams,
10
+ setChainlinkTimeout,
11
+ setUSDCAmount,
12
+ testingHelper
13
+ } from "./utils/testingHelper";
7
14
  import { allowanceDelta, balanceDelta } from "./utils/token";
15
+ import BigNumber from "bignumber.js";
8
16
 
9
- import { wallet } from "./wallet";
10
-
11
- const ETHy = "0xb2cfb909e8657c0ec44d3dd898c1053b87804755";
12
- const network = Network.OPTIMISM;
13
- const SUSD = CONTRACT_ADDRESS[network].SUSD;
17
+ const testToros = ({ wallet, network, provider }: TestingRunParams) => {
18
+ const USDC = CONTRACT_ADDRESS[network].USDC;
19
+ const TOROS = CONTRACT_ADDRESS[network].TOROS;
14
20
 
15
- let dhedge: Dhedge;
16
- let pool: Pool;
17
- jest.setTimeout(100000);
21
+ let dhedge: Dhedge;
22
+ let pool: Pool;
23
+ jest.setTimeout(100000);
18
24
 
19
- describe("pool", () => {
20
- beforeAll(async () => {
21
- dhedge = new Dhedge(wallet, network);
22
- pool = await dhedge.loadPool(TEST_POOL[network]);
23
- });
25
+ describe(`pool on ${network}`, () => {
26
+ beforeAll(async () => {
27
+ dhedge = new Dhedge(wallet, network);
28
+ pool = await dhedge.loadPool(TEST_POOL[network]);
29
+ await setChainlinkTimeout({ pool, provider }, 86400 * 365);
30
+ // top up gas
31
+ await provider.send("hardhat_setBalance", [
32
+ wallet.address,
33
+ "0x10000000000000000"
34
+ ]);
35
+ await provider.send("evm_mine", []);
36
+ // top up USDC
37
+ const amount = new BigNumber(1000).times(1e6).toFixed(0);
38
+ await setUSDCAmount({
39
+ amount,
40
+ userAddress: pool.address,
41
+ network,
42
+ provider
43
+ });
44
+ });
24
45
 
25
- it("approves unlimited ETHy on Toros (Easyswapper)", async () => {
26
- await pool.approve(Dapp.TOROS, ETHy, MAX_AMOUNT);
27
- const ETHyAllowanceDelta = await allowanceDelta(
28
- pool.address,
29
- ETHy,
30
- routerAddress[network].toros!,
31
- pool.signer
32
- );
33
- expect(ETHyAllowanceDelta.gt(0));
34
- });
46
+ it("approves unlimited USDC on Toros", async () => {
47
+ await pool.approve(Dapp.TOROS, USDC, MAX_AMOUNT);
48
+ const usdcAllowanceDelta = await allowanceDelta(
49
+ pool.address,
50
+ USDC,
51
+ routerAddress[network].toros!,
52
+ pool.signer
53
+ );
54
+ await expect(usdcAllowanceDelta.gt(0));
55
+ });
35
56
 
36
- it("sell ETHy to SUSD on Toros", async () => {
37
- const ETHyBalance = await pool.utils.getBalance(ETHy, pool.address);
38
- await pool.trade(Dapp.TOROS, ETHy, SUSD, ETHyBalance, 3);
39
- const ETHyBalanceDelta = await balanceDelta(
40
- pool.address,
41
- SUSD,
42
- pool.signer
43
- );
44
- expect(ETHyBalanceDelta.lt(0));
45
- });
57
+ it("trades USDC balance into Toros Token", async () => {
58
+ const usdcBalance = await pool.utils.getBalance(USDC, pool.address);
59
+ await pool.trade(Dapp.TOROS, USDC, TOROS, usdcBalance, 1);
60
+ const torosBalanceDelta = await balanceDelta(
61
+ pool.address,
62
+ TOROS,
63
+ pool.signer
64
+ );
65
+ expect(torosBalanceDelta.gt(0));
66
+ });
46
67
 
47
- it("approves unlimited sUSD on Toros (Easyswapper)", async () => {
48
- await pool.approve(Dapp.TOROS, SUSD, MAX_AMOUNT, { gasLimit: "3000000" });
49
- const sUSDAllowanceDelta = await allowanceDelta(
50
- pool.address,
51
- SUSD,
52
- routerAddress[network].toros!,
53
- pool.signer
54
- );
55
- expect(sUSDAllowanceDelta.gt(0));
56
- });
68
+ it("init Toros Token for withdrawal", async () => {
69
+ await provider.send("evm_increaseTime", [86400]);
70
+ await provider.send("evm_mine", []);
71
+ const torosBalance = await pool.utils.getBalance(TOROS, pool.address);
72
+ await pool.approve(Dapp.TOROS, TOROS, MAX_AMOUNT);
73
+ await pool.trade(Dapp.TOROS, TOROS, USDC, torosBalance, 1);
74
+ const torosBalanceDelta = await balanceDelta(
75
+ pool.address,
76
+ TOROS,
77
+ pool.signer
78
+ );
79
+ expect(torosBalanceDelta.lt(0));
80
+ });
57
81
 
58
- it("buys ETHy for 3 sUSD", async () => {
59
- await pool.trade(Dapp.TOROS, SUSD, ETHy, (3 * 10e18).toString(), 3, {
60
- gasLimit: "3000000"
82
+ it("complete withdrawal from Toros asset", async () => {
83
+ await pool.completeTorosWithdrawal(USDC, 1);
84
+ const usdcBalanceDelta = await balanceDelta(
85
+ pool.address,
86
+ USDC,
87
+ pool.signer
88
+ );
89
+ expect(usdcBalanceDelta.gt(0));
61
90
  });
62
- const ETHyBalanceDelta = await balanceDelta(
63
- pool.address,
64
- ETHy,
65
- pool.signer
66
- );
67
- expect(ETHyBalanceDelta.gt(0));
68
91
  });
92
+ };
93
+
94
+ testingHelper({
95
+ network: Network.OPTIMISM,
96
+ testingRun: testToros
69
97
  });
@@ -1,3 +1,4 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
1
2
  import { BigNumber, Contract, ethers } from "ethers";
2
3
  import { Network } from "../../types";
3
4
  import { getWalletData } from "../wallet";
@@ -34,8 +35,8 @@ export const beforeAfterReset = ({
34
35
  afterAll,
35
36
  provider
36
37
  }: {
37
- beforeAll: jest.Lifecycle;
38
- afterAll: jest.Lifecycle;
38
+ beforeAll: any;
39
+ afterAll: any;
39
40
  provider: ethers.providers.JsonRpcProvider;
40
41
  }): void => {
41
42
  let snapshot = "";
package/src/types.ts CHANGED
@@ -27,7 +27,8 @@ export enum Dapp {
27
27
  RAMSES = "ramses",
28
28
  AERODROME = "aerodrome",
29
29
  AERODROMECL = "aerodromeCL",
30
- RAMSESCL = "ramsesCL"
30
+ RAMSESCL = "ramsesCL",
31
+ COMPOUNDV3 = "compoundV3"
31
32
  }
32
33
 
33
34
  export enum Transaction {