@dhedge/v2-sdk 1.7.2 → 1.8.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.
Files changed (49) hide show
  1. package/dist/config.d.ts +0 -1
  2. package/dist/entities/pool.d.ts +16 -7
  3. package/dist/services/futures/constants.d.ts +3 -0
  4. package/dist/services/futures/index.d.ts +2 -0
  5. package/dist/services/futures/margin.d.ts +2 -0
  6. package/dist/services/futures/trade.d.ts +2 -0
  7. package/dist/services/velodrome/liquidity.d.ts +2 -2
  8. package/dist/test/constants.d.ts +24 -2
  9. package/dist/test/utils/token.d.ts +3 -0
  10. package/dist/utils/deadline.d.ts +2 -0
  11. package/dist/v2-sdk.cjs.development.js +4540 -5103
  12. package/dist/v2-sdk.cjs.development.js.map +1 -1
  13. package/dist/v2-sdk.cjs.production.min.js +1 -1
  14. package/dist/v2-sdk.cjs.production.min.js.map +1 -1
  15. package/dist/v2-sdk.esm.js +7341 -7904
  16. package/dist/v2-sdk.esm.js.map +1 -1
  17. package/package.json +5 -2
  18. package/src/abi/IDhedgeEasySwapper.json +99 -239
  19. package/src/abi/ISynthetiXFuturesMarketV2.json +531 -0
  20. package/src/config.ts +4 -5
  21. package/src/entities/pool.ts +68 -44
  22. package/src/services/futures/constants.ts +4 -0
  23. package/src/services/futures/index.ts +2 -0
  24. package/src/services/futures/margin.ts +10 -0
  25. package/src/services/futures/trade.ts +15 -0
  26. package/src/services/oneInch/protocols.ts +3 -4
  27. package/src/services/toros/easySwapper.ts +3 -2
  28. package/src/services/uniswap/V3Liquidity.ts +2 -3
  29. package/src/services/velodrome/liquidity.ts +7 -7
  30. package/src/test/constants.ts +27 -2
  31. package/src/test/futures.test.ts +48 -0
  32. package/src/test/oneInch.test.ts +32 -36
  33. package/src/test/pool.test.ts +42 -85
  34. package/src/test/toros.test.ts +50 -98
  35. package/src/test/uniswap.test.ts +65 -30
  36. package/src/test/utils/token.ts +31 -0
  37. package/src/test/velodrome.test.ts +74 -101
  38. package/src/test/wallet.ts +5 -3
  39. package/src/utils/deadline.ts +6 -0
  40. package/dist/services/claim-balancer/claim.service.d.ts +0 -17
  41. package/dist/services/claim-balancer/claim.worker.d.ts +0 -4
  42. package/dist/services/claim-balancer/ipfs.service.d.ts +0 -4
  43. package/dist/services/claim-balancer/types.d.ts +0 -54
  44. package/src/services/claim-balancer/MultiTokenClaim.json +0 -115
  45. package/src/services/claim-balancer/claim.service.ts +0 -262
  46. package/src/services/claim-balancer/claim.worker.ts +0 -32
  47. package/src/services/claim-balancer/ipfs.service.ts +0 -12
  48. package/src/services/claim-balancer/types.ts +0 -66
  49. package/src/test/1inch.test.ts +0 -54
@@ -1,141 +1,114 @@
1
+ /* eslint-disable @typescript-eslint/no-non-null-assertion */
1
2
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { Dhedge, ethers } from "..";
3
+ import { Dhedge, Pool } from "..";
4
+ import { routerAddress } from "../config";
3
5
  import { Dapp, Network } from "../types";
4
- import { TEST_POOL, VEL, WETH, WSTETH } from "./constants";
5
- import { getTxOptions } from "./txOptions";
6
+ import { CONTRACT_ADDRESS, MAX_AMOUNT, TEST_POOL } from "./constants";
7
+ import { allowanceDelta, balanceDelta } from "./utils/token";
6
8
 
