moonbeam_runtime/
asset_config.rsuse super::{
currency, governance, AccountId, AssetId, Balance, Balances, Runtime, RuntimeEvent,
FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX,
};
use super::moonbeam_weights;
use frame_support::{
parameter_types,
traits::{AsEnsureOriginWithArg, ConstU128, ConstU32, EitherOfDiverse},
};
use moonkit_xcm_primitives::AccountIdAssetIdConversion;
use frame_system::{EnsureNever, EnsureRoot};
use sp_core::H160;
use parity_scale_codec::Compact;
use sp_std::{
convert::{From, Into},
prelude::*,
};
const REMOVE_ITEMS_LIMIT: u32 = 656;
pub type ForeignAssetInstance = ();
parameter_types! {
pub const AssetDeposit: Balance = 100 * currency::GLMR * currency::SUPPLY_FACTOR;
pub const ApprovalDeposit: Balance = 0;
pub const AssetsStringLimit: u32 = 50;
pub const MetadataDepositBase: Balance = currency::deposit(1,68);
pub const MetadataDepositPerByte: Balance = currency::deposit(0, 1);
}
pub type AssetsForceOrigin =
EitherOfDiverse<EnsureRoot<AccountId>, governance::custom_origins::GeneralAdmin>;
pallet_assets::runtime_benchmarks_enabled! {
pub struct BenchmarkHelper;
impl<AssetIdParameter> pallet_assets::BenchmarkHelper<AssetIdParameter> for BenchmarkHelper
where
AssetIdParameter: From<u128>,
{
fn create_asset_id_parameter(id: u32) -> AssetIdParameter {
(id as u128).into()
}
}
}
impl pallet_assets::Config<ForeignAssetInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type Balance = Balance;
type AssetId = AssetId;
type Currency = Balances;
type ForceOrigin = AssetsForceOrigin;
type AssetDeposit = AssetDeposit;
type MetadataDepositBase = MetadataDepositBase;
type MetadataDepositPerByte = MetadataDepositPerByte;
type ApprovalDeposit = ApprovalDeposit;
type StringLimit = AssetsStringLimit;
type Freezer = ();
type Extra = ();
type AssetAccountDeposit = ConstU128<{ currency::deposit(1, 18) }>;
type WeightInfo = moonbeam_weights::pallet_assets::WeightInfo<Runtime>;
type RemoveItemsLimit = ConstU32<{ REMOVE_ITEMS_LIMIT }>;
type AssetIdParameter = Compact<AssetId>;
type CreateOrigin = AsEnsureOriginWithArg<EnsureNever<AccountId>>;
type CallbackHandle = ();
type Holder = ();
pallet_assets::runtime_benchmarks_enabled! {
type BenchmarkHelper = BenchmarkHelper;
}
}
impl AccountIdAssetIdConversion<AccountId, AssetId> for Runtime {
fn account_to_asset_id(account: AccountId) -> Option<(Vec<u8>, AssetId)> {
let h160_account: H160 = account.into();
let mut data = [0u8; 16];
let (prefix_part, id_part) = h160_account.as_fixed_bytes().split_at(4);
if prefix_part == FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX {
data.copy_from_slice(id_part);
let asset_id: AssetId = u128::from_be_bytes(data).into();
Some((prefix_part.to_vec(), asset_id))
} else {
None
}
}
fn asset_id_to_account(prefix: &[u8], asset_id: AssetId) -> AccountId {
let mut data = [0u8; 20];
data[0..4].copy_from_slice(prefix);
data[4..20].copy_from_slice(&asset_id.to_be_bytes());
AccountId::from(data)
}
}