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

feat: script optimizations #99

Merged
merged 8 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
58 changes: 55 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ jobs:
"chainId": 31337,
"rpc": "http://127.0.0.1:8545",
"tokenSymbol": "TEST",
"contracts": {}
"contracts": {
"InterchainGovernance": {
"minimumTimeDelay": 3600
},
"AxelarServiceGovernance": {
"minimumTimeDelay": 3600
}
}
}
}
}' > ./axelar-chains-config/info/local.json
Expand All @@ -52,13 +59,58 @@ jobs:
run: cat ./axelar-chains-config/info/local.json

- name: Deploy ConstAddressDeployer
run: node evm/deploy-contract.js -a ../node_modules/@axelar-network/axelar-gmp-sdk-solidity/artifacts/contracts/deploy/ -c ConstAddressDeployer -m create -y
run: node evm/deploy-contract.js -c ConstAddressDeployer -m create -y

- name: Deploy Create3Deployer
run: node evm/deploy-contract.js -a ../node_modules/@axelar-network/axelar-gmp-sdk-solidity/artifacts/contracts/deploy/ -c Create3Deployer -m create2 -y
run: node evm/deploy-contract.js -c Create3Deployer -m create2 -y

- name: Deploy AxelarGateway
run: node evm/deploy-gateway-v6.2.x.js -m create3 -s "AxelarGateway v6.2" -g 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 -m 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --keyID 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 -y

- name: Call Method on Gateway
run: node evm/gateway.js --action callContract --destinationChain test2 -y

- name: Deploy InterchainGovernance using create
run: node evm/deploy-contract.js -c InterchainGovernance -m create -y

- name: Deploy AxelarServiceGovernance using create
run: node evm/deploy-contract.js -c AxelarServiceGovernance -m create -y

- name: Deploy Multisig using create
run: node evm/deploy-contract.js -c Multisig -m create -y

- name: Deploy Operators using create
run: node evm/deploy-contract.js -c Operators -m create -y

- name: Deploy TokenDeployer using create
run: node evm/deploy-contract.js -c TokenDeployer -m create -y

- name: Deploy InterchainGovernance using create2
run: node evm/deploy-contract.js -c InterchainGovernance -m create2 -y

- name: Deploy AxelarServiceGovernance using create2
run: node evm/deploy-contract.js -c AxelarServiceGovernance -m create2 -y

- name: Deploy Multisig using create2
run: node evm/deploy-contract.js -c Multisig -m create2 -y

- name: Deploy Operators using create2
milapsheth marked this conversation as resolved.
Show resolved Hide resolved
run: node evm/deploy-contract.js -c Operators -m create2 -y

- name: Deploy TokenDeployer using create2
milapsheth marked this conversation as resolved.
Show resolved Hide resolved
run: node evm/deploy-contract.js -c TokenDeployer -m create2 -y

- name: Deploy InterchainGovernance using create3
run: node evm/deploy-contract.js -c InterchainGovernance -m create3 -y

- name: Deploy AxelarServiceGovernance using create3
run: node evm/deploy-contract.js -c AxelarServiceGovernance -m create3 -y

- name: Deploy Multisig using create3
run: node evm/deploy-contract.js -c Multisig -m create3 -y

- name: Deploy Operators using create3
run: node evm/deploy-contract.js -c Operators -m create3 -y

- name: Deploy TokenDeployer using create3
run: node evm/deploy-contract.js -c TokenDeployer -m create3 -y
20 changes: 15 additions & 5 deletions evm/cli-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ const addBaseOptions = (program, options = {}) => {
.makeOptionMandatory(true)
.env('ENV'),
);
program.addOption(new Option('--skipChains <skipChains>', 'chains to skip over'));
program.addOption(new Option('-y, --yes', 'skip deployment prompt confirmation').env('YES'));

if (!options.ignoreChainNames) {
program.addOption(
new Option('-n, --chainNames <chainNames>', 'chains to run the script over').makeOptionMandatory(true).env('CHAINS'),
milapsheth marked this conversation as resolved.
Show resolved Hide resolved
);
program.addOption(new Option('--skipChains <skipChains>', 'chains to skip over'));
}

