Skip to content

Commit

Permalink
Merge branch 'main' into chore/remove-gateway-token-support
Browse files Browse the repository at this point in the history
  • Loading branch information
milapsheth committed Oct 15, 2024
2 parents f74a329 + c0fb73d commit b6c03e3
Show file tree
Hide file tree
Showing 14 changed files with 689 additions and 151 deletions.
248 changes: 170 additions & 78 deletions contracts/interchain-token-service/src/abi.rs

Large diffs are not rendered by default.

158 changes: 126 additions & 32 deletions contracts/interchain-token-service/src/events.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cosmwasm_std::Attribute;
use axelar_wasm_std::event::EventExt;
use router_api::{Address, ChainNameRaw, CrossChainId};

use crate::primitives::Message;
Expand Down Expand Up @@ -45,11 +45,10 @@ fn make_message_event(
destination_chain: ChainNameRaw,
msg: Message,
) -> cosmwasm_std::Event {
let mut attrs = vec![
Attribute::new("cc_id", cc_id.to_string()),
Attribute::new("destination_chain", destination_chain.to_string()),
Attribute::new("message_type", msg.as_ref().to_string()),
];
let event = cosmwasm_std::Event::new(event_name)
.add_attribute("cc_id", cc_id.to_string())
.add_attribute("destination_chain", destination_chain.to_string())
.add_attribute("message_type", msg.as_ref().to_string());

match msg {
Message::InterchainTransfer {
Expand All @@ -58,42 +57,137 @@ fn make_message_event(
destination_address,
amount,
data,
} => {
attrs.extend(vec![
Attribute::new("token_id", token_id.to_string()),
Attribute::new("source_address", source_address.to_string()),
Attribute::new("destination_address", destination_address.to_string()),
Attribute::new("amount", amount.to_string()),
Attribute::new("data", data.to_string()),
]);
}
} => event
.add_attribute("token_id", token_id.to_string())
.add_attribute("source_address", source_address.to_string())
.add_attribute("destination_address", destination_address.to_string())
.add_attribute("amount", amount.to_string())
.add_attribute_if_some("data", data.map(|data| data.to_string())),
Message::DeployInterchainToken {
token_id,
name,
symbol,
decimals,
minter,
} => {
attrs.extend(vec![
Attribute::new("token_id", token_id.to_string()),
Attribute::new("name", name),
Attribute::new("symbol", symbol),
Attribute::new("decimals", decimals.to_string()),
Attribute::new("minter", minter.to_string()),
]);
}
} => event
.add_attribute("token_id", token_id.to_string())
.add_attribute("name", name)
.add_attribute("symbol", symbol)
.add_attribute("decimals", decimals.to_string())
.add_attribute_if_some("minter", minter.map(|minter| minter.to_string())),
Message::DeployTokenManager {
token_id,
token_manager_type,
params,
} => {
attrs.extend(vec![
Attribute::new("token_id", token_id.to_string()),
Attribute::new("token_manager_type", format!("{:?}", token_manager_type)),
Attribute::new("params", params.to_string()),
]);
}
} => event
.add_attribute("token_id", token_id.to_string())
.add_attribute(
"token_manager_type",
token_manager_type.as_ref().to_string(),
)
.add_attribute("params", params.to_string()),
}
}

#[cfg(test)]
mod test {
use cosmwasm_std::HexBinary;
use router_api::CrossChainId;

use crate::events::Event;
use crate::{Message, TokenId, TokenManagerType};

#[test]
fn message_received_with_all_attributes() {
let test_cases: Vec<Message> = vec![
Message::InterchainTransfer {
token_id: TokenId::new([1; 32]),
source_address: HexBinary::from([1; 32]).try_into().unwrap(),
destination_address: HexBinary::from([1, 2, 3, 4]).try_into().unwrap(),
amount: 1u64.try_into().unwrap(),
data: Some(HexBinary::from([1, 2, 3, 4]).try_into().unwrap()),
},
Message::DeployInterchainToken {
token_id: TokenId::new([1; 32]),
name: "Test".try_into().unwrap(),
symbol: "TST".try_into().unwrap(),
decimals: 18,
minter: Some(HexBinary::from([1; 32]).try_into().unwrap()),
},
Message::DeployTokenManager {
token_id: TokenId::new([1; 32]),
token_manager_type: TokenManagerType::MintBurn,
params: HexBinary::from([1, 2, 3, 4]).try_into().unwrap(),
},
];

let events: Vec<_> = test_cases
.into_iter()
.map(|message| {
let event = Event::MessageReceived {
cc_id: CrossChainId::new("source", "hash").unwrap(),
destination_chain: "destination".parse().unwrap(),
message,
};

cosmwasm_std::Event::new(event_name).add_attributes(attrs)
cosmwasm_std::Event::from(event)
})
.collect();

goldie::assert_json!(events);
}

#[test]
fn message_received_with_empty_attributes() {
let test_cases: Vec<Message> = vec![
Message::InterchainTransfer {
token_id: TokenId::new([1; 32]),
source_address: HexBinary::from([1; 32]).try_into().unwrap(),
destination_address: HexBinary::from([1, 2, 3, 4]).try_into().unwrap(),
amount: 1u64.try_into().unwrap(),
data: None,
},
Message::InterchainTransfer {
token_id: TokenId::new([1; 32]),
source_address: HexBinary::from([0u8]).try_into().unwrap(),
destination_address: HexBinary::from([0u8]).try_into().unwrap(),
amount: 1u64.try_into().unwrap(),
data: None,
},
Message::DeployInterchainToken {
token_id: TokenId::new([1; 32]),
name: "Test".try_into().unwrap(),
symbol: "TST".try_into().unwrap(),
decimals: 18,
minter: None,
},
Message::DeployInterchainToken {
token_id: TokenId::new([1; 32]),
name: "t".try_into().unwrap(),
symbol: "T".try_into().unwrap(),
decimals: 0,
minter: None,
},
Message::DeployTokenManager {
token_id: TokenId::new([1; 32]),
token_manager_type: TokenManagerType::MintBurn,
params: HexBinary::from([0u8]).try_into().unwrap(),
},
];

let events: Vec<_> = test_cases
.into_iter()
.map(|message| {
let event = Event::MessageReceived {
cc_id: CrossChainId::new("source", "hash").unwrap(),
destination_chain: "destination".parse().unwrap(),
message,
};

cosmwasm_std::Event::from(event)
})
.collect();

goldie::assert_json!(events);
}
}
29 changes: 11 additions & 18 deletions contracts/interchain-token-service/src/primitives.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt::Display;

