@zyfai/sdk 0.2.42 → 0.2.43

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 CHANGED
@@ -100,6 +100,25 @@ This method:
100
100
 
101
101
  ## Core Features
102
102
 
103
+ > **Predeployed (pool) wallets.** Wallets provisioned by ZyFi's predeployment
104
+ > service are already deployed, already have the agent session enabled, and are
105
+ > backend-owned until the user's first deposit rotates ownership to them. The SDK
106
+ > detects these automatically from the sign-in response (`predeployed: true`) and
107
+ > adjusts, with no extra flags from the integrator:
108
+ >
109
+ > - `deploySafe()` returns the assigned wallet without sending a deploy tx.
110
+ > - `createSessionKey()` returns `{ alreadyActive: true }` without prompting a
111
+ > signature — the pool enabled the session at deploy time.
112
+ > - The address is always the backend-assigned one; it is **never** derived with
113
+ > `getDeterministicSafeAddress`.
114
+ >
115
+ > Net effect: onboarding a predeployed wallet takes a **single signature — the
116
+ > USDC deposit** (no wallet-deploy or session-key signatures).
117
+ >
118
+ > The pool's ERC-7579 module addresses are exported as reference constants
119
+ > (`POOL_MODULE_ADDRESSES`, `INTENT_SMART_SESSIONS`, `PROXY_EXECUTOR`, …) for
120
+ > parity/validation only — the SDK does not install them.
121
+
103
122
  ### 1. Deploy Safe Smart Wallet
104
123
 
105
124
  Deploy a Safe smart wallet:
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { Chain, PublicClient } from 'viem';
1
+ import { Chain, PublicClient, Address as Address$1 } from 'viem';
2
2
 
3
3
  /**
4
4
  * Zyfai SDK Types
@@ -693,6 +693,8 @@ declare class ZyfaiSDK {
693
693
  private walletClient;
694
694
  private authenticatedUserId;
695
695
  private hasActiveSessionKey;
696
+ private isPredeployed;
697
+ private connectedSmartWallet;
696
698
  private currentProvider;
697
699
  private currentChainId;
698
700
  private rpcUrls?;
@@ -874,6 +876,22 @@ declare class ZyfaiSDK {
874
876
  * @private
875
877
  */
876
878
  private getWalletClient;
