Skip to content

Commit

Permalink
feat(evm): retrieve domain separator from axelar (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs47 authored May 16, 2024
1 parent 584a817 commit 3e43967
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
run: node evm/deploy-contract.js -c Create3Deployer -m create2 -y

- name: Deploy AxelarAmplifierGateway
run: node evm/deploy-amplifier-gateway.js --deployMethod create3 -s "AxelarAmplifierGateway v5.8" --owner 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --keyID 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 -y
run: node evm/deploy-amplifier-gateway.js --deployMethod create3 -s "AxelarAmplifierGateway v5.8" --owner 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --keyID 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --domainSeparator 0xe95c4726b1aca58a875174db9810fff4d337011a24b81e31ad812a1b53ed8970 -y

- name: Deploy AxelarGateway
run: node evm/deploy-gateway-v6.2.x.js --deployMethod create3 -s "AxelarGateway v6.2" --governance 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --mintLimiter 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --keyID 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 -y
Expand Down
21 changes: 17 additions & 4 deletions evm/deploy-amplifier-gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {
Contract,
Wallet,
BigNumber,
utils: { defaultAbiCoder, getContractAddress, keccak256 },
utils: { defaultAbiCoder, getContractAddress, keccak256, hexlify },
constants: { HashZero },
getDefaultProvider,
} = ethers;
Expand All @@ -26,6 +26,8 @@ const {
deployContract,
getGasOptions,
isValidAddress,
isKeccak256Hash,
getContractConfig,
} = require('./utils');
const { addExtendedOptions } = require('./cli-utils');
const { storeSignedTx, signTransaction, getWallet } = require('./sign-utils.js');
Expand All @@ -52,7 +54,7 @@ async function getWeightedSigners(config, chain, options) {
nonce: HashZero,
};
} else {
const addresses = getAmplifierKeyAddresses(config, chain.axelarId);
const addresses = await getAmplifierKeyAddresses(config, chain.axelarId);
const nonce = ethers.utils.hexZeroPad(BigNumber.from(addresses.created_at).toHexString(), 32);

signers = {
Expand All @@ -65,6 +67,17 @@ async function getWeightedSigners(config, chain, options) {
return [signers];
}

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;
}

return hexlify((await getContractConfig(config, chain.name)).domain_separator);
}

async function getSetupParams(config, chain, operator, options) {
const signerSets = await getWeightedSigners(config, chain, options);
printInfo('Setup params', JSON.stringify([operator, signerSets], null, 2));
Expand Down Expand Up @@ -155,7 +168,7 @@ async function deploy(config, chain, options) {
}

contractConfig.deployer = wallet.address;
const domainSeparator = options.domainSeparator; // TODO: retrieve domain separator from amplifier / calculate the same way
const domainSeparator = await getDomainSeparator(config, chain, options);
const minimumRotationDelay = options.minimumRotationDelay;
const salt = options.salt || '';

Expand Down Expand Up @@ -422,7 +435,7 @@ async function programHandler() {

program.addOption(new Option('-r, --rpc <rpc>', 'chain rpc url').env('URL'));
program.addOption(new Option('--previousSignersRetention <previousSignersRetention>', 'previous signer retention').default(15));
program.addOption(new Option('--domainSeparator <domainSeparator>', 'domain separator').default(HashZero));
program.addOption(new Option('--domainSeparator <domainSeparator>', 'domain separator'));
program.addOption(
new Option('--minimumRotationDelay <minimumRotationDelay>', 'minium delay for signer rotations').default(24 * 60 * 60),
); // 1 day
Expand Down
9 changes: 9 additions & 0 deletions evm/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,13 @@ const getEVMAddresses = async (config, chain, options = {}) => {
return { addresses, weights, threshold, keyID: evmAddresses.key_id };
};

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 getAmplifierKeyAddresses = async (config, chain) => {
const client = await CosmWasmClient.connect(config.axelar.rpc);
const workerSet = await client.queryContractSmart(config.axelar.contracts.MultisigProver[chain].address, 'get_worker_set');
Expand Down Expand Up @@ -1247,4 +1254,6 @@ module.exports = {
isValidChain,
toBigNumberString,
timeout,
getAmplifierKeyAddresses,
getContractConfig,
};

0 comments on commit 3e43967

Please sign in to comment.