@owney/sdk 0.7.25-beta.3 → 0.7.26-beta.0
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 +7 -9
- package/dist/index.cjs +1482 -2454
- package/dist/index.d.cts +414 -144
- package/dist/index.d.ts +414 -144
- package/dist/index.js +1485 -2473
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,197 @@
|
|
|
1
|
-
import { Hex } from 'viem';
|
|
2
1
|
import { SIWXConfig } from '@reown/appkit-controllers';
|
|
3
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
|
+
* How many more sources `searchSwapTokens` could reach on this chain.
|
|
36
|
+
*
|
|
37
|
+
* `sources` is the short list worth showing unprompted; the full set runs to
|
|
38
|
+
* thousands per chain, which is not something to download to render a
|
|
39
|
+
* picker. A non-zero count here is what tells the UI a search box is worth
|
|
40
|
+
* offering. Zero, absent, or an older routing API all mean the same thing:
|
|
41
|
+
* the short list is everything.
|
|
42
|
+
*/
|
|
43
|
+
readonly searchableSources?: number;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* A search hit from `searchSwapTokens`.
|
|
47
|
+
*
|
|
48
|
+
* Richer than `SwapTokenInfo` because the search endpoint returns more than
|
|
49
|
+
* the bulk list does, and the extra fields are the ones a picker needs to let
|
|
50
|
+
* someone choose safely between three tokens all called PEPE.
|
|
51
|
+
*/
|
|
52
|
+
type SwapTokenSearchResult = SwapTokenInfo & {
|
|
53
|
+
readonly chainId: number;
|
|
54
|
+
readonly name?: string;
|
|
55
|
+
readonly logoURI?: string;
|
|
56
|
+
/**
|
|
57
|
+
* The token lists carrying this address, by NAME — ["1inch", "CoinGecko"].
|
|
58
|
+
*
|
|
59
|
+
* An array, not a count. It was typed as a number first, and a UI that
|
|
60
|
+
* rendered it straight into a row got "1inch,CoinGecko lists".
|
|
61
|
+
*
|
|
62
|
+
* The best available "is this the real one" signal: the genuine mainnet PEPE
|
|
63
|
+
* is on several lists, a lookalike on one. Worth sorting on; the names are
|
|
64
|
+
* too long to put on a row.
|
|
65
|
+
*/
|
|
66
|
+
readonly providers?: readonly string[];
|
|
67
|
+
/**
|
|
68
|
+
* Fee-on-transfer: less arrives than was sent. The swap still works (arrival
|
|
69
|
+
* is measured, not assumed) but any figure quoted to the user beforehand
|
|
70
|
+
* will read high.
|
|
71
|
+
*/
|
|
72
|
+
readonly isFoT?: boolean;
|
|
73
|
+
/** 1inch's own ranking. Not a trust score — an unverified token can outrank
|
|
74
|
+
* an established one, so do not present it as safety. */
|
|
75
|
+
readonly rating?: string;
|
|
76
|
+
};
|
|
77
|
+
type SwapQuote = {
|
|
78
|
+
rail: SwapRail;
|
|
79
|
+
src: {
|
|
80
|
+
chainId: number;
|
|
81
|
+
symbol: string;
|
|
82
|
+
address: string;
|
|
83
|
+
amount: string;
|
|
84
|
+
};
|
|
85
|
+
dst: {
|
|
86
|
+
chainId: number;
|
|
87
|
+
symbol: string;
|
|
88
|
+
address: string;
|
|
89
|
+
amount: string;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Worst-case output once the Dutch auction has fully decayed. Gate minimum
|
|
93
|
+
* deposit checks on THIS, not `dst.amount` — a fill at auction end that lands
|
|
94
|
+
* under the agent's floor would leave the user swapped but not deposited.
|
|
95
|
+
*/
|
|
96
|
+
dstAmountMin: string;
|
|
97
|
+
/** Cross-chain only. Per-order escrow schedule in seconds, set by 1inch. */
|
|
98
|
+
timeLocks?: Record<string, number>;
|
|
99
|
+
/**
|
|
100
|
+
* Cross-chain only. How many preimages to mint before building an order.
|
|
101
|
+
* Building with the wrong number produces escrows the user's secrets cannot
|
|
102
|
+
* unlock, stranding the swap until its cancellation timelock.
|
|
103
|
+
*/
|
|
104
|
+
secretsCount?: number;
|
|
105
|
+
/**
|
|
106
|
+
* Cross-chain only. The contract the source token must be approved to (the
|
|
107
|
+
* 1inch Limit Order Protocol) before a resolver can fill the order.
|
|
108
|
+
*
|
|
109
|
+
* Absent on the classic rail, where the router address arrives with the swap
|
|
110
|
+
* calldata instead.
|
|
111
|
+
*/
|
|
112
|
+
spender?: string;
|
|
113
|
+
/**
|
|
114
|
+
* True only for a cross-chain swap FROM native ETH, which needs an on-chain
|
|
115
|
+
* order creation carrying the full amount as msg.value. The user's funds
|
|
116
|
+
* leave the wallet before any fill, so the UI must say so. ERC-20 sources are
|
|
117
|
+
* signature-only after their one-time approval.
|
|
118
|
+
*/
|
|
119
|
+
requiresOnchainOrder: boolean;
|
|
120
|
+
/**
|
|
121
|
+
* What the swap costs, as the provider reports it on this quote.
|
|
122
|
+
*
|
|
123
|
+
* Surfaced rather than derived: a fee the UI computes from its own constant
|
|
124
|
+
* drifts from the one actually charged the moment the two disagree, and they
|
|
125
|
+
* did — the integrator fee was configured on our side for days while the
|
|
126
|
+
* provider had it switched off, so the real charge was zero.
|
|
127
|
+
*
|
|
128
|
+
* Cross-chain only. The classic rail reports no breakdown.
|
|
129
|
+
*/
|
|
130
|
+
feeInfo?: {
|
|
131
|
+
/** Owney's cut. Absent until a fee receiver is configured. */
|
|
132
|
+
integratorFee?: {
|
|
133
|
+
receiver: string;
|
|
134
|
+
bps: number;
|
|
135
|
+
share: number;
|
|
136
|
+
};
|
|
137
|
+
/** The filler's cut, charged either way. */
|
|
138
|
+
resolverFee?: {
|
|
139
|
+
receiver: string;
|
|
140
|
+
bps: number;
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* Owney's cut in basis points, for display.
|
|
145
|
+
*
|
|
146
|
+
* Distinct from `feeInfo`, which is what the provider measured on this
|
|
147
|
+
* quote. When the provider applies the fee at settlement it reports nothing
|
|
148
|
+
* here, and this carries the agreed figure instead so the UI can still name
|
|
149
|
+
* one. Stated, not verified.
|
|
150
|
+
*/
|
|
151
|
+
integratorFeeBps?: number;
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* Terminal states are `executed`, `expired`, `cancelled` and `refunded`.
|
|
155
|
+
* `refunding` is the window the returning-funds screen renders: the order has
|
|
156
|
+
* failed and the money is on its way back, but is not back yet.
|
|
157
|
+
*/
|
|
158
|
+
type SwapOrderStatus = "pending" | "executed" | "expired" | "cancelled" | "refunding" | "refunded" | "unpublished";
|
|
159
|
+
/**
|
|
160
|
+
* Stage reported to the UI while a swap runs, in either direction.
|
|
161
|
+
*
|
|
162
|
+
* `withdrawing` and `withdrawn` belong to the withdrawal path only: the
|
|
163
|
+
* withdrawal is acknowledged by the agent long before the tokens appear in the
|
|
164
|
+
* wallet, and the swap cannot start until they have. That wait is a visible
|
|
165
|
+
* stage rather than dead time inside "quoting", because it is the longest part
|
|
166
|
+
* of the flow and the one place a user would otherwise think nothing is
|
|
167
|
+
* happening.
|
|
168
|
+
*/
|
|
169
|
+
type SwapStage = "withdrawing" | "withdrawn" | "quoting" | "approving" | "signing" | "swapping" | "swapped" | "depositing" | "refunding" | "refunded";
|
|
170
|
+
/**
|
|
171
|
+
* Which way the funds travel, which decides what each side may be.
|
|
172
|
+
*
|
|
173
|
+
* On a `deposit` the source is any wallet asset and the destination must be
|
|
174
|
+
* depositable. On a `withdraw` that reverses, and the destination widens to
|
|
175
|
+
* anything the wallet can receive — native ETH and USDT included. The routing
|
|
176
|
+
* API enforces both, so this has to be stated rather than inferred.
|
|
177
|
+
*/
|
|
178
|
+
type SwapDirection = "deposit" | "withdraw";
|
|
179
|
+
type SwapQuoteParams = {
|
|
180
|
+
/** Asset being spent: a wallet asset on a deposit, an Owney asset on a withdrawal. */
|
|
181
|
+
from: {
|
|
182
|
+
chainId: number;
|
|
183
|
+
symbol: string;
|
|
184
|
+
amount: string;
|
|
185
|
+
};
|
|
186
|
+
/** Asset being received: a deposit target on a deposit, any wallet asset on a withdrawal. */
|
|
187
|
+
to: {
|
|
188
|
+
chainId: number;
|
|
189
|
+
symbol: string;
|
|
190
|
+
};
|
|
191
|
+
/** Defaults to `deposit`. */
|
|
192
|
+
direction?: SwapDirection;
|
|
193
|
+
};
|
|
194
|
+
|
|
4
195
|
type ZyfaiRpcUrlsConfig = Partial<Record<(typeof SUPPORTED_CHAIN_IDS)[number], string>>;
|
|
5
196
|
interface OwneySDKConfig {
|
|
6
197
|
apiKey: string;
|
|
@@ -9,10 +200,6 @@ interface OwneySDKConfig {
|
|
|
9
200
|
* Example: { 8453: "https://...", 42161: "https://..." }
|
|
10
201
|
*/
|
|
11
202
|
zyfaiRpcUrls?: ZyfaiRpcUrlsConfig;
|
|
12
|
-
/** Optional Owney Yieldseeker proxy base URL override for integration tests. */
|
|
13
|
-
yieldseekerApiBaseUrl?: string;
|
|
14
|
-
/** Optional SIWE origin override. Defaults to the requesting browser origin. */
|
|
15
|
-
yieldseekerSiweOrigin?: string;
|
|
16
203
|
/**
|
|
17
204
|
* Optional override for the Owney routing API base URL used by all routing
|
|
18
205
|
* calls (defaults to the OWNEY_ROUTING_API_BASE_URL env var, then the
|
|
@@ -59,7 +246,7 @@ type OwneySupportedChainId = (typeof SUPPORTED_CHAIN_IDS)[number];
|
|
|
59
246
|
type OwneySupportedChains = (typeof SUPPORTED_CHAINS)[number];
|
|
60
247
|
type OwneySupportedTokens = (typeof SUPPORTED_TOKENS)[number];
|
|
61
248
|
|
|
62
|
-
type AgentId = "zyfai"
|
|
249
|
+
type AgentId = "zyfai";
|
|
63
250
|
type Asset = string;
|
|
64
251
|
type AgentSupportedAsset = {
|
|
65
252
|
readonly symbol: string;
|
|
@@ -237,8 +424,6 @@ interface OwneyPosition {
|
|
|
237
424
|
pool?: string;
|
|
238
425
|
asset: string;
|
|
239
426
|
amount: string;
|
|
240
|
-
/** Smallest-unit amount when the provider exposes it alongside `amount`. */
|
|
241
|
-
amountRaw?: string;
|
|
242
427
|
apy?: number;
|
|
243
428
|
tvl?: number;
|
|
244
429
|
/** Pool liquidity. Prepared slot — Zyfai will add this to its portfolio
|
|
@@ -269,19 +454,10 @@ interface OwneyPendingAllocation {
|
|
|
269
454
|
since?: string;
|
|
270
455
|
}
|
|
271
456
|
interface AgentBalance {
|
|
272
|
-
/** Authoritative native balances per asset/network, including idle and invested funds. */
|
|
273
|
-
assetBalances?: OwneyToken[];
|
|
274
457
|
smartWallet?: `0x${string}`;
|
|
275
458
|
totalBalance: string;
|
|
276
459
|
/** Asset that `totalBalance` is denominated in. Currently always `"usdc"`. */
|
|
277
460
|
totalBalanceAsset: string;
|
|
278
|
-
/**
|
|
279
|
-
* Describes whether `tokens` already includes deployed `positions`.
|
|
280
|
-
* Consumers must add matching positions only for `tokens-plus-positions`;
|
|
281
|
-
* doing so for Zyfai would double-count, while omitting it for Yieldseeker
|
|
282
|
-
* makes its balance disappear as soon as idle funds enter a vault.
|
|
283
|
-
*/
|
|
284
|
-
balanceComposition?: "tokens-include-positions" | "tokens-plus-positions";
|
|
285
461
|
tokens: OwneyToken[];
|
|
286
462
|
/**
|
|
287
463
|
* Per-protocol/pool positions when the agent's portfolio payload includes
|
|
@@ -296,14 +472,10 @@ interface OwneyBalances {
|
|
|
296
472
|
/** Asset that `totalBalance` is denominated in. Currently always `"usdc"`. */
|
|
297
473
|
totalBalanceAsset: string;
|
|
298
474
|
agentBalances: Record<AgentId, AgentBalance>;
|
|
299
|
-
/**
|
|
300
|
-
|
|
301
|
-
* partial result. Callers may display the successful balances, but funding
|
|
302
|
-
* operations must not interpret a missing agent as having a zero balance.
|
|
303
|
-
*/
|
|
304
|
-
agentErrors?: Partial<Record<AgentId, string>>;
|
|
475
|
+
/** Omitted agents failed to load; they must not be interpreted as zero. */
|
|
476
|
+
agentErrors?: Record<AgentId, string>;
|
|
305
477
|
/** Absolute provider cooldown deadlines (Unix milliseconds). */
|
|
306
|
-
agentRetryAt?:
|
|
478
|
+
agentRetryAt?: Record<AgentId, number>;
|
|
307
479
|
}
|
|
308
480
|
interface AgentEarnings {
|
|
309
481
|
smartWallet: `0x${string}`;
|
|
@@ -476,15 +648,8 @@ interface IAgent {
|
|
|
476
648
|
readonly id: string;
|
|
477
649
|
readonly supportedChainIds: readonly OwneySupportedChainId[];
|
|
478
650
|
readonly supportedAssets: readonly AgentSupportedAssets[];
|
|
479
|
-
/**
|
|
480
|
-
* Describes how `AgentBalance.tokens` relates to `positions`.
|
|
481
|
-
* Most adapters expose token totals that already include deployed positions.
|
|
482
|
-
* Providers such as Yieldseeker expose idle wallet tokens separately, so
|
|
483
|
-
* withdrawal planning must add matching position amounts.
|
|
484
|
-
*/
|
|
485
|
-
readonly balanceComposition?: "tokens-include-positions" | "tokens-plus-positions";
|
|
486
651
|
disconnect(): Promise<void>;
|
|
487
|
-
activateAgent(state: ConnectionState, chainId: number
|
|
652
|
+
activateAgent(state: ConnectionState, chainId: number): Promise<void>;
|
|
488
653
|
/**
|
|
489
654
|
* Apply the organization's agent policy to this user's account.
|
|
490
655
|
*
|
|
@@ -555,8 +720,6 @@ declare class OwneySDK {
|
|
|
555
720
|
private orgAgentConfig;
|
|
556
721
|
private orgAgentConfigPromise;
|
|
557
722
|
private zyfaiRpcUrls?;
|
|
558
|
-
private yieldseekerApiBaseUrl?;
|
|
559
|
-
private yieldseekerSiweOrigin?;
|
|
560
723
|
private routingApiBaseUrl?;
|
|
561
724
|
private referralSource?;
|
|
562
725
|
private cachedSponsoredCallback;
|
|
@@ -593,15 +756,25 @@ declare class OwneySDK {
|
|
|
593
756
|
private requireState;
|
|
594
757
|
private requireChainId;
|
|
595
758
|
private requireConnectedProvider;
|
|
596
|
-
/**
|
|
759
|
+
/**
|
|
760
|
+
* Lazily builds (and caches) the default EIP-3009 sponsored deposit callback
|
|
761
|
+
* used when the caller omits `depositCallback`. Wraps the connected EIP-1193
|
|
762
|
+
* provider with viem `custom(provider)` to read token meta and sign the
|
|
763
|
+
* `TransferWithAuthorization`, then POSTs to the sponsor API.
|
|
764
|
+
*/
|
|
597
765
|
private getDefaultSponsoredCallback;
|
|
598
|
-
/**
|
|
766
|
+
/**
|
|
767
|
+
* Lazily builds (and caches) the default Permit2 sponsored WETH deposit
|
|
768
|
+
* callback used when the caller omits `depositCallback` for a WETH
|
|
769
|
+
* deposit. Mirrors `getDefaultSponsoredCallback()` but signs a Permit2
|
|
770
|
+
* `PermitTransferFrom` instead of an EIP-3009 authorization.
|
|
771
|
+
*/
|
|
599
772
|
private getDefaultSponsoredCallsCallback;
|
|
600
773
|
/**
|
|
601
774
|
* Lazily builds (and caches) the default Permit2 sponsored WETH deposit
|
|
602
775
|
* callback used when the caller omits `depositCallback` for a WETH deposit.
|
|
603
776
|
* Mirrors `getDefaultSponsoredCallback()` but signs a Permit2
|
|
604
|
-
*
|
|
777
|
+
* `PermitTransferFrom` instead of an EIP-3009 authorization.
|
|
605
778
|
*/
|
|
606
779
|
private getDefaultWethSponsoredCallback;
|
|
607
780
|
private getAgent;
|
|
@@ -637,8 +810,7 @@ declare class OwneySDK {
|
|
|
637
810
|
* If provided, ALL specified agents must support the chainId or the call
|
|
638
811
|
* throws before activating any agent.
|
|
639
812
|
*/
|
|
640
|
-
activateAgent(chainId: number, agentId?: AgentId[]
|
|
641
|
-
private assertActivationSession;
|
|
813
|
+
activateAgent(chainId: number, agentId?: AgentId[]): Promise<void>;
|
|
642
814
|
/**
|
|
643
815
|
* Activate agents ONE AT A TIME, each followed by its org policy.
|
|
644
816
|
*
|
|
@@ -652,9 +824,10 @@ declare class OwneySDK {
|
|
|
652
824
|
* Serializing costs no real wall-clock: the user can only approve one prompt
|
|
653
825
|
* at a time anyway.
|
|
654
826
|
*
|
|
655
|
-
*
|
|
656
|
-
*
|
|
657
|
-
*
|
|
827
|
+
* Every agent is attempted even if an earlier one fails, so one declined
|
|
828
|
+
* signature can't deny the remaining agents their turn. The first failure is
|
|
829
|
+
* rethrown (matching the previous `Promise.all` rejection) once all agents
|
|
830
|
+
* have had a chance to activate.
|
|
658
831
|
*/
|
|
659
832
|
private activateAgentsInTurn;
|
|
660
833
|
/**
|
|
@@ -665,8 +838,7 @@ declare class OwneySDK {
|
|
|
665
838
|
* @param options.asset - Asset symbol to deposit (e.g. "USDC")
|
|
666
839
|
* @param options.depositCallback - Callback that performs the token transfer and returns a tx hash.
|
|
667
840
|
* When agentId is omitted, this callback is invoked once per eligible agent with that agent's
|
|
668
|
-
* split amount and smart wallet address
|
|
669
|
-
* all shares into one signature; custom callbacks still run once per agent.
|
|
841
|
+
* split amount and smart wallet address — expect multiple wallet prompts.
|
|
670
842
|
* @param options.agentId - Optional explicit target. Otherwise split equally,
|
|
671
843
|
* or fund remaining agents when a recovery deposit cannot meet every minimum.
|
|
672
844
|
* @returns {OwneyDepositResult} for a single agent, or {OwneyMultiDepositResult} with per-agent results
|
|
@@ -678,7 +850,7 @@ declare class OwneySDK {
|
|
|
678
850
|
*
|
|
679
851
|
* 1. Missing Permit2 allowance: when the app did not supply its own
|
|
680
852
|
* callback and the attempt fails with `PERMIT2_APPROVAL_REQUIRED` on a
|
|
681
|
-
*
|
|
853
|
+
* WETH deposit, this is the wallet's first gasless WETH deposit. We send
|
|
682
854
|
* the one-time (user-paid) Permit2 approval via `approvePermit2()` and
|
|
683
855
|
* retry the SAME sponsored attempt once. Bounded to one approval attempt
|
|
684
856
|
* per call so a wallet/agent that keeps reporting the allowance as
|
|
@@ -700,7 +872,6 @@ declare class OwneySDK {
|
|
|
700
872
|
private depositWithFallback;
|
|
701
873
|
private getMinDepositAmount;
|
|
702
874
|
private splitDepositAmount;
|
|
703
|
-
private formatAgentName;
|
|
704
875
|
private validateMinDepositAmount;
|
|
705
876
|
/**
|
|
706
877
|
* Whether the user already holds a non-zero balance with `agent` for the
|
|
@@ -711,6 +882,159 @@ declare class OwneySDK {
|
|
|
711
882
|
private hasExistingBalance;
|
|
712
883
|
private validateAssetSupport;
|
|
713
884
|
private getEligibleAgents;
|
|
885
|
+
/** Lazily built so an app that never swaps pays nothing for it. */
|
|
886
|
+
private swapApiClient?;
|
|
887
|
+
private swapApi;
|
|
888
|
+
/**
|
|
889
|
+
* Put the wallet on `chainId`, or fail with something actionable.
|
|
890
|
+
*
|
|
891
|
+
* Reuses the same guard the deposit rail uses, which re-reads the chain after
|
|
892
|
+
* switching — some wallets resolve wallet_switchEthereumChain before the
|
|
893
|
+
* network has actually changed.
|
|
894
|
+
*/
|
|
895
|
+
private ensureSwapChain;
|
|
896
|
+
/**
|
|
897
|
+
* Binds the executor's abstract deps to this client's wallet.
|
|
898
|
+
*
|
|
899
|
+
* Kept as a builder rather than baked into the executor so the whole swap
|
|
900
|
+
* flow stays testable without a provider — the executor never imports viem.
|
|
901
|
+
*/
|
|
902
|
+
private buildSwapDeps;
|
|
903
|
+
/**
|
|
904
|
+
* Assets the user may pay with, and what each chain deposits into.
|
|
905
|
+
*
|
|
906
|
+
* The source list is deliberately wider than the deposit list: it includes
|
|
907
|
+
* native ETH and USDT, which Owney never holds but users often do.
|
|
908
|
+
*/
|
|
909
|
+
getSwapTokens(): Promise<{
|
|
910
|
+
chains: SwapChainTokens[];
|
|
911
|
+
}>;
|
|
912
|
+
/**
|
|
913
|
+
* Search the assets a user may pay with on one chain.
|
|
914
|
+
*
|
|
915
|
+
* `getSwapTokens` returns the short list worth rendering unprompted. This
|
|
916
|
+
* reaches everything else the routing API will accept — thousands per chain
|
|
917
|
+
* once the wider allowlist is enabled, which is why it is a query rather
|
|
918
|
+
* than a download.
|
|
919
|
+
*
|
|
920
|
+
* Results are filtered server-side to what a quote will accept, so anything
|
|
921
|
+
* returned can be paid with. They are NOT ranked by trustworthiness: several
|
|
922
|
+
* tokens can share a ticker, and `providers` (how many token lists carry the
|
|
923
|
+
* address) is the only usable signal for telling them apart. Surface it.
|
|
924
|
+
*
|
|
925
|
+
* Returns nothing for a blank query rather than asking for the whole list.
|
|
926
|
+
*/
|
|
927
|
+
searchSwapTokens(params: {
|
|
928
|
+
chainId: number;
|
|
929
|
+
query: string;
|
|
930
|
+
limit?: number;
|
|
931
|
+
}): Promise<{
|
|
932
|
+
tokens: SwapTokenSearchResult[];
|
|
933
|
+
}>;
|
|
934
|
+
/**
|
|
935
|
+
* Price a swap without committing to it.
|
|
936
|
+
*
|
|
937
|
+
* `dstAmountMin` is the number to validate against a deposit minimum —
|
|
938
|
+
* `dst.amount` is an estimate that a decaying auction or slippage can undercut,
|
|
939
|
+
* and a swap landing below the floor leaves the user swapped but not
|
|
940
|
+
* deposited.
|
|
941
|
+
*/
|
|
942
|
+
getSwapQuote(params: SwapQuoteParams): Promise<SwapQuote>;
|
|
943
|
+
/**
|
|
944
|
+
* Swap an asset the user holds into a deposit asset, then deposit it.
|
|
945
|
+
*
|
|
946
|
+
* Kept separate from `deposit()` rather than bolted on as an option: the
|
|
947
|
+
* return shape differs, the staging callback is meaningless on the plain
|
|
948
|
+
* path, and integrators who never swap should not have to reason about any
|
|
949
|
+
* of it.
|
|
950
|
+
*
|
|
951
|
+
* The deposit runs on the MEASURED arrival, not the quote. A quote is an
|
|
952
|
+
* estimate, so depositing the quoted figure would either strand dust or try
|
|
953
|
+
* to move funds that never came.
|
|
954
|
+
*
|
|
955
|
+
* Failure modes differ in a way callers must respect. A same-chain swap is
|
|
956
|
+
* atomic — if it fails, nothing moved. A cross-chain swap escrows the user's
|
|
957
|
+
* funds first, so SWAP_ORDER_EXPIRED / REFUNDED / CANCELLED all mean the
|
|
958
|
+
* money left the wallet. Only the former can honestly say "nothing has left
|
|
959
|
+
* your wallet".
|
|
960
|
+
*/
|
|
961
|
+
swapAndDeposit(options: {
|
|
962
|
+
from: {
|
|
963
|
+
chainId: number;
|
|
964
|
+
symbol: string;
|
|
965
|
+
amount: string;
|
|
966
|
+
};
|
|
967
|
+
/** Deposit target. Defaults to the active chain's asset when omitted. */
|
|
968
|
+
to: {
|
|
969
|
+
chainId: number;
|
|
970
|
+
symbol: string;
|
|
971
|
+
};
|
|
972
|
+
agentId?: AgentId;
|
|
973
|
+
/** Percent, classic rail only. Fusion+ prices through its auction. */
|
|
974
|
+
slippage?: number;
|
|
975
|
+
onSwapProgress?: (stage: SwapStage) => void;
|
|
976
|
+
}): Promise<{
|
|
977
|
+
swap: {
|
|
978
|
+
received: string;
|
|
979
|
+
orderHash?: string;
|
|
980
|
+
txHash?: string;
|
|
981
|
+
};
|
|
982
|
+
deposit: OwneyDepositResult | OwneyMultiDepositResult;
|
|
983
|
+
}>;
|
|
984
|
+
/**
|
|
985
|
+
* Withdraw from an agent and swap the proceeds into whatever the user wants
|
|
986
|
+
* to hold, delivered to their own wallet.
|
|
987
|
+
*
|
|
988
|
+
* The mirror of `swapAndDeposit()`, with one structural difference that
|
|
989
|
+
* drives the whole implementation: a deposit swap starts from funds already
|
|
990
|
+
* sitting in the wallet, but a withdrawal has to wait for them. The agent's
|
|
991
|
+
* provider acknowledges a withdrawal and *then* queues the on-chain transfer
|
|
992
|
+
* to the EOA, so `withdraw()` resolving means "accepted", not "arrived".
|
|
993
|
+
* Quoting before the tokens land would size the swap against a balance that
|
|
994
|
+
* is not there yet.
|
|
995
|
+
*
|
|
996
|
+
* The swap is therefore sized from the MEASURED arrival, exactly as the
|
|
997
|
+
* deposit path sizes its deposit from the measured swap output. On a full
|
|
998
|
+
* withdrawal there is no other number available — "MAX" has no figure until
|
|
999
|
+
* the agent picks one.
|
|
1000
|
+
*
|
|
1001
|
+
* **Failure here is not symmetrical with the deposit path.** A failed
|
|
1002
|
+
* deposit-swap leaves the user holding what they started with. A failed
|
|
1003
|
+
* withdrawal-swap leaves them holding the AGENT'S asset in their own wallet:
|
|
1004
|
+
* the money is out, safe, and in the wrong denomination. Both
|
|
1005
|
+
* `WITHDRAW_ARRIVAL_TIMEOUT` and `WITHDRAW_SWAP_FAILED` carry `withdrawn` for
|
|
1006
|
+
* that reason — the UI has to tell the user where their money actually is,
|
|
1007
|
+
* and must never present either as a lost withdrawal.
|
|
1008
|
+
*/
|
|
1009
|
+
withdrawAndSwap(options: {
|
|
1010
|
+
/** The agent's asset. Must be on the active chain. */
|
|
1011
|
+
from: {
|
|
1012
|
+
chainId: number;
|
|
1013
|
+
symbol: string;
|
|
1014
|
+
};
|
|
1015
|
+
/** What to deliver to the wallet. Any swappable asset, including native ETH. */
|
|
1016
|
+
to: {
|
|
1017
|
+
chainId: number;
|
|
1018
|
+
symbol: string;
|
|
1019
|
+
};
|
|
1020
|
+
/** Human units ("10.5"). Omit to withdraw the full agent balance. */
|
|
1021
|
+
amount?: string;
|
|
1022
|
+
agentId?: AgentId;
|
|
1023
|
+
/** Percent, classic rail only. Fusion+ prices through its auction. */
|
|
1024
|
+
slippage?: number;
|
|
1025
|
+
onSwapProgress?: (stage: SwapStage) => void;
|
|
1026
|
+
/** How long to wait for the withdrawal to land before giving up on the swap. */
|
|
1027
|
+
arrivalTimeoutMs?: number;
|
|
1028
|
+
}): Promise<{
|
|
1029
|
+
withdraw: OwneyWithdrawResult | AgentWithdrawResult;
|
|
1030
|
+
/** What actually arrived in the wallet, smallest unit of the agent's asset. */
|
|
1031
|
+
withdrawn: string;
|
|
1032
|
+
swap: {
|
|
1033
|
+
received: string;
|
|
1034
|
+
orderHash?: string;
|
|
1035
|
+
txHash?: string;
|
|
1036
|
+
};
|
|
1037
|
+
}>;
|
|
714
1038
|
/**
|
|
715
1039
|
* Withdraw funds from a specific agent, or all agents that support the active chain+asset if agentId is omitted.
|
|
716
1040
|
* Validates that the asset is supported by the target agent(s) on the active chain.
|
|
@@ -792,15 +1116,14 @@ declare class OwneySDK {
|
|
|
792
1116
|
*/
|
|
793
1117
|
ensureAutoSelectProtocols(asset: "USDC" | "WETH", agentId?: AgentId): Promise<boolean>;
|
|
794
1118
|
/**
|
|
795
|
-
*
|
|
796
|
-
*
|
|
797
|
-
*
|
|
798
|
-
*
|
|
799
|
-
*
|
|
800
|
-
* @param requiredAmount Raw base-unit amount the pending deposit must cover.
|
|
1119
|
+
* One-time, user-paid approval of Permit2 on the sponsored WETH token for
|
|
1120
|
+
* the active chain. Required once per wallet per chain before gasless WETH
|
|
1121
|
+
* deposits; afterwards deposit() is signature-only. Resolves only after the
|
|
1122
|
+
* approval transaction is mined (1 confirmation), so a subsequent deposit()
|
|
1123
|
+
* will see the new allowance; throws if the transaction reverted.
|
|
801
1124
|
* @returns the approval transaction hash.
|
|
802
1125
|
*/
|
|
803
|
-
approvePermit2(asset?:
|
|
1126
|
+
approvePermit2(asset?: "WETH"): Promise<`0x${string}`>;
|
|
804
1127
|
/**
|
|
805
1128
|
* Get the agent's average APY performance over a time period. Does not require a wallet connection.
|
|
806
1129
|
* @param options - Contains agentId (optional) and days ("7D", "14D", or "30D")
|
|
@@ -824,96 +1147,7 @@ declare class OwneySDK {
|
|
|
824
1147
|
getAllocationApy({ agentId, }?: AllocationApyOptions): Promise<OwneyAllocationApy>;
|
|
825
1148
|
}
|
|
826
1149
|
|
|
827
|
-
type
|
|
828
|
-
origin?: string;
|
|
829
|
-
now?: () => Date;
|
|
830
|
-
nonce?: () => string;
|
|
831
|
-
};
|
|
832
|
-
|
|
833
|
-
type YieldseekerFetch = typeof fetch;
|
|
834
|
-
|
|
835
|
-
type YieldseekerTransaction = {
|
|
836
|
-
from: `0x${string}`;
|
|
837
|
-
to: `0x${string}`;
|
|
838
|
-
data: `0x${string}`;
|
|
839
|
-
value: string;
|
|
840
|
-
chainId: number;
|
|
841
|
-
};
|
|
842
|
-
|
|
843
|
-
type YieldseekerAgentOptions = {
|
|
844
|
-
baseUrl?: string;
|
|
845
|
-
fetchFn?: YieldseekerFetch;
|
|
846
|
-
auth?: YieldseekerAuthDependencies;
|
|
847
|
-
/** Test seam for the wallet-submission/receipt boundary. */
|
|
848
|
-
transactionExecutor?: (state: ConnectionState, chainId: number, transaction: YieldseekerTransaction) => Promise<Hex>;
|
|
849
|
-
/** Test seam for transactions submitted outside transactionExecutor. */
|
|
850
|
-
unwindReceiptWaiter?: (state: ConnectionState, chainId: number, transactionHash: Hex) => Promise<void>;
|
|
851
|
-
};
|
|
852
|
-
declare class YieldseekerAgent implements IAgent {
|
|
853
|
-
readonly id = "yieldseeker";
|
|
854
|
-
readonly balanceComposition: "tokens-plus-positions";
|
|
855
|
-
readonly supportedChainIds: readonly [8453];
|
|
856
|
-
readonly supportedAssets: readonly [{
|
|
857
|
-
readonly chainId: 8453;
|
|
858
|
-
readonly chain: "BASE";
|
|
859
|
-
readonly assets: readonly [{
|
|
860
|
-
readonly symbol: "USDC";
|
|
861
|
-
readonly minDepositAmount: "10000000";
|
|
862
|
-
}, {
|
|
863
|
-
readonly symbol: "WETH";
|
|
864
|
-
readonly minDepositAmount: "1";
|
|
865
|
-
}];
|
|
866
|
-
}];
|
|
867
|
-
private readonly api;
|
|
868
|
-
private readonly auth;
|
|
869
|
-
private readonly transactionExecutor?;
|
|
870
|
-
private readonly unwindReceiptWaiter?;
|
|
871
|
-
private readonly agentContexts;
|
|
872
|
-
private readonly users;
|
|
873
|
-
private readonly pendingAgents;
|
|
874
|
-
private readonly yieldOptions;
|
|
875
|
-
private readonly pendingYieldOptions;
|
|
876
|
-
constructor(owneyApiKey: string, options?: YieldseekerAgentOptions);
|
|
877
|
-
disconnect(): Promise<void>;
|
|
878
|
-
activateAgent(state: ConnectionState, chainId: number, asset?: OwneySupportedTokens): Promise<void>;
|
|
879
|
-
deposit(state: ConnectionState, chainId: number, amount: string, asset: OwneySupportedTokens, depositCallback?: DepositCallback): Promise<OwneyDepositResult>;
|
|
880
|
-
withdraw(state: ConnectionState, chainId: number, asset: OwneySupportedTokens, amount?: string): Promise<AgentWithdrawResult>;
|
|
881
|
-
getBalances(state: ConnectionState, chainId: number): Promise<AgentBalance>;
|
|
882
|
-
getEarnings(state: ConnectionState, chainId: number): Promise<AgentEarnings>;
|
|
883
|
-
getAccountApy(state: ConnectionState, chainId: number, days: DailyApyDays, tokenSymbol?: string): Promise<AccountAgentApy>;
|
|
884
|
-
getHistory(state: ConnectionState, chainId: number, options?: HistoryFilters): Promise<OwneyAgentHistory>;
|
|
885
|
-
getUserProfile(state: ConnectionState, chainId: number): Promise<AgentUserProfile>;
|
|
886
|
-
getAgentApy(days: DailyApyDays, options?: AgentApyOptions): Promise<AgentApy>;
|
|
887
|
-
private loadYieldOptions;
|
|
888
|
-
private userKey;
|
|
889
|
-
private contextKey;
|
|
890
|
-
private resolveUser;
|
|
891
|
-
private forgetUser;
|
|
892
|
-
private ensureAgent;
|
|
893
|
-
private findAgent;
|
|
894
|
-
private resolveAgent;
|
|
895
|
-
private loadPortfolio;
|
|
896
|
-
private loadPortfolioContext;
|
|
897
|
-
private deployAgent;
|
|
898
|
-
private refreshSnapshotAfterMovement;
|
|
899
|
-
private agentPath;
|
|
900
|
-
private walletRequest;
|
|
901
|
-
private providerRequest;
|
|
902
|
-
private mapApiError;
|
|
903
|
-
private submitTransaction;
|
|
904
|
-
private waitForReceipt;
|
|
905
|
-
private assertTransaction;
|
|
906
|
-
private assertAgent;
|
|
907
|
-
private isOwneyAgent;
|
|
908
|
-
private assetForAgent;
|
|
909
|
-
private isTransactionHash;
|
|
910
|
-
private assertChain;
|
|
911
|
-
private assertOptionalChain;
|
|
912
|
-
private assertAsset;
|
|
913
|
-
private invalidResponse;
|
|
914
|
-
}
|
|
915
|
-
|
|
916
|
-
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" | "AGENT_ACTIVATION_PARTIAL_FAILURE" | "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_BALANCE_UNAVAILABLE" | "WITHDRAW_INSUFFICIENT_BALANCE" | "WITHDRAW_ALL_FAILED" | "WITHDRAW_PARTIAL_FAILURE" | "WITHDRAW_FAILED" | "AGENT_RATE_LIMITED" | "API_ROUTING_ERROR" | "API_ROUTING_FAILED" | "API_NO_AGENTS" | "AGENT_API_ERROR" | "AGENT_AUTH_FAILED" | "AGENT_INVALID_RESPONSE" | "AGENT_TIMEOUT" | "AGENT_TRANSACTION_REVERTED" | "SPONSOR_REQUEST_FAILED" | "PERMIT2_APPROVAL_REQUIRED" | "SPONSORED_CALLS_UNSUPPORTED" | "SPONSORED_CALLS_NO_ID" | "SPONSORED_CALLS_NO_RECEIPT" | "BALANCE_ALL_FAILED" | "ALLOCATION_ALL_FAILED" | "VALIDATION_INVALID_DAYS";
|
|
1150
|
+
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" | "WITHDRAW_ARRIVAL_TIMEOUT" | "WITHDRAW_SWAP_FAILED" | "BALANCE_ALL_FAILED" | "ALLOCATION_ALL_FAILED" | "VALIDATION_INVALID_DAYS";
|
|
917
1151
|
declare class OwneyError extends Error {
|
|
918
1152
|
readonly code: OwneyErrorCode;
|
|
919
1153
|
readonly details?: Record<string, unknown>;
|
|
@@ -979,4 +1213,40 @@ type OwneySIWXConfig = {
|
|
|
979
1213
|
*/
|
|
980
1214
|
declare function createOwneySIWX(config: OwneySIWXConfig): SIWXConfig;
|
|
981
1215
|
|
|
982
|
-
|
|
1216
|
+
/**
|
|
1217
|
+
* Persists cross-chain swap secrets so an in-flight order survives a reload.
|
|
1218
|
+
*
|
|
1219
|
+
* This is not a convenience. A Fusion+ order is only completable by whoever
|
|
1220
|
+
* holds the secret preimages: the resolver deploys escrows, then waits for the
|
|
1221
|
+
* secret before it can claim and release funds to the user. Lose the secrets
|
|
1222
|
+
* mid-order and the swap cannot complete — the user waits out the cancellation
|
|
1223
|
+
* timelock for a refund instead.
|
|
1224
|
+
*
|
|
1225
|
+
* That matters here because the UI explicitly tells the user "you can safely
|
|
1226
|
+
* close this window", so surviving a reload is a requirement, not a nicety.
|
|
1227
|
+
*
|
|
1228
|
+
* Trade-off: the same one `zyfai.auth-cache` makes. Secrets in `localStorage`
|
|
1229
|
+
* are exposed to XSS, but they are single-use, worthless once the order
|
|
1230
|
+
* settles, and only ever unlock funds back to the user's own wallet.
|
|
1231
|
+
*/
|
|
1232
|
+
type StoredOrder = {
|
|
1233
|
+
orderHash: string;
|
|
1234
|
+
/** Preimages, one per fill. Index matters — fill N needs secret N. */
|
|
1235
|
+
secrets: string[];
|
|
1236
|
+
/** Chain the funds left from, so a resumed session can report it. */
|
|
1237
|
+
srcChainId: number;
|
|
1238
|
+
/** For the resumed UI: what the user was paying with and expecting. */
|
|
1239
|
+
srcSymbol: string;
|
|
1240
|
+
dstSymbol: string;
|
|
1241
|
+
dstChainId: number;
|
|
1242
|
+
amount: string;
|
|
1243
|
+
/** Epoch ms. Used to drop orders far past any plausible timelock. */
|
|
1244
|
+
createdAt: number;
|
|
1245
|
+
};
|
|
1246
|
+
/**
|
|
1247
|
+
* Every stored order, newest first, dropping anything past MAX_AGE_MS.
|
|
1248
|
+
* Used on mount to resume orders the user left in flight.
|
|
1249
|
+
*/
|
|
1250
|
+
declare function listOrders(now?: number): StoredOrder[];
|
|
1251
|
+
|
|
1252
|
+
export { type AccountAgentApy, type AccountApyOptions, type AccountDailyEarnings, 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 AssetDailyEarnings, type AvailableAgent, type AvailableAgentsOptions, type ConnectionState, type DailyApyDays, type DailyEarningsOptions, type DailyEarningsPoint, type DepositCallback, type DepositOptions, type HistoryAction, type HistoryFilters, type HistoryOptions, type HistoryTransaction, type IAgent, InvalidHistoryCursorError, type LookbackDays, 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 SwapDirection, type SwapOrderStatus, type SwapQuote, type SwapQuoteParams, type SwapRail, type SwapStage, type SwapTokenInfo, type SwapTokenSearchResult, type WithdrawOptions, createOwneySIWX, listOrders as listPendingSwaps, setOwneyDebug };
|