@owney/sdk 0.6.0-beta.0 → 0.6.0-beta.1

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[];
@@ -195,11 +141,6 @@ interface OwneyAgentHistory {
195
141
  /** Opaque cursor for the next page. Present iff `hasMore === true`. */
196
142
  nextCursor?: string;
197
143
  }
198
- interface OwneyAgentStatus {
199
- success: boolean;
200
- strategy?: string;
201
- protocols?: string[];
202
- }
203
144
  interface AgentUserProfile {
204
145
  address: string;
205
146
  smartWallet: string;
@@ -223,8 +164,92 @@ interface OwneyAgentApy {
223
164
  }
224
165
  interface OwneyAgentAllocation {
225
166
  agentAllocation: Record<AgentId, number>;
167
+ /** Per-agent positions. Empty array for agents that don't expose positions. */
168
+ agentPositions: Record<AgentId, OwneyPosition[]>;
226
169
  }
227
170
 
171
+ type DepositCallback = (smartWalletAddress: string, chainId: number, amount: string) => Promise<`0x${string}`> | `0x${string}`;
172
+ interface IAgent {
173
+ readonly id: string;
174
+ readonly supportedChainIds: readonly OwneySupportedChainId[];
175
+ readonly supportedAssets: readonly AgentSupportedAssets[];
176
+ disconnect(): Promise<void>;
177
+ activateAgent(state: ConnectionState, chainId: number): Promise<void>;
178
+ deposit(state: ConnectionState, chainId: number, amount: string, asset: OwneySupportedTokens, depositCallback?: DepositCallback): Promise<OwneyDepositResult>;
179
+ withdraw(state: ConnectionState, chainId: number, token: OwneySupportedTokens, amount?: string): Promise<AgentWithdrawResult>;
180
+ getBalances(state: ConnectionState, chainId: number): Promise<AgentBalance>;
181
+ getEarnings(state: ConnectionState, chainId: number): Promise<AgentEarnings>;
182
+ getAccountApy(state: ConnectionState, chainId: number, days: DailyApyDays): Promise<AccountAgentApy>;
183
+ getHistory(state: ConnectionState, chainId: number, options?: HistoryFilters): Promise<OwneyAgentHistory>;
184
+ getUserProfile(state: ConnectionState, chainId: number): Promise<AgentUserProfile>;
185
+ getAgentApy(days: DailyApyDays, options?: AgentApyOptions): Promise<AgentApy>;
186
+ }
187
+ /**
188
+ * Optional filters for per-agent APY lookups.
189
+ * - `tokenSymbol` / `chainId` scope the APY to a specific asset+chain when
190
+ * the underlying provider supports it (Zyfai). Agents whose backends do
191
+ * not yet support per-asset APY will ignore these options.
192
+ */
193
+ type AgentApyOptions = {
194
+ tokenSymbol?: string;
195
+ chainId?: number;
196
+ };
197
+
198
+ type AgentId = "zyfai" | "sail";
199
+ type Asset = string;
200
+ type AgentSupportedAsset = {
201
+ readonly symbol: string;
202
+ readonly minDepositAmount: string;
203
+ };
204
+ type AgentSupportedAssets = {
205
+ readonly chainId: number;
206
+ readonly chain?: string;
207
+ readonly assets: readonly AgentSupportedAsset[];
208
+ };
209
+ type DailyApyDays = "7D" | "14D" | "30D";
210
+ type HistoryFilters = {
211
+ fromDate?: string;
212
+ toDate?: string;
213
+ /** Max entries returned per call. Defaults to 10. */
214
+ limit?: number;
215
+ /** Opaque cursor returned by a previous getHistory call. */
216
+ cursor?: string;
217
+ };
218
+ type HistoryOptions = {
219
+ agentId?: AgentId;
220
+ filters?: HistoryFilters;
221
+ };
222
+ type WithdrawOptions = {
223
+ asset: Asset;
224
+ amount?: string;
225
+ agentId?: AgentId;
226
+ };
227
+ type AccountApyOptions = {
228
+ agentId?: AgentId;
229
+ days: DailyApyDays;
230
+ };
231
+ type AgentsApyOptions = {
232
+ agentId?: AgentId;
233
+ days: DailyApyDays;
234
+ /**
235
+ * Optional asset symbol (e.g. "USDC", "WETH") to scope the APY to a
236
+ * specific asset+chain. Ignored by agents whose backends do not yet
237
+ * support per-asset APY.
238
+ */
239
+ tokenSymbol?: string;
240
+ /**
241
+ * Optional chain id for per-asset APY lookups. Typically paired with
242
+ * `tokenSymbol`.
243
+ */
244
+ chainId?: number;
245
+ };
246
+ type DepositOptions = {
247
+ amount: string;
248
+ asset: Asset;
249
+ depositCallback?: DepositCallback;
250
+ agentId?: AgentId;
251
+ };
252
+
228
253
  declare class OwneySDK {
229
254
  private agents;
230
255
  private activeAgents;
@@ -237,6 +262,7 @@ declare class OwneySDK {
237
262
  private state;
238
263
  private apiKey;
239
264
  private zyfaiRpcUrls?;
265
+ private cachedSponsoredCallback;
240
266
  private initializingAgentsPromise;
241
267
  constructor(config: OwneySDKConfig);
242
268
  /**
@@ -263,6 +289,14 @@ declare class OwneySDK {
263
289
  getActiveChainId(): number | null;
264
290
  private requireState;
265
291
  private requireChainId;
292
+ private requireConnectedProvider;
293
+ /**
294
+ * Lazily builds (and caches) the default EIP-3009 sponsored deposit callback
295
+ * used when the caller omits `depositCallback`. Wraps the connected EIP-1193
296
+ * provider with viem `custom(provider)` to read token meta and sign the
297
+ * `TransferWithAuthorization`, then POSTs to the sponsor API.
298
+ */
299
+ private getDefaultSponsoredCallback;
266
300
  private getAgent;
267
301
  private getActiveAgents;
268
302
  private ensureAgentsInitialized;
@@ -352,18 +386,6 @@ declare class OwneySDK {
352
386
  * @returns {OwneyAgentHistory} `data` (up to `limit` entries), `hasMore`, `nextCursor`.
353
387
  */
354
388
  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
389
  /**
368
390
  * Get the user's profile for a specific agent, or all agents.
369
391
  * @param agentId - Optional. Agent to query. Omit for all agents.
@@ -388,9 +410,19 @@ declare class OwneySDK {
388
410
  * @returns Object with agent names as keys and allocation percentages as values
389
411
  */
390
412
  getAgentAllocation(): Promise<OwneyAgentAllocation>;
413
+ /**
414
+ * Allocation-weighted APY from the current portfolio: each pool's APY
415
+ * weighted by the user's position value in it. More accurate per-user than
416
+ * the historical 30D APY. (ROUT-228)
417
+ * @param options.agentId - Optional. Scope to one agent. Omit to aggregate
418
+ * positions across all active agents.
419
+ */
420
+ getAllocationApy({ agentId, }?: {
421
+ agentId?: AgentId;
422
+ }): Promise<OwneyAllocationApy>;
391
423
  }
392
424
 
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";
425
+ 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
426
  declare class OwneyError extends Error {
395
427
  readonly code: OwneyErrorCode;
396
428
  readonly details?: Record<string, unknown>;
@@ -433,4 +465,4 @@ type OwneySIWXConfig = {
433
465
  */
434
466
  declare function createOwneySIWX(config: OwneySIWXConfig): SIWXConfig;
435
467
 
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 };
468
+ 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[];
@@ -195,11 +141,6 @@ interface OwneyAgentHistory {
195
141
  /** Opaque cursor for the next page. Present iff `hasMore === true`. */
196
142
  nextCursor?: string;
197
143
  }
198
- interface OwneyAgentStatus {
199
- success: boolean;
200
- strategy?: string;
201
- protocols?: string[];
202
- }
203
144
  interface AgentUserProfile {
204
145
  address: string;
205
146
  smartWallet: string;
@@ -223,8 +164,92 @@ interface OwneyAgentApy {
223
164
  }
224
165
  interface OwneyAgentAllocation {
225
166
  agentAllocation: Record<AgentId, number>;
167
+ /** Per-agent positions. Empty array for agents that don't expose positions. */
168
+ agentPositions: Record<AgentId, OwneyPosition[]>;
226
169
  }
227
170
 
171
+ type DepositCallback = (smartWalletAddress: string, chainId: number, amount: string) => Promise<`0x${string}`> | `0x${string}`;
172
+ interface IAgent {
173
+ readonly id: string;
174
+ readonly supportedChainIds: readonly OwneySupportedChainId[];
175
+ readonly supportedAssets: readonly AgentSupportedAssets[];
176
+ disconnect(): Promise<void>;
177
+ activateAgent(state: ConnectionState, chainId: number): Promise<void>;
178
+ deposit(state: ConnectionState, chainId: number, amount: string, asset: OwneySupportedTokens, depositCallback?: DepositCallback): Promise<OwneyDepositResult>;
179
+ withdraw(state: ConnectionState, chainId: number, token: OwneySupportedTokens, amount?: string): Promise<AgentWithdrawResult>;
180
+ getBalances(state: ConnectionState, chainId: number): Promise<AgentBalance>;
181
+ getEarnings(state: ConnectionState, chainId: number): Promise<AgentEarnings>;
182
+ getAccountApy(state: ConnectionState, chainId: number, days: DailyApyDays): Promise<AccountAgentApy>;
183
+ getHistory(state: ConnectionState, chainId: number, options?: HistoryFilters): Promise<OwneyAgentHistory>;
184
+ getUserProfile(state: ConnectionState, chainId: number): Promise<AgentUserProfile>;
185
+ getAgentApy(days: DailyApyDays, options?: AgentApyOptions): Promise<AgentApy>;
186
+ }
187
+ /**
188
+ * Optional filters for per-agent APY lookups.
189
+ * - `tokenSymbol` / `chainId` scope the APY to a specific asset+chain when
190
+ * the underlying provider supports it (Zyfai). Agents whose backends do
191
+ * not yet support per-asset APY will ignore these options.
192
+ */
193
+ type AgentApyOptions = {
194
+ tokenSymbol?: string;
195
+ chainId?: number;
196
+ };
197
+
198
+ type AgentId = "zyfai" | "sail";
199
+ type Asset = string;
200
+ type AgentSupportedAsset = {
201
+ readonly symbol: string;
202
+ readonly minDepositAmount: string;
203
+ };
204
+ type AgentSupportedAssets = {
205
+ readonly chainId: number;
206
+ readonly chain?: string;
207
+ readonly assets: readonly AgentSupportedAsset[];
208
+ };
209
+ type DailyApyDays = "7D" | "14D" | "30D";
210
+ type HistoryFilters = {
211
+ fromDate?: string;
212
+ toDate?: string;
213
+ /** Max entries returned per call. Defaults to 10. */
214
+ limit?: number;
215
+ /** Opaque cursor returned by a previous getHistory call. */
216
+ cursor?: string;
217
+ };
218
+ type HistoryOptions = {
219
+ agentId?: AgentId;
220
+ filters?: HistoryFilters;
221
+ };
222
+ type WithdrawOptions = {
223
+ asset: Asset;
224
+ amount?: string;
225
+ agentId?: AgentId;
226
+ };
227
+ type AccountApyOptions = {
228
+ agentId?: AgentId;
229
+ days: DailyApyDays;
230
+ };
231
+ type AgentsApyOptions = {
232
+ agentId?: AgentId;
233
+ days: DailyApyDays;
234
+ /**
235
+ * Optional asset symbol (e.g. "USDC", "WETH") to scope the APY to a
236
+ * specific asset+chain. Ignored by agents whose backends do not yet
237
+ * support per-asset APY.
238
+ */
239
+ tokenSymbol?: string;
240
+ /**
241
+ * Optional chain id for per-asset APY lookups. Typically paired with
242
+ * `tokenSymbol`.
243
+ */
244
+ chainId?: number;
245
+ };
246
+ type DepositOptions = {
247
+ amount: string;
248
+ asset: Asset;
249
+ depositCallback?: DepositCallback;
250
+ agentId?: AgentId;
251
+ };
252
+
228
253
  declare class OwneySDK {
229
254
  private agents;
230
255
  private activeAgents;
@@ -237,6 +262,7 @@ declare class OwneySDK {
237
262
  private state;
238
263
  private apiKey;
239
264
  private zyfaiRpcUrls?;
265
+ private cachedSponsoredCallback;
240
266
  private initializingAgentsPromise;
241
267
  constructor(config: OwneySDKConfig);
242
268
  /**
@@ -263,6 +289,14 @@ declare class OwneySDK {
263
289
  getActiveChainId(): number | null;
264
290
  private requireState;
265
291
  private requireChainId;
292
+ private requireConnectedProvider;
293
+ /**
294
+ * Lazily builds (and caches) the default EIP-3009 sponsored deposit callback
295
+ * used when the caller omits `depositCallback`. Wraps the connected EIP-1193
296
+ * provider with viem `custom(provider)` to read token meta and sign the
297
+ * `TransferWithAuthorization`, then POSTs to the sponsor API.
298
+ */
299
+ private getDefaultSponsoredCallback;
266
300
  private getAgent;
267
301
  private getActiveAgents;
268
302
  private ensureAgentsInitialized;
@@ -352,18 +386,6 @@ declare class OwneySDK {
352
386
  * @returns {OwneyAgentHistory} `data` (up to `limit` entries), `hasMore`, `nextCursor`.
353
387
  */
354
388
  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
389
  /**
368
390
  * Get the user's profile for a specific agent, or all agents.
369
391
  * @param agentId - Optional. Agent to query. Omit for all agents.
@@ -388,9 +410,19 @@ declare class OwneySDK {
388
410
  * @returns Object with agent names as keys and allocation percentages as values
389
411
  */
390
412
  getAgentAllocation(): Promise<OwneyAgentAllocation>;
413
+ /**
414
+ * Allocation-weighted APY from the current portfolio: each pool's APY
415
+ * weighted by the user's position value in it. More accurate per-user than
416
+ * the historical 30D APY. (ROUT-228)
417
+ * @param options.agentId - Optional. Scope to one agent. Omit to aggregate
418
+ * positions across all active agents.
419
+ */
420
+ getAllocationApy({ agentId, }?: {
421
+ agentId?: AgentId;
422
+ }): Promise<OwneyAllocationApy>;
391
423
  }
392
424
 
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";
425
+ 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
426
  declare class OwneyError extends Error {
395
427
  readonly code: OwneyErrorCode;
396
428
  readonly details?: Record<string, unknown>;
@@ -433,4 +465,4 @@ type OwneySIWXConfig = {
433
465
  */
434
466
  declare function createOwneySIWX(config: OwneySIWXConfig): SIWXConfig;
435
467
 
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 };
468
+ 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 };