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

chore: cleanup deploy script pr #327

Merged
merged 7 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
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
53 changes: 21 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.
*/
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.
* Package Mapping Object for Command Options and Post-Deployment Functions
*/
const CMD_OPTIONS = {
AxelarGateway: () => [...DEPLOY_CMD_OPTIONS, ...GATEWAY_CMD_OPTIONS],
GasService: () => DEPLOY_CMD_OPTIONS,
Test: () => DEPLOY_CMD_OPTIONS,
Operators: () => DEPLOY_CMD_OPTIONS,
const PACKAGE_MAPPING = {
npty marked this conversation as resolved.
Show resolved Hide resolved
CMD_OPTIONS: {
AxelarGateway: () => [...DEPLOY_CMD_OPTIONS, ...GATEWAY_CMD_OPTIONS],
GasService: () => DEPLOY_CMD_OPTIONS,
Test: () => DEPLOY_CMD_OPTIONS,
Operators: () => DEPLOY_CMD_OPTIONS,
},
POST_DEPLOY_FUNCTIONS: {
AxelarGateway: postDeployAxelarGateway,
GasService: postDeployGasService,
Test: postDeployTest,
Operators: postDeployOperators,
},
npty marked this conversation as resolved.
Show resolved Hide resolved
};

/**
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_MAPPING.POST_DEPLOY_FUNCTIONS[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,7 +284,7 @@ const addDeployOptions = (program) => {
const packageName = program.name();

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

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