@owney/sdk 0.7.22-beta.1 → 0.7.23-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
@@ -1,5 +1,135 @@
1
1
  import { SIWXConfig } from '@reown/appkit-controllers';
2
2
 
3
+ /**
4
+ * Swap-to-yield types (ROUT-242).
5
+ *
6
+ * The SDK never talks to 1inch directly — the API key is a paid credential and
7
+ * lives in the routing API. Everything here describes the routing API's
8
+ * `/api/v1/swap/*` contract.
9
+ */
10
+ /**
11
+ * Which rail a swap rides, decided server-side from the chains.
12
+ *
13
+ * `classic` — same chain. One atomic transaction: it either completes or
14
+ * nothing moved.
15
+ *
16
+ * `fusion-plus` — crossing chains. The user's funds sit in an escrow while a
17
+ * resolver fills the other side, so the order has a lifecycle and can end in
18
+ * `expired` → `refunding` → `refunded` without ever depositing.
19
+ */
20
+ type SwapRail = "classic" | "fusion-plus";
21
+ type SwapTokenInfo = {
22
+ readonly symbol: string;
23
+ readonly address: string;
24
+ readonly decimals: number;
25
+ /** Native asset (ETH). A swap SOURCE only — never a deposit target. */
26
+ readonly isNative?: true;
27
+ };
28
+ type SwapChainTokens = {
29
+ readonly chainId: number;
30
+ /** What the user may pay with. */
31
+ readonly sources: readonly SwapTokenInfo[];
32
+ /** What a swap may resolve into — what Owney actually deposits. */
33
+ readonly depositTargets: readonly SwapTokenInfo[];
34
+ };
35
+ type SwapQuote = {
36
+ rail: SwapRail;
37
+ src: {
38
+ chainId: number;
39
+ symbol: string;
40
+ address: string;
41
+ amount: string;
42
+ };
43
+ dst: {
44
+ chainId: number;
45
+ symbol: string;
46
+ address: string;
47
+ amount: string;
48
+ };
49
+ /**
50
+ * Worst-case output once the Dutch auction has fully decayed. Gate minimum
51
+ * deposit checks on THIS, not `dst.amount` — a fill at auction end that lands
52
+ * under the agent's floor would leave the user swapped but not deposited.
53
+ */
54
+ dstAmountMin: string;
55
+ /** Cross-chain only. Per-order escrow schedule in seconds, set by 1inch. */
56
+ timeLocks?: Record<string, number>;
57
+ /**
58
+ * Cross-chain only. How many preimages to mint before building an order.
59
+ * Building with the wrong number produces escrows the user's secrets cannot
60
+ * unlock, stranding the swap until its cancellation timelock.
61
+ */
62
+ secretsCount?: number;
63
+ /**
64
+ * Cross-chain only. The contract the source token must be approved to (the
65
+ * 1inch Limit Order Protocol) before a resolver can fill the order.
66
+ *
67
+ * Absent on the classic rail, where the router address arrives with the swap
68
+ * calldata instead.
69
+ */
70
+ spender?: string;
71
+ /**
72
+ * True only for a cross-chain swap FROM native ETH, which needs an on-chain
73
+ * order creation carrying the full amount as msg.value. The user's funds
74
+ * leave the wallet before any fill, so the UI must say so. ERC-20 sources are
75
+ * signature-only after their one-time approval.
76
+ */
77
+ requiresOnchainOrder: boolean;
78
+ /**
79
+ * What the swap costs, as the provider reports it on this quote.
80
+ *
81
+ * Surfaced rather than derived: a fee the UI computes from its own constant
82
+ * drifts from the one actually charged the moment the two disagree, and they
83
+ * did — the integrator fee was configured on our side for days while the
84
+ * provider had it switched off, so the real charge was zero.
85
+ *
86
+ * Cross-chain only. The classic rail reports no breakdown.
87
+ */
88
+ feeInfo?: {
89
+ /** Owney's cut. Absent until a fee receiver is configured. */
90
+ integratorFee?: {
91
+ receiver: string;
92
+ bps: number;
93
+ share: number;
94
+ };
95
+ /** The filler's cut, charged either way. */
96
+ resolverFee?: {
97
+ receiver: string;
98
+ bps: number;
99
+ };
100
+ };
101
+ /**
102
+ * Owney's cut in basis points, for display.
103
+ *
104
+ * Distinct from `feeInfo`, which is what the provider measured on this
105
+ * quote. When the provider applies the fee at settlement it reports nothing
106
+ * here, and this carries the agreed figure instead so the UI can still name
107
+ * one. Stated, not verified.
108
+ */
109
+ integratorFeeBps?: number;
110
+ };
111
+ /**
112
+ * Terminal states are `executed`, `expired`, `cancelled` and `refunded`.
113
+ * `refunding` is the window the returning-funds screen renders: the order has
114
+ * failed and the money is on its way back, but is not back yet.
115
+ */
116
+ type SwapOrderStatus = "pending" | "executed" | "expired" | "cancelled" | "refunding" | "refunded" | "unpublished";
117
+ /** Stage reported to the UI while a swap-and-deposit runs. */
118
+ type SwapStage = "quoting" | "approving" | "signing" | "swapping" | "swapped" | "depositing" | "refunding" | "refunded";
119
+ type SwapQuoteParams = {
120
+ /** Asset the user is paying WITH. */
121
+ from: {
122
+ chainId: number;
123
+ symbol: string;
124
+ amount: string;
125
+ };
126
+ /** Deposit target. Must be an asset Owney can actually deposit. */
127
+ to: {
128
+ chainId: number;
129
+ symbol: string;
130
+ };
131
+ };
132
+
3
133
  type ZyfaiRpcUrlsConfig = Partial<Record<(typeof SUPPORTED_CHAIN_IDS)[number], string>>;
