-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds hardhat deploy with its utils (#26)
- Loading branch information
Showing
9 changed files
with
135 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ coverage.json | |
artifacts | ||
cache | ||
typechained | ||
deployments | ||
|
||
# JS | ||
node_modules | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { HardhatRuntimeEnvironment } from 'hardhat/types'; | ||
import { DeployFunction } from 'hardhat-deploy/types'; | ||
import { getChainId, shouldVerifyContract } from '../utils/deploy'; | ||
|
||
export const INITIAL_GREET: { [chainId: string]: string } = { | ||
'1': 'Halo!', | ||
'137': 'Halo to polygon network!', | ||
}; | ||
|
||
const deployFunction: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { | ||
const { deployer } = await hre.getNamedAccounts(); | ||
|
||
const chainId = await getChainId(hre); | ||
|
||
const deploy = await hre.deployments.deploy('Greeter', { | ||
contract: 'contracts/Greeter.sol:Greeter', | ||
from: deployer, | ||
args: [INITIAL_GREET[chainId]], | ||
log: true, | ||
}); | ||
|
||
if (await shouldVerifyContract(deploy)) { | ||
await hre.run('verify:verify', { | ||
address: deploy.address, | ||
constructorArguments: [INITIAL_GREET[chainId]], | ||
}); | ||
} | ||
}; | ||
deployFunction.dependencies = []; | ||
deployFunction.tags = ['Greeter']; | ||
export default deployFunction; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { ethers } from 'hardhat'; | ||
import { DeployResult } from 'hardhat-deploy/dist/types'; | ||
import { HardhatNetworkUserConfig, HardhatRuntimeEnvironment } from 'hardhat/types'; | ||
|
||
let testChainId: number; | ||
|
||
export const setTestChainId = (chainId: number): void => { | ||
testChainId = chainId; | ||
}; | ||
|
||
export const getChainId = async (hre: HardhatRuntimeEnvironment): Promise<number> => { | ||
if (!!process.env.TEST) { | ||
if (!testChainId) throw new Error('Should specify chain id of test'); | ||
return testChainId; | ||
} | ||
if (!!process.env.FORK) return getRealChainIdOfFork(hre); | ||
return await (hre as any).getChainId(); | ||
}; | ||
|
||
export const getRealChainIdOfFork = (hre: HardhatRuntimeEnvironment): number => { | ||
const config = hre.network.config as HardhatNetworkUserConfig; | ||
if (config.forking?.url.includes('mainnet')) return 1; | ||
if (config.forking?.url.includes('ftm') || config.forking?.url.includes('fantom')) return 250; | ||
if (config.forking?.url.includes('polygon')) return 137; | ||
throw new Error('Should specify chain id of fork'); | ||
}; | ||
|
||
export const shouldVerifyContract = async (deploy: DeployResult): Promise<boolean> => { | ||
if (process.env.FORK || process.env.TEST) return false; | ||
if (!deploy.newlyDeployed) return false; | ||
const txReceipt = await ethers.provider.getTransaction(deploy.receipt!.transactionHash); | ||
await txReceipt.wait(10); | ||
return true; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters