@owney/sdk 0.7.24 → 0.7.25-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,3 +1,4 @@
1
+ import { Hex } from 'viem';
1
2
  import { SIWXConfig } from '@reown/appkit-controllers';
2
3
 
3
4
  type ZyfaiRpcUrlsConfig = Partial<Record<(typeof SUPPORTED_CHAIN_IDS)[number], string>>;
@@ -8,6 +9,10 @@ interface OwneySDKConfig {
8
9
  * Example: { 8453: "https://...", 42161: "https://..." }
9
10
  */
10
11
  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;
11
16
  /**
12
17
  * Optional override for the Owney routing API base URL used by all routing
13
18
  * calls (defaults to the OWNEY_ROUTING_API_BASE_URL env var, then the
@@ -54,7 +59,7 @@ type OwneySupportedChainId = (typeof SUPPORTED_CHAIN_IDS)[number];
54
59
  type OwneySupportedChains = (typeof SUPPORTED_CHAINS)[number];
55
60
  type OwneySupportedTokens = (typeof SUPPORTED_TOKENS)[number];
56
61
 
57
- type AgentId = "zyfai";
62
+ type AgentId = "zyfai" | "yieldseeker";
58
63
  type Asset = string;
59
64
  type AgentSupportedAsset = {
60
65
  readonly symbol: string;
@@ -232,6 +237,8 @@ interface OwneyPosition {
232
237
  pool?: string;
233
238
  asset: string;
234
239
  amount: string;
240
+ /** Smallest-unit amount when the provider exposes it alongside `amount`. */
241
+ amountRaw?: string;
235
242
  apy?: number;
236
243
  tvl?: number;
237
244
  /** Pool liquidity. Prepared slot — Zyfai will add this to its portfolio
@@ -262,10 +269,19 @@ interface OwneyPendingAllocation {
262
269
  since?: string;
263
270
  }
264
271
  interface AgentBalance {
272
+ /** Authoritative native balances per asset/network, including idle and invested funds. */
273
+ assetBalances?: OwneyToken[];
265
274
  smartWallet?: `0x${string}`;
266
275
  totalBalance: string;
267
276
  /** Asset that `totalBalance` is denominated in. Currently always `"usdc"`. */
268
277
  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";
269
285
  tokens: OwneyToken[];
270
286
  /**
271
287
  * Per-protocol/pool positions when the agent's portfolio payload includes
@@ -280,10 +296,14 @@ interface OwneyBalances {
280
296
  /** Asset that `totalBalance` is denominated in. Currently always `"usdc"`. */
281
297
  totalBalanceAsset: string;
282
298
  agentBalances: Record<AgentId, AgentBalance>;
283
- /** Omitted agents failed to load; they must not be interpreted as zero. */
284
- agentErrors?: Record<AgentId, string>;
299
+ /**
300
+ * Per-agent read failures when an aggregate balance request returned only a
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>>;
285
305
  /** Absolute provider cooldown deadlines (Unix milliseconds). */
286
- agentRetryAt?: Record<AgentId, number>;
306
+ agentRetryAt?: Partial<Record<AgentId, number>>;
287
307
  }
