Skip to content

Commit

Permalink
fix: return simulate amount when offer is orai relayer fee
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamle2 committed Oct 17, 2023
1 parent 502b20a commit b25469e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
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 @@ -950,16 +950,20 @@ pub fn get_token_price(
swap_router_contract: &RouterController,
offer_asset_info: AssetInfo,
) -> Uint128 {
let orai_asset_info = AssetInfo::NativeToken {
denom: "orai".to_string(),
};
if offer_asset_info.eq(&orai_asset_info) {
return simulate_amount;
}
let token_price = swap_router_contract
.simulate_swap(
querier,
simulate_amount,
vec![SwapOperation::OraiSwap {
offer_asset_info,
// always swap with orai. If it does not share a pool with ORAI => ignore, no fee
ask_asset_info: AssetInfo::NativeToken {
denom: "orai".to_string(),
},
ask_asset_info: orai_asset_info,
}],
)
.map(|data| data.amount)
Expand Down
19 changes: 17 additions & 2 deletions contracts/cw-ics20-latest/src/ibc_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ mod test {
use cosmwasm_std::{coin, Addr, CosmosMsg, IbcTimeout, StdError};
use cw20_ics20_msg::receiver::DestinationInfo;
use oraiswap::asset::AssetInfo;
use oraiswap::router::SwapOperation;
use oraiswap::router::{RouterController, SwapOperation};

use crate::ibc::{
build_ibc_msg, build_swap_msgs, check_gas_limit, convert_remote_denom_to_evm_prefix,
deduct_fee, deduct_relayer_fee, deduct_token_fee, ibc_packet_receive,
deduct_fee, deduct_relayer_fee, deduct_token_fee, get_token_price, ibc_packet_receive,
is_follow_up_msgs_only_send_amount, parse_ibc_channel_without_sanity_checks,
parse_ibc_denom_without_sanity_checks, parse_voucher_denom, process_ibc_msg, Ics20Ack,
Ics20Packet, FOLLOW_UP_IBC_SEND_FAILURE_ID, IBC_TRANSFER_NATIVE_ERROR_ID,
Expand Down Expand Up @@ -1294,4 +1294,19 @@ mod test {
)
)
}

#[test]
fn test_get_token_price_orai_case() {
let deps = mock_dependencies();
let simulate_amount = Uint128::from(10u128);
let result = get_token_price(
&deps.as_ref().querier,
simulate_amount,
&RouterController("foo".to_string()),
AssetInfo::NativeToken {
denom: "orai".to_string(),
},
);
assert_eq!(result, simulate_amount)
}
}

0 comments on commit b25469e

Please sign in to comment.