diff --git a/package.json b/package.json index cb33ddb..187a960 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ethers-multicall-provider", - "version": "6.2.0", + "version": "6.3.0", "description": "⚡🕰️ Drop-in solution to batch smart contract RPC calls in a single RPC query via Multicall!", "main": "lib/index.js", "files": [ @@ -42,7 +42,7 @@ "homepage": "https://github.com/rubilmax/ethers-multicall-provider#readme", "dependencies": { "dataloader": "^2.2.2", - "ethers": "^6.0.0" + "ethers": "^6.11.0" }, "devDependencies": { "@trivago/prettier-plugin-sort-imports": "^4.3.0", diff --git a/src/multicall-provider.ts b/src/multicall-provider.ts index 3c6ca5d..60fc8fb 100644 --- a/src/multicall-provider.ts +++ b/src/multicall-provider.ts @@ -1,12 +1,5 @@ import DataLoader from "dataloader"; -import { - BlockTag, - BytesLike, - AbstractProvider, - PerformActionRequest, - Network, - isHexString, -} from "ethers"; +import { BlockTag, AbstractProvider, PerformActionRequest } from "ethers"; import { multicallAddresses } from "./constants"; import { Multicall2, Multicall3 } from "./types"; @@ -25,9 +18,7 @@ export interface ContractCallRequest { export type MulticallProvider = T & { readonly _isMulticallProvider: boolean; - - fetchNetwork(): Promise; - _networkPromise: Promise; + readonly cache: boolean; maxMulticallDataLength: number; isMulticallEnabled: boolean; @@ -62,7 +53,7 @@ export class MulticallWrapper { // Overload provider - Object.defineProperties(provider, { + const multicallProvider = Object.defineProperties(provider, { _isMulticallProvider: { value: true, writable: false, @@ -75,6 +66,12 @@ export class MulticallWrapper { enumerable: true, configurable: false, }, + cache: { + value: cache, + writable: false, + enumerable: true, + configurable: false, + }, maxMulticallDataLength: { value: maxMulticallDataLength, writable: true, @@ -87,9 +84,7 @@ export class MulticallWrapper { enumerable: true, configurable: true, }, - }); - - const multicallProvider = provider as MulticallProvider; + }) as MulticallProvider; // Define execution context @@ -171,24 +166,6 @@ export class MulticallWrapper { } ); - // Expose `Provider.fetchNetwork` to fetch & update the network cache when needed - - const getNetwork = provider.getNetwork.bind(provider); - - multicallProvider.fetchNetwork = async function fetchNetwork(): Promise { - this._networkPromise = getNetwork(); - - return this._networkPromise; - }; - - multicallProvider.fetchNetwork(); - - // Overload `Provider._detectNetwork` to disable polling the network at each RPC call - - multicallProvider._detectNetwork = async function _detectNetwork(): Promise { - return this._networkPromise; - }; - // Overload `Provider._perform` const _perform = provider._perform.bind(provider); @@ -203,7 +180,7 @@ export class MulticallWrapper { if (!to || !data || multicallAddresses.has(to.toString().toLowerCase())) return _perform(req); - const network = await this._networkPromise; + const network = await this._detectNetwork(); const blockNumber = getBlockNumber(blockTag); const multicall = getMulticall(blockNumber, Number(network.chainId), provider); diff --git a/yarn.lock b/yarn.lock index 1ae896d..23b7509 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,10 +2,10 @@ # yarn lockfile v1 -"@adraffy/ens-normalize@1.9.2": - version "1.9.2" - resolved "https://registry.yarnpkg.com/@adraffy/ens-normalize/-/ens-normalize-1.9.2.tgz#60111a5d9db45b2e5cbb6231b0bb8d97e8659316" - integrity sha512-0h+FrQDqe2Wn+IIGFkTCd4aAwTJ+7834Ek1COohCyV26AXhwQ7WQaz+4F/nLOeVl/3BtWHOHLPsq46V8YB46Eg== +"@adraffy/ens-normalize@1.10.1": + version "1.10.1" + resolved "https://registry.yarnpkg.com/@adraffy/ens-normalize/-/ens-normalize-1.10.1.tgz#63430d04bd8c5e74f8d7d049338f1cd9d4f02069" + integrity sha512-96Z2IP3mYmF1Xg2cDm8f1gWGf/HUVedQ3FMifV4kG/PQ4yEP51xDtRAEfhVNt5f/uzpNkZHwWQuUcu6D6K+Ekw== "@ampproject/remapping@^2.2.0": version "2.2.1" @@ -714,15 +714,17 @@ "@jridgewell/resolve-uri" "^3.1.0" "@jridgewell/sourcemap-codec" "^1.4.14" -"@noble/hashes@1.1.2": - version "1.1.2" - resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.1.2.tgz#e9e035b9b166ca0af657a7848eb2718f0f22f183" - integrity sha512-KYRCASVTv6aeUi1tsF8/vpyR7zpfs3FUzy2Jqm+MU+LmUKhQ0y2FpfwqkCcxSg2ua4GALJd8k2R76WxwZGbQpA== +"@noble/curves@1.2.0": + version "1.2.0" + resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.2.0.tgz#92d7e12e4e49b23105a2555c6984d41733d65c35" + integrity sha512-oYclrNgRaM9SsBUBVbb8M6DTV7ZHRTKugureoYEncY5c65HOmRzvSiTE3y5CYaPYJA/GVkrhXEoF0M3Ya9PMnw== + dependencies: + "@noble/hashes" "1.3.2" -"@noble/secp256k1@1.7.1": - version "1.7.1" - resolved "https://registry.yarnpkg.com/@noble/secp256k1/-/secp256k1-1.7.1.tgz#b251c70f824ce3ca7f8dc3df08d58f005cc0507c" - integrity sha512-hOUk6AyBFmqVrv7k5WAw/LpszxVbj9gGN4JRkIX52fdFAj1UA61KXmZDvqVEm+pOyec3+fIeZB02LYa/pWOArw== +"@noble/hashes@1.3.2": + version "1.3.2" + resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.2.tgz#6f26dbc8fbc7205873ce3cee2f690eba0d421b39" + integrity sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ== "@sinclair/typebox@^0.27.8": version "0.27.8" @@ -1569,14 +1571,14 @@ esprima@^4.0.0: resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.1.tgz#13b04cdb3e6c5d19df91ab6987a8695619b0aa71" integrity sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A== -ethers@^6.0.0: - version "6.7.1" - resolved "https://registry.yarnpkg.com/ethers/-/ethers-6.7.1.tgz#9c65e8b5d8e9ad77b7e8cf1c46099892cfafad49" - integrity sha512-qX5kxIFMfg1i+epfgb0xF4WM7IqapIIu50pOJ17aebkxxa4BacW5jFrQRmCJpDEg2ZK2oNtR5QjrQ1WDBF29dA== +ethers@^6.11.0: + version "6.11.1" + resolved "https://registry.yarnpkg.com/ethers/-/ethers-6.11.1.tgz#96aae00b627c2e35f9b0a4d65c7ab658259ee6af" + integrity sha512-mxTAE6wqJQAbp5QAe/+o+rXOID7Nw91OZXvgpjDa1r4fAbq2Nu314oEZSbjoRLacuCzs7kUC3clEvkCQowffGg== dependencies: - "@adraffy/ens-normalize" "1.9.2" - "@noble/hashes" "1.1.2" - "@noble/secp256k1" "1.7.1" + "@adraffy/ens-normalize" "1.10.1" + "@noble/curves" "1.2.0" + "@noble/hashes" "1.3.2" "@types/node" "18.15.13" aes-js "4.0.0-beta.5" tslib "2.4.0"