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

pallet-ibc: adjust rate limit based on decimal places #3620

Merged
merged 2 commits into from
May 18, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 19 additions & 1 deletion code/parachain/runtime/composable/src/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use common::{
fees::{IbcIcs20FeePalletId, IbcIcs20ServiceCharge},
governance::native::EnsureRootOrOneThirdNativeTechnical,
};
use composable_traits::assets::InspectRegistryMetadata;
use frame_system::EnsureSigned;
use pallet_ibc::{
ics20::{MODULE_ID_STR, PORT_ID_STR},
Expand Down Expand Up @@ -131,7 +132,24 @@ impl Ics20RateLimiter for ConstantAny {
denom if Some(denom) == pica_denom.as_deref() => 500_000,
_ => 10_000,
};
if msg.token.amount.as_u256() <= ::ibc::bigint::U256::from(limit * 10_u64.pow(12)) {

// adjust the number of decimals based on the currency id, as different assets have
// different decimals places and not doing it would defeat the purpose of fixing the nominal
// amount tha we are allowing users to transfer.
let token = &msg.token;
let asset_id: CurrencyId =
<<Runtime as pallet_ibc::Config>::IbcDenomToAssetIdConversion as DenomToAssetId<
Runtime,
>>::from_denom_to_asset_id(&token.denom.to_string())
.map_err(|_| ())?;

let decimals =
<assets_registry::Pallet<Runtime> as InspectRegistryMetadata>::decimals(&asset_id)
.unwrap_or(12);

if msg.token.amount.as_u256() <=
::ibc::bigint::U256::from(limit * 10_u64.pow(decimals as _))
{
return Ok(())
}
Err(())
Expand Down
21 changes: 20 additions & 1 deletion code/parachain/runtime/picasso/src/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use common::{
fees::{IbcIcs20FeePalletId, IbcIcs20ServiceCharge},
ibc::{ForeignIbcIcs20Assets, MinimumConnectionDelaySeconds},
};
use composable_traits::assets::InspectRegistryMetadata;
use frame_system::EnsureSigned;
use hex_literal::hex;
pub(crate) use pallet_ibc::{
Expand Down Expand Up @@ -126,9 +127,27 @@ impl Ics20RateLimiter for ConstantAny {
denom if Some(denom) == pica_denom.as_deref() => 500_000,
_ => 10_000,
};
if msg.token.amount.as_u256() <= ::ibc::bigint::U256::from(limit * 10_u64.pow(12)) {

// adjust the number of decimals based on the currency id, as different assets have
// different decimals places and not doing it would defeat the purpose of fixing the nominal
// amount tha we are allowing users to transfer.
let token = &msg.token;
let asset_id: CurrencyId =
<<Runtime as pallet_ibc::Config>::IbcDenomToAssetIdConversion as DenomToAssetId<
Runtime,
>>::from_denom_to_asset_id(&token.denom.to_string())
.map_err(|_| ())?;

let decimals =
<assets_registry::Pallet<Runtime> as InspectRegistryMetadata>::decimals(&asset_id)
.unwrap_or(12);

if msg.token.amount.as_u256() <=
::ibc::bigint::U256::from(limit * 10_u64.pow(decimals as _))
{
return Ok(())
}

Err(())
}
}
Expand Down