if (!options.ignorePrivateKey) {
Expand All @@ -35,15 +35,25 @@ const addExtendedOptions = (program, options = {}) => {

program.addOption(new Option('-v, --verify', 'verify the deployed contract on the explorer').env('VERIFY'));

if (options.artifactPath) program.addOption(new Option('-a, --artifactPath <artifactPath>', 'artifact path'));
if (options.contractName) program.addOption(new Option('-c, --contractName <contractName>', 'contract name').makeOptionMandatory(true));
if (options.salt) program.addOption(new Option('-s, --salt <salt>', 'salt to use for create2 deployment').env('SALT'));
if (options.artifactPath) {
program.addOption(new Option('-a, --artifactPath <artifactPath>', 'artifact path'));
}

if (options.contractName) {
program.addOption(new Option('-c, --contractName <contractName>', 'contract name').makeOptionMandatory(true));
}

if (options.salt) {
program.addOption(new Option('-s, --salt <salt>', 'salt to use for create2 deployment').env('SALT'));
}

if (options.skipExisting) {
program.addOption(new Option('-x, --skipExisting', 'skip existing if contract was already deployed on chain').env('SKIP_EXISTING'));
}

if (options.upgrade) program.addOption(new Option('-u, --upgrade', 'upgrade a deployed contract').env('UPGRADE'));
if (options.upgrade) {
program.addOption(new Option('-u, --upgrade', 'upgrade a deployed contract').env('UPGRADE'));
}

return program;
};
Expand Down
2 changes: 1 addition & 1 deletion evm/deploy-const-address-deployer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const { addExtendedOptions } = require('./cli-utils');
const contractJson = require('@axelar-network/axelar-gmp-sdk-solidity/artifacts/contracts/deploy/ConstAddressDeployer.sol/ConstAddressDeployer.json');
const contractName = 'ConstAddressDeployer';

async function deployConstAddressDeployer(wallet, chain, options = null, verifyOptions = null) {
async function deployConstAddressDeployer(wallet, chain, options = {}, verifyOptions = null) {
printInfo('Deployer address', wallet.address);

const contracts = chain.contracts;
Expand Down
33 changes: 17 additions & 16 deletions evm/deploy-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const {
prompt,
mainProcessor,
isContract,
getContractPath,
getContractJSON,
} = require('./utils');
const { addExtendedOptions } = require('./cli-utils');

Expand All @@ -41,13 +41,15 @@ async function getConstructorArgs(contractName, chain, wallet) {
throw new Error(`Missing AxelarGateway address in the chain info.`);
}

const governanceChain = contractConfig.governanceChain;
const governanceChain = contractConfig.governanceChain || 'Axelarnet';
contractConfig.governanceChain = governanceChain;

if (!isString(governanceChain)) {
throw new Error(`Missing AxelarServiceGovernance.governanceChain in the chain info.`);
}

const governanceAddress = contractConfig.governanceAddress;
const governanceAddress = contractConfig.governanceAddress || 'axelar10d07y265gmmuvt4z0w9aw880jnsr700j7v9daj';
milapsheth marked this conversation as resolved.
Show resolved Hide resolved
contractConfig.governanceAddress = governanceAddress;

if (!isString(governanceAddress)) {
throw new Error(`Missing AxelarServiceGovernance.governanceAddress in the chain info.`);
Expand All @@ -59,13 +61,22 @@ async function getConstructorArgs(contractName, chain, wallet) {
throw new Error(`Missing AxelarServiceGovernance.minimumTimeDelay in the chain info.`);
}

const cosigners = contractConfig.cosigners;
const cosigners = contractConfig.cosigners || [
'0x3f5876a2b06E54949aB106651Ab6694d0289b2b4',
milapsheth marked this conversation as resolved.
Show resolved Hide resolved
'0x9256Fd872118ed3a97754B0fB42c15015d17E0CC',
'0x1486157d505C7F7E546aD00E3E2Eee25BF665C9b',
'0x2eC991B5c0B742AbD9d2ea31fe6c14a85e91C821',
'0xf505462A29E36E26f25Ef0175Ca1eCBa09CC118f',
'0x027c1882B975E2cd771AE068b0389FA38B9dda73',
];
contractConfig.cosigners = cosigners;

if (!isAddressArray(cosigners)) {
throw new Error(`Missing AxelarServiceGovernance.cosigners in the chain info.`);
}

const threshold = contractConfig.threshold;
const threshold = contractConfig.threshold || Math.floor((cosigners.length + 1) / 2);
contractConfig.threshold = threshold;

if (!isNumber(threshold)) {
throw new Error(`Missing AxelarServiceGovernance.threshold in the chain info.`);
Expand Down Expand Up @@ -251,17 +262,7 @@ async function processCommand(config, chain, options) {

printInfo('Contract name', contractName);

let contractPath;

if (artifactPath) {
contractPath = artifactPath.charAt(0) === '@' ? artifactPath : artifactPath + contractName + '.sol/' + contractName + '.json';
} else {
contractPath = getContractPath(contractName);
}

printInfo('Contract path', contractPath);

const contractJson = require(contractPath);
const contractJson = getContractJSON(contractName, artifactPath);

const predeployCodehash = await getBytecodeHash(contractJson, chain.id);
printInfo('Pre-deploy Contract bytecode hash', predeployCodehash);
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 @@ -15,7 +15,7 @@ const contractJson = require('@axelar-network/axelar-gmp-sdk-solidity/artifacts/
const { deployConstAddressDeployer } = require('./deploy-const-address-deployer');
const contractName = 'Create3Deployer';

async function deployCreate3Deployer(wallet, chain, options = null, verifyOptions = null) {
async function deployCreate3Deployer(wallet, chain, options = {}, verifyOptions = null) {
printInfo('Deployer address', wallet.address);

console.log(
Expand Down
46 changes: 14 additions & 32 deletions evm/execute-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const {

const readlineSync = require('readline-sync');
const { Command, Option } = require('commander');
const { isNumber, isString, loadConfig, saveConfig, printObj, printLog, printError, printInfo } = require('./utils');
const { isNumber, isString, loadConfig, saveConfig, printObj, printLog, printError, getContractJSON } = require('./utils');
const { addBaseOptions } = require('./cli-utils');

async function getCallData(methodName, targetContract, inputRecipient, inputAmount) {
Expand Down Expand Up @@ -137,24 +137,15 @@ async function executeContract(options, chain, wallet) {
throw new Error('Missing native value from user info');
}

var contractPath =
callContractPath.charAt(0) === '@' ? callContractPath : callContractPath + callContractName + '.sol/' + callContractName + '.json';
printInfo('Call Contract path', contractPath);

const IContractExecutor = require(contractPath);
const IContractExecutor = getContractJSON(callContractName, callContractPath);
const contract = new Contract(callContractAddress, IContractExecutor.abi, wallet);
var finalCallData, finalNativeValue;

if (methodName === 'default') {
finalCallData = callData;
finalNativeValue = nativeValue;
} else {
contractPath =
targetContractPath.charAt(0) === '@'
? targetContractPath
: targetContractPath + targetContractName + '.sol/' + targetContractName + '.json';
printInfo('Target Contract path', contractPath);
const ITargetContract = require(contractPath);
const ITargetContract = getContractJSON(targetContractName, targetContractPath);
const targetContract = new Contract(targetContractAddress, ITargetContract.abi, wallet);
finalCallData = await getCallData(methodName, targetContract, recipientAddress, Number(amount));
finalNativeValue = Number(0);
Expand Down Expand Up @@ -207,39 +198,30 @@ if (require.main === module) {

addBaseOptions(program);

program.addOption(new Option('-c, --callContractName <callContractName>', 'name of the called contract').makeOptionMandatory(true));
program.addOption(new Option('--callContractPath <callContractPath>', 'artifact path for the called contract'));
program.addOption(new Option('--targetContractPath <targetContractPath>', 'artifact path for the target contract'));
program.addOption(
new Option('-pc, --callContractPath <callContractPath>', 'artifact path for the called contract').makeOptionMandatory(true),
);
program.addOption(new Option('-cn, --callContractName <callContractName>', 'name of the called contract').makeOptionMandatory(true));
program.addOption(
new Option('-pt, --targetContractPath <targetContractPath>', 'artifact path for the target contract').makeOptionMandatory(true),
);
program.addOption(
new Option(
'-tn, --targetContractName <targetContractName>',
'name of the target contract that is called through executeContract',
).makeOptionMandatory(false),
new Option('-t, --targetContractName <targetContractName>', 'target contract name called by executeContract').makeOptionMandatory(
true,
),
);
program.addOption(
new Option('-ta, --targetContractAddress <targetContractAddress>', 'The address of the contract to be called')
new Option('-a, --targetContractAddress <targetContractAddress>', 'target contract address')
.makeOptionMandatory(true)
.env('TARGET_ADDR'),
);
program.addOption(
new Option('-v, --nativeValue <nativeValue>', 'The amount of native token (e.g., Ether) to be sent along with the call').default(0),
);
program.addOption(
new Option('-m, --methodName <methodName>', 'method name to call in executeContract')
new Option('--action <action>', 'executeContract action')
milapsheth marked this conversation as resolved.
Show resolved Hide resolved
.choices(['withdraw', 'transfer', 'approve', 'default'])
.default('default'),
);
program.addOption(new Option('-c, --callData <callData>', 'The calldata to be sent').env('CALL_DATA').default('0x'));
program.addOption(
new Option('-ra, --recipientAddress <recipientAddress>', 'The recipient address for the tokens').env('RECIPIENT_ADDR'),
);
program.addOption(
new Option('-am, --amount <amount>', 'The amount of tokens to transfer/withdraw/provide allowance etc.').env('AMOUNT'),
);
program.addOption(new Option('--callData <callData>', 'The calldata to be sent').env('CALL_DATA').default('0x'));
program.addOption(new Option('--recipientAddress <recipientAddress>', 'The recipient address for the tokens').env('RECIPIENT_ADDR'));
program.addOption(new Option('--amount <amount>', 'The amount of tokens to transfer/withdraw/provide allowance etc.').env('AMOUNT'));

program.action((options) => {
main(options);
Expand Down
35 changes: 30 additions & 5 deletions evm/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,6 @@ function findProjectRoot(startDir) {
return currentDir;
}

// Move up a directory
currentDir = path.resolve(currentDir, '..');
}

Expand All @@ -805,7 +804,10 @@ function findContractPath(dir, contractName) {

if (stat && stat.isDirectory()) {
const recursivePath = findContractPath(filePath, contractName);
if (recursivePath) return recursivePath;

if (recursivePath) {
return recursivePath;
}
} else if (file === `${contractName}.json`) {
return filePath;
}
Expand All @@ -816,20 +818,42 @@ function getContractPath(contractName) {
const projectRoot = findProjectRoot(__dirname);

const searchDirs = [
path.join(projectRoot, 'node_modules', '@axelar-network/axelar-gmp-sdk-solidity/artifacts/contracts'),
path.join(projectRoot, 'node_modules', '@axelar-network/axelar-cgp-solidity/artifacts/contracts'),
path.join(projectRoot, 'node_modules', '@axelar-network', 'axelar-gmp-sdk-solidity', 'artifacts', 'contracts'),
path.join(projectRoot, 'node_modules', '@axelar-network', 'axelar-cgp-solidity', 'artifacts', 'contracts'),
];

for (const dir of searchDirs) {
if (fs.existsSync(dir)) {
const contractPath = findContractPath(dir, contractName);
if (contractPath) return contractPath;

if (contractPath) {
return contractPath;
}
}
}

throw new Error(`Contract path for ${contractName} must be entered manually.`);
}

function getContractJSON(contractName, artifactPath) {
let contractPath;

if (artifactPath) {
contractPath = artifactPath.charAt(0) === '@' ? artifactPath : artifactPath + contractName + '.sol/' + contractName + '.json';
} else {
contractPath = getContractPath(contractName);
}

printInfo('Contract path', contractPath);

try {
const contractJson = require(contractPath);
return contractJson;
} catch (err) {
throw new Error(`Failed to load contract JSON for ${contractName} at path ${contractPath}`);
}
}

module.exports = {
deployCreate,
deployCreate2,
Expand Down Expand Up @@ -876,4 +900,5 @@ module.exports = {
prompt,
mainProcessor,
getContractPath,
getContractJSON,
};
Loading