@d8x/perpetuals-sdk 2.4.3 → 2.4.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.
Files changed (37) hide show
  1. package/dist/cjs/config/priceFeedConfig.json +155 -11
  2. package/dist/cjs/marketData.d.ts +2 -2
  3. package/dist/cjs/marketData.js +54 -34
  4. package/dist/cjs/marketData.js.map +1 -1
  5. package/dist/cjs/nodeSDKTypes.d.ts +2 -1
  6. package/dist/cjs/nodeSDKTypes.js.map +1 -1
  7. package/dist/cjs/perpetualDataHandler.d.ts +3 -1
  8. package/dist/cjs/perpetualDataHandler.js +35 -11
  9. package/dist/cjs/perpetualDataHandler.js.map +1 -1
  10. package/dist/cjs/priceFeeds.d.ts +5 -6
  11. package/dist/cjs/priceFeeds.js +6 -7
  12. package/dist/cjs/priceFeeds.js.map +1 -1
  13. package/dist/cjs/version.d.ts +1 -1
  14. package/dist/cjs/version.js +1 -1
  15. package/dist/esm/config/priceFeedConfig.json +155 -11
  16. package/dist/esm/marketData.d.ts +2 -2
  17. package/dist/esm/marketData.js +55 -35
  18. package/dist/esm/marketData.js.map +1 -1
  19. package/dist/esm/nodeSDKTypes.d.ts +2 -1
  20. package/dist/esm/nodeSDKTypes.js.map +1 -1
  21. package/dist/esm/perpetualDataHandler.d.ts +3 -1
  22. package/dist/esm/perpetualDataHandler.js +35 -11
  23. package/dist/esm/perpetualDataHandler.js.map +1 -1
  24. package/dist/esm/priceFeeds.d.ts +5 -6
  25. package/dist/esm/priceFeeds.js +6 -7
  26. package/dist/esm/priceFeeds.js.map +1 -1
  27. package/dist/esm/version.d.ts +1 -1
  28. package/dist/esm/version.js +1 -1
  29. package/doc/d8x-perpetuals-sdk.md +12 -12
  30. package/doc/perpetualDataHandler.md +1 -1
  31. package/package.json +1 -1
  32. package/src/config/priceFeedConfig.json +155 -11
  33. package/src/marketData.ts +54 -35
  34. package/src/nodeSDKTypes.ts +3 -1
  35. package/src/perpetualDataHandler.ts +36 -11
  36. package/src/priceFeeds.ts +10 -9
  37. package/src/version.ts +1 -1
