@1delta/margin-fetcher 0.0.230 → 0.0.231
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/index.js +110 -28
- package/dist/index.js.map +1 -1
- package/dist/prices/oracle-prices/fetchOraclePrices.d.ts.map +1 -1
- package/dist/prices/oracle-prices/fetchers/siloV2.d.ts.map +1 -1
- package/dist/prices/oracle-prices/fetchers/siloV2Graphql.d.ts +19 -1
- package/dist/prices/oracle-prices/fetchers/siloV2Graphql.d.ts.map +1 -1
- package/dist/prices/oracle-prices/fetchers/siloV3.d.ts.map +1 -1
- package/dist/prices/oracle-prices/fetchers/siloV3Graphql.d.ts +12 -1
- package/dist/prices/oracle-prices/fetchers/siloV3Graphql.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -30637,9 +30637,7 @@ function parseSiloV2Results(data, meta, context) {
|
|
|
30637
30637
|
const rawQt = data[qtIdx];
|
|
30638
30638
|
if (!rawQt || rawQt === "0x") continue;
|
|
30639
30639
|
const quoteTokenAddr = rawQt.toLowerCase();
|
|
30640
|
-
const
|
|
30641
|
-
const qtDecimals = qtMeta?.decimals ?? 18;
|
|
30642
|
-
const priceInQt = Number(quoteAmount) / Number(10n ** BigInt(qtDecimals));
|
|
30640
|
+
const priceInQt = Number(quoteAmount) / 1e18;
|
|
30643
30641
|
if (isNaN(priceInQt) || priceInQt === 0) continue;
|
|
30644
30642
|
const qtUSD = lookupUSD(context, quoteTokenAddr);
|
|
30645
30643
|
if (!qtUSD) continue;
|
|
@@ -30810,9 +30808,7 @@ function parseSiloV3Results(data, meta, context) {
|
|
|
30810
30808
|
const rawQt = data[qtIdx];
|
|
30811
30809
|
if (!rawQt || rawQt === "0x") continue;
|
|
30812
30810
|
const quoteTokenAddr = rawQt.toLowerCase();
|
|
30813
|
-
const
|
|
30814
|
-
const qtDecimals = qtMeta?.decimals ?? 18;
|
|
30815
|
-
const priceInQt = Number(quoteAmount) / Number(10n ** BigInt(qtDecimals));
|
|
30811
|
+
const priceInQt = Number(quoteAmount) / 1e18;
|
|
30816
30812
|
if (isNaN(priceInQt) || priceInQt === 0) continue;
|
|
30817
30813
|
const qtUSD = lookupUSD2(context, quoteTokenAddr);
|
|
30818
30814
|
if (!qtUSD) continue;
|
|
@@ -30861,6 +30857,51 @@ async function fetchSiloV2GraphQLMarkets(chainId) {
|
|
|
30861
30857
|
return null;
|
|
30862
30858
|
}
|
|
30863
30859
|
}
|
|
30860
|
+
async function fetchSiloV2GraphQLPrices(chainId, basePrices = {}, tokenList = {}) {
|
|
30861
|
+
const items = await fetchSiloV2GraphQLMarkets(chainId);
|
|
30862
|
+
if (items == null) return null;
|
|
30863
|
+
const usdPrices = buildSelfDerivedUsdMap(chainId, items, basePrices, tokenList);
|
|
30864
|
+
const context = { chainId, usdPrices, tokenList };
|
|
30865
|
+
const entries = parseSiloV2GraphQLResults(items, context);
|
|
30866
|
+
if (entries.length === 0) {
|
|
30867
|
+
console.warn(
|
|
30868
|
+
`[silo-v2-gql] chain ${chainId}: ${items.length} markets fetched but 0 price entries produced`
|
|
30869
|
+
);
|
|
30870
|
+
return null;
|
|
30871
|
+
}
|
|
30872
|
+
return entries;
|
|
30873
|
+
}
|
|
30874
|
+
function buildSelfDerivedUsdMap(chainId, items, basePrices, tokenList) {
|
|
30875
|
+
const map = {};
|
|
30876
|
+
const set = (tokenLc, priceUSD) => {
|
|
30877
|
+
if (!Number.isFinite(priceUSD) || priceUSD === 0) return;
|
|
30878
|
+
const groupKey = tokenList[tokenLc]?.assetGroup ?? `${chainId}-${tokenLc}`;
|
|
30879
|
+
if (map[groupKey] == null) map[groupKey] = priceUSD;
|
|
30880
|
+
if (map[tokenLc] == null) map[tokenLc] = priceUSD;
|
|
30881
|
+
};
|
|
30882
|
+
for (const item of items) {
|
|
30883
|
+
for (const market of [item.market1, item.market2]) {
|
|
30884
|
+
if (!market) continue;
|
|
30885
|
+
const tokenLc = (market.inputTokenId ?? market.inputToken?.id ?? "").toLowerCase();
|
|
30886
|
+
if (!tokenLc) continue;
|
|
30887
|
+
const supply = safeNumber3(market.supply);
|
|
30888
|
+
const supplyUsd = market.supplyUsd != null ? Number(market.supplyUsd) : 0;
|
|
30889
|
+
if (supply > 0 && supplyUsd > 0) {
|
|
30890
|
+
set(tokenLc, supplyUsd / supply);
|
|
30891
|
+
continue;
|
|
30892
|
+
}
|
|
30893
|
+
const borrowed = safeNumber3(market.borrowed);
|
|
30894
|
+
const borrowedUsd = market.borrowedUsd != null ? Number(market.borrowedUsd) : 0;
|
|
30895
|
+
if (borrowed > 0 && borrowedUsd > 0) {
|
|
30896
|
+
set(tokenLc, borrowedUsd / borrowed);
|
|
30897
|
+
}
|
|
30898
|
+
}
|
|
30899
|
+
}
|
|
30900
|
+
for (const [k, v] of Object.entries(basePrices)) {
|
|
30901
|
+
if (Number.isFinite(v) && v > 0) map[k] = v;
|
|
30902
|
+
}
|
|
30903
|
+
return map;
|
|
30904
|
+
}
|
|
30864
30905
|
function safeNumber3(v) {
|
|
30865
30906
|
if (v == null) return 0;
|
|
30866
30907
|
const n = typeof v === "number" ? v : Number(v);
|
|
@@ -30960,6 +31001,51 @@ async function fetchSiloV3GraphQLMarkets(chainId) {
|
|
|
30960
31001
|
return null;
|
|
30961
31002
|
}
|
|
30962
31003
|
}
|
|
31004
|
+
async function fetchSiloV3GraphQLPrices(chainId, basePrices = {}, tokenList = {}) {
|
|
31005
|
+
const items = await fetchSiloV3GraphQLMarkets(chainId);
|
|
31006
|
+
if (items == null) return null;
|
|
31007
|
+
const usdPrices = buildSelfDerivedUsdMap2(chainId, items, basePrices, tokenList);
|
|
31008
|
+
const context = { chainId, usdPrices, tokenList };
|
|
31009
|
+
const entries = parseSiloV3GraphQLResults(items, context);
|
|
31010
|
+
if (entries.length === 0) {
|
|
31011
|
+
console.warn(
|
|
31012
|
+
`[silo-v3-gql] chain ${chainId}: ${items.length} markets fetched but 0 price entries produced`
|
|
31013
|
+
);
|
|
31014
|
+
return null;
|
|
31015
|
+
}
|
|
31016
|
+
return entries;
|
|
31017
|
+
}
|
|
31018
|
+
function buildSelfDerivedUsdMap2(chainId, items, basePrices, tokenList) {
|
|
31019
|
+
const map = {};
|
|
31020
|
+
const set = (tokenLc, priceUSD) => {
|
|
31021
|
+
if (!Number.isFinite(priceUSD) || priceUSD === 0) return;
|
|
31022
|
+
const groupKey = tokenList[tokenLc]?.assetGroup ?? `${chainId}-${tokenLc}`;
|
|
31023
|
+
if (map[groupKey] == null) map[groupKey] = priceUSD;
|
|
31024
|
+
if (map[tokenLc] == null) map[tokenLc] = priceUSD;
|
|
31025
|
+
};
|
|
31026
|
+
for (const item of items) {
|
|
31027
|
+
for (const market of [item.market1, item.market2]) {
|
|
31028
|
+
if (!market) continue;
|
|
31029
|
+
const tokenLc = (market.inputTokenId ?? market.inputToken?.id ?? "").toLowerCase();
|
|
31030
|
+
if (!tokenLc) continue;
|
|
31031
|
+
const supply = safeNumber4(market.supply);
|
|
31032
|
+
const supplyUsd = market.supplyUsd != null ? Number(market.supplyUsd) : 0;
|
|
31033
|
+
if (supply > 0 && supplyUsd > 0) {
|
|
31034
|
+
set(tokenLc, supplyUsd / supply);
|
|
31035
|
+
continue;
|
|
31036
|
+
}
|
|
31037
|
+
const borrowed = safeNumber4(market.borrowed);
|
|
31038
|
+
const borrowedUsd = market.borrowedUsd != null ? Number(market.borrowedUsd) : 0;
|
|
31039
|
+
if (borrowed > 0 && borrowedUsd > 0) {
|
|
31040
|
+
set(tokenLc, borrowedUsd / borrowed);
|
|
31041
|
+
}
|
|
31042
|
+
}
|
|
31043
|
+
}
|
|
31044
|
+
for (const [k, v] of Object.entries(basePrices)) {
|
|
31045
|
+
if (Number.isFinite(v) && v > 0) map[k] = v;
|
|
31046
|
+
}
|
|
31047
|
+
return map;
|
|
31048
|
+
}
|
|
30963
31049
|
function safeNumber4(v) {
|
|
30964
31050
|
if (v == null) return 0;
|
|
30965
31051
|
const n = typeof v === "number" ? v : Number(v);
|
|
@@ -31287,8 +31373,8 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
|
|
|
31287
31373
|
}
|
|
31288
31374
|
const chainBatchSize = batchSize?.[chainId];
|
|
31289
31375
|
const morphoGqlPromise = isActive("morpho") ? fetchMorphoGraphQLPrices(chainId) : Promise.resolve(null);
|
|
31290
|
-
const siloV2GqlPromise =
|
|
31291
|
-
const siloV3GqlPromise =
|
|
31376
|
+
const siloV2GqlPromise = isActive("silov2") ? fetchSiloV2GraphQLPrices(chainId, basePrices, tokenList) : Promise.resolve(null);
|
|
31377
|
+
const siloV3GqlPromise = isActive("silov3") ? fetchSiloV3GraphQLPrices(chainId, basePrices, tokenList) : Promise.resolve(null);
|
|
31292
31378
|
const [
|
|
31293
31379
|
aaveData,
|
|
31294
31380
|
compoundV2Data,
|
|
@@ -31297,8 +31383,8 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
|
|
|
31297
31383
|
eulerData,
|
|
31298
31384
|
aaveV4Data,
|
|
31299
31385
|
morphoGqlEntries,
|
|
31300
|
-
|
|
31301
|
-
|
|
31386
|
+
siloV2GqlEntries,
|
|
31387
|
+
siloV3GqlEntries
|
|
31302
31388
|
] = await Promise.all([
|
|
31303
31389
|
executeGroup(
|
|
31304
31390
|
aaveGroup,
|
|
@@ -31352,12 +31438,12 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
|
|
|
31352
31438
|
siloV2GqlPromise,
|
|
31353
31439
|
siloV3GqlPromise
|
|
31354
31440
|
]);
|
|
31355
|
-
if (
|
|
31441
|
+
if (siloV2GqlEntries == null && siloV2Group.calls.length > 0) {
|
|
31356
31442
|
console.warn(
|
|
31357
|
-
`[prices] chain ${chainId}: Silo v2 GraphQL
|
|
31443
|
+
`[prices] chain ${chainId}: Silo v2 GraphQL returned null, falling back to on-chain (${siloV2Group.trackers.length} trackers)`
|
|
31358
31444
|
);
|
|
31359
31445
|
}
|
|
31360
|
-
const siloV2Data =
|
|
31446
|
+
const siloV2Data = siloV2GqlEntries != null ? { results: [], error: void 0 } : await executeGroup(
|
|
31361
31447
|
siloV2Group,
|
|
31362
31448
|
chainId,
|
|
31363
31449
|
chainBatchSize,
|
|
@@ -31365,12 +31451,12 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
|
|
|
31365
31451
|
allowFailure,
|
|
31366
31452
|
rpcOverrides
|
|
31367
31453
|
);
|
|
31368
|
-
if (
|
|
31454
|
+
if (siloV3GqlEntries == null && siloV3Group.calls.length > 0) {
|
|
31369
31455
|
console.warn(
|
|
31370
|
-
`[prices] chain ${chainId}: Silo v3 GraphQL
|
|
31456
|
+
`[prices] chain ${chainId}: Silo v3 GraphQL returned null, falling back to on-chain (${siloV3Group.trackers.length} trackers)`
|
|
31371
31457
|
);
|
|
31372
31458
|
}
|
|
31373
|
-
const siloV3Data =
|
|
31459
|
+
const siloV3Data = siloV3GqlEntries != null ? { results: [], error: void 0 } : await executeGroup(
|
|
31374
31460
|
siloV3Group,
|
|
31375
31461
|
chainId,
|
|
31376
31462
|
chainBatchSize,
|
|
@@ -31399,8 +31485,8 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
|
|
|
31399
31485
|
{ group: listaGroup, data: listaData },
|
|
31400
31486
|
{ group: eulerGroup, data: eulerData },
|
|
31401
31487
|
{ group: aaveV4Group, data: aaveV4Data },
|
|
31402
|
-
...
|
|
31403
|
-
...
|
|
31488
|
+
...siloV2GqlEntries != null ? [] : [{ group: siloV2Group, data: siloV2Data }],
|
|
31489
|
+
...siloV3GqlEntries != null ? [] : [{ group: siloV3Group, data: siloV3Data }],
|
|
31404
31490
|
...useMorphoGql ? [] : [{ group: morphoGroup, data: morphoData }]
|
|
31405
31491
|
];
|
|
31406
31492
|
for (const { group, data } of groupResults) {
|
|
@@ -31485,16 +31571,14 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
|
|
|
31485
31571
|
true,
|
|
31486
31572
|
(t) => !!t.meta.baseAssetSource
|
|
31487
31573
|
);
|
|
31488
|
-
if (
|
|
31489
|
-
const context = { chainId, usdPrices, tokenList };
|
|
31490
|
-
const entries = parseSiloV2GraphQLResults(siloV2GqlItems, context);
|
|
31574
|
+
if (siloV2GqlEntries != null) {
|
|
31491
31575
|
const diag2 = {
|
|
31492
31576
|
lender: "SILO_V2 (GraphQL)",
|
|
31493
31577
|
callCount: 0,
|
|
31494
31578
|
failedCalls: 0,
|
|
31495
|
-
parsedEntries:
|
|
31579
|
+
parsedEntries: siloV2GqlEntries.length
|
|
31496
31580
|
};
|
|
31497
|
-
for (const entry of
|
|
31581
|
+
for (const entry of siloV2GqlEntries) {
|
|
31498
31582
|
const lender = entry.targetLender ?? "SILO_V2";
|
|
31499
31583
|
if (!chainResult[lender]) chainResult[lender] = [];
|
|
31500
31584
|
chainResult[lender].push(entry);
|
|
@@ -31506,16 +31590,14 @@ async function fetchOraclePrices(chainIds, rpcOverrides, lists = {}, retries = 3
|
|
|
31506
31590
|
} else {
|
|
31507
31591
|
parseTrackers(siloV2Group, siloV2Data.results);
|
|
31508
31592
|
}
|
|
31509
|
-
if (
|
|
31510
|
-
const context = { chainId, usdPrices, tokenList };
|
|
31511
|
-
const entries = parseSiloV3GraphQLResults(siloV3GqlItems, context);
|
|
31593
|
+
if (siloV3GqlEntries != null) {
|
|
31512
31594
|
const diag2 = {
|
|
31513
31595
|
lender: "SILO_V3 (GraphQL)",
|
|
31514
31596
|
callCount: 0,
|
|
31515
31597
|
failedCalls: 0,
|
|
31516
|
-
parsedEntries:
|
|
31598
|
+
parsedEntries: siloV3GqlEntries.length
|
|
31517
31599
|
};
|
|
31518
|
-
for (const entry of
|
|
31600
|
+
for (const entry of siloV3GqlEntries) {
|
|
31519
31601
|
const lender = entry.targetLender ?? "SILO_V3";
|
|
31520
31602
|
if (!chainResult[lender]) chainResult[lender] = [];
|
|
31521
31603
|
chainResult[lender].push(entry);
|