Skip to content

Commit

Permalink
feat(mainnet): support running examples on mainnet
Browse files Browse the repository at this point in the history
  • Loading branch information
re1ro committed Jun 17, 2024
1 parent b71def0 commit f1609df
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions scripts/libs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ function getEVMChains(env, chains = []) {
return fs.readJsonSync(configPath.localEvmChains).filter((chain) => selectedChains.includes(chain.name));
}

const testnet = getTestnetChains(selectedChains);
const configs = env === 'mainnet' ? getMainnetChains(selectedChains) : getTestnetChains(selectedChains);

return testnet.map((chain) => ({
...chain,
gateway: chain.contracts.AxelarGateway.address,
gasService: chain.contracts.AxelarGasService.address,
return configs.map((config) => ({
...config,
gateway: config.contracts.AxelarGateway.address,
gasService: config.contracts.AxelarGasService.address,
}));
}

Expand All @@ -57,7 +57,7 @@ function getTestnetChains(chains = []) {
let testnet = [];
if (fs.existsSync(_path)) {
testnet = fs
.readJsonSync(path.join(__dirname, '../../chain-config/testnet-evm.json'))
.readJsonSync(_path)
.filter((chain) => chains.includes(chain.name));
}

Expand All @@ -79,6 +79,33 @@ function getTestnetChains(chains = []) {
}));
}

/**
* Get chains config for testnet.
* @param {*} chains - The list of chains to get the chain objects for. If this is empty, the default chains will be used.
* @returns {Chain[]} - The chain objects.
*/
function getMainnetChains(chains = []) {
const _path = path.join(__dirname, '../../chain-config/mainnet-evm.json');
let mainnet = [];
if (fs.existsSync(_path)) {
mainnet = fs
.readJsonSync(_path)
.filter((chain) => chains.includes(chain.name));
}

if (mainnet.length < chains.length) {
const { mainnetInfo } = require('@axelar-network/axelar-local-dev');
mainnet = [];
for (const chain of chains) {
mainnet.push(mainnetInfo[chain.toLowerCase()]);
}
}

// temporary fix for gas service contract address

return mainnet;
}

/**
* Get the balances of an address on a list of chains.
* @param {*} chains - The list of chains to get the balances from.
Expand Down Expand Up @@ -187,7 +214,7 @@ function checkWallet() {
* @param {*} env - The environment to check. Available options are 'local' and 'testnet'.
*/
function checkEnv(env) {
if (env == null || (env !== 'testnet' && env !== 'local')) {
if (env == null || (env !== 'mainnet' && env !== 'testnet' && env !== 'local')) {
throw new Error('Need to specify testnet or local as an argument to this script.');
}
}
Expand Down

0 comments on commit f1609df

Please sign in to comment.