@dhedge/v2-sdk 1.9.0 → 1.9.2

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,20 @@
1
+ import { ethers } from "ethers";
2
+ import { Network } from "../../types";
3
+ import { getWallet } from "../wallet";
4
+
5
+ export type TestingRunParams = {
6
+ network: Network;
7
+ wallet: ethers.Wallet;
8
+ };
9
+
10
+ type TestHelperParams = {
11
+ testingRun: (testingRunParams: TestingRunParams) => void;
12
+ } & { network: Network };
13
+
14
+ export const testingHelper = ({
15
+ network,
16
+ testingRun
17
+ }: TestHelperParams): void => {
18
+ const wallet = getWallet(network);
19
+ testingRun({ network, wallet });
20
+ };
@@ -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
+ });
@@ -1,5 +1,5 @@
1
1
  import { ethers } from "ethers";
2
-
2
+ import { Network } from "../types";
3
3
  // eslint-disable-next-line @typescript-eslint/no-var-requires
4
4
  require("dotenv").config();
5
5
 
@@ -25,3 +25,16 @@ export const wallet = new ethers.Wallet(
25
25
  process.env.PRIVATE_KEY as string,
26
26
  provider
27
27
  );
28
+
29
+ export const networkPortMap = {
30
+ [Network.POLYGON]: 8542,
31
+ [Network.OPTIMISM]: 8544,
32
+ [Network.ARBITRUM]: 8540
33
+ };
34
+
35
+ export const getWallet = (network: Network): ethers.Wallet => {
36
+ const provider = new ethers.providers.JsonRpcProvider(
37
+ `http://127.0.0.1:${networkPortMap[network]}/`
38
+ );
39
+ return new ethers.Wallet(process.env.PRIVATE_KEY as string, provider);
40
+ };
@@ -0,0 +1,54 @@
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 { TestingRunParams, testingHelper } from "./utils/testingHelper";
7
+ import { allowanceDelta, balanceDelta } from "./utils/token";
8
+
9
+ const testZeroEx = ({ wallet, network }: TestingRunParams) => {
10
+ const USDC = CONTRACT_ADDRESS[network].USDC;
11
+ const WETH = CONTRACT_ADDRESS[network].WETH;
12
+
13
+ let dhedge: Dhedge;
14
+ let pool: Pool;
15
+ jest.setTimeout(100000);
16
+
17
+ describe(`[${network}] 0x trade`, () => {
18
+ beforeAll(async () => {
19
+ dhedge = new Dhedge(wallet, network);
20
+ pool = await dhedge.loadPool(TEST_POOL[network]);
21
+ });
22
+
23
+ it("approves unlimited USDC on 0x", async () => {
24
+ await pool.approve(Dapp.ZEROEX, USDC, MAX_AMOUNT);
25
+ const usdcAllowanceDelta = await allowanceDelta(
26
+ pool.address,
27
+ USDC,
28
+ routerAddress[network]["0x"]!,
29
+ pool.signer
30
+ );
31
+ await expect(usdcAllowanceDelta.gt(0));
32
+ });
33
+
34
+ it("trades 2 USDC into WETH on 0x", async () => {
35
+ await pool.trade(Dapp.ZEROEX, USDC, WETH, "2000000", 0.5);
36
+ const wethBalanceDelta = await balanceDelta(
37
+ pool.address,
38
+ WETH,
39
+ pool.signer
40
+ );
41
+ expect(wethBalanceDelta.gt(0));
42
+ });
43
+ });
44
+ };
45
+
46
+ testingHelper({
47
+ network: Network.OPTIMISM,
48
+ testingRun: testZeroEx
49
+ });
50
+
51
+ testingHelper({
52
+ network: Network.POLYGON,
53
+ testingRun: testZeroEx
54
+ });
package/src/types.ts CHANGED
@@ -19,7 +19,9 @@ export enum Dapp {
19
19
  ARRAKIS = "arrakis",
20
20
  TOROS = "toros",
21
21
  VELODROME = "velodrome",
22
- LYRA = "lyra"
22
+ VELODROMEV2 = "velodromeV2",
23
+ LYRA = "lyra",
24
+ ZEROEX = "0x"
23
25
  }
24
26
 
25
27
  export enum Transaction {
@@ -1 +0,0 @@
1
- export declare function getOneInchProtocols(chainId: number): Promise<string>;
@@ -1,17 +0,0 @@
1
- import axios from "axios";
2
-
3
- export async function getOneInchProtocols(chainId: number): Promise<string> {
4
- try {
5
- const response = await axios.get(
6
- `https://api.1inch.io/v5.0/${chainId}/liquidity-sources`
7
- );
8
- const protocols = response.data.protocols.map((e: { id: string }) => e.id);
9
- const filteredProtocols = protocols.filter(
10
- (e: string) => !e.includes("PMM")
11
- );
12
-
13
- return `&protocols=${filteredProtocols.join(",")}`;
14
- } catch {
15
- return "";
16
- }
17
- }