Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 83 additions & 4 deletions publish/src/commands/deploy-migration.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
'use strict';

const fs = require('fs');
const qs = require('querystring');
const solc = require('solc');
const axios = require('axios');
const path = require('path');
const ethers = require('ethers');
const { gray, green, yellow } = require('chalk');
const { getUsers } = require('../../..');
const {
getUsers,
constants: { FLATTENED_FOLDER },
} = require('../../..');
const { loadCompiledFiles, getLatestSolTimestamp } = require('../solidity');

const { optimizerRuns } = require('./build').DEFAULTS;

const {
ensureNetwork,
loadConnections,
Expand All @@ -15,6 +23,7 @@ const {
loadAndCheckRequiredSources,
appendOwnerActionGenerator,
} = require('../util');
const { performTransactionalStep } = require('../command-utils/transact');

const {
wrap,
Expand Down Expand Up @@ -51,7 +60,12 @@ const deployMigration = async ({
// now get the latest time a Solidity file was edited
const latestSolTimestamp = getLatestSolTimestamp(CONTRACTS_FOLDER);

const { providerUrl, privateKey: envPrivateKey } = loadConnections({
const {
providerUrl,
privateKey: envPrivateKey,
etherscanUrl,
explorerLinkPrefix,
} = loadConnections({
network,
useOvm,
});
Expand Down Expand Up @@ -117,7 +131,6 @@ const deployMigration = async ({

console.log(green(`\nSuccessfully deployed: ${deployedContract.address}\n`));

// append owner action to run the actual migration
const { getPathToNetwork } = wrap({
network,
useOvm,
Expand All @@ -138,6 +151,27 @@ const deployMigration = async ({
// 'https://',
});

// run nominations
const requiringOwnership = await deployedContract.contractsRequiringOwnership();

for (const addr of requiringOwnership) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So on mainnet, this will nominate in real time the contracts that are owned by the deployer and the rest will be put together in a batch submission by running the owner command?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep thats the idea

console.log('Nominating ownership: ', addr);

const contract = new ethers.Contract(addr, compiled['Owned'].abi, signer);
await performTransactionalStep({
account: signer.address,
contract: contract.address,
target: contract,
write: 'nominateNewOwner',
writeArg: [deployedContract.address],

signer,
explorerLinkPrefix,
ownerActions,
ownerActionsFile,
});
}

const actionName = `Migration_${releaseName}.migrate(${ownerAddress})`;
const txn = await deployedContract.populateTransaction.migrate(ownerAddress);

Expand All @@ -150,9 +184,54 @@ const deployMigration = async ({

appendOwnerAction(ownerAction);

console.log(gray(`All contracts deployed on "${network}" network:`));
await verifyMigrationContract({ deployedContract, releaseName, buildPath, etherscanUrl });

console.log(gray(`Done.`));
};

async function verifyMigrationContract({ deployedContract, releaseName, buildPath, etherscanUrl }) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏼

const readFlattened = () => {
const flattenedFilename = path.join(
buildPath,
FLATTENED_FOLDER,
`migrations/Migration_${releaseName}.sol`
);
try {
return fs.readFileSync(flattenedFilename).toString();
} catch (err) {
throw Error(`Cannot read file ${flattenedFilename}`);
}
};

const runs = optimizerRuns;

// The version reported by solc-js is too verbose and needs a v at the front
const solcVersion = 'v' + solc.version().replace('.Emscripten.clang', '');

const payload = {
module: 'contract',
action: 'verifysourcecode',
contractaddress: deployedContract.address,
sourceCode: readFlattened(),
contractName: 'Migration_' + releaseName,
constructorArguements: '',
compilerversion: solcVersion,
optimizationUsed: 1,
runs,
apikey: process.env.ETHERSCAN_KEY,
};

console.log('verify on etherscan:', payload);

const response = await axios.post(etherscanUrl, qs.stringify(payload), {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
});

console.log(green('etherscan verify response:'), response.data.message);
}

module.exports = {
deployMigration,
DEFAULTS,
Expand Down
2 changes: 1 addition & 1 deletion publish/src/commands/deploy/generate-solidity-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ contract Migration_${releaseName} is BaseMigration {
.join('\n\t\t')}
}

function migrate(address currentOwner) external onlyDeployer {
function migrate(address currentOwner) external onlyOwner {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏼

require(owner == currentOwner, "Only the assigned owner can be re-assigned when complete");

${Object.entries(newContractsBeingAdded)
Expand Down