@dhedge/v2-sdk 1.8.1 → 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.1",
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
  }
@@ -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
  });