@zyfai/sdk 0.2.44 → 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/README.md CHANGED
@@ -403,9 +403,13 @@ Only deposits on Mainnet in USDC that would leave the Safe below 5 USDC are reje
403
403
  const result = await sdk.depositFunds(
404
404
  userAddress,
405
405
  8453, // Chain ID
406
- "10000000" // Amount: 10 USDC = 10 * 10^6
406
+ "10000000", // Amount: 10 USDC = 10 * 10^6
407
+ "USDC"
407
408
  );
408
409
 
410
+ // First deposit with aggressive strategy (protocol patching)
411
+ await sdk.depositFunds(userAddress, 8453, "10000000", "USDC", "aggressive");
412
+
409
413
  if (result.success) {
410
414
  console.log("Deposit successful!");
411
415
  console.log("Transaction Hash:", result.txHash);
@@ -415,10 +419,10 @@ if (result.success) {
415
419
  **Note:**
416
420
 
417
421
  - Amount must be in least decimal units. For USDC (6 decimals): 1 USDC = 1000000
418
- - Token address is automatically selected based on chain (USDC by default; pass `asset: "WETH"` or `asset: "EURC"` — EURC on Mainnet/Base only)
422
+ - `asset` is required (`"USDC"`, `"WETH"`, or `"EURC"` — EURC on Mainnet/Base only); token address is selected from that for the chain
419
423
  - On Ethereum Mainnet, the total Safe balance in USDC must be at least 5 USDC after the deposit (test threshold); smaller top-ups are allowed if the Safe already holds enough USDC to meet the minimum
420
424
  - The SDK automatically authenticates via SIWE before logging the deposit with Zyfai's API, so no extra steps are required on your end once the transfer confirms
421
- - **First deposit only** (before transfer + `log_deposit`): if the USDC profile has no `chains` yet, the SDK patches protocols for **USDC, WETH, and EURC** across all supported chains (EURC on Mainnet/Base only → `assetTypeSettings.[usdc|eth|eurc]`). Later deposits skip this.
425
+ - **First deposit only** (before transfer + `log_deposit`): if the USDC profile has no `chains` yet, the SDK patches protocols for **USDC, WETH, and EURC** across all supported chains (EURC on Mainnet/Base only → `assetTypeSettings.[usdc|eth|eurc]`). Pass optional `strategy` (`"conservative"` default or `"aggressive"`) — same role as the former `deploySafe` strategy argument. Later deposits skip this.
422
426
 
423
427
  #### Log External Deposit (For Sponsored Transactions)
424
428
 
package/dist/index.d.mts CHANGED
@@ -1009,12 +1009,15 @@ declare class ZyfaiSDK {
1009
1009
  * Deposit funds from EOA to Safe smart wallet
1010
1010
  * Transfers tokens from the connected wallet to the user's Safe and logs the deposit
1011
1011
  *
1012
- * Token is automatically selected based on chain (USDC by default):
1013
- * - Ethereum Mainnet (1), Base (8453), Arbitrum (42161)
1012
+ * Token address is selected from `asset` for the given chain:
1013
+ * - Ethereum Mainnet (1), Base (8453), Arbitrum (42161): USDC or WETH
1014
+ * - Ethereum Mainnet (1), Base (8453): EURC
1014
1015
  *
1015
1016
  * On the account's first deposit (USDC profile has no chains yet), patches
1016
1017
  * protocol selection for USDC, WETH, and EURC across all supported chains
1017
1018
  * (EURC on Mainnet/Base only) before the transfer and log_deposit.
1019
+ * Pass `strategy` to select protocols for that first-deposit setup
1020
+ * (same role as the former `deploySafe` strategy argument).
1018
1021
  *
1019
1022
  * Minimum portfolio balance enforced (Safe balance + deposit amount),
1020
1023
  * configured per-chain in `MIN_PORTFOLIO_BALANCE`:
@@ -1027,8 +1030,10 @@ declare class ZyfaiSDK {
1027
1030
  * @param userAddress - User's address (owner of the Safe)
1028
1031
  * @param chainId - Target chain ID
1029
1032
  * @param amount - Amount in least decimal units (e.g., "100000000" for 100 USDC with 6 decimals)
1030
- * @param asset - Optional asset symbol ("USDC", "WETH", or "EURC"). Defaults to "USDC".
1033
+ * @param asset - Asset symbol: "USDC", "WETH", or "EURC".
1031
1034
  * EURC is supported on Ethereum Mainnet and Base only.
1035
+ * @param strategy - Optional strategy for first-deposit protocol patching:
1036
+ * "conservative" (default) or "aggressive"
1032
1037
  * @returns Deposit response with transaction hash
1033
1038
  *
1034
1039
  * @example
@@ -1037,11 +1042,15 @@ declare class ZyfaiSDK {
1037
1042
  * const result = await sdk.depositFunds(
1038
1043
  * "0xUser...",
1039
1044
  * 8453,
1040
- * "10000000000" // 10,000 USDC = 10_000 * 10^6
1045
+ * "10000000000",
1046
+ * "USDC"
1041
1047
  * );
1048
+ *
1049
+ * // First deposit with aggressive strategy
1050
+ * await sdk.depositFunds(userAddress, 8453, "10000000000", "USDC", "aggressive");
1042
1051
  * ```
1043
1052
  */
1044
- depositFunds(userAddress: string, chainId: SupportedChainId, amount: string, asset?: string): Promise<DepositResponse>;
1053
+ depositFunds(userAddress: string, chainId: SupportedChainId, amount: string, asset: string, strategy?: Strategy): Promise<DepositResponse>;
1045
1054
  /**
1046
1055
  * Log a deposit that was executed client-side
1047
1056
  *
package/dist/index.d.ts CHANGED
@@ -1009,12 +1009,15 @@ declare class ZyfaiSDK {
1009
1009
  * Deposit funds from EOA to Safe smart wallet
1010
1010
  * Transfers tokens from the connected wallet to the user's Safe and logs the deposit
1011
1011
  *
1012
- * Token is automatically selected based on chain (USDC by default):
1013
- * - Ethereum Mainnet (1), Base (8453), Arbitrum (42161)
1012
+ * Token address is selected from `asset` for the given chain:
1013
+ * - Ethereum Mainnet (1), Base (8453), Arbitrum (42161): USDC or WETH
1014
+ * - Ethereum Mainnet (1), Base (8453): EURC
1014
1015
  *
1015
1016
  * On the account's first deposit (USDC profile has no chains yet), patches
1016
1017
  * protocol selection for USDC, WETH, and EURC across all supported chains
1017
1018
  * (EURC on Mainnet/Base only) before the transfer and log_deposit.
1019
+ * Pass `strategy` to select protocols for that first-deposit setup
1020
+ * (same role as the former `deploySafe` strategy argument).
1018
1021
  *
1019
1022
  * Minimum portfolio balance enforced (Safe balance + deposit amount),
1020
1023
  * configured per-chain in `MIN_PORTFOLIO_BALANCE`:
@@ -1027,8 +1030,10 @@ declare class ZyfaiSDK {
1027
1030
  * @param userAddress - User's address (owner of the Safe)
1028
1031
  * @param chainId - Target chain ID
1029
1032
  * @param amount - Amount in least decimal units (e.g., "100000000" for 100 USDC with 6 decimals)
1030
- * @param asset - Optional asset symbol ("USDC", "WETH", or "EURC"). Defaults to "USDC".
1033
+ * @param asset - Asset symbol: "USDC", "WETH", or "EURC".
1031
1034
  * EURC is supported on Ethereum Mainnet and Base only.
1035
+ * @param strategy - Optional strategy for first-deposit protocol patching:
1036
+ * "conservative" (default) or "aggressive"
1032
1037
  * @returns Deposit response with transaction hash
1033
1038
  *
1034
1039
  * @example
@@ -1037,11 +1042,15 @@ declare class ZyfaiSDK {
1037
1042
  * const result = await sdk.depositFunds(
1038
1043
  * "0xUser...",
1039
1044
  * 8453,
1040
- * "10000000000" // 10,000 USDC = 10_000 * 10^6
1045
+ * "10000000000",
1046
+ * "USDC"
1041
1047
  * );
1048
+ *
1049
+ * // First deposit with aggressive strategy
1050
+ * await sdk.depositFunds(userAddress, 8453, "10000000000", "USDC", "aggressive");
1042
1051
  * ```
1043
1052
  */
1044
- depositFunds(userAddress: string, chainId: SupportedChainId, amount: string, asset?: string): Promise<DepositResponse>;
1053
+ depositFunds(userAddress: string, chainId: SupportedChainId, amount: string, asset: string, strategy?: Strategy): Promise<DepositResponse>;
1045
1054
  /**
1046
1055
  * Log a deposit that was executed client-side
1047
1056
  *
package/dist/index.js CHANGED
@@ -1136,7 +1136,6 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1136
1136
  }
1137
1137
  this.httpClient.setAuthToken(authToken);
1138
1138
  this.authenticatedUserId = loginResponse.userId || null;
1139
- console.log("this.authenticatedUserId", loginResponse);
1140
1139
  this.hasActiveSessionKey = loginResponse.hasActiveSessionKey || false;
1141
1140
  this.isPredeployed = loginResponse.predeployed || false;
1142
1141
  this.connectedSmartWallet = loginResponse.smartWallet || null;
@@ -2094,12 +2093,15 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2094
2093
  * Deposit funds from EOA to Safe smart wallet
2095
2094
  * Transfers tokens from the connected wallet to the user's Safe and logs the deposit
2096
2095
  *
2097
- * Token is automatically selected based on chain (USDC by default):
2098
- * - Ethereum Mainnet (1), Base (8453), Arbitrum (42161)
2096
+ * Token address is selected from `asset` for the given chain:
2097
+ * - Ethereum Mainnet (1), Base (8453), Arbitrum (42161): USDC or WETH
2098
+ * - Ethereum Mainnet (1), Base (8453): EURC
2099
2099
  *
2100
2100
  * On the account's first deposit (USDC profile has no chains yet), patches
2101
2101
  * protocol selection for USDC, WETH, and EURC across all supported chains
2102
2102
  * (EURC on Mainnet/Base only) before the transfer and log_deposit.
2103
+ * Pass `strategy` to select protocols for that first-deposit setup
2104
+ * (same role as the former `deploySafe` strategy argument).
2103
2105
  *
2104
2106
  * Minimum portfolio balance enforced (Safe balance + deposit amount),
2105
2107
  * configured per-chain in `MIN_PORTFOLIO_BALANCE`:
@@ -2112,8 +2114,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2112
2114
  * @param userAddress - User's address (owner of the Safe)
2113
2115
  * @param chainId - Target chain ID
2114
2116
  * @param amount - Amount in least decimal units (e.g., "100000000" for 100 USDC with 6 decimals)
2115
- * @param asset - Optional asset symbol ("USDC", "WETH", or "EURC"). Defaults to "USDC".
2117
+ * @param asset - Asset symbol: "USDC", "WETH", or "EURC".
2116
2118
  * EURC is supported on Ethereum Mainnet and Base only.
2119
+ * @param strategy - Optional strategy for first-deposit protocol patching:
2120
+ * "conservative" (default) or "aggressive"
2117
2121
  * @returns Deposit response with transaction hash
2118
2122
  *
2119
2123
  * @example
@@ -2122,11 +2126,15 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2122
2126
  * const result = await sdk.depositFunds(
2123
2127
  * "0xUser...",
2124
2128
  * 8453,
2125
- * "10000000000" // 10,000 USDC = 10_000 * 10^6
2129
+ * "10000000000",
2130
+ * "USDC"
2126
2131
  * );
2132
+ *
2133
+ * // First deposit with aggressive strategy
2134
+ * await sdk.depositFunds(userAddress, 8453, "10000000000", "USDC", "aggressive");
2127
2135
  * ```
2128
2136
  */
2129
- async depositFunds(userAddress, chainId, amount, asset) {
2137
+ async depositFunds(userAddress, chainId, amount, asset, strategy) {
2130
2138
  try {
2131
2139
  if (!userAddress) {
2132
2140
  throw new Error("User address is required");
@@ -2137,7 +2145,15 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2137
2145
  if (!amount || isNaN(Number(amount)) || Number(amount) <= 0) {
2138
2146
  throw new Error("Valid amount is required");
2139
2147
  }
2140
- const assetSymbol = (asset || "USDC").toUpperCase();
2148
+ if (!asset) {
2149
+ throw new Error("Asset is required (USDC, WETH, or EURC)");
2150
+ }
2151
+ if (strategy !== void 0 && !isValidPublicStrategy(strategy)) {
2152
+ throw new Error(
2153
+ `Invalid strategy: ${strategy}. Must be "conservative" or "aggressive".`
2154
+ );
2155
+ }
2156
+ const assetSymbol = asset.toUpperCase();
2141
2157
  const assetConfig = ASSET_CONFIGS[assetSymbol];
2142
2158
  if (!assetConfig) {
2143
2159
  throw new Error(
@@ -2161,7 +2177,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2161
2177
  try {
2162
2178
  const usdcDetails = await this.getUserDetails("USDC");
2163
2179
  if ((usdcDetails.chains?.length ?? 0) === 0) {
2164
- await this.updateUserProtocols();
2180
+ await this.updateUserProtocols(strategy);
2165
2181
  }
2166
2182
  } catch (protocolError) {
2167
2183
  console.warn(
@@ -2201,12 +2217,6 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2201
2217
  hash: txHash
2202
2218
  });
2203
2219
  try {
2204
- console.log("Logging deposit to backend", {
2205
- chainId,
2206
- transaction: txHash,
2207
- token,
2208
- amount
2209
- });
2210
2220
  await this.httpClient.post(ENDPOINTS.LOG_DEPOSIT, {
2211
2221
  chainId,
2212
2222
  transaction: txHash,
@@ -2346,7 +2356,6 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2346
2356
  tokenSymbol
2347
2357
  });
2348
2358
  } else {
2349
- console.log("Full withdrawal", tokenSymbol);
2350
2359
  response = await this.httpClient.get(ENDPOINTS.USER_WITHDRAW, {
2351
2360
  params: { chainId, tokenSymbol }
2352
2361
  });
package/dist/index.mjs CHANGED
@@ -1104,7 +1104,6 @@ var _ZyfaiSDK = class _ZyfaiSDK {
1104
1104
  }
1105
1105
  this.httpClient.setAuthToken(authToken);
1106
1106
  this.authenticatedUserId = loginResponse.userId || null;
1107
- console.log("this.authenticatedUserId", loginResponse);
1108
1107
  this.hasActiveSessionKey = loginResponse.hasActiveSessionKey || false;
1109
1108
  this.isPredeployed = loginResponse.predeployed || false;
1110
1109
  this.connectedSmartWallet = loginResponse.smartWallet || null;
@@ -2062,12 +2061,15 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2062
2061
  * Deposit funds from EOA to Safe smart wallet
2063
2062
  * Transfers tokens from the connected wallet to the user's Safe and logs the deposit
2064
2063
  *
2065
- * Token is automatically selected based on chain (USDC by default):
2066
- * - 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
2067
  *
2068
2068
  * On the account's first deposit (USDC profile has no chains yet), patches
2069
2069
  * protocol selection for USDC, WETH, and EURC across all supported chains
2070
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).
2071
2073
  *
2072
2074
  * Minimum portfolio balance enforced (Safe balance + deposit amount),
2073
2075
  * configured per-chain in `MIN_PORTFOLIO_BALANCE`:
@@ -2080,8 +2082,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2080
2082
  * @param userAddress - User's address (owner of the Safe)
2081
2083
  * @param chainId - Target chain ID
2082
2084
  * @param amount - Amount in least decimal units (e.g., "100000000" for 100 USDC with 6 decimals)
2083
- * @param asset - Optional asset symbol ("USDC", "WETH", or "EURC"). Defaults to "USDC".
2085
+ * @param asset - Asset symbol: "USDC", "WETH", or "EURC".
2084
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"
2085
2089
  * @returns Deposit response with transaction hash
2086
2090
  *
2087
2091
  * @example
@@ -2090,11 +2094,15 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2090
2094
  * const result = await sdk.depositFunds(
2091
2095
  * "0xUser...",
2092
2096
  * 8453,
2093
- * "10000000000" // 10,000 USDC = 10_000 * 10^6
2097
+ * "10000000000",
2098
+ * "USDC"
2094
2099
  * );
2100
+ *
2101
+ * // First deposit with aggressive strategy
2102
+ * await sdk.depositFunds(userAddress, 8453, "10000000000", "USDC", "aggressive");
2095
2103
  * ```
2096
2104
  */
2097
- async depositFunds(userAddress, chainId, amount, asset) {
2105
+ async depositFunds(userAddress, chainId, amount, asset, strategy) {
2098
2106
  try {
2099
2107
  if (!userAddress) {
2100
2108
  throw new Error("User address is required");
@@ -2105,7 +2113,15 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2105
2113
  if (!amount || isNaN(Number(amount)) || Number(amount) <= 0) {
2106
2114
  throw new Error("Valid amount is required");
2107
2115
  }
2108
- 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();
2109
2125
  const assetConfig = ASSET_CONFIGS[assetSymbol];
2110
2126
  if (!assetConfig) {
2111
2127
  throw new Error(
@@ -2129,7 +2145,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2129
2145
  try {
2130
2146
  const usdcDetails = await this.getUserDetails("USDC");
2131
2147
  if ((usdcDetails.chains?.length ?? 0) === 0) {
2132
- await this.updateUserProtocols();
2148
+ await this.updateUserProtocols(strategy);
2133
2149
  }
2134
2150
  } catch (protocolError) {
2135
2151
  console.warn(
@@ -2169,12 +2185,6 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2169
2185
  hash: txHash
2170
2186
  });
2171
2187
  try {
2172
- console.log("Logging deposit to backend", {
2173
- chainId,
2174
- transaction: txHash,
2175
- token,
2176
- amount
2177
- });
2178
2188
  await this.httpClient.post(ENDPOINTS.LOG_DEPOSIT, {
2179
2189
  chainId,
2180
2190
  transaction: txHash,
@@ -2314,7 +2324,6 @@ var _ZyfaiSDK = class _ZyfaiSDK {
2314
2324
  tokenSymbol
2315
2325
  });
2316
2326
  } else {
2317
- console.log("Full withdrawal", tokenSymbol);
2318
2327
  response = await this.httpClient.get(ENDPOINTS.USER_WITHDRAW, {
2319
2328
  params: { chainId, tokenSymbol }
2320
2329
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zyfai/sdk",
3
- "version": "0.2.44",
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",