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: improve gateway script to transfer permissions #111

Merged
merged 1 commit into from
Nov 9, 2023
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
3 changes: 2 additions & 1 deletion evm/deploy-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require('dotenv').config();

const chalk = require('chalk');
const { ethers } = require('hardhat');
const {
Wallet,
Expand Down Expand Up @@ -290,7 +291,7 @@ async function processCommand(config, chain, options) {

printInfo('Deployment method', deployMethod);
printInfo('Deployer contract', deployerContract);
printInfo(`${contractName} will be deployed to`, predictedAddress);
printInfo(`${contractName} will be deployed to`, predictedAddress, chalk.cyan);

const existingAddress = config.chains.ethereum?.contracts?.[contractName]?.address;

Expand Down
3 changes: 2 additions & 1 deletion evm/deploy-gateway-v6.2.x.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require('dotenv').config();

const { Command, Option } = require('commander');
const chalk = require('chalk');
const { ethers } = require('hardhat');
const {
ContractFactory,
Expand Down Expand Up @@ -149,7 +150,7 @@ async function deploy(config, chain, options) {
from: wallet.address,
nonce: transactionCount + 3,
});
printInfo('Predicted proxy address', proxyAddress);
printInfo('Predicted proxy address', proxyAddress, chalk.cyan);
}

const gasOptions = JSON.parse(JSON.stringify(contractConfig.gasOptions || chain.gasOptions || {}));
Expand Down
50 changes: 47 additions & 3 deletions evm/gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require('dotenv').config();

const chalk = require('chalk');
const { ethers } = require('hardhat');
const {
getDefaultProvider,
Expand Down Expand Up @@ -264,7 +265,7 @@ async function processCommand(config, chain, options) {
}

case 'transferGovernance': {
const newGovernance = options.destination;
const newGovernance = options.destination || chain.contracts.InterchainGovernance?.address;

if (!isValidAddress(newGovernance)) {
throw new Error('Invalid new governor address');
Expand All @@ -277,7 +278,7 @@ async function processCommand(config, chain, options) {
throw new Error('Wallet address is not the governor');
}

if (prompt(`Proceed with governance transfer to ${newGovernance}`, yes)) {
if (prompt(`Proceed with governance transfer to ${chalk.cyan(newGovernance)}`, yes)) {
return;
}

Expand All @@ -292,7 +293,11 @@ async function processCommand(config, chain, options) {
throw new Error('Event not emitted in receipt.');
}

contracts.AxelarGateway.governance = newGovernance;
if (!chain.contracts.InterchainGovernance) {
chain.contracts.InterchainGovernance = {};
}

chain.contracts.InterchainGovernance.address = newGovernance;

break;
}
Expand All @@ -307,6 +312,44 @@ async function processCommand(config, chain, options) {
break;
}

case 'transferMintLimiter': {
const newMintLimiter = options.destination || chain.contracts.Multisig?.address;

if (!isValidAddress(newMintLimiter)) {
throw new Error('Invalid address');
}

const currMintLimiter = await gateway.mintLimiter();
printInfo('Current governance', currMintLimiter);

if (!(currMintLimiter === walletAddress)) {
throw new Error('Wallet address is not the mint limiter');
}

if (prompt(`Proceed with mint limiter transfer to ${chalk.cyan(newMintLimiter)}`, yes)) {
return;
}

const tx = await gateway.transferMintLimiter(newMintLimiter, gasOptions);
printInfo('Transfer mint limiter tx', tx.hash);

const receipt = await tx.wait(chain.confirmations);

const eventEmitted = wasEventEmitted(receipt, gateway, 'MintLimiterTransferred');

if (!eventEmitted) {
throw new Error('Event not emitted in receipt.');
}

if (!chain.contracts.Multisig) {
chain.contracts.Multisig = {};
}

chain.contracts.Multisig.address = newMintLimiter;

break;
}

case 'mintLimit': {
if (!options.symbol) {
throw new Error('Missing symbol');
Expand Down Expand Up @@ -348,6 +391,7 @@ if (require.main === module) {
'transferGovernance',
'governance',
'mintLimiter',
'transferMintLimiter',
'mintLimit',
'params',
])
Expand Down
8 changes: 4 additions & 4 deletions evm/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ const deployCreate3 = async (
return contract;
};

const printInfo = (msg, info = '') => {
const printInfo = (msg, info = '', colour = chalk.green) => {
if (info) {
console.log(`${msg}: ${chalk.green(info)}\n`);
console.log(`${msg}: ${colour(info)}\n`);
} else {
console.log(`${msg}\n`);
}
Expand All @@ -133,15 +133,15 @@ const printWarn = (msg, info = '') => {
msg = `${msg}: ${info}`;
}

console.log(`${chalk.yellow(msg)}\n`);
console.log(`${chalk.italic.yellow(msg)}\n`);
};

const printError = (msg, info = '') => {
if (info) {
msg = `${msg}: ${info}`;
}

console.log(`${chalk.red(msg)}\n`);
console.log(`${chalk.bold.red(msg)}\n`);
};

function printLog(log) {
Expand Down
Loading