@owney/sdk 0.6.1-beta.0 → 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/README.md CHANGED
@@ -211,9 +211,9 @@ console.log(results.agentResult.zyfai.type); // "full"
211
211
 
212
212
  Get the user's balances for a specific agent, or aggregated across all agents.
213
213
 
214
- | Param | Type | Description |
215
- | --------- | ------------------------------ | ------------------------------------ |
216
- | `agentId` | `"zyfai"` (optional) | Agent to query. Omit for all agents. |
214
+ | Param | Type | Description |
215
+ | --------- | -------------------- | ------------------------------------ |
216
+ | `agentId` | `"zyfai"` (optional) | Agent to query. Omit for all agents. |
217
217
 
218
218
  Returns: `AgentBalance` (single agent) or `OwneyBalances` (all agents)
219
219
 
@@ -221,22 +221,25 @@ Returns: `AgentBalance` (single agent) or `OwneyBalances` (all agents)
221
221
  // Single agent
222
222
  const balance = await sdk.getBalances("zyfai");
223
223
  console.log(balance.totalBalance); // "150.25"
224
+ console.log(balance.totalBalanceAsset); // "usdc" — unit of totalBalance
224
225
  console.log(balance.smartWallet); // "0x..."
225
226
  console.log(balance.tokens); // [{ chain: "BASE", chainId: 8453, asset: "USDC", amount: "150.25" }]
226
227
 
227
228
  // All agents
228
229
  const allBalances = await sdk.getBalances();
229
230
  console.log(allBalances.totalBalance); // "150.25"
231
+ console.log(allBalances.totalBalanceAsset); // "usdc" — unit of totalBalance
230
232
  console.log(allBalances.agentBalances.zyfai.totalBalance); // "150.25"
