@dhedge/v2-sdk 1.8.0 → 1.8.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhedge/v2-sdk",
3
- "version": "1.8.0",
3
+ "version": "1.8.2",
4
4
  "license": "MIT",
5
5
  "description": "🛠 An SDK for building applications on top of dHEDGE V2",
6
6
  "main": "dist/index.js",
@@ -1242,11 +1242,12 @@ export class Pool {
1242
1242
  changeAmount: BigNumber | string,
1243
1243
  options: any = null
1244
1244
  ): Promise<any> {
1245
- const tx = await this.poolLogic.execTransaction(
1245
+ const txData = await getFuturesChangePositionTxData(
1246
+ changeAmount,
1246
1247
  market,
1247
- getFuturesChangePositionTxData(changeAmount),
1248
- options
1248
+ this
1249
1249
  );
1250
+ const tx = await this.poolLogic.execTransaction(market, txData, options);
1250
1251
  return tx;
1251
1252
  }
1252
1253
  }
@@ -1,4 +1 @@
1
- import { BigNumber } from "ethers";
2
-
3
- export const PRICE_IMPACT_DELTA = BigNumber.from("500000000000000000");
4
1
  export const FUTURES_TRACKING = "DHEDGE";
@@ -1,15 +1,26 @@
1
- import { ethers } from "../..";
2
- import { FUTURES_TRACKING, PRICE_IMPACT_DELTA } from "./constants";
1
+ import { Pool, ethers } from "../..";
2
+ import { FUTURES_TRACKING } from "./constants";
3
3
  import ISynthetixFuturesMarketV2 from "../../abi/ISynthetixFuturesMarketV2.json";
4
4
 
5
- export function getFuturesChangePositionTxData(
6
- amount: ethers.BigNumber | string
7
- ): string {
5
+ export async function getFuturesChangePositionTxData(
6
+ amount: ethers.BigNumber | string,
7
+ market: string,
8
+ pool: Pool
9
+ ): Promise<string> {
10
+ const futuresMarket = new ethers.Contract(
11
+ market,
12
+ ISynthetixFuturesMarketV2.abi,
13
+ pool.signer
14
+ );
15
+ const fillPrice = await futuresMarket.fillPrice(amount);
16
+ //Allows for +-0.5% price movements on the desired fill price
17
+ const adjustmentFactor = ethers.BigNumber.from(amount).lt(0) ? 995 : 1005;
18
+ const desiredFillPrice = fillPrice.price.mul(adjustmentFactor).div(1000);
8
19
  return new ethers.utils.Interface(
9
20
  ISynthetixFuturesMarketV2.abi
10
21
  ).encodeFunctionData("submitOffchainDelayedOrderWithTracking", [
11
22
  amount,
12
- PRICE_IMPACT_DELTA,
23
+ desiredFillPrice,
13
24
  ethers.utils.formatBytes32String(FUTURES_TRACKING)
14
25
  ]);
15
26
  }
@@ -1,7 +1,5 @@
1
1
  import axios from "axios";
2
2
 
3
- const excludedProtocols = ["OPTIMISM_PMM6"]; //Clipper
4
-
5
3
  export async function getOneInchProtocols(chainId: number): Promise<string> {
6
4
  try {
7
5
  const response = await axios.get(
@@ -9,8 +7,9 @@ export async function getOneInchProtocols(chainId: number): Promise<string> {
9
7
  );
10
8
  const protocols = response.data.protocols.map((e: { id: string }) => e.id);
11
9
  const filteredProtocols = protocols.filter(
12
- (e: string) => !excludedProtocols.includes(e)
10
+ (e: string) => !e.includes("PMM")
13
11
  );
12
+
14
13
  return `&protocols=${filteredProtocols.join(",")}`;
15
14
  } catch {
16
15
  return "";
@@ -29,9 +29,9 @@ describe("pool", () => {
29
29
  expect(sUSDBalanceDelta.abs().toString()).toBe(depositAmount);
30
30
  });
31
31
 
32
- it("goes long ETH-PERP about 3x leverage", async () => {
33
- //size 50*3/1600 (margin * leverage / price)
34
- const size = (0.09 * 1e18).toString();
32
+ it("goes long ETH-PERP about 2x leverage", async () => {
33
+ //size 50*2/2000 (margin * leverage / price)
34
+ const size = (0.05 * 1e18).toString();
35
35
  const tx = await pool.changeFuturesPosition(perp, size);
36
36
  expect(tx).not.toBe(null);
37
37
  });
@@ -1,54 +0,0 @@
1
- import { Dhedge } from "..";
2
- import { Dapp, Network } from "../types";
3
- import { TEST_POOL, USDC, WBTC } from "./constants";
4
- import { getTxOptions } from "./txOptions";
5
-
6
- import { wallet } from "./wallet";
7
-
8
- let dhedge: Dhedge;
9
- let options: any;
10
-
11
- jest.setTimeout(100000);
12
-
13
- describe("pool", () => {
14
- beforeAll(async () => {
15
- dhedge = new Dhedge(wallet, Network.OPTIMISM);
16
- options = await getTxOptions(Network.OPTIMISM);
17
- });
18
-
19
- // it("approves unlimited USDC on 1Inch", async () => {
20
- // let result;
21
- // const pool = await dhedge.loadPool(TEST_POOL);
22
- // try {
23
- // result = await pool.approve(
24
- // Dapp.ONEINCH,
25
- // USDC,
26
- // ethers.constants.MaxInt256,
27
- // options
28
- // );
29
- // console.log(result);
30
- // } catch (e) {
31
- // console.log(e);
32
- // }
33
- // expect(result).not.toBe(null);
34
- // });
35
-
36
- it("trades 1 USDC into WBTC on 1Inch", async () => {
37
- let result;
38
- const pool = await dhedge.loadPool(TEST_POOL);
39
- try {
40
- result = await pool.trade(
41
- Dapp.ONEINCH,
42
- USDC,
43
- WBTC,
44
- "1000000",
45
- 0.5,
46
- options
47
- );
48
- console.log(result);
49
- } catch (e) {
50
- console.log(e);
51
- }
52
- expect(result).not.toBe(null);
53
- });
54
- });