Skip to content

Commit

Permalink
Merge branch 'main' into chore/improve-error-message
Browse files Browse the repository at this point in the history
  • Loading branch information
milapsheth authored Sep 26, 2024
2 parents 11e0acc + 1827193 commit 8f6d8af
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 166 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/test-sui.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ jobs:
run: node sui/gateway.js approve --proof wallet ethereum 0x32034b47cb29d162d9d803cc405356f4ac0ec07fe847ace431385fe8acf3e6e5-2 0x4F4495243837681061C4743b74B3eEdf548D56A5 0x6ce0d81b412abca2770eddb1549c9fcff721889c3aab1203dc93866db22ecc4b 0x56570de287d73cd1cb6092bb8fdee6173974955fdef345ae579ee9f475ea7432

- name: Gateway Call Contract
continue-on-error: true
run: node sui/gateway.js call-contract ethereum 0x4F4495243837681061C4743b74B3eEdf548D56A5 0x1234

- name: Gateway Rotate Signers
Expand All @@ -150,11 +149,9 @@ jobs:
###### Command: GMP ######

- name: Execute Outgoing Call Contract
continue-on-error: true
run: node sui/gmp.js sendCall ethereum 0x6f24A47Fc8AE5441Eb47EFfC3665e70e69Ac3F05 0.1 0x1234

- name: Execute Incoming Call Contract
continue-on-error: true
run: |
channel_id=$(cat axelar-chains-config/info/local.json | jq '.sui.contracts.Example.objects.ChannelId' | sed 's/"//g')
echo "Channel ID: $channel_id"
Expand Down Expand Up @@ -238,7 +235,6 @@ jobs:
&& mv temp.json axelar-chains-config/info/local.json
- name: Post Upgrade Gateway Approval With New Package ID
continue-on-error: true
run: node sui/gateway.js approve --proof wallet ethereum 0x32034b47cb29d162d9d803cc405356f4ac0ec07fe847ace431385fe8acf3e6e5-10 0x4F4495243837681061C4743b74B3eEdf548D56A5 0x6ce0d81b412abca2770eddb1549c9fcff721889c3aab1203dc93866db22ecc4b 0x56570de287d73cd1cb6092bb8fdee6173974955fdef345ae579ee9f475ea7432

###### Command: Transfer Object ######
Expand Down
2 changes: 1 addition & 1 deletion common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ async function getDomainSeparator(config, chain, options) {
}