288
308
  interface AgentEarnings {
289
309
  smartWallet: `0x${string}`;
@@ -456,8 +476,15 @@ interface IAgent {
456
476
  readonly id: string;
457
477
  readonly supportedChainIds: readonly OwneySupportedChainId[];
458
478
  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";
459
486
  disconnect(): Promise<void>;
460
- activateAgent(state: ConnectionState, chainId: number): Promise<void>;
487
+ activateAgent(state: ConnectionState, chainId: number, asset?: OwneySupportedTokens): Promise<void>;
461
488
  /**
462
489
  * Apply the organization's agent policy to this user's account.
463
490
  *
@@ -528,6 +555,8 @@ declare class OwneySDK {
528
555
  private orgAgentConfig;
529
556
  private orgAgentConfigPromise;
530
557
  private zyfaiRpcUrls?;
558
+ private yieldseekerApiBaseUrl?;
559
+ private yieldseekerSiweOrigin?;
531
560
  private routingApiBaseUrl?;
532
561
  private referralSource?;
533
562
  private cachedSponsoredCallback;
@@ -564,25 +593,15 @@ declare class OwneySDK {
564
593
  private requireState;
565
594
  private requireChainId;
566
595
  private requireConnectedProvider;
567
- /**
568
- * Lazily builds (and caches) the default EIP-3009 sponsored deposit callback
569
- * used when the caller omits `depositCallback`. Wraps the connected EIP-1193
570
- * provider with viem `custom(provider)` to read token meta and sign the
571
- * `TransferWithAuthorization`, then POSTs to the sponsor API.
572
- */
596
+ /** Builds the default USDC batch callback for the connected wallet. */
573
597
  private getDefaultSponsoredCallback;
574
- /**
575
- * Lazily builds (and caches) the default Permit2 sponsored WETH deposit
576
- * callback used when the caller omits `depositCallback` for a WETH
577
- * deposit. Mirrors `getDefaultSponsoredCallback()` but signs a Permit2
578
- * `PermitTransferFrom` instead of an EIP-3009 authorization.
579
- */
598
+ /** Builds the wallet-native sponsored calls callback for compatible paymasters. */
580
599
  private getDefaultSponsoredCallsCallback;
581
600
  /**
582
601
  * Lazily builds (and caches) the default Permit2 sponsored WETH deposit
583
602
  * callback used when the caller omits `depositCallback` for a WETH deposit.
584
603
  * Mirrors `getDefaultSponsoredCallback()` but signs a Permit2
585
- * `PermitTransferFrom` instead of an EIP-3009 authorization.
604
+ * single-use batch authorization instead of an EIP-3009 authorization.
586
605
  */
587
606
  private getDefaultWethSponsoredCallback;
588
607
  private getAgent;
@@ -618,7 +637,8 @@ declare class OwneySDK {
618
637
  * If provided, ALL specified agents must support the chainId or the call
619
638
  * throws before activating any agent.
620
639
  */
621
- activateAgent(chainId: number, agentId?: AgentId[]): Promise<void>;
640
+ activateAgent(chainId: number, agentId?: AgentId[], asset?: OwneySupportedTokens): Promise<void>;
641
+ private assertActivationSession;
622
642
  /**
623
643
  * Activate agents ONE AT A TIME, each followed by its org policy.
624
644
  *
@@ -632,10 +652,9 @@ declare class OwneySDK {
632
652
  * Serializing costs no real wall-clock: the user can only approve one prompt
633
653
  * at a time anyway.
634
654
  *
635
- * Every agent is attempted even if an earlier one fails, so one declined
636
- * signature can't deny the remaining agents their turn. The first failure is
637
- * rethrown (matching the previous `Promise.all` rejection) once all agents
638
- * have had a chance to activate.
655
+ * Stop at the first failure so a canceled sign-in does not open another
656
+ * agent's wallet prompt. Report any earlier successes for diagnostics; the
657
+ * app discards the session when the complete sign-in does not succeed.
639
658
  */
640
659
  private activateAgentsInTurn;
641
660
  /**
@@ -646,7 +665,8 @@ declare class OwneySDK {
646
665
  * @param options.asset - Asset symbol to deposit (e.g. "USDC")
647
666
  * @param options.depositCallback - Callback that performs the token transfer and returns a tx hash.
648
667
  * When agentId is omitted, this callback is invoked once per eligible agent with that agent's
649
- * split amount and smart wallet address — expect multiple wallet prompts.
668
+ * split amount and smart wallet address. Default sponsored deposits batch
669
+ * all shares into one signature; custom callbacks still run once per agent.
650
670
  * @param options.agentId - Optional explicit target. Otherwise split equally,
651
671
  * or fund remaining agents when a recovery deposit cannot meet every minimum.
652
672
  * @returns {OwneyDepositResult} for a single agent, or {OwneyMultiDepositResult} with per-agent results
@@ -658,7 +678,7 @@ declare class OwneySDK {
658
678
  *
659
679
  * 1. Missing Permit2 allowance: when the app did not supply its own
660
680
  * callback and the attempt fails with `PERMIT2_APPROVAL_REQUIRED` on a
661
- * WETH deposit, this is the wallet's first gasless WETH deposit. We send
681
+ * token deposit, this is the wallet's first Permit2 deposit for that token. We send
662
682
  * the one-time (user-paid) Permit2 approval via `approvePermit2()` and
663
683
  * retry the SAME sponsored attempt once. Bounded to one approval attempt
664
684
  * per call so a wallet/agent that keeps reporting the allowance as
@@ -680,6 +700,7 @@ declare class OwneySDK {
680
700
  private depositWithFallback;
681
701
  private getMinDepositAmount;
682
702
  private splitDepositAmount;
703
+ private formatAgentName;
683
704
  private validateMinDepositAmount;
684
705
  /**
685
706
  * Whether the user already holds a non-zero balance with `agent` for the
@@ -771,14 +792,15 @@ declare class OwneySDK {
771
792
  */
772
793
  ensureAutoSelectProtocols(asset: "USDC" | "WETH", agentId?: AgentId): Promise<boolean>;
773
794
  /**
774
- * One-time, user-paid approval of Permit2 on the sponsored WETH token for
775
- * the active chain. Required once per wallet per chain before gasless WETH
776
- * deposits; afterwards deposit() is signature-only. Resolves only after the
777
- * approval transaction is mined (1 confirmation), so a subsequent deposit()
778
- * will see the new allowance; throws if the transaction reverted.
795
+ * User-paid approval of Permit2 on the selected token for the active chain.
796
+ * Approves exactly the pending deposit amount. Another approval is required
797
+ * for a later deposit once this allowance has been consumed. Resolves after
798
+ * one confirmation so the subsequent deposit attempt sees the new allowance.
799
+ *
800
+ * @param requiredAmount Raw base-unit amount the pending deposit must cover.
779
801
  * @returns the approval transaction hash.
780
802
  */
781
- approvePermit2(asset?: "WETH"): Promise<`0x${string}`>;
803
+ approvePermit2(asset?: OwneySupportedTokens, requiredAmount?: bigint): Promise<`0x${string}`>;
782
804
  /**
783
805
  * Get the agent's average APY performance over a time period. Does not require a wallet connection.
784
806
  * @param options - Contains agentId (optional) and days ("7D", "14D", or "30D")
@@ -802,7 +824,96 @@ declare class OwneySDK {
802
824
  getAllocationApy({ agentId, }?: AllocationApyOptions): Promise<OwneyAllocationApy>;
803
825
  }
804
826
 
805
- 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" | "BALANCE_ALL_FAILED" | "ALLOCATION_ALL_FAILED" | "VALIDATION_INVALID_DAYS";
827
+ type YieldseekerAuthDependencies = {
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";
806
917
  declare class OwneyError extends Error {
807
918
  readonly code: OwneyErrorCode;
808
919
  readonly details?: Record<string, unknown>;
@@ -868,4 +979,4 @@ type OwneySIWXConfig = {
868
979
  */
869
980
  declare function createOwneySIWX(config: OwneySIWXConfig): SIWXConfig;
870
981
 
871
- 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 WithdrawOptions, createOwneySIWX, setOwneyDebug };
982
+ 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 WithdrawOptions, YieldseekerAgent, createOwneySIWX, setOwneyDebug };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { Hex } from 'viem';
1
2
  import { SIWXConfig } from '@reown/appkit-controllers';
2
3
 
3
4
  type ZyfaiRpcUrlsConfig = Partial<Record<(typeof SUPPORTED_CHAIN_IDS)[number], string>>;
@@ -8,6 +9,10 @@ interface OwneySDKConfig {
8
9
  * Example: { 8453: "https://...", 42161: "https://..." }
9
10
  */
10
11
  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;
11
16
  /**
12
17
  * Optional override for the Owney routing API base URL used by all routing
13
18
  * calls (defaults to the OWNEY_ROUTING_API_BASE_URL env var, then the
@@ -54,7 +59,7 @@ type OwneySupportedChainId = (typeof SUPPORTED_CHAIN_IDS)[number];
54
59
  type OwneySupportedChains = (typeof SUPPORTED_CHAINS)[number];
55
60
  type OwneySupportedTokens = (typeof SUPPORTED_TOKENS)[number];
56
61
 
57
- type AgentId = "zyfai";
62
+ type AgentId = "zyfai" | "yieldseeker";
58
63
  type Asset = string;
59
64
  type AgentSupportedAsset = {
60
65
  readonly symbol: string;
@@ -232,6 +237,8 @@ interface OwneyPosition {
232
237
  pool?: string;
233
238
  asset: string;
234
239
  amount: string;
240
+ /** Smallest-unit amount when the provider exposes it alongside `amount`. */
241
+ amountRaw?: string;
235
242
  apy?: number;
236
243
  tvl?: number;
237
244
  /** Pool liquidity. Prepared slot — Zyfai will add this to its portfolio
@@ -262,10 +269,19 @@ interface OwneyPendingAllocation {
262
269
  since?: string;
263
270
  }
264
271
  interface AgentBalance {
272
+ /** Authoritative native balances per asset/network, including idle and invested funds. */
273
+ assetBalances?: OwneyToken[];
265
274
  smartWallet?: `0x${string}`;
266
275
  totalBalance: string;
267
276
  /** Asset that `totalBalance` is denominated in. Currently always `"usdc"`. */
268
277
  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";
269
285
  tokens: OwneyToken[];
270
286
  /**
271
287
  * Per-protocol/pool positions when the agent's portfolio payload includes
@@ -280,10 +296,14 @@ interface OwneyBalances {
280
296
  /** Asset that `totalBalance` is denominated in. Currently always `"usdc"`. */
281
297
  totalBalanceAsset: string;
282
298
  agentBalances: Record<AgentId, AgentBalance>;
283
- /** Omitted agents failed to load; they must not be interpreted as zero. */
284
- agentErrors?: Record<AgentId, string>;
299
+ /**
300
+ * Per-agent read failures when an aggregate balance request returned only a
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>>;
285
305
  /** Absolute provider cooldown deadlines (Unix milliseconds). */
286
- agentRetryAt?: Record<AgentId, number>;
306
+ agentRetryAt?: Partial<Record<AgentId, number>>;
287
307
  }
288
308
  interface AgentEarnings {
289
309
  smartWallet: `0x${string}`;
@@ -456,8 +476,15 @@ interface IAgent {
456
476
  readonly id: string;
457
477
  readonly supportedChainIds: readonly OwneySupportedChainId[];
458
478
  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";
459
486
  disconnect(): Promise<void>;
460
- activateAgent(state: ConnectionState, chainId: number): Promise<void>;
487
+ activateAgent(state: ConnectionState, chainId: number, asset?: OwneySupportedTokens): Promise<void>;
461
488
  /**
462
489
  * Apply the organization's agent policy to this user's account.
463
490
  *
@@ -528,6 +555,8 @@ declare class OwneySDK {
528
555
  private orgAgentConfig;
529
556
  private orgAgentConfigPromise;
530
557
  private zyfaiRpcUrls?;
558
+ private yieldseekerApiBaseUrl?;
559
+ private yieldseekerSiweOrigin?;
531
560
  private routingApiBaseUrl?;
532
561
  private referralSource?;
533
562
  private cachedSponsoredCallback;
@@ -564,25 +593,15 @@ declare class OwneySDK {
564
593
  private requireState;
565
594
  private requireChainId;
566
595
  private requireConnectedProvider;
567
- /**
568
- * Lazily builds (and caches) the default EIP-3009 sponsored deposit callback
569
- * used when the caller omits `depositCallback`. Wraps the connected EIP-1193
570
- * provider with viem `custom(provider)` to read token meta and sign the
571
- * `TransferWithAuthorization`, then POSTs to the sponsor API.
572
- */
596
+ /** Builds the default USDC batch callback for the connected wallet. */
573
597
  private getDefaultSponsoredCallback;
574
- /**
575
- * Lazily builds (and caches) the default Permit2 sponsored WETH deposit
576
- * callback used when the caller omits `depositCallback` for a WETH
577
- * deposit. Mirrors `getDefaultSponsoredCallback()` but signs a Permit2
578
- * `PermitTransferFrom` instead of an EIP-3009 authorization.
579
- */
598
+ /** Builds the wallet-native sponsored calls callback for compatible paymasters. */
580
599
  private getDefaultSponsoredCallsCallback;
581
600
  /**
582
601
  * Lazily builds (and caches) the default Permit2 sponsored WETH deposit
583
602
  * callback used when the caller omits `depositCallback` for a WETH deposit.
584
603
  * Mirrors `getDefaultSponsoredCallback()` but signs a Permit2
585
- * `PermitTransferFrom` instead of an EIP-3009 authorization.
604
+ * single-use batch authorization instead of an EIP-3009 authorization.
586
605
  */
587
606
  private getDefaultWethSponsoredCallback;
588
607
  private getAgent;
@@ -618,7 +637,8 @@ declare class OwneySDK {
618
637
  * If provided, ALL specified agents must support the chainId or the call
619
638
  * throws before activating any agent.
620
639
  */
621
- activateAgent(chainId: number, agentId?: AgentId[]): Promise<void>;
640
+ activateAgent(chainId: number, agentId?: AgentId[], asset?: OwneySupportedTokens): Promise<void>;
641
+ private assertActivationSession;
622
642
  /**
623
643
  * Activate agents ONE AT A TIME, each followed by its org policy.
624
644
  *
@@ -632,10 +652,9 @@ declare class OwneySDK {
632
652
  * Serializing costs no real wall-clock: the user can only approve one prompt
633
653
  * at a time anyway.
634
654
  *
635
- * Every agent is attempted even if an earlier one fails, so one declined
636
- * signature can't deny the remaining agents their turn. The first failure is
637
- * rethrown (matching the previous `Promise.all` rejection) once all agents
638
- * have had a chance to activate.
655
+ * Stop at the first failure so a canceled sign-in does not open another
656
+ * agent's wallet prompt. Report any earlier successes for diagnostics; the
657
+ * app discards the session when the complete sign-in does not succeed.
639
658
  */
640
659
  private activateAgentsInTurn;
641
660
  /**
@@ -646,7 +665,8 @@ declare class OwneySDK {
646
665
  * @param options.asset - Asset symbol to deposit (e.g. "USDC")
647
666
  * @param options.depositCallback - Callback that performs the token transfer and returns a tx hash.
648
667
  * When agentId is omitted, this callback is invoked once per eligible agent with that agent's
649
- * split amount and smart wallet address — expect multiple wallet prompts.
668
+ * split amount and smart wallet address. Default sponsored deposits batch
669
+ * all shares into one signature; custom callbacks still run once per agent.
650
670
  * @param options.agentId - Optional explicit target. Otherwise split equally,
651
671
  * or fund remaining agents when a recovery deposit cannot meet every minimum.
652
672
  * @returns {OwneyDepositResult} for a single agent, or {OwneyMultiDepositResult} with per-agent results
@@ -658,7 +678,7 @@ declare class OwneySDK {
658
678
  *
659
679
  * 1. Missing Permit2 allowance: when the app did not supply its own
660
680
  * callback and the attempt fails with `PERMIT2_APPROVAL_REQUIRED` on a
661
- * WETH deposit, this is the wallet's first gasless WETH deposit. We send
681
+ * token deposit, this is the wallet's first Permit2 deposit for that token. We send
662
682
  * the one-time (user-paid) Permit2 approval via `approvePermit2()` and
663
683
  * retry the SAME sponsored attempt once. Bounded to one approval attempt
664
684
  * per call so a wallet/agent that keeps reporting the allowance as
@@ -680,6 +700,7 @@ declare class OwneySDK {
680
700
  private depositWithFallback;
681
701
  private getMinDepositAmount;
682
702
  private splitDepositAmount;
703
+ private formatAgentName;
683
704
  private validateMinDepositAmount;
684
705
  /**
685
706
  * Whether the user already holds a non-zero balance with `agent` for the
@@ -771,14 +792,15 @@ declare class OwneySDK {
771
792
  */
772
793
  ensureAutoSelectProtocols(asset: "USDC" | "WETH", agentId?: AgentId): Promise<boolean>;
773
794
  /**
774
- * One-time, user-paid approval of Permit2 on the sponsored WETH token for
775
- * the active chain. Required once per wallet per chain before gasless WETH
776
- * deposits; afterwards deposit() is signature-only. Resolves only after the
777
- * approval transaction is mined (1 confirmation), so a subsequent deposit()
778
- * will see the new allowance; throws if the transaction reverted.
795
+ * User-paid approval of Permit2 on the selected token for the active chain.
796
+ * Approves exactly the pending deposit amount. Another approval is required
797
+ * for a later deposit once this allowance has been consumed. Resolves after
798
+ * one confirmation so the subsequent deposit attempt sees the new allowance.
799
+ *
800
+ * @param requiredAmount Raw base-unit amount the pending deposit must cover.
779
801
  * @returns the approval transaction hash.
780
802
  */
781
- approvePermit2(asset?: "WETH"): Promise<`0x${string}`>;
803
+ approvePermit2(asset?: OwneySupportedTokens, requiredAmount?: bigint): Promise<`0x${string}`>;
782
804
  /**
783
805
  * Get the agent's average APY performance over a time period. Does not require a wallet connection.
784
806
  * @param options - Contains agentId (optional) and days ("7D", "14D", or "30D")
@@ -802,7 +824,96 @@ declare class OwneySDK {
802
824
  getAllocationApy({ agentId, }?: AllocationApyOptions): Promise<OwneyAllocationApy>;
803
825
  }
804
826
 
805
- 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" | "BALANCE_ALL_FAILED" | "ALLOCATION_ALL_FAILED" | "VALIDATION_INVALID_DAYS";
827
+ type YieldseekerAuthDependencies = {
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";
806
917
  declare class OwneyError extends Error {
807
918
  readonly code: OwneyErrorCode;
808
919
  readonly details?: Record<string, unknown>;
@@ -868,4 +979,4 @@ type OwneySIWXConfig = {
868
979
  */
869
980
  declare function createOwneySIWX(config: OwneySIWXConfig): SIWXConfig;
870
981
 
871
- 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 WithdrawOptions, createOwneySIWX, setOwneyDebug };
982
+ 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 WithdrawOptions, YieldseekerAgent, createOwneySIWX, setOwneyDebug };