@@ -2,6 +2,60 @@
2
2
  {
3
3
  "network": "mainnet",
4
4
  "ids": [
5
+ {
6
+ "symbol": "FED25BPS-USD",
7
+ "id": "0x199326ac3436c8a01052155eec8d85c5092c9c3c56e0f3590c5d96d89dceec2c",
8
+ "type": "polymarket",
9
+ "origin": "0xa11a9c66032cbe8c607bf1b21591f65dfee9d5eb65d73cc8ad5009c1f9826fa3"
10
+ },
11
+ {
12
+ "symbol": "TRMPUKR-USD",
13
+ "id": "0xbbad52c7a569d729424c917dd3181149d59b5f4fc3115d510b91197c4368c22a",
14
+ "type": "polymarket",
15
+ "origin": "0xa5ac4cdcfff44ddfb0d332d33575f766414465786fb7d4350782db40d5e9da11"
16
+ },
17
+ {
18
+ "symbol": "MANCITY-USD",
19
+ "id": "0x99949191c4996cfb75262a15ee1ecc16c1cd07b8f0561694db177636b58321d4",
20
+ "type": "polymarket",
21
+ "origin": "0x586e7ee86609bd6ea5b71bddff7ea7877100c03d22ece5a336baa98aadacdb1a"
22
+ },
23
+ {
24
+ "symbol": "BTCNOV90-USD",
25
+ "id": "0x3c711064722ff96741641b5b54f055874bbfb478042888fd4121a145c852060b",
26
+ "type": "polymarket",
27
+ "origin": "0x952e8d6dcd67c7d28720491a798e96a2729a57598cb04b4de6f6c2e6f75fd12b"
28
+ },
29
+ {
30
+ "symbol": "BTC24100-USD",
31
+ "id": "0x8f7dd95917a1bcf74cd5964c9a779c267d38d4c6a87e8c7a66fae7fe30ada9a6",
32
+ "type": "polymarket",
33
+ "origin": "0x9c66114d2dfe2139325cc7a408a5cd5d2e73b55d919e2141b3a0ed83fc15895d"
34
+ },
35
+ {
36
+ "symbol": "MCLAREN24-USD",
37
+ "id": "0xa54c8b0fca58649775eece82cf6bf4aea245a431bdff4dfba40f01a17e4c1248",
38
+ "type": "polymarket",
39
+ "origin": "0x6154df852fac6dd9748b97883c03220bb267ad2be71fa215c8df1431995db74d"
40
+ },
41
+ {
42
+ "symbol": "HARRIS24P-USD",
43
+ "id": "0x2f06f5a323466c1ad9a9a8afb19a21dd3fe0f39853a16ae58637086e8ff5838d",
44
+ "type": "polymarket",
45
+ "origin": "0x265366ede72d73e137b2b9095a6cdc9be6149290caa295738a95e3d881ad0865"
46
+ },
47
+ {
48
+ "symbol": "SUPBWL49-USD",
49
+ "id": "0x7eea0b94fc1916efdd031978918abba566b9aef7f12b3d5a5b0f7141fd8e0b33",
50
+ "type": "polymarket",
51
+ "origin": "0x67e68c5eee8ac767dd1177de8c653b20642fee48f0f2a56d784e4856b130749d"
52
+ },
53
+ {
54
+ "symbol": "INSOUT2-USD",
55
+ "id": "0x6ec8114a0dba99a037c7122c93a68f2ab905c3e42e2b82e1ce659aef96de58f2",
56
+ "type": "polymarket",
57
+ "origin": "0x1ab07117f9f698f28490f57754d6fe5309374230c95867a7eba572892a11d710"
58
+ },
5
59
  {
6
60
  "symbol": "USDC-USD",
7
61
  "id": "0xeaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a",
@@ -92,6 +146,18 @@
92
146
  "type": "pyth",
93
147
  "origin": "Crypto.DOGE/USD"
94
148
  },
149
+ {
150
+ "symbol": "GOAT-USD",
151
+ "id": "0xf7731dc812590214d3eb4343bfb13d1b4cfa9b1d4e020644b5d5d8e07d60c66c",
152
+ "type": "pyth",
153
+ "origin": "Crypto.GOAT/USD"
154
+ },
155
+ {
156
+ "symbol": "PNUT-USD",
157
+ "id": "0x116da895807f81f6b5c5f01b109376e7f6834dc8b51365ab7cdfa66634340e54",
158
+ "type": "pyth",
159
+ "origin": "Crypto.PNUT/USD"
160
+ },
95
161
  {
96
162
  "symbol": "WIF-USD",
97
163
  "id": "0x4ca4beeca86f0d164160323817a4e42b10010a724c2217c6ee41b54cd4cc61fc",
@@ -101,6 +167,7 @@
101
167
  {
102
168
  "symbol": "PEPE-USD",
103
169
  "id": "0xd69731a2e74ac1ce884fc3890f7ee324b6deb66147055249568869ed700882e4",
170
+ "pxMultiplier": 1000,
104
171
  "type": "pyth",
105
172
  "origin": "Crypto.PEPE/USD"
106
173
  },
@@ -133,6 +200,30 @@
133
200
  "id": "0x9a4df90b25497f66b1afb012467e316e801ca3d839456db028892fe8c70c8016",
134
201
  "type": "pyth",
135
202
  "origin": "Crypto.PENDLE/USD"
203
+ },
204
+ {
205
+ "symbol": "TON-USD",
206
+ "id": "0x8963217838ab4cf5cadc172203c1f0b763fbaa45f346d8ee50ba994bbcac3026",
207
+ "type": "pyth",
208
+ "origin": "Crypto.TON/USD"
209
+ },
210
+ {
211
+ "symbol": "BNB-USD",
212
+ "id": "0x2f95862b045670cd22bee3114c39763a4a08beeb663b145d283c31d7d1101c4f",
213
+ "type": "pyth",
214
+ "origin": "Crypto.BNB/USD"
215
+ },
216
+ {
217
+ "symbol": "SHIB-USD",
218
+ "id": "0xf0d57deca57b3da2fe63a493f4c25925fdfd8edf834b20f93e1f84dbd1504d4a",
219
+ "type": "pyth",
220
+ "origin": "Crypto.SHIB/USD"
221
+ },
222
+ {
223
+ "symbol": "POL-USD",
224
+ "id": "0xffd11c5a1cfd42f80afb2df4d9f264c15f956d68153335374ec10722edd70472",
225
+ "type": "pyth",
226
+ "origin": "Crypto.POL/USD"
136
227
  }
137
228
  ],
138
229
  "endpoints": [
@@ -142,23 +233,52 @@
142
233
  "writeEndpoints": ["https://hermes.pyth.network"]
143
234
  },
144
235
  { "type": "onchain", "endpoints": [], "writeEndpoints": [] },
145
- { "type": "polymarket", "endpoints": [], "writeEndpoints": ["https://odin-poly.d8x.xyz"] }
236
+ {
237
+ "type": "polymarket",
238
+ "endpoints": [],
239
+ "writeEndpoints": ["https://odin-poly.d8x.xyz"]
240
+ }
146
241
  ]
