forked from defisaver/defisaver-v3-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhardhat-tasks.js
More file actions
93 lines (83 loc) · 3.22 KB
/
Copy pathhardhat-tasks.js
File metadata and controls
93 lines (83 loc) · 3.22 KB
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
/* eslint-disable no-undef */
const { execSync } = require('child_process');
const {
flatten,
verifyContract,
deployContract,
findPathByContractName,
encryptPrivateKey,
} = require('./hardhat-tasks-functions');
task('fladepver', 'Deploys and verifies contract(s) on etherscan')
.addPositionalParam('gas', 'The price (in gwei) per unit of gas')
.addVariadicPositionalParam(
'contractNames',
'The names of the contracts to flatten, deploy and verify',
[],
types.string,
)
.addFlag('nonce', 'Use this flag to specify nonce: --nonce NUMBER')
.setAction(async (args) => {
const newArgs = { ...args };
const contracts = args.contractNames;
if (contracts.length === 0) {
throw new Error(
'At least one contract name is required. Usage: npx hardhat fladepver GAS_PRICE Contract1 Contract2 ... [--nonce NUMBER]',
);
}
// Fla - Flatten
await Promise.all(
contracts.map(async (contractName) => {
const path = await findPathByContractName(contractName);
await flatten(path);
}),
);
// Dep - Deploy
const deployedAddresses = await deployContract(contracts, newArgs);
// Ver - Verify
console.log('\nStarting contract verification...');
const verificationPromises = Object.entries(deployedAddresses).map(
async ([contractName, contractAddress]) => {
try {
await verifyContract(contractAddress, contractName);
console.log(`✓ ${contractName} verified successfully`);
} catch (error) {
console.log(`✗ Failed to verify ${contractName}: ${error.message}`);
}
},
);
await Promise.all(verificationPromises);
});
task('customVerify', 'Verifies a contract on etherscan')
.addOptionalPositionalParam('contractAddress', 'Address where the contract is deployed')
.addOptionalPositionalParam('contractName', 'Name of the contract to verify')
.setAction(async (args) => {
await verifyContract(args.contractAddress, args.contractName);
});
task('customFlatten', 'Flattens for our DFS team')
.addOptionalPositionalParam('contractName', 'The contract to flatten')
.setAction(async (args) => {
await flatten(await findPathByContractName(args.contractName));
});
task('encryptPrivateKey', 'Encrypt private key').setAction(async () => {
encryptPrivateKey();
});
task('deployOnFork', 'Deploys contracts on an existing fork')
.addVariadicPositionalParam(
'contractNames',
'The names of the contracts to deploy',
[],
types.string,
)
.setAction(async (args) => {
const contractNames = args.contractNames.join(' ');
try {
execSync('npx', ['hardhat', 'run', './scripts/utils/deploy-on-fork.js', '--network', 'fork'], {
stdio: 'inherit',
shell: true,
env: { ...process.env, CONTRACTS: contractNames },
});
} catch (error) {
console.error(`Command failed: ${error}`);
process.exit(1);
}
});