879
+ /**
880
+ * True when userAddress is the currently connected/authenticated wallet.
881
+ * @private
882
+ */
883
+ private isConnectedUser;
884
+ /**
885
+ * Resolve the Safe smart wallet address for a user on a chain.
886
+ *
887
+ * Predeployed (pool) wallets are provisioned and owned by the backend at
888
+ * deploy time, so their address CANNOT be derived from the user's EOA with
889
+ * getDeterministicSafeAddress (CREATE2 from the EOA yields the wrong address).
890
+ * For the connected predeployed user we always use the backend-assigned
891
+ * address. Legacy wallets keep the API-first, deterministic-fallback behavior.
892
+ * @private
893
+ */
894
+ private getSafeAddressFor;
877
895
  /**
878
896
  * Get smart wallet address for a user
879
897
  * Returns the deterministic Safe address for an EOA, or the address itself if already a Safe
@@ -1713,4 +1731,48 @@ type BankrProvider = ReturnType<typeof createBankrProvider>;
1713
1731
 
1714
1732
  declare const VAULT_ADDRESS: "0xD580071c47d4a667858B5FafAb85BC9C609beC5D";
1715
1733
 
1716
- export { type APYPerStrategy, type APYPerStrategyResponse, type ActionData, type ActiveWallet, type ActiveWalletsResponse, type AddWalletToSdkResponse, type Address, type AllocationDetail, type ApyPosition, type BankrProvider, type BankrProviderConfig, type BestOpportunityDetails, type BestOpportunityResponse, type ChainConfig, type ChainPortfolio, type ChainTokenEarnings, type CustomizationConfig, type CustomizeBatchRequest, type CustomizeBatchResponse, DEFAULT_TOKEN_ADDRESSES, type DailyApyEntry, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DepegEvent, type DeploySafeResponse, type DepositResponse, type ERC7739Context, type ERC7739Data, type ExcludedPool, type FirstTopupResponse, type GetPoolsResponse, type GetSelectedPoolsResponse, type Hex, type HistoryEntry, type HistoryPosition, type HistoryResponse, type LiquidityDropEvent, type LogDepositResponse, type NewCollateralDetectedEvent, type OnchainEarnings, type OnchainEarningsResponse, type OpportunitiesResponse, type Opportunity, type OpportunityPosition, type PolicyData, type Pool, type Portfolio, type PortfolioAssetBalance, type PortfolioByAssetType, type PortfolioByChain, type PortfolioDetailed, type PortfolioDetailedResponse, type PortfolioResponse, type PortfolioToken, type PositionSlot, type Protocol, type ProtocolsResponse, type RebalanceFrequencyResponse, type RegisterAgentResponse, type SDKConfig, type SdkKeyTVLResponse, type Session, type SessionKeyResponse, type SimulateBestPositionsParams, type SimulateBestPositionsResponse, type SimulateCalldataItem, type SimulatedPosition, type SmartWalletByEOAResponse, type SmartWalletResponse, type Strategy, type SupportedChainId, type TVLResponse, type TokenApy, type TokenEarnings, type UpdateUserProfileRequest, type UpdateUserProfileResponse, type UserPosition, VAULT_ADDRESS, type VaultAsset, type VaultClaimResponse, type VaultDepositResponse, type VaultSharesResponse, type VaultWithdrawResponse, type VaultWithdrawStatusResponse, type VolumeResponse, type WalletTVL, type WithdrawResponse, type ZyfaiEventFilters, type ZyfaiEventHandlers, ZyfaiSDK, createBankrProvider, getChainConfig, getDefaultTokenAddress, getSupportedChainIds, isSupportedChain };
1734
+ /**
1735
+ * Predeployment (pool) module addresses — reference constants.
1736
+ *
1737
+ * These mirror the ERC-7579 module set that ZyFi's predeployment service installs
1738
+ * on a pool smart account. Source of truth: the predeployment repo
1739
+ * `src/infrastructure/chain/modules.ts` — keep these in sync with it.
1740
+ *
1741
+ * FOR PARITY / VALIDATION AND DOCUMENTATION ONLY. The SDK does not install
1742
+ * modules on-chain: legacy wallets are deployed by the backend (SAFE_DEPLOY) and
1743
+ * predeployed wallets are provisioned by the pool. Nothing in the SDK reads these
1744
+ * to build, sign, or derive transactions. They are hardcoded (not recomputed via
1745
+ * `@rhinestone/module-sdk`) on purpose — see SMART_SESSIONS_VALIDATOR below.
1746
+ */
1747
+
1748
+ /**
1749
+ * Classic SmartSessions validator (installed empty, session enabled later).
1750
+ *
1751
+ * IMPORTANT: this address is VERSION-DEPENDENT. The pool runs
1752
+ * `@rhinestone/module-sdk` 0.4.0, which yields this address; the SDK's local
1753
+ * 0.2.11 yields the older `0x00000000002B0eCfbD0496EE71e01257dA0E37DE`. We pin
1754
+ * the pool's value so the two never silently diverge.
1755
+ */
1756
+ declare const SMART_SESSIONS_VALIDATOR: Address$1;
1757
+ /** ERC-7739 compatibility fallback (selector 0x84b0196e). */
1758
+ declare const SMART_SESSIONS_FALLBACK: Address$1;
1759
+ /** Intent (SmartSession v1) executor. */
1760
+ declare const INTENT_EXECUTOR: Address$1;
1761
+ /** Proxy executor used by the intent / omni-account session profile. */
1762
+ declare const PROXY_EXECUTOR: Address$1;
1763
+ /** Intent smart-sessions validator — the emissary the pool enables via setConfig. */
1764
+ declare const INTENT_SMART_SESSIONS: Address$1;
1765
+ /** OwnableValidator — the module whose owner set is rotated to the user on deposit. */
1766
+ declare const OWNABLE_VALIDATOR: Address$1;
1767
+ /** Safe 7579 adapter — matches the pool; already used by the SDK for deploys. */
1768
+ declare const SAFE_7579_ADDRESS: Address$1;
1769
+ /** ERC-7579 launchpad — matches the pool; already used by the SDK for deploys. */
1770
+ declare const ERC7579_LAUNCHPAD_ADDRESS: Address$1;
1771
+ /**
1772
+ * The full module set a predeployed (pool) wallet carries, for validation.
1773
+ * Mirrors predeployment `DEFAULT_MODULES` plus OwnableValidator (the latter is
1774
+ * installed by the Rhinestone SDK at deploy, not in the provisioning batch).
1775
+ */
1776
+ declare const POOL_MODULE_ADDRESSES: readonly Address$1[];
1777
+
1778
+ export { type APYPerStrategy, type APYPerStrategyResponse, type ActionData, type ActiveWallet, type ActiveWalletsResponse, type AddWalletToSdkResponse, type Address, type AllocationDetail, type ApyPosition, type BankrProvider, type BankrProviderConfig, type BestOpportunityDetails, type BestOpportunityResponse, type ChainConfig, type ChainPortfolio, type ChainTokenEarnings, type CustomizationConfig, type CustomizeBatchRequest, type CustomizeBatchResponse, DEFAULT_TOKEN_ADDRESSES, type DailyApyEntry, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DepegEvent, type DeploySafeResponse, type DepositResponse, ERC7579_LAUNCHPAD_ADDRESS, type ERC7739Context, type ERC7739Data, type ExcludedPool, type FirstTopupResponse, type GetPoolsResponse, type GetSelectedPoolsResponse, type Hex, type HistoryEntry, type HistoryPosition, type HistoryResponse, INTENT_EXECUTOR, INTENT_SMART_SESSIONS, type LiquidityDropEvent, type LogDepositResponse, type NewCollateralDetectedEvent, OWNABLE_VALIDATOR, type OnchainEarnings, type OnchainEarningsResponse, type OpportunitiesResponse, type Opportunity, type OpportunityPosition, POOL_MODULE_ADDRESSES, PROXY_EXECUTOR, type PolicyData, type Pool, type Portfolio, type PortfolioAssetBalance, type PortfolioByAssetType, type PortfolioByChain, type PortfolioDetailed, type PortfolioDetailedResponse, type PortfolioResponse, type PortfolioToken, type PositionSlot, type Protocol, type ProtocolsResponse, type RebalanceFrequencyResponse, type RegisterAgentResponse, SAFE_7579_ADDRESS, type SDKConfig, SMART_SESSIONS_FALLBACK, SMART_SESSIONS_VALIDATOR, type SdkKeyTVLResponse, type Session, type SessionKeyResponse, type SimulateBestPositionsParams, type SimulateBestPositionsResponse, type SimulateCalldataItem, type SimulatedPosition, type SmartWalletByEOAResponse, type SmartWalletResponse, type Strategy, type SupportedChainId, type TVLResponse, type TokenApy, type TokenEarnings, type UpdateUserProfileRequest, type UpdateUserProfileResponse, type UserPosition, VAULT_ADDRESS, type VaultAsset, type VaultClaimResponse, type VaultDepositResponse, type VaultSharesResponse, type VaultWithdrawResponse, type VaultWithdrawStatusResponse, type VolumeResponse, type WalletTVL, type WithdrawResponse, type ZyfaiEventFilters, type ZyfaiEventHandlers, ZyfaiSDK, createBankrProvider, getChainConfig, getDefaultTokenAddress, getSupportedChainIds, isSupportedChain };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Chain, PublicClient } from 'viem';
1
+ import { Chain, PublicClient, Address as Address$1 } from 'viem';
2
2
 
