@elemental-stv-core/sdk 0.9.1 → 0.9.2
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/jlpd-strategy/jlp-data.js +32 -10
- package/package.json +1 -1
|
@@ -105,19 +105,41 @@ async function fetchAllCustodies(connection) {
|
|
|
105
105
|
};
|
|
106
106
|
});
|
|
107
107
|
}
|
|
108
|
+
// Module-level memo for Jupiter price/v3 — 3 consumers in this file
|
|
109
|
+
// (fetchJlpCustodyData, fetchJlpPoolDetails, fetchJlpEffectiveWeights) used to
|
|
110
|
+
// each hit the API independently. A single jlp-pool-snapshot route would fire
|
|
111
|
+
// 3 redundant calls per cache miss. 30s TTL is short enough that prices stay
|
|
112
|
+
// fresh for downstream NAV/weight math, long enough to coalesce snapshot loads.
|
|
113
|
+
const PRICES_TTL_MS = 30000;
|
|
114
|
+
let pricesCache = null;
|
|
115
|
+
let pricesInFlight = null;
|
|
108
116
|
async function fetchPrices() {
|
|
117
|
+
if (pricesCache && Date.now() - pricesCache.at < PRICES_TTL_MS) {
|
|
118
|
+
return pricesCache.data;
|
|
119
|
+
}
|
|
120
|
+
if (pricesInFlight)
|
|
121
|
+
return pricesInFlight;
|
|
109
122
|
const ids = CUSTODIES.map((c) => c.mintAddress).join(",");
|
|
110
123
|
const url = `${JUPITER_PRICE_API}?ids=${ids}`;
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
124
|
+
pricesInFlight = (async () => {
|
|
125
|
+
try {
|
|
126
|
+
const response = await fetch(url);
|
|
127
|
+
if (!response.ok) {
|
|
128
|
+
throw new Error(`Jupiter Price API error: ${response.status}`);
|
|
129
|
+
}
|
|
130
|
+
const json = (await response.json());
|
|
131
|
+
const prices = {};
|
|
132
|
+
for (const [mint, data] of Object.entries(json)) {
|
|
133
|
+
prices[mint] = data.usdPrice;
|
|
134
|
+
}
|
|
135
|
+
pricesCache = { at: Date.now(), data: prices };
|
|
136
|
+
return prices;
|
|
137
|
+
}
|
|
138
|
+
finally {
|
|
139
|
+
pricesInFlight = null;
|
|
140
|
+
}
|
|
141
|
+
})();
|
|
142
|
+
return pricesInFlight;
|
|
121
143
|
}
|
|
122
144
|
function calculateDebtTokens(raw) {
|
|
123
145
|
if (raw.debt <= raw.borrowLendInterestsAccrued)
|