147
242
  },
148
243
  {
149
244
  "network": "odin",
150
245
  "ids": [
151
246
  {
152
- "symbol": "BTLJ-USD",
153
- "id": "0xE40F3EF726A04AD63510BAF90238F6BCACF4365DB2A38E02A6E8623C2BEDC97D",
154
- "type": "polymarket",
155
- "origin": "0x3157ea263270be44bd68a3d6bde1f6f639be2746974f65de24e00ea6378d7838"
247
+ "symbol": "HONEY-USDC",
248
+ "origin": "Crypto.HONEY/USDC",
249
+ "comment": "DAI price for temporary feed honey-usdc",
250
+ "id": "0xb0948a5e5313200c632b51bb5ca32f6de0d36e9950a942d19751e833f70dabfd",
251
+ "type": "odin"
156
252
  },
157
253
  {
158
- "symbol": "TRUMP24-USD",
159
- "id": "0x3011e4ede0f6befa0ad3f571001d3e1ffeef3d4af78c3112aaac90416e3a43e7",
160
- "type": "polymarket",
161
- "origin": "0xdd22472e552920b8438158ea7238bfadfa4f736aa4cee91a6b86c39ead110917"
254
+ "symbol": "DIRAC-HONEY",
255
+ "id": "0xebd937fe18c8122f35e2fb280f4b70343a8403dc848f02511d6791ae1db5a25f",
256
+ "type": "low-liq",
257
+ "origin": ""
258
+ },
259
+ {
260
+ "symbol": "BUDS-HONEY",
261
+ "id": "0xb859493d77dc52043bbeaa6aa090ebd24ae913a707b330a34e4f168b5d8dd58c",
262
+ "type": "low-liq",
263
+ "origin": ""
264
+ },
265
+ {
266
+ "symbol": "IBGT-HONEY",
267
+ "id": "0x2cb8e3da2690aee73a495107a849e58989d73c1151719920b06bbdf1bb1a0150",
268
+ "type": "low-liq",
269
+ "origin": ""
270
+ },
271
+ {
272
+ "symbol": "BDEG-HONEY",
273
+ "id": "0x0becdebd3154dfe6c06b952800b379f091374a16a8ee09aba0e503092479bfca",
274
+ "type": "low-liq",
275
+ "origin": ""
276
+ },
277
+ {
278
+ "symbol": "BEARTIC-HONEY",
279
+ "id": "0x617bbf5a0cb37d312fe6b1021fa42ab1502746cfe9eae37b5ff9f3d9eb71ae36",
280
+ "type": "low-liq",
281
+ "origin": ""
162
282
  },
163
283
  {
164
284
  "symbol": "USDC-USD",
@@ -228,8 +348,32 @@
228
348
  }
229
349
  ],
230
350
  "endpoints": [
231
- { "type": "odin", "endpoints": ["https://hermes.pyth.network"], "writeEndpoints": ["https://odin-poly.d8x.xyz"] },
232
- { "type": "polymarket", "endpoints": [""], "writeEndpoints": ["https://odin-poly.d8x.xyz"] }
351
+ {
352
+ "type": "odin",
353
+ "endpoints": ["https://hermes.pyth.network"],
354
+ "writeEndpoints": ["https://odin.d8x.xyz/"]
355
+ },
356
+ {
357
+ "type": "low-liq",
358
+ "comment": "legacy",
359
+ "endpoints": ["https://odin-lowliq.d8x.xyz/"],
360
+ "writeEndpoints": ["https://odin-lowliq.d8x.xyz/"]
361
+ },
362
+ {
363
+ "type": "v2",
364
+ "endpoints": ["https://odin-lowliq.d8x.xyz/"],
365
+ "writeEndpoints": ["https://odin-lowliq.d8x.xyz/"]
366
+ },
367
+ {
368
+ "type": "v3",
369
+ "endpoints": ["https://odin-lowliq.d8x.xyz/"],
370
+ "writeEndpoints": ["https://odin-lowliq.d8x.xyz/"]
371
+ },
372
+ {
373
+ "type": "polymarket",
374
+ "endpoints": [""],
375
+ "writeEndpoints": ["https://odin-poly.d8x.xyz"]
376
+ }
233
377
  ]
234
378
  }
