diff --git a/cosmwasm/README.md b/cosmwasm/README.md index 7836ca9c..f666c045 100644 --- a/cosmwasm/README.md +++ b/cosmwasm/README.md @@ -176,6 +176,8 @@ Use the option `--fetchCodeId` to retrieve and update the code id from the netwo Note: The rules for chain name specification and the use of `--instantiate2` as described in the "Deploy the contracts" and "Constant Address Deployment" sections above also apply when instantiating through governance. Refer to those sections for details on omitting chain names for certain contracts and using `--instantiate2` for address prediction. +Since the instantiation is not executed until the porposal passes, the contract address cannot be known in advance and therefore it cannot be saved in the config, unless the address is predicted using the `--instantiate2` flag. + Order of execution to satisfy dependencies: 1. `node cosmwasm/submit-proposal.js instantiate -c Router -t "Router roposal title" -d "Router proposal description" -r $RUN_AS_ACCOUNT --deposit 100000000 --instantiate2 --predictOnly` @@ -194,7 +196,7 @@ Order of execution to satisfy dependencies: The command `storeInstantiate` from the `submit-proposal` script, allows uploading and instantiating in one step. However, there are a couple of caveats to be aware of: -1. There is no support for `instantiate2` in this proposal type. This means that the contract address will not be known until the proposal is executed. +1. There is no support for `instantiate2` using this proposal type. This means that the contract address will not be known until the proposal is executed and therefore it cannot be saved in the config. 2. Since governance proposals are executed asynchronously, both the codeId and contract address are not immediately available. Querying the network for the correct values could be tricky if multiple proposals are executed together. diff --git a/cosmwasm/submit-proposal.js b/cosmwasm/submit-proposal.js index f2e3a7a4..90f3c73a 100644 --- a/cosmwasm/submit-proposal.js +++ b/cosmwasm/submit-proposal.js @@ -41,15 +41,15 @@ const { ParameterChangeProposal } = require('cosmjs-types/cosmos/params/v1beta1/ const { Command } = require('commander'); const { addAmplifierOptions } = require('./cli-utils'); -const predictAndUpdateAddress = async (client, contractConfig, options) => { +const predictAddress = async (client, contractConfig, options) => { const { contractName, salt, chainName, runAs } = options; const { checksum } = await client.getCodeDetails(contractConfig.codeId); const contractAddress = instantiate2Address(fromHex(checksum), runAs, getSalt(salt, contractName, chainName), 'axelar'); - contractConfig.address = contractAddress; - printInfo(`Predicted address for ${chainName ? chainName.concat(' ') : ''}${contractName}. Address`, contractAddress); + + return contractAddress; }; const printProposal = (proposal, proposalType) => { @@ -119,8 +119,13 @@ const instantiate = async (client, wallet, config, options) => { await updateCodeId(client, config, options); + let contractAddress; + if (predictOnly) { - return predictAndUpdateAddress(client, contractConfig, options); + contractAddress = await predictAddress(client, contractConfig, options); + contractConfig.address = contractAddress; + + return; } const initMsg = makeInstantiateMsg(contractName, chainName, config); @@ -131,9 +136,13 @@ const instantiate = async (client, wallet, config, options) => { if (instantiate2) { proposal = encodeInstantiate2Proposal(config, options, initMsg); proposalType = InstantiateContract2Proposal; + + contractAddress = await predictAddress(client, contractConfig, options); } else { proposal = encodeInstantiateProposal(config, options, initMsg); proposalType = InstantiateContractProposal; + + printInfo('Contract address cannot be predicted without using `--instantiate2` flag, address will not be saved in the config'); } if (!confirmProposalSubmission(options, proposal, proposalType)) { @@ -143,10 +152,7 @@ const instantiate = async (client, wallet, config, options) => { const proposalId = await callSubmitProposal(client, wallet, config, options, proposal); contractConfig.instantiateProposalId = proposalId; - - if (instantiate2) { - return predictAndUpdateAddress(client, contractConfig, options); - } + if (instantiate2) contractConfig.address = contractAddress; }; const execute = async (client, wallet, config, options) => {