Skip to content

Commit

Permalink
add migrate command
Browse files Browse the repository at this point in the history
  • Loading branch information
eguajardo committed Jan 10, 2025
1 parent 9220bf1 commit 18e210b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
31 changes: 31 additions & 0 deletions cosmwasm/deploy-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const {
getCodeId,
uploadContract,
instantiateContract,
migrateContract,
} = require('./utils');

const { Command } = require('commander');
Expand Down Expand Up @@ -69,6 +70,23 @@ const uploadInstantiate = async (client, wallet, config, options) => {
await instantiate(client, wallet, config, options);
};

const migrate = async (client, wallet, config, options) => {
const { yes } = options;
const { contractConfig } = getAmplifierContractConfig(config, options);

const codeId = await getCodeId(client, config, options);
printInfo('Using code id', codeId);

if (prompt(`Proceed with contract migration on axelar?`, yes)) {
return;
}

contractConfig.codeId = codeId;

const { transactionHash } = await migrateContract(client, wallet, config, options);
printInfo('Migration completed. Transaction hash', transactionHash);
};

const mainProcessor = async (processor, options) => {
const { env } = options;
const config = loadConfig(env);
Expand Down Expand Up @@ -127,6 +145,19 @@ const programHandler = () => {
instantiate2Options: true,
});

const migrateCmd = program
.command('migrate')
.description('Migrate contract')
.action((options) => {
mainProcessor(migrate, options);
});
addAmplifierOptions(migrateCmd, {
contractOptions: true,
migrateOptions: true,
codeId: true,
fetchCodeId: true,
});

program.parse();
};

Expand Down
18 changes: 15 additions & 3 deletions cosmwasm/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,12 @@ const uploadContract = async (client, wallet, config, options) => {
const uploadFee = gasLimit === 'auto' ? 'auto' : calculateFee(gasLimit, GasPrice.fromString(gasPrice));

// uploading through stargate doesn't support defining instantiate permissions
return await client.upload(account.address, wasm, uploadFee);
return client.upload(account.address, wasm, uploadFee);
};

const instantiateContract = async (client, wallet, initMsg, config, options) => {
const { contractName, salt, instantiate2, chainName, admin } = options;

const [account] = await wallet.getAccounts();

const { contractConfig } = getAmplifierContractConfig(config, options);

const {
Expand All @@ -171,6 +169,19 @@ const instantiateContract = async (client, wallet, initMsg, config, options) =>
return contractAddress;
};

const migrateContract = async (client, wallet, config, options) => {
const { msg } = options;
const [account] = await wallet.getAccounts();
const { contractConfig } = getAmplifierContractConfig(config, options);

const {
axelar: { gasPrice, gasLimit },
} = config;
const migrateFee = gasLimit === 'auto' ? 'auto' : calculateFee(gasLimit, GasPrice.fromString(gasPrice));

return client.migrate(account.address, contractConfig.address, contractConfig.codeId, JSON.parse(msg), migrateFee);
};

const validateAddress = (address) => {
return isString(address) && isValidCosmosAddress(address);
};
Expand Down Expand Up @@ -875,6 +886,7 @@ module.exports = {
getCodeId,
uploadContract,
instantiateContract,
migrateContract,
fetchCodeIdFromCodeHash,
addDefaultInstantiateAddresses,
getChainTruncationParams,
Expand Down

0 comments on commit 18e210b

Please sign in to comment.