@owney/sdk 0.7.27-beta.2 → 0.7.28-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 +19 -93
- package/dist/index.cjs +3401 -10481
- package/dist/index.d.cts +319 -652
- package/dist/index.d.ts +319 -652
- package/dist/index.js +3386 -10500
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import * as viem from 'viem';
|
|
2
|
-
import { Address, Hex } from 'viem';
|
|
3
1
|
import { SIWXConfig } from '@reown/appkit-controllers';
|
|
4
2
|
|
|
5
3
|
/**
|
|
@@ -222,9 +220,7 @@ type SwapOrderStatus = "pending" | "executed" | "expired" | "cancelled" | "refun
|
|
|
222
220
|
* of the flow and the one place a user would otherwise think nothing is
|
|
223
221
|
* happening.
|
|
224
222
|
*/
|
|
225
|
-
type SwapStage = "withdrawing" | "withdrawn"
|
|
226
|
-
/** Withdrawal incomplete or unconfirmed; no swap was submitted. */
|
|
227
|
-
| "withdrawal-incomplete" | "swap-unknown" | "swap-partial" | "swap-not-started" | "quoting" | "wrapping" | "wrapped" | "approving" | "building" | "signing" | "swapping" | "swapped" | "depositing" | "refunding" | "refunded";
|
|
223
|
+
type SwapStage = "withdrawing" | "withdrawn" | "quoting" | "wrapping" | "wrapped" | "approving" | "signing" | "swapping" | "swapped" | "depositing" | "refunding" | "refunded";
|
|
228
224
|
/**
|
|
229
225
|
* Which way the funds travel, which decides what each side may be.
|
|
230
226
|
*
|
|
@@ -250,34 +246,19 @@ type SwapQuoteParams = {
|
|
|
250
246
|
direction?: SwapDirection;
|
|
251
247
|
};
|
|
252
248
|
|
|
253
|
-
type
|
|
254
|
-
/** @deprecated Use RpcUrlsConfig. */
|
|
255
|
-
type ZyfaiRpcUrlsConfig = RpcUrlsConfig;
|
|
249
|
+
type ZyfaiRpcUrlsConfig = Partial<Record<(typeof SUPPORTED_CHAIN_IDS)[number], string>>;
|
|
256
250
|
interface OwneySDKConfig {
|
|
257
251
|
apiKey: string;
|
|
258
|
-
/**
|
|
259
|
-
* Optional per-chain RPC overrides used for application-owned reads and
|
|
260
|
-
* transaction receipt polling. Missing chains use the Owney routing API's
|
|
261
|
-
* read-only RPC proxy. No upstream RPC credentials are included in the SDK.
|
|
262
|
-
* Wallet providers remain responsible for account access, chain switching,
|
|
263
|
-
* signatures, and transaction submission.
|
|
264
|
-
*/
|
|
265
|
-
rpcUrls?: RpcUrlsConfig;
|
|
266
252
|
/**
|
|
267
253
|
* Optional per-chain RPC overrides for Zyfai SDK network calls.
|
|
268
254
|
* Example: { 8453: "https://...", 42161: "https://..." }
|
|
269
|
-
* @deprecated Use rpcUrls so every agent shares the same read transport.
|
|
270
255
|
*/
|
|
271
256
|
zyfaiRpcUrls?: ZyfaiRpcUrlsConfig;
|
|
272
|
-
/** Optional Owney Yieldseeker proxy base URL override for integration tests. */
|
|
273
|
-
yieldseekerApiBaseUrl?: string;
|
|
274
|
-
/** Optional SIWE origin override. Defaults to the requesting browser origin. */
|
|
275
|
-
yieldseekerSiweOrigin?: string;
|
|
276
257
|
/**
|
|
277
258
|
* Optional override for the Owney routing API base URL used by all routing
|
|
278
|
-
* calls
|
|
279
|
-
*
|
|
280
|
-
*
|
|
259
|
+
* calls (defaults to the OWNEY_ROUTING_API_BASE_URL env var, then the
|
|
260
|
+
* production URL). Set this to point at a local/staging routing API,
|
|
261
|
+
* e.g. "http://localhost:3000", when testing sponsor changes.
|
|
281
262
|
*/
|
|
282
263
|
routingApiBaseUrl?: string;
|
|
283
264
|
/**
|
|
@@ -319,136 +300,7 @@ type OwneySupportedChainId = (typeof SUPPORTED_CHAIN_IDS)[number];
|
|
|
319
300
|
type OwneySupportedChains = (typeof SUPPORTED_CHAINS)[number];
|
|
320
301
|
type OwneySupportedTokens = (typeof SUPPORTED_TOKENS)[number];
|
|
321
302
|
|
|
322
|
-
|
|
323
|
-
* One protocol's pool selection on one chain. `pools` holds Zyfai pool NAMES
|
|
324
|
-
* verbatim — matched case-sensitively by customizeBatch, and an unrecognised
|
|
325
|
-
* name makes Zyfai's rebalance engine skip the whole protocol, so these strings
|
|
326
|
-
* must not be normalised anywhere.
|
|
327
|
-
*
|
|
328
|
-
* An empty array means "no usable pools on this chain".
|
|
329
|
-
*/
|
|
330
|
-
type OrgPoolSelection = {
|
|
331
|
-
protocolId: string;
|
|
332
|
-
chainId: number;
|
|
333
|
-
pools: string[];
|
|
334
|
-
};
|
|
335
|
-
/**
|
|
336
|
-
* The partner's protocol/pool policy (ROUT-224). Sparse — only protocols they
|
|
337
|
-
* narrowed appear. Optional so an older routing API, which does not return the
|
|
338
|
-
* field, still parses; undefined and null both mean "change nothing".
|
|
339
|
-
*/
|
|
340
|
-
type OrgPoolPolicy = {
|
|
341
|
-
autoApproveProtocols: boolean;
|
|
342
|
-
autoApprovePools: boolean;
|
|
343
|
-
selections: OrgPoolSelection[];
|
|
344
|
-
};
|
|
345
|
-
/**
|
|
346
|
-
* The organization's agent execution policy, or null when the partner has never
|
|
347
|
-
* configured one — in which case the agents leave the user's profile alone.
|
|
348
|
-
*/
|
|
349
|
-
type OrgAgentConfig = {
|
|
350
|
-
splittingMode: "none" | "automatic" | "force";
|
|
351
|
-
minSplits: number | null;
|
|
352
|
-
poolPolicy?: OrgPoolPolicy | null;
|
|
353
|
-
};
|
|
354
|
-
|
|
355
|
-
type DepositCallback = (smartWalletAddress: string, chainId: number, amount: string) => Promise<`0x${string}`> | `0x${string}`;
|
|
356
|
-
interface IAgent {
|
|
357
|
-
readonly id: string;
|
|
358
|
-
readonly supportedChainIds: readonly OwneySupportedChainId[];
|
|
359
|
-
readonly supportedAssets: readonly AgentSupportedAssets[];
|
|
360
|
-
/**
|
|
361
|
-
* Describes how `AgentBalance.tokens` relates to `positions`.
|
|
362
|
-
* Most adapters expose token totals that already include deployed positions.
|
|
363
|
-
* Providers such as Yieldseeker expose idle wallet tokens separately, so
|
|
364
|
-
* withdrawal planning must add matching position amounts.
|
|
365
|
-
*/
|
|
366
|
-
readonly balanceComposition?: "tokens-include-positions" | "tokens-plus-positions";
|
|
367
|
-
/**
|
|
368
|
-
* Whether a withdrawal requires an owner-approved wallet transaction.
|
|
369
|
-
* Aggregate withdrawals run these agents before relayer-only agents so a
|
|
370
|
-
* rejected wallet request cannot happen after another leg has committed.
|
|
371
|
-
*/
|
|
372
|
-
readonly withdrawalRequiresWalletApproval?: boolean;
|
|
373
|
-
disconnect(): Promise<void>;
|
|
374
|
-
activateAgent(state: ConnectionState, chainId: number, asset?: OwneySupportedTokens): Promise<void>;
|
|
375
|
-
/**
|
|
376
|
-
* Apply the organization's agent policy to this user's account.
|
|
377
|
-
*
|
|
378
|
-
* Optional: an agent that has no equivalent knob simply omits it, which is why
|
|
379
|
-
* this is not part of `activateAgent`'s signature. Declared on the interface
|
|
380
|
-
* rather than only on ZyfaiAgent so the contract stays agent-neutral — the
|
|
381
|
-
* ticket asks for a design that can also cover Surf, which has no adapter yet.
|
|
382
|
-
*
|
|
383
|
-
* Implementations must be **non-fatal**: this runs during activation as a side
|
|
384
|
-
* effect, so a failure has to leave the user connected and their profile
|
|
385
|
-
* unchanged rather than break the connect.
|
|
386
|
-
*/
|
|
387
|
-
applyOrgPolicy?(state: ConnectionState, chainId: number, policy: OrgAgentConfig): Promise<void>;
|
|
388
|
-
deposit(state: ConnectionState, chainId: number, amount: string, asset: OwneySupportedTokens, depositCallback?: DepositCallback, onProgress?: FundingProgress, onBeforeSubmission?: (evidence: FundingEvidence) => void | Promise<void>): Promise<OwneyDepositResult>;
|
|
389
|
-
withdraw(state: ConnectionState, chainId: number, token: OwneySupportedTokens, amount?: string, onProgress?: FundingProgress, gasMode?: "auto" | "sponsored" | "paid", onBeforeSubmission?: FundingProgress, assertCurrent?: () => void): Promise<AgentWithdrawResult>;
|
|
390
|
-
/** Read-only MAX proof at the owner payout block; never sends another withdrawal. */
|
|
391
|
-
verifyWithdrawalCompletion?(state: ConnectionState, evidence: FundingEvidence): Promise<WithdrawalCompletion>;
|
|
392
|
-
/** A newly observed pool allocation invalidates this asset's portfolio cache only. */
|
|
393
|
-
invalidateAllocationRead?(state: ConnectionState, chainId: number, asset: OwneySupportedTokens): void;
|
|
394
|
-
/** Invalidate only the confirmed asset. This hook must not sign or submit transactions. */
|
|
395
|
-
invalidateFundingRead?(state: ConnectionState, chainId: number, asset: OwneySupportedTokens, refreshUntil?: number): void;
|
|
396
|
-
/** End accelerated balance reads only for the exact snapshot the caller displayed. */
|
|
397
|
-
endFundingBalanceRefresh?(state: ConnectionState, chainId: number, asset: OwneySupportedTokens, read: AssetReadMetadata): boolean;
|
|
398
|
-
getFundingHistory?(state: ConnectionState, chainId: number, options?: HistoryFilters): Promise<OwneyAgentHistory>;
|
|
399
|
-
getFundingWallet?(state: ConnectionState, chainId: number, asset: OwneySupportedTokens): Promise<string>;
|
|
400
|
-
/** Verify the displayed remaining balance after a receipt-confirmed payout.
|
|
401
|
-
* Undefined means unknown; never substitute a failed read with zero. */
|
|
402
|
-
verifyWithdrawalBalance?(state: ConnectionState, evidence: FundingEvidence, balance: AgentBalance): Promise<AssetReadMetadata | undefined>;
|
|
403
|
-
/** Read-only chain proof when indexed withdrawal components are incomplete.
|
|
404
|
-
* Returns raw owner-withdrawable units; unavailable proof must throw.
|
|
405
|
-
* minimumAmount is the raw liquidity required from this agent for a typed
|
|
406
|
-
* plan, so adapters can expand discovery when known positions fall short. */
|
|
407
|
-
getWithdrawableBalance?(state: ConnectionState, chainId: number, asset: OwneySupportedTokens, minimumAmount?: bigint): Promise<bigint>;
|
|
408
|
-
/** Optional positive proof for a repeat deposit; unknown must fall back to portfolio validation. */
|
|
409
|
-
hasExistingDepositFunds?(state: ConnectionState, chainId: number, asset: OwneySupportedTokens): Promise<true | undefined>;
|
|
410
|
-
getBalances(state: ConnectionState, chainId: number, asset?: OwneySupportedTokens): Promise<AgentBalance>;
|
|
411
|
-
getEarnings(state: ConnectionState, chainId: number): Promise<AgentEarnings>;
|
|
412
|
-
/**
|
|
413
|
-
* Refresh the agent's earnings snapshot when its backend supports doing so.
|
|
414
|
-
* Implementations own freshness and request-deduplication policy.
|
|
415
|
-
*/
|
|
416
|
-
refreshEarnings?(state: ConnectionState, chainId: number): Promise<AgentEarnings>;
|
|
417
|
-
getAccountApy(state: ConnectionState, chainId: number, days: DailyApyDays,
|
|
418
|
-
/**
|
|
419
|
-
* Optional asset symbol ("USDC" / "WETH") scoping the daily series to a
|
|
420
|
-
* single asset on the chain. Agents without per-asset positions ignore it.
|
|
421
|
-
*/
|
|
422
|
-
tokenSymbol?: string): Promise<AccountAgentApy>;
|
|
423
|
-
/**
|
|
424
|
-
* Daily cumulative earnings in token units, scoped to a chain/asset, using
|
|
425
|
-
* the provider's earnings basis. Include an opening snapshot when available
|
|
426
|
-
* so the "recent earnings" subline can difference the endpoints. (ROUT-452)
|
|
427
|
-
*/
|
|
428
|
-
getDailyEarnings?(state: ConnectionState, chainId: number, days: LookbackDays, tokenSymbol?: string): Promise<AccountDailyEarnings>;
|
|
429
|
-
getHistory(state: ConnectionState, chainId: number, options?: HistoryFilters): Promise<OwneyAgentHistory>;
|
|
430
|
-
getUserProfile(state: ConnectionState, chainId: number): Promise<AgentUserProfile>;
|
|
431
|
-
/**
|
|
432
|
-
* Ensure the given asset uses backend protocol auto-selection
|
|
433
|
-
* (`autoSelectProtocols: true`). Optional capability — only agents whose
|
|
434
|
-
* backend models per-asset protocol selection implement it. Returns whether
|
|
435
|
-
* a write occurred (`false` = already enabled / not supported).
|
|
436
|
-
*/
|
|
437
|
-
ensureAutoSelectProtocols?(state: ConnectionState, chainId: number, asset: "USDC" | "WETH"): Promise<boolean>;
|
|
438
|
-
getAgentApy(days: DailyApyDays, options?: AgentApyOptions): Promise<AgentApy>;
|
|
439
|
-
}
|
|
440
|
-
/**
|
|
441
|
-
* Optional filters for per-agent APY lookups.
|
|
442
|
-
* - `tokenSymbol` / `chainId` scope the APY to a specific asset+chain when
|
|
443
|
-
* the underlying provider supports it (Zyfai). Agents whose backends do
|
|
444
|
-
* not yet support per-asset APY will ignore these options.
|
|
445
|
-
*/
|
|
446
|
-
type AgentApyOptions = {
|
|
447
|
-
tokenSymbol?: string;
|
|
448
|
-
chainId?: number;
|
|
449
|
-
};
|
|
450
|
-
|
|
451
|
-
type AgentId = "zyfai" | "yieldseeker";
|
|
303
|
+
type AgentId = "zyfai";
|
|
452
304
|
type Asset = string;
|
|
453
305
|
type AgentSupportedAsset = {
|
|
454
306
|
readonly symbol: string;
|
|
@@ -497,29 +349,27 @@ type HistoryFilters = {
|
|
|
497
349
|
tokenSymbol?: string;
|
|
498
350
|
};
|
|
499
351
|
type HistoryOptions = {
|
|
500
|
-
chainId?: number;
|
|
501
352
|
agentId?: AgentId;
|
|
502
353
|
filters?: HistoryFilters;
|
|
354
|
+
/**
|
|
355
|
+
* Chains to read, instead of the one `activateAgent` last set (ROUT-479).
|
|
356
|
+
*
|
|
357
|
+
* Each chain pages independently and the results merge into one
|
|
358
|
+
* chronological list, with every entry stamped with the chain it came from.
|
|
359
|
+
* Omit for the single-chain behaviour, which stays the default: fanning out
|
|
360
|
+
* by default would multiply every existing caller's request count.
|
|
361
|
+
*/
|
|
362
|
+
chainIds?: OwneySupportedChainId[];
|
|
503
363
|
};
|
|
504
364
|
type WithdrawOptions = {
|
|
505
|
-
/** Internal orchestration observation deadline; never retries a send. */
|
|
506
|
-
observationDeadline?: number;
|
|
507
|
-
assertCurrent?: () => void;
|
|
508
|
-
/** Yieldseeker V2 only. "auto" requests sponsorship for a verified V2 wallet. */
|
|
509
|
-
gasMode?: "auto" | "sponsored" | "paid";
|
|
510
|
-
/** Exclude unresolved providers from aggregate withdrawals; direct agent requests are unchanged. */
|
|
511
|
-
excludeAgentIds?: AgentId[];
|
|
512
|
-
onProgress?: FundingProgress;
|
|
513
|
-
/**
|
|
514
|
-
* Durable pre-dispatch checkpoint for adapters with a recoverable operation ID.
|
|
515
|
-
* Rejection prevents submission; progress observers remain non-fatal.
|
|
516
|
-
*/
|
|
517
|
-
onBeforeSubmission?: FundingProgress;
|
|
518
365
|
asset: Asset;
|
|
519
366
|
amount?: string;
|
|
520
367
|
agentId?: AgentId;
|
|
521
|
-
/**
|
|
522
|
-
|
|
368
|
+
/**
|
|
369
|
+
* Chain to withdraw from. Defaults to the chain `activateAgent` last set.
|
|
370
|
+
* See `DepositOptions.chainId` — the same rules apply.
|
|
371
|
+
*/
|
|
372
|
+
chainId?: number;
|
|
523
373
|
};
|
|
524
374
|
type AccountApyOptions = {
|
|
525
375
|
agentId?: AgentId;
|
|
@@ -541,6 +391,14 @@ type AccountApyOptions = {
|
|
|
541
391
|
type DailyEarningsOptions = {
|
|
542
392
|
agentId?: AgentId;
|
|
543
393
|
days: LookbackDays;
|
|
394
|
+
/**
|
|
395
|
+
* Chains to read, instead of the one `activateAgent` last set (ROUT-479).
|
|
396
|
+
*
|
|
397
|
+
* The same asset is summed across them — USDC on Base and USDC on Arbitrum
|
|
398
|
+
* are the same unit. Different assets stay apart, as they already do within
|
|
399
|
+
* one chain. Omit for the single-chain behaviour, which stays the default.
|
|
400
|
+
*/
|
|
401
|
+
chainIds?: OwneySupportedChainId[];
|
|
544
402
|
/**
|
|
545
403
|
* Optional asset symbol (e.g. "USDC", "WETH") scoping the series to one
|
|
546
404
|
* asset on the active chain.
|
|
@@ -566,112 +424,59 @@ type AgentsApyOptions = {
|
|
|
566
424
|
chainId?: number;
|
|
567
425
|
};
|
|
568
426
|
type DepositOptions = {
|
|
569
|
-
/** Resume only these already signed relayer bytes; never create a new authorization. */
|
|
570
|
-
resumeTxHash?: `0x${string}`;
|
|
571
|
-
onProgress?: FundingProgress;
|
|
572
|
-
/** Awaited immediately before dispatch. Throwing prevents submission.
|
|
573
|
-
* All legs of an atomic batch are checkpointed together. */
|
|
574
|
-
onBeforeSubmission?: (evidence: FundingEvidence[]) => void | Promise<void>;
|
|
575
427
|
amount: string;
|
|
576
428
|
asset: Asset;
|
|
577
429
|
depositCallback?: DepositCallback;
|
|
578
430
|
agentId?: AgentId;
|
|
579
431
|
onApproved?: () => void;
|
|
432
|
+
/**
|
|
433
|
+
* Chain to deposit on. Defaults to the chain `activateAgent` last set, so
|
|
434
|
+
* omitting it behaves exactly as before.
|
|
435
|
+
*
|
|
436
|
+
* Pass it to fund several chains in a row without re-activating between
|
|
437
|
+
* them (ROUT-245's spread strategies). It selects the target; it does not
|
|
438
|
+
* replace activation, which is what populates `activeAgents`, and it does
|
|
439
|
+
* not remove the wallet's network switch — the default deposit callbacks
|
|
440
|
+
* still put the wallet on this chain before signing, since a deposit
|
|
441
|
+
* signature is EIP-712 with the chain in its domain.
|
|
442
|
+
*/
|
|
443
|
+
chainId?: number;
|
|
580
444
|
};
|
|
581
445
|
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
446
|
+
/**
|
|
447
|
+
* One protocol's pool selection on one chain. `pools` holds Zyfai pool NAMES
|
|
448
|
+
* verbatim — matched case-sensitively by customizeBatch, and an unrecognised
|
|
449
|
+
* name makes Zyfai's rebalance engine skip the whole protocol, so these strings
|
|
450
|
+
* must not be normalised anywhere.
|
|
451
|
+
*
|
|
452
|
+
* An empty array means "no usable pools on this chain".
|
|
453
|
+
*/
|
|
454
|
+
type OrgPoolSelection = {
|
|
455
|
+
protocolId: string;
|
|
456
|
+
chainId: number;
|
|
457
|
+
pools: string[];
|
|
589
458
|
};
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
459
|
+
/**
|
|
460
|
+
* The partner's protocol/pool policy (ROUT-224). Sparse — only protocols they
|
|
461
|
+
* narrowed appear. Optional so an older routing API, which does not return the
|
|
462
|
+
* field, still parses; undefined and null both mean "change nothing".
|
|
463
|
+
*/
|
|
464
|
+
type OrgPoolPolicy = {
|
|
465
|
+
autoApproveProtocols: boolean;
|
|
466
|
+
autoApprovePools: boolean;
|
|
467
|
+
selections: OrgPoolSelection[];
|
|
594
468
|
};
|
|
595
|
-
/**
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
preVerificationGas: string;
|
|
604
|
-
maxFeePerGas: string;
|
|
605
|
-
maxPriorityFeePerGas: string;
|
|
606
|
-
paymasterAndData: string;
|
|
469
|
+
/**
|
|
470
|
+
* The organization's agent execution policy, or null when the partner has never
|
|
471
|
+
* configured one — in which case the agents leave the user's profile alone.
|
|
472
|
+
*/
|
|
473
|
+
type OrgAgentConfig = {
|
|
474
|
+
splittingMode: "none" | "automatic" | "force";
|
|
475
|
+
minSplits: number | null;
|
|
476
|
+
poolPolicy?: OrgPoolPolicy | null;
|
|
607
477
|
};
|
|
608
|
-
|
|
609
|
-
interface FundingEvidence {
|
|
610
|
-
agentId: AgentId;
|
|
611
|
-
chainId: number;
|
|
612
|
-
token: OwneySupportedTokens;
|
|
613
|
-
walletAddress: string;
|
|
614
|
-
agentWallet?: string;
|
|
615
|
-
maxCompletion?: WithdrawalCompletionContext;
|
|
616
|
-
maxCompletionCheck?: WithdrawalCompletion;
|
|
617
|
-
intendedAmount: string;
|
|
618
|
-
confirmedAmount?: string;
|
|
619
|
-
/** Receipt delivery and fulfillment of a typed requested amount are separate facts. */
|
|
620
|
-
amountCompletion?: "complete" | "shortfall";
|
|
621
|
-
/** Verified difference between the typed request and the actual owner payout. */
|
|
622
|
-
shortfallAmount?: string;
|
|
623
|
-
txHash?: string;
|
|
624
|
-
/** Persisted before a sponsored EOA operation is sent. */
|
|
625
|
-
userOpHash?: string;
|
|
626
|
-
/** Lets recovery verify a consumed nonce even if a bundler forgets the operation. */
|
|
627
|
-
userOperation?: UnsignedUserOperationEvidence;
|
|
628
|
-
/** Base Account calls ID used to recover an uncertain wallet submission. */
|
|
629
|
-
callsId?: string;
|
|
630
|
-
/** Deposit execution was attempted, rather than only prepared. Not confirmation. */
|
|
631
|
-
depositSubmission?: "started";
|
|
632
|
-
blockNumber?: string;
|
|
633
|
-
logIndexes?: number[];
|
|
634
|
-
transferLogs?: {
|
|
635
|
-
logIndex: number;
|
|
636
|
-
amountRaw: string;
|
|
637
|
-
}[];
|
|
638
|
-
/** Sanitized execution-request evidence. Attempted does not prove server acceptance. */
|
|
639
|
-
withdrawalRequest?: {
|
|
640
|
-
attempted: boolean;
|
|
641
|
-
method?: "GET" | "POST";
|
|
642
|
-
path?: "/users/withdraw" | "/users/partial-withdraw";
|
|
643
|
-
elapsedMs?: number;
|
|
644
|
-
/** Actual response status captured before the vendor replaces the HTTP error. */
|
|
645
|
-
httpStatus?: number;
|
|
646
|
-
failure?: "network" | "unauthorized" | "forbidden" | "rate-limited" | "insufficient-balance" | "session-key-missing" | "withdrawal-in-progress" | "other";
|
|
647
|
-
};
|
|
648
|
-
transfer: FundingStage;
|
|
649
|
-
registration: FundingStage;
|
|
650
|
-
delivery: FundingStage;
|
|
651
|
-
}
|
|
652
|
-
type FundingProgress = (evidence: FundingEvidence) => void;
|
|
653
|
-
interface AssetReadMetadata {
|
|
654
|
-
chainId: number;
|
|
655
|
-
asset: string;
|
|
656
|
-
fetchedAt?: number;
|
|
657
|
-
/** When the underlying provider request started; preserved on cached reads. */
|
|
658
|
-
requestedAt?: number;
|
|
659
|
-
/** SDK cache generation, not an onchain block or provider timestamp. */
|
|
660
|
-
readVersion?: number;
|
|
661
|
-
providerUpdatedAt?: string;
|
|
662
|
-
snapshotId?: string;
|
|
663
|
-
blockNumber?: string;
|
|
664
|
-
netDepositsRaw?: string;
|
|
665
|
-
/** Display-only agreement with a post-payout read. Does not prove that
|
|
666
|
-
* provider accounting, history or allocations include the transaction. */
|
|
667
|
-
withdrawalCheck?: {
|
|
668
|
-
txHash: string;
|
|
669
|
-
blockNumber: string;
|
|
670
|
-
};
|
|
671
|
-
positionsStatus: "available" | "unavailable";
|
|
672
|
-
}
|
|
478
|
+
|
|
673
479
|
interface OwneyDepositResult {
|
|
674
|
-
evidence?: FundingEvidence;
|
|
675
480
|
txHash: string;
|
|
676
481
|
smartWallet: string;
|
|
677
482
|
amount: string;
|
|
@@ -680,28 +485,16 @@ interface OwneyMultiDepositResult {
|
|
|
680
485
|
agentResults: Record<string, OwneyDepositResult>;
|
|
681
486
|
}
|
|
682
487
|
interface AgentWithdrawResult {
|
|
683
|
-
evidence?: FundingEvidence;
|
|
684
488
|
txHash?: string;
|
|
685
489
|
type: "full" | "partial";
|
|
686
|
-
/**
|
|
687
|
-
completion?: "unverified";
|
|
688
|
-
/** Confirmed smallest-unit amount; "0" when no owner payout is verified.
|
|
689
|
-
* Legacy providers may return a sentinel such as "all" for a full request. */
|
|
490
|
+
/** Smallest-unit amount, or a provider sentinel such as "all" for a full request. */
|
|
690
491
|
amount: string;
|
|
691
|
-
/** Yieldseeker typed withdrawal fulfilled after an exactly verified fee
|
|
692
|
-
* deduction. Amount remains the confirmed net owner payout, and the gross
|
|
693
|
-
* amount must equal that payout plus the fee, all in token base units. */
|
|
694
|
-
feeAdjustment?: {
|
|
695
|
-
grossAmount: string;
|
|
696
|
-
feeAmount: string;
|
|
697
|
-
};
|
|
698
492
|
}
|
|
699
493
|
interface OwneyWithdrawResult {
|
|
700
494
|
agentResult: Record<AgentId, AgentWithdrawResult>;
|
|
701
495
|
/**
|
|
702
|
-
* Sum of
|
|
703
|
-
*
|
|
704
|
-
* Evidence-less custom adapters retain their confirmed-amount contract.
|
|
496
|
+
* Sum of reported smallest-unit amounts; null when a full withdrawal's
|
|
497
|
+
* amount is not yet known. An accepted request is not proof of settlement.
|
|
705
498
|
*/
|
|
706
499
|
totalWithdrawn: string | null;
|
|
707
500
|
}
|
|
@@ -719,10 +512,6 @@ interface OwneyPosition {
|
|
|
719
512
|
pool?: string;
|
|
720
513
|
asset: string;
|
|
721
514
|
amount: string;
|
|
722
|
-
/** Provider-native raw quantity; may represent vault shares, not the underlying asset. */
|
|
723
|
-
amountRaw?: string;
|
|
724
|
-
/** Withdrawable underlying asset amount in that asset's smallest units. */
|
|
725
|
-
withdrawableAmountRaw?: string;
|
|
726
515
|
apy?: number;
|
|
727
516
|
tvl?: number;
|
|
728
517
|
/** Pool liquidity. Prepared slot — Zyfai will add this to its portfolio
|
|
@@ -753,20 +542,10 @@ interface OwneyPendingAllocation {
|
|
|
753
542
|
since?: string;
|
|
754
543
|
}
|
|
755
544
|
interface AgentBalance {
|
|
756
|
-
readMetadata?: AssetReadMetadata[];
|
|
757
|
-
/** Authoritative native balances per asset/network, including idle and invested funds. */
|
|
758
|
-
assetBalances?: OwneyToken[];
|
|
759
545
|
smartWallet?: `0x${string}`;
|
|
760
546
|
totalBalance: string;
|
|
761
547
|
/** Asset that `totalBalance` is denominated in. Currently always `"usdc"`. */
|
|
762
548
|
totalBalanceAsset: string;
|
|
763
|
-
/**
|
|
764
|
-
* Describes whether `tokens` already includes deployed `positions`.
|
|
765
|
-
* Consumers must add matching positions only for `tokens-plus-positions`;
|
|
766
|
-
* doing so for Zyfai would double-count, while omitting it for Yieldseeker
|
|
767
|
-
* makes its balance disappear as soon as idle funds enter a vault.
|
|
768
|
-
*/
|
|
769
|
-
balanceComposition?: "tokens-include-positions" | "tokens-plus-positions";
|
|
770
549
|
tokens: OwneyToken[];
|
|
771
550
|
/**
|
|
772
551
|
* Per-protocol/pool positions when the agent's portfolio payload includes
|
|
@@ -776,19 +555,34 @@ interface AgentBalance {
|
|
|
776
555
|
/** Funds received but not yet deployed. Omitted when nothing is pending. */
|
|
777
556
|
pendingAllocations?: OwneyPendingAllocation[];
|
|
778
557
|
}
|
|
558
|
+
/**
|
|
559
|
+
* One position drained by `withdrawAll()` — a chain and asset pair.
|
|
560
|
+
*
|
|
561
|
+
* Carries either a result or an error, never both: a leg that failed while
|
|
562
|
+
* others succeeded is the normal case, not an exception, and the caller needs
|
|
563
|
+
* to name the ones that did not arrive.
|
|
564
|
+
*/
|
|
565
|
+
interface OwneyWithdrawAllLeg {
|
|
566
|
+
chainId: OwneySupportedChainId;
|
|
567
|
+
asset: OwneySupportedTokens;
|
|
568
|
+
/** What the position held when the sweep started. */
|
|
569
|
+
amount: string;
|
|
570
|
+
result?: OwneyWithdrawResult | AgentWithdrawResult;
|
|
571
|
+
error?: string;
|
|
572
|
+
}
|
|
573
|
+
interface OwneyWithdrawAllResult {
|
|
574
|
+
/** Every position attempted, in the order it was attempted. */
|
|
575
|
+
legs: OwneyWithdrawAllLeg[];
|
|
576
|
+
}
|
|
779
577
|
interface OwneyBalances {
|
|
780
578
|
totalBalance: string;
|
|
781
579
|
/** Asset that `totalBalance` is denominated in. Currently always `"usdc"`. */
|
|
782
580
|
totalBalanceAsset: string;
|
|
783
581
|
agentBalances: Record<AgentId, AgentBalance>;
|
|
784
|
-
/**
|
|
785
|
-
|
|
786
|
-
* partial result. Callers may display the successful balances, but funding
|
|
787
|
-
* operations must not interpret a missing agent as having a zero balance.
|
|
788
|
-
*/
|
|
789
|
-
agentErrors?: Partial<Record<AgentId, string>>;
|
|
582
|
+
/** Omitted agents failed to load; they must not be interpreted as zero. */
|
|
583
|
+
agentErrors?: Record<AgentId, string>;
|
|
790
584
|
/** Absolute provider cooldown deadlines (Unix milliseconds). */
|
|
791
|
-
agentRetryAt?:
|
|
585
|
+
agentRetryAt?: Record<AgentId, number>;
|
|
792
586
|
}
|
|
793
587
|
interface AgentEarnings {
|
|
794
588
|
smartWallet: `0x${string}`;
|
|
@@ -798,10 +592,6 @@ interface AgentEarnings {
|
|
|
798
592
|
interface OwneyEarnings {
|
|
799
593
|
totalEarnings: string;
|
|
800
594
|
agentEarnings: Record<AgentId, AgentEarnings>;
|
|
801
|
-
/** Per-agent failures when an aggregate read returned a partial result. */
|
|
802
|
-
agentErrors?: Partial<Record<AgentId, string>>;
|
|
803
|
-
/** Absolute provider cooldown deadlines (Unix milliseconds). */
|
|
804
|
-
agentRetryAt?: Partial<Record<AgentId, number>>;
|
|
805
595
|
}
|
|
806
596
|
type ApyByChainAndAsset = Partial<Record<OwneySupportedChainId, Partial<Record<OwneySupportedTokens, number>>>>;
|
|
807
597
|
/** A single day's net APY for the connected account, as a percentage number. */
|
|
@@ -847,15 +637,6 @@ interface OwneyAllocationApy {
|
|
|
847
637
|
}
|
|
848
638
|
type HistoryAction = "Rebalance" | "Deposit" | "Top up" | "Withdraw" | "Earned";
|
|
849
639
|
interface HistoryTransaction {
|
|
850
|
-
tokenAddress?: string;
|
|
851
|
-
agentWallet?: string;
|
|
852
|
-
logIndexes?: number[];
|
|
853
|
-
transferLogs?: {
|
|
854
|
-
logIndex: number;
|
|
855
|
-
amountRaw: string;
|
|
856
|
-
}[];
|
|
857
|
-
amountRaw?: string;
|
|
858
|
-
blockNumber?: string;
|
|
859
640
|
txHashes: string[];
|
|
860
641
|
chainId?: number;
|
|
861
642
|
tokenSymbol?: string;
|
|
@@ -884,10 +665,17 @@ interface AgentHistoryPosition {
|
|
|
884
665
|
amount?: string;
|
|
885
666
|
}
|
|
886
667
|
interface AgentHistoryEntry {
|
|
887
|
-
/** Stable provider/transfer identity, independent of row order. */
|
|
888
|
-
id?: string;
|
|
889
668
|
agent: AgentId;
|
|
890
669
|
action: HistoryAction;
|
|
670
|
+
/**
|
|
671
|
+
* Chain this entry came from, stamped by the history fan-out (ROUT-479).
|
|
672
|
+
*
|
|
673
|
+
* Absent on a single-chain read, where the caller already knows the chain.
|
|
674
|
+
* The entry has no chain of its own otherwise: `transactions[].chainId` is
|
|
675
|
+
* optional and missing whenever the indexer has not attached the transfer,
|
|
676
|
+
* so a row cannot be labelled from it reliably.
|
|
677
|
+
*/
|
|
678
|
+
chainId?: OwneySupportedChainId;
|
|
891
679
|
date: string;
|
|
892
680
|
oldApy: string | null;
|
|
893
681
|
newApy: string | null;
|
|
@@ -896,8 +684,6 @@ interface AgentHistoryEntry {
|
|
|
896
684
|
positions?: AgentHistoryPosition[];
|
|
897
685
|
}
|
|
898
686
|
interface OwneyAgentHistory {
|
|
899
|
-
agentErrors?: Partial<Record<AgentId, string>>;
|
|
900
|
-
agentRetryAt?: Partial<Record<AgentId, number>>;
|
|
901
687
|
data: AgentHistoryEntry[];
|
|
902
688
|
/** True iff a subsequent page exists; pair with `nextCursor`. */
|
|
903
689
|
hasMore: boolean;
|
|
@@ -938,15 +724,15 @@ interface AgentApy {
|
|
|
938
724
|
interface OwneyAgentApy {
|
|
939
725
|
agentApy: Record<AgentId, AgentApy>;
|
|
940
726
|
}
|
|
941
|
-
/** One day's cumulative earnings for a single asset. */
|
|
727
|
+
/** One day's cumulative NET earnings for a single asset. */
|
|
942
728
|
interface DailyEarningsPoint {
|
|
943
729
|
/** ISO date string for the day, e.g. "2026-09-01". */
|
|
944
730
|
date: string;
|
|
945
731
|
/**
|
|
946
|
-
*
|
|
947
|
-
*
|
|
948
|
-
*
|
|
949
|
-
*
|
|
732
|
+
* Earnings accumulated from the start of the returned series up to and
|
|
733
|
+
* including this day, net of the agent's performance fee, denominated in the
|
|
734
|
+
* asset's own units. A running total of daily deltas, so it measures the
|
|
735
|
+
* window — not the wallet's lifetime.
|
|
950
736
|
*/
|
|
951
737
|
amount: number;
|
|
952
738
|
}
|
|
@@ -955,9 +741,8 @@ interface AssetDailyEarnings {
|
|
|
955
741
|
/** Asset symbol, e.g. "USDC" / "WETH". */
|
|
956
742
|
asset: string;
|
|
957
743
|
/**
|
|
958
|
-
* Ascending by date
|
|
959
|
-
*
|
|
960
|
-
* most recent cumulative value across dates reported by other providers.
|
|
744
|
+
* Ascending by date. Days the wallet held nothing of this asset are absent
|
|
745
|
+
* rather than zero — a zero would read as "earned nothing that day".
|
|
961
746
|
*/
|
|
962
747
|
points: DailyEarningsPoint[];
|
|
963
748
|
}
|
|
@@ -974,7 +759,70 @@ interface AccountDailyEarnings {
|
|
|
974
759
|
assets: AssetDailyEarnings[];
|
|
975
760
|
}
|
|
976
761
|
|
|
977
|
-
type
|
|
762
|
+
type DepositCallback = (smartWalletAddress: string, chainId: number, amount: string) => Promise<`0x${string}`> | `0x${string}`;
|
|
763
|
+
interface IAgent {
|
|
764
|
+
readonly id: string;
|
|
765
|
+
readonly supportedChainIds: readonly OwneySupportedChainId[];
|
|
766
|
+
readonly supportedAssets: readonly AgentSupportedAssets[];
|
|
767
|
+
disconnect(): Promise<void>;
|
|
768
|
+
activateAgent(state: ConnectionState, chainId: number): Promise<void>;
|
|
769
|
+
/**
|
|
770
|
+
* Apply the organization's agent policy to this user's account.
|
|
771
|
+
*
|
|
772
|
+
* Optional: an agent that has no equivalent knob simply omits it, which is why
|
|
773
|
+
* this is not part of `activateAgent`'s signature. Declared on the interface
|
|
774
|
+
* rather than only on ZyfaiAgent so the contract stays agent-neutral — the
|
|
775
|
+
* ticket asks for a design that can also cover Surf, which has no adapter yet.
|
|
776
|
+
*
|
|
777
|
+
* Implementations must be **non-fatal**: this runs during activation as a side
|
|
778
|
+
* effect, so a failure has to leave the user connected and their profile
|
|
779
|
+
* unchanged rather than break the connect.
|
|
780
|
+
*/
|
|
781
|
+
applyOrgPolicy?(state: ConnectionState, chainId: number, policy: OrgAgentConfig): Promise<void>;
|
|
782
|
+
deposit(state: ConnectionState, chainId: number, amount: string, asset: OwneySupportedTokens, depositCallback?: DepositCallback): Promise<OwneyDepositResult>;
|
|
783
|
+
withdraw(state: ConnectionState, chainId: number, token: OwneySupportedTokens, amount?: string): Promise<AgentWithdrawResult>;
|
|
784
|
+
getBalances(state: ConnectionState, chainId: number): Promise<AgentBalance>;
|
|
785
|
+
getEarnings(state: ConnectionState, chainId: number): Promise<AgentEarnings>;
|
|
786
|
+
/**
|
|
787
|
+
* Refresh the agent's earnings snapshot when its backend supports doing so.
|
|
788
|
+
* Implementations own freshness and request-deduplication policy.
|
|
789
|
+
*/
|
|
790
|
+
refreshEarnings?(state: ConnectionState, chainId: number): Promise<AgentEarnings>;
|
|
791
|
+
getAccountApy(state: ConnectionState, chainId: number, days: DailyApyDays,
|
|
792
|
+
/**
|
|
793
|
+
* Optional asset symbol ("USDC" / "WETH") scoping the daily series to a
|
|
794
|
+
* single asset on the chain. Agents without per-asset positions ignore it.
|
|
795
|
+
*/
|
|
796
|
+
tokenSymbol?: string): Promise<AccountAgentApy>;
|
|
797
|
+
/**
|
|
798
|
+
* Daily cumulative NET earnings for the window, scoped to a chain/asset.
|
|
799
|
+
* Backs the "recent earnings" subline, whose figure must reconcile with the
|
|
800
|
+
* balance headline directly above it. (ROUT-452)
|
|
801
|
+
*/
|
|
802
|
+
getDailyEarnings?(state: ConnectionState, chainId: number, days: LookbackDays, tokenSymbol?: string): Promise<AccountDailyEarnings>;
|
|
803
|
+
getHistory(state: ConnectionState, chainId: number, options?: HistoryFilters): Promise<OwneyAgentHistory>;
|
|
804
|
+
getUserProfile(state: ConnectionState, chainId: number): Promise<AgentUserProfile>;
|
|
805
|
+
/**
|
|
806
|
+
* Ensure the given asset uses backend protocol auto-selection
|
|
807
|
+
* (`autoSelectProtocols: true`). Optional capability — only agents whose
|
|
808
|
+
* backend models per-asset protocol selection implement it. Returns whether
|
|
809
|
+
* a write occurred (`false` = already enabled / not supported).
|
|
810
|
+
*/
|
|
811
|
+
ensureAutoSelectProtocols?(state: ConnectionState, chainId: number, asset: "USDC" | "WETH"): Promise<boolean>;
|
|
812
|
+
getAgentApy(days: DailyApyDays, options?: AgentApyOptions): Promise<AgentApy>;
|
|
813
|
+
}
|
|
814
|
+
/**
|
|
815
|
+
* Optional filters for per-agent APY lookups.
|
|
816
|
+
* - `tokenSymbol` / `chainId` scope the APY to a specific asset+chain when
|
|
817
|
+
* the underlying provider supports it (Zyfai). Agents whose backends do
|
|
818
|
+
* not yet support per-asset APY will ignore these options.
|
|
819
|
+
*/
|
|
820
|
+
type AgentApyOptions = {
|
|
821
|
+
tokenSymbol?: string;
|
|
822
|
+
chainId?: number;
|
|
823
|
+
};
|
|
824
|
+
|
|
825
|
+
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_NOTHING_TO_WITHDRAW" | "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_DEPOSIT_PENDING" | "SWAP_WALLET_PROMPT_TIMEOUT" | "SWAP_INSUFFICIENT_GAS" | "SWAP_NATIVE_UNSUPPORTED" | "SWAP_ORDER_EXPIRED" | "SWAP_ORDER_REFUNDED" | "SWAP_ORDER_CANCELLED" | "WITHDRAW_ARRIVAL_TIMEOUT" | "WITHDRAW_SWAP_FAILED" | "BALANCE_ALL_FAILED" | "ALLOCATION_ALL_FAILED" | "VALIDATION_INVALID_DAYS";
|
|
978
826
|
declare class OwneyError extends Error {
|
|
979
827
|
readonly code: OwneyErrorCode;
|
|
980
828
|
readonly details?: Record<string, unknown>;
|
|
@@ -999,30 +847,41 @@ declare class AgentChainIncompatibleError extends OwneyError {
|
|
|
999
847
|
}>, connectedChainId: number);
|
|
1000
848
|
}
|
|
1001
849
|
|
|
1002
|
-
/**
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
850
|
+
/**
|
|
851
|
+
* Withdrawal swaps the user has walked away from, and how they ended.
|
|
852
|
+
*
|
|
853
|
+
* The deposit side has `swap.pending-deposit.ts` for the same shape of
|
|
854
|
+
* problem, but the two are not symmetrical. A pending deposit is a JOB: the
|
|
855
|
+
* money is in the wallet and an ordinary deposit finishes it. This is a
|
|
856
|
+
* WATCH — the funds are in escrow, nothing the user does moves them along,
|
|
857
|
+
* and the only question is where they ended up.
|
|
858
|
+
*
|
|
859
|
+
* That is the whole reason this exists. `withdrawAndSwap` used to hold the
|
|
860
|
+
* screen for the entire escrow lifecycle, which on a slow mainnet fill is
|
|
861
|
+
* minutes of a modal the user cannot leave (ROUT-242). Backgrounding it means
|
|
862
|
+
* the outcome arrives after the UI that started it has gone, so the outcome
|
|
863
|
+
* has to be written down somewhere the next render can find it.
|
|
864
|
+
*
|
|
865
|
+
* Only cross-chain swaps are recorded. A same-chain classic swap is one
|
|
866
|
+
* transaction and resolves in seconds; a same-chain fusion order has no stored
|
|
867
|
+
* preimages, so there would be nothing for a reloaded session to resume and
|
|
868
|
+
* the record would sit at `swapping` for ever.
|
|
869
|
+
*
|
|
870
|
+
* Kept deliberately separate from the secret store. Secrets are retired the
|
|
871
|
+
* moment an order reaches a verdict — that is a safety property, not a display
|
|
872
|
+
* one — and the record has to outlive them so the user can still be told what
|
|
873
|
+
* happened after they come back.
|
|
874
|
+
*/
|
|
875
|
+
/**
|
|
876
|
+
* `swapping` is the only non-terminal state. `unknown` is what a watch that
|
|
877
|
+
* gave up looks like: we stopped polling before the order spoke, so the order
|
|
878
|
+
* may well have filled. It is not a failure, and it must never be shown as
|
|
879
|
+
* one.
|
|
880
|
+
*/
|
|
881
|
+
type WithdrawSwapStatus = "swapping" | "landed" | "refunded" | "unknown";
|
|
1018
882
|
type WithdrawSwapRecord = {
|
|
1019
883
|
/** Identity. One record per Fusion+ order. */
|
|
1020
884
|
orderHash: string;
|
|
1021
|
-
walletAddress?: string;
|
|
1022
|
-
txHash?: string;
|
|
1023
|
-
recovery?: WithdrawalSwapRecovery;
|
|
1024
|
-
spent?: string;
|
|
1025
|
-
dismissed?: boolean;
|
|
1026
885
|
status: WithdrawSwapStatus;
|
|
1027
886
|
/**
|
|
1028
887
|
* What actually left the agent, smallest unit of the SOURCE asset.
|
|
@@ -1059,7 +918,7 @@ declare function subscribeWithdrawSwaps(listener: () => void): () => void;
|
|
|
1059
918
|
* Not after the swap resolves: the point is to survive the gap between submit
|
|
1060
919
|
* and settle, which is exactly when the user closes the tab.
|
|
1061
920
|
*/
|
|
1062
|
-
declare function saveWithdrawSwap(record: WithdrawSwapRecord):
|
|
921
|
+
declare function saveWithdrawSwap(record: WithdrawSwapRecord): void;
|
|
1063
922
|
/**
|
|
1064
923
|
* Move a record to its outcome.
|
|
1065
924
|
*
|
|
@@ -1073,8 +932,8 @@ declare function saveWithdrawSwap(record: WithdrawSwapRecord): boolean;
|
|
|
1073
932
|
declare function updateWithdrawSwap(orderHash: string, patch: Partial<Omit<WithdrawSwapRecord, "orderHash">>): void;
|
|
1074
933
|
/** The user has read the outcome. Only they do this. */
|
|
1075
934
|
declare function clearWithdrawSwap(orderHash: string): void;
|
|
1076
|
-
/**
|
|
1077
|
-
declare function listWithdrawSwaps(now?: number
|
|
935
|
+
/** Every record, newest first, sweeping anything past MAX_AGE_MS. */
|
|
936
|
+
declare function listWithdrawSwaps(now?: number): WithdrawSwapRecord[];
|
|
1078
937
|
|
|
1079
938
|
/**
|
|
1080
939
|
* Swaps that landed but were never deposited.
|
|
@@ -1123,15 +982,10 @@ declare class OwneySDK {
|
|
|
1123
982
|
*/
|
|
1124
983
|
private disabledAgents;
|
|
1125
984
|
private state;
|
|
1126
|
-
private connectionRevision;
|
|
1127
|
-
private disconnectingAgents;
|
|
1128
985
|
private apiKey;
|
|
1129
986
|
private orgAgentConfig;
|
|
1130
987
|
private orgAgentConfigPromise;
|
|
1131
|
-
private rpcUrls?;
|
|
1132
988
|
private zyfaiRpcUrls?;
|
|
1133
|
-
private yieldseekerApiBaseUrl?;
|
|
1134
|
-
private yieldseekerSiweOrigin?;
|
|
1135
989
|
private routingApiBaseUrl?;
|
|
1136
990
|
private referralSource?;
|
|
1137
991
|
private cachedSponsoredCallback;
|
|
@@ -1139,11 +993,7 @@ declare class OwneySDK {
|
|
|
1139
993
|
private paymasterServiceUrl?;
|
|
1140
994
|
private cachedSponsoredCallsCallbacks;
|
|
1141
995
|
private readonly agentReads;
|
|
1142
|
-
private readonly recoveredFundingReads;
|
|
1143
|
-
private fundingBalanceChecks;
|
|
1144
996
|
private readonly activationChecks;
|
|
1145
|
-
private readonly withdrawalSubmissions;
|
|
1146
|
-
private readonly withdrawalSwapSubmissions;
|
|
1147
997
|
private readAgent;
|
|
1148
998
|
private initializingAgentsPromise;
|
|
1149
999
|
constructor(config: OwneySDKConfig);
|
|
@@ -1158,8 +1008,6 @@ declare class OwneySDK {
|
|
|
1158
1008
|
* After calling this, `connect()` must be called again before using agent methods.
|
|
1159
1009
|
*/
|
|
1160
1010
|
disconnect(): Promise<void>;
|
|
1161
|
-
private clearConnectionState;
|
|
1162
|
-
private disconnectAgents;
|
|
1163
1011
|
private isAgentDisabled;
|
|
1164
1012
|
/**
|
|
1165
1013
|
* Check if the SDK has an active connection state.
|
|
@@ -1174,20 +1022,28 @@ declare class OwneySDK {
|
|
|
1174
1022
|
private requireState;
|
|
1175
1023
|
private requireChainId;
|
|
1176
1024
|
private requireConnectedProvider;
|
|
1177
|
-
|
|
1178
|
-
|
|
1025
|
+
/**
|
|
1026
|
+
* Lazily builds (and caches) the default EIP-3009 sponsored deposit callback
|
|
1027
|
+
* used when the caller omits `depositCallback`. Wraps the connected EIP-1193
|
|
1028
|
+
* provider with viem `custom(provider)` to read token meta and sign the
|
|
1029
|
+
* `TransferWithAuthorization`, then POSTs to the sponsor API.
|
|
1030
|
+
*/
|
|
1179
1031
|
private getDefaultSponsoredCallback;
|
|
1180
|
-
/**
|
|
1032
|
+
/**
|
|
1033
|
+
* Lazily builds (and caches) the default Permit2 sponsored WETH deposit
|
|
1034
|
+
* callback used when the caller omits `depositCallback` for a WETH
|
|
1035
|
+
* deposit. Mirrors `getDefaultSponsoredCallback()` but signs a Permit2
|
|
1036
|
+
* `PermitTransferFrom` instead of an EIP-3009 authorization.
|
|
1037
|
+
*/
|
|
1181
1038
|
private getDefaultSponsoredCallsCallback;
|
|
1182
1039
|
/**
|
|
1183
1040
|
* Lazily builds (and caches) the default Permit2 sponsored WETH deposit
|
|
1184
1041
|
* callback used when the caller omits `depositCallback` for a WETH deposit.
|
|
1185
1042
|
* Mirrors `getDefaultSponsoredCallback()` but signs a Permit2
|
|
1186
|
-
*
|
|
1043
|
+
* `PermitTransferFrom` instead of an EIP-3009 authorization.
|
|
1187
1044
|
*/
|
|
1188
1045
|
private getDefaultWethSponsoredCallback;
|
|
1189
1046
|
private getAgent;
|
|
1190
|
-
getActiveAgentIds(): AgentId[];
|
|
1191
1047
|
private getActiveAgents;
|
|
1192
1048
|
/**
|
|
1193
1049
|
* Read the org's agent policy once and reuse it. fetchOrgAgentConfig never
|
|
@@ -1220,8 +1076,7 @@ declare class OwneySDK {
|
|
|
1220
1076
|
* If provided, ALL specified agents must support the chainId or the call
|
|
1221
1077
|
* throws before activating any agent.
|
|
1222
1078
|
*/
|
|
1223
|
-
activateAgent(chainId: number, agentId?: AgentId[]
|
|
1224
|
-
private assertActivationSession;
|
|
1079
|
+
activateAgent(chainId: number, agentId?: AgentId[]): Promise<void>;
|
|
1225
1080
|
/**
|
|
1226
1081
|
* Activate agents ONE AT A TIME, each followed by its org policy.
|
|
1227
1082
|
*
|
|
@@ -1235,9 +1090,10 @@ declare class OwneySDK {
|
|
|
1235
1090
|
* Serializing costs no real wall-clock: the user can only approve one prompt
|
|
1236
1091
|
* at a time anyway.
|
|
1237
1092
|
*
|
|
1238
|
-
*
|
|
1239
|
-
*
|
|
1240
|
-
*
|
|
1093
|
+
* Every agent is attempted even if an earlier one fails, so one declined
|
|
1094
|
+
* signature can't deny the remaining agents their turn. The first failure is
|
|
1095
|
+
* rethrown (matching the previous `Promise.all` rejection) once all agents
|
|
1096
|
+
* have had a chance to activate.
|
|
1241
1097
|
*/
|
|
1242
1098
|
private activateAgentsInTurn;
|
|
1243
1099
|
/**
|
|
@@ -1248,8 +1104,7 @@ declare class OwneySDK {
|
|
|
1248
1104
|
* @param options.asset - Asset symbol to deposit (e.g. "USDC")
|
|
1249
1105
|
* @param options.depositCallback - Callback that performs the token transfer and returns a tx hash.
|
|
1250
1106
|
* When agentId is omitted, this callback is invoked once per eligible agent with that agent's
|
|
1251
|
-
* split amount and smart wallet address
|
|
1252
|
-
* all shares into one signature; custom callbacks still run once per agent.
|
|
1107
|
+
* split amount and smart wallet address — expect multiple wallet prompts.
|
|
1253
1108
|
* @param options.agentId - Optional explicit target. Otherwise split equally,
|
|
1254
1109
|
* or fund remaining agents when a recovery deposit cannot meet every minimum.
|
|
1255
1110
|
* @returns {OwneyDepositResult} for a single agent, or {OwneyMultiDepositResult} with per-agent results
|
|
@@ -1259,12 +1114,10 @@ declare class OwneySDK {
|
|
|
1259
1114
|
* Invokes `agent.deposit` with the resolved sponsored callback, composing
|
|
1260
1115
|
* two independent auto-recovery mechanisms:
|
|
1261
1116
|
*
|
|
1262
|
-
* 1. Missing Permit2 allowance
|
|
1263
|
-
*
|
|
1264
|
-
*
|
|
1265
|
-
*
|
|
1266
|
-
* its sponsored deposit and never reaches this branch. Other tokens send
|
|
1267
|
-
* the one-time user-paid Permit2 approval via `approvePermit2()` and
|
|
1117
|
+
* 1. Missing Permit2 allowance: when the app did not supply its own
|
|
1118
|
+
* callback and the attempt fails with `PERMIT2_APPROVAL_REQUIRED` on a
|
|
1119
|
+
* WETH deposit, this is the wallet's first gasless WETH deposit. We send
|
|
1120
|
+
* the one-time (user-paid) Permit2 approval via `approvePermit2()` and
|
|
1268
1121
|
* retry the SAME sponsored attempt once. Bounded to one approval attempt
|
|
1269
1122
|
* per call so a wallet/agent that keeps reporting the allowance as
|
|
1270
1123
|
* missing can't loop forever. If `approvePermit2()` itself throws (e.g.
|
|
@@ -1285,7 +1138,6 @@ declare class OwneySDK {
|
|
|
1285
1138
|
private depositWithFallback;
|
|
1286
1139
|
private getMinDepositAmount;
|
|
1287
1140
|
private splitDepositAmount;
|
|
1288
|
-
private formatAgentName;
|
|
1289
1141
|
private validateMinDepositAmount;
|
|
1290
1142
|
/**
|
|
1291
1143
|
* Whether the user already holds a non-zero balance with `agent` for the
|
|
@@ -1294,50 +1146,25 @@ declare class OwneySDK {
|
|
|
1294
1146
|
* false, so the minimum is enforced as today.
|
|
1295
1147
|
*/
|
|
1296
1148
|
private hasExistingBalance;
|
|
1149
|
+
/**
|
|
1150
|
+
* Guard an explicitly requested chain against one agent's own list.
|
|
1151
|
+
*
|
|
1152
|
+
* Only reachable when the caller passes `chainId` — the activated chain has
|
|
1153
|
+
* already been checked by `activateAgent`. Kept separate from
|
|
1154
|
+
* `validateAssetSupport` so "this agent is not on Ethereum" does not arrive
|
|
1155
|
+
* worded as "this agent does not support USDC".
|
|
1156
|
+
*/
|
|
1157
|
+
private validateChainSupport;
|
|
1158
|
+
/**
|
|
1159
|
+
* Guard an explicitly requested chain before a fan-out.
|
|
1160
|
+
*
|
|
1161
|
+
* Without this the split simply produces no agents, and the caller is told
|
|
1162
|
+
* their amount "cannot activate every eligible agent" against a combined
|
|
1163
|
+
* minimum of 0 — an error about the amount when the chain is at fault.
|
|
1164
|
+
*/
|
|
1165
|
+
private validateChainHasAgents;
|
|
1297
1166
|
private validateAssetSupport;
|
|
1298
1167
|
private getEligibleAgents;
|
|
1299
|
-
/**
|
|
1300
|
-
* Run owner-approved withdrawals before relayer-only withdrawals. Wallet
|
|
1301
|
-
* approval is the only point at which the user can cancel the aggregate
|
|
1302
|
-
* operation, so no relayer leg should commit before it has completed.
|
|
1303
|
-
*/
|
|
1304
|
-
private orderAgentsForWithdrawal;
|
|
1305
|
-
private isUserRejectedWithdrawal;
|
|
1306
|
-
private captureReadScope;
|
|
1307
|
-
/** Revalidate a saved transfer against the authenticated account and actual receipt. */
|
|
1308
|
-
inspectFunding(evidence: FundingEvidence, direction: "deposit" | "withdraw", options?: {
|
|
1309
|
-
balanceRefreshUntil?: number;
|
|
1310
|
-
refreshBalance?: boolean;
|
|
1311
|
-
requireAmountMatch?: boolean;
|
|
1312
|
-
}): Promise<FundingEvidence>;
|
|
1313
|
-
/** Resolve a saved sponsored-withdrawal ID without opening a wallet prompt. */
|
|
1314
|
-
resolveSponsoredWithdrawalEvidence(evidence: FundingEvidence, options?: {
|
|
1315
|
-
submittedAt?: number;
|
|
1316
|
-
}): Promise<FundingEvidence>;
|
|
1317
|
-
/** Recover an EIP-5792 deposit or payout using this account's exact batch ID. */
|
|
1318
|
-
resolveWalletCallsFundingEvidence(evidence: FundingEvidence, direction: "deposit" | "withdraw"): Promise<FundingEvidence>;
|
|
1319
|
-
/** Whether a foreground deposit can resume the same signed batch, never a
|
|
1320
|
-
* fresh authorization. The batch rail independently rechecks the exact plan. */
|
|
1321
|
-
canResumePendingDeposit(evidences: FundingEvidence[], amount: string): Promise<boolean>;
|
|
1322
|
-
/** Optional post-payout display proof; receipt verification and the provider
|
|
1323
|
-
* adapter must agree before attaching it to this exact balance object. */
|
|
1324
|
-
verifyWithdrawalBalance(evidence: FundingEvidence, balance: AgentBalance): Promise<AgentBalance>;
|
|
1325
|
-
/** A display acknowledgement controls polling only; it never confirms a financial outcome. */
|
|
1326
|
-
endFundingBalanceRefresh(evidence: FundingEvidence, read: AssetReadMetadata): boolean;
|
|
1327
|
-
/** History lookup for receipt recovery; adapters may not authenticate or sign here. */
|
|
1328
|
-
getFundingHistory(evidence: FundingEvidence, fromDate: string, options?: Pick<HistoryFilters, "cursor" | "toDate">): Promise<OwneyAgentHistory>;
|
|
1329
|
-
recoverDepositRegistration(evidence: FundingEvidence): Promise<FundingEvidence>;
|
|
1330
|
-
/** On-chain version and ownership status for this owner's Yieldseeker agent. */
|
|
1331
|
-
getYieldseekerWalletStatus(asset: OwneySupportedTokens): Promise<YieldseekerWalletStatus | null>;
|
|
1332
|
-
/** Deployment gate; an unavailable response keeps the current paid path. */
|
|
1333
|
-
isYieldseekerWithdrawalSponsorshipAvailable(): Promise<boolean>;
|
|
1334
|
-
isYieldseekerUpgradeSponsorshipAvailable(): Promise<boolean>;
|
|
1335
|
-
private isYieldseekerSponsorshipAvailable;
|
|
1336
|
-
/** Explicit V1-to-V2 upgrade, confirmed on chain before returning. */
|
|
1337
|
-
upgradeYieldseekerWallet(asset: OwneySupportedTokens, gasMode?: "paid" | "sponsored"): Promise<{
|
|
1338
|
-
txHash: viem.Hex;
|
|
1339
|
-
status: YieldseekerWalletStatus;
|
|
1340
|
-
}>;
|
|
1341
1168
|
/** Lazily built so an app that never swaps pays nothing for it. */
|
|
1342
1169
|
private swapApiClient?;
|
|
1343
1170
|
private swapApi;
|
|
@@ -1382,15 +1209,45 @@ declare class OwneySDK {
|
|
|
1382
1209
|
* would strand funds we might have been able to move.
|
|
1383
1210
|
*/
|
|
1384
1211
|
/** ERC20 balance of the connected wallet, read through the wallet's own node. */
|
|
1212
|
+
/**
|
|
1213
|
+
* A read client pinned to `chainId`, over HTTP rather than the wallet.
|
|
1214
|
+
*
|
|
1215
|
+
* The swap rail has read this way from the start, and the reason is written
|
|
1216
|
+
* out at `buildSwapDeps`: a provider-backed client reads from whatever chain
|
|
1217
|
+
* the WALLET is on, which after a cross-chain swap is the source chain, not
|
|
1218
|
+
* the one the funds landed on. The deposit's own reads did not, so a Permit2
|
|
1219
|
+
* check for WETH on Arbitrum went to Base — where that address is not a
|
|
1220
|
+
* contract at all, so viem got "0x" back and threw "The contract function
|
|
1221
|
+
* 'allowance' returned no data".
|
|
1222
|
+
*/
|
|
1223
|
+
private chainReader;
|
|
1385
1224
|
private readTokenBalance;
|
|
1386
1225
|
/** How much of `token` the wallet has already approved Permit2 to move. */
|
|
1387
1226
|
private readTokenPermit2Allowance;
|
|
1388
1227
|
/**
|
|
1389
|
-
*
|
|
1390
|
-
*
|
|
1391
|
-
*
|
|
1392
|
-
*
|
|
1393
|
-
*
|
|
1228
|
+
* How much of a landed swap to actually deposit.
|
|
1229
|
+
*
|
|
1230
|
+
* The swap reports what ARRIVED, and the deposit used to be handed that
|
|
1231
|
+
* figure directly. It is the entire arrival, so there is no slack: anything
|
|
1232
|
+
* that spends the target asset between the two fails the deposit outright.
|
|
1233
|
+
*
|
|
1234
|
+
* Something does. A first WETH deposit needs a one-time Permit2 approval,
|
|
1235
|
+
* and that approval is a transaction. A wallet holding no native gas token -
|
|
1236
|
+
* the normal state of someone who just swapped everything INTO WETH - pays
|
|
1237
|
+
* for it out of the WETH. The deposit then asked for ~2e12 wei more than was
|
|
1238
|
+
* left and refused with DEPOSIT_INSUFFICIENT_BALANCE, under a wrapper saying
|
|
1239
|
+
* the funds were safe but unadded (ROUT-242).
|
|
1240
|
+
*
|
|
1241
|
+
* So the approval happens here, before the amount is settled, and the amount
|
|
1242
|
+
* comes from a read taken after it. Two things this deliberately is not:
|
|
1243
|
+
*
|
|
1244
|
+
* - It is not a balance sweep. `received` is a DELTA over the pre-swap
|
|
1245
|
+
* balance, so a wallet already holding WETH reads far above it; depositing
|
|
1246
|
+
* the balance would move funds the user never offered. The arrival is the
|
|
1247
|
+
* ceiling and the balance is only ever allowed to lower it.
|
|
1248
|
+
* - It does not touch USDC, which moves on signed typed data and so spends
|
|
1249
|
+
* nothing of the user's in between, nor a paymaster-configured client,
|
|
1250
|
+
* where the sponsor covers the transfer and Permit2 never applies.
|
|
1394
1251
|
*/
|
|
1395
1252
|
private settleSwapDepositAmount;
|
|
1396
1253
|
private walletSeesBalance;
|
|
@@ -1463,12 +1320,11 @@ declare class OwneySDK {
|
|
|
1463
1320
|
* Every order is attempted even if an earlier one throws: they are unrelated
|
|
1464
1321
|
* escrows, and one ending badly must not abandon the next one's secrets.
|
|
1465
1322
|
* `unfinished` is not a verdict — the order may still settle, so unless the
|
|
1466
|
-
*
|
|
1323
|
+
* chain has said refunded or cancelled its preimages are kept.
|
|
1467
1324
|
*/
|
|
1468
1325
|
resumePendingSwaps(options?: {
|
|
1469
1326
|
onStage?: (orderHash: string, stage: SwapStage) => void;
|
|
1470
1327
|
timeoutMs?: number;
|
|
1471
|
-
orderHash?: string;
|
|
1472
1328
|
}): Promise<{
|
|
1473
1329
|
orderHash: string;
|
|
1474
1330
|
status: "completed" | "unfinished";
|
|
@@ -1600,20 +1456,6 @@ declare class OwneySDK {
|
|
|
1600
1456
|
*/
|
|
1601
1457
|
deposited: string;
|
|
1602
1458
|
}>;
|
|
1603
|
-
/** Read-only confirmation of a saved pre-swap withdrawal. Never withdraws or swaps. */
|
|
1604
|
-
recheckWithdrawalSwap(id: string): Promise<WithdrawSwapRecord>;
|
|
1605
|
-
/** Explicit foreground continuation: spends verified payouts, never withdraws again. */
|
|
1606
|
-
continueWithdrawalSwap(id: string, callbacks?: Pick<Parameters<OwneySDK["withdrawAndSwap"]>[0], "onSwapProgress" | "onOrderSubmitted" | "onWithdrawalProgress" | "assertCurrent">): Promise<{
|
|
1607
|
-
withdraw: OwneyWithdrawResult | AgentWithdrawResult;
|
|
1608
|
-
/** What actually arrived in the wallet, smallest unit of the agent's asset. */
|
|
1609
|
-
withdrawn: string;
|
|
1610
|
-
swap: {
|
|
1611
|
-
received: string;
|
|
1612
|
-
spent?: string;
|
|
1613
|
-
orderHash?: string;
|
|
1614
|
-
txHash?: string;
|
|
1615
|
-
};
|
|
1616
|
-
}>;
|
|
1617
1459
|
/**
|
|
1618
1460
|
* Withdraw from an agent and swap the proceeds into whatever the user wants
|
|
1619
1461
|
* to hold, delivered to their own wallet.
|
|
@@ -1626,9 +1468,10 @@ declare class OwneySDK {
|
|
|
1626
1468
|
* Quoting before the tokens land would size the swap against a balance that
|
|
1627
1469
|
* is not there yet.
|
|
1628
1470
|
*
|
|
1629
|
-
*
|
|
1630
|
-
*
|
|
1631
|
-
*
|
|
1471
|
+
* The swap is therefore sized from the MEASURED arrival, exactly as the
|
|
1472
|
+
* deposit path sizes its deposit from the measured swap output. On a full
|
|
1473
|
+
* withdrawal there is no other number available — "MAX" has no figure until
|
|
1474
|
+
* the agent picks one.
|
|
1632
1475
|
*
|
|
1633
1476
|
* **Failure here is not symmetrical with the deposit path.** A failed
|
|
1634
1477
|
* deposit-swap leaves the user holding what they started with. A failed
|
|
@@ -1648,7 +1491,6 @@ declare class OwneySDK {
|
|
|
1648
1491
|
to: {
|
|
1649
1492
|
chainId: number;
|
|
1650
1493
|
symbol: string;
|
|
1651
|
-
decimals?: number;
|
|
1652
1494
|
};
|
|
1653
1495
|
/** Human units ("10.5"). Omit to withdraw the full agent balance. */
|
|
1654
1496
|
amount?: string;
|
|
@@ -1656,8 +1498,6 @@ declare class OwneySDK {
|
|
|
1656
1498
|
/** Percent, classic rail only. Fusion+ prices through its auction. */
|
|
1657
1499
|
slippage?: number;
|
|
1658
1500
|
onSwapProgress?: (stage: SwapStage) => void;
|
|
1659
|
-
/** Receipt evidence for the existing funding/recovery tracker. */
|
|
1660
|
-
onWithdrawalProgress?: FundingProgress;
|
|
1661
1501
|
/**
|
|
1662
1502
|
* Fires once the order is with the relayer, before the watch.
|
|
1663
1503
|
*
|
|
@@ -1683,22 +1523,15 @@ declare class OwneySDK {
|
|
|
1683
1523
|
withdrawn: string;
|
|
1684
1524
|
/** Smallest unit of the destination — the auction's start, not its floor. */
|
|
1685
1525
|
expected: string;
|
|
1686
|
-
spent?: string;
|
|
1687
|
-
durable?: boolean;
|
|
1688
1526
|
}) => void;
|
|
1689
1527
|
/** How long to wait for the withdrawal to land before giving up on the swap. */
|
|
1690
1528
|
arrivalTimeoutMs?: number;
|
|
1691
|
-
/** UI ownership fence, checked before each financial continuation. */
|
|
1692
|
-
assertCurrent?: () => void;
|
|
1693
|
-
/** Used only by explicit continueWithdrawalSwap; it never sends another withdrawal. */
|
|
1694
|
-
recoveryId?: string;
|
|
1695
1529
|
}): Promise<{
|
|
1696
1530
|
withdraw: OwneyWithdrawResult | AgentWithdrawResult;
|
|
1697
1531
|
/** What actually arrived in the wallet, smallest unit of the agent's asset. */
|
|
1698
1532
|
withdrawn: string;
|
|
1699
1533
|
swap: {
|
|
1700
1534
|
received: string;
|
|
1701
|
-
spent?: string;
|
|
1702
1535
|
orderHash?: string;
|
|
1703
1536
|
txHash?: string;
|
|
1704
1537
|
};
|
|
@@ -1713,21 +1546,25 @@ declare class OwneySDK {
|
|
|
1713
1546
|
* @returns {AgentWithdrawResult} for a single agent, or {OwneyWithdrawResult} with per-agent results
|
|
1714
1547
|
*/
|
|
1715
1548
|
withdraw(options: WithdrawOptions): Promise<OwneyWithdrawResult | AgentWithdrawResult>;
|
|
1716
|
-
private withdrawFromAgents;
|
|
1717
|
-
/** Read-only invalidation after new pool-deposit activity. Does not restart
|
|
1718
|
-
* funding reconciliation, bypass cooldowns, or authorize a transaction. */
|
|
1719
|
-
invalidateAllocationRead(scope: Pick<FundingEvidence, "agentId" | "walletAddress" | "chainId" | "token">): boolean;
|
|
1720
1549
|
/**
|
|
1721
1550
|
* Get the user's balances for a specific agent, or aggregated across all agents.
|
|
1722
1551
|
* @param agentId - Optional. Agent to query. Omit for aggregated balances.
|
|
1723
1552
|
* @returns {AgentBalance} for a single agent, or {OwneyBalances} with totalBalance and per-agent breakdown
|
|
1724
1553
|
*/
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1554
|
+
/**
|
|
1555
|
+
* Withdraw every position the wallet holds, across chains and assets.
|
|
1556
|
+
*
|
|
1557
|
+
* `withdraw()` drains one asset on one chain, so this is N of those. It
|
|
1558
|
+
* deliberately does not stop at the first failure: the funds in the other
|
|
1559
|
+
* positions are just as withdrawable, and someone who asked for everything
|
|
1560
|
+
* is better served by three of four than by none. Each leg reports its own
|
|
1561
|
+
* outcome so the caller can name the ones that did not arrive; only a total
|
|
1562
|
+
* failure throws.
|
|
1563
|
+
*
|
|
1564
|
+
* @returns {OwneyWithdrawAllResult} one leg per position attempted.
|
|
1565
|
+
*/
|
|
1566
|
+
withdrawAll(): Promise<OwneyWithdrawAllResult>;
|
|
1567
|
+
getBalances(agentId?: AgentId): Promise<OwneyBalances | AgentBalance>;
|
|
1731
1568
|
/**
|
|
1732
1569
|
* Get the user's on-chain earnings for a specific agent, or aggregated across all agents.
|
|
1733
1570
|
* @param agentId - Optional. Agent to query. Omit for aggregated earnings.
|
|
@@ -1739,7 +1576,6 @@ declare class OwneySDK {
|
|
|
1739
1576
|
* Agents without a refresh capability fall back to their current snapshot.
|
|
1740
1577
|
*/
|
|
1741
1578
|
refreshEarnings(agentId?: AgentId): Promise<OwneyEarnings | AgentEarnings>;
|
|
1742
|
-
private aggregateEarnings;
|
|
1743
1579
|
/**
|
|
1744
1580
|
* Get the weighted APY for the user's account over a time period.
|
|
1745
1581
|
* When querying all agents, the total APY is a balance-weighted average.
|
|
@@ -1749,15 +1585,17 @@ declare class OwneySDK {
|
|
|
1749
1585
|
* @returns {AccountAgentApy} for a single agent, or {OwneyAccountApy} with totalApy and per-agent breakdown
|
|
1750
1586
|
*/
|
|
1751
1587
|
/**
|
|
1752
|
-
* Daily cumulative earnings
|
|
1753
|
-
* "recent earnings" subline.
|
|
1588
|
+
* Daily cumulative NET earnings for the selected chain/asset, backing the
|
|
1589
|
+
* "recent earnings" subline. Net is computed as Zyfai's own
|
|
1590
|
+
* `lifetime + unrealized + current x 0.9`, so the figure reconciles with the
|
|
1591
|
+
* balance headline rather than reading ~11% high. (ROUT-452)
|
|
1754
1592
|
*
|
|
1755
1593
|
* Unlike getAccountApy this does NOT blend across agents: earnings are
|
|
1756
1594
|
* summed, not weighted, and an agent that fails to report must not silently
|
|
1757
1595
|
* subtract from the total. Without an agentId the series is the sum of the
|
|
1758
1596
|
* agents that answered.
|
|
1759
1597
|
*/
|
|
1760
|
-
getDailyEarnings({ agentId, days, tokenSymbol, }: DailyEarningsOptions): Promise<AccountDailyEarnings>;
|
|
1598
|
+
getDailyEarnings({ agentId, days, tokenSymbol, chainIds, }: DailyEarningsOptions): Promise<AccountDailyEarnings>;
|
|
1761
1599
|
getAccountApy({ agentId, days, tokenSymbol, }: AccountApyOptions): Promise<OwneyAccountApy | AccountAgentApy>;
|
|
1762
1600
|
/**
|
|
1763
1601
|
* Get transaction history for a specific agent, or all agents.
|
|
@@ -1792,17 +1630,14 @@ declare class OwneySDK {
|
|
|
1792
1630
|
*/
|
|
1793
1631
|
ensureAutoSelectProtocols(asset: "USDC" | "WETH", agentId?: AgentId): Promise<boolean>;
|
|
1794
1632
|
/**
|
|
1795
|
-
*
|
|
1796
|
-
*
|
|
1797
|
-
*
|
|
1798
|
-
*
|
|
1799
|
-
*
|
|
1800
|
-
*
|
|
1801
|
-
* @param requiredAmount Raw base-unit amount the pending deposit must cover.
|
|
1802
|
-
* @param expectedChainId Chain captured by the deposit that requested approval.
|
|
1633
|
+
* One-time, user-paid approval of Permit2 on the sponsored WETH token for
|
|
1634
|
+
* the active chain. Required once per wallet per chain before gasless WETH
|
|
1635
|
+
* deposits; afterwards deposit() is signature-only. Resolves only after the
|
|
1636
|
+
* approval transaction is mined (1 confirmation), so a subsequent deposit()
|
|
1637
|
+
* will see the new allowance; throws if the transaction reverted.
|
|
1803
1638
|
* @returns the approval transaction hash.
|
|
1804
1639
|
*/
|
|
1805
|
-
approvePermit2(asset?:
|
|
1640
|
+
approvePermit2(asset?: "WETH"): Promise<`0x${string}`>;
|
|
1806
1641
|
/**
|
|
1807
1642
|
* Get the agent's average APY performance over a time period. Does not require a wallet connection.
|
|
1808
1643
|
* @param options - Contains agentId (optional) and days ("7D", "14D", or "30D")
|
|
@@ -1826,173 +1661,6 @@ declare class OwneySDK {
|
|
|
1826
1661
|
getAllocationApy({ agentId, }?: AllocationApyOptions): Promise<OwneyAllocationApy>;
|
|
1827
1662
|
}
|
|
1828
1663
|
|
|
1829
|
-
type YieldseekerAuthDependencies = {
|
|
1830
|
-
origin?: string;
|
|
1831
|
-
now?: () => Date;
|
|
1832
|
-
nonce?: () => string;
|
|
1833
|
-
};
|
|
1834
|
-
|
|
1835
|
-
type YieldseekerFetch = typeof fetch;
|
|
1836
|
-
|
|
1837
|
-
type YieldseekerTransaction = {
|
|
1838
|
-
from: `0x${string}`;
|
|
1839
|
-
to: `0x${string}`;
|
|
1840
|
-
data: `0x${string}`;
|
|
1841
|
-
value: string;
|
|
1842
|
-
chainId: number;
|
|
1843
|
-
};
|
|
1844
|
-
|
|
1845
|
-
type YieldseekerWalletStatus = {
|
|
1846
|
-
agentWallet: Address;
|
|
1847
|
-
owner: Address;
|
|
1848
|
-
ownerPath: "eoa" | "smart";
|
|
1849
|
-
asset: Address;
|
|
1850
|
-
implementation: Address;
|
|
1851
|
-
version: "v1" | "v2" | "unknown";
|
|
1852
|
-
upgradeAvailable: boolean;
|
|
1853
|
-
/** The factory, owner, base asset, and provider wallet mapping all agree. */
|
|
1854
|
-
verified: boolean;
|
|
1855
|
-
};
|
|
1856
|
-
|
|
1857
|
-
type YieldseekerAgentOptions = {
|
|
1858
|
-
baseUrl?: string;
|
|
1859
|
-
routingApiBaseUrl?: string;
|
|
1860
|
-
fetchFn?: YieldseekerFetch;
|
|
1861
|
-
auth?: YieldseekerAuthDependencies;
|
|
1862
|
-
/** Dedicated read transport; Base is used for receipt polling. */
|
|
1863
|
-
rpcUrls?: RpcUrlsConfig;
|
|
1864
|
-
/** Test seam for the wallet-submission/receipt boundary. */
|
|
1865
|
-
transactionExecutor?: (state: ConnectionState, chainId: number, transaction: YieldseekerTransaction, onReceipt?: (receipt: viem.TransactionReceipt) => void) => Promise<Hex>;
|
|
1866
|
-
/** Test seam for transactions submitted outside transactionExecutor. */
|
|
1867
|
-
unwindReceiptWaiter?: (state: ConnectionState, chainId: number, transactionHash: Hex) => Promise<void>;
|
|
1868
|
-
};
|
|
1869
|
-
declare class YieldseekerAgent implements IAgent {
|
|
1870
|
-
readonly id = "yieldseeker";
|
|
1871
|
-
readonly balanceComposition: "tokens-plus-positions";
|
|
1872
|
-
readonly withdrawalRequiresWalletApproval = true;
|
|
1873
|
-
readonly supportedChainIds: readonly [8453];
|
|
1874
|
-
readonly supportedAssets: readonly [{
|
|
1875
|
-
readonly chainId: 8453;
|
|
1876
|
-
readonly chain: "BASE";
|
|
1877
|
-
readonly assets: readonly [{
|
|
1878
|
-
readonly symbol: "USDC";
|
|
1879
|
-
readonly minDepositAmount: "10000000";
|
|
1880
|
-
}, {
|
|
1881
|
-
readonly symbol: "WETH";
|
|
1882
|
-
readonly minDepositAmount: "1";
|
|
1883
|
-
}];
|
|
1884
|
-
}];
|
|
1885
|
-
private readonly api;
|
|
1886
|
-
private readonly auth;
|
|
1887
|
-
private readonly rpcUrls?;
|
|
1888
|
-
private readonly owneyApiKey;
|
|
1889
|
-
private readonly routingApiBaseUrl?;
|
|
1890
|
-
private receiptClient?;
|
|
1891
|
-
private readonly withdrawalVersionCache;
|
|
1892
|
-
private readonly pendingUpgrades;
|
|
1893
|
-
private readonly transactionExecutor?;
|
|
1894
|
-
private readonly unwindReceiptWaiter?;
|
|
1895
|
-
private readonly agentContexts;
|
|
1896
|
-
private readonly balanceContexts;
|
|
1897
|
-
private readonly balanceVaults;
|
|
1898
|
-
private readonly users;
|
|
1899
|
-
private readonly pendingAgents;
|
|
1900
|
-
private readonly pendingWalletContexts;
|
|
1901
|
-
private readonly readCache;
|
|
1902
|
-
private readonly pendingReads;
|
|
1903
|
-
private readGeneration;
|
|
1904
|
-
private readonly portfolioVersions;
|
|
1905
|
-
private readonly liquidityVersions;
|
|
1906
|
-
private readonly snapshotFailures;
|
|
1907
|
-
private readonly standardReadFailures;
|
|
1908
|
-
private readonly reconcileUntil;
|
|
1909
|
-
private readonly allocationRefresh;
|
|
1910
|
-
private readonly activityRefreshUntil;
|
|
1911
|
-
private readonly snapshotMovements;
|
|
1912
|
-
private readonly movementEpochs;
|
|
1913
|
-
private readonly vaultOptions;
|
|
1914
|
-
private readonly pendingVaultOptions;
|
|
1915
|
-
constructor(owneyApiKey: string, options?: YieldseekerAgentOptions);
|
|
1916
|
-
private getReceiptClient;
|
|
1917
|
-
/** Reads the actual proxy implementation; Yieldseeker's API walletType is not a version check. */
|
|
1918
|
-
getWalletStatus(state: ConnectionState, chainId: number, asset: OwneySupportedTokens, useCachedV2?: boolean): Promise<YieldseekerWalletStatus | null>;
|
|
1919
|
-
private rememberWalletStatus;
|
|
1920
|
-
/** Explicit owner action. This never runs as a side effect of withdrawal. */
|
|
1921
|
-
upgradeWallet(state: ConnectionState, chainId: number, asset: OwneySupportedTokens, gasMode?: "paid" | "sponsored"): Promise<{
|
|
1922
|
-
txHash: Hex;
|
|
1923
|
-
status: YieldseekerWalletStatus;
|
|
1924
|
-
}>;
|
|
1925
|
-
disconnect(): Promise<void>;
|
|
1926
|
-
activateAgent(state: ConnectionState, chainId: number, asset?: OwneySupportedTokens): Promise<void>;
|
|
1927
|
-
deposit(state: ConnectionState, chainId: number, amount: string, asset: OwneySupportedTokens, depositCallback?: DepositCallback, onProgress?: FundingProgress, onBeforeSubmission?: (evidence: FundingEvidence) => void | Promise<void>): Promise<OwneyDepositResult>;
|
|
1928
|
-
withdraw(state: ConnectionState, chainId: number, asset: OwneySupportedTokens, amount?: string, onProgress?: FundingProgress, gasMode?: "auto" | "sponsored" | "paid", onBeforeSubmission?: FundingProgress, assertOperation?: () => void): Promise<AgentWithdrawResult>;
|
|
1929
|
-
private withdrawInternal;
|
|
1930
|
-
/** Fresh position amounts for withdrawal planning, net of reserved fees. */
|
|
1931
|
-
getWithdrawableBalance(state: ConnectionState, chainId: number, asset: OwneySupportedTokens, minimumAmount?: bigint): Promise<bigint>;
|
|
1932
|
-
/** Recheck MAX without re-unwinding, paying out, or requesting a signature. */
|
|
1933
|
-
verifyWithdrawalCompletion(state: ConnectionState, evidence: FundingEvidence): Promise<WithdrawalCompletion>;
|
|
1934
|
-
private readVaultShares;
|
|
1935
|
-
private validateWithdrawalPositions;
|
|
1936
|
-
private withdrawalVaultHints;
|
|
1937
|
-
private readWithdrawalPositions;
|
|
1938
|
-
private resolveWithdrawalLiquidity;
|
|
1939
|
-
getBalances(state: ConnectionState, chainId: number, asset?: OwneySupportedTokens): Promise<AgentBalance>;
|
|
1940
|
-
verifyWithdrawalBalance(state: ConnectionState, evidence: FundingEvidence, balance: AgentBalance): Promise<AssetReadMetadata | undefined>;
|
|
1941
|
-
invalidateAllocationRead(state: ConnectionState, chainId: number, asset: OwneySupportedTokens): void;
|
|
1942
|
-
invalidateFundingRead(state: ConnectionState, chainId: number, asset: OwneySupportedTokens, refreshUntil?: number): void;
|
|
1943
|
-
endFundingBalanceRefresh(state: ConnectionState, chainId: number, asset: OwneySupportedTokens, read: AssetReadMetadata): boolean;
|
|
1944
|
-
getFundingWallet(state: ConnectionState, chainId: number, asset: OwneySupportedTokens): Promise<string>;
|
|
1945
|
-
hasExistingDepositFunds(state: ConnectionState, chainId: number, asset: OwneySupportedTokens): Promise<true | undefined>;
|
|
1946
|
-
getEarnings(state: ConnectionState, chainId: number): Promise<AgentEarnings>;
|
|
1947
|
-
getAccountApy(state: ConnectionState, chainId: number, days: DailyApyDays, tokenSymbol?: string): Promise<AccountAgentApy>;
|
|
1948
|
-
getDailyEarnings(state: ConnectionState, chainId: number, days: LookbackDays, tokenSymbol?: string): Promise<AccountDailyEarnings>;
|
|
1949
|
-
getHistory(state: ConnectionState, chainId: number, options?: HistoryFilters): Promise<OwneyAgentHistory>;
|
|
1950
|
-
getUserProfile(state: ConnectionState, chainId: number): Promise<AgentUserProfile>;
|
|
1951
|
-
getAgentApy(days: DailyApyDays, options?: AgentApyOptions): Promise<AgentApy>;
|
|
1952
|
-
private loadVaultOptions;
|
|
1953
|
-
private userKey;
|
|
1954
|
-
private contextKey;
|
|
1955
|
-
private assertSession;
|
|
1956
|
-
private cachedRead;
|
|
1957
|
-
private agentListKey;
|
|
1958
|
-
private listAgents;
|
|
1959
|
-
private contextForAgent;
|
|
1960
|
-
private resolveUser;
|
|
1961
|
-
private forgetUser;
|
|
1962
|
-
private ensureAgent;
|
|
1963
|
-
private findAgent;
|
|
1964
|
-
private resolveAgent;
|
|
1965
|
-
private loadPortfolio;
|
|
1966
|
-
private loadActivityPortfolio;
|
|
1967
|
-
private resolvePortfolioContexts;
|
|
1968
|
-
private portfolioVersion;
|
|
1969
|
-
private portfolioCacheMs;
|
|
1970
|
-
private snapshotMovement;
|
|
1971
|
-
private advancePortfolioVersion;
|
|
1972
|
-
private requestPortfolioSnapshot;
|
|
1973
|
-
private portfolioSnapshot;
|
|
1974
|
-
private loadPortfolioContext;
|
|
1975
|
-
private loadActivityContext;
|
|
1976
|
-
private loadPortfolioParts;
|
|
1977
|
-
private deployAgent;
|
|
1978
|
-
private refreshSnapshotAfterMovement;
|
|
1979
|
-
private agentPath;
|
|
1980
|
-
private walletRequest;
|
|
1981
|
-
private providerRequest;
|
|
1982
|
-
private mapApiError;
|
|
1983
|
-
private submitTransaction;
|
|
1984
|
-
private waitForReceipt;
|
|
1985
|
-
private assertTransaction;
|
|
1986
|
-
private assertAgent;
|
|
1987
|
-
private isOwneyAgent;
|
|
1988
|
-
private assetForAgent;
|
|
1989
|
-
private isTransactionHash;
|
|
1990
|
-
private assertChain;
|
|
1991
|
-
private assertOptionalChain;
|
|
1992
|
-
private assertAsset;
|
|
1993
|
-
private invalidResponse;
|
|
1994
|
-
}
|
|
1995
|
-
|
|
1996
1664
|
declare class InvalidHistoryCursorError extends Error {
|
|
1997
1665
|
readonly code: "invalid_cursor";
|
|
1998
1666
|
constructor(message: string);
|
|
@@ -2052,7 +1720,6 @@ declare function createOwneySIWX(config: OwneySIWXConfig): SIWXConfig;
|
|
|
2052
1720
|
*/
|
|
2053
1721
|
type StoredOrder = {
|
|
2054
1722
|
orderHash: string;
|
|
2055
|
-
walletAddress?: string;
|
|
2056
1723
|
/** Preimages, one per fill. Index matters — fill N needs secret N. */
|
|
2057
1724
|
secrets: string[];
|
|
2058
1725
|
/** Chain the funds left from, so a resumed session can report it. */
|
|
@@ -2062,13 +1729,13 @@ type StoredOrder = {
|
|
|
2062
1729
|
dstSymbol: string;
|
|
2063
1730
|
dstChainId: number;
|
|
2064
1731
|
amount: string;
|
|
2065
|
-
/** Epoch ms
|
|
1732
|
+
/** Epoch ms. Used to drop orders far past any plausible timelock. */
|
|
2066
1733
|
createdAt: number;
|
|
2067
1734
|
};
|
|
2068
1735
|
/**
|
|
2069
|
-
* Every
|
|
1736
|
+
* Every stored order, newest first, dropping anything past MAX_AGE_MS.
|
|
2070
1737
|
* Used on mount to resume orders the user left in flight.
|
|
2071
1738
|
*/
|
|
2072
|
-
declare function listOrders(
|
|
1739
|
+
declare function listOrders(now?: number): StoredOrder[];
|
|
2073
1740
|
|
|
2074
|
-
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
|
|
1741
|
+
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 OwneyWithdrawAllLeg, type OwneyWithdrawAllResult, type OwneyWithdrawResult, type PendingDeposit, type RebalanceLog, type SwapChainTokens, type SwapDirection, type SwapOrderStatus, type SwapQuote, type SwapQuoteParams, type SwapRail, type SwapStage, type SwapTokenInfo, type SwapTokenSearchResult, type WithdrawOptions, type WithdrawSwapRecord, type WithdrawSwapStatus, clearWithdrawSwap, createOwneySIWX, listPendingDeposits, listOrders as listPendingSwaps, listWithdrawSwaps, saveWithdrawSwap, setOwneyDebug, subscribeWithdrawSwaps, updateWithdrawSwap };
|