Skip to content

Commit

Permalink
refactor: interchain token service scripts (#124)
Browse files Browse the repository at this point in the history
* refactor: ITS scripts

* fix: lint error

* fix: verify contract for proxies

* feat: bump ITS version

* fix: test

* fix: default deploy method for ITS

* fix: default deploy method for ITS create

* feat: remove unused imports

* improve scripts

* prettier

---------

Co-authored-by: Dean Amiel <dean@axelar.network>
Co-authored-by: Milap Sheth <milap@axelar.network>
  • Loading branch information
3 people authored Dec 7, 2023
1 parent 1c74027 commit e206346
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 197 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ jobs:
run: node evm/deploy-its.js -s "ITS v1.0.0" -f "ITS v1.0.0 Factory" -m create2 -u -y

- name: InterchainTokenFactory deploy interchain token on current chain
run: node evm/interchainTokenFactory.js --action deployInterchainToken --name "test" --symbol "TST" --decimals 18 --distributor 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --salt "salt" -y
run: node evm/interchainTokenFactory.js --action deployInterchainToken --name "test" --symbol "TST" --decimals 18 --minter 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --salt "salt" -y

- name: InterchainTokenService deploy interchain token on current chain
run: node evm/its.js --action deployInterchainToken --name "test" --symbol "TST" --decimals 18 --distributor 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 --destinationChain '' --gasValue 0 --salt "salt" -y
run: node evm/its.js --action deployInterchainToken --name "test" --symbol "TST" --decimals 18 --minter 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 --destinationChain '' --gasValue 0 --salt "salt" -y

- name: Add gasOptions to local.json
run: |
Expand Down
109 changes: 42 additions & 67 deletions evm/deploy-its.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ const {
sleep,
getBytecodeHash,
getGasOptions,
isContract,
} = require('./utils');
const { addExtendedOptions } = require('./cli-utils');
const InterchainTokenService = getContractJSON('InterchainTokenService');
const { Command, Option } = require('commander');

/**
Expand All @@ -33,12 +33,21 @@ const { Command, Option } = require('commander');
* @param {*} verifyOptions
*/

async function deployImplementation(config, wallet, chain, options) {
const { env, salt, factorySalt, deployMethod, skipExisting, verify, yes } = options;
async function deployAll(config, wallet, chain, options) {
const { env, artifactPath, salt, factorySalt, deployMethod, skipExisting, verify, yes } = options;
const verifyOptions = verify ? { env, chain: chain.name, only: verify === 'only' } : null;

const provider = getDefaultProvider(chain.rpc);
const InterchainTokenService = getContractJSON('InterchainTokenService', artifactPath);

const contractName = 'InterchainTokenService';
const contracts = chain.contracts;

// Reset config data if it's a fresh deployment
if (!skipExisting) {
contracts[contractName] = {};
}

const contractConfig = contracts[contractName] || {};

contractConfig.salt = salt;
Expand Down Expand Up @@ -79,7 +88,7 @@ async function deployImplementation(config, wallet, chain, options) {
return await deployContract(
deployMethod,
wallet,
getContractJSON('TokenManagerDeployer'),
getContractJSON('TokenManagerDeployer', artifactPath),
[],
deployOptions,
gasOptions,
Expand All @@ -94,8 +103,8 @@ async function deployImplementation(config, wallet, chain, options) {
return await deployContract(
deployMethod,
wallet,
getContractJSON('InterchainToken'),
[],
getContractJSON('InterchainToken', artifactPath),
[interchainTokenServiceAddress],
deployOptions,
gasOptions,
verifyOptions,
Expand All @@ -109,7 +118,7 @@ async function deployImplementation(config, wallet, chain, options) {
return await deployContract(
deployMethod,
wallet,
getContractJSON('InterchainTokenDeployer'),
getContractJSON('InterchainTokenDeployer', artifactPath),
[contractConfig.interchainToken],
deployOptions,
gasOptions,
Expand All @@ -118,13 +127,13 @@ async function deployImplementation(config, wallet, chain, options) {
);
},
},
tokenManagerMintBurn: {
name: 'Token Manager Mint Burn',
tokenManager: {
name: 'Token Manager',
async deploy() {
return await deployContract(
deployMethod,
wallet,
getContractJSON('TokenManagerMintBurn'),
getContractJSON('TokenManager', artifactPath),
[interchainTokenServiceAddress],
deployOptions,
gasOptions,
Expand All @@ -133,44 +142,14 @@ async function deployImplementation(config, wallet, chain, options) {
);
},
},
tokenManagerMintBurnFrom: {
name: 'Token Manager Mint Burn From',
tokenHandler: {
name: 'Token Handler',
async deploy() {
return await deployContract(
deployMethod,
wallet,
getContractJSON('TokenManagerMintBurnFrom'),
[interchainTokenServiceAddress],
deployOptions,
gasOptions,
verifyOptions,
chain,
);
},
},
tokenManagerLockUnlock: {
name: 'Token Manager Lock Unlock',
async deploy() {
return await deployContract(
deployMethod,
wallet,
getContractJSON('TokenManagerLockUnlock'),
[interchainTokenServiceAddress],
deployOptions,
gasOptions,
verifyOptions,
chain,
);
},
},
tokenManagerLockUnlockFee: {
name: 'Token Manager Lock Unlock Fee',
async deploy() {
return await deployContract(
deployMethod,
wallet,
getContractJSON('TokenManagerLockUnlockFee'),
[interchainTokenServiceAddress],
getContractJSON('TokenHandler', artifactPath),
[],
deployOptions,
gasOptions,
verifyOptions,
Expand All @@ -184,20 +163,16 @@ async function deployImplementation(config, wallet, chain, options) {
return await deployContract(
deployMethod,
wallet,
getContractJSON('InterchainTokenService', options.artifactPath),
InterchainTokenService,
[
contractConfig.tokenManagerDeployer,
contractConfig.interchainTokenDeployer,
contracts.AxelarGateway.address,
contracts.AxelarGasService.address,
interchainTokenFactory,
chain.id,
[
contractConfig.tokenManagerMintBurn,
contractConfig.tokenManagerMintBurnFrom,
contractConfig.tokenManagerLockUnlock,
contractConfig.tokenManagerLockUnlockFee,
],
contractConfig.tokenManager,
contractConfig.tokenHandler,
],
deployOptions,
gasOptions,
Expand All @@ -219,7 +194,7 @@ async function deployImplementation(config, wallet, chain, options) {
return await deployContract(
'create3',
wallet,
getContractJSON('InterchainTokenServiceProxy'),
getContractJSON('InterchainProxy', artifactPath),
[contractConfig.implementation, wallet.address, deploymentParams],
{ salt, deployerContract: contracts.Create3Deployer.address },
gasOptions,
Expand All @@ -234,7 +209,7 @@ async function deployImplementation(config, wallet, chain, options) {
return await deployContract(
deployMethod,
wallet,
getContractJSON('InterchainTokenFactory'),
getContractJSON('InterchainTokenFactory', artifactPath),
[interchainTokenServiceAddress],
deployOptions,
gasOptions,
Expand All @@ -249,8 +224,8 @@ async function deployImplementation(config, wallet, chain, options) {
return await deployContract(
'create3',
wallet,
getContractJSON('InterchainTokenFactoryProxy'),
[contractConfig.interchainTokenFactoryImplementation, wallet.address],
getContractJSON('InterchainProxy', artifactPath),
[contractConfig.interchainTokenFactoryImplementation, wallet.address, '0x'],
{ salt: factorySalt, deployerContract: contracts.Create3Deployer.address },
gasOptions,
verifyOptions,
Expand All @@ -264,23 +239,21 @@ async function deployImplementation(config, wallet, chain, options) {
if (skipExisting && contractConfig[key]) continue;

const deployment = deployments[key];
printInfo(`Deploying ${deployment.name}.`);
printInfo(`Deploying ${deployment.name}`);

const contract = await deployment.deploy();

if (contract.address === undefined) {
contractConfig[key] = contract;
printInfo(`Deployed ${deployment.name} at ${JSON.stringify(contract)}`);
} else {
contractConfig[key] = contract.address;
printInfo(`Deployed ${deployment.name} at ${contract.address}`);
}
contractConfig[key] = contract.address;
printInfo(`Deployed ${deployment.name} at ${contract.address}`);

saveConfig(config, options.env);

if (chain.chainId !== 31337) {
await sleep(2000);
}

if (!(await isContract(contract.address, provider))) {
throw new Error(`Contract ${deployment.name} at ${contract.address} was not deployed on ${chain.name}`);
}
}
}

Expand Down Expand Up @@ -309,11 +282,11 @@ async function deploy(config, chain, options) {
throw new Error(`Invalid operator address: ${operatorAddress}`);
}

await deployImplementation(config, wallet, chain, options);
await deployAll(config, wallet, chain, options);
}

async function upgrade(config, chain, options) {
const { salt, privateKey } = options;
const { artifactPath, salt, privateKey } = options;

const rpc = chain.rpc;
const provider = getDefaultProvider(rpc);
Expand All @@ -331,10 +304,12 @@ async function upgrade(config, chain, options) {

contracts[contractName] = contractConfig;

await deployImplementation(config, wallet, chain, options);
await deployAll(config, wallet, chain, options);

printInfo(`Upgrading Interchain Token Service.`);

const InterchainTokenService = getContractJSON('InterchainTokenService', artifactPath);

const gasOptions = await getGasOptions(chain, options, contractName);
const contract = new Contract(contractConfig.address, InterchainTokenService.abi, wallet);

Expand Down
Loading

0 comments on commit e206346

Please sign in to comment.