@zyfai/sdk 0.2.43 → 0.2.45

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));
@@ -952,6 +1033,15 @@ var _ZyfaiSDK = class _ZyfaiSDK {
952
1033
  this.rpcUrls = rpcUrls;
953
1034
  this.referralSource = referralSource;
954
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
+ }
955
1045
  /**
956
1046
  * Authenticate user with SIWE (Sign-In with Ethereum) & JWT token
957
1047
  * This is required for accessing user-specific endpoints like session-keys/config
@@ -1105,10 +1195,14 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1105
1195
  asset: "USDC",
1106
1196
  protocols: []
1107
1197
  });
1108
- const response = await this.updateUserProfile({
1198
+ await this.updateUserProfile({
1109
1199
  asset: "WETH",
1110
1200
  protocols: []
1111
1201
  });
1202
+ const response = await this.updateUserProfile({
1203
+ asset: "EURC",
1204
+ protocols: []
1205
+ });
1112
1206
  return response;
1113
1207
  } catch (error) {
1114
1208
  throw new Error(`Failed to pause agent: ${error.message}`);
@@ -1136,16 +1230,19 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1136
1230
  try {
1137
1231
  const userDetailsUSDC = await this.getUserDetails("USDC");
1138
1232
  const userDetailsETH = await this.getUserDetails("WETH");
1233
+ const userDetailsEURC = await this.getUserDetails("EURC");
1139
1234
  const chains = userDetailsUSDC.chains && userDetailsUSDC.chains.length > 0 ? userDetailsUSDC.chains : [8453, 42161];
1235
+ const eurcChains = userDetailsEURC.chains && userDetailsEURC.chains.length > 0 ? userDetailsEURC.chains.filter((c) => c === 1 || c === 8453) : [1, 8453];
1140
1236
  const allProtocols = await this.httpClient.get(
1141
1237
  ENDPOINTS.PROTOCOLS()
1142
1238
  );
1143
1239
  const usdcStrategy = userDetailsUSDC.strategy || "safe_strategy";
1144
1240
  const ethStrategy = userDetailsETH.strategy || "safe_strategy";
1145
- const filterProtocolsByStrategy = (strategy) => {
1241
+ const eurcStrategy = userDetailsEURC.strategy || "safe_strategy";
1242
+ const filterProtocolsByStrategy = (strategy, selectedChains) => {
1146
1243
  return allProtocols.filter((protocol) => {
1147
1244
  const hasMatchingChain = protocol.chains.some(
1148
- (chain) => chains.includes(chain)
1245
+ (chain) => selectedChains.includes(chain)
1149
1246
  );
1150
1247
  if (!hasMatchingChain) {
1151
1248
  return false;
@@ -1156,17 +1253,21 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1156
1253
  return protocol.strategies?.includes("safe_strategy");
1157
1254
  }).map((protocol) => protocol.id);
1158
1255
  };
1159
- const usdcProtocols = filterProtocolsByStrategy(usdcStrategy);
1160
- const ethProtocols = filterProtocolsByStrategy(ethStrategy);
1256
+ const usdcProtocols = filterProtocolsByStrategy(usdcStrategy, chains);
1257
+ const ethProtocols = filterProtocolsByStrategy(ethStrategy, chains);
1258
+ const eurcProtocols = filterProtocolsByStrategy(eurcStrategy, eurcChains);
1161
1259
  await this.updateUserProfile({
1162
1260
  asset: "USDC",
1163
1261
  protocols: usdcProtocols
1164
1262
  });
1165
- const updatedUserDetailsETH = await this.updateUserProfile({
1263
+ await this.updateUserProfile({
1166
1264
  asset: "WETH",
1167
1265
  protocols: ethProtocols
1168
1266
  });
1169
- return updatedUserDetailsETH;
1267
+ return await this.updateUserProfile({
1268
+ asset: "EURC",
1269
+ protocols: eurcProtocols
1270
+ });
1170
1271
  } catch (error) {
1171
1272
  throw new Error(`Failed to resume agent: ${error.message}`);
1172
1273
  }
@@ -1522,11 +1623,14 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1522
1623
  }
1523
1624
  /**
1524
1625
  * Get smart wallet address for a user
1525
- * Returns the deterministic Safe address for an EOA, or the address itself if already a Safe
1626
+ * Returns the Safe address for an EOA (deterministic for legacy wallets,
1627
+ * backend-assigned for predeployed pool wallets).
1526
1628
  *
1527
1629
  * @param userAddress - User's EOA address
1528
1630
  * @param chainId - Target chain ID
1529
- * @returns Smart wallet information including address and deployment status
1631
+ * @returns Smart wallet address, deployment status, and whether userAddress
1632
+ * is an on-chain OwnableValidator owner (false for reserved predeployed
1633
+ * wallets until the first deposit rotates ownership)
1530
1634
  */
1531
1635
  async getSmartWalletAddress(userAddress, chainId) {
1532
1636
  if (!userAddress) {
@@ -1541,14 +1645,24 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1541
1645
  safeAddress,
1542
1646
  chainConfig.publicClient
1543
1647
  );
1648
+ const isOwner = isDeployed ? await isOwnableValidatorOwner(
1649
+ safeAddress,
1650
+ userAddress,
1651
+ chainConfig.publicClient
1652
+ ) : false;
1544
1653
  return {
1545
1654
  address: safeAddress,
1546
- isDeployed
1655
+ isDeployed,
1656
+ isOwner
1547
1657
  };
1548
1658
  }
1549
1659
  /**
1550
1660
  * Deploy Safe Smart Wallet for a user
1551
1661
  *
1662
+ * @deprecated Prefer `depositFunds()`. Predeployed Safes and session keys are
1663
+ * managed automatically on first deposit. This method remains available for
1664
+ * legacy flows.
1665
+ *
1552
1666
  * @param userAddress - User's EOA address (the connected EOA, not the smart wallet address)
1553
1667
  * @param chainId - Target chain ID
1554
1668
  * @param strategy - Optional strategy selection: "conservative" (default) or "aggressive"
@@ -1557,17 +1671,15 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1557
1671
  *
1558
1672
  * @example
1559
1673
  * ```typescript
1560
- * // Deploy with default conservative strategy
1561
- * await sdk.deploySafe(userAddress, 8453);
1674
+ * // Preferred: depositFunds handles predeployed wallet onboarding
1675
+ * await sdk.depositFunds(userAddress, 8453, amount, "USDC");
1562
1676
  *
1563
- * // Deploy with aggressive strategy
1564
- * await sdk.deploySafe(userAddress, 8453, "aggressive");
1565
- *
1566
- * // Deploy and automatically create session key
1567
- * await sdk.deploySafe(userAddress, 8453, "conservative", true);
1677
+ * // Legacy: deploy with default conservative strategy
1678
+ * await sdk.deploySafe(userAddress, 8453);
1568
1679
  * ```
1569
1680
  */
