@zyfai/sdk 0.1.3 → 0.1.5

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
@@ -100,16 +100,23 @@ const walletInfo = await sdk.getSmartWalletAddress(userAddress, 42161);
100
100
  console.log("Safe Address:", walletInfo.address);
101
101
  console.log("Is Deployed:", walletInfo.isDeployed);
102
102
 
103
- // Deploy the Safe
103
+ // Deploy the Safe (automatically checks if already deployed)
104
104
  const result = await sdk.deploySafe(userAddress, 42161);
105
105
 
106
106
  if (result.success) {
107
107
  console.log("Safe Address:", result.safeAddress);
108
108
  console.log("Status:", result.status); // 'deployed' | 'failed'
109
- console.log("Transaction Hash:", result.txHash);
109
+
110
+ if (result.alreadyDeployed) {
111
+ console.log("Safe was already deployed - no action needed");
112
+ } else {
113
+ console.log("Transaction Hash:", result.txHash);
114
+ }
110
115
  }
111
116
  ```
112
117
 
118
+ **Note:** The SDK proactively checks if the Safe is already deployed before attempting deployment. If it exists, it returns `alreadyDeployed: true` without making any transactions.
119
+
113
120
  ### 2. Multi-Chain Support
114
121
 
115
122
  The SDK supports the following chains:
@@ -370,7 +377,7 @@ console.log("Active wallet count:", wallets.count);
370
377
  #### Get Smart Wallets by EOA
371
378
 
372
379
  ```typescript
373
- const result = await sdk.getSmartWalletsByEOA("0xYourEOA...");
380
+ const result = await sdk.getSmartWalletByEOA("0xYourEOA...");
374
381
  console.log("Smart wallets:", result.smartWallets);
375
382
  ```
376
383
 
package/dist/index.d.mts CHANGED
@@ -21,6 +21,8 @@ interface DeploySafeResponse {
21
21
  safeAddress: Address;
22
22
  txHash: string;
23
23
  status: "deployed" | "failed";
24
+ /** True if the Safe was already deployed (no new deployment needed) */
25
+ alreadyDeployed?: boolean;
24
26
  }
25
27
  /** @internal */
26
28
  interface UpdateUserProfileRequest {
@@ -175,11 +177,10 @@ interface ActiveWalletsResponse {
175
177
  wallets: ActiveWallet[];
176
178
  count: number;
177
179
  }
178
- interface SmartWalletsByEOAResponse {
180
+ interface SmartWalletByEOAResponse {
179
181
  success: boolean;
180
182
  eoa: string;
181
- smartWallet: string | null;
182
- smartWallets: string[];
183
+ smartWallet: Address | null;
183
184
  chains: number[];
184
185
  }
185
186
  interface FirstTopupResponse {
@@ -645,11 +646,11 @@ declare class ZyfaiSDK {
645
646
  *
646
647
  * @example
647
648
  * ```typescript
648
- * const result = await sdk.getSmartWalletsByEOA("0x...");
649
+ * const result = await sdk.getSmartWalletByEOA("0x...");
649
650
  * console.log("Smart wallets:", result.smartWallets);
