Skip to content

Commit a39a69d

Browse files
committed
fixed ORAI to ORAI single step error no swap ops
1 parent a6a1903 commit a39a69d

File tree

3 files changed

+87
-12
lines changed

3 files changed

+87
-12
lines changed
222 Bytes
Binary file not shown.

contracts/cw-ics20-latest/src/ibc.rs

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -449,17 +449,15 @@ pub fn get_follow_up_msgs(
449449
) -> Result<(Vec<CosmosMsg>, String), ContractError> {
450450
let config = CONFIG.load(storage)?;
451451
let mut cosmos_msgs: Vec<CosmosMsg> = vec![];
452-
if memo.is_empty() {
453-
return Ok((
454-
vec![send_amount(to_send, receiver.to_string(), None)],
455-
"".to_string(),
456-
));
457-
}
458452
let destination: DestinationInfo = DestinationInfo::from_str(memo);
459-
// if destination denom, then we simply transfers cw20 to the receiver address.
460-
if destination.destination_denom.is_empty() {
453+
if is_follow_up_msgs_only_send_amount(
454+
&memo,
455+
&destination.destination_denom,
456+
&initial_receive_asset_info.to_string(),
457+
&config.fee_denom,
458+
) {
461459
return Ok((
462-
vec![send_amount(to_send, destination.receiver.clone(), None)],
460+
vec![send_amount(to_send, receiver.to_string(), None)],
463461
"".to_string(),
464462
));
465463
}
@@ -528,6 +526,32 @@ pub fn get_follow_up_msgs(
528526
return Ok((cosmos_msgs, ibc_error_msg));
529527
}
530528

529+
pub fn is_follow_up_msgs_only_send_amount(
530+
memo: &str,
531+
destination_denom: &str,
532+
initial_receive_asset_info: &str,
533+
fee_denom: &str,
534+
) -> bool {
535+
if memo.is_empty() {
536+
return true;
537+
}
538+
// if destination denom, then we simply transfers cw20 to the receiver address.
539+
if destination_denom.is_empty() {
540+
return true;
541+
}
542+
// special case, if inital receiver asset info is native orai (fee denom in this case), and the destination is also orai => we just transfer instead of swapping
543+
// the reason is that orai is the central asset info for swapping. There's no ORAI/ORAI pair
544+
if initial_receive_asset_info.eq(&AssetInfo::NativeToken {
545+
denom: fee_denom.to_string(),
546+
}
547+
.to_string())
548+
&& destination_denom.eq(fee_denom)
549+
{
550+
return true;
551+
}
552+
false
553+
}
554+
531555
pub fn build_swap_operations(
532556
receiver_asset_info: AssetInfo,
533557
initial_receive_asset_info: AssetInfo,

contracts/cw-ics20-latest/src/ibc_tests.rs

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ mod test {
77

88
use crate::ibc::{
99
ack_fail, build_ibc_msg, build_swap_msgs, check_gas_limit, handle_follow_up_failure,
10-
ibc_packet_receive, parse_voucher_denom, send_amount, Ics20Ack, Ics20Packet, RECEIVE_ID,
11-
REFUND_FAILURE_ID,
10+
ibc_packet_receive, is_follow_up_msgs_only_send_amount, parse_voucher_denom, send_amount,
11+
Ics20Ack, Ics20Packet, RECEIVE_ID, REFUND_FAILURE_ID,
1212
};
1313
use crate::ibc::{build_swap_operations, get_follow_up_msgs};
1414
use crate::test_helpers::*;
@@ -876,7 +876,7 @@ mod test {
876876
vec![CosmosMsg::Wasm(WasmMsg::Execute {
877877
contract_addr: env.contract.address.to_string(),
878878
msg: to_binary(&Cw20ExecuteMsg::Transfer {
879-
recipient: "cosmosabcd".to_string(),
879+
recipient: receiver.to_string(),
880880
amount: amount.clone()
881881
})
882882
.unwrap(),
@@ -960,4 +960,55 @@ mod test {
960960
// should undo reduce channel state
961961
assert_eq!(channel_state.outstanding, remote_amount)
962962
}
963+
964+
#[test]
965+
fn test_is_follow_up_msgs_only_send_amount() {
966+
assert_eq!(
967+
is_follow_up_msgs_only_send_amount("", "dest denom", "initial info", "fee denom"),
968+
true
969+
);
970+
assert_eq!(
971+
is_follow_up_msgs_only_send_amount("memo", "", "initial info", "fee denom"),
972+
true
973+
);
974+
// dest denom no equal to fee denom, return false
975+
assert_eq!(
976+
is_follow_up_msgs_only_send_amount(
977+
"memo",
978+
"dest denom",
979+
&AssetInfo::NativeToken {
980+
denom: "fee_denom".to_string()
981+
}
982+
.to_string(),
983+
"fee_denom"
984+
),
985+
false
986+
);
987+
// initial no equal to fee denom => return false
988+
assert_eq!(
989+
is_follow_up_msgs_only_send_amount(
990+
"memo",
991+
"fee_denom",
992+
&AssetInfo::NativeToken {
993+
denom: "foobar".to_string()
994+
}
995+
.to_string(),
996+
"fee_denom"
997+
),
998+
false
999+
);
1000+
// both dest denom and initial equal fee denom => true
1001+
assert_eq!(
1002+
is_follow_up_msgs_only_send_amount(
1003+
"memo",
1004+
"fee_denom",
1005+
&AssetInfo::NativeToken {
1006+
denom: "fee_denom".to_string()
1007+
}
1008+
.to_string(),
1009+
"fee_denom"
1010+
),
1011+
true
1012+
);
1013+
}
9631014
}

0 commit comments

Comments
 (0)