@owney/sdk 0.2.6 → 0.2.8
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 +76 -6
- package/dist/index.cjs +196 -208
- package/dist/index.d.cts +18 -4
- package/dist/index.d.ts +18 -4
- package/dist/index.js +195 -208
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -603,13 +603,83 @@ type DepositCallback = (
|
|
|
603
603
|
) => Promise<`0x${string}`> | `0x${string}`;
|
|
604
604
|
```
|
|
605
605
|
|
|
606
|
-
### Error
|
|
606
|
+
### Error Handling
|
|
607
607
|
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
608
|
+
All errors thrown by the SDK are instances of `OwneyError` (which extends `Error`), each carrying a stable `code` string and optional `details` object for programmatic handling.
|
|
609
|
+
|
|
610
|
+
```typescript
|
|
611
|
+
import { OwneyError } from "@owney/sdk";
|
|
612
|
+
|
|
613
|
+
try {
|
|
614
|
+
await sdk.getBalances();
|
|
615
|
+
} catch (error) {
|
|
616
|
+
if (error instanceof OwneyError) {
|
|
617
|
+
switch (error.code) {
|
|
618
|
+
case "NOT_CONNECTED":
|
|
619
|
+
// prompt user to connect wallet
|
|
620
|
+
break;
|
|
621
|
+
case "NO_ACTIVE_CHAIN":
|
|
622
|
+
// prompt user to activate an agent
|
|
623
|
+
break;
|
|
624
|
+
case "BALANCE_ALL_FAILED":
|
|
625
|
+
// all agents failed to return balances
|
|
626
|
+
break;
|
|
627
|
+
default:
|
|
628
|
+
console.error(`[${error.code}] ${error.message}`, error.details);
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
```
|
|
633
|
+
|
|
634
|
+
```typescript
|
|
635
|
+
type OwneyErrorCode =
|
|
636
|
+
// Connection & wallet
|
|
637
|
+
| "NOT_CONNECTED" // Wallet-dependent method called before connect()
|
|
638
|
+
| "NO_ACTIVE_CHAIN" // Method called before activateAgent()
|
|
639
|
+
| "WALLET_NO_ACCOUNTS" // Provider returned no accounts during connect()
|
|
640
|
+
| "WALLET_ADDRESS_REQUIRED" // Wallet address missing during agent auth
|
|
641
|
+
// Agent resolution
|
|
642
|
+
| "AGENT_NOT_FOUND" // Unknown agent ID passed
|
|
643
|
+
| "AGENT_CHAIN_INCOMPATIBLE" // Agent(s) don't support the given chain
|
|
644
|
+
| "AGENT_EMPTY_LIST" // Empty agentId array passed to activateAgent()
|
|
645
|
+
// Chain
|
|
646
|
+
| "CHAIN_UNSUPPORTED" // Chain ID not in supported list (8453, 42161)
|
|
647
|
+
| "CHAIN_NO_COMPATIBLE_AGENTS" // No agents support the given chain
|
|
648
|
+
// Asset
|
|
649
|
+
| "ASSET_UNSUPPORTED" // Agent doesn't support the asset on the active chain
|
|
650
|
+
| "ASSET_NO_COMPATIBLE_AGENTS" // No agents support the asset on the active chain
|
|
651
|
+
// Deposit
|
|
652
|
+
| "DEPOSIT_AMOUNT_TOO_SMALL" // Amount too small to split across agents
|
|
653
|
+
| "DEPOSIT_CALLBACK_REQUIRED" // Sail agent requires a depositCallback
|
|
654
|
+
| "DEPOSIT_CALLBACK_INVALID" // depositCallback didn't return a tx hash
|
|
655
|
+
| "DEPOSIT_NO_PERMITTED_TOKENS" // No permitted tokens available for deposit
|
|
656
|
+
// Withdraw
|
|
657
|
+
| "WITHDRAW_NO_PERMITTED_TOKENS" // No permitted tokens available for withdrawal
|
|
658
|
+
// API
|
|
659
|
+
| "API_ROUTING_ERROR" // Routing API returned a non-OK HTTP status
|
|
660
|
+
| "API_ROUTING_FAILED" // Routing API returned { success: false }
|
|
661
|
+
| "API_SAIL_ERROR" // Sail API returned a non-OK HTTP status
|
|
662
|
+
| "API_SAIL_TIMEOUT" // Sail API request timed out
|
|
663
|
+
| "API_NO_AGENTS" // No supported agents returned by routing API
|
|
664
|
+
// Aggregation
|
|
665
|
+
| "BALANCE_ALL_FAILED" // All agents failed to return balances
|
|
666
|
+
| "ALLOCATION_ALL_FAILED" // All agents failed to return allocation data
|
|
667
|
+
// Validation
|
|
668
|
+
| "VALIDATION_INVALID_DAYS"; // Invalid days value (expected "7D", "14D", or "30D")
|
|
669
|
+
|
|
670
|
+
class OwneyError extends Error {
|
|
671
|
+
readonly code: OwneyErrorCode;
|
|
672
|
+
readonly details?: Record<string, unknown>;
|
|
673
|
+
}
|
|
674
|
+
```
|
|
675
|
+
|
|
676
|
+
The three convenience subclasses extend `OwneyError` and remain backwards-compatible:
|
|
677
|
+
|
|
678
|
+
| Class | Code | Extra properties |
|
|
679
|
+
|-------|------|------------------|
|
|
680
|
+
| `NotConnectedError` | `NOT_CONNECTED` | — |
|
|
681
|
+
| `AgentNotFoundError` | `AGENT_NOT_FOUND` | — |
|
|
682
|
+
| `AgentChainIncompatibleError` | `AGENT_CHAIN_INCOMPATIBLE` | `incompatibleAgents`, `connectedChainId` |
|
|
613
683
|
|
|
614
684
|
## License
|
|
615
685
|
|