233
+ console.log(allBalances.agentBalances.zyfai.totalBalanceAsset); // "usdc"
231
234
  ```
232
235
 
233
236
  ### `getEarnings(agentId?)`
234
237
 
235
238
  Get the user's on-chain earnings for a specific agent, or aggregated across all agents.
236
239
 
237
- | Param | Type | Description |
238
- | --------- | ------------------------------ | ------------------------------------ |
239
- | `agentId` | `"zyfai"` (optional) | Agent to query. Omit for all agents. |
240
+ | Param | Type | Description |
241
+ | --------- | -------------------- | ------------------------------------ |
242
+ | `agentId` | `"zyfai"` (optional) | Agent to query. Omit for all agents. |
240
243
 
241
244
  Returns: `AgentEarnings` (single agent) or `OwneyEarnings` (all agents)
242
245
 
@@ -262,10 +265,10 @@ console.log(allEarnings.agentEarnings.zyfai.tokens); // per-chain, per-asset bre
262
265
 
263
266
  Get the weighted APY for the user's account. When querying all agents, the total APY is a balance-weighted average.
264
267
 
265
- | Param | Type | Description |
266
- | --------- | ------------------------------ | ------------------------------------------------ |
267
- | `agentId` | `"zyfai"` (optional) | Agent to query. Omit for balance-weighted total. |
268
- | `days` | `"7D" \| "14D" \| "30D"` | Lookback period |
268
+ | Param | Type | Description |
269
+ | --------- | ------------------------ | ------------------------------------------------ |
270
+ | `agentId` | `"zyfai"` (optional) | Agent to query. Omit for balance-weighted total. |
271
+ | `days` | `"7D" \| "14D" \| "30D"` | Lookback period |
269
272
 
270
273
  Returns: `AccountAgentApy` (single agent) or `OwneyAccountApy` (all agents)
271
274
 
@@ -297,13 +300,13 @@ Results are **cursor-paginated**. The first call (no `cursor`) anchors a stable
297
300
 
298
301
  > **Per-chain filtering:** The Zyfai backend no longer accepts a `chainId` filter directly. The SDK performs a bounded internal drain (up to 5 backend round-trips per logical page) to fill the requested `limit` with entries matching the active chain. This is transparent to callers — the `getHistory` API is unchanged.
299
302
 
300
- | Param | Type | Description |
301
- | ------------------ | ------------------------------ | -------------------------------------------------------- |
302
- | `agentId` | `"zyfai"` (optional) | Agent to query. Omit for all agents. |
303
- | `filters.fromDate` | `string` (optional) | Start date (`YYYY-MM-DD`) |
304
- | `filters.toDate` | `string` (optional) | End date (`YYYY-MM-DD`) |
305
- | `filters.limit` | `number` (optional) | Max entries returned per call. Defaults to `10`. |
306
- | `filters.cursor` | `string` (optional) | Opaque cursor returned by a previous `getHistory` call. |
303
+ | Param | Type | Description |
304
+ | ------------------ | -------------------- | ------------------------------------------------------- |
305
+ | `agentId` | `"zyfai"` (optional) | Agent to query. Omit for all agents. |
306
+ | `filters.fromDate` | `string` (optional) | Start date (`YYYY-MM-DD`) |
307
+ | `filters.toDate` | `string` (optional) | End date (`YYYY-MM-DD`) |
308
+ | `filters.limit` | `number` (optional) | Max entries returned per call. Defaults to `10`. |
309
+ | `filters.cursor` | `string` (optional) | Opaque cursor returned by a previous `getHistory` call. |
307
310
 
308
311
  Returns: `OwneyAgentHistory`
309
312
 
@@ -350,9 +353,9 @@ do {
350
353
 
351
354
  Get the user's profile for a specific agent, or all agents.
352
355
 
353
- | Param | Type | Description |
354
- | --------- | ------------------------------ | ------------------------------------ |
355
- | `agentId` | `"zyfai"` (optional) | Agent to query. Omit for all agents. |
356
+ | Param | Type | Description |
357
+ | --------- | -------------------- | ------------------------------------ |
358
+ | `agentId` | `"zyfai"` (optional) | Agent to query. Omit for all agents. |
356
359
 
357
360
  Returns: `AgentUserProfile` (single agent) or `OwneyUserProfile` (all agents)
358
361
 
@@ -374,16 +377,16 @@ console.log(allProfiles.agentUserProfile.zyfai.smartWallet); // "0x..."
374
377
 
375
378
  Get the agent's average APY performance over a time period. Does not require a wallet connection.
376
379
 
377
- | Param | Type | Description |
378
- | ------------- | ------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
379
- | `agentId` | `"zyfai"` (optional) | Agent to query. Omit for all agents. |
380
- | `days` | `"7D" \| "14D" \| "30D"` | Lookback period |
381
- | `tokenSymbol` | `string` (optional) | Asset symbol (e.g. `"USDC"`). Scopes the upstream request to a specific asset when the agent's backend supports it. |
382
- | `chainId` | `number` (optional) | Chain id. Typically paired with `tokenSymbol` for per-asset+chain APY. |
380
+ | Param | Type | Description |
381
+ | ------------- | ------------------------ | ------------------------------------------------------------------------------------------------------------------- |
382
+ | `agentId` | `"zyfai"` (optional) | Agent to query. Omit for all agents. |
383
+ | `days` | `"7D" \| "14D" \| "30D"` | Lookback period |
384
+ | `tokenSymbol` | `string` (optional) | Asset symbol (e.g. `"USDC"`). Scopes the upstream request to a specific asset when the agent's backend supports it. |
385
+ | `chainId` | `number` (optional) | Chain id. Typically paired with `tokenSymbol` for per-asset+chain APY. |
383
386
 
384
387
  Returns: `AgentApy` (single agent) or `OwneyAgentApy` (all agents)
385
388
 
386
- The agent populates `detailedApys.apyPerAsset` with a per-chain, per-token
389
+ The agent populates `detailedApys.apyPerAsset` with a per-chain, per-token
387
390
  breakdown when available. `tokenSymbol` / `chainId` only affect whether the
388
391
  upstream query is scoped — the breakdown is built from whatever the agent
389
392
  returns.
@@ -518,11 +521,13 @@ interface OwneyToken {
518
521
  interface AgentBalance {
519
522
  smartWallet?: `0x${string}`;
520
523
  totalBalance: string;
524
+ totalBalanceAsset: string; // unit of totalBalance, currently always "usdc"
521
525
  tokens: OwneyToken[];
522
526
  }
523
527
 
524
528
  interface OwneyBalances {
525
529
  totalBalance: string;
530
+ totalBalanceAsset: string; // unit of totalBalance, currently always "usdc"
526
531
  agentBalances: Record<AgentId, AgentBalance>;
527
532
  }
528
533
 
@@ -627,7 +632,7 @@ interface OwneyAgentApy {
627
632
  type DepositCallback = (
628
633
  smartWalletAddress: string,
629
634
  chainId: number,
630
- amount: string
635
+ amount: string,
631
636
  ) => Promise<`0x${string}`> | `0x${string}`;
632
637
  ```
