@ercworldio/blockchain-shared 1.0.3-dev.0-PROJ-1281 → 1.0.3-dev.0-PROJ-1281.2

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.
@@ -1,14 +1,35 @@
1
1
  import { ethers } from "ethers";
2
2
  import { IConfig } from "../interfaces/config";
3
3
  import BaseErrors from "../errors/errors";
4
+ import { ChainId, NetworkConfig } from "../interfaces";
4
5
  export declare enum RpcType {
5
6
  HTTP = 0,
6
7
  WSS = 1
7
8
  }
9
+ export declare enum RpcProviderType {
10
+ ANKR = "ankr",
11
+ QUICKNODE = "quicknode"
12
+ }
8
13
  declare class Provider extends BaseErrors {
9
14
  private config;
15
+ private chainIdToQuicknodeNetworkName;
16
+ private quicknodeEndpointBaseUrl;
10
17
  constructor(config: IConfig);
11
- getProvider: (chainId: string, rpcType: RpcType) => {
18
+ getQuicknodeUrl: (chain_id: ChainId) => string;
19
+ getRpcUrlComponents: (chain_id: ChainId, chain_config: NetworkConfig, rpcType: RpcType, providerType?: RpcProviderType) => {
20
+ url: string;
21
+ };
22
+ /**
23
+ * Backwards compatible with defualt ANKR provider if `providerType` is not passed as an arg
24
+ * Use `providerType` to choose the provider for HTTP rpc.
25
+ * Provider selection does not work for wss.
26
+ * Wss uses Ankr by default
27
+ * @param chainId
28
+ * @param rpcType
29
+ * @param providerType
30
+ * @returns
31
+ */
32
+ getProvider: (chainId: string, rpcType: RpcType, providerType?: RpcProviderType) => {
12
33
  provider: ethers.JsonRpcProvider;
13
34
  url: string;
14
35
  } | {
@@ -1 +1 @@
1
- {"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["../../src/chains/Provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,UAAU,MAAM,kBAAkB,CAAC;AAE1C,oBAAY,OAAO;IACf,IAAI,IAAI;IACR,GAAG,IAAI;CACV;AAGD,cAAM,QAAS,SAAQ,UAAU;IAE7B,OAAO,CAAC,MAAM,CAAU;gBAEZ,MAAM,EAAE,OAAO;IA4C3B,WAAW,GAAI,SAAS,MAAM,EAAE,SAAS,OAAO;;;;;;MAsB/C;CA+CJ;AAGD,eAAe,QAAQ,CAAC"}
1
+ {"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["../../src/chains/Provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,UAAU,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEvD,oBAAY,OAAO;IACf,IAAI,IAAI;IACR,GAAG,IAAI;CACV;AAED,oBAAY,eAAe;IACvB,IAAI,SAAS;IACb,SAAS,cAAc;CAC1B;AAmBD,cAAM,QAAS,SAAQ,UAAU;IAE7B,OAAO,CAAC,MAAM,CAAU;IACxB,OAAO,CAAC,6BAA6B,CAAY;IACjD,OAAO,CAAC,wBAAwB,CAAS;gBAC7B,MAAM,EAAE,OAAO;IAqB3B,eAAe,GAAI,UAAU,OAAO,YAoBnC;IAED,mBAAmB,GAAI,UAAU,OAAO,EAAE,cAAc,aAAa,EAAE,SAAS,OAAO,EAAE,eAAc,eAAsC;;MAyB5I;IAED;;;;;;;;;OASG;IACH,WAAW,GAAI,SAAS,MAAM,EAAE,SAAS,OAAO,EAAE,eAAc,eAAsC;;;;;;MAcrG;CAGJ;AAGD,eAAe,QAAQ,CAAC"}
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.RpcType = void 0;
6
+ exports.RpcProviderType = exports.RpcType = void 0;
7
7
  const ethers_1 = require("ethers");
8
8
  const ChainManager_1 = __importDefault(require("../services/ChainManager"));
9
9
  const errors_1 = __importDefault(require("../errors/errors"));
@@ -12,74 +12,120 @@ var RpcType;
12
12
  RpcType[RpcType["HTTP"] = 0] = "HTTP";
13
13
  RpcType[RpcType["WSS"] = 1] = "WSS";
14
14
  })(RpcType || (exports.RpcType = RpcType = {}));
15
+ var RpcProviderType;
16
+ (function (RpcProviderType) {
17
+ RpcProviderType["ANKR"] = "ankr";
18
+ RpcProviderType["QUICKNODE"] = "quicknode";
19
+ })(RpcProviderType || (exports.RpcProviderType = RpcProviderType = {}));
20
+ const avax_c_chain_rpc_path = '/ext/bc/C/rpc/';
21
+ const quicknodeChainIdToName = {
22
+ 11155111: "ethereum-sepolia",
23
+ 1: "",
24
+ 97: "bsc-testnet",
25
+ 56: "bsc",
26
+ 103: "solana-devnet",
27
+ 101: "solana-mainnet",
28
+ 10143: "monad-testnet",
29
+ 143: "monad-mainnet",
30
+ 43113: "avalanche-testnet",
31
+ 43114: "avalanche-mainnet",
32
+ 80002: "matic-amoy",
33
+ 137: "matic",
34
+ 728126428: "tron-mainnet"
35
+ };
15
36
  class Provider extends errors_1.default {
16
37
  constructor(config) {
17
38
  super();
18
- this.getProvider = (chainId, rpcType) => {
39
+ this.chainIdToQuicknodeNetworkName = new Map();
40
+ /*
41
+ * Parses and returns the final Quicknode Endpoint url for a given network
42
+ * Assumes quicknodeEndpointBaseUrl uses the pattern: https://<RandomName>.*.quiknode.pro
43
+ * Where the * wildcard is replaced with the respective chain id's quicknode endpoint network name
44
+ * */
45
+ this.getQuicknodeUrl = (chain_id) => {
46
+ const endpoint_network_name = this.chainIdToQuicknodeNetworkName.get(parseInt(chain_id));
47
+ if (!endpoint_network_name)
48
+ throw new Error(`Quicknode Endpoint chain id to network name map not set`);
49
+ const quicknodeApiKey = this.config.config.quicknodeEndpointApikey;
50
+ if (!quicknodeApiKey)
51
+ throw new Error(`quicknodeApiKey secret is required`);
52
+ // Handle avalanche separately as it requires a path at the end of the string
53
+ if ([43113, 43114].includes(parseInt(chain_id))) {
54
+ return `${this.quicknodeEndpointBaseUrl.replace("*", endpoint_network_name)}/${quicknodeApiKey}/${avax_c_chain_rpc_path}`;
55
+ }
56
+ // Handle mainnet case where final url doesnt include the network name
57
+ // e.g https://distinguished-aged-aura.quiknode.pro
58
+ // as opposed to non Ethereum Mainnet networks: https://distinguished-aged-aura.bsc.quiknode.pro
59
+ if (parseInt(chain_id) === 1) {
60
+ return `${this.quicknodeEndpointBaseUrl.replace(".*.", ".")}/${quicknodeApiKey}`;
61
+ }
62
+ return `${this.quicknodeEndpointBaseUrl.replace("*", endpoint_network_name)}/${quicknodeApiKey}`;
63
+ };
64
+ this.getRpcUrlComponents = (chain_id, chain_config, rpcType, providerType = RpcProviderType.ANKR) => {
65
+ switch (providerType) {
66
+ case RpcProviderType.ANKR:
67
+ if (!this.config.config.ankrApiKey)
68
+ throw new Error(this.RequireParameter("secret: ankrApiKey"));
69
+ if (rpcType === RpcType.HTTP) {
70
+ if (!chain_config.rpcBaseUrl)
71
+ throw new Error(this.RequireParameter("configuration: rpcBaseUrl"));
72
+ return { url: `${chain_config.rpcBaseUrl}/${this.config.config.ankrApiKey}` };
73
+ }
74
+ else if (rpcType === RpcType.WSS) {
75
+ if (!chain_config.rpcBaseUrlWss)
76
+ throw new Error(this.RequireParameter("configuration: rpcBaseUrlWss"));
77
+ const rpcUrl = `${chain_config.rpcBaseUrlWss}/${this.config.config.ankrApiKey}`;
78
+ return { url: rpcUrl };
79
+ }
80
+ throw new Error(`Unsupported RPC type ${rpcType}`);
81
+ case RpcProviderType.QUICKNODE:
82
+ if (!this.config.config.quicknodeEndpointApikey)
83
+ throw new Error(`quicknodeEndpointApiKey is not set`);
84
+ const quicknodeEndpointUrl = this.getQuicknodeUrl(chain_id);
85
+ const urlWithProtocol = rpcType === RpcType.HTTP ? quicknodeEndpointUrl : quicknodeEndpointUrl.replace("https://", "wss://");
86
+ console.log(`Quicknode url`, urlWithProtocol);
87
+ return { url: urlWithProtocol };
88
+ default:
89
+ throw new Error(`Invalid provider type ${providerType}`);
90
+ }
91
+ };
92
+ /**
93
+ * Backwards compatible with defualt ANKR provider if `providerType` is not passed as an arg
94
+ * Use `providerType` to choose the provider for HTTP rpc.
95
+ * Provider selection does not work for wss.
96
+ * Wss uses Ankr by default
97
+ * @param chainId
98
+ * @param rpcType
99
+ * @param providerType
100
+ * @returns
101
+ */
102
+ this.getProvider = (chainId, rpcType, providerType = RpcProviderType.ANKR) => {
19
103
  const chain_config = ChainManager_1.default.getInstance(this.config).getChainConfigForChainIdSync(parseInt(chainId));
20
104
  if (!chain_config)
21
105
  throw new Error("Chain configuration not found");
22
- // TODO: Handle provider different than ankr
23
- // const chainName = chainIdToName.getChainName(chainId as ChainId);
24
106
  if (rpcType === RpcType.HTTP) {
25
- if (!chain_config.rpcBaseUrl)
26
- throw new Error(this.RequireParameter("configuration: rpcBaseUrl"));
27
- if (!this.config.config.ankrApiKey)
28
- throw new Error(this.RequireParameter("secret: ankrApiKey"));
29
- const rpcUrl = `${chain_config.rpcBaseUrl}/${this.config.config.ankrApiKey}`;
30
- return { provider: new ethers_1.ethers.JsonRpcProvider(rpcUrl), url: rpcUrl };
107
+ const { url } = this.getRpcUrlComponents(chainId, chain_config, rpcType, providerType);
108
+ return { provider: new ethers_1.ethers.JsonRpcProvider(url), url: url };
31
109
  }
32
110
  else if (rpcType === RpcType.WSS) {
33
- if (!chain_config.rpcBaseUrlWss)
34
- throw new Error(this.RequireParameter("configuration: rpcBaseUrlWss"));
35
- if (!this.config.config.ankrApiKey)
36
- throw new Error(this.RequireParameter("secret: ankrApiKey"));
37
- const rpcUrl = `${chain_config.rpcBaseUrlWss}/${this.config.config.ankrApiKey}`;
38
- return { provider: new ethers_1.ethers.WebSocketProvider(rpcUrl), url: rpcUrl };
111
+ const { url } = this.getRpcUrlComponents(chainId, chain_config, rpcType, providerType);
112
+ return { provider: new ethers_1.ethers.WebSocketProvider(url), url: url };
39
113
  }
40
114
  else {
41
- throw new Error(`Invalid RPC type.`);
115
+ throw new Error(`Invalid RPC type ${rpcType}`);
42
116
  }
43
117
  };
44
118
  this.config = config;
45
- // this._providerUrls = {
46
- // polygon: {
47
- // wss: this.config.config.rpcPolygonWss || "",
48
- // https: this.config.config.rpcPolygon || ""
49
- // },
50
- // polygonMainnet: {
51
- // wss: this.config.config.rpcPolygonMainnet || "",
52
- // https: this.config.config.rpcPolygonWss
53
- // },
54
- // ethereum: {
55
- // wss: this.config.config.rpcEthereumWss || "",
56
- // https: this.config.config.rpcEthereum
57
- // },
58
- // fantom: {
59
- // wss: this.config.config.rpcFantomWss || "",
60
- // https: this.config.config.rpcFantom
61
- // },
62
- // bsc: {
63
- // wss: this.config.config.rpcBscWss || "",
64
- // https: this.config.config.rpcBsc
65
- // },
66
- // avalanche: {
67
- // wss: this.config.config.rpcAvalancheWss || "",
68
- // https: this.config.config.rpcAvalanche
69
- // },
70
- // bitlayer: {
71
- // wss: this.config.config.rpcBitlayerWss || "",
72
- // https: this.config.config.rpcBitlayer
73
- // },
74
- // lightning: {
75
- // wss: "",
76
- // https: ""
77
- // },
78
- // solana: {
79
- // wss: "",
80
- // https: ""
81
- // }
82
- // }
119
+ const raw = config.config.quicknodeEndpointUrlPattern;
120
+ if (!raw)
121
+ throw new Error('quicknodeEndpointUrlPattern is required');
122
+ const parsed = new URL(raw);
123
+ if (parsed.protocol !== 'https:')
124
+ throw new Error('quicknodeEndpointUrlPattern must use https');
125
+ if (!parsed.hostname.endsWith('.quiknode.pro'))
126
+ throw new Error('quicknodeEndpointUrlPattern must be a quiknode.pro domain');
127
+ this.quicknodeEndpointBaseUrl = raw.replace(/\/+$/, '');
128
+ this.chainIdToQuicknodeNetworkName = new Map(Object.entries(quicknodeChainIdToName));
83
129
  }
84
130
  }
85
131
  exports.default = Provider;
@@ -20,6 +20,7 @@ export interface IConfigProvider {
20
20
  }
21
21
  export type EnvironmentVariableNames = "quicknodeEndpointApikey" | "quicknodeBaseUrl" | "keyVaultName" | "cryptoKeyVaultName" | "version" | "host" | "serverPort" | "localHost" | "tunnel" | "useTunnel" | "projectName" | "serviceName" | "environment" | "elasticUrl" | "maxInstructionsPerTxSolana" | "requiredContractTypes" | "depositEventHubName" | "transferLogsRawEventHubName" | "withdrawalEventHubName" | "rolesEventHubName" | "walletServiceMnemonicEvm" | "walletServiceMnemonicSolana" | "walletServiceMnemonicTron" | "alchemyApiKey" | "alchemyAccessToken" | "alchemyAccessTokenDev" | "syncableEventNames" | "ankrApiKey" | "azureConnectionStringNotifications" | "azureStorageAccount" | "elasticApiKey" | "rpcEthereum" | "rpcEthereumWss" | "rpcPolygon" | "rpcPolygonWss" | "rpcFantom" | "rpcFantomWss" | "rpcAvalanche" | "rpcAvalancheWss" | "rpcBsc" | "rpcBscWss" | "rpcPolygonMainnet" | "rpcBitlayer" | "rpcBitlayerWss" | "jwtSecret" | "blockchainDbConnectionString" | "customerBlockchainDbConnectionString" | "voltageWebhookSecret" | "redisConnectionstring" | "lndRestHost" | "lndRestHostLnbits" | "lndMacaroon" | "lndMacaroonLnbits" | "escrowFundingWalletPrivateKeyEvm" | "escrowFundingWalletPrivateKeySol" | "escrowFundingWalletPrivateKeyTron";
22
22
  export interface EnvironmentVariables {
23
+ quicknodeEndpointUrlPattern: string;
23
24
  quicknodeApiKey: string;
24
25
  quicknodeEndpointApikey?: string;
25
26
  qnEndpointSolanaNetwork?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/interfaces/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD,aAAK,SAAS;IACV,MAAM,WAAW;IACjB,OAAO,YAAY;CACtB;AAED,MAAM,WAAW,OAAO;IACpB,MAAM,EAAE,oBAAoB,CAAC;IAC7B,oBAAoB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7C,YAAY,EAAE,GAAG,CA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AAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,4BAA4B,EAAE,MAAM,CAAC;IACrC,oCAAoC,EAAE,MAAM,CAAC;IAC7C,oBAAoB,EAAE,MAAM,CAAC;IAC7B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,gCAAgC,EAAE,MAAM,CAAC;IACzC,gCAAgC,EAAE,MAAM,CAAC;IACzC,iCAAiC,EAAE,MAAM,CAAC;CAC7C"}
@@ -1,6 +1,7 @@
1
1
  import { ethers, JsonRpcProvider, WebSocketProvider } from "ethers";
2
2
  import { ChainId } from "../interfaces";
3
3
  import { IConfig } from "../interfaces/config";
4
+ import { RpcProviderType } from "../chains/Provider";
4
5
  interface EvmChainHttpProvider {
5
6
  provider: JsonRpcProvider;
6
7
  url: string;
@@ -26,7 +27,7 @@ declare class ProviderManager {
26
27
  private wss_providers;
27
28
  private constructor();
28
29
  static getInstance(config: IConfig): ProviderManager;
29
- getNewProvider(chainId: string): EvmChainHttpProvider | {
30
+ getNewProvider(chainId: string, provider_type?: RpcProviderType): EvmChainHttpProvider | {
30
31
  provider: ethers.WebSocketProvider;
31
32
  url: string;
32
33
  };
@@ -1 +1 @@
1
- {"version":3,"file":"ProviderManager.d.ts","sourceRoot":"","sources":["../../src/services/ProviderManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAEpE,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAGxC,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAO/C,UAAU,oBAAoB;IAC1B,QAAQ,EAAE,eAAe,CAAC;IAC1B,GAAG,EAAE,MAAM,CAAC;C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oBAAoB;IAC1B,QAAQ,EAAE,eAAe,CAAC;IAC1B,GAAG,EAAE,MAAM,CAAC;CACf;AAED,UAAU,mBAAmB;IACzB,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,GAAG,EAAE,MAAM,CAAC;CACf;AAED,cAAM,eAAe;IACjB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAgC;IACvD,OAAO,CAAC,MAAM,CAAU;IACxB,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,SAAS,CAAoD;IACrE,OAAO,CAAC,eAAe,CAAgB;IACvC,OAAO,CAAC,eAAe,CAA6B;IAEpD,OAAO,CAAC,SAAS,CAAoC;IACrD,OAAO,CAAC,iBAAiB,CAAkD;IAC3E,OAAO,CAAC,EAAE,CAA6C;IACvD,OAAO,CAAC,WAAW,CAAkD;IAErE,OAAO,CAAC,iBAAiB,CAAkC;IAE3D,OAAO,CAAC,oBAAoB,CAA0C;IAEtE,OAAO,CAAC,cAAc,CAAgD;IACtE,OAAO,CAAC,aAAa,CAA+C;IAEpE,OAAO;WAQO,WAAW,CAAC,MAAM,EAAE,OAAO,GAAG,eAAe;IAOpD,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,aAAa,GAAE,eAAsC;;;;IAgBrF,cAAc,CAAC,OAAO,EAAE,MAAM;;;;IAW9B,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,QAAQ,EAAE;IAQxD,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,GAAG,OAAO;CAenF;AAED,eAAe,eAAe,CAAC"}
@@ -40,8 +40,6 @@ const ethers_1 = require("ethers");
40
40
  const events_1 = __importDefault(require("events"));
41
41
  const ElasticSearch_1 = __importDefault(require("./ElasticSearch"));
42
42
  const Provider_1 = __importStar(require("../chains/Provider"));
43
- const EXPECTED_PONG_BACK = 15000;
44
- const KEEP_ALIVE_CHECK_INTERVAL = 30 * 1000;
45
43
  class ProviderManager {
46
44
  constructor(config) {
47
45
  this.providers = new Map();
@@ -65,10 +63,10 @@ class ProviderManager {
65
63
  }
66
64
  return this.instance;
67
65
  }
68
- getNewProvider(chainId) {
66
+ getNewProvider(chainId, provider_type = Provider_1.RpcProviderType.ANKR) {
69
67
  let provider = this.http_providers.get(chainId);
70
68
  if (!provider || !provider.provider) {
71
- const new_provider = this.provider.getProvider(chainId, Provider_1.RpcType.HTTP);
69
+ const new_provider = this.provider.getProvider(chainId, Provider_1.RpcType.HTTP, provider_type);
72
70
  this.http_providers.set(chainId, { provider: new_provider.provider, url: new_provider.url });
73
71
  return new_provider;
74
72
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ercworldio/blockchain-shared",
3
- "version": "1.0.3-dev.0-PROJ-1281",
3
+ "version": "1.0.3-dev.0-PROJ-1281.2",
4
4
  "description": "Shared library for blockchain projects",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",