@owney/sdk 0.6.2 → 0.6.4-beta.0

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,27 @@ function mapWeightedApyByChain(raw) {
264
264
  }
265
265
  return Object.keys(out).length > 0 ? out : void 0;
266
266
  }
267
- function mapApyHistory(raw) {
267
+ function rawPoolApyForChain(entry, chainId) {
268
+ let weightedSum = 0;
269
+ let totalBalance = 0;
270
+ for (const p of entry.positions ?? []) {
271
+ if (p.chainId !== chainId)
272
+ continue;
273
+ const balance = p.balance ?? 0;
274
+ if (balance <= 0 || typeof p.apy !== "number")
275
+ continue;
276
+ weightedSum += p.apy * balance;
277
+ totalBalance += balance;
278
+ }
279
+ return totalBalance > 0 ? weightedSum / totalBalance : null;
280
+ }
281
+ function mapApyHistory(raw, chainId) {
282
+ const history = Object.entries(raw.history ?? {}).map(([date, entry]) => ({ date, apy: rawPoolApyForChain(entry, chainId) })).filter((p) => p.apy !== null).sort((a, b) => a.date.localeCompare(b.date));
268
283
  return {
269
284
  walletAddress: raw.walletAddress,
270
285
  weightedApyAfterFee: raw.weightedApyAfterFee ? sumTokenValues(raw.weightedApyAfterFee) : void 0,
271
- apyByChainAndAsset: mapWeightedApyByChain(raw.weightedApyAfterFeeByChain)
286
+ apyByChainAndAsset: mapWeightedApyByChain(raw.weightedApyAfterFeeByChain),
287
+ history
272
288
  };
273
289
  }
274
290
  function splitOpportunity(opportunity) {
@@ -844,7 +860,7 @@ var ZyfaiAgent = class {
844
860
  async getAccountApy(state, chainId, days) {
845
861
  const { smartWallet } = await this.resolveSmartWallet(state, chainId);
846
862
  const raw = await this.sdk.getDailyApyHistory(smartWallet, days);
847
- return mapApyHistory(raw);
863
+ return mapApyHistory(raw, chainId);
848
864
  }
849
865
  async getHistory(state, chainId, options) {
850
866
  const { smartWallet, chainId: validChainId } = await this.resolveSmartWallet(state, chainId);
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,27 @@ function mapWeightedApyByChain(raw) {
232
232
  }
233
233
  return Object.keys(out).length > 0 ? out : void 0;
234
234
  }
235
- function mapApyHistory(raw) {
235
+ function rawPoolApyForChain(entry, chainId) {
236
+ let weightedSum = 0;
237
+ let totalBalance = 0;
238
+ for (const p of entry.positions ?? []) {
239
+ if (p.chainId !== chainId)
240
+ continue;
241
+ const balance = p.balance ?? 0;
242
+ if (balance <= 0 || typeof p.apy !== "number")
243
+ continue;
244
+ weightedSum += p.apy * balance;
245
+ totalBalance += balance;
246
+ }
247
+ return totalBalance > 0 ? weightedSum / totalBalance : null;
248
+ }
249
+ function mapApyHistory(raw, chainId) {
250
+ const history = Object.entries(raw.history ?? {}).map(([date, entry]) => ({ date, apy: rawPoolApyForChain(entry, chainId) })).filter((p) => p.apy !== null).sort((a, b) => a.date.localeCompare(b.date));
236
251
  return {
237
252
  walletAddress: raw.walletAddress,
238
253
  weightedApyAfterFee: raw.weightedApyAfterFee ? sumTokenValues(raw.weightedApyAfterFee) : void 0,
239
- apyByChainAndAsset: mapWeightedApyByChain(raw.weightedApyAfterFeeByChain)
254
+ apyByChainAndAsset: mapWeightedApyByChain(raw.weightedApyAfterFeeByChain),
255
+ history
240
256
  };
241
257
  }
242
258
  function splitOpportunity(opportunity) {
@@ -812,7 +828,7 @@ var ZyfaiAgent = class {
812
828
  async getAccountApy(state, chainId, days) {
813
829
  const { smartWallet } = await this.resolveSmartWallet(state, chainId);
814
830
  const raw = await this.sdk.getDailyApyHistory(smartWallet, days);
815
- return mapApyHistory(raw);
831
+ return mapApyHistory(raw, chainId);
816
832
  }
817
833
  async getHistory(state, chainId, options) {
818
834
  const { smartWallet, chainId: validChainId } = await this.resolveSmartWallet(state, chainId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owney/sdk",
3
- "version": "0.6.2",
3
+ "version": "0.6.4-beta.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",