-
Notifications
You must be signed in to change notification settings - Fork 0
/
extender.ts
43 lines (41 loc) · 1.43 KB
/
extender.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import "@nomiclabs/hardhat-ethers";
import { extendEnvironment } from "hardhat/config";
import { lazyObject } from "hardhat/plugins";
import "./type-extensions";
import { GasModelProvider } from "@lacchain/gas-model-provider";
import { ContractFactory } from "ethers";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { HttpNetworkUserConfig } from "hardhat/types/config";
import { GasModelSignerModified } from "./GasModelModified";
extendEnvironment((hre: HardhatRuntimeEnvironment) => {
hre.lacchain = lazyObject(() => {
const gasModelProvider = new GasModelProvider(
(hre.network.config as HttpNetworkUserConfig).url
);
return {
provider: gasModelProvider,
getSigners: () => {
const { privateKeys, nodeAddress, expiration } = hre.network
.config as HttpNetworkUserConfig;
return (privateKeys || []).map(
(privateKey: string) =>
new GasModelSignerModified(
privateKey,
gasModelProvider,
nodeAddress,
expiration
)
);
},
deployContract: async (contract: ContractFactory, ...params) => {
const instance = await contract.deploy(...params);
const receipt = await instance.deployTransaction.wait();
return new hre.ethers.Contract(
receipt.contractAddress,
contract.interface,
contract.signer
);
},
};
});
});