-
Notifications
You must be signed in to change notification settings - Fork 1
/
hardhat-deployer.ts
111 lines (94 loc) · 2.98 KB
/
hardhat-deployer.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import { ITenderlyContractData, TDeployArgs, TProxyKind } from "../missions/types";
import axios from "axios";
import { IContractV6 } from "../campaign/types";
import { IHardhatBase, ISignerBase, IHardhatDeployerArgs } from "./types";
export class HardhatDeployer <
H extends IHardhatBase,
S extends ISignerBase
> {
hre : H;
signer : S;
env : string;
constructor ({
hre,
signer,
env,
} : IHardhatDeployerArgs<H, S>) {
this.hre = hre;
this.signer = signer;
this.env = env;
}
async getFactory (contractName : string, signer ?: S) {
const attachedSigner = signer ?? this.signer;
return this.hre.ethers.getContractFactory(contractName, attachedSigner);
}
async getContractObject (contractName : string, address : string) {
const factory = await this.getFactory(contractName);
return factory.attach(address);
}
async deployProxy ({
contractName,
args,
kind,
} : {
contractName : string;
args : TDeployArgs;
kind : TProxyKind;
}) : Promise<IContractV6> {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const contractFactory = await this.getFactory(contractName);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const deployment = await this.hre.upgrades!.deployProxy(contractFactory, args, {
kind,
});
return deployment.waitForDeployment();
}
async deployContract (contractName : string, args : TDeployArgs) : Promise<IContractV6> {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const contractFactory = await this.getFactory(contractName);
const deployment = await contractFactory.deploy(...args);
return deployment.waitForDeployment();
}
getContractArtifact (contractName : string) {
return this.hre.artifacts.readArtifactSync(contractName);
}
async getProxyImplAddress (proxyContract : string) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return this.hre.upgrades!.erc1967.getImplementationAddress(proxyContract);
}
async getBytecodeFromChain (address : string) {
return this.hre.ethers.provider.getCode(address);
}
async tenderlyPush (contracts : Array<ITenderlyContractData>) {
const inst = axios.create({
baseURL: "https://api.tenderly.co/",
headers: {
"Content-Type": "application/json",
"X-Access-Key": process.env.TENDERLY_ACCESS_KEY,
},
});
const { data } = await inst.post(
`api/v2/accounts/${process.env.TENDERLY_ACCOUNT_ID}/projects/${process.env.TENDERLY_PROJECT_SLUG}/contracts`,
{
contracts,
}
);
return data;
}
async etherscanVerify ({
address,
ctorArgs,
} : {
address : string;
ctorArgs ?: TDeployArgs;
}) {
return this.hre.run("verify:verify", {
address,
// this should only be used for non-proxied contracts
// or proxy impls that have actual constructors
constructorArguments: ctorArgs,
});
}
}