650
651
  * ```
651
652
  */
652
- getSmartWalletsByEOA(eoaAddress: string): Promise<SmartWalletsByEOAResponse>;
653
+ getSmartWalletByEOA(eoaAddress: string): Promise<SmartWalletByEOAResponse>;
653
654
  /**
654
655
  * Get the first topup (deposit) information for a wallet
655
656
  *
@@ -812,4 +813,4 @@ declare class ZyfaiSDK {
812
813
  getRebalanceFrequency(walletAddress: string): Promise<RebalanceFrequencyResponse>;
813
814
  }
814
815
 
815
- export { type ActionData, type ActiveWallet, type ActiveWalletsResponse, type Address, type ChainConfig, type ChainPortfolio, type DailyApyEntry, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DeploySafeResponse, type DepositResponse, type ERC7739Context, type ERC7739Data, type Environment, type FirstTopupResponse, type Hex, type HistoryEntry, type HistoryPosition, type HistoryResponse, type OnchainEarnings, type OnchainEarningsResponse, type OpportunitiesResponse, type Opportunity, type PolicyData, type Pool, type PortfolioToken, type Position, type PositionSlot, type PositionsResponse, type Protocol, type ProtocolsResponse, type RebalanceFrequencyResponse, type RebalanceInfo, type RebalanceInfoResponse, type SDKConfig, type Session, type SessionKeyResponse, type SmartWalletResponse, type SmartWalletsByEOAResponse, type SupportedChainId, type TVLResponse, type UserDetails, type UserDetailsResponse, type VolumeResponse, type WithdrawResponse, ZyfaiSDK, getChainConfig, getSupportedChainIds, isSupportedChain };
816
+ export { type ActionData, type ActiveWallet, type ActiveWalletsResponse, type Address, type ChainConfig, type ChainPortfolio, type DailyApyEntry, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DeploySafeResponse, type DepositResponse, type ERC7739Context, type ERC7739Data, type Environment, type FirstTopupResponse, type Hex, type HistoryEntry, type HistoryPosition, type HistoryResponse, type OnchainEarnings, type OnchainEarningsResponse, type OpportunitiesResponse, type Opportunity, type PolicyData, type Pool, type PortfolioToken, type Position, type PositionSlot, type PositionsResponse, type Protocol, type ProtocolsResponse, type RebalanceFrequencyResponse, type RebalanceInfo, type RebalanceInfoResponse, type SDKConfig, type Session, type SessionKeyResponse, type SmartWalletByEOAResponse, type SmartWalletResponse, type SupportedChainId, type TVLResponse, type UserDetails, type UserDetailsResponse, type VolumeResponse, type WithdrawResponse, ZyfaiSDK, getChainConfig, getSupportedChainIds, isSupportedChain };
package/dist/index.d.ts CHANGED
@@ -21,6 +21,8 @@ interface DeploySafeResponse {
21
21
  safeAddress: Address;
22
22
  txHash: string;
23
23
  status: "deployed" | "failed";
24
+ /** True if the Safe was already deployed (no new deployment needed) */
25
+ alreadyDeployed?: boolean;
24
26
  }
25
27
  /** @internal */
26
28
  interface UpdateUserProfileRequest {
@@ -175,11 +177,10 @@ interface ActiveWalletsResponse {
175
177
  wallets: ActiveWallet[];
176
178
  count: number;
177
179
  }
178
- interface SmartWalletsByEOAResponse {
180
+ interface SmartWalletByEOAResponse {
179
181
  success: boolean;
180
182
  eoa: string;
181
- smartWallet: string | null;
182
- smartWallets: string[];
183
+ smartWallet: Address | null;
183
184
  chains: number[];
184
185
  }
185
186
  interface FirstTopupResponse {
@@ -645,11 +646,11 @@ declare class ZyfaiSDK {
645
646
  *
646
647
  * @example
647
648
  * ```typescript
648
- * const result = await sdk.getSmartWalletsByEOA("0x...");
649
+ * const result = await sdk.getSmartWalletByEOA("0x...");
649
650
  * console.log("Smart wallets:", result.smartWallets);
