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

refactor(minor-axelarnet-gateway): simplify the initial implementation #583

Merged
merged 28 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
56ffd0d
refactor(axelarnet-gateway-minor): simplify the initial implementation
cgorenflo Aug 13, 2024
6e98c71
Merge branch 'refs/heads/main' into refactor-axelarnet-gateway
cgorenflo Aug 13, 2024
ecd5724
clippy
cgorenflo Aug 13, 2024
a5a674c
improvements and panic
cgorenflo Aug 13, 2024
d4d6696
refactor(axelarnet-gateeway): improve contract structure
cgorenflo Aug 22, 2024
d1a4c6b
improve naming
cgorenflo Aug 22, 2024
3054ae5
Merge remote-tracking branch 'refs/remotes/origin/main' into refactor…
cgorenflo Aug 22, 2024
42953ac
merge conflicts
cgorenflo Aug 22, 2024
65d4dbb
finish tests
cgorenflo Aug 23, 2024
020d0eb
remove commented out lines
cgorenflo Aug 23, 2024
1ed4353
fix tests
cgorenflo Aug 23, 2024
61da7ea
fix tests
cgorenflo Aug 23, 2024
0827d36
lint
cgorenflo Aug 23, 2024
8eef118
revert gateway changes
cgorenflo Aug 23, 2024
14b135e
Merge branch 'main' into refactor-axelarnet-gateway
cgorenflo Aug 23, 2024
d258975
Merge branch 'main' into refactor-axelarnet-gateway
cgorenflo Aug 23, 2024
8ad0661
Merge remote-tracking branch 'refs/remotes/origin/main' into refactor…
cgorenflo Aug 29, 2024
31d21bb
fixes from comments
cgorenflo Aug 29, 2024
b965022
lint
cgorenflo Aug 29, 2024
b0867a7
clippy
cgorenflo Aug 29, 2024
8b91e4c
remove goldie
cgorenflo Aug 29, 2024
af5c11c
readd goldie
cgorenflo Aug 29, 2024
101961a
remove goldie
cgorenflo Aug 29, 2024
095cd76
remove goldie
cgorenflo Aug 29, 2024
cfbd7a3
panic if config is missing
cgorenflo Aug 29, 2024
c2f0ad9
fix bug
cgorenflo Aug 29, 2024
2880411
address validation function comment
cgorenflo Aug 29, 2024
1619e05
fix bug
cgorenflo Aug 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 51 additions & 14 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ strum = { version = "0.25", default-features = false, features = ["derive"] }
interchain-token-service = { version = "^0.1.0", path = "interchain-token-service" }
goldie = { version = "0.5" }
axelarnet-gateway = { version = "^0.1.0", path = "contracts/axelarnet-gateway" }
cw-multi-test = "1.2.0"

[workspace.lints.clippy]
arithmetic_side_effects = "deny"
Expand Down
4 changes: 3 additions & 1 deletion contracts/axelarnet-gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ cosmwasm-std = { workspace = true }
cw-storage-plus = { workspace = true }
cw2 = { workspace = true }
error-stack = { workspace = true }
itertools = { workspace = true }
msgs-derive = { workspace = true }
report = { workspace = true }
router-api = { workspace = true }
Expand All @@ -48,7 +49,8 @@ sha3 = { workspace = true }
thiserror = { workspace = true }

[dev-dependencies]
cw-multi-test = "0.15.1"
cw-multi-test = { workspace = true }
goldie = { workspace = true }

[lints]
workspace = true
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use axelar_wasm_std::address;
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{HexBinary, WasmMsg};
use cosmwasm_std::{Deps, HexBinary, WasmMsg};
use router_api::{Address, CrossChainId};

/// `AxelarExecutableMsg` is a struct containing the args used by the axelarnet gateway to execute a destination contract on Axelar.
Expand All @@ -11,39 +12,47 @@ pub struct AxelarExecutableMsg {
pub payload: HexBinary,
}

/// Crate-specific `ExecuteMsg` type wraps the `AxelarExecutableMsg` for the AxelarExecutable client.
/// By convention, amplifier-compatible contracts must expose this `Execute` variant.
/// Due to identical json serialization, we can imitate it here so the gateway can call it.
#[cw_serde]
pub enum AxelarExecutableExecuteMsg {
pub enum ExecuteMsg {
/// Execute the message at the destination contract with the corresponding payload.
Execute(AxelarExecutableMsg),
}

impl<'a> From<client::Client<'a, AxelarExecutableExecuteMsg, ()>> for AxelarExecutableClient<'a> {
fn from(client: client::Client<'a, AxelarExecutableExecuteMsg, ()>) -> Self {
AxelarExecutableClient { client }
}
pub struct CrossChainExecutor<'a> {
client: client::Client<'a, ExecuteMsg, ()>,
}

pub struct AxelarExecutableClient<'a> {
client: client::Client<'a, AxelarExecutableExecuteMsg, ()>,
}
impl<'a> CrossChainExecutor<'a> {
pub fn new(deps: Deps<'a>, destination: &str) -> error_stack::Result<Self, address::Error> {
let destination = address::validate_cosmwasm_address(deps.api, destination)?;
Ok(CrossChainExecutor {
client: client::Client::new(deps.querier, destination),
})
}

impl<'a> AxelarExecutableClient<'a> {
pub fn execute(
pub fn prepare_execute_msg(
cgorenflo marked this conversation as resolved.
Show resolved Hide resolved
&self,
cc_id: CrossChainId,
source_address: Address,
payload: HexBinary,
) -> WasmMsg {
self.client
.execute(&AxelarExecutableExecuteMsg::Execute(AxelarExecutableMsg {
cgorenflo marked this conversation as resolved.
Show resolved Hide resolved
.execute(&ExecuteMsg::Execute(AxelarExecutableMsg {
cc_id,
source_address,
payload,
}))
}
}

impl<'a> From<client::Client<'a, ExecuteMsg, ()>> for CrossChainExecutor<'a> {
cgorenflo marked this conversation as resolved.
Show resolved Hide resolved
fn from(client: client::Client<'a, ExecuteMsg, ()>) -> Self {
CrossChainExecutor { client }
}
}

#[cfg(test)]
mod test {
use cosmwasm_std::testing::MockQuerier;
Expand All @@ -54,20 +63,21 @@ mod test {
#[test]
fn execute_message() {
let (querier, addr) = setup();
let client: AxelarExecutableClient =
let client: CrossChainExecutor =
client::Client::new(QuerierWrapper::new(&querier), addr.clone()).into();

let cc_id = CrossChainId::new("source-chain", "message-id").unwrap();
let source_address: Address = "source-address".parse().unwrap();
let payload = HexBinary::from(vec![1, 2, 3]);

let msg = client.execute(cc_id.clone(), source_address.clone(), payload.clone());
let msg =
client.prepare_execute_msg(cc_id.clone(), source_address.clone(), payload.clone());

assert_eq!(
msg,
WasmMsg::Execute {
contract_addr: addr.to_string(),
msg: to_json_binary(&AxelarExecutableExecuteMsg::Execute(AxelarExecutableMsg {
msg: to_json_binary(&ExecuteMsg::Execute(AxelarExecutableMsg {
cc_id,
source_address,
payload,
Expand Down
5 changes: 5 additions & 0 deletions contracts/axelarnet-gateway/src/clients/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mod external;
mod gateway;

pub use external::*;
pub use gateway::Client as GatewayClient;
cgorenflo marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading