@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.
@@ -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
- const response = await fetch(url);
112
- if (!response.ok) {
113
- throw new Error(`Jupiter Price API error: ${response.status}`);
114
- }
115
- const json = (await response.json());
116
- const prices = {};
117
- for (const [mint, data] of Object.entries(json)) {
118
- prices[mint] = data.usdPrice;
119
- }
120
- return prices;
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)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elemental-stv-core/sdk",
3
- "version": "0.9.1",
3
+ "version": "0.9.2",
4
4
  "description": "TypeScript SDK for Elemental Vaults — p-STV Core, Elemental Lend, JLPD Strategy",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [