Skip to content

Commit

Permalink
feat(interchain-token-service): add its hub contract (#572)
Browse files Browse the repository at this point in the history
Co-authored-by: Sammy <[email protected]>
Co-authored-by: Christian Gorenflo <[email protected]>
Co-authored-by: Rareș <[email protected]>
Co-authored-by: CJ Cobb <[email protected]>
Co-authored-by: jcs47 <[email protected]>
Co-authored-by: João Sousa <[email protected]>
Co-authored-by: haiyizxx <[email protected]>
  • Loading branch information
8 people authored Sep 11, 2024
1 parent a73560d commit 0da965d
Show file tree
Hide file tree
Showing 34 changed files with 1,733 additions and 176 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/basic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ jobs:
- name: Build ITS release
working-directory: ./interchain-token-service
run: cargo build --release --target wasm32-unknown-unknown --locked
run: cargo build --release --lib --target wasm32-unknown-unknown --locked

# cosmwasm-check v1.3.x is used to check for compatibility with wasmvm v1.3.x used by Axelar
# Older rust toolchain is required to install cosmwasm-check v1.3.x
Expand Down
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion contracts/axelarnet-gateway/tests/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::str::FromStr;
use assert_ok::assert_ok;
use axelar_wasm_std::assert_err_contains;
use axelar_wasm_std::error::ContractError;
use axelar_wasm_std::response::inspect_response_msg;
use axelarnet_gateway::contract::{self, ExecuteError};
use axelarnet_gateway::msg::ExecuteMsg;
use axelarnet_gateway::StateError;
Expand All @@ -12,7 +13,6 @@ use router_api::msg::ExecuteMsg as RouterExecuteMsg;
use router_api::{Address, ChainName, CrossChainId, Message};

use crate::utils::messages;
use crate::utils::messages::inspect_response_msg;

mod utils;

Expand Down
2 changes: 1 addition & 1 deletion contracts/axelarnet-gateway/tests/query.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use assert_ok::assert_ok;
use axelar_wasm_std::response::inspect_response_msg;
use axelarnet_gateway::msg::QueryMsg;
use axelarnet_gateway::{contract, ExecutableMessage};
use cosmwasm_std::testing::{mock_dependencies, mock_env, MockApi, MockQuerier, MockStorage};
Expand All @@ -7,7 +8,6 @@ use router_api::msg::ExecuteMsg as RouterExecuteMsg;
use router_api::{ChainName, CrossChainId, Message};
use sha3::{Digest, Keccak256};

use crate::utils::messages::inspect_response_msg;
use crate::utils::params;

mod utils;
Expand Down
20 changes: 0 additions & 20 deletions contracts/axelarnet-gateway/tests/utils/messages.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use cosmwasm_std::{from_json, CosmosMsg, Response, WasmMsg};
use router_api::{CrossChainId, Message};
use serde::de::DeserializeOwned;
use sha3::Digest;

use crate::utils::params;
Expand All @@ -24,21 +22,3 @@ pub fn dummy_to_router(payload: &impl AsRef<[u8]>) -> Message {
payload_hash: sha3::Keccak256::digest(payload).into(),
}
}

pub fn inspect_response_msg<T>(response: Response) -> Result<T, ()>
where
T: DeserializeOwned,
{
let mut followup_messages = response.messages.into_iter();

let msg = followup_messages.next().ok_or(())?.msg;

if followup_messages.next().is_some() {
return Err(());
}

match msg {
CosmosMsg::Wasm(WasmMsg::Execute { msg, .. }) => from_json(msg).map_err(|_| ()),
_ => Err(()),
}
}
34 changes: 34 additions & 0 deletions interchain-token-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,56 @@ version = "0.1.0"
rust-version = { workspace = true }
edition = { workspace = true }

exclude = [
# Those files are rust-optimizer artifacts. You might want to commit them for convenience, but they should not be part of the source code publication.
"contract.wasm",
"hash.txt",
]

[lib]
crate-type = ["cdylib", "rlib"]

[[bin]]
name = "interchain-token-service-schema"
path = "src/bin/schema.rs"

[features]
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]
# use library feature to disable all instantiate/execute/query exports
library = []

[package.metadata.scripts]
optimize = """docker run --rm -v "$(pwd)":/code \
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/optimizer:0.16.0
"""

[dependencies]
alloy-primitives = { workspace = true }
alloy-sol-types = { workspace = true }
axelar-wasm-std = { workspace = true, features = ["derive"] }
axelarnet-gateway = { workspace = true, features = ["library"] }
client = { workspace = true }
cosmwasm-schema = { workspace = true }
cosmwasm-std = { workspace = true }
cw-storage-plus = { workspace = true }
cw2 = { workspace = true }
error-stack = { workspace = true }
hex = { workspace = true }
msgs-derive = { workspace = true }
report = { workspace = true }
router-api = { workspace = true }
schemars = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
sha3 = { workspace = true }
strum = { workspace = true }
thiserror = { workspace = true }

[dev-dependencies]
assert_ok = { workspace = true }
goldie = { workspace = true }

[lints]
Expand Down
15 changes: 15 additions & 0 deletions interchain-token-service/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Interchain Token Service Hub

## Overview

The Interchain Token Service (ITS) Hub contract is a crucial component of a cross-chain ITS protocol. It facilitates the transfer of tokens between different blockchains, manages token deployments, and maintains balance integrity across chains. It connects to ITS edge contracts on different chains (e.g. EVM ITS [contract](https://github.com/axelarnetwork/interchain-token-service)).

## Key Components

1. **ITS Message Processing**: Processes incoming ITS messages from trusted sources.
2. **Balance Tracking**: Ensures accurate token balances are maintained during cross-chain operations.
3. **ITS Address Registry**: Tracks the trusted ITS address for each chain for routing.

### Cross-chain messaging

The ITS Hub makes use of the Axelarnet gateway [contract](../contracts/axelarnet-gateway/) to facilitate sending or receiving cross-chain messages. Messages are sent via `CallContract`, and received when the Axelarnet gateway is executed (by a relayer / user) through `Execute`, which in turn executes ITS Hub's `Execute` method.
Loading

0 comments on commit 0da965d

Please sign in to comment.