From 00a3fa6d3bb92907b3c3f94f616d1421dcf04a6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Sousa?= Date: Tue, 27 Aug 2024 19:31:51 +0100 Subject: [PATCH 1/4] add support for deploying the axelarnet-gateway contract --- cosmwasm/utils.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/cosmwasm/utils.js b/cosmwasm/utils.js index 33c5239d..c9d28263 100644 --- a/cosmwasm/utils.js +++ b/cosmwasm/utils.js @@ -420,6 +420,28 @@ const makeMultisigProverInstantiateMsg = (config, chainName) => { }; }; +const makeAxelarnetGatewayInstantiateMsg = (config, chainName) => { + const { + axelar: { contracts }, + } = config; + const chainConfig = getChainConfig(config, chainName); + + const { axelarId: chainId } = chainConfig; + + const { + Router: { address: routerAddress }, + } = contracts; + + if (!validateAddress(routerAddress)) { + throw new Error('Missing or invalid Router.address in axelar info'); + } + + return { + router_address: routerAddress, + chain_name: chainId, + }; +}; + const makeInstantiateMsg = (contractName, chainName, config) => { const { axelar: { contracts }, @@ -500,6 +522,14 @@ const makeInstantiateMsg = (contractName, chainName, config) => { return makeMultisigProverInstantiateMsg(config, chainName); } + + case 'AxelarnetGateway': { + if (!chainConfig) { + throw new Error('AxelarnetGateway requires chainNames option'); + } + + return makeAxelarnetGatewayInstantiateMsg(config, chainName); + } } throw new Error(`${contractName} is not supported.`); From bfe21572c34f1e1b262974fb2050bbedf4f82356 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Sousa?= Date: Tue, 27 Aug 2024 20:21:45 +0100 Subject: [PATCH 2/4] cleanup --- cosmwasm/utils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cosmwasm/utils.js b/cosmwasm/utils.js index c9d28263..04c79d41 100644 --- a/cosmwasm/utils.js +++ b/cosmwasm/utils.js @@ -426,7 +426,7 @@ const makeAxelarnetGatewayInstantiateMsg = (config, chainName) => { } = config; const chainConfig = getChainConfig(config, chainName); - const { axelarId: chainId } = chainConfig; + const { axelarId } = chainConfig; const { Router: { address: routerAddress }, @@ -438,7 +438,7 @@ const makeAxelarnetGatewayInstantiateMsg = (config, chainName) => { return { router_address: routerAddress, - chain_name: chainId, + chain_name: axelarId.toLowerCase(), }; }; From 23f1025f490dad54808dd35b0b52a73a017abea8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Sousa?= Date: Tue, 27 Aug 2024 20:42:05 +0100 Subject: [PATCH 3/4] refactor --- common/utils.js | 11 +++++--- cosmwasm/utils.js | 67 +++++++++++++++++++++++++++-------------------- 2 files changed, 46 insertions(+), 32 deletions(-) diff --git a/common/utils.js b/common/utils.js index d3451c0a..e4ab84de 100644 --- a/common/utils.js +++ b/common/utils.js @@ -57,12 +57,16 @@ function printLog(log) { console.log(JSON.stringify({ log }, null, 2)); } +const isString = (arg) => { + return typeof arg === 'string'; +}; + const isNonEmptyString = (arg) => { - return typeof arg === 'string' && arg !== ''; + return isString(arg) && arg !== ''; }; -const isString = (arg) => { - return typeof arg === 'string'; +const isStringLowercase = (arg) => { + return isString(arg) && arg === arg.toLowerCase(); }; const isStringArray = (arr) => Array.isArray(arr) && arr.every(isString); @@ -440,6 +444,7 @@ module.exports = { isNonEmptyString, isString, isStringArray, + isStringLowercase, isNumber, isValidNumber, isValidDecimal, diff --git a/cosmwasm/utils.js b/cosmwasm/utils.js index 04c79d41..3fa94f88 100644 --- a/cosmwasm/utils.js +++ b/cosmwasm/utils.js @@ -19,6 +19,7 @@ const { AccessType } = require('cosmjs-types/cosmwasm/wasm/v1/types'); const { isString, isStringArray, + isStringLowercase, isKeccak256Hash, isNumber, toBigNumberString, @@ -215,10 +216,10 @@ const makeNexusGatewayInstantiateMsg = ({ nexus }, { Router: { address: router } const makeVotingVerifierInstantiateMsg = ( contractConfig, { ServiceRegistry: { address: serviceRegistryAddress }, Rewards: { address: rewardsAddress } }, - { axelarId: chainId }, + { axelarId }, ) => { const { - [chainId]: { + [axelarId]: { governanceAddress, serviceName, sourceGatewayAddress, @@ -230,6 +231,10 @@ const makeVotingVerifierInstantiateMsg = ( }, } = 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'); } @@ -239,35 +244,35 @@ const makeVotingVerifierInstantiateMsg = ( } if (!validateAddress(governanceAddress)) { - throw new Error(`Missing or invalid VotingVerifier[${chainId}].governanceAddress in axelar info`); + throw new Error(`Missing or invalid VotingVerifier[${axelarId}].governanceAddress in axelar info`); } if (!isString(serviceName)) { - throw new Error(`Missing or invalid VotingVerifier[${chainId}].serviceName in axelar info`); + throw new Error(`Missing or invalid VotingVerifier[${axelarId}].serviceName in axelar info`); } if (!isString(sourceGatewayAddress)) { - throw new Error(`Missing or invalid VotingVerifier[${chainId}].sourceGatewayAddress in axelar info`); + throw new Error(`Missing or invalid VotingVerifier[${axelarId}].sourceGatewayAddress in axelar info`); } if (!isStringArray(votingThreshold)) { - throw new Error(`Missing or invalid VotingVerifier[${chainId}].votingThreshold in axelar info`); + throw new Error(`Missing or invalid VotingVerifier[${axelarId}].votingThreshold in axelar info`); } if (!isNumber(blockExpiry)) { - throw new Error(`Missing or invalid VotingVerifier[${chainId}].blockExpiry in axelar info`); + throw new Error(`Missing or invalid VotingVerifier[${axelarId}].blockExpiry in axelar info`); } if (!isNumber(confirmationHeight)) { - throw new Error(`Missing or invalid VotingVerifier[${chainId}].confirmationHeight in axelar info`); + throw new Error(`Missing or invalid VotingVerifier[${axelarId}].confirmationHeight in axelar info`); } if (!isString(msgIdFormat)) { - throw new Error(`Missing or invalid VotingVerifier[${chainId}].msgIdFormat in axelar info`); + throw new Error(`Missing or invalid VotingVerifier[${axelarId}].msgIdFormat in axelar info`); } if (!isString(addressFormat)) { - throw new Error(`Missing or invalid VotingVerifier[${chainId}].addressFormat in axelar info`); + throw new Error(`Missing or invalid VotingVerifier[${axelarId}].addressFormat in axelar info`); } return { @@ -279,7 +284,7 @@ const makeVotingVerifierInstantiateMsg = ( voting_threshold: votingThreshold, block_expiry: toBigNumberString(blockExpiry), confirmation_height: confirmationHeight, - source_chain: chainId, + source_chain: axelarId, msg_id_format: msgIdFormat, address_format: addressFormat, }; @@ -307,7 +312,7 @@ const makeMultisigProverInstantiateMsg = (config, chainName) => { } = config; const chainConfig = getChainConfig(config, chainName); - const { axelarId: chainId } = chainConfig; + const { axelarId } = chainConfig; const { Router: { address: routerAddress }, @@ -315,15 +320,15 @@ const makeMultisigProverInstantiateMsg = (config, chainName) => { Multisig: { address: multisigAddress }, ServiceRegistry: { address: serviceRegistryAddress }, VotingVerifier: { - [chainId]: { address: verifierAddress }, + [axelarId]: { address: verifierAddress }, }, Gateway: { - [chainId]: { address: gatewayAddress }, + [axelarId]: { address: gatewayAddress }, }, MultisigProver: contractConfig, } = contracts; const { - [chainId]: { + [axelarId]: { adminAddress, governanceAddress, domainSeparator, @@ -335,7 +340,7 @@ const makeMultisigProverInstantiateMsg = (config, chainName) => { }, } = contractConfig; - if (!isString(chainId)) { + if (!isStringLowercase(axelarId)) { throw new Error(`Missing or invalid axelar ID for chain ${chainName}`); } @@ -347,19 +352,19 @@ const makeMultisigProverInstantiateMsg = (config, chainName) => { throw new Error(`Missing or invalid chain ID`); } - const separator = domainSeparator || calculateDomainSeparator(chainId, routerAddress, axelarChainId); - contractConfig[chainId].domainSeparator = separator; + const separator = domainSeparator || calculateDomainSeparator(axelarId, routerAddress, axelarChainId); + contractConfig[axelarId].domainSeparator = separator; if (!validateAddress(adminAddress)) { - throw new Error(`Missing or invalid MultisigProver[${chainId}].adminAddress in axelar info`); + throw new Error(`Missing or invalid MultisigProver[${axelarId}].adminAddress in axelar info`); } if (!validateAddress(governanceAddress)) { - throw new Error(`Missing or invalid MultisigProver[${chainId}].governanceAddress in axelar info`); + throw new Error(`Missing or invalid MultisigProver[${axelarId}].governanceAddress in axelar info`); } if (!validateAddress(gatewayAddress)) { - throw new Error(`Missing or invalid Gateway[${chainId}].address in axelar info`); + throw new Error(`Missing or invalid Gateway[${axelarId}].address in axelar info`); } if (!validateAddress(coordinatorAddress)) { @@ -375,31 +380,31 @@ const makeMultisigProverInstantiateMsg = (config, chainName) => { } if (!validateAddress(verifierAddress)) { - throw new Error(`Missing or invalid VotingVerifier[${chainId}].address in axelar info`); + throw new Error(`Missing or invalid VotingVerifier[${axelarId}].address in axelar info`); } if (!isKeccak256Hash(separator)) { - throw new Error(`Invalid MultisigProver[${chainId}].domainSeparator in axelar info`); + throw new Error(`Invalid MultisigProver[${axelarId}].domainSeparator in axelar info`); } if (!isStringArray(signingThreshold)) { - throw new Error(`Missing or invalid MultisigProver[${chainId}].signingThreshold in axelar info`); + throw new Error(`Missing or invalid MultisigProver[${axelarId}].signingThreshold in axelar info`); } if (!isString(serviceName)) { - throw new Error(`Missing or invalid MultisigProver[${chainId}].serviceName in axelar info`); + throw new Error(`Missing or invalid MultisigProver[${axelarId}].serviceName in axelar info`); } if (!isNumber(verifierSetDiffThreshold)) { - throw new Error(`Missing or invalid MultisigProver[${chainId}].verifierSetDiffThreshold in axelar info`); + throw new Error(`Missing or invalid MultisigProver[${axelarId}].verifierSetDiffThreshold in axelar info`); } if (!isString(encoder)) { - throw new Error(`Missing or invalid MultisigProver[${chainId}].encoder in axelar info`); + throw new Error(`Missing or invalid MultisigProver[${axelarId}].encoder in axelar info`); } if (!isString(keyType)) { - throw new Error(`Missing or invalid MultisigProver[${chainId}].keyType in axelar info`); + throw new Error(`Missing or invalid MultisigProver[${axelarId}].keyType in axelar info`); } return { @@ -413,7 +418,7 @@ const makeMultisigProverInstantiateMsg = (config, chainName) => { domain_separator: separator.replace('0x', ''), signing_threshold: signingThreshold, service_name: serviceName, - chain_name: chainId, + chain_name: axelarId, verifier_set_diff_threshold: verifierSetDiffThreshold, encoder, key_type: keyType, @@ -432,6 +437,10 @@ const makeAxelarnetGatewayInstantiateMsg = (config, chainName) => { Router: { address: routerAddress }, } = contracts; + if (!isString(axelarId)) { + throw new Error(`Missing or invalid axelar ID for chain ${chainName}`); + } + if (!validateAddress(routerAddress)) { throw new Error('Missing or invalid Router.address in axelar info'); } From f126969adf5db9dec85212ce8545d230c7db198b Mon Sep 17 00:00:00 2001 From: jcs47 <11947034+jcs47@users.noreply.github.com> Date: Tue, 27 Aug 2024 20:51:56 +0100 Subject: [PATCH 4/4] fix Co-authored-by: Milap Sheth --- common/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/utils.js b/common/utils.js index e4ab84de..322e93f6 100644 --- a/common/utils.js +++ b/common/utils.js @@ -66,7 +66,7 @@ const isNonEmptyString = (arg) => { }; const isStringLowercase = (arg) => { - return isString(arg) && arg === arg.toLowerCase(); + return isNonEmptyString(arg) && arg === arg.toLowerCase(); }; const isStringArray = (arr) => Array.isArray(arr) && arr.every(isString);