Skip to content

Commit

Permalink
Merge branch 'main' into feat/axelar-local-dev-cosmos
Browse files Browse the repository at this point in the history
  • Loading branch information
npty committed Mar 12, 2024
2 parents e1e38d9 + ae9a8cb commit c0df27b
Show file tree
Hide file tree
Showing 45 changed files with 2,455 additions and 152 deletions.
25 changes: 24 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ jobs:
matrix:
os: [ubuntu-22.04]
arch: [amd64]
# Elasticsearch used by MultiversX test
services:
elasticsearch:
image: "docker.elastic.co/elasticsearch/elasticsearch:8.12.0"
env:
discovery.type: single-node
xpack.security.enabled: false
ports:
- "9200:9200"
steps:
- name: Download and Install Aptos Binary
run: |
Expand Down Expand Up @@ -37,6 +46,17 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3

- name: Download and Install Multiversx Binary
run: |
pip3 install multiversx-sdk-cli==v9.3.1
mxpy localnet setup
cp -rf ./packages/axelar-local-dev-multiversx/external.toml ./localnet/validator00/config
cp -rf ./packages/axelar-local-dev-multiversx/external.toml ./localnet/validator01/config
cp -rf ./packages/axelar-local-dev-multiversx/external.toml ./localnet/validator02/config
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Cache node_modules
uses: actions/cache@v3
with:
Expand All @@ -54,5 +74,8 @@ jobs:
run: |
nohup sh -c "sui-test-validator" > nohup.out 2> nohup.err < /dev/null &
nohup sh -c "aptos node run-local-testnet --with-faucet" > nohup.out 2> nohup.err < /dev/null &
sleep 10
nohup sh -c "mxpy localnet start" > nohup.out 2> nohup.err < /dev/null &
nohup sh -c "anvil" < /dev/null &
nohup sh -c "anvil -p 8546" < /dev/null &
sleep 30
npm run test
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ Welcome to the Axelar Local Development Environment! This monorepo contains esse
- [@axelar-network/axelar-local-dev-near](./packages/axelar-local-dev-near/)
- [@axelar-network/axelar-local-dev-sui](./packages/axelar-local-dev-sui/)
- [@axelar-network/axelar-local-dev-cosmos](./packages/axelar-local-dev-cosmos/)
- [@axelar-network/axelar-local-dev-multiversx](./packages/axelar-local-dev-multiversx/)

The `axelar-local-dev` package is all you need for cross-chain applications between EVM chains. However, if you wish to explore cross-chain applications between EVM chains and other chain stacks, check out our specific guides:

- [EVM <-> Aptos Integration Guide](./packages/axelar-local-dev-aptos/README.md#configuration)
- [EVM <-> Near Integration Guide](./packages/axelar-local-dev-near/README.md#configuration)
- [Evm <-> Sui Integration Guide](./packages/axelar-local-dev-sui/README.md)
- [Evm <-> Cosmos Integration Guide](./packages/axelar-local-dev-cosmos/README.md)
- [EVM <-> MultiversX Integration Guide](./packages/axelar-local-dev-multiversx/README.md#configuration)

## Prerequisites

Expand Down Expand Up @@ -47,3 +49,4 @@ We currently support the following chain stacks:
- [Near](./packages/axelar-local-dev-near/)
- [Sui](./packages/axelar-local-dev-sui/)
- [Cosmos](./packages/axelar-local-dev-cosmos/)
- [MultiversX](./packages/axelar-local-dev-multiversx/)
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"useWorkspaces": true,
"version": "2.2.0-alpha.28",
"version": "2.2.0",
"packages": [
"packages/*"
]
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
"test:sui": "lerna exec --scope=@axelar-network/axelar-local-dev-sui npm run test",
"test:cosmos": "lerna exec --scope=@axelar-network/axelar-local-dev-cosmos npm run test",
"test-e2e:cosmos": "lerna exec --scope=@axelar-network/axelar-local-dev-cosmos npm run test:e2e",
"test:multiversx": "lerna exec --scope=@axelar-network/axelar-local-dev-multiversx npm run test",
"build": "lerna run build",
"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:cosmos": "lerna exec --scope=@axelar-network/axelar-local-dev-cosmos npm run build"
"build:cosmos": "lerna exec --scope=@axelar-network/axelar-local-dev-cosmos npm run build",
"build:multiversx": "lerna exec --scope=@axelar-network/axelar-local-dev-multiversx npm run build"
},
"devDependencies": {
"lerna": "^6.6.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/axelar-local-dev-aptos/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@axelar-network/axelar-local-dev-aptos",
"version": "2.2.0-alpha.28",
"version": "2.2.0",
"main": "dist/index.js",
"files": [
"dist/",
Expand All @@ -19,7 +19,7 @@
},
"dependencies": {
"@axelar-network/axelar-cgp-aptos": "^1.0.5",
"@axelar-network/axelar-local-dev": "2.2.0-alpha.28",
"@axelar-network/axelar-local-dev": "2.2.0",
"aptos": "1.3.16"
},
"author": "",
Expand Down
16 changes: 16 additions & 0 deletions packages/axelar-local-dev-multiversx/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"env": {
"browser": true,
"jest": true,
"es2021": true
},
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"overrides": [],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["@typescript-eslint"],
"rules": {}
}
8 changes: 8 additions & 0 deletions packages/axelar-local-dev-multiversx/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
**/node_modules

src/types

# Build
artifacts

multiversxConfig.json
15 changes: 15 additions & 0 deletions packages/axelar-local-dev-multiversx/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"printWidth": 140,
"singleQuote": true,
"tabWidth": 4,
"useTabs": false,
"bracketSpacing": true,
"overrides": [
{
"files": "*.js",
"options": {
"trailingComma": "all"
}
}
]
}
72 changes: 72 additions & 0 deletions packages/axelar-local-dev-multiversx/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Axelar Local Dev: MultiversX Integration

Welcome to the Axelar Local Development MultiversX featuring MultiversX Integration. This package empowers developers to establish a local development environment for streamlined cross-chain communication utilizing the [MultiversX protocol](https://multiversx.com/).
Currently, the integration facilitates general message passing exclusively with the EVM chain.

## Prerequisite

0. You should have Docker & Docker Compose installed.

1. Install Mxpy CLI Tool

Download from here: https://docs.multiversx.com/sdk-and-tools/sdk-py/installing-mxpy/

> **Note**: Our examples are tested on Mxpy version `9.4.1`, but newer versions might also work.
2. Run Elasticsearch

`dcker-compose up -d` (in this folder)

3. Create & run a MultiversX Localnet

More info: https://docs.multiversx.com/developers/setup-local-testnet

```bash
mkdir -p .multiversx && cd .multiversx
mxpy localnet setup
mxpy localnet start
```

Stop the localnet. You will now have `localnet` folder populate with the subfolders `validator00`, `validator01`, `validator02`.

Copy the [external.toml](external.toml) from this folder into all the validators `config` folder (eg full path: `.multiversx/localnet/validator00/config`)
and overwrite the existing file.

This will setup connection to Elasticsearch to index events used by the MultiversXRelayer.

Start again the localnet: `mxpy localnet start`

## Installation

To install this package, use the following command:

```bash
npm install @axelar-network/axelar-local-dev-multiversx
```

## Configuration

To set up the MultiversX chain stack with the EVM chain stack, you need to modify the `createAndExport` function in your script. Create an `MultiversXRelayer` instance and incorporate it with your existing EVM relayer. Here's an example:

```ts
const multiversxRelayer = new MultiversXRelayer();
const relayers = { evm: new EvmRelayer({ multiversxRelayer }), multiversx: multiversxRelayer };
```

For more details on setting up the `createAndExport` function, check our [Standalone Environment Setup Guide](../../docs/guide_create_and_exports.md).

## API Reference

`MultiversXNetwork` is a generalization of `ProxyNetworkProvider` (avaliable in the `@multiversx/sdk-network-providers` package) that includes (among others that are mainly used for intrnal purposes):

- `deployAxelarFrameworkModules()`: Deploy Axelar related smart contracts found in `contracts`.
- `deployContract(contractCode: string, initArguments: TypedValue[]): Promise<string>`: A wrapper for deploying a contract from code with init arguments, deployed by `alice.pem` wallet. Returns the SC address.
- `signAndSendTransaction(transaction: Transaction, privateKey: UserSecretKey = this.ownerPrivateKey)`: A wrapper to easily sign, send and wait for a transaction to be completed.
- `callContract(address: string, func: string, args: TypedValue[] = []): Promise<ContractQueryResponse>)`: A wrapper to easily query a smart contract.

Additionaly we export two utility functions

- `createMultiversXNetwork(config?: {gatewayUrl: string})`: This deploys all the Axelar related smart contracts (`gas-service`, `auth`, `gateway`) if they are not deployed and saves their addresses to a config file. `gatewayUrl` defaults to `http://localhost:7950`
- `loadMultiversXNetwork(gatewayUrl = 'http://localhost:7950')`: This loads the preconfigured `MultiversXNetwork` by reading the contract addresses from the config file. Needs to be used after `createMultiversXNetwork` was called at least once by a process.

`createAndExport` (see above) will try to also call `createMultiversXNetwork` so that relaying works to MultiversX as well.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//SPDX-License-Identifier: MIT
pragma solidity >=0.8.9 <0.9.0;

import { AxelarExecutable } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/executable/AxelarExecutable.sol';
import { IAxelarGateway } from '@axelar-network/axelar-cgp-solidity/contracts/interfaces/IAxelarGateway.sol';
import { IAxelarGasService } from '@axelar-network/axelar-cgp-solidity/contracts/interfaces/IAxelarGasService.sol';

contract HelloWorld is AxelarExecutable {
string public value;
string public sourceChain;
string public sourceAddress;
IAxelarGasService gasService;

constructor(address _gateway, address _gasReceiver)
AxelarExecutable(_gateway)
{
gasService = IAxelarGasService(_gasReceiver);
}

event Executed();

// Call this function to update the value of this contract along with all its siblings'.
function setRemoteValue(
string memory destinationChain,
string memory destinationAddress,
string calldata message
) external payable {
bytes memory payload = abi.encodePacked(message);
if (msg.value > 0) {
gasService.payNativeGasForContractCall{value: msg.value}(
address(this),
destinationChain,
destinationAddress,
payload,
msg.sender
);
}
gateway.callContract(destinationChain, destinationAddress, payload);
}

// Handles calls created by setAndSend. Updates this contract's value
function _execute(
string calldata sourceChain_,
string calldata sourceAddress_,
bytes calldata payload_
) internal override {
(value) = abi.decode(payload_, (string));
sourceChain = sourceChain_;
sourceAddress = sourceAddress_;

emit Executed();
}
}
Binary file not shown.
Loading

0 comments on commit c0df27b

Please sign in to comment.