650
651
  * ```
651
652
  */
652
- getSmartWalletsByEOA(eoaAddress: string): Promise<SmartWalletsByEOAResponse>;
653
+ getSmartWalletByEOA(eoaAddress: string): Promise<SmartWalletByEOAResponse>;
653
654
  /**
654
655
  * Get the first topup (deposit) information for a wallet
655
656
  *
@@ -812,4 +813,4 @@ declare class ZyfaiSDK {
812
813
  getRebalanceFrequency(walletAddress: string): Promise<RebalanceFrequencyResponse>;
813
814
  }
814
815
 
815
- export { type ActionData, type ActiveWallet, type ActiveWalletsResponse, type Address, type ChainConfig, type ChainPortfolio, type DailyApyEntry, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DeploySafeResponse, type DepositResponse, type ERC7739Context, type ERC7739Data, type Environment, type FirstTopupResponse, type Hex, type HistoryEntry, type HistoryPosition, type HistoryResponse, type OnchainEarnings, type OnchainEarningsResponse, type OpportunitiesResponse, type Opportunity, type PolicyData, type Pool, type PortfolioToken, type Position, type PositionSlot, type PositionsResponse, type Protocol, type ProtocolsResponse, type RebalanceFrequencyResponse, type RebalanceInfo, type RebalanceInfoResponse, type SDKConfig, type Session, type SessionKeyResponse, type SmartWalletResponse, type SmartWalletsByEOAResponse, type SupportedChainId, type TVLResponse, type UserDetails, type UserDetailsResponse, type VolumeResponse, type WithdrawResponse, ZyfaiSDK, getChainConfig, getSupportedChainIds, isSupportedChain };
816
+ export { type ActionData, type ActiveWallet, type ActiveWalletsResponse, type Address, type ChainConfig, type ChainPortfolio, type DailyApyEntry, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DeploySafeResponse, type DepositResponse, type ERC7739Context, type ERC7739Data, type Environment, type FirstTopupResponse, type Hex, type HistoryEntry, type HistoryPosition, type HistoryResponse, type OnchainEarnings, type OnchainEarningsResponse, type OpportunitiesResponse, type Opportunity, type PolicyData, type Pool, type PortfolioToken, type Position, type PositionSlot, type PositionsResponse, type Protocol, type ProtocolsResponse, type RebalanceFrequencyResponse, type RebalanceInfo, type RebalanceInfoResponse, type SDKConfig, type Session, type SessionKeyResponse, type SmartWalletByEOAResponse, type SmartWalletResponse, type SupportedChainId, type TVLResponse, type UserDetails, type UserDetailsResponse, type VolumeResponse, type WithdrawResponse, ZyfaiSDK, getChainConfig, getSupportedChainIds, isSupportedChain };
package/dist/index.js CHANGED
@@ -414,7 +414,7 @@ var SAFE_7579_ADDRESS = "0x7579EE8307284F293B1927136486880611F20002";
414
414
  var ERC7579_LAUNCHPAD_ADDRESS = "0x7579011aB74c46090561ea277Ba79D510c6C00ff";
415
415
  var ACCOUNT_SALTS = {
416
416
  staging: "zyfai-staging",
417
- production: "zyfai-production"
417
+ production: "zyfai"
418
418
  };
419
419
  var getSafeAccount = async (config) => {
420
420
  const {
@@ -440,8 +440,8 @@ var getSafeAccount = async (config) => {
440
440
  const saltHex = (0, import_viem3.fromHex)((0, import_viem3.toHex)(effectiveSalt), "bigint");
441
441
  const safeAccount = await (0, import_accounts.toSafeSmartAccount)({
442
442
  client: publicClient,
443
- owners: [owner.account],
444
- // Pass the account object with address and signMessage capability
443
+ owners: [owner],
444
+ // Pass the owner object with address and signMessage capability
445
445
  version: "1.4.1",
446
446
  entryPoint: {
447
447
  address: import_account_abstraction.entryPoint07Address,
@@ -512,7 +512,7 @@ var getAccountType = async (address, publicClient) => {
512
512
  }
513
513
  };
514
514
  var getSmartAccountClient = async (config) => {
515
- const { publicClient, chain, bundlerUrl } = config;
515
+ const { chain, bundlerUrl } = config;
516
516
  const safeAccount = await getSafeAccount(config);
517
517
  const bundlerClient = (0, import_pimlico.createPimlicoClient)({
518
518
  transport: (0, import_viem3.http)(bundlerUrl),
@@ -875,6 +875,26 @@ var ZyfaiSDK = class {
875
875
  }
876
876
  const walletClient = this.getWalletClient(chainId);
877
877
  const chainConfig = getChainConfig(chainId);
878
+ const safeAddress = await getDeterministicSafeAddress({
879
+ owner: walletClient,
880
+ safeOwnerAddress: userAddress,
881
+ chain: chainConfig.chain,
882
+ publicClient: chainConfig.publicClient,
883
+ environment: this.environment
884
+ });
885
+ const alreadyDeployed = await isSafeDeployed(
886
+ safeAddress,
887
+ chainConfig.publicClient
888
+ );
889
+ if (alreadyDeployed) {
890
+ return {
891
+ success: true,
892
+ safeAddress,
893
+ txHash: "0x0",
894
+ status: "deployed",
895
+ alreadyDeployed: true
896
+ };
897
+ }
878
898
  const accountType = await getAccountType(
879
899
  userAddress,
880
900
  chainConfig.publicClient
@@ -1456,11 +1476,11 @@ var ZyfaiSDK = class {
1456
1476
  *
1457
1477
  * @example
1458
1478
  * ```typescript
1459
- * const result = await sdk.getSmartWalletsByEOA("0x...");
1479
+ * const result = await sdk.getSmartWalletByEOA("0x...");
1460
1480
  * console.log("Smart wallets:", result.smartWallets);
