@owney/sdk 0.6.1-beta.1 → 0.6.1-beta.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/index.cjs +20 -1
- package/dist/index.js +20 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -264,10 +264,29 @@ function mapWeightedApyByChain(raw) {
|
|
|
264
264
|
}
|
|
265
265
|
return Object.keys(out).length > 0 ? out : void 0;
|
|
266
266
|
}
|
|
267
|
+
function weightedFinalApy(entry) {
|
|
268
|
+
const finalByToken = entry.final_weighted_apy ?? {};
|
|
269
|
+
const balanceByToken = {};
|
|
270
|
+
for (const p of entry.positions ?? []) {
|
|
271
|
+
const token = p.tokenSymbol ?? "";
|
|
272
|
+
balanceByToken[token] = (balanceByToken[token] ?? 0) + (p.balance ?? 0);
|
|
273
|
+
}
|
|
274
|
+
let weightedSum = 0;
|
|
275
|
+
let totalBalance = 0;
|
|
276
|
+
for (const [token, apy] of Object.entries(finalByToken)) {
|
|
277
|
+
const balance = balanceByToken[token] ?? 0;
|
|
278
|
+
weightedSum += apy * balance;
|
|
279
|
+
totalBalance += balance;
|
|
280
|
+
}
|
|
281
|
+
if (totalBalance > 0)
|
|
282
|
+
return weightedSum / totalBalance;
|
|
283
|
+
const values = Object.values(finalByToken);
|
|
284
|
+
return values.length ? values.reduce((sum, v) => sum + v, 0) / values.length : 0;
|
|
285
|
+
}
|
|
267
286
|
function mapApyHistory(raw) {
|
|
268
287
|
const history = Object.entries(raw.history ?? {}).map(([date, entry]) => ({
|
|
269
288
|
date,
|
|
270
|
-
apy:
|
|
289
|
+
apy: weightedFinalApy(entry)
|
|
271
290
|
})).sort((a, b) => a.date.localeCompare(b.date));
|
|
272
291
|
return {
|
|
273
292
|
walletAddress: raw.walletAddress,
|
package/dist/index.js
CHANGED
|
@@ -232,10 +232,29 @@ function mapWeightedApyByChain(raw) {
|
|
|
232
232
|
}
|
|
233
233
|
return Object.keys(out).length > 0 ? out : void 0;
|
|
234
234
|
}
|
|
235
|
+
function weightedFinalApy(entry) {
|
|
236
|
+
const finalByToken = entry.final_weighted_apy ?? {};
|
|
237
|
+
const balanceByToken = {};
|
|
238
|
+
for (const p of entry.positions ?? []) {
|
|
239
|
+
const token = p.tokenSymbol ?? "";
|
|
240
|
+
balanceByToken[token] = (balanceByToken[token] ?? 0) + (p.balance ?? 0);
|
|
241
|
+
}
|
|
242
|
+
let weightedSum = 0;
|
|
243
|
+
let totalBalance = 0;
|
|
244
|
+
for (const [token, apy] of Object.entries(finalByToken)) {
|
|
245
|
+
const balance = balanceByToken[token] ?? 0;
|
|
246
|
+
weightedSum += apy * balance;
|
|
247
|
+
totalBalance += balance;
|
|
248
|
+
}
|
|
249
|
+
if (totalBalance > 0)
|
|
250
|
+
return weightedSum / totalBalance;
|
|
251
|
+
const values = Object.values(finalByToken);
|
|
252
|
+
return values.length ? values.reduce((sum, v) => sum + v, 0) / values.length : 0;
|
|
253
|
+
}
|
|
235
254
|
function mapApyHistory(raw) {
|
|
236
255
|
const history = Object.entries(raw.history ?? {}).map(([date, entry]) => ({
|
|
237
256
|
date,
|
|
238
|
-
apy:
|
|
257
|
+
apy: weightedFinalApy(entry)
|
|
239
258
|
})).sort((a, b) => a.date.localeCompare(b.date));
|
|
240
259
|
return {
|
|
241
260
|
walletAddress: raw.walletAddress,
|