@d8x/perpetuals-sdk 2.6.1 → 2.6.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/cjs/abi/IPerpetualManager.json +7 -0
- package/dist/cjs/accountTrade.js +3 -3
- package/dist/cjs/accountTrade.js.map +1 -1
- package/dist/cjs/config/defaultConfig.json +2 -1
- package/dist/cjs/contracts/IPerpetualManager.d.ts +5 -1
- package/dist/cjs/contracts/factories/IPerpetualManager__factory.d.ts +6 -0
- package/dist/cjs/contracts/factories/IPerpetualManager__factory.js +7 -0
- package/dist/cjs/contracts/factories/IPerpetualManager__factory.js.map +1 -1
- package/dist/cjs/liquidatorTool.d.ts +2 -2
- package/dist/cjs/liquidatorTool.js +3 -3
- package/dist/cjs/liquidatorTool.js.map +1 -1
- package/dist/cjs/marketData.d.ts +1 -1
- package/dist/cjs/marketData.js +3 -0
- package/dist/cjs/marketData.js.map +1 -1
- package/dist/cjs/orderExecutorTool.js +2 -2
- package/dist/cjs/orderExecutorTool.js.map +1 -1
- package/dist/cjs/perpetualDataHandler.d.ts +1 -1
- package/dist/cjs/perpetualDataHandler.js +9 -1
- package/dist/cjs/perpetualDataHandler.js.map +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/abi/IPerpetualManager.json +7 -0
- package/dist/esm/accountTrade.js +3 -3
- package/dist/esm/accountTrade.js.map +1 -1
- package/dist/esm/config/defaultConfig.json +2 -1
- package/dist/esm/contracts/IPerpetualManager.d.ts +5 -1
- package/dist/esm/contracts/factories/IPerpetualManager__factory.d.ts +6 -0
- package/dist/esm/contracts/factories/IPerpetualManager__factory.js +7 -0
- package/dist/esm/contracts/factories/IPerpetualManager__factory.js.map +1 -1
- package/dist/esm/liquidatorTool.d.ts +2 -2
- package/dist/esm/liquidatorTool.js +5 -5
- package/dist/esm/liquidatorTool.js.map +1 -1
- package/dist/esm/marketData.d.ts +1 -1
- package/dist/esm/marketData.js +4 -1
- package/dist/esm/marketData.js.map +1 -1
- package/dist/esm/orderExecutorTool.js +2 -2
- package/dist/esm/orderExecutorTool.js.map +1 -1
- package/dist/esm/perpetualDataHandler.d.ts +1 -1
- package/dist/esm/perpetualDataHandler.js +9 -1
- package/dist/esm/perpetualDataHandler.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +3 -2
- package/src/abi/IPerpetualManager.json +5596 -5589
- package/src/accountTrade.ts +4 -4
- package/src/config/defaultConfig.json +2 -1
- package/src/contracts/IPerpetualManager.ts +8 -0
- package/src/contracts/factories/IPerpetualManager__factory.ts +7 -0
- package/src/liquidatorTool.ts +5 -12
- package/src/marketData.ts +7 -9
- package/src/orderExecutorTool.ts +3 -3
- package/src/perpetualDataHandler.ts +9 -1
- package/src/version.ts +1 -1
package/src/accountTrade.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Buffer } from "buffer";
|
|
2
|
-
import { BigNumberish,
|
|
2
|
+
import { BigNumberish, ContractTransaction, ContractTransactionResponse, Overrides, Signer } from "ethers";
|
|
3
3
|
import { ZERO_ADDRESS } from "./constants";
|
|
4
4
|
import { IPerpetualManager, LimitOrderBook } from "./contracts";
|
|
5
5
|
import { PayableOverrides } from "./contracts/common";
|
|
@@ -310,7 +310,7 @@ export default class AccountTrade extends WriteAccessHandler {
|
|
|
310
310
|
// value is minimal necessary by default, but can be overriden
|
|
311
311
|
if (!overrides || overrides.value == undefined) {
|
|
312
312
|
overrides = {
|
|
313
|
-
value: submission.timestamps.length * this.
|
|
313
|
+
value: submission.timestamps.length * this.priceUpdateFee(),
|
|
314
314
|
gasLimit: overrides?.gasLimit ?? this.gasLimit,
|
|
315
315
|
...overrides,
|
|
316
316
|
} as PayableOverrides;
|
|
@@ -384,7 +384,7 @@ export default class AccountTrade extends WriteAccessHandler {
|
|
|
384
384
|
}
|
|
385
385
|
if (!overrides || overrides.value == undefined) {
|
|
386
386
|
overrides = {
|
|
387
|
-
value: submission.timestamps.length * this.
|
|
387
|
+
value: submission.timestamps.length * this.priceUpdateFee(),
|
|
388
388
|
gasLimit: overrides?.gasLimit ?? this.gasLimit,
|
|
389
389
|
...overrides,
|
|
390
390
|
} as PayableOverrides;
|
|
@@ -435,7 +435,7 @@ export default class AccountTrade extends WriteAccessHandler {
|
|
|
435
435
|
}
|
|
436
436
|
if (!overrides || overrides.value == undefined) {
|
|
437
437
|
overrides = {
|
|
438
|
-
value: submission.timestamps.length * this.
|
|
438
|
+
value: submission.timestamps.length * this.priceUpdateFee(),
|
|
439
439
|
gasLimit: overrides?.gasLimit ?? this.gasLimit,
|
|
440
440
|
...overrides,
|
|
441
441
|
} as PayableOverrides;
|
|
@@ -35,7 +35,8 @@
|
|
|
35
35
|
"shareTokenABILocation": "./abi/ShareToken.json",
|
|
36
36
|
"proxyABILocation": "./abi/IPerpetualManager.json",
|
|
37
37
|
"limitOrderBookFactoryABILocation": "./abi/LimitOrderBookFactory.json",
|
|
38
|
-
"limitOrderBookABILocation": "./abi/LimitOrderBook.json"
|
|
38
|
+
"limitOrderBookABILocation": "./abi/LimitOrderBook.json",
|
|
39
|
+
"configSource": "https://d8-x.github.io/sync-hub/d8x-futures-node-sdk/"
|
|
39
40
|
},
|
|
40
41
|
{
|
|
41
42
|
"name": "bera",
|
|
@@ -547,6 +547,7 @@ export interface IPerpetualManagerInterface extends Interface {
|
|
|
547
547
|
| "settleNextTraderInPool"
|
|
548
548
|
| "settleTraders"
|
|
549
549
|
| "splitProtocolFee"
|
|
550
|
+
| "sponsor"
|
|
550
551
|
| "testTradeEvent"
|
|
551
552
|
| "togglePerpEmergencyState"
|
|
552
553
|
| "tradeViaOrderBook"
|
|
@@ -1165,6 +1166,7 @@ export interface IPerpetualManagerInterface extends Interface {
|
|
|
1165
1166
|
functionFragment: "splitProtocolFee",
|
|
1166
1167
|
values: [BigNumberish]
|
|
1167
1168
|
): string;
|
|
1169
|
+
encodeFunctionData(functionFragment: "sponsor", values?: undefined): string;
|
|
1168
1170
|
encodeFunctionData(
|
|
1169
1171
|
functionFragment: "testTradeEvent",
|
|
1170
1172
|
values: [IPerpetualOrder.OrderStruct]
|
|
@@ -1702,6 +1704,7 @@ export interface IPerpetualManagerInterface extends Interface {
|
|
|
1702
1704
|
functionFragment: "splitProtocolFee",
|
|
1703
1705
|
data: BytesLike
|
|
1704
1706
|
): Result;
|
|
1707
|
+
decodeFunctionResult(functionFragment: "sponsor", data: BytesLike): Result;
|
|
1705
1708
|
decodeFunctionResult(
|
|
1706
1709
|
functionFragment: "testTradeEvent",
|
|
1707
1710
|
data: BytesLike
|
|
@@ -3457,6 +3460,8 @@ export interface IPerpetualManager extends BaseContract {
|
|
|
3457
3460
|
"view"
|
|
3458
3461
|
>;
|
|
3459
3462
|
|
|
3463
|
+
sponsor: TypedContractMethod<[], [void], "payable">;
|
|
3464
|
+
|
|
3460
3465
|
testTradeEvent: TypedContractMethod<
|
|
3461
3466
|
[_order: IPerpetualOrder.OrderStruct],
|
|
3462
3467
|
[void],
|
|
@@ -4420,6 +4425,9 @@ export interface IPerpetualManager extends BaseContract {
|
|
|
4420
4425
|
getFunction(
|
|
4421
4426
|
nameOrSignature: "splitProtocolFee"
|
|
4422
4427
|
): TypedContractMethod<[fee: BigNumberish], [[bigint, bigint]], "view">;
|
|
4428
|
+
getFunction(
|
|
4429
|
+
nameOrSignature: "sponsor"
|
|
4430
|
+
): TypedContractMethod<[], [void], "payable">;
|
|
4423
4431
|
getFunction(
|
|
4424
4432
|
nameOrSignature: "testTradeEvent"
|
|
4425
4433
|
): TypedContractMethod<
|
package/src/liquidatorTool.ts
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BigNumberish,
|
|
3
|
-
ContractTransactionResponse,
|
|
4
|
-
JsonRpcProvider,
|
|
5
|
-
Overrides,
|
|
6
|
-
Signer,
|
|
7
|
-
TransactionResponse,
|
|
8
|
-
} from "ethers";
|
|
1
|
+
import { BigNumberish, JsonRpcProvider, Overrides, Signer, TransactionResponse } from "ethers";
|
|
9
2
|
import { PayableOverrides } from "./contracts/common";
|
|
10
3
|
import { IPyth__factory } from "./contracts/factories";
|
|
11
|
-
import { ABK64x64ToFloat,
|
|
4
|
+
import { ABK64x64ToFloat, entropy, floatToABK64x64 } from "./d8XMath";
|
|
12
5
|
import type { NodeSDKConfig, PriceFeedSubmission } from "./nodeSDKTypes";
|
|
13
6
|
import WriteAccessHandler from "./writeAccessHandler";
|
|
14
7
|
|
|
@@ -69,7 +62,7 @@ export default class LiquidatorTool extends WriteAccessHandler {
|
|
|
69
62
|
const pyth = IPyth__factory.connect(this.pythAddr!, provider).connect(this.signer);
|
|
70
63
|
const priceIds = this.symbolToPerpStaticInfo.get(symbol)!.priceIds;
|
|
71
64
|
return await pyth.updatePriceFeedsIfNecessary(priceUpdates.priceFeedVaas, priceIds, priceUpdates.timestamps, {
|
|
72
|
-
value: this.
|
|
65
|
+
value: this.priceUpdateFee() * priceUpdates.timestamps.length,
|
|
73
66
|
gasLimit: overrides?.gasLimit ?? this.gasLimit,
|
|
74
67
|
nonce: overrides.nonce,
|
|
75
68
|
});
|
|
@@ -141,7 +134,7 @@ export default class LiquidatorTool extends WriteAccessHandler {
|
|
|
141
134
|
priceIds,
|
|
142
135
|
submission.timestamps,
|
|
143
136
|
{
|
|
144
|
-
value: this.
|
|
137
|
+
value: this.priceUpdateFee() * submission.timestamps.length,
|
|
145
138
|
gasLimit: overrides?.gasLimit ?? this.gasLimit,
|
|
146
139
|
nonce: overrides?.nonce,
|
|
147
140
|
}
|
|
@@ -166,7 +159,7 @@ export default class LiquidatorTool extends WriteAccessHandler {
|
|
|
166
159
|
submission.priceFeedVaas,
|
|
167
160
|
submission.timestamps,
|
|
168
161
|
]);
|
|
169
|
-
value = this.
|
|
162
|
+
value = this.priceUpdateFee() * submission.timestamps.length;
|
|
170
163
|
}
|
|
171
164
|
if (overrides?.nonce != undefined) {
|
|
172
165
|
overrides.nonce = overrides.nonce + nonceInc;
|
package/src/marketData.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Contract, formatUnits, Interface, JsonRpcProvider, Overrides, Provider
|
|
1
|
+
import { Contract, formatUnits, hexlify, Interface, JsonRpcProvider, Overrides, Provider } from "ethers";
|
|
2
2
|
import {
|
|
3
3
|
BUY_SIDE,
|
|
4
4
|
CLOSED_SIDE,
|
|
@@ -26,20 +26,17 @@ import { IPerpetualOrder, type PerpStorage } from "./contracts/IPerpetualManager
|
|
|
26
26
|
import { type IClientOrder } from "./contracts/LimitOrderBook";
|
|
27
27
|
import {
|
|
28
28
|
ABK64x64ToFloat,
|
|
29
|
-
calculateLiquidationPriceCollateralBase,
|
|
30
|
-
calculateLiquidationPriceCollateralQuanto,
|
|
31
|
-
calculateLiquidationPriceCollateralQuote,
|
|
32
29
|
dec18ToFloat,
|
|
33
30
|
decNToFloat,
|
|
34
31
|
floatToABK64x64,
|
|
35
32
|
getDepositAmountForLvgTrade,
|
|
36
33
|
getMaxSignedPositionSize,
|
|
37
|
-
entropy,
|
|
38
|
-
expectedLoss,
|
|
39
34
|
pmExchangeFee,
|
|
40
35
|
} from "./d8XMath";
|
|
41
36
|
import {
|
|
37
|
+
PythMetadata,
|
|
42
38
|
type ExchangeInfo,
|
|
39
|
+
type IdxPriceInfo,
|
|
43
40
|
type MarginAccount,
|
|
44
41
|
type NodeSDKConfig,
|
|
45
42
|
type Order,
|
|
@@ -48,8 +45,6 @@ import {
|
|
|
48
45
|
type PoolState,
|
|
49
46
|
type PoolStaticInfo,
|
|
50
47
|
type SmartContractOrder,
|
|
51
|
-
type IdxPriceInfo,
|
|
52
|
-
PythMetadata,
|
|
53
48
|
} from "./nodeSDKTypes";
|
|
54
49
|
import PerpetualDataHandler from "./perpetualDataHandler";
|
|
55
50
|
import PriceFeeds from "./priceFeeds";
|
|
@@ -1005,7 +1000,7 @@ export default class MarketData extends PerpetualDataHandler {
|
|
|
1005
1000
|
traderState[idx_mark_price] = floatToABK64x64(markPrice);
|
|
1006
1001
|
traderState[idx_s3] = floatToABK64x64(collToQuoteConversion);
|
|
1007
1002
|
traderState[idx_maint_mgn_rate] = floatToABK64x64(PerpetualDataHandler.getMaintenanceMarginRate(staticInfo));
|
|
1008
|
-
let tau;
|
|
1003
|
+
let tau;
|
|
1009
1004
|
[S2Liq, S3Liq, tau, ,] = MarketData._calculateLiquidationPrice(
|
|
1010
1005
|
symbol,
|
|
1011
1006
|
traderState,
|
|
@@ -2338,7 +2333,9 @@ export default class MarketData extends PerpetualDataHandler {
|
|
|
2338
2333
|
};
|
|
2339
2334
|
|
|
2340
2335
|
// get all prices from off-chain price-sources: no RPC calls
|
|
2336
|
+
console.log("1");
|
|
2341
2337
|
let idxPriceMap = await MarketData._getAllActivePerpIndexPrices(_symbolToPerpStaticInfo, _priceFeedGetter);
|
|
2338
|
+
console.log({ idxPriceMap });
|
|
2342
2339
|
|
|
2343
2340
|
// query mid-prices from on-chain conditional on the off-chain prices
|
|
2344
2341
|
let midPriceMap: Map<string, number> = await MarketData._queryMidPrices(
|
|
@@ -2351,6 +2348,7 @@ export default class MarketData extends PerpetualDataHandler {
|
|
|
2351
2348
|
idxPriceMap,
|
|
2352
2349
|
overrides
|
|
2353
2350
|
);
|
|
2351
|
+
console.log({ midPriceMap });
|
|
2354
2352
|
const { pools: poolStateInfos, perpetuals: perpStateInfos } = await MarketData._queryPoolAndPerpetualStates(
|
|
2355
2353
|
_proxyContract,
|
|
2356
2354
|
_multicall,
|
package/src/orderExecutorTool.ts
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
TransactionResponse,
|
|
9
9
|
ZeroHash,
|
|
10
10
|
} from "ethers";
|
|
11
|
-
import { BUY_SIDE, MULTICALL_ADDRESS, OrderStatus, SELL_SIDE, ZERO_ADDRESS
|
|
11
|
+
import { BUY_SIDE, MULTICALL_ADDRESS, OrderStatus, SELL_SIDE, ZERO_ADDRESS } from "./constants";
|
|
12
12
|
import { IPyth__factory, LimitOrderBook__factory, Multicall3, Multicall3__factory } from "./contracts";
|
|
13
13
|
import { PayableOverrides } from "./contracts/common";
|
|
14
14
|
import { ABK64x64ToFloat, floatToABK64x64 } from "./d8XMath";
|
|
@@ -167,7 +167,7 @@ export default class OrderExecutorTool extends WriteAccessHandler {
|
|
|
167
167
|
priceIds,
|
|
168
168
|
submission.timestamps,
|
|
169
169
|
{
|
|
170
|
-
value: this.
|
|
170
|
+
value: this.priceUpdateFee() * submission.timestamps.length,
|
|
171
171
|
gasLimit: overrides?.gasLimit ?? this.gasLimit,
|
|
172
172
|
nonce: overrides?.nonce,
|
|
173
173
|
}
|
|
@@ -186,7 +186,7 @@ export default class OrderExecutorTool extends WriteAccessHandler {
|
|
|
186
186
|
submission.priceFeedVaas,
|
|
187
187
|
submission.timestamps,
|
|
188
188
|
]);
|
|
189
|
-
value = this.
|
|
189
|
+
value = this.priceUpdateFee() * submission.timestamps.length;
|
|
190
190
|
}
|
|
191
191
|
|
|
192
192
|
if (overrides?.nonce != undefined) {
|
|
@@ -100,7 +100,6 @@ import {
|
|
|
100
100
|
* common data and chain operations.
|
|
101
101
|
*/
|
|
102
102
|
export default class PerpetualDataHandler {
|
|
103
|
-
PRICE_UPDATE_FEE_GWEI = 1;
|
|
104
103
|
//map symbol of the form ETH-USD-MATIC into perpetual ID and other static info
|
|
105
104
|
//this is initialized in the createProxyInstance function
|
|
106
105
|
protected symbolToPerpStaticInfo: Map<string, PerpetualStaticInfo>; // maps symbol of the form BTC-USD-MATIC to static info
|
|
@@ -659,6 +658,7 @@ export default class PerpetualDataHandler {
|
|
|
659
658
|
protected static async fetchSymbolList(chainId: bigint | number | string, short: string[]) {
|
|
660
659
|
const endpoint = `https://sports.quantena.org/long-symbol/${Number(chainId)}?short[]=`; //BTC&short[]=GBP
|
|
661
660
|
const query = endpoint + short.join("&short[]=");
|
|
661
|
+
console.log({ query });
|
|
662
662
|
const res = await fetch(query);
|
|
663
663
|
if (res.status !== 200) {
|
|
664
664
|
throw new Error(`failed to fetch symbolList status code: ${res.status}`);
|
|
@@ -2301,4 +2301,12 @@ export default class PerpetualDataHandler {
|
|
|
2301
2301
|
closeSec: closeSlot * 900,
|
|
2302
2302
|
};
|
|
2303
2303
|
}
|
|
2304
|
+
|
|
2305
|
+
public priceUpdateFee() {
|
|
2306
|
+
if ([8453, 84532].includes(Number(this.chainId))) {
|
|
2307
|
+
return 10;
|
|
2308
|
+
} else {
|
|
2309
|
+
return 1;
|
|
2310
|
+
}
|
|
2311
|
+
}
|
|
2304
2312
|
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const D8X_SDK_VERSION = "2.6.
|
|
1
|
+
export const D8X_SDK_VERSION = "2.6.2";
|