Skip to content

Commit

Permalink
chore: cleanup deploy script pr (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
npty authored Aug 1, 2024
1 parent cd3c913 commit a674c87
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 46 deletions.
14 changes: 1 addition & 13 deletions common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,7 @@ const {
const { normalizeBech32 } = require('@cosmjs/encoding');

function loadConfig(env) {
const config = require(`${__dirname}/../axelar-chains-config/info/${env}.json`);

if (!config.sui) {
config.sui = {
networkType: env === 'local' ? 'localnet' : env,
name: 'Sui',
contracts: {
AxelarGateway: {},
},
};
}

return config;
return require(`${__dirname}/../axelar-chains-config/info/${env}.json`);
}

function saveConfig(config, env) {
Expand Down
4 changes: 3 additions & 1 deletion sui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ If you want to run against a local Sui network, then create a `axelar-chains-con
"tokenSymbol": "SUI",
"rpc": "http://127.0.0.1:9000",
"faucetUrl": "http://127.0.0.1:9123",
"contracts": {}
"contracts": {
"AxelarGateway": {}
}
}
}
```
Expand Down
56 changes: 24 additions & 32 deletions sui/deploy-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,21 @@ const {
const PACKAGE_DIRS = ['gas_service', 'test', 'axelar_gateway', 'operators'];

/**
* Post-Deployment Functions Mapping
*
* This object maps each package name to a post-deployment function.
* Package Mapping Object for Command Options and Post-Deployment Functions
*/
const POST_DEPLOY_FUNCTIONS = {
GasService: postDeployGasService,
Test: postDeployTest,
Operators: postDeployOperators,
AxelarGateway: postDeployAxelarGateway,
};

/**
* Command Options Mapping
*
* This object maps each package name to a function that returns an array of command options.
*/
const CMD_OPTIONS = {
AxelarGateway: () => [...DEPLOY_CMD_OPTIONS, ...GATEWAY_CMD_OPTIONS],
GasService: () => DEPLOY_CMD_OPTIONS,
Test: () => DEPLOY_CMD_OPTIONS,
Operators: () => DEPLOY_CMD_OPTIONS,
const PACKAGE_CONFIGS = {
cmdOptions: {
AxelarGateway: () => GATEWAY_CMD_OPTIONS,
GasService: () => [],
Test: () => [],
Operators: () => [],
},
postDeployFunctions: {
AxelarGateway: postDeployAxelarGateway,
GasService: postDeployGasService,
Test: postDeployTest,
Operators: postDeployOperators,
},
};

/**
Expand All @@ -85,8 +79,7 @@ const supportedPackages = PACKAGE_DIRS.map((dir) => ({
* Define post-deployment functions for each supported package below.
*/

async function postDeployGasService(published, args) {
const { chain } = args;
async function postDeployGasService(published, keypair, client, config, chain, options) {
const [gasCollectorCapObjectId, gasServiceObjectId] = getObjectIdsByObjectTypes(published.publishTxn, [
`${published.packageId}::gas_service::GasCollectorCap`,
`${published.packageId}::gas_service::GasService`,
Expand All @@ -97,9 +90,7 @@ async function postDeployGasService(published, args) {
};
}

async function postDeployTest(published, args) {
const { chain, config, options } = args;
const [keypair, client] = getWallet(chain, options);
async function postDeployTest(published, keypair, client, config, chain, options) {
const relayerDiscovery = config.sui.contracts.AxelarGateway?.objects?.RelayerDiscovery;

const [singletonObjectId] = getObjectIdsByObjectTypes(published.publishTxn, [`${published.packageId}::test::Singleton`]);
Expand All @@ -117,8 +108,7 @@ async function postDeployTest(published, args) {
printInfo('Register transaction', registerTx.digest);
}

async function postDeployOperators(published, args) {
const { chain } = args;
async function postDeployOperators(published, keypair, client, config, chain, options) {
const [operatorsObjectId, ownerCapObjectId] = getObjectIdsByObjectTypes(published.publishTxn, [
`${published.packageId}::operators::Operators`,
`${published.packageId}::operators::OwnerCap`,
Expand All @@ -129,8 +119,7 @@ async function postDeployOperators(published, args) {
};
}

async function postDeployAxelarGateway(published, args) {
const { keypair, client, config, chain, options } = args;
async function postDeployAxelarGateway(published, keypair, client, config, chain, options) {
const { packageId, publishTxn } = published;
const { minimumRotationDelay, policy, previousSigners } = options;
const operator = options.operator || keypair.toSuiAddress();
Expand Down Expand Up @@ -216,8 +205,8 @@ async function deploy(keypair, client, supportedContract, config, chain, options
};

// Execute post-deployment function
const executePostDeploymentFn = POST_DEPLOY_FUNCTIONS[packageName];
executePostDeploymentFn(published, { keypair, client, config, chain, options });
const executePostDeploymentFn = PACKAGE_CONFIGS.postDeployFunctions[packageName];
await executePostDeploymentFn(published, keypair, client, config, chain, options);

printInfo(`${packageName} Configuration Updated`, JSON.stringify(chain.contracts[packageName], null, 2));
}
Expand Down Expand Up @@ -295,11 +284,14 @@ const addDeployOptions = (program) => {
const packageName = program.name();

// Find the corresponding options for the package
const options = CMD_OPTIONS[packageName]();
const options = PACKAGE_CONFIGS.cmdOptions[packageName]();

// Add the options to the program
options.forEach((option) => program.addOption(option));

// Add the base deploy options to the program
DEPLOY_CMD_OPTIONS.forEach((option) => program.addOption(option));

return program;
};

Expand Down

0 comments on commit a674c87

Please sign in to comment.