Skip to content

Commit

Permalink
Fix hardhat deploy script (#109)
Browse files Browse the repository at this point in the history
* Fix hardhat deploy script

* lint

* fix
  • Loading branch information
channing-magiceden authored Feb 15, 2024
1 parent 14f84ce commit dfbec62
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
18 changes: 10 additions & 8 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,21 @@ task('deploy', 'Deploy ERC721M')
'0x0000000000000000000000000000000000000000',
)
.addOptionalParam('autoapproveaddress', 'auto approve address')
.addParam(
.addParam<boolean>(
'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<boolean>('pausable', 'whether to allow transfers to be paused', false, types.boolean)
.addParam<boolean>('useoperatorfilterer', 'whether or not to use operator filterer', false, types.boolean)
.addParam<boolean>(
'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<boolean>('useerc721c', 'whether or not to use ERC721C', true, types.boolean)
.addOptionalParam<boolean>('useerc2198', 'whether or not to use ERC2198', true, types.boolean)
.addOptionalParam('erc2198royaltyreceiver', 'erc2198 royalty receiver address')
.addOptionalParam('erc2198royaltyfeenumerator', 'erc2198 royalty fee numerator')
.setAction(deploy);
Expand Down
6 changes: 5 additions & 1 deletion scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion scripts/dev/getContractCodehash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
17 changes: 17 additions & 0 deletions scripts/utils/helper.ts
Original file line number Diff line number Diff line change
@@ -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<TransactionRequest>) => {
const estimatedGasUnit = await hre.ethers.provider.estimateGas(tx);
Expand Down

0 comments on commit dfbec62

Please sign in to comment.