@zyfai/sdk 0.2.3 → 0.2.4

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
@@ -258,6 +258,8 @@ console.log("Disconnected and cleared");
258
258
 
259
259
  Get the Smart Wallet (Safe) address for a user.
260
260
 
261
+ **Note:** This is a **read-only** operation and does **not** require `connectAccount()`.
262
+
261
263
  **Parameters:**
262
264
 
263
265
  - `userAddress`: User's EOA address
@@ -861,7 +863,7 @@ CHAIN_ID=8453
861
863
 
862
864
  ### "No account connected" Error
863
865
 
864
- Make sure to call `connectAccount()` before calling other methods that require signing. Note that `connectAccount()` automatically authenticates the user via SIWE.
866
+ Make sure to call `connectAccount()` before calling methods that require **signing or SIWE authentication** (e.g. `deploySafe`, `createSessionKey`, `withdrawFunds`, `updateUserProfile`). Read-only data methods (e.g. `getPositions`, `getHistory`, `getOnchainEarnings`) do not require a connected wallet.
865
867
 
866
868
  ### "Unsupported chain" Error
867
869
 
package/dist/index.d.mts CHANGED
@@ -24,6 +24,7 @@ interface DeploySafeResponse {
24
24
  /** @internal */
25
25
  interface UpdateUserProfileRequest {
26
26
  smartWallet?: string;
27
+ strategy?: string;
27
28
  chains?: number[];
28
29
  protocols?: string[];
29
30
  autoSelectProtocols?: boolean;
@@ -34,6 +35,7 @@ interface UpdateUserProfileResponse {
34
35
  userId: string;
35
36
  smartWallet?: Address;
36
37
  chains?: number[];
38
+ strategy?: string;
37
39
  }
38
40
  /** @internal */
39
41
  interface AddSessionKeyResponse {
package/dist/index.d.ts CHANGED
@@ -24,6 +24,7 @@ interface DeploySafeResponse {
24
24
  /** @internal */
25
25
  interface UpdateUserProfileRequest {
26
26
  smartWallet?: string;
27
+ strategy?: string;
27
28
  chains?: number[];
28
29
  protocols?: string[];
29
30
  autoSelectProtocols?: boolean;
@@ -34,6 +35,7 @@ interface UpdateUserProfileResponse {
34
35
  userId: string;
35
36
  smartWallet?: Address;
36
37
  chains?: number[];
38
+ strategy?: string;
37
39
  }
38
40
  /** @internal */
39
41
  interface AddSessionKeyResponse {
package/dist/index.js CHANGED
@@ -437,33 +437,18 @@ var SAFE_7579_ADDRESS = "0x7579EE8307284F293B1927136486880611F20002";
437
437
  var ERC7579_LAUNCHPAD_ADDRESS = "0x7579011aB74c46090561ea277Ba79D510c6C00ff";
438
438
  var ACCOUNT_SALT = "zyfai";
439
439
  var getSafeAccount = async (config) => {
440
- const { owner, safeOwnerAddress, publicClient } = config;
441
- if (!owner || !owner.account) {
442
- throw new Error("Wallet not connected. Please connect your wallet first.");
443
- }
444
- const signerAddress = owner.account.address;
445
- if (!signerAddress) {
446
- throw new Error("Owner account address is required");
447
- }
448
- const effectiveOwnerAddress = safeOwnerAddress || signerAddress;
449
- if (!effectiveOwnerAddress) {
450
- throw new Error("Address is required");
451
- }
452
- const formattedEffectiveAddress = (0, import_viem3.getAddress)(effectiveOwnerAddress);
453
- const isReadOnly = safeOwnerAddress && safeOwnerAddress.toLowerCase() !== signerAddress.toLowerCase();
454
- if (!isReadOnly && safeOwnerAddress && safeOwnerAddress.toLowerCase() !== signerAddress.toLowerCase()) {
455
- throw new Error(
456
- `Connected wallet address (${signerAddress}) must match the Safe owner address (${safeOwnerAddress}). Please connect with the correct wallet.`
457
- );
440
+ const { safeOwnerAddress, publicClient } = config;
441
+ if (!safeOwnerAddress) {
442
+ throw new Error("Safe owner address is required");
458
443
  }
444
+ const formattedOwnerAddress = (0, import_viem3.getAddress)(safeOwnerAddress);
459
445
  const ownableValidator = (0, import_module_sdk.getOwnableValidator)({
460
- owners: [formattedEffectiveAddress],
461
- // Use formatted effective owner address for validator
446
+ owners: [formattedOwnerAddress],
462
447
  threshold: 1
463
448
  });
464
449
  const saltHex = (0, import_viem3.fromHex)((0, import_viem3.toHex)(ACCOUNT_SALT), "bigint");
465
450
  const tempOwner = {
466
- address: formattedEffectiveAddress,
451
+ address: formattedOwnerAddress,
467
452
  type: "json-rpc"
468
453
  };
469
454
  const safeAccount = await (0, import_accounts.toSafeSmartAccount)({
@@ -648,6 +633,9 @@ function toPublicStrategy(internalStrategy) {
648
633
  `Invalid internal strategy: ${internalStrategy}. Must be "safe_strategy" or "degen_strategy".`
649
634
  );
650
635
  }
636
+ function isValidPublicStrategy(strategy) {
637
+ return strategy === "conservative" || strategy === "aggressive";
638
+ }
651
639
  function convertStrategyToPublic(obj) {
652
640
  if (!obj.strategy) {
653
641
  return obj;
@@ -771,15 +759,27 @@ var ZyfaiSDK = class {
771
759
  async updateUserProfile(request) {
772
760
  try {
773
761
  await this.authenticateUser();
762
+ const payload = { ...request };
763
+ if (payload.strategy) {
764
+ if (!isValidPublicStrategy(payload.strategy)) {
765
+ throw new Error(
766
+ `Invalid strategy: ${payload.strategy}. Must be "conservative" or "aggressive".`
767
+ );
768
+ }
769
+ payload.strategy = toInternalStrategy(
770
+ payload.strategy
771
+ );
772
+ }
774
773
  const response = await this.httpClient.patch(
775
774
  ENDPOINTS.USER_ME,
776
- request
775
+ payload
777
776
  );
778
777
  return {
779
778
  success: true,
780
779
  userId: response.userId || response.id,
781
780
  smartWallet: response.smartWallet,
782
- chains: response.chains
781
+ chains: response.chains,
782
+ strategy: response.strategy
783
783
  };
784
784
  } catch (error) {
785
785
  throw new Error(
@@ -1027,9 +1027,7 @@ var ZyfaiSDK = class {
1027
1027
  }
1028
1028
  } catch {
1029
1029
  }
1030
- const walletClient = this.getWalletClient(chainId);
1031
1030
  const safeAddress = await getDeterministicSafeAddress({
1032
- owner: walletClient,
1033
1031
  safeOwnerAddress: userAddress,
1034
1032
  chain: chainConfig.chain,
1035
1033
  publicClient: chainConfig.publicClient
@@ -1072,7 +1070,6 @@ var ZyfaiSDK = class {
1072
1070
  const walletClient = this.getWalletClient(chainId);
1073
1071
  const chainConfig = getChainConfig(chainId, this.rpcUrls);
1074
1072
  const safeAddress = await getDeterministicSafeAddress({
1075
- owner: walletClient,
1076
1073
  safeOwnerAddress: userAddress,
1077
1074
  chain: chainConfig.chain,
1078
1075
  publicClient: chainConfig.publicClient
@@ -1257,12 +1254,6 @@ var ZyfaiSDK = class {
1257
1254
  allPublicClients,
1258
1255
  signingParams
1259
1256
  );
1260
- const safeAddress = await getDeterministicSafeAddress({
1261
- owner: walletClient,
1262
- safeOwnerAddress: userAddress,
1263
- chain: chainConfig.chain,
1264
- publicClient: chainConfig.publicClient
1265
- });
1266
1257
  return {
1267
1258
  success: true,
1268
1259
  signature,
@@ -1368,7 +1359,6 @@ var ZyfaiSDK = class {
1368
1359
  const walletClient = this.getWalletClient();
1369
1360
  const chainConfig = getChainConfig(chainId, this.rpcUrls);
1370
1361
  const safeAddress = await getDeterministicSafeAddress({
1371
- owner: walletClient,
1372
1362
  safeOwnerAddress: userAddress,
1373
1363
  chain: chainConfig.chain,
1374
1364
  publicClient: chainConfig.publicClient
@@ -1447,18 +1437,14 @@ var ZyfaiSDK = class {
1447
1437
  if (smartWalletInfo.smartWallet) {
1448
1438
  safeAddress = smartWalletInfo.smartWallet;
1449
1439
  } else {
1450
- const walletClient = this.getWalletClient();
1451
1440
  safeAddress = await getDeterministicSafeAddress({
1452
- owner: walletClient,
1453
1441
  safeOwnerAddress: userAddress,
1454
1442
  chain: chainConfig.chain,
1455
1443
  publicClient: chainConfig.publicClient
1456
1444
  });
1457
1445
  }
1458
1446
  } catch {
1459
- const walletClient = this.getWalletClient();
1460
1447
  safeAddress = await getDeterministicSafeAddress({
1461
- owner: walletClient,
1462
1448
  safeOwnerAddress: userAddress,
1463
1449
  chain: chainConfig.chain,
1464
1450
  publicClient: chainConfig.publicClient
package/dist/index.mjs CHANGED
@@ -414,33 +414,18 @@ var SAFE_7579_ADDRESS = "0x7579EE8307284F293B1927136486880611F20002";
414
414
  var ERC7579_LAUNCHPAD_ADDRESS = "0x7579011aB74c46090561ea277Ba79D510c6C00ff";
415
415
  var ACCOUNT_SALT = "zyfai";
416
416
  var getSafeAccount = async (config) => {
417
- const { owner, safeOwnerAddress, publicClient } = config;
418
- if (!owner || !owner.account) {
419
- throw new Error("Wallet not connected. Please connect your wallet first.");
420
- }
421
- const signerAddress = owner.account.address;
422
- if (!signerAddress) {
423
- throw new Error("Owner account address is required");
424
- }
425
- const effectiveOwnerAddress = safeOwnerAddress || signerAddress;
426
- if (!effectiveOwnerAddress) {
427
- throw new Error("Address is required");
428
- }
429
- const formattedEffectiveAddress = getAddress(effectiveOwnerAddress);
430
- const isReadOnly = safeOwnerAddress && safeOwnerAddress.toLowerCase() !== signerAddress.toLowerCase();
431
- if (!isReadOnly && safeOwnerAddress && safeOwnerAddress.toLowerCase() !== signerAddress.toLowerCase()) {
432
- throw new Error(
433
- `Connected wallet address (${signerAddress}) must match the Safe owner address (${safeOwnerAddress}). Please connect with the correct wallet.`
434
- );
417
+ const { safeOwnerAddress, publicClient } = config;
418
+ if (!safeOwnerAddress) {
419
+ throw new Error("Safe owner address is required");
435
420
  }
421
+ const formattedOwnerAddress = getAddress(safeOwnerAddress);
436
422
  const ownableValidator = getOwnableValidator({
437
- owners: [formattedEffectiveAddress],
438
- // Use formatted effective owner address for validator
423
+ owners: [formattedOwnerAddress],
439
424
  threshold: 1
440
425
  });
441
426
  const saltHex = fromHex(toHex(ACCOUNT_SALT), "bigint");
442
427
  const tempOwner = {
443
- address: formattedEffectiveAddress,
428
+ address: formattedOwnerAddress,
444
429
  type: "json-rpc"
445
430
  };
446
431
  const safeAccount = await toSafeSmartAccount({
@@ -625,6 +610,9 @@ function toPublicStrategy(internalStrategy) {
625
610
  `Invalid internal strategy: ${internalStrategy}. Must be "safe_strategy" or "degen_strategy".`
626
611
  );
627
612
  }
613
+ function isValidPublicStrategy(strategy) {
614
+ return strategy === "conservative" || strategy === "aggressive";
615
+ }
628
616
  function convertStrategyToPublic(obj) {
629
617
  if (!obj.strategy) {
630
618
  return obj;
@@ -748,15 +736,27 @@ var ZyfaiSDK = class {
748
736
  async updateUserProfile(request) {
749
737
  try {
750
738
  await this.authenticateUser();
739
+ const payload = { ...request };
740
+ if (payload.strategy) {
741
+ if (!isValidPublicStrategy(payload.strategy)) {
742
+ throw new Error(
743
+ `Invalid strategy: ${payload.strategy}. Must be "conservative" or "aggressive".`
744
+ );
745
+ }
746
+ payload.strategy = toInternalStrategy(
747
+ payload.strategy
748
+ );
749
+ }
751
750
  const response = await this.httpClient.patch(
752
751
  ENDPOINTS.USER_ME,
753
- request
752
+ payload
754
753
  );
755
754
  return {
756
755
  success: true,
757
756
  userId: response.userId || response.id,
758
757
  smartWallet: response.smartWallet,
759
- chains: response.chains
758
+ chains: response.chains,
759
+ strategy: response.strategy
760
760
  };
761
761
  } catch (error) {
762
762
  throw new Error(
@@ -1004,9 +1004,7 @@ var ZyfaiSDK = class {
1004
1004
  }
1005
1005
  } catch {
1006
1006
  }
1007
- const walletClient = this.getWalletClient(chainId);
1008
1007
  const safeAddress = await getDeterministicSafeAddress({
1009
- owner: walletClient,
1010
1008
  safeOwnerAddress: userAddress,
1011
1009
  chain: chainConfig.chain,
1012
1010
  publicClient: chainConfig.publicClient
@@ -1049,7 +1047,6 @@ var ZyfaiSDK = class {
1049
1047
  const walletClient = this.getWalletClient(chainId);
1050
1048
  const chainConfig = getChainConfig(chainId, this.rpcUrls);
1051
1049
  const safeAddress = await getDeterministicSafeAddress({
1052
- owner: walletClient,
1053
1050
  safeOwnerAddress: userAddress,
1054
1051
  chain: chainConfig.chain,
1055
1052
  publicClient: chainConfig.publicClient
@@ -1234,12 +1231,6 @@ var ZyfaiSDK = class {
1234
1231
  allPublicClients,
1235
1232
  signingParams
1236
1233
  );
1237
- const safeAddress = await getDeterministicSafeAddress({
1238
- owner: walletClient,
1239
- safeOwnerAddress: userAddress,
1240
- chain: chainConfig.chain,
1241
- publicClient: chainConfig.publicClient
1242
- });
1243
1234
  return {
1244
1235
  success: true,
1245
1236
  signature,
@@ -1345,7 +1336,6 @@ var ZyfaiSDK = class {
1345
1336
  const walletClient = this.getWalletClient();
1346
1337
  const chainConfig = getChainConfig(chainId, this.rpcUrls);
1347
1338
  const safeAddress = await getDeterministicSafeAddress({
1348
- owner: walletClient,
1349
1339
  safeOwnerAddress: userAddress,
1350
1340
  chain: chainConfig.chain,
1351
1341
  publicClient: chainConfig.publicClient
@@ -1424,18 +1414,14 @@ var ZyfaiSDK = class {
1424
1414
  if (smartWalletInfo.smartWallet) {
1425
1415
  safeAddress = smartWalletInfo.smartWallet;
1426
1416
  } else {
1427
- const walletClient = this.getWalletClient();
1428
1417
  safeAddress = await getDeterministicSafeAddress({
1429
- owner: walletClient,
1430
1418
  safeOwnerAddress: userAddress,
1431
1419
  chain: chainConfig.chain,
1432
1420
  publicClient: chainConfig.publicClient
1433
1421
  });
1434
1422
  }
1435
1423
  } catch {
1436
- const walletClient = this.getWalletClient();
1437
1424
  safeAddress = await getDeterministicSafeAddress({
1438
- owner: walletClient,
1439
1425
  safeOwnerAddress: userAddress,
1440
1426
  chain: chainConfig.chain,
1441
1427
  publicClient: chainConfig.publicClient
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zyfai/sdk",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
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",