Skip to content

Commit

Permalink
Merge branch 'main' into chore/update-published-at-when-upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
npty authored Sep 24, 2024
2 parents cd3d93e + 8254ec7 commit ab473c6
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 594 deletions.
2 changes: 1 addition & 1 deletion axelar-chains-config/info/devnet-amplifier.json
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@
"10"
]
},
"codeId": 620,
"codeId": 737,
"address": "axelar1vaj9sfzc3z0gpel90wu4ljutncutv0wuhvvwfsh30rqxq422z89qnd989l"
},
"NexusGateway": {
Expand Down
559 changes: 0 additions & 559 deletions axelar-chains-config/info/devnet-verifiers.json

This file was deleted.

6 changes: 3 additions & 3 deletions common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ const getSaltFromKey = (key) => {
return keccak256(defaultAbiCoder.encode(['string'], [key.toString()]));
};

const getContractConfig = async (config, chain) => {
const getAmplifierContractOnchainConfig = async (config, chain) => {
const key = Buffer.from('config');
const client = await CosmWasmClient.connect(config.axelar.rpc);
const value = await client.queryContractRaw(config.axelar.contracts.MultisigProver[chain].address, key);
Expand Down Expand Up @@ -400,7 +400,7 @@ async function getDomainSeparator(config, chain, options) {
}

printInfo(`Retrieving domain separator for ${chain.name} from Axelar network`);
const domainSeparator = hexlify((await getContractConfig(config, chain.axelarId)).domain_separator);
const domainSeparator = hexlify((await getAmplifierContractOnchainConfig(config, chain.axelarId)).domain_separator);

if (domainSeparator !== expectedDomainSeparator) {
throw new Error(`unexpected domain separator (want ${expectedDomainSeparator}, got ${domainSeparator})`);
Expand Down Expand Up @@ -467,7 +467,7 @@ module.exports = {
getDomainSeparator,
getChainConfig,
getMultisigProof,
getContractConfig,
getAmplifierContractOnchainConfig,
getSaltFromKey,
calculateDomainSeparator,
};
17 changes: 17 additions & 0 deletions cosmwasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,20 @@ node cosmwasm/submit-proposal.js paramChange \
}
]'
```

### Submit a proposal to migrate a contract

To submit a governance proposal to migrate a contract, use the `submit-proposal` script with the `migrate` command. The `--msg` option should be used to pass the migrate message.

Example usage:

```
node cosmwasm/submit-proposal.js migrate \
-c MultisigProver \
-t "Proposal title" \
-d "Proposal description" \
-n avalanche \
--msg '{}' \
--fetchCodeId \
--deposit 100000000
```
14 changes: 13 additions & 1 deletion cosmwasm/cli-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ const addAmplifierOptions = (program, options) => {
addParamChangeProposalOptions(program);
}

if (options.migrateOptions) {
addMigrateOptions(program);
}

if (options.proposalOptions) {
addProposalOptions(program);
}
Expand Down Expand Up @@ -100,13 +104,21 @@ const addInstantiateProposalOptions = (program) => {
};

const addExecuteProposalOptions = (program) => {
program.addOption(new Option('--msg <msg>', 'json encoded execute message'));
program.addOption(new Option('--msg <msg>', 'json encoded execute message').makeOptionMandatory(true));
};

const addParamChangeProposalOptions = (program) => {
program.addOption(new Option('--changes <changes>', 'parameter changes'));
};

const addMigrateOptions = (program) => {
program.addOption(
new Option('--msg <msg>', "json encoded migration message. Use '{}' to denote an empty migration message").makeOptionMandatory(
true,
),
);
};

const addProposalOptions = (program) => {
program.addOption(new Option('-t, --title <title>', 'title of proposal').makeOptionMandatory(true));
program.addOption(new Option('-d, --description <description>', 'description of proposal').makeOptionMandatory(true));
Expand Down
68 changes: 44 additions & 24 deletions cosmwasm/submit-proposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const {
getSalt,
readWasmFile,
getChains,
getAmplifierContractConfig,
updateContractConfig,
fetchCodeIdFromCodeHash,
decodeProposalAttributes,
Expand All @@ -22,16 +23,18 @@ const {
encodeInstantiate2Proposal,
encodeExecuteContractProposal,
encodeParameterChangeProposal,
encodeMigrateContractProposal,
submitProposal,
makeInstantiateMsg,
} = require('./utils');
const { isNumber, saveConfig, loadConfig, printInfo, prompt } = require('../common');
const { isNumber, saveConfig, loadConfig, printInfo, prompt, getChainConfig } = require('../common');
const {
StoreCodeProposal,
StoreAndInstantiateContractProposal,
InstantiateContractProposal,
InstantiateContract2Proposal,
ExecuteContractProposal,
MigrateContractProposal,
} = require('cosmjs-types/cosmwasm/wasm/v1/proposal');
const { ParameterChangeProposal } = require('cosmjs-types/cosmos/params/v1beta1/params');

Expand Down Expand Up @@ -78,11 +81,7 @@ const callSubmitProposal = async (client, wallet, config, options, proposal) =>

const storeCode = async (client, wallet, config, options) => {
const { contractName } = options;
const {
axelar: {
contracts: { [contractName]: contractConfig },
},
} = config;
const contractConfig = getAmplifierContractConfig(config, contractName);

const proposal = encodeStoreCodeProposal(options);

Expand All @@ -103,12 +102,8 @@ const storeInstantiate = async (client, wallet, config, options) => {
const chainName = chain.toLowerCase();

const { contractName, instantiate2 } = options;
const {
axelar: {
contracts: { [contractName]: contractConfig },
},
chains: { [chainName]: chainConfig },
} = config;
const contractConfig = getAmplifierContractConfig(config, contractName);
const chainConfig = getChainConfig(config, chainName);

if (instantiate2) {
throw new Error('instantiate2 not supported for storeInstantiate');
Expand All @@ -135,12 +130,8 @@ const instantiate = async (client, wallet, config, options) => {
const chainName = chain.toLowerCase();

const { contractName, instantiate2, predictOnly, fetchCodeId } = options;
const {
axelar: {
contracts: { [contractName]: contractConfig },
},
chains: { [chainName]: chainConfig },
} = config;
const contractConfig = getAmplifierContractConfig(config, contractName);
const chainConfig = getChainConfig(config, chainName);

if (fetchCodeId) {
contractConfig.codeId = await fetchCodeIdFromCodeHash(client, contractConfig);
Expand Down Expand Up @@ -186,12 +177,8 @@ const execute = async (client, wallet, config, options) => {
const chainName = chain.toLowerCase();

const { contractName } = options;
const {
axelar: {
contracts: { [contractName]: contractConfig },
},
chains: { [chainName]: chainConfig },
} = config;
const contractConfig = getAmplifierContractConfig(config, contractName);
const chainConfig = getChainConfig(config, chainName);

const proposal = encodeExecuteContractProposal(config, options, chainName);

Expand All @@ -215,6 +202,31 @@ const paramChange = async (client, wallet, config, options) => {
await callSubmitProposal(client, wallet, config, options, proposal);
};

const migrate = async (client, wallet, config, options) => {
const chains = getChains(config, options);

for (const chain of chains) {
const chainName = chain.toLowerCase();

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

if (fetchCodeId) {
contractConfig.codeId = await fetchCodeIdFromCodeHash(client, contractConfig);
} else if (!isNumber(contractConfig.codeId)) {
throw new Error('Code Id is not defined');
}

const proposal = encodeMigrateContractProposal(config, options, chainName);

if (!confirmProposalSubmission(options, proposal, MigrateContractProposal)) {
return;
}

await callSubmitProposal(client, wallet, config, options, proposal);
}
};

const mainProcessor = async (processor, options) => {
const { env, contractName } = options;
const config = loadConfig(env);
Expand Down Expand Up @@ -301,6 +313,14 @@ const programHandler = () => {
});
addAmplifierOptions(paramChangeCmd, { paramChangeProposalOptions: true, proposalOptions: true });

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

program.parse();
};

Expand Down
36 changes: 36 additions & 0 deletions cosmwasm/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const {
InstantiateContractProposal,
InstantiateContract2Proposal,
ExecuteContractProposal,
MigrateContractProposal,
} = require('cosmjs-types/cosmwasm/wasm/v1/proposal');
const { ParameterChangeProposal } = require('cosmjs-types/cosmos/params/v1beta1/params');
const { AccessType } = require('cosmjs-types/cosmwasm/wasm/v1/types');
Expand Down Expand Up @@ -73,6 +74,16 @@ const getChains = (config, { chainNames, instantiate2 }) => {
return chains;
};

const getAmplifierContractConfig = (config, contractName) => {
const contractConfig = config.axelar.contracts[contractName];

if (!contractConfig) {
throw new Error(`Contract ${contractName} not found in config`);
}

return contractConfig;
};

const updateContractConfig = (contractConfig, chainConfig, key, value) => {
if (chainConfig) {
contractConfig[chainConfig.axelarId] = {
Expand Down Expand Up @@ -675,6 +686,20 @@ const getParameterChangeParams = ({ title, description, changes }) => ({
})),
});

const getMigrateContractParams = (config, options, chainName) => {
const { contractName, msg } = options;

const contractConfig = getAmplifierContractConfig(config, contractName);
const chainConfig = getChainConfig(config, chainName);

return {
...getSubmitProposalParams(options),
contract: contractConfig[chainConfig?.axelarId]?.address || contractConfig.address,
codeId: contractConfig.codeId,
msg: Buffer.from(msg),
};
};

const encodeStoreCodeProposal = (options) => {
const proposal = StoreCodeProposal.fromPartial(getStoreCodeParams(options));

Expand Down Expand Up @@ -737,6 +762,15 @@ const encodeParameterChangeProposal = (options) => {
};
};

const encodeMigrateContractProposal = (config, options, chainName) => {
const proposal = MigrateContractProposal.fromPartial(getMigrateContractParams(config, options, chainName));

return {
typeUrl: '/cosmwasm.wasm.v1.MigrateContractProposal',
value: Uint8Array.from(MigrateContractProposal.encode(proposal).finish()),
};
};

const encodeSubmitProposal = (content, config, options, proposer) => {
const {
axelar: { tokenSymbol },
Expand Down Expand Up @@ -777,6 +811,7 @@ module.exports = {
calculateDomainSeparator,
readWasmFile,
getChains,
getAmplifierContractConfig,
updateContractConfig,
uploadContract,
instantiateContract,
Expand All @@ -789,6 +824,7 @@ module.exports = {
encodeInstantiate2Proposal,
encodeExecuteContractProposal,
encodeParameterChangeProposal,
encodeMigrateContractProposal,
submitProposal,
isValidCosmosAddress,
};
17 changes: 15 additions & 2 deletions sui/faucet.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
'use strict';

const { requestSuiFromFaucetV0, getFaucetHost } = require('@mysten/sui/faucet');
const { saveConfig, loadConfig, printInfo } = require('../common/utils');
const { saveConfig, loadConfig, printInfo, printWarn } = require('../common/utils');
const { getWallet, printWalletInfo, addBaseOptions } = require('./utils');
const { Command, Option } = require('commander');

async function processCommand(config, chain, options) {
const [keypair, client] = getWallet(chain, options);
const recipient = options.recipient || keypair.toSuiAddress();

await printWalletInfo(keypair, client, chain, options);
await printWalletInfo(recipient, client, chain, options);

const balance = Number((await client.getBalance({ owner: recipient })).totalBalance) / 1e9;

if (balance >= Number(options.minBalance)) {
printWarn('Wallet balance above minimum, skipping faucet request');
process.exit(0);
}

await requestSuiFromFaucetV0({
host: getFaucetHost(chain.networkType),
Expand All @@ -31,6 +38,12 @@ if (require.main === module) {
program
.name('faucet')
.addOption(new Option('--recipient <recipient>', 'recipient to request funds for'))
.addOption(
new Option(
'--minBalance <amount>',
'tokens will only be requested from the faucet if recipient balance is below the amount provided',
).default('1'),
)
.description('Query the faucet for funds.')
.action((options) => {
mainProcessor(options, processCommand);
Expand Down
12 changes: 8 additions & 4 deletions sui/utils/sign-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,14 @@ function getWallet(chain, options) {
return [keypair, client];
}

async function printWalletInfo(keypair, client, chain, options) {
printInfo('Wallet address', keypair.toSuiAddress());

const coins = await client.getBalance({ owner: keypair.toSuiAddress() });
async function printWalletInfo(wallet, client, chain, options) {
const owner =
wallet instanceof Ed25519Keypair || wallet instanceof Secp256k1Keypair || wallet instanceof Secp256r1Keypair
? wallet.toSuiAddress()
: wallet;
printInfo('Wallet address', owner);

const coins = await client.getBalance({ owner });
printInfo('Wallet balance', `${coins.totalBalance / 1e9} ${chain.tokenSymbol || coins.coinType}`);
}

Expand Down

0 comments on commit ab473c6

Please sign in to comment.