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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
fd13b23
chore: add test contract deployment into deploy-contract script
npty Jul 26, 2024
49d9057
chore: update post deployment for test contract
npty Jul 26, 2024
f1874dc
chore: remove unnecessary address record
npty Jul 26, 2024
473521d
chore: refactor deploy-contract
npty Jul 29, 2024
8aaa5cd
fix: choices is overrided by the handler
npty Jul 29, 2024
ab5d5c3
chore: update test contract deployment doc
npty Jul 29, 2024
c44a132
Merge branch 'main' into chore/merge-deploy-test-into-deploy-contract
npty Jul 30, 2024
74fe620
chore: refactor commands in deploy script
npty Jul 30, 2024
c29a4fd
chore: use common utils
npty Jul 30, 2024
5feec84
chore: move getDomainSeparator to common
npty Jul 30, 2024
2481958
fix: all contracts deployment
npty Jul 30, 2024
8f0eac1
chore: lint
npty Jul 30, 2024
4dc660f
chore: move getSigners and getChannelId to utils
npty Jul 31, 2024
9d5efa6
chore: refactor upgrade
npty Jul 31, 2024
292945c
chore: fix missing package address
npty Jul 31, 2024
845c015
chore: refactor deploy script
npty Jul 31, 2024
bf9a68a
Merge branch 'main' into chore/merge-deploy-test-into-deploy-contract
npty Jul 31, 2024
98e6f64
chore: update README.md
npty Jul 31, 2024
07f46c2
chore: prettier
npty Jul 31, 2024
d44cef7
chore: remove program and deploy function in deploy-utils.js
npty Jul 31, 2024
4f41195
chore: move getDeplooyGatewayOptions to deploy-utils
npty Jul 31, 2024
fe2be1a
chore: use constant for 0x2
npty Jul 31, 2024
bdbbce9
chore: prettier
npty Jul 31, 2024
29b8bd1
feat: deploy Operators contract
npty Jul 31, 2024
6f2010e
chore: move the command options into deploy-contract file
npty Aug 1, 2024
d0002f1
chore: create a mapping for command options and post deployment scripts
npty Aug 1, 2024
5eed902
chore: add toml parser
npty Aug 1, 2024
6b3d1c4
chore: fix default value for config.sui
npty Aug 1, 2024
4964688
chore: use loadConfig instead of loadSuiConfig
npty Aug 1, 2024
1a78c79
chore: reword
npty Aug 1, 2024
e56c054
chore: prettier
npty Aug 1, 2024
fd2421e
chore: fix prettier
npty Aug 1, 2024
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
81 changes: 80 additions & 1 deletion common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,27 @@ const chalk = require('chalk');
const https = require('https');
const http = require('http');
const readlineSync = require('readline-sync');
const { CosmWasmClient } = require('@cosmjs/cosmwasm-stargate');
const { ethers } = require('hardhat');
const {
utils: { keccak256, hexlify },
} = ethers;
const { normalizeBech32 } = require('@cosmjs/encoding');

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

if (!config.sui) {
npty marked this conversation as resolved.
Show resolved Hide resolved
config.sui = {
networkType: env === 'local' ? 'localnet' : env,
name: 'Sui',
contracts: {
AxelarGateway: {},
},
};
}

return config;
}

function saveConfig(config, env) {
Expand Down Expand Up @@ -331,6 +349,66 @@ function toBigNumberString(number) {
return Math.ceil(number).toLocaleString('en', { useGrouping: false });
}

const isValidCosmosAddress = (str) => {
try {
normalizeBech32(str);

return true;
} catch (error) {
return false;
}
};

async function getDomainSeparator(config, chain, options) {
// Allow any domain separator for local deployments or `0x` if not provided
if (options.env === 'local') {
return options.domainSeparator || ethers.constants.HashZero;
}

if (isKeccak256Hash(options.domainSeparator)) {
// return the domainSeparator for debug deployments
return options.domainSeparator;
}

const {
axelar: { contracts, chainId },
} = config;
const {
Router: { address: routerAddress },
} = contracts;

if (!isString(chain.axelarId)) {
throw new Error(`missing or invalid axelar ID for chain ${chain.name}`);
}

if (!isString(routerAddress) || !isValidCosmosAddress(routerAddress)) {
throw new Error(`missing or invalid router address`);
}

if (!isString(chainId)) {
throw new Error(`missing or invalid chain ID`);
}

printInfo(`Retrieving domain separator for ${chain.name} from Axelar network`);
const domainSeparator = hexlify((await getContractConfig(config, chain.axelarId)).domain_separator);
const expectedDomainSeparator = calculateDomainSeparator(chain.axelarId, routerAddress, chainId);

if (domainSeparator !== expectedDomainSeparator) {
throw new Error(`unexpected domain separator (want ${expectedDomainSeparator}, got ${domainSeparator})`);
}

return domainSeparator;
}

const getContractConfig = async (config, chain) => {
const key = Buffer.from('config');
const client = await CosmWasmClient.connect(config.axelar.rpc);
const value = await client.queryContractRaw(config.axelar.contracts.MultisigProver[chain].address, key);
return JSON.parse(Buffer.from(value).toString('ascii'));
};

const calculateDomainSeparator = (chain, router, network) => keccak256(Buffer.from(`${chain}${router}${network}`));

module.exports = {
loadConfig,
saveConfig,
Expand Down Expand Up @@ -362,4 +440,5 @@ module.exports = {
toBigNumberString,
timeout,
validateParameters,
getDomainSeparator,
};
44 changes: 2 additions & 42 deletions evm/deploy-amplifier-gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const {
ContractFactory,
Contract,
Wallet,
utils: { defaultAbiCoder, keccak256, hexlify },
utils: { defaultAbiCoder, keccak256 },
getDefaultProvider,
} = ethers;

Expand All @@ -22,59 +22,19 @@ const {
mainProcessor,
deployContract,
getGasOptions,
isKeccak256Hash,
getContractConfig,
isString,
getWeightedSigners,
getContractJSON,
getDeployedAddress,
getDeployOptions,
getDomainSeparator,
} = require('./utils');
const { calculateDomainSeparator, isValidCosmosAddress } = require('../cosmwasm/utils');
const { addExtendedOptions } = require('./cli-utils');
const { storeSignedTx, signTransaction, getWallet } = require('./sign-utils.js');

const { WEIGHTED_SIGNERS_TYPE, encodeWeightedSigners } = require('@axelar-network/axelar-gmp-sdk-solidity/scripts/utils');
const AxelarAmplifierGatewayProxy = require('@axelar-network/axelar-gmp-sdk-solidity/artifacts/contracts/gateway/AxelarAmplifierGatewayProxy.sol/AxelarAmplifierGatewayProxy.json');
const AxelarAmplifierGateway = require('@axelar-network/axelar-gmp-sdk-solidity/artifacts/contracts/gateway/AxelarAmplifierGateway.sol/AxelarAmplifierGateway.json');

async function getDomainSeparator(config, chain, options) {
printInfo(`Retrieving domain separator for ${chain.name} from Axelar network`);

if (isKeccak256Hash(options.domainSeparator)) {
// return the domainSeparator for debug deployments
return options.domainSeparator;
}

const {
axelar: { contracts, chainId },
} = config;
const {
Router: { address: routerAddress },
} = contracts;

if (!isString(chain.axelarId)) {
throw new Error(`missing or invalid axelar ID for chain ${chain.name}`);
}

if (!isString(routerAddress) || !isValidCosmosAddress(routerAddress)) {
throw new Error(`missing or invalid router address`);
}

if (!isString(chainId)) {
throw new Error(`missing or invalid chain ID`);
}

const domainSeparator = hexlify((await getContractConfig(config, chain.axelarId)).domain_separator);
const expectedDomainSeparator = calculateDomainSeparator(chain.axelarId, routerAddress, chainId);

if (domainSeparator !== expectedDomainSeparator) {
throw new Error(`unexpected domain separator (want ${expectedDomainSeparator}, got ${domainSeparator})`);
}

return domainSeparator;
}

async function getSetupParams(config, chain, operator, options) {
const { signers: signerSets, verifierSetId } = await getWeightedSigners(config, chain, options);
printInfo('Setup params', JSON.stringify([operator, signerSets], null, 2));
Expand Down
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"@mysten/sui": "^1.3.0",
"@stellar/stellar-sdk": "^12.0.0-rc3",
"axios": "^1.6.2",
"path": "^0.12.7"
"path": "^0.12.7",
"toml": "^3.0.0"
},
"devDependencies": {
"@ledgerhq/hw-transport-node-hid": "^6.27.21",
Expand Down
18 changes: 12 additions & 6 deletions sui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Deploy the gateway package:
- By querying the signer set from the Amplifier contract (this only works if Amplifier contracts have been setup):

```bash
node sui/deploy-contract.js deploy axelar_gateway
node sui/deploy-contract.js deploy AxelarGateway
```

Note: the `minimumRotationDelay` is in `seconds` unit. The default value is `24 * 60 * 60` (1 day).
Expand All @@ -64,21 +64,21 @@ Use `--help` flag to see other setup params that can be overridden.
- For testing convenience, you can use the secp256k1 wallet as the signer set for the gateway.

```bash
node sui/deploy-contract.js deploy axelar_gateway --signers wallet --nonce test
node sui/deploy-contract.js deploy AxelarGateway --signers wallet --nonce test
```

- You can also provide a JSON object with a full signer set:

```bash
node sui/deploy-contract.js deploy axelar_gateway -e testnet --signers '{"signers": [{"pub_key": "0x020194ead85b350d90472117e6122cf1764d93bf17d6de4b51b03d19afc4d6302b", "weight": 1}], "threshold": 1, "nonce": "0x0000000000000000000000000000000000000000000000000000000000000000"}'
node sui/deploy-contract.js deploy AxelarGateway -e testnet --signers '{"signers": [{"pub_key": "0x020194ead85b350d90472117e6122cf1764d93bf17d6de4b51b03d19afc4d6302b", "weight": 1}], "threshold": 1, "nonce": "0x0000000000000000000000000000000000000000000000000000000000000000"}'
```

Upgrading Gateway:

To update the gateway run the following command:

```bash
node sui/deploy-contract.js upgrade axelar_gateway <policy>
node sui/deploy-contract.js upgrade AxelarGateway <policy>
```

policy should be one of the following:
Expand All @@ -92,13 +92,19 @@ Provide `--txFilePath` with `--offline` to generate tx data file for offline sig
Deploy the Gas Service package:

```bash
node sui/deploy-contract.js deploy gas_service
node sui/deploy-contract.js deploy GasService
```

Deploy the test GMP package:

```bash
node sui/deploy-test.js
node sui/deploy-contract.js deploy Test
```

Deploy the Operators package:

```bash
node sui/deploy-contract.js deploy Operators
```

Call Contract:
Expand Down
Loading
Loading