Skip to content

Commit

Permalink
ERC1155NonTransferable deploy fixes (#349)
Browse files Browse the repository at this point in the history
* properly add environment to output file

* separate verification script

* Pass erc1155nt address as env variable

* Warn if erc1155nt address not provided

* empty env value in env.example

* format

* added npm scripts
  • Loading branch information
zajck authored Mar 14, 2022
1 parent cbe0b8f commit 6c9bebb
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ CC_TOKEN_DEPLOYER_PRIVATE_KEY=0000000000000000000000000000000000000000
# Default values for BOSON_TOKEN and DAI_TOKEN are required to allow deployment script to work
# When run locally (env == hardhat), a mock Boson Token is deployed
# For deployment to a public chain, adjust them accordingly
# Add ERC1155NONTRANSFERABLE_TOKEN if it was already deployed, so it gets included in addresses
# Leaving the ERC1155NONTRANSFERABLE_TOKEN empty assumes you do not use it or you will deploy it later
BOSON_TOKEN=0x056b1ce5510ceefa6c33600551e55333aff8296f
DAI_TOKEN=0x6A9865aDE2B6207dAAC49f8bCba9705dEB0B0e6D
ERC1155NONTRANSFERABLE_TOKEN=

# ETH AND TOKEN LIMITS in the base unit, i.e. wei
ETH_LIMIT=1000000000000000000
Expand Down
7 changes: 7 additions & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ task("contracts-verify", "Verify already deployed contracts. Bear in mind that a
await verifyContracts(env);
})

task("contracts-verify-erc1155", "Verify deployed ERC1155NonTransferable. Bear in mind that at least couple of blocks should be mined before execution!")
.addOptionalParam("env", "(Optional) Provide additional context on which environment the contracts are deployed to: production, staging or testing", "")
.setAction(async ({env}) => {
const { verifyContracts } = await lazyImport('./scripts/verify-erc1155-non-transferable')
await verifyContracts(env);
})

