Skip to content

Commit

Permalink
feat: allow gateway deployment with amplifier worker set (#35)
Browse files Browse the repository at this point in the history
* feat: update auth deployment to accept worker set from amplifier

* fix: lint and format

* fix: get prover from specific chain

* fix: config structure and some cleanup

* fix: removed specific contract name for amplifier
  • Loading branch information
eguajardo authored Aug 30, 2023
1 parent a11a260 commit ef1d11e
Show file tree
Hide file tree
Showing 4 changed files with 705 additions and 6 deletions.
8 changes: 5 additions & 3 deletions evm/deploy-gateway-v5.0.x.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ const readlineSync = require('readline-sync');
const { Command, Option } = require('commander');
const chalk = require('chalk');

async function getAuthParams(config, chain) {
async function getAuthParams(config, chainName, options) {
printLog('retrieving addresses');
const { addresses, weights, threshold } = await getEVMAddresses(config, chain);
const { addresses, weights, threshold } = await getEVMAddresses(config, chainName, options);
printObj(JSON.stringify({ addresses, weights, threshold }));
const paramsAuth = [defaultAbiCoder.encode(['address[]', 'uint256[]', 'uint256'], [addresses, weights, threshold])];
return paramsAuth;
Expand Down Expand Up @@ -94,7 +94,7 @@ async function deploy(config, options) {
auth = authFactory.attach(await gateway.authModule());
} else {
printLog(`deploying auth contract`);
const params = await getAuthParams(config, chain.id);
const params = await getAuthParams(config, chainName, options);
printLog(`auth deployment args: ${params}`);

auth = await authFactory.deploy(params).then((d) => d.deployed());
Expand Down Expand Up @@ -261,6 +261,8 @@ async function programHandler() {
program.addOption(new Option('-g, --governance <governance>', 'governance address').env('GOVERNANCE'));
program.addOption(new Option('-m, --mintLimiter <mintLimiter>', 'mint limiter address').env('MINT_LIMITER'));
program.addOption(new Option('-y, --yes', 'skip deployment prompt confirmation').env('YES'));
program.addOption(new Option('-k, --keyId <keyId>', 'key ID').env('KEY_ID'));
program.addOption(new Option('-a, --amplifier', 'deploy amplifier gateway').env('AMPLIFIER'));

program.action((options) => {
main(options);
Expand Down
27 changes: 24 additions & 3 deletions evm/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const {
ContractFactory,
Contract,
utils: { getContractAddress, keccak256, isAddress, getCreate2Address, defaultAbiCoder },
utils: { computeAddress, getContractAddress, keccak256, isAddress, getCreate2Address, defaultAbiCoder },
} = require('ethers');
const https = require('https');
const http = require('http');
Expand All @@ -19,6 +19,7 @@ const {
predictContractConstant,
getCreate3Address,
} = require('@axelar-network/axelar-gmp-sdk-solidity');
const { CosmWasmClient } = require('@cosmjs/cosmwasm-stargate');
const CreateDeploy = require('@axelar-network/axelar-gmp-sdk-solidity/artifacts/contracts/deploy/CreateDeploy.sol/CreateDeploy.json');
const IDeployer = require('@axelar-network/axelar-gmp-sdk-solidity/interfaces/IDeployer.json');

Expand Down Expand Up @@ -455,8 +456,13 @@ const getProxy = async (config, chain) => {
return address;
};

const getEVMAddresses = async (config, chain, keyID = '') => {
const evmAddresses = await httpGet(`${config.axelar.lcd}/axelar/evm/v1beta1/key_address/${chain}?key_id=${keyID}`);
const getEVMAddresses = async (config, chainName, options) => {
const keyID = options.keyId || '';

const evmAddresses = options.amplifier
? await getAmplifierKeyAddresses(config, chainName, keyID)
: await httpGet(`${config.axelar.lcd}/axelar/evm/v1beta1/key_address/${config.chains[chainName].id}?key_id=${keyID}`);

const sortedAddresses = evmAddresses.addresses.sort((a, b) => a.address.toLowerCase().localeCompare(b.address.toLowerCase()));

const addresses = sortedAddresses.map((weightedAddress) => weightedAddress.address);
Expand All @@ -466,6 +472,21 @@ const getEVMAddresses = async (config, chain, keyID = '') => {
return { addresses, weights, threshold };
};

const getAmplifierKeyAddresses = async (config, chainName, keyID = '') => {
const client = await CosmWasmClient.connect(config.axelar.rpc);
const key = await client.queryContractSmart(config.axelar.contracts.Multisig.address, {
get_key: { key_id: { owner: config.axelar.contracts.MultisigProver[chainName].address, subkey: keyID } },
});
const pubkeys = new Map(Object.entries(key.pub_keys));

const weightedAddresses = Object.values(key.snapshot.participants).map((participant) => ({
address: computeAddress(`0x${pubkeys.get(participant.address)}`),
weight: participant.weight,
}));

return { addresses: weightedAddresses, threshold: key.snapshot.quorum };
};

function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
Expand Down
Loading

0 comments on commit ef1d11e

Please sign in to comment.