235
379
  ]
@@ -661,13 +661,13 @@ export default class MarketData extends PerpetualDataHandler {
661
661
  */
662
662
  getTraderLoyalityScore(traderAddr: string, overrides?: Overrides): Promise<number>;
663
663
  /**
664
- * Get all off-chain prices
664
+ * Get all off-chain prices for normal perps
665
665
  * @param _symbolToPerpStaticInfo mapping: PerpetualStaticInfo for each perpetual
666
666
  * @param _priceFeedGetter priceFeed class from which we can get offchain price data
667
667
  * @returns mapping of symbol-pair (e.g. BTC-USD) to price/isMarketClosed
668
668
  * @ignore
669
669
  */
670
- private static _getAllIndexPrices;
670
+ private static _getAllActivePerpIndexPrices;
671
671
  /**
672
672
  * Get market open/closed status
673
673
  * @param {string} symbol Perpetual symbol of the form ETH-USD-MATIC
@@ -1105,7 +1105,9 @@ class MarketData extends perpetualDataHandler_1.default {
1105
1105
  if (!this.proxyContract) {
1106
1106
  throw Error("no proxy contract initialized. Use createProxyInstance().");
1107
1107
  }
1108
- return await this.proxyContract.getOraclePrice([(0, utils_1.toBytes4)(base), (0, utils_1.toBytes4)(quote)], overrides || {});
1108
+ const baseBytes = (0, ethers_1.hexlify)(Uint8Array.from((0, utils_1.toBytes4)(base)));
1109
+ const quoteBytes = (0, ethers_1.hexlify)(Uint8Array.from((0, utils_1.toBytes4)(quote)));
1110
+ return await this.proxyContract.getOraclePrice([baseBytes, quoteBytes], overrides || {});
1109
1111
  }
1110
1112
  /**
1111
1113
  * Get the status of an order given a symbol and order Id
@@ -1291,6 +1293,7 @@ class MarketData extends perpetualDataHandler_1.default {
1291
1293
  let res = {
1292
1294
  id: perpInfo.id,
1293
1295
  poolId: perpInfo.poolId,
1296
+ state: perpInfo.state,
1294
1297
  limitOrderBookAddr: perpInfo.limitOrderBookAddr,
1295
1298
  initialMarginRate: perpInfo.initialMarginRate,
1296
1299
  maintenanceMarginRate: perpInfo.maintenanceMarginRate,
@@ -1513,17 +1516,20 @@ class MarketData extends perpetualDataHandler_1.default {
1513
1516
  return 5 - rank4;
1514
1517
  }
1515
1518
  /**
1516
- * Get all off-chain prices
1519
+ * Get all off-chain prices for normal perps
1517
1520
  * @param _symbolToPerpStaticInfo mapping: PerpetualStaticInfo for each perpetual
1518
1521
  * @param _priceFeedGetter priceFeed class from which we can get offchain price data
1519
1522
  * @returns mapping of symbol-pair (e.g. BTC-USD) to price/isMarketClosed
1520
1523
  * @ignore
1521
1524
  */
1522
- static async _getAllIndexPrices(_symbolToPerpStaticInfo, _priceFeedGetter) {
1525
+ static async _getAllActivePerpIndexPrices(_symbolToPerpStaticInfo, _priceFeedGetter) {
1523
1526
  // get all prices from off-chain price-sources
1524
1527
  let allSym = new Set();
1525
1528
  for (let perpSymbol of _symbolToPerpStaticInfo.keys()) {
1526
1529
  let sInfo = _symbolToPerpStaticInfo.get(perpSymbol);
1530
+ if (sInfo?.state == "INVALID" || sInfo?.state == "INITIALIZING") {
1531
+ continue;
1532
+ }
1527
1533
  allSym.add(sInfo.S2Symbol);
1528
1534
  if (sInfo.S3Symbol != "") {
1529
1535
  allSym.add(sInfo.S3Symbol);
@@ -1597,9 +1603,11 @@ class MarketData extends perpetualDataHandler_1.default {
1597
1603
  // prepare calls
1598
1604
  const proxyCalls = [];
1599
1605
  let midPriceMap = new Map();
1606
+ const collectedPerpIds = [];
1600
1607
  for (let k = 0; k < perpetualIDChunks.length; k++) {
1601
1608
  let indexPrices = [];
1602
1609
  // collect/order all index prices
1610
+ const collectedIds = [];
1603
1611
  for (let j = 0; j < perpetualIDChunks[k].length; j++) {
1604
1612
  let id = perpetualIDChunks[k][j];
1605
1613
  const poolId = Math.floor(id / 100000);
@@ -1608,6 +1616,10 @@ class MarketData extends perpetualDataHandler_1.default {
1608
1616
  }
1609
1617
  let symbol3s = _perpetualIdToSymbol.get(id);
1610
1618
  let info = _symbolToPerpStaticInfo.get(symbol3s);
1619
+ if (info?.state == "INVALID" || info?.state == "INITIALIZING") {
1620
+ continue;
1621
+ }
1622
+ collectedIds.push(id);
1611
1623
  let S2 = (0, d8XMath_1.floatToABK64x64)(_idxPriceMap.get(info.S2Symbol)[0]);
1612
1624
  let S3 = 0n;
1613
1625
  if (info.S3Symbol != "") {
@@ -1616,21 +1628,24 @@ class MarketData extends perpetualDataHandler_1.default {
1616
1628
  indexPrices.push(S2);
1617
1629
  indexPrices.push(S3);
1618
1630
  }
1631
+ collectedPerpIds.push(collectedIds);
1619
1632
  proxyCalls.push({
1620
1633
  target: _proxyContract.target,
1621
1634
  allowFailure: false,
1622
- callData: _proxyContract.interface.encodeFunctionData("queryMidPrices", [perpetualIDChunks[k], indexPrices]),
1635
+ callData: _proxyContract.interface.encodeFunctionData("queryMidPrices", [collectedIds, indexPrices]),
1623
1636
  });
1624
1637
  }
1625
1638
  // multicall
1626
1639
  const encodedResults = await _multicall.aggregate3.staticCall(proxyCalls, overrides || {});
1627
1640
  // apply results
1628
- for (let k = 0; k < perpetualIDChunks.length; k++) {
1641
+ for (let k = 0; k < collectedPerpIds.length; k++) {
1629
1642
  let fMidPrice = _proxyContract.interface.decodeFunctionResult("queryMidPrices", encodedResults[k].returnData)[0];
1630
1643
  for (let j = 0; j < fMidPrice.length; j++) {
1631
- let id = perpetualIDChunks[k][j];
1644
+ let id = collectedPerpIds[k][j];
1632
1645
  let symbol3s = _perpetualIdToSymbol.get(id);
1633
- midPriceMap.set(symbol3s, (0, d8XMath_1.ABK64x64ToFloat)(fMidPrice[j]));
1646
+ if (symbol3s != undefined) {
1647
+ midPriceMap.set(symbol3s, (0, d8XMath_1.ABK64x64ToFloat)(fMidPrice[j]));
1648
+ }
1634
1649
  }
1635
1650
  }
1636
1651
  return midPriceMap;
@@ -1771,7 +1786,7 @@ class MarketData extends perpetualDataHandler_1.default {
1771
1786
  proxyAddr: _proxyContract.target.toString(),
1772
1787
  };
1773
1788
  // get all prices from off-chain price-sources: no RPC calls
1774
- let idxPriceMap = await MarketData._getAllIndexPrices(_symbolToPerpStaticInfo, _priceFeedGetter);
1789
+ let idxPriceMap = await MarketData._getAllActivePerpIndexPrices(_symbolToPerpStaticInfo, _priceFeedGetter);
1775
1790
  // query mid-prices from on-chain conditional on the off-chain prices
1776
1791
  let midPriceMap = await MarketData._queryMidPrices(_proxyContract, _poolStaticInfos, _multicall, _nestedPerpetualIDs, _symbolToPerpStaticInfo, _perpetualIdToSymbol, idxPriceMap, overrides);
1777
1792
  const { pools: poolStateInfos, perpetuals: perpStateInfos } = await MarketData._queryPoolAndPerpetualStates(_proxyContract, _multicall, _poolStaticInfos, _symbolList, _nestedPerpetualIDs, overrides);
@@ -1779,35 +1794,40 @@ class MarketData extends perpetualDataHandler_1.default {
1779
1794
  for (const perp of perpStateInfos) {
1780
1795
  let symbol3s = _perpetualIdToSymbol.get(perp.id);
1781
1796
  let info = _symbolToPerpStaticInfo.get(symbol3s);
1782
- const idxPriceS2Pair = idxPriceMap.get(info.S2Symbol);
1783
- let idxPriceS3Pair = [0, false];
1784
- perp.isMarketClosed = idxPriceS2Pair[1];
1785
- if (info.S3Symbol != "") {
1786
- idxPriceS3Pair = idxPriceMap.get(info.S3Symbol);
1787
- perp.isMarketClosed = perp.isMarketClosed || idxPriceS3Pair[1];
1788
- }
1789
- perp.indexPrice = idxPriceS2Pair[0];
1790
- let indexS3 = 1;
1791
- if (info.collateralCurrencyType == constants_1.COLLATERAL_CURRENCY_BASE) {
1792
- indexS3 = idxPriceS2Pair[0];
1793
- }
1794
- else if (info.collateralCurrencyType == constants_1.COLLATERAL_CURRENCY_QUANTO) {
1795
- indexS3 = idxPriceS3Pair[0];
1796
- }
1797
- perp.collToQuoteIndexPrice = indexS3;
1798
- const emaKey = info.S2Symbol + ":ema";
1799
- let markPrice;
1800
- if (idxPriceMap.has(emaKey)) {
1801
- let ema;
1802
- let res = idxPriceMap.get(emaKey);
1803
- ema = res[0];
1804
- markPrice = Math.min(Math.max(ema + perp.markPremium, 1), 2);
1797
+ if (info?.state == "INVALID" || info?.state == "INITIALIZING") {
1798
+ perp.isMarketClosed = true;
1805
1799
  }
1806
1800
  else {
1807
- markPrice = perp.indexPrice * (1 + perp.markPremium);
1801
+ const idxPriceS2Pair = idxPriceMap.get(info.S2Symbol);
1802
+ let idxPriceS3Pair = [0, false];
1803
+ perp.isMarketClosed = idxPriceS2Pair[1];
1804
+ if (info.S3Symbol != "") {
1805
+ idxPriceS3Pair = idxPriceMap.get(info.S3Symbol);
1806
+ perp.isMarketClosed = perp.isMarketClosed || idxPriceS3Pair[1];
1807
+ }
1808
+ perp.indexPrice = idxPriceS2Pair[0];
1809
+ let indexS3 = 1;
1810
+ if (info.collateralCurrencyType == constants_1.COLLATERAL_CURRENCY_BASE) {
1811
+ indexS3 = idxPriceS2Pair[0];
1812
+ }
1813
+ else if (info.collateralCurrencyType == constants_1.COLLATERAL_CURRENCY_QUANTO) {
1814
+ indexS3 = idxPriceS3Pair[0];
1815
+ }
1816
+ perp.collToQuoteIndexPrice = indexS3;
1817
+ const emaKey = info.S2Symbol + ":ema";
1818
+ let markPrice;
1819
+ if (idxPriceMap.has(emaKey)) {
1820
+ let ema;
1821
+ let res = idxPriceMap.get(emaKey);
1822
+ ema = res[0];
1823
+ markPrice = Math.min(Math.max(ema + perp.markPremium, 1), 2);
1824
+ }
1825
+ else {
1826
+ markPrice = perp.indexPrice * (1 + perp.markPremium);
1827
+ }
1828
+ perp.markPrice = markPrice;
1829
+ perp.midPrice = midPriceMap.get(symbol3s);
1808
1830
  }
1809
- perp.markPrice = markPrice;
1810
- perp.midPrice = midPriceMap.get(symbol3s);
1811
1831
  // which pool?
1812
1832
  const poolId = info.poolId;
1813
1833
  poolStateInfos[poolId - 1].perpetuals.push(perp);