@owney/sdk 0.3.0-beta.0 → 0.3.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/README.md CHANGED
@@ -280,12 +280,18 @@ console.log(apy.walletAddress); // "0x..."
280
280
  console.log(apy.weightedApyAfterFee); // 5.2
281
281
  // Per chain + token breakdown, when the agent reports it
282
282
  console.log(apy.weightedApyAfterFeeDetails?.apyPerAsset[8453]?.USDC); // 5.4
283
+ // Same per-(chain, asset) breakdown surfaced under a unified key
284
+ console.log(apy.apyByChainAndAsset?.[8453]?.USDC); // 5.4
283
285
 
284
286
  // All agents (balance-weighted)
285
287
  const allApy = await sdk.getAccountApy({ days: "30D" });
286
288
  console.log(allApy.totalApy); // "5.6"
287
289
  console.log(allApy.agentApy.zyfai.weightedApyAfterFee); // 6.0
288
290
  console.log(allApy.agentApy.sail.weightedApyAfterFee); // 4.0
291
+ // Per (chain, asset), balance-weighted across all agents.
292
+ // Cells with 0/missing APY for a given agent are excluded from that cell.
293
+ console.log(allApy.apyByChainAndAsset[8453]?.USDC); // 5.3
294
+ console.log(allApy.apyByChainAndAsset[42161]?.USDT); // 4.7
289
295
  ```
290
296
 
291
297
  ### `getHistory({ agentId?, filters? })`
@@ -560,15 +566,21 @@ interface OwneyEarnings {
560
566
  agentEarnings: Record<AgentId, AgentEarnings>;
561
567
  }
562
568
 
569
+ type ApyByChainAndAsset = Partial<
570
+ Record<OwneySupportedChainId, Partial<Record<OwneySupportedTokens, number>>>
571
+ >;
572
+
563
573
  interface AccountAgentApy {
564
574
  walletAddress: string;
565
575
  weightedApyAfterFee?: number;
566
576
  weightedApyAfterFeeDetails?: AgentApyDetails;
577
+ apyByChainAndAsset?: ApyByChainAndAsset;
567
578
  }
568
579
 
569
580
  interface OwneyAccountApy {
570
581
  totalApy: string;
571
582
  agentApy: Record<AgentId, AccountAgentApy>;
583
+ apyByChainAndAsset: ApyByChainAndAsset;
572
584
  }
573
585
 
574
586
  type HistoryAction = "Rebalance" | "Deposit" | "Top up" | "Withdraw" | "Earned";
package/dist/index.cjs CHANGED
@@ -36,6 +36,7 @@ var P_SUPPORTED_CHAINS = {
36
36
  chainIds: [8453, 42161],
37
37
  chains: ["BASE", "ARBITRUM"]
38
38
  };
39
+ var SUPPORTED_TOKENS = ["USDC", "USDT"];
39
40
  var SUPPORTED_CHAIN_IDS = P_SUPPORTED_CHAINS.chainIds;
40
41
  var SUPPORTED_CHAINS = P_SUPPORTED_CHAINS.chains;
41
42
  var SupportedAssets = [
@@ -209,10 +210,31 @@ function mapEarnings(raw, smartWallet) {
209
210
  tokens
210
211
  };
211
212
  }
213
+ function mapWeightedApyByChain(raw) {
214
+ if (!raw)
215
+ return void 0;
216
+ const out = {};
217
+ for (const [chainKey, tokenApy] of Object.entries(raw)) {
218
+ const chainId = Number(chainKey);
219
+ if (!SUPPORTED_CHAIN_IDS.includes(chainId))
220
+ continue;
221
+ const perAsset = {};
222
+ for (const [symbol, apy] of Object.entries(tokenApy)) {
223
+ const token = symbol;
224
+ if (!SUPPORTED_TOKENS.includes(token))
225
+ continue;
226
+ perAsset[token] = apy;
227
+ }
228
+ if (Object.keys(perAsset).length > 0)
229
+ out[chainId] = perAsset;
230
+ }
231
+ return Object.keys(out).length > 0 ? out : void 0;
232
+ }
212
233
  function mapApyHistory(raw) {
213
234
  return {
214
235
  walletAddress: raw.walletAddress,
215
- weightedApyAfterFee: raw.weightedApyAfterFee ? sumTokenValues(raw.weightedApyAfterFee) : void 0
236
+ weightedApyAfterFee: raw.weightedApyAfterFee ? sumTokenValues(raw.weightedApyAfterFee) : void 0,
237
+ apyByChainAndAsset: mapWeightedApyByChain(raw.weightedApyAfterFeeByChain)
216
238
  };
217
239
  }
218
240
  function mapHistory(raw, chainId) {
@@ -641,6 +663,46 @@ function sumWithdrawnAmount(results) {
641
663
  return Object.values(results).reduce((sum, r) => sum + BigInt(r.amount), 0n);
642
664
  }
643
665
 
666
+ // src/lib/helpers/account-apy-helper.ts
667
+ function aggregateApyByChainAndAsset(agentApys, agentBalances) {
668
+ const sums = {};
669
+ const weights = {};
670
+ for (const id of Object.keys(agentApys)) {
671
+ const cells = agentApys[id].apyByChainAndAsset;
672
+ const balance = agentBalances[id] ?? 0;
673
+ if (!cells || balance <= 0)
674
+ continue;
675
+ for (const [chainKey, perAsset] of Object.entries(cells)) {
676
+ if (!perAsset)
677
+ continue;
678
+ const chainId = Number(chainKey);
679
+ for (const [asset, apyValue] of Object.entries(perAsset)) {
680
+ const apy = Number(apyValue ?? 0);
681
+ if (apy === 0)
682
+ continue;
683
+ sums[chainId] ??= {};
684
+ weights[chainId] ??= {};
685
+ sums[chainId][asset] = (sums[chainId][asset] ?? 0) + apy * balance;
686
+ weights[chainId][asset] = (weights[chainId][asset] ?? 0) + balance;
687
+ }
688
+ }
689
+ }
690
+ const out = {};
691
+ for (const chainKey of Object.keys(sums)) {
692
+ const chainId = Number(chainKey);
693
+ const perAssetOut = {};
694
+ for (const asset of Object.keys(sums[chainId])) {
695
+ const w = weights[chainId][asset];
696
+ if (w > 0)
697
+ perAssetOut[asset] = sums[chainId][asset] / w;
698
+ }
699
+ if (Object.keys(perAssetOut).length > 0) {
700
+ out[chainId] = perAssetOut;
701
+ }
702
+ }
703
+ return out;
704
+ }
705
+
644
706
  // src/client.ts
645
707
  var OwneySDK = class {
646
708
  agents = /* @__PURE__ */ new Map();
@@ -1269,9 +1331,11 @@ var OwneySDK = class {
1269
1331
  totalApy += agentApy * weight;
1270
1332
  }
1271
1333
  }
1334
+ const apyByChainAndAsset = aggregateApyByChainAndAsset(results, balances);
1272
1335
  return {
1273
1336
  totalApy: String(totalApy),
1274
- agentApy: results
1337
+ agentApy: results,
1338
+ apyByChainAndAsset
1275
1339
  };
1276
1340
  }
1277
1341
  /**
package/dist/index.d.cts CHANGED
@@ -139,14 +139,17 @@ interface OwneyEarnings {
139
139
  totalEarnings: string;
140
140
  agentEarnings: Record<AgentId, AgentEarnings>;
141
141
  }
142
+ type ApyByChainAndAsset = Partial<Record<OwneySupportedChainId, Partial<Record<OwneySupportedTokens, number>>>>;
142
143
  interface AccountAgentApy {
143
144
  walletAddress: string;
144
145
  weightedApyAfterFee?: number;
145
146
  weightedApyAfterFeeDetails?: AgentApyDetails;
147
+ apyByChainAndAsset?: ApyByChainAndAsset;
146
148
  }
147
149
  interface OwneyAccountApy {
148
150
  totalApy: string;
149
151
  agentApy: Record<AgentId, AccountAgentApy>;
152
+ apyByChainAndAsset: ApyByChainAndAsset;
150
153
  }
151
154
  type HistoryAction = "Rebalance" | "Deposit" | "Top up" | "Withdraw" | "Earned";
152
155
  interface HistoryTransaction {
@@ -378,4 +381,4 @@ declare class AgentChainIncompatibleError extends OwneyError {
378
381
  }>, connectedChainId: number);
379
382
  }
380
383
 
381
- export { AccountAgentApy, AccountApyOptions, AgentApy, AgentApyDetails, AgentBalance, AgentChainIncompatibleError, AgentEarnings, AgentHistoryEntry, AgentId, AgentNotFoundError, AgentSupportedAsset, AgentSupportedAssets, AgentUserProfile, AgentWithdrawResult, AgentsApyOptions, Asset, ConnectionState, DailyApyDays, DepositCallback, DepositOptions, HistoryAction, HistoryFilters, HistoryOptions, HistoryTransaction, IAgent, NotConnectedError, OwneyAccountApy, OwneyAgentAllocation, OwneyAgentApy, OwneyAgentHistory, OwneyAgentStatus, OwneyBalances, OwneyDepositResult, OwneyEarnings, OwneyError, OwneyErrorCode, OwneyMultiDepositResult, OwneySDK, OwneySDKConfig, OwneySupportedChainId, OwneySupportedChains, OwneySupportedTokens, OwneyToken, OwneyUserProfile, OwneyWithdrawResult, RebalanceLog, WithdrawOptions };
384
+ export { AccountAgentApy, AccountApyOptions, AgentApy, AgentApyDetails, AgentBalance, AgentChainIncompatibleError, AgentEarnings, AgentHistoryEntry, AgentId, AgentNotFoundError, AgentSupportedAsset, AgentSupportedAssets, AgentUserProfile, AgentWithdrawResult, AgentsApyOptions, ApyByChainAndAsset, Asset, ConnectionState, DailyApyDays, DepositCallback, DepositOptions, HistoryAction, HistoryFilters, HistoryOptions, HistoryTransaction, IAgent, NotConnectedError, OwneyAccountApy, OwneyAgentAllocation, OwneyAgentApy, OwneyAgentHistory, OwneyAgentStatus, OwneyBalances, OwneyDepositResult, OwneyEarnings, OwneyError, OwneyErrorCode, OwneyMultiDepositResult, OwneySDK, OwneySDKConfig, OwneySupportedChainId, OwneySupportedChains, OwneySupportedTokens, OwneyToken, OwneyUserProfile, OwneyWithdrawResult, RebalanceLog, WithdrawOptions };
package/dist/index.d.ts CHANGED
@@ -139,14 +139,17 @@ interface OwneyEarnings {
139
139
  totalEarnings: string;
140
140
  agentEarnings: Record<AgentId, AgentEarnings>;
141
141
  }
142
+ type ApyByChainAndAsset = Partial<Record<OwneySupportedChainId, Partial<Record<OwneySupportedTokens, number>>>>;
142
143
  interface AccountAgentApy {
143
144
  walletAddress: string;
144
145
  weightedApyAfterFee?: number;
145
146
  weightedApyAfterFeeDetails?: AgentApyDetails;
147
+ apyByChainAndAsset?: ApyByChainAndAsset;
146
148
  }
147
149
  interface OwneyAccountApy {
148
150
  totalApy: string;
149
151
  agentApy: Record<AgentId, AccountAgentApy>;
152
+ apyByChainAndAsset: ApyByChainAndAsset;
150
153
  }
151
154
  type HistoryAction = "Rebalance" | "Deposit" | "Top up" | "Withdraw" | "Earned";
152
155
  interface HistoryTransaction {
@@ -378,4 +381,4 @@ declare class AgentChainIncompatibleError extends OwneyError {
378
381
  }>, connectedChainId: number);
379
382
  }
380
383
 
381
- export { AccountAgentApy, AccountApyOptions, AgentApy, AgentApyDetails, AgentBalance, AgentChainIncompatibleError, AgentEarnings, AgentHistoryEntry, AgentId, AgentNotFoundError, AgentSupportedAsset, AgentSupportedAssets, AgentUserProfile, AgentWithdrawResult, AgentsApyOptions, Asset, ConnectionState, DailyApyDays, DepositCallback, DepositOptions, HistoryAction, HistoryFilters, HistoryOptions, HistoryTransaction, IAgent, NotConnectedError, OwneyAccountApy, OwneyAgentAllocation, OwneyAgentApy, OwneyAgentHistory, OwneyAgentStatus, OwneyBalances, OwneyDepositResult, OwneyEarnings, OwneyError, OwneyErrorCode, OwneyMultiDepositResult, OwneySDK, OwneySDKConfig, OwneySupportedChainId, OwneySupportedChains, OwneySupportedTokens, OwneyToken, OwneyUserProfile, OwneyWithdrawResult, RebalanceLog, WithdrawOptions };
384
+ export { AccountAgentApy, AccountApyOptions, AgentApy, AgentApyDetails, AgentBalance, AgentChainIncompatibleError, AgentEarnings, AgentHistoryEntry, AgentId, AgentNotFoundError, AgentSupportedAsset, AgentSupportedAssets, AgentUserProfile, AgentWithdrawResult, AgentsApyOptions, ApyByChainAndAsset, Asset, ConnectionState, DailyApyDays, DepositCallback, DepositOptions, HistoryAction, HistoryFilters, HistoryOptions, HistoryTransaction, IAgent, NotConnectedError, OwneyAccountApy, OwneyAgentAllocation, OwneyAgentApy, OwneyAgentHistory, OwneyAgentStatus, OwneyBalances, OwneyDepositResult, OwneyEarnings, OwneyError, OwneyErrorCode, OwneyMultiDepositResult, OwneySDK, OwneySDKConfig, OwneySupportedChainId, OwneySupportedChains, OwneySupportedTokens, OwneyToken, OwneyUserProfile, OwneyWithdrawResult, RebalanceLog, WithdrawOptions };
package/dist/index.js CHANGED
@@ -6,6 +6,7 @@ var P_SUPPORTED_CHAINS = {
6
6
  chainIds: [8453, 42161],
7
7
  chains: ["BASE", "ARBITRUM"]
8
8
  };
9
+ var SUPPORTED_TOKENS = ["USDC", "USDT"];
9
10
  var SUPPORTED_CHAIN_IDS = P_SUPPORTED_CHAINS.chainIds;
10
11
  var SUPPORTED_CHAINS = P_SUPPORTED_CHAINS.chains;
11
12
  var SupportedAssets = [
@@ -179,10 +180,31 @@ function mapEarnings(raw, smartWallet) {
179
180
  tokens
180
181
  };
181
182
  }
183
+ function mapWeightedApyByChain(raw) {
184
+ if (!raw)
185
+ return void 0;
186
+ const out = {};
187
+ for (const [chainKey, tokenApy] of Object.entries(raw)) {
188
+ const chainId = Number(chainKey);
189
+ if (!SUPPORTED_CHAIN_IDS.includes(chainId))
190
+ continue;
191
+ const perAsset = {};
192
+ for (const [symbol, apy] of Object.entries(tokenApy)) {
193
+ const token = symbol;
194
+ if (!SUPPORTED_TOKENS.includes(token))
195
+ continue;
196
+ perAsset[token] = apy;
197
+ }
198
+ if (Object.keys(perAsset).length > 0)
199
+ out[chainId] = perAsset;
200
+ }
201
+ return Object.keys(out).length > 0 ? out : void 0;
202
+ }
182
203
  function mapApyHistory(raw) {
183
204
  return {
184
205
  walletAddress: raw.walletAddress,
185
- weightedApyAfterFee: raw.weightedApyAfterFee ? sumTokenValues(raw.weightedApyAfterFee) : void 0
206
+ weightedApyAfterFee: raw.weightedApyAfterFee ? sumTokenValues(raw.weightedApyAfterFee) : void 0,
207
+ apyByChainAndAsset: mapWeightedApyByChain(raw.weightedApyAfterFeeByChain)
186
208
  };
187
209
  }
188
210
  function mapHistory(raw, chainId) {
@@ -611,6 +633,46 @@ function sumWithdrawnAmount(results) {
611
633
  return Object.values(results).reduce((sum, r) => sum + BigInt(r.amount), 0n);
612
634
  }
613
635
 
636
+ // src/lib/helpers/account-apy-helper.ts
637
+ function aggregateApyByChainAndAsset(agentApys, agentBalances) {
638
+ const sums = {};
639
+ const weights = {};
640
+ for (const id of Object.keys(agentApys)) {
641
+ const cells = agentApys[id].apyByChainAndAsset;
642
+ const balance = agentBalances[id] ?? 0;
643
+ if (!cells || balance <= 0)
644
+ continue;
645
+ for (const [chainKey, perAsset] of Object.entries(cells)) {
646
+ if (!perAsset)
647
+ continue;
648
+ const chainId = Number(chainKey);
649
+ for (const [asset, apyValue] of Object.entries(perAsset)) {
650
+ const apy = Number(apyValue ?? 0);
651
+ if (apy === 0)
652
+ continue;
653
+ sums[chainId] ??= {};
654
+ weights[chainId] ??= {};
655
+ sums[chainId][asset] = (sums[chainId][asset] ?? 0) + apy * balance;
656
+ weights[chainId][asset] = (weights[chainId][asset] ?? 0) + balance;
657
+ }
658
+ }
659
+ }
660
+ const out = {};
661
+ for (const chainKey of Object.keys(sums)) {
662
+ const chainId = Number(chainKey);
663
+ const perAssetOut = {};
664
+ for (const asset of Object.keys(sums[chainId])) {
665
+ const w = weights[chainId][asset];
666
+ if (w > 0)
667
+ perAssetOut[asset] = sums[chainId][asset] / w;
668
+ }
669
+ if (Object.keys(perAssetOut).length > 0) {
670
+ out[chainId] = perAssetOut;
671
+ }
672
+ }
673
+ return out;
674
+ }
675
+
614
676
  // src/client.ts
615
677
  var OwneySDK = class {
616
678
  agents = /* @__PURE__ */ new Map();
@@ -1239,9 +1301,11 @@ var OwneySDK = class {
1239
1301
  totalApy += agentApy * weight;
1240
1302
  }
1241
1303
  }
1304
+ const apyByChainAndAsset = aggregateApyByChainAndAsset(results, balances);
1242
1305
  return {
1243
1306
  totalApy: String(totalApy),
1244
- agentApy: results
1307
+ agentApy: results,
1308
+ apyByChainAndAsset
1245
1309
  };
1246
1310
  }
1247
1311
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owney/sdk",
3
- "version": "0.3.0-beta.0",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",
@@ -22,7 +22,7 @@
22
22
  "test:watch": "vitest"
23
23
  },
24
24
  "dependencies": {
25
- "@zyfai/sdk": "^0.2.33",
25
+ "@zyfai/sdk": "^0.2.34",
26
26
  "viem": "^2.48.1"
27
27
  },
28
28
  "devDependencies": {