7
9
  import { wallet } from "./wallet";
8
10
 
9
- const wETHwstETHLp = "0xBf205335De602ac38244F112d712ab04CB59A498";
10
- const wETHwstETHGauge = "0x131Ae347E654248671Afc885F0767cB605C065d7";
11
+ const USDC_SUSD_Lp = "0xd16232ad60188b68076a235c65d692090caba155";
12
+ const USDC_SUSD_Gauge = "0xb03f52d2db3e758dd49982defd6aeefea9454e80";
13
+ const network = Network.OPTIMISM;
14
+ const SUSD = CONTRACT_ADDRESS[network].SUSD;
15
+ const USDC = CONTRACT_ADDRESS[network].USDC;
11
16
 
12
17
  let dhedge: Dhedge;
13
- let options: any;
18
+ let pool: Pool;
14
19
  jest.setTimeout(100000);
15
20
 
16
21
  describe("pool", () => {
17
22
  beforeAll(async () => {
18
- dhedge = new Dhedge(wallet, Network.OPTIMISM);
19
- options = await getTxOptions(Network.OPTIMISM);
23
+ dhedge = new Dhedge(wallet, network);
24
+ pool = await dhedge.loadPool(TEST_POOL[network]);
20
25
  });
21
26
 
22
- it("approves unlimited WETH on for Velodrome", async () => {
23
- let result;
24
- const pool = await dhedge.loadPool(TEST_POOL);
25
- try {
26
- result = await pool.approve(
27
- Dapp.VELODROME,
28
- WSTETH,
29
- ethers.constants.MaxInt256,
30
- options
31
- );
32
- console.log(result);
33
- } catch (e) {
34
- console.log(e);
35
- }
36
- expect(result).not.toBe(null);
27
+ it("approves unlimited sUSD and USDC on for Velodrome", async () => {
28
+ await pool.approve(Dapp.VELODROME, SUSD, MAX_AMOUNT);
29
+ await pool.approve(Dapp.VELODROME, USDC, MAX_AMOUNT);
30
+ const UsdcAllowanceDelta = await allowanceDelta(
31
+ pool.address,
32
+ USDC,
33
+ routerAddress[network].velodrome!,
34
+ pool.signer
35
+ );
36
+ await expect(UsdcAllowanceDelta.gt(0));
37
37
  });
38
38
 
39
- it("adds WETH and wstETH to a Velodrome stable pool", async () => {
40
- const pool = await dhedge.loadPool(TEST_POOL);
41
- const wethBalance = await dhedge.utils.getBalance(WETH, pool.address);
42
- const stwethBalance = await dhedge.utils.getBalance(WSTETH, pool.address);
43
-
44
- const result = await pool.addLiquidityVelodrome(
45
- WETH,
46
- WSTETH,
47
- wethBalance,
48
- stwethBalance,
49
- true,
50
- options
39
+ it("adds USDC and SUSD to a Velodrome stable pool", async () => {
40
+ await pool.addLiquidityVelodrome(
41
+ USDC,
42
+ SUSD,
43
+ (5 * 1e6).toString(),
44
+ (5 * 1e18).toString(),
45
+ true
51
46
  );
52
47
 
53
- result.wait(1);
54
- const lpBalance = await dhedge.utils.getBalance(wETHwstETHLp, pool.address);
55
- expect(lpBalance.gt(0));
48
+ const lpTokenDelta = await balanceDelta(
49
+ pool.address,
50
+ USDC_SUSD_Lp,
51
+ pool.signer
52
+ );
53
+ expect(lpTokenDelta.gt(0));
56
54
  });
57
55
 
58
- it("should stake wETH/wStETH LP in a gauge", async () => {
59
- const pool = await dhedge.loadPool(TEST_POOL);
60
- const balance = await dhedge.utils.getBalance(wETHwstETHLp, pool.address);
61
- const result = await pool.stakeInGauge(
62
- Dapp.VELODROME,
63
- wETHwstETHGauge,
64
- balance,
65
- options
66
- );
67
- result.wait(1);
68
- const gaugeBalance = await dhedge.utils.getBalance(
69
- wETHwstETHGauge,
70
- pool.address
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.VELODROME, USDC_SUSD_Gauge, balance);
60
+ const gaugeBalance = await balanceDelta(
61
+ pool.address,
62
+ USDC_SUSD_Lp,
63
+ pool.signer
71
64
  );
72
65
  expect(gaugeBalance.gt(0));
73
66
  });
74
67
 
75
68
  it("should claim rewards from Gauge", async () => {
76
- const pool = await dhedge.loadPool(TEST_POOL);
77
- const result = await pool.claimFees(
78
- Dapp.VELODROME,
79
- wETHwstETHGauge,
80
- options
81
- );
82
- result.wait(1);
83
- const velBalance = await dhedge.utils.getBalance(VEL, pool.address);
84
- expect(velBalance.gt(0));
69
+ const tx = await pool.claimFees(Dapp.VELODROME, USDC_SUSD_Gauge);
70
+ expect(tx).not.toBe(null);
85
71
  });
86
72
 
87
- it("should unStake wETH/wStETH LP from a gauge", async () => {
88
- const pool = await dhedge.loadPool(TEST_POOL);
73
+ it("should unStake USDC-sUSD LP from a gauge", async () => {
89
74
  const gaugeBalance = await dhedge.utils.getBalance(
90
- wETHwstETHGauge,
75
+ USDC_SUSD_Gauge,
91
76
  pool.address
92
77
  );
93
- const result = await pool.unstakeFromGauge(
94
- wETHwstETHGauge,
95
- gaugeBalance,
96
- options
97
- );
98
- result.wait(1);
99
- const lpBalance = await dhedge.utils.getBalance(wETHwstETHLp, pool.address);
100
- expect(lpBalance.gt(0));
101
- const gaugeBalanceAfter = await dhedge.utils.getBalance(
102
- wETHwstETHGauge,
103
- pool.address
78
+ await pool.unstakeFromGauge(USDC_SUSD_Gauge, gaugeBalance);
79
+ const lpTokenDelta = await balanceDelta(
80
+ pool.address,
81
+ USDC_SUSD_Lp,
82
+ pool.signer
104
83
  );
105
- expect(gaugeBalanceAfter.eq(0));
84
+ expect(lpTokenDelta.gt(0));
106
85
  });
107
86
 
108
87
  it("approves unlimited wETH/stwETH LP for Velodrome", async () => {
109
- let result;
110
- const pool = await dhedge.loadPool(TEST_POOL);
111
- try {
112
- result = await pool.approve(
113
- Dapp.VELODROME,
114
- wETHwstETHLp,
115
- ethers.constants.MaxInt256,
116
- options
117
- );
118
- console.log(result);
119
- } catch (e) {
120
- console.log(e);
121
- }
122
- expect(result).not.toBe(null);
88
+ await pool.approve(Dapp.VELODROME, 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));
123
96
  });
124
97
 
125
98
  it("should remove all liquidity from an existing pool ", async () => {
126
- const pool = await dhedge.loadPool(TEST_POOL);
127
- const balance = await dhedge.utils.getBalance(wETHwstETHLp, pool.address);
128
- const result = await pool.removeLiquidityVelodrome(
129
- WETH,
130
- WSTETH,
131
- balance,
132
- options
99
+ const balance = await dhedge.utils.getBalance(USDC_SUSD_Lp, pool.address);
100
+ await pool.removeLiquidityVelodrome(USDC, SUSD, balance, true);
101
+ const usdcBalanceDelta = await balanceDelta(
102
+ pool.address,
103
+ USDC,
104
+ pool.signer
133
105
  );
134
- result.wait(1);
135
- const balanceAfter = await dhedge.utils.getBalance(
136
- wETHwstETHLp,
137
- pool.address
106
+ const susdBalanceDelta = await balanceDelta(
107
+ pool.address,
108
+ SUSD,
109
+ pool.signer
138
110
  );
139
- expect(balanceAfter.eq(0));
111
+ expect(usdcBalanceDelta.gt(0));
112
+ expect(susdBalanceDelta.gt(0));
140
113
  });
141
114
  });
@@ -3,9 +3,9 @@ import { ethers } from "ethers";
3
3
  // eslint-disable-next-line @typescript-eslint/no-var-requires
4
4
  require("dotenv").config();
5
5
 
6
- const provider = new ethers.providers.JsonRpcProvider(
7
- `https://opt-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_PROJECT_ID}`
8
- );
6
+ // const provider = new ethers.providers.JsonRpcProvider(
7
+ // `https://opt-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_PROJECT_ID}`
8
+ // );
9
9
 
10
10
  // const provider = new ethers.providers.JsonRpcProvider(
11
11
  // `https://opt-kovan.g.alchemy.com/v2/${process.env.ALCHEMY_PROJECT_ID}`
@@ -19,6 +19,8 @@ const provider = new ethers.providers.JsonRpcProvider(
19
19
  // `https://polygon-mainnet.infura.io/v3/${process.env.INFURA_PROJECT_ID}`
20
20
  // );
21
21
 
22
+ const provider = new ethers.providers.JsonRpcProvider("http://127.0.0.1:8545/");
23
+
22
24
  export const wallet = new ethers.Wallet(
23
25
  process.env.PRIVATE_KEY as string,
24
26
  provider
@@ -0,0 +1,6 @@
1
+ import { Pool } from "../entities";
2
+
3
+ export const getDeadline = async (pool: Pool): Promise<number> => {
4
+ const timestamp = (await pool.signer.provider.getBlock("latest")).timestamp;
5
+ return timestamp + 60 * 20; //add 20 min
6
+ };
@@ -1,17 +0,0 @@
1
- import { ethers, Wallet } from "ethers";
2
- import { MultiTokenPendingClaims, TokenClaimInfo } from "./types";
3
- import { Network } from "../../types";
4
- export declare class ClaimService {
5
- network: Network;
6
- signer: ethers.Wallet;
7
- constructor(network: Network, signer: Wallet);
8
- getMultiTokensPendingClaims(account: string): Promise<MultiTokenPendingClaims[]>;
9
- getTokenPendingClaims(tokenClaimInfo: TokenClaimInfo, account: string): Promise<MultiTokenPendingClaims>;
10
- multiTokenClaimRewards(account: string, multiTokenPendingClaims: MultiTokenPendingClaims[]): Promise<any>;
11
- private computeClaimProofs;
12
- private computeClaimProof;
13
- private getTokenClaimsInfo;
14
- private getSnapshot;
15
- private getClaimStatus;
16
- private getReports;
17
- }
@@ -1,4 +0,0 @@
1
- import { ComputeClaimProofPayload } from "./types";
2
- export declare class ClaimWorker {
3
- calcClaimProof(payload: ComputeClaimProofPayload): any;
4
- }
@@ -1,4 +0,0 @@
1
- export default class IpfsService {
2
- get<T>(hash: string, protocol?: string): Promise<T>;
3
- }
4
- export declare const ipfsService: IpfsService;
@@ -1,54 +0,0 @@
1
- export interface Claim {
2
- id: string;
3
- amount: string;
4
- }
5
- export declare type Snapshot = Record<number, string>;
6
- export declare type TokenClaimInfo = {
7
- label: string;
8
- distributor: string;
9
- token: string;
10
- decimals: number;
11
- manifest: string;
12
- weekStart: number;
13
- };
14
- export declare type MultiTokenPendingClaims = {
15
- claims: Claim[];
16
- reports: Report;
17
- tokenClaimInfo: TokenClaimInfo;
18
- availableToClaim: string;
19
- };
20
- export declare type ClaimStatus = boolean;
21
- export declare type Report = Record<string, any>;
22
- export declare type MultiTokenCurrentRewardsEstimateResponse = {
23
- success: boolean;
24
- result: {
25
- current_timestamp: string;
26
- "liquidity-providers": Array<{
27
- snapshot_timestamp: string;
28
- address: string;
29
- token_address: string;
30
- chain_id: number;
31
- current_estimate: string;
32
- velocity: string;
33
- week: number;
34
- }>;
35
- };
36
- };
37
- export declare type MultiTokenCurrentRewardsEstimate = {
38
- rewards: string;
39
- velocity: string;
40
- token: string;
41
- };
42
- export declare type ClaimProofTuple = [number, string, string, number, string[]];
43
- export declare type ComputeClaimProofPayload = {
44
- report: Report;
45
- account: string;
46
- claim: Claim;
47
- distributor: string;
48
- tokenIndex: number;
49
- decimals: number;
50
- };
51
- export declare type ClaimWorkerMessage<P = any> = {
52
- type: "computeClaimProof";
53
- payload: P;
54
- };
@@ -1,115 +0,0 @@
1
- {
2
- "1": [
3
- {
4
- "label": "BAL",
5
- "distributor": "0xd2EB7Bd802A7CA68d9AcD209bEc4E664A9abDD7b",
6
- "token": "0xba100000625a3754423978a60c9317c58a424e3d",
7
- "manifest": "https://raw.githubusercontent.com/balancer-labs/bal-mining-scripts/master/reports/_current.json",
8
- "weekStart": 52
9
- },
10
- {
11
- "label": "UNN",
12
- "distributor": "0xBfbd6e720ffdF0497f69C95E5C03a4861C65A6E7",
13
- "token": "0x226f7b842E0F0120b7E194D05432b3fd14773a9D",
14
- "manifest": "https://raw.githubusercontent.com/balancer-labs/bal-mining-scripts/master/reports/_current-union.json",
15
- "weekStart": 1
16
- },
17
- {
18
- "label": "BANK",
19
- "distributor": "0x9d20FE66eC5Dd15a3D3213556534C77cA20318bE",
20
- "token": "0x2d94AA3e47d9D5024503Ca8491fcE9A2fB4DA198",
21
- "manifest": "https://raw.githubusercontent.com/balancer-labs/bal-mining-scripts/master/reports/_current-bankless.json",
22
- "weekStart": 1
23
- },
24
- {
25
- "label": "NOTE",
26
- "distributor": "0xF1C2dD9bD863f2444086B739383F1043E6b88F69",
27
- "token": "0xcfeaead4947f0705a14ec42ac3d44129e1ef3ed5",
28
- "manifest": "https://raw.githubusercontent.com/balancer-labs/bal-mining-scripts/master/reports/_current-note.json",
29
- "weekStart": 1
30
- },
31
- {
32
- "label": "NEXO",
33
- "distributor": "0x0000000000000000000000000000000000000000",
34
- "token": "0xB62132e35a6c13ee1EE0f84dC5d40bad8d815206",
35
- "manifest": "https://raw.githubusercontent.com/balancer-labs/bal-mining-scripts/master/reports/_current-nexo.json",
36
- "weekStart": 1
37
- }
38
- ],
39
- "42": [
40
- {
41
- "label": "BAL",
42
- "distributor": "0x95FaE1C936B4Cd6c5099d7A705D792ee6aC9FEc3",
43
- "token": "0x41286Bb1D3E870f3F750eB7E1C25d7E48c8A1Ac7",
44
- "manifest": "https://raw.githubusercontent.com/balancer-labs/bal-mining-scripts/sample-tree/reports-kovan/_current.json",
45
- "weekStart": 52
46
- },
47
- {
48
- "label": "DAI",
49
- "distributor": "0x95FaE1C936B4Cd6c5099d7A705D792ee6aC9FEc3",
50
- "token": "0x04DF6e4121c27713ED22341E7c7Df330F56f289B",
51
- "manifest": "https://raw.githubusercontent.com/balancer-labs/bal-mining-scripts/sample-tree/reports-kovan/_current-dai.json",
52
- "weekStart": 1
53
- }
54
- ],
55
- "137": [
56
- {
57
- "label": "BAL",
58
- "distributor": "0xd2EB7Bd802A7CA68d9AcD209bEc4E664A9abDD7b",
59
- "token": "0x9a71012b13ca4d3d0cdc72a177df3ef03b0e76a3",
60
- "manifest": "https://raw.githubusercontent.com/balancer-labs/bal-mining-scripts/master/reports/_current-polygon.json",
61
- "weekStart": 1
62
- },
63
- {
64
- "label": "WMATIC",
65
- "distributor": "0x087A7AFB6975A2837453BE685EB6272576c0bC06",
66
- "token": "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270",
67
- "manifest": "https://raw.githubusercontent.com/balancer-labs/bal-mining-scripts/master/reports/_current-wmatic-polygon.json",
68
- "weekStart": 1
69
- },
70
- {
71
- "label": "WMATIC",
72
- "distributor": "0xBd44C01EC7d623372B4572247afB6231eDD8486F",
73
- "token": "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270",
74
- "manifest": "https://raw.githubusercontent.com/balancer-labs/bal-mining-scripts/master/reports/_current-wmatic-polygon.json",
75
- "weekStart": 4
76
- },
77
- {
78
- "label": "WMATIC",
79
- "distributor": "0x632208491602Dd205da8Cb9C0BA98620fc19854A",
80
- "token": "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270",
81
- "manifest": "https://raw.githubusercontent.com/balancer-labs/bal-mining-scripts/master/reports/_current-wmatic-polygon.json",
82
- "weekStart": 5
83
- },
84
- {
85
- "label": "TUSD",
86
- "distributor": "0x09f3010ec0f6d72ef8ff2008f8e756d60482c9a8",
87
- "token": "0x2e1ad108ff1d8c782fcbbb89aad783ac49586756",
88
- "manifest": "https://raw.githubusercontent.com/balancer-labs/bal-mining-scripts/master/reports/_current-tusd-polygon.json",
89
- "weekStart": 1
90
- }
91
- ],
92
- "42161": [
93
- {
94
- "label": "BAL",
95
- "distributor": "0xd2EB7Bd802A7CA68d9AcD209bEc4E664A9abDD7b",
96
- "token": "0x040d1EdC9569d4Bab2D15287Dc5A4F10F56a56B8",
97
- "manifest": "https://raw.githubusercontent.com/balancer-labs/bal-mining-scripts/master/reports/_current-arbitrum.json",
98
- "weekStart": 6
99
- },
100
- {
101
- "label": "MCB",
102
- "distributor": "0x25c646adf184051b35a405b9aaeba321e8d5342a",
103
- "token": "0x4e352cf164e64adcbad318c3a1e222e9eba4ce42",
104
- "manifest": "https://raw.githubusercontent.com/balancer-labs/bal-mining-scripts/master/reports/_current-mcdex-arbitrum.json",
105
- "weekStart": 4
106
- },
107
- {
108
- "label": "PICKLE",
109
- "distributor": "0xf02CeB58d549E4b403e8F85FBBaEe4c5dfA47c01",
110
- "token": "0x965772e0e9c84b6f359c8597c891108dcf1c5b1a",
111
- "manifest": "https://raw.githubusercontent.com/balancer-labs/bal-mining-scripts/master/reports/_current-pickle-arbitrum.json",
112
- "weekStart": 4
113
- }
114
- ]
115
- }