@zyfai/sdk 0.1.19 → 0.1.21

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
@@ -342,14 +342,16 @@ console.log("User ID:", result.userId);
342
342
 
343
343
  ### 4. Deposit Funds
344
344
 
345
- Transfer tokens to your Safe smart wallet:
345
+ Transfer tokens to your Safe smart wallet. Token address is automatically selected based on chain:
346
+
347
+ - **Base (8453) and Arbitrum (42161)**: USDC
348
+ - **Plasma (9745)**: USDT
346
349
 
347
350
  ```typescript
348
351
  // Deposit 100 USDC (6 decimals) to Safe on Base
349
352
  const result = await sdk.depositFunds(
350
353
  userAddress,
351
354
  8453, // Chain ID
352
- "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // USDC on Base
353
355
  "100000000" // Amount: 100 USDC = 100 * 10^6
354
356
  );
355
357
 
@@ -359,8 +361,11 @@ if (result.success) {
359
361
  }
360
362
  ```
361
363
 
362
- **Note:** Amount must be in least decimal units. For USDC (6 decimals): 1 USDC = 1000000
363
- 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.
364
+ **Note:**
365
+
366
+ - Amount must be in least decimal units. For USDC (6 decimals): 1 USDC = 1000000
367
+ - Token address is automatically selected based on chain (USDC for Base/Arbitrum, USDT for Plasma)
368
+ - 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
364
369
 
365
370
  ### 5. Withdraw Funds
366
371
 
package/dist/index.d.mts CHANGED
@@ -388,6 +388,8 @@ interface ChainConfig {
388
388
  rpcUrl: string;
389
389
  publicClient: PublicClient;
390
390
  }
391
+ declare const DEFAULT_TOKEN_ADDRESSES: Record<SupportedChainId, string>;
392
+ declare const getDefaultTokenAddress: (chainId: SupportedChainId) => string;
391
393
  /**
392
394
  * Get chain configuration for a given chain ID
393
395
  */
@@ -553,9 +555,12 @@ declare class ZyfaiSDK {
553
555
  * Deposit funds from EOA to Safe smart wallet
554
556
  * Transfers tokens from the connected wallet to the user's Safe and logs the deposit
555
557
  *
558
+ * Token is automatically selected based on chain:
559
+ * - Base (8453) and Arbitrum (42161): USDC
560
+ * - Plasma (9745): USDT
561
+ *
556
562
  * @param userAddress - User's address (owner of the Safe)
557
563
  * @param chainId - Target chain ID
558
- * @param tokenAddress - Token contract address to deposit
559
564
  * @param amount - Amount in least decimal units (e.g., "100000000" for 100 USDC with 6 decimals)
560
565
  * @returns Deposit response with transaction hash
561
566
  *
@@ -565,12 +570,11 @@ declare class ZyfaiSDK {
565
570
  * const result = await sdk.depositFunds(
566
571
  * "0xUser...",
567
572
  * 8453,
568
- * "0xaf88d065e77c8cc2239327c5edb3a432268e5831", // USDC
569
573
  * "100000000" // 100 USDC = 100 * 10^6
570
574
  * );
571
575
  * ```
572
576
  */
573
- depositFunds(userAddress: string, chainId: SupportedChainId, tokenAddress: string, amount: string): Promise<DepositResponse>;
577
+ depositFunds(userAddress: string, chainId: SupportedChainId, amount: string): Promise<DepositResponse>;
574
578
  /**
575
579
  * Withdraw funds from Safe smart wallet
576
580
  * Initiates a withdrawal request to the ZyFAI API
@@ -857,4 +861,4 @@ declare class ZyfaiSDK {
857
861
  getRebalanceFrequency(walletAddress: string): Promise<RebalanceFrequencyResponse>;
858
862
  }
859
863
 
860
- export { type ActionData, type ActiveWallet, type ActiveWalletsResponse, type AddWalletToSdkResponse, 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 };
864
+ export { type ActionData, type ActiveWallet, type ActiveWalletsResponse, type AddWalletToSdkResponse, type Address, type ChainConfig, type ChainPortfolio, DEFAULT_TOKEN_ADDRESSES, 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, getDefaultTokenAddress, getSupportedChainIds, isSupportedChain };
package/dist/index.d.ts CHANGED
@@ -388,6 +388,8 @@ interface ChainConfig {
388
388
  rpcUrl: string;
389
389
  publicClient: PublicClient;
390
390
  }
391
+ declare const DEFAULT_TOKEN_ADDRESSES: Record<SupportedChainId, string>;
392
+ declare const getDefaultTokenAddress: (chainId: SupportedChainId) => string;
391
393
  /**
392
394
  * Get chain configuration for a given chain ID
393
395
  */
@@ -553,9 +555,12 @@ declare class ZyfaiSDK {
553
555
  * Deposit funds from EOA to Safe smart wallet
554
556
  * Transfers tokens from the connected wallet to the user's Safe and logs the deposit
555
557
  *
558
+ * Token is automatically selected based on chain:
559
+ * - Base (8453) and Arbitrum (42161): USDC
560
+ * - Plasma (9745): USDT
561
+ *
556
562
  * @param userAddress - User's address (owner of the Safe)
557
563
  * @param chainId - Target chain ID
558
- * @param tokenAddress - Token contract address to deposit
559
564
  * @param amount - Amount in least decimal units (e.g., "100000000" for 100 USDC with 6 decimals)
560
565
  * @returns Deposit response with transaction hash
561
566
  *
@@ -565,12 +570,11 @@ declare class ZyfaiSDK {
565
570
  * const result = await sdk.depositFunds(
566
571
  * "0xUser...",
567
572
  * 8453,
568
- * "0xaf88d065e77c8cc2239327c5edb3a432268e5831", // USDC
569
573
  * "100000000" // 100 USDC = 100 * 10^6
570
574
  * );
571
575
  * ```
572
576
  */
573
- depositFunds(userAddress: string, chainId: SupportedChainId, tokenAddress: string, amount: string): Promise<DepositResponse>;
577
+ depositFunds(userAddress: string, chainId: SupportedChainId, amount: string): Promise<DepositResponse>;
574
578
  /**
575
579
  * Withdraw funds from Safe smart wallet
576
580
  * Initiates a withdrawal request to the ZyFAI API
@@ -857,4 +861,4 @@ declare class ZyfaiSDK {
857
861
  getRebalanceFrequency(walletAddress: string): Promise<RebalanceFrequencyResponse>;
858
862
  }
859
863
 
860
- export { type ActionData, type ActiveWallet, type ActiveWalletsResponse, type AddWalletToSdkResponse, 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 };
864
+ export { type ActionData, type ActiveWallet, type ActiveWalletsResponse, type AddWalletToSdkResponse, type Address, type ChainConfig, type ChainPortfolio, DEFAULT_TOKEN_ADDRESSES, 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, getDefaultTokenAddress, getSupportedChainIds, isSupportedChain };
package/dist/index.js CHANGED
@@ -30,8 +30,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
+ DEFAULT_TOKEN_ADDRESSES: () => DEFAULT_TOKEN_ADDRESSES,
33
34
  ZyfaiSDK: () => ZyfaiSDK,
34
35
  getChainConfig: () => getChainConfig,
36
+ getDefaultTokenAddress: () => getDefaultTokenAddress,
35
37
  getSupportedChainIds: () => getSupportedChainIds,
36
38
  isSupportedChain: () => isSupportedChain
37
39
  });
@@ -382,6 +384,23 @@ var plasma = (0, import_viem2.defineChain)({
382
384
  }
383
385
  }
384
386
  });
387
+ var DEFAULT_TOKEN_ADDRESSES = {
388
+ 8453: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
389
+ // USDC on Base
390
+ 42161: "0xaf88d065e77c8cc2239327c5edb3a432268e5831",
391
+ // USDC on Arbitrum
392
+ 9745: "0xB8CE59FC3717ada4C02eaDF9682A9e934F625ebb"
393
+ // USDT on Plasma
394
+ };
395
+ var getDefaultTokenAddress = (chainId) => {
396
+ const address = DEFAULT_TOKEN_ADDRESSES[chainId];
397
+ if (!address || address === "0x0000000000000000000000000000000000000000") {
398
+ throw new Error(
399
+ `Default token address not configured for chain ${chainId}. Please provide tokenAddress explicitly.`
400
+ );
401
+ }
402
+ return address;
403
+ };
385
404
  var DEFAULT_RPC_URLS = {
386
405
  8453: "https://mainnet.base.org",
387
406
  42161: "https://arb1.arbitrum.io/rpc",
@@ -436,12 +455,98 @@ var import_pimlico = require("permissionless/clients/pimlico");
436
455
  var import_accounts = require("permissionless/accounts");
437
456
  var import_viem3 = require("viem");
438
457
  var import_account_abstraction = require("viem/account-abstraction");
458
+ var import_actions = require("permissionless/actions");
459
+ var import_account_abstraction2 = require("viem/account-abstraction");
439
460
  var SAFE_7579_ADDRESS = "0x7579EE8307284F293B1927136486880611F20002";
440
461
  var ERC7579_LAUNCHPAD_ADDRESS = "0x7579011aB74c46090561ea277Ba79D510c6C00ff";
441
462
  var ACCOUNT_SALTS = {
442
463
  staging: "zyfai-staging",
443
464
  production: "zyfai"
444
465
  };
466
+ var MODULE_TYPE_IDS = {
467
+ validator: 1n,
468
+ executor: 2n,
469
+ fallback: 3n,
470
+ hook: 4n
471
+ };
472
+ var SMART_SESSIONS_FALLBACK = {
473
+ module: "0x12cae64c42f362e7d5a847c2d33388373f629177",
474
+ address: "0x12cae64c42f362e7d5a847c2d33388373f629177",
475
+ type: "fallback",
476
+ selector: (0, import_viem3.encodeAbiParameters)(
477
+ [{ name: "functionSignature", type: "bytes4" }],
478
+ ["0x84b0196e"]
479
+ ),
480
+ initData: "0x84b0196e00000000000000000000000000000000000000000000000000000000fe0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000"
481
+ };
482
+ var INTENT_EXECUTOR = {
483
+ address: "0x00000000005aD9ce1f5035FD62CA96CEf16AdAAF",
484
+ type: "executor",
485
+ initData: "0x"
486
+ };
487
+ var PROXY_EXECUTOR = {
488
+ address: "0xF659d30D4EB88B06A909F20839D8959Bd77d8790",
489
+ type: "executor",
490
+ initData: "0x"
491
+ };
492
+ var getModulesToInstall = (chainId) => {
493
+ const smartSessions = (0, import_module_sdk.getSmartSessionsValidator)({});
494
+ const accountLockerHook = (0, import_module_sdk.getAccountLockerHook)({ isOmniMode: true });
495
+ const accountLockerSourceExecutor = (0, import_module_sdk.getAccountLockerSourceExecutor)();
496
+ const accountLockerTargetExecutor = (0, import_module_sdk.getAccountLockerTargetExecutor)();
497
+ if (chainId === 9745) {
498
+ return [
499
+ smartSessions,
500
+ SMART_SESSIONS_FALLBACK,
501
+ INTENT_EXECUTOR,
502
+ PROXY_EXECUTOR
503
+ ];
504
+ }
505
+ return [
506
+ smartSessions,
507
+ {
508
+ ...accountLockerHook,
509
+ type: "executor"
510
+ },
511
+ accountLockerSourceExecutor,
512
+ accountLockerTargetExecutor,
513
+ SMART_SESSIONS_FALLBACK,
514
+ INTENT_EXECUTOR,
515
+ PROXY_EXECUTOR
516
+ ];
517
+ };
518
+ var getInstallModuleCallData = (module2) => {
519
+ return (0, import_viem3.encodeFunctionData)({
520
+ abi: [
521
+ {
522
+ type: "function",
523
+ name: "installModule",
524
+ inputs: [
525
+ {
526
+ type: "uint256",
527
+ name: "moduleTypeId"
528
+ },
529
+ {
530
+ type: "address",
531
+ name: "module"
532
+ },
533
+ {
534
+ type: "bytes",
535
+ name: "initData"
536
+ }
537
+ ],
538
+ outputs: [],
539
+ stateMutability: "nonpayable"
540
+ }
541
+ ],
542
+ functionName: "installModule",
543
+ args: [
544
+ MODULE_TYPE_IDS[module2.type],
545
+ module2.address,
546
+ module2.initData || "0x"
547
+ ]
548
+ });
549
+ };
445
550
  var getSafeAccount = async (config) => {
446
551
  const {
447
552
  owner,
@@ -592,7 +697,7 @@ var getSmartAccountClient = async (config) => {
592
697
  };
593
698
  var deploySafeAccount = async (config) => {
594
699
  try {
595
- const { owner, publicClient } = config;
700
+ const { owner, publicClient, chainId } = config;
596
701
  if (!owner || !owner.account) {
597
702
  throw new Error(
598
703
  "Wallet not connected. Please connect your wallet first."
@@ -606,24 +711,61 @@ var deploySafeAccount = async (config) => {
606
711
  isDeployed: true
607
712
  };
608
713
  }
714
+ const modulesToInstall = getModulesToInstall(chainId);
715
+ const installCalls = modulesToInstall.map((module2) => ({
716
+ to: safeAddress,
717
+ data: getInstallModuleCallData(module2)
718
+ }));
609
719
  const smartAccountClient = await getSmartAccountClient(config);
610
- const userOpHash = await smartAccountClient.sendUserOperation({
611
- calls: [
612
- {
613
- to: safeAddress,
614
- value: BigInt(0),
615
- data: "0x"
616
- }
617
- ]
720
+ const safeAccount = await getSafeAccount(config);
721
+ const ownableValidator = (0, import_module_sdk.getOwnableValidator)({
722
+ owners: [owner.account.address],
723
+ threshold: 1
618
724
  });
619
- const receipt = await smartAccountClient.waitForUserOperationReceipt({
620
- hash: userOpHash
725
+ const nonce = await (0, import_actions.getAccountNonce)(publicClient, {
726
+ address: safeAddress,
727
+ entryPointAddress: import_account_abstraction.entryPoint07Address,
728
+ key: BigInt(
729
+ (0, import_viem3.pad)(ownableValidator.address, {
730
+ dir: "right",
731
+ size: 24
732
+ }) || 0
733
+ )
621
734
  });
622
- return {
623
- safeAddress,
624
- txHash: receipt.receipt.transactionHash,
625
- isDeployed: true
626
- };
735
+ const userOperation = await smartAccountClient.prepareUserOperation({
736
+ account: safeAccount,
737
+ calls: installCalls,
738
+ nonce
739
+ });
740
+ const userOpHashToSign = (0, import_account_abstraction2.getUserOperationHash)({
741
+ chainId,
742
+ entryPointAddress: import_account_abstraction.entryPoint07Address,
743
+ entryPointVersion: "0.7",
744
+ userOperation
745
+ });
746
+ if (!owner.account) {
747
+ throw new Error("Owner account is required for signing");
748
+ }
749
+ userOperation.signature = await owner.signMessage({
750
+ account: owner.account,
751
+ message: { raw: userOpHashToSign }
752
+ });
753
+ const userOpHash = await smartAccountClient.sendUserOperation(
754
+ userOperation
755
+ );
756
+ try {
757
+ const transaction = await smartAccountClient.waitForUserOperationReceipt({
758
+ hash: userOpHash
759
+ });
760
+ return {
761
+ safeAddress,
762
+ txHash: transaction.receipt.transactionHash,
763
+ isDeployed: true
764
+ };
765
+ } catch (error) {
766
+ console.error("Transaction failed:", error);
767
+ throw new Error("Failed to execute transaction");
768
+ }
627
769
  } catch (error) {
628
770
  throw new Error(
629
771
  `Failed to deploy Safe account: ${error.message}`
@@ -1109,7 +1251,8 @@ var ZyfaiSDK = class {
1109
1251
  chain: chainConfig.chain,
1110
1252
  publicClient: chainConfig.publicClient,
1111
1253
  bundlerUrl,
1112
- environment: this.environment
1254
+ environment: this.environment,
1255
+ chainId
1113
1256
  });
1114
1257
  try {
1115
1258
  await this.updateUserProfile({
@@ -1348,9 +1491,12 @@ var ZyfaiSDK = class {
1348
1491
  * Deposit funds from EOA to Safe smart wallet
1349
1492
  * Transfers tokens from the connected wallet to the user's Safe and logs the deposit
1350
1493
  *
1494
+ * Token is automatically selected based on chain:
1495
+ * - Base (8453) and Arbitrum (42161): USDC
1496
+ * - Plasma (9745): USDT
1497
+ *
1351
1498
  * @param userAddress - User's address (owner of the Safe)
1352
1499
  * @param chainId - Target chain ID
1353
- * @param tokenAddress - Token contract address to deposit
1354
1500
  * @param amount - Amount in least decimal units (e.g., "100000000" for 100 USDC with 6 decimals)
1355
1501
  * @returns Deposit response with transaction hash
1356
1502
  *
@@ -1360,12 +1506,11 @@ var ZyfaiSDK = class {
1360
1506
  * const result = await sdk.depositFunds(
1361
1507
  * "0xUser...",
1362
1508
  * 8453,
1363
- * "0xaf88d065e77c8cc2239327c5edb3a432268e5831", // USDC
1364
1509
  * "100000000" // 100 USDC = 100 * 10^6
1365
1510
  * );
1366
1511
  * ```
1367
1512
  */
1368
- async depositFunds(userAddress, chainId, tokenAddress, amount) {
1513
+ async depositFunds(userAddress, chainId, amount) {
1369
1514
  try {
1370
1515
  if (!userAddress) {
1371
1516
  throw new Error("User address is required");
@@ -1373,12 +1518,10 @@ var ZyfaiSDK = class {
1373
1518
  if (!isSupportedChain(chainId)) {
1374
1519
  throw new Error(`Unsupported chain ID: ${chainId}`);
1375
1520
  }
1376
- if (!tokenAddress) {
1377
- throw new Error("Token address is required");
1378
- }
1379
1521
  if (!amount || isNaN(Number(amount)) || Number(amount) <= 0) {
1380
1522
  throw new Error("Valid amount is required");
1381
1523
  }
1524
+ const token = getDefaultTokenAddress(chainId);
1382
1525
  const walletClient = this.getWalletClient();
1383
1526
  const chainConfig = getChainConfig(chainId);
1384
1527
  const safeAddress = await getDeterministicSafeAddress({
@@ -1399,7 +1542,7 @@ var ZyfaiSDK = class {
1399
1542
  }
1400
1543
  const amountBigInt = BigInt(amount);
1401
1544
  const txHash = await walletClient.writeContract({
1402
- address: tokenAddress,
1545
+ address: token,
1403
1546
  abi: ERC20_ABI,
1404
1547
  functionName: "transfer",
1405
1548
  args: [safeAddress, amountBigInt],
@@ -2218,8 +2361,10 @@ var ZyfaiSDK = class {
2218
2361
  };
2219
2362
  // Annotate the CommonJS export names for ESM import in node:
2220
2363
  0 && (module.exports = {
2364
+ DEFAULT_TOKEN_ADDRESSES,
2221
2365
  ZyfaiSDK,
2222
2366
  getChainConfig,
2367
+ getDefaultTokenAddress,
2223
2368
  getSupportedChainIds,
2224
2369
  isSupportedChain
2225
2370
  });
package/dist/index.mjs CHANGED
@@ -348,6 +348,23 @@ var plasma = defineChain({
348
348
  }
349
349
  }
350
350
  });
351
+ var DEFAULT_TOKEN_ADDRESSES = {
352
+ 8453: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
353
+ // USDC on Base
354
+ 42161: "0xaf88d065e77c8cc2239327c5edb3a432268e5831",
355
+ // USDC on Arbitrum
356
+ 9745: "0xB8CE59FC3717ada4C02eaDF9682A9e934F625ebb"
357
+ // USDT on Plasma
358
+ };
359
+ var getDefaultTokenAddress = (chainId) => {
360
+ const address = DEFAULT_TOKEN_ADDRESSES[chainId];
361
+ if (!address || address === "0x0000000000000000000000000000000000000000") {
362
+ throw new Error(
363
+ `Default token address not configured for chain ${chainId}. Please provide tokenAddress explicitly.`
364
+ );
365
+ }
366
+ return address;
367
+ };
351
368
  var DEFAULT_RPC_URLS = {
352
369
  8453: "https://mainnet.base.org",
353
370
  42161: "https://arb1.arbitrum.io/rpc",
@@ -401,7 +418,11 @@ import {
401
418
  getAccount,
402
419
  getEnableSessionDetails,
403
420
  getPermissionId,
404
- getSessionNonce
421
+ getSessionNonce,
422
+ getSmartSessionsValidator,
423
+ getAccountLockerHook,
424
+ getAccountLockerSourceExecutor,
425
+ getAccountLockerTargetExecutor
405
426
  } from "@rhinestone/module-sdk";
406
427
  import { createSmartAccountClient } from "permissionless";
407
428
  import { erc7579Actions } from "permissionless/actions/erc7579";
@@ -410,18 +431,107 @@ import { toSafeSmartAccount } from "permissionless/accounts";
410
431
  import {
411
432
  http as http2,
412
433
  getAddress,
434
+ encodeFunctionData,
413
435
  fromHex,
414
- toHex
436
+ toHex,
437
+ encodeAbiParameters,
438
+ pad
415
439
  } from "viem";
416
440
  import {
417
441
  entryPoint07Address
418
442
  } from "viem/account-abstraction";
443
+ import { getAccountNonce } from "permissionless/actions";
444
+ import { getUserOperationHash } from "viem/account-abstraction";
419
445
  var SAFE_7579_ADDRESS = "0x7579EE8307284F293B1927136486880611F20002";
420
446
  var ERC7579_LAUNCHPAD_ADDRESS = "0x7579011aB74c46090561ea277Ba79D510c6C00ff";
421
447
  var ACCOUNT_SALTS = {
422
448
  staging: "zyfai-staging",
423
449
  production: "zyfai"
424
450
  };
451
+ var MODULE_TYPE_IDS = {
452
+ validator: 1n,
453
+ executor: 2n,
454
+ fallback: 3n,
455
+ hook: 4n
456
+ };
457
+ var SMART_SESSIONS_FALLBACK = {
458
+ module: "0x12cae64c42f362e7d5a847c2d33388373f629177",
459
+ address: "0x12cae64c42f362e7d5a847c2d33388373f629177",
460
+ type: "fallback",
461
+ selector: encodeAbiParameters(
462
+ [{ name: "functionSignature", type: "bytes4" }],
463
+ ["0x84b0196e"]
464
+ ),
465
+ initData: "0x84b0196e00000000000000000000000000000000000000000000000000000000fe0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000"
466
+ };
467
+ var INTENT_EXECUTOR = {
468
+ address: "0x00000000005aD9ce1f5035FD62CA96CEf16AdAAF",
469
+ type: "executor",
470
+ initData: "0x"
471
+ };
472
+ var PROXY_EXECUTOR = {
473
+ address: "0xF659d30D4EB88B06A909F20839D8959Bd77d8790",
474
+ type: "executor",
475
+ initData: "0x"
476
+ };
477
+ var getModulesToInstall = (chainId) => {
478
+ const smartSessions = getSmartSessionsValidator({});
479
+ const accountLockerHook = getAccountLockerHook({ isOmniMode: true });
480
+ const accountLockerSourceExecutor = getAccountLockerSourceExecutor();
481
+ const accountLockerTargetExecutor = getAccountLockerTargetExecutor();
482
+ if (chainId === 9745) {
483
+ return [
484
+ smartSessions,
485
+ SMART_SESSIONS_FALLBACK,
486
+ INTENT_EXECUTOR,
487
+ PROXY_EXECUTOR
488
+ ];
489
+ }
490
+ return [
491
+ smartSessions,
492
+ {
493
+ ...accountLockerHook,
494
+ type: "executor"
495
+ },
496
+ accountLockerSourceExecutor,
497
+ accountLockerTargetExecutor,
498
+ SMART_SESSIONS_FALLBACK,
499
+ INTENT_EXECUTOR,
500
+ PROXY_EXECUTOR
501
+ ];
502
+ };
503
+ var getInstallModuleCallData = (module) => {
504
+ return encodeFunctionData({
505
+ abi: [
506
+ {
507
+ type: "function",
508
+ name: "installModule",
509
+ inputs: [
510
+ {
511
+ type: "uint256",
512
+ name: "moduleTypeId"
513
+ },
514
+ {
515
+ type: "address",
516
+ name: "module"
517
+ },
518
+ {
519
+ type: "bytes",
520
+ name: "initData"
521
+ }
522
+ ],
523
+ outputs: [],
524
+ stateMutability: "nonpayable"
525
+ }
526
+ ],
527
+ functionName: "installModule",
528
+ args: [
529
+ MODULE_TYPE_IDS[module.type],
530
+ module.address,
531
+ module.initData || "0x"
532
+ ]
533
+ });
534
+ };
425
535
  var getSafeAccount = async (config) => {
426
536
  const {
427
537
  owner,
@@ -572,7 +682,7 @@ var getSmartAccountClient = async (config) => {
572
682
  };
573
683
  var deploySafeAccount = async (config) => {
574
684
  try {
575
- const { owner, publicClient } = config;
685
+ const { owner, publicClient, chainId } = config;
576
686
  if (!owner || !owner.account) {
577
687
  throw new Error(
578
688
  "Wallet not connected. Please connect your wallet first."
@@ -586,24 +696,61 @@ var deploySafeAccount = async (config) => {
586
696
  isDeployed: true
587
697
  };
588
698
  }
699
+ const modulesToInstall = getModulesToInstall(chainId);
700
+ const installCalls = modulesToInstall.map((module) => ({
701
+ to: safeAddress,
702
+ data: getInstallModuleCallData(module)
703
+ }));
589
704
  const smartAccountClient = await getSmartAccountClient(config);
590
- const userOpHash = await smartAccountClient.sendUserOperation({
591
- calls: [
592
- {
593
- to: safeAddress,
594
- value: BigInt(0),
595
- data: "0x"
596
- }
597
- ]
705
+ const safeAccount = await getSafeAccount(config);
706
+ const ownableValidator = getOwnableValidator({
707
+ owners: [owner.account.address],
708
+ threshold: 1
598
709
  });
599
- const receipt = await smartAccountClient.waitForUserOperationReceipt({
600
- hash: userOpHash
710
+ const nonce = await getAccountNonce(publicClient, {
711
+ address: safeAddress,
712
+ entryPointAddress: entryPoint07Address,
713
+ key: BigInt(
714
+ pad(ownableValidator.address, {
715
+ dir: "right",
716
+ size: 24
717
+ }) || 0
718
+ )
601
719
  });
602
- return {
603
- safeAddress,
604
- txHash: receipt.receipt.transactionHash,
605
- isDeployed: true
606
- };
720
+ const userOperation = await smartAccountClient.prepareUserOperation({
721
+ account: safeAccount,
722
+ calls: installCalls,
723
+ nonce
724
+ });
725
+ const userOpHashToSign = getUserOperationHash({
726
+ chainId,
727
+ entryPointAddress: entryPoint07Address,
728
+ entryPointVersion: "0.7",
729
+ userOperation
730
+ });
731
+ if (!owner.account) {
732
+ throw new Error("Owner account is required for signing");
733
+ }
734
+ userOperation.signature = await owner.signMessage({
735
+ account: owner.account,
736
+ message: { raw: userOpHashToSign }
737
+ });
738
+ const userOpHash = await smartAccountClient.sendUserOperation(
739
+ userOperation
740
+ );
741
+ try {
742
+ const transaction = await smartAccountClient.waitForUserOperationReceipt({
743
+ hash: userOpHash
744
+ });
745
+ return {
746
+ safeAddress,
747
+ txHash: transaction.receipt.transactionHash,
748
+ isDeployed: true
749
+ };
750
+ } catch (error) {
751
+ console.error("Transaction failed:", error);
752
+ throw new Error("Failed to execute transaction");
753
+ }
607
754
  } catch (error) {
608
755
  throw new Error(
609
756
  `Failed to deploy Safe account: ${error.message}`
@@ -1089,7 +1236,8 @@ var ZyfaiSDK = class {
1089
1236
  chain: chainConfig.chain,
1090
1237
  publicClient: chainConfig.publicClient,
1091
1238
  bundlerUrl,
1092
- environment: this.environment
1239
+ environment: this.environment,
1240
+ chainId
1093
1241
  });
1094
1242
  try {
1095
1243
  await this.updateUserProfile({
@@ -1328,9 +1476,12 @@ var ZyfaiSDK = class {
1328
1476
  * Deposit funds from EOA to Safe smart wallet
1329
1477
  * Transfers tokens from the connected wallet to the user's Safe and logs the deposit
1330
1478
  *
1479
+ * Token is automatically selected based on chain:
1480
+ * - Base (8453) and Arbitrum (42161): USDC
1481
+ * - Plasma (9745): USDT
1482
+ *
1331
1483
  * @param userAddress - User's address (owner of the Safe)
1332
1484
  * @param chainId - Target chain ID
1333
- * @param tokenAddress - Token contract address to deposit
1334
1485
  * @param amount - Amount in least decimal units (e.g., "100000000" for 100 USDC with 6 decimals)
1335
1486
  * @returns Deposit response with transaction hash
1336
1487
  *
@@ -1340,12 +1491,11 @@ var ZyfaiSDK = class {
1340
1491
  * const result = await sdk.depositFunds(
1341
1492
  * "0xUser...",
1342
1493
  * 8453,
1343
- * "0xaf88d065e77c8cc2239327c5edb3a432268e5831", // USDC
1344
1494
  * "100000000" // 100 USDC = 100 * 10^6
1345
1495
  * );
1346
1496
  * ```
1347
1497
  */
1348
- async depositFunds(userAddress, chainId, tokenAddress, amount) {
1498
+ async depositFunds(userAddress, chainId, amount) {
1349
1499
  try {
1350
1500
  if (!userAddress) {
1351
1501
  throw new Error("User address is required");
@@ -1353,12 +1503,10 @@ var ZyfaiSDK = class {
1353
1503
  if (!isSupportedChain(chainId)) {
1354
1504
  throw new Error(`Unsupported chain ID: ${chainId}`);
1355
1505
  }
1356
- if (!tokenAddress) {
1357
- throw new Error("Token address is required");
1358
- }
1359
1506
  if (!amount || isNaN(Number(amount)) || Number(amount) <= 0) {
1360
1507
  throw new Error("Valid amount is required");
1361
1508
  }
1509
+ const token = getDefaultTokenAddress(chainId);
1362
1510
  const walletClient = this.getWalletClient();
1363
1511
  const chainConfig = getChainConfig(chainId);
1364
1512
  const safeAddress = await getDeterministicSafeAddress({
@@ -1379,7 +1527,7 @@ var ZyfaiSDK = class {
1379
1527
  }
1380
1528
  const amountBigInt = BigInt(amount);
1381
1529
  const txHash = await walletClient.writeContract({
1382
- address: tokenAddress,
1530
+ address: token,
1383
1531
  abi: ERC20_ABI,
1384
1532
  functionName: "transfer",
1385
1533
  args: [safeAddress, amountBigInt],
@@ -2197,8 +2345,10 @@ var ZyfaiSDK = class {
2197
2345
  }
2198
2346
  };
2199
2347
  export {
2348
+ DEFAULT_TOKEN_ADDRESSES,
2200
2349
  ZyfaiSDK,
2201
2350
  getChainConfig,
2351
+ getDefaultTokenAddress,
2202
2352
  getSupportedChainIds,
2203
2353
  isSupportedChain
2204
2354
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zyfai/sdk",
3
- "version": "0.1.19",
3
+ "version": "0.1.21",
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",