@owney/sdk 0.2.9 → 0.2.11
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 +19 -6
- package/dist/index.cjs +173 -689
- package/dist/index.d.cts +7 -6
- package/dist/index.d.ts +7 -6
- package/dist/index.js +173 -689
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -167,6 +167,14 @@ console.log(results.agentResults.sail.amount); // "50000000"
|
|
|
167
167
|
|
|
168
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.
|
|
169
169
|
|
|
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
|
+
|
|
170
178
|
| Param | Type | Description |
|
|
171
179
|
| ----------------- | -------------------- | --------------------------------------------- |
|
|
172
180
|
| `options.asset` | `string` | Asset symbol (e.g. `"USDC"`) |
|
|
@@ -185,6 +193,12 @@ const result = await sdk.withdraw({
|
|
|
185
193
|
console.log(result.type); // "partial"
|
|
186
194
|
console.log(result.amount); // "50000000"
|
|
187
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"
|
|
201
|
+
|
|
188
202
|
// Full withdrawal from all agents
|
|
189
203
|
const results = await sdk.withdraw({ asset: "USDC" });
|
|
190
204
|
console.log(results.agentResult.zyfai.type); // "full"
|
|
@@ -608,11 +622,6 @@ interface OwneyAgentApy {
|
|
|
608
622
|
agentApy: Record<AgentId, AgentApy>;
|
|
609
623
|
}
|
|
610
624
|
|
|
611
|
-
interface OwneyRouteResponse {
|
|
612
|
-
agent: AgentId;
|
|
613
|
-
chainId: number;
|
|
614
|
-
}
|
|
615
|
-
|
|
616
625
|
interface OwneyAgentAllocation {
|
|
617
626
|
agentAllocation: Record<AgentId, number>;
|
|
618
627
|
}
|
|
@@ -630,7 +639,7 @@ type DepositCallback = (
|
|
|
630
639
|
|
|
631
640
|
### Error Handling
|
|
632
641
|
|
|
633
|
-
All errors thrown by the SDK are instances of `OwneyError` (which extends `Error`), each carrying a stable `code` string
|
|
642
|
+
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.
|
|
634
643
|
|
|
635
644
|
```typescript
|
|
636
645
|
import { OwneyError } from "@owney/sdk";
|
|
@@ -680,6 +689,9 @@ type OwneyErrorCode =
|
|
|
680
689
|
| "DEPOSIT_NO_PERMITTED_TOKENS" // No permitted tokens available for deposit
|
|
681
690
|
// Withdraw
|
|
682
691
|
| "WITHDRAW_NO_PERMITTED_TOKENS" // No permitted tokens available for withdrawal
|
|
692
|
+
| "WITHDRAW_INSUFFICIENT_BALANCE" // Requested amount exceeds total available across agents
|
|
693
|
+
| "WITHDRAW_ALL_FAILED" // Every eligible agent's withdraw call failed
|
|
694
|
+
| "WITHDRAW_PARTIAL_FAILURE" // Some agents succeeded; total withdrawn < requested
|
|
683
695
|
// API
|
|
684
696
|
| "API_ROUTING_ERROR" // Routing API returned a non-OK HTTP status
|
|
685
697
|
| "API_ROUTING_FAILED" // Routing API returned { success: false }
|
|
@@ -695,6 +707,7 @@ type OwneyErrorCode =
|
|
|
695
707
|
class OwneyError extends Error {
|
|
696
708
|
readonly code: OwneyErrorCode;
|
|
697
709
|
readonly details?: Record<string, unknown>;
|
|
710
|
+
readonly agentId?: string;
|
|
698
711
|
}
|
|
699
712
|
```
|
|
700
713
|
|