@owney/sdk 0.6.2 → 0.6.3
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 +25 -1
- package/dist/index.d.cts +13 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.js +25 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -264,11 +264,35 @@ 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) {
|
|
287
|
+
const history = Object.entries(raw.history ?? {}).map(([date, entry]) => ({
|
|
288
|
+
date,
|
|
289
|
+
apy: weightedFinalApy(entry)
|
|
290
|
+
})).sort((a, b) => a.date.localeCompare(b.date));
|
|
268
291
|
return {
|
|
269
292
|
walletAddress: raw.walletAddress,
|
|
270
293
|
weightedApyAfterFee: raw.weightedApyAfterFee ? sumTokenValues(raw.weightedApyAfterFee) : void 0,
|
|
271
|
-
apyByChainAndAsset: mapWeightedApyByChain(raw.weightedApyAfterFeeByChain)
|
|
294
|
+
apyByChainAndAsset: mapWeightedApyByChain(raw.weightedApyAfterFeeByChain),
|
|
295
|
+
history
|
|
272
296
|
};
|
|
273
297
|
}
|
|
274
298
|
function splitOpportunity(opportunity) {
|
package/dist/index.d.cts
CHANGED
|
@@ -86,11 +86,23 @@ interface OwneyEarnings {
|
|
|
86
86
|
agentEarnings: Record<AgentId, AgentEarnings>;
|
|
87
87
|
}
|
|
88
88
|
type ApyByChainAndAsset = Partial<Record<OwneySupportedChainId, Partial<Record<OwneySupportedTokens, number>>>>;
|
|
89
|
+
/** A single day's net APY for the connected account, as a percentage number. */
|
|
90
|
+
interface ApyHistoryPoint {
|
|
91
|
+
/** ISO date string for the day, e.g. "2026-06-20". */
|
|
92
|
+
date: string;
|
|
93
|
+
/** Net (after-fee) weighted APY for that day, summed across tokens. */
|
|
94
|
+
apy: number;
|
|
95
|
+
}
|
|
89
96
|
interface AccountAgentApy {
|
|
90
97
|
walletAddress: string;
|
|
91
98
|
weightedApyAfterFee?: number;
|
|
92
99
|
weightedApyAfterFeeDetails?: AgentApyDetails;
|
|
93
100
|
apyByChainAndAsset?: ApyByChainAndAsset;
|
|
101
|
+
/**
|
|
102
|
+
* Daily net-APY series for the requested window (7D/14D/30D), ascending by
|
|
103
|
+
* date. Empty when the provider returns no daily history.
|
|
104
|
+
*/
|
|
105
|
+
history?: ApyHistoryPoint[];
|
|
94
106
|
}
|
|
95
107
|
interface OwneyAccountApy {
|
|
96
108
|
totalApy: string;
|
|
@@ -469,4 +481,4 @@ type OwneySIWXConfig = {
|
|
|
469
481
|
*/
|
|
470
482
|
declare function createOwneySIWX(config: OwneySIWXConfig): SIWXConfig;
|
|
471
483
|
|
|
472
|
-
export { AccountAgentApy, AccountApyOptions, AgentApy, AgentApyDetails, AgentBalance, AgentChainIncompatibleError, AgentEarnings, AgentHistoryEntry, AgentHistoryPosition, AgentId, AgentNotFoundError, AgentSupportedAsset, AgentSupportedAssets, AgentUserProfile, AgentWithdrawResult, AgentsApyOptions, AllocationAgentApy, AllocationApyOptions, ApyByChainAndAsset, Asset, ConnectionState, DailyApyDays, DepositCallback, DepositOptions, HistoryAction, HistoryFilters, HistoryOptions, HistoryTransaction, IAgent, InvalidHistoryCursorError, NotConnectedError, OwneyAccountApy, OwneyAgentApy, OwneyAgentHistory, OwneyAllocationApy, OwneyBalances, OwneyDepositResult, OwneyEarnings, OwneyError, OwneyErrorCode, OwneyMultiDepositResult, OwneyPosition, OwneySDK, OwneySDKConfig, OwneySIWXConfig, OwneySupportedChainId, OwneySupportedChains, OwneySupportedTokens, OwneyToken, OwneyUserProfile, OwneyWithdrawResult, RebalanceLog, WithdrawOptions, createOwneySIWX };
|
|
484
|
+
export { AccountAgentApy, AccountApyOptions, AgentApy, AgentApyDetails, AgentBalance, AgentChainIncompatibleError, AgentEarnings, AgentHistoryEntry, AgentHistoryPosition, AgentId, AgentNotFoundError, AgentSupportedAsset, AgentSupportedAssets, AgentUserProfile, AgentWithdrawResult, AgentsApyOptions, AllocationAgentApy, AllocationApyOptions, ApyByChainAndAsset, ApyHistoryPoint, Asset, ConnectionState, DailyApyDays, DepositCallback, DepositOptions, HistoryAction, HistoryFilters, HistoryOptions, HistoryTransaction, IAgent, InvalidHistoryCursorError, NotConnectedError, OwneyAccountApy, OwneyAgentApy, OwneyAgentHistory, OwneyAllocationApy, OwneyBalances, OwneyDepositResult, OwneyEarnings, OwneyError, OwneyErrorCode, OwneyMultiDepositResult, OwneyPosition, OwneySDK, OwneySDKConfig, OwneySIWXConfig, OwneySupportedChainId, OwneySupportedChains, OwneySupportedTokens, OwneyToken, OwneyUserProfile, OwneyWithdrawResult, RebalanceLog, WithdrawOptions, createOwneySIWX };
|
package/dist/index.d.ts
CHANGED
|
@@ -86,11 +86,23 @@ interface OwneyEarnings {
|
|
|
86
86
|
agentEarnings: Record<AgentId, AgentEarnings>;
|
|
87
87
|
}
|
|
88
88
|
type ApyByChainAndAsset = Partial<Record<OwneySupportedChainId, Partial<Record<OwneySupportedTokens, number>>>>;
|
|
89
|
+
/** A single day's net APY for the connected account, as a percentage number. */
|
|
90
|
+
interface ApyHistoryPoint {
|
|
91
|
+
/** ISO date string for the day, e.g. "2026-06-20". */
|
|
92
|
+
date: string;
|
|
93
|
+
/** Net (after-fee) weighted APY for that day, summed across tokens. */
|
|
94
|
+
apy: number;
|
|
95
|
+
}
|
|
89
96
|
interface AccountAgentApy {
|
|
90
97
|
walletAddress: string;
|
|
91
98
|
weightedApyAfterFee?: number;
|
|
92
99
|
weightedApyAfterFeeDetails?: AgentApyDetails;
|
|
93
100
|
apyByChainAndAsset?: ApyByChainAndAsset;
|
|
101
|
+
/**
|
|
102
|
+
* Daily net-APY series for the requested window (7D/14D/30D), ascending by
|
|
103
|
+
* date. Empty when the provider returns no daily history.
|
|
104
|
+
*/
|
|
105
|
+
history?: ApyHistoryPoint[];
|
|
94
106
|
}
|
|
95
107
|
interface OwneyAccountApy {
|
|
96
108
|
totalApy: string;
|
|
@@ -469,4 +481,4 @@ type OwneySIWXConfig = {
|
|
|
469
481
|
*/
|
|
470
482
|
declare function createOwneySIWX(config: OwneySIWXConfig): SIWXConfig;
|
|
471
483
|
|
|
472
|
-
export { AccountAgentApy, AccountApyOptions, AgentApy, AgentApyDetails, AgentBalance, AgentChainIncompatibleError, AgentEarnings, AgentHistoryEntry, AgentHistoryPosition, AgentId, AgentNotFoundError, AgentSupportedAsset, AgentSupportedAssets, AgentUserProfile, AgentWithdrawResult, AgentsApyOptions, AllocationAgentApy, AllocationApyOptions, ApyByChainAndAsset, Asset, ConnectionState, DailyApyDays, DepositCallback, DepositOptions, HistoryAction, HistoryFilters, HistoryOptions, HistoryTransaction, IAgent, InvalidHistoryCursorError, NotConnectedError, OwneyAccountApy, OwneyAgentApy, OwneyAgentHistory, OwneyAllocationApy, OwneyBalances, OwneyDepositResult, OwneyEarnings, OwneyError, OwneyErrorCode, OwneyMultiDepositResult, OwneyPosition, OwneySDK, OwneySDKConfig, OwneySIWXConfig, OwneySupportedChainId, OwneySupportedChains, OwneySupportedTokens, OwneyToken, OwneyUserProfile, OwneyWithdrawResult, RebalanceLog, WithdrawOptions, createOwneySIWX };
|
|
484
|
+
export { AccountAgentApy, AccountApyOptions, AgentApy, AgentApyDetails, AgentBalance, AgentChainIncompatibleError, AgentEarnings, AgentHistoryEntry, AgentHistoryPosition, AgentId, AgentNotFoundError, AgentSupportedAsset, AgentSupportedAssets, AgentUserProfile, AgentWithdrawResult, AgentsApyOptions, AllocationAgentApy, AllocationApyOptions, ApyByChainAndAsset, ApyHistoryPoint, Asset, ConnectionState, DailyApyDays, DepositCallback, DepositOptions, HistoryAction, HistoryFilters, HistoryOptions, HistoryTransaction, IAgent, InvalidHistoryCursorError, NotConnectedError, OwneyAccountApy, OwneyAgentApy, OwneyAgentHistory, OwneyAllocationApy, OwneyBalances, OwneyDepositResult, OwneyEarnings, OwneyError, OwneyErrorCode, OwneyMultiDepositResult, OwneyPosition, OwneySDK, OwneySDKConfig, OwneySIWXConfig, OwneySupportedChainId, OwneySupportedChains, OwneySupportedTokens, OwneyToken, OwneyUserProfile, OwneyWithdrawResult, RebalanceLog, WithdrawOptions, createOwneySIWX };
|
package/dist/index.js
CHANGED
|
@@ -232,11 +232,35 @@ 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) {
|
|
255
|
+
const history = Object.entries(raw.history ?? {}).map(([date, entry]) => ({
|
|
256
|
+
date,
|
|
257
|
+
apy: weightedFinalApy(entry)
|
|
258
|
+
})).sort((a, b) => a.date.localeCompare(b.date));
|
|
236
259
|
return {
|
|
237
260
|
walletAddress: raw.walletAddress,
|
|
238
261
|
weightedApyAfterFee: raw.weightedApyAfterFee ? sumTokenValues(raw.weightedApyAfterFee) : void 0,
|
|
239
|
-
apyByChainAndAsset: mapWeightedApyByChain(raw.weightedApyAfterFeeByChain)
|
|
262
|
+
apyByChainAndAsset: mapWeightedApyByChain(raw.weightedApyAfterFeeByChain),
|
|
263
|
+
history
|
|
240
264
|
};
|
|
241
265
|
}
|
|
242
266
|
function splitOpportunity(opportunity) {
|