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

Aptos Integration - Finish e2e #2776

Closed
wants to merge 14 commits into from
Closed
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ yarn-error.log
.idea
**/*.ignore
.vscode
move/**/build

2 changes: 2 additions & 0 deletions move/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build
.aptos
11 changes: 11 additions & 0 deletions move/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Write Move smart contracts for MessaingAPI service.

- MailBox Module

- ISM Module (Interchain Security Module)

- IGP Module (Interchain Gas PayMaster Module)

- Library Module ( MerkleTree, and some Structures)

Linked Issue: [Issue #1](https://github.com/movemntdev/hyperlane-move-extension/issues/1)
1 change: 1 addition & 0 deletions move/e2e/aptos-test-keys/localnet1/examples-keypair.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0xcca41831fd0a98c9d55c03f6ddbe543815720484067d9432e49d3b72ca9f62f6
1 change: 1 addition & 0 deletions move/e2e/aptos-test-keys/localnet1/igps-keypair.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x3785286238a72057e5b1f83300e052dc102158dbab66254ea8ef4f12d79bce33
1 change: 1 addition & 0 deletions move/e2e/aptos-test-keys/localnet1/isms-keypair.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0xe1434ec74549ce4c3d6eded91a0656f864b0982fdb196ef511921efc25dfc499
1 change: 1 addition & 0 deletions move/e2e/aptos-test-keys/localnet1/library-keypair.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0xa5aaf43ccc39754ee4ff452823280512a3396a8edc5b2757baea1d48f39e8890
1 change: 1 addition & 0 deletions move/e2e/aptos-test-keys/localnet1/mailbox-keypair.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x1ed2f723dc01765649659d935fa61a32725d52e147bb3e7b52e27914c8bd6205
1 change: 1 addition & 0 deletions move/e2e/aptos-test-keys/localnet1/router-keypair.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x864071c62098f7c1f97347e538183ffdfa310d302370aa4ff5d75423507d7265
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x6d5652c87468aca92ad0f3aac30720c5ce39bbccbd94bdefb3fb60ada2205560
1 change: 1 addition & 0 deletions move/e2e/aptos-test-keys/localnet2/examples-keypair.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x7490546a85595d4bbbf07bdd5e524aaccfc8fb5038e5790e6d4643b33de26ade
1 change: 1 addition & 0 deletions move/e2e/aptos-test-keys/localnet2/igps-keypair.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0xb0b11abcc3ae2eecb88180211773577ad572295f8bfddbd8f4c9d71abbdab08c
1 change: 1 addition & 0 deletions move/e2e/aptos-test-keys/localnet2/isms-keypair.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x3093c33117b6425e523e394b6fb214440e3e1dde9fc31e439904b423ae483669
1 change: 1 addition & 0 deletions move/e2e/aptos-test-keys/localnet2/library-keypair.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x6e6e2e0691cb73fbe074959459ac6ba451fa945ce4afcd0eba0a65982ce01001
1 change: 1 addition & 0 deletions move/e2e/aptos-test-keys/localnet2/mailbox-keypair.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x3072f00ae1de7011285b00d0f1009ecf24c51977904ab03e557cfb620400bd33
1 change: 1 addition & 0 deletions move/e2e/aptos-test-keys/localnet2/router-keypair.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0xad2826c16baaf24e23fcf27aaec34920463c1f8244ec0d2a3f6a425bad8f2de6
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0xbbcfb326abea4a900599a60d3390a7bee2237fe1b686a3cf06a3f860f80cf878
75 changes: 75 additions & 0 deletions move/e2e/compile-and-deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#cd router && aptos move compile
#cd ../examples && aptos move compile
#cd ../validator-announce && aptos move compile

# To make use of aptos cli
export PATH="/root/.local/bin:$PATH"

function aptos_init() {
aptos init --assume-yes --network custom --rest-url "http://0.0.0.0:8080/v1" --faucet-url "http://127.0.0.1:8081" --encoding hex --private-key-file $1
}

SHELL_DIR_PATH="$(dirname $0)";
PWD_DIR_PATH="$(pwd)"

FAUCET_URL="http://127.0.0.1:8081"
REST_API_URL="http://0.0.0.0:8080/v1"

LN1_EXAMPLES_ADDRESS="0xd1eaef049ac77e63f2ffefae43e14c1a73700f25cde849b6614dc3f3580123fc"
LN1_IGPS_ADDRESS="0xc5cb1f1ce6951226e9c46ce8d42eda1ac9774a0fef91e2910939119ef0c95568"
LN1_ISMS_ADDRESS="0x6bbae7820a27ff21f28ba5a4b64c8b746cdd95e2b3264a686dd15651ef90a2a1"
LN1_LIBRARY_ADDRESS="0xe818394d0f37cd6accd369cdd4e723c8dc4f9b8d2517264fec3d9e8cabc66541"
LN1_MAILBOX_ADDRESS="0x476307c25c54b76b331a4e3422ae293ada422f5455efed1553cf4de1222a108f"
LN1_ROUTER_ADDRESS="0xafce3ab5dc5d513c13e746cef4d65bf54f4abdcb34ea8ab0728d01c035610e3d"
LN1_VALIDATOR_ANNOUNCE_ADDRESS="0xa4a4eb4bab83650ba62cabe9ce429ad021b29c12f2fbf808768838255c7e191d"

LN2_EXAMPLES_ADDRESS="0xb2586f8d1347b988157b9e7aaea24d19064dfb596835145db1f93ff931948732"
LN2_IGPS_ADDRESS="0xea7d568d0705450331a8f09fd1c823faec91f4ef1c7e6ed4b12c0c53d0c08bc8"
LN2_ISMS_ADDRESS="0x39a36a558e955f29f60f9e7ad7e391510fcd6a744d8aec9b86952106bfc3e5e2"
LN2_LIBRARY_ADDRESS="0xc29e4ea7972150a5f3bd6531eba94907ce2be3b47eb17eaee40d381d2fd9122c"
LN2_MAILBOX_ADDRESS="0xd338e68ca12527e77cab474ee8ec91ffa4e6512ced9ae8f47e28c5c7c4804b78"
LN2_ROUTER_ADDRESS="0xd85669f567da6d24d296dccb7a7bfa1c666530eeb0e7b294791094e7a2dce8e3"
LN2_VALIDATOR_ANNOUNCE_ADDRESS="0xce1f65297828eaa6e460724a869317154f05cdde26619c0e5c0ca23aac3f69c7"

################# Fund contract signers and compile & publish contracts ####################
function fund_and_publish() {
cd $PWD_DIR_PATH
cd ../$1
aptos account fund-with-faucet --account $2 --url $REST_API_URL --faucet-url $FAUCET_URL
aptos move publish --url $REST_API_URL --private-key-file $3 --assume-yes $4
}

LN1_ADDRESS_MATHING="--named-addresses hp_library=$LN1_LIBRARY_ADDRESS,hp_validator=$LN1_VALIDATOR_ANNOUNCE_ADDRESS,hp_isms=$LN1_ISMS_ADDRESS,hp_igps=$LN1_IGPS_ADDRESS,hp_mailbox=$LN1_MAILBOX_ADDRESS,hp_router=$LN1_ROUTER_ADDRESS,examples=$LN1_EXAMPLES_ADDRESS"

fund_and_publish "library" $LN1_LIBRARY_ADDRESS "../e2e/aptos-test-keys/localnet1/library-keypair.json" "$LN1_ADDRESS_MATHING"
fund_and_publish "validator-announce" $LN1_VALIDATOR_ANNOUNCE_ADDRESS "../e2e/aptos-test-keys/localnet1/validator-announce-keypair.json" "$LN1_ADDRESS_MATHING"
fund_and_publish "isms" $LN1_ISMS_ADDRESS "../e2e/aptos-test-keys/localnet1/isms-keypair.json" "$LN1_ADDRESS_MATHING"
fund_and_publish "igps" $LN1_IGPS_ADDRESS "../e2e/aptos-test-keys/localnet1/igps-keypair.json" "$LN1_ADDRESS_MATHING"
fund_and_publish "router" $LN1_ROUTER_ADDRESS "../e2e/aptos-test-keys/localnet1/router-keypair.json" "$LN1_ADDRESS_MATHING"
fund_and_publish "mailbox" $LN1_MAILBOX_ADDRESS "../e2e/aptos-test-keys/localnet1/mailbox-keypair.json" "$LN1_ADDRESS_MATHING"
fund_and_publish "examples" $LN1_EXAMPLES_ADDRESS "../e2e/aptos-test-keys/localnet1/examples-keypair.json" "$LN1_ADDRESS_MATHING"

LN2_ADDRESS_MATHING="--named-addresses hp_library=$LN2_LIBRARY_ADDRESS,hp_validator=$LN2_VALIDATOR_ANNOUNCE_ADDRESS,hp_isms=$LN2_ISMS_ADDRESS,hp_igps=$LN2_IGPS_ADDRESS,hp_mailbox=$LN2_MAILBOX_ADDRESS,hp_router=$LN2_ROUTER_ADDRESS,examples=$LN2_EXAMPLES_ADDRESS"

fund_and_publish "library" $LN2_LIBRARY_ADDRESS "../e2e/aptos-test-keys/localnet2/library-keypair.json" "$LN2_ADDRESS_MATHING"
fund_and_publish "validator-announce" $LN2_VALIDATOR_ANNOUNCE_ADDRESS "../e2e/aptos-test-keys/localnet2/validator-announce-keypair.json" "$LN2_ADDRESS_MATHING"
fund_and_publish "isms" $LN2_ISMS_ADDRESS "../e2e/aptos-test-keys/localnet2/isms-keypair.json" "$LN2_ADDRESS_MATHING"
fund_and_publish "igps" $LN2_IGPS_ADDRESS "../e2e/aptos-test-keys/localnet2/igps-keypair.json" "$LN2_ADDRESS_MATHING"
fund_and_publish "router" $LN2_ROUTER_ADDRESS "../e2e/aptos-test-keys/localnet2/router-keypair.json" "$LN2_ADDRESS_MATHING"
fund_and_publish "mailbox" $LN2_MAILBOX_ADDRESS "../e2e/aptos-test-keys/localnet2/mailbox-keypair.json" "$LN2_ADDRESS_MATHING"
fund_and_publish "examples" $LN2_EXAMPLES_ADDRESS "../e2e/aptos-test-keys/localnet2/examples-keypair.json" "$LN2_ADDRESS_MATHING"

################# Fund signers ####################
function fund() {
aptos account fund-with-faucet --account $1 --url $REST_API_URL --faucet-url $FAUCET_URL
}

LN1_VALIDATOR_SIGNER_ADDRESS="0x21779477148b80ec9e123cc087a04ebbfb4a9de0ba64aa8f31510a0266423bb9"
LN1_RELAYER_SIGNER_ADDRESS="0x8b4376073a408ece791f4adc34a8afdde405bae071711dcbb95ca4e5d4f26c93"
LN2_VALIDATOR_SIGNER_ADDRESS="0xef7adb55757d157d1a1f76d5d04806aba4f9099a32260b9356d6dd53c177cd1e"
LN2_RELAYER_SIGNER_ADDRESS="0xcc7867910e0c3a1b8f304255123a4459c0222c78987d628f1effbf122f436b7b"

fund $LN1_VALIDATOR_SIGNER_ADDRESS
fund $LN1_RELAYER_SIGNER_ADDRESS
fund $LN2_VALIDATOR_SIGNER_ADDRESS
fund $LN2_RELAYER_SIGNER_ADDRESS
99 changes: 99 additions & 0 deletions move/e2e/init_states.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
FUNCTION=$1

LN1_EXAMPLES_ADDRESS="0xd1eaef049ac77e63f2ffefae43e14c1a73700f25cde849b6614dc3f3580123fc"
LN1_IGPS_ADDRESS="0xc5cb1f1ce6951226e9c46ce8d42eda1ac9774a0fef91e2910939119ef0c95568"
LN1_ISMS_ADDRESS="0x6bbae7820a27ff21f28ba5a4b64c8b746cdd95e2b3264a686dd15651ef90a2a1"
LN1_LIBRARY_ADDRESS="0xe818394d0f37cd6accd369cdd4e723c8dc4f9b8d2517264fec3d9e8cabc66541"
LN1_MAILBOX_ADDRESS="0x476307c25c54b76b331a4e3422ae293ada422f5455efed1553cf4de1222a108f"
LN1_ROUTER_ADDRESS="0xafce3ab5dc5d513c13e746cef4d65bf54f4abdcb34ea8ab0728d01c035610e3d"
LN1_VALIDATOR_ANNOUNCE_ADDRESS="0xa4a4eb4bab83650ba62cabe9ce429ad021b29c12f2fbf808768838255c7e191d"

LN2_EXAMPLES_ADDRESS="0xb2586f8d1347b988157b9e7aaea24d19064dfb596835145db1f93ff931948732"
# [178,88,111,141,19,71,185,136,21,123,158,122,174,162,77,25,6,77,251,89,104,53,20,93,177,249,63,249,49,148,135,50]
LN2_IGPS_ADDRESS="0xea7d568d0705450331a8f09fd1c823faec91f4ef1c7e6ed4b12c0c53d0c08bc8"
LN2_ISMS_ADDRESS="0x39a36a558e955f29f60f9e7ad7e391510fcd6a744d8aec9b86952106bfc3e5e2"
LN2_LIBRARY_ADDRESS="0xc29e4ea7972150a5f3bd6531eba94907ce2be3b47eb17eaee40d381d2fd9122c"
LN2_MAILBOX_ADDRESS="0xd338e68ca12527e77cab474ee8ec91ffa4e6512ced9ae8f47e28c5c7c4804b78"
LN2_ROUTER_ADDRESS="0xd85669f567da6d24d296dccb7a7bfa1c666530eeb0e7b294791094e7a2dce8e3"
LN2_VALIDATOR_ANNOUNCE_ADDRESS="0xce1f65297828eaa6e460724a869317154f05cdde26619c0e5c0ca23aac3f69c7"

LN1_VALIDATOR_SIGNER_ADDRESS="0x21779477148b80ec9e123cc087a04ebbfb4a9de0ba64aa8f31510a0266423bb9"
LN1_VALIDATOR_ETH_ADDY="0x04e7bc384e10353c714327f7b85b3d0ceb52bf6d"
LN1_RELAYER_SIGNER_ADDRESS="0x8b4376073a408ece791f4adc34a8afdde405bae071711dcbb95ca4e5d4f26c93"

LN2_VALIDATOR_SIGNER_ADDRESS="0xef7adb55757d157d1a1f76d5d04806aba4f9099a32260b9356d6dd53c177cd1e"
LN2_VALIDATOR_ETH_ADDY="0x8a9f9818b6ba031c5f2c8baf850942d4c98fa2ee"
LN2_RELAYER_SIGNER_ADDRESS="0xcc7867910e0c3a1b8f304255123a4459c0222c78987d628f1effbf122f436b7b"

APTOSDEVNET_DOMAIN=14477
APTOSTESTNET_DOMAIN=14402
APTOSLOCALNET1_DOMAIN=14411
APTOSLOCALNET2_DOMAIN=14412
BSCTESTNET_DOMAIN=97

REST_API_URL="http://0.0.0.0:8080/v1"
# VALIDATOR_ETH_SIGNER="0x598264ff31f198f6071226b2b7e9ce360163accd"

# inits
function init_ln1_modules() {
# To make use of aptos cli
export PATH="/root/.local/bin:$PATH"

cd "$(pwd)"
# init validator
cd ../validator-announce && aptos move run --assume-yes --function-id $LN1_VALIDATOR_ANNOUNCE_ADDRESS::validator_announce::initialize --args address:$LN1_MAILBOX_ADDRESS u32:$APTOSLOCALNET1_DOMAIN --url $REST_API_URL --private-key-file "../e2e/aptos-test-keys/localnet1/validator-announce-keypair.json"

# setting router
L1_ROUTER_CAP="$LN1_EXAMPLES_ADDRESS::hello_world::HelloWorld"
# enroll ln2 router
cd ../router && aptos move run --assume-yes --function-id $LN1_ROUTER_ADDRESS::router::enroll_remote_router --type-args $L1_ROUTER_CAP --args u32:$APTOSLOCALNET2_DOMAIN "u8:[178,88,111,141,19,71,185,136,21,123,158,122,174,162,77,25,6,77,251,89,104,53,20,93,177,249,63,249,49,148,135,50]" --url $REST_API_URL --private-key-file "../e2e/aptos-test-keys/localnet1/examples-keypair.json"

cd ../mailbox && aptos move run --assume-yes --function-id $LN1_MAILBOX_ADDRESS::mailbox::initialize --args u32:$APTOSLOCALNET1_DOMAIN --url $REST_API_URL --private-key-file "../e2e/aptos-test-keys/localnet1/mailbox-keypair.json"

# set ln2 validator to ism
cd ../isms && aptos move run --assume-yes --function-id $LN1_ISMS_ADDRESS::multisig_ism::set_validators_and_threshold --args 'address:["'$LN2_VALIDATOR_ETH_ADDY'"]' u64:1 u32:$APTOSLOCALNET2_DOMAIN --url $REST_API_URL --private-key-file "../e2e/aptos-test-keys/localnet1/isms-keypair.json"
}

function init_ln2_modules() {
# To make use of aptos cli
export PATH="/root/.local/bin:$PATH"

cd "$(pwd)"
# init validator
cd ../validator-announce && aptos move run --assume-yes --function-id $LN2_VALIDATOR_ANNOUNCE_ADDRESS::validator_announce::initialize --args address:$LN2_MAILBOX_ADDRESS u32:$APTOSLOCALNET2_DOMAIN --url $REST_API_URL --private-key-file "../e2e/aptos-test-keys/localnet2/validator-announce-keypair.json"

# setting router
L2_ROUTER_CAP="$LN2_EXAMPLES_ADDRESS::hello_world::HelloWorld"
# enroll ln1 router
cd ../router && aptos move run --assume-yes --function-id $LN2_ROUTER_ADDRESS::router::enroll_remote_router --type-args $L2_ROUTER_CAP --args u32:$APTOSLOCALNET1_DOMAIN "u8:[209,234,239,4,154,199,126,99,242,255,239,174,67,225,76,26,115,112,15,37,205,232,73,182,97,77,195,243,88,1,35,252]" --url $REST_API_URL --private-key-file "../e2e/aptos-test-keys/localnet2/examples-keypair.json"

cd ../mailbox && aptos move run --assume-yes --function-id $LN2_MAILBOX_ADDRESS::mailbox::initialize --args u32:$APTOSLOCALNET2_DOMAIN --url $REST_API_URL --private-key-file "../e2e/aptos-test-keys/localnet2/mailbox-keypair.json"

# set ln1 validator to ism
cd ../isms && aptos move run --assume-yes --function-id $LN2_ISMS_ADDRESS::multisig_ism::set_validators_and_threshold --args 'address:["'$LN1_VALIDATOR_ETH_ADDY'"]' u64:1 u32:$APTOSLOCALNET1_DOMAIN --url $REST_API_URL --private-key-file "../e2e/aptos-test-keys/localnet2/isms-keypair.json"
}

function send_hello_ln1_to_ln2() {

export PATH="/root/.local/bin:$PATH"

cd "$(pwd)"

cd ../examples && aptos move run --function-id $LN1_EXAMPLES_ADDRESS::hello_world::send_message --args u32:$APTOSLOCALNET2_DOMAIN string:"Hello World!" --url $REST_API_URL --private-key-file "../e2e/aptos-test-keys/localnet1/examples-keypair.json" --assume-yes
}
function send_hello_ln2_to_ln1() {

export PATH="/root/.local/bin:$PATH"

cd "$(pwd)"

cd ../examples && aptos move run --function-id $LN2_EXAMPLES_ADDRESS::hello_world::send_message --args u32:$APTOSLOCALNET1_DOMAIN string:"Hello World!" --url $REST_API_URL --private-key-file "../e2e/aptos-test-keys/localnet2/examples-keypair.json" --assume-yes
}

#`address:0x1 bool:true u8:0 u256:1234 "bool:[true, false]" 'address:[["0xace", "0xbee"], []]'`

if [[ $FUNCTION == "" ]]; then
echo "input function name"
else
$FUNCTION
fi
28 changes: 28 additions & 0 deletions move/examples/Move.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "examples"
version = "1.0.0"
authors = []

[addresses]
examples = "_"

[dev-addresses]

[dependencies.AptosFramework]
git = "https://github.com/aptos-labs/aptos-core.git"
rev = "testnet"
subdir = "aptos-move/framework/aptos-framework"

[dependencies.HyperlaneLibrary]
local = "../library"

[dependencies.HyperlaneISM]
local = "../isms"

[dependencies.HyperlaneMailBox]
local = "../mailbox"

[dependencies.HyperlaneRouter]
local = "../router"

[dev-dependencies]
86 changes: 86 additions & 0 deletions move/examples/sources/hello_world.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// !TODO: add remote router control, gas control
module examples::hello_world {
use std::vector;
use hp_router::router;
use hp_library::msg_utils;
use hp_mailbox::mailbox;

// Constants

const DOMAIN_BSCTESTNET: u32 = 97;
const DEFAULT_GAS_AMOUNT: u256 = 1_000_000_000;

// Errors
const ERROR_INVALID_DOMAIN: u64 = 0;

struct HelloWorld {}

struct State has key {
cap: router::RouterCap<HelloWorld>,
received_messages: vector<vector<u8>>
}

/// Initialize Module
fun init_module(account: &signer) {
let cap = router::init<HelloWorld>(account);
move_to<State>(account, State {
cap,
received_messages: vector::empty()
});
}

/// Send single message from aptos to bsctestnet
public entry fun send_message(
_account: &signer,
dest_domain: u32,
message: vector<u8>
) acquires State {
let state = borrow_global<State>(@examples);

mailbox::dispatch<HelloWorld>(
dest_domain,
message,
&state.cap
);
}

/// Send single message from aptos to bsctestnet
public entry fun send_message_with_gas(
account: &signer,
dest_domain: u32,
message: vector<u8>
) acquires State {
let state = borrow_global<State>(@examples);

mailbox::dispatch_with_gas<HelloWorld>(
account,
dest_domain,
message,
DEFAULT_GAS_AMOUNT,
&state.cap
);
}


/// Receive message from other chains
public entry fun handle_message(
message: vector<u8>,
metadata: vector<u8>
) acquires State {
let state = borrow_global_mut<State>(@examples);

mailbox::handle_message<HelloWorld>(
message,
metadata,
&state.cap
);

vector::push_back(&mut state.received_messages, msg_utils::body(&message));
}

#[test]
fun get_hello_world_bytes() {
aptos_std::debug::print<vector<u8>>(&b"Hello World!");
assert!(x"48656c6c6f20576f726c6421" == b"Hello World!", 0);
}
}
Loading