From 92945fe41f766c4be0bb6e7d389b854fcf449f10 Mon Sep 17 00:00:00 2001 From: Edwin Guajardo Date: Thu, 12 Dec 2024 11:57:05 -0600 Subject: [PATCH 1/4] remove requirement to use chainName option for AxelarnetGateway --- cosmwasm/utils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cosmwasm/utils.js b/cosmwasm/utils.js index fdc39758..b5e49338 100644 --- a/cosmwasm/utils.js +++ b/cosmwasm/utils.js @@ -568,8 +568,8 @@ const makeInstantiateMsg = (contractName, chainName, config) => { } case 'AxelarnetGateway': { - if (!chainConfig) { - throw new Error('AxelarnetGateway requires chainName option'); + if (chainConfig) { + throw new Error('AxelarnetGateway does not support chainName option'); } return makeAxelarnetGatewayInstantiateMsg(contractConfig, config); From 9a22f750871557ff7f16e02052d6cddcafec0f4d Mon Sep 17 00:00:00 2001 From: Edwin Guajardo Date: Sun, 15 Dec 2024 14:42:19 -0600 Subject: [PATCH 2/4] add chainName requirement validation --- .../info/devnet-amplifier.json | 9 +- axelar-chains-config/info/stagenet.json | 9 +- cosmwasm/cli-utils.js | 19 ++++- cosmwasm/utils.js | 85 +++++++++---------- 4 files changed, 59 insertions(+), 63 deletions(-) diff --git a/axelar-chains-config/info/devnet-amplifier.json b/axelar-chains-config/info/devnet-amplifier.json index c18db356..f3a54076 100644 --- a/axelar-chains-config/info/devnet-amplifier.json +++ b/axelar-chains-config/info/devnet-amplifier.json @@ -839,10 +839,6 @@ "codeId": 844, "address": "axelar1wvms3cy5hxrgl7uxhkz7yth4qzqum6aaccwkmvafq8z0mgdfxr8qrnvw0k", "nexus": "axelar17h8uk4ct0mdv9mgkuxszt4gp2htpfr08mge20r", - "axelar": { - "storeInstantiateProposalId": "59", - "codeId": 845 - }, "storeCodeProposalCodeHash": "c7286d0f59276b794641bdfbb4f96fafcee3553b67f3397d662a4683968f525b", "storeCodeProposalId": "60", "lastUploadedCodeId": 845 @@ -852,10 +848,7 @@ "governanceAddress": "axelar1zlr7e5qf3sz7yf890rkh9tcnu87234k6k7ytd9", "codeId": 843, "address": "axelar157hl7gpuknjmhtac2qnphuazv2yerfagva7lsu9vuj2pgn32z22qa26dk4", - "axelar": { - "codeId": 843, - "instantiateProposalId": "61" - }, + "instantiateProposalId": "61", "sui": { "maxUintBits": 64, "maxDecimalsWhenTruncating": 8 diff --git a/axelar-chains-config/info/stagenet.json b/axelar-chains-config/info/stagenet.json index fe74a23c..4f806358 100644 --- a/axelar-chains-config/info/stagenet.json +++ b/axelar-chains-config/info/stagenet.json @@ -1851,10 +1851,7 @@ "storeCodeProposalCodeHash": "b60d0d227c7a400a0fcc80ed52f0e6688e5da6db676a61ed8b6942823294031d", "governanceAddress": "axelar10d07y265gmmuvt4z0w9aw880jnsr700j7v9daj", "adminAddress": "axelar12qvsvse32cjyw60ztysd3v655aj5urqeup82ky", - "axelar": { - "codeId": 17, - "address": "axelar1ph8qufmsh556e40uk0ceaufc06nwhnw0ksgdqqk6ldszxchh8llq8x52dk" - }, + "codeId": 17, "address": "axelar1ph8qufmsh556e40uk0ceaufc06nwhnw0ksgdqqk6ldszxchh8llq8x52dk", "lastUploadedCodeId": 17 }, @@ -1864,10 +1861,6 @@ "nexus": "axelar17h8uk4ct0mdv9mgkuxszt4gp2htpfr08mge20r", "address": "axelar1s9amtxejrdlsunwdf0cclhjtezdp6wmurxxnh45gfvtpa2jrsusqv934n6", "codeId": 20, - "axelar": { - "codeId": 20, - "address": "axelar1s9amtxejrdlsunwdf0cclhjtezdp6wmurxxnh45gfvtpa2jrsusqv934n6" - }, "lastUploadedCodeId": 20 } }, diff --git a/cosmwasm/cli-utils.js b/cosmwasm/cli-utils.js index 75746a07..2e93354e 100644 --- a/cosmwasm/cli-utils.js +++ b/cosmwasm/cli-utils.js @@ -3,7 +3,7 @@ require('dotenv').config(); const { isNumber, addEnvOption } = require('../common'); -const { governanceAddress } = require('./utils'); +const { CONTRACT_SCOPE_CHAIN, CONTRACT_SCOPE_GLOBAL, CONTRACTS_SCOPES, governanceAddress } = require('./utils'); const { Option, InvalidArgumentError } = require('commander'); @@ -83,6 +83,23 @@ const addAmplifierOptions = (program, options) => { const addContractOptions = (program) => { program.addOption(new Option('-c, --contractName ', 'contract name').makeOptionMandatory(true)); program.addOption(new Option('-n, --chainName ', 'chain name').env('CHAIN').argParser((value) => value.toLowerCase())); + program.hook('preAction', (command) => { + const chainName = command.opts().chainName; + const contractName = command.opts().contractName; + const scope = CONTRACTS_SCOPES[contractName]; + + if (!scope) { + throw new Error(`Scope of contract ${contractName} is not defined`); + } + + if (scope === CONTRACT_SCOPE_CHAIN && !chainName) { + throw new Error(`${contractName} requires chainName option`); + } + + if (scope === CONTRACT_SCOPE_GLOBAL && chainName) { + throw new Error(`${contractName} does not support chainName option`); + } + }); }; const addStoreOptions = (program) => { diff --git a/cosmwasm/utils.js b/cosmwasm/utils.js index cf788731..7048f48c 100644 --- a/cosmwasm/utils.js +++ b/cosmwasm/utils.js @@ -36,6 +36,32 @@ const { normalizeBech32 } = require('@cosmjs/encoding'); const DEFAULT_MAX_UINT_BITS_EVM = 256; const DEFAULT_MAX_DECIMALS_WHEN_TRUNCATING_EVM = 255; +const CONTRACT_NAME_COORDINATOR = 'Coordinator'; +const CONTRACT_NAME_SERVICE_REGISTRY = 'ServiceRegistry'; +const CONTRACT_NAME_MULTISIG = 'Multisig'; +const CONTRACT_NAME_REWARDS = 'Rewards'; +const CONTRACT_NAME_ROUTER = 'Router'; +const CONTRACT_NAME_VOTING_VERIFIER = 'VotingVerifier'; +const CONTRACT_NAME_GATEWAY = 'Gateway'; +const CONTRACT_NAME_MULTISIG_PROVER = 'MultisigProver'; +const CONTRACT_NAME_AXELARNET_GATEWAY = 'AxelarnetGateway'; +const CONTRACT_NAME_INTERCHAIN_TOKEN_SERVICE = 'InterchainTokenService'; + +const CONTRACT_SCOPE_GLOBAL = 'global'; +const CONTRACT_SCOPE_CHAIN = 'chain'; +const CONTRACTS_SCOPES = { + [CONTRACT_NAME_COORDINATOR]: CONTRACT_SCOPE_GLOBAL, + [CONTRACT_NAME_SERVICE_REGISTRY]: CONTRACT_SCOPE_GLOBAL, + [CONTRACT_NAME_MULTISIG]: CONTRACT_SCOPE_GLOBAL, + [CONTRACT_NAME_REWARDS]: CONTRACT_SCOPE_GLOBAL, + [CONTRACT_NAME_ROUTER]: CONTRACT_SCOPE_GLOBAL, + [CONTRACT_NAME_VOTING_VERIFIER]: CONTRACT_SCOPE_CHAIN, + [CONTRACT_NAME_GATEWAY]: CONTRACT_SCOPE_CHAIN, + [CONTRACT_NAME_MULTISIG_PROVER]: CONTRACT_SCOPE_CHAIN, + [CONTRACT_NAME_AXELARNET_GATEWAY]: CONTRACT_SCOPE_GLOBAL, + [CONTRACT_NAME_INTERCHAIN_TOKEN_SERVICE]: CONTRACT_SCOPE_GLOBAL, +}; + const governanceAddress = 'axelar10d07y265gmmuvt4z0w9aw880jnsr700j7v9daj'; const prepareWallet = async ({ mnemonic }) => await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, { prefix: 'axelar' }); @@ -503,79 +529,43 @@ const makeInstantiateMsg = (contractName, chainName, config) => { const { [contractName]: contractConfig } = contracts; switch (contractName) { - case 'Coordinator': { - if (chainConfig) { - throw new Error('Coordinator does not support chainName option'); - } - + case CONTRACT_NAME_COORDINATOR: { return makeCoordinatorInstantiateMsg(contractConfig, contracts); } - case 'ServiceRegistry': { - if (chainConfig) { - throw new Error('ServiceRegistry does not support chainName option'); - } - + case CONTRACT_NAME_SERVICE_REGISTRY: { return makeServiceRegistryInstantiateMsg(contractConfig); } - case 'Multisig': { - if (chainConfig) { - throw new Error('Multisig does not support chainName option'); - } - + case CONTRACT_NAME_MULTISIG: { return makeMultisigInstantiateMsg(contractConfig, contracts); } - case 'Rewards': { - if (chainConfig) { - throw new Error('Rewards does not support chainName option'); - } - + case CONTRACT_NAME_REWARDS: { return makeRewardsInstantiateMsg(contractConfig); } - case 'Router': { - if (chainConfig) { - throw new Error('Router does not support chainName option'); - } - + case CONTRACT_NAME_ROUTER: { return makeRouterInstantiateMsg(contractConfig, contracts); } - case 'VotingVerifier': { - if (!chainConfig) { - throw new Error('VotingVerifier requires chainName option'); - } - + case CONTRACT_NAME_VOTING_VERIFIER: { return makeVotingVerifierInstantiateMsg(contractConfig, contracts, chainConfig); } - case 'Gateway': { - if (!chainConfig) { - throw new Error('Gateway requires chainName option'); - } - + case CONTRACT_NAME_GATEWAY: { return makeGatewayInstantiateMsg(contracts, chainConfig); } - case 'MultisigProver': { - if (!chainConfig) { - throw new Error('MultisigProver requires chainName option'); - } - + case CONTRACT_NAME_MULTISIG_PROVER: { return makeMultisigProverInstantiateMsg(config, chainName); } - case 'AxelarnetGateway': { - if (chainConfig) { - throw new Error('AxelarnetGateway does not support chainName option'); - } - + case CONTRACT_NAME_AXELARNET_GATEWAY: { return makeAxelarnetGatewayInstantiateMsg(contractConfig, config); } - case 'InterchainTokenService': { + case CONTRACT_NAME_INTERCHAIN_TOKEN_SERVICE: { return makeInterchainTokenServiceInstantiateMsg(config, contractConfig); } } @@ -847,6 +837,9 @@ const submitProposal = async (client, wallet, config, options, content) => { }; module.exports = { + CONTRACT_SCOPE_CHAIN, + CONTRACT_SCOPE_GLOBAL, + CONTRACTS_SCOPES, governanceAddress, prepareWallet, prepareClient, From 96960a8025f272ac34c2a791b7fc6ec65bbf1ff9 Mon Sep 17 00:00:00 2001 From: Edwin Guajardo Date: Mon, 16 Dec 2024 18:45:44 -0600 Subject: [PATCH 3/4] refactor contract instantiation --- cosmwasm/cli-utils.js | 15 +- cosmwasm/deploy-contract.js | 4 +- cosmwasm/submit-proposal.js | 10 +- cosmwasm/utils.js | 294 +++++++++++++++++------------------- 4 files changed, 157 insertions(+), 166 deletions(-) diff --git a/cosmwasm/cli-utils.js b/cosmwasm/cli-utils.js index 2e93354e..446946d2 100644 --- a/cosmwasm/cli-utils.js +++ b/cosmwasm/cli-utils.js @@ -3,7 +3,7 @@ require('dotenv').config(); const { isNumber, addEnvOption } = require('../common'); -const { CONTRACT_SCOPE_CHAIN, CONTRACT_SCOPE_GLOBAL, CONTRACTS_SCOPES, governanceAddress } = require('./utils'); +const { CONTRACT_SCOPE_CHAIN, CONTRACT_SCOPE_GLOBAL, CONTRACTS, governanceAddress } = require('./utils'); const { Option, InvalidArgumentError } = require('commander'); @@ -86,10 +86,19 @@ const addContractOptions = (program) => { program.hook('preAction', (command) => { const chainName = command.opts().chainName; const contractName = command.opts().contractName; - const scope = CONTRACTS_SCOPES[contractName]; + + if (!CONTRACTS[contractName]) { + throw new Error(`contract ${contractName} is not supported`); + } + + if (!CONTRACTS[contractName].makeInstantiateMsg) { + throw new Error(`makeInstantiateMsg function for contract ${contractName} is not defined`); + } + + const scope = CONTRACTS[contractName].scope; if (!scope) { - throw new Error(`Scope of contract ${contractName} is not defined`); + throw new Error(`scope of contract ${contractName} is not defined`); } if (scope === CONTRACT_SCOPE_CHAIN && !chainName) { diff --git a/cosmwasm/deploy-contract.js b/cosmwasm/deploy-contract.js index 486e7f12..e2050ffa 100644 --- a/cosmwasm/deploy-contract.js +++ b/cosmwasm/deploy-contract.js @@ -7,6 +7,7 @@ const { instantiate2Address } = require('@cosmjs/cosmwasm-stargate'); const { printInfo, loadConfig, saveConfig, prompt } = require('../common'); const { + CONTRACTS, prepareWallet, prepareClient, fromHex, @@ -16,7 +17,6 @@ const { updateCodeId, uploadContract, instantiateContract, - makeInstantiateMsg, } = require('./utils'); const { Command, Option } = require('commander'); @@ -66,7 +66,7 @@ const instantiate = async (client, wallet, config, options) => { await updateCodeId(client, config, options); - const initMsg = makeInstantiateMsg(contractName, chainName, config); + const initMsg = CONTRACTS[contractName].makeInstantiateMsg(config, options, contractConfig); const contractAddress = await instantiateContract(client, wallet, initMsg, config, options); contractConfig.address = contractAddress; diff --git a/cosmwasm/submit-proposal.js b/cosmwasm/submit-proposal.js index 92c29a15..441b86d5 100644 --- a/cosmwasm/submit-proposal.js +++ b/cosmwasm/submit-proposal.js @@ -7,6 +7,7 @@ const { createHash } = require('crypto'); const { instantiate2Address } = require('@cosmjs/cosmwasm-stargate'); const { + CONTRACTS, prepareWallet, prepareClient, fromHex, @@ -26,7 +27,6 @@ const { encodeParameterChangeProposal, encodeMigrateContractProposal, submitProposal, - makeInstantiateMsg, } = require('./utils'); const { saveConfig, loadConfig, printInfo, prompt, getChainConfig, getItsEdgeContract } = require('../common'); const { @@ -94,14 +94,14 @@ const storeCode = async (client, wallet, config, options) => { }; const storeInstantiate = async (client, wallet, config, options) => { - const { contractName, instantiate2, chainName } = options; + const { contractName, instantiate2 } = options; const { contractConfig, contractBaseConfig } = getAmplifierContractConfig(config, options); if (instantiate2) { throw new Error('instantiate2 not supported for storeInstantiate'); } - const initMsg = makeInstantiateMsg(contractName, chainName, config); + const initMsg = CONTRACTS[contractName].makeInstantiateMsg(config, options, contractConfig); const proposal = encodeStoreInstantiateProposal(config, options, initMsg); if (!confirmProposalSubmission(options, proposal, StoreAndInstantiateContractProposal)) { @@ -115,7 +115,7 @@ const storeInstantiate = async (client, wallet, config, options) => { }; const instantiate = async (client, wallet, config, options) => { - const { contractName, instantiate2, predictOnly, chainName } = options; + const { contractName, instantiate2, predictOnly } = options; const { contractConfig } = getAmplifierContractConfig(config, options); await updateCodeId(client, config, options); @@ -129,7 +129,7 @@ const instantiate = async (client, wallet, config, options) => { return; } - const initMsg = makeInstantiateMsg(contractName, chainName, config); + const initMsg = CONTRACTS[contractName].makeInstantiateMsg(config, options, contractConfig); let proposal; let proposalType; diff --git a/cosmwasm/utils.js b/cosmwasm/utils.js index 7048f48c..883a6e9f 100644 --- a/cosmwasm/utils.js +++ b/cosmwasm/utils.js @@ -22,7 +22,6 @@ const { printInfo, isString, isStringArray, - isStringLowercase, isKeccak256Hash, isNumber, toBigNumberString, @@ -36,31 +35,8 @@ const { normalizeBech32 } = require('@cosmjs/encoding'); const DEFAULT_MAX_UINT_BITS_EVM = 256; const DEFAULT_MAX_DECIMALS_WHEN_TRUNCATING_EVM = 255; -const CONTRACT_NAME_COORDINATOR = 'Coordinator'; -const CONTRACT_NAME_SERVICE_REGISTRY = 'ServiceRegistry'; -const CONTRACT_NAME_MULTISIG = 'Multisig'; -const CONTRACT_NAME_REWARDS = 'Rewards'; -const CONTRACT_NAME_ROUTER = 'Router'; -const CONTRACT_NAME_VOTING_VERIFIER = 'VotingVerifier'; -const CONTRACT_NAME_GATEWAY = 'Gateway'; -const CONTRACT_NAME_MULTISIG_PROVER = 'MultisigProver'; -const CONTRACT_NAME_AXELARNET_GATEWAY = 'AxelarnetGateway'; -const CONTRACT_NAME_INTERCHAIN_TOKEN_SERVICE = 'InterchainTokenService'; - const CONTRACT_SCOPE_GLOBAL = 'global'; const CONTRACT_SCOPE_CHAIN = 'chain'; -const CONTRACTS_SCOPES = { - [CONTRACT_NAME_COORDINATOR]: CONTRACT_SCOPE_GLOBAL, - [CONTRACT_NAME_SERVICE_REGISTRY]: CONTRACT_SCOPE_GLOBAL, - [CONTRACT_NAME_MULTISIG]: CONTRACT_SCOPE_GLOBAL, - [CONTRACT_NAME_REWARDS]: CONTRACT_SCOPE_GLOBAL, - [CONTRACT_NAME_ROUTER]: CONTRACT_SCOPE_GLOBAL, - [CONTRACT_NAME_VOTING_VERIFIER]: CONTRACT_SCOPE_CHAIN, - [CONTRACT_NAME_GATEWAY]: CONTRACT_SCOPE_CHAIN, - [CONTRACT_NAME_MULTISIG_PROVER]: CONTRACT_SCOPE_CHAIN, - [CONTRACT_NAME_AXELARNET_GATEWAY]: CONTRACT_SCOPE_GLOBAL, - [CONTRACT_NAME_INTERCHAIN_TOKEN_SERVICE]: CONTRACT_SCOPE_GLOBAL, -}; const governanceAddress = 'axelar10d07y265gmmuvt4z0w9aw880jnsr700j7v9daj'; @@ -191,7 +167,15 @@ const validateAddress = (address) => { return isString(address) && isValidCosmosAddress(address); }; -const makeCoordinatorInstantiateMsg = ({ governanceAddress }, { ServiceRegistry: { address: registryAddress } }) => { +const makeCoordinatorInstantiateMsg = (config, _options, contractConfig) => { + const { + axelar: { contracts }, + } = config; + const { + ServiceRegistry: { address: registryAddress }, + } = contracts; + const { governanceAddress } = contractConfig; + if (!validateAddress(governanceAddress)) { throw new Error('Missing or invalid Coordinator.governanceAddress in axelar info'); } @@ -203,7 +187,9 @@ const makeCoordinatorInstantiateMsg = ({ governanceAddress }, { ServiceRegistry: return { governance_address: governanceAddress, service_registry: registryAddress }; }; -const makeServiceRegistryInstantiateMsg = ({ governanceAccount }) => { +const makeServiceRegistryInstantiateMsg = (_config, _options, contractConfig) => { + const { governanceAccount } = contractConfig; + if (!validateAddress(governanceAccount)) { throw new Error('Missing or invalid ServiceRegistry.governanceAccount in axelar info'); } @@ -211,7 +197,15 @@ const makeServiceRegistryInstantiateMsg = ({ governanceAccount }) => { return { governance_account: governanceAccount }; }; -const makeMultisigInstantiateMsg = ({ adminAddress, governanceAddress, blockExpiry }, { Rewards: { address: rewardsAddress } }) => { +const makeMultisigInstantiateMsg = (config, _options, contractConfig) => { + const { + axelar: { contracts }, + } = config; + const { + Rewards: { address: rewardsAddress }, + } = contracts; + const { adminAddress, governanceAddress, blockExpiry } = contractConfig; + if (!validateAddress(adminAddress)) { throw new Error('Missing or invalid Multisig.adminAddress in axelar info'); } @@ -236,7 +230,9 @@ const makeMultisigInstantiateMsg = ({ adminAddress, governanceAddress, blockExpi }; }; -const makeRewardsInstantiateMsg = ({ governanceAddress, rewardsDenom }) => { +const makeRewardsInstantiateMsg = (_config, _options, contractConfig) => { + const { governanceAddress, rewardsDenom } = contractConfig; + if (!validateAddress(governanceAddress)) { throw new Error('Missing or invalid Rewards.governanceAddress in axelar info'); } @@ -248,7 +244,15 @@ const makeRewardsInstantiateMsg = ({ governanceAddress, rewardsDenom }) => { return { governance_address: governanceAddress, rewards_denom: rewardsDenom }; }; -const makeRouterInstantiateMsg = ({ adminAddress, governanceAddress }, { AxelarnetGateway: { address: axelarnetGateway } }) => { +const makeRouterInstantiateMsg = (config, _options, contractConfig) => { + const { + axelar: { contracts }, + } = config; + const { + AxelarnetGateway: { address: axelarnetGateway }, + } = contracts; + const { adminAddress, governanceAddress } = contractConfig; + if (!validateAddress(adminAddress)) { throw new Error('Missing or invalid Router.adminAddress in axelar info'); } @@ -264,28 +268,26 @@ const makeRouterInstantiateMsg = ({ adminAddress, governanceAddress }, { Axelarn return { admin_address: adminAddress, governance_address: governanceAddress, axelarnet_gateway: axelarnetGateway }; }; -const makeVotingVerifierInstantiateMsg = ( - contractConfig, - { ServiceRegistry: { address: serviceRegistryAddress }, Rewards: { address: rewardsAddress } }, - { axelarId }, -) => { +const makeVotingVerifierInstantiateMsg = (config, options, contractConfig) => { + const { chainName } = options; const { - [axelarId]: { - governanceAddress, - serviceName, - sourceGatewayAddress, - votingThreshold, - blockExpiry, - confirmationHeight, - msgIdFormat, - addressFormat, - }, + axelar: { contracts }, + } = config; + const { + ServiceRegistry: { address: serviceRegistryAddress }, + Rewards: { address: rewardsAddress }, + } = contracts; + const { + governanceAddress, + serviceName, + sourceGatewayAddress, + votingThreshold, + blockExpiry, + confirmationHeight, + msgIdFormat, + addressFormat, } = contractConfig; - if (!isStringLowercase(axelarId)) { - throw new Error('Missing or invalid axelar ID'); - } - if (!validateAddress(serviceRegistryAddress)) { throw new Error('Missing or invalid ServiceRegistry.address in axelar info'); } @@ -295,35 +297,35 @@ const makeVotingVerifierInstantiateMsg = ( } if (!validateAddress(governanceAddress)) { - throw new Error(`Missing or invalid VotingVerifier[${axelarId}].governanceAddress in axelar info`); + throw new Error(`Missing or invalid VotingVerifier[${chainName}].governanceAddress in axelar info`); } if (!isString(serviceName)) { - throw new Error(`Missing or invalid VotingVerifier[${axelarId}].serviceName in axelar info`); + throw new Error(`Missing or invalid VotingVerifier[${chainName}].serviceName in axelar info`); } if (!isString(sourceGatewayAddress)) { - throw new Error(`Missing or invalid VotingVerifier[${axelarId}].sourceGatewayAddress in axelar info`); + throw new Error(`Missing or invalid VotingVerifier[${chainName}].sourceGatewayAddress in axelar info`); } if (!isStringArray(votingThreshold)) { - throw new Error(`Missing or invalid VotingVerifier[${axelarId}].votingThreshold in axelar info`); + throw new Error(`Missing or invalid VotingVerifier[${chainName}].votingThreshold in axelar info`); } if (!isNumber(blockExpiry)) { - throw new Error(`Missing or invalid VotingVerifier[${axelarId}].blockExpiry in axelar info`); + throw new Error(`Missing or invalid VotingVerifier[${chainName}].blockExpiry in axelar info`); } if (!isNumber(confirmationHeight)) { - throw new Error(`Missing or invalid VotingVerifier[${axelarId}].confirmationHeight in axelar info`); + throw new Error(`Missing or invalid VotingVerifier[${chainName}].confirmationHeight in axelar info`); } if (!isString(msgIdFormat)) { - throw new Error(`Missing or invalid VotingVerifier[${axelarId}].msgIdFormat in axelar info`); + throw new Error(`Missing or invalid VotingVerifier[${chainName}].msgIdFormat in axelar info`); } if (!isString(addressFormat)) { - throw new Error(`Missing or invalid VotingVerifier[${axelarId}].addressFormat in axelar info`); + throw new Error(`Missing or invalid VotingVerifier[${chainName}].addressFormat in axelar info`); } return { @@ -335,65 +337,55 @@ const makeVotingVerifierInstantiateMsg = ( voting_threshold: votingThreshold, block_expiry: toBigNumberString(blockExpiry), confirmation_height: confirmationHeight, - source_chain: axelarId, + source_chain: chainName, msg_id_format: msgIdFormat, address_format: addressFormat, }; }; -const makeGatewayInstantiateMsg = ({ Router: { address: routerAddress }, VotingVerifier }, { axelarId: chainId }) => { +const makeGatewayInstantiateMsg = (config, options, _contractConfig) => { + const { chainName } = options; const { - [chainId]: { address: verifierAddress }, - } = VotingVerifier; + axelar: { + contracts: { + Router: { address: routerAddress }, + VotingVerifier: { + [chainName]: { address: verifierAddress }, + }, + }, + }, + } = config; if (!validateAddress(routerAddress)) { throw new Error('Missing or invalid Router.address in axelar info'); } if (!validateAddress(verifierAddress)) { - throw new Error(`Missing or invalid VotingVerifier[${chainId}].address in axelar info`); + throw new Error(`Missing or invalid VotingVerifier[${chainName}].address in axelar info`); } return { router_address: routerAddress, verifier_address: verifierAddress }; }; -const makeMultisigProverInstantiateMsg = (config, chainName) => { +const makeMultisigProverInstantiateMsg = (config, options, contractConfig) => { + const { chainName } = options; const { axelar: { contracts, chainId: axelarChainId }, } = config; - const chainConfig = getChainConfig(config, chainName); - - const { axelarId } = chainConfig; - const { Router: { address: routerAddress }, Coordinator: { address: coordinatorAddress }, Multisig: { address: multisigAddress }, ServiceRegistry: { address: serviceRegistryAddress }, VotingVerifier: { - [axelarId]: { address: verifierAddress }, + [chainName]: { address: verifierAddress }, }, Gateway: { - [axelarId]: { address: gatewayAddress }, + [chainName]: { address: gatewayAddress }, }, - MultisigProver: contractConfig, } = contracts; - const { - [axelarId]: { - adminAddress, - governanceAddress, - domainSeparator, - signingThreshold, - serviceName, - verifierSetDiffThreshold, - encoder, - keyType, - }, - } = contractConfig; - - if (!isStringLowercase(axelarId)) { - throw new Error(`Missing or invalid axelar ID for chain ${chainName}`); - } + const { adminAddress, governanceAddress, domainSeparator, signingThreshold, serviceName, verifierSetDiffThreshold, encoder, keyType } = + contractConfig; if (!validateAddress(routerAddress)) { throw new Error('Missing or invalid Router.address in axelar info'); @@ -403,19 +395,19 @@ const makeMultisigProverInstantiateMsg = (config, chainName) => { throw new Error(`Missing or invalid chain ID`); } - const separator = domainSeparator || calculateDomainSeparator(axelarId, routerAddress, axelarChainId); - contractConfig[axelarId].domainSeparator = separator; + const separator = domainSeparator || calculateDomainSeparator(chainName, routerAddress, axelarChainId); + contractConfig[chainName].domainSeparator = separator; if (!validateAddress(adminAddress)) { - throw new Error(`Missing or invalid MultisigProver[${axelarId}].adminAddress in axelar info`); + throw new Error(`Missing or invalid MultisigProver[${chainName}].adminAddress in axelar info`); } if (!validateAddress(governanceAddress)) { - throw new Error(`Missing or invalid MultisigProver[${axelarId}].governanceAddress in axelar info`); + throw new Error(`Missing or invalid MultisigProver[${chainName}].governanceAddress in axelar info`); } if (!validateAddress(gatewayAddress)) { - throw new Error(`Missing or invalid Gateway[${axelarId}].address in axelar info`); + throw new Error(`Missing or invalid Gateway[${chainName}].address in axelar info`); } if (!validateAddress(coordinatorAddress)) { @@ -431,31 +423,31 @@ const makeMultisigProverInstantiateMsg = (config, chainName) => { } if (!validateAddress(verifierAddress)) { - throw new Error(`Missing or invalid VotingVerifier[${axelarId}].address in axelar info`); + throw new Error(`Missing or invalid VotingVerifier[${chainName}].address in axelar info`); } if (!isKeccak256Hash(separator)) { - throw new Error(`Invalid MultisigProver[${axelarId}].domainSeparator in axelar info`); + throw new Error(`Invalid MultisigProver[${chainName}].domainSeparator in axelar info`); } if (!isStringArray(signingThreshold)) { - throw new Error(`Missing or invalid MultisigProver[${axelarId}].signingThreshold in axelar info`); + throw new Error(`Missing or invalid MultisigProver[${chainName}].signingThreshold in axelar info`); } if (!isString(serviceName)) { - throw new Error(`Missing or invalid MultisigProver[${axelarId}].serviceName in axelar info`); + throw new Error(`Missing or invalid MultisigProver[${chainName}].serviceName in axelar info`); } if (!isNumber(verifierSetDiffThreshold)) { - throw new Error(`Missing or invalid MultisigProver[${axelarId}].verifierSetDiffThreshold in axelar info`); + throw new Error(`Missing or invalid MultisigProver[${chainName}].verifierSetDiffThreshold in axelar info`); } if (!isString(encoder)) { - throw new Error(`Missing or invalid MultisigProver[${axelarId}].encoder in axelar info`); + throw new Error(`Missing or invalid MultisigProver[${chainName}].encoder in axelar info`); } if (!isString(keyType)) { - throw new Error(`Missing or invalid MultisigProver[${axelarId}].keyType in axelar info`); + throw new Error(`Missing or invalid MultisigProver[${chainName}].keyType in axelar info`); } return { @@ -469,18 +461,18 @@ const makeMultisigProverInstantiateMsg = (config, chainName) => { domain_separator: separator.replace('0x', ''), signing_threshold: signingThreshold, service_name: serviceName, - chain_name: axelarId, + chain_name: chainName, verifier_set_diff_threshold: verifierSetDiffThreshold, encoder, key_type: keyType, }; }; -const makeAxelarnetGatewayInstantiateMsg = ({ nexus }, config) => { +const makeAxelarnetGatewayInstantiateMsg = (config, _options, contractConfig) => { + const { nexus } = contractConfig; const { axelar: { contracts, axelarId }, } = config; - const { Router: { address: routerAddress }, } = contracts; @@ -500,7 +492,8 @@ const makeAxelarnetGatewayInstantiateMsg = ({ nexus }, config) => { }; }; -const makeInterchainTokenServiceInstantiateMsg = (config, { adminAddress, governanceAddress }) => { +const makeInterchainTokenServiceInstantiateMsg = (config, _options, contractConfig) => { + const { adminAddress, governanceAddress } = contractConfig; const { axelar: { contracts }, } = config; @@ -520,59 +513,6 @@ const makeInterchainTokenServiceInstantiateMsg = (config, { adminAddress, govern }; }; -const makeInstantiateMsg = (contractName, chainName, config) => { - const { - axelar: { contracts }, - } = config; - const chainConfig = getChainConfig(config, chainName); - - const { [contractName]: contractConfig } = contracts; - - switch (contractName) { - case CONTRACT_NAME_COORDINATOR: { - return makeCoordinatorInstantiateMsg(contractConfig, contracts); - } - - case CONTRACT_NAME_SERVICE_REGISTRY: { - return makeServiceRegistryInstantiateMsg(contractConfig); - } - - case CONTRACT_NAME_MULTISIG: { - return makeMultisigInstantiateMsg(contractConfig, contracts); - } - - case CONTRACT_NAME_REWARDS: { - return makeRewardsInstantiateMsg(contractConfig); - } - - case CONTRACT_NAME_ROUTER: { - return makeRouterInstantiateMsg(contractConfig, contracts); - } - - case CONTRACT_NAME_VOTING_VERIFIER: { - return makeVotingVerifierInstantiateMsg(contractConfig, contracts, chainConfig); - } - - case CONTRACT_NAME_GATEWAY: { - return makeGatewayInstantiateMsg(contracts, chainConfig); - } - - case CONTRACT_NAME_MULTISIG_PROVER: { - return makeMultisigProverInstantiateMsg(config, chainName); - } - - case CONTRACT_NAME_AXELARNET_GATEWAY: { - return makeAxelarnetGatewayInstantiateMsg(contractConfig, config); - } - - case CONTRACT_NAME_INTERCHAIN_TOKEN_SERVICE: { - return makeInterchainTokenServiceInstantiateMsg(config, contractConfig); - } - } - - throw new Error(`${contractName} is not supported.`); -}; - const fetchCodeIdFromCodeHash = async (client, contractBaseConfig) => { if (!contractBaseConfig.storeCodeProposalCodeHash) { throw new Error('storeCodeProposalCodeHash not found in contract config'); @@ -836,10 +776,53 @@ const submitProposal = async (client, wallet, config, options, content) => { return events.find(({ type }) => type === 'submit_proposal').attributes.find(({ key }) => key === 'proposal_id').value; }; +const CONTRACTS = { + Coordinator: { + scope: CONTRACT_SCOPE_GLOBAL, + makeInstantiateMsg: makeCoordinatorInstantiateMsg, + }, + ServiceRegistry: { + scope: CONTRACT_SCOPE_GLOBAL, + makeInstantiateMsg: makeServiceRegistryInstantiateMsg, + }, + Multisig: { + scope: CONTRACT_SCOPE_GLOBAL, + makeInstantiateMsg: makeMultisigInstantiateMsg, + }, + Rewards: { + scope: CONTRACT_SCOPE_GLOBAL, + makeInstantiateMsg: makeRewardsInstantiateMsg, + }, + Router: { + scope: CONTRACT_SCOPE_GLOBAL, + makeInstantiateMsg: makeRouterInstantiateMsg, + }, + VotingVerifier: { + scope: CONTRACT_SCOPE_CHAIN, + makeInstantiateMsg: makeVotingVerifierInstantiateMsg, + }, + Gateway: { + scope: CONTRACT_SCOPE_CHAIN, + makeInstantiateMsg: makeGatewayInstantiateMsg, + }, + MultisigProver: { + scope: CONTRACT_SCOPE_CHAIN, + makeInstantiateMsg: makeMultisigProverInstantiateMsg, + }, + AxelarnetGateway: { + scope: CONTRACT_SCOPE_GLOBAL, + makeInstantiateMsg: makeAxelarnetGatewayInstantiateMsg, + }, + InterchainTokenService: { + scope: CONTRACT_SCOPE_GLOBAL, + makeInstantiateMsg: makeInterchainTokenServiceInstantiateMsg, + }, +}; + module.exports = { CONTRACT_SCOPE_CHAIN, CONTRACT_SCOPE_GLOBAL, - CONTRACTS_SCOPES, + CONTRACTS, governanceAddress, prepareWallet, prepareClient, @@ -853,7 +836,6 @@ module.exports = { updateCodeId, uploadContract, instantiateContract, - makeInstantiateMsg, fetchCodeIdFromCodeHash, getChainTruncationParams, decodeProposalAttributes, From 4e25cb02c8110bf6188682108ca0646cc8afa9e9 Mon Sep 17 00:00:00 2001 From: Edwin Guajardo Date: Tue, 17 Dec 2024 14:39:12 -0600 Subject: [PATCH 4/4] fix prover instantiation --- cosmwasm/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cosmwasm/utils.js b/cosmwasm/utils.js index 883a6e9f..787feb39 100644 --- a/cosmwasm/utils.js +++ b/cosmwasm/utils.js @@ -396,7 +396,7 @@ const makeMultisigProverInstantiateMsg = (config, options, contractConfig) => { } const separator = domainSeparator || calculateDomainSeparator(chainName, routerAddress, axelarChainId); - contractConfig[chainName].domainSeparator = separator; + contractConfig.domainSeparator = separator; if (!validateAddress(adminAddress)) { throw new Error(`Missing or invalid MultisigProver[${chainName}].adminAddress in axelar info`);