1461
1481
  * ```
1462
1482
  */
1463
- async getSmartWalletsByEOA(eoaAddress) {
1483
+ async getSmartWalletByEOA(eoaAddress) {
1464
1484
  try {
1465
1485
  if (!eoaAddress) {
1466
1486
  throw new Error("EOA address is required");
@@ -1468,14 +1488,12 @@ var ZyfaiSDK = class {
1468
1488
  const response = await this.httpClient.get(
1469
1489
  ENDPOINTS.DATA_BY_EOA(eoaAddress)
1470
1490
  );
1471
- const smartWallet = response.agent || response.smartWallet || response.smartWallets?.[0];
1472
- const smartWallets = smartWallet ? [smartWallet] : [];
1491
+ const smartWallet = response.agent || null;
1473
1492
  const chains = response.chains || [];
1474
1493
  return {
1475
1494
  success: true,
1476
1495
  eoa: eoaAddress,
1477
- smartWallet: smartWallet || null,
1478
- smartWallets,
1496
+ smartWallet,
1479
1497
  chains
1480
1498
  };
1481
1499
  } catch (error) {
package/dist/index.mjs CHANGED
@@ -393,7 +393,7 @@ var SAFE_7579_ADDRESS = "0x7579EE8307284F293B1927136486880611F20002";
393
393
  var ERC7579_LAUNCHPAD_ADDRESS = "0x7579011aB74c46090561ea277Ba79D510c6C00ff";
394
394
  var ACCOUNT_SALTS = {
395
395
  staging: "zyfai-staging",
396
- production: "zyfai-production"
396
+ production: "zyfai"
397
397
  };
398
398
  var getSafeAccount = async (config) => {
399
399
  const {
@@ -419,8 +419,8 @@ var getSafeAccount = async (config) => {
419
419
  const saltHex = fromHex(toHex(effectiveSalt), "bigint");
420
420
  const safeAccount = await toSafeSmartAccount({
421
421
  client: publicClient,
422
- owners: [owner.account],
423
- // Pass the account object with address and signMessage capability
422
+ owners: [owner],
423
+ // Pass the owner object with address and signMessage capability
424
424
  version: "1.4.1",
425
425
  entryPoint: {
426
426
  address: entryPoint07Address,
@@ -491,7 +491,7 @@ var getAccountType = async (address, publicClient) => {
491
491
  }
492
492
  };
493
493
  var getSmartAccountClient = async (config) => {
494
- const { publicClient, chain, bundlerUrl } = config;
494
+ const { chain, bundlerUrl } = config;
495
495
  const safeAccount = await getSafeAccount(config);
496
496
  const bundlerClient = createPimlicoClient({
497
497
  transport: http2(bundlerUrl),
@@ -854,6 +854,26 @@ var ZyfaiSDK = class {
854
854
  }
855
855
  const walletClient = this.getWalletClient(chainId);
856
856
  const chainConfig = getChainConfig(chainId);
857
+ const safeAddress = await getDeterministicSafeAddress({
858
+ owner: walletClient,
859
+ safeOwnerAddress: userAddress,
860
+ chain: chainConfig.chain,
861
+ publicClient: chainConfig.publicClient,
862
+ environment: this.environment
863
+ });
864
+ const alreadyDeployed = await isSafeDeployed(
865
+ safeAddress,
866
+ chainConfig.publicClient
867
+ );
868
+ if (alreadyDeployed) {
869
+ return {
870
+ success: true,
871
+ safeAddress,
872
+ txHash: "0x0",
873
+ status: "deployed",
874
+ alreadyDeployed: true
875
+ };
876
+ }
857
877
  const accountType = await getAccountType(
858
878
  userAddress,
859
879
  chainConfig.publicClient
@@ -1435,11 +1455,11 @@ var ZyfaiSDK = class {
1435
1455
  *
1436
1456
  * @example
1437
1457
  * ```typescript
1438
- * const result = await sdk.getSmartWalletsByEOA("0x...");
1458
+ * const result = await sdk.getSmartWalletByEOA("0x...");
1439
1459
  * console.log("Smart wallets:", result.smartWallets);
1440
1460
  * ```
1441
1461
  */
1442
- async getSmartWalletsByEOA(eoaAddress) {
1462
+ async getSmartWalletByEOA(eoaAddress) {
1443
1463
  try {
1444
1464
  if (!eoaAddress) {
1445
1465
  throw new Error("EOA address is required");
@@ -1447,14 +1467,12 @@ var ZyfaiSDK = class {
1447
1467
  const response = await this.httpClient.get(
1448
1468
  ENDPOINTS.DATA_BY_EOA(eoaAddress)
1449
1469
  );
1450
- const smartWallet = response.agent || response.smartWallet || response.smartWallets?.[0];
1451
- const smartWallets = smartWallet ? [smartWallet] : [];
1470
+ const smartWallet = response.agent || null;
1452
1471
  const chains = response.chains || [];
1453
1472
  return {
1454
1473
  success: true,
1455
1474
  eoa: eoaAddress,
1456
- smartWallet: smartWallet || null,
1457
- smartWallets,
1475
+ smartWallet,
1458
1476
  chains
1459
1477
  };
1460
1478
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zyfai/sdk",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
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",