@zyfai/sdk 0.2.42 → 0.2.44

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.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_ADDRESS,
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_ADDRESS,
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,
@@ -336,6 +345,15 @@ var HttpClient = class {
336
345
 
337
346
  // src/config/abis.ts
338
347
  var import_viem = require("viem");
348
+ var OWNABLE_VALIDATOR_ABI = [
349
+ {
350
+ name: "getOwners",
351
+ type: "function",
352
+ stateMutability: "view",
353
+ inputs: [{ name: "account", type: "address" }],
354
+ outputs: [{ name: "ownersArray", type: "address[]" }]
355
+ }
356
+ ];
339
357
  var ERC20_ABI = [
340
358
  {
341
359
  name: "transfer",
@@ -584,6 +602,25 @@ var ASSET_CONFIGS = {
584
602
  // Linea
585
603
  },
586
604
  enabled: true
605
+ },
606
+ EURC: {
607
+ symbol: "EURC",
608
+ assetType: "eurc",
609
+ displayName: "EURC",
610
+ icon: "/ai-dashboard/eurc-token.png",
611
+ decimals: 6,
612
+ tokenSymbols: ["EURC"],
613
+ tokenSymbolsByChainId: {
614
+ 1: "EURC",
615
+ 8453: "EURC"
616
+ },
617
+ addresses: {
618
+ 1: "0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c",
619
+ // Ethereum
620
+ 8453: "0x60a3E35Cc302bFA44Cb288Bc5a4F316Fdb1adb42"
621
+ // Base
622
+ },
623
+ enabled: true
587
624
  }
588
625
  };
589
626
  var getDefaultTokenAddress = (chainId, asset) => {
@@ -633,8 +670,28 @@ var import_module_sdk = require("@rhinestone/module-sdk");
633
670
  var import_accounts = require("permissionless/accounts");
634
671
  var import_viem3 = require("viem");
635
672
  var import_account_abstraction = require("viem/account-abstraction");
673
+
674
+ // src/config/modules.ts
675
+ var SMART_SESSIONS_VALIDATOR = "0x00000000008bDABA73cD9815d79069c247Eb4bDA";
676
+ var SMART_SESSIONS_FALLBACK = "0x12cae64c42f362e7d5a847c2d33388373f629177";
677
+ var INTENT_EXECUTOR = "0x00000000005aD9ce1f5035FD62CA96CEf16AdAAF";
678
+ var PROXY_EXECUTOR = "0xF659d30D4EB88B06A909F20839D8959Bd77d8790";
679
+ var INTENT_SMART_SESSIONS = "0xad568b3f825a8d5ffc06dd3253526b64d810ae89";
680
+ var OWNABLE_VALIDATOR = "0x000000000013fdB5234E4E3162a810F54d9f7E98";
636
681
  var SAFE_7579_ADDRESS = "0x7579EE8307284F293B1927136486880611F20002";
637
682
  var ERC7579_LAUNCHPAD_ADDRESS = "0x7579011aB74c46090561ea277Ba79D510c6C00ff";
683
+ var POOL_MODULE_ADDRESSES = [
684
+ SMART_SESSIONS_VALIDATOR,
685
+ SMART_SESSIONS_FALLBACK,
686
+ INTENT_EXECUTOR,
687
+ PROXY_EXECUTOR,
688
+ INTENT_SMART_SESSIONS,
689
+ OWNABLE_VALIDATOR
690
+ ];
691
+
692
+ // src/utils/safe-account.ts
693
+ var SAFE_7579_ADDRESS2 = "0x7579EE8307284F293B1927136486880611F20002";
694
+ var ERC7579_LAUNCHPAD_ADDRESS2 = "0x7579011aB74c46090561ea277Ba79D510c6C00ff";
638
695
  var ACCOUNT_SALT = "zyfai";
639
696
  var getSafeAccount = async (config) => {
640
697
  const { safeOwnerAddress, publicClient } = config;
@@ -659,8 +716,8 @@ var getSafeAccount = async (config) => {
659
716
  address: import_account_abstraction.entryPoint07Address,
660
717
  version: "0.7"
661
718
  },
662
- safe4337ModuleAddress: SAFE_7579_ADDRESS,
663
- erc7579LaunchpadAddress: ERC7579_LAUNCHPAD_ADDRESS,
719
+ safe4337ModuleAddress: SAFE_7579_ADDRESS2,
720
+ erc7579LaunchpadAddress: ERC7579_LAUNCHPAD_ADDRESS2,
664
721
  attesters: [import_module_sdk.RHINESTONE_ATTESTER_ADDRESS],
665
722
  attestersThreshold: 1,
666
723
  validators: [
@@ -692,6 +749,31 @@ var isSafeDeployed = async (address, publicClient) => {
692
749
  return false;
693
750
  }
694
751
  };
752
+ var isOwnableValidatorOwner = async (safeAddress, userAddress, publicClient) => {
753
+ const normalizedUser = (0, import_viem3.getAddress)(userAddress);
754
+ const normalizedSafe = (0, import_viem3.getAddress)(safeAddress);
755
+ const validatorAddresses = Array.from(
756
+ /* @__PURE__ */ new Set([
757
+ (0, import_viem3.getAddress)(OWNABLE_VALIDATOR),
758
+ (0, import_viem3.getAddress)(import_module_sdk.OWNABLE_VALIDATOR_ADDRESS)
759
+ ])
760
+ );
761
+ for (const validatorAddress of validatorAddresses) {
762
+ try {
763
+ const owners = await publicClient.readContract({
764
+ address: validatorAddress,
765
+ abi: OWNABLE_VALIDATOR_ABI,
766
+ functionName: "getOwners",
767
+ args: [normalizedSafe]
768
+ });
769
+ if (owners.some((owner) => (0, import_viem3.getAddress)(owner) === normalizedUser)) {
770
+ return true;
771
+ }
772
+ } catch {
773
+ }
774
+ }
775
+ return false;
776
+ };
695
777
  var getAccountType = async (address, publicClient) => {
696
778
  try {
697
779
  const code = await publicClient.getCode({ address });
@@ -734,10 +816,12 @@ var deploySafeAccount = async (config) => {
734
816
  "Wallet not connected. Please connect your wallet first."
735
817
  );
736
818
  }
819
+ console.log("strategy", strategy);
737
820
  const prepareResponse = await httpClient.post(
738
821
  `${ENDPOINTS.SAFE_DEPLOY}?chainId=${chainId}`,
739
822
  { strategy }
740
823
  );
824
+ console.log("prepareResponse", prepareResponse);
741
825
  if (!prepareResponse.userOpHashToSign) {
742
826
  throw new Error(
743
827
  "Backend did not return userOpHashToSign. Response: " + JSON.stringify(prepareResponse)
@@ -883,7 +967,12 @@ function convertAssetInternally(asset) {
883
967
  if (asset === "WETH") {
884
968
  return "eth";
885
969
  }
886
- throw new Error(`Invalid asset: ${asset}. Must be "USDC" or "WETH".`);
970
+ if (asset === "EURC") {
971
+ return "eurc";
972
+ }
973
+ throw new Error(
974
+ `Invalid asset: ${asset}. Must be "USDC", "WETH", or "EURC".`
975
+ );
887
976
  }
888
977
  function convertStrategiesToPublic(array) {
889
978
  return array.map((item) => convertStrategyToPublic(item));
@@ -963,6 +1052,8 @@ var _ZyfaiSDK = class _ZyfaiSDK {
963
1052
  this.walletClient = null;
964
1053
  this.authenticatedUserId = null;
965
1054
  this.hasActiveSessionKey = false;
1055
+ this.isPredeployed = false;
1056
+ this.connectedSmartWallet = null;
966
1057
  this.currentProvider = null;
967
1058
  this.currentChainId = null;
968
1059
  const sdkConfig = typeof config === "string" ? { apiKey: config } : config;
@@ -974,6 +1065,15 @@ var _ZyfaiSDK = class _ZyfaiSDK {
974
1065
  this.rpcUrls = rpcUrls;
975
1066
  this.referralSource = referralSource;
976
1067
  }
1068
+ /**
1069
+ * Warn that a legacy method is deprecated in favor of depositFunds.
1070
+ * Predeployed wallets no longer require deploySafe / createSessionKey.
1071
+ */
1072
+ warnDeprecatedOnboardingMethod(methodName) {
1073
+ console.warn(
1074
+ `[ZyfaiSDK] ${methodName}() is deprecated for partner integrations. Prefer depositFunds() \u2014 predeployed Safes and session keys are handled automatically on first deposit.`
1075
+ );
1076
+ }
977
1077
  /**
978
1078
  * Authenticate user with SIWE (Sign-In with Ethereum) & JWT token
979
1079
  * This is required for accessing user-specific endpoints like session-keys/config
@@ -1036,7 +1136,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1036
1136
  }
1037
1137
  this.httpClient.setAuthToken(authToken);
1038
1138
  this.authenticatedUserId = loginResponse.userId || null;
1139
+ console.log("this.authenticatedUserId", loginResponse);
1039
1140
  this.hasActiveSessionKey = loginResponse.hasActiveSessionKey || false;
1141
+ this.isPredeployed = loginResponse.predeployed || false;
1142
+ this.connectedSmartWallet = loginResponse.smartWallet || null;
1040
1143
  } catch (error) {
1041
1144
  throw new Error(
1042
1145
  `Failed to authenticate user: ${error.message}`
@@ -1125,10 +1228,14 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1125
1228
  asset: "USDC",
1126
1229
  protocols: []
1127
1230
  });
1128
- const response = await this.updateUserProfile({
1231
+ await this.updateUserProfile({
1129
1232
  asset: "WETH",
1130
1233
  protocols: []
1131
1234
  });
1235
+ const response = await this.updateUserProfile({
1236
+ asset: "EURC",
1237
+ protocols: []
1238
+ });
1132
1239
  return response;
1133
1240
  } catch (error) {
1134
1241
  throw new Error(`Failed to pause agent: ${error.message}`);
@@ -1156,16 +1263,19 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1156
1263
  try {
1157
1264
  const userDetailsUSDC = await this.getUserDetails("USDC");
1158
1265
  const userDetailsETH = await this.getUserDetails("WETH");
1266
+ const userDetailsEURC = await this.getUserDetails("EURC");
1159
1267
  const chains = userDetailsUSDC.chains && userDetailsUSDC.chains.length > 0 ? userDetailsUSDC.chains : [8453, 42161];
1268
+ const eurcChains = userDetailsEURC.chains && userDetailsEURC.chains.length > 0 ? userDetailsEURC.chains.filter((c) => c === 1 || c === 8453) : [1, 8453];
1160
1269
  const allProtocols = await this.httpClient.get(
1161
1270
  ENDPOINTS.PROTOCOLS()
1162
1271
  );
1163
1272
  const usdcStrategy = userDetailsUSDC.strategy || "safe_strategy";
1164
1273
  const ethStrategy = userDetailsETH.strategy || "safe_strategy";
1165
- const filterProtocolsByStrategy = (strategy) => {
1274
+ const eurcStrategy = userDetailsEURC.strategy || "safe_strategy";
1275
+ const filterProtocolsByStrategy = (strategy, selectedChains) => {
1166
1276
  return allProtocols.filter((protocol) => {
1167
1277
  const hasMatchingChain = protocol.chains.some(
1168
- (chain) => chains.includes(chain)
1278
+ (chain) => selectedChains.includes(chain)
1169
1279
  );
1170
1280
  if (!hasMatchingChain) {
1171
1281
  return false;
@@ -1176,17 +1286,21 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1176
1286
  return protocol.strategies?.includes("safe_strategy");
1177
1287
  }).map((protocol) => protocol.id);
1178
1288
  };
1179
- const usdcProtocols = filterProtocolsByStrategy(usdcStrategy);
1180
- const ethProtocols = filterProtocolsByStrategy(ethStrategy);
1289
+ const usdcProtocols = filterProtocolsByStrategy(usdcStrategy, chains);
1290
+ const ethProtocols = filterProtocolsByStrategy(ethStrategy, chains);
1291
+ const eurcProtocols = filterProtocolsByStrategy(eurcStrategy, eurcChains);
1181
1292
  await this.updateUserProfile({
1182
1293
  asset: "USDC",
1183
1294
  protocols: usdcProtocols
1184
1295
  });
1185
- const updatedUserDetailsETH = await this.updateUserProfile({
1296
+ await this.updateUserProfile({
1186
1297
  asset: "WETH",
1187
1298
  protocols: ethProtocols
1188
1299
  });
1189
- return updatedUserDetailsETH;
1300
+ return await this.updateUserProfile({
1301
+ asset: "EURC",
1302
+ protocols: eurcProtocols
1303
+ });
1190
1304
  } catch (error) {
1191
1305
  throw new Error(`Failed to resume agent: ${error.message}`);
1192
1306
  }
@@ -1379,6 +1493,8 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1379
1493
  throw new Error(`Unsupported chain ID: ${chainId}`);
1380
1494
  }
1381
1495
  this.authenticatedUserId = null;
1496
+ this.isPredeployed = false;
1497
+ this.connectedSmartWallet = null;
1382
1498
  this.currentChainId = null;
1383
1499
  this.httpClient.clearAuthToken();
1384
1500
  if (this.currentProvider?.removeAllListeners) {
@@ -1469,6 +1585,8 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1469
1585
  this.currentChainId = null;
1470
1586
  this.authenticatedUserId = null;
1471
1587
  this.hasActiveSessionKey = false;
1588
+ this.isPredeployed = false;
1589
+ this.connectedSmartWallet = null;
1472
1590
  this.httpClient.clearAuthToken();
1473
1591
  }
1474
1592
  /**
@@ -1494,13 +1612,58 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1494
1612
  return this.walletClient;
1495
1613
  }
1496
1614
  }
1615
+ /**
1616
+ * True when userAddress is the currently connected/authenticated wallet.
1617
+ * @private
1618
+ */
1619
+ isConnectedUser(userAddress) {
1620
+ const connected = this.signer?.address ?? this.walletClient?.account?.address;
1621
+ return !!connected && connected.toLowerCase() === userAddress.toLowerCase();
1622
+ }
1623
+ /**
1624
+ * Resolve the Safe smart wallet address for a user on a chain.
1625
+ *
1626
+ * Predeployed (pool) wallets are provisioned and owned by the backend at
1627
+ * deploy time, so their address CANNOT be derived from the user's EOA with
1628
+ * getDeterministicSafeAddress (CREATE2 from the EOA yields the wrong address).
1629
+ * For the connected predeployed user we always use the backend-assigned
1630
+ * address. Legacy wallets keep the API-first, deterministic-fallback behavior.
1631
+ * @private
1632
+ */
1633
+ async getSafeAddressFor(userAddress, chainId) {
1634
+ if (this.isPredeployed && this.isConnectedUser(userAddress)) {
1635
+ if (this.connectedSmartWallet) return this.connectedSmartWallet;
1636
+ try {
1637
+ const info = await this.getSmartWalletByEOA(userAddress);
1638
+ if (info.smartWallet) return info.smartWallet;
1639
+ } catch {
1640
+ }
1641
+ throw new Error(
1642
+ "Predeployed smart wallet address is not available from the API yet. Ensure the user has signed in so the pool can reserve their wallet."
1643
+ );
1644
+ }
1645
+ try {
1646
+ const info = await this.getSmartWalletByEOA(userAddress);
1647
+ if (info.smartWallet) return info.smartWallet;
1648
+ } catch {
1649
+ }
1650
+ const chainConfig = getChainConfig(chainId, this.rpcUrls);
1651
+ return getDeterministicSafeAddress({
1652
+ safeOwnerAddress: userAddress,
1653
+ chain: chainConfig.chain,
1654
+ publicClient: chainConfig.publicClient
1655
+ });
1656
+ }
1497
1657
  /**
1498
1658
  * Get smart wallet address for a user
1499
- * Returns the deterministic Safe address for an EOA, or the address itself if already a Safe
1659
+ * Returns the Safe address for an EOA (deterministic for legacy wallets,
1660
+ * backend-assigned for predeployed pool wallets).
1500
1661
  *
1501
1662
  * @param userAddress - User's EOA address
1502
1663
  * @param chainId - Target chain ID
1503
- * @returns Smart wallet information including address and deployment status
1664
+ * @returns Smart wallet address, deployment status, and whether userAddress
1665
+ * is an on-chain OwnableValidator owner (false for reserved predeployed
1666
+ * wallets until the first deposit rotates ownership)
1504
1667
  */
1505
1668
  async getSmartWalletAddress(userAddress, chainId) {
1506
1669
  if (!userAddress) {
@@ -1510,37 +1673,29 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1510
1673
  throw new Error(`Unsupported chain ID: ${chainId}`);
1511
1674
  }
1512
1675
  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
- });
1676
+ const safeAddress = await this.getSafeAddressFor(userAddress, chainId);
1532
1677
  const isDeployed = await isSafeDeployed(
1533
1678
  safeAddress,
1534
1679
  chainConfig.publicClient
1535
1680
  );
1681
+ const isOwner = isDeployed ? await isOwnableValidatorOwner(
1682
+ safeAddress,
1683
+ userAddress,
1684
+ chainConfig.publicClient
1685
+ ) : false;
1536
1686
  return {
1537
1687
  address: safeAddress,
1538
- isDeployed
1688
+ isDeployed,
1689
+ isOwner
1539
1690
  };
1540
1691
  }
1541
1692
  /**
1542
1693
  * Deploy Safe Smart Wallet for a user
1543
1694
  *
1695
+ * @deprecated Prefer `depositFunds()`. Predeployed Safes and session keys are
1696
+ * managed automatically on first deposit. This method remains available for
1697
+ * legacy flows.
1698
+ *
1544
1699
  * @param userAddress - User's EOA address (the connected EOA, not the smart wallet address)
1545
1700
  * @param chainId - Target chain ID
1546
1701
  * @param strategy - Optional strategy selection: "conservative" (default) or "aggressive"
@@ -1549,17 +1704,15 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1549
1704
  *
1550
1705
  * @example
1551
1706
  * ```typescript
1552
- * // Deploy with default conservative strategy
1553
- * await sdk.deploySafe(userAddress, 8453);
1554
- *
1555
- * // Deploy with aggressive strategy
1556
- * await sdk.deploySafe(userAddress, 8453, "aggressive");
1707
+ * // Preferred: depositFunds handles predeployed wallet onboarding
1708
+ * await sdk.depositFunds(userAddress, 8453, amount, "USDC");
1557
1709
  *
1558
- * // Deploy and automatically create session key
1559
- * await sdk.deploySafe(userAddress, 8453, "conservative", true);
1710
+ * // Legacy: deploy with default conservative strategy
1711
+ * await sdk.deploySafe(userAddress, 8453);
1560
1712
  * ```
1561
1713
  */
1562
1714
  async deploySafe(userAddress, chainId, strategy, createSessionKey) {
1715
+ this.warnDeprecatedOnboardingMethod("deploySafe");
1563
1716
  try {
1564
1717
  if (!userAddress) {
1565
1718
  throw new Error("User address is required");
@@ -1568,6 +1721,20 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1568
1721
  throw new Error(`Unsupported chain ID: ${chainId}`);
1569
1722
  }
1570
1723
  await this.authenticateUser();
1724
+ if (this.isPredeployed && this.isConnectedUser(userAddress)) {
1725
+ const predeployedAddress = await this.getSafeAddressFor(
1726
+ userAddress,
1727
+ chainId
1728
+ );
1729
+ await this.updateUserProtocols(strategy);
1730
+ return {
1731
+ success: true,
1732
+ safeAddress: predeployedAddress,
1733
+ txHash: "0x0",
1734
+ status: "deployed",
1735
+ sessionKeyCreated: true
1736
+ };
1737
+ }
1571
1738
  const walletClient = this.getWalletClient(chainId);
1572
1739
  const chainConfig = getChainConfig(chainId, this.rpcUrls);
1573
1740
  const safeAddress = await getDeterministicSafeAddress({
@@ -1580,7 +1747,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1580
1747
  chainConfig.publicClient
1581
1748
  );
1582
1749
  if (alreadyDeployed) {
1583
- await this.updateUserProtocols(chainId, strategy);
1750
+ await this.updateUserProtocols(strategy);
1584
1751
  let sessionKeyCreated2 = false;
1585
1752
  if (createSessionKey) {
1586
1753
  try {
@@ -1620,7 +1787,6 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1620
1787
  initError.message
1621
1788
  );
1622
1789
  }
1623
- await this.updateUserProtocols(chainId, strategy);
1624
1790
  let sessionKeyCreated = false;
1625
1791
  if (createSessionKey) {
1626
1792
  try {
@@ -1642,25 +1808,34 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1642
1808
  };
1643
1809
  } catch (error) {
1644
1810
  console.error("Safe deployment failed:", error);
1645
- throw new Error(`Safe deployment failed: ${error.message}`);
1811
+ throw new Error(
1812
+ `Safe deployment failed: ${error.message}. deploySafe() is deprecated \u2014 prefer depositFunds() for predeployed wallet onboarding.`
1813
+ );
1646
1814
  }
1647
1815
  }
1648
1816
  /**
1649
1817
  * Create session key with auto-fetched configuration from Zyfai API
1650
1818
  * This is the simplified method that automatically fetches session configuration
1651
1819
  *
1820
+ * @deprecated Prefer `depositFunds()`. Predeployed wallets already have the
1821
+ * agent session enabled; session activation is handled after first deposit.
1822
+ * This method remains available for legacy flows.
1823
+ *
1652
1824
  * @param userAddress - User's EOA or Safe address
1653
1825
  * @param chainId - Target chain ID
1654
1826
  * @returns Session key response with signature and nonces
1655
1827
  *
1656
1828
  * @example
1657
1829
  * ```typescript
1658
- * // Simple usage - no need to configure sessions manually
1830
+ * // Preferred: depositFunds handles session onboarding for predeployed wallets
1831
+ * await sdk.depositFunds(userAddress, 8453, amount, "USDC");
1832
+ *
1833
+ * // Legacy:
1659
1834
  * const result = await sdk.createSessionKey(userAddress, 8453);
1660
- * console.log("Session created:", result.signature);
1661
1835
  * ```
1662
1836
  */
1663
1837
  async createSessionKey(userAddress, chainId) {
1838
+ this.warnDeprecatedOnboardingMethod("createSessionKey");
1664
1839
  try {
1665
1840
  await this.authenticateUser();
1666
1841
  if (!this.authenticatedUserId) {
@@ -1668,6 +1843,14 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1668
1843
  "User ID not available. Please ensure authentication completed successfully."
1669
1844
  );
1670
1845
  }
1846
+ if (this.isPredeployed) {
1847
+ return {
1848
+ success: true,
1849
+ userId: this.authenticatedUserId,
1850
+ message: "Predeployed wallet: agent session is managed by the backend",
1851
+ alreadyActive: true
1852
+ };
1853
+ }
1671
1854
  if (this.hasActiveSessionKey) {
1672
1855
  return {
1673
1856
  success: true,
@@ -1726,7 +1909,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1726
1909
  };
1727
1910
  } catch (error) {
1728
1911
  throw new Error(
1729
- `Failed to create session key: ${error.message}`
1912
+ `Failed to create session key: ${error.message}. createSessionKey() is deprecated \u2014 prefer depositFunds() for predeployed wallet onboarding.`
1730
1913
  );
1731
1914
  }
1732
1915
  }
@@ -1783,29 +1966,33 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1783
1966
  }
1784
1967
  }
1785
1968
  /**
1786
- * Patch the user's protocol selection for the given chain + strategy on
1787
- * both USDC and WETH. Mirrors the front-end customization flow:
1788
- * 1. Merge existing chains from `getUserDetails` with the new `chainId`
1969
+ * Patch the user's protocol selection on USDC, WETH, and EURC across all
1970
+ * supported chains (EURC limited to Mainnet/Base). Mirrors the front-end
1971
+ * customization flow:
1972
+ * 1. Merge existing chains from `getUserDetails` with the target chains
1789
1973
  * (never overwrite already-configured chains).
1790
1974
  * 2. Filter protocols by strategy, chain and asset support.
1791
1975
  * 3. Drop protocols that don't have any pools available for the
1792
1976
  * asset/chain/strategy combo.
1793
1977
  * 4. Persist via `updateUserProfile` (writes `assetTypeSettings`).
1794
1978
  *
1795
- * Called from `deploySafe` — SDK consumers don't handle protocols manually.
1979
+ * Called once from `depositFunds` on the account's first deposit.
1796
1980
  *
1797
1981
  * @internal
1798
1982
  */
1799
- async updateUserProtocols(chainId, strategy) {
1983
+ async updateUserProtocols(strategy) {
1800
1984
  try {
1801
1985
  const allProtocols = await this.httpClient.get(
1802
1986
  ENDPOINTS.PROTOCOLS()
1803
1987
  );
1804
- for (const asset of ["USDC", "WETH"]) {
1988
+ const allChains = [1, 8453, 42161];
1989
+ const assets = ["USDC", "WETH", "EURC"];
1990
+ for (const asset of assets) {
1805
1991
  try {
1992
+ const chainsForAsset = asset === "EURC" ? [1, 8453] : allChains;
1806
1993
  await this.updateUserProtocolsForAsset(
1807
1994
  asset,
1808
- chainId,
1995
+ chainsForAsset,
1809
1996
  strategy,
1810
1997
  allProtocols
1811
1998
  );
@@ -1825,11 +2012,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1825
2012
  * Compute and persist the protocol selection for a single asset.
1826
2013
  * @internal
1827
2014
  */
1828
- async updateUserProtocolsForAsset(asset, chainId, strategy, allProtocols) {
2015
+ async updateUserProtocolsForAsset(asset, chains, strategy, allProtocols) {
1829
2016
  const userDetails = await this.getUserDetails(asset);
1830
2017
  const existingChains = userDetails.chains ?? [];
1831
2018
  const effectiveChains = Array.from(
1832
- /* @__PURE__ */ new Set([...existingChains, chainId])
2019
+ /* @__PURE__ */ new Set([...existingChains, ...chains])
1833
2020
  );
1834
2021
  const publicStrategy = strategy ?? (isValidPublicStrategy(userDetails.strategy ?? "") ? userDetails.strategy : "conservative");
1835
2022
  const internalStrategy = toInternalStrategy(publicStrategy);
@@ -1844,7 +2031,6 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1844
2031
  effectiveChains,
1845
2032
  asset
1846
2033
  );
1847
- console.log("withPools", withPools, "effectiveChains", effectiveChains, "asset", asset);
1848
2034
  await this.updateUserProfile({
1849
2035
  asset,
1850
2036
  protocols: withPools,
@@ -1911,6 +2097,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1911
2097
  * Token is automatically selected based on chain (USDC by default):
1912
2098
  * - Ethereum Mainnet (1), Base (8453), Arbitrum (42161)
1913
2099
  *
2100
+ * On the account's first deposit (USDC profile has no chains yet), patches
2101
+ * protocol selection for USDC, WETH, and EURC across all supported chains
2102
+ * (EURC on Mainnet/Base only) before the transfer and log_deposit.
2103
+ *
1914
2104
  * Minimum portfolio balance enforced (Safe balance + deposit amount),
1915
2105
  * configured per-chain in `MIN_PORTFOLIO_BALANCE`:
1916
2106
  * - Ethereum Mainnet (1): 5 USDC (test threshold)
@@ -1922,7 +2112,8 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1922
2112
  * @param userAddress - User's address (owner of the Safe)
1923
2113
  * @param chainId - Target chain ID
1924
2114
  * @param amount - Amount in least decimal units (e.g., "100000000" for 100 USDC with 6 decimals)
1925
- * @param asset - Optional asset symbol ("USDC" or "WETH"). Defaults to "USDC".
2115
+ * @param asset - Optional asset symbol ("USDC", "WETH", or "EURC"). Defaults to "USDC".
2116
+ * EURC is supported on Ethereum Mainnet and Base only.
1926
2117
  * @returns Deposit response with transaction hash
1927
2118
  *
1928
2119
  * @example
@@ -1950,25 +2141,32 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1950
2141
  const assetConfig = ASSET_CONFIGS[assetSymbol];
1951
2142
  if (!assetConfig) {
1952
2143
  throw new Error(
1953
- `Unsupported asset: ${assetSymbol}. Supported: USDC, WETH.`
2144
+ `Unsupported asset: ${assetSymbol}. Supported: USDC, WETH, EURC.`
1954
2145
  );
1955
2146
  }
1956
2147
  const minRequired = MIN_PORTFOLIO_BALANCE[chainId]?.[assetSymbol];
1957
2148
  const token = getDefaultTokenAddress(chainId, assetSymbol);
1958
2149
  const walletClient = this.getWalletClient();
1959
2150
  const chainConfig = getChainConfig(chainId, this.rpcUrls);
1960
- const safeAddress = await getDeterministicSafeAddress({
1961
- safeOwnerAddress: userAddress,
1962
- chain: chainConfig.chain,
1963
- publicClient: chainConfig.publicClient
1964
- });
2151
+ const safeAddress = await this.getSafeAddressFor(userAddress, chainId);
1965
2152
  const isDeployed = await isSafeDeployed(
1966
2153
  safeAddress,
1967
2154
  chainConfig.publicClient
1968
2155
  );
1969
2156
  if (!isDeployed) {
1970
2157
  throw new Error(
1971
- `Safe not deployed for ${userAddress}. Please deploy the Safe first using deploySafe().`
2158
+ `Safe not available for ${userAddress} on chain ${chainId}.`
2159
+ );
2160
+ }
2161
+ try {
2162
+ const usdcDetails = await this.getUserDetails("USDC");
2163
+ if ((usdcDetails.chains?.length ?? 0) === 0) {
2164
+ await this.updateUserProtocols();
2165
+ }
2166
+ } catch (protocolError) {
2167
+ console.warn(
2168
+ "Failed to update user protocols before deposit:",
2169
+ protocolError.message
1972
2170
  );
1973
2171
  }
1974
2172
  const amountBigInt = BigInt(amount);
@@ -2003,6 +2201,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2003
2201
  hash: txHash
2004
2202
  });
2005
2203
  try {
2204
+ console.log("Logging deposit to backend", {
2205
+ chainId,
2206
+ transaction: txHash,
2207
+ token,
2208
+ amount
2209
+ });
2006
2210
  await this.httpClient.post(ENDPOINTS.LOG_DEPOSIT, {
2007
2211
  chainId,
2008
2212
  transaction: txHash,
@@ -2123,25 +2327,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2123
2327
  throw new Error(`Unsupported chain ID: ${chainId}`);
2124
2328
  }
2125
2329
  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
- }
2330
+ const safeAddress = await this.getSafeAddressFor(userAddress, chainId);
2145
2331
  const isDeployed = await isSafeDeployed(
2146
2332
  safeAddress,
2147
2333
  chainConfig.publicClient
@@ -3955,6 +4141,15 @@ function createBankrProvider(config) {
3955
4141
  // Annotate the CommonJS export names for ESM import in node:
3956
4142
  0 && (module.exports = {
3957
4143
  DEFAULT_TOKEN_ADDRESSES,
4144
+ ERC7579_LAUNCHPAD_ADDRESS,
4145
+ INTENT_EXECUTOR,
4146
+ INTENT_SMART_SESSIONS,
4147
+ OWNABLE_VALIDATOR,
4148
+ POOL_MODULE_ADDRESSES,
4149
+ PROXY_EXECUTOR,
4150
+ SAFE_7579_ADDRESS,
4151
+ SMART_SESSIONS_FALLBACK,
4152
+ SMART_SESSIONS_VALIDATOR,
3958
4153
  VAULT_ADDRESS,
3959
4154
  ZyfaiSDK,
3960
4155
  createBankrProvider,