diff --git a/pallets/asset-registry/src/lib.rs b/pallets/asset-registry/src/lib.rs index 162b9d697..c1ce4b1b2 100644 --- a/pallets/asset-registry/src/lib.rs +++ b/pallets/asset-registry/src/lib.rs @@ -630,7 +630,7 @@ impl CreateRegistry for Pallet { } } -impl InspectRegistry for Pallet { +impl InspectRegistry::StringLimit>> for Pallet { fn exists(asset_id: T::AssetId) -> bool { Assets::::contains_key(asset_id) } @@ -638,4 +638,12 @@ impl InspectRegistry for Pallet { fn decimals(asset_id: T::AssetId) -> Option { Some(AssetMetadataMap::::get(asset_id)?.decimals) } + + fn asset_name(asset_id: T::AssetId) -> Option::StringLimit>> { + Some(Assets::::get(asset_id)?.name) + } + + fn asset_symbol(asset_id: T::AssetId) -> Option::StringLimit>> { + Some(AssetMetadataMap::::get(asset_id)?.symbol) + } } diff --git a/pallets/stableswap/src/lib.rs b/pallets/stableswap/src/lib.rs index 77f98ddaf..c66f9cfce 100644 --- a/pallets/stableswap/src/lib.rs +++ b/pallets/stableswap/src/lib.rs @@ -64,6 +64,7 @@ use hydradx_traits::pools::DustRemovalAccountWhitelist; use orml_traits::MultiCurrency; use sp_std::collections::btree_map::BTreeMap; use weights::WeightInfo; +use pallet_asset_registry::Config as PalletAssetRegistryConfig; #[cfg(test)] pub(crate) mod tests; @@ -126,7 +127,7 @@ pub mod pallet { type ShareAccountId: AccountIdFor; /// Asset registry mechanism - type AssetInspection: InspectRegistry; + type AssetInspection: InspectRegistry::StringLimit>>; /// The origin which can create a new pool type AuthorityOrigin: EnsureOrigin; diff --git a/runtime/hydradx/src/evm/precompiles/multicurrency.rs b/runtime/hydradx/src/evm/precompiles/multicurrency.rs index 3504066e3..9b192ae08 100644 --- a/runtime/hydradx/src/evm/precompiles/multicurrency.rs +++ b/runtime/hydradx/src/evm/precompiles/multicurrency.rs @@ -42,6 +42,7 @@ use primitive_types::H160; use primitives::{AssetId, Balance}; use sp_runtime::{traits::Dispatchable, RuntimeDebug}; use sp_std::{marker::PhantomData, prelude::*}; +use hydradx_traits::InspectRegistry; #[module_evm_utility_macro::generate_function_selector] #[derive(RuntimeDebug, Eq, PartialEq, TryFromPrimitive, IntoPrimitive)] @@ -121,15 +122,15 @@ where let input = handle.read_input()?; input.expect_arguments(0)?; - match >::retrieve_asset_name(asset_id.into()) { - Ok(name) => { + match >::asset_name(asset_id.into()) { + Some(name) => { log::debug!(target: "evm", "multicurrency: symbol: {:?}", name); let encoded = Output::encode_bytes(name.as_slice()); Ok(succeed(encoded)) } - Err(_) => Err(PrecompileFailure::Error { + None => Err(PrecompileFailure::Error { exit_status: pallet_evm::ExitError::Other("Non-existing asset.".into()), }), } @@ -142,15 +143,15 @@ where let input = handle.read_input()?; input.expect_arguments(0)?; - match >::retrieve_asset_symbol(asset_id.into()) { - Ok(symbol) => { + match >::asset_symbol(asset_id.into()) { + Some(symbol) => { log::debug!(target: "evm", "multicurrency: name: {:?}", symbol); let encoded = Output::encode_bytes(symbol.as_slice()); Ok(succeed(encoded)) } - Err(_) => Err(PrecompileFailure::Error { + None => Err(PrecompileFailure::Error { exit_status: pallet_evm::ExitError::Other("Non-existing asset.".into()), }), } @@ -163,15 +164,15 @@ where let input = handle.read_input()?; input.expect_arguments(0)?; - match >::retrieve_asset_decimals(asset_id.into()) { - Ok(decimals) => { + match >::decimals(asset_id.into()) { + Some(decimals) => { log::debug!(target: "evm", "multicurrency: decimals: {:?}", decimals); let encoded = Output::encode_uint::(decimals); Ok(succeed(encoded)) } - Err(_) => Err(PrecompileFailure::Error { + None => Err(PrecompileFailure::Error { exit_status: pallet_evm::ExitError::Other("Non-existing asset.".into()), }), } diff --git a/traits/src/registry.rs b/traits/src/registry.rs index 57359d48d..1a60fa6c8 100644 --- a/traits/src/registry.rs +++ b/traits/src/registry.rs @@ -1,6 +1,4 @@ -use frame_support::BoundedVec; use sp_std::vec::Vec; - pub trait Registry { fn exists(name: AssetId) -> bool; @@ -41,9 +39,11 @@ pub trait ShareTokenRegistry: Registry { +pub trait InspectRegistry { fn exists(asset_id: AssetId) -> bool; fn decimals(asset_id: AssetId) -> Option; + fn asset_name(asset_id: AssetId) -> Option; + fn asset_symbol(asset_id: AssetId) -> Option; } #[derive(Eq, PartialEq, Copy, Clone)]