-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdeployLock.ts
86 lines (76 loc) · 3.85 KB
/
deployLock.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
import hre, { ethers, network } from 'hardhat'
import { getDeployConfig, DeployableNetworks, saveDeploymentOutput } from './deploy.config'
import { DeployManager } from './DeployManager'
import { logger } from '../../hardhat/utils'
import { getCurrentGasPriceForNetwork } from '../../lib/evm/getCurrentGasPrice'
import { forkIfHardhat } from './utils/forkDeployHelper'
import { Lock__factory, LockUpgradeable__factory } from '../../typechain-types'
import { deployLockFixture } from './fixtures/deployLockFixture'
import { createActionLog } from './utils/actionLog'
/**
* // NOTE: This is an example of the default hardhat deployment approach.
* This project takes deployments one step further by assigning each deployment
* its own task in ../tasks/ organized by date.
*/
async function main() {
// -------------------------------------------------------------------------------------------------------------------
// Deployment Setup
// -------------------------------------------------------------------------------------------------------------------
// Setup network and fork if hardhat
const currentNetwork = network.name as DeployableNetworks
const dryRunNetwork: DeployableNetworks = 'bsc'
const deployConfigNetwork = await forkIfHardhat(currentNetwork, dryRunNetwork)
// Estimate gas price
const estimatedGasPrice = await getCurrentGasPriceForNetwork(deployConfigNetwork)
logger.log(`Deploy estimated gas price: ${ethers.utils.formatUnits(estimatedGasPrice.toString(), 'gwei')} gwei`, `⛽`)
// Setup accounts
const accounts = await ethers.getSigners()
const [deployerAccount, hardhatAdminAccount, hardhatProxyAdminOwnerAddress] = accounts
// Optionally pass in accounts to be able to use them in the deployConfig
let deploymentVariables = await getDeployConfig(deployConfigNetwork)
if (currentNetwork === 'hardhat') {
logger.warn(`Using hardhat network, deploying with overriding accounts`)
deploymentVariables = await getDeployConfig(deployConfigNetwork, {
accountOverrides: {
adminAddress: hardhatAdminAccount.address,
proxyAdminOwnerAddress: hardhatProxyAdminOwnerAddress.address,
},
})
}
// Setup deploy manager, optionally pass in signer
const deployManager = await DeployManager.create({ signer: deployerAccount, gasPriceOverride: estimatedGasPrice })
// Actions to take after deployment to finalize deployment setup
const { pushActionsAndLog, pushActions, getActions, tryActionCatchAndLog } = createActionLog()
// -------------------------------------------------------------------------------------------------------------------
// Deployment
// -------------------------------------------------------------------------------------------------------------------
const lockDeployment = await deployLockFixture(hre, deployManager, {
accountOverrides: deploymentVariables.accounts,
contractOverrides: deploymentVariables.contractOverrides,
})
// -------------------------------------------------------------------------------------------------------------------
// Output
// -------------------------------------------------------------------------------------------------------------------
let output = {
deployedContracts: {
// Add in contract details here
...lockDeployment.addressOutput,
},
deploymentVariables,
NEXT_ACTIONS: getActions(),
}
try {
await saveDeploymentOutput(currentNetwork, output, true, true)
} catch (e) {
logger.error(`Error saving deployment output to file: ${e}`)
}
// NOTE: Verifications are verbose, would be nice to cut down on that. The contracts compile each time
logger.log('Verifying contracts...', '🔎')
await deployManager.verifyContracts()
}
// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main().catch((error) => {
console.error(error)
process.exitCode = 1
})