4
134
  interface OwneySDKConfig {
5
135
  apiKey: string;
@@ -54,7 +184,7 @@ type OwneySupportedChainId = (typeof SUPPORTED_CHAIN_IDS)[number];
54
184
  type OwneySupportedChains = (typeof SUPPORTED_CHAINS)[number];
55
185
  type OwneySupportedTokens = (typeof SUPPORTED_TOKENS)[number];
56
186
 
57
- type AgentId = "zyfai" | "surfliquid";
187
+ type AgentId = "zyfai";
58
188
  type Asset = string;
59
189
  type AgentSupportedAsset = {
60
190
  readonly symbol: string;
@@ -182,12 +312,6 @@ interface OwneyDepositResult {
182
312
  }
183
313
  interface OwneyMultiDepositResult {
184
314
  agentResults: Record<string, OwneyDepositResult>;
185
- /**
186
- * Per-agent failure messages for agents that errored during a diversified
187
- * deposit. Present only when at least one (but not all) agents failed —
188
- * the deposit is partial, not total. Omitted when every agent succeeded.
189
- */
190
- agentErrors?: Record<string, string>;
191
315
  }
192
316
  interface AgentWithdrawResult {
193
317
  txHash?: string;
@@ -635,17 +759,83 @@ declare class OwneySDK {
635
759
  private hasExistingBalance;
636
760
  private validateAssetSupport;
637
761
  private getEligibleAgents;
762
+ /** Lazily built so an app that never swaps pays nothing for it. */
763
+ private swapApiClient?;
764
+ private swapApi;
765
+ /**
766
+ * Put the wallet on `chainId`, or fail with something actionable.
767
+ *
768
+ * Reuses the same guard the deposit rail uses, which re-reads the chain after
769
+ * switching — some wallets resolve wallet_switchEthereumChain before the
770
+ * network has actually changed.
771
+ */
772
+ private ensureSwapChain;
773
+ /**
774
+ * Binds the executor's abstract deps to this client's wallet.
775
+ *
776
+ * Kept as a builder rather than baked into the executor so the whole swap
777
+ * flow stays testable without a provider — the executor never imports viem.
778
+ */
779
+ private buildSwapDeps;
780
+ /**
781
+ * Assets the user may pay with, and what each chain deposits into.
782
+ *
783
+ * The source list is deliberately wider than the deposit list: it includes
784
+ * native ETH and USDT, which Owney never holds but users often do.
785
+ */
786
+ getSwapTokens(): Promise<{
787
+ chains: SwapChainTokens[];
788
+ }>;
638
789
  /**
639
- * Agent ids the routing API provisioned for this org that support the given
640
- * chain + asset, ordered by preference ({@link AGENT_ELIGIBILITY_ORDER},
641
- * surfliquid first). Returns `[]` when the org has no compatible agent — never
642
- * throws on an empty org. Loads agent keys on first call (apiKey only, no
643
- * wallet), so the UI can resolve which agent to use before the user connects.
790
+ * Price a swap without committing to it.
644
791
  *
645
- * This is the source of truth for agent availability: an agent appears here
646
- * iff the routing API returned its key. No per-app feature flags.
792
+ * `dstAmountMin` is the number to validate against a deposit minimum —
793
+ * `dst.amount` is an estimate that a decaying auction or slippage can undercut,
794
+ * and a swap landing below the floor leaves the user swapped but not
795
+ * deposited.
647
796
  */
648
- getEligibleAgentIds(chainId: number, asset: string): Promise<AgentId[]>;
797
+ getSwapQuote(params: SwapQuoteParams): Promise<SwapQuote>;
798
+ /**
799
+ * Swap an asset the user holds into a deposit asset, then deposit it.
800
+ *
801
+ * Kept separate from `deposit()` rather than bolted on as an option: the
802
+ * return shape differs, the staging callback is meaningless on the plain
803
+ * path, and integrators who never swap should not have to reason about any
804
+ * of it.
805
+ *
806
+ * The deposit runs on the MEASURED arrival, not the quote. A quote is an
807
+ * estimate, so depositing the quoted figure would either strand dust or try
808
+ * to move funds that never came.
809
+ *
810
+ * Failure modes differ in a way callers must respect. A same-chain swap is
811
+ * atomic — if it fails, nothing moved. A cross-chain swap escrows the user's
812
+ * funds first, so SWAP_ORDER_EXPIRED / REFUNDED / CANCELLED all mean the
813
+ * money left the wallet. Only the former can honestly say "nothing has left
814
+ * your wallet".
815
+ */
816
+ swapAndDeposit(options: {
817
+ from: {
818
+ chainId: number;
819
+ symbol: string;
820
+ amount: string;
821
+ };
822
+ /** Deposit target. Defaults to the active chain's asset when omitted. */
823
+ to: {
824
+ chainId: number;
825
+ symbol: string;
826
+ };
827
+ agentId?: AgentId;
828
+ /** Percent, classic rail only. Fusion+ prices through its auction. */
829
+ slippage?: number;
830
+ onSwapProgress?: (stage: SwapStage) => void;
831
+ }): Promise<{
832
+ swap: {
833
+ received: string;
834
+ orderHash?: string;
835
+ txHash?: string;
836
+ };
837
+ deposit: OwneyDepositResult | OwneyMultiDepositResult;
838
+ }>;
649
839
  /**
650
840
  * Withdraw funds from a specific agent, or all agents that support the active chain+asset if agentId is omitted.
651
841
  * Validates that the asset is supported by the target agent(s) on the active chain.
@@ -746,7 +936,7 @@ declare class OwneySDK {
746
936
  getAllocationApy({ agentId, }?: AllocationApyOptions): Promise<OwneyAllocationApy>;
747
937
  }
748
938
 
749
- type OwneyErrorCode = "NOT_CONNECTED" | "NO_ACTIVE_CHAIN" | "WALLET_NO_ACCOUNTS" | "WALLET_ADDRESS_REQUIRED" | "WALLET_NOT_DEPLOYED" | "AGENT_NOT_FOUND" | "AGENT_CHAIN_INCOMPATIBLE" | "AGENT_EMPTY_LIST" | "AGENT_DISABLED" | "CHAIN_UNSUPPORTED" | "CHAIN_NO_COMPATIBLE_AGENTS" | "CHAIN_MISMATCH" | "ASSET_UNSUPPORTED" | "ASSET_NO_COMPATIBLE_AGENTS" | "DEPOSIT_BALANCE_UNAVAILABLE" | "DEPOSIT_PARTIAL_FAILURE" | "DEPOSIT_AMOUNT_BELOW_MINIMUM" | "DEPOSIT_CALLBACK_REQUIRED" | "DEPOSIT_CALLBACK_INVALID" | "DEPOSIT_NO_PERMITTED_TOKENS" | "DEPOSIT_ALL_FAILED" | "DEPOSIT_INSUFFICIENT_BALANCE" | "WITHDRAW_NO_PERMITTED_TOKENS" | "WITHDRAW_INSUFFICIENT_BALANCE" | "WITHDRAW_ALL_FAILED" | "WITHDRAW_PARTIAL_FAILURE" | "WITHDRAW_FAILED" | "AGENT_RATE_LIMITED" | "API_ROUTING_ERROR" | "API_ROUTING_FAILED" | "API_NO_AGENTS" | "SPONSOR_REQUEST_FAILED" | "PERMIT2_APPROVAL_REQUIRED" | "SPONSORED_CALLS_UNSUPPORTED" | "SPONSORED_CALLS_NO_ID" | "SPONSORED_CALLS_NO_RECEIPT" | "SURF_UNAVAILABLE" | "SPONSORSHIP_UNAVAILABLE" | "USER_REJECTED" | "OPERATION_PENDING" | "VAULT_NOT_SPONSORABLE" | "BALANCE_ALL_FAILED" | "ALLOCATION_ALL_FAILED" | "VALIDATION_INVALID_DAYS";
939
+ type OwneyErrorCode = "NOT_CONNECTED" | "NO_ACTIVE_CHAIN" | "WALLET_NO_ACCOUNTS" | "WALLET_ADDRESS_REQUIRED" | "WALLET_NOT_DEPLOYED" | "AGENT_NOT_FOUND" | "AGENT_CHAIN_INCOMPATIBLE" | "AGENT_EMPTY_LIST" | "AGENT_DISABLED" | "CHAIN_UNSUPPORTED" | "CHAIN_NO_COMPATIBLE_AGENTS" | "CHAIN_MISMATCH" | "ASSET_UNSUPPORTED" | "ASSET_NO_COMPATIBLE_AGENTS" | "DEPOSIT_BALANCE_UNAVAILABLE" | "DEPOSIT_PARTIAL_FAILURE" | "DEPOSIT_AMOUNT_BELOW_MINIMUM" | "DEPOSIT_CALLBACK_REQUIRED" | "DEPOSIT_CALLBACK_INVALID" | "DEPOSIT_NO_PERMITTED_TOKENS" | "DEPOSIT_INSUFFICIENT_BALANCE" | "WITHDRAW_NO_PERMITTED_TOKENS" | "WITHDRAW_INSUFFICIENT_BALANCE" | "WITHDRAW_ALL_FAILED" | "WITHDRAW_PARTIAL_FAILURE" | "WITHDRAW_FAILED" | "AGENT_RATE_LIMITED" | "API_ROUTING_ERROR" | "API_ROUTING_FAILED" | "API_NO_AGENTS" | "SPONSOR_REQUEST_FAILED" | "PERMIT2_APPROVAL_REQUIRED" | "SPONSORED_CALLS_UNSUPPORTED" | "SPONSORED_CALLS_NO_ID" | "SPONSORED_CALLS_NO_RECEIPT" | "SWAP_DISABLED" | "SWAP_RATE_LIMITED" | "SWAP_REQUEST_FAILED" | "SWAP_QUOTE_FAILED" | "SWAP_UNSUPPORTED_PAIR" | "SWAP_APPROVAL_REQUIRED" | "SWAP_BELOW_DEPOSIT_MINIMUM" | "SWAP_ORDER_EXPIRED" | "SWAP_ORDER_REFUNDED" | "SWAP_ORDER_CANCELLED" | "BALANCE_ALL_FAILED" | "ALLOCATION_ALL_FAILED" | "VALIDATION_INVALID_DAYS";
750
940
  declare class OwneyError extends Error {
751
941
  readonly code: OwneyErrorCode;
752
942
  readonly details?: Record<string, unknown>;
@@ -812,4 +1002,40 @@ type OwneySIWXConfig = {
812
1002
  */
813
1003
  declare function createOwneySIWX(config: OwneySIWXConfig): SIWXConfig;
814
1004
 
815
- export { type AccountAgentApy, type AccountApyOptions, type AgentApy, type AgentApyDetails, type AgentBalance, AgentChainIncompatibleError, type AgentEarnings, type AgentHistoryEntry, type AgentHistoryPosition, type AgentId, AgentNotFoundError, type AgentSupportedAsset, type AgentSupportedAssets, type AgentUserProfile, type AgentWithdrawResult, type AgentsApyOptions, type AllocationAgentApy, type AllocationApyOptions, type ApyByChainAndAsset, type ApyHistoryPoint, type Asset, type AvailableAgent, type AvailableAgentsOptions, type ConnectionState, type DailyApyDays, type DepositCallback, type DepositOptions, type HistoryAction, type HistoryFilters, type HistoryOptions, type HistoryTransaction, type IAgent, InvalidHistoryCursorError, NotConnectedError, type OwneyAccountApy, type OwneyAgentApy, type OwneyAgentHistory, type OwneyAllocationApy, type OwneyBalances, type OwneyDepositResult, type OwneyEarnings, OwneyError, type OwneyErrorCode, type OwneyMultiDepositResult, type OwneyPosition, OwneySDK, type OwneySDKConfig, type OwneySIWXConfig, type OwneySupportedChainId, type OwneySupportedChains, type OwneySupportedTokens, type OwneyToken, type OwneyUserProfile, type OwneyWithdrawResult, type RebalanceLog, type WithdrawOptions, createOwneySIWX, setOwneyDebug };
1005
+ /**
1006
+ * Persists cross-chain swap secrets so an in-flight order survives a reload.
1007
+ *
1008
+ * This is not a convenience. A Fusion+ order is only completable by whoever
1009
+ * holds the secret preimages: the resolver deploys escrows, then waits for the
1010
+ * secret before it can claim and release funds to the user. Lose the secrets
1011
+ * mid-order and the swap cannot complete — the user waits out the cancellation
1012
+ * timelock for a refund instead.
1013
+ *
1014
+ * That matters here because the UI explicitly tells the user "you can safely
1015
+ * close this window", so surviving a reload is a requirement, not a nicety.
1016
+ *
1017
+ * Trade-off: the same one `zyfai.auth-cache` makes. Secrets in `localStorage`
1018
+ * are exposed to XSS, but they are single-use, worthless once the order
1019
+ * settles, and only ever unlock funds back to the user's own wallet.
1020
+ */
1021
+ type StoredOrder = {
1022
+ orderHash: string;
1023
+ /** Preimages, one per fill. Index matters — fill N needs secret N. */
1024
+ secrets: string[];
1025
+ /** Chain the funds left from, so a resumed session can report it. */
1026
+ srcChainId: number;
1027
+ /** For the resumed UI: what the user was paying with and expecting. */
1028
+ srcSymbol: string;
1029
+ dstSymbol: string;
1030
+ dstChainId: number;
1031
+ amount: string;
1032
+ /** Epoch ms. Used to drop orders far past any plausible timelock. */
1033
+ createdAt: number;
1034
+ };
1035
+ /**
1036
+ * Every stored order, newest first, dropping anything past MAX_AGE_MS.
1037
+ * Used on mount to resume orders the user left in flight.
1038
+ */
1039
+ declare function listOrders(now?: number): StoredOrder[];
1040
+
1041
+ export { type AccountAgentApy, type AccountApyOptions, type AgentApy, type AgentApyDetails, type AgentBalance, AgentChainIncompatibleError, type AgentEarnings, type AgentHistoryEntry, type AgentHistoryPosition, type AgentId, AgentNotFoundError, type AgentSupportedAsset, type AgentSupportedAssets, type AgentUserProfile, type AgentWithdrawResult, type AgentsApyOptions, type AllocationAgentApy, type AllocationApyOptions, type ApyByChainAndAsset, type ApyHistoryPoint, type Asset, type AvailableAgent, type AvailableAgentsOptions, type ConnectionState, type DailyApyDays, type DepositCallback, type DepositOptions, type HistoryAction, type HistoryFilters, type HistoryOptions, type HistoryTransaction, type IAgent, InvalidHistoryCursorError, NotConnectedError, type OwneyAccountApy, type OwneyAgentApy, type OwneyAgentHistory, type OwneyAllocationApy, type OwneyBalances, type OwneyDepositResult, type OwneyEarnings, OwneyError, type OwneyErrorCode, type OwneyMultiDepositResult, type OwneyPosition, OwneySDK, type OwneySDKConfig, type OwneySIWXConfig, type OwneySupportedChainId, type OwneySupportedChains, type OwneySupportedTokens, type OwneyToken, type OwneyUserProfile, type OwneyWithdrawResult, type RebalanceLog, type SwapChainTokens, type SwapOrderStatus, type SwapQuote, type SwapQuoteParams, type SwapRail, type SwapStage, type SwapTokenInfo, type WithdrawOptions, createOwneySIWX, listOrders as listPendingSwaps, setOwneyDebug };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,135 @@
1
1
  import { SIWXConfig } from '@reown/appkit-controllers';
2
2
 
3
+ /**
4
+ * Swap-to-yield types (ROUT-242).
5
+ *
6
+ * The SDK never talks to 1inch directly — the API key is a paid credential and
7
+ * lives in the routing API. Everything here describes the routing API's
8
+ * `/api/v1/swap/*` contract.
9
+ */
10
+ /**
11
+ * Which rail a swap rides, decided server-side from the chains.
12
+ *
13
+ * `classic` — same chain. One atomic transaction: it either completes or
14
+ * nothing moved.
15
+ *
16
+ * `fusion-plus` — crossing chains. The user's funds sit in an escrow while a
17
+ * resolver fills the other side, so the order has a lifecycle and can end in
18
+ * `expired` → `refunding` → `refunded` without ever depositing.
19
+ */
20
+ type SwapRail = "classic" | "fusion-plus";
21
+ type SwapTokenInfo = {
22
+ readonly symbol: string;
23
+ readonly address: string;
24
+ readonly decimals: number;
25
+ /** Native asset (ETH). A swap SOURCE only — never a deposit target. */
26
+ readonly isNative?: true;
27
+ };
28
+ type SwapChainTokens = {
29
+ readonly chainId: number;
30
+ /** What the user may pay with. */
31
+ readonly sources: readonly SwapTokenInfo[];
32
+ /** What a swap may resolve into — what Owney actually deposits. */
33
+ readonly depositTargets: readonly SwapTokenInfo[];
34
+ };
35
+ type SwapQuote = {
36
+ rail: SwapRail;
37
+ src: {
38
+ chainId: number;
39
+ symbol: string;
40
+ address: string;
41
+ amount: string;
42
+ };
43
+ dst: {
44
+ chainId: number;
45
+ symbol: string;
46
+ address: string;
47
+ amount: string;
48
+ };
49
+ /**
50
+ * Worst-case output once the Dutch auction has fully decayed. Gate minimum
51
+ * deposit checks on THIS, not `dst.amount` — a fill at auction end that lands
52
+ * under the agent's floor would leave the user swapped but not deposited.
53
+ */
54
+ dstAmountMin: string;
55
+ /** Cross-chain only. Per-order escrow schedule in seconds, set by 1inch. */
56
+ timeLocks?: Record<string, number>;
57
+ /**
58
+ * Cross-chain only. How many preimages to mint before building an order.
59
+ * Building with the wrong number produces escrows the user's secrets cannot
60
+ * unlock, stranding the swap until its cancellation timelock.
61
+ */
62
+ secretsCount?: number;
63
+ /**
64
+ * Cross-chain only. The contract the source token must be approved to (the
65
+ * 1inch Limit Order Protocol) before a resolver can fill the order.
66
+ *
67
+ * Absent on the classic rail, where the router address arrives with the swap
68
+ * calldata instead.
69
+ */
70
+ spender?: string;
71
+ /**
72
+ * True only for a cross-chain swap FROM native ETH, which needs an on-chain
73
+ * order creation carrying the full amount as msg.value. The user's funds
74
+ * leave the wallet before any fill, so the UI must say so. ERC-20 sources are
75
+ * signature-only after their one-time approval.
76
+ */
77
+ requiresOnchainOrder: boolean;
78
+ /**
79
+ * What the swap costs, as the provider reports it on this quote.
80
+ *
81
+ * Surfaced rather than derived: a fee the UI computes from its own constant
82
+ * drifts from the one actually charged the moment the two disagree, and they
83
+ * did — the integrator fee was configured on our side for days while the
84
+ * provider had it switched off, so the real charge was zero.
85
+ *
86
+ * Cross-chain only. The classic rail reports no breakdown.
87
+ */
88
+ feeInfo?: {
89
+ /** Owney's cut. Absent until a fee receiver is configured. */
90
+ integratorFee?: {
91
+ receiver: string;
92
+ bps: number;
93
+ share: number;
94
+ };
95
+ /** The filler's cut, charged either way. */
96
+ resolverFee?: {
97
+ receiver: string;
98
+ bps: number;
99
+ };
100
+ };
101
+ /**
102
+ * Owney's cut in basis points, for display.
103
+ *
104
+ * Distinct from `feeInfo`, which is what the provider measured on this
105
+ * quote. When the provider applies the fee at settlement it reports nothing
106
+ * here, and this carries the agreed figure instead so the UI can still name
107
+ * one. Stated, not verified.
108
+ */
109
+ integratorFeeBps?: number;
110
+ };
111
+ /**
112
+ * Terminal states are `executed`, `expired`, `cancelled` and `refunded`.
113
+ * `refunding` is the window the returning-funds screen renders: the order has
114
+ * failed and the money is on its way back, but is not back yet.
115
+ */
116
+ type SwapOrderStatus = "pending" | "executed" | "expired" | "cancelled" | "refunding" | "refunded" | "unpublished";
117
+ /** Stage reported to the UI while a swap-and-deposit runs. */
118
+ type SwapStage = "quoting" | "approving" | "signing" | "swapping" | "swapped" | "depositing" | "refunding" | "refunded";
119
+ type SwapQuoteParams = {
120
+ /** Asset the user is paying WITH. */
121
+ from: {
122
+ chainId: number;
123
+ symbol: string;
124
+ amount: string;
125
+ };
126
+ /** Deposit target. Must be an asset Owney can actually deposit. */
127
+ to: {
128
+ chainId: number;
129
+ symbol: string;
130
+ };
131
+ };
132
+
3
133
  type ZyfaiRpcUrlsConfig = Partial<Record<(typeof SUPPORTED_CHAIN_IDS)[number], string>>;
4
134
  interface OwneySDKConfig {
5
135
  apiKey: string;
@@ -54,7 +184,7 @@ type OwneySupportedChainId = (typeof SUPPORTED_CHAIN_IDS)[number];
54
184
  type OwneySupportedChains = (typeof SUPPORTED_CHAINS)[number];
55
185
  type OwneySupportedTokens = (typeof SUPPORTED_TOKENS)[number];
56
186
 
57
- type AgentId = "zyfai" | "surfliquid";
187
+ type AgentId = "zyfai";
58
188
  type Asset = string;
59
189
  type AgentSupportedAsset = {
60
190
  readonly symbol: string;
@@ -182,12 +312,6 @@ interface OwneyDepositResult {
182
312
  }
183
313
  interface OwneyMultiDepositResult {
184
314
  agentResults: Record<string, OwneyDepositResult>;
185
- /**
186
- * Per-agent failure messages for agents that errored during a diversified
187
- * deposit. Present only when at least one (but not all) agents failed —
188
- * the deposit is partial, not total. Omitted when every agent succeeded.
189
- */
190
- agentErrors?: Record<string, string>;
191
315
  }
192
316
  interface AgentWithdrawResult {
193
317
  txHash?: string;
@@ -635,17 +759,83 @@ declare class OwneySDK {
635
759
  private hasExistingBalance;
636
760
  private validateAssetSupport;
637
761
  private getEligibleAgents;
762
+ /** Lazily built so an app that never swaps pays nothing for it. */
763
+ private swapApiClient?;
764
+ private swapApi;
765
+ /**
766
+ * Put the wallet on `chainId`, or fail with something actionable.
767
+ *
768
+ * Reuses the same guard the deposit rail uses, which re-reads the chain after
769
+ * switching — some wallets resolve wallet_switchEthereumChain before the
770
+ * network has actually changed.
771
+ */
772
+ private ensureSwapChain;
773
+ /**
774
+ * Binds the executor's abstract deps to this client's wallet.
775
+ *
776
+ * Kept as a builder rather than baked into the executor so the whole swap
777
+ * flow stays testable without a provider — the executor never imports viem.
778
+ */
779
+ private buildSwapDeps;
780
+ /**
781
+ * Assets the user may pay with, and what each chain deposits into.
782
+ *
783
+ * The source list is deliberately wider than the deposit list: it includes
784
+ * native ETH and USDT, which Owney never holds but users often do.
785
+ */
786
+ getSwapTokens(): Promise<{
787
+ chains: SwapChainTokens[];
788
+ }>;
638
789
  /**
639
- * Agent ids the routing API provisioned for this org that support the given
640
- * chain + asset, ordered by preference ({@link AGENT_ELIGIBILITY_ORDER},
641
- * surfliquid first). Returns `[]` when the org has no compatible agent — never
642
- * throws on an empty org. Loads agent keys on first call (apiKey only, no
643
- * wallet), so the UI can resolve which agent to use before the user connects.
790
+ * Price a swap without committing to it.
644
791
  *
645
- * This is the source of truth for agent availability: an agent appears here
646
- * iff the routing API returned its key. No per-app feature flags.
792
+ * `dstAmountMin` is the number to validate against a deposit minimum —
793
+ * `dst.amount` is an estimate that a decaying auction or slippage can undercut,
794
+ * and a swap landing below the floor leaves the user swapped but not
795
+ * deposited.
647
796
  */
648
- getEligibleAgentIds(chainId: number, asset: string): Promise<AgentId[]>;
797
+ getSwapQuote(params: SwapQuoteParams): Promise<SwapQuote>;
798
+ /**
799
+ * Swap an asset the user holds into a deposit asset, then deposit it.
800
+ *
801
+ * Kept separate from `deposit()` rather than bolted on as an option: the
802
+ * return shape differs, the staging callback is meaningless on the plain
803
+ * path, and integrators who never swap should not have to reason about any
804
+ * of it.
805
+ *
806
+ * The deposit runs on the MEASURED arrival, not the quote. A quote is an
807
+ * estimate, so depositing the quoted figure would either strand dust or try
808
+ * to move funds that never came.
809
+ *
810
+ * Failure modes differ in a way callers must respect. A same-chain swap is
811
+ * atomic — if it fails, nothing moved. A cross-chain swap escrows the user's
812
+ * funds first, so SWAP_ORDER_EXPIRED / REFUNDED / CANCELLED all mean the
813
+ * money left the wallet. Only the former can honestly say "nothing has left
814
+ * your wallet".
815
+ */
816
+ swapAndDeposit(options: {
817
+ from: {
818
+ chainId: number;
819
+ symbol: string;
820
+ amount: string;
821
+ };
822
+ /** Deposit target. Defaults to the active chain's asset when omitted. */
823
+ to: {
824
+ chainId: number;
825
+ symbol: string;
826
+ };
827
+ agentId?: AgentId;
828
+ /** Percent, classic rail only. Fusion+ prices through its auction. */
829
+ slippage?: number;
830
+ onSwapProgress?: (stage: SwapStage) => void;
831
+ }): Promise<{
832
+ swap: {
833
+ received: string;
834
+ orderHash?: string;
835
+ txHash?: string;
836
+ };
837
+ deposit: OwneyDepositResult | OwneyMultiDepositResult;
838
+ }>;
649
839
  /**
650
840
  * Withdraw funds from a specific agent, or all agents that support the active chain+asset if agentId is omitted.
651
841
  * Validates that the asset is supported by the target agent(s) on the active chain.
@@ -746,7 +936,7 @@ declare class OwneySDK {
746
936
  getAllocationApy({ agentId, }?: AllocationApyOptions): Promise<OwneyAllocationApy>;
747
937
  }
748
938
 
749
- type OwneyErrorCode = "NOT_CONNECTED" | "NO_ACTIVE_CHAIN" | "WALLET_NO_ACCOUNTS" | "WALLET_ADDRESS_REQUIRED" | "WALLET_NOT_DEPLOYED" | "AGENT_NOT_FOUND" | "AGENT_CHAIN_INCOMPATIBLE" | "AGENT_EMPTY_LIST" | "AGENT_DISABLED" | "CHAIN_UNSUPPORTED" | "CHAIN_NO_COMPATIBLE_AGENTS" | "CHAIN_MISMATCH" | "ASSET_UNSUPPORTED" | "ASSET_NO_COMPATIBLE_AGENTS" | "DEPOSIT_BALANCE_UNAVAILABLE" | "DEPOSIT_PARTIAL_FAILURE" | "DEPOSIT_AMOUNT_BELOW_MINIMUM" | "DEPOSIT_CALLBACK_REQUIRED" | "DEPOSIT_CALLBACK_INVALID" | "DEPOSIT_NO_PERMITTED_TOKENS" | "DEPOSIT_ALL_FAILED" | "DEPOSIT_INSUFFICIENT_BALANCE" | "WITHDRAW_NO_PERMITTED_TOKENS" | "WITHDRAW_INSUFFICIENT_BALANCE" | "WITHDRAW_ALL_FAILED" | "WITHDRAW_PARTIAL_FAILURE" | "WITHDRAW_FAILED" | "AGENT_RATE_LIMITED" | "API_ROUTING_ERROR" | "API_ROUTING_FAILED" | "API_NO_AGENTS" | "SPONSOR_REQUEST_FAILED" | "PERMIT2_APPROVAL_REQUIRED" | "SPONSORED_CALLS_UNSUPPORTED" | "SPONSORED_CALLS_NO_ID" | "SPONSORED_CALLS_NO_RECEIPT" | "SURF_UNAVAILABLE" | "SPONSORSHIP_UNAVAILABLE" | "USER_REJECTED" | "OPERATION_PENDING" | "VAULT_NOT_SPONSORABLE" | "BALANCE_ALL_FAILED" | "ALLOCATION_ALL_FAILED" | "VALIDATION_INVALID_DAYS";
939
+ type OwneyErrorCode = "NOT_CONNECTED" | "NO_ACTIVE_CHAIN" | "WALLET_NO_ACCOUNTS" | "WALLET_ADDRESS_REQUIRED" | "WALLET_NOT_DEPLOYED" | "AGENT_NOT_FOUND" | "AGENT_CHAIN_INCOMPATIBLE" | "AGENT_EMPTY_LIST" | "AGENT_DISABLED" | "CHAIN_UNSUPPORTED" | "CHAIN_NO_COMPATIBLE_AGENTS" | "CHAIN_MISMATCH" | "ASSET_UNSUPPORTED" | "ASSET_NO_COMPATIBLE_AGENTS" | "DEPOSIT_BALANCE_UNAVAILABLE" | "DEPOSIT_PARTIAL_FAILURE" | "DEPOSIT_AMOUNT_BELOW_MINIMUM" | "DEPOSIT_CALLBACK_REQUIRED" | "DEPOSIT_CALLBACK_INVALID" | "DEPOSIT_NO_PERMITTED_TOKENS" | "DEPOSIT_INSUFFICIENT_BALANCE" | "WITHDRAW_NO_PERMITTED_TOKENS" | "WITHDRAW_INSUFFICIENT_BALANCE" | "WITHDRAW_ALL_FAILED" | "WITHDRAW_PARTIAL_FAILURE" | "WITHDRAW_FAILED" | "AGENT_RATE_LIMITED" | "API_ROUTING_ERROR" | "API_ROUTING_FAILED" | "API_NO_AGENTS" | "SPONSOR_REQUEST_FAILED" | "PERMIT2_APPROVAL_REQUIRED" | "SPONSORED_CALLS_UNSUPPORTED" | "SPONSORED_CALLS_NO_ID" | "SPONSORED_CALLS_NO_RECEIPT" | "SWAP_DISABLED" | "SWAP_RATE_LIMITED" | "SWAP_REQUEST_FAILED" | "SWAP_QUOTE_FAILED" | "SWAP_UNSUPPORTED_PAIR" | "SWAP_APPROVAL_REQUIRED" | "SWAP_BELOW_DEPOSIT_MINIMUM" | "SWAP_ORDER_EXPIRED" | "SWAP_ORDER_REFUNDED" | "SWAP_ORDER_CANCELLED" | "BALANCE_ALL_FAILED" | "ALLOCATION_ALL_FAILED" | "VALIDATION_INVALID_DAYS";
750
940
  declare class OwneyError extends Error {
751
941
  readonly code: OwneyErrorCode;
752
942
  readonly details?: Record<string, unknown>;
@@ -812,4 +1002,40 @@ type OwneySIWXConfig = {
812
1002
  */
813
1003
  declare function createOwneySIWX(config: OwneySIWXConfig): SIWXConfig;
814
1004
 
815
- export { type AccountAgentApy, type AccountApyOptions, type AgentApy, type AgentApyDetails, type AgentBalance, AgentChainIncompatibleError, type AgentEarnings, type AgentHistoryEntry, type AgentHistoryPosition, type AgentId, AgentNotFoundError, type AgentSupportedAsset, type AgentSupportedAssets, type AgentUserProfile, type AgentWithdrawResult, type AgentsApyOptions, type AllocationAgentApy, type AllocationApyOptions, type ApyByChainAndAsset, type ApyHistoryPoint, type Asset, type AvailableAgent, type AvailableAgentsOptions, type ConnectionState, type DailyApyDays, type DepositCallback, type DepositOptions, type HistoryAction, type HistoryFilters, type HistoryOptions, type HistoryTransaction, type IAgent, InvalidHistoryCursorError, NotConnectedError, type OwneyAccountApy, type OwneyAgentApy, type OwneyAgentHistory, type OwneyAllocationApy, type OwneyBalances, type OwneyDepositResult, type OwneyEarnings, OwneyError, type OwneyErrorCode, type OwneyMultiDepositResult, type OwneyPosition, OwneySDK, type OwneySDKConfig, type OwneySIWXConfig, type OwneySupportedChainId, type OwneySupportedChains, type OwneySupportedTokens, type OwneyToken, type OwneyUserProfile, type OwneyWithdrawResult, type RebalanceLog, type WithdrawOptions, createOwneySIWX, setOwneyDebug };
1005
+ /**
1006
+ * Persists cross-chain swap secrets so an in-flight order survives a reload.
1007
+ *
1008
+ * This is not a convenience. A Fusion+ order is only completable by whoever
1009
+ * holds the secret preimages: the resolver deploys escrows, then waits for the
1010
+ * secret before it can claim and release funds to the user. Lose the secrets
1011
+ * mid-order and the swap cannot complete — the user waits out the cancellation
1012
+ * timelock for a refund instead.
1013
+ *
1014
+ * That matters here because the UI explicitly tells the user "you can safely
1015
+ * close this window", so surviving a reload is a requirement, not a nicety.
1016
+ *
1017
+ * Trade-off: the same one `zyfai.auth-cache` makes. Secrets in `localStorage`
1018
+ * are exposed to XSS, but they are single-use, worthless once the order
1019
+ * settles, and only ever unlock funds back to the user's own wallet.
1020
+ */
1021
+ type StoredOrder = {
1022
+ orderHash: string;
1023
+ /** Preimages, one per fill. Index matters — fill N needs secret N. */
1024
+ secrets: string[];
1025
+ /** Chain the funds left from, so a resumed session can report it. */
1026
+ srcChainId: number;
1027
+ /** For the resumed UI: what the user was paying with and expecting. */
1028
+ srcSymbol: string;
1029
+ dstSymbol: string;
1030
+ dstChainId: number;
1031
+ amount: string;
1032
+ /** Epoch ms. Used to drop orders far past any plausible timelock. */
1033
+ createdAt: number;
1034
+ };
1035
+ /**
1036
+ * Every stored order, newest first, dropping anything past MAX_AGE_MS.
1037
+ * Used on mount to resume orders the user left in flight.
1038
+ */
1039
+ declare function listOrders(now?: number): StoredOrder[];
1040
+
1041
+ export { type AccountAgentApy, type AccountApyOptions, type AgentApy, type AgentApyDetails, type AgentBalance, AgentChainIncompatibleError, type AgentEarnings, type AgentHistoryEntry, type AgentHistoryPosition, type AgentId, AgentNotFoundError, type AgentSupportedAsset, type AgentSupportedAssets, type AgentUserProfile, type AgentWithdrawResult, type AgentsApyOptions, type AllocationAgentApy, type AllocationApyOptions, type ApyByChainAndAsset, type ApyHistoryPoint, type Asset, type AvailableAgent, type AvailableAgentsOptions, type ConnectionState, type DailyApyDays, type DepositCallback, type DepositOptions, type HistoryAction, type HistoryFilters, type HistoryOptions, type HistoryTransaction, type IAgent, InvalidHistoryCursorError, NotConnectedError, type OwneyAccountApy, type OwneyAgentApy, type OwneyAgentHistory, type OwneyAllocationApy, type OwneyBalances, type OwneyDepositResult, type OwneyEarnings, OwneyError, type OwneyErrorCode, type OwneyMultiDepositResult, type OwneyPosition, OwneySDK, type OwneySDKConfig, type OwneySIWXConfig, type OwneySupportedChainId, type OwneySupportedChains, type OwneySupportedTokens, type OwneyToken, type OwneyUserProfile, type OwneyWithdrawResult, type RebalanceLog, type SwapChainTokens, type SwapOrderStatus, type SwapQuote, type SwapQuoteParams, type SwapRail, type SwapStage, type SwapTokenInfo, type WithdrawOptions, createOwneySIWX, listOrders as listPendingSwaps, setOwneyDebug };