1570
1681
  async deploySafe(userAddress, chainId, strategy, createSessionKey) {
1682
+ this.warnDeprecatedOnboardingMethod("deploySafe");
1571
1683
  try {
1572
1684
  if (!userAddress) {
1573
1685
  throw new Error("User address is required");
@@ -1581,7 +1693,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1581
1693
  userAddress,
1582
1694
  chainId
1583
1695
  );
1584
- await this.updateUserProtocols(chainId, strategy);
1696
+ await this.updateUserProtocols(strategy);
1585
1697
  return {
1586
1698
  success: true,
1587
1699
  safeAddress: predeployedAddress,
@@ -1602,7 +1714,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1602
1714
  chainConfig.publicClient
1603
1715
  );
1604
1716
  if (alreadyDeployed) {
1605
- await this.updateUserProtocols(chainId, strategy);
1717
+ await this.updateUserProtocols(strategy);
1606
1718
  let sessionKeyCreated2 = false;
1607
1719
  if (createSessionKey) {
1608
1720
  try {
@@ -1642,7 +1754,6 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1642
1754
  initError.message
1643
1755
  );
1644
1756
  }
1645
- await this.updateUserProtocols(chainId, strategy);
1646
1757
  let sessionKeyCreated = false;
1647
1758
  if (createSessionKey) {
1648
1759
  try {
@@ -1664,25 +1775,34 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1664
1775
  };
1665
1776
  } catch (error) {
1666
1777
  console.error("Safe deployment failed:", error);
1667
- throw new Error(`Safe deployment failed: ${error.message}`);
1778
+ throw new Error(
1779
+ `Safe deployment failed: ${error.message}. deploySafe() is deprecated \u2014 prefer depositFunds() for predeployed wallet onboarding.`
1780
+ );
1668
1781
  }
1669
1782
  }
1670
1783
  /**
1671
1784
  * Create session key with auto-fetched configuration from Zyfai API
1672
1785
  * This is the simplified method that automatically fetches session configuration
1673
1786
  *
1787
+ * @deprecated Prefer `depositFunds()`. Predeployed wallets already have the
1788
+ * agent session enabled; session activation is handled after first deposit.
1789
+ * This method remains available for legacy flows.
1790
+ *
1674
1791
  * @param userAddress - User's EOA or Safe address
1675
1792
  * @param chainId - Target chain ID
1676
1793
  * @returns Session key response with signature and nonces
1677
1794
  *
1678
1795
  * @example
1679
1796
  * ```typescript
1680
- * // Simple usage - no need to configure sessions manually
1797
+ * // Preferred: depositFunds handles session onboarding for predeployed wallets
1798
+ * await sdk.depositFunds(userAddress, 8453, amount, "USDC");
1799
+ *
1800
+ * // Legacy:
1681
1801
  * const result = await sdk.createSessionKey(userAddress, 8453);
1682
- * console.log("Session created:", result.signature);
1683
1802
  * ```
1684
1803
  */
1685
1804
  async createSessionKey(userAddress, chainId) {
1805
+ this.warnDeprecatedOnboardingMethod("createSessionKey");
1686
1806
  try {
1687
1807
  await this.authenticateUser();
1688
1808
  if (!this.authenticatedUserId) {
@@ -1756,7 +1876,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1756
1876
  };
1757
1877
  } catch (error) {
1758
1878
  throw new Error(
1759
- `Failed to create session key: ${error.message}`
1879
+ `Failed to create session key: ${error.message}. createSessionKey() is deprecated \u2014 prefer depositFunds() for predeployed wallet onboarding.`
1760
1880
  );
1761
1881
  }
1762
1882
  }
@@ -1813,29 +1933,33 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1813
1933
  }
1814
1934
  }
1815
1935
  /**
1816
- * Patch the user's protocol selection for the given chain + strategy on
1817
- * both USDC and WETH. Mirrors the front-end customization flow:
1818
- * 1. Merge existing chains from `getUserDetails` with the new `chainId`
1936
+ * Patch the user's protocol selection on USDC, WETH, and EURC across all
1937
+ * supported chains (EURC limited to Mainnet/Base). Mirrors the front-end
1938
+ * customization flow:
1939
+ * 1. Merge existing chains from `getUserDetails` with the target chains
1819
1940
  * (never overwrite already-configured chains).
1820
1941
  * 2. Filter protocols by strategy, chain and asset support.
1821
1942
  * 3. Drop protocols that don't have any pools available for the
1822
1943
  * asset/chain/strategy combo.
1823
1944
  * 4. Persist via `updateUserProfile` (writes `assetTypeSettings`).
1824
1945
  *
1825
- * Called from `deploySafe` — SDK consumers don't handle protocols manually.
1946
+ * Called once from `depositFunds` on the account's first deposit.
1826
1947
  *
1827
1948
  * @internal
1828
1949
  */
