Skip to content

Commit

Permalink
Merge branch 'main' into feat/add-sui-stagenet
Browse files Browse the repository at this point in the history
  • Loading branch information
blockchainguyy authored Jan 9, 2025
2 parents 533655f + 58bcb02 commit 0d10c5f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
4 changes: 3 additions & 1 deletion cosmwasm/cli-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ const addStoreProposalOptions = (program) => {
new Option('--builder <builder>', 'a valid docker image name with tag, such as "cosmwasm/workspace-optimizer:0.16.0'),
);
program.addOption(
new Option('-i, --instantiateAddresses <instantiateAddresses>', 'comma separated list of addresses allowed to instantiate'),
new Option('-i, --instantiateAddresses <instantiateAddresses>', 'comma separated list of addresses allowed to instantiate')
.default([])
.argParser((addresses) => addresses.split(',').map((address) => address.trim())),
);
};

Expand Down
3 changes: 3 additions & 0 deletions cosmwasm/submit-proposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const {
getAmplifierBaseContractConfig,
getAmplifierContractConfig,
updateCodeId,
addDefaultInstantiateAddresses,
getChainTruncationParams,
decodeProposalAttributes,
encodeStoreCodeProposal,
Expand Down Expand Up @@ -80,6 +81,7 @@ const callSubmitProposal = async (client, wallet, config, options, proposal) =>
const storeCode = async (client, wallet, config, options) => {
const { contractName } = options;
const contractBaseConfig = getAmplifierBaseContractConfig(config, contractName);
await addDefaultInstantiateAddresses(client, config, options);

const proposal = encodeStoreCodeProposal(options);

Expand All @@ -96,6 +98,7 @@ const storeCode = async (client, wallet, config, options) => {
const storeInstantiate = async (client, wallet, config, options) => {
const { contractName, instantiate2 } = options;
const { contractConfig, contractBaseConfig } = getAmplifierContractConfig(config, options);
await addDefaultInstantiateAddresses(client, config, options);

if (instantiate2) {
throw new Error('instantiate2 not supported for storeInstantiate');
Expand Down
42 changes: 38 additions & 4 deletions cosmwasm/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const { ParameterChangeProposal } = require('cosmjs-types/cosmos/params/v1beta1/
const { AccessType } = require('cosmjs-types/cosmwasm/wasm/v1/types');
const {
printInfo,
printWarn,
isString,
isStringArray,
isKeccak256Hash,
Expand Down Expand Up @@ -133,6 +134,7 @@ 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);
};

Expand Down Expand Up @@ -544,6 +546,36 @@ const fetchCodeIdFromCodeHash = async (client, contractBaseConfig) => {
return codeId;
};

const addDefaultInstantiateAddresses = async (client, config, options) => {
const { contractConfig } = getAmplifierContractConfig(config, options);

if (!contractConfig.address) {
return;
}

const contract = await client.getContract(contractConfig.address);

let { instantiateAddresses } = options;

if (!instantiateAddresses) {
instantiateAddresses = [];
}

if (contract.admin && !instantiateAddresses.includes(contract.admin)) {
instantiateAddresses.push(contract.admin);
printWarn(
`Contract ${contractConfig.address} admin address ${contract.admin} was not included in instantiateAddresses list. Adding it by default.`,
);
}

if (contract.creator && !instantiateAddresses.includes(contract.creator)) {
instantiateAddresses.push(contract.creator);
printWarn(
`Contract ${contractConfig.address} creator address ${contract.creator} was not included in instantiateAddresses list. Adding it by default.`,
);
}
};

const getChainTruncationParams = (config, chainConfig) => {
const key = chainConfig.axelarId.toLowerCase();
const chainTruncationParams = config.axelar.contracts.InterchainTokenService[key];
Expand All @@ -565,7 +597,7 @@ const getChainTruncationParams = (config, chainConfig) => {
const getInstantiatePermission = (accessType, addresses) => {
return {
permission: accessType,
addresses: addresses.split(',').map((address) => address.trim()),
addresses,
};
};

Expand All @@ -591,9 +623,10 @@ const getStoreCodeParams = (options) => {
codeHash = createHash('sha256').update(wasm).digest();
}

const instantiatePermission = instantiateAddresses
? getInstantiatePermission(AccessType.ACCESS_TYPE_ANY_OF_ADDRESSES, instantiateAddresses)
: getInstantiatePermission(AccessType.ACCESS_TYPE_NOBODY, '');
const instantiatePermission =
instantiateAddresses && instantiateAddresses.length > 0
? getInstantiatePermission(AccessType.ACCESS_TYPE_ANY_OF_ADDRESSES, instantiateAddresses)
: getInstantiatePermission(AccessType.ACCESS_TYPE_NOBODY, []);

return {
...getSubmitProposalParams(options),
Expand Down Expand Up @@ -841,6 +874,7 @@ module.exports = {
uploadContract,
instantiateContract,
fetchCodeIdFromCodeHash,
addDefaultInstantiateAddresses,
getChainTruncationParams,
decodeProposalAttributes,
encodeStoreCodeProposal,
Expand Down

0 comments on commit 0d10c5f

Please sign in to comment.