@owney/sdk 0.7.25-beta.4 → 0.7.25-beta.7

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,23 @@
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 the Owney routing API's
12
+ * read-only RPC proxy. No upstream RPC credentials are included in the SDK.
13
+ * Wallet providers remain responsible for account access, chain switching,
14
+ * signatures, and transaction submission.
15
+ */
16
+ rpcUrls?: RpcUrlsConfig;
7
17
  /**
8
18
  * Optional per-chain RPC overrides for Zyfai SDK network calls.
9
19
  * Example: { 8453: "https://...", 42161: "https://..." }
20
+ * @deprecated Use rpcUrls so every agent shares the same read transport.
10
21
  */
11
22
  zyfaiRpcUrls?: ZyfaiRpcUrlsConfig;
12
23
  /** Optional Owney Yieldseeker proxy base URL override for integration tests. */
@@ -15,9 +26,9 @@ interface OwneySDKConfig {
15
26
  yieldseekerSiweOrigin?: string;
16
27
  /**
17
28
  * Optional override for the Owney routing API base URL used by all routing
18
- * calls (defaults to the OWNEY_ROUTING_API_BASE_URL env var, then the
19
- * production URL). Set this to point at a local/staging routing API,
20
- * e.g. "http://localhost:3000", when testing sponsor changes.
29
+ * calls. RPC proxy requests use OWNEY_ROUTING_API_BASE_URL when this is
30
+ * omitted; without either value, all rpcUrls must be configured.
31
+ * Set this to a local/staging routing API when testing sponsor changes.
21
32
  */
22
33
  routingApiBaseUrl?: string;
23
34
  /**
@@ -483,6 +494,12 @@ interface IAgent {
483
494
  * withdrawal planning must add matching position amounts.
484
495
  */
485
496
  readonly balanceComposition?: "tokens-include-positions" | "tokens-plus-positions";
497
+ /**
498
+ * Whether a withdrawal requires an owner-approved wallet transaction.
499
+ * Aggregate withdrawals run these agents before relayer-only agents so a
500
+ * rejected wallet request cannot happen after another leg has committed.
501
+ */
502
+ readonly withdrawalRequiresWalletApproval?: boolean;
486
503
  disconnect(): Promise<void>;
487
504
  activateAgent(state: ConnectionState, chainId: number, asset?: OwneySupportedTokens): Promise<void>;
488
505
  /**
@@ -554,6 +571,7 @@ declare class OwneySDK {
554
571
  private apiKey;
555
572
  private orgAgentConfig;
556
573
  private orgAgentConfigPromise;
574
+ private rpcUrls?;
557
575
  private zyfaiRpcUrls?;
558
576
  private yieldseekerApiBaseUrl?;
559
577
  private yieldseekerSiweOrigin?;
@@ -593,6 +611,7 @@ declare class OwneySDK {
593
611
  private requireState;
594
612
  private requireChainId;
595
613
  private requireConnectedProvider;
614
+ private getPaidRpcClient;
596
615
  /** Builds the default USDC batch callback for the connected wallet. */
597
616
  private getDefaultSponsoredCallback;
598
617
  /** Builds the wallet-native sponsored calls callback for compatible paymasters. */
@@ -676,10 +695,12 @@ declare class OwneySDK {
676
695
  * Invokes `agent.deposit` with the resolved sponsored callback, composing
677
696
  * two independent auto-recovery mechanisms:
678
697
  *
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
698
+ * 1. Missing Permit2 allowance outside the atomic Base-USDC path: when the
699
+ * app did not supply its own callback and the attempt fails with
700
+ * `PERMIT2_APPROVAL_REQUIRED`, this is the wallet's first Permit2 deposit
701
+ * for that token. Base USDC bundles a gasless ERC-2612 approval inside
702
+ * its sponsored deposit and never reaches this branch. Other tokens send
703
+ * the one-time user-paid Permit2 approval via `approvePermit2()` and
683
704
  * retry the SAME sponsored attempt once. Bounded to one approval attempt
684
705
  * per call so a wallet/agent that keeps reporting the allowance as
685
706
  * missing can't loop forever. If `approvePermit2()` itself throws (e.g.
@@ -711,6 +732,13 @@ declare class OwneySDK {
711
732
  private hasExistingBalance;
712
733
  private validateAssetSupport;
713
734
  private getEligibleAgents;
735
+ /**
736
+ * Run owner-approved withdrawals before relayer-only withdrawals. Wallet
737
+ * approval is the only point at which the user can cancel the aggregate
738
+ * operation, so no relayer leg should commit before it has completed.
739
+ */
740
+ private orderAgentsForWithdrawal;
741
+ private isUserRejectedWithdrawal;
714
742
  /**
715
743
  * Withdraw funds from a specific agent, or all agents that support the active chain+asset if agentId is omitted.
716
744
  * Validates that the asset is supported by the target agent(s) on the active chain.
@@ -846,6 +874,8 @@ type YieldseekerAgentOptions = {
846
874
  baseUrl?: string;
847
875
  fetchFn?: YieldseekerFetch;
848
876
  auth?: YieldseekerAuthDependencies;
877
+ /** Dedicated read transport; Base is used for receipt polling. */
878
+ rpcUrls?: RpcUrlsConfig;
849
879
  /** Test seam for the wallet-submission/receipt boundary. */
850
880
  transactionExecutor?: (state: ConnectionState, chainId: number, transaction: YieldseekerTransaction) => Promise<Hex>;
851
881
  /** Test seam for transactions submitted outside transactionExecutor. */
@@ -854,6 +884,7 @@ type YieldseekerAgentOptions = {
854
884
  declare class YieldseekerAgent implements IAgent {
855
885
  readonly id = "yieldseeker";
856
886
  readonly balanceComposition: "tokens-plus-positions";
887
+ readonly withdrawalRequiresWalletApproval = true;
857
888
  readonly supportedChainIds: readonly [8453];
858
889
  readonly supportedAssets: readonly [{
859
890
  readonly chainId: 8453;
@@ -868,14 +899,21 @@ declare class YieldseekerAgent implements IAgent {
868
899
  }];
869
900
  private readonly api;
870
901
  private readonly auth;
902
+ private readonly rpcUrls?;
903
+ private receiptClient?;
871
904
  private readonly transactionExecutor?;
872
905
  private readonly unwindReceiptWaiter?;
873
906
  private readonly agentContexts;
874
907
  private readonly users;
875
908
  private readonly pendingAgents;
909
+ private readonly pendingWalletContexts;
910
+ private readonly readCache;
911
+ private readonly pendingReads;
912
+ private readGeneration;
876
913
  private readonly yieldOptions;
877
914
  private readonly pendingYieldOptions;
878
915
  constructor(owneyApiKey: string, options?: YieldseekerAgentOptions);
916
+ private getReceiptClient;
879
917
  disconnect(): Promise<void>;
880
918
  activateAgent(state: ConnectionState, chainId: number, asset?: OwneySupportedTokens): Promise<void>;
881
919
  deposit(state: ConnectionState, chainId: number, amount: string, asset: OwneySupportedTokens, depositCallback?: DepositCallback): Promise<OwneyDepositResult>;
@@ -889,6 +927,10 @@ declare class YieldseekerAgent implements IAgent {
889
927
  private loadYieldOptions;
890
928
  private userKey;
891
929
  private contextKey;
930
+ private cachedRead;
931
+ private agentListKey;
932
+ private listAgents;
933
+ private contextForAgent;
892
934
  private resolveUser;
893
935
  private forgetUser;
894
936
  private ensureAgent;
@@ -981,4 +1023,4 @@ type OwneySIWXConfig = {
981
1023
  */
982
1024
  declare function createOwneySIWX(config: OwneySIWXConfig): SIWXConfig;
983
1025
 
984
- 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 };
1026
+ 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,23 @@
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 the Owney routing API's
12
+ * read-only RPC proxy. No upstream RPC credentials are included in the SDK.
13
+ * Wallet providers remain responsible for account access, chain switching,
14
+ * signatures, and transaction submission.
15
+ */
16
+ rpcUrls?: RpcUrlsConfig;
7
17
  /**
8
18
  * Optional per-chain RPC overrides for Zyfai SDK network calls.
9
19
  * Example: { 8453: "https://...", 42161: "https://..." }
20
+ * @deprecated Use rpcUrls so every agent shares the same read transport.
10
21
  */
11
22
  zyfaiRpcUrls?: ZyfaiRpcUrlsConfig;
12
23
  /** Optional Owney Yieldseeker proxy base URL override for integration tests. */
@@ -15,9 +26,9 @@ interface OwneySDKConfig {
15
26
  yieldseekerSiweOrigin?: string;
16
27
  /**
17
28
  * Optional override for the Owney routing API base URL used by all routing
18
- * calls (defaults to the OWNEY_ROUTING_API_BASE_URL env var, then the
19
- * production URL). Set this to point at a local/staging routing API,
20
- * e.g. "http://localhost:3000", when testing sponsor changes.
29
+ * calls. RPC proxy requests use OWNEY_ROUTING_API_BASE_URL when this is
30
+ * omitted; without either value, all rpcUrls must be configured.
31
+ * Set this to a local/staging routing API when testing sponsor changes.
21
32
  */
22
33
  routingApiBaseUrl?: string;
23
34
  /**
@@ -483,6 +494,12 @@ interface IAgent {
483
494
  * withdrawal planning must add matching position amounts.
484
495
  */
485
496
  readonly balanceComposition?: "tokens-include-positions" | "tokens-plus-positions";
497
+ /**
498
+ * Whether a withdrawal requires an owner-approved wallet transaction.
499
+ * Aggregate withdrawals run these agents before relayer-only agents so a
500
+ * rejected wallet request cannot happen after another leg has committed.
501
+ */
502
+ readonly withdrawalRequiresWalletApproval?: boolean;
486
503
  disconnect(): Promise<void>;
487
504
  activateAgent(state: ConnectionState, chainId: number, asset?: OwneySupportedTokens): Promise<void>;
488
505
  /**
@@ -554,6 +571,7 @@ declare class OwneySDK {
554
571
  private apiKey;
555
572
  private orgAgentConfig;
556
573
  private orgAgentConfigPromise;
574
+ private rpcUrls?;
557
575
  private zyfaiRpcUrls?;
558
576
  private yieldseekerApiBaseUrl?;
559
577
  private yieldseekerSiweOrigin?;
@@ -593,6 +611,7 @@ declare class OwneySDK {
593
611
  private requireState;
594
612
  private requireChainId;
595
613
  private requireConnectedProvider;
614
+ private getPaidRpcClient;
596
615
  /** Builds the default USDC batch callback for the connected wallet. */
597
616
  private getDefaultSponsoredCallback;
598
617
  /** Builds the wallet-native sponsored calls callback for compatible paymasters. */
@@ -676,10 +695,12 @@ declare class OwneySDK {
676
695
  * Invokes `agent.deposit` with the resolved sponsored callback, composing
677
696
  * two independent auto-recovery mechanisms:
678
697
  *
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
698
+ * 1. Missing Permit2 allowance outside the atomic Base-USDC path: when the
699
+ * app did not supply its own callback and the attempt fails with
700
+ * `PERMIT2_APPROVAL_REQUIRED`, this is the wallet's first Permit2 deposit
701
+ * for that token. Base USDC bundles a gasless ERC-2612 approval inside
702
+ * its sponsored deposit and never reaches this branch. Other tokens send
703
+ * the one-time user-paid Permit2 approval via `approvePermit2()` and
683
704
  * retry the SAME sponsored attempt once. Bounded to one approval attempt
684
705
  * per call so a wallet/agent that keeps reporting the allowance as
685
706
  * missing can't loop forever. If `approvePermit2()` itself throws (e.g.
@@ -711,6 +732,13 @@ declare class OwneySDK {
711
732
  private hasExistingBalance;
712
733
  private validateAssetSupport;
713
734
  private getEligibleAgents;
735
+ /**
736
+ * Run owner-approved withdrawals before relayer-only withdrawals. Wallet
737
+ * approval is the only point at which the user can cancel the aggregate
738
+ * operation, so no relayer leg should commit before it has completed.
739
+ */
740
+ private orderAgentsForWithdrawal;
741
+ private isUserRejectedWithdrawal;
714
742
  /**
715
743
  * Withdraw funds from a specific agent, or all agents that support the active chain+asset if agentId is omitted.
716
744
  * Validates that the asset is supported by the target agent(s) on the active chain.
@@ -846,6 +874,8 @@ type YieldseekerAgentOptions = {
846
874
  baseUrl?: string;
847
875
  fetchFn?: YieldseekerFetch;
848
876
  auth?: YieldseekerAuthDependencies;
877
+ /** Dedicated read transport; Base is used for receipt polling. */
878
+ rpcUrls?: RpcUrlsConfig;
849
879
  /** Test seam for the wallet-submission/receipt boundary. */
850
880
  transactionExecutor?: (state: ConnectionState, chainId: number, transaction: YieldseekerTransaction) => Promise<Hex>;
851
881
  /** Test seam for transactions submitted outside transactionExecutor. */
@@ -854,6 +884,7 @@ type YieldseekerAgentOptions = {
854
884
  declare class YieldseekerAgent implements IAgent {
855
885
  readonly id = "yieldseeker";
856
886
  readonly balanceComposition: "tokens-plus-positions";
887
+ readonly withdrawalRequiresWalletApproval = true;
857
888
  readonly supportedChainIds: readonly [8453];
858
889
  readonly supportedAssets: readonly [{
859
890
  readonly chainId: 8453;
@@ -868,14 +899,21 @@ declare class YieldseekerAgent implements IAgent {
868
899
  }];
869
900
  private readonly api;
870
901
  private readonly auth;
902
+ private readonly rpcUrls?;
903
+ private receiptClient?;
871
904
  private readonly transactionExecutor?;
872
905
  private readonly unwindReceiptWaiter?;
873
906
  private readonly agentContexts;
874
907
  private readonly users;
875
908
  private readonly pendingAgents;
909
+ private readonly pendingWalletContexts;
910
+ private readonly readCache;
911
+ private readonly pendingReads;
912
+ private readGeneration;
876
913
  private readonly yieldOptions;
877
914
  private readonly pendingYieldOptions;
878
915
  constructor(owneyApiKey: string, options?: YieldseekerAgentOptions);
916
+ private getReceiptClient;
879
917
  disconnect(): Promise<void>;
880
918
  activateAgent(state: ConnectionState, chainId: number, asset?: OwneySupportedTokens): Promise<void>;
881
919
  deposit(state: ConnectionState, chainId: number, amount: string, asset: OwneySupportedTokens, depositCallback?: DepositCallback): Promise<OwneyDepositResult>;
@@ -889,6 +927,10 @@ declare class YieldseekerAgent implements IAgent {
889
927
  private loadYieldOptions;
890
928
  private userKey;
891
929
  private contextKey;
930
+ private cachedRead;
931
+ private agentListKey;
932
+ private listAgents;
933
+ private contextForAgent;
892
934
  private resolveUser;
893
935
  private forgetUser;
894
936
  private ensureAgent;
@@ -981,4 +1023,4 @@ type OwneySIWXConfig = {
981
1023
  */
982
1024
  declare function createOwneySIWX(config: OwneySIWXConfig): SIWXConfig;
983
1025
 
984
- 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 };
1026
+ 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 };