Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: setup contracts script #996

Merged
merged 1 commit into from
Sep 26, 2022
Merged
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
35 changes: 22 additions & 13 deletions nightfall-deployer/src/contract-setup.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,36 @@ import { getContractInstance } from 'common-files/utils/contract.mjs';
import logger from 'common-files/utils/logger.mjs';

async function setupContracts() {
const stateInstanceAddress = (await getContractInstance('State')).options.address;
const proposersContract = await getContractInstance('Proposers');
const shieldContract = await getContractInstance('Shield');
const challengesContract = await getContractInstance('Challenges');
const stateContract = await getContractInstance('State');
const stateAddress = stateContract.options.address;
const simpleMultiSigAddress = (await getContractInstance('SimpleMultiSig')).options.address;
logger.debug(`address of State contract is ${stateInstanceAddress}`);
logger.debug(`address of State contract is ${stateAddress}`);

const contracts = await Promise.all([
await getContractInstance('Proposers'),
await getContractInstance('Shield'),
await getContractInstance('Challenges'),
]);
const contractsState = [proposersContract, shieldContract, challengesContract];
const contractsOwnables = [proposersContract, shieldContract, challengesContract, stateContract];

// set State
await Promise.all(
contracts.map(async contract => {
const setStateContract = contract.methods.setStateContract(stateInstanceAddress);
const transferOwnership = contract.methods.transferOwnership(simpleMultiSigAddress);

contractsState.map(async contract => {
const setStateContract = contract.methods.setStateContract(stateAddress);
if (!config.ETH_PRIVATE_KEY) {
setStateContract.send();
transferOwnership.send();
await setStateContract.send();
} else {
await Web3.submitRawTransaction(setStateContract.encodeABI(), contract.options.address);
}
}),
);

// transfer ownership
await Promise.all(
contractsOwnables.map(async contract => {
const transferOwnership = contract.methods.transferOwnership(simpleMultiSigAddress);
if (!config.ETH_PRIVATE_KEY) {
await transferOwnership.send();
} else {
await Web3.submitRawTransaction(transferOwnership.encodeABI(), contract.options.address);
}
}),
Expand Down