Skip to content

Commit

Permalink
chore: update sui doc
Browse files Browse the repository at this point in the history
  • Loading branch information
npty committed Sep 4, 2023
1 parent 67a85a8 commit babf73e
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 41 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
"build:core": "lerna exec --scope=@axelar-network/axelar-local-dev npm run build",
"build:near": "lerna exec --scope=@axelar-network/axelar-local-dev-near npm run build",
"build:aptos": "lerna exec --scope=@axelar-network/axelar-local-dev-aptos npm run build",
"build:sui": "lerna exec --scope=@axelar-network/axelar-local-dev-sui npm run build",
"build:sui_test": "lerna exec --scope=@axelar-network/axelar-local-dev-sui npm run build-contract"
"build:sui": "lerna exec --scope=@axelar-network/axelar-local-dev-sui npm run build"
},
"devDependencies": {
"lerna": "^6.6.1",
Expand Down
35 changes: 13 additions & 22 deletions packages/axelar-local-dev-sui/README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,24 @@
# Axelar Local Dev Sui
# Axelar Local Dev: Sui Integration

## Running Local Sui Network

1. Clone the repository
This package allows you to create a local development environment for cross-chain communication using the [Sui](https://sui.io/) protocol. At present, we support general message passing only with EVM chain

```bash
git clone https://github.com/MystenLabs/sui.git
```
## Prequisite

2. cd into sui directory and run the following commmand
You'll have to install `sui` and `sui-test-validator` in your local machine.

```bash
RUST_LOG="consensus=off" cargo run --bin sui-test-validator
```
To do this, please follow the guide from Sui [here](https://docs.sui.io/build/sui-local-network#install-sui-from-github)

> Important: Each time you start the sui-test-validator, the network starts as a new network with no previous data. The local network is not persistent.
> Note: This package has tested against version [devnet-v1.8.1](https://github.com/MystenLabs/sui/releases/tag/devnet-v1.8.1).
```
OPTIONS:
--epoch-duration-ms <EPOCH_DURATION_MS>
The duration for epochs (defaults to one minute) [default: 60000]
## Running Local Sui Network

--faucet-port <FAUCET_PORT>
Port to start the Sui faucet on [default: 9123]
To start running local sui network, run the following command.

--fullnode-rpc-port <FULLNODE_RPC_PORT>
Port to start the Fullnode RPC server on [default: 9000]
```
RUST_LOG="consensus=off" cargo run --bin sui-test-validator
```

See more: https://docs.sui.io/build/install#start-the-local-network
## Usage

##
1. [Relay Transaction to Sui](./docs/evm_to_sui.md)
2. [Relay Transaction to Evm](./docs/sui_to_evm.md)
18 changes: 7 additions & 11 deletions packages/axelar-local-dev-sui/__tests__/e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { SuiNetwork } from '../src/SuiNetwork';
import { SuiRelayer } from '../src/SuiRelayer';
import { Contract, ethers } from 'ethers';
import { TransactionBlock } from '@mysten/sui.js/transactions';
import { Network, createNetwork, deployContract } from '@axelar-network/axelar-local-dev';
import { EvmRelayer } from '@axelar-network/axelar-local-dev/dist/relay/EvmRelayer';
import { Network, createNetwork, deployContract, EvmRelayer, RelayerType } from '@axelar-network/axelar-local-dev';
import { SuiNetwork, SuiRelayer, initSui } from '@axelar-network/axelar-local-dev-sui';
import path from 'path';

describe('e2e', () => {
Expand All @@ -15,9 +13,9 @@ describe('e2e', () => {
const Executable = require('../artifacts/contracts/TestExecutable.sol/TestExecutable.json');

beforeEach(async () => {
client = new SuiNetwork();
await client.init();
relayer = new SuiRelayer(client);
const response = await initSui();
client = response.suiNetwork;
relayer = response.suiRelayer;

evmNetwork = await createNetwork({
name: evmChainName,
Expand Down Expand Up @@ -54,9 +52,8 @@ describe('e2e', () => {
});

it('should be able to relay from evm to sui', async () => {
const evmRelayer = new EvmRelayer({
suiRelayer: relayer,
});
const evmRelayer = new EvmRelayer();
evmRelayer.setRelayer(RelayerType.Sui, relayer);

// deploy a contract on Avalanche
evmContract = await deployContract(evmNetwork.userWallets[0], Executable, [
Expand All @@ -69,7 +66,6 @@ describe('e2e', () => {

// add sibling
await evmContract.addSibling('sui', `${response.packages[0].packageId}::hello_world`);

await evmContract.set('sui', 'hello from evm', {
value: 10000000,
});
Expand Down
40 changes: 40 additions & 0 deletions packages/axelar-local-dev-sui/docs/evm_to_sui.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## Relay from Evm to Sui

```ts
import { createSuiRelayer, RelayerType } from '@axelar-network/axelar-local-dev-sui';
import { ethers } from 'ethers';

// Initialize SuiRelayer and EvmRelayer
const { suiRelayer, suiClient } = await initSui();
const evmRelayer = new EvmRelayer();

// Set SuiRelayer to EvmRelayer to allow relaying transactions to Sui Network.
evmRelayer.setRelayer(RelayerType.sui, suiRelayer);

// Create Evm network named "Evm1"
const evmNetwork = await createNetwork({
name: 'Evm1',
});

// Deploy a contract on Evm1
const Executable = require('path/to/contract_json');
const evmContract = await deployContract(evmNetwork.userWallets[0], Executable, [
evmNetwork.gateway.address,
evmNetwork.gasService.address,
]);

// Deploy a module on Sui
const pathToModule = '..'; // Specify a path to your move folder containing `Move.toml` file.
const response = await suiClient.deploy(path.join(__dirname, pathToModule));
// Tips: You can print the transaction digest from `response` and see deployment details here: https://suiexplorer.com/?network=local

// ### Execute a function on Evm contract
// We use the [TestExecutable contract](../contracts/TestExecutable.sol) as a reference here.
await evmContract.addSibling('sui', `${response.packages[0].packageId}::hello_world`);
await evmContract.set('sui', 'hello from evm', {
value: 10000000, // hardcoded relayer fee, we don't check for the fee right now, so you can specify any fee
});

// Relay the transaction to Sui
await evmRekayer.relay();
```
44 changes: 44 additions & 0 deletions packages/axelar-local-dev-sui/docs/sui_to_evm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
## Relay from Sui to Evm

```ts
import { createSuiRelayer, RelayerType } from '@axelar-network/axelar-local-dev-sui';
import { ethers } from 'ethers';

// Initialize SuiRelayer and EvmRelayer
const { suiRelayer, suiClient } = await initSui();
const evmRelayer = new EvmRelayer();

// Set SuiRelayer to EvmRelayer to allow relaying transactions to Sui Network.
evmRelayer.setRelayer(RelayerType.sui, suiRelayer);

// Create Evm network named "Evm1"
const evmNetwork = await createNetwork({
name: 'Evm1',
});

// Deploy a contract on Evm1
const Executable = require('path/to/contract_json');
const evmContract = await deployContract(evmNetwork.userWallets[0], Executable, [
evmNetwork.gateway.address,
evmNetwork.gasService.address,
]);

// Deploy a module on Sui
const pathToModule = '..'; // Specify a path to your move folder containing `Move.toml` file.
const response = await suiClient.deploy(path.join(__dirname, pathToModule));
// Tips: You can print the transaction digest from `response` and see deployment details here: https://suiexplorer.com/?network=local

// ### Execute a function on Sui module.
// We use the [hello_world module](./move/sample/sources/hello_world.move) as a reference here.
const tx = new TransactionBlock();
const payload = ethers.utils.defaultAbiCoder.encode(['string'], ['hello from sui']);
tx.moveCall({
target: `${response.packages[0].packageId}::hello_world::call`, // Note: use the response object above
arguments: [tx.pure(evmNetwork.name), tx.pure(evmContract.address), tx.pure(payload), tx.pure(1)],
});
// Send a transaction to Sui network.
await client.execute(tx);

// Relay the transaction to chain Evm1
await suiRelayer.relay();
```
2 changes: 1 addition & 1 deletion packages/axelar-local-dev-sui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"test": "jest",
"clean": "rm -rf src/types dist artifacts",
"prettier": "prettier --write 'src/**/*.ts'",
"build": "npm run clean && npm run build-ts",
"build": "npm run clean && npm run build-ts && npm run build-contract",
"build-ts": "tsc",
"build-contract": "hardhat compile",
"build-sui": "cd move && sui move build"
Expand Down
36 changes: 31 additions & 5 deletions packages/axelar-local-dev-sui/src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,35 @@ import { SuiRelayer } from './SuiRelayer';
export let suiNetwork: SuiNetwork;
export let suiRelayer: SuiRelayer;

export async function createSuiRelayer(nodeUrl?: string, faucetUrl?: string): Promise<SuiRelayer> {
suiNetwork = new SuiNetwork(nodeUrl, faucetUrl);
await suiNetwork.init();
suiRelayer = new SuiRelayer(suiNetwork);
return suiRelayer;
/**
* Initializes the Sui network and relayer instances.
*
* @param nodeUrl - The URL of the node, optional parameter. If not provided, SuiNetwork will use its default value.
* @param faucetUrl - The URL of the faucet, optional parameter. If not provided, SuiNetwork will use its default value.
*
* @returns A promise that resolves to an object containing initialized instances of SuiNetwork and SuiRelayer.
*
* @throws Will throw an error if the initialization of SuiNetwork or SuiRelayer fails.
*/
export async function initSui(
nodeUrl?: string,
faucetUrl?: string,
): Promise<{
suiNetwork: SuiNetwork;
suiRelayer: SuiRelayer;
}> {
try {
suiNetwork = new SuiNetwork(nodeUrl, faucetUrl);

await suiNetwork.init();

suiRelayer = new SuiRelayer(suiNetwork);

return { suiNetwork, suiRelayer };
} catch (error) {
console.error('Initialization failed due to the following error:', error);
throw new Error(
`Initialization failed: Please check if the node and faucet URLs are correctly configured and running. You may need to review the logs or documentation for more details.`,
);
}
}

0 comments on commit babf73e

Please sign in to comment.