@1delta/margin-fetcher 0.0.66 → 0.0.67
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
CHANGED
|
@@ -19993,121 +19993,65 @@ var getChainLinkKeys = (chainId) => {
|
|
|
19993
19993
|
|
|
19994
19994
|
// src/prices/pendle/fetchPendlePrices.ts
|
|
19995
19995
|
var PENDLE_API_BASE = "https://api-v2.pendle.finance/core";
|
|
19996
|
-
var MARKETS_ENDPOINT =
|
|
19997
|
-
var PRICES_ENDPOINT = (
|
|
19998
|
-
var
|
|
19999
|
-
// '1', Disabled for now
|
|
20000
|
-
"42161",
|
|
20001
|
-
"10",
|
|
20002
|
-
"56",
|
|
20003
|
-
"8453",
|
|
20004
|
-
"5000",
|
|
20005
|
-
"146",
|
|
20006
|
-
"80094"
|
|
20007
|
-
];
|
|
20008
|
-
var marketsCache = null;
|
|
19996
|
+
var MARKETS_ENDPOINT = `${PENDLE_API_BASE}/v1/markets/all`;
|
|
19997
|
+
var PRICES_ENDPOINT = (types) => `${PENDLE_API_BASE}/v1/prices/assets${types ? `?type=${types.join(",")}` : ""}`;
|
|
19998
|
+
var marketsCache = {};
|
|
20009
19999
|
var marketsCacheTimestamp = 0;
|
|
20010
20000
|
var MARKETS_CACHE_TTL = 5 * 60 * 1e3;
|
|
20011
|
-
async function fetchMarketsForChain(chainId) {
|
|
20012
|
-
try {
|
|
20013
|
-
const response = await fetch(MARKETS_ENDPOINT(chainId));
|
|
20014
|
-
const data = await response.json();
|
|
20015
|
-
return data.markets || [];
|
|
20016
|
-
} catch (error) {
|
|
20017
|
-
console.error(`Error fetching markets for chain ${chainId}:`, error);
|
|
20018
|
-
return [];
|
|
20019
|
-
}
|
|
20020
|
-
}
|
|
20021
20001
|
async function fetchPendleMarkets() {
|
|
20022
|
-
|
|
20023
|
-
if (marketsCache && now - marketsCacheTimestamp < MARKETS_CACHE_TTL) {
|
|
20002
|
+
if (Object.keys(marketsCache).length && marketsCacheTimestamp > Date.now() - MARKETS_CACHE_TTL) {
|
|
20024
20003
|
return marketsCache;
|
|
20025
20004
|
}
|
|
20026
20005
|
try {
|
|
20027
|
-
const
|
|
20028
|
-
|
|
20029
|
-
|
|
20030
|
-
const chainMarkets = fetchMarketsForChain(chainId);
|
|
20031
|
-
promises.push(chainMarkets);
|
|
20006
|
+
const response = await fetch(MARKETS_ENDPOINT);
|
|
20007
|
+
if (!response.ok) {
|
|
20008
|
+
throw new Error(`Failed to fetch all markets data: ${response.status}`);
|
|
20032
20009
|
}
|
|
20033
|
-
const
|
|
20034
|
-
|
|
20035
|
-
|
|
20036
|
-
|
|
20037
|
-
|
|
20038
|
-
|
|
20010
|
+
const data = await response.json();
|
|
20011
|
+
const marketsByChain = {};
|
|
20012
|
+
if (data.markets) {
|
|
20013
|
+
for (const market of data.markets) {
|
|
20014
|
+
const chainId = market.chainId.toString();
|
|
20015
|
+
if (!marketsByChain[chainId]) {
|
|
20016
|
+
marketsByChain[chainId] = [];
|
|
20017
|
+
}
|
|
20018
|
+
marketsByChain[chainId].push(market);
|
|
20019
|
+
}
|
|
20020
|
+
}
|
|
20021
|
+
marketsCache = marketsByChain;
|
|
20022
|
+
marketsCacheTimestamp = Date.now();
|
|
20023
|
+
return marketsByChain;
|
|
20039
20024
|
} catch (error) {
|
|
20040
|
-
console.error("Error fetching
|
|
20041
|
-
return
|
|
20025
|
+
console.error("Error fetching all markets data:", error);
|
|
20026
|
+
return {};
|
|
20042
20027
|
}
|
|
20043
20028
|
}
|
|
20044
|
-
async function
|
|
20029
|
+
async function fetchPendlePricesForAllChain(lists = {}, assetType = ["YT", "PT"]) {
|
|
20045
20030
|
try {
|
|
20046
|
-
const
|
|
20047
|
-
|
|
20048
|
-
|
|
20049
|
-
|
|
20050
|
-
const
|
|
20051
|
-
|
|
20052
|
-
|
|
20053
|
-
|
|
20054
|
-
|
|
20055
|
-
return allPrices;
|
|
20031
|
+
const response = await fetch(PRICES_ENDPOINT(assetType));
|
|
20032
|
+
const data = await response.json();
|
|
20033
|
+
let prices = {};
|
|
20034
|
+
Object.entries(data.prices).forEach(([key, val]) => {
|
|
20035
|
+
const [chainId, address] = key.split("-");
|
|
20036
|
+
const assetKey = lists[chainId]?.list?.[address.toLowerCase()]?.assetGroup ?? key;
|
|
20037
|
+
prices[assetKey] = val;
|
|
20038
|
+
});
|
|
20039
|
+
return prices;
|
|
20056
20040
|
} catch (error) {
|
|
20057
|
-
console.error(`Error fetching
|
|
20041
|
+
console.error(`Error fetching prices pendle prices:`, error);
|
|
20058
20042
|
return {};
|
|
20059
20043
|
}
|
|
20060
20044
|
}
|
|
20061
|
-
function
|
|
20062
|
-
const tokensByChain = {};
|
|
20063
|
-
markets.forEach((market) => {
|
|
20064
|
-
const chain = market.pt?.split("-")[0];
|
|
20065
|
-
if (chain && !tokensByChain[chain]) {
|
|
20066
|
-
tokensByChain[chain] = { pt: [], yt: [], sy: [] };
|
|
20067
|
-
}
|
|
20068
|
-
if (market.pt && chain) {
|
|
20069
|
-
const address = market.pt.split("-")[1];
|
|
20070
|
-
if (address && !tokensByChain[chain].pt.includes(address)) {
|
|
20071
|
-
tokensByChain[chain].pt.push(address);
|
|
20072
|
-
}
|
|
20073
|
-
}
|
|
20074
|
-
if (market.yt && chain) {
|
|
20075
|
-
const address = market.yt.split("-")[1];
|
|
20076
|
-
if (address && !tokensByChain[chain].yt.includes(address)) {
|
|
20077
|
-
tokensByChain[chain].yt.push(address);
|
|
20078
|
-
}
|
|
20079
|
-
}
|
|
20080
|
-
if (market.sy && chain) {
|
|
20081
|
-
const address = market.sy.split("-")[1];
|
|
20082
|
-
if (address && !tokensByChain[chain].sy.includes(address)) {
|
|
20083
|
-
tokensByChain[chain].sy.push(address);
|
|
20084
|
-
}
|
|
20085
|
-
}
|
|
20086
|
-
});
|
|
20087
|
-
return tokensByChain;
|
|
20088
|
-
}
|
|
20089
|
-
async function fetchPendlePrices() {
|
|
20045
|
+
async function fetchPendlePrices(lists = {}) {
|
|
20090
20046
|
try {
|
|
20091
20047
|
const marketsResponse = await fetchPendleMarkets();
|
|
20092
|
-
if (!marketsResponse.
|
|
20048
|
+
if (!Object.keys(marketsResponse).length) {
|
|
20093
20049
|
return {};
|
|
20094
20050
|
}
|
|
20095
|
-
const
|
|
20096
|
-
|
|
20051
|
+
const allPrices = await fetchPendlePricesForAllChain(lists);
|
|
20052
|
+
return Object.fromEntries(
|
|
20053
|
+
Object.entries(allPrices).filter(([, price]) => !!price)
|
|
20097
20054
|
);
|
|
20098
|
-
const allPrices = {};
|
|
20099
|
-
for (const chainId of SUPPORTED_CHAINS) {
|
|
20100
|
-
if (tokensByChain[chainId]) {
|
|
20101
|
-
const chainPrices = await fetchPendlePricesForChain(chainId, "YT");
|
|
20102
|
-
Object.entries(chainPrices).forEach(([address, price]) => {
|
|
20103
|
-
if (price !== 0) {
|
|
20104
|
-
const prefixedAddress = `${chainId}-${address}`;
|
|
20105
|
-
allPrices[prefixedAddress] = price;
|
|
20106
|
-
}
|
|
20107
|
-
});
|
|
20108
|
-
}
|
|
20109
|
-
}
|
|
20110
|
-
return allPrices;
|
|
20111
20055
|
} catch (error) {
|
|
20112
20056
|
console.error("Error in fetchPendlePrices:", error);
|
|
20113
20057
|
return {};
|
|
@@ -20281,7 +20225,7 @@ var fetchMainPrices = async (chainIds, rpcOverrides, lists = {}) => {
|
|
|
20281
20225
|
}
|
|
20282
20226
|
};
|
|
20283
20227
|
});
|
|
20284
|
-
const otherDataPromises = [fetchDefillamaData(), fetchPendlePrices()];
|
|
20228
|
+
const otherDataPromises = [fetchDefillamaData(), fetchPendlePrices(lists)];
|
|
20285
20229
|
const [chainResults, ...otherResults] = await Promise.all([
|
|
20286
20230
|
Promise.all(multicallPromises),
|
|
20287
20231
|
...otherDataPromises
|