@owney/sdk 0.7.18 → 0.7.19
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 +37 -2
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +37 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2223,6 +2223,39 @@ function sumWithdrawnAmount(results) {
|
|
|
2223
2223
|
}
|
|
2224
2224
|
|
|
2225
2225
|
// src/lib/helpers/account-apy-helper.ts
|
|
2226
|
+
function balanceForApyScope(balance, chainId, tokenSymbol) {
|
|
2227
|
+
if (!tokenSymbol) {
|
|
2228
|
+
const total = Number(balance.totalBalance);
|
|
2229
|
+
return Number.isFinite(total) && total > 0 ? total : 0;
|
|
2230
|
+
}
|
|
2231
|
+
const normalizedToken = tokenSymbol.toUpperCase();
|
|
2232
|
+
return balance.tokens.reduce((total, token) => {
|
|
2233
|
+
if (Number(token.chainId) !== chainId || String(token.asset).toUpperCase() !== normalizedToken) {
|
|
2234
|
+
return total;
|
|
2235
|
+
}
|
|
2236
|
+
const amount = Number(token.amount);
|
|
2237
|
+
return Number.isFinite(amount) && amount > 0 ? total + amount : total;
|
|
2238
|
+
}, 0);
|
|
2239
|
+
}
|
|
2240
|
+
function aggregateApyHistory(agentApys, agentBalances) {
|
|
2241
|
+
const byDate = /* @__PURE__ */ new Map();
|
|
2242
|
+
for (const [id, accountApy] of Object.entries(agentApys)) {
|
|
2243
|
+
const balance = agentBalances[id] ?? 0;
|
|
2244
|
+
if (!Number.isFinite(balance) || balance <= 0) continue;
|
|
2245
|
+
for (const point of accountApy.history ?? []) {
|
|
2246
|
+
const apy = Number(point.apy);
|
|
2247
|
+
if (!point.date || !Number.isFinite(apy)) continue;
|
|
2248
|
+
const current = byDate.get(point.date) ?? { weightedSum: 0, weight: 0 };
|
|
2249
|
+
current.weightedSum += apy * balance;
|
|
2250
|
+
current.weight += balance;
|
|
2251
|
+
byDate.set(point.date, current);
|
|
2252
|
+
}
|
|
2253
|
+
}
|
|
2254
|
+
return [...byDate.entries()].sort(([left], [right]) => left.localeCompare(right)).map(([date, value]) => ({
|
|
2255
|
+
date,
|
|
2256
|
+
apy: value.weightedSum / value.weight
|
|
2257
|
+
}));
|
|
2258
|
+
}
|
|
2226
2259
|
function aggregateApyByChainAndAsset(agentApys, agentBalances) {
|
|
2227
2260
|
const sums = {};
|
|
2228
2261
|
const weights = {};
|
|
@@ -3893,7 +3926,7 @@ var OwneySDK = class {
|
|
|
3893
3926
|
Promise.all(
|
|
3894
3927
|
entries.map(async ([id, agent]) => {
|
|
3895
3928
|
const b = await this.readAgent(agent, "balances", () => agent.getBalances(state, chainId));
|
|
3896
|
-
return [id,
|
|
3929
|
+
return [id, balanceForApyScope(b, chainId, tokenSymbol)];
|
|
3897
3930
|
})
|
|
3898
3931
|
)
|
|
3899
3932
|
]);
|
|
@@ -3921,10 +3954,12 @@ var OwneySDK = class {
|
|
|
3921
3954
|
}
|
|
3922
3955
|
}
|
|
3923
3956
|
const apyByChainAndAsset = aggregateApyByChainAndAsset(results, balances);
|
|
3957
|
+
const history = aggregateApyHistory(results, balances);
|
|
3924
3958
|
return {
|
|
3925
3959
|
totalApy: String(totalApy),
|
|
3926
3960
|
agentApy: results,
|
|
3927
|
-
apyByChainAndAsset
|
|
3961
|
+
apyByChainAndAsset,
|
|
3962
|
+
history
|
|
3928
3963
|
};
|
|
3929
3964
|
}
|
|
3930
3965
|
/**
|
package/dist/index.d.cts
CHANGED
|
@@ -296,6 +296,8 @@ interface OwneyAccountApy {
|
|
|
296
296
|
totalApy: string;
|
|
297
297
|
agentApy: Record<AgentId, AccountAgentApy>;
|
|
298
298
|
apyByChainAndAsset: ApyByChainAndAsset;
|
|
299
|
+
/** Daily APY weighted by current balances in the requested chain/asset scope. */
|
|
300
|
+
history?: ApyHistoryPoint[];
|
|
299
301
|
}
|
|
300
302
|
interface AllocationAgentApy {
|
|
301
303
|
/** Account-wide weighted APY for this agent, as a decimal string. */
|
package/dist/index.d.ts
CHANGED
|
@@ -296,6 +296,8 @@ interface OwneyAccountApy {
|
|
|
296
296
|
totalApy: string;
|
|
297
297
|
agentApy: Record<AgentId, AccountAgentApy>;
|
|
298
298
|
apyByChainAndAsset: ApyByChainAndAsset;
|
|
299
|
+
/** Daily APY weighted by current balances in the requested chain/asset scope. */
|
|
300
|
+
history?: ApyHistoryPoint[];
|
|
299
301
|
}
|
|
300
302
|
interface AllocationAgentApy {
|
|
301
303
|
/** Account-wide weighted APY for this agent, as a decimal string. */
|
package/dist/index.js
CHANGED
|
@@ -2190,6 +2190,39 @@ function sumWithdrawnAmount(results) {
|
|
|
2190
2190
|
}
|
|
2191
2191
|
|
|
2192
2192
|
// src/lib/helpers/account-apy-helper.ts
|
|
2193
|
+
function balanceForApyScope(balance, chainId, tokenSymbol) {
|
|
2194
|
+
if (!tokenSymbol) {
|
|
2195
|
+
const total = Number(balance.totalBalance);
|
|
2196
|
+
return Number.isFinite(total) && total > 0 ? total : 0;
|
|
2197
|
+
}
|
|
2198
|
+
const normalizedToken = tokenSymbol.toUpperCase();
|
|
2199
|
+
return balance.tokens.reduce((total, token) => {
|
|
2200
|
+
if (Number(token.chainId) !== chainId || String(token.asset).toUpperCase() !== normalizedToken) {
|
|
2201
|
+
return total;
|
|
2202
|
+
}
|
|
2203
|
+
const amount = Number(token.amount);
|
|
2204
|
+
return Number.isFinite(amount) && amount > 0 ? total + amount : total;
|
|
2205
|
+
}, 0);
|
|
2206
|
+
}
|
|
2207
|
+
function aggregateApyHistory(agentApys, agentBalances) {
|
|
2208
|
+
const byDate = /* @__PURE__ */ new Map();
|
|
2209
|
+
for (const [id, accountApy] of Object.entries(agentApys)) {
|
|
2210
|
+
const balance = agentBalances[id] ?? 0;
|
|
2211
|
+
if (!Number.isFinite(balance) || balance <= 0) continue;
|
|
2212
|
+
for (const point of accountApy.history ?? []) {
|
|
2213
|
+
const apy = Number(point.apy);
|
|
2214
|
+
if (!point.date || !Number.isFinite(apy)) continue;
|
|
2215
|
+
const current = byDate.get(point.date) ?? { weightedSum: 0, weight: 0 };
|
|
2216
|
+
current.weightedSum += apy * balance;
|
|
2217
|
+
current.weight += balance;
|
|
2218
|
+
byDate.set(point.date, current);
|
|
2219
|
+
}
|
|
2220
|
+
}
|
|
2221
|
+
return [...byDate.entries()].sort(([left], [right]) => left.localeCompare(right)).map(([date, value]) => ({
|
|
2222
|
+
date,
|
|
2223
|
+
apy: value.weightedSum / value.weight
|
|
2224
|
+
}));
|
|
2225
|
+
}
|
|
2193
2226
|
function aggregateApyByChainAndAsset(agentApys, agentBalances) {
|
|
2194
2227
|
const sums = {};
|
|
2195
2228
|
const weights = {};
|
|
@@ -3864,7 +3897,7 @@ var OwneySDK = class {
|
|
|
3864
3897
|
Promise.all(
|
|
3865
3898
|
entries.map(async ([id, agent]) => {
|
|
3866
3899
|
const b = await this.readAgent(agent, "balances", () => agent.getBalances(state, chainId));
|
|
3867
|
-
return [id,
|
|
3900
|
+
return [id, balanceForApyScope(b, chainId, tokenSymbol)];
|
|
3868
3901
|
})
|
|
3869
3902
|
)
|
|
3870
3903
|
]);
|
|
@@ -3892,10 +3925,12 @@ var OwneySDK = class {
|
|
|
3892
3925
|
}
|
|
3893
3926
|
}
|
|
3894
3927
|
const apyByChainAndAsset = aggregateApyByChainAndAsset(results, balances);
|
|
3928
|
+
const history = aggregateApyHistory(results, balances);
|
|
3895
3929
|
return {
|
|
3896
3930
|
totalApy: String(totalApy),
|
|
3897
3931
|
agentApy: results,
|
|
3898
|
-
apyByChainAndAsset
|
|
3932
|
+
apyByChainAndAsset,
|
|
3933
|
+
history
|
|
3899
3934
|
};
|
|
3900
3935
|
}
|
|
3901
3936
|
/**
|