Skip to content

Commit

Permalink
add chainName requirement validation
Browse files Browse the repository at this point in the history
  • Loading branch information
eguajardo committed Dec 15, 2024
1 parent e7e933f commit 9a22f75
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 63 deletions.
9 changes: 1 addition & 8 deletions axelar-chains-config/info/devnet-amplifier.json
Original file line number Diff line number Diff line change
Expand Up @@ -839,10 +839,6 @@
"codeId": 844,
"address": "axelar1wvms3cy5hxrgl7uxhkz7yth4qzqum6aaccwkmvafq8z0mgdfxr8qrnvw0k",
"nexus": "axelar17h8uk4ct0mdv9mgkuxszt4gp2htpfr08mge20r",
"axelar": {
"storeInstantiateProposalId": "59",
"codeId": 845
},
"storeCodeProposalCodeHash": "c7286d0f59276b794641bdfbb4f96fafcee3553b67f3397d662a4683968f525b",
"storeCodeProposalId": "60",
"lastUploadedCodeId": 845
Expand All @@ -852,10 +848,7 @@
"governanceAddress": "axelar1zlr7e5qf3sz7yf890rkh9tcnu87234k6k7ytd9",
"codeId": 843,
"address": "axelar157hl7gpuknjmhtac2qnphuazv2yerfagva7lsu9vuj2pgn32z22qa26dk4",
"axelar": {
"codeId": 843,
"instantiateProposalId": "61"
},
"instantiateProposalId": "61",
"sui": {
"maxUintBits": 64,
"maxDecimalsWhenTruncating": 8
Expand Down
9 changes: 1 addition & 8 deletions axelar-chains-config/info/stagenet.json
Original file line number Diff line number Diff line change
Expand Up @@ -1851,10 +1851,7 @@
"storeCodeProposalCodeHash": "b60d0d227c7a400a0fcc80ed52f0e6688e5da6db676a61ed8b6942823294031d",
"governanceAddress": "axelar10d07y265gmmuvt4z0w9aw880jnsr700j7v9daj",
"adminAddress": "axelar12qvsvse32cjyw60ztysd3v655aj5urqeup82ky",
"axelar": {
"codeId": 17,
"address": "axelar1ph8qufmsh556e40uk0ceaufc06nwhnw0ksgdqqk6ldszxchh8llq8x52dk"
},
"codeId": 17,
"address": "axelar1ph8qufmsh556e40uk0ceaufc06nwhnw0ksgdqqk6ldszxchh8llq8x52dk",
"lastUploadedCodeId": 17
},
Expand All @@ -1864,10 +1861,6 @@
"nexus": "axelar17h8uk4ct0mdv9mgkuxszt4gp2htpfr08mge20r",
"address": "axelar1s9amtxejrdlsunwdf0cclhjtezdp6wmurxxnh45gfvtpa2jrsusqv934n6",
"codeId": 20,
"axelar": {
"codeId": 20,
"address": "axelar1s9amtxejrdlsunwdf0cclhjtezdp6wmurxxnh45gfvtpa2jrsusqv934n6"
},
"lastUploadedCodeId": 20
}
},
Expand Down
19 changes: 18 additions & 1 deletion cosmwasm/cli-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -83,6 +83,23 @@ const addAmplifierOptions = (program, options) => {
const addContractOptions = (program) => {
program.addOption(new Option('-c, --contractName <contractName>', 'contract name').makeOptionMandatory(true));
program.addOption(new Option('-n, --chainName <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) => {
Expand Down
85 changes: 39 additions & 46 deletions cosmwasm/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 9a22f75

Please sign in to comment.