UNPKG

1.34 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.createProviderProxy = void 0;
4const constants_1 = require("hardhat/internal/constants");
5const ethers_provider_wrapper_1 = require("./ethers-provider-wrapper");
6const updatable_target_proxy_1 = require("./updatable-target-proxy");
7/**
8 * This method returns a proxy that uses an underlying provider for everything.
9 *
10 * This underlying provider is replaced by a new one after a successful hardhat_reset,
11 * because ethers providers can have internal state that returns wrong results after
12 * the network is reset.
13 */
14function createProviderProxy(hardhatProvider) {
15 const initialProvider = new ethers_provider_wrapper_1.EthersProviderWrapper(hardhatProvider);
16 const { proxy: providerProxy, setTarget } = (0, updatable_target_proxy_1.createUpdatableTargetProxy)(initialProvider);
17 hardhatProvider.on(constants_1.HARDHAT_NETWORK_RESET_EVENT, () => {
18 setTarget(new ethers_provider_wrapper_1.EthersProviderWrapper(hardhatProvider));
19 });
20 hardhatProvider.on(constants_1.HARDHAT_NETWORK_REVERT_SNAPSHOT_EVENT, () => {
21 setTarget(new ethers_provider_wrapper_1.EthersProviderWrapper(hardhatProvider));
22 });
23 return providerProxy;
24}
25exports.createProviderProxy = createProviderProxy;
26//# sourceMappingURL=provider-proxy.js.map
\No newline at end of file