diff --git a/hardhat.config.ts b/hardhat.config.ts index aa8588a..101cd7b 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -145,19 +145,21 @@ task('deploy', 'Deploy ERC721M') '0x0000000000000000000000000000000000000000', ) .addOptionalParam('autoapproveaddress', 'auto approve address') - .addParam( + .addParam( 'increasesupply', - 'whether or not to enable increasing supply behavior', 'false', + 'whether or not to enable increasing supply behavior', false, + types.boolean, ) - .addParam('pausable', 'whether to allow transfers to be paused', 'false') - .addParam('useoperatorfilterer', 'whether or not to use operator filterer', 'false') - .addParam( + .addParam('pausable', 'whether to allow transfers to be paused', false, types.boolean) + .addParam('useoperatorfilterer', 'whether or not to use operator filterer', false, types.boolean) + .addParam( 'openedition', 'whether or not a open edition mint (unlimited supply, 999,999,999)', - 'false', + false, + types.boolean, ) - .addOptionalParam('useerc721c', 'whether or not to use ERC721C', 'true') - .addOptionalParam('useerc2198', 'whether or not to use ERC2198', 'true') + .addOptionalParam('useerc721c', 'whether or not to use ERC721C', true, types.boolean) + .addOptionalParam('useerc2198', 'whether or not to use ERC2198', true, types.boolean) .addOptionalParam('erc2198royaltyreceiver', 'erc2198 royalty receiver address') .addOptionalParam('erc2198royaltyfeenumerator', 'erc2198 royalty fee numerator') .setAction(deploy); diff --git a/scripts/deploy.ts b/scripts/deploy.ts index e867b37..060282f 100644 --- a/scripts/deploy.ts +++ b/scripts/deploy.ts @@ -7,7 +7,7 @@ import { confirm } from '@inquirer/prompts'; import { HardhatRuntimeEnvironment } from 'hardhat/types'; import { ContractDetails } from './common/constants'; -import { estimateGas } from './utils/helper'; +import { checkCodeVersion, estimateGas } from './utils/helper'; export interface IDeployParams { name: string; @@ -33,6 +33,10 @@ export const deploy = async ( args: IDeployParams, hre: HardhatRuntimeEnvironment, ) => { + if (!await checkCodeVersion()) { + return; + } + // Compile again in case we have a coverage build (binary too large to deploy) await hre.run('compile'); let contractName: string = ContractDetails.ERC721M.name; diff --git a/scripts/dev/getContractCodehash.ts b/scripts/dev/getContractCodehash.ts index 61bc195..7b4a412 100644 --- a/scripts/dev/getContractCodehash.ts +++ b/scripts/dev/getContractCodehash.ts @@ -6,7 +6,7 @@ export const getContractCodehash = async ( ) => { const [signer] = await hre.ethers.getSigners(); const provider = signer.provider; - let code = await provider!.getCode(args.contract); + const code = await provider!.getCode(args.contract); const codehash = hre.ethers.utils.keccak256(code); console.log(codehash); } diff --git a/scripts/utils/helper.ts b/scripts/utils/helper.ts index 96d1c9c..d2d8ed4 100644 --- a/scripts/utils/helper.ts +++ b/scripts/utils/helper.ts @@ -1,6 +1,23 @@ +import { confirm } from '@inquirer/prompts'; import { Deferrable } from 'ethers/lib/utils'; import { HardhatRuntimeEnvironment } from 'hardhat/types'; import { TransactionRequest } from "@ethersproject/abstract-provider"; +import * as child from 'child_process'; + +export const checkCodeVersion = async () => { + const localLatestCommit = child.execSync('git rev-parse HEAD').toString().trim(); + const remoteLatestCommit = child.execSync("git ls-remote https://github.com/magicoss/erc721m.git HEAD | awk '{ print $1}'").toString().trim(); + console.log('local latest commit:\t', localLatestCommit); + console.log('remote latest commit:\t', remoteLatestCommit); + + if (localLatestCommit !== remoteLatestCommit) { + console.log("🟡 Warning: you are NOT using the latest version of the code. Please run `git pull` on main branch to update the code."); + if (!(await confirm({ message: 'Proceed anyway?', default: false }))) { + return false; + }; + } + return true; +} export const estimateGas = async (hre: HardhatRuntimeEnvironment, tx: Deferrable) => { const estimatedGasUnit = await hre.ethers.provider.estimateGas(tx);