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

feat(minor-interchain-token-service)!: remove deploy token manager cmd #680

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
137 changes: 8 additions & 129 deletions contracts/interchain-token-service/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ sol! {
enum MessageType {
InterchainTransfer,
DeployInterchainToken,
DeployTokenManager,
SendToHub,
ReceiveFromHub,
}
Expand All @@ -39,13 +38,6 @@ sol! {
bytes minter;
}

struct DeployTokenManager {
uint256 messageType;
bytes32 tokenId;
uint256 tokenManagerType;
bytes params;
}

struct SendToHub {
uint256 messageType;
/// True destination chain name when sending a message from ITS edge source contract -> ITS Hub
Expand Down Expand Up @@ -110,17 +102,6 @@ impl Message {
minter: into_vec(minter).into(),
}
.abi_encode_params(),
Message::DeployTokenManager(primitives::DeployTokenManager {
token_id,
token_manager_type,
params,
}) => DeployTokenManager {
messageType: MessageType::DeployTokenManager.into(),
tokenId: FixedBytes::<32>::new(token_id.into()),
tokenManagerType: token_manager_type.into(),
params: Vec::<u8>::from(params).into(),
}
.abi_encode_params(),
}
.into()
}
Expand Down Expand Up @@ -164,24 +145,6 @@ impl Message {
}
.into()
}
MessageType::DeployTokenManager => {
let decoded = DeployTokenManager::abi_decode_params(payload, true)
.map_err(Error::AbiDecodeFailed)?;

let token_manager_type = u8::try_from(decoded.tokenManagerType)
.change_context(Error::InvalidTokenManagerType)?
.then(TokenManagerType::from_repr)
.ok_or_else(|| Error::InvalidTokenManagerType)?;

primitives::DeployTokenManager {
token_id: TokenId::new(decoded.tokenId.into()),
token_manager_type,
params: Vec::<u8>::from(decoded.params)
.try_into()
.map_err(Error::NonEmpty)?,
}
.into()
}
_ => bail!(Error::InvalidMessageType),
};