const getChainConfig = (config, chainName) => {
if (chainName === 'none') {
if (!chainName) {
return undefined;
}

Expand Down
2 changes: 1 addition & 1 deletion cosmwasm/cli-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const addAmplifierOptions = (program, options) => {

const addContractOptions = (program) => {
program.addOption(new Option('-c, --contractName <contractName>', 'contract name').makeOptionMandatory(true));
program.addOption(new Option('-n, --chainNames <chainNames>', 'chain names').default('none').env('CHAINS'));
program.addOption(new Option('-n, --chainName <chainName>', 'chain name').env('CHAIN'));
};

const addStoreOptions = (program) => {
Expand Down
40 changes: 15 additions & 25 deletions cosmwasm/deploy-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const {
prepareClient,
fromHex,
getSalt,
getChains,
getAmplifierContractConfig,
updateContractConfig,
fetchCodeIdFromCodeHash,
uploadContract,
Expand All @@ -22,14 +22,11 @@ const {
const { Command, Option } = require('commander');
const { addAmplifierOptions } = require('./cli-utils');

const upload = async (client, wallet, chainName, config, options) => {
const { reuseCodeId, contractName, fetchCodeId, instantiate2, salt, chainNames } = options;
const {
axelar: {
contracts: { [contractName]: contractConfig },
},
} = config;
const chainConfig = chainName === 'none' ? undefined : getChainConfig(config, chainName);
const upload = async (client, wallet, config, options) => {
const { reuseCodeId, contractName, fetchCodeId, instantiate2, salt, chainName } = options;

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

if (!fetchCodeId && (!reuseCodeId || isNil(contractConfig.codeId))) {
printInfo('Uploading contract binary');
Expand All @@ -41,7 +38,7 @@ const upload = async (client, wallet, chainName, config, options) => {

if (instantiate2) {
const [account] = await wallet.getAccounts();
const address = instantiate2Address(fromHex(checksum), account.address, getSalt(salt, contractName, chainNames), 'axelar');
const address = instantiate2Address(fromHex(checksum), account.address, getSalt(salt, contractName, chainName), 'axelar');

updateContractConfig(contractConfig, chainConfig, 'address', address);

Expand All @@ -52,14 +49,11 @@ const upload = async (client, wallet, chainName, config, options) => {
}
};

const instantiate = async (client, wallet, chainName, config, options) => {
const { contractName, fetchCodeId } = options;
const {
axelar: {
contracts: { [contractName]: contractConfig },
},
chains: { [chainName]: chainConfig },
} = config;
const instantiate = async (client, wallet, config, options) => {
const { contractName, fetchCodeId, chainName } = options;

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

if (fetchCodeId) {
contractConfig.codeId = await fetchCodeIdFromCodeHash(client, contractConfig);
Expand All @@ -72,24 +66,20 @@ const instantiate = async (client, wallet, chainName, config, options) => {

updateContractConfig(contractConfig, chainConfig, 'address', contractAddress);

printInfo(`Instantiated ${chainName === 'none' ? '' : chainName.concat(' ')}${contractName}. Address`, contractAddress);
printInfo(`Instantiated ${chainName ? chainName.concat(' ') : ''}${contractName}. Address`, contractAddress);
};

const main = async (options) => {
const { env, uploadOnly, yes } = options;
const config = loadConfig(env);

const chains = getChains(config, options);

const wallet = await prepareWallet(options);
const client = await prepareClient(config, wallet);

await upload(client, wallet, chains[0], config, options);
await upload(client, wallet, config, options);

if (!(uploadOnly || prompt(`Proceed with deployment on axelar?`, yes))) {
for (const chain of chains) {
await instantiate(client, wallet, chain.toLowerCase(), config, options);
}
await instantiate(client, wallet, config, options);
}

saveConfig(config, env);
Expand Down
162 changes: 67 additions & 95 deletions cosmwasm/submit-proposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const {
fromHex,
getSalt,
readWasmFile,
getChains,
getAmplifierContractConfig,
updateContractConfig,
fetchCodeIdFromCodeHash,
Expand Down Expand Up @@ -41,18 +40,15 @@ const { ParameterChangeProposal } = require('cosmjs-types/cosmos/params/v1beta1/
const { Command } = require('commander');
const { addAmplifierOptions } = require('./cli-utils');

const predictAndUpdateAddress = async (client, contractConfig, chainConfig, chainName, options) => {
const { contractName, salt, chainNames, runAs } = options;
const predictAndUpdateAddress = async (client, contractConfig, chainConfig, options) => {
const { contractName, salt, chainName, runAs } = options;

const { checksum } = await client.getCodeDetails(contractConfig.codeId);
const contractAddress = instantiate2Address(fromHex(checksum), runAs, getSalt(salt, contractName, chainNames), 'axelar');
const contractAddress = instantiate2Address(fromHex(checksum), runAs, getSalt(salt, contractName, chainName), 'axelar');

updateContractConfig(contractConfig, chainConfig, 'address', contractAddress);

printInfo(
`Predicted address for ${chainName.toLowerCase() === 'none' ? '' : chainName.toLowerCase().concat(' ')}${contractName}. Address`,
contractAddress,
);
printInfo(`Predicted address for ${chainName ? chainName.concat(' ') : ''}${contractName}. Address`, contractAddress);
};

const printProposal = (proposal, proposalType) => {
Expand Down Expand Up @@ -96,100 +92,82 @@ const storeCode = async (client, wallet, config, options) => {
};

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

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

const { contractName, instantiate2 } = options;
const contractConfig = getAmplifierContractConfig(config, contractName);
const chainConfig = getChainConfig(config, chainName);
const { contractName, instantiate2, chainName } = options;
const contractConfig = getAmplifierContractConfig(config, contractName);
const chainConfig = getChainConfig(config, chainName);

if (instantiate2) {
throw new Error('instantiate2 not supported for storeInstantiate');
}
if (instantiate2) {
throw new Error('instantiate2 not supported for storeInstantiate');
}

const initMsg = makeInstantiateMsg(contractName, chainName, config);
const proposal = encodeStoreInstantiateProposal(config, options, initMsg);
const initMsg = makeInstantiateMsg(contractName, chainName, config);
const proposal = encodeStoreInstantiateProposal(config, options, initMsg);

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

const proposalId = await callSubmitProposal(client, wallet, config, options, proposal);
const proposalId = await callSubmitProposal(client, wallet, config, options, proposal);

updateContractConfig(contractConfig, chainConfig, 'storeInstantiateProposalId', proposalId);
contractConfig.storeCodeProposalCodeHash = createHash('sha256').update(readWasmFile(options)).digest().toString('hex');
}
updateContractConfig(contractConfig, chainConfig, 'storeInstantiateProposalId', proposalId);
contractConfig.storeCodeProposalCodeHash = createHash('sha256').update(readWasmFile(options)).digest().toString('hex');
};

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

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

const { contractName, instantiate2, predictOnly, fetchCodeId } = options;
const contractConfig = getAmplifierContractConfig(config, contractName);
const chainConfig = getChainConfig(config, chainName);
const { contractName, instantiate2, predictOnly, fetchCodeId, chainName } = options;
const contractConfig = getAmplifierContractConfig(config, contractName);
const chainConfig = getChainConfig(config, chainName);

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

if (predictOnly) {
return predictAndUpdateAddress(client, contractConfig, chainConfig, chainName, options);
}
if (predictOnly) {
return predictAndUpdateAddress(client, contractConfig, chainConfig, options);
}

const initMsg = makeInstantiateMsg(contractName, chainName, config);
const initMsg = makeInstantiateMsg(contractName, chainName, config);

let proposal;
let proposalType;
let proposal;
let proposalType;

if (instantiate2) {
proposal = encodeInstantiate2Proposal(config, options, initMsg);
proposalType = InstantiateContract2Proposal;
} else {
proposal = encodeInstantiateProposal(config, options, initMsg);
proposalType = InstantiateContractProposal;
}
if (instantiate2) {
proposal = encodeInstantiate2Proposal(config, options, initMsg);
proposalType = InstantiateContract2Proposal;
} else {
proposal = encodeInstantiateProposal(config, options, initMsg);
proposalType = InstantiateContractProposal;
}

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

const proposalId = await callSubmitProposal(client, wallet, config, options, proposal);
const proposalId = await callSubmitProposal(client, wallet, config, options, proposal);

updateContractConfig(contractConfig, chainConfig, 'instantiateProposalId', proposalId);
updateContractConfig(contractConfig, chainConfig, 'instantiateProposalId', proposalId);

if (instantiate2) {
return predictAndUpdateAddress(client, contractConfig, chainConfig, chainName, options);
}
if (instantiate2) {
return predictAndUpdateAddress(client, contractConfig, chainConfig, options);
}
};

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

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

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

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

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

const proposalId = await callSubmitProposal(client, wallet, config, options, proposal);
const proposalId = await callSubmitProposal(client, wallet, config, options, proposal);

updateContractConfig(contractConfig, chainConfig, 'executeProposalId', proposalId);
}
updateContractConfig(contractConfig, chainConfig, 'executeProposalId', proposalId);
};

const paramChange = async (client, wallet, config, options) => {
Expand All @@ -203,28 +181,22 @@ const paramChange = async (client, wallet, config, options) => {
};

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 { contractName, fetchCodeId, chainName } = options;
const contractConfig = getAmplifierContractConfig(config, contractName);

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

if (!confirmProposalSubmission(options, proposal, MigrateContractProposal)) {
return;
}
const proposal = encodeMigrateContractProposal(config, options, chainName);

await callSubmitProposal(client, wallet, config, options, proposal);
if (!confirmProposalSubmission(options, proposal, MigrateContractProposal)) {
return;
}

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

const mainProcessor = async (processor, options) => {
Expand Down
Loading

0 comments on commit 8f6d8af

Please sign in to comment.