@d8x/perpetuals-sdk 2.6.3 → 2.6.5

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.
@@ -100,12 +100,14 @@ import {
100
100
  * common data and chain operations.
101
101
  */
102
102
  export default class PerpetualDataHandler {
103
+ PRICE_UPDATE_FEE_GWEI = 1;
103
104
  //map symbol of the form ETH-USD-MATIC into perpetual ID and other static info
104
105
  //this is initialized in the createProxyInstance function
105
106
  protected symbolToPerpStaticInfo: Map<string, PerpetualStaticInfo>; // maps symbol of the form BTC-USD-MATIC to static info
106
107
  protected perpetualIdToSymbol: Map<number, string>; // maps unique perpetual id to symbol of the form BTC-USD-MATIC
107
108
  protected poolStaticInfos: Array<PoolStaticInfo>;
108
109
  protected symbolList: Map<string, string>; //mapping 4-digit symbol <-> long format
110
+ protected indexSymbol: Map<string, string> = new Map(); //mapping perpetual symbol to index symbol (NFL_TOR_...-USD-PUSD => NFL0-USD:84532)
109
111
  protected settlementConfig: SettlementConfig;
110
112
  public requiredSymbols: string[] = []; // array of symbols in the current perpetual deployment
111
113
  // config
@@ -325,6 +327,7 @@ export default class PerpetualDataHandler {
325
327
  this.proxyContract,
326
328
  this.nestedPerpetualIDs,
327
329
  this.symbolList,
330
+ this.indexSymbol,
328
331
  overrides
329
332
  );
330
333
 
@@ -337,7 +340,8 @@ export default class PerpetualDataHandler {
337
340
  if (perp.state != "INVALID" && perp.state != "INITIALIZING") {
338
341
  // we only require price feeds to be available if the perpetual
339
342
  // is in normal state
340
- requiredPairs.add(perp.S2Symbol);
343
+ requiredPairs.add(PerpetualDataHandler.getIndexSymbol(this.symbolList, perp));
344
+
341
345
  if (perp.S3Symbol != "") {
342
346
  requiredPairs.add(perp.S3Symbol);
343
347
  }
@@ -531,21 +535,12 @@ export default class PerpetualDataHandler {
531
535
  */
532
536
  public getIndexSymbols(symbol: string): [string, string] {
533
537
  // get index
534
- console.log(symbol, this.symbolToPerpStaticInfo);
535
538
  let staticInfo = this.symbolToPerpStaticInfo.get(symbol);
536
539
  if (staticInfo == undefined) {
537
540
  throw new Error(`No static info for perpetual with symbol ${symbol}`);
538
541
  }
539
- const quoteCcy = staticInfo.S2Symbol.split("-")[1];
540
542
  return this.isPredictionMarket(symbol)
541
- ? [
542
- PerpetualDataHandler._getBySingleValue(this.symbolList, staticInfo.S2Symbol) +
543
- "-" +
544
- quoteCcy +
545
- ":" +
546
- Number(this.chainId),
547
- staticInfo.S3Symbol,
548
- ]
543
+ ? [PerpetualDataHandler.getIndexSymbol(this.symbolList, staticInfo), staticInfo.S3Symbol]
549
544
  : [staticInfo.S2Symbol, staticInfo.S3Symbol];
550
545
  }
551
546
 
@@ -684,6 +679,7 @@ export default class PerpetualDataHandler {
684
679
  _proxyContract: IPerpetualManager,
685
680
  nestedPerpetualIDs: Array<Array<number>>,
686
681
  symbolList: Map<string, string>,
682
+ indexSymbol: Map<string, string>,
687
683
  overrides?: Overrides
688
684
  ): Promise<Array<PerpetualStaticInfo>> {
689
685
  // flatten perpetual ids into chunks
@@ -703,6 +699,7 @@ export default class PerpetualDataHandler {
703
699
  for (const s of shorts) {
704
700
  if (sList.has(s)) {
705
701
  symbolList.set(s, sList.get(s)!);
702
+ indexSymbol.set(sList.get(s)!, s + ":" + BigInt(overrides.chainId!));
706
703
  }
707
704
  }
708
705
  }
@@ -1521,7 +1518,7 @@ export default class PerpetualDataHandler {
1521
1518
  return undefined;
1522
1519
  }
1523
1520
 
1524
- private static _getBySingleValue(map: Map<string, string>, searchValue: string) {
1521
+ protected static _getBySingleValue(map: Map<string, string>, searchValue: string) {
1525
1522
  for (let [key, value] of map.entries()) {
1526
1523
  if (searchValue.startsWith(value)) {
1527
1524
  return key;
@@ -2302,4 +2299,13 @@ export default class PerpetualDataHandler {
2302
2299
  return 1;
2303
2300
  }
2304
2301
  }
2302
+
2303
+ public static getIndexSymbol(_symbolList: Map<string, string>, info: PerpetualStaticInfo) {
2304
+ return PerpetualDataHandler.isPredictionMarketStatic(info!)
2305
+ ? PerpetualDataHandler._getBySingleValue(_symbolList, info.S2Symbol)! +
2306
+ "-" +
2307
+ info!.S2Symbol.split("-")[1] +
2308
+ ":84532"
2309
+ : info!.S2Symbol;
2310
+ }
2305
2311
  }
package/src/priceFeeds.ts CHANGED
@@ -220,7 +220,9 @@ export default class PriceFeeds {
220
220
  * @returns map of feed-price symbol to price/isMarketClosed
221
221
  */
222
222
  public async fetchPrices(symbols: string[]): Promise<Map<string, [number, boolean]>> {
223
+ console.log({ symbols });
223
224
  let feedPrices = await this.fetchAllFeedPrices();
225
+ console.log({ feedPrices });
224
226
  let [prices, mktClosed] = this.triangulatePricesFromFeedPrices(symbols, feedPrices);
225
227
  let symMap = new Map<string, [number, boolean]>();
226
228
  for (let k = 0; k < symbols.length; k++) {
@@ -239,6 +241,7 @@ export default class PriceFeeds {
239
241
  let p = feedPrices.get(key);
240
242
  symMap.set(key, p!);
241
243
  }
244
+ console.log({ symMap });
242
245
  return symMap;
243
246
  }
244
247
 
@@ -456,6 +459,7 @@ export default class PriceFeeds {
456
459
  * @returns map of feed-price symbol to price/isMarketClosed
457
460
  */
458
461
  public async fetchAllFeedPrices(): Promise<Map<string, [number, boolean]>> {
462
+ console.log({ symbols: this.dataHandler.requiredSymbols });
459
463
  return this.fetchFeedPrices(this.dataHandler.requiredSymbols);
460
464
  }
461
465
 
@@ -585,6 +589,7 @@ export default class PriceFeeds {
585
589
  let mktClosed = new Array<boolean>();
586
590
  for (let k = 0; k < symbols.length; k++) {
587
591
  let sym = symbols[k] as string;
592
+ console.log({ t: this.triangulations });
588
593
  let triangulation: [string[], boolean[]] | undefined = this.triangulations.get(sym);
589
594
  if (triangulation == undefined) {
590
595
  let feedPrice = feedPriceMap.get(sym);
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const D8X_SDK_VERSION = "2.6.3";
1
+ export const D8X_SDK_VERSION = "2.6.5";