Skip to content

added another check for evm based case single step #12

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

Merged
merged 1 commit into from
Aug 1, 2023
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
10 changes: 7 additions & 3 deletions contracts/cw-ics20-latest/src/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,18 +652,22 @@ pub fn build_ibc_msg(
.range(storage, None, None, Order::Ascending)
.collect::<StdResult<Vec<(String, MappingMetadata)>>>()?;

let (is_evm_based, evm_destination) = destination.is_receiver_evm_based();
let (is_evm_based, evm_prefix) = destination.is_receiver_evm_based();
if is_evm_based {
let mapping = pair_mappings
.into_iter()
.find(|(key, _)| {
// eg: 'wasm.orai195269awwnt5m6c843q6w7hp8rt0k7syfu9de4h0wz384slshuzps8y7ccm/channel-29/eth-mainnet0x4c11249814f11b9346808179Cf06e71ac328c1b5'
// parse to get eth-mainnet0x...
// then collect eth-mainnet prefix, and compare with dest channel
// then we compare the dest channel with the pair mapping. They should match as well
convert_remote_denom_to_evm_prefix(
parse_ibc_denom_without_sanity_checks(key).unwrap_or_default(),
)
.eq(&evm_destination.destination_channel)
.eq(&evm_prefix)
&& parse_ibc_channel_without_sanity_checks(key)
.unwrap_or_default()
.eq(&destination.destination_channel)
})
.ok_or(StdError::generic_err("cannot find pair mappings"))?;
let msg: CosmosMsg = process_ibc_msg(
Expand All @@ -673,7 +677,7 @@ pub fn build_ibc_msg(
local_channel_id,
env.contract.address.as_str(),
remote_address, // use sender from ICS20Packet as receiver when transferring back because we have the actual receiver in memo for evm cases
Some(evm_destination.receiver),
Some(destination.receiver.clone()),
amount,
timeout,
reply_args,
Expand Down
2 changes: 1 addition & 1 deletion contracts/cw-ics20-latest/src/ibc_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ mod test {
)
.unwrap();
destination.receiver = "trx-mainnet0x73Ddc880916021EFC4754Cb42B53db6EAB1f9D64".to_string();
destination.destination_channel = "trx-mainnet".to_string();
destination.destination_channel = update.local_channel_id;
let result = build_ibc_msg(
deps.as_mut().storage,
env.clone(),
Expand Down
16 changes: 7 additions & 9 deletions packages/cw20-ics20-msg/src/receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,21 @@ impl DestinationInfo {
}
}

pub fn is_receiver_evm_based(&self) -> (bool, Self) {
let mut new_destination: DestinationInfo = DestinationInfo { ..self.clone() };
pub fn is_receiver_evm_based(&self) -> (bool, String) {
match self.receiver.split_once("0x") {
Some((evm_prefix, address)) => {
// has to have evm_prefix, otherwise we would not be able to know the real denom
if evm_prefix.is_empty() {
return (false, new_destination);
return (false, "".to_string());
}
// after spliting (removing 0x) => size 40 for eth address
if address.len() != 40usize {
return (false, new_destination);
return (false, "".to_string());
}
// we store evm-preifx as destination channel so we can filter in the pair mapping based on asset info
new_destination.destination_channel = evm_prefix.to_string();
(true, new_destination)
(true, evm_prefix.to_string())
}
None => (false, new_destination),
None => (false, "".to_string()),
}
}

Expand Down Expand Up @@ -76,9 +74,9 @@ fn test_is_evm_based() {
let d1 = DestinationInfo::from_str(
"channel-15/foobar0x3C5C6b570C1DA469E8B24A2E8Ed33c278bDA3222:usdt",
);
let (is_evm_based, d1) = d1.is_receiver_evm_based();
let (is_evm_based, prefix) = d1.is_receiver_evm_based();
assert_eq!(true, is_evm_based);
assert_eq!("foobar".to_string(), d1.destination_channel);
assert_eq!("foobar".to_string(), prefix);
assert_eq!(
"foobar0x3C5C6b570C1DA469E8B24A2E8Ed33c278bDA3222".to_string(),
d1.receiver
Expand Down