@zyfai/sdk 0.1.22 → 0.1.24

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
@@ -29,7 +29,7 @@ pnpm add @zyfai/sdk viem
29
29
  2. **Bundler API Key**: Required for Safe deployment. Get it from:
30
30
  - [Pimlico](https://www.pimlico.io/) (Recommended)
31
31
 
32
- **Get your API key from [ZyFAI Dashboard](https://app.zyf.ai)**
32
+ **Get your API key from [ZyFAI Dashboard](https://sdk.zyf.ai)**
33
33
 
34
34
  ## Quick Start
35
35
 
@@ -177,6 +177,10 @@ new ZyfaiSDK(config: SDKConfig | string)
177
177
  - `apiKey` (string): Your ZyFAI API key (required)
178
178
  - `environment` ('production' | 'staging', optional): API environment (default: 'production')
179
179
  - `bundlerApiKey` (string, optional): Bundler API key for Safe deployment (required for deploySafe)
180
+ - `rpcUrls` (object, optional): Custom RPC URLs per chain to avoid rate limiting
181
+ - `8453` (string, optional): Base Mainnet RPC URL
182
+ - `42161` (string, optional): Arbitrum One RPC URL
183
+ - `9745` (string, optional): Plasma Mainnet RPC URL
180
184
 
181
185
  **Examples:**
182
186
 
@@ -190,6 +194,18 @@ const sdk = new ZyfaiSDK({
190
194
  bundlerApiKey: "your-bundler-api-key",
191
195
  environment: "production",
192
196
  });
197
+
198
+ // Option 3: With custom RPC URLs (recommended to avoid rate limiting)
199
+ const sdk = new ZyfaiSDK({
200
+ apiKey: "your-api-key",
201
+ bundlerApiKey: "your-bundler-api-key",
202
+ environment: "production",
203
+ rpcUrls: {
204
+ 8453: "https://base-mainnet.g.alchemy.com/v2/YOUR_API_KEY", // Base
205
+ 42161: "https://arb-mainnet.g.alchemy.com/v2/YOUR_API_KEY", // Arbitrum
206
+ 9745: "https://your-plasma-rpc-provider.com", // Plasma
207
+ },
208
+ });
193
209
  ```
194
210
 
195
211
  #### Methods
package/dist/index.d.mts CHANGED
@@ -6,13 +6,16 @@ import { Chain, PublicClient } from 'viem';
6
6
  type Address = `0x${string}`;
7
7
  type Hex = `0x${string}`;
8
8
  type Environment = "staging" | "production";
9
+ interface RpcUrlsConfig {
10
+ 8453?: string;
11
+ 42161?: string;
12
+ 9745?: string;
13
+ }
9
14
  interface SDKConfig {
10
- /** API key for both Execution API and Data API */
11
15
  apiKey: string;
12
- /** Environment: 'staging' or 'production' (default: 'production') */
13
16
  environment?: Environment;
14
- /** Bundler API key for Safe deployment (e.g., Pimlico) */
15
17
  bundlerApiKey?: string;
18
+ rpcUrls?: RpcUrlsConfig;
16
19
  }
17
20
  interface DeploySafeResponse {
18
21
  success: boolean;
@@ -388,9 +391,12 @@ interface ChainConfig {
388
391
  declare const DEFAULT_TOKEN_ADDRESSES: Record<SupportedChainId, string>;
389
392
  declare const getDefaultTokenAddress: (chainId: SupportedChainId) => string;
390
393
  /**
391
- * Get chain configuration for a given chain ID
394
+ * Get chain configuration for a given chain ID.
395
+ *
396
+ * @param chainId - Supported chain ID
397
+ * @param rpcUrls - Optional per-chain RPC URL overrides
392
398
  */
393
- declare const getChainConfig: (chainId: SupportedChainId) => ChainConfig;
399
+ declare const getChainConfig: (chainId: SupportedChainId, rpcUrls?: RpcUrlsConfig) => ChainConfig;
394
400
  /**
395
401
  * Check if a chain ID is supported
396
402
  */
@@ -414,6 +420,7 @@ declare class ZyfaiSDK {
414
420
  private environment;
415
421
  private currentProvider;
416
422
  private currentChainId;
423
+ private rpcUrls?;
417
424
  constructor(config: SDKConfig | string);
418
425
  /**
419
426
  * Authenticate user with SIWE (Sign-In with Ethereum) & JWT token
package/dist/index.d.ts CHANGED
@@ -6,13 +6,16 @@ import { Chain, PublicClient } from 'viem';
6
6
  type Address = `0x${string}`;
7
7
  type Hex = `0x${string}`;
8
8
  type Environment = "staging" | "production";
9
+ interface RpcUrlsConfig {
10
+ 8453?: string;
11
+ 42161?: string;
12
+ 9745?: string;
13
+ }
9
14
  interface SDKConfig {
10
- /** API key for both Execution API and Data API */
11
15
  apiKey: string;
12
- /** Environment: 'staging' or 'production' (default: 'production') */
13
16
  environment?: Environment;
14
- /** Bundler API key for Safe deployment (e.g., Pimlico) */
15
17
  bundlerApiKey?: string;
18
+ rpcUrls?: RpcUrlsConfig;
16
19
  }
17
20
  interface DeploySafeResponse {
18
21
  success: boolean;
@@ -388,9 +391,12 @@ interface ChainConfig {
388
391
  declare const DEFAULT_TOKEN_ADDRESSES: Record<SupportedChainId, string>;
389
392
  declare const getDefaultTokenAddress: (chainId: SupportedChainId) => string;
390
393
  /**
391
- * Get chain configuration for a given chain ID
394
+ * Get chain configuration for a given chain ID.
395
+ *
396
+ * @param chainId - Supported chain ID
397
+ * @param rpcUrls - Optional per-chain RPC URL overrides
392
398
  */
393
- declare const getChainConfig: (chainId: SupportedChainId) => ChainConfig;
399
+ declare const getChainConfig: (chainId: SupportedChainId, rpcUrls?: RpcUrlsConfig) => ChainConfig;
394
400
  /**
395
401
  * Check if a chain ID is supported
396
402
  */
@@ -414,6 +420,7 @@ declare class ZyfaiSDK {
414
420
  private environment;
415
421
  private currentProvider;
416
422
  private currentChainId;
423
+ private rpcUrls?;
417
424
  constructor(config: SDKConfig | string);
418
425
  /**
419
426
  * Authenticate user with SIWE (Sign-In with Ethereum) & JWT token
package/dist/index.js CHANGED
@@ -411,12 +411,12 @@ var CHAINS = {
411
411
  42161: import_chains.arbitrum,
412
412
  9745: plasma
413
413
  };
414
- var getChainConfig = (chainId) => {
414
+ var getChainConfig = (chainId, rpcUrls) => {
415
415
  const chain = CHAINS[chainId];
416
416
  if (!chain) {
417
417
  throw new Error(`Unsupported chain ID: ${chainId}`);
418
418
  }
419
- const rpcUrl = DEFAULT_RPC_URLS[chainId];
419
+ const rpcUrl = rpcUrls && rpcUrls[chainId] || DEFAULT_RPC_URLS[chainId];
420
420
  const publicClient = (0, import_viem.createPublicClient)({
421
421
  chain,
422
422
  transport: (0, import_viem.http)(rpcUrl)
@@ -819,25 +819,25 @@ var signSessionKey = async (config, sessions, allPublicClients, signingParams) =
819
819
  // src/core/ZyfaiSDK.ts
820
820
  var import_siwe = require("siwe");
821
821
  var ZyfaiSDK = class {
822
- // Store current chain ID for private key connections
822
+ // Optional custom RPC URLs per chain
823
823
  constructor(config) {
824
824
  this.signer = null;
825
825
  this.walletClient = null;
826
826
  this.authenticatedUserId = null;
827
827
  // If non-null, user is authenticated
828
828
  this.hasActiveSessionKey = false;
829
- // TODO: The environment should be removed. Having the same key for staging and production is not ideal, but for now it's fine.
830
829
  this.currentProvider = null;
831
830
  // Store reference to current provider for event handling
832
831
  this.currentChainId = null;
833
832
  const sdkConfig = typeof config === "string" ? { apiKey: config } : config;
834
- const { apiKey, environment, bundlerApiKey } = sdkConfig;
833
+ const { apiKey, environment, bundlerApiKey, rpcUrls } = sdkConfig;
835
834
  if (!apiKey) {
836
835
  throw new Error("API key is required");
837
836
  }
838
837
  this.environment = environment || "production";
839
838
  this.httpClient = new HttpClient(apiKey, this.environment);
840
839
  this.bundlerApiKey = bundlerApiKey;
840
+ this.rpcUrls = rpcUrls;
841
841
  }
842
842
  /**
843
843
  * Authenticate user with SIWE (Sign-In with Ethereum) & JWT token
@@ -995,7 +995,8 @@ var ZyfaiSDK = class {
995
995
  this.httpClient.clearAuthToken();
996
996
  if (this.walletClient && this.currentProvider) {
997
997
  const chainConfig = getChainConfig(
998
- this.walletClient.chain?.id || 8453
998
+ this.walletClient.chain?.id || 8453,
999
+ this.rpcUrls
999
1000
  );
1000
1001
  this.walletClient = (0, import_viem4.createWalletClient)({
1001
1002
  account: newAddress,
@@ -1043,7 +1044,7 @@ var ZyfaiSDK = class {
1043
1044
  } catch (error) {
1044
1045
  }
1045
1046
  }
1046
- const chainConfig = getChainConfig(chainId);
1047
+ const chainConfig = getChainConfig(chainId, this.rpcUrls);
1047
1048
  let connectedAddress;
1048
1049
  if (typeof account === "string") {
1049
1050
  let privateKey = account;
@@ -1134,10 +1135,14 @@ var ZyfaiSDK = class {
1134
1135
  getWalletClient(chainId) {
1135
1136
  if (this.signer) {
1136
1137
  const targetChainId = chainId || this.currentChainId || 8453;
1138
+ const targetChainConfig = getChainConfig(
1139
+ targetChainId,
1140
+ this.rpcUrls
1141
+ );
1137
1142
  return (0, import_viem4.createWalletClient)({
1138
1143
  account: this.signer,
1139
- chain: getChainConfig(targetChainId).chain,
1140
- transport: (0, import_viem4.http)(getChainConfig(targetChainId).rpcUrl)
1144
+ chain: targetChainConfig.chain,
1145
+ transport: (0, import_viem4.http)(targetChainConfig.rpcUrl)
1141
1146
  });
1142
1147
  } else {
1143
1148
  if (!this.walletClient) {
@@ -1161,7 +1166,7 @@ var ZyfaiSDK = class {
1161
1166
  if (!isSupportedChain(chainId)) {
1162
1167
  throw new Error(`Unsupported chain ID: ${chainId}`);
1163
1168
  }
1164
- const chainConfig = getChainConfig(chainId);
1169
+ const chainConfig = getChainConfig(chainId, this.rpcUrls);
1165
1170
  try {
1166
1171
  const smartWalletInfo = await this.getSmartWalletByEOA(userAddress);
1167
1172
  if (smartWalletInfo.smartWallet) {
@@ -1214,7 +1219,7 @@ var ZyfaiSDK = class {
1214
1219
  );
1215
1220
  }
1216
1221
  const walletClient = this.getWalletClient(chainId);
1217
- const chainConfig = getChainConfig(chainId);
1222
+ const chainConfig = getChainConfig(chainId, this.rpcUrls);
1218
1223
  const safeAddress = await getDeterministicSafeAddress({
1219
1224
  owner: walletClient,
1220
1225
  safeOwnerAddress: userAddress,
@@ -1333,7 +1338,7 @@ var ZyfaiSDK = class {
1333
1338
  (action) => action.actionTarget === DEFAULT_ACTION_TARGET && action.actionTargetSelector === DEFAULT_ACTION_SELECTOR
1334
1339
  )
1335
1340
  );
1336
- const chainConfig = getChainConfig(chainId);
1341
+ const chainConfig = getChainConfig(chainId, this.rpcUrls);
1337
1342
  const accountType = await getAccountType(
1338
1343
  userAddress,
1339
1344
  chainConfig.publicClient
@@ -1387,7 +1392,7 @@ var ZyfaiSDK = class {
1387
1392
  throw new Error("At least one session configuration is required");
1388
1393
  }
1389
1394
  const walletClient = this.getWalletClient();
1390
- const chainConfig = getChainConfig(chainId);
1395
+ const chainConfig = getChainConfig(chainId, this.rpcUrls);
1391
1396
  const accountType = await getAccountType(
1392
1397
  userAddress,
1393
1398
  chainConfig.publicClient
@@ -1400,7 +1405,7 @@ var ZyfaiSDK = class {
1400
1405
  const sessionChainIds = [
1401
1406
  ...new Set(sessions.map((s) => Number(s.chainId)))
1402
1407
  ];
1403
- const allPublicClients = sessionChainIds.filter(isSupportedChain).map((id) => getChainConfig(id).publicClient);
1408
+ const allPublicClients = sessionChainIds.filter(isSupportedChain).map((id) => getChainConfig(id, this.rpcUrls).publicClient);
1404
1409
  const { signature, sessionNonces } = await signSessionKey(
1405
1410
  {
1406
1411
  owner: walletClient,
@@ -1523,7 +1528,7 @@ var ZyfaiSDK = class {
1523
1528
  }
1524
1529
  const token = getDefaultTokenAddress(chainId);
1525
1530
  const walletClient = this.getWalletClient();
1526
- const chainConfig = getChainConfig(chainId);
1531
+ const chainConfig = getChainConfig(chainId, this.rpcUrls);
1527
1532
  const safeAddress = await getDeterministicSafeAddress({
1528
1533
  owner: walletClient,
1529
1534
  safeOwnerAddress: userAddress,
@@ -1598,7 +1603,7 @@ var ZyfaiSDK = class {
1598
1603
  if (!isSupportedChain(chainId)) {
1599
1604
  throw new Error(`Unsupported chain ID: ${chainId}`);
1600
1605
  }
1601
- const chainConfig = getChainConfig(chainId);
1606
+ const chainConfig = getChainConfig(chainId, this.rpcUrls);
1602
1607
  let safeAddress;
1603
1608
  try {
1604
1609
  const smartWalletInfo = await this.getSmartWalletByEOA(userAddress);
package/dist/index.mjs CHANGED
@@ -375,12 +375,12 @@ var CHAINS = {
375
375
  42161: arbitrum,
376
376
  9745: plasma
377
377
  };
378
- var getChainConfig = (chainId) => {
378
+ var getChainConfig = (chainId, rpcUrls) => {
379
379
  const chain = CHAINS[chainId];
380
380
  if (!chain) {
381
381
  throw new Error(`Unsupported chain ID: ${chainId}`);
382
382
  }
383
- const rpcUrl = DEFAULT_RPC_URLS[chainId];
383
+ const rpcUrl = rpcUrls && rpcUrls[chainId] || DEFAULT_RPC_URLS[chainId];
384
384
  const publicClient = createPublicClient({
385
385
  chain,
386
386
  transport: http(rpcUrl)
@@ -804,25 +804,25 @@ var signSessionKey = async (config, sessions, allPublicClients, signingParams) =
804
804
  // src/core/ZyfaiSDK.ts
805
805
  import { SiweMessage } from "siwe";
806
806
  var ZyfaiSDK = class {
807
- // Store current chain ID for private key connections
807
+ // Optional custom RPC URLs per chain
808
808
  constructor(config) {
809
809
  this.signer = null;
810
810
  this.walletClient = null;
811
811
  this.authenticatedUserId = null;
812
812
  // If non-null, user is authenticated
813
813
  this.hasActiveSessionKey = false;
814
- // TODO: The environment should be removed. Having the same key for staging and production is not ideal, but for now it's fine.
815
814
  this.currentProvider = null;
816
815
  // Store reference to current provider for event handling
817
816
  this.currentChainId = null;
818
817
  const sdkConfig = typeof config === "string" ? { apiKey: config } : config;
819
- const { apiKey, environment, bundlerApiKey } = sdkConfig;
818
+ const { apiKey, environment, bundlerApiKey, rpcUrls } = sdkConfig;
820
819
  if (!apiKey) {
821
820
  throw new Error("API key is required");
822
821
  }
823
822
  this.environment = environment || "production";
824
823
  this.httpClient = new HttpClient(apiKey, this.environment);
825
824
  this.bundlerApiKey = bundlerApiKey;
825
+ this.rpcUrls = rpcUrls;
826
826
  }
827
827
  /**
828
828
  * Authenticate user with SIWE (Sign-In with Ethereum) & JWT token
@@ -980,7 +980,8 @@ var ZyfaiSDK = class {
980
980
  this.httpClient.clearAuthToken();
981
981
  if (this.walletClient && this.currentProvider) {
982
982
  const chainConfig = getChainConfig(
983
- this.walletClient.chain?.id || 8453
983
+ this.walletClient.chain?.id || 8453,
984
+ this.rpcUrls
984
985
  );
985
986
  this.walletClient = createWalletClient({
986
987
  account: newAddress,
@@ -1028,7 +1029,7 @@ var ZyfaiSDK = class {
1028
1029
  } catch (error) {
1029
1030
  }
1030
1031
  }
1031
- const chainConfig = getChainConfig(chainId);
1032
+ const chainConfig = getChainConfig(chainId, this.rpcUrls);
1032
1033
  let connectedAddress;
1033
1034
  if (typeof account === "string") {
1034
1035
  let privateKey = account;
@@ -1119,10 +1120,14 @@ var ZyfaiSDK = class {
1119
1120
  getWalletClient(chainId) {
1120
1121
  if (this.signer) {
1121
1122
  const targetChainId = chainId || this.currentChainId || 8453;
1123
+ const targetChainConfig = getChainConfig(
1124
+ targetChainId,
1125
+ this.rpcUrls
1126
+ );
1122
1127
  return createWalletClient({
1123
1128
  account: this.signer,
1124
- chain: getChainConfig(targetChainId).chain,
1125
- transport: http3(getChainConfig(targetChainId).rpcUrl)
1129
+ chain: targetChainConfig.chain,
1130
+ transport: http3(targetChainConfig.rpcUrl)
1126
1131
  });
1127
1132
  } else {
1128
1133
  if (!this.walletClient) {
@@ -1146,7 +1151,7 @@ var ZyfaiSDK = class {
1146
1151
  if (!isSupportedChain(chainId)) {
1147
1152
  throw new Error(`Unsupported chain ID: ${chainId}`);
1148
1153
  }
1149
- const chainConfig = getChainConfig(chainId);
1154
+ const chainConfig = getChainConfig(chainId, this.rpcUrls);
1150
1155
  try {
1151
1156
  const smartWalletInfo = await this.getSmartWalletByEOA(userAddress);
1152
1157
  if (smartWalletInfo.smartWallet) {
@@ -1199,7 +1204,7 @@ var ZyfaiSDK = class {
1199
1204
  );
1200
1205
  }
1201
1206
  const walletClient = this.getWalletClient(chainId);
1202
- const chainConfig = getChainConfig(chainId);
1207
+ const chainConfig = getChainConfig(chainId, this.rpcUrls);
1203
1208
  const safeAddress = await getDeterministicSafeAddress({
1204
1209
  owner: walletClient,
1205
1210
  safeOwnerAddress: userAddress,
@@ -1318,7 +1323,7 @@ var ZyfaiSDK = class {
1318
1323
  (action) => action.actionTarget === DEFAULT_ACTION_TARGET && action.actionTargetSelector === DEFAULT_ACTION_SELECTOR
1319
1324
  )
1320
1325
  );
1321
- const chainConfig = getChainConfig(chainId);
1326
+ const chainConfig = getChainConfig(chainId, this.rpcUrls);
1322
1327
  const accountType = await getAccountType(
1323
1328
  userAddress,
1324
1329
  chainConfig.publicClient
@@ -1372,7 +1377,7 @@ var ZyfaiSDK = class {
1372
1377
  throw new Error("At least one session configuration is required");
1373
1378
  }
1374
1379
  const walletClient = this.getWalletClient();
1375
- const chainConfig = getChainConfig(chainId);
1380
+ const chainConfig = getChainConfig(chainId, this.rpcUrls);
1376
1381
  const accountType = await getAccountType(
1377
1382
  userAddress,
1378
1383
  chainConfig.publicClient
@@ -1385,7 +1390,7 @@ var ZyfaiSDK = class {
1385
1390
  const sessionChainIds = [
1386
1391
  ...new Set(sessions.map((s) => Number(s.chainId)))
1387
1392
  ];
1388
- const allPublicClients = sessionChainIds.filter(isSupportedChain).map((id) => getChainConfig(id).publicClient);
1393
+ const allPublicClients = sessionChainIds.filter(isSupportedChain).map((id) => getChainConfig(id, this.rpcUrls).publicClient);
1389
1394
  const { signature, sessionNonces } = await signSessionKey(
1390
1395
  {
1391
1396
  owner: walletClient,
@@ -1508,7 +1513,7 @@ var ZyfaiSDK = class {
1508
1513
  }
1509
1514
  const token = getDefaultTokenAddress(chainId);
1510
1515
  const walletClient = this.getWalletClient();
1511
- const chainConfig = getChainConfig(chainId);
1516
+ const chainConfig = getChainConfig(chainId, this.rpcUrls);
1512
1517
  const safeAddress = await getDeterministicSafeAddress({
1513
1518
  owner: walletClient,
1514
1519
  safeOwnerAddress: userAddress,
@@ -1583,7 +1588,7 @@ var ZyfaiSDK = class {
1583
1588
  if (!isSupportedChain(chainId)) {
1584
1589
  throw new Error(`Unsupported chain ID: ${chainId}`);
1585
1590
  }
1586
- const chainConfig = getChainConfig(chainId);
1591
+ const chainConfig = getChainConfig(chainId, this.rpcUrls);
1587
1592
  let safeAddress;
1588
1593
  try {
1589
1594
  const smartWalletInfo = await this.getSmartWalletByEOA(userAddress);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zyfai/sdk",
3
- "version": "0.1.22",
3
+ "version": "0.1.24",
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",