3
3
  /**
4
4
  * Zyfai SDK Types
@@ -693,6 +693,8 @@ declare class ZyfaiSDK {
693
693
  private walletClient;
694
694
  private authenticatedUserId;
695
695
  private hasActiveSessionKey;
696
+ private isPredeployed;
697
+ private connectedSmartWallet;
696
698
  private currentProvider;
697
699
  private currentChainId;
698
700
  private rpcUrls?;
@@ -874,6 +876,22 @@ declare class ZyfaiSDK {
874
876
  * @private
875
877
  */
876
878
  private getWalletClient;
879
+ /**
880
+ * True when userAddress is the currently connected/authenticated wallet.
881
+ * @private
882
+ */
883
+ private isConnectedUser;
884
+ /**
885
+ * Resolve the Safe smart wallet address for a user on a chain.
886
+ *
887
+ * Predeployed (pool) wallets are provisioned and owned by the backend at
888
+ * deploy time, so their address CANNOT be derived from the user's EOA with
889
+ * getDeterministicSafeAddress (CREATE2 from the EOA yields the wrong address).
890
+ * For the connected predeployed user we always use the backend-assigned
891
+ * address. Legacy wallets keep the API-first, deterministic-fallback behavior.
892
+ * @private
893
+ */
894
+ private getSafeAddressFor;
877
895
  /**
878
896
  * Get smart wallet address for a user
879
897
  * Returns the deterministic Safe address for an EOA, or the address itself if already a Safe
@@ -1713,4 +1731,48 @@ type BankrProvider = ReturnType<typeof createBankrProvider>;
1713
1731
 
1714
1732
  declare const VAULT_ADDRESS: "0xD580071c47d4a667858B5FafAb85BC9C609beC5D";
1715
1733
 
1716
- export { type APYPerStrategy, type APYPerStrategyResponse, type ActionData, type ActiveWallet, type ActiveWalletsResponse, type AddWalletToSdkResponse, type Address, type AllocationDetail, type ApyPosition, type BankrProvider, type BankrProviderConfig, type BestOpportunityDetails, type BestOpportunityResponse, type ChainConfig, type ChainPortfolio, type ChainTokenEarnings, type CustomizationConfig, type CustomizeBatchRequest, type CustomizeBatchResponse, DEFAULT_TOKEN_ADDRESSES, type DailyApyEntry, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DepegEvent, type DeploySafeResponse, type DepositResponse, type ERC7739Context, type ERC7739Data, type ExcludedPool, type FirstTopupResponse, type GetPoolsResponse, type GetSelectedPoolsResponse, type Hex, type HistoryEntry, type HistoryPosition, type HistoryResponse, type LiquidityDropEvent, type LogDepositResponse, type NewCollateralDetectedEvent, type OnchainEarnings, type OnchainEarningsResponse, type OpportunitiesResponse, type Opportunity, type OpportunityPosition, type PolicyData, type Pool, type Portfolio, type PortfolioAssetBalance, type PortfolioByAssetType, type PortfolioByChain, type PortfolioDetailed, type PortfolioDetailedResponse, type PortfolioResponse, type PortfolioToken, type PositionSlot, type Protocol, type ProtocolsResponse, type RebalanceFrequencyResponse, type RegisterAgentResponse, type SDKConfig, type SdkKeyTVLResponse, type Session, type SessionKeyResponse, type SimulateBestPositionsParams, type SimulateBestPositionsResponse, type SimulateCalldataItem, type SimulatedPosition, type SmartWalletByEOAResponse, type SmartWalletResponse, type Strategy, type SupportedChainId, type TVLResponse, type TokenApy, type TokenEarnings, type UpdateUserProfileRequest, type UpdateUserProfileResponse, type UserPosition, VAULT_ADDRESS, type VaultAsset, type VaultClaimResponse, type VaultDepositResponse, type VaultSharesResponse, type VaultWithdrawResponse, type VaultWithdrawStatusResponse, type VolumeResponse, type WalletTVL, type WithdrawResponse, type ZyfaiEventFilters, type ZyfaiEventHandlers, ZyfaiSDK, createBankrProvider, getChainConfig, getDefaultTokenAddress, getSupportedChainIds, isSupportedChain };
1734
+ /**
1735
+ * Predeployment (pool) module addresses — reference constants.
1736
+ *
1737
+ * These mirror the ERC-7579 module set that ZyFi's predeployment service installs
1738
+ * on a pool smart account. Source of truth: the predeployment repo
1739
+ * `src/infrastructure/chain/modules.ts` — keep these in sync with it.
1740
+ *
1741
+ * FOR PARITY / VALIDATION AND DOCUMENTATION ONLY. The SDK does not install
1742
+ * modules on-chain: legacy wallets are deployed by the backend (SAFE_DEPLOY) and
1743
+ * predeployed wallets are provisioned by the pool. Nothing in the SDK reads these
1744
+ * to build, sign, or derive transactions. They are hardcoded (not recomputed via
1745
+ * `@rhinestone/module-sdk`) on purpose — see SMART_SESSIONS_VALIDATOR below.
1746
+ */
1747
+
1748
+ /**
1749
+ * Classic SmartSessions validator (installed empty, session enabled later).
1750
+ *
1751
+ * IMPORTANT: this address is VERSION-DEPENDENT. The pool runs
1752
+ * `@rhinestone/module-sdk` 0.4.0, which yields this address; the SDK's local
1753
+ * 0.2.11 yields the older `0x00000000002B0eCfbD0496EE71e01257dA0E37DE`. We pin
1754
+ * the pool's value so the two never silently diverge.
1755
+ */
1756
+ declare const SMART_SESSIONS_VALIDATOR: Address$1;
1757
+ /** ERC-7739 compatibility fallback (selector 0x84b0196e). */
1758
+ declare const SMART_SESSIONS_FALLBACK: Address$1;
1759
+ /** Intent (SmartSession v1) executor. */
1760
+ declare const INTENT_EXECUTOR: Address$1;
1761
+ /** Proxy executor used by the intent / omni-account session profile. */
1762
+ declare const PROXY_EXECUTOR: Address$1;
1763
+ /** Intent smart-sessions validator — the emissary the pool enables via setConfig. */
1764
+ declare const INTENT_SMART_SESSIONS: Address$1;
1765
+ /** OwnableValidator — the module whose owner set is rotated to the user on deposit. */
1766
+ declare const OWNABLE_VALIDATOR: Address$1;
1767
+ /** Safe 7579 adapter — matches the pool; already used by the SDK for deploys. */
1768
+ declare const SAFE_7579_ADDRESS: Address$1;
1769
+ /** ERC-7579 launchpad — matches the pool; already used by the SDK for deploys. */
1770
+ declare const ERC7579_LAUNCHPAD_ADDRESS: Address$1;
1771
+ /**
1772
+ * The full module set a predeployed (pool) wallet carries, for validation.
1773
+ * Mirrors predeployment `DEFAULT_MODULES` plus OwnableValidator (the latter is
1774
+ * installed by the Rhinestone SDK at deploy, not in the provisioning batch).
1775
+ */
1776
+ declare const POOL_MODULE_ADDRESSES: readonly Address$1[];
1777
+
1778
+ export { type APYPerStrategy, type APYPerStrategyResponse, type ActionData, type ActiveWallet, type ActiveWalletsResponse, type AddWalletToSdkResponse, type Address, type AllocationDetail, type ApyPosition, type BankrProvider, type BankrProviderConfig, type BestOpportunityDetails, type BestOpportunityResponse, type ChainConfig, type ChainPortfolio, type ChainTokenEarnings, type CustomizationConfig, type CustomizeBatchRequest, type CustomizeBatchResponse, DEFAULT_TOKEN_ADDRESSES, type DailyApyEntry, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DepegEvent, type DeploySafeResponse, type DepositResponse, ERC7579_LAUNCHPAD_ADDRESS, type ERC7739Context, type ERC7739Data, type ExcludedPool, type FirstTopupResponse, type GetPoolsResponse, type GetSelectedPoolsResponse, type Hex, type HistoryEntry, type HistoryPosition, type HistoryResponse, INTENT_EXECUTOR, INTENT_SMART_SESSIONS, type LiquidityDropEvent, type LogDepositResponse, type NewCollateralDetectedEvent, OWNABLE_VALIDATOR, type OnchainEarnings, type OnchainEarningsResponse, type OpportunitiesResponse, type Opportunity, type OpportunityPosition, POOL_MODULE_ADDRESSES, PROXY_EXECUTOR, type PolicyData, type Pool, type Portfolio, type PortfolioAssetBalance, type PortfolioByAssetType, type PortfolioByChain, type PortfolioDetailed, type PortfolioDetailedResponse, type PortfolioResponse, type PortfolioToken, type PositionSlot, type Protocol, type ProtocolsResponse, type RebalanceFrequencyResponse, type RegisterAgentResponse, SAFE_7579_ADDRESS, type SDKConfig, SMART_SESSIONS_FALLBACK, SMART_SESSIONS_VALIDATOR, type SdkKeyTVLResponse, type Session, type SessionKeyResponse, type SimulateBestPositionsParams, type SimulateBestPositionsResponse, type SimulateCalldataItem, type SimulatedPosition, type SmartWalletByEOAResponse, type SmartWalletResponse, type Strategy, type SupportedChainId, type TVLResponse, type TokenApy, type TokenEarnings, type UpdateUserProfileRequest, type UpdateUserProfileResponse, type UserPosition, VAULT_ADDRESS, type VaultAsset, type VaultClaimResponse, type VaultDepositResponse, type VaultSharesResponse, type VaultWithdrawResponse, type VaultWithdrawStatusResponse, type VolumeResponse, type WalletTVL, type WithdrawResponse, type ZyfaiEventFilters, type ZyfaiEventHandlers, ZyfaiSDK, createBankrProvider, getChainConfig, getDefaultTokenAddress, getSupportedChainIds, isSupportedChain };
package/dist/index.js CHANGED
@@ -31,6 +31,15 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
33
  DEFAULT_TOKEN_ADDRESSES: () => DEFAULT_TOKEN_ADDRESSES,
