@d8x/perpetuals-sdk 2.6.22 → 2.7.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.
- package/dist/cjs/config/defaultConfig.json +2 -2
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/d8XMath.d.ts +42 -25
- package/dist/cjs/d8XMath.js +188 -151
- package/dist/cjs/d8XMath.js.map +1 -1
- package/dist/cjs/liquidatorTool.d.ts +1 -1
- package/dist/cjs/liquidatorTool.js +9 -9
- package/dist/cjs/liquidatorTool.js.map +1 -1
- package/dist/cjs/marketData.d.ts +3 -3
- package/dist/cjs/marketData.js +9 -8
- package/dist/cjs/marketData.js.map +1 -1
- package/dist/cjs/perpetualDataHandler.d.ts +3 -3
- package/dist/cjs/perpetualDataHandler.js +7 -5
- package/dist/cjs/perpetualDataHandler.js.map +1 -1
- package/dist/cjs/polyMktsPxFeed.js +2 -2
- package/dist/cjs/polyMktsPxFeed.js.map +1 -1
- package/dist/cjs/priceFeeds.d.ts +1 -0
- package/dist/cjs/priceFeeds.js +18 -2
- package/dist/cjs/priceFeeds.js.map +1 -1
- package/dist/cjs/utils.d.ts +3 -3
- package/dist/cjs/utils.js.map +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/config/defaultConfig.json +2 -2
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/d8XMath.d.ts +42 -25
- package/dist/esm/d8XMath.js +187 -150
- package/dist/esm/d8XMath.js.map +1 -1
- package/dist/esm/liquidatorTool.d.ts +1 -1
- package/dist/esm/liquidatorTool.js +10 -10
- package/dist/esm/liquidatorTool.js.map +1 -1
- package/dist/esm/marketData.d.ts +3 -3
- package/dist/esm/marketData.js +9 -8
- package/dist/esm/marketData.js.map +1 -1
- package/dist/esm/perpetualDataHandler.d.ts +3 -3
- package/dist/esm/perpetualDataHandler.js +7 -5
- package/dist/esm/perpetualDataHandler.js.map +1 -1
- package/dist/esm/polyMktsPxFeed.js +2 -2
- package/dist/esm/polyMktsPxFeed.js.map +1 -1
- package/dist/esm/priceFeeds.d.ts +1 -0
- package/dist/esm/priceFeeds.js +18 -2
- package/dist/esm/priceFeeds.js.map +1 -1
- package/dist/esm/utils.d.ts +3 -3
- package/dist/esm/utils.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/doc/d8x-perpetuals-sdk.md +116 -64
- package/package.json +1 -1
- package/src/config/defaultConfig.json +2 -2
- package/src/constants.ts +0 -1
- package/src/d8XMath.ts +210 -167
- package/src/liquidatorTool.ts +16 -10
- package/src/marketData.ts +38 -25
- package/src/perpetualDataHandler.ts +13 -9
- package/src/polyMktsPxFeed.ts +6 -7
- package/src/priceFeeds.ts +19 -3
- package/src/utils.ts +3 -3
- package/src/version.ts +1 -1
package/src/marketData.ts
CHANGED
|
@@ -487,6 +487,7 @@ export default class MarketData extends PerpetualDataHandler {
|
|
|
487
487
|
const [fS2, fS3, fEma] = [indexPriceInfo.s2, indexPriceInfo.s3 ?? 0, indexPriceInfo.ema].map((x) =>
|
|
488
488
|
floatToABK64x64(x)
|
|
489
489
|
) as [bigint, bigint, bigint];
|
|
490
|
+
|
|
490
491
|
const proxyCalls: Multicall3.Call3Struct[] = [
|
|
491
492
|
// 0: traderState
|
|
492
493
|
{
|
|
@@ -502,7 +503,7 @@ export default class MarketData extends PerpetualDataHandler {
|
|
|
502
503
|
perpId,
|
|
503
504
|
floatToABK64x64(tradeAmountBC),
|
|
504
505
|
[fS2, fS3],
|
|
505
|
-
indexPriceInfo.conf
|
|
506
|
+
indexPriceInfo.conf & ((1n << 16n) - 1n),
|
|
506
507
|
indexPriceInfo.predMktCLOBParams,
|
|
507
508
|
]),
|
|
508
509
|
},
|
|
@@ -563,7 +564,7 @@ export default class MarketData extends PerpetualDataHandler {
|
|
|
563
564
|
perpId,
|
|
564
565
|
floatToABK64x64(tradeAmountBC),
|
|
565
566
|
[floatToABK64x64(indexPriceInfo.s2), floatToABK64x64(indexPriceInfo.s3 ?? 0)],
|
|
566
|
-
indexPriceInfo.conf
|
|
567
|
+
indexPriceInfo.conf,
|
|
567
568
|
indexPriceInfo.predMktCLOBParams
|
|
568
569
|
);
|
|
569
570
|
}
|
|
@@ -754,14 +755,23 @@ export default class MarketData extends PerpetualDataHandler {
|
|
|
754
755
|
b0 = b0 < 0 ? b0 : 0;
|
|
755
756
|
pos0 = 0;
|
|
756
757
|
}
|
|
757
|
-
traderDepositCC = getDepositAmountForLvgTrade(
|
|
758
|
+
traderDepositCC = getDepositAmountForLvgTrade(
|
|
759
|
+
pos0,
|
|
760
|
+
b0,
|
|
761
|
+
tradeAmountBC,
|
|
762
|
+
targetLvg,
|
|
763
|
+
tradePrice,
|
|
764
|
+
S3,
|
|
765
|
+
Sm,
|
|
766
|
+
isPredMkt ? initialMarginRate : undefined
|
|
767
|
+
);
|
|
758
768
|
// fees are paid from wallet in this case
|
|
759
769
|
traderDepositCC += tradingFeeCC + referralFeeCC;
|
|
760
770
|
}
|
|
761
771
|
|
|
762
772
|
// Contract: _executeTrade
|
|
763
|
-
let deltaCashCC = (-tradeAmountBC * (tradePrice - S2)) / S3;
|
|
764
|
-
let deltaLockedQC = tradeAmountBC * S2;
|
|
773
|
+
let deltaCashCC = 0; // (-tradeAmountBC * (tradePrice - S2)) / S3;
|
|
774
|
+
let deltaLockedQC = tradeAmountBC * tradePrice; // tradeAmountBC * S2;
|
|
765
775
|
if (isClose) {
|
|
766
776
|
let pnl = account.entryPrice * tradeAmountBC - deltaLockedQC;
|
|
767
777
|
deltaLockedQC += pnl;
|
|
@@ -1688,7 +1698,7 @@ export default class MarketData extends PerpetualDataHandler {
|
|
|
1688
1698
|
this.symbolToPerpStaticInfo,
|
|
1689
1699
|
this.proxyContract,
|
|
1690
1700
|
[priceInfo.s2, priceInfo.s3 ?? 0], //s2,s3
|
|
1691
|
-
priceInfo.conf,
|
|
1701
|
+
priceInfo.conf,
|
|
1692
1702
|
priceInfo.predMktCLOBParams, //params
|
|
1693
1703
|
overrides
|
|
1694
1704
|
);
|
|
@@ -2044,9 +2054,9 @@ export default class MarketData extends PerpetualDataHandler {
|
|
|
2044
2054
|
* @ignore
|
|
2045
2055
|
*/
|
|
2046
2056
|
private static async _getAllActivePerpIndexPrices(
|
|
2047
|
-
_symbolToPerpStaticInfo:
|
|
2057
|
+
_symbolToPerpStaticInfo: ReadonlyMap<string, PerpetualStaticInfo>,
|
|
2048
2058
|
_priceFeedGetter: PriceFeeds,
|
|
2049
|
-
_symbolList:
|
|
2059
|
+
_symbolList: ReadonlyMap<string, string>
|
|
2050
2060
|
): Promise<Map<string, [number, boolean]>> {
|
|
2051
2061
|
// get all prices from off-chain price-sources
|
|
2052
2062
|
let allSym = new Set<string>();
|
|
@@ -2133,13 +2143,13 @@ export default class MarketData extends PerpetualDataHandler {
|
|
|
2133
2143
|
*/
|
|
2134
2144
|
private static async _queryMidPrices(
|
|
2135
2145
|
_proxyContract: Contract,
|
|
2136
|
-
_poolStaticInfos:
|
|
2146
|
+
_poolStaticInfos: ReadonlyArray<PoolStaticInfo>,
|
|
2137
2147
|
_multicall: Multicall3,
|
|
2138
|
-
_nestedPerpetualIDs:
|
|
2139
|
-
_symbolToPerpStaticInfo:
|
|
2140
|
-
_perpetualIdToSymbol:
|
|
2141
|
-
_idxPriceMap:
|
|
2142
|
-
_symbolList:
|
|
2148
|
+
_nestedPerpetualIDs: ReadonlyArray<ReadonlyArray<number>>,
|
|
2149
|
+
_symbolToPerpStaticInfo: ReadonlyMap<string, PerpetualStaticInfo>,
|
|
2150
|
+
_perpetualIdToSymbol: ReadonlyMap<number, string>,
|
|
2151
|
+
_idxPriceMap: ReadonlyMap<string, [number, boolean]>,
|
|
2152
|
+
_symbolList: ReadonlyMap<string, string>,
|
|
2143
2153
|
overrides?: Overrides
|
|
2144
2154
|
): Promise<Map<string, number>> {
|
|
2145
2155
|
// what is the maximal number of queries at once?
|
|
@@ -2218,9 +2228,9 @@ export default class MarketData extends PerpetualDataHandler {
|
|
|
2218
2228
|
private static async _queryPoolAndPerpetualStates(
|
|
2219
2229
|
_proxyContract: Contract,
|
|
2220
2230
|
_multicall: Multicall3,
|
|
2221
|
-
_poolStaticInfos: PoolStaticInfo
|
|
2222
|
-
_symbolList:
|
|
2223
|
-
_nestedPerpetualIDs:
|
|
2231
|
+
_poolStaticInfos: ReadonlyArray<PoolStaticInfo>,
|
|
2232
|
+
_symbolList: ReadonlyMap<string, string>,
|
|
2233
|
+
_nestedPerpetualIDs: ReadonlyArray<ReadonlyArray<number>>,
|
|
2224
2234
|
overrides?: Overrides
|
|
2225
2235
|
): Promise<{ pools: Array<PoolState>; perpetuals: Array<PerpetualState> }> {
|
|
2226
2236
|
const chunkSize = 5;
|
|
@@ -2298,7 +2308,7 @@ export default class MarketData extends PerpetualDataHandler {
|
|
|
2298
2308
|
*/
|
|
2299
2309
|
protected static _poolDataToPoolState(
|
|
2300
2310
|
_liquidityPools: Partial<PerpStorage.LiquidityPoolDataStructOutput>[],
|
|
2301
|
-
_poolStaticInfos: PoolStaticInfo
|
|
2311
|
+
_poolStaticInfos: ReadonlyArray<PoolStaticInfo>
|
|
2302
2312
|
): PoolState[] {
|
|
2303
2313
|
const poolStates = _liquidityPools.map(
|
|
2304
2314
|
(pool, k) =>
|
|
@@ -2328,7 +2338,7 @@ export default class MarketData extends PerpetualDataHandler {
|
|
|
2328
2338
|
protected static _perpetualDataToPerpetualState(
|
|
2329
2339
|
_perpetuals: any[],
|
|
2330
2340
|
_longShortBC: [bigint, bigint][],
|
|
2331
|
-
_symbolList:
|
|
2341
|
+
_symbolList: ReadonlyMap<string, string>
|
|
2332
2342
|
): PerpetualState[] {
|
|
2333
2343
|
const perpStates = new Array<PerpetualState>();
|
|
2334
2344
|
for (let k = 0; k < _perpetuals.length; k++) {
|
|
@@ -2370,11 +2380,11 @@ export default class MarketData extends PerpetualDataHandler {
|
|
|
2370
2380
|
public static async _exchangeInfo(
|
|
2371
2381
|
_proxyContract: Contract,
|
|
2372
2382
|
_multicall: Multicall3,
|
|
2373
|
-
_poolStaticInfos:
|
|
2374
|
-
_symbolToPerpStaticInfo:
|
|
2375
|
-
_perpetualIdToSymbol:
|
|
2376
|
-
_nestedPerpetualIDs:
|
|
2377
|
-
_symbolList:
|
|
2383
|
+
_poolStaticInfos: ReadonlyArray<PoolStaticInfo>,
|
|
2384
|
+
_symbolToPerpStaticInfo: ReadonlyMap<string, PerpetualStaticInfo>,
|
|
2385
|
+
_perpetualIdToSymbol: ReadonlyMap<number, string>,
|
|
2386
|
+
_nestedPerpetualIDs: ReadonlyArray<ReadonlyArray<number>>,
|
|
2387
|
+
_symbolList: ReadonlyMap<string, string>,
|
|
2378
2388
|
_priceFeedGetter: PriceFeeds,
|
|
2379
2389
|
_oracleFactoryAddr: string,
|
|
2380
2390
|
overrides?: Overrides
|
|
@@ -2429,11 +2439,14 @@ export default class MarketData extends PerpetualDataHandler {
|
|
|
2429
2439
|
} else {
|
|
2430
2440
|
const idxPriceS2Pair = idxPriceMap.get(MarketData.getIndexSymbol(_symbolList, info))!;
|
|
2431
2441
|
let idxPriceS3Pair: [number, boolean] = [0, false];
|
|
2432
|
-
perp.isMarketClosed =
|
|
2442
|
+
perp.isMarketClosed =
|
|
2443
|
+
idxPriceS2Pair[1] ||
|
|
2444
|
+
(MarketData.isPredictionMarketStatic(info) && (idxPriceS2Pair[0] == 1 || idxPriceS2Pair[0] == 2));
|
|
2433
2445
|
if (info.S3Symbol != "" && idxPriceMap.has(info.S3Symbol)) {
|
|
2434
2446
|
idxPriceS3Pair = idxPriceMap.get(info.S3Symbol)!;
|
|
2435
2447
|
perp.isMarketClosed = perp.isMarketClosed || idxPriceS3Pair[1];
|
|
2436
2448
|
}
|
|
2449
|
+
|
|
2437
2450
|
perp.indexPrice = idxPriceS2Pair[0];
|
|
2438
2451
|
let indexS3 = 1;
|
|
2439
2452
|
if (info.collateralCurrencyType == COLLATERAL_CURRENCY_BASE) {
|
|
@@ -225,6 +225,7 @@ export default class PerpetualDataHandler {
|
|
|
225
225
|
throw new Error(`failed to fetch config (${res.status}): ${res.statusText} ${this.config.configSource}`);
|
|
226
226
|
}
|
|
227
227
|
let symlist = await res.json();
|
|
228
|
+
console.log("fetched symbol list from source", this.config.configSource + "/symbolList.json");
|
|
228
229
|
this.symbolList = new Map<string, string>(Object.entries(symlist));
|
|
229
230
|
}
|
|
230
231
|
|
|
@@ -302,7 +303,7 @@ export default class PerpetualDataHandler {
|
|
|
302
303
|
const tokenOverrides = require("./config/tokenOverrides.json") as TokenOverride[];
|
|
303
304
|
|
|
304
305
|
let poolInfo = await PerpetualDataHandler.getPoolStaticInfo(this.proxyContract);
|
|
305
|
-
|
|
306
|
+
console.log({ poolInfo });
|
|
306
307
|
const IERC20 = ERC20__factory.createInterface();
|
|
307
308
|
|
|
308
309
|
const proxyCalls: Multicall3.Call3Struct[] = poolInfo.poolMarginTokenAddr.map((tokenAddr) => ({
|
|
@@ -323,6 +324,7 @@ export default class PerpetualDataHandler {
|
|
|
323
324
|
|
|
324
325
|
// multicall
|
|
325
326
|
const encodedResults = await this.multicall.aggregate3.staticCall(proxyCalls, overrides || {});
|
|
327
|
+
console.log({ encodedResults });
|
|
326
328
|
|
|
327
329
|
// pre-allocate all pool static infos with id and margin token info
|
|
328
330
|
const poolStaticInfos: PoolStaticInfo[] = [];
|
|
@@ -729,7 +731,7 @@ export default class PerpetualDataHandler {
|
|
|
729
731
|
*/
|
|
730
732
|
protected static async fetchSlotsInfo(chainId: bigint | number | string) {
|
|
731
733
|
let result: SlotInfo[] = [];
|
|
732
|
-
const query = `https://sports.quantena.org/slots-info/${Number(chainId)}`;
|
|
734
|
+
const query = `https://sports-v2.quantena.org/slots-info/${Number(chainId)}`;
|
|
733
735
|
const res = await fetch(query);
|
|
734
736
|
if (res.status == 200 && res.ok) {
|
|
735
737
|
result = await res.json();
|
|
@@ -796,7 +798,10 @@ export default class PerpetualDataHandler {
|
|
|
796
798
|
* @param {number[][]} nestedIDs The array of nested arrays to chunk.
|
|
797
799
|
* @returns {number[][]} An array of subarrays, each containing `chunkSize` or fewer elements from `nestedIDs`.
|
|
798
800
|
*/
|
|
799
|
-
public static nestedIDsToChunks(
|
|
801
|
+
public static nestedIDsToChunks(
|
|
802
|
+
chunkSize: number,
|
|
803
|
+
nestedIDs: ReadonlyArray<ReadonlyArray<number>>
|
|
804
|
+
): Array<Array<number>> {
|
|
800
805
|
const chunkIDs: number[][] = [];
|
|
801
806
|
let currentChunk: number[] = [];
|
|
802
807
|
for (let k = 0; k < nestedIDs.length; k++) {
|
|
@@ -1327,7 +1332,7 @@ export default class PerpetualDataHandler {
|
|
|
1327
1332
|
perpId,
|
|
1328
1333
|
floatToABK64x64(tradeAmount),
|
|
1329
1334
|
fIndexPrices as [bigint, bigint],
|
|
1330
|
-
conf
|
|
1335
|
+
conf & ((1n << 16n) - 1n),
|
|
1331
1336
|
params,
|
|
1332
1337
|
overrides || {}
|
|
1333
1338
|
);
|
|
@@ -1507,10 +1512,10 @@ export default class PerpetualDataHandler {
|
|
|
1507
1512
|
let unpaidFunding = unpaidFundingCC;
|
|
1508
1513
|
|
|
1509
1514
|
if (isPredMarket) {
|
|
1510
|
-
const S2Liq = pmFindLiquidationPrice(position, S3Liq, lockedInValueQC, cashCC, tau
|
|
1515
|
+
const S2Liq = pmFindLiquidationPrice(position, S3Liq, lockedInValueQC, cashCC, tau);
|
|
1511
1516
|
let pnl = position * Sm - lockedInValueQC + unpaidFunding / S3Liq;
|
|
1512
1517
|
// liquidation margin rate
|
|
1513
|
-
const tauLiq = pmMaintenanceMarginRate(position, S2Liq, tau);
|
|
1518
|
+
const tauLiq = pmMaintenanceMarginRate(position, lockedInValueQC, S2Liq, tau);
|
|
1514
1519
|
return [S2Liq, S3Liq, tauLiq, pnl, unpaidFundingCC];
|
|
1515
1520
|
}
|
|
1516
1521
|
// regular perpetuals:
|
|
@@ -1579,7 +1584,7 @@ export default class PerpetualDataHandler {
|
|
|
1579
1584
|
return undefined;
|
|
1580
1585
|
}
|
|
1581
1586
|
|
|
1582
|
-
protected static _getBySingleValue(map:
|
|
1587
|
+
protected static _getBySingleValue(map: ReadonlyMap<string, string>, searchValue: string) {
|
|
1583
1588
|
for (let [key, value] of map.entries()) {
|
|
1584
1589
|
if (searchValue.startsWith(value)) {
|
|
1585
1590
|
return key;
|
|
@@ -1785,7 +1790,6 @@ export default class PerpetualDataHandler {
|
|
|
1785
1790
|
}
|
|
1786
1791
|
|
|
1787
1792
|
private static _flagToOrderType(orderFlags: bigint, orderLimitPrice: bigint): string {
|
|
1788
|
-
// TODO: check
|
|
1789
1793
|
let flag = BigInt(orderFlags);
|
|
1790
1794
|
let isLimit = containsFlag(flag, MASK_LIMIT_ORDER);
|
|
1791
1795
|
let hasLimit = BigInt(orderLimitPrice) != 0n || BigInt(orderLimitPrice) != MAX_64x64;
|
|
@@ -2367,7 +2371,7 @@ export default class PerpetualDataHandler {
|
|
|
2367
2371
|
* @param info Perpetual static info
|
|
2368
2372
|
* @returns Index symbol
|
|
2369
2373
|
*/
|
|
2370
|
-
public static getIndexSymbol(_symbolList:
|
|
2374
|
+
public static getIndexSymbol(_symbolList: ReadonlyMap<string, string>, info: PerpetualStaticInfo) {
|
|
2371
2375
|
if (PerpetualDataHandler.isPredictionMarketStatic(info)) {
|
|
2372
2376
|
const slot = PerpetualDataHandler._getBySingleValue(_symbolList, info.S2Symbol);
|
|
2373
2377
|
if (slot !== undefined) {
|
package/src/polyMktsPxFeed.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { probToPrice } from "./d8XMath";
|
|
2
2
|
import type { PredMktPriceInfo, PriceFeedConfig, PriceFeedJson } from "./nodeSDKTypes";
|
|
3
|
-
import { sleepForSec } from "./utils";
|
|
4
3
|
|
|
5
4
|
interface PolyConfig {
|
|
6
5
|
sym: string;
|
|
@@ -43,7 +42,7 @@ export default class PolyMktsPxFeed {
|
|
|
43
42
|
}
|
|
44
43
|
}
|
|
45
44
|
|
|
46
|
-
this.oracleEndpoint = this.oracleEndpoint.replace(/\/$/, "") + "/
|
|
45
|
+
this.oracleEndpoint = this.oracleEndpoint.replace(/\/$/, "") + "/v3/updates/price/latest?encoding=base64&ids[]=";
|
|
47
46
|
}
|
|
48
47
|
|
|
49
48
|
public isPolyMktsSym(sym: string) {
|
|
@@ -98,21 +97,21 @@ export default class PolyMktsPxFeed {
|
|
|
98
97
|
| { price: PriceFeedJson; ema_price: PriceFeedJson; metadata: { market_closed: boolean } }
|
|
99
98
|
| undefined;
|
|
100
99
|
|
|
101
|
-
const emaObj = parsed?.ema_price
|
|
102
|
-
const pxObj = parsed?.price
|
|
100
|
+
const emaObj = parsed?.ema_price;
|
|
101
|
+
const pxObj = parsed?.price;
|
|
103
102
|
const marketClosed = Boolean(parsed?.metadata.market_closed);
|
|
104
103
|
|
|
105
104
|
const s2 = pxObj == undefined || pxObj.price == "NaN" ? 0 : Number(pxObj.price) * Math.pow(10, pxObj.expo);
|
|
106
105
|
const ema = emaObj == undefined || emaObj.price == "NaN" ? 0 : Number(emaObj.price) * Math.pow(10, emaObj.expo);
|
|
107
106
|
const params = emaObj?.conf == undefined ? 0n : BigInt(emaObj.conf);
|
|
108
107
|
const conf = pxObj?.conf == undefined ? 0n : BigInt(pxObj.conf);
|
|
109
|
-
const info = {
|
|
108
|
+
const info: PredMktPriceInfo = {
|
|
110
109
|
s2,
|
|
111
110
|
ema,
|
|
112
111
|
s2MktClosed: marketClosed || s2 == 0 || ema == 0,
|
|
113
|
-
conf
|
|
112
|
+
conf,
|
|
114
113
|
predMktCLOBParams: params,
|
|
115
|
-
}
|
|
114
|
+
};
|
|
116
115
|
res.push(info);
|
|
117
116
|
}
|
|
118
117
|
return res;
|
package/src/priceFeeds.ts
CHANGED
|
@@ -69,6 +69,7 @@ export default class PriceFeeds {
|
|
|
69
69
|
throw new Error(`failed to fetch config (${res.status}): ${res.statusText} ${configSrc}`);
|
|
70
70
|
}
|
|
71
71
|
configs = await res.json();
|
|
72
|
+
console.log("fetched price config from source", configSrc + "/priceFeedConfig.json");
|
|
72
73
|
}
|
|
73
74
|
this.config = PriceFeeds._selectConfig(configs, this.priceFeedConfigNetwork);
|
|
74
75
|
|
|
@@ -257,7 +258,7 @@ export default class PriceFeeds {
|
|
|
257
258
|
let priceObj = (await this.polyMktsPxFeed.fetchPricesForSyms([indexSymbols[0]]))[0];
|
|
258
259
|
const s3map = await this.fetchFeedPrices([indexSymbols[1]]);
|
|
259
260
|
const s3 = s3map.get(indexSymbols[1])!;
|
|
260
|
-
|
|
261
|
+
const pxInfo: IdxPriceInfo = {
|
|
261
262
|
s2: priceObj.s2,
|
|
262
263
|
s3: s3[0],
|
|
263
264
|
ema: priceObj.ema,
|
|
@@ -265,7 +266,8 @@ export default class PriceFeeds {
|
|
|
265
266
|
s3MktClosed: s3[1],
|
|
266
267
|
conf: priceObj.conf,
|
|
267
268
|
predMktCLOBParams: priceObj.predMktCLOBParams,
|
|
268
|
-
}
|
|
269
|
+
};
|
|
270
|
+
return pxInfo;
|
|
269
271
|
}
|
|
270
272
|
// determine relevant price feeds
|
|
271
273
|
let feedSymbols = new Array<string>();
|
|
@@ -464,6 +466,20 @@ export default class PriceFeeds {
|
|
|
464
466
|
return this.fetchFeedPrices(this.dataHandler.requiredSymbols);
|
|
465
467
|
}
|
|
466
468
|
|
|
469
|
+
private _buildQuery(baseUrl: string, id: string) {
|
|
470
|
+
// odin-sports use v3 api, all else v2
|
|
471
|
+
let method = "";
|
|
472
|
+
if (baseUrl.includes("odin-sport")) {
|
|
473
|
+
method = "/v3/updates/price/latest?encoding=base64&ids[]=";
|
|
474
|
+
} else {
|
|
475
|
+
method = "/v2/updates/price/latest?encoding=base64&ids[]=";
|
|
476
|
+
}
|
|
477
|
+
// e.g.
|
|
478
|
+
// 'https://odin-sport.quantena.org/v3/updates/price/latest?encoding=base64&ids[]=0x5b622123024d99bea493662fe91bf9785b8b0decd46c65cdbeef6a0a1672b057',
|
|
479
|
+
// 'https://hermes.pyth.network/v2/updates/price/latest?encoding=base64&ids[]=0x2b89b9dc8fdf9f34709a5b106b472f0f39bb6ca9ce04b0fd7f2e971688e2e53b'
|
|
480
|
+
return baseUrl + method + id;
|
|
481
|
+
}
|
|
482
|
+
|
|
467
483
|
/**
|
|
468
484
|
* Get the latest prices for a given perpetual from the offchain oracle
|
|
469
485
|
* networks. Uses write price feed endpoints.
|
|
@@ -487,7 +503,7 @@ export default class PriceFeeds {
|
|
|
487
503
|
// we use the first endpoint for a given symbol even if there is another symbol with the same id
|
|
488
504
|
let idx = info[0].endpointId;
|
|
489
505
|
let feedId = feedIds[k];
|
|
490
|
-
queries.push(this.writeFeedEndpoints[idx]
|
|
506
|
+
queries.push(this._buildQuery(this.writeFeedEndpoints[idx], feedId));
|
|
491
507
|
|
|
492
508
|
for (let j = 0; j < info.length; j++) {
|
|
493
509
|
if (symbols.has(feedId)) {
|
package/src/utils.ts
CHANGED
|
@@ -83,7 +83,7 @@ export function fromBytes4HexString(s: string): string {
|
|
|
83
83
|
* @param {Object} mapping List of symbol and clean symbol pairs, e.g. [{symbol: "MATIC", cleanSymbol: "MATC"}, ...]
|
|
84
84
|
* @returns {string} User friendly currency symbol, e.g. "MATIC"
|
|
85
85
|
*/
|
|
86
|
-
export function contractSymbolToSymbol(s: string, mapping:
|
|
86
|
+
export function contractSymbolToSymbol(s: string, mapping: ReadonlyMap<string, string>): string {
|
|
87
87
|
let shortCCY = fromBytes4HexString(s);
|
|
88
88
|
// assume CCY is already short if not in the mapping file
|
|
89
89
|
let longCCY = mapping.get(shortCCY) ?? shortCCY;
|
|
@@ -96,7 +96,7 @@ export function contractSymbolToSymbol(s: string, mapping: Map<string, string>):
|
|
|
96
96
|
* @param {Object} mapping List of symbol and clean symbol pairs, e.g. [{symbol: "MATIC", cleanSymbol: "MATC"}, ...]
|
|
97
97
|
* @returns {Buffer} Buffer that can be used with smart contract to identify tokens
|
|
98
98
|
*/
|
|
99
|
-
export function symbolToContractSymbol(s: string, mapping:
|
|
99
|
+
export function symbolToContractSymbol(s: string, mapping: ReadonlyMap<string, string>): Buffer {
|
|
100
100
|
let shortCCY: string | undefined = undefined;
|
|
101
101
|
for (let [k, v] of mapping) {
|
|
102
102
|
if (v == s) {
|
|
@@ -114,7 +114,7 @@ export function symbolToContractSymbol(s: string, mapping: Map<string, string>):
|
|
|
114
114
|
* @param {Object} mapping list of symbol and clean symbol pairs, e.g. [{symbol: "MATIC", cleanSymbol: "MATC"}, ...]
|
|
115
115
|
* @returns {string} long format e.g. MATIC. if not found the element is ""
|
|
116
116
|
*/
|
|
117
|
-
export function symbol4BToLongSymbol(s: string, mapping:
|
|
117
|
+
export function symbol4BToLongSymbol(s: string, mapping: ReadonlyMap<string, string>): string {
|
|
118
118
|
let ccy = s.split("-");
|
|
119
119
|
let longCCY = "";
|
|
120
120
|
for (let k = 0; k < ccy.length; k++) {
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const D8X_SDK_VERSION = "2.
|
|
1
|
+
export const D8X_SDK_VERSION = "2.7.00";
|