@elsoul/erpc-sdk 0.4.0 → 0.6.0

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/dist/index.js CHANGED
@@ -314,6 +314,7 @@ var CloudCatalogClient = class {
314
314
 
315
315
  // src/config.ts
316
316
  var DEFAULT_ENDPOINT = "https://edge.erpc.global";
317
+ var DEFAULT_AVALANCHE_ENDPOINT = "https://ava-rpc.erpc.global";
317
318
  var DEFAULT_ACCOUNT_ENDPOINT = "https://solana-rpc.erpc.global";
318
319
  var DEFAULT_USER_ENDPOINT = "https://user-api.erpc.global";
319
320
  var DEFAULT_TIMEOUT_MS = 3e4;
@@ -330,10 +331,14 @@ var resolveConfig = (config) => {
330
331
  const apiKey = config.apiKey.trim();
331
332
  if (!apiKey) throw new ErpcConfigError("apiKey must not be empty");
332
333
  let endpoint;
334
+ let avalancheEndpoint;
333
335
  let accountEndpoint;
334
336
  let userEndpoint;
335
337
  try {
336
338
  endpoint = new URL(config.endpoint ?? DEFAULT_ENDPOINT);
339
+ avalancheEndpoint = new URL(
340
+ config.avalancheEndpoint ?? DEFAULT_AVALANCHE_ENDPOINT
341
+ );
337
342
  accountEndpoint = new URL(
338
343
  config.accountEndpoint ?? DEFAULT_ACCOUNT_ENDPOINT
339
344
  );
@@ -344,6 +349,9 @@ var resolveConfig = (config) => {
344
349
  if (endpoint.protocol !== "https:" && endpoint.protocol !== "http:") {
345
350
  throw new ErpcConfigError("endpoint must use HTTP or HTTPS");
346
351
  }
352
+ if (avalancheEndpoint.protocol !== "https:" && avalancheEndpoint.protocol !== "http:") {
353
+ throw new ErpcConfigError("avalancheEndpoint must use HTTP or HTTPS");
354
+ }
347
355
  if (accountEndpoint.protocol !== "https:" && accountEndpoint.protocol !== "http:") {
348
356
  throw new ErpcConfigError("accountEndpoint must use HTTP or HTTPS");
349
357
  }
@@ -353,6 +361,9 @@ var resolveConfig = (config) => {
353
361
  endpoint.search = "";
354
362
  endpoint.hash = "";
355
363
  endpoint.pathname = endpoint.pathname.replace(/\/+$/, "") || "/";
364
+ avalancheEndpoint.search = "";
365
+ avalancheEndpoint.hash = "";
366
+ avalancheEndpoint.pathname = avalancheEndpoint.pathname.replace(/\/+$/, "") || "/";
356
367
  accountEndpoint.search = "";
357
368
  accountEndpoint.hash = "";
358
369
  accountEndpoint.pathname = accountEndpoint.pathname.replace(/\/+$/, "") || "/";
@@ -366,6 +377,7 @@ var resolveConfig = (config) => {
366
377
  return {
367
378
  accountEndpoint,
368
379
  apiKey,
380
+ avalancheEndpoint,
369
381
  endpoint,
370
382
  fetch: requireFetch(config.fetch),
371
383
  headers: config.headers ?? {},
@@ -527,10 +539,14 @@ var methodParams = (mode, args) => {
527
539
  return args[0];
528
540
  };
529
541
  var createRpcNamespace = (config) => {
542
+ const wireMethod = (method) => config.methodPrefix === void 0 ? method : `${config.methodPrefix}.${method}`;
530
543
  const base = {
531
544
  endpoint: config.transport.endpoint,
532
545
  batch: (calls) => {
533
- const wireCalls = calls;
546
+ const wireCalls = calls.map((call) => ({
547
+ ...call,
548
+ method: wireMethod(call.method)
549
+ }));
534
550
  config.validateBatch?.(wireCalls);
535
551
  return new PendingRpcBatchRequest(
536
552
  (options) => config.transport.batch(
@@ -544,7 +560,7 @@ var createRpcNamespace = (config) => {
544
560
  ),
545
561
  request: (method, ...params) => new PendingRpcRequest(
546
562
  (options) => config.transport.request(
547
- method,
563
+ wireMethod(method),
548
564
  params[0],
549
565
  options
550
566
  )
@@ -558,7 +574,7 @@ var createRpcNamespace = (config) => {
558
574
  if (property === "then") return void 0;
559
575
  return (...args) => new PendingRpcRequest(
560
576
  (options) => config.transport.request(
561
- property,
577
+ wireMethod(property),
562
578
  methodParams(config.parameterMode, args),
563
579
  options
564
580
  )
@@ -634,6 +650,110 @@ var createEthereumClient = (transport) => ({
634
650
  })
635
651
  });
636
652
 
653
+ // src/rpc/avalanche.ts
654
+ var AVALANCHE_AVAX_METHODS = [
655
+ "avax.getAtomicTx",
656
+ "avax.getAtomicTxStatus",
657
+ "avax.getUTXOs",
658
+ "avax.issueTx"
659
+ ];
660
+ var AVALANCHE_X_CHAIN_METHODS = [
661
+ "avm.buildGenesis",
662
+ "avm.getAllBalances",
663
+ "avm.getAssetDescription",
664
+ "avm.getBalance",
665
+ "avm.getBlockByHeight",
666
+ "avm.getHeight",
667
+ "avm.getTx",
668
+ "avm.getTxFee",
669
+ "avm.getTxStatus",
670
+ "avm.getUTXOs",
671
+ "avm.issueTx"
672
+ ];
673
+ var AVALANCHE_P_CHAIN_METHODS = [
674
+ "platform.getAllValidatorsAt",
675
+ "platform.getBalance",
676
+ "platform.getBlockchainStatus",
677
+ "platform.getBlockchains",
678
+ "platform.getCurrentSupply",
679
+ "platform.getCurrentValidators",
680
+ "platform.getFeeConfig",
681
+ "platform.getFeeState",
682
+ "platform.getHeight",
683
+ "platform.getMinStake",
684
+ "platform.getRewardUTXOs",
685
+ "platform.getStake",
686
+ "platform.getStakingAssetID",
687
+ "platform.getSubnets",
688
+ "platform.getTimestamp",
689
+ "platform.getTotalStake",
690
+ "platform.getTx",
691
+ "platform.getTxStatus",
692
+ "platform.getUTXOs",
693
+ "platform.getValidatorFeeConfig",
694
+ "platform.getValidatorFeeState",
695
+ "platform.getValidatorsAt",
696
+ "platform.issueTx",
697
+ "platform.sampleValidators",
698
+ "platform.validatedBy",
699
+ "platform.validates"
700
+ ];
701
+ var AVALANCHE_PROPOSER_VM_METHODS = [
702
+ "proposervm.getCurrentEpoch",
703
+ "proposervm.getProposedHeight"
704
+ ];
705
+ var AVALANCHE_INFO_METHODS = ["info.upgrades"];
706
+ var AVALANCHE_INDEX_METHODS = [
707
+ "index.getContainerByID",
708
+ "index.getContainerByIndex",
709
+ "index.getContainerRange",
710
+ "index.getIndex",
711
+ "index.getLastAccepted",
712
+ "index.isAccepted"
713
+ ];
714
+ var rejectNativeBatch = (calls) => {
715
+ if (calls.length > 0) {
716
+ throw new ErpcBatchPolicyError(
717
+ "Avalanche native RPC methods do not support batching"
718
+ );
719
+ }
720
+ };
721
+ var nativeNamespace = (transport, methodPrefix) => createRpcNamespace({
722
+ methodPrefix,
723
+ parameterMode: "named",
724
+ transport,
725
+ validateBatch: rejectNativeBatch
726
+ });
727
+ var createAvalancheClient = (transport, indexTransports) => ({
728
+ ...createEthereumClient(transport),
729
+ avax: nativeNamespace(transport, "avax"),
730
+ xChain: nativeNamespace(transport, "avm"),
731
+ pChain: nativeNamespace(transport, "platform"),
732
+ proposerVm: nativeNamespace(
733
+ transport,
734
+ "proposervm"
735
+ ),
736
+ info: nativeNamespace(transport, "info"),
737
+ index: {
738
+ cChainBlocks: nativeNamespace(
739
+ indexTransports.cChainBlocks,
740
+ "index"
741
+ ),
742
+ pChainBlocks: nativeNamespace(
743
+ indexTransports.pChainBlocks,
744
+ "index"
745
+ ),
746
+ xChainBlocks: nativeNamespace(
747
+ indexTransports.xChainBlocks,
748
+ "index"
749
+ ),
750
+ xChainTransactions: nativeNamespace(
751
+ indexTransports.xChainTransactions,
752
+ "index"
753
+ )
754
+ }
755
+ });
756
+
637
757
  // src/rpc/solana.ts
638
758
  var SOLANA_RPC_METHODS = [
639
759
  "getAccountInfo",
@@ -1392,6 +1512,14 @@ var createErpcClient = (config) => {
1392
1512
  ...sharedTransport,
1393
1513
  endpoint: ethereumEndpoint
1394
1514
  });
1515
+ const avalancheTransport = new HttpJsonRpcTransport({
1516
+ ...sharedTransport,
1517
+ endpoint: endpointWithPath(resolved.avalancheEndpoint, "/ava")
1518
+ });
1519
+ const avalancheIndexTransport = (path) => new HttpJsonRpcTransport({
1520
+ ...sharedTransport,
1521
+ endpoint: endpointWithPath(resolved.avalancheEndpoint, path)
1522
+ });
1395
1523
  const solanaWebSocket = new WebSocketJsonRpcTransport({
1396
1524
  endpoint: websocketUrl(resolved.endpoint, resolved.apiKey),
1397
1525
  timeoutMs: resolved.timeoutMs,
@@ -1402,6 +1530,15 @@ var createErpcClient = (config) => {
1402
1530
  timeoutMs: resolved.timeoutMs,
1403
1531
  ...resolved.webSocket === void 0 ? {} : { webSocket: resolved.webSocket }
1404
1532
  });
1533
+ const avalancheWebSocket = new WebSocketJsonRpcTransport({
1534
+ endpoint: websocketUrl(
1535
+ resolved.avalancheEndpoint,
1536
+ resolved.apiKey,
1537
+ "/ava-ws"
1538
+ ),
1539
+ timeoutMs: resolved.timeoutMs,
1540
+ ...resolved.webSocket === void 0 ? {} : { webSocket: resolved.webSocket }
1541
+ });
1405
1542
  const priceTransport = new RestTransport({
1406
1543
  ...sharedTransport,
1407
1544
  endpoint: resolved.endpoint
@@ -1422,15 +1559,26 @@ var createErpcClient = (config) => {
1422
1559
  ...createEthereumClient(ethereumTransport),
1423
1560
  subscriptions: new EthereumSubscriptions(ethereumWebSocket)
1424
1561
  };
1562
+ const avalanche = {
1563
+ ...createAvalancheClient(avalancheTransport, {
1564
+ cChainBlocks: avalancheIndexTransport("/ava/ext/index/C/block"),
1565
+ pChainBlocks: avalancheIndexTransport("/ava/ext/index/P/block"),
1566
+ xChainBlocks: avalancheIndexTransport("/ava/ext/index/X/block"),
1567
+ xChainTransactions: avalancheIndexTransport("/ava/ext/index/X/tx")
1568
+ }),
1569
+ subscriptions: new EthereumSubscriptions(avalancheWebSocket)
1570
+ };
1425
1571
  return {
1426
1572
  solana,
1427
1573
  ethereum,
1574
+ avalanche,
1428
1575
  price: new PriceClient(priceTransport),
1429
1576
  account: new AccountClient(accountTransport),
1430
1577
  usage: new UsageClient(userTransport),
1431
1578
  close: () => {
1432
1579
  solana.subscriptions.close();
1433
1580
  ethereum.subscriptions.close();
1581
+ avalanche.subscriptions.close();
1434
1582
  }
1435
1583
  };
1436
1584
  };
@@ -1651,6 +1799,6 @@ var createErpcCloudClient = (config) => {
1651
1799
  };
1652
1800
  };
1653
1801
 
1654
- export { AccountClient, CloudCatalogClient, CloudCreditClient, CloudResourcesClient, DEFAULT_ACCOUNT_ENDPOINT, DEFAULT_ENDPOINT, DEFAULT_TIMEOUT_MS, DEFAULT_USER_ENDPOINT, ETHEREUM_RPC_METHODS, ETHEREUM_SUBSCRIPTION_METHODS, ErpcAbortedError, ErpcBatchPolicyError, ErpcConfigError, ErpcError, ErpcHttpError, ErpcInvalidResponseError, ErpcJsonRpcError, ErpcTimeoutError, ErpcTransportError, EthereumSubscriptions, PendingRpcBatchRequest, PendingRpcRequest, PriceClient, RpcSubscription, SOLANA_ANALYTICS_METHODS, SOLANA_DAS_METHODS, SOLANA_ENHANCED_SUBSCRIPTION_METHODS, SOLANA_HISTORY_METHODS, SOLANA_LEADER_METHODS, SOLANA_RPC_METHODS, SolanaSubscriptions, UsageClient, createErpcClient, createErpcCloudClient };
1802
+ export { AVALANCHE_AVAX_METHODS, AVALANCHE_INDEX_METHODS, AVALANCHE_INFO_METHODS, AVALANCHE_PROPOSER_VM_METHODS, AVALANCHE_P_CHAIN_METHODS, AVALANCHE_X_CHAIN_METHODS, AccountClient, CloudCatalogClient, CloudCreditClient, CloudResourcesClient, DEFAULT_ACCOUNT_ENDPOINT, DEFAULT_AVALANCHE_ENDPOINT, DEFAULT_ENDPOINT, DEFAULT_TIMEOUT_MS, DEFAULT_USER_ENDPOINT, ETHEREUM_RPC_METHODS, ETHEREUM_SUBSCRIPTION_METHODS, ErpcAbortedError, ErpcBatchPolicyError, ErpcConfigError, ErpcError, ErpcHttpError, ErpcInvalidResponseError, ErpcJsonRpcError, ErpcTimeoutError, ErpcTransportError, EthereumSubscriptions, PendingRpcBatchRequest, PendingRpcRequest, PriceClient, RpcSubscription, SOLANA_ANALYTICS_METHODS, SOLANA_DAS_METHODS, SOLANA_ENHANCED_SUBSCRIPTION_METHODS, SOLANA_HISTORY_METHODS, SOLANA_LEADER_METHODS, SOLANA_RPC_METHODS, SolanaSubscriptions, UsageClient, createErpcClient, createErpcCloudClient };
1655
1803
  //# sourceMappingURL=index.js.map
1656
1804
  //# sourceMappingURL=index.js.map