34
+ ERC7579_LAUNCHPAD_ADDRESS: () => ERC7579_LAUNCHPAD_ADDRESS2,
35
+ INTENT_EXECUTOR: () => INTENT_EXECUTOR,
36
+ INTENT_SMART_SESSIONS: () => INTENT_SMART_SESSIONS,
37
+ OWNABLE_VALIDATOR: () => OWNABLE_VALIDATOR,
38
+ POOL_MODULE_ADDRESSES: () => POOL_MODULE_ADDRESSES,
39
+ PROXY_EXECUTOR: () => PROXY_EXECUTOR,
40
+ SAFE_7579_ADDRESS: () => SAFE_7579_ADDRESS2,
41
+ SMART_SESSIONS_FALLBACK: () => SMART_SESSIONS_FALLBACK,
42
+ SMART_SESSIONS_VALIDATOR: () => SMART_SESSIONS_VALIDATOR,
34
43
  VAULT_ADDRESS: () => VAULT_ADDRESS,
35
44
  ZyfaiSDK: () => ZyfaiSDK,
36
45
  createBankrProvider: () => createBankrProvider,
@@ -963,6 +972,8 @@ var _ZyfaiSDK = class _ZyfaiSDK {
963
972
  this.walletClient = null;
964
973
  this.authenticatedUserId = null;
965
974
  this.hasActiveSessionKey = false;
975
+ this.isPredeployed = false;
976
+ this.connectedSmartWallet = null;
966
977
  this.currentProvider = null;
967
978
  this.currentChainId = null;
968
979
  const sdkConfig = typeof config === "string" ? { apiKey: config } : config;
@@ -1037,6 +1048,8 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1037
1048
  this.httpClient.setAuthToken(authToken);
1038
1049
  this.authenticatedUserId = loginResponse.userId || null;
1039
1050
  this.hasActiveSessionKey = loginResponse.hasActiveSessionKey || false;
1051
+ this.isPredeployed = loginResponse.predeployed || false;
1052
+ this.connectedSmartWallet = loginResponse.smartWallet || null;
1040
1053
  } catch (error) {
1041
1054
  throw new Error(
1042
1055
  `Failed to authenticate user: ${error.message}`
@@ -1379,6 +1392,8 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1379
1392
  throw new Error(`Unsupported chain ID: ${chainId}`);
1380
1393
  }
1381
1394
  this.authenticatedUserId = null;
1395
+ this.isPredeployed = false;
1396
+ this.connectedSmartWallet = null;
1382
1397
  this.currentChainId = null;
1383
1398
  this.httpClient.clearAuthToken();
1384
1399
  if (this.currentProvider?.removeAllListeners) {
@@ -1469,6 +1484,8 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1469
1484
  this.currentChainId = null;
1470
1485
  this.authenticatedUserId = null;
1471
1486
  this.hasActiveSessionKey = false;
1487
+ this.isPredeployed = false;
1488
+ this.connectedSmartWallet = null;
1472
1489
  this.httpClient.clearAuthToken();
1473
1490
  }
1474
1491
  /**
@@ -1494,6 +1511,48 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1494
1511
  return this.walletClient;
1495
1512
  }
1496
1513
  }
1514
+ /**
1515
+ * True when userAddress is the currently connected/authenticated wallet.
1516
+ * @private
1517
+ */
1518
+ isConnectedUser(userAddress) {
1519
+ const connected = this.signer?.address ?? this.walletClient?.account?.address;
1520
+ return !!connected && connected.toLowerCase() === userAddress.toLowerCase();
1521
+ }
1522
+ /**
1523
+ * Resolve the Safe smart wallet address for a user on a chain.
1524
+ *
1525
+ * Predeployed (pool) wallets are provisioned and owned by the backend at
1526
+ * deploy time, so their address CANNOT be derived from the user's EOA with
1527
+ * getDeterministicSafeAddress (CREATE2 from the EOA yields the wrong address).
1528
+ * For the connected predeployed user we always use the backend-assigned
1529
+ * address. Legacy wallets keep the API-first, deterministic-fallback behavior.
1530
+ * @private
1531
+ */
1532
+ async getSafeAddressFor(userAddress, chainId) {
1533
+ if (this.isPredeployed && this.isConnectedUser(userAddress)) {
1534
+ if (this.connectedSmartWallet) return this.connectedSmartWallet;
1535
+ try {
1536
+ const info = await this.getSmartWalletByEOA(userAddress);
1537
+ if (info.smartWallet) return info.smartWallet;
1538
+ } catch {
1539
+ }
1540
+ throw new Error(
1541
+ "Predeployed smart wallet address is not available from the API yet. Ensure the user has signed in so the pool can reserve their wallet."
1542
+ );
1543
+ }
1544
+ try {
1545
+ const info = await this.getSmartWalletByEOA(userAddress);
1546
+ if (info.smartWallet) return info.smartWallet;
1547
+ } catch {
1548
+ }
1549
+ const chainConfig = getChainConfig(chainId, this.rpcUrls);
1550
+ return getDeterministicSafeAddress({
1551
+ safeOwnerAddress: userAddress,
1552
+ chain: chainConfig.chain,
1553
+ publicClient: chainConfig.publicClient
1554
+ });
1555
+ }
1497
1556
  /**
1498
1557
  * Get smart wallet address for a user
1499
1558
  * Returns the deterministic Safe address for an EOA, or the address itself if already a Safe
@@ -1510,25 +1569,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1510
1569
  throw new Error(`Unsupported chain ID: ${chainId}`);
1511
1570
  }
1512
1571
  const chainConfig = getChainConfig(chainId, this.rpcUrls);
1513
- try {
1514
- const smartWalletInfo = await this.getSmartWalletByEOA(userAddress);
1515
- if (smartWalletInfo.smartWallet) {
1516
- const isDeployed2 = await isSafeDeployed(
1517
- smartWalletInfo.smartWallet,
1518
- chainConfig.publicClient
1519
- );
1520
- return {
1521
- address: smartWalletInfo.smartWallet,
1522
- isDeployed: isDeployed2
1523
- };
1524
- }
1525
- } catch {
1526
- }
1527
- const safeAddress = await getDeterministicSafeAddress({
1528
- safeOwnerAddress: userAddress,
1529
- chain: chainConfig.chain,
1530
- publicClient: chainConfig.publicClient
1531
- });
1572
+ const safeAddress = await this.getSafeAddressFor(userAddress, chainId);
1532
1573
  const isDeployed = await isSafeDeployed(
1533
1574
  safeAddress,
1534
1575
  chainConfig.publicClient
@@ -1568,6 +1609,20 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1568
1609
  throw new Error(`Unsupported chain ID: ${chainId}`);
1569
1610
  }
1570
1611
  await this.authenticateUser();
1612
+ if (this.isPredeployed && this.isConnectedUser(userAddress)) {
1613
+ const predeployedAddress = await this.getSafeAddressFor(
1614
+ userAddress,
1615
+ chainId
1616
+ );
1617
+ await this.updateUserProtocols(chainId, strategy);
1618
+ return {
1619
+ success: true,
1620
+ safeAddress: predeployedAddress,
1621
+ txHash: "0x0",
1622
+ status: "deployed",
1623
+ sessionKeyCreated: true
1624
+ };
1625
+ }
1571
1626
  const walletClient = this.getWalletClient(chainId);
1572
1627
  const chainConfig = getChainConfig(chainId, this.rpcUrls);
1573
1628
  const safeAddress = await getDeterministicSafeAddress({
@@ -1668,6 +1723,14 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1668
1723
  "User ID not available. Please ensure authentication completed successfully."
1669
1724
  );
1670
1725
  }
1726
+ if (this.isPredeployed) {
1727
+ return {
1728
+ success: true,
1729
+ userId: this.authenticatedUserId,
1730
+ message: "Predeployed wallet: agent session is managed by the backend",
1731
+ alreadyActive: true
1732
+ };
1733
+ }
1671
1734
  if (this.hasActiveSessionKey) {
1672
1735
  return {
1673
1736
  success: true,
@@ -1957,11 +2020,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1957
2020
  const token = getDefaultTokenAddress(chainId, assetSymbol);
1958
2021
  const walletClient = this.getWalletClient();
1959
2022
  const chainConfig = getChainConfig(chainId, this.rpcUrls);
1960
- const safeAddress = await getDeterministicSafeAddress({
1961
- safeOwnerAddress: userAddress,
1962
- chain: chainConfig.chain,
1963
- publicClient: chainConfig.publicClient
1964
- });
2023
+ const safeAddress = await this.getSafeAddressFor(userAddress, chainId);
1965
2024
  const isDeployed = await isSafeDeployed(
1966
2025
  safeAddress,
1967
2026
  chainConfig.publicClient
@@ -2123,25 +2182,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2123
2182
  throw new Error(`Unsupported chain ID: ${chainId}`);
2124
2183
  }
2125
2184
  const chainConfig = getChainConfig(chainId, this.rpcUrls);
2126
- let safeAddress;
2127
- try {
2128
- const smartWalletInfo = await this.getSmartWalletByEOA(userAddress);
2129
- if (smartWalletInfo.smartWallet) {
2130
- safeAddress = smartWalletInfo.smartWallet;
2131
- } else {
2132
- safeAddress = await getDeterministicSafeAddress({
2133
- safeOwnerAddress: userAddress,
2134
- chain: chainConfig.chain,
2135
- publicClient: chainConfig.publicClient
2136
- });
2137
- }
2138
- } catch {
2139
- safeAddress = await getDeterministicSafeAddress({
2140
- safeOwnerAddress: userAddress,
2141
- chain: chainConfig.chain,
2142
- publicClient: chainConfig.publicClient
2143
- });
2144
- }
2185
+ const safeAddress = await this.getSafeAddressFor(userAddress, chainId);
2145
2186
  const isDeployed = await isSafeDeployed(
2146
2187
  safeAddress,
2147
2188
  chainConfig.publicClient
@@ -3952,9 +3993,36 @@ function createBankrProvider(config) {
3952
3993
  };
3953
3994
  return provider;
3954
3995
  }
3996
+
3997
+ // src/config/modules.ts
3998
+ var SMART_SESSIONS_VALIDATOR = "0x00000000008bDABA73cD9815d79069c247Eb4bDA";
3999
+ var SMART_SESSIONS_FALLBACK = "0x12cae64c42f362e7d5a847c2d33388373f629177";
4000
+ var INTENT_EXECUTOR = "0x00000000005aD9ce1f5035FD62CA96CEf16AdAAF";
4001
+ var PROXY_EXECUTOR = "0xF659d30D4EB88B06A909F20839D8959Bd77d8790";
4002
+ var INTENT_SMART_SESSIONS = "0xad568b3f825a8d5ffc06dd3253526b64d810ae89";
4003
+ var OWNABLE_VALIDATOR = "0x000000000013fdB5234E4E3162a810F54d9f7E98";
4004
+ var SAFE_7579_ADDRESS2 = "0x7579EE8307284F293B1927136486880611F20002";
4005
+ var ERC7579_LAUNCHPAD_ADDRESS2 = "0x7579011aB74c46090561ea277Ba79D510c6C00ff";
4006
+ var POOL_MODULE_ADDRESSES = [
4007
+ SMART_SESSIONS_VALIDATOR,
4008
+ SMART_SESSIONS_FALLBACK,
4009
+ INTENT_EXECUTOR,
4010
+ PROXY_EXECUTOR,
4011
+ INTENT_SMART_SESSIONS,
4012
+ OWNABLE_VALIDATOR
4013
+ ];
3955
4014
  // Annotate the CommonJS export names for ESM import in node:
3956
4015
  0 && (module.exports = {
3957
4016
  DEFAULT_TOKEN_ADDRESSES,
4017
+ ERC7579_LAUNCHPAD_ADDRESS,
4018
+ INTENT_EXECUTOR,
4019
+ INTENT_SMART_SESSIONS,
4020
+ OWNABLE_VALIDATOR,
4021
+ POOL_MODULE_ADDRESSES,
4022
+ PROXY_EXECUTOR,
4023
+ SAFE_7579_ADDRESS,
4024
+ SMART_SESSIONS_FALLBACK,
4025
+ SMART_SESSIONS_VALIDATOR,
3958
4026
  VAULT_ADDRESS,
3959
4027
  ZyfaiSDK,
3960
4028
  createBankrProvider,
package/dist/index.mjs CHANGED
@@ -939,6 +939,8 @@ var _ZyfaiSDK = class _ZyfaiSDK {
939
939
  this.walletClient = null;
940
940
  this.authenticatedUserId = null;
941
941
  this.hasActiveSessionKey = false;
942
+ this.isPredeployed = false;
943
+ this.connectedSmartWallet = null;
942
944
  this.currentProvider = null;
943
945
  this.currentChainId = null;
944
946
  const sdkConfig = typeof config === "string" ? { apiKey: config } : config;
@@ -1013,6 +1015,8 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1013
1015
  this.httpClient.setAuthToken(authToken);
1014
1016
  this.authenticatedUserId = loginResponse.userId || null;
1015
1017
  this.hasActiveSessionKey = loginResponse.hasActiveSessionKey || false;
1018
+ this.isPredeployed = loginResponse.predeployed || false;
1019
+ this.connectedSmartWallet = loginResponse.smartWallet || null;
1016
1020
  } catch (error) {
1017
1021
  throw new Error(
1018
1022
  `Failed to authenticate user: ${error.message}`
@@ -1355,6 +1359,8 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1355
1359
  throw new Error(`Unsupported chain ID: ${chainId}`);
1356
1360
  }
1357
1361
  this.authenticatedUserId = null;
1362
+ this.isPredeployed = false;
1363
+ this.connectedSmartWallet = null;
1358
1364
  this.currentChainId = null;
1359
1365
  this.httpClient.clearAuthToken();
1360
1366
  if (this.currentProvider?.removeAllListeners) {
@@ -1445,6 +1451,8 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1445
1451
  this.currentChainId = null;
1446
1452
  this.authenticatedUserId = null;
1447
1453
  this.hasActiveSessionKey = false;
1454
+ this.isPredeployed = false;
1455
+ this.connectedSmartWallet = null;
1448
1456
  this.httpClient.clearAuthToken();
1449
1457
  }
1450
1458
  /**
@@ -1470,6 +1478,48 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1470
1478
  return this.walletClient;
1471
1479
  }
1472
1480
  }
1481
+ /**
1482
+ * True when userAddress is the currently connected/authenticated wallet.
1483
+ * @private
1484
+ */
1485
+ isConnectedUser(userAddress) {
1486
+ const connected = this.signer?.address ?? this.walletClient?.account?.address;
1487
+ return !!connected && connected.toLowerCase() === userAddress.toLowerCase();
1488
+ }
1489
+ /**
1490
+ * Resolve the Safe smart wallet address for a user on a chain.
1491
+ *
1492
+ * Predeployed (pool) wallets are provisioned and owned by the backend at
1493
+ * deploy time, so their address CANNOT be derived from the user's EOA with
1494
+ * getDeterministicSafeAddress (CREATE2 from the EOA yields the wrong address).
1495
+ * For the connected predeployed user we always use the backend-assigned
1496
+ * address. Legacy wallets keep the API-first, deterministic-fallback behavior.
1497
+ * @private
1498
+ */
1499
+ async getSafeAddressFor(userAddress, chainId) {
1500
+ if (this.isPredeployed && this.isConnectedUser(userAddress)) {
1501
+ if (this.connectedSmartWallet) return this.connectedSmartWallet;
1502
+ try {
1503
+ const info = await this.getSmartWalletByEOA(userAddress);
1504
+ if (info.smartWallet) return info.smartWallet;
1505
+ } catch {
1506
+ }
1507
+ throw new Error(
1508
+ "Predeployed smart wallet address is not available from the API yet. Ensure the user has signed in so the pool can reserve their wallet."
1509
+ );
1510
+ }
1511
+ try {
1512
+ const info = await this.getSmartWalletByEOA(userAddress);
1513
+ if (info.smartWallet) return info.smartWallet;
1514
+ } catch {
1515
+ }
1516
+ const chainConfig = getChainConfig(chainId, this.rpcUrls);
1517
+ return getDeterministicSafeAddress({
1518
+ safeOwnerAddress: userAddress,
1519
+ chain: chainConfig.chain,
1520
+ publicClient: chainConfig.publicClient
1521
+ });
1522
+ }
1473
1523
  /**
1474
1524
  * Get smart wallet address for a user
1475
1525
  * Returns the deterministic Safe address for an EOA, or the address itself if already a Safe
@@ -1486,25 +1536,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1486
1536
  throw new Error(`Unsupported chain ID: ${chainId}`);
1487
1537
  }
1488
1538
  const chainConfig = getChainConfig(chainId, this.rpcUrls);
1489
- try {
1490
- const smartWalletInfo = await this.getSmartWalletByEOA(userAddress);
1491
- if (smartWalletInfo.smartWallet) {
1492
- const isDeployed2 = await isSafeDeployed(
1493
- smartWalletInfo.smartWallet,
1494
- chainConfig.publicClient
1495
- );
1496
- return {
1497
- address: smartWalletInfo.smartWallet,
1498
- isDeployed: isDeployed2
1499
- };
1500
- }
1501
- } catch {
1502
- }
1503
- const safeAddress = await getDeterministicSafeAddress({
1504
- safeOwnerAddress: userAddress,
1505
- chain: chainConfig.chain,
1506
- publicClient: chainConfig.publicClient
1507
- });
1539
+ const safeAddress = await this.getSafeAddressFor(userAddress, chainId);
1508
1540
  const isDeployed = await isSafeDeployed(
1509
1541
  safeAddress,
1510
1542
  chainConfig.publicClient
@@ -1544,6 +1576,20 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1544
1576
  throw new Error(`Unsupported chain ID: ${chainId}`);
1545
1577
  }
1546
1578
  await this.authenticateUser();
1579
+ if (this.isPredeployed && this.isConnectedUser(userAddress)) {
1580
+ const predeployedAddress = await this.getSafeAddressFor(
1581
+ userAddress,
1582
+ chainId
1583
+ );
1584
+ await this.updateUserProtocols(chainId, strategy);
1585
+ return {
1586
+ success: true,
1587
+ safeAddress: predeployedAddress,
1588
+ txHash: "0x0",
1589
+ status: "deployed",
1590
+ sessionKeyCreated: true
1591
+ };
1592
+ }
1547
1593
  const walletClient = this.getWalletClient(chainId);
1548
1594
  const chainConfig = getChainConfig(chainId, this.rpcUrls);
1549
1595
  const safeAddress = await getDeterministicSafeAddress({
@@ -1644,6 +1690,14 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1644
1690
  "User ID not available. Please ensure authentication completed successfully."
1645
1691
  );
1646
1692
  }
1693
+ if (this.isPredeployed) {
1694
+ return {
1695
+ success: true,
1696
+ userId: this.authenticatedUserId,
1697
+ message: "Predeployed wallet: agent session is managed by the backend",
1698
+ alreadyActive: true
1699
+ };
1700
+ }
1647
1701
  if (this.hasActiveSessionKey) {
1648
1702
  return {
1649
1703
  success: true,
@@ -1933,11 +1987,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1933
1987
  const token = getDefaultTokenAddress(chainId, assetSymbol);
1934
1988
  const walletClient = this.getWalletClient();
1935
1989
  const chainConfig = getChainConfig(chainId, this.rpcUrls);
1936
- const safeAddress = await getDeterministicSafeAddress({
1937
- safeOwnerAddress: userAddress,
1938
- chain: chainConfig.chain,
1939
- publicClient: chainConfig.publicClient
1940
- });
1990
+ const safeAddress = await this.getSafeAddressFor(userAddress, chainId);
1941
1991
  const isDeployed = await isSafeDeployed(
1942
1992
  safeAddress,
1943
1993
  chainConfig.publicClient
@@ -2099,25 +2149,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2099
2149
  throw new Error(`Unsupported chain ID: ${chainId}`);
2100
2150
  }
2101
2151
  const chainConfig = getChainConfig(chainId, this.rpcUrls);
2102
- let safeAddress;
2103
- try {
2104
- const smartWalletInfo = await this.getSmartWalletByEOA(userAddress);
2105
- if (smartWalletInfo.smartWallet) {
2106
- safeAddress = smartWalletInfo.smartWallet;
2107
- } else {
2108
- safeAddress = await getDeterministicSafeAddress({
2109
- safeOwnerAddress: userAddress,
2110
- chain: chainConfig.chain,
2111
- publicClient: chainConfig.publicClient
2112
- });
2113
- }
2114
- } catch {
2115
- safeAddress = await getDeterministicSafeAddress({
2116
- safeOwnerAddress: userAddress,
2117
- chain: chainConfig.chain,
2118
- publicClient: chainConfig.publicClient
2119
- });
2120
- }
2152
+ const safeAddress = await this.getSafeAddressFor(userAddress, chainId);
2121
2153
  const isDeployed = await isSafeDeployed(
2122
2154
  safeAddress,
2123
2155
  chainConfig.publicClient
@@ -3928,8 +3960,35 @@ function createBankrProvider(config) {
3928
3960
  };
3929
3961
  return provider;
3930
3962
  }
3963
+
3964
+ // src/config/modules.ts
3965
+ var SMART_SESSIONS_VALIDATOR = "0x00000000008bDABA73cD9815d79069c247Eb4bDA";
3966
+ var SMART_SESSIONS_FALLBACK = "0x12cae64c42f362e7d5a847c2d33388373f629177";
3967
+ var INTENT_EXECUTOR = "0x00000000005aD9ce1f5035FD62CA96CEf16AdAAF";
3968
+ var PROXY_EXECUTOR = "0xF659d30D4EB88B06A909F20839D8959Bd77d8790";
3969
+ var INTENT_SMART_SESSIONS = "0xad568b3f825a8d5ffc06dd3253526b64d810ae89";
3970
+ var OWNABLE_VALIDATOR = "0x000000000013fdB5234E4E3162a810F54d9f7E98";
3971
+ var SAFE_7579_ADDRESS2 = "0x7579EE8307284F293B1927136486880611F20002";
3972
+ var ERC7579_LAUNCHPAD_ADDRESS2 = "0x7579011aB74c46090561ea277Ba79D510c6C00ff";
3973
+ var POOL_MODULE_ADDRESSES = [
3974
+ SMART_SESSIONS_VALIDATOR,
3975
+ SMART_SESSIONS_FALLBACK,
3976
+ INTENT_EXECUTOR,
3977
+ PROXY_EXECUTOR,
3978
+ INTENT_SMART_SESSIONS,
3979
+ OWNABLE_VALIDATOR
3980
+ ];
3931
3981
  export {
3932
3982
  DEFAULT_TOKEN_ADDRESSES,
3983
+ ERC7579_LAUNCHPAD_ADDRESS2 as ERC7579_LAUNCHPAD_ADDRESS,
3984
+ INTENT_EXECUTOR,
3985
+ INTENT_SMART_SESSIONS,
3986
+ OWNABLE_VALIDATOR,
3987
+ POOL_MODULE_ADDRESSES,
3988
+ PROXY_EXECUTOR,
3989
+ SAFE_7579_ADDRESS2 as SAFE_7579_ADDRESS,
3990
+ SMART_SESSIONS_FALLBACK,
3991
+ SMART_SESSIONS_VALIDATOR,
3933
3992
  VAULT_ADDRESS,
3934
3993
  ZyfaiSDK,
3935
3994
  createBankrProvider,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zyfai/sdk",
3
- "version": "0.2.42",
3
+ "version": "0.2.43",
4
4
  "description": "TypeScript SDK for Zyfai Yield Optimization Engine - Deploy Safe smart wallets, manage session keys, and interact with DeFi protocols",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",