Skip to content

Commit

Permalink
Merge branch 'main' into update/token-ownership-script
Browse files Browse the repository at this point in the history
  • Loading branch information
blockchainguyy committed Aug 2, 2024
2 parents fa7cf33 + 0ba1321 commit 48cad57
Show file tree
Hide file tree
Showing 16 changed files with 1,725 additions and 1,067 deletions.
1,319 changes: 1,077 additions & 242 deletions axelar-chains-config/info/stagenet.json

Large diffs are not rendered by default.

67 changes: 67 additions & 0 deletions common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ const chalk = require('chalk');
const https = require('https');
const http = require('http');
const readlineSync = require('readline-sync');
const { CosmWasmClient } = require('@cosmjs/cosmwasm-stargate');
const { ethers } = require('hardhat');
const {
utils: { keccak256, hexlify },
} = ethers;
const { normalizeBech32 } = require('@cosmjs/encoding');

function loadConfig(env) {
return require(`${__dirname}/../axelar-chains-config/info/${env}.json`);
Expand Down Expand Up @@ -331,6 +337,66 @@ function toBigNumberString(number) {
return Math.ceil(number).toLocaleString('en', { useGrouping: false });
}

const isValidCosmosAddress = (str) => {
try {
normalizeBech32(str);

return true;
} catch (error) {
return false;
}
};

async function getDomainSeparator(config, chain, options) {
// Allow any domain separator for local deployments or `0x` if not provided
if (options.env === 'local') {
return options.domainSeparator || ethers.constants.HashZero;
}

if (isKeccak256Hash(options.domainSeparator)) {
// return the domainSeparator for debug deployments
return options.domainSeparator;
}

const {
axelar: { contracts, chainId },
} = config;
const {
Router: { address: routerAddress },
} = contracts;

if (!isString(chain.axelarId)) {
throw new Error(`missing or invalid axelar ID for chain ${chain.name}`);
}

if (!isString(routerAddress) || !isValidCosmosAddress(routerAddress)) {
throw new Error(`missing or invalid router address`);
}

if (!isString(chainId)) {
throw new Error(`missing or invalid chain ID`);
}

printInfo(`Retrieving domain separator for ${chain.name} from Axelar network`);
const domainSeparator = hexlify((await getContractConfig(config, chain.axelarId)).domain_separator);
const expectedDomainSeparator = calculateDomainSeparator(chain.axelarId, routerAddress, chainId);

if (domainSeparator !== expectedDomainSeparator) {
throw new Error(`unexpected domain separator (want ${expectedDomainSeparator}, got ${domainSeparator})`);
}

return domainSeparator;
}

const getContractConfig = async (config, chain) => {
const key = Buffer.from('config');
const client = await CosmWasmClient.connect(config.axelar.rpc);
const value = await client.queryContractRaw(config.axelar.contracts.MultisigProver[chain].address, key);
return JSON.parse(Buffer.from(value).toString('ascii'));
};

const calculateDomainSeparator = (chain, router, network) => keccak256(Buffer.from(`${chain}${router}${network}`));

module.exports = {
loadConfig,
saveConfig,
Expand Down Expand Up @@ -362,4 +428,5 @@ module.exports = {
toBigNumberString,
timeout,
validateParameters,
getDomainSeparator,
};
44 changes: 2 additions & 42 deletions evm/deploy-amplifier-gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const {
ContractFactory,
Contract,
Wallet,
utils: { defaultAbiCoder, keccak256, hexlify },
utils: { defaultAbiCoder, keccak256 },
getDefaultProvider,
} = ethers;

Expand All @@ -22,59 +22,19 @@ const {
mainProcessor,
deployContract,
getGasOptions,
isKeccak256Hash,
getContractConfig,
isString,
getWeightedSigners,
getContractJSON,
getDeployedAddress,
getDeployOptions,
getDomainSeparator,
} = require('./utils');
const { calculateDomainSeparator, isValidCosmosAddress } = require('../cosmwasm/utils');
const { addExtendedOptions } = require('./cli-utils');
const { storeSignedTx, signTransaction, getWallet } = require('./sign-utils.js');

const { WEIGHTED_SIGNERS_TYPE, encodeWeightedSigners } = require('@axelar-network/axelar-gmp-sdk-solidity/scripts/utils');
const AxelarAmplifierGatewayProxy = require('@axelar-network/axelar-gmp-sdk-solidity/artifacts/contracts/gateway/AxelarAmplifierGatewayProxy.sol/AxelarAmplifierGatewayProxy.json');
const AxelarAmplifierGateway = require('@axelar-network/axelar-gmp-sdk-solidity/artifacts/contracts/gateway/AxelarAmplifierGateway.sol/AxelarAmplifierGateway.json');

async function getDomainSeparator(config, chain, options) {
printInfo(`Retrieving domain separator for ${chain.name} from Axelar network`);

if (isKeccak256Hash(options.domainSeparator)) {
// return the domainSeparator for debug deployments
return options.domainSeparator;
}

const {
axelar: { contracts, chainId },
} = config;
const {
Router: { address: routerAddress },
} = contracts;

if (!isString(chain.axelarId)) {
throw new Error(`missing or invalid axelar ID for chain ${chain.name}`);
}

if (!isString(routerAddress) || !isValidCosmosAddress(routerAddress)) {
throw new Error(`missing or invalid router address`);
}

if (!isString(chainId)) {
throw new Error(`missing or invalid chain ID`);
}

const domainSeparator = hexlify((await getContractConfig(config, chain.axelarId)).domain_separator);
const expectedDomainSeparator = calculateDomainSeparator(chain.axelarId, routerAddress, chainId);

if (domainSeparator !== expectedDomainSeparator) {
throw new Error(`unexpected domain separator (want ${expectedDomainSeparator}, got ${domainSeparator})`);
}

return domainSeparator;
}

async function getSetupParams(config, chain, operator, options) {
const { signers: signerSets, verifierSetId } = await getWeightedSigners(config, chain, options);
printInfo('Setup params', JSON.stringify([operator, signerSets], null, 2));
Expand Down
Loading

0 comments on commit 48cad57

Please sign in to comment.