@owney/sdk 0.7.25-beta.3 → 0.7.25-beta.6

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,12 +1,22 @@
1
1
  import { Hex } from 'viem';
2
2
  import { SIWXConfig } from '@reown/appkit-controllers';
3
3
 
4
- type ZyfaiRpcUrlsConfig = Partial<Record<(typeof SUPPORTED_CHAIN_IDS)[number], string>>;
4
+ type RpcUrlsConfig = Partial<Record<(typeof SUPPORTED_CHAIN_IDS)[number], string>>;
5
+ /** @deprecated Use RpcUrlsConfig. */
6
+ type ZyfaiRpcUrlsConfig = RpcUrlsConfig;
5
7
  interface OwneySDKConfig {
6
8
  apiKey: string;
9
+ /**
10
+ * Optional per-chain RPC overrides used for application-owned reads and
11
+ * transaction receipt polling. Missing chains use Owney SDK defaults.
12
+ * Wallet providers remain responsible for account access, chain switching,
13
+ * signatures, and transaction submission.
14
+ */
15
+ rpcUrls?: RpcUrlsConfig;
7
16
  /**
8
17
  * Optional per-chain RPC overrides for Zyfai SDK network calls.
9
18
  * Example: { 8453: "https://...", 42161: "https://..." }
19
+ * @deprecated Use rpcUrls so every agent shares the same read transport.
10
20
  */
11
21
  zyfaiRpcUrls?: ZyfaiRpcUrlsConfig;
12
22
  /** Optional Owney Yieldseeker proxy base URL override for integration tests. */
@@ -483,6 +493,12 @@ interface IAgent {
483
493
  * withdrawal planning must add matching position amounts.
484
494
  */
485
495
  readonly balanceComposition?: "tokens-include-positions" | "tokens-plus-positions";
496
+ /**
497
+ * Whether a withdrawal requires an owner-approved wallet transaction.
498
+ * Aggregate withdrawals run these agents before relayer-only agents so a
499
+ * rejected wallet request cannot happen after another leg has committed.
500
+ */
501
+ readonly withdrawalRequiresWalletApproval?: boolean;
486
502
  disconnect(): Promise<void>;
487
503
  activateAgent(state: ConnectionState, chainId: number, asset?: OwneySupportedTokens): Promise<void>;
488
504
  /**
@@ -554,6 +570,7 @@ declare class OwneySDK {
554
570
  private apiKey;
555
571
  private orgAgentConfig;
556
572
  private orgAgentConfigPromise;
573
+ private rpcUrls?;
557
574
  private zyfaiRpcUrls?;
558
575
  private yieldseekerApiBaseUrl?;
559
576
  private yieldseekerSiweOrigin?;
@@ -593,6 +610,7 @@ declare class OwneySDK {
593
610
  private requireState;
594
611
  private requireChainId;
595
612
  private requireConnectedProvider;
613
+ private getPaidRpcClient;
596
614
  /** Builds the default USDC batch callback for the connected wallet. */
597
615
  private getDefaultSponsoredCallback;
598
616
  /** Builds the wallet-native sponsored calls callback for compatible paymasters. */
@@ -676,10 +694,12 @@ declare class OwneySDK {
676
694
  * Invokes `agent.deposit` with the resolved sponsored callback, composing
677
695
  * two independent auto-recovery mechanisms:
678
696
  *
679
- * 1. Missing Permit2 allowance: when the app did not supply its own
680
- * callback and the attempt fails with `PERMIT2_APPROVAL_REQUIRED` on a
681
- * token deposit, this is the wallet's first Permit2 deposit for that token. We send
682
- * the one-time (user-paid) Permit2 approval via `approvePermit2()` and
697
+ * 1. Missing Permit2 allowance outside the atomic Base-USDC path: when the
698
+ * app did not supply its own callback and the attempt fails with
699
+ * `PERMIT2_APPROVAL_REQUIRED`, this is the wallet's first Permit2 deposit
700
+ * for that token. Base USDC bundles a gasless ERC-2612 approval inside
701
+ * its sponsored deposit and never reaches this branch. Other tokens send
702
+ * the one-time user-paid Permit2 approval via `approvePermit2()` and
683
703
  * retry the SAME sponsored attempt once. Bounded to one approval attempt
684
704
  * per call so a wallet/agent that keeps reporting the allowance as
685
705
  * missing can't loop forever. If `approvePermit2()` itself throws (e.g.
@@ -711,6 +731,13 @@ declare class OwneySDK {
711
731
  private hasExistingBalance;
712
732
  private validateAssetSupport;
713
733
  private getEligibleAgents;
734
+ /**
735
+ * Run owner-approved withdrawals before relayer-only withdrawals. Wallet
736
+ * approval is the only point at which the user can cancel the aggregate
737
+ * operation, so no relayer leg should commit before it has completed.
738
+ */
739
+ private orderAgentsForWithdrawal;
740
+ private isUserRejectedWithdrawal;
714
741
  /**
715
742
  * Withdraw funds from a specific agent, or all agents that support the active chain+asset if agentId is omitted.
716
743
  * Validates that the asset is supported by the target agent(s) on the active chain.
@@ -795,12 +822,14 @@ declare class OwneySDK {
795
822
  * User-paid approval of Permit2 on the selected token for the active chain.
796
823
  * Grants the maximum ERC20 allowance so later deposits do not require another
797
824
  * approval. Resolves after one confirmation so the subsequent deposit attempt
798
- * sees the new allowance.
825
+ * sees the new allowance. Deposit retries pass their captured chain id so a
826
+ * concurrent activation cannot redirect the approval to another network.
799
827
  *
800
828
  * @param requiredAmount Raw base-unit amount the pending deposit must cover.
829
+ * @param expectedChainId Chain captured by the deposit that requested approval.
801
830
  * @returns the approval transaction hash.
802
831
  */
803
- approvePermit2(asset?: OwneySupportedTokens, requiredAmount?: bigint): Promise<`0x${string}`>;
832
+ approvePermit2(asset?: OwneySupportedTokens, requiredAmount?: bigint, expectedChainId?: OwneySupportedChainId): Promise<`0x${string}`>;
804
833
  /**
805
834
  * Get the agent's average APY performance over a time period. Does not require a wallet connection.
806
835
  * @param options - Contains agentId (optional) and days ("7D", "14D", or "30D")
@@ -844,6 +873,8 @@ type YieldseekerAgentOptions = {
844
873
  baseUrl?: string;
845
874
  fetchFn?: YieldseekerFetch;
846
875
  auth?: YieldseekerAuthDependencies;
876
+ /** Dedicated read transport; Base is used for receipt polling. */
877
+ rpcUrls?: RpcUrlsConfig;
847
878
  /** Test seam for the wallet-submission/receipt boundary. */
848
879
  transactionExecutor?: (state: ConnectionState, chainId: number, transaction: YieldseekerTransaction) => Promise<Hex>;
849
880
  /** Test seam for transactions submitted outside transactionExecutor. */
@@ -852,6 +883,7 @@ type YieldseekerAgentOptions = {
852
883
  declare class YieldseekerAgent implements IAgent {
853
884
  readonly id = "yieldseeker";
854
885
  readonly balanceComposition: "tokens-plus-positions";
886
+ readonly withdrawalRequiresWalletApproval = true;
855
887
  readonly supportedChainIds: readonly [8453];
856
888
  readonly supportedAssets: readonly [{
857
889
  readonly chainId: 8453;
@@ -866,14 +898,21 @@ declare class YieldseekerAgent implements IAgent {
866
898
  }];
867
899
  private readonly api;
868
900
  private readonly auth;
901
+ private readonly rpcUrls?;
902
+ private receiptClient?;
869
903
  private readonly transactionExecutor?;
870
904
  private readonly unwindReceiptWaiter?;
871
905
  private readonly agentContexts;
872
906
  private readonly users;
873
907
  private readonly pendingAgents;
908
+ private readonly pendingWalletContexts;
909
+ private readonly readCache;
910
+ private readonly pendingReads;
911
+ private readGeneration;
874
912
  private readonly yieldOptions;
875
913
  private readonly pendingYieldOptions;
876
914
  constructor(owneyApiKey: string, options?: YieldseekerAgentOptions);
915
+ private getReceiptClient;
877
916
  disconnect(): Promise<void>;
878
917
  activateAgent(state: ConnectionState, chainId: number, asset?: OwneySupportedTokens): Promise<void>;
879
918
  deposit(state: ConnectionState, chainId: number, amount: string, asset: OwneySupportedTokens, depositCallback?: DepositCallback): Promise<OwneyDepositResult>;
@@ -887,6 +926,10 @@ declare class YieldseekerAgent implements IAgent {
887
926
  private loadYieldOptions;
888
927
  private userKey;
889
928
  private contextKey;
929
+ private cachedRead;
930
+ private agentListKey;
931
+ private listAgents;
932
+ private contextForAgent;
890
933
  private resolveUser;
891
934
  private forgetUser;
892
935
  private ensureAgent;
@@ -979,4 +1022,4 @@ type OwneySIWXConfig = {
979
1022
  */
980
1023
  declare function createOwneySIWX(config: OwneySIWXConfig): SIWXConfig;
981
1024
 
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 };
1025
+ 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 RpcUrlsConfig, type WithdrawOptions, YieldseekerAgent, type ZyfaiRpcUrlsConfig, createOwneySIWX, setOwneyDebug };
package/dist/index.d.ts CHANGED
@@ -1,12 +1,22 @@
1
1
  import { Hex } from 'viem';
2
2
  import { SIWXConfig } from '@reown/appkit-controllers';
3
3
 
4
- type ZyfaiRpcUrlsConfig = Partial<Record<(typeof SUPPORTED_CHAIN_IDS)[number], string>>;
4
+ type RpcUrlsConfig = Partial<Record<(typeof SUPPORTED_CHAIN_IDS)[number], string>>;
5
+ /** @deprecated Use RpcUrlsConfig. */
6
+ type ZyfaiRpcUrlsConfig = RpcUrlsConfig;
5
7
  interface OwneySDKConfig {
6
8
  apiKey: string;
9
+ /**
10
+ * Optional per-chain RPC overrides used for application-owned reads and
11
+ * transaction receipt polling. Missing chains use Owney SDK defaults.
12
+ * Wallet providers remain responsible for account access, chain switching,
13
+ * signatures, and transaction submission.
14
+ */
15
+ rpcUrls?: RpcUrlsConfig;
7
16
  /**
8
17
  * Optional per-chain RPC overrides for Zyfai SDK network calls.
9
18
  * Example: { 8453: "https://...", 42161: "https://..." }
19
+ * @deprecated Use rpcUrls so every agent shares the same read transport.
10
20
  */
11
21
  zyfaiRpcUrls?: ZyfaiRpcUrlsConfig;
12
22
  /** Optional Owney Yieldseeker proxy base URL override for integration tests. */
@@ -483,6 +493,12 @@ interface IAgent {
483
493
  * withdrawal planning must add matching position amounts.
484
494
  */
485
495
  readonly balanceComposition?: "tokens-include-positions" | "tokens-plus-positions";
496
+ /**
497
+ * Whether a withdrawal requires an owner-approved wallet transaction.
498
+ * Aggregate withdrawals run these agents before relayer-only agents so a
499
+ * rejected wallet request cannot happen after another leg has committed.
500
+ */
501
+ readonly withdrawalRequiresWalletApproval?: boolean;
486
502
  disconnect(): Promise<void>;
487
503
  activateAgent(state: ConnectionState, chainId: number, asset?: OwneySupportedTokens): Promise<void>;
488
504
  /**
@@ -554,6 +570,7 @@ declare class OwneySDK {
554
570
  private apiKey;
555
571
  private orgAgentConfig;
556
572
  private orgAgentConfigPromise;
573
+ private rpcUrls?;
557
574
  private zyfaiRpcUrls?;
558
575
  private yieldseekerApiBaseUrl?;
559
576
  private yieldseekerSiweOrigin?;
@@ -593,6 +610,7 @@ declare class OwneySDK {
593
610
  private requireState;
594
611
  private requireChainId;
595
612
  private requireConnectedProvider;
613
+ private getPaidRpcClient;
596
614
  /** Builds the default USDC batch callback for the connected wallet. */
597
615
  private getDefaultSponsoredCallback;
598
616
  /** Builds the wallet-native sponsored calls callback for compatible paymasters. */
@@ -676,10 +694,12 @@ declare class OwneySDK {
676
694
  * Invokes `agent.deposit` with the resolved sponsored callback, composing
677
695
  * two independent auto-recovery mechanisms:
678
696
  *
679
- * 1. Missing Permit2 allowance: when the app did not supply its own
680
- * callback and the attempt fails with `PERMIT2_APPROVAL_REQUIRED` on a
681
- * token deposit, this is the wallet's first Permit2 deposit for that token. We send
682
- * the one-time (user-paid) Permit2 approval via `approvePermit2()` and
697
+ * 1. Missing Permit2 allowance outside the atomic Base-USDC path: when the
698
+ * app did not supply its own callback and the attempt fails with
699
+ * `PERMIT2_APPROVAL_REQUIRED`, this is the wallet's first Permit2 deposit
700
+ * for that token. Base USDC bundles a gasless ERC-2612 approval inside
701
+ * its sponsored deposit and never reaches this branch. Other tokens send
702
+ * the one-time user-paid Permit2 approval via `approvePermit2()` and
683
703
  * retry the SAME sponsored attempt once. Bounded to one approval attempt
684
704
  * per call so a wallet/agent that keeps reporting the allowance as
685
705
  * missing can't loop forever. If `approvePermit2()` itself throws (e.g.
@@ -711,6 +731,13 @@ declare class OwneySDK {
711
731
  private hasExistingBalance;
712
732
  private validateAssetSupport;
713
733
  private getEligibleAgents;
734
+ /**
735
+ * Run owner-approved withdrawals before relayer-only withdrawals. Wallet
736
+ * approval is the only point at which the user can cancel the aggregate
737
+ * operation, so no relayer leg should commit before it has completed.
738
+ */
739
+ private orderAgentsForWithdrawal;
740
+ private isUserRejectedWithdrawal;
714
741
  /**
715
742
  * Withdraw funds from a specific agent, or all agents that support the active chain+asset if agentId is omitted.
716
743
  * Validates that the asset is supported by the target agent(s) on the active chain.
@@ -795,12 +822,14 @@ declare class OwneySDK {
795
822
  * User-paid approval of Permit2 on the selected token for the active chain.
796
823
  * Grants the maximum ERC20 allowance so later deposits do not require another
797
824
  * approval. Resolves after one confirmation so the subsequent deposit attempt
798
- * sees the new allowance.
825
+ * sees the new allowance. Deposit retries pass their captured chain id so a
826
+ * concurrent activation cannot redirect the approval to another network.
799
827
  *
800
828
  * @param requiredAmount Raw base-unit amount the pending deposit must cover.
829
+ * @param expectedChainId Chain captured by the deposit that requested approval.
801
830
  * @returns the approval transaction hash.
802
831
  */
803
- approvePermit2(asset?: OwneySupportedTokens, requiredAmount?: bigint): Promise<`0x${string}`>;
832
+ approvePermit2(asset?: OwneySupportedTokens, requiredAmount?: bigint, expectedChainId?: OwneySupportedChainId): Promise<`0x${string}`>;
804
833
  /**
805
834
  * Get the agent's average APY performance over a time period. Does not require a wallet connection.
806
835
  * @param options - Contains agentId (optional) and days ("7D", "14D", or "30D")
@@ -844,6 +873,8 @@ type YieldseekerAgentOptions = {
844
873
  baseUrl?: string;
845
874
  fetchFn?: YieldseekerFetch;
846
875
  auth?: YieldseekerAuthDependencies;
876
+ /** Dedicated read transport; Base is used for receipt polling. */
877
+ rpcUrls?: RpcUrlsConfig;
847
878
  /** Test seam for the wallet-submission/receipt boundary. */
848
879
  transactionExecutor?: (state: ConnectionState, chainId: number, transaction: YieldseekerTransaction) => Promise<Hex>;
849
880
  /** Test seam for transactions submitted outside transactionExecutor. */
@@ -852,6 +883,7 @@ type YieldseekerAgentOptions = {
852
883
  declare class YieldseekerAgent implements IAgent {
853
884
  readonly id = "yieldseeker";
854
885
  readonly balanceComposition: "tokens-plus-positions";
886
+ readonly withdrawalRequiresWalletApproval = true;
855
887
  readonly supportedChainIds: readonly [8453];
856
888
  readonly supportedAssets: readonly [{
857
889
  readonly chainId: 8453;
@@ -866,14 +898,21 @@ declare class YieldseekerAgent implements IAgent {
866
898
  }];
867
899
  private readonly api;
868
900
  private readonly auth;
901
+ private readonly rpcUrls?;
902
+ private receiptClient?;
869
903
  private readonly transactionExecutor?;
870
904
  private readonly unwindReceiptWaiter?;
871
905
  private readonly agentContexts;
872
906
  private readonly users;
873
907
  private readonly pendingAgents;
908
+ private readonly pendingWalletContexts;
909
+ private readonly readCache;
910
+ private readonly pendingReads;
911
+ private readGeneration;
874
912
  private readonly yieldOptions;
875
913
  private readonly pendingYieldOptions;
876
914
  constructor(owneyApiKey: string, options?: YieldseekerAgentOptions);
915
+ private getReceiptClient;
877
916
  disconnect(): Promise<void>;
878
917
  activateAgent(state: ConnectionState, chainId: number, asset?: OwneySupportedTokens): Promise<void>;
879
918
  deposit(state: ConnectionState, chainId: number, amount: string, asset: OwneySupportedTokens, depositCallback?: DepositCallback): Promise<OwneyDepositResult>;
@@ -887,6 +926,10 @@ declare class YieldseekerAgent implements IAgent {
887
926
  private loadYieldOptions;
888
927
  private userKey;
889
928
  private contextKey;
929
+ private cachedRead;
930
+ private agentListKey;
931
+ private listAgents;
932
+ private contextForAgent;
890
933
  private resolveUser;
891
934
  private forgetUser;
892
935
  private ensureAgent;
@@ -979,4 +1022,4 @@ type OwneySIWXConfig = {
979
1022
  */
980
1023
  declare function createOwneySIWX(config: OwneySIWXConfig): SIWXConfig;
981
1024
 
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 };
1025
+ 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 RpcUrlsConfig, type WithdrawOptions, YieldseekerAgent, type ZyfaiRpcUrlsConfig, createOwneySIWX, setOwneyDebug };