1829
- async updateUserProtocols(chainId, strategy) {
1950
+ async updateUserProtocols(strategy) {
1830
1951
  try {
1831
1952
  const allProtocols = await this.httpClient.get(
1832
1953
  ENDPOINTS.PROTOCOLS()
1833
1954
  );
1834
- for (const asset of ["USDC", "WETH"]) {
1955
+ const allChains = [1, 8453, 42161];
1956
+ const assets = ["USDC", "WETH", "EURC"];
1957
+ for (const asset of assets) {
1835
1958
  try {
1959
+ const chainsForAsset = asset === "EURC" ? [1, 8453] : allChains;
1836
1960
  await this.updateUserProtocolsForAsset(
1837
1961
  asset,
1838
- chainId,
1962
+ chainsForAsset,
1839
1963
  strategy,
1840
1964
  allProtocols
1841
1965
  );
@@ -1855,11 +1979,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1855
1979
  * Compute and persist the protocol selection for a single asset.
1856
1980
  * @internal
1857
1981
  */
1858
- async updateUserProtocolsForAsset(asset, chainId, strategy, allProtocols) {
1982
+ async updateUserProtocolsForAsset(asset, chains, strategy, allProtocols) {
1859
1983
  const userDetails = await this.getUserDetails(asset);
1860
1984
  const existingChains = userDetails.chains ?? [];
1861
1985
  const effectiveChains = Array.from(
1862
- /* @__PURE__ */ new Set([...existingChains, chainId])
1986
+ /* @__PURE__ */ new Set([...existingChains, ...chains])
1863
1987
  );
1864
1988
  const publicStrategy = strategy ?? (isValidPublicStrategy(userDetails.strategy ?? "") ? userDetails.strategy : "conservative");
1865
1989
  const internalStrategy = toInternalStrategy(publicStrategy);
@@ -1874,7 +1998,6 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1874
1998
  effectiveChains,
1875
1999
  asset
1876
2000
  );
1877
- console.log("withPools", withPools, "effectiveChains", effectiveChains, "asset", asset);
1878
2001
  await this.updateUserProfile({
1879
2002
  asset,
1880
2003
  protocols: withPools,
@@ -1938,8 +2061,15 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1938
2061
  * Deposit funds from EOA to Safe smart wallet
1939
2062
  * Transfers tokens from the connected wallet to the user's Safe and logs the deposit
1940
2063
  *
1941
- * Token is automatically selected based on chain (USDC by default):
1942
- * - Ethereum Mainnet (1), Base (8453), Arbitrum (42161)
2064
+ * Token address is selected from `asset` for the given chain:
2065
+ * - Ethereum Mainnet (1), Base (8453), Arbitrum (42161): USDC or WETH
2066
+ * - Ethereum Mainnet (1), Base (8453): EURC
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
+ * Pass `strategy` to select protocols for that first-deposit setup
2072
+ * (same role as the former `deploySafe` strategy argument).
1943
2073
  *
1944
2074
  * Minimum portfolio balance enforced (Safe balance + deposit amount),
1945
2075
  * configured per-chain in `MIN_PORTFOLIO_BALANCE`:
@@ -1952,7 +2082,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1952
2082
  * @param userAddress - User's address (owner of the Safe)
1953
2083
  * @param chainId - Target chain ID
1954
2084
  * @param amount - Amount in least decimal units (e.g., "100000000" for 100 USDC with 6 decimals)
1955
- * @param asset - Optional asset symbol ("USDC" or "WETH"). Defaults to "USDC".
2085
+ * @param asset - Asset symbol: "USDC", "WETH", or "EURC".
2086
+ * EURC is supported on Ethereum Mainnet and Base only.
2087
+ * @param strategy - Optional strategy for first-deposit protocol patching:
2088
+ * "conservative" (default) or "aggressive"
1956
2089
  * @returns Deposit response with transaction hash
1957
2090
  *
1958
2091
  * @example
@@ -1961,11 +2094,15 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1961
2094
  * const result = await sdk.depositFunds(
1962
2095
  * "0xUser...",
1963
2096
  * 8453,
1964
- * "10000000000" // 10,000 USDC = 10_000 * 10^6
2097
+ * "10000000000",
2098
+ * "USDC"
1965
2099
  * );
2100
+ *
2101
+ * // First deposit with aggressive strategy
2102
+ * await sdk.depositFunds(userAddress, 8453, "10000000000", "USDC", "aggressive");
1966
2103
  * ```
1967
2104
  */
1968
- async depositFunds(userAddress, chainId, amount, asset) {
2105
+ async depositFunds(userAddress, chainId, amount, asset, strategy) {
1969
2106
  try {
1970
2107
  if (!userAddress) {
1971
2108
  throw new Error("User address is required");
@@ -1976,11 +2113,19 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1976
2113
  if (!amount || isNaN(Number(amount)) || Number(amount) <= 0) {
1977
2114
  throw new Error("Valid amount is required");
1978
2115
  }
1979
- const assetSymbol = (asset || "USDC").toUpperCase();
2116
+ if (!asset) {
2117
+ throw new Error("Asset is required (USDC, WETH, or EURC)");
2118
+ }
2119
+ if (strategy !== void 0 && !isValidPublicStrategy(strategy)) {
2120
+ throw new Error(
2121
+ `Invalid strategy: ${strategy}. Must be "conservative" or "aggressive".`
2122
+ );
2123
+ }
2124
+ const assetSymbol = asset.toUpperCase();
1980
2125
  const assetConfig = ASSET_CONFIGS[assetSymbol];
1981
2126
  if (!assetConfig) {
1982
2127
  throw new Error(
1983
- `Unsupported asset: ${assetSymbol}. Supported: USDC, WETH.`
2128
+ `Unsupported asset: ${assetSymbol}. Supported: USDC, WETH, EURC.`
1984
2129
  );
1985
2130
  }
1986
2131
  const minRequired = MIN_PORTFOLIO_BALANCE[chainId]?.[assetSymbol];
@@ -1994,7 +2139,18 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1994
2139
  );
1995
2140
  if (!isDeployed) {
1996
2141
  throw new Error(
1997
- `Safe not deployed for ${userAddress}. Please deploy the Safe first using deploySafe().`
2142
+ `Safe not available for ${userAddress} on chain ${chainId}.`
2143
+ );
2144
+ }
2145
+ try {
2146
+ const usdcDetails = await this.getUserDetails("USDC");
2147
+ if ((usdcDetails.chains?.length ?? 0) === 0) {
2148
+ await this.updateUserProtocols(strategy);
2149
+ }
2150
+ } catch (protocolError) {
2151
+ console.warn(
2152
+ "Failed to update user protocols before deposit:",
2153
+ protocolError.message
1998
2154
  );
1999
2155
  }
2000
2156
  const amountBigInt = BigInt(amount);
@@ -2168,7 +2324,6 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2168
2324
  tokenSymbol
2169
2325
  });
2170
2326
  } else {
2171
- console.log("Full withdrawal", tokenSymbol);
2172
2327
  response = await this.httpClient.get(ENDPOINTS.USER_WITHDRAW, {
2173
2328
  params: { chainId, tokenSymbol }
2174
2329
  });
@@ -3960,33 +4115,15 @@ function createBankrProvider(config) {
3960
4115
  };
3961
4116
  return provider;
3962
4117
  }
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
- ];
3981
4118
  export {
3982
4119
  DEFAULT_TOKEN_ADDRESSES,
3983
- ERC7579_LAUNCHPAD_ADDRESS2 as ERC7579_LAUNCHPAD_ADDRESS,
4120
+ ERC7579_LAUNCHPAD_ADDRESS,
3984
4121
  INTENT_EXECUTOR,
3985
4122
  INTENT_SMART_SESSIONS,
3986
4123
  OWNABLE_VALIDATOR,
3987
4124
  POOL_MODULE_ADDRESSES,
3988
4125
  PROXY_EXECUTOR,
3989
- SAFE_7579_ADDRESS2 as SAFE_7579_ADDRESS,
4126
+ SAFE_7579_ADDRESS,
3990
4127
  SMART_SESSIONS_FALLBACK,
3991
4128
  SMART_SESSIONS_VALIDATOR,
3992
4129
  VAULT_ADDRESS,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zyfai/sdk",
3
- "version": "0.2.43",
3
+ "version": "0.2.45",
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",