Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(amplifier): allow custom instance labels #335

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cosmwasm/deploy-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ const programHandler = () => {
),
);
program.addOption(new Option('--instantiate2', 'use instantiate2 for constant address deployment'));
program.addOption(new Option('-l, --label <label>', 'contract instance label'));
program.addOption(new Option('--aarch64', 'aarch64').env('AARCH64').default(false));
program.addOption(new Option('-y, --yes', 'skip deployment prompt confirmation').env('YES'));

Expand Down
2 changes: 2 additions & 0 deletions cosmwasm/submit-proposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ const programHandler = () => {

program.name('submit-proposal').description('Submit governance proposals');

// TODO: combine deploy-contract and submit-proposal options to remove duplicates
program.addOption(
new Option('-e, --env <env>', 'environment')
.choices(['local', 'devnet', 'devnet-amplifier', 'devnet-verifiers', 'stagenet', 'testnet', 'mainnet'])
Expand All @@ -267,6 +268,7 @@ const programHandler = () => {
),
);
program.addOption(new Option('--instantiate2', 'use instantiate2 for constant address deployment'));
program.addOption(new Option('-l, --label <label>', 'contract instance label'));
program.addOption(new Option('--aarch64', 'aarch64').env('AARCH64').default(false));
program.addOption(new Option('-y, --yes', 'skip prompt confirmation').env('YES'));

Expand Down
18 changes: 12 additions & 6 deletions cosmwasm/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ const calculateDomainSeparator = (chain, router, network) => keccak256(Buffer.fr

const getSalt = (salt, contractName, chainNames) => fromHex(getSaltFromKey(salt || contractName.concat(chainNames)));

const getLabel = ({ contractName, label }) => label || contractName;

const readWasmFile = ({ artifactPath, contractName, aarch64 }) =>
readFileSync(`${artifactPath}/${pascalToSnake(contractName)}${aarch64 ? '-aarch64' : ''}.wasm`);

Expand Down Expand Up @@ -94,7 +96,9 @@ const uploadContract = async (client, wallet, config, options) => {
});
};

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

return wallet
.getAccounts()
.then(([account]) => {
Expand All @@ -105,17 +109,19 @@ const instantiateContract = (client, wallet, initMsg, config, { contractName, sa
} = config;
const initFee = gasLimit === 'auto' ? 'auto' : calculateFee(gasLimit, GasPrice.fromString(gasPrice));

const contractLabel = getLabel(options);

return instantiate2
? client.instantiate2(
account.address,
contractConfig.codeId,
getSalt(salt, contractName, chainNames),
initMsg,
contractName,
contractLabel,
initFee,
{ admin },
)
: client.instantiate(account.address, contractConfig.codeId, initMsg, contractName, initFee, {
: client.instantiate(account.address, contractConfig.codeId, initMsg, contractLabel, initFee, {
admin,
});
})
Expand Down Expand Up @@ -573,12 +579,12 @@ const getStoreCodeParams = (options) => {
};

const getStoreInstantiateParams = (config, options, msg) => {
const { contractName, admin } = options;
const { admin } = options;

return {
...getStoreCodeParams(options),
admin,
label: contractName,
label: getLabel(options),
msg: Buffer.from(JSON.stringify(msg)),
};
};
Expand All @@ -592,7 +598,7 @@ const getInstantiateContractParams = (config, options, msg) => {
...getSubmitProposalParams(options),
admin,
codeId: contractConfig.codeId,
label: contractName,
label: getLabel(options),
msg: Buffer.from(JSON.stringify(msg)),
};
};
Expand Down
Loading