@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/dist/services/futures/constants.d.ts +0 -2
- package/dist/services/futures/trade.d.ts +2 -2
- package/dist/v2-sdk.cjs.development.js +38 -6
- package/dist/v2-sdk.cjs.development.js.map +1 -1
- package/dist/v2-sdk.cjs.production.min.js +1 -1
- package/dist/v2-sdk.cjs.production.min.js.map +1 -1
- package/dist/v2-sdk.esm.js +38 -6
- package/dist/v2-sdk.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/entities/pool.ts +4 -3
- package/src/services/futures/constants.ts +0 -3
- package/src/services/futures/trade.ts +17 -6
- package/src/test/futures.test.ts +3 -3
package/package.json
CHANGED
package/src/entities/pool.ts
CHANGED
|
@@ -1242,11 +1242,12 @@ export class Pool {
|
|
|
1242
1242
|
changeAmount: BigNumber | string,
|
|
1243
1243
|
options: any = null
|
|
1244
1244
|
): Promise<any> {
|
|
1245
|
-
const
|
|
1245
|
+
const txData = await getFuturesChangePositionTxData(
|
|
1246
|
+
changeAmount,
|
|
1246
1247
|
market,
|
|
1247
|
-
|
|
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,15 +1,26 @@
|
|
|
1
|
-
import { ethers } from "../..";
|
|
2
|
-
import { FUTURES_TRACKING
|
|
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
|
-
|
|
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
|
-
|
|
23
|
+
desiredFillPrice,
|
|
13
24
|
ethers.utils.formatBytes32String(FUTURES_TRACKING)
|
|
14
25
|
]);
|
|
15
26
|
}
|
package/src/test/futures.test.ts
CHANGED
|
@@ -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
|
|
33
|
-
//size 50*
|
|
34
|
-
const size = (0.
|
|
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
|
});
|