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(sui): support all contract deployment in deploy-contract script #323

Merged
merged 32 commits into from
Aug 1, 2024

Conversation

npty
Copy link
Member

@npty npty commented Jul 29, 2024

Description

AXE-4558

This PR expands contracts support for both deployment and upgrade including Test, AxelarGateway, and GasService contracts. As a generalized script to deploy and upgrade contract, it's mostly focusing on providing a clear structure to support additional contracts.

There're few different sections that needs to modify/add when we need to support new contracts:

1. Package Dirs

This constant contains a list of folder names for each contract

const PACKAGE_DIRS = ['gas_service', 'test', 'axelar_gateway'];

The package names will be read from the Move.toml file programmatically based on given PACKAGE_DIRS. They will be used as a command name for the sub-commands in the deploy and upgrade commands dynamically.

2. Post-Deployment Functions

These functions serve the purposes such as updating chain config, submitting additional setup transactions. Each function will be called based on the package name in a switch-case condition as follows:

switch (packageName) {
    case 'GasService':
        await postDeployGasService(published, chain);
        break;
    case 'AxelarGateway':
        await postDeployAxelarGateway(published, keypair, client, config, chain, options);
        break;
    case 'Test':
        await postDeployTest(published, config, chain, options);
        break;
    default:
        throw new Error(`${packageName} is not supported.`);
}

3. Deploy Options

Each contract has its own set of arguments. They're defined in the cli-utils.js file and added to the program conditionally based on the packageName as follows:

const getDeployGatewayOptions = () => {
    return [
        new Option('--signers <signers>', 'JSON with the initial signer set').env('SIGNERS'),
        new Option('--operator <operator>', 'operator for the gateway (defaults to the deployer address)').env('OPERATOR'),
        new Option('--minimumRotationDelay <minimumRotationDelay>', 'minium delay for signer rotations (in second)')
            .argParser((val) => parseInt(val) * 1000)
            .default(24 * 60 * 60),
        new Option('--domainSeparator <domainSeparator>', 'domain separator'),
        new Option('--nonce <nonce>', 'nonce for the signer (defaults to HashZero)'),
        new Option('--previousSigners <previousSigners>', 'number of previous signers to retain').default('15'),
        new Option('--policy <policy>', 'upgrade policy for upgrade cap: For example, use "any_upgrade" to allow all types of upgrades')
            .choices(['any_upgrade', 'code_upgrade', 'dep_upgrade'])
            .default('any_upgrade'),
    ];
};

const addDeployOptions = (program) => {
    switch (program.name()) {
        case 'AxelarGateway':
            getDeployGatewayOptions().forEach((option) => program.addOption(option));
            break;
        case 'GasService':
        case 'Test':
            break;
        default:
            throw new Error(`Unsupported package: ${program.name()}. `);
    }

    return program;
};

Changes

  • Refactor the deployment scripts structure.
  • Moved getSigners and getChannelId methods from sui/deploy-contract.js to sui/utils.js to reduce the complexity.
  • Moved getDomainSeparator from evm/utils to common/utils as we have to use it when deploys the AxelarGateway contract on Sui network as well. Also modifying a bit to allow zero hex as a default value when the env is local

Usage

  1. Deploy Axelar Gateway contract:
node sui/deploy-contract.js deploy AxelarGateway --signers wallet --nonce test
  1. Deploy Gas Service contract:
node sui/deploy-contract.js deploy GasService
  1. Upgrade Axelar Gateway contract:
node sui/deploy-contract.js upgrade AxelarGateway <policy>

@npty npty self-assigned this Jul 29, 2024
@npty npty marked this pull request as ready for review July 29, 2024 10:25
@npty npty requested a review from a team as a code owner July 29, 2024 10:25
@npty npty marked this pull request as draft July 29, 2024 10:34
@npty npty force-pushed the chore/merge-deploy-test-into-deploy-contract branch from 4ac2eae to c29a4fd Compare July 30, 2024 13:32
@npty npty changed the base branch from main to chore/use-common-utils July 30, 2024 13:33
@npty npty changed the title chore: merge deploy test into deploy contract feat: merge deploy test into deploy contract Jul 30, 2024
Base automatically changed from chore/use-common-utils to main July 30, 2024 13:38
@npty npty marked this pull request as ready for review July 31, 2024 06:33
@npty npty changed the title feat: merge deploy test into deploy contract feat(sui): support all contract deployment in deploy-contract script Jul 31, 2024
sui/deploy-contract.js Outdated Show resolved Hide resolved
sui/cli-utils.js Outdated Show resolved Hide resolved
sui/utils.js Show resolved Hide resolved
sui/deploy-utils.js Outdated Show resolved Hide resolved
sui/deploy-contract.js Outdated Show resolved Hide resolved
sui/deploy-contract.js Outdated Show resolved Hide resolved
sui/deploy-contract.js Show resolved Hide resolved
@npty npty force-pushed the chore/merge-deploy-test-into-deploy-contract branch from 3637904 to a7c4242 Compare July 31, 2024 11:10
@npty npty force-pushed the chore/merge-deploy-test-into-deploy-contract branch from a7c4242 to 29b8bd1 Compare July 31, 2024 11:12
sui/deploy-utils.js Outdated Show resolved Hide resolved
common/utils.js Show resolved Hide resolved
sui/deploy-contract.js Show resolved Hide resolved
sui/deploy-contract.js Show resolved Hide resolved
sui/deploy-contract.js Show resolved Hide resolved
@npty npty merged commit cd3c913 into main Aug 1, 2024
4 checks passed
@npty npty deleted the chore/merge-deploy-test-into-deploy-contract branch August 1, 2024 04:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants