Skip to content

Commit

Permalink
fix(scripts): miscellaneous corrections (#15)
Browse files Browse the repository at this point in the history
Co-authored-by: João Sousa <joaosousa@MBP-de-Joao.home>
Co-authored-by: Dean Amiel <damiel@deans-mbp.lan>
  • Loading branch information
3 people authored Jul 12, 2023
1 parent d7a205b commit 3416d66
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 47 deletions.
9 changes: 4 additions & 5 deletions evm/deploy-const-address-deployer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ const readlineSync = require('readline-sync');
const { Command, Option } = require('commander');
const chalk = require('chalk');

const { deployCreate } = require('./upgradable');
const { printInfo, writeJSON, predictAddressCreate } = require('./utils');
const contractJson = require('../artifacts/contracts/deploy/ConstAddressDeployer.sol/ConstAddressDeployer.json');
const { printInfo, writeJSON, predictAddressCreate, deployContract } = require('./utils');
const contractJson = require('@axelar-network/axelar-gmp-sdk-solidity/dist/ConstAddressDeployer.json');
const contractName = 'ConstAddressDeployer';

async function deploy(options, chain) {
const { env, privateKey, ignore, verify } = options;
const { privateKey, ignore, verify } = options;
const wallet = new Wallet(privateKey);

printInfo('Deployer address', wallet.address);
Expand Down Expand Up @@ -50,7 +49,7 @@ async function deploy(options, chain) {
const anwser = readlineSync.question(`Proceed with deployment on ${chain.name}? ${chalk.green('(y/n)')} `);
if (anwser !== 'y') return;

const contract = await deployCreate(wallet.connect(provider), contractJson, [], gasOptions, env, chain.name, verify);
const contract = await deployContract(wallet.connect(provider), contractJson, [], gasOptions, verify);

contractConfig.address = contract.address;
contractConfig.deployer = wallet.address;
Expand Down
2 changes: 1 addition & 1 deletion evm/deploy-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async function getConstructorArgs(contractName, config) {

const governanceAddress = contractConfig.governanceAddress;

if (!isAddress(governanceAddress)) {
if (!isString(governanceAddress)) {
throw new Error(`Missing InterchainGovernance.governanceAddress in the chain info.`);
}

Expand Down
2 changes: 1 addition & 1 deletion evm/deploy-create3-deployer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { Command, Option } = require('commander');
const chalk = require('chalk');

const { printInfo, writeJSON, deployCreate2 } = require('./utils');
const implementationJson = require('../artifacts/contracts/deploy/Create3Deployer.sol/Create3Deployer.json');
const implementationJson = require('@axelar-network/axelar-gmp-sdk-solidity/dist/Create3Deployer.json');
const contractName = 'Create3Deployer';

async function deploy(options, chain) {
Expand Down
32 changes: 14 additions & 18 deletions evm/deploy-gateway-v4.3.x.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,7 @@

require('dotenv').config();

const {
printObj,
writeJSON,
getBytecodeHash,
verifyContract,
printInfo,
printLog,
getProxy,
getEVMAddresses,
} = require('./utils');
const { printObj, writeJSON, getBytecodeHash, verifyContract, printInfo, printLog, getProxy, getEVMAddresses } = require('./utils');
const { ethers } = require('hardhat');
const {
getContractFactory,
Expand All @@ -36,7 +27,7 @@ function getProxyParams(adminAddresses, adminThreshold) {
}

async function deploy(config, options) {
const { chainName, privateKey, reuseProxy, adminAddresses, adminThreshold, verify } = options;
const { env, chainName, privateKey, reuseProxy, adminAddresses, adminThreshold, verify } = options;

const contractName = 'AxelarGateway';

Expand Down Expand Up @@ -77,7 +68,7 @@ async function deploy(config, options) {

if (reuseProxy) {
printLog(`reusing gateway proxy contract`);
const gatewayProxy = chain.contracts.AxelarGateway?.address || await getProxy(config, chain.id);
const gatewayProxy = chain.contracts.AxelarGateway?.address || (await getProxy(config, chain.id));
printLog(`proxy address ${gatewayProxy}`);
gateway = gatewayFactory.attach(gatewayProxy);
}
Expand Down Expand Up @@ -124,7 +115,7 @@ async function deploy(config, options) {

contractsToVerify.push({
address: gatewayImplementation.address,
params: [auth.address, tokenDeployer.address]
params: [auth.address, tokenDeployer.address],
});

if (!reuseProxy) {
Expand All @@ -137,7 +128,7 @@ async function deploy(config, options) {

contractsToVerify.push({
address: gatewayProxy.address,
params: [gatewayImplementation.address, params]
params: [gatewayImplementation.address, params],
});
}

Expand All @@ -152,6 +143,7 @@ async function deploy(config, options) {
const admins = `${await gateway.admins(epoch)}`.split(',');
printLog(`Existing admins ${admins}`);
const encodedAdmins = JSON.parse(adminAddresses);

if (!reuseProxy && `${admins}` !== `${encodedAdmins}`) {
printLog(`ERROR: Retrieved admins are different:`);
printLog(` Actual: ${admins}`);
Expand All @@ -160,12 +152,14 @@ async function deploy(config, options) {
}

const authModule = await gateway.authModule();

if (authModule !== auth.address) {
printLog(`ERROR: Auth module retrieved from gateway ${authModule} doesn't match deployed contract ${auth.address}`);
error = true;
}

const tokenDeployerAddress = await gateway.tokenDeployer();

if (tokenDeployerAddress !== tokenDeployer.address) {
printLog(
`ERROR: Token deployer retrieved from gateway ${tokenDeployerAddress} doesn't match deployed contract ${tokenDeployer.address}`,
Expand All @@ -174,12 +168,14 @@ async function deploy(config, options) {
}

const authOwner = await auth.owner();

if (authOwner !== gateway.address) {
printLog(`ERROR: Auth module owner is set to ${authOwner} instead of proxy address ${gateway.address}`);
error = true;
}

const implementation = await gateway.implementation();

if (implementation !== gatewayImplementation.address) {
printLog(
`ERROR: Implementation contract retrieved from gateway ${implementation} doesn't match deployed contract ${gatewayImplementation.address}`,
Expand All @@ -203,7 +199,7 @@ async function deploy(config, options) {
if (verify) {
// Verify contracts at the end to avoid deployment failures in the middle
for (const contract of contractsToVerify) {
await verifyContract(network, chain, contract.address, contract.params);
await verifyContract(env, chain, contract.address, contract.params);
}

printLog('Verified all contracts!');
Expand Down Expand Up @@ -243,12 +239,12 @@ async function programHandler() {
});

program.parse();
};
}

if (require.main === module) {
programHandler();
}

module.exports = {
deployGatewayv4_3: deploy,
}
deployGatewayv43: deploy,
};
31 changes: 14 additions & 17 deletions evm/deploy-gateway-v5.x.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,7 @@

require('dotenv').config();

const {
printObj,
writeJSON,
getBytecodeHash,
verifyContract,
printInfo,
printLog,
getProxy,
getEVMAddresses,
} = require('./utils');
const { printObj, writeJSON, getBytecodeHash, verifyContract, printInfo, printLog, getProxy, getEVMAddresses } = require('./utils');
const { ethers } = require('hardhat');
const {
getContractFactory,
Expand All @@ -35,7 +26,7 @@ function getProxyParams(governance, mintLimiter) {
}

async function deploy(config, options) {
const { chainName, privateKey, reuseProxy, verify } = options;
const { env, chainName, privateKey, reuseProxy, verify } = options;

const contractName = 'AxelarGateway';

Expand Down Expand Up @@ -87,7 +78,7 @@ async function deploy(config, options) {

if (reuseProxy) {
printLog(`reusing gateway proxy contract`);
const gatewayProxy = chain.contracts.AxelarGateway?.address || await getProxy(config, chain.id);
const gatewayProxy = chain.contracts.AxelarGateway?.address || (await getProxy(config, chain.id));
printLog(`proxy address ${gatewayProxy}`);
gateway = gatewayFactory.attach(gatewayProxy);
}
Expand Down Expand Up @@ -134,7 +125,7 @@ async function deploy(config, options) {

contractsToVerify.push({
address: gatewayImplementation.address,
params: [auth.address, tokenDeployer.address]
params: [auth.address, tokenDeployer.address],
});

if (!reuseProxy) {
Expand All @@ -147,7 +138,7 @@ async function deploy(config, options) {

contractsToVerify.push({
address: gatewayProxy.address,
params: [gatewayImplementation.address, params]
params: [gatewayImplementation.address, params],
});
}

Expand All @@ -160,6 +151,7 @@ async function deploy(config, options) {
var error = false;
const governanceModule = await gateway.governance();
printLog(`Existing governance ${governanceModule}`);

if (!reuseProxy && governanceModule !== governance) {
printLog(`ERROR: Retrieved governance address is different:`);
printLog(` Actual: ${governanceModule}`);
Expand All @@ -169,6 +161,7 @@ async function deploy(config, options) {

const mintLimiterModule = await gateway.mintLimiter();
printLog(`Existing mintLimiter ${mintLimiterModule}`);

if (!reuseProxy && mintLimiterModule !== mintLimiter) {
printLog(`ERROR: Retrieved mintLimiter address is different:`);
printLog(` Actual: ${mintLimiterModule}`);
Expand All @@ -177,12 +170,14 @@ async function deploy(config, options) {
}

const authModule = await gateway.authModule();

if (authModule !== auth.address) {
printLog(`ERROR: Auth module retrieved from gateway ${authModule} doesn't match deployed contract ${auth.address}`);
error = true;
}

const tokenDeployerAddress = await gateway.tokenDeployer();

if (tokenDeployerAddress !== tokenDeployer.address) {
printLog(
`ERROR: Token deployer retrieved from gateway ${tokenDeployerAddress} doesn't match deployed contract ${tokenDeployer.address}`,
Expand All @@ -191,12 +186,14 @@ async function deploy(config, options) {
}

const authOwner = await auth.owner();

if (authOwner !== gateway.address) {
printLog(`ERROR: Auth module owner is set to ${authOwner} instead of proxy address ${gateway.address}`);
error = true;
}

const implementation = await gateway.implementation();

if (implementation !== gatewayImplementation.address) {
printLog(
`ERROR: Implementation contract retrieved from gateway ${implementation} doesn't match deployed contract ${gatewayImplementation.address}`,
Expand All @@ -222,7 +219,7 @@ async function deploy(config, options) {
if (verify) {
// Verify contracts at the end to avoid deployment failures in the middle
for (const contract of contractsToVerify) {
await verifyContract(network, chain, contract.address, contract.params);
await verifyContract(env, chain, contract.address, contract.params);
}

printLog('Verified all contracts!');
Expand Down Expand Up @@ -262,12 +259,12 @@ async function programHandler() {
});

program.parse();
};
}

if (require.main === module) {
programHandler();
}

module.exports = {
deployGatewayv5: deploy,
}
};
4 changes: 2 additions & 2 deletions evm/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const { printObj, readJSON, writeJSON, importNetworks, verifyContract, getBytecodeHash } = require('./utils');
const { deployGatewayv4_3 } = require('./deploy-gateway-v4.3.x');
const { deployGatewayv43 } = require('./deploy-gateway-v4.3.x');
const { deployGatewayv5 } = require('./deploy-gateway-v5.x');

module.exports = {
Expand All @@ -11,6 +11,6 @@ module.exports = {
importNetworks,
verifyContract,
getBytecodeHash,
deployGatewayv4_3,
deployGatewayv43,
deployGatewayv5,
};
7 changes: 4 additions & 3 deletions evm/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const {
utils: { isAddress, getContractAddress, keccak256 },
} = require('ethers');
const https = require('https');
const http = require('http');
const { outputJsonSync, readJsonSync } = require('fs-extra');
const { exec } = require('child_process');
const { writeFile } = require('fs');
Expand Down Expand Up @@ -86,7 +87,7 @@ const writeJSON = (data, name) => {

const httpGet = (url) => {
return new Promise((resolve, reject) => {
https.get(url, (res) => {
(url.startsWith('https://') ? https : http).get(url, (res) => {
const { statusCode } = res;
const contentType = res.headers['content-type'];
let error;
Expand Down Expand Up @@ -277,7 +278,7 @@ const predictAddressCreate = async (from, nonce) => {
const getProxy = async (config, chain) => {
const address = (await httpGet(`${config.axelar.lcd}/axelar/evm/v1beta1/gateway_address/${chain}`)).address;
return address;
}
};

const getEVMAddresses = async (config, chain) => {
const evmAddresses = await httpGet(`${config.axelar.lcd}/axelar/evm/v1beta1/key_address/${chain}`);
Expand All @@ -288,7 +289,7 @@ const getEVMAddresses = async (config, chain) => {
const threshold = Number(evmAddresses.threshold);

return { addresses, weights, threshold };
}
};

module.exports = {
deployContract,
Expand Down

0 comments on commit 3416d66

Please sign in to comment.