633
638
 
@@ -740,9 +745,9 @@ try {
740
745
 
741
746
  **Recovery:** catch `InvalidHistoryCursorError`, clear your stored cursor, and refetch from page 1.
742
747
 
743
- | Class | `code` | Extends |
744
- | ---------------------------- | ----------------- | ---------- |
745
- | `InvalidHistoryCursorError` | `"invalid_cursor"`| `Error` |
748
+ | Class | `code` | Extends |
749
+ | --------------------------- | ------------------ | ------- |
750
+ | `InvalidHistoryCursorError` | `"invalid_cursor"` | `Error` |
746
751
 
747
752
  ## License
748
753
 
package/dist/index.cjs CHANGED
@@ -210,6 +210,7 @@ function mapBalances(raw, _chainId, smartWallet) {
210
210
  return {
211
211
  smartWallet,
212
212
  totalBalance: String(totalBalance),
213
+ totalBalanceAsset: "usdc",
213
214
  tokens,
214
215
  positions
215
216
  };
@@ -263,10 +264,29 @@ function mapWeightedApyByChain(raw) {
263
264
  }
264
265
  return Object.keys(out).length > 0 ? out : void 0;
265
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
+ }
266
286
  function mapApyHistory(raw) {
267
287
  const history = Object.entries(raw.history ?? {}).map(([date, entry]) => ({
268
288
  date,
269
- apy: sumTokenValues(entry.weighted_apy_after_fee)
289
+ apy: weightedFinalApy(entry)
270
290
  })).sort((a, b) => a.date.localeCompare(b.date));
271
291
  return {
272
292
  walletAddress: raw.walletAddress,
@@ -1880,6 +1900,7 @@ var OwneySDK = class {
1880
1900
  }
1881
1901
  return {
1882
1902
  totalBalance: String(totalBalance),
1903
+ totalBalanceAsset: "usdc",
1883
1904
  agentBalances: results
1884
1905
  };
1885
1906
  }
@@ -1987,17 +2008,17 @@ var OwneySDK = class {
1987
2008
  * preserve the user's scroll position should keep using cursors from the
1988
2009
  * original snapshot.
1989
2010
  *
1990
- * @param params.agentId - Optional. Agent to query. Omit for all active agents.
1991
- * @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.
1992
2013
  * - `limit`: max entries per page (default 10)
1993
2014
  * - `cursor`: opaque cursor returned by a previous call
1994
2015
  * - `fromDate` / `toDate`: ISO 8601 date strings
1995
2016
  * @returns {OwneyAgentHistory} `data` (up to `limit` entries), `hasMore`, `nextCursor`.
1996
2017
  */
1997
- async getHistory(params) {
2018
+ async getHistory(options) {
1998
2019
  const state = this.requireState();
1999
2020
  const chainId = this.requireChainId();
2000
- const { agentId, filters } = params ?? {};
2021
+ const { agentId, filters } = options ?? {};
2001
2022
  if (agentId) {
2002
2023
  return this.getAgent(agentId).getHistory(state, chainId, filters);
2003
2024
  }
package/dist/index.d.cts CHANGED
@@ -61,6 +61,8 @@ interface OwneyPosition {
61
61
  interface AgentBalance {
62
62
  smartWallet?: `0x${string}`;
63
63
  totalBalance: string;
64
+ /** Asset that `totalBalance` is denominated in. Currently always `"usdc"`. */
65
+ totalBalanceAsset: string;
64
66
  tokens: OwneyToken[];
65
67
  /**
66
68
  * Per-protocol/pool positions when the agent's portfolio payload includes
@@ -70,6 +72,8 @@ interface AgentBalance {
70
72
  }
71
73
  interface OwneyBalances {
72
74
  totalBalance: string;
75
+ /** Asset that `totalBalance` is denominated in. Currently always `"usdc"`. */
76
+ totalBalanceAsset: string;
73
77
  agentBalances: Record<AgentId, AgentBalance>;
74
78
  }
75
79
  interface AgentEarnings {
@@ -244,6 +248,9 @@ type AccountApyOptions = {
244
248
  agentId?: AgentId;
245
249
  days: DailyApyDays;
246
250
  };
251
+ type AllocationApyOptions = {
252
+ agentId?: AgentId;
253
+ };
247
254
  type AgentsApyOptions = {
248
255
  agentId?: AgentId;
249
256
  days: DailyApyDays;
@@ -394,14 +401,14 @@ declare class OwneySDK {
394
401
  * preserve the user's scroll position should keep using cursors from the
395
402
  * original snapshot.
396
403
  *
397
- * @param params.agentId - Optional. Agent to query. Omit for all active agents.
398
- * @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.
399
406
  * - `limit`: max entries per page (default 10)
400
407
  * - `cursor`: opaque cursor returned by a previous call
401
408
  * - `fromDate` / `toDate`: ISO 8601 date strings
402
409
  * @returns {OwneyAgentHistory} `data` (up to `limit` entries), `hasMore`, `nextCursor`.
403
410
  */
404
- getHistory(params?: HistoryOptions): Promise<OwneyAgentHistory>;
411
+ getHistory(options?: HistoryOptions): Promise<OwneyAgentHistory>;
405
412
  /**
406
413
  * Get the user's profile for a specific agent, or all agents.
407
414
  * @param agentId - Optional. Agent to query. Omit for all agents.
@@ -428,9 +435,7 @@ declare class OwneySDK {
428
435
  * @param options.agentId - Optional. Scope to one agent. Omit to aggregate
429
436
  * positions across all active agents.
430
437
  */
431
- getAllocationApy({ agentId, }?: {
432
- agentId?: AgentId;
433
- }): Promise<OwneyAllocationApy>;
438
+ getAllocationApy({ agentId, }?: AllocationApyOptions): Promise<OwneyAllocationApy>;
434
439
  }
435
440
 
436
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";
@@ -476,4 +481,4 @@ type OwneySIWXConfig = {
476
481
  */
477
482
  declare function createOwneySIWX(config: OwneySIWXConfig): SIWXConfig;
478
483
 
479
- export { AccountAgentApy, AccountApyOptions, AgentApy, AgentApyDetails, AgentBalance, AgentChainIncompatibleError, AgentEarnings, AgentHistoryEntry, AgentHistoryPosition, AgentId, AgentNotFoundError, AgentSupportedAsset, AgentSupportedAssets, AgentUserProfile, AgentWithdrawResult, AgentsApyOptions, AllocationAgentApy, 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 };
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
@@ -61,6 +61,8 @@ interface OwneyPosition {
61
61
  interface AgentBalance {
62
62
  smartWallet?: `0x${string}`;
63
63
  totalBalance: string;
64
+ /** Asset that `totalBalance` is denominated in. Currently always `"usdc"`. */
65
+ totalBalanceAsset: string;
64
66
  tokens: OwneyToken[];
65
67
  /**
66
68
  * Per-protocol/pool positions when the agent's portfolio payload includes
@@ -70,6 +72,8 @@ interface AgentBalance {
70
72
  }
71
73
  interface OwneyBalances {
72
74
  totalBalance: string;
75
+ /** Asset that `totalBalance` is denominated in. Currently always `"usdc"`. */
76
+ totalBalanceAsset: string;
73
77
  agentBalances: Record<AgentId, AgentBalance>;
74
78
  }
75
79
  interface AgentEarnings {
@@ -244,6 +248,9 @@ type AccountApyOptions = {
244
248
  agentId?: AgentId;
245
249
  days: DailyApyDays;
246
250
  };
251
+ type AllocationApyOptions = {
252
+ agentId?: AgentId;
253
+ };
247
254
  type AgentsApyOptions = {
248
255
  agentId?: AgentId;
249
256
  days: DailyApyDays;
@@ -394,14 +401,14 @@ declare class OwneySDK {
394
401
  * preserve the user's scroll position should keep using cursors from the
395
402
  * original snapshot.
396
403
  *
397
- * @param params.agentId - Optional. Agent to query. Omit for all active agents.
398
- * @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.
399
406
  * - `limit`: max entries per page (default 10)
400
407
  * - `cursor`: opaque cursor returned by a previous call
401
408
  * - `fromDate` / `toDate`: ISO 8601 date strings
402
409
  * @returns {OwneyAgentHistory} `data` (up to `limit` entries), `hasMore`, `nextCursor`.
403
410
  */
404
- getHistory(params?: HistoryOptions): Promise<OwneyAgentHistory>;
411
+ getHistory(options?: HistoryOptions): Promise<OwneyAgentHistory>;
405
412
  /**
406
413
  * Get the user's profile for a specific agent, or all agents.
407
414
  * @param agentId - Optional. Agent to query. Omit for all agents.
@@ -428,9 +435,7 @@ declare class OwneySDK {
428
435
  * @param options.agentId - Optional. Scope to one agent. Omit to aggregate
429
436
  * positions across all active agents.
430
437
  */
431
- getAllocationApy({ agentId, }?: {
432
- agentId?: AgentId;
433
- }): Promise<OwneyAllocationApy>;
438
+ getAllocationApy({ agentId, }?: AllocationApyOptions): Promise<OwneyAllocationApy>;
434
439
  }
435
440
 
436
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";
@@ -476,4 +481,4 @@ type OwneySIWXConfig = {
476
481
  */
477
482
  declare function createOwneySIWX(config: OwneySIWXConfig): SIWXConfig;
478
483
 
479
- export { AccountAgentApy, AccountApyOptions, AgentApy, AgentApyDetails, AgentBalance, AgentChainIncompatibleError, AgentEarnings, AgentHistoryEntry, AgentHistoryPosition, AgentId, AgentNotFoundError, AgentSupportedAsset, AgentSupportedAssets, AgentUserProfile, AgentWithdrawResult, AgentsApyOptions, AllocationAgentApy, 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 };
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
@@ -178,6 +178,7 @@ function mapBalances(raw, _chainId, smartWallet) {
178
178
  return {
179
179
  smartWallet,
180
180
  totalBalance: String(totalBalance),
181
+ totalBalanceAsset: "usdc",
181
182
  tokens,
182
183
  positions
183
184
  };
@@ -231,10 +232,29 @@ function mapWeightedApyByChain(raw) {
231
232
  }
232
233
  return Object.keys(out).length > 0 ? out : void 0;
233
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
+ }
234
254
  function mapApyHistory(raw) {
235
255
  const history = Object.entries(raw.history ?? {}).map(([date, entry]) => ({
236
256
  date,
237
- apy: sumTokenValues(entry.weighted_apy_after_fee)
257
+ apy: weightedFinalApy(entry)
238
258
  })).sort((a, b) => a.date.localeCompare(b.date));
239
259
  return {
240
260
  walletAddress: raw.walletAddress,
@@ -1852,6 +1872,7 @@ var OwneySDK = class {
1852
1872
  }
1853
1873
  return {
1854
1874
  totalBalance: String(totalBalance),
1875
+ totalBalanceAsset: "usdc",
1855
1876
  agentBalances: results
1856
1877
  };
1857
1878
  }
@@ -1959,17 +1980,17 @@ var OwneySDK = class {
1959
1980
  * preserve the user's scroll position should keep using cursors from the
1960
1981
  * original snapshot.
1961
1982
  *
1962
- * @param params.agentId - Optional. Agent to query. Omit for all active agents.
1963
- * @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.
1964
1985
  * - `limit`: max entries per page (default 10)
1965
1986
  * - `cursor`: opaque cursor returned by a previous call
1966
1987
  * - `fromDate` / `toDate`: ISO 8601 date strings
1967
1988
  * @returns {OwneyAgentHistory} `data` (up to `limit` entries), `hasMore`, `nextCursor`.
1968
1989
  */
1969
- async getHistory(params) {
1990
+ async getHistory(options) {
1970
1991
  const state = this.requireState();
1971
1992
  const chainId = this.requireChainId();
1972
- const { agentId, filters } = params ?? {};
1993
+ const { agentId, filters } = options ?? {};
1973
1994
  if (agentId) {
1974
1995
  return this.getAgent(agentId).getHistory(state, chainId, filters);
1975
1996
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owney/sdk",
3
- "version": "0.6.1-beta.0",
3
+ "version": "0.6.1-beta.2",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",