task("deploy-gate", "Deploy and verify the Gate contract on a provided network")
.addOptionalParam("env", "(Optional) Provide additional context on which environment the contracts are deployed to: production, staging or testing", "")
.setAction( async ({env}) => {
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
"contracts:migrate:gate:testing": "npm run contracts:clean && npm run contracts:compile && hardhat deploy-gate --network ropsten --env testing",
"contracts:migrate:gate:staging": "npm run contracts:clean && npm run contracts:compile && hardhat deploy-gate --network ropsten --env staging",
"contracts:migrate:gate:production": "npm run contracts:clean && npm run contracts:compile && hardhat deploy-gate --network mainnet --env production",
"contracts:migrate:erc1155only:testing": "npm run contracts:clean && npm run contracts:compile && hardhat deploy-erc1155-only --network ropsten --env testing",
"contracts:migrate:erc1155only:staging": "npm run contracts:clean && npm run contracts:compile && hardhat deploy-erc1155-only --network ropsten --env staging",
"contracts:migrate:erc1155only:production": "npm run contracts:clean && npm run contracts:compile && hardhat deploy-erc1155-only --network mainnet --env production",
"contracts:migrate:mocks": "npm run contracts:clean && npm run contracts:compile && hardhat deploy-mocks --network ropsten --env testing",
"contracts:migrate:mocks:rinkeby": "npm run contracts:clean && npm run contracts:compile && hardhat deploy-mocks --network rinkeby --env testing",
"contracts:size": "hardhat size-contracts",
Expand All @@ -65,6 +68,9 @@
"contracts:verify:gate:testing": "hardhat verify-gate --network ropsten --env testing",
"contracts:verify:gate:staging": "hardhat verify-gate --network ropsten --env staging",
"contracts:verify:gate:production": "hardhat verify-gate --network mainnet --env production",
"contracts:verify:erc1155only:testing": "hardhat contracts-verify-erc1155 --network ropsten --env testing",
"contracts:verify:erc1155only:staging": "hardhat contracts-verify-erc1155 --network ropsten --env staging",
"contracts:verify:erc1155only:production": "hardhat contracts-verify-erc1155 --network mainnet --env production",
"tests:lint": "eslint test/**/*.ts testHelpers/**/*.ts",
"tests:lint-fix": "eslint --fix test/**/*.ts testHelpers/**/*.ts scripts/**/*.ts",
"tests:format": "prettier --list-different test/**/*.ts testHelpers/**/*.ts scripts/**/*.ts",
Expand Down
6 changes: 3 additions & 3 deletions scripts/deploy-erc1155-non-transferable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class DeploymentExecutor {
maxTip;
txOptions;

constructor() {
this.env;
constructor(env: string) {
this.env = env;
this.erc1155NonTransferable;

this.maxTip = ethers.utils.parseUnits(
Expand Down Expand Up @@ -107,7 +107,7 @@ export async function deploy(_env: string): Promise<void> {
throw new Error(`Env: ${env} is not recognized!`);
}

const executor = new DeploymentExecutor();
const executor = new DeploymentExecutor(env);

await executor.deployContracts();

Expand Down
12 changes: 12 additions & 0 deletions scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class DeploymentExecutor {
dai_token_limit;
complainPeriod;
cancelFaultPeriod;
erc1155NonTransferable;
maxTip;
txOptions;

Expand Down Expand Up @@ -54,6 +55,8 @@ class DeploymentExecutor {
this.complainPeriod = process.env.COMPLAIN_PERIOD;
this.cancelFaultPeriod = process.env.CANCEL_FAULT_PERIOD;

this.erc1155NonTransferable = process.env.ERC1155NONTRANSFERABLE_TOKEN;

this.maxTip = ethers.utils.parseUnits(
process.env.MAX_TIP ? String(process.env.MAX_TIP) : '1',
'gwei'
Expand Down Expand Up @@ -300,6 +303,14 @@ class DeploymentExecutor {

console.log('DAI Token Address Used: ', this.dai_token);
console.log('Boson Token Address Used: ', this.boson_token);
if (this.erc1155NonTransferable) {
console.log(
'Erc1155NonTransferable Token Address Used: ',
this.erc1155NonTransferable
);
} else {
console.warn('Erc1155NonTransferable Token Address not provided!');
}
}

async writeContracts() {
Expand All @@ -325,6 +336,7 @@ class DeploymentExecutor {
daiTokenWrapper: this.daiTokenWrapper.address,
daiToken: this.dai_token,
bosonToken: this.boson_token,
erc1155NonTransferable: this.erc1155NonTransferable,
},
null,
2
Expand Down
44 changes: 44 additions & 0 deletions scripts/verify-erc1155-non-transferable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {isValidEnv, getAddressesFilePath} from './utils';
import fs from 'fs';
import hre from 'hardhat';

export async function verifyContracts(env: string): Promise<void> {
const contracts = JSON.parse(
fs.readFileSync(
getAddressesFilePath(hre.network.config.chainId, env, 'erc1155nt'),
'utf-8'
)
);

if (contracts.chainId != hre.network.config.chainId) {
throw new Error(
'Contracts are not deployed on the same network, that you are trying to verify!'
);
}

if (!isValidEnv(env.toLowerCase())) {
throw new Error(`Env: ${env} is not recognized!`);
}

//verify ERC1155NonTransferable
try {
await hre.run('verify:verify', {
address: contracts.erc1155NonTransferable,
constructorArguments: [process.env.CONDITIONAL_COMMIT_TOKEN_METADATA_URI],
});
} catch (error) {
logError('ERC1155NonTransferable', error.message);
}
}

function logError(contractName, msg) {
console.log(
`\x1b[31mError while trying to verify contract: ${contractName}!`
);
console.log(`Error message: ${msg}`);
resetConsoleColor();
}

function resetConsoleColor() {
console.log('\x1b[0m');
}
10 changes: 0 additions & 10 deletions scripts/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,6 @@ export async function verifyContracts(env: string): Promise<void> {
logError('BosonRouter', error.message);
}

//verify ERC1155NonTransferable
try {
await hre.run('verify:verify', {
address: contracts.erc1155NonTransferable,
constructorArguments: [process.env.CONDITIONAL_COMMIT_TOKEN_METADATA_URI],
});
} catch (error) {
logError('ERC1155NonTransferable', error.message);
}

//DAITokenWrapper
try {
await hre.run('verify:verify', {
Expand Down

0 comments on commit 6c9bebb

Please sign in to comment.