@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.mjs CHANGED
@@ -293,6 +293,15 @@ var HttpClient = class {
293
293
 
294
294
  // src/config/abis.ts
295
295
  import { parseAbi } from "viem";
296
+ var OWNABLE_VALIDATOR_ABI = [
297
+ {
298
+ name: "getOwners",
299
+ type: "function",
300
+ stateMutability: "view",
301
+ inputs: [{ name: "account", type: "address" }],
302
+ outputs: [{ name: "ownersArray", type: "address[]" }]
303
+ }
304
+ ];
296
305
  var ERC20_ABI = [
297
306
  {
298
307
  name: "transfer",
@@ -547,6 +556,25 @@ var ASSET_CONFIGS = {
547
556
  // Linea
548
557
  },
549
558
  enabled: true
559
+ },
560
+ EURC: {
561
+ symbol: "EURC",
562
+ assetType: "eurc",
563
+ displayName: "EURC",
564
+ icon: "/ai-dashboard/eurc-token.png",
565
+ decimals: 6,
566
+ tokenSymbols: ["EURC"],
567
+ tokenSymbolsByChainId: {
568
+ 1: "EURC",
569
+ 8453: "EURC"
570
+ },
571
+ addresses: {
572
+ 1: "0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c",
573
+ // Ethereum
574
+ 8453: "0x60a3E35Cc302bFA44Cb288Bc5a4F316Fdb1adb42"
575
+ // Base
576
+ },
577
+ enabled: true
550
578
  }
551
579
  };
552
580
  var getDefaultTokenAddress = (chainId, asset) => {
@@ -594,6 +622,7 @@ var getSupportedChainIds = () => {
594
622
  // src/utils/safe-account.ts
595
623
  import {
596
624
  RHINESTONE_ATTESTER_ADDRESS,
625
+ OWNABLE_VALIDATOR_ADDRESS,
597
626
  getOwnableValidator,
598
627
  getAccount,
599
628
  getEnableSessionDetails,
@@ -609,8 +638,28 @@ import {
609
638
  import {
610
639
  entryPoint07Address
611
640
  } from "viem/account-abstraction";
641
+
642
+ // src/config/modules.ts
643
+ var SMART_SESSIONS_VALIDATOR = "0x00000000008bDABA73cD9815d79069c247Eb4bDA";
644
+ var SMART_SESSIONS_FALLBACK = "0x12cae64c42f362e7d5a847c2d33388373f629177";
645
+ var INTENT_EXECUTOR = "0x00000000005aD9ce1f5035FD62CA96CEf16AdAAF";
646
+ var PROXY_EXECUTOR = "0xF659d30D4EB88B06A909F20839D8959Bd77d8790";
647
+ var INTENT_SMART_SESSIONS = "0xad568b3f825a8d5ffc06dd3253526b64d810ae89";
648
+ var OWNABLE_VALIDATOR = "0x000000000013fdB5234E4E3162a810F54d9f7E98";
612
649
  var SAFE_7579_ADDRESS = "0x7579EE8307284F293B1927136486880611F20002";
613
650
  var ERC7579_LAUNCHPAD_ADDRESS = "0x7579011aB74c46090561ea277Ba79D510c6C00ff";
651
+ var POOL_MODULE_ADDRESSES = [
652
+ SMART_SESSIONS_VALIDATOR,
653
+ SMART_SESSIONS_FALLBACK,
654
+ INTENT_EXECUTOR,
655
+ PROXY_EXECUTOR,
656
+ INTENT_SMART_SESSIONS,
657
+ OWNABLE_VALIDATOR
658
+ ];
659
+
660
+ // src/utils/safe-account.ts
661
+ var SAFE_7579_ADDRESS2 = "0x7579EE8307284F293B1927136486880611F20002";
662
+ var ERC7579_LAUNCHPAD_ADDRESS2 = "0x7579011aB74c46090561ea277Ba79D510c6C00ff";
614
663
  var ACCOUNT_SALT = "zyfai";
615
664
  var getSafeAccount = async (config) => {
616
665
  const { safeOwnerAddress, publicClient } = config;
@@ -635,8 +684,8 @@ var getSafeAccount = async (config) => {
635
684
  address: entryPoint07Address,
636
685
  version: "0.7"
637
686
  },
638
- safe4337ModuleAddress: SAFE_7579_ADDRESS,
639
- erc7579LaunchpadAddress: ERC7579_LAUNCHPAD_ADDRESS,
687
+ safe4337ModuleAddress: SAFE_7579_ADDRESS2,
688
+ erc7579LaunchpadAddress: ERC7579_LAUNCHPAD_ADDRESS2,
640
689
  attesters: [RHINESTONE_ATTESTER_ADDRESS],
641
690
  attestersThreshold: 1,
642
691
  validators: [
@@ -668,6 +717,31 @@ var isSafeDeployed = async (address, publicClient) => {
668
717
  return false;
669
718
  }
670
719
  };
720
+ var isOwnableValidatorOwner = async (safeAddress, userAddress, publicClient) => {
721
+ const normalizedUser = getAddress(userAddress);
722
+ const normalizedSafe = getAddress(safeAddress);
723
+ const validatorAddresses = Array.from(
724
+ /* @__PURE__ */ new Set([
725
+ getAddress(OWNABLE_VALIDATOR),
726
+ getAddress(OWNABLE_VALIDATOR_ADDRESS)
727
+ ])
728
+ );
729
+ for (const validatorAddress of validatorAddresses) {
730
+ try {
731
+ const owners = await publicClient.readContract({
732
+ address: validatorAddress,
733
+ abi: OWNABLE_VALIDATOR_ABI,
734
+ functionName: "getOwners",
735
+ args: [normalizedSafe]
736
+ });
737
+ if (owners.some((owner) => getAddress(owner) === normalizedUser)) {
738
+ return true;
739
+ }
740
+ } catch {
741
+ }
742
+ }
743
+ return false;
744
+ };
671
745
  var getAccountType = async (address, publicClient) => {
672
746
  try {
673
747
  const code = await publicClient.getCode({ address });
@@ -710,10 +784,12 @@ var deploySafeAccount = async (config) => {
710
784
  "Wallet not connected. Please connect your wallet first."
711
785
  );
712
786
  }
787
+ console.log("strategy", strategy);
713
788
  const prepareResponse = await httpClient.post(
714
789
  `${ENDPOINTS.SAFE_DEPLOY}?chainId=${chainId}`,
715
790
  { strategy }
716
791
  );
792
+ console.log("prepareResponse", prepareResponse);
717
793
  if (!prepareResponse.userOpHashToSign) {
718
794
  throw new Error(
719
795
  "Backend did not return userOpHashToSign. Response: " + JSON.stringify(prepareResponse)
@@ -859,7 +935,12 @@ function convertAssetInternally(asset) {
859
935
  if (asset === "WETH") {
860
936
  return "eth";
861
937
  }
862
- throw new Error(`Invalid asset: ${asset}. Must be "USDC" or "WETH".`);
938
+ if (asset === "EURC") {
939
+ return "eurc";
940
+ }
941
+ throw new Error(
942
+ `Invalid asset: ${asset}. Must be "USDC", "WETH", or "EURC".`
943
+ );
863
944
  }
864
945
  function convertStrategiesToPublic(array) {
865
946
  return array.map((item) => convertStrategyToPublic(item));
@@ -939,6 +1020,8 @@ var _ZyfaiSDK = class _ZyfaiSDK {
939
1020
  this.walletClient = null;
940
1021
  this.authenticatedUserId = null;
941
1022
  this.hasActiveSessionKey = false;
1023
+ this.isPredeployed = false;
1024
+ this.connectedSmartWallet = null;
942
1025
  this.currentProvider = null;
943
1026
  this.currentChainId = null;
944
1027
  const sdkConfig = typeof config === "string" ? { apiKey: config } : config;
@@ -950,6 +1033,15 @@ var _ZyfaiSDK = class _ZyfaiSDK {
950
1033
  this.rpcUrls = rpcUrls;
951
1034
  this.referralSource = referralSource;
952
1035
  }
1036
+ /**
1037
+ * Warn that a legacy method is deprecated in favor of depositFunds.
1038
+ * Predeployed wallets no longer require deploySafe / createSessionKey.
1039
+ */
1040
+ warnDeprecatedOnboardingMethod(methodName) {
1041
+ console.warn(
1042
+ `[ZyfaiSDK] ${methodName}() is deprecated for partner integrations. Prefer depositFunds() \u2014 predeployed Safes and session keys are handled automatically on first deposit.`
1043
+ );
1044
+ }
953
1045
  /**
954
1046
  * Authenticate user with SIWE (Sign-In with Ethereum) & JWT token
955
1047
  * This is required for accessing user-specific endpoints like session-keys/config
@@ -1012,7 +1104,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1012
1104
  }
1013
1105
  this.httpClient.setAuthToken(authToken);
1014
1106
  this.authenticatedUserId = loginResponse.userId || null;
1107
+ console.log("this.authenticatedUserId", loginResponse);
1015
1108
  this.hasActiveSessionKey = loginResponse.hasActiveSessionKey || false;
1109
+ this.isPredeployed = loginResponse.predeployed || false;
1110
+ this.connectedSmartWallet = loginResponse.smartWallet || null;
1016
1111
  } catch (error) {
1017
1112
  throw new Error(
1018
1113
  `Failed to authenticate user: ${error.message}`
@@ -1101,10 +1196,14 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1101
1196
  asset: "USDC",
1102
1197
  protocols: []
1103
1198
  });
1104
- const response = await this.updateUserProfile({
1199
+ await this.updateUserProfile({
1105
1200
  asset: "WETH",
1106
1201
  protocols: []
1107
1202
  });
1203
+ const response = await this.updateUserProfile({
1204
+ asset: "EURC",
1205
+ protocols: []
1206
+ });
1108
1207
  return response;
1109
1208
  } catch (error) {
1110
1209
  throw new Error(`Failed to pause agent: ${error.message}`);
@@ -1132,16 +1231,19 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1132
1231
  try {
1133
1232
  const userDetailsUSDC = await this.getUserDetails("USDC");
1134
1233
  const userDetailsETH = await this.getUserDetails("WETH");
1234
+ const userDetailsEURC = await this.getUserDetails("EURC");
1135
1235
  const chains = userDetailsUSDC.chains && userDetailsUSDC.chains.length > 0 ? userDetailsUSDC.chains : [8453, 42161];
1236
+ const eurcChains = userDetailsEURC.chains && userDetailsEURC.chains.length > 0 ? userDetailsEURC.chains.filter((c) => c === 1 || c === 8453) : [1, 8453];
1136
1237
  const allProtocols = await this.httpClient.get(
1137
1238
  ENDPOINTS.PROTOCOLS()
1138
1239
  );
1139
1240
  const usdcStrategy = userDetailsUSDC.strategy || "safe_strategy";
1140
1241
  const ethStrategy = userDetailsETH.strategy || "safe_strategy";
1141
- const filterProtocolsByStrategy = (strategy) => {
1242
+ const eurcStrategy = userDetailsEURC.strategy || "safe_strategy";
1243
+ const filterProtocolsByStrategy = (strategy, selectedChains) => {
1142
1244
  return allProtocols.filter((protocol) => {
1143
1245
  const hasMatchingChain = protocol.chains.some(
1144
- (chain) => chains.includes(chain)
1246
+ (chain) => selectedChains.includes(chain)
1145
1247
  );
1146
1248
  if (!hasMatchingChain) {
1147
1249
  return false;
@@ -1152,17 +1254,21 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1152
1254
  return protocol.strategies?.includes("safe_strategy");
1153
1255
  }).map((protocol) => protocol.id);
1154
1256
  };
1155
- const usdcProtocols = filterProtocolsByStrategy(usdcStrategy);
1156
- const ethProtocols = filterProtocolsByStrategy(ethStrategy);
1257
+ const usdcProtocols = filterProtocolsByStrategy(usdcStrategy, chains);
1258
+ const ethProtocols = filterProtocolsByStrategy(ethStrategy, chains);
1259
+ const eurcProtocols = filterProtocolsByStrategy(eurcStrategy, eurcChains);
1157
1260
  await this.updateUserProfile({
1158
1261
  asset: "USDC",
1159
1262
  protocols: usdcProtocols
1160
1263
  });
1161
- const updatedUserDetailsETH = await this.updateUserProfile({
1264
+ await this.updateUserProfile({
1162
1265
  asset: "WETH",
1163
1266
  protocols: ethProtocols
1164
1267
  });
1165
- return updatedUserDetailsETH;
1268
+ return await this.updateUserProfile({
1269
+ asset: "EURC",
1270
+ protocols: eurcProtocols
1271
+ });
1166
1272
  } catch (error) {
1167
1273
  throw new Error(`Failed to resume agent: ${error.message}`);
1168
1274
  }
@@ -1355,6 +1461,8 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1355
1461
  throw new Error(`Unsupported chain ID: ${chainId}`);
1356
1462
  }
1357
1463
  this.authenticatedUserId = null;
1464
+ this.isPredeployed = false;
1465
+ this.connectedSmartWallet = null;
1358
1466
  this.currentChainId = null;
1359
1467
  this.httpClient.clearAuthToken();
1360
1468
  if (this.currentProvider?.removeAllListeners) {
@@ -1445,6 +1553,8 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1445
1553
  this.currentChainId = null;
1446
1554
  this.authenticatedUserId = null;
1447
1555
  this.hasActiveSessionKey = false;
1556
+ this.isPredeployed = false;
1557
+ this.connectedSmartWallet = null;
1448
1558
  this.httpClient.clearAuthToken();
1449
1559
  }
1450
1560
  /**
@@ -1470,13 +1580,58 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1470
1580
  return this.walletClient;
1471
1581
  }
1472
1582
  }
1583
+ /**
1584
+ * True when userAddress is the currently connected/authenticated wallet.
1585
+ * @private
1586
+ */
1587
+ isConnectedUser(userAddress) {
1588
+ const connected = this.signer?.address ?? this.walletClient?.account?.address;
1589
+ return !!connected && connected.toLowerCase() === userAddress.toLowerCase();
1590
+ }
1591
+ /**
1592
+ * Resolve the Safe smart wallet address for a user on a chain.
1593
+ *
1594
+ * Predeployed (pool) wallets are provisioned and owned by the backend at
1595
+ * deploy time, so their address CANNOT be derived from the user's EOA with
1596
+ * getDeterministicSafeAddress (CREATE2 from the EOA yields the wrong address).
1597
+ * For the connected predeployed user we always use the backend-assigned
1598
+ * address. Legacy wallets keep the API-first, deterministic-fallback behavior.
1599
+ * @private
1600
+ */
1601
+ async getSafeAddressFor(userAddress, chainId) {
1602
+ if (this.isPredeployed && this.isConnectedUser(userAddress)) {
1603
+ if (this.connectedSmartWallet) return this.connectedSmartWallet;
1604
+ try {
1605
+ const info = await this.getSmartWalletByEOA(userAddress);
1606
+ if (info.smartWallet) return info.smartWallet;
1607
+ } catch {
1608
+ }
1609
+ throw new Error(
1610
+ "Predeployed smart wallet address is not available from the API yet. Ensure the user has signed in so the pool can reserve their wallet."
1611
+ );
1612
+ }
1613
+ try {
1614
+ const info = await this.getSmartWalletByEOA(userAddress);
1615
+ if (info.smartWallet) return info.smartWallet;
1616
+ } catch {
1617
+ }
1618
+ const chainConfig = getChainConfig(chainId, this.rpcUrls);
1619
+ return getDeterministicSafeAddress({
1620
+ safeOwnerAddress: userAddress,
1621
+ chain: chainConfig.chain,
1622
+ publicClient: chainConfig.publicClient
1623
+ });
1624
+ }
1473
1625
  /**
1474
1626
  * Get smart wallet address for a user
1475
- * Returns the deterministic Safe address for an EOA, or the address itself if already a Safe
1627
+ * Returns the Safe address for an EOA (deterministic for legacy wallets,
1628
+ * backend-assigned for predeployed pool wallets).
1476
1629
  *
1477
1630
  * @param userAddress - User's EOA address
1478
1631
  * @param chainId - Target chain ID
1479
- * @returns Smart wallet information including address and deployment status
1632
+ * @returns Smart wallet address, deployment status, and whether userAddress
1633
+ * is an on-chain OwnableValidator owner (false for reserved predeployed
1634
+ * wallets until the first deposit rotates ownership)
1480
1635
  */
1481
1636
  async getSmartWalletAddress(userAddress, chainId) {
1482
1637
  if (!userAddress) {
@@ -1486,37 +1641,29 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1486
1641
  throw new Error(`Unsupported chain ID: ${chainId}`);
1487
1642
  }
1488
1643
  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
- });
1644
+ const safeAddress = await this.getSafeAddressFor(userAddress, chainId);
1508
1645
  const isDeployed = await isSafeDeployed(
1509
1646
  safeAddress,
1510
1647
  chainConfig.publicClient
1511
1648
  );
1649
+ const isOwner = isDeployed ? await isOwnableValidatorOwner(
1650
+ safeAddress,
1651
+ userAddress,
1652
+ chainConfig.publicClient
1653
+ ) : false;
1512
1654
  return {
1513
1655
  address: safeAddress,
1514
- isDeployed
1656
+ isDeployed,
1657
+ isOwner
1515
1658
  };
1516
1659
  }
1517
1660
  /**
1518
1661
  * Deploy Safe Smart Wallet for a user
1519
1662
  *
1663
+ * @deprecated Prefer `depositFunds()`. Predeployed Safes and session keys are
1664
+ * managed automatically on first deposit. This method remains available for
1665
+ * legacy flows.
1666
+ *
1520
1667
  * @param userAddress - User's EOA address (the connected EOA, not the smart wallet address)
1521
1668
  * @param chainId - Target chain ID
1522
1669
  * @param strategy - Optional strategy selection: "conservative" (default) or "aggressive"
@@ -1525,17 +1672,15 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1525
1672
  *
1526
1673
  * @example
1527
1674
  * ```typescript
1528
- * // Deploy with default conservative strategy
1529
- * await sdk.deploySafe(userAddress, 8453);
1530
- *
1531
- * // Deploy with aggressive strategy
1532
- * await sdk.deploySafe(userAddress, 8453, "aggressive");
1675
+ * // Preferred: depositFunds handles predeployed wallet onboarding
1676
+ * await sdk.depositFunds(userAddress, 8453, amount, "USDC");
1533
1677
  *
1534
- * // Deploy and automatically create session key
1535
- * await sdk.deploySafe(userAddress, 8453, "conservative", true);
1678
+ * // Legacy: deploy with default conservative strategy
1679
+ * await sdk.deploySafe(userAddress, 8453);
1536
1680
  * ```
1537
1681
  */
1538
1682
  async deploySafe(userAddress, chainId, strategy, createSessionKey) {
1683
+ this.warnDeprecatedOnboardingMethod("deploySafe");
1539
1684
  try {
1540
1685
  if (!userAddress) {
1541
1686
  throw new Error("User address is required");
@@ -1544,6 +1689,20 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1544
1689
  throw new Error(`Unsupported chain ID: ${chainId}`);
1545
1690
  }
1546
1691
  await this.authenticateUser();
1692
+ if (this.isPredeployed && this.isConnectedUser(userAddress)) {
1693
+ const predeployedAddress = await this.getSafeAddressFor(
1694
+ userAddress,
1695
+ chainId
1696
+ );
1697
+ await this.updateUserProtocols(strategy);
1698
+ return {
1699
+ success: true,
1700
+ safeAddress: predeployedAddress,
1701
+ txHash: "0x0",
1702
+ status: "deployed",
1703
+ sessionKeyCreated: true
1704
+ };
1705
+ }
1547
1706
  const walletClient = this.getWalletClient(chainId);
1548
1707
  const chainConfig = getChainConfig(chainId, this.rpcUrls);
1549
1708
  const safeAddress = await getDeterministicSafeAddress({
@@ -1556,7 +1715,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1556
1715
  chainConfig.publicClient
1557
1716
  );
1558
1717
  if (alreadyDeployed) {
1559
- await this.updateUserProtocols(chainId, strategy);
1718
+ await this.updateUserProtocols(strategy);
1560
1719
  let sessionKeyCreated2 = false;
1561
1720
  if (createSessionKey) {
1562
1721
  try {
@@ -1596,7 +1755,6 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1596
1755
  initError.message
1597
1756
  );
1598
1757
  }
1599
- await this.updateUserProtocols(chainId, strategy);
1600
1758
  let sessionKeyCreated = false;
1601
1759
  if (createSessionKey) {
1602
1760
  try {
@@ -1618,25 +1776,34 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1618
1776
  };
1619
1777
  } catch (error) {
1620
1778
  console.error("Safe deployment failed:", error);
1621
- throw new Error(`Safe deployment failed: ${error.message}`);
1779
+ throw new Error(
1780
+ `Safe deployment failed: ${error.message}. deploySafe() is deprecated \u2014 prefer depositFunds() for predeployed wallet onboarding.`
1781
+ );
1622
1782
  }
1623
1783
  }
1624
1784
  /**
1625
1785
  * Create session key with auto-fetched configuration from Zyfai API
1626
1786
  * This is the simplified method that automatically fetches session configuration
1627
1787
  *
1788
+ * @deprecated Prefer `depositFunds()`. Predeployed wallets already have the
1789
+ * agent session enabled; session activation is handled after first deposit.
1790
+ * This method remains available for legacy flows.
1791
+ *
1628
1792
  * @param userAddress - User's EOA or Safe address
1629
1793
  * @param chainId - Target chain ID
1630
1794
  * @returns Session key response with signature and nonces
1631
1795
  *
1632
1796
  * @example
1633
1797
  * ```typescript
1634
- * // Simple usage - no need to configure sessions manually
1798
+ * // Preferred: depositFunds handles session onboarding for predeployed wallets
1799
+ * await sdk.depositFunds(userAddress, 8453, amount, "USDC");
1800
+ *
1801
+ * // Legacy:
1635
1802
  * const result = await sdk.createSessionKey(userAddress, 8453);
1636
- * console.log("Session created:", result.signature);
1637
1803
  * ```
1638
1804
  */
1639
1805
  async createSessionKey(userAddress, chainId) {
1806
+ this.warnDeprecatedOnboardingMethod("createSessionKey");
1640
1807
  try {
1641
1808
  await this.authenticateUser();
1642
1809
  if (!this.authenticatedUserId) {
@@ -1644,6 +1811,14 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1644
1811
  "User ID not available. Please ensure authentication completed successfully."
1645
1812
  );
1646
1813
  }
1814
+ if (this.isPredeployed) {
1815
+ return {
1816
+ success: true,
1817
+ userId: this.authenticatedUserId,
1818
+ message: "Predeployed wallet: agent session is managed by the backend",
1819
+ alreadyActive: true
1820
+ };
1821
+ }
1647
1822
  if (this.hasActiveSessionKey) {
1648
1823
  return {
1649
1824
  success: true,
@@ -1702,7 +1877,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1702
1877
  };
1703
1878
  } catch (error) {
1704
1879
  throw new Error(
1705
- `Failed to create session key: ${error.message}`
1880
+ `Failed to create session key: ${error.message}. createSessionKey() is deprecated \u2014 prefer depositFunds() for predeployed wallet onboarding.`
1706
1881
  );
1707
1882
  }
1708
1883
  }
@@ -1759,29 +1934,33 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1759
1934
  }
1760
1935
  }
1761
1936
  /**
1762
- * Patch the user's protocol selection for the given chain + strategy on
1763
- * both USDC and WETH. Mirrors the front-end customization flow:
1764
- * 1. Merge existing chains from `getUserDetails` with the new `chainId`
1937
+ * Patch the user's protocol selection on USDC, WETH, and EURC across all
1938
+ * supported chains (EURC limited to Mainnet/Base). Mirrors the front-end
1939
+ * customization flow:
1940
+ * 1. Merge existing chains from `getUserDetails` with the target chains
1765
1941
  * (never overwrite already-configured chains).
1766
1942
  * 2. Filter protocols by strategy, chain and asset support.
1767
1943
  * 3. Drop protocols that don't have any pools available for the
1768
1944
  * asset/chain/strategy combo.
1769
1945
  * 4. Persist via `updateUserProfile` (writes `assetTypeSettings`).
1770
1946
  *
1771
- * Called from `deploySafe` — SDK consumers don't handle protocols manually.
1947
+ * Called once from `depositFunds` on the account's first deposit.
1772
1948
  *
1773
1949
  * @internal
1774
1950
  */
1775
- async updateUserProtocols(chainId, strategy) {
1951
+ async updateUserProtocols(strategy) {
1776
1952
  try {
1777
1953
  const allProtocols = await this.httpClient.get(
1778
1954
  ENDPOINTS.PROTOCOLS()
1779
1955
  );
1780
- for (const asset of ["USDC", "WETH"]) {
1956
+ const allChains = [1, 8453, 42161];
1957
+ const assets = ["USDC", "WETH", "EURC"];
1958
+ for (const asset of assets) {
1781
1959
  try {
1960
+ const chainsForAsset = asset === "EURC" ? [1, 8453] : allChains;
1782
1961
  await this.updateUserProtocolsForAsset(
1783
1962
  asset,
1784
- chainId,
1963
+ chainsForAsset,
1785
1964
  strategy,
1786
1965
  allProtocols
1787
1966
  );
@@ -1801,11 +1980,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1801
1980
  * Compute and persist the protocol selection for a single asset.
1802
1981
  * @internal
1803
1982
  */
1804
- async updateUserProtocolsForAsset(asset, chainId, strategy, allProtocols) {
1983
+ async updateUserProtocolsForAsset(asset, chains, strategy, allProtocols) {
1805
1984
  const userDetails = await this.getUserDetails(asset);
1806
1985
  const existingChains = userDetails.chains ?? [];
1807
1986
  const effectiveChains = Array.from(
1808
- /* @__PURE__ */ new Set([...existingChains, chainId])
1987
+ /* @__PURE__ */ new Set([...existingChains, ...chains])
1809
1988
  );
1810
1989
  const publicStrategy = strategy ?? (isValidPublicStrategy(userDetails.strategy ?? "") ? userDetails.strategy : "conservative");
1811
1990
  const internalStrategy = toInternalStrategy(publicStrategy);
@@ -1820,7 +1999,6 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1820
1999
  effectiveChains,
1821
2000
  asset
1822
2001
  );
1823
- console.log("withPools", withPools, "effectiveChains", effectiveChains, "asset", asset);
1824
2002
  await this.updateUserProfile({
1825
2003
  asset,
1826
2004
  protocols: withPools,
@@ -1887,6 +2065,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1887
2065
  * Token is automatically selected based on chain (USDC by default):
1888
2066
  * - Ethereum Mainnet (1), Base (8453), Arbitrum (42161)
1889
2067
  *
2068
+ * On the account's first deposit (USDC profile has no chains yet), patches
2069
+ * protocol selection for USDC, WETH, and EURC across all supported chains
2070
+ * (EURC on Mainnet/Base only) before the transfer and log_deposit.
2071
+ *
1890
2072
  * Minimum portfolio balance enforced (Safe balance + deposit amount),
1891
2073
  * configured per-chain in `MIN_PORTFOLIO_BALANCE`:
1892
2074
  * - Ethereum Mainnet (1): 5 USDC (test threshold)
@@ -1898,7 +2080,8 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1898
2080
  * @param userAddress - User's address (owner of the Safe)
1899
2081
  * @param chainId - Target chain ID
1900
2082
  * @param amount - Amount in least decimal units (e.g., "100000000" for 100 USDC with 6 decimals)
1901
- * @param asset - Optional asset symbol ("USDC" or "WETH"). Defaults to "USDC".
2083
+ * @param asset - Optional asset symbol ("USDC", "WETH", or "EURC"). Defaults to "USDC".
2084
+ * EURC is supported on Ethereum Mainnet and Base only.
1902
2085
  * @returns Deposit response with transaction hash
1903
2086
  *
1904
2087
  * @example
@@ -1926,25 +2109,32 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1926
2109
  const assetConfig = ASSET_CONFIGS[assetSymbol];
1927
2110
  if (!assetConfig) {
1928
2111
  throw new Error(
1929
- `Unsupported asset: ${assetSymbol}. Supported: USDC, WETH.`
2112
+ `Unsupported asset: ${assetSymbol}. Supported: USDC, WETH, EURC.`
1930
2113
  );
1931
2114
  }
1932
2115
  const minRequired = MIN_PORTFOLIO_BALANCE[chainId]?.[assetSymbol];
1933
2116
  const token = getDefaultTokenAddress(chainId, assetSymbol);
1934
2117
  const walletClient = this.getWalletClient();
1935
2118
  const chainConfig = getChainConfig(chainId, this.rpcUrls);
1936
- const safeAddress = await getDeterministicSafeAddress({
1937
- safeOwnerAddress: userAddress,
1938
- chain: chainConfig.chain,
1939
- publicClient: chainConfig.publicClient
1940
- });
2119
+ const safeAddress = await this.getSafeAddressFor(userAddress, chainId);
1941
2120
  const isDeployed = await isSafeDeployed(
1942
2121
  safeAddress,
1943
2122
  chainConfig.publicClient
1944
2123
  );
1945
2124
  if (!isDeployed) {
1946
2125
  throw new Error(
1947
- `Safe not deployed for ${userAddress}. Please deploy the Safe first using deploySafe().`
2126
+ `Safe not available for ${userAddress} on chain ${chainId}.`
2127
+ );
2128
+ }
2129
+ try {
2130
+ const usdcDetails = await this.getUserDetails("USDC");
2131
+ if ((usdcDetails.chains?.length ?? 0) === 0) {
2132
+ await this.updateUserProtocols();
2133
+ }
2134
+ } catch (protocolError) {
2135
+ console.warn(
2136
+ "Failed to update user protocols before deposit:",
2137
+ protocolError.message
1948
2138
  );
1949
2139
  }
1950
2140
  const amountBigInt = BigInt(amount);
@@ -1979,6 +2169,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1979
2169
  hash: txHash
1980
2170
  });
1981
2171
  try {
2172
+ console.log("Logging deposit to backend", {
2173
+ chainId,
2174
+ transaction: txHash,
2175
+ token,
2176
+ amount
2177
+ });
1982
2178
  await this.httpClient.post(ENDPOINTS.LOG_DEPOSIT, {
1983
2179
  chainId,
1984
2180
  transaction: txHash,
@@ -2099,25 +2295,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2099
2295
  throw new Error(`Unsupported chain ID: ${chainId}`);
2100
2296
  }
2101
2297
  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
- }
2298
+ const safeAddress = await this.getSafeAddressFor(userAddress, chainId);
2121
2299
  const isDeployed = await isSafeDeployed(
2122
2300
  safeAddress,
2123
2301
  chainConfig.publicClient
@@ -3930,6 +4108,15 @@ function createBankrProvider(config) {
3930
4108
  }
3931
4109
  export {
3932
4110
  DEFAULT_TOKEN_ADDRESSES,
4111
+ ERC7579_LAUNCHPAD_ADDRESS,
4112
+ INTENT_EXECUTOR,
4113
+ INTENT_SMART_SESSIONS,
4114
+ OWNABLE_VALIDATOR,
4115
+ POOL_MODULE_ADDRESSES,
4116
+ PROXY_EXECUTOR,
4117
+ SAFE_7579_ADDRESS,
4118
+ SMART_SESSIONS_FALLBACK,
4119
+ SMART_SESSIONS_VALIDATOR,
3933
4120
  VAULT_ADDRESS,
3934
4121
  ZyfaiSDK,
3935
4122
  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.44",
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",