@sentio/sdk 2.16.2-rc.4 → 2.17.0-rc.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.
@@ -70,11 +70,23 @@ class QueuedStaticJsonRpcProvider extends JsonRpcProvider {
70
70
  this.executor = new PQueue({ concurrency: concurrency });
71
71
  }
72
72
  async send(method, params) {
73
+ if (method !== 'eth_call') {
74
+ return super.send(method, params);
75
+ }
73
76
  const tag = getTag(method, params);
74
77
  const block = params[params.length - 1];
75
78
  let perform = this.#performCache.get(tag);
76
79
  if (!perform) {
77
80
  perform = this.executor.add(() => super.send(method, params));
81
+ perform.catch((e) => {
82
+ if (e.code !== 'CALL_EXCEPTION') {
83
+ setTimeout(() => {
84
+ if (this.#performCache.get(tag) === perform) {
85
+ this.#performCache.delete(tag);
86
+ }
87
+ }, 1000);
88
+ }
89
+ });
78
90
  this.#performCache.set(tag, perform);
79
91
  // For non latest block call, we cache permanently, otherwise we cache for one minute
80
92
  if (block === 'latest') {
@@ -1 +1 @@
1
- {"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/eth/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,OAAO,EAAY,MAAM,QAAQ,CAAA;AAE3D,OAAO,MAAM,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,eAAe,CAAC,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;AAErE,MAAM,SAAS,GAAG,IAAI,GAAG,EAA2B,CAAA;AAEpD,oFAAoF;AACpF,uBAAuB;AACvB,uCAAuC;AACvC,MAAM;AACN,6CAA6C;AAC7C,2CAA2C;AAC3C,MAAM;AACN,sBAAsB;AACtB,IAAI;AAEJ,MAAM,UAAU,WAAW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G,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QACzC,IAAI,CAAC,OAAO,EAAE;YACZ,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;YAC7D,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;YACpC,qFAAqF;YACrF,IAAI,KAAK,KAAK,QAAQ,EAAE;gBACtB,UAAU,CAAC,GAAG,EAAE;oBACd,IAAI,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,OAAO,EAAE;wBAC3C,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;qBAC/B;gBACH,CAAC,EAAE,EAAE,GAAG,IAAI,CAAC,CAAA;aACd;SACF;QAED,MAAM,MAAM,GAAG,MAAM,OAAO,CAAA;QAC5B,IAAI,CAAC,MAAM,EAAE;YACX,MAAM,KAAK,CAAC,0BAA0B,CAAC,CAAA;SACxC;QACD,OAAO,MAAM,CAAA;IACf,CAAC;CACF","sourcesContent":["import { JsonRpcProvider, Network, Provider } from 'ethers'\n\nimport PQueue from 'p-queue'\nimport { Endpoints } from '@sentio/runtime'\nimport { EthChainId } from '../core/chain.js'\n\nexport const DummyProvider = new JsonRpcProvider('', Network.from(1))\n\nconst providers = new Map<string, JsonRpcProvider>()\n\n// export function getEthChainId(networkish?: EthContext | EthChainId): EthChainId {\n// if (!networkish) {\n// networkish = EthChainId.ETHEREUM\n// }\n// if (networkish instanceof BaseContext) {\n// networkish = networkish.getChainId()\n// }\n// return networkish\n// }\n\nexport function getProvider(chainId?: EthChainId): Provider {\n // const network = getNetworkFromCtxOrNetworkish(networkish)\n if (!chainId) {\n chainId = EthChainId.ETHEREUM\n }\n const network = Network.from(parseInt(chainId))\n // TODO check if other key needed\n\n const address = Endpoints.INSTANCE.chainServer.get(chainId)\n const key = network.chainId.toString() + '-' + address\n let provider = providers.get(key)\n\n if (provider) {\n return provider\n }\n\n if (address === undefined) {\n throw Error(\n 'Provider not found for chain ' +\n network.chainId +\n ', configured chains: ' +\n [...Endpoints.INSTANCE.chainServer.keys()].join(' ')\n )\n }\n provider = new QueuedStaticJsonRpcProvider(address, network, Endpoints.INSTANCE.concurrency)\n providers.set(network.chainId.toString(), provider)\n return provider\n}\n\nfunction getTag(prefix: string, value: any): string {\n return (\n prefix +\n ':' +\n JSON.stringify(value, (k, v) => {\n if (v == null) {\n return 'null'\n }\n if (typeof v === 'bigint') {\n return `bigint:${v.toString()}`\n }\n if (typeof v === 'string') {\n return v.toLowerCase()\n }\n\n // Sort object keys\n if (typeof v === 'object' && !Array.isArray(v)) {\n const keys = Object.keys(v)\n keys.sort()\n return keys.reduce((accum, key) => {\n accum[key] = v[key]\n return accum\n }, <any>{})\n }\n\n return v\n })\n )\n}\n\nclass QueuedStaticJsonRpcProvider extends JsonRpcProvider {\n executor: PQueue\n #performCache = new Map<string, Promise<any>>()\n\n constructor(url: string, network: Network, concurrency: number) {\n // TODO re-enable match when possible\n super(url, network, { staticNetwork: network, batchMaxCount: 1 })\n this.executor = new PQueue({ concurrency: concurrency })\n }\n\n async send(method: string, params: Array<any>): Promise<any> {\n const tag = getTag(method, params)\n const block = params[params.length - 1]\n let perform = this.#performCache.get(tag)\n if (!perform) {\n perform = this.executor.add(() => super.send(method, params))\n this.#performCache.set(tag, perform)\n // For non latest block call, we cache permanently, otherwise we cache for one minute\n if (block === 'latest') {\n setTimeout(() => {\n if (this.#performCache.get(tag) === perform) {\n this.#performCache.delete(tag)\n }\n }, 60 * 1000)\n }\n }\n\n const result = await perform\n if (!result) {\n throw Error('Unexpected null response')\n }\n return result\n }\n}\n"]}
1
+ {"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/eth/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,OAAO,EA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C,qFAAqF;YACrF,IAAI,KAAK,KAAK,QAAQ,EAAE;gBACtB,UAAU,CAAC,GAAG,EAAE;oBACd,IAAI,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,OAAO,EAAE;wBAC3C,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;qBAC/B;gBACH,CAAC,EAAE,EAAE,GAAG,IAAI,CAAC,CAAA;aACd;SACF;QAED,MAAM,MAAM,GAAG,MAAM,OAAO,CAAA;QAC5B,IAAI,CAAC,MAAM,EAAE;YACX,MAAM,KAAK,CAAC,0BAA0B,CAAC,CAAA;SACxC;QACD,OAAO,MAAM,CAAA;IACf,CAAC;CACF","sourcesContent":["import { JsonRpcProvider, Network, Provider } from 'ethers'\n\nimport PQueue from 'p-queue'\nimport { Endpoints } from '@sentio/runtime'\nimport { EthChainId } from '../core/chain.js'\n\nexport const DummyProvider = new JsonRpcProvider('', Network.from(1))\n\nconst providers = new Map<string, JsonRpcProvider>()\n\n// export function getEthChainId(networkish?: EthContext | EthChainId): EthChainId {\n// if (!networkish) {\n// networkish = EthChainId.ETHEREUM\n// }\n// if (networkish instanceof BaseContext) {\n// networkish = networkish.getChainId()\n// }\n// return networkish\n// }\n\nexport function getProvider(chainId?: EthChainId): Provider {\n // const network = getNetworkFromCtxOrNetworkish(networkish)\n if (!chainId) {\n chainId = EthChainId.ETHEREUM\n }\n const network = Network.from(parseInt(chainId))\n // TODO check if other key needed\n\n const address = Endpoints.INSTANCE.chainServer.get(chainId)\n const key = network.chainId.toString() + '-' + address\n let provider = providers.get(key)\n\n if (provider) {\n return provider\n }\n\n if (address === undefined) {\n throw Error(\n 'Provider not found for chain ' +\n network.chainId +\n ', configured chains: ' +\n [...Endpoints.INSTANCE.chainServer.keys()].join(' ')\n )\n }\n provider = new QueuedStaticJsonRpcProvider(address, network, Endpoints.INSTANCE.concurrency)\n providers.set(network.chainId.toString(), provider)\n return provider\n}\n\nfunction getTag(prefix: string, value: any): string {\n return (\n prefix +\n ':' +\n JSON.stringify(value, (k, v) => {\n if (v == null) {\n return 'null'\n }\n if (typeof v === 'bigint') {\n return `bigint:${v.toString()}`\n }\n if (typeof v === 'string') {\n return v.toLowerCase()\n }\n\n // Sort object keys\n if (typeof v === 'object' && !Array.isArray(v)) {\n const keys = Object.keys(v)\n keys.sort()\n return keys.reduce((accum, key) => {\n accum[key] = v[key]\n return accum\n }, <any>{})\n }\n\n return v\n })\n )\n}\n\nclass QueuedStaticJsonRpcProvider extends JsonRpcProvider {\n executor: PQueue\n #performCache = new Map<string, Promise<any>>()\n\n constructor(url: string, network: Network, concurrency: number) {\n // TODO re-enable match when possible\n super(url, network, { staticNetwork: network, batchMaxCount: 1 })\n this.executor = new PQueue({ concurrency: concurrency })\n }\n\n async send(method: string, params: Array<any>): Promise<any> {\n if (method !== 'eth_call') {\n return super.send(method, params)\n }\n const tag = getTag(method, params)\n const block = params[params.length - 1]\n let perform = this.#performCache.get(tag)\n if (!perform) {\n perform = this.executor.add(() => super.send(method, params))\n perform.catch((e) => {\n if (e.code !== 'CALL_EXCEPTION') {\n setTimeout(() => {\n if (this.#performCache.get(tag) === perform) {\n this.#performCache.delete(tag)\n }\n }, 1000)\n }\n })\n this.#performCache.set(tag, perform)\n // For non latest block call, we cache permanently, otherwise we cache for one minute\n if (block === 'latest') {\n setTimeout(() => {\n if (this.#performCache.get(tag) === perform) {\n this.#performCache.delete(tag)\n }\n }, 60 * 1000)\n }\n }\n\n const result = await perform\n if (!result) {\n throw Error('Unexpected null response')\n }\n return result\n }\n}\n"]}
@@ -69,6 +69,8 @@ export async function getPriceByTypeOrSymbolInternal(priceClient, date, coinId,
69
69
  if (e.code === Status.NOT_FOUND) {
70
70
  return undefined;
71
71
  }
72
+ // TODO maybe use small set of error
73
+ priceMap.delete(key);
72
74
  throw e;
73
75
  });
74
76
  priceMap.set(key, price);
@@ -1 +1 @@
1
- {"version":3,"file":"price.js","sourceRoot":"","sources":["../../src/utils/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ACrB;QACD,OAAO,GAAG,CAAC,KAAK,CAAA;IAClB,CAAC,CAAC;SACD,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;QACX,IAAI,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,SAAS,EAAE;YAC/B,OAAO,SAAS,CAAA;SACjB;QACD,MAAM,CAAC,CAAA;IACT,CAAC,CAAC,CAAA;IACJ,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;IACxB,OAAO,KAAK,CAAA;AACd,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,OAAgB,EAChB,QAAgB,EAChB,IAAU,EACV,OAAsB;IAEtB,OAAO,sBAAsB,CAC3B,IAAI,EACJ;QACE,OAAO,EAAE;YACP,KAAK,EAAE,OAAO;YACd,OAAO,EAAE,QAAQ;SAClB;KACF,EACD,OAAO,CACR,CAAA;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,MAAc,EACd,IAAU,EACV,OAAsB;IAEtB,OAAO,sBAAsB,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,CAAA;AAC1D,CAAC;AAED,SAAS,UAAU,CAAC,IAAU;IAC5B,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,IAAI,CAAC,WAAW,EAAE,GAAG,CAAC,EAAE,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AACrF,CAAC","sourcesContent":["import { CoinID, PriceServiceClient, PriceServiceDefinition } from '@sentio/protos/price'\nimport { createChannel, createClientFactory, Status } from 'nice-grpc'\nimport { prometheusClientMiddleware } from 'nice-grpc-prometheus'\nimport { retryMiddleware, RetryOptions } from 'nice-grpc-client-middleware-retry'\nimport { Endpoints } from '@sentio/runtime'\nimport { ChainId } from '../core/chain.js'\n\nexport function getPriceClient(address?: string) {\n if (!address) {\n address = Endpoints.INSTANCE.priceFeedAPI\n }\n const channel = createChannel(address)\n\n return createClientFactory()\n .use(prometheusClientMiddleware())\n .use(retryMiddleware)\n .create(PriceServiceDefinition, channel)\n}\n\nconst priceMap = new Map<string, Promise<number | undefined>>()\nlet priceClient: PriceServiceClient<RetryOptions>\n\ninterface PriceOptions {\n toleranceInDays?: number\n}\nasync function getPriceByTypeOrSymbol(date: Date, coinId: CoinID, options?: PriceOptions): Promise<number | undefined> {\n if (!priceClient) {\n priceClient = getPriceClient()\n }\n return getPriceByTypeOrSymbolInternal(priceClient, date, coinId, options)\n}\n\nexport async function getPriceByTypeOrSymbolInternal(\n priceClient: PriceServiceClient<RetryOptions>,\n date: Date,\n coinId: CoinID,\n options?: PriceOptions\n): Promise<number | undefined> {\n const dateStr = dateString(date)\n const todayDateString = dateString(new Date())\n\n let key: string\n if (coinId.symbol) {\n key = `${coinId.symbol}-${dateStr}`\n } else {\n key = `${coinId.address?.address}-${coinId.address?.chain}-${dateStr}`\n }\n let price = priceMap.get(key)\n if (price) {\n return price\n }\n\n const response = priceClient.getPrice(\n {\n timestamp: date,\n coinId,\n },\n {\n retry: true,\n retryMaxAttempts: 5,\n }\n )\n price = response\n .then((res) => {\n if (res.timestamp) {\n const responseDateString = dateString(res.timestamp)\n if (responseDateString === todayDateString) {\n priceMap.delete(key)\n } else {\n // https://www.javatpoint.com/javascript-date-difference\n const diff = Math.abs(res.timestamp.getTime() - date.getTime())\n const daysDiff = diff / (1000 * 60 * 60 * 24)\n const tolerance = options?.toleranceInDays || 2\n if (daysDiff > tolerance) {\n priceMap.delete(key)\n return undefined\n }\n }\n } else {\n priceMap.delete(key)\n }\n return res.price\n })\n .catch((e) => {\n if (e.code === Status.NOT_FOUND) {\n return undefined\n }\n throw e\n })\n priceMap.set(key, price)\n return price\n}\n\n/**\n *\n * @param chainId chain id refers to CHAIN_MAP\n * @param coinType\n * @param date\n * @param options other behavior options\n */\nexport async function getPriceByType(\n chainId: ChainId,\n coinType: string,\n date: Date,\n options?: PriceOptions\n): Promise<number | undefined> {\n return getPriceByTypeOrSymbol(\n date,\n {\n address: {\n chain: chainId,\n address: coinType,\n },\n },\n options\n )\n}\n\n/**\n * @param symbol token symbol like BTC, etc\n * @param date\n * @param options other behavior options\n */\nexport async function getPriceBySymbol(\n symbol: string,\n date: Date,\n options?: PriceOptions\n): Promise<number | undefined> {\n return getPriceByTypeOrSymbol(date, { symbol }, options)\n}\n\nfunction dateString(date: Date) {\n return [date.getUTCDate(), date.getUTCMonth() + 1, date.getUTCFullYear()].join('-')\n}\n"]}
1
+ {"version":3,"file":"price.js","sourceRoot":"","sources":["../../src/utils/price.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,sBAAsB,EAAE,MAAM,sBAAsB,CAAA;AACzF,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AACtE,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAA;AACjE,OAAO,EAAE,eAAe,EAAgB,MAAM,mCAAmC,CAAA;AACjF,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAG3C,MAAM,UAAU,cAAc,CAAC,OAAgB;IAC7C,IAAI,CAAC,OAAO,EAAE;QACZ,OAAO,GAAG,SAAS,CAAC,QAAQ,CAAC,YAAY,CAAA;KAC1C;IACD,MAAM,OAAO,GAAG,aAAa,CAAC,OAAO,CAAC,CAAA;IAEtC,OAAO,mBAAmB,EAAE;SACzB,GAAG,CAAC,0BAA0B,EAAE,CAAC;SACjC,GAAG,CAAC,eAAe,CAAC;SACpB,MAAM,CAAC,sBAAsB,EAAE,OAAO,CAAC,CAAA;AAC5C,CAAC;AAED,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAuC,CAAA;AAC/D,IAAI,WAA6C,CAAA;AAKjD,KAAK,UAAU,sBAAsB,CAAC,IAAU,EAAE,MAAc,EAAE,OAAsB;IACtF,IAAI,CAAC,WAAW,EAAE;QAChB,WAAW,GAA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,UAAU,CAAC,IAAU;IAC5B,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,IAAI,CAAC,WAAW,EAAE,GAAG,CAAC,EAAE,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AACrF,CAAC","sourcesContent":["import { CoinID, PriceServiceClient, PriceServiceDefinition } from '@sentio/protos/price'\nimport { createChannel, createClientFactory, Status } from 'nice-grpc'\nimport { prometheusClientMiddleware } from 'nice-grpc-prometheus'\nimport { retryMiddleware, RetryOptions } from 'nice-grpc-client-middleware-retry'\nimport { Endpoints } from '@sentio/runtime'\nimport { ChainId } from '../core/chain.js'\n\nexport function getPriceClient(address?: string) {\n if (!address) {\n address = Endpoints.INSTANCE.priceFeedAPI\n }\n const channel = createChannel(address)\n\n return createClientFactory()\n .use(prometheusClientMiddleware())\n .use(retryMiddleware)\n .create(PriceServiceDefinition, channel)\n}\n\nconst priceMap = new Map<string, Promise<number | undefined>>()\nlet priceClient: PriceServiceClient<RetryOptions>\n\ninterface PriceOptions {\n toleranceInDays?: number\n}\nasync function getPriceByTypeOrSymbol(date: Date, coinId: CoinID, options?: PriceOptions): Promise<number | undefined> {\n if (!priceClient) {\n priceClient = getPriceClient()\n }\n return getPriceByTypeOrSymbolInternal(priceClient, date, coinId, options)\n}\n\nexport async function getPriceByTypeOrSymbolInternal(\n priceClient: PriceServiceClient<RetryOptions>,\n date: Date,\n coinId: CoinID,\n options?: PriceOptions\n): Promise<number | undefined> {\n const dateStr = dateString(date)\n const todayDateString = dateString(new Date())\n\n let key: string\n if (coinId.symbol) {\n key = `${coinId.symbol}-${dateStr}`\n } else {\n key = `${coinId.address?.address}-${coinId.address?.chain}-${dateStr}`\n }\n let price = priceMap.get(key)\n if (price) {\n return price\n }\n\n const response = priceClient.getPrice(\n {\n timestamp: date,\n coinId,\n },\n {\n retry: true,\n retryMaxAttempts: 5,\n }\n )\n price = response\n .then((res) => {\n if (res.timestamp) {\n const responseDateString = dateString(res.timestamp)\n if (responseDateString === todayDateString) {\n priceMap.delete(key)\n } else {\n // https://www.javatpoint.com/javascript-date-difference\n const diff = Math.abs(res.timestamp.getTime() - date.getTime())\n const daysDiff = diff / (1000 * 60 * 60 * 24)\n const tolerance = options?.toleranceInDays || 2\n if (daysDiff > tolerance) {\n priceMap.delete(key)\n return undefined\n }\n }\n } else {\n priceMap.delete(key)\n }\n return res.price\n })\n .catch((e) => {\n if (e.code === Status.NOT_FOUND) {\n return undefined\n }\n // TODO maybe use small set of error\n priceMap.delete(key)\n throw e\n })\n priceMap.set(key, price)\n return price\n}\n\n/**\n *\n * @param chainId chain id refers to CHAIN_MAP\n * @param coinType\n * @param date\n * @param options other behavior options\n */\nexport async function getPriceByType(\n chainId: ChainId,\n coinType: string,\n date: Date,\n options?: PriceOptions\n): Promise<number | undefined> {\n return getPriceByTypeOrSymbol(\n date,\n {\n address: {\n chain: chainId,\n address: coinType,\n },\n },\n options\n )\n}\n\n/**\n * @param symbol token symbol like BTC, etc\n * @param date\n * @param options other behavior options\n */\nexport async function getPriceBySymbol(\n symbol: string,\n date: Date,\n options?: PriceOptions\n): Promise<number | undefined> {\n return getPriceByTypeOrSymbol(date, { symbol }, options)\n}\n\nfunction dateString(date: Date) {\n return [date.getUTCDate(), date.getUTCMonth() + 1, date.getUTCFullYear()].join('-')\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentio/sdk",
3
- "version": "2.16.2-rc.4",
3
+ "version": "2.17.0-rc.2",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "exports": {
@@ -71,8 +71,8 @@
71
71
  "typedoc": "^0.24.1",
72
72
  "utility-types": "^3.10.0",
73
73
  "yaml": "^2.2.1",
74
- "@sentio/protos": "2.16.2-rc.4",
75
- "@sentio/runtime": "^2.16.2-rc.4"
74
+ "@sentio/protos": "2.17.0-rc.2",
75
+ "@sentio/runtime": "^2.17.0-rc.2"
76
76
  },
77
77
  "peerDependencies": {
78
78
  "tsup": "npm:@sentio/tsup@^6.7.0"
@@ -88,11 +88,23 @@ class QueuedStaticJsonRpcProvider extends JsonRpcProvider {
88
88
  }
89
89
 
90
90
  async send(method: string, params: Array<any>): Promise<any> {
91
+ if (method !== 'eth_call') {
92
+ return super.send(method, params)
93
+ }
91
94
  const tag = getTag(method, params)
92
95
  const block = params[params.length - 1]
93
96
  let perform = this.#performCache.get(tag)
94
97
  if (!perform) {
95
98
  perform = this.executor.add(() => super.send(method, params))
99
+ perform.catch((e) => {
100
+ if (e.code !== 'CALL_EXCEPTION') {
101
+ setTimeout(() => {
102
+ if (this.#performCache.get(tag) === perform) {
103
+ this.#performCache.delete(tag)
104
+ }
105
+ }, 1000)
106
+ }
107
+ })
96
108
  this.#performCache.set(tag, perform)
97
109
  // For non latest block call, we cache permanently, otherwise we cache for one minute
98
110
  if (block === 'latest') {
@@ -85,6 +85,8 @@ export async function getPriceByTypeOrSymbolInternal(
85
85
  if (e.code === Status.NOT_FOUND) {
86
86
  return undefined
87
87
  }
88
+ // TODO maybe use small set of error
89
+ priceMap.delete(key)
88
90
  throw e
89
91
  })
90
92
  priceMap.set(key, price)