Expand Down Expand Up @@ -286,8 +249,8 @@ mod tests {
use router_api::ChainNameRaw;

use super::{DeployInterchainToken, InterchainTransfer};
use crate::abi::{DeployTokenManager, Error, MessageType, SendToHub};
use crate::{primitives, HubMessage, TokenManagerType};
use crate::abi::{Error, MessageType, SendToHub};
use crate::{primitives, HubMessage};

fn from_hex(hex: &str) -> nonempty::HexBinary {
HexBinary::from_hex(hex).unwrap().try_into().unwrap()
Expand Down Expand Up @@ -406,13 +369,6 @@ mod tests {
minter: vec![].into(),
}
.abi_encode_params(),
DeployTokenManager {
messageType: MessageType::DeployTokenManager.into(),
tokenId: FixedBytes::<32>::new([1u8; 32]),
tokenManagerType: TokenManagerType::NativeInterchainToken.into(),
params: vec![].into(),
}
.abi_encode_params(),
];

for message in test_cases {
Expand Down Expand Up @@ -515,70 +471,12 @@ mod tests {
}
}

#[test]
fn deploy_token_manager_encode_decode() {
let remote_chain = ChainNameRaw::from_str("chain").unwrap();

let cases = vec![
HubMessage::SendToHub {
destination_chain: remote_chain.clone(),
message: primitives::DeployTokenManager {
token_id: [0u8; 32].into(),
token_manager_type: TokenManagerType::NativeInterchainToken,
params: from_hex("00"),
}
.into(),
},
HubMessage::SendToHub {
destination_chain: remote_chain.clone(),
message: primitives::DeployTokenManager {
token_id: [1u8; 32].into(),
token_manager_type: TokenManagerType::Gateway,
params: from_hex("1234"),
}
.into(),
},
HubMessage::ReceiveFromHub {
source_chain: remote_chain.clone(),
message: primitives::DeployTokenManager {
token_id: [0u8; 32].into(),
token_manager_type: TokenManagerType::NativeInterchainToken,
params: from_hex("00"),
}
.into(),
},
HubMessage::ReceiveFromHub {
source_chain: remote_chain.clone(),
message: primitives::DeployTokenManager {
token_id: [1u8; 32].into(),
token_manager_type: TokenManagerType::Gateway,
params: from_hex("1234"),
}
.into(),
},
];

let encoded: Vec<_> = cases
.iter()
.map(|original| original.clone().abi_encode().to_hex())
.collect();

goldie::assert_json!(encoded);

for original in cases {
let encoded = original.clone().abi_encode();
let decoded = assert_ok!(HubMessage::abi_decode(&encoded));
assert_eq!(original, decoded);
}
}

#[test]
fn invalid_hub_message_type() {
let invalid_message_types = vec![
u8::MIN,
MessageType::InterchainTransfer as u8,
MessageType::DeployInterchainToken as u8,
MessageType::DeployTokenManager as u8,
MessageType::ReceiveFromHub as u8 + 1,
u8::MAX,
];
Expand All @@ -601,7 +499,6 @@ mod tests {
let invalid_message_types = vec![
MessageType::SendToHub as u8,
MessageType::ReceiveFromHub as u8,
MessageType::DeployTokenManager as u8 + 1,
u8::MAX,
];

Expand All @@ -620,11 +517,13 @@ mod tests {

#[test]
fn invalid_destination_chain() {
let message = DeployTokenManager {
messageType: MessageType::DeployTokenManager.into(),
let message = DeployInterchainToken {
messageType: MessageType::DeployInterchainToken.into(),
tokenId: FixedBytes::<32>::new([0u8; 32]),
tokenManagerType: TokenManagerType::NativeInterchainToken.into(),
params: vec![].into(),
name: "Test Token".into(),
symbol: "TST".into(),
decimals: 18,
minter: vec![].into(),
};

let payload = SendToHub {
Expand All @@ -638,26 +537,6 @@ mod tests {
assert_err_contains!(result, Error, Error::InvalidChainName);
}

#[test]
fn invalid_token_manager_type() {
let message = DeployTokenManager {
messageType: MessageType::DeployTokenManager.into(),
tokenId: FixedBytes::<32>::new([0u8; 32]),
tokenManagerType: U256::from(TokenManagerType::Gateway as u8 + 1),
params: vec![].into(),
};

let payload = SendToHub {
messageType: MessageType::SendToHub.into(),
destination_chain: "chain".into(),
message: message.abi_encode_params().into(),
}
.abi_encode_params();

let result = HubMessage::abi_decode(&payload);
assert_err_contains!(result, Error, Error::InvalidTokenManagerType);
}

#[test]
fn encode_decode_large_data() {
let large_data = vec![0u8; 1024 * 1024]; // 1MB of data
Expand Down
34 changes: 1 addition & 33 deletions contracts/interchain-token-service/src/contract/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use crate::events::Event;
use crate::primitives::HubMessage;
use crate::state::{self, is_chain_frozen, load_config, load_its_contract, TokenDeploymentType};
use crate::{
DeployInterchainToken, DeployTokenManager, InterchainTransfer, Message, TokenConfig, TokenId,
TokenInstance,
DeployInterchainToken, InterchainTransfer, Message, TokenConfig, TokenId, TokenInstance,
};

#[derive(thiserror::Error, Debug, IntoContractError)]
Expand Down Expand Up @@ -158,13 +157,6 @@ fn apply_to_hub(
apply_token_deployment(storage, &source_chain, &destination_chain, deploy_token)
.map(Message::DeployInterchainToken)?
}
Message::DeployTokenManager(deploy_manager) => apply_token_manager_deployment(
storage,
&source_chain,
&destination_chain,
deploy_manager,
)
.map(Message::DeployTokenManager)?,
}
.then(Result::Ok)
}
Expand Down Expand Up @@ -473,24 +465,6 @@ fn apply_token_deployment(
})
}

fn apply_token_manager_deployment(
storage: &mut dyn Storage,
source_chain: &ChainNameRaw,
destination_chain: &ChainNameRaw,
deploy_token_manager: DeployTokenManager,
) -> Result<DeployTokenManager, Error> {
save_token_instances(
storage,
source_chain,
destination_chain,
None,
None,
deploy_token_manager.token_id,
&deploy_token_manager.deployment_type(),
)
.map(|_| deploy_token_manager)
}

fn save_token_instances(
storage: &mut dyn Storage,
source_chain: &ChainNameRaw,
Expand Down Expand Up @@ -628,12 +602,6 @@ impl DeploymentType for DeployInterchainToken {
}
}

impl DeploymentType for DeployTokenManager {
fn deployment_type(&self) -> TokenDeploymentType {
TokenDeploymentType::CustomMinter
}
}

#[cfg(test)]
mod tests {
use assert_ok::assert_ok;
Expand Down
30 changes: 2 additions & 28 deletions contracts/interchain-token-service/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use axelar_wasm_std::event::EventExt;
use router_api::{Address, ChainNameRaw, CrossChainId};

use crate::primitives::Message;
use crate::{DeployInterchainToken, DeployTokenManager, InterchainTransfer};
use crate::{DeployInterchainToken, InterchainTransfer};

pub enum Event {
MessageReceived {
Expand Down Expand Up @@ -80,17 +80,6 @@ fn make_message_event(
.add_attribute("symbol", symbol)
.add_attribute("decimals", decimals.to_string())
.add_attribute_if_some("minter", minter.map(|minter| minter.to_string())),
Message::DeployTokenManager(DeployTokenManager {
token_id,
token_manager_type,
params,
}) => 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()),
}
}

Expand All @@ -100,10 +89,7 @@ mod test {
use router_api::CrossChainId;

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

#[test]
fn message_received_with_all_attributes() {
Expand All @@ -124,12 +110,6 @@ mod test {
minter: Some(HexBinary::from([1; 32]).try_into().unwrap()),
}
.into(),
DeployTokenManager {
token_id: TokenId::new([1; 32]),
token_manager_type: TokenManagerType::MintBurn,
params: HexBinary::from([1, 2, 3, 4]).try_into().unwrap(),
}
.into(),
];

let events: Vec<_> = test_cases
Expand Down Expand Up @@ -183,12 +163,6 @@ mod test {
minter: None,
}
.into(),
DeployTokenManager {
token_id: TokenId::new([1; 32]),
token_manager_type: TokenManagerType::MintBurn,
params: HexBinary::from([0u8]).try_into().unwrap(),
}
.into(),
];

let events: Vec<_> = test_cases
Expand Down
22 changes: 1 addition & 21 deletions contracts/interchain-token-service/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ pub enum Message {
InterchainTransfer(InterchainTransfer),
/// Deploy a new interchain token on the destination chain
DeployInterchainToken(DeployInterchainToken),
/// Deploy a new token manager on the destination chain
DeployTokenManager(DeployTokenManager),
}

#[cw_serde]
Expand Down Expand Up @@ -90,23 +88,6 @@ impl From<DeployInterchainToken> for Message {
}
}

#[cw_serde]
#[derive(Eq)]
pub struct DeployTokenManager {
/// The unique identifier of the token that the token manager will manage
pub token_id: TokenId,
/// The type of token manager to deploy
pub token_manager_type: TokenManagerType,
/// The parameters to be provided to the token manager contract
pub params: nonempty::HexBinary,
}

impl From<DeployTokenManager> for Message {
fn from(value: DeployTokenManager) -> Self {
Message::DeployTokenManager(value)
}
}

/// A message sent between ITS edge contracts and the ITS hub contract (defined in this crate).
/// `HubMessage` is used to route an ITS [`Message`] between ITS edge contracts on different chains via the ITS Hub.
#[cw_serde]
Expand Down Expand Up @@ -143,8 +124,7 @@ impl Message {
pub fn token_id(&self) -> TokenId {
match self {
Message::InterchainTransfer(InterchainTransfer { token_id, .. })
| Message::DeployInterchainToken(DeployInterchainToken { token_id, .. })
| Message::DeployTokenManager(DeployTokenManager { token_id, .. }) => *token_id,
| Message::DeployInterchainToken(DeployInterchainToken { token_id, .. }) => *token_id,
}
}
}
Expand Down
Loading
Loading