@owney/sdk 0.6.2-beta.0 → 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 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) {
@@ -1984,17 +2008,17 @@ var OwneySDK = class {
1984
2008
  * preserve the user's scroll position should keep using cursors from the
1985
2009
  * original snapshot.
1986
2010
  *
1987
- * @param params.agentId - Optional. Agent to query. Omit for all active agents.
1988
- * @param params.filters - Optional. Pagination + date filters.
2011
+ * @param options.agentId - Optional. Agent to query. Omit for all active agents.
2012
+ * @param options.filters - Optional. Pagination + date filters.
1989
2013
  * - `limit`: max entries per page (default 10)
1990
2014
  * - `cursor`: opaque cursor returned by a previous call
1991
2015
  * - `fromDate` / `toDate`: ISO 8601 date strings
1992
2016
  * @returns {OwneyAgentHistory} `data` (up to `limit` entries), `hasMore`, `nextCursor`.
1993
2017
  */
1994
- async getHistory(params) {
2018
+ async getHistory(options) {
1995
2019
  const state = this.requireState();
1996
2020
  const chainId = this.requireChainId();
1997
- const { agentId, filters } = params ?? {};
2021
+ const { agentId, filters } = options ?? {};
1998
2022
  if (agentId) {
1999
2023
  return this.getAgent(agentId).getHistory(state, chainId, filters);
2000
2024
  }
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;
@@ -236,6 +248,9 @@ type AccountApyOptions = {
236
248
  agentId?: AgentId;
237
249
  days: DailyApyDays;
238
250
  };
251
+ type AllocationApyOptions = {
252
+ agentId?: AgentId;
253
+ };
239
254
  type AgentsApyOptions = {
240
255
  agentId?: AgentId;
241
256
  days: DailyApyDays;
@@ -386,14 +401,14 @@ declare class OwneySDK {
386
401
  * preserve the user's scroll position should keep using cursors from the
387
402
  * original snapshot.
388
403
  *
389
- * @param params.agentId - Optional. Agent to query. Omit for all active agents.
390
- * @param params.filters - Optional. Pagination + date filters.
404
+ * @param options.agentId - Optional. Agent to query. Omit for all active agents.
405
+ * @param options.filters - Optional. Pagination + date filters.
391
406
  * - `limit`: max entries per page (default 10)
392
407
  * - `cursor`: opaque cursor returned by a previous call
393
408
  * - `fromDate` / `toDate`: ISO 8601 date strings
394
409
  * @returns {OwneyAgentHistory} `data` (up to `limit` entries), `hasMore`, `nextCursor`.
395
410
  */
396
- getHistory(params?: HistoryOptions): Promise<OwneyAgentHistory>;
411
+ getHistory(options?: HistoryOptions): Promise<OwneyAgentHistory>;
397
412
  /**
398
413
  * Get the user's profile for a specific agent, or all agents.
399
414
  * @param agentId - Optional. Agent to query. Omit for all agents.
@@ -420,9 +435,7 @@ declare class OwneySDK {
420
435
  * @param options.agentId - Optional. Scope to one agent. Omit to aggregate
421
436
  * positions across all active agents.
422
437
  */
423
- getAllocationApy({ agentId, }?: {
424
- agentId?: AgentId;
425
- }): Promise<OwneyAllocationApy>;
438
+ getAllocationApy({ agentId, }?: AllocationApyOptions): Promise<OwneyAllocationApy>;
426
439
  }
427
440
 
428
441
  type OwneyErrorCode = "NOT_CONNECTED" | "NO_ACTIVE_CHAIN" | "WALLET_NO_ACCOUNTS" | "WALLET_ADDRESS_REQUIRED" | "AGENT_NOT_FOUND" | "AGENT_CHAIN_INCOMPATIBLE" | "AGENT_EMPTY_LIST" | "AGENT_DISABLED" | "CHAIN_UNSUPPORTED" | "CHAIN_NO_COMPATIBLE_AGENTS" | "ASSET_UNSUPPORTED" | "ASSET_NO_COMPATIBLE_AGENTS" | "DEPOSIT_AMOUNT_BELOW_MINIMUM" | "DEPOSIT_CALLBACK_REQUIRED" | "DEPOSIT_CALLBACK_INVALID" | "DEPOSIT_NO_PERMITTED_TOKENS" | "WITHDRAW_NO_PERMITTED_TOKENS" | "WITHDRAW_INSUFFICIENT_BALANCE" | "WITHDRAW_ALL_FAILED" | "WITHDRAW_PARTIAL_FAILURE" | "WITHDRAW_FAILED" | "API_ROUTING_ERROR" | "API_ROUTING_FAILED" | "API_SAIL_ERROR" | "API_SAIL_TIMEOUT" | "API_NO_AGENTS" | "SPONSOR_REQUEST_FAILED" | "BALANCE_ALL_FAILED" | "ALLOCATION_ALL_FAILED" | "VALIDATION_INVALID_DAYS";
@@ -468,4 +481,4 @@ type OwneySIWXConfig = {
468
481
  */
469
482
  declare function createOwneySIWX(config: OwneySIWXConfig): SIWXConfig;
470
483
 
471
- export { AccountAgentApy, AccountApyOptions, AgentApy, AgentApyDetails, AgentBalance, AgentChainIncompatibleError, AgentEarnings, AgentHistoryEntry, AgentHistoryPosition, AgentId, AgentNotFoundError, AgentSupportedAsset, AgentSupportedAssets, AgentUserProfile, AgentWithdrawResult, AgentsApyOptions, AllocationAgentApy, 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;
@@ -236,6 +248,9 @@ type AccountApyOptions = {
236
248
  agentId?: AgentId;
237
249
  days: DailyApyDays;
238
250
  };
251
+ type AllocationApyOptions = {
252
+ agentId?: AgentId;
253
+ };
239
254
  type AgentsApyOptions = {
240
255
  agentId?: AgentId;
241
256
  days: DailyApyDays;
@@ -386,14 +401,14 @@ declare class OwneySDK {
386
401
  * preserve the user's scroll position should keep using cursors from the
387
402
  * original snapshot.
388
403
  *
389
- * @param params.agentId - Optional. Agent to query. Omit for all active agents.
390
- * @param params.filters - Optional. Pagination + date filters.
404
+ * @param options.agentId - Optional. Agent to query. Omit for all active agents.
405
+ * @param options.filters - Optional. Pagination + date filters.
391
406
  * - `limit`: max entries per page (default 10)
392
407
  * - `cursor`: opaque cursor returned by a previous call
393
408
  * - `fromDate` / `toDate`: ISO 8601 date strings
394
409
  * @returns {OwneyAgentHistory} `data` (up to `limit` entries), `hasMore`, `nextCursor`.
395
410
  */
396
- getHistory(params?: HistoryOptions): Promise<OwneyAgentHistory>;
411
+ getHistory(options?: HistoryOptions): Promise<OwneyAgentHistory>;
397
412
  /**
398
413
  * Get the user's profile for a specific agent, or all agents.
399
414
  * @param agentId - Optional. Agent to query. Omit for all agents.
@@ -420,9 +435,7 @@ declare class OwneySDK {
420
435
  * @param options.agentId - Optional. Scope to one agent. Omit to aggregate
421
436
  * positions across all active agents.
422
437
  */
423
- getAllocationApy({ agentId, }?: {
424
- agentId?: AgentId;
425
- }): Promise<OwneyAllocationApy>;
438
+ getAllocationApy({ agentId, }?: AllocationApyOptions): Promise<OwneyAllocationApy>;
426
439
  }
427
440
 
428
441
  type OwneyErrorCode = "NOT_CONNECTED" | "NO_ACTIVE_CHAIN" | "WALLET_NO_ACCOUNTS" | "WALLET_ADDRESS_REQUIRED" | "AGENT_NOT_FOUND" | "AGENT_CHAIN_INCOMPATIBLE" | "AGENT_EMPTY_LIST" | "AGENT_DISABLED" | "CHAIN_UNSUPPORTED" | "CHAIN_NO_COMPATIBLE_AGENTS" | "ASSET_UNSUPPORTED" | "ASSET_NO_COMPATIBLE_AGENTS" | "DEPOSIT_AMOUNT_BELOW_MINIMUM" | "DEPOSIT_CALLBACK_REQUIRED" | "DEPOSIT_CALLBACK_INVALID" | "DEPOSIT_NO_PERMITTED_TOKENS" | "WITHDRAW_NO_PERMITTED_TOKENS" | "WITHDRAW_INSUFFICIENT_BALANCE" | "WITHDRAW_ALL_FAILED" | "WITHDRAW_PARTIAL_FAILURE" | "WITHDRAW_FAILED" | "API_ROUTING_ERROR" | "API_ROUTING_FAILED" | "API_SAIL_ERROR" | "API_SAIL_TIMEOUT" | "API_NO_AGENTS" | "SPONSOR_REQUEST_FAILED" | "BALANCE_ALL_FAILED" | "ALLOCATION_ALL_FAILED" | "VALIDATION_INVALID_DAYS";
@@ -468,4 +481,4 @@ type OwneySIWXConfig = {
468
481
  */
469
482
  declare function createOwneySIWX(config: OwneySIWXConfig): SIWXConfig;
470
483
 
471
- export { AccountAgentApy, AccountApyOptions, AgentApy, AgentApyDetails, AgentBalance, AgentChainIncompatibleError, AgentEarnings, AgentHistoryEntry, AgentHistoryPosition, AgentId, AgentNotFoundError, AgentSupportedAsset, AgentSupportedAssets, AgentUserProfile, AgentWithdrawResult, AgentsApyOptions, AllocationAgentApy, 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) {
@@ -1956,17 +1980,17 @@ var OwneySDK = class {
1956
1980
  * preserve the user's scroll position should keep using cursors from the
1957
1981
  * original snapshot.
1958
1982
  *
1959
- * @param params.agentId - Optional. Agent to query. Omit for all active agents.
1960
- * @param params.filters - Optional. Pagination + date filters.
1983
+ * @param options.agentId - Optional. Agent to query. Omit for all active agents.
1984
+ * @param options.filters - Optional. Pagination + date filters.
1961
1985
  * - `limit`: max entries per page (default 10)
1962
1986
  * - `cursor`: opaque cursor returned by a previous call
1963
1987
  * - `fromDate` / `toDate`: ISO 8601 date strings
1964
1988
  * @returns {OwneyAgentHistory} `data` (up to `limit` entries), `hasMore`, `nextCursor`.
1965
1989
  */
1966
- async getHistory(params) {
1990
+ async getHistory(options) {
1967
1991
  const state = this.requireState();
1968
1992
  const chainId = this.requireChainId();
1969
- const { agentId, filters } = params ?? {};
1993
+ const { agentId, filters } = options ?? {};
1970
1994
  if (agentId) {
1971
1995
  return this.getAgent(agentId).getHistory(state, chainId, filters);
1972
1996
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owney/sdk",
3
- "version": "0.6.2-beta.0",
3
+ "version": "0.6.3",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",