@owney/sdk 0.2.8 → 0.2.10
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 +159 -116
- package/dist/index.cjs +283 -58
- package/dist/index.d.cts +9 -9
- package/dist/index.d.ts +9 -9
- package/dist/index.js +283 -58
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -32,9 +32,10 @@ const balances = await sdk.getBalances();
|
|
|
32
32
|
|
|
33
33
|
Create a new SDK instance.
|
|
34
34
|
|
|
35
|
-
| Param
|
|
36
|
-
|
|
37
|
-
| `config.apiKey`
|
|
35
|
+
| Param | Type | Description |
|
|
36
|
+
| --------------------- | ---------------------------------------------- | ------------------------------------------------------------------------------------------- |
|
|
37
|
+
| `config.apiKey` | `string` | Your Owney API key, used to authenticate with the routing API and fetch agent-specific keys |
|
|
38
|
+
| `config.zyfaiRpcUrls` | `{ 8453?: string; 42161?: string }` (optional) | Per-chain RPC URL overrides used by Zyfai SDK network calls |
|
|
38
39
|
|
|
39
40
|
```typescript
|
|
40
41
|
import { OwneySDK } from "@owney/sdk";
|
|
@@ -42,12 +43,32 @@ import { OwneySDK } from "@owney/sdk";
|
|
|
42
43
|
const sdk = new OwneySDK({ apiKey: "your-owney-api-key" });
|
|
43
44
|
```
|
|
44
45
|
|
|
46
|
+
#### Custom Zyfai RPC URLs
|
|
47
|
+
|
|
48
|
+
Use `zyfaiRpcUrls` to override Zyfai SDK RPC endpoints (for example, to avoid public endpoint rate limits).
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
const sdk = new OwneySDK({
|
|
52
|
+
apiKey: "your-owney-api-key",
|
|
53
|
+
zyfaiRpcUrls: {
|
|
54
|
+
8453: "https://base-mainnet.g.alchemy.com/v2/<key>",
|
|
55
|
+
42161: "https://arb-mainnet.g.alchemy.com/v2/<key>",
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Notes:
|
|
61
|
+
|
|
62
|
+
- These overrides are used by Zyfai SDK flows only.
|
|
63
|
+
- If omitted, Zyfai SDK uses its default RPC endpoints.
|
|
64
|
+
- Other app-level RPC clients (for example, direct viem calls outside Zyfai) are configured separately.
|
|
65
|
+
|
|
45
66
|
### `connect(provider)`
|
|
46
67
|
|
|
47
68
|
Establish connection state. Must be called before any wallet-dependent operation.
|
|
48
69
|
|
|
49
|
-
| Param
|
|
50
|
-
|
|
70
|
+
| Param | Type | Description |
|
|
71
|
+
| ---------- | ----------------- | ---------------------------------------------- |
|
|
51
72
|
| `provider` | EIP-1193 provider | Wallet provider (e.g. MetaMask, WalletConnect) |
|
|
52
73
|
|
|
53
74
|
```typescript
|
|
@@ -89,9 +110,9 @@ if (chainId) {
|
|
|
89
110
|
|
|
90
111
|
Activate the user's smart wallet for the specified agents, or all chain-compatible agents if omitted. Deploys the Safe contract and creates a session key if not already set up. Saves the chainId for use by all subsequent SDK calls.
|
|
91
112
|
|
|
92
|
-
| Param
|
|
93
|
-
|
|
94
|
-
| `chainId` | `number`
|
|
113
|
+
| Param | Type | Description |
|
|
114
|
+
| --------- | ---------------------- | ----------------------------------------------------------------------------- |
|
|
115
|
+
| `chainId` | `number` | Target chain ID (e.g. `8453` for Base, `42161` for Arbitrum) |
|
|
95
116
|
| `agentId` | `AgentId[]` (optional) | Agents to activate. Omit to activate all agents that support the given chain. |
|
|
96
117
|
|
|
97
118
|
```typescript
|
|
@@ -104,14 +125,14 @@ await sdk.activateAgent(42161);
|
|
|
104
125
|
|
|
105
126
|
### `deposit(options)`
|
|
106
127
|
|
|
107
|
-
Deposit funds into a specific agent, or split equally across all agents if `agentId` is omitted. Validates that the asset is supported by the target agent(s) on the active chain. When splitting across agents, `depositCallback` is invoked once per agent with that agent's split amount and smart wallet address — expect multiple wallet prompts.
|
|
128
|
+
Deposit funds into a specific agent, or split equally across all agents if `agentId` is omitted. Validates that the asset is supported by the target agent(s) on the active chain, and agent minimum deposit amounts are taken into account. When splitting across agents, `depositCallback` is invoked once per final valid agent with that agent's split amount and smart wallet address — expect multiple wallet prompts.
|
|
108
129
|
|
|
109
|
-
| Param
|
|
110
|
-
|
|
111
|
-
| `options.amount`
|
|
112
|
-
| `options.asset`
|
|
113
|
-
| `options.depositCallback` | `DepositCallback`
|
|
114
|
-
| `options.agentId`
|
|
130
|
+
| Param | Type | Description |
|
|
131
|
+
| ------------------------- | -------------------- | --------------------------------------------------------------- |
|
|
132
|
+
| `options.amount` | `string` | Amount in smallest unit (e.g. `"100000000"` for 100 USDC) |
|
|
133
|
+
| `options.asset` | `string` | Asset symbol (e.g. `"USDC"`) |
|
|
134
|
+
| `options.depositCallback` | `DepositCallback` | Callback that performs the token transfer and returns a tx hash |
|
|
135
|
+
| `options.agentId` | `AgentId` (optional) | Target agent. Omit to split equally across all agents. |
|
|
115
136
|
|
|
116
137
|
Returns: `OwneyDepositResult` (single agent) or `OwneyMultiDepositResult` (all agents)
|
|
117
138
|
|
|
@@ -126,9 +147,9 @@ const result = await sdk.deposit({
|
|
|
126
147
|
return txHash;
|
|
127
148
|
},
|
|
128
149
|
});
|
|
129
|
-
console.log(result.txHash);
|
|
130
|
-
console.log(result.smartWallet);
|
|
131
|
-
console.log(result.amount);
|
|
150
|
+
console.log(result.txHash); // "0x..."
|
|
151
|
+
console.log(result.smartWallet); // "0x..."
|
|
152
|
+
console.log(result.amount); // "100000000"
|
|
132
153
|
|
|
133
154
|
// Split equally across all agents
|
|
134
155
|
const results = await sdk.deposit({
|
|
@@ -138,19 +159,27 @@ const results = await sdk.deposit({
|
|
|
138
159
|
return await transferTokens(smartWallet, amount);
|
|
139
160
|
},
|
|
140
161
|
});
|
|
141
|
-
console.log(results.agentResults.zyfai.amount);
|
|
142
|
-
console.log(results.agentResults.sail.amount);
|
|
162
|
+
console.log(results.agentResults.zyfai.amount); // "50000000"
|
|
163
|
+
console.log(results.agentResults.sail.amount); // "50000000"
|
|
143
164
|
```
|
|
144
165
|
|
|
145
166
|
### `withdraw(options)`
|
|
146
167
|
|
|
147
168
|
Withdraw funds from a specific agent, or all agents that support the active chain+asset if `agentId` is omitted. Validates that the asset is supported.
|
|
148
169
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
170
|
+
When `agentId` is omitted with a partial `amount`, the SDK splits the requested amount proportionally across eligible agents based on each agent's per-asset balance. If an agent's withdraw fails, its share is redistributed to remaining not-yet-attempted agents (capped by their headroom). Throws:
|
|
171
|
+
|
|
172
|
+
- `WITHDRAW_INSUFFICIENT_BALANCE` — total available across agents is less than `amount`.
|
|
173
|
+
- `WITHDRAW_ALL_FAILED` — every agent's withdraw call failed.
|
|
174
|
+
- `WITHDRAW_PARTIAL_FAILURE` — some agents succeeded but total withdrawn is less than `amount`. Successful txs are surfaced via `error.details.partialResults`; per-agent failure messages via `error.details.agentErrors`.
|
|
175
|
+
|
|
176
|
+
`WITHDRAW_ALL_FAILED` also carries per-agent failure messages via `error.details.agentErrors` (a `Record<agentId, string>`). Any error originating from a specific agent also has `error.agentId` set and a `[agent:<id>]` prefix on `error.message`.
|
|
177
|
+
|
|
178
|
+
| Param | Type | Description |
|
|
179
|
+
| ----------------- | -------------------- | --------------------------------------------- |
|
|
180
|
+
| `options.asset` | `string` | Asset symbol (e.g. `"USDC"`) |
|
|
181
|
+
| `options.amount` | `string` (optional) | Amount to withdraw. Omit for full withdrawal. |
|
|
182
|
+
| `options.agentId` | `AgentId` (optional) | Target agent. Omit to withdraw from all. |
|
|
154
183
|
|
|
155
184
|
Returns: `AgentWithdrawResult` (single agent) or `OwneyWithdrawResult` (all agents)
|
|
156
185
|
|
|
@@ -161,21 +190,27 @@ const result = await sdk.withdraw({
|
|
|
161
190
|
agentId: "zyfai",
|
|
162
191
|
amount: "50000000",
|
|
163
192
|
});
|
|
164
|
-
console.log(result.type);
|
|
165
|
-
console.log(result.amount);
|
|
193
|
+
console.log(result.type); // "partial"
|
|
194
|
+
console.log(result.amount); // "50000000"
|
|
195
|
+
|
|
196
|
+
// Partial withdrawal split proportionally across all agents
|
|
197
|
+
// e.g. zyfai=$5, sail=$2, amount=$4 → zyfai withdraws $3, sail withdraws $1
|
|
198
|
+
const split = await sdk.withdraw({ asset: "USDC", amount: "4000000" });
|
|
199
|
+
console.log(split.agentResult.zyfai.amount); // "3000000"
|
|
200
|
+
console.log(split.agentResult.sail.amount); // "1000000"
|
|
166
201
|
|
|
167
202
|
// Full withdrawal from all agents
|
|
168
203
|
const results = await sdk.withdraw({ asset: "USDC" });
|
|
169
|
-
console.log(results.agentResult.zyfai.type);
|
|
170
|
-
console.log(results.agentResult.sail.type);
|
|
204
|
+
console.log(results.agentResult.zyfai.type); // "full"
|
|
205
|
+
console.log(results.agentResult.sail.type); // "full"
|
|
171
206
|
```
|
|
172
207
|
|
|
173
208
|
### `getBalances(agentId?)`
|
|
174
209
|
|
|
175
210
|
Get the user's balances for a specific agent, or aggregated across all agents.
|
|
176
211
|
|
|
177
|
-
| Param
|
|
178
|
-
|
|
212
|
+
| Param | Type | Description |
|
|
213
|
+
| --------- | ------------------------------ | ------------------------------------ |
|
|
179
214
|
| `agentId` | `"zyfai" \| "sail"` (optional) | Agent to query. Omit for all agents. |
|
|
180
215
|
|
|
181
216
|
Returns: `AgentBalance` (single agent) or `OwneyBalances` (all agents)
|
|
@@ -183,23 +218,23 @@ Returns: `AgentBalance` (single agent) or `OwneyBalances` (all agents)
|
|
|
183
218
|
```typescript
|
|
184
219
|
// Single agent
|
|
185
220
|
const balance = await sdk.getBalances("zyfai");
|
|
186
|
-
console.log(balance.totalBalance);
|
|
187
|
-
console.log(balance.smartWallet);
|
|
188
|
-
console.log(balance.tokens);
|
|
221
|
+
console.log(balance.totalBalance); // "150.25"
|
|
222
|
+
console.log(balance.smartWallet); // "0x..."
|
|
223
|
+
console.log(balance.tokens); // [{ chain: "BASE", chainId: 8453, asset: "USDC", amount: "150.25" }]
|
|
189
224
|
|
|
190
225
|
// All agents
|
|
191
226
|
const allBalances = await sdk.getBalances();
|
|
192
|
-
console.log(allBalances.totalBalance);
|
|
227
|
+
console.log(allBalances.totalBalance); // "300.50"
|
|
193
228
|
console.log(allBalances.agentBalances.zyfai.totalBalance); // "150.25"
|
|
194
|
-
console.log(allBalances.agentBalances.sail.totalBalance);
|
|
229
|
+
console.log(allBalances.agentBalances.sail.totalBalance); // "150.25"
|
|
195
230
|
```
|
|
196
231
|
|
|
197
232
|
### `getEarnings(agentId?)`
|
|
198
233
|
|
|
199
234
|
Get the user's on-chain earnings for a specific agent, or aggregated across all agents.
|
|
200
235
|
|
|
201
|
-
| Param
|
|
202
|
-
|
|
236
|
+
| Param | Type | Description |
|
|
237
|
+
| --------- | ------------------------------ | ------------------------------------ |
|
|
203
238
|
| `agentId` | `"zyfai" \| "sail"` (optional) | Agent to query. Omit for all agents. |
|
|
204
239
|
|
|
205
240
|
Returns: `AgentEarnings` (single agent) or `OwneyEarnings` (all agents)
|
|
@@ -207,12 +242,12 @@ Returns: `AgentEarnings` (single agent) or `OwneyEarnings` (all agents)
|
|
|
207
242
|
```typescript
|
|
208
243
|
// Single agent
|
|
209
244
|
const earnings = await sdk.getEarnings("zyfai");
|
|
210
|
-
console.log(earnings.smartWallet);
|
|
211
|
-
console.log(earnings.lifetimeEarnings);
|
|
245
|
+
console.log(earnings.smartWallet); // "0x..."
|
|
246
|
+
console.log(earnings.lifetimeEarnings); // 42.5
|
|
212
247
|
|
|
213
248
|
// All agents
|
|
214
249
|
const allEarnings = await sdk.getEarnings();
|
|
215
|
-
console.log(allEarnings.totalEarnings);
|
|
250
|
+
console.log(allEarnings.totalEarnings); // "85.0"
|
|
216
251
|
console.log(allEarnings.agentEarnings.zyfai.lifetimeEarnings); // 42.5
|
|
217
252
|
```
|
|
218
253
|
|
|
@@ -220,37 +255,37 @@ console.log(allEarnings.agentEarnings.zyfai.lifetimeEarnings); // 42.5
|
|
|
220
255
|
|
|
221
256
|
Get the weighted APY for the user's account. When querying all agents, the total APY is a balance-weighted average.
|
|
222
257
|
|
|
223
|
-
| Param
|
|
224
|
-
|
|
258
|
+
| Param | Type | Description |
|
|
259
|
+
| --------- | ------------------------------ | ------------------------------------------------ |
|
|
225
260
|
| `agentId` | `"zyfai" \| "sail"` (optional) | Agent to query. Omit for balance-weighted total. |
|
|
226
|
-
| `days`
|
|
261
|
+
| `days` | `"7D" \| "14D" \| "30D"` | Lookback period |
|
|
227
262
|
|
|
228
263
|
Returns: `AccountAgentApy` (single agent) or `OwneyAccountApy` (all agents)
|
|
229
264
|
|
|
230
265
|
```typescript
|
|
231
266
|
// Single agent
|
|
232
267
|
const apy = await sdk.getAccountApy({ agentId: "zyfai", days: "30D" });
|
|
233
|
-
console.log(apy.walletAddress);
|
|
268
|
+
console.log(apy.walletAddress); // "0x..."
|
|
234
269
|
console.log(apy.weightedApyAfterFee); // 5.2
|
|
235
270
|
// Per chain + token breakdown, when the agent reports it
|
|
236
|
-
console.log(apy.weightedApyAfterFeeDetails?.apyPerAsset[8453]?.USDC);
|
|
271
|
+
console.log(apy.weightedApyAfterFeeDetails?.apyPerAsset[8453]?.USDC); // 5.4
|
|
237
272
|
|
|
238
273
|
// All agents (balance-weighted)
|
|
239
274
|
const allApy = await sdk.getAccountApy({ days: "30D" });
|
|
240
|
-
console.log(allApy.totalApy);
|
|
275
|
+
console.log(allApy.totalApy); // "5.6"
|
|
241
276
|
console.log(allApy.agentApy.zyfai.weightedApyAfterFee); // 6.0
|
|
242
|
-
console.log(allApy.agentApy.sail.weightedApyAfterFee);
|
|
277
|
+
console.log(allApy.agentApy.sail.weightedApyAfterFee); // 4.0
|
|
243
278
|
```
|
|
244
279
|
|
|
245
280
|
### `getHistory({ agentId?, filters? })`
|
|
246
281
|
|
|
247
282
|
Get transaction history for a specific agent, or all agents. When querying all agents, results are merged into a single list sorted by date (newest first). Each entry includes the originating `agent` and a `transactions` array with typed on-chain transaction details.
|
|
248
283
|
|
|
249
|
-
| Param
|
|
250
|
-
|
|
251
|
-
| `agentId`
|
|
252
|
-
| `filters.fromDate` | `string` (optional)
|
|
253
|
-
| `filters.toDate`
|
|
284
|
+
| Param | Type | Description |
|
|
285
|
+
| ------------------ | ------------------------------ | ------------------------------------ |
|
|
286
|
+
| `agentId` | `"zyfai" \| "sail"` (optional) | Agent to query. Omit for all agents. |
|
|
287
|
+
| `filters.fromDate` | `string` (optional) | Start date (`YYYY-MM-DD`) |
|
|
288
|
+
| `filters.toDate` | `string` (optional) | End date (`YYYY-MM-DD`) |
|
|
254
289
|
|
|
255
290
|
Returns: `OwneyAgentHistory`
|
|
256
291
|
|
|
@@ -260,65 +295,65 @@ const history = await sdk.getHistory({
|
|
|
260
295
|
agentId: "zyfai",
|
|
261
296
|
filters: { fromDate: "2025-01-01" },
|
|
262
297
|
});
|
|
263
|
-
console.log(history.total);
|
|
264
|
-
console.log(history.data[0].agent);
|
|
265
|
-
console.log(history.data[0].action);
|
|
266
|
-
console.log(history.data[0].date);
|
|
267
|
-
console.log(history.data[0].transactions[0].txHashes);
|
|
268
|
-
console.log(history.data[0].transactions[0].amount);
|
|
298
|
+
console.log(history.total); // 42
|
|
299
|
+
console.log(history.data[0].agent); // "zyfai"
|
|
300
|
+
console.log(history.data[0].action); // "Rebalance"
|
|
301
|
+
console.log(history.data[0].date); // "2025-03-15T12:00:00Z"
|
|
302
|
+
console.log(history.data[0].transactions[0].txHashes); // ["0x..."]
|
|
303
|
+
console.log(history.data[0].transactions[0].amount); // "100.00"
|
|
269
304
|
console.log(history.data[0].transactions[0].tokenSymbol); // "USDC"
|
|
270
305
|
|
|
271
306
|
// Rebalance logs show fund movement between protocols
|
|
272
307
|
console.log(history.data[0].rebalanceLog[0].fromProtocol); // "Aave V3"
|
|
273
|
-
console.log(history.data[0].rebalanceLog[0].toProtocol);
|
|
274
|
-
console.log(history.data[0].rebalanceLog[0].tokenSymbol);
|
|
275
|
-
console.log(history.data[0].rebalanceLog[0].amount);
|
|
276
|
-
console.log(history.data[0].rebalanceLog[0].status);
|
|
308
|
+
console.log(history.data[0].rebalanceLog[0].toProtocol); // "Morpho Blue"
|
|
309
|
+
console.log(history.data[0].rebalanceLog[0].tokenSymbol); // "USDC"
|
|
310
|
+
console.log(history.data[0].rebalanceLog[0].amount); // "100.00"
|
|
311
|
+
console.log(history.data[0].rebalanceLog[0].status); // "success"
|
|
277
312
|
|
|
278
313
|
// All agents (merged and sorted by date)
|
|
279
314
|
const allHistory = await sdk.getHistory();
|
|
280
|
-
console.log(allHistory.total);
|
|
281
|
-
console.log(allHistory.data[0].agent);
|
|
282
|
-
console.log(allHistory.data[0].action);
|
|
315
|
+
console.log(allHistory.total); // 57
|
|
316
|
+
console.log(allHistory.data[0].agent); // "sail" (most recent entry)
|
|
317
|
+
console.log(allHistory.data[0].action); // "Rebalance"
|
|
283
318
|
```
|
|
284
319
|
|
|
285
320
|
### `pauseAgent(agentId)`
|
|
286
321
|
|
|
287
322
|
Pause an agent's automated operations. The agent will stop rebalancing until resumed.
|
|
288
323
|
|
|
289
|
-
| Param
|
|
290
|
-
|
|
324
|
+
| Param | Type | Description |
|
|
325
|
+
| --------- | ------------------- | -------------- |
|
|
291
326
|
| `agentId` | `"zyfai" \| "sail"` | Agent to pause |
|
|
292
327
|
|
|
293
328
|
Returns: `OwneyAgentStatus`
|
|
294
329
|
|
|
295
330
|
```typescript
|
|
296
331
|
const status = await sdk.pauseAgent("zyfai");
|
|
297
|
-
console.log(status.success);
|
|
332
|
+
console.log(status.success); // true
|
|
298
333
|
```
|
|
299
334
|
|
|
300
335
|
### `resumeAgent(agentId)`
|
|
301
336
|
|
|
302
337
|
Resume an agent's automated operations.
|
|
303
338
|
|
|
304
|
-
| Param
|
|
305
|
-
|
|
339
|
+
| Param | Type | Description |
|
|
340
|
+
| --------- | ------------------- | --------------- |
|
|
306
341
|
| `agentId` | `"zyfai" \| "sail"` | Agent to resume |
|
|
307
342
|
|
|
308
343
|
Returns: `OwneyAgentStatus`
|
|
309
344
|
|
|
310
345
|
```typescript
|
|
311
346
|
const status = await sdk.resumeAgent("zyfai");
|
|
312
|
-
console.log(status.success);
|
|
313
|
-
console.log(status.protocols);
|
|
347
|
+
console.log(status.success); // true
|
|
348
|
+
console.log(status.protocols); // ["aave", "compound"]
|
|
314
349
|
```
|
|
315
350
|
|
|
316
351
|
### `getUserProfile(agentId?)`
|
|
317
352
|
|
|
318
353
|
Get the user's profile for a specific agent, or all agents.
|
|
319
354
|
|
|
320
|
-
| Param
|
|
321
|
-
|
|
355
|
+
| Param | Type | Description |
|
|
356
|
+
| --------- | ------------------------------ | ------------------------------------ |
|
|
322
357
|
| `agentId` | `"zyfai" \| "sail"` (optional) | Agent to query. Omit for all agents. |
|
|
323
358
|
|
|
324
359
|
Returns: `AgentUserProfile` (single agent) or `OwneyUserProfile` (all agents)
|
|
@@ -326,28 +361,28 @@ Returns: `AgentUserProfile` (single agent) or `OwneyUserProfile` (all agents)
|
|
|
326
361
|
```typescript
|
|
327
362
|
// Single agent
|
|
328
363
|
const profile = await sdk.getUserProfile("zyfai");
|
|
329
|
-
console.log(profile.address);
|
|
330
|
-
console.log(profile.smartWallet);
|
|
331
|
-
console.log(profile.chains);
|
|
364
|
+
console.log(profile.address); // "0x..."
|
|
365
|
+
console.log(profile.smartWallet); // "0x..."
|
|
366
|
+
console.log(profile.chains); // [8453]
|
|
332
367
|
console.log(profile.hasActiveSessionKey); // true
|
|
333
|
-
console.log(profile.protocols);
|
|
368
|
+
console.log(profile.protocols); // ["aave", "compound"]
|
|
334
369
|
|
|
335
370
|
// All agents
|
|
336
371
|
const allProfiles = await sdk.getUserProfile();
|
|
337
372
|
console.log(allProfiles.agentUserProfile.zyfai.smartWallet); // "0x..."
|
|
338
|
-
console.log(allProfiles.agentUserProfile.sail.smartWallet);
|
|
373
|
+
console.log(allProfiles.agentUserProfile.sail.smartWallet); // "0x..."
|
|
339
374
|
```
|
|
340
375
|
|
|
341
376
|
### `getAgentApy({ agentId?, days, tokenSymbol?, chainId? })`
|
|
342
377
|
|
|
343
378
|
Get the agent's average APY performance over a time period. Does not require a wallet connection.
|
|
344
379
|
|
|
345
|
-
| Param
|
|
346
|
-
|
|
347
|
-
| `agentId`
|
|
348
|
-
| `days`
|
|
349
|
-
| `tokenSymbol` | `string` (optional)
|
|
350
|
-
| `chainId`
|
|
380
|
+
| Param | Type | Description |
|
|
381
|
+
| ------------- | ------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
382
|
+
| `agentId` | `"zyfai" \| "sail"` (optional) | Agent to query. Omit for all agents. |
|
|
383
|
+
| `days` | `"7D" \| "14D" \| "30D"` | Lookback period |
|
|
384
|
+
| `tokenSymbol` | `string` (optional) | Asset symbol (e.g. `"USDC"`, `"WETH"`). Scopes the upstream request to a specific asset when the agent's backend supports it. Zyfai forwards this; Sail currently ignores it at the API level. |
|
|
385
|
+
| `chainId` | `number` (optional) | Chain id. Typically paired with `tokenSymbol` for per-asset+chain APY. Zyfai forwards this; Sail currently ignores it at the API level. |
|
|
351
386
|
|
|
352
387
|
Returns: `AgentApy` (single agent) or `OwneyAgentApy` (all agents)
|
|
353
388
|
|
|
@@ -359,13 +394,13 @@ returns.
|
|
|
359
394
|
```typescript
|
|
360
395
|
// Single agent
|
|
361
396
|
const apy = await sdk.getAgentApy({ agentId: "zyfai", days: "30D" });
|
|
362
|
-
console.log(apy.averageApy);
|
|
397
|
+
console.log(apy.averageApy); // 8.5
|
|
363
398
|
console.log(apy.detailedApys?.apyPerAsset[8453]?.USDC); // 8.7
|
|
364
399
|
|
|
365
400
|
// All agents
|
|
366
401
|
const allApy = await sdk.getAgentApy({ days: "30D" });
|
|
367
402
|
console.log(allApy.agentApy.zyfai.averageApy); // 8.5
|
|
368
|
-
console.log(allApy.agentApy.sail.averageApy);
|
|
403
|
+
console.log(allApy.agentApy.sail.averageApy); // 6.2
|
|
369
404
|
console.log(allApy.agentApy.sail.detailedApys?.apyPerAsset[42161]?.USDT); // 6.4
|
|
370
405
|
|
|
371
406
|
// Scope the upstream query to USDC on Base (Zyfai-aware; Sail ignores the filter)
|
|
@@ -385,7 +420,7 @@ Returns: `OwneyAgentAllocation`
|
|
|
385
420
|
|
|
386
421
|
```typescript
|
|
387
422
|
const allocation = await sdk.getAgentAllocation();
|
|
388
|
-
console.log(allocation.agentAllocation);
|
|
423
|
+
console.log(allocation.agentAllocation); // { zyfai: 75, sail: 25 }
|
|
389
424
|
```
|
|
390
425
|
|
|
391
426
|
## Types
|
|
@@ -408,6 +443,10 @@ type AgentSupportedAssets = {
|
|
|
408
443
|
|
|
409
444
|
interface OwneySDKConfig {
|
|
410
445
|
apiKey: string;
|
|
446
|
+
zyfaiRpcUrls?: {
|
|
447
|
+
8453?: string;
|
|
448
|
+
42161?: string;
|
|
449
|
+
};
|
|
411
450
|
}
|
|
412
451
|
|
|
413
452
|
interface ConnectionState {
|
|
@@ -417,8 +456,8 @@ interface ConnectionState {
|
|
|
417
456
|
}
|
|
418
457
|
|
|
419
458
|
type HistoryFilters = {
|
|
420
|
-
fromDate?: string;
|
|
421
|
-
toDate?: string;
|
|
459
|
+
fromDate?: string; // YYYY-MM-DD
|
|
460
|
+
toDate?: string; // YYYY-MM-DD
|
|
422
461
|
};
|
|
423
462
|
|
|
424
463
|
type HistoryOptions = {
|
|
@@ -447,8 +486,8 @@ type AccountApyOptions = {
|
|
|
447
486
|
type AgentsApyOptions = {
|
|
448
487
|
agentId?: AgentId;
|
|
449
488
|
days: DailyApyDays;
|
|
450
|
-
tokenSymbol?: string;
|
|
451
|
-
chainId?: number;
|
|
489
|
+
tokenSymbol?: string; // e.g. "USDC", "WETH"
|
|
490
|
+
chainId?: number; // typically paired with tokenSymbol
|
|
452
491
|
};
|
|
453
492
|
```
|
|
454
493
|
|
|
@@ -605,7 +644,7 @@ type DepositCallback = (
|
|
|
605
644
|
|
|
606
645
|
### Error Handling
|
|
607
646
|
|
|
608
|
-
All errors thrown by the SDK are instances of `OwneyError` (which extends `Error`), each carrying a stable `code` string
|
|
647
|
+
All errors thrown by the SDK are instances of `OwneyError` (which extends `Error`), each carrying a stable `code` string, optional `details` object, and optional `agentId` identifying the originating agent. When `agentId` is set, `error.message` is also prefixed with `[agent:<id>]` for logs.
|
|
609
648
|
|
|
610
649
|
```typescript
|
|
611
650
|
import { OwneyError } from "@owney/sdk";
|
|
@@ -634,51 +673,55 @@ try {
|
|
|
634
673
|
```typescript
|
|
635
674
|
type OwneyErrorCode =
|
|
636
675
|
// Connection & wallet
|
|
637
|
-
| "NOT_CONNECTED"
|
|
638
|
-
| "NO_ACTIVE_CHAIN"
|
|
639
|
-
| "WALLET_NO_ACCOUNTS"
|
|
676
|
+
| "NOT_CONNECTED" // Wallet-dependent method called before connect()
|
|
677
|
+
| "NO_ACTIVE_CHAIN" // Method called before activateAgent()
|
|
678
|
+
| "WALLET_NO_ACCOUNTS" // Provider returned no accounts during connect()
|
|
640
679
|
| "WALLET_ADDRESS_REQUIRED" // Wallet address missing during agent auth
|
|
641
680
|
// Agent resolution
|
|
642
|
-
| "AGENT_NOT_FOUND"
|
|
681
|
+
| "AGENT_NOT_FOUND" // Unknown agent ID passed
|
|
643
682
|
| "AGENT_CHAIN_INCOMPATIBLE" // Agent(s) don't support the given chain
|
|
644
|
-
| "AGENT_EMPTY_LIST"
|
|
683
|
+
| "AGENT_EMPTY_LIST" // Empty agentId array passed to activateAgent()
|
|
645
684
|
// Chain
|
|
646
|
-
| "CHAIN_UNSUPPORTED"
|
|
647
|
-
| "CHAIN_NO_COMPATIBLE_AGENTS"
|
|
685
|
+
| "CHAIN_UNSUPPORTED" // Chain ID not in supported list (8453, 42161)
|
|
686
|
+
| "CHAIN_NO_COMPATIBLE_AGENTS" // No agents support the given chain
|
|
648
687
|
// Asset
|
|
649
|
-
| "ASSET_UNSUPPORTED"
|
|
650
|
-
| "ASSET_NO_COMPATIBLE_AGENTS"
|
|
688
|
+
| "ASSET_UNSUPPORTED" // Agent doesn't support the asset on the active chain
|
|
689
|
+
| "ASSET_NO_COMPATIBLE_AGENTS" // No agents support the asset on the active chain
|
|
651
690
|
// Deposit
|
|
652
|
-
| "
|
|
653
|
-
| "DEPOSIT_CALLBACK_REQUIRED"
|
|
654
|
-
| "DEPOSIT_CALLBACK_INVALID"
|
|
691
|
+
| "DEPOSIT_AMOUNT_BELOW_MINIMUM" // Amount below an agent's required minimum deposit
|
|
692
|
+
| "DEPOSIT_CALLBACK_REQUIRED" // Sail agent requires a depositCallback
|
|
693
|
+
| "DEPOSIT_CALLBACK_INVALID" // depositCallback didn't return a tx hash
|
|
655
694
|
| "DEPOSIT_NO_PERMITTED_TOKENS" // No permitted tokens available for deposit
|
|
656
695
|
// Withdraw
|
|
657
696
|
| "WITHDRAW_NO_PERMITTED_TOKENS" // No permitted tokens available for withdrawal
|
|
697
|
+
| "WITHDRAW_INSUFFICIENT_BALANCE" // Requested amount exceeds total available across agents
|
|
698
|
+
| "WITHDRAW_ALL_FAILED" // Every eligible agent's withdraw call failed
|
|
699
|
+
| "WITHDRAW_PARTIAL_FAILURE" // Some agents succeeded; total withdrawn < requested
|
|
658
700
|
// API
|
|
659
|
-
| "API_ROUTING_ERROR"
|
|
701
|
+
| "API_ROUTING_ERROR" // Routing API returned a non-OK HTTP status
|
|
660
702
|
| "API_ROUTING_FAILED" // Routing API returned { success: false }
|
|
661
|
-
| "API_SAIL_ERROR"
|
|
662
|
-
| "API_SAIL_TIMEOUT"
|
|
663
|
-
| "API_NO_AGENTS"
|
|
703
|
+
| "API_SAIL_ERROR" // Sail API returned a non-OK HTTP status
|
|
704
|
+
| "API_SAIL_TIMEOUT" // Sail API request timed out
|
|
705
|
+
| "API_NO_AGENTS" // No supported agents returned by routing API
|
|
664
706
|
// Aggregation
|
|
665
|
-
| "BALANCE_ALL_FAILED"
|
|
666
|
-
| "ALLOCATION_ALL_FAILED"
|
|
707
|
+
| "BALANCE_ALL_FAILED" // All agents failed to return balances
|
|
708
|
+
| "ALLOCATION_ALL_FAILED" // All agents failed to return allocation data
|
|
667
709
|
// Validation
|
|
668
710
|
| "VALIDATION_INVALID_DAYS"; // Invalid days value (expected "7D", "14D", or "30D")
|
|
669
711
|
|
|
670
712
|
class OwneyError extends Error {
|
|
671
713
|
readonly code: OwneyErrorCode;
|
|
672
714
|
readonly details?: Record<string, unknown>;
|
|
715
|
+
readonly agentId?: string;
|
|
673
716
|
}
|
|
674
717
|
```
|
|
675
718
|
|
|
676
719
|
The three convenience subclasses extend `OwneyError` and remain backwards-compatible:
|
|
677
720
|
|
|
678
|
-
| Class
|
|
679
|
-
|
|
680
|
-
| `NotConnectedError`
|
|
681
|
-
| `AgentNotFoundError`
|
|
721
|
+
| Class | Code | Extra properties |
|
|
722
|
+
| ----------------------------- | -------------------------- | ---------------------------------------- |
|
|
723
|
+
| `NotConnectedError` | `NOT_CONNECTED` | — |
|
|
724
|
+
| `AgentNotFoundError` | `AGENT_NOT_FOUND` | — |
|
|
682
725
|
| `AgentChainIncompatibleError` | `AGENT_CHAIN_INCOMPATIBLE` | `incompatibleAgents`, `connectedChainId` |
|
|
683
726
|
|
|
684
727
|
## License
|