@dhedge/v2-sdk 1.8.3 → 1.9.1

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.
@@ -0,0 +1,114 @@
1
+ /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ import { Dhedge, Pool } from "..";
4
+ import { routerAddress } from "../config";
5
+ import { Dapp, Network } from "../types";
6
+ import { CONTRACT_ADDRESS, MAX_AMOUNT, TEST_POOL } from "./constants";
7
+ import { allowanceDelta, balanceDelta } from "./utils/token";
8
+
9
+ import { wallet } from "./wallet";
10
+
11
+ const USDC_SUSD_Lp = "0x6d5BA400640226e24b50214d2bBb3D4Db8e6e15a";
12
+ const USDC_SUSD_Gauge = "0x55a272304456355242f6690863b5c8d5c512ff71";
13
+ const network = Network.OPTIMISM;
14
+ const SUSD = CONTRACT_ADDRESS[network].SUSD;
15
+ const USDC = CONTRACT_ADDRESS[network].USDC;
16
+
17
+ let dhedge: Dhedge;
18
+ let pool: Pool;
19
+ jest.setTimeout(100000);
20
+
21
+ describe("pool", () => {
22
+ beforeAll(async () => {
23
+ dhedge = new Dhedge(wallet, network);
24
+ pool = await dhedge.loadPool(TEST_POOL[network]);
25
+ });
26
+
27
+ it("approves unlimited sUSD and USDC on for Velodrome", async () => {
28
+ await pool.approve(Dapp.VELODROMEV2, SUSD, MAX_AMOUNT);
29
+ await pool.approve(Dapp.VELODROMEV2, USDC, MAX_AMOUNT);
30
+ const UsdcAllowanceDelta = await allowanceDelta(
31
+ pool.address,
32
+ USDC,
33
+ routerAddress[network].velodromeV2!,
34
+ pool.signer
35
+ );
36
+ await expect(UsdcAllowanceDelta.gt(0));
37
+ });
38
+
39
+ it("adds USDC and SUSD to a Velodrome stable pool", async () => {
40
+ await pool.addLiquidityVelodromeV2(
41
+ USDC,
42
+ SUSD,
43
+ (5 * 1e6).toString(),
44
+ (5 * 1e18).toString(),
45
+ true
46
+ );
47
+
48
+ const lpTokenDelta = await balanceDelta(
49
+ pool.address,
50
+ USDC_SUSD_Lp,
51
+ pool.signer
52
+ );
53
+ expect(lpTokenDelta.gt(0));
54
+ });
55
+
56
+ it("should stake USDC-sUSD LP in a gauge", async () => {
57
+ const balance = await dhedge.utils.getBalance(USDC_SUSD_Lp, pool.address);
58
+ await pool.approveSpender(USDC_SUSD_Gauge, USDC_SUSD_Lp, MAX_AMOUNT);
59
+ await pool.stakeInGauge(Dapp.VELODROMEV2, USDC_SUSD_Gauge, balance);
60
+ const gaugeBalance = await balanceDelta(
61
+ pool.address,
62
+ USDC_SUSD_Lp,
63
+ pool.signer
64
+ );
65
+ expect(gaugeBalance.gt(0));
66
+ });
67
+
68
+ it("should claim rewards from Gauge", async () => {
69
+ const tx = await pool.claimFees(Dapp.VELODROMEV2, USDC_SUSD_Gauge);
70
+ expect(tx).not.toBe(null);
71
+ });
72
+
73
+ it("should unStake USDC-sUSD LP from a gauge", async () => {
74
+ const gaugeBalance = await dhedge.utils.getBalance(
75
+ USDC_SUSD_Gauge,
76
+ pool.address
77
+ );
78
+ await pool.unstakeFromGauge(USDC_SUSD_Gauge, gaugeBalance);
79
+ const lpTokenDelta = await balanceDelta(
80
+ pool.address,
81
+ USDC_SUSD_Lp,
82
+ pool.signer
83
+ );
84
+ expect(lpTokenDelta.gt(0));
85
+ });
86
+
87
+ it("approves unlimited wETH/stwETH LP for Velodrome", async () => {
88
+ await pool.approve(Dapp.VELODROMEV2, USDC_SUSD_Lp, MAX_AMOUNT);
89
+ const lpAllowanceDelta = await allowanceDelta(
90
+ pool.address,
91
+ USDC_SUSD_Lp,
92
+ routerAddress[network].velodrome!,
93
+ pool.signer
94
+ );
95
+ expect(lpAllowanceDelta.gt(0));
96
+ });
97
+
98
+ it("should remove all liquidity from an existing pool ", async () => {
99
+ const balance = await dhedge.utils.getBalance(USDC_SUSD_Lp, pool.address);
100
+ await pool.removeLiquidityVelodromeV2(USDC, SUSD, balance, true);
101
+ const usdcBalanceDelta = await balanceDelta(
102
+ pool.address,
103
+ USDC,
104
+ pool.signer
105
+ );
106
+ const susdBalanceDelta = await balanceDelta(
107
+ pool.address,
108
+ SUSD,
109
+ pool.signer
110
+ );
111
+ expect(usdcBalanceDelta.gt(0));
112
+ expect(susdBalanceDelta.gt(0));
113
+ });
114
+ });
@@ -12,7 +12,7 @@ require("dotenv").config();
12
12
  // );
13
13
 
14
14
  // const provider = new ethers.providers.JsonRpcProvider(
15
- // `https://polygon-mainnet.infura.io/v3/${process.env.INFURA_PROJECT_ID}`
15
+ // `https://arb-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_PROJECT_ID}`
16
16
  // );
17
17
 
18
18
  // const provider = new ethers.providers.JsonRpcProvider(
@@ -0,0 +1,46 @@
1
+ /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
+ import { Dhedge, Pool } from "..";
3
+ import { routerAddress } from "../config";
4
+ import { Dapp, Network } from "../types";
5
+ import { CONTRACT_ADDRESS, MAX_AMOUNT, TEST_POOL } from "./constants";
6
+ import { allowanceDelta, balanceDelta } from "./utils/token";
7
+
8
+ import { wallet } from "./wallet";
9
+
10
+ //const network = Network.OPTIMISM;
11
+ const network = Network.POLYGON;
12
+ // const network = Network.ARBITRUM;
13
+ const USDC = CONTRACT_ADDRESS[network].USDC;
14
+ const WETH = CONTRACT_ADDRESS[network].WETH;
15
+
16
+ let dhedge: Dhedge;
17
+ let pool: Pool;
18
+ jest.setTimeout(100000);
19
+
20
+ describe("pool", () => {
21
+ beforeAll(async () => {
22
+ dhedge = new Dhedge(wallet, network);
23
+ pool = await dhedge.loadPool(TEST_POOL[network]);
24
+ });
25
+
26
+ it("approves unlimited USDC on 0x", async () => {
27
+ await pool.approve(Dapp.ZEROEX, USDC, MAX_AMOUNT);
28
+ const usdcAllowanceDelta = await allowanceDelta(
29
+ pool.address,
30
+ USDC,
31
+ routerAddress[network]["0x"]!,
32
+ pool.signer
33
+ );
34
+ await expect(usdcAllowanceDelta.gt(0));
35
+ });
36
+
37
+ it("trades 2 USDC into WETH on 0x", async () => {
38
+ await pool.trade(Dapp.ZEROEX, USDC, WETH, "2000000", 0.5);
39
+ const wethBalanceDelta = await balanceDelta(
40
+ pool.address,
41
+ WETH,
42
+ pool.signer
43
+ );
44
+ expect(wethBalanceDelta.gt(0));
45
+ });
46
+ });
package/src/types.ts CHANGED
@@ -3,7 +3,8 @@ import { BigNumber } from "ethers";
3
3
 
4
4
  export enum Network {
5
5
  POLYGON = "polygon",
6
- OPTIMISM = "optimism"
6
+ OPTIMISM = "optimism",
7
+ ARBITRUM = "arbitrum"
7
8
  }
8
9
 
9
10
  export enum Dapp {
@@ -18,7 +19,9 @@ export enum Dapp {
18
19
  ARRAKIS = "arrakis",
19
20
  TOROS = "toros",
20
21
  VELODROME = "velodrome",
21
- LYRA = "lyra"
22
+ VELODROMEV2 = "velodromeV2",
23
+ LYRA = "lyra",
24
+ ZEROEX = "0x"
22
25
  }
23
26
 
24
27
  export enum Transaction {