@zyfai/sdk 0.1.13 → 0.1.15

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
@@ -40,8 +40,7 @@ pnpm add @zyfai/sdk viem
40
40
  import { ZyfaiSDK } from "@zyfai/sdk";
41
41
 
42
42
  const sdk = new ZyfaiSDK({
43
- apiKey: "your-execution-api-key", // Execution API (transactions, Safe deployment)
44
- dataApiKey: "your-data-api-key", // Data API (analytics, earnings, opportunities)
43
+ apiKey: "your-api-key", // API key for both Execution API and Data API
45
44
  bundlerApiKey: "your-bundler-api-key", // Required for Safe deployment
46
45
  environment: "production", // or 'staging' (default: 'production')
47
46
  });
@@ -49,12 +48,11 @@ const sdk = new ZyfaiSDK({
49
48
 
50
49
  **Configuration Options:**
51
50
 
52
- | Option | Required | Description |
53
- | --------------- | -------- | ----------------------------------------------------------------------------------------------- |
54
- | `apiKey` | Yes | API key for Execution API (Safe deployment, transactions, session keys) |
55
- | `dataApiKey` | No | API key for Data API (earnings, opportunities, analytics). Defaults to `apiKey` if not provided |
56
- | `bundlerApiKey` | No\* | Pimlico API key for Safe deployment (\*required for `deploySafe`) |
57
- | `environment` | No | `"production"` or `"staging"` (default: `"production"`) |
51
+ | Option | Required | Description |
52
+ | --------------- | -------- | ---------------------------------------------------------------------------------------------------- |
53
+ | `apiKey` | Yes | API key for both Execution API and Data API (Safe deployment, transactions, session keys, analytics) |
54
+ | `bundlerApiKey` | No\* | Pimlico API key for Safe deployment (\*required for `deploySafe`) |
55
+ | `environment` | No | `"production"` or `"staging"` (default: `"production"`) |
58
56
 
59
57
  **API Endpoints by Environment:**
60
58
 
@@ -69,7 +67,7 @@ The SDK accepts either a private key or a modern wallet provider. **The SDK auto
69
67
 
70
68
  ```typescript
71
69
  // Option 1: With private key (chainId required)
72
- await sdk.connectAccount("0x...", 42161);
70
+ await sdk.connectAccount("0x...", 8453);
73
71
 
74
72
  // Option 2: With wallet provider (chainId optional - uses provider's chain)
75
73
  const provider = await connector.getProvider();
@@ -81,7 +79,7 @@ await sdk.connectAccount(provider); // Automatically uses provider's current cha
81
79
 
82
80
  // Now call methods with explicit user addresses
83
81
  const userAddress = "0xUser...";
84
- await sdk.deploySafe(userAddress, 42161);
82
+ await sdk.deploySafe(userAddress, 8453);
85
83
  ```
86
84
 
87
85
  **Note:**
@@ -116,12 +114,12 @@ Deploy a Safe smart wallet:
116
114
  const userAddress = "0xUser..."; // User's EOA address
117
115
 
118
116
  // Get the deterministic Safe address (before deployment)
119
- const walletInfo = await sdk.getSmartWalletAddress(userAddress, 42161);
117
+ const walletInfo = await sdk.getSmartWalletAddress(userAddress, 8453);
120
118
  console.log("Safe Address:", walletInfo.address);
121
119
  console.log("Is Deployed:", walletInfo.isDeployed);
122
120
 
123
121
  // Deploy the Safe (automatically checks if already deployed)
124
- const result = await sdk.deploySafe(userAddress, 42161);
122
+ const result = await sdk.deploySafe(userAddress, 8453);
125
123
 
126
124
  if (result.success) {
127
125
  console.log("Safe Address:", result.safeAddress);
@@ -157,9 +155,9 @@ const chains = getSupportedChainIds();
157
155
  console.log("Supported chains:", chains);
158
156
 
159
157
  // Check if a chain is supported
160
- if (isSupportedChain(42161)) {
158
+ if (isSupportedChain(8453)) {
161
159
  const userAddress = "0xUser...";
162
- const result = await sdk.deploySafe(userAddress, 42161); // Arbitrum
160
+ const result = await sdk.deploySafe(userAddress, 8453); // Base
163
161
  }
164
162
  ```
165
163
 
@@ -192,7 +190,7 @@ Connect account for signing transactions and authenticate via SIWE. Accepts eith
192
190
  - `chainId`: Target chain ID
193
191
  - **Required** for private key
194
192
  - **Optional** for wallet providers (auto-detects from provider)
195
- - Default: 42161 (Arbitrum)
193
+ - Default: 8453 (Base)
196
194
 
197
195
  **Returns:** Connected wallet address
198
196
 
@@ -206,7 +204,7 @@ Connect account for signing transactions and authenticate via SIWE. Accepts eith
206
204
 
207
205
  ```typescript
208
206
  // With private key (chainId required)
209
- await sdk.connectAccount("0x...", 42161);
207
+ await sdk.connectAccount("0x...", 8453);
210
208
 
211
209
  // With wallet provider (chainId optional)
212
210
  const provider = await connector.getProvider();
@@ -307,7 +305,7 @@ The SDK automatically fetches optimal session configuration from ZyFAI API:
307
305
  // 5. Signs the session key
308
306
  // 6. Calls /session-keys/add so the session becomes active immediately
309
307
 
310
- const result = await sdk.createSessionKey(userAddress, 42161);
308
+ const result = await sdk.createSessionKey(userAddress, 8453);
311
309
 
312
310
  // Check if session key already existed
313
311
  if (result.alreadyActive) {
@@ -332,11 +330,11 @@ console.log("User ID:", result.userId);
332
330
  Transfer tokens to your Safe smart wallet:
333
331
 
334
332
  ```typescript
335
- // Deposit 100 USDC (6 decimals) to Safe on Arbitrum
333
+ // Deposit 100 USDC (6 decimals) to Safe on Base
336
334
  const result = await sdk.depositFunds(
337
335
  userAddress,
338
- 42161, // Chain ID
339
- "0xaf88d065e77c8cc2239327c5edb3a432268e5831", // USDC on Arbitrum
336
+ 8453, // Chain ID
337
+ "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // USDC on Base
340
338
  "100000000" // Amount: 100 USDC = 100 * 10^6
341
339
  );
342
340
 
@@ -355,12 +353,12 @@ Initiate a withdrawal from your Safe. **Note: Withdrawals are processed asynchro
355
353
 
356
354
  ```typescript
357
355
  // Full withdrawal
358
- const result = await sdk.withdrawFunds(userAddress, 42161);
356
+ const result = await sdk.withdrawFunds(userAddress, 8453);
359
357
 
360
358
  // Partial withdrawal of 50 USDC (6 decimals)
361
359
  const result = await sdk.withdrawFunds(
362
360
  userAddress,
363
- 42161,
361
+ 8453,
364
362
  "50000000", // Amount: 50 USDC = 50 * 10^6
365
363
  "0xReceiverAddress" // Optional: receiver address
366
364
  );
@@ -389,7 +387,7 @@ if (result.success) {
389
387
  Retrieve all available DeFi protocols and pools for a specific chain:
390
388
 
391
389
  ```typescript
392
- const protocols = await sdk.getAvailableProtocols(42161);
390
+ const protocols = await sdk.getAvailableProtocols(8453);
393
391
 
394
392
  console.log(`Found ${protocols.protocols.length} protocols`);
395
393
  protocols.protocols.forEach((protocol) => {
@@ -626,7 +624,7 @@ pnpm tsx examples/end-to-end.ts
626
624
 
627
625
  ## Complete Examples
628
626
 
629
- ### Example 1: Deploy Safe on Arbitrum
627
+ ### Example 1: Deploy Safe on Base
630
628
 
631
629
  ```typescript
632
630
  import { ZyfaiSDK } from "@zyfai/sdk";
@@ -638,12 +636,12 @@ async function main() {
638
636
  });
639
637
 
640
638
  // Connect account (automatically authenticates via SIWE)
641
- await sdk.connectAccount(process.env.PRIVATE_KEY!, 42161);
639
+ await sdk.connectAccount(process.env.PRIVATE_KEY!, 8453);
642
640
 
643
641
  const userAddress = "0xUser..."; // User's EOA address
644
642
 
645
643
  // Check if Safe already exists
646
- const walletInfo = await sdk.getSmartWalletAddress(userAddress, 42161);
644
+ const walletInfo = await sdk.getSmartWalletAddress(userAddress, 8453);
647
645
 
648
646
  if (walletInfo.isDeployed) {
649
647
  console.log("Safe already deployed at:", walletInfo.address);
@@ -651,7 +649,7 @@ async function main() {
651
649
  }
652
650
 
653
651
  // Deploy Safe
654
- const result = await sdk.deploySafe(userAddress, 42161);
652
+ const result = await sdk.deploySafe(userAddress, 8453);
655
653
 
656
654
  if (result.success) {
657
655
  console.log("✅ Successfully deployed Safe");
@@ -692,7 +690,7 @@ function SafeDeployment() {
692
690
  console.log("Connected and authenticated:", address);
693
691
 
694
692
  // Get Safe address for this user
695
- const walletInfo = await sdk.getSmartWalletAddress(address, 42161);
693
+ const walletInfo = await sdk.getSmartWalletAddress(address, 8453);
696
694
  setSafeAddress(walletInfo.address);
697
695
  } catch (error) {
698
696
  console.error("Connection failed:", error);
@@ -704,7 +702,7 @@ function SafeDeployment() {
704
702
 
705
703
  setIsDeploying(true);
706
704
  try {
707
- const result = await sdk.deploySafe(userAddress, 42161);
705
+ const result = await sdk.deploySafe(userAddress, 8453);
708
706
  if (result.success) {
709
707
  alert(`Safe deployed at ${result.safeAddress}`);
710
708
  }
@@ -761,7 +759,7 @@ The SDK is built on top of:
761
759
  ```typescript
762
760
  try {
763
761
  const userAddress = "0xUser...";
764
- const result = await sdk.deploySafe(userAddress, 42161);
762
+ const result = await sdk.deploySafe(userAddress, 8453);
765
763
  if (!result.success) {
766
764
  console.error("Deployment failed:", result.status);
767
765
  }
@@ -786,12 +784,8 @@ try {
786
784
  For running the examples, set up the following environment variables:
787
785
 
788
786
  ```bash
789
- # Required: Execution API key (Safe deployment, transactions, session keys)
790
- ZYFAI_API_KEY=your-execution-api-key
791
-
792
- # Optional: Data API key (earnings, opportunities, analytics)
793
- # Falls back to ZYFAI_API_KEY if not provided
794
- ZYFAI_DATA_API_KEY=your-data-api-key
787
+ # Required: API key for both Execution API and Data API
788
+ ZYFAI_API_KEY=your-api-key
795
789
 
796
790
  # Required for Safe deployment: Bundler API key (e.g., Pimlico)
797
791
  BUNDLER_API_KEY=your-pimlico-api-key
package/dist/index.d.mts CHANGED
@@ -7,10 +7,8 @@ type Address = `0x${string}`;
7
7
  type Hex = `0x${string}`;
8
8
  type Environment = "staging" | "production";
9
9
  interface SDKConfig {
10
- /** API key for the Execution API */
10
+ /** API key for both Execution API and Data API */
11
11
  apiKey: string;
12
- /** API key for the Data API - defaults to apiKey if not provided */
13
- dataApiKey?: string;
14
12
  /** Environment: 'staging' or 'production' (default: 'production') */
15
13
  environment?: Environment;
16
14
  /** Bundler API key for Safe deployment (e.g., Pimlico) */
@@ -437,7 +435,7 @@ declare class ZyfaiSDK {
437
435
  * ```typescript
438
436
  * await sdk.updateUserProfile({
439
437
  * smartWallet: "0x1396730...",
440
- * chains: [8453, 42161],
438
+ * chains: [8453],
441
439
  * });
442
440
  * ```
443
441
  */
@@ -468,7 +466,7 @@ declare class ZyfaiSDK {
468
466
  * Accepts either a private key string or a modern wallet provider
469
467
  *
470
468
  * @param account - Private key string or wallet provider object
471
- * @param chainId - Target chain ID (default: 42161 - Arbitrum)
469
+ * @param chainId - Target chain ID (default: 8453 - Base)
472
470
  * @returns The connected EOA address
473
471
  *
474
472
  * @example
@@ -563,10 +561,10 @@ declare class ZyfaiSDK {
563
561
  *
564
562
  * @example
565
563
  * ```typescript
566
- * // Deposit 100 USDC (6 decimals) to Safe on Arbitrum
564
+ * // Deposit 100 USDC (6 decimals) to Safe on Base
567
565
  * const result = await sdk.depositFunds(
568
566
  * "0xUser...",
569
- * 42161,
567
+ * 8453,
570
568
  * "0xaf88d065e77c8cc2239327c5edb3a432268e5831", // USDC
571
569
  * "100000000" // 100 USDC = 100 * 10^6
572
570
  * );
@@ -587,13 +585,13 @@ declare class ZyfaiSDK {
587
585
  * @example
588
586
  * ```typescript
589
587
  * // Full withdrawal
590
- * const result = await sdk.withdrawFunds("0xUser...", 42161);
588
+ * const result = await sdk.withdrawFunds("0xUser...", 8453);
591
589
  * console.log(result.message); // "Withdrawal request sent"
592
590
  *
593
591
  * // Partial withdrawal of 50 USDC (6 decimals)
594
592
  * const result = await sdk.withdrawFunds(
595
593
  * "0xUser...",
596
- * 42161,
594
+ * 8453,
597
595
  * "50000000", // 50 USDC = 50 * 10^6
598
596
  * "0xReceiver..."
599
597
  * );
@@ -608,7 +606,7 @@ declare class ZyfaiSDK {
608
606
  *
609
607
  * @example
610
608
  * ```typescript
611
- * const protocols = await sdk.getAvailableProtocols(42161);
609
+ * const protocols = await sdk.getAvailableProtocols(8453);
612
610
  * protocols.forEach(protocol => {
613
611
  * console.log(`${protocol.name}: ${protocol.minApy}% - ${protocol.maxApy}% APY`);
614
612
  * });
@@ -628,7 +626,7 @@ declare class ZyfaiSDK {
628
626
  * const positions = await sdk.getPositions(userAddress);
629
627
  *
630
628
  * // Get positions on a specific chain
631
- * const arbPositions = await sdk.getPositions(userAddress, 42161);
629
+ * const basePositions = await sdk.getPositions(userAddress, 8453);
632
630
  * ```
633
631
  */
634
632
  getPositions(userAddress: string, chainId?: SupportedChainId): Promise<PositionsResponse>;
package/dist/index.d.ts CHANGED
@@ -7,10 +7,8 @@ type Address = `0x${string}`;
7
7
  type Hex = `0x${string}`;
8
8
  type Environment = "staging" | "production";
9
9
  interface SDKConfig {
10
- /** API key for the Execution API */
10
+ /** API key for both Execution API and Data API */
11
11
  apiKey: string;
12
- /** API key for the Data API - defaults to apiKey if not provided */
13
- dataApiKey?: string;
14
12
  /** Environment: 'staging' or 'production' (default: 'production') */
15
13
  environment?: Environment;
16
14
  /** Bundler API key for Safe deployment (e.g., Pimlico) */
@@ -437,7 +435,7 @@ declare class ZyfaiSDK {
437
435
  * ```typescript
438
436
  * await sdk.updateUserProfile({
439
437
  * smartWallet: "0x1396730...",
440
- * chains: [8453, 42161],
438
+ * chains: [8453],
441
439
  * });
442
440
  * ```
443
441
  */
@@ -468,7 +466,7 @@ declare class ZyfaiSDK {
468
466
  * Accepts either a private key string or a modern wallet provider
469
467
  *
470
468
  * @param account - Private key string or wallet provider object
471
- * @param chainId - Target chain ID (default: 42161 - Arbitrum)
469
+ * @param chainId - Target chain ID (default: 8453 - Base)
472
470
  * @returns The connected EOA address
473
471
  *
474
472
  * @example
@@ -563,10 +561,10 @@ declare class ZyfaiSDK {
563
561
  *
564
562
  * @example
565
563
  * ```typescript
566
- * // Deposit 100 USDC (6 decimals) to Safe on Arbitrum
564
+ * // Deposit 100 USDC (6 decimals) to Safe on Base
567
565
  * const result = await sdk.depositFunds(
568
566
  * "0xUser...",
569
- * 42161,
567
+ * 8453,
570
568
  * "0xaf88d065e77c8cc2239327c5edb3a432268e5831", // USDC
571
569
  * "100000000" // 100 USDC = 100 * 10^6
572
570
  * );
@@ -587,13 +585,13 @@ declare class ZyfaiSDK {
587
585
  * @example
588
586
  * ```typescript
589
587
  * // Full withdrawal
590
- * const result = await sdk.withdrawFunds("0xUser...", 42161);
588
+ * const result = await sdk.withdrawFunds("0xUser...", 8453);
591
589
  * console.log(result.message); // "Withdrawal request sent"
592
590
  *
593
591
  * // Partial withdrawal of 50 USDC (6 decimals)
594
592
  * const result = await sdk.withdrawFunds(
595
593
  * "0xUser...",
596
- * 42161,
594
+ * 8453,
597
595
  * "50000000", // 50 USDC = 50 * 10^6
598
596
  * "0xReceiver..."
599
597
  * );
@@ -608,7 +606,7 @@ declare class ZyfaiSDK {
608
606
  *
609
607
  * @example
610
608
  * ```typescript
611
- * const protocols = await sdk.getAvailableProtocols(42161);
609
+ * const protocols = await sdk.getAvailableProtocols(8453);
612
610
  * protocols.forEach(protocol => {
613
611
  * console.log(`${protocol.name}: ${protocol.minApy}% - ${protocol.maxApy}% APY`);
614
612
  * });
@@ -628,7 +626,7 @@ declare class ZyfaiSDK {
628
626
  * const positions = await sdk.getPositions(userAddress);
629
627
  *
630
628
  * // Get positions on a specific chain
631
- * const arbPositions = await sdk.getPositions(userAddress, 42161);
629
+ * const basePositions = await sdk.getPositions(userAddress, 8453);
632
630
  * ```
633
631
  */
634
632
  getPositions(userAddress: string, chainId?: SupportedChainId): Promise<PositionsResponse>;
package/dist/index.js CHANGED
@@ -102,14 +102,12 @@ var HttpClient = class {
102
102
  /**
103
103
  * Create HTTP client for both Execution API and Data API
104
104
  *
105
- * @param apiKey - API key for Execution API
105
+ * @param apiKey - API key for both Execution API and Data API
106
106
  * @param environment - 'staging' or 'production'
107
- * @param dataApiKey - API key for Data API - defaults to apiKey
108
107
  */
109
- constructor(apiKey, environment = "production", dataApiKey) {
108
+ constructor(apiKey, environment = "production") {
110
109
  this.authToken = null;
111
110
  this.apiKey = apiKey;
112
- this.dataApiKey = dataApiKey || apiKey;
113
111
  this.environment = environment;
114
112
  const endpoint = API_ENDPOINTS[environment];
115
113
  const parsedUrl = new URL(endpoint);
@@ -128,7 +126,7 @@ var HttpClient = class {
128
126
  baseURL: `${dataEndpoint}${DATA_API_VERSION}`,
129
127
  headers: {
130
128
  "Content-Type": "application/json",
131
- "X-API-Key": this.dataApiKey
129
+ "X-API-Key": this.apiKey
132
130
  },
133
131
  timeout: 3e4
134
132
  });
@@ -227,7 +225,7 @@ var HttpClient = class {
227
225
  const fullUrl = `${DATA_API_ENDPOINTS[this.environment]}${path}`;
228
226
  const headers = {
229
227
  "Content-Type": "application/json",
230
- "X-API-Key": this.dataApiKey,
228
+ "X-API-Key": this.apiKey,
231
229
  ...config?.headers
232
230
  };
233
231
  if (this.authToken) {
@@ -243,7 +241,7 @@ var HttpClient = class {
243
241
  setupDataInterceptors() {
244
242
  this.dataClient.interceptors.request.use(
245
243
  (config) => {
246
- config.headers["X-API-Key"] = this.dataApiKey;
244
+ config.headers["X-API-Key"] = this.apiKey;
247
245
  if (this.authToken) {
248
246
  config.headers["Authorization"] = `Bearer ${this.authToken}`;
249
247
  }
@@ -476,10 +474,30 @@ var getSafeAccount = async (config) => {
476
474
  threshold: 1
477
475
  });
478
476
  const saltHex = (0, import_viem3.fromHex)((0, import_viem3.toHex)(effectiveSalt), "bigint");
477
+ const signer = {
478
+ ...owner.account,
479
+ address: signerAddress,
480
+ // Override with the signer address at top level
481
+ signMessage: async (message) => {
482
+ if (typeof message === "string") {
483
+ return await owner.signMessage({
484
+ account: owner.account,
485
+ message
486
+ });
487
+ } else {
488
+ return await owner.signMessage({
489
+ account: owner.account,
490
+ message: {
491
+ raw: message.raw
492
+ }
493
+ });
494
+ }
495
+ }
496
+ };
479
497
  const safeAccount = await (0, import_accounts.toSafeSmartAccount)({
480
498
  client: publicClient,
481
- owners: [owner],
482
- // Pass the owner object with address and signMessage capability
499
+ owners: [signer],
500
+ // Pass the signer object with address at top level and signMessage capability
483
501
  version: "1.4.1",
484
502
  entryPoint: {
485
503
  address: import_account_abstraction.entryPoint07Address,
@@ -612,7 +630,7 @@ var deploySafeAccount = async (config) => {
612
630
  );
613
631
  }
614
632
  };
615
- var signSessionKey = async (config, sessions, allPublicClients) => {
633
+ var signSessionKey = async (config, sessions, allPublicClients, signingParams) => {
616
634
  const { owner, publicClient } = config;
617
635
  if (!owner || !owner.account) {
618
636
  throw new Error("Wallet not connected. Please connect your wallet first.");
@@ -640,8 +658,9 @@ var signSessionKey = async (config, sessions, allPublicClients) => {
640
658
  sessions,
641
659
  account,
642
660
  clients,
643
- permitGenericPolicy: true,
644
- sessionNonces
661
+ permitGenericPolicy: signingParams?.permitGenericPolicy ?? true,
662
+ sessionNonces,
663
+ ignoreSecurityAttestations: signingParams?.ignoreSecurityAttestations ?? false
645
664
  });
646
665
  const signature = await owner.signMessage({
647
666
  account: owner.account,
@@ -670,12 +689,12 @@ var ZyfaiSDK = class {
670
689
  // Store reference to current provider for event handling
671
690
  this.currentChainId = null;
672
691
  const sdkConfig = typeof config === "string" ? { apiKey: config } : config;
673
- const { apiKey, dataApiKey, environment, bundlerApiKey } = sdkConfig;
692
+ const { apiKey, environment, bundlerApiKey } = sdkConfig;
674
693
  if (!apiKey) {
675
694
  throw new Error("API key is required");
676
695
  }
677
696
  this.environment = environment || "production";
678
- this.httpClient = new HttpClient(apiKey, this.environment, dataApiKey);
697
+ this.httpClient = new HttpClient(apiKey, this.environment);
679
698
  this.bundlerApiKey = bundlerApiKey;
680
699
  }
681
700
  /**
@@ -697,6 +716,7 @@ var ZyfaiSDK = class {
697
716
  let uri;
698
717
  let domain;
699
718
  const globalWindow = typeof globalThis !== "undefined" ? globalThis.window : void 0;
719
+ const isNodeJs = !globalWindow?.location?.origin;
700
720
  if (globalWindow?.location?.origin) {
701
721
  uri = globalWindow.location.origin;
702
722
  domain = globalWindow.location.host;
@@ -724,7 +744,13 @@ var ZyfaiSDK = class {
724
744
  {
725
745
  message: messageObj,
726
746
  signature
727
- }
747
+ },
748
+ // Set Origin header in Node.js to match message.uri (required by backend validation)
749
+ isNodeJs ? {
750
+ headers: {
751
+ Origin: uri
752
+ }
753
+ } : void 0
728
754
  );
729
755
  const authToken = loginResponse.accessToken;
730
756
  if (!authToken) {
@@ -750,7 +776,7 @@ var ZyfaiSDK = class {
750
776
  * ```typescript
751
777
  * await sdk.updateUserProfile({
752
778
  * smartWallet: "0x1396730...",
753
- * chains: [8453, 42161],
779
+ * chains: [8453],
754
780
  * });
755
781
  * ```
756
782
  */
@@ -827,7 +853,7 @@ var ZyfaiSDK = class {
827
853
  this.httpClient.clearAuthToken();
828
854
  if (this.walletClient && this.currentProvider) {
829
855
  const chainConfig = getChainConfig(
830
- this.walletClient.chain?.id || 42161
856
+ this.walletClient.chain?.id || 8453
831
857
  );
832
858
  this.walletClient = (0, import_viem4.createWalletClient)({
833
859
  account: newAddress,
@@ -850,7 +876,7 @@ var ZyfaiSDK = class {
850
876
  * Accepts either a private key string or a modern wallet provider
851
877
  *
852
878
  * @param account - Private key string or wallet provider object
853
- * @param chainId - Target chain ID (default: 42161 - Arbitrum)
879
+ * @param chainId - Target chain ID (default: 8453 - Base)
854
880
  * @returns The connected EOA address
855
881
  *
856
882
  * @example
@@ -862,7 +888,7 @@ var ZyfaiSDK = class {
862
888
  * const provider = await connector.getProvider();
863
889
  * await sdk.connectAccount(provider);
864
890
  */
865
- async connectAccount(account, chainId = 42161) {
891
+ async connectAccount(account, chainId = 8453) {
866
892
  if (!isSupportedChain(chainId)) {
867
893
  throw new Error(`Unsupported chain ID: ${chainId}`);
868
894
  }
@@ -1146,9 +1172,10 @@ var ZyfaiSDK = class {
1146
1172
  alreadyActive: true
1147
1173
  };
1148
1174
  }
1149
- const sessionConfig = await this.httpClient.get(
1175
+ const sessionConfigResponse = await this.httpClient.get(
1150
1176
  ENDPOINTS.SESSION_KEYS_CONFIG
1151
1177
  );
1178
+ const sessionConfig = Array.isArray(sessionConfigResponse) ? sessionConfigResponse : sessionConfigResponse.sessions;
1152
1179
  if (!sessionConfig || sessionConfig.length === 0) {
1153
1180
  throw new Error("No session configuration available from API");
1154
1181
  }
@@ -1156,16 +1183,37 @@ var ZyfaiSDK = class {
1156
1183
  ...session,
1157
1184
  chainId: BigInt(session.chainId)
1158
1185
  }));
1186
+ const DEFAULT_ACTION_TARGET = "0x0000000000000000000000000000000000000001";
1187
+ const DEFAULT_ACTION_SELECTOR = "0x00000001";
1188
+ const permitGenericPolicy = sessionConfig.some(
1189
+ (session) => session.actions?.some(
1190
+ (action) => action.actionTarget === DEFAULT_ACTION_TARGET && action.actionTargetSelector === DEFAULT_ACTION_SELECTOR
1191
+ )
1192
+ );
1193
+ const chainConfig = getChainConfig(chainId);
1194
+ const accountType = await getAccountType(
1195
+ userAddress,
1196
+ chainConfig.publicClient
1197
+ );
1198
+ const signingParams = {
1199
+ permitGenericPolicy,
1200
+ ignoreSecurityAttestations: accountType === "Safe"
1201
+ };
1159
1202
  const signatureResult = await this.signSessionKey(
1160
1203
  userAddress,
1161
1204
  chainId,
1162
- sessions
1205
+ sessions,
1206
+ signingParams
1163
1207
  );
1164
1208
  if (!signatureResult.signature) {
1165
1209
  throw new Error("Failed to obtain session key signature");
1166
1210
  }
1167
1211
  await this.updateUserProtocols(chainId);
1212
+ const signer = sessions[0].sessionValidator;
1213
+ console.log("Session validator:", signer);
1168
1214
  const activation = await this.activateSessionKey(
1215
+ signer || "0x2483DA3A338895199E5e538530213157e931Bf06",
1216
+ // TODO: This is a temporary fix to avoid the session validator being null
1169
1217
  signatureResult.signature,
1170
1218
  signatureResult.sessionNonces
1171
1219
  );
@@ -1185,7 +1233,7 @@ var ZyfaiSDK = class {
1185
1233
  * Internal method to sign session key
1186
1234
  * @private
1187
1235
  */
1188
- async signSessionKey(userAddress, chainId, sessions) {
1236
+ async signSessionKey(userAddress, chainId, sessions, signingParams) {
1189
1237
  try {
1190
1238
  if (!userAddress) {
1191
1239
  throw new Error("User address is required");
@@ -1220,7 +1268,8 @@ var ZyfaiSDK = class {
1220
1268
  environment: this.environment
1221
1269
  },
1222
1270
  sessions,
1223
- allPublicClients
1271
+ allPublicClients,
1272
+ signingParams
1224
1273
  );
1225
1274
  const safeAddress = await getDeterministicSafeAddress({
1226
1275
  owner: walletClient,
@@ -1267,9 +1316,10 @@ var ZyfaiSDK = class {
1267
1316
  /**
1268
1317
  * Activate session key via ZyFAI API
1269
1318
  */
1270
- async activateSessionKey(signature, sessionNonces) {
1319
+ async activateSessionKey(signer, signature, sessionNonces) {
1271
1320
  const nonces = this.normalizeSessionNonces(sessionNonces);
1272
1321
  const payload = {
1322
+ signer,
1273
1323
  hash: signature,
1274
1324
  nonces
1275
1325
  };
@@ -1307,10 +1357,10 @@ var ZyfaiSDK = class {
1307
1357
  *
1308
1358
  * @example
1309
1359
  * ```typescript
1310
- * // Deposit 100 USDC (6 decimals) to Safe on Arbitrum
1360
+ * // Deposit 100 USDC (6 decimals) to Safe on Base
1311
1361
  * const result = await sdk.depositFunds(
1312
1362
  * "0xUser...",
1313
- * 42161,
1363
+ * 8453,
1314
1364
  * "0xaf88d065e77c8cc2239327c5edb3a432268e5831", // USDC
1315
1365
  * "100000000" // 100 USDC = 100 * 10^6
1316
1366
  * );
@@ -1388,13 +1438,13 @@ var ZyfaiSDK = class {
1388
1438
  * @example
1389
1439
  * ```typescript
1390
1440
  * // Full withdrawal
1391
- * const result = await sdk.withdrawFunds("0xUser...", 42161);
1441
+ * const result = await sdk.withdrawFunds("0xUser...", 8453);
1392
1442
  * console.log(result.message); // "Withdrawal request sent"
1393
1443
  *
1394
1444
  * // Partial withdrawal of 50 USDC (6 decimals)
1395
1445
  * const result = await sdk.withdrawFunds(
1396
1446
  * "0xUser...",
1397
- * 42161,
1447
+ * 8453,
1398
1448
  * "50000000", // 50 USDC = 50 * 10^6
1399
1449
  * "0xReceiver..."
1400
1450
  * );
@@ -1480,7 +1530,7 @@ var ZyfaiSDK = class {
1480
1530
  *
1481
1531
  * @example
1482
1532
  * ```typescript
1483
- * const protocols = await sdk.getAvailableProtocols(42161);
1533
+ * const protocols = await sdk.getAvailableProtocols(8453);
1484
1534
  * protocols.forEach(protocol => {
1485
1535
  * console.log(`${protocol.name}: ${protocol.minApy}% - ${protocol.maxApy}% APY`);
1486
1536
  * });
@@ -1518,7 +1568,7 @@ var ZyfaiSDK = class {
1518
1568
  * const positions = await sdk.getPositions(userAddress);
1519
1569
  *
1520
1570
  * // Get positions on a specific chain
1521
- * const arbPositions = await sdk.getPositions(userAddress, 42161);
1571
+ * const basePositions = await sdk.getPositions(userAddress, 8453);
1522
1572
  * ```
1523
1573
  */
1524
1574
  async getPositions(userAddress, chainId) {
package/dist/index.mjs CHANGED
@@ -63,14 +63,12 @@ var HttpClient = class {
63
63
  /**
64
64
  * Create HTTP client for both Execution API and Data API
65
65
  *
66
- * @param apiKey - API key for Execution API
66
+ * @param apiKey - API key for both Execution API and Data API
67
67
  * @param environment - 'staging' or 'production'
68
- * @param dataApiKey - API key for Data API - defaults to apiKey
69
68
  */
70
- constructor(apiKey, environment = "production", dataApiKey) {
69
+ constructor(apiKey, environment = "production") {
71
70
  this.authToken = null;
72
71
  this.apiKey = apiKey;
73
- this.dataApiKey = dataApiKey || apiKey;
74
72
  this.environment = environment;
75
73
  const endpoint = API_ENDPOINTS[environment];
76
74
  const parsedUrl = new URL(endpoint);
@@ -89,7 +87,7 @@ var HttpClient = class {
89
87
  baseURL: `${dataEndpoint}${DATA_API_VERSION}`,
90
88
  headers: {
91
89
  "Content-Type": "application/json",
92
- "X-API-Key": this.dataApiKey
90
+ "X-API-Key": this.apiKey
93
91
  },
94
92
  timeout: 3e4
95
93
  });
@@ -188,7 +186,7 @@ var HttpClient = class {
188
186
  const fullUrl = `${DATA_API_ENDPOINTS[this.environment]}${path}`;
189
187
  const headers = {
190
188
  "Content-Type": "application/json",
191
- "X-API-Key": this.dataApiKey,
189
+ "X-API-Key": this.apiKey,
192
190
  ...config?.headers
193
191
  };
194
192
  if (this.authToken) {
@@ -204,7 +202,7 @@ var HttpClient = class {
204
202
  setupDataInterceptors() {
205
203
  this.dataClient.interceptors.request.use(
206
204
  (config) => {
207
- config.headers["X-API-Key"] = this.dataApiKey;
205
+ config.headers["X-API-Key"] = this.apiKey;
208
206
  if (this.authToken) {
209
207
  config.headers["Authorization"] = `Bearer ${this.authToken}`;
210
208
  }
@@ -456,10 +454,30 @@ var getSafeAccount = async (config) => {
456
454
  threshold: 1
457
455
  });
458
456
  const saltHex = fromHex(toHex(effectiveSalt), "bigint");
457
+ const signer = {
458
+ ...owner.account,
459
+ address: signerAddress,
460
+ // Override with the signer address at top level
461
+ signMessage: async (message) => {
462
+ if (typeof message === "string") {
463
+ return await owner.signMessage({
464
+ account: owner.account,
465
+ message
466
+ });
467
+ } else {
468
+ return await owner.signMessage({
469
+ account: owner.account,
470
+ message: {
471
+ raw: message.raw
472
+ }
473
+ });
474
+ }
475
+ }
476
+ };
459
477
  const safeAccount = await toSafeSmartAccount({
460
478
  client: publicClient,
461
- owners: [owner],
462
- // Pass the owner object with address and signMessage capability
479
+ owners: [signer],
480
+ // Pass the signer object with address at top level and signMessage capability
463
481
  version: "1.4.1",
464
482
  entryPoint: {
465
483
  address: entryPoint07Address,
@@ -592,7 +610,7 @@ var deploySafeAccount = async (config) => {
592
610
  );
593
611
  }
594
612
  };
595
- var signSessionKey = async (config, sessions, allPublicClients) => {
613
+ var signSessionKey = async (config, sessions, allPublicClients, signingParams) => {
596
614
  const { owner, publicClient } = config;
597
615
  if (!owner || !owner.account) {
598
616
  throw new Error("Wallet not connected. Please connect your wallet first.");
@@ -620,8 +638,9 @@ var signSessionKey = async (config, sessions, allPublicClients) => {
620
638
  sessions,
621
639
  account,
622
640
  clients,
623
- permitGenericPolicy: true,
624
- sessionNonces
641
+ permitGenericPolicy: signingParams?.permitGenericPolicy ?? true,
642
+ sessionNonces,
643
+ ignoreSecurityAttestations: signingParams?.ignoreSecurityAttestations ?? false
625
644
  });
626
645
  const signature = await owner.signMessage({
627
646
  account: owner.account,
@@ -650,12 +669,12 @@ var ZyfaiSDK = class {
650
669
  // Store reference to current provider for event handling
651
670
  this.currentChainId = null;
652
671
  const sdkConfig = typeof config === "string" ? { apiKey: config } : config;
653
- const { apiKey, dataApiKey, environment, bundlerApiKey } = sdkConfig;
672
+ const { apiKey, environment, bundlerApiKey } = sdkConfig;
654
673
  if (!apiKey) {
655
674
  throw new Error("API key is required");
656
675
  }
657
676
  this.environment = environment || "production";
658
- this.httpClient = new HttpClient(apiKey, this.environment, dataApiKey);
677
+ this.httpClient = new HttpClient(apiKey, this.environment);
659
678
  this.bundlerApiKey = bundlerApiKey;
660
679
  }
661
680
  /**
@@ -677,6 +696,7 @@ var ZyfaiSDK = class {
677
696
  let uri;
678
697
  let domain;
679
698
  const globalWindow = typeof globalThis !== "undefined" ? globalThis.window : void 0;
699
+ const isNodeJs = !globalWindow?.location?.origin;
680
700
  if (globalWindow?.location?.origin) {
681
701
  uri = globalWindow.location.origin;
682
702
  domain = globalWindow.location.host;
@@ -704,7 +724,13 @@ var ZyfaiSDK = class {
704
724
  {
705
725
  message: messageObj,
706
726
  signature
707
- }
727
+ },
728
+ // Set Origin header in Node.js to match message.uri (required by backend validation)
729
+ isNodeJs ? {
730
+ headers: {
731
+ Origin: uri
732
+ }
733
+ } : void 0
708
734
  );
709
735
  const authToken = loginResponse.accessToken;
710
736
  if (!authToken) {
@@ -730,7 +756,7 @@ var ZyfaiSDK = class {
730
756
  * ```typescript
731
757
  * await sdk.updateUserProfile({
732
758
  * smartWallet: "0x1396730...",
733
- * chains: [8453, 42161],
759
+ * chains: [8453],
734
760
  * });
735
761
  * ```
736
762
  */
@@ -807,7 +833,7 @@ var ZyfaiSDK = class {
807
833
  this.httpClient.clearAuthToken();
808
834
  if (this.walletClient && this.currentProvider) {
809
835
  const chainConfig = getChainConfig(
810
- this.walletClient.chain?.id || 42161
836
+ this.walletClient.chain?.id || 8453
811
837
  );
812
838
  this.walletClient = createWalletClient({
813
839
  account: newAddress,
@@ -830,7 +856,7 @@ var ZyfaiSDK = class {
830
856
  * Accepts either a private key string or a modern wallet provider
831
857
  *
832
858
  * @param account - Private key string or wallet provider object
833
- * @param chainId - Target chain ID (default: 42161 - Arbitrum)
859
+ * @param chainId - Target chain ID (default: 8453 - Base)
834
860
  * @returns The connected EOA address
835
861
  *
836
862
  * @example
@@ -842,7 +868,7 @@ var ZyfaiSDK = class {
842
868
  * const provider = await connector.getProvider();
843
869
  * await sdk.connectAccount(provider);
844
870
  */
845
- async connectAccount(account, chainId = 42161) {
871
+ async connectAccount(account, chainId = 8453) {
846
872
  if (!isSupportedChain(chainId)) {
847
873
  throw new Error(`Unsupported chain ID: ${chainId}`);
848
874
  }
@@ -1126,9 +1152,10 @@ var ZyfaiSDK = class {
1126
1152
  alreadyActive: true
1127
1153
  };
1128
1154
  }
1129
- const sessionConfig = await this.httpClient.get(
1155
+ const sessionConfigResponse = await this.httpClient.get(
1130
1156
  ENDPOINTS.SESSION_KEYS_CONFIG
1131
1157
  );
1158
+ const sessionConfig = Array.isArray(sessionConfigResponse) ? sessionConfigResponse : sessionConfigResponse.sessions;
1132
1159
  if (!sessionConfig || sessionConfig.length === 0) {
1133
1160
  throw new Error("No session configuration available from API");
1134
1161
  }
@@ -1136,16 +1163,37 @@ var ZyfaiSDK = class {
1136
1163
  ...session,
1137
1164
  chainId: BigInt(session.chainId)
1138
1165
  }));
1166
+ const DEFAULT_ACTION_TARGET = "0x0000000000000000000000000000000000000001";
1167
+ const DEFAULT_ACTION_SELECTOR = "0x00000001";
1168
+ const permitGenericPolicy = sessionConfig.some(
1169
+ (session) => session.actions?.some(
1170
+ (action) => action.actionTarget === DEFAULT_ACTION_TARGET && action.actionTargetSelector === DEFAULT_ACTION_SELECTOR
1171
+ )
1172
+ );
1173
+ const chainConfig = getChainConfig(chainId);
1174
+ const accountType = await getAccountType(
1175
+ userAddress,
1176
+ chainConfig.publicClient
1177
+ );
1178
+ const signingParams = {
1179
+ permitGenericPolicy,
1180
+ ignoreSecurityAttestations: accountType === "Safe"
1181
+ };
1139
1182
  const signatureResult = await this.signSessionKey(
1140
1183
  userAddress,
1141
1184
  chainId,
1142
- sessions
1185
+ sessions,
1186
+ signingParams
1143
1187
  );
1144
1188
  if (!signatureResult.signature) {
1145
1189
  throw new Error("Failed to obtain session key signature");
1146
1190
  }
1147
1191
  await this.updateUserProtocols(chainId);
1192
+ const signer = sessions[0].sessionValidator;
1193
+ console.log("Session validator:", signer);
1148
1194
  const activation = await this.activateSessionKey(
1195
+ signer || "0x2483DA3A338895199E5e538530213157e931Bf06",
1196
+ // TODO: This is a temporary fix to avoid the session validator being null
1149
1197
  signatureResult.signature,
1150
1198
  signatureResult.sessionNonces
1151
1199
  );
@@ -1165,7 +1213,7 @@ var ZyfaiSDK = class {
1165
1213
  * Internal method to sign session key
1166
1214
  * @private
1167
1215
  */
1168
- async signSessionKey(userAddress, chainId, sessions) {
1216
+ async signSessionKey(userAddress, chainId, sessions, signingParams) {
1169
1217
  try {
1170
1218
  if (!userAddress) {
1171
1219
  throw new Error("User address is required");
@@ -1200,7 +1248,8 @@ var ZyfaiSDK = class {
1200
1248
  environment: this.environment
1201
1249
  },
1202
1250
  sessions,
1203
- allPublicClients
1251
+ allPublicClients,
1252
+ signingParams
1204
1253
  );
1205
1254
  const safeAddress = await getDeterministicSafeAddress({
1206
1255
  owner: walletClient,
@@ -1247,9 +1296,10 @@ var ZyfaiSDK = class {
1247
1296
  /**
1248
1297
  * Activate session key via ZyFAI API
1249
1298
  */
1250
- async activateSessionKey(signature, sessionNonces) {
1299
+ async activateSessionKey(signer, signature, sessionNonces) {
1251
1300
  const nonces = this.normalizeSessionNonces(sessionNonces);
1252
1301
  const payload = {
1302
+ signer,
1253
1303
  hash: signature,
1254
1304
  nonces
1255
1305
  };
@@ -1287,10 +1337,10 @@ var ZyfaiSDK = class {
1287
1337
  *
1288
1338
  * @example
1289
1339
  * ```typescript
1290
- * // Deposit 100 USDC (6 decimals) to Safe on Arbitrum
1340
+ * // Deposit 100 USDC (6 decimals) to Safe on Base
1291
1341
  * const result = await sdk.depositFunds(
1292
1342
  * "0xUser...",
1293
- * 42161,
1343
+ * 8453,
1294
1344
  * "0xaf88d065e77c8cc2239327c5edb3a432268e5831", // USDC
1295
1345
  * "100000000" // 100 USDC = 100 * 10^6
1296
1346
  * );
@@ -1368,13 +1418,13 @@ var ZyfaiSDK = class {
1368
1418
  * @example
1369
1419
  * ```typescript
1370
1420
  * // Full withdrawal
1371
- * const result = await sdk.withdrawFunds("0xUser...", 42161);
1421
+ * const result = await sdk.withdrawFunds("0xUser...", 8453);
1372
1422
  * console.log(result.message); // "Withdrawal request sent"
1373
1423
  *
1374
1424
  * // Partial withdrawal of 50 USDC (6 decimals)
1375
1425
  * const result = await sdk.withdrawFunds(
1376
1426
  * "0xUser...",
1377
- * 42161,
1427
+ * 8453,
1378
1428
  * "50000000", // 50 USDC = 50 * 10^6
1379
1429
  * "0xReceiver..."
1380
1430
  * );
@@ -1460,7 +1510,7 @@ var ZyfaiSDK = class {
1460
1510
  *
1461
1511
  * @example
1462
1512
  * ```typescript
1463
- * const protocols = await sdk.getAvailableProtocols(42161);
1513
+ * const protocols = await sdk.getAvailableProtocols(8453);
1464
1514
  * protocols.forEach(protocol => {
1465
1515
  * console.log(`${protocol.name}: ${protocol.minApy}% - ${protocol.maxApy}% APY`);
1466
1516
  * });
@@ -1498,7 +1548,7 @@ var ZyfaiSDK = class {
1498
1548
  * const positions = await sdk.getPositions(userAddress);
1499
1549
  *
1500
1550
  * // Get positions on a specific chain
1501
- * const arbPositions = await sdk.getPositions(userAddress, 42161);
1551
+ * const basePositions = await sdk.getPositions(userAddress, 8453);
1502
1552
  * ```
1503
1553
  */
1504
1554
  async getPositions(userAddress, chainId) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zyfai/sdk",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
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",