Skip to content

Commit

Permalink
feat: axelar local dev cosmos (#92)
Browse files Browse the repository at this point in the history
* chore: init

* chore: refactor setup

* chore: update docker stuff

* chore: fix docker commands

* chore: refactor docker

* chore: add more expect in stop testcase

* chore: export mnemonic

* chore: improve gitignore

* chore: return mnemonic to response

* chore: add more checks in test

* chore: init cosmos client

* chore: replace simd with cosmd

* chore: fix wasm startup script

* chore: update healtchecking url

* chore: setup tests and fix wrong mnemonic exposed

* chore: fix hardcoded denom

* chore: refactor CosmosClient

* chore: add response check

* chore: add wasm contract

* chore: reorder import

* chore: allow denom to be specified

* chore: update chain_name to chain_id

* chore: remove moniker in config

* chore: fix moniker

* chore: add denom to default config

* chore: refactor test

* chore: fix tests

* chore: update default denom

* chore: remove unnecessary confie files

* feat: add axelar container

* chore: fix denom issue

* chore: refactor docker for axelar and wasm

* chore: fix start script

* chore: fix start script to start all chains

* chore: stardardized logs

* chore: fix port issues

* chore: fix return rpcUrl and lcdIrl

* chore: fix tests

* chore: remove lcdPort and rpcPort in config

* chore: fix gas issue

* chore: added IBCRelayerClient

* chore: add axelar setup commands

* chore: updates tests

* chore: refactor scripts

* chore: add ws stop

* chore: update command

* chore: integrate axelar script with start command

* chore: remove conflict

* chore: remove empty function

* chore: add doc to RelayerAccountManager

* chore: fix docker path

* chore: add retry function and fix path

* chore: fix axelar setup bug

* chore: start implemented relayer

* feat: add AxelarRelayerService

* chore: add start script

* chore: add example contracts

* feat: complete evm -> cosmos

* chore: add wasm to evm test

* chore: update

* chore: fix relayer test

* chore: remove unnecessary tests

* chore: add tests for validating axelar chain states

* chore: add Path to provide consistent path values

* chore: remove unused functions

* chore: refactor CosmosClient

* chore: cleanup

* chore: replace readFileSync

* chore: refactor paths

* chore: refactor docker

* chore: fix channels bug

* chore: cleanup

* chore: bump version to 2.2.0-alpha.1

* chore: add build and test command

* chore: fix build error

* v2.2.0-alpha.2

* chore: fix dependencies

* v2.2.0-alpha.3

* chore: bump to alpha.3

* v2.2.0-alpha.4

* chore: remove jest from build

* v2.2.0-alpha.5

* chore: add check if docker command is installed

* chore: remove logs

* chore: add build:cosmos command

* v2.2.0-alpha.6

* chore: add docker to published files

* v2.2.0-alpha.7

* chore: clean up

* chore: handle existing ibc connection doesn't work

* v2.2.0-alpha.8

* chore: allow to pass mnemonic to create function

* v2.2.0-alpha.9

* chore: move create and import account to CosmosClient

* chore: catch error in relay function

* v2.2.0-alpha.10

* chore: start traefik first

* chore: bump version

* chore: update port to avoid conflict

* chore: bump version

* v2.2.0

* chore: update package.json

* feat: add waitTimeout

* chore: bump to alpha 13

* chore: add rpc wait timeout

* chore: bump version to 14

* chore: update docker base image

* chore: add makefile for managing docker images

* chore: update to alpha 16

* chore: fix bug cannot setup axelar chain

* chore: bump to alpha 17

* chore: add way to stop ws connection

* chore: bump to 18

* chore: add back close event listener

* v2.2.0-alpha.19

* chore: refactor AxelarListener

* v2.2.0-alpha.20

* chore: fix cannot remove close event on ws listener

* chore: bump to version 21

* chore: bump to 22

* add maxRetries

* chore: add start:cosmos script

* chore: fix build script

* chore: fix cosmos build error

* chore: update package.lock

chore: update package-lock

chore: fix fsevents

chore: fix interchain-token-service version

* chore: increase sleep duration

chore: start containers during jest setup

* chore: fix fetch is not defined

* chore: fix test

chore: test e2e

chore: fix typo

* feat: updated its once more (#102)

* updated its once more

* update version

* fix sui

* chore: run all tests

chore: update package-lock.json

chore: don't install optional dep

chore: update omit command

chore: update package-lock.json

chore: update  package-lock

chore: uncomment sui-test-validator

chore: update README.md

chore: update root README.md

chore: fix cache key

* v2.2.0-beta.1

* chore: allow configure gas price

* chore: add function doc for `CosmosClient`

* chore: update setup docs

* chore: fix gas price bug

* v2.2.0

* chore: fix need to call relay twice

* chore: refactor AxelarRelayerService to make it easier to use

* chore: remove testMnemonic

* chore: rename function and revert package-lock.json

* chore: update startAll to startChains

* chore: add README.md

* chore: fix test

* v2.2.0-alpha.26

* v2.2.0-alpha.27

* chore: add bech32

* chore:  update v28

* chore: update package.json

* chore: update package-lock.json

* chore: fix package-lock.json

* chore: bump version to 2.3.0

* chore: bump axelar-local-dev version for cosmos

* chore: fix deps install

---------

Co-authored-by: Foivos <[email protected]>
  • Loading branch information
npty and Foivos authored Mar 18, 2024
1 parent ae9a8cb commit a7221ce
Show file tree
Hide file tree
Showing 80 changed files with 5,145 additions and 1,490 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}

- name: Install dependencies
run: npm ci
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,4 @@ target/
**/*.rs.bk

# Near wasm contract
*.wasm
packages/axelar-local-dev-near/**/*.wasm
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ Welcome to the Axelar Local Development Environment! This monorepo contains esse
- [@axelar-network/axelar-local-dev-aptos](./packages/axelar-local-dev-aptos/)
- [@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 @@ -46,4 +48,5 @@ We currently support the following chain stacks:
- [Aptos](./packages/axelar-local-dev-aptos/)
- [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",
"version": "2.3.0",
"packages": [
"packages/*"
]
Expand Down
3,598 changes: 2,129 additions & 1,469 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,20 @@
"test": "lerna run test",
"update": "lerna update",
"clean": "lerna clean",
"start:cosmos": "lerna exec --scope=@axelar-network/axelar-local-dev-cosmos npm run start",
"test:core": "lerna exec --scope=@axelar-network/axelar-local-dev npm run test",
"test:near": "lerna exec --scope=@axelar-network/axelar-local-dev-near npm run test",
"test:aptos": "lerna exec --scope=@axelar-network/axelar-local-dev-aptos npm run test",
"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:multiversx": "lerna exec --scope=@axelar-network/axelar-local-dev-multiversx npm run build"
},
"devDependencies": {
Expand Down
7 changes: 4 additions & 3 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",
"version": "2.3.0",
"main": "dist/index.js",
"files": [
"dist/",
Expand All @@ -19,10 +19,11 @@
},
"dependencies": {
"@axelar-network/axelar-cgp-aptos": "^1.0.5",
"@axelar-network/axelar-local-dev": "2.2.0",
"@axelar-network/axelar-local-dev": "2.3.0",
"aptos": "1.3.16"
},
"author": "",
"license": "ISC",
"description": ""
"description": "",
"gitHead": "39d77bf2128077a615e6d3a5a4caf55e79f53b70"
}
5 changes: 3 additions & 2 deletions packages/axelar-local-dev-aptos/src/AptosRelayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ export class AptosRelayer extends Relayer {
const data = arrayify(
defaultAbiCoder.encode(
['uint256', 'bytes32[]', 'string[]', 'bytes[]'],
[to.chainId, commands.map((com) => com.commandId), commands.map((com) => com.name), commands.map((com) => com.encodedData)]
)
[to.chainId, commands.map((com) => com.commandId), commands.map((com) => com.name), commands.map((com) => com.encodedData)],
),
);
const signedData = await getSignedExecuteInput(data, to.operatorWallet);

Expand Down Expand Up @@ -180,6 +180,7 @@ export class AptosRelayer extends Relayer {
createCallContractCommand(commandId: string, relayData: RelayData, contractCallArgs: CallContractArgs): Command {
return AptosCommand.createAptosContractCallCommand(commandId, relayData, contractCallArgs);
}

createCallContractWithTokenCommand(): Command {
throw new Error('Method not implemented.');
}
Expand Down
8 changes: 8 additions & 0 deletions packages/axelar-local-dev-cosmos/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.env

# Docker
docker/**/.*
config.json
channel.json
connection.json
info/*
84 changes: 84 additions & 0 deletions packages/axelar-local-dev-cosmos/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Axelar Local Dev Cosmos

Axelar Local Dev Cosmos offers a comprehensive suite of tools for local development involving Cosmos chains. With this package, developers can easily deploy WebAssembly (Wasm) contracts on a Wasm chain and seamlessly send cross-chain messages to the Ethereum Virtual Machine (EVM) chain.

> **Note:** This package is currently under development. Some functionalities might be unstable.
## Prerequisite

- Docker installed and running on your local machine.

## Quick Start

### Start Wasm and Axelar Chain

Run the following command to pull the Docker image, set up the chains, and establish IBC connections:

```bash
npm run start
```

Alternatively, you can start the chains programmatically:

```ts
import { startChains } from "@axelar-network/axelar-local-dev-cosmos";

startChains();
```

## Running IBC Relayer and Axelar Event Listener

After setting up the chains, follow these steps to run the IBC Relayer and Axelar Event Listener:

**Create Axelar Relayer Service** for initailizing the IBC channels and keep listening to incoming events:

```ts
import {
defaultAxelarChainInfo,
AxelarRelayerService,
} from "@axelar-network/axelar-local-dev-cosmos";

const axelarRelayerService = await AxelarRelayerService.create(
defaultAxelarChainInfo
);
```

## Relaying Messages

To relay messages after they have been submitted on the Ethereum or Wasm chains, use the following method:

```ts
import {
evmRelayer,
createNetwork,
relay,
RelayerType,
} from "@axelar-network/axelar-local-dev";
import {
defaultAxelarChainInfo,
AxelarRelayerService,
} from "@axelar-network/axelar-local-dev-cosmos";

// Setup for Ethereum Network and Wasm chain relayer
const evmNetwork = await createNetwork({ name: "Ethereum" });
const wasmRelayer = await AxelarRelayerService.create(defaultAxelarChainInfo);

// Deploy contracts, send messages, and call the relay function
// ...

evmRelayer.setRelayer(RelayerType.Wasm, wasmRelayer);
await relay({
wasm: wasmRelayer,
evm: evmRelayer,
});

// Verify results on the destination chain
// ...
```

### Examples

- We currently support `Ethereum` as the destination chain for messages originating from the Wasm chain.
- For implementation details, see our [Local Example](docs/example.md) and [Axelar Example](https://github.com/axelarnetwork/axelar-examples/tree/feat/add-cosmos-examples/examples/cosmos/call-contract).

> The Local Example utilizes the same contracts as in the Axelar Examples.
14 changes: 14 additions & 0 deletions packages/axelar-local-dev-cosmos/docker/axelar/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Download axelar binary for alpine image
FROM ubuntu:22.04

# Define a build argument for architecture
ARG ARCH=amd64

RUN apt update && apt install -y wget

# Download axelar binary for alpine image
RUN wget https://github.com/axelarnetwork/axelar-core/releases/download/v0.34.1/axelard-linux-${ARCH}-v0.34.1 -O axelard \
&& chmod +x axelard \
&& mv axelard /usr/local/bin/

ENTRYPOINT ["/bin/sh"]
24 changes: 24 additions & 0 deletions packages/axelar-local-dev-cosmos/docker/axelar/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.PHONY: build-arm64 build-amd64 push-arm64 push-amd64 push manifest

IMAGE_NAME=nptytn/local-axelard

# Check if VERSION is set
ifndef VERSION
$(error VERSION is not set)
endif

push-arm64:
docker buildx build --platform linux/arm64 --build-arg ARCH=arm64 -t $(IMAGE_NAME):$(VERSION)-arm64 . --push

push-amd64:
docker buildx build --platform linux/amd64 --build-arg ARCH=amd64 -t $(IMAGE_NAME):$(VERSION)-amd64 . --push

push:
make push-arm64
make push-amd64

manifest:
docker manifest create $(IMAGE_NAME):$(VERSION) $(IMAGE_NAME):$(VERSION)-arm64 $(IMAGE_NAME):$(VERSION)-amd64
docker manifest annotate $(IMAGE_NAME):$(VERSION) $(IMAGE_NAME):$(VERSION)-arm64 --os linux --arch arm64
docker manifest annotate $(IMAGE_NAME):$(VERSION) $(IMAGE_NAME):$(VERSION)-amd64 --os linux --arch amd64
docker manifest push $(IMAGE_NAME):$(VERSION)
92 changes: 92 additions & 0 deletions packages/axelar-local-dev-cosmos/docker/axelar/bin/init_axelar.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/bin/sh

DENOM=uaxl
CHAIN_ID=axelar
MONIKER=axelar
HOME=/root/private/.axelar

# Removing the existing directory to start with a clean slate
rm -rf ${HOME}/*

DEFAULT_KEYS_FLAGS="--keyring-backend test --home ${HOME}"
ASSETS="100000000000000000000${DENOM}"

# Initializing a new blockchain with identifier ${CHAIN_ID} in the specified home directory
axelard init "$MONIKER" --chain-id ${CHAIN_ID} --home ${HOME} > /dev/null 2>&1 && echo "Initialized new blockchain with chain ID ${CHAIN_ID}"

# edit the app.toml file to enable the API and swagger
sed -i '/\[api\]/,/\[/ s/enable = false/enable = true/' "$HOME"/config/app.toml
sed -i '/\[api\]/,/\[/ s/swagger = false/swagger = true/' "$HOME"/config/app.toml

# staking/governance token is hardcoded in config, change this
sed -i "s/\"stake\"/\"$DENOM\"/" "$HOME"/config/genesis.json && echo "Updated staking token to $DENOM"


# Adding a new key named 'owner' with a test keyring-backend in the specified home directory
# and storing the mnemonic in the mnemonic.txt file
mnemonic=$(axelard keys add owner ${DEFAULT_KEYS_FLAGS} 2>&1 | tail -n 1)
echo ${mnemonic} | tr -d "\n" > ${HOME}/mnemonic.txt
echo "Added new key 'owner'"

gov1_mnemonic=$(axelard keys add gov1 ${DEFAULT_KEYS_FLAGS} 2>&1 | tail -n 1)
echo ${gov1_mnemonic} | tr -d "\n" > ${HOME}/mnemonic-gov1.txt
echo "Added new key 'gov1'"

gov2_mnemonic=$(axelard keys add gov2 ${DEFAULT_KEYS_FLAGS} 2>&1 | tail -n 1)
echo ${gov2_mnemonic} | tr -d "\n" > ${HOME}/mnemonic-gov2.txt
echo "Added new key 'gov2'"

$(axelard keys add governance --multisig "gov1,gov2" --multisig-threshold 1 --nosort ${DEFAULT_KEYS_FLAGS} 2>&1 | tail -n 1)
echo "Added new key 'governance'"

# Adding a new genesis account named 'owner' with an initial balance of 100000000000000000000 in the blockchain
axelard add-genesis-account owner ${ASSETS} \
--home ${HOME} \
--keyring-backend test > /dev/null 2>&1 && echo "Added 'owner' to genesis account"

axelard add-genesis-account gov1 ${ASSETS} \
--home ${HOME} \
--keyring-backend test > /dev/null 2>&1 && echo "Added 'gov1' to genesis account"

axelard add-genesis-account gov2 ${ASSETS} \
--home ${HOME} \
--keyring-backend test > /dev/null 2>&1 && echo "Added 'gov2' to genesis account"

axelard add-genesis-account governance ${ASSETS} \
--home ${HOME} \
--keyring-backend test > /dev/null 2>&1 && echo "Added 'governance' to genesis account"

axelard set-genesis-mint --inflation-min 0 --inflation-max 0 --inflation-max-rate-change 0 --home ${HOME}
axelard set-genesis-gov --minimum-deposit "100000000${DENOM}" --max-deposit-period 90s --voting-period 90s --home ${HOME}
axelard set-genesis-reward --external-chain-voting-inflation-rate 0 --home ${HOME}
axelard set-genesis-slashing --signed-blocks-window 35000 --min-signed-per-window 0.50 --home ${HOME} \
--downtime-jail-duration 600s --slash-fraction-double-sign 0.02 --slash-fraction-downtime 0.0001 --home ${HOME}
axelard set-genesis-snapshot --min-proxy-balance 5000000 --home ${HOME}
axelard set-genesis-staking --unbonding-period 168h --max-validators 50 --bond-denom "$DENOM" --home ${HOME}
axelard set-genesis-chain-params evm Ethereum --evm-network-name ethereum --evm-chain-id 5 --network ethereum --confirmation-height 1 --revote-locking-period 5 --home ${HOME}

GOV_1_KEY="$(axelard keys show gov1 ${DEFAULT_KEYS_FLAGS} -p)"
GOV_2_KEY="$(axelard keys show gov2 ${DEFAULT_KEYS_FLAGS} -p)"
axelard set-governance-key 1 "$GOV_1_KEY" "$GOV_2_KEY" --home ${HOME}
axelard validate-genesis --home ${HOME}

# Generating a new genesis transaction for 'owner' delegating 70000000${DENOM} in the blockchain with the specified chain-id
axelard gentx owner 70000000${DENOM} \
--home ${HOME} \
--keyring-backend test \
--moniker ${MONIKER} \
--chain-id ${CHAIN_ID} > /dev/null 2>&1 && echo "Generated genesis transaction for 'owner'"

# Collecting all genesis transactions to form the genesis block
axelard collect-gentxs \
--home ${HOME} > /dev/null 2>&1 && echo "Collected genesis transactions"

# Read the content of the local file and append it to the file inside the Docker container
cat /root/private/bin/libs/evm-rpc.toml >> "$HOME"/config/config.toml

# Starting the blockchain node with the specified home directory
axelard start --home ${HOME} \
--minimum-gas-prices 0${DENOM} \
--moniker ${MONIKER} \
--rpc.laddr "tcp://0.0.0.0:26657"

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

CHAIN_ID=axelar
HOME=/root/private/.axelar
DEFAULT_KEYS_FLAGS="--keyring-backend test --home ${HOME}"
CHAIN=$1
DIR="$(dirname "$0")"

if [ -z "$CHAIN" ]
then
echo "Chain name is required"
exit 1
fi

docker exec axelar /bin/bash -c "axelard tx nexus activate-chain ${CHAIN} --generate-only \
--chain-id ${CHAIN_ID} --from \$(axelard keys show governance -a ${DEFAULT_KEYS_FLAGS}) --home ${HOME} \
--output json --gas 500000 &> ${HOME}/unsigned_msg.json"
docker exec axelar /bin/bash -c "cat ${HOME}/unsigned_msg.json"

sh "$DIR/broadcast-unsigned-multi-tx.sh"
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

CHAIN_ID=axelar
HOME=/root/private/.axelar
DEFAULT_KEYS_FLAGS="--keyring-backend test --home ${HOME}"

## Sign unsigned transaction.
docker exec axelar /bin/bash -c "axelard tx sign ${HOME}/unsigned_msg.json --from gov1 \
--multisig \$(axelard keys show governance -a ${DEFAULT_KEYS_FLAGS}) \
--chain-id $CHAIN_ID ${DEFAULT_KEYS_FLAGS} &> ${HOME}/signed_tx.json"
docker exec axelar /bin/bash -c "cat ${HOME}/signed_tx.json"

## Multisign signed transaction.
docker exec axelar /bin/bash -c "axelard tx multisign ${HOME}/unsigned_msg.json governance ${HOME}/signed_tx.json \
--from owner --chain-id $CHAIN_ID ${DEFAULT_KEYS_FLAGS} &> ${HOME}/tx-ms.json"
docker exec axelar /bin/bash -c "cat ${HOME}/tx-ms.json"

## Broadcast multisigned transaction.
docker exec axelar /bin/bash -c "axelard tx broadcast ${HOME}/tx-ms.json ${DEFAULT_KEYS_FLAGS}"
Loading

0 comments on commit a7221ce

Please sign in to comment.