use axelar_wasm_std::nonempty;
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{HexBinary, Uint256};
use cw_storage_plus::{Key, KeyDeserialize, Prefixer, PrimaryKey};
use router_api::ChainNameRaw;
use strum::FromRepr;
Expand All @@ -23,7 +23,7 @@ impl Display for TokenId {

/// The supported types of token managers that can be deployed by ITS contracts.
#[cw_serde]
#[derive(Eq, Copy, FromRepr)]
#[derive(Eq, Copy, FromRepr, strum::AsRefStr)]
#[repr(u8)]
pub enum TokenManagerType {
NativeInterchainToken,
Expand All @@ -44,27 +44,27 @@ pub enum Message {
/// The unique identifier of the token being transferred
token_id: TokenId,
/// The address that called the ITS contract on the source chain
source_address: HexBinary,
source_address: nonempty::HexBinary,
/// The address that the token will be sent to on the destination chain
/// If data is not empty, this address will given the token and executed as a contract on the destination chain
destination_address: HexBinary,
destination_address: nonempty::HexBinary,
/// The amount of tokens to transfer
amount: Uint256,
amount: nonempty::Uint256,
/// An optional payload to be provided to the destination address, if `data` is not empty
data: HexBinary,
data: Option<nonempty::HexBinary>,
},
/// Deploy a new interchain token on the destination chain
DeployInterchainToken {
/// The unique identifier of the token to be deployed
token_id: TokenId,
/// The name of the token
name: String,
name: nonempty::String,
/// The symbol of the token
symbol: String,
symbol: nonempty::String,
/// The number of decimal places the token supports
decimals: u8,
/// The address that will be the initial minter of the token (in addition to the ITS contract)
minter: HexBinary,
/// An additional minter of the token (optional). ITS on the external chain is always a minter.
minter: Option<nonempty::HexBinary>,
},
/// Deploy a new token manager on the destination chain
DeployTokenManager {
Expand All @@ -73,7 +73,7 @@ pub enum Message {
/// The type of token manager to deploy
token_manager_type: TokenManagerType,
/// The parameters to be provided to the token manager contract
params: HexBinary,
params: nonempty::HexBinary,
},
}

Expand Down Expand Up @@ -113,13 +113,6 @@ impl Message {
| Message::DeployTokenManager { token_id, .. } => token_id.clone(),
}
}

pub fn transfer_amount(&self) -> Option<Uint256> {
match self {
Message::InterchainTransfer { amount, .. } => Some(amount.to_owned()),
_ => None,
}
}
}

impl TokenId {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[
"0000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000005636861696e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"0000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000005636861696e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001600000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000017400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000154000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"0000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000005636861696e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000000000000000001010101010101010101010101010101010101010101010101010101010101010100000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000000a5465737420546f6b656e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003545354000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000021234000000000000000000000000000000000000000000000000000000000000",
"0000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000005636861696e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000ff00000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000012556e69636f646520546f6b656e20f09faa9900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007554e49f09f94a3000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002abcd000000000000000000000000000000000000000000000000000000000000",
"0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000005636861696e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000005636861696e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001600000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000017400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000154000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000005636861696e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000000000000000001010101010101010101010101010101010101010101010101010101010101010100000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000000a5465737420546f6b656e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003545354000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000021234000000000000000000000000000000000000000000000000000000000000",
"0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000005636861696e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000ff00000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000012556e69636f646520546f6b656e20f09faa9900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007554e49f09f94a3000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002abcd000000000000000000000000000000000000000000000000000000000000"
]
Loading

0 comments on commit b6c03e3

Please sign in to comment.