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): add test gmp command #301

Merged
merged 22 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from 21 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
12 changes: 11 additions & 1 deletion sui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,32 +121,36 @@ node sui/gateway.js rotate --signers wallet --proof wallet --currentNonce test -

Use the same nonce for `--currentNonce` as the `--nonce` when deploying the gateway.


### Multisig

To create a Multisig, follow the documentation [here](https://docs.sui.io/guides/developer/cryptography/multisig).

Get test SUI coins to your multisig address via a faucet:

```bash
sui client faucet --address <multisig address>
```

Get public keys for all wallets:

```bash
sui keytool list
```

Get private key of wallet using wallet alias or address:

```bash
sui keytool export --key-identity <alias/wallet address>
```

Get tx data for testing:

```bash
sui client transfer-sui --to <recipient address> --amount 1 --sui-coin-object-id <sui coin object id> --serialize-unsigned-transaction --gas-budget 77047880
```

To get sui coin object id

```bash
sui client gas <multisig address>
```
Expand All @@ -158,6 +162,7 @@ node sui/multisig.js --txBlockPath <path to unsigned tx block> --signatureFilePa
```

example txBlock file:

```
{
"bytes": "AAACACBC5cSnnYJrDEn9nSW1BDzPLLAbUJbYOeJnUgYl/b90..."
Expand All @@ -181,6 +186,7 @@ node sui/multisig.js --txBlockPath <path to unsigned tx block> --action execute
use --multisigKey `multisigKey` to override existing multisig info in chains config

example for adding multisig info to chains config:

```
{
"sui": {
Expand All @@ -207,6 +213,10 @@ example for adding multisig info to chains config:
}
```

GMP Demo:

Follow the instructions [here](docs/gmp.md)

## Troubleshooting

1. Move build error during the deployment step
Expand Down
3 changes: 0 additions & 3 deletions sui/deploy-contract.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const { saveConfig, printInfo } = require('../evm/utils');
const { Command, Argument, Option } = require('commander');
const { updateMoveToml } = require('@axelar-network/axelar-cgp-sui');
const { addBaseOptions } = require('./cli-utils');
const { getWallet, printWalletInfo } = require('./sign-utils');
const { loadSuiConfig, findPublishedObject, deployPackage } = require('./utils');
Expand All @@ -27,8 +26,6 @@ async function processCommand(contractName, config, chain, options) {
const published = await deployPackage(packageName, client, keypair);
const packageId = published.packageId;

updateMoveToml(packageName, packageId);

const contractObject = findPublishedObject(published, packageName, contractName);
const gasCollectorCapObject = findPublishedObject(published, packageName, 'GasCollectorCap');

Expand Down
32 changes: 14 additions & 18 deletions sui/deploy-test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
const { saveConfig, prompt, printInfo } = require('../evm/utils');
const { Command, Option } = require('commander');
const { Command } = require('commander');
const { loadSuiConfig, deployPackage, getBcsBytesByObjectId } = require('./utils');
const { singletonStruct } = require('./types-utils');
const { Transaction } = require('@mysten/sui/transactions');
const { ethers } = require('hardhat');
const {
constants: { HashZero },
} = ethers;
const { loadSuiConfig, deployPackage } = require('./utils');

const { addBaseOptions } = require('./cli-utils');
const { getWallet, printWalletInfo, broadcast } = require('./sign-utils');

// Parse bcs bytes from singleton object to get channel id
async function getChannelId(client, singletonObjectId) {
const bcsBytes = await getBcsBytesByObjectId(client, singletonObjectId);
const data = singletonStruct.parse(bcsBytes);
return '0x' + data.channel.id;
}

async function processCommand(config, chain, options) {
const [keypair, client] = getWallet(chain, options);

Expand Down Expand Up @@ -42,8 +45,10 @@ async function processCommand(config, chain, options) {

await broadcast(client, keypair, tx);

const channelId = await getChannelId(client, singleton.objectId);
npty marked this conversation as resolved.
Show resolved Hide resolved

chain.contracts.test.address = published.packageId;
chain.contracts.test.objects = { singleton: singleton.objectId };
chain.contracts.test.objects = { singleton: singleton.objectId, channelId };
npty marked this conversation as resolved.
Show resolved Hide resolved

printInfo('Test package deployed', JSON.stringify(chain.contracts.test, null, 2));
}
Expand All @@ -58,19 +63,10 @@ async function mainProcessor(options, processor) {
if (require.main === module) {
const program = new Command();

program.name('deploy-gateway').description('Deploys/publishes the Sui gateway');
program.name('deploy-test').description('Deploys/publishes the test module');

addBaseOptions(program);

program.addOption(new Option('--signers <signers>', 'JSON with the initial signer set').env('SIGNERS'));
program.addOption(new Option('--operator <operator>', 'operator for the gateway (defaults to the deployer address)'));
program.addOption(
new Option('--minimumRotationDelay <minimumRotationDelay>', 'minium delay for signer rotations (in ms)').default(
24 * 60 * 60 * 1000,
),
); // 1 day (in ms)
program.addOption(new Option('--domainSeparator <domainSeparator>', 'domain separator').default(HashZero));

program.action((options) => {
mainProcessor(options, processCommand);
});
Expand Down
63 changes: 63 additions & 0 deletions sui/docs/gmp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# GMP Demo

This document provides a step-by-step guide to execute GMP flow on the SUI network.

## Prerequisites

- Deploy gateway contract `node sui/deploy-gateway.js --signers wallet`
- Deploy gas service contract `node sui/deploy-contract.js GasService`
- Deploy test contract `node sui/deploy-test.js`

## Usage

### Send Command (Outgoing)

Send a messsage from SUI to the destination chain.

Example:
```bash
# node sui/gmp.js sendCall <destChain> <destContractAddress> <feeAmount> <payload>
node sui/gmp.js sendCall ethereum 0x6f24A47Fc8AE5441Eb47EFfC3665e70e69Ac3F05 0.1 0x1234
```

Note:
- `feeAmount` is the amount of SUI coins to be sent to the destination chain. The amount is in full units. For example, `0.1` means 0.1 SUI coins.

### Execute Command (Incoming)

Execute a message from the source chain at SUI application module.

1. Approve the incoming message

```bash
# node sui/gateway.js approve --proof ...... <source> <messageId> <sourceAddress> <destinationId> <payloadHash>
node sui/gateway.js approve --proof wallet ethereum 0x32034b47cb29d162d9d803cc405356f4ac0ec07fe847ace431385fe8acf3e6e5-2 0x4F4495243837681061C4743b74B3eEdf548D56A5 0x6ce0d81b412abca2770eddb1549c9fcff721889c3aab1203dc93866db22ecc4b 0x56570de287d73cd1cb6092bb8fdee6173974955fdef345ae579ee9f475ea7432
```

Note:
- `destinationId` is the channel id of test module. It can be retrieved from test module deployment output.
- `payloadHash` is the keccak256 hash of the payload. The payloadHash in the example `(0x565...7432)` is the hash of `0x1234`.

2. Execute the incoming message

This command will execute the message to the deployed test contract.
```bash
# node sui/gmp.js execute <source> <messageId> <sourceAddress> <payload>

# Example
node sui/gmp.js execute ethereum 0x32034b47cb29d162d9d803cc405356f4ac0ec07fe847ace431385fe8acf3e6e5-2 0x4F4495243837681061C4743b74B3eEdf548D56A5 0x1234
```

This command will execute the message to the contract that associated with the given `channelId`

```bash
# node sui/gmp.js execute <source> <messageId> <sourceAddress> <payload> --channelId <channelId>

# Example
node sui/gmp.js execute ethereum 0x32034b47cb29d162d9d803cc405356f4ac0ec07fe847ace431385fe8acf3e6e5-2 0x4F4495243837681061C4743b74B3eEdf548D56A5 0x1234 --channelId 0xcd5d203ea2cf1139af83939e3f74114a31fe682cc90f73a0d2647956bc3e5acf
```


Note:
- `source`, `sourceAddress` and `messageId` needed to be matched with the approve command.
- `payload` must be associated with the `payloadHash` in the approve command.
4 changes: 2 additions & 2 deletions sui/gas-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ async function payGas(keypair, client, gasServiceConfig, args, options) {

const gasServicePackageId = gasServiceConfig.address;

const { params } = options;
const refundAddress = options.refundAddress || walletAddress;
const params = options.params || '0x';

const [destinationChain, destinationAddress, channelId, payload] = args;
const unitAmount = options.amount;
Expand Down Expand Up @@ -51,8 +51,8 @@ async function addGas(keypair, client, gasServiceConfig, args, options) {

const gasServicePackageId = gasServiceConfig.address;

const { params } = options;
const refundAddress = options.refundAddress || walletAddress;
const params = options.params || '0x';

const [messageId] = args;
const unitAmount = options.amount;
Expand Down
Loading
Loading