@owney/sdk 0.6.0-beta.0 → 0.6.0-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/dist/index.d.cts CHANGED
@@ -14,97 +14,13 @@ interface ConnectionState {
14
14
  walletAddress: `0x${string}`;
15
15
  chainId: number | null;
16
16
  }
17
- declare const SUPPORTED_TOKENS: readonly ["USDC", "USDT"];
17
+ declare const SUPPORTED_TOKENS: readonly ["USDC", "USDT", "WETH"];
18
18
  declare const SUPPORTED_CHAIN_IDS: readonly [8453, 42161];
19
19
  declare const SUPPORTED_CHAINS: readonly ["BASE", "ARBITRUM"];
20
20
  type OwneySupportedChainId = (typeof SUPPORTED_CHAIN_IDS)[number];
21
21
  type OwneySupportedChains = (typeof SUPPORTED_CHAINS)[number];
22
22
  type OwneySupportedTokens = (typeof SUPPORTED_TOKENS)[number];
23
23
 
24
- type DepositCallback = (smartWalletAddress: string, chainId: number, amount: string) => Promise<`0x${string}`> | `0x${string}`;
25
- interface IAgent {
26
- readonly id: string;
27
- readonly supportedChainIds: readonly OwneySupportedChainId[];
28
- readonly supportedAssets: readonly AgentSupportedAssets[];
29
- disconnect(): Promise<void>;
30
- activateAgent(state: ConnectionState, chainId: number): Promise<void>;
31
- deposit(state: ConnectionState, chainId: number, amount: string, depositCallback?: DepositCallback): Promise<OwneyDepositResult>;
32
- withdraw(state: ConnectionState, chainId: number, token: OwneySupportedTokens, amount?: string): Promise<AgentWithdrawResult>;
33
- getBalances(state: ConnectionState, chainId: number): Promise<AgentBalance>;
34
- getEarnings(state: ConnectionState, chainId: number): Promise<AgentEarnings>;
35
- getAccountApy(state: ConnectionState, chainId: number, days: DailyApyDays): Promise<AccountAgentApy>;
36
- getHistory(state: ConnectionState, chainId: number, options?: HistoryFilters): Promise<OwneyAgentHistory>;
37
- pause(state: ConnectionState, chainId: number): Promise<OwneyAgentStatus>;
38
- resume(state: ConnectionState, chainId: number): Promise<OwneyAgentStatus>;
39
- getUserProfile(state: ConnectionState, chainId: number): Promise<AgentUserProfile>;
40
- getAgentApy(days: DailyApyDays, options?: AgentApyOptions): Promise<AgentApy>;
41
- }
42
- /**
43
- * Optional filters for per-agent APY lookups.
44
- * - `tokenSymbol` / `chainId` scope the APY to a specific asset+chain when
45
- * the underlying provider supports it (Zyfai). Agents whose backends do
46
- * not yet support per-asset APY will ignore these options.
47
- */
48
- type AgentApyOptions = {
49
- tokenSymbol?: string;
50
- chainId?: number;
51
- };
52
-
53
- type AgentId = "zyfai" | "sail";
54
- type Asset = string;
55
- type AgentSupportedAsset = {
56
- readonly symbol: string;
57
- readonly minDepositAmount: string;
58
- };
59
- type AgentSupportedAssets = {
60
- readonly chainId: number;
61
- readonly chain?: string;
62
- readonly assets: readonly AgentSupportedAsset[];
63
- };
64
- type DailyApyDays = "7D" | "14D" | "30D";
65
- type HistoryFilters = {
66
- fromDate?: string;
67
- toDate?: string;
68
- /** Max entries returned per call. Defaults to 10. */
69
- limit?: number;
70
- /** Opaque cursor returned by a previous getHistory call. */
71
- cursor?: string;
72
- };
73
- type HistoryOptions = {
74
- agentId?: AgentId;
75
- filters?: HistoryFilters;
76
- };
77
- type WithdrawOptions = {
78
- asset: Asset;
79
- amount?: string;
80
- agentId?: AgentId;
81
- };
82
- type AccountApyOptions = {
83
- agentId?: AgentId;
84
- days: DailyApyDays;
85
- };
86
- type AgentsApyOptions = {
87
- agentId?: AgentId;
88
- days: DailyApyDays;
89
- /**
90
- * Optional asset symbol (e.g. "USDC", "WETH") to scope the APY to a
91
- * specific asset+chain. Ignored by agents whose backends do not yet
92
- * support per-asset APY.
93
- */
94
- tokenSymbol?: string;
95
- /**
96
- * Optional chain id for per-asset APY lookups. Typically paired with
97
- * `tokenSymbol`.
98
- */
99
- chainId?: number;
100
- };
101
- type DepositOptions = {
102
- amount: string;
103
- asset: Asset;
104
- depositCallback: DepositCallback;
105
- agentId?: AgentId;
106
- };
107
-
108
24
  interface OwneyDepositResult {
109
25
  txHash: string;
110
26
  smartWallet: string;
@@ -128,10 +44,29 @@ interface OwneyToken {
128
44
  asset: OwneySupportedTokens;
129
45
  amount: string;
130
46
  }
47
+ interface OwneyPosition {
48
+ /** Raw chain identifier as returned by the agent (chain id or name); not coerced. */
49
+ chain: string;
50
+ protocol: string;
51
+ protocolId?: string;
52
+ pool?: string;
53
+ asset: string;
54
+ amount: string;
55
+ apy?: number;
56
+ tvl?: number;
57
+ /** Pool liquidity. Prepared slot — Zyfai will add this to its portfolio
58
+ * response later; undefined until then. */
59
+ liquidity?: number;
60
+ }
131
61
  interface AgentBalance {
132
62
  smartWallet?: `0x${string}`;
133
63
  totalBalance: string;
134
64
  tokens: OwneyToken[];
65
+ /**
66
+ * Per-protocol/pool positions when the agent's portfolio payload includes
67
+ * them (zyfai). Omitted for agents that don't expose positions (sail).
68
+ */
69
+ positions?: OwneyPosition[];
135
70
  }
136
71
  interface OwneyBalances {
137
72
  totalBalance: string;
@@ -158,6 +93,17 @@ interface OwneyAccountApy {
158
93
  agentApy: Record<AgentId, AccountAgentApy>;
159
94
  apyByChainAndAsset: ApyByChainAndAsset;
160
95
  }
96
+ interface AllocationAgentApy {
97
+ /** Account-wide weighted APY for this agent, as a decimal string. */
98
+ totalApy: string;
99
+ apyByChainAndAsset: ApyByChainAndAsset;
100
+ }
101
+ interface OwneyAllocationApy {
102
+ /** Account-wide weighted APY across all active agents, as a decimal string. */
103
+ totalApy: string;
104
+ apyByChainAndAsset: ApyByChainAndAsset;
105
+ agentApy: Record<AgentId, AllocationAgentApy>;
106
+ }
161
107
  type HistoryAction = "Rebalance" | "Deposit" | "Top up" | "Withdraw" | "Earned";
162
108
  interface HistoryTransaction {
163
109
  txHashes: string[];
@@ -168,6 +114,15 @@ interface HistoryTransaction {
168
114
  interface RebalanceLog {
169
115
  fromProtocol: string;
170
116
  toProtocol: string;
117
+ /**
118
+ * Pool/vault sub-label for the source position (e.g. "USDC Core"), when the
119
+ * agent exposes one. Lets consumers disambiguate moves within the same
120
+ * protocol ("Morpho · USDC Core → Morpho · Spark USDC"). Absent when the
121
+ * agent only reports a bare protocol name.
122
+ */
123
+ fromPool?: string;
124
+ /** Pool/vault sub-label for the destination position. See {@link fromPool}. */
125
+ toPool?: string;
171
126
  tokenSymbol: string;
172
127
  amount: string;
173
128
  status: "success" | "failed";
@@ -195,11 +150,6 @@ interface OwneyAgentHistory {
195
150
  /** Opaque cursor for the next page. Present iff `hasMore === true`. */
196
151
  nextCursor?: string;
197
152
  }
198
- interface OwneyAgentStatus {
199
- success: boolean;
200
- strategy?: string;
201
- protocols?: string[];
202
- }
203
153
  interface AgentUserProfile {
204
154
  address: string;
205
155
  smartWallet: string;
@@ -223,8 +173,92 @@ interface OwneyAgentApy {
223
173
  }
224
174
  interface OwneyAgentAllocation {
225
175
  agentAllocation: Record<AgentId, number>;
176
+ /** Per-agent positions. Empty array for agents that don't expose positions. */
177
+ agentPositions: Record<AgentId, OwneyPosition[]>;
226
178
  }
227
179
 
180
+ type DepositCallback = (smartWalletAddress: string, chainId: number, amount: string) => Promise<`0x${string}`> | `0x${string}`;
181
+ interface IAgent {
182
+ readonly id: string;
183
+ readonly supportedChainIds: readonly OwneySupportedChainId[];
184
+ readonly supportedAssets: readonly AgentSupportedAssets[];
185
+ disconnect(): Promise<void>;
186
+ activateAgent(state: ConnectionState, chainId: number): Promise<void>;
187
+ deposit(state: ConnectionState, chainId: number, amount: string, asset: OwneySupportedTokens, depositCallback?: DepositCallback): Promise<OwneyDepositResult>;
188
+ withdraw(state: ConnectionState, chainId: number, token: OwneySupportedTokens, amount?: string): Promise<AgentWithdrawResult>;
189
+ getBalances(state: ConnectionState, chainId: number): Promise<AgentBalance>;
190
+ getEarnings(state: ConnectionState, chainId: number): Promise<AgentEarnings>;
191
+ getAccountApy(state: ConnectionState, chainId: number, days: DailyApyDays): Promise<AccountAgentApy>;
192
+ getHistory(state: ConnectionState, chainId: number, options?: HistoryFilters): Promise<OwneyAgentHistory>;
193
+ getUserProfile(state: ConnectionState, chainId: number): Promise<AgentUserProfile>;
194
+ getAgentApy(days: DailyApyDays, options?: AgentApyOptions): Promise<AgentApy>;
195
+ }
196
+ /**
197
+ * Optional filters for per-agent APY lookups.
198
+ * - `tokenSymbol` / `chainId` scope the APY to a specific asset+chain when
199
+ * the underlying provider supports it (Zyfai). Agents whose backends do
200
+ * not yet support per-asset APY will ignore these options.
201
+ */
202
+ type AgentApyOptions = {
203
+ tokenSymbol?: string;
204
+ chainId?: number;
205
+ };
206
+
207
+ type AgentId = "zyfai" | "sail";
208
+ type Asset = string;
209
+ type AgentSupportedAsset = {
210
+ readonly symbol: string;
211
+ readonly minDepositAmount: string;
212
+ };
213
+ type AgentSupportedAssets = {
214
+ readonly chainId: number;
215
+ readonly chain?: string;
216
+ readonly assets: readonly AgentSupportedAsset[];
217
+ };
218
+ type DailyApyDays = "7D" | "14D" | "30D";
219
+ type HistoryFilters = {
220
+ fromDate?: string;
221
+ toDate?: string;
222
+ /** Max entries returned per call. Defaults to 10. */
223
+ limit?: number;
224
+ /** Opaque cursor returned by a previous getHistory call. */
225
+ cursor?: string;
226
+ };
227
+ type HistoryOptions = {
228
+ agentId?: AgentId;
229
+ filters?: HistoryFilters;
230
+ };
231
+ type WithdrawOptions = {
232
+ asset: Asset;
233
+ amount?: string;
234
+ agentId?: AgentId;
235
+ };
236
+ type AccountApyOptions = {
237
+ agentId?: AgentId;
238
+ days: DailyApyDays;
239
+ };
240
+ type AgentsApyOptions = {
241
+ agentId?: AgentId;
242
+ days: DailyApyDays;
243
+ /**
244
+ * Optional asset symbol (e.g. "USDC", "WETH") to scope the APY to a
245
+ * specific asset+chain. Ignored by agents whose backends do not yet
246
+ * support per-asset APY.
247
+ */
248
+ tokenSymbol?: string;
249
+ /**
250
+ * Optional chain id for per-asset APY lookups. Typically paired with
251
+ * `tokenSymbol`.
252
+ */
253
+ chainId?: number;
254
+ };
255
+ type DepositOptions = {
256
+ amount: string;
257
+ asset: Asset;
258
+ depositCallback?: DepositCallback;
259
+ agentId?: AgentId;
260
+ };
261
+
228
262
  declare class OwneySDK {
229
263
  private agents;
230
264
  private activeAgents;
@@ -237,6 +271,7 @@ declare class OwneySDK {
237
271
  private state;
238
272
  private apiKey;
239
273
  private zyfaiRpcUrls?;
274
+ private cachedSponsoredCallback;
240
275
  private initializingAgentsPromise;
241
276
  constructor(config: OwneySDKConfig);
242
277
  /**
@@ -263,6 +298,14 @@ declare class OwneySDK {
263
298
  getActiveChainId(): number | null;
264
299
  private requireState;
265
300
  private requireChainId;
301
+ private requireConnectedProvider;
302
+ /**
303
+ * Lazily builds (and caches) the default EIP-3009 sponsored deposit callback
304
+ * used when the caller omits `depositCallback`. Wraps the connected EIP-1193
305
+ * provider with viem `custom(provider)` to read token meta and sign the
306
+ * `TransferWithAuthorization`, then POSTs to the sponsor API.
307
+ */
308
+ private getDefaultSponsoredCallback;
266
309
  private getAgent;
267
310
  private getActiveAgents;
268
311
  private ensureAgentsInitialized;
@@ -352,18 +395,6 @@ declare class OwneySDK {
352
395
  * @returns {OwneyAgentHistory} `data` (up to `limit` entries), `hasMore`, `nextCursor`.
353
396
  */
354
397
  getHistory(params?: HistoryOptions): Promise<OwneyAgentHistory>;
355
- /**
356
- * Pause an agent's automated operations. The agent will stop rebalancing until resumed.
357
- * @param agentId - The agent to pause (e.g. "zyfai")
358
- * @returns OwneyAgentStatus with success flag
359
- */
360
- pauseAgent(agentId: AgentId): Promise<OwneyAgentStatus>;
361
- /**
362
- * Resume an agent's automated operations.
363
- * @param agentId - The agent to resume (e.g. "zyfai")
364
- * @returns OwneyAgentStatus with success flag
365
- */
366
- resumeAgent(agentId: AgentId): Promise<OwneyAgentStatus>;
367
398
  /**
368
399
  * Get the user's profile for a specific agent, or all agents.
369
400
  * @param agentId - Optional. Agent to query. Omit for all agents.
@@ -388,9 +419,19 @@ declare class OwneySDK {
388
419
  * @returns Object with agent names as keys and allocation percentages as values
389
420
  */
390
421
  getAgentAllocation(): Promise<OwneyAgentAllocation>;
422
+ /**
423
+ * Allocation-weighted APY from the current portfolio: each pool's APY
424
+ * weighted by the user's position value in it. More accurate per-user than
425
+ * the historical 30D APY. (ROUT-228)
426
+ * @param options.agentId - Optional. Scope to one agent. Omit to aggregate
427
+ * positions across all active agents.
428
+ */
429
+ getAllocationApy({ agentId, }?: {
430
+ agentId?: AgentId;
431
+ }): Promise<OwneyAllocationApy>;
391
432
  }
392
433
 
393
- 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" | "BALANCE_ALL_FAILED" | "ALLOCATION_ALL_FAILED" | "VALIDATION_INVALID_DAYS";
434
+ 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";
394
435
  declare class OwneyError extends Error {
395
436
  readonly code: OwneyErrorCode;
396
437
  readonly details?: Record<string, unknown>;
@@ -433,4 +474,4 @@ type OwneySIWXConfig = {
433
474
  */
434
475
  declare function createOwneySIWX(config: OwneySIWXConfig): SIWXConfig;
435
476
 
436
- export { AccountAgentApy, AccountApyOptions, AgentApy, AgentApyDetails, AgentBalance, AgentChainIncompatibleError, AgentEarnings, AgentHistoryEntry, AgentHistoryPosition, AgentId, AgentNotFoundError, AgentSupportedAsset, AgentSupportedAssets, AgentUserProfile, AgentWithdrawResult, AgentsApyOptions, ApyByChainAndAsset, Asset, ConnectionState, DailyApyDays, DepositCallback, DepositOptions, HistoryAction, HistoryFilters, HistoryOptions, HistoryTransaction, IAgent, InvalidHistoryCursorError, NotConnectedError, OwneyAccountApy, OwneyAgentAllocation, OwneyAgentApy, OwneyAgentHistory, OwneyAgentStatus, OwneyBalances, OwneyDepositResult, OwneyEarnings, OwneyError, OwneyErrorCode, OwneyMultiDepositResult, OwneySDK, OwneySDKConfig, OwneySIWXConfig, OwneySupportedChainId, OwneySupportedChains, OwneySupportedTokens, OwneyToken, OwneyUserProfile, OwneyWithdrawResult, RebalanceLog, WithdrawOptions, createOwneySIWX };
477
+ 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, OwneyAgentAllocation, 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
@@ -14,97 +14,13 @@ interface ConnectionState {
14
14
  walletAddress: `0x${string}`;
15
15
  chainId: number | null;
16
16
  }
17
- declare const SUPPORTED_TOKENS: readonly ["USDC", "USDT"];
17
+ declare const SUPPORTED_TOKENS: readonly ["USDC", "USDT", "WETH"];
18
18
  declare const SUPPORTED_CHAIN_IDS: readonly [8453, 42161];
19
19
  declare const SUPPORTED_CHAINS: readonly ["BASE", "ARBITRUM"];
20
20
  type OwneySupportedChainId = (typeof SUPPORTED_CHAIN_IDS)[number];
21
21
  type OwneySupportedChains = (typeof SUPPORTED_CHAINS)[number];
22
22
  type OwneySupportedTokens = (typeof SUPPORTED_TOKENS)[number];
23
23
 
24
- type DepositCallback = (smartWalletAddress: string, chainId: number, amount: string) => Promise<`0x${string}`> | `0x${string}`;
25
- interface IAgent {
26
- readonly id: string;
27
- readonly supportedChainIds: readonly OwneySupportedChainId[];
28
- readonly supportedAssets: readonly AgentSupportedAssets[];
29
- disconnect(): Promise<void>;
30
- activateAgent(state: ConnectionState, chainId: number): Promise<void>;
31
- deposit(state: ConnectionState, chainId: number, amount: string, depositCallback?: DepositCallback): Promise<OwneyDepositResult>;
32
- withdraw(state: ConnectionState, chainId: number, token: OwneySupportedTokens, amount?: string): Promise<AgentWithdrawResult>;
33
- getBalances(state: ConnectionState, chainId: number): Promise<AgentBalance>;
34
- getEarnings(state: ConnectionState, chainId: number): Promise<AgentEarnings>;
35
- getAccountApy(state: ConnectionState, chainId: number, days: DailyApyDays): Promise<AccountAgentApy>;
36
- getHistory(state: ConnectionState, chainId: number, options?: HistoryFilters): Promise<OwneyAgentHistory>;
37
- pause(state: ConnectionState, chainId: number): Promise<OwneyAgentStatus>;
38
- resume(state: ConnectionState, chainId: number): Promise<OwneyAgentStatus>;
39
- getUserProfile(state: ConnectionState, chainId: number): Promise<AgentUserProfile>;
40
- getAgentApy(days: DailyApyDays, options?: AgentApyOptions): Promise<AgentApy>;
41
- }
42
- /**
43
- * Optional filters for per-agent APY lookups.
44
- * - `tokenSymbol` / `chainId` scope the APY to a specific asset+chain when
45
- * the underlying provider supports it (Zyfai). Agents whose backends do
46
- * not yet support per-asset APY will ignore these options.
47
- */
48
- type AgentApyOptions = {
49
- tokenSymbol?: string;
50
- chainId?: number;
51
- };
52
-
53
- type AgentId = "zyfai" | "sail";
54
- type Asset = string;
55
- type AgentSupportedAsset = {
56
- readonly symbol: string;
57
- readonly minDepositAmount: string;
58
- };
59
- type AgentSupportedAssets = {
60
- readonly chainId: number;
61
- readonly chain?: string;
62
- readonly assets: readonly AgentSupportedAsset[];
63
- };
64
- type DailyApyDays = "7D" | "14D" | "30D";
65
- type HistoryFilters = {
66
- fromDate?: string;
67
- toDate?: string;
68
- /** Max entries returned per call. Defaults to 10. */
69
- limit?: number;
70
- /** Opaque cursor returned by a previous getHistory call. */
71
- cursor?: string;
72
- };
73
- type HistoryOptions = {
74
- agentId?: AgentId;
75
- filters?: HistoryFilters;
76
- };
77
- type WithdrawOptions = {
78
- asset: Asset;
79
- amount?: string;
80
- agentId?: AgentId;
81
- };
82
- type AccountApyOptions = {
83
- agentId?: AgentId;
84
- days: DailyApyDays;
85
- };
86
- type AgentsApyOptions = {
87
- agentId?: AgentId;
88
- days: DailyApyDays;
89
- /**
90
- * Optional asset symbol (e.g. "USDC", "WETH") to scope the APY to a
91
- * specific asset+chain. Ignored by agents whose backends do not yet
92
- * support per-asset APY.
93
- */
94
- tokenSymbol?: string;
95
- /**
96
- * Optional chain id for per-asset APY lookups. Typically paired with
97
- * `tokenSymbol`.
98
- */
99
- chainId?: number;
100
- };
101
- type DepositOptions = {
102
- amount: string;
103
- asset: Asset;
104
- depositCallback: DepositCallback;
105
- agentId?: AgentId;
106
- };
107
-
108
24
  interface OwneyDepositResult {
109
25
  txHash: string;
110
26
  smartWallet: string;
@@ -128,10 +44,29 @@ interface OwneyToken {
128
44
  asset: OwneySupportedTokens;
129
45
  amount: string;
130
46
  }
47
+ interface OwneyPosition {
48
+ /** Raw chain identifier as returned by the agent (chain id or name); not coerced. */
49
+ chain: string;
50
+ protocol: string;
51
+ protocolId?: string;
52
+ pool?: string;
53
+ asset: string;
54
+ amount: string;
55
+ apy?: number;
56
+ tvl?: number;
57
+ /** Pool liquidity. Prepared slot — Zyfai will add this to its portfolio
58
+ * response later; undefined until then. */
59
+ liquidity?: number;
60
+ }
131
61
  interface AgentBalance {
132
62
  smartWallet?: `0x${string}`;
133
63
  totalBalance: string;
134
64
  tokens: OwneyToken[];
65
+ /**
66
+ * Per-protocol/pool positions when the agent's portfolio payload includes
67
+ * them (zyfai). Omitted for agents that don't expose positions (sail).
68
+ */
69
+ positions?: OwneyPosition[];
135
70
  }
136
71
  interface OwneyBalances {
137
72
  totalBalance: string;
@@ -158,6 +93,17 @@ interface OwneyAccountApy {
158
93
  agentApy: Record<AgentId, AccountAgentApy>;
159
94
  apyByChainAndAsset: ApyByChainAndAsset;
160
95
  }
96
+ interface AllocationAgentApy {
97
+ /** Account-wide weighted APY for this agent, as a decimal string. */
98
+ totalApy: string;
99
+ apyByChainAndAsset: ApyByChainAndAsset;
100
+ }
101
+ interface OwneyAllocationApy {
102
+ /** Account-wide weighted APY across all active agents, as a decimal string. */
103
+ totalApy: string;
104
+ apyByChainAndAsset: ApyByChainAndAsset;
105
+ agentApy: Record<AgentId, AllocationAgentApy>;
106
+ }
161
107
  type HistoryAction = "Rebalance" | "Deposit" | "Top up" | "Withdraw" | "Earned";
162
108
  interface HistoryTransaction {
163
109
  txHashes: string[];
@@ -168,6 +114,15 @@ interface HistoryTransaction {
168
114
  interface RebalanceLog {
169
115
  fromProtocol: string;
170
116
  toProtocol: string;
117
+ /**
118
+ * Pool/vault sub-label for the source position (e.g. "USDC Core"), when the
119
+ * agent exposes one. Lets consumers disambiguate moves within the same
120
+ * protocol ("Morpho · USDC Core → Morpho · Spark USDC"). Absent when the
121
+ * agent only reports a bare protocol name.
122
+ */
123
+ fromPool?: string;
124
+ /** Pool/vault sub-label for the destination position. See {@link fromPool}. */
125
+ toPool?: string;
171
126
  tokenSymbol: string;
172
127
  amount: string;
173
128
  status: "success" | "failed";
@@ -195,11 +150,6 @@ interface OwneyAgentHistory {
195
150
  /** Opaque cursor for the next page. Present iff `hasMore === true`. */
196
151
  nextCursor?: string;
197
152
  }
198
- interface OwneyAgentStatus {
199
- success: boolean;
200
- strategy?: string;
201
- protocols?: string[];
202
- }
203
153
  interface AgentUserProfile {
204
154
  address: string;
205
155
  smartWallet: string;
@@ -223,8 +173,92 @@ interface OwneyAgentApy {
223
173
  }
224
174
  interface OwneyAgentAllocation {
225
175
  agentAllocation: Record<AgentId, number>;
176
+ /** Per-agent positions. Empty array for agents that don't expose positions. */
177
+ agentPositions: Record<AgentId, OwneyPosition[]>;
226
178
  }
227
179
 
180
+ type DepositCallback = (smartWalletAddress: string, chainId: number, amount: string) => Promise<`0x${string}`> | `0x${string}`;
181
+ interface IAgent {
182
+ readonly id: string;
183
+ readonly supportedChainIds: readonly OwneySupportedChainId[];
184
+ readonly supportedAssets: readonly AgentSupportedAssets[];
185
+ disconnect(): Promise<void>;
186
+ activateAgent(state: ConnectionState, chainId: number): Promise<void>;
187
+ deposit(state: ConnectionState, chainId: number, amount: string, asset: OwneySupportedTokens, depositCallback?: DepositCallback): Promise<OwneyDepositResult>;
188
+ withdraw(state: ConnectionState, chainId: number, token: OwneySupportedTokens, amount?: string): Promise<AgentWithdrawResult>;
189
+ getBalances(state: ConnectionState, chainId: number): Promise<AgentBalance>;
190
+ getEarnings(state: ConnectionState, chainId: number): Promise<AgentEarnings>;
191
+ getAccountApy(state: ConnectionState, chainId: number, days: DailyApyDays): Promise<AccountAgentApy>;
192
+ getHistory(state: ConnectionState, chainId: number, options?: HistoryFilters): Promise<OwneyAgentHistory>;
193
+ getUserProfile(state: ConnectionState, chainId: number): Promise<AgentUserProfile>;
194
+ getAgentApy(days: DailyApyDays, options?: AgentApyOptions): Promise<AgentApy>;
195
+ }
196
+ /**
197
+ * Optional filters for per-agent APY lookups.
198
+ * - `tokenSymbol` / `chainId` scope the APY to a specific asset+chain when
199
+ * the underlying provider supports it (Zyfai). Agents whose backends do
200
+ * not yet support per-asset APY will ignore these options.
201
+ */
202
+ type AgentApyOptions = {
203
+ tokenSymbol?: string;
204
+ chainId?: number;
205
+ };
206
+
207
+ type AgentId = "zyfai" | "sail";
208
+ type Asset = string;
209
+ type AgentSupportedAsset = {
210
+ readonly symbol: string;
211
+ readonly minDepositAmount: string;
212
+ };
213
+ type AgentSupportedAssets = {
214
+ readonly chainId: number;
215
+ readonly chain?: string;
216
+ readonly assets: readonly AgentSupportedAsset[];
217
+ };
218
+ type DailyApyDays = "7D" | "14D" | "30D";
219
+ type HistoryFilters = {
220
+ fromDate?: string;
221
+ toDate?: string;
222
+ /** Max entries returned per call. Defaults to 10. */
223
+ limit?: number;
224
+ /** Opaque cursor returned by a previous getHistory call. */
225
+ cursor?: string;
226
+ };
227
+ type HistoryOptions = {
228
+ agentId?: AgentId;
229
+ filters?: HistoryFilters;
230
+ };
231
+ type WithdrawOptions = {
232
+ asset: Asset;
233
+ amount?: string;
234
+ agentId?: AgentId;
235
+ };
236
+ type AccountApyOptions = {
237
+ agentId?: AgentId;
238
+ days: DailyApyDays;
239
+ };
240
+ type AgentsApyOptions = {
241
+ agentId?: AgentId;
242
+ days: DailyApyDays;
243
+ /**
244
+ * Optional asset symbol (e.g. "USDC", "WETH") to scope the APY to a
245
+ * specific asset+chain. Ignored by agents whose backends do not yet
246
+ * support per-asset APY.
247
+ */
248
+ tokenSymbol?: string;
249
+ /**
250
+ * Optional chain id for per-asset APY lookups. Typically paired with
251
+ * `tokenSymbol`.
252
+ */
253
+ chainId?: number;
254
+ };
255
+ type DepositOptions = {
256
+ amount: string;
257
+ asset: Asset;
258
+ depositCallback?: DepositCallback;
259
+ agentId?: AgentId;
260
+ };
261
+
228
262
  declare class OwneySDK {
229
263
  private agents;
230
264
  private activeAgents;
@@ -237,6 +271,7 @@ declare class OwneySDK {
237
271
  private state;
238
272
  private apiKey;
239
273
  private zyfaiRpcUrls?;
274
+ private cachedSponsoredCallback;
240
275
  private initializingAgentsPromise;
241
276
  constructor(config: OwneySDKConfig);
242
277
  /**
@@ -263,6 +298,14 @@ declare class OwneySDK {
263
298
  getActiveChainId(): number | null;
264
299
  private requireState;
265
300
  private requireChainId;
301
+ private requireConnectedProvider;
302
+ /**
303
+ * Lazily builds (and caches) the default EIP-3009 sponsored deposit callback
304
+ * used when the caller omits `depositCallback`. Wraps the connected EIP-1193
305
+ * provider with viem `custom(provider)` to read token meta and sign the
306
+ * `TransferWithAuthorization`, then POSTs to the sponsor API.
307
+ */
308
+ private getDefaultSponsoredCallback;
266
309
  private getAgent;
267
310
  private getActiveAgents;
268
311
  private ensureAgentsInitialized;
@@ -352,18 +395,6 @@ declare class OwneySDK {
352
395
  * @returns {OwneyAgentHistory} `data` (up to `limit` entries), `hasMore`, `nextCursor`.
353
396
  */
354
397
  getHistory(params?: HistoryOptions): Promise<OwneyAgentHistory>;
355
- /**
356
- * Pause an agent's automated operations. The agent will stop rebalancing until resumed.
357
- * @param agentId - The agent to pause (e.g. "zyfai")
358
- * @returns OwneyAgentStatus with success flag
359
- */
360
- pauseAgent(agentId: AgentId): Promise<OwneyAgentStatus>;
361
- /**
362
- * Resume an agent's automated operations.
363
- * @param agentId - The agent to resume (e.g. "zyfai")
364
- * @returns OwneyAgentStatus with success flag
365
- */
366
- resumeAgent(agentId: AgentId): Promise<OwneyAgentStatus>;
367
398
  /**
368
399
  * Get the user's profile for a specific agent, or all agents.
369
400
  * @param agentId - Optional. Agent to query. Omit for all agents.
@@ -388,9 +419,19 @@ declare class OwneySDK {
388
419
  * @returns Object with agent names as keys and allocation percentages as values
389
420
  */
390
421
  getAgentAllocation(): Promise<OwneyAgentAllocation>;
422
+ /**
423
+ * Allocation-weighted APY from the current portfolio: each pool's APY
424
+ * weighted by the user's position value in it. More accurate per-user than
425
+ * the historical 30D APY. (ROUT-228)
426
+ * @param options.agentId - Optional. Scope to one agent. Omit to aggregate
427
+ * positions across all active agents.
428
+ */
429
+ getAllocationApy({ agentId, }?: {
430
+ agentId?: AgentId;
431
+ }): Promise<OwneyAllocationApy>;
391
432
  }
392
433
 
393
- 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" | "BALANCE_ALL_FAILED" | "ALLOCATION_ALL_FAILED" | "VALIDATION_INVALID_DAYS";
434
+ 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";
394
435
  declare class OwneyError extends Error {
395
436
  readonly code: OwneyErrorCode;
396
437
  readonly details?: Record<string, unknown>;
@@ -433,4 +474,4 @@ type OwneySIWXConfig = {
433
474
  */
434
475
  declare function createOwneySIWX(config: OwneySIWXConfig): SIWXConfig;
435
476
 
436
- export { AccountAgentApy, AccountApyOptions, AgentApy, AgentApyDetails, AgentBalance, AgentChainIncompatibleError, AgentEarnings, AgentHistoryEntry, AgentHistoryPosition, AgentId, AgentNotFoundError, AgentSupportedAsset, AgentSupportedAssets, AgentUserProfile, AgentWithdrawResult, AgentsApyOptions, ApyByChainAndAsset, Asset, ConnectionState, DailyApyDays, DepositCallback, DepositOptions, HistoryAction, HistoryFilters, HistoryOptions, HistoryTransaction, IAgent, InvalidHistoryCursorError, NotConnectedError, OwneyAccountApy, OwneyAgentAllocation, OwneyAgentApy, OwneyAgentHistory, OwneyAgentStatus, OwneyBalances, OwneyDepositResult, OwneyEarnings, OwneyError, OwneyErrorCode, OwneyMultiDepositResult, OwneySDK, OwneySDKConfig, OwneySIWXConfig, OwneySupportedChainId, OwneySupportedChains, OwneySupportedTokens, OwneyToken, OwneyUserProfile, OwneyWithdrawResult, RebalanceLog, WithdrawOptions, createOwneySIWX };
477
+ 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, OwneyAgentAllocation, OwneyAgentApy, OwneyAgentHistory, OwneyAllocationApy, OwneyBalances, OwneyDepositResult, OwneyEarnings, OwneyError, OwneyErrorCode, OwneyMultiDepositResult, OwneyPosition, OwneySDK, OwneySDKConfig, OwneySIWXConfig, OwneySupportedChainId, OwneySupportedChains, OwneySupportedTokens, OwneyToken, OwneyUserProfile, OwneyWithdrawResult, RebalanceLog, WithdrawOptions, createOwneySIWX };