@d8x/perpetuals-sdk 0.0.46 → 0.1.0

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.
@@ -96,7 +96,6 @@ class OrderReferrerTool extends writeAccessHandler_1.default {
96
96
  nonce: nonce,
97
97
  value: this.PRICE_UPDATE_FEE_GWEI * (submission === null || submission === void 0 ? void 0 : submission.priceFeedVaas.length),
98
98
  };
99
- console.log(submission);
100
99
  return yield orderBookSC.executeOrder(orderId, referrerAddr, submission === null || submission === void 0 ? void 0 : submission.priceFeedVaas, submission === null || submission === void 0 ? void 0 : submission.timestamps, options);
101
100
  });
102
101
  }
@@ -164,8 +164,8 @@ class PerpetualDataHandler {
164
164
  this.symbolToTokenAddrMap.set(poolCCY, poolMarginTokenAddr);
165
165
  }
166
166
  // pre-calculate all triangulation paths so we can easily get from
167
- // the prices of price-feeds to the index price required, e.g.
168
- // BTC-USDC : BTC-USD / USDC-USD
167
+ // the prices of price-feeds to the index price required, e.g.
168
+ // BTC-USDC : BTC-USD / USDC-USD
169
169
  this.priceFeedGetter.initializeTriangulations(requiredPairs);
170
170
  });
171
171
  }
@@ -328,7 +328,7 @@ class PerpetualDataHandler {
328
328
  static _queryPerpetualPrice(symbol, tradeAmount, symbolToPerpStaticInfo, _proxyContract, indexPrices) {
329
329
  return __awaiter(this, void 0, void 0, function* () {
330
330
  let perpId = PerpetualDataHandler.symbolToPerpetualId(symbol, symbolToPerpStaticInfo);
331
- let fIndexPrices = indexPrices.map(x => (0, d8XMath_1.floatToABK64x64)(x));
331
+ let fIndexPrices = indexPrices.map((x) => (0, d8XMath_1.floatToABK64x64)(x == undefined || Number.isNaN(x) ? 0 : x));
332
332
  let fPrice = yield _proxyContract.queryPerpetualPrice(perpId, (0, d8XMath_1.floatToABK64x64)(tradeAmount), fIndexPrices);
333
333
  return (0, d8XMath_1.ABK64x64ToFloat)(fPrice);
334
334
  });
@@ -336,7 +336,7 @@ class PerpetualDataHandler {
336
336
  static _queryPerpetualMarkPrice(symbol, symbolToPerpStaticInfo, _proxyContract, indexPrices) {
337
337
  return __awaiter(this, void 0, void 0, function* () {
338
338
  let perpId = PerpetualDataHandler.symbolToPerpetualId(symbol, symbolToPerpStaticInfo);
339
- let [S2, S3] = indexPrices.map(x => (0, d8XMath_1.floatToABK64x64)(x));
339
+ let [S2, S3] = indexPrices.map((x) => (0, d8XMath_1.floatToABK64x64)(x == undefined || Number.isNaN(x) ? 0 : x));
340
340
  let ammState = yield _proxyContract.getAMMState(perpId, [S2, S3]);
341
341
  return (0, d8XMath_1.ABK64x64ToFloat)(ammState[6].mul(nodeSDKTypes_1.ONE_64x64.add(ammState[8])).div(nodeSDKTypes_1.ONE_64x64));
342
342
  });
@@ -347,7 +347,7 @@ class PerpetualDataHandler {
347
347
  let perpId = PerpetualDataHandler.symbolToPerpetualId(symbol, symbolToPerpStaticInfo);
348
348
  let ccy = symbol.split("-");
349
349
  let [S2, S3] = [indexPrices[0], indexPrices[1]];
350
- let ammState = yield _proxyContract.getAMMState(perpId, [S2, S3].map(x => (0, d8XMath_1.floatToABK64x64)(x)));
350
+ let ammState = yield _proxyContract.getAMMState(perpId, [S2, S3].map((x) => (0, d8XMath_1.floatToABK64x64)(x == undefined || Number.isNaN(x) ? 0 : x)));
351
351
  let markPrice = (0, d8XMath_1.ABK64x64ToFloat)(ammState[6].mul(nodeSDKTypes_1.ONE_64x64.add(ammState[8])).div(nodeSDKTypes_1.ONE_64x64));
352
352
  let state = {
353
353
  id: perpId,
@@ -361,7 +361,7 @@ class PerpetualDataHandler {
361
361
  currentFundingRateBps: (0, d8XMath_1.ABK64x64ToFloat)(ammState[14]) * 1e4,
362
362
  openInterestBC: (0, d8XMath_1.ABK64x64ToFloat)(ammState[11]),
363
363
  maxPositionBC: (0, d8XMath_1.ABK64x64ToFloat)(ammState[12]),
364
- isMarketClosed: indexPrices[2] || indexPrices[3]
364
+ isMarketClosed: indexPrices[2] || indexPrices[3],
365
365
  };
366
366
  if (((_a = symbolToPerpStaticInfo.get(symbol)) === null || _a === void 0 ? void 0 : _a.collateralCurrencyType) == nodeSDKTypes_1.CollaterlCCY.BASE) {
367
367
  state.collToQuoteIndexPrice = state.indexPrice;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const D8X_SDK_VERSION = "0.0.46";
1
+ export declare const D8X_SDK_VERSION = "0.1.0";
package/dist/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.D8X_SDK_VERSION = void 0;
4
- exports.D8X_SDK_VERSION = "0.0.46";
4
+ exports.D8X_SDK_VERSION = "0.1.0";
package/package.json CHANGED
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "name": "@d8x/perpetuals-sdk",
35
35
  "description": "Node TypeScript SDK for D8X Perpetual Futures",
36
- "version": "0.0.46",
36
+ "version": "0.1.0",
37
37
  "main": "./dist/index.js",
38
38
  "types": "./dist/index.d.ts",
39
39
  "directories": {
@@ -99,7 +99,6 @@ export default class OrderReferrerTool extends WriteAccessHandler {
99
99
  nonce: nonce,
100
100
  value: this.PRICE_UPDATE_FEE_GWEI * submission?.priceFeedVaas.length,
101
101
  };
102
- console.log(submission);
103
102
  return await orderBookSC.executeOrder(
104
103
  orderId,
105
104
  referrerAddr,
@@ -77,7 +77,7 @@ export default class PerpetualDataHandler {
77
77
  protected provider: ethers.providers.JsonRpcProvider | null = null;
78
78
 
79
79
  private signerOrProvider: ethers.Signer | ethers.providers.Provider | null = null;
80
- protected priceFeedGetter : PriceFeeds;
80
+ protected priceFeedGetter: PriceFeeds;
81
81
 
82
82
  // pools are numbered consecutively starting at 1
83
83
  // nestedPerpetualIDs contains an array for each pool
@@ -153,7 +153,7 @@ export default class PerpetualDataHandler {
153
153
  let sym = base + "-" + quote;
154
154
  let sym3 = base3 + "-" + quote3;
155
155
  requiredPairs.add(sym);
156
- if (sym3!="-") {
156
+ if (sym3 != "-") {
157
157
  requiredPairs.add(sym3);
158
158
  } else {
159
159
  sym3 = "";
@@ -218,8 +218,8 @@ export default class PerpetualDataHandler {
218
218
  this.symbolToTokenAddrMap.set(poolCCY!, poolMarginTokenAddr);
219
219
  }
220
220
  // pre-calculate all triangulation paths so we can easily get from
221
- // the prices of price-feeds to the index price required, e.g.
222
- // BTC-USDC : BTC-USD / USDC-USD
221
+ // the prices of price-feeds to the index price required, e.g.
222
+ // BTC-USDC : BTC-USD / USDC-USD
223
223
  this.priceFeedGetter.initializeTriangulations(requiredPairs);
224
224
  }
225
225
 
@@ -268,7 +268,9 @@ export default class PerpetualDataHandler {
268
268
  * @param symbol pool symbol of the form "ETH-USD-MATIC"
269
269
  * @returns PriceFeedSubmission and prices for S2 and S3. [S2price, 0] if S3 not defined.
270
270
  */
271
- public async fetchPriceSubmissionInfoForPerpetual(symbol: string) : Promise<{submission : PriceFeedSubmission, pxS2S3 : [number,number]}> {
271
+ public async fetchPriceSubmissionInfoForPerpetual(
272
+ symbol: string
273
+ ): Promise<{ submission: PriceFeedSubmission; pxS2S3: [number, number] }> {
272
274
  // fetch prices from required price-feeds (REST)
273
275
  return await this.priceFeedGetter.fetchFeedPriceInfoAndIndicesForPerpetual(symbol);
274
276
  }
@@ -278,23 +280,23 @@ export default class PerpetualDataHandler {
278
280
  * @param symbol of the form ETH-USD-MATIC, specifying the perpetual
279
281
  * @returns name of underlying index prices, e.g. ["MATIC-USD", ""]
280
282
  */
281
- public getIndexSymbols(symbol: string) : [string, string] {
282
- // get index
283
- let staticInfo = this.symbolToPerpStaticInfo.get(symbol);
284
- if (staticInfo==undefined) {
285
- throw new Error(`No static info for perpetual with symbol ${symbol}`);
286
- }
287
- return [staticInfo.S2Symbol,staticInfo.S3Symbol];
283
+ public getIndexSymbols(symbol: string): [string, string] {
284
+ // get index
285
+ let staticInfo = this.symbolToPerpStaticInfo.get(symbol);
286
+ if (staticInfo == undefined) {
287
+ throw new Error(`No static info for perpetual with symbol ${symbol}`);
288
+ }
289
+ return [staticInfo.S2Symbol, staticInfo.S3Symbol];
288
290
  }
289
291
 
290
292
  /**
291
293
  * Get the latest prices for a given perpetual from the offchain oracle
292
294
  * networks
293
295
  * @param symbol perpetual symbol of the form BTC-USD-MATIC
294
- * @returns array of price feed updates that can be submitted to the smart contract
295
- * and corresponding price information
296
+ * @returns array of price feed updates that can be submitted to the smart contract
297
+ * and corresponding price information
296
298
  */
297
- public async fetchLatestFeedPriceInfo(symbol: string) : Promise<PriceFeedSubmission> {
299
+ public async fetchLatestFeedPriceInfo(symbol: string): Promise<PriceFeedSubmission> {
298
300
  return await this.priceFeedGetter.fetchLatestFeedPriceInfoForPerpetual(symbol);
299
301
  }
300
302
 
@@ -408,7 +410,7 @@ export default class PerpetualDataHandler {
408
410
  indexPrices: [number, number]
409
411
  ): Promise<number> {
410
412
  let perpId = PerpetualDataHandler.symbolToPerpetualId(symbol, symbolToPerpStaticInfo);
411
- let fIndexPrices = indexPrices.map(x=>floatToABK64x64(x));
413
+ let fIndexPrices = indexPrices.map((x) => floatToABK64x64(x == undefined || Number.isNaN(x) ? 0 : x));
412
414
  let fPrice = await _proxyContract.queryPerpetualPrice(perpId, floatToABK64x64(tradeAmount), fIndexPrices);
413
415
  return ABK64x64ToFloat(fPrice);
414
416
  }
@@ -420,7 +422,7 @@ export default class PerpetualDataHandler {
420
422
  indexPrices: [number, number]
421
423
  ): Promise<number> {
422
424
  let perpId = PerpetualDataHandler.symbolToPerpetualId(symbol, symbolToPerpStaticInfo);
423
- let [S2, S3] = indexPrices.map(x=>floatToABK64x64(x));
425
+ let [S2, S3] = indexPrices.map((x) => floatToABK64x64(x == undefined || Number.isNaN(x) ? 0 : x));
424
426
  let ammState = await _proxyContract.getAMMState(perpId, [S2, S3]);
425
427
  return ABK64x64ToFloat(ammState[6].mul(ONE_64x64.add(ammState[8])).div(ONE_64x64));
426
428
  }
@@ -434,7 +436,10 @@ export default class PerpetualDataHandler {
434
436
  let perpId = PerpetualDataHandler.symbolToPerpetualId(symbol, symbolToPerpStaticInfo);
435
437
  let ccy = symbol.split("-");
436
438
  let [S2, S3] = [indexPrices[0], indexPrices[1]];
437
- let ammState = await _proxyContract.getAMMState(perpId, [S2, S3].map(x=>floatToABK64x64(x)));
439
+ let ammState = await _proxyContract.getAMMState(
440
+ perpId,
441
+ [S2, S3].map((x) => floatToABK64x64(x == undefined || Number.isNaN(x) ? 0 : x))
442
+ );
438
443
  let markPrice = ABK64x64ToFloat(ammState[6].mul(ONE_64x64.add(ammState[8])).div(ONE_64x64));
439
444
  let state = {
440
445
  id: perpId,
@@ -448,7 +453,7 @@ export default class PerpetualDataHandler {
448
453
  currentFundingRateBps: ABK64x64ToFloat(ammState[14]) * 1e4,
449
454
  openInterestBC: ABK64x64ToFloat(ammState[11]),
450
455
  maxPositionBC: ABK64x64ToFloat(ammState[12]),
451
- isMarketClosed: indexPrices[2] || indexPrices[3]
456
+ isMarketClosed: indexPrices[2] || indexPrices[3],
452
457
  };
453
458
  if (symbolToPerpStaticInfo.get(symbol)?.collateralCurrencyType == CollaterlCCY.BASE) {
454
459
  state.collToQuoteIndexPrice = state.indexPrice;
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const D8X_SDK_VERSION = "0.0.46";
1
+ export const D8X_SDK_VERSION = "0.1.0";