diff --git a/Cargo.lock b/Cargo.lock index 743894dfa..cb3d02d24 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7975,6 +7975,7 @@ dependencies = [ "sp-core", "sp-runtime", "sp-std", + "staging-xcm", ] [[package]] diff --git a/pallets/rewards/src/lib.rs b/pallets/rewards/src/lib.rs index 2b52c908c..a68895a8a 100644 --- a/pallets/rewards/src/lib.rs +++ b/pallets/rewards/src/lib.rs @@ -431,12 +431,6 @@ impl Pallet { .saturating_sub(user_reward_info.claim_amount), ); - //ensure the claimable amount is greater than min claimable amount - ensure!( - rewards_claimable.saturated_into::() > MIN_REWARDS_CLAIMABLE_AMOUNT, - Error::::AmountToLowToRedeem - ); - //remove lock T::NativeCurrency::remove_lock(user_reward_info.lock_id, &user); diff --git a/pallets/rewards/src/tests.rs b/pallets/rewards/src/tests.rs index d5bdd2f24..041835a94 100644 --- a/pallets/rewards/src/tests.rs +++ b/pallets/rewards/src/tests.rs @@ -937,11 +937,5 @@ pub fn claim_rewards_for_alice_at_multiple_intervals() { System::set_block_number( start_block.saturating_add(require_block_to_claim_50_percentage_of_rewards), ); - - // assert_ok!(Rewards::claim(RuntimeOrigin::signed(alice_account.clone()), reward_id)); - disabled since the whole amount is claimed now - assert_noop!( - Rewards::claim(RuntimeOrigin::signed(alice_account), reward_id), - Error::::AmountToLowToRedeem - ); }) } diff --git a/pallets/thea-executor/src/lib.rs b/pallets/thea-executor/src/lib.rs index 1222714c0..e1e879090 100644 --- a/pallets/thea-executor/src/lib.rs +++ b/pallets/thea-executor/src/lib.rs @@ -26,6 +26,7 @@ extern crate core; use frame_support::pallet_prelude::Weight; pub use pallet::*; +use xcm::v3::AssetId as XcmAssetId; #[cfg(feature = "runtime-benchmarks")] mod benchmarking; @@ -89,6 +90,7 @@ pub mod pallet { /// Assets Pallet type Assets: frame_support::traits::tokens::fungibles::Mutate + frame_support::traits::tokens::fungibles::Create + + frame_support::traits::tokens::fungibles::metadata::Mutate + frame_support::traits::tokens::fungibles::Inspect; /// Asset Id type AssetId: Member @@ -470,6 +472,32 @@ pub mod pallet { Ok(()) } + + #[pallet::call_index(7)] + #[pallet::weight(< T as Config >::TheaExecWeightInfo::claim_deposit(1))] + #[transactional] + pub fn create_parachain_asset( + origin: OriginFor, + asset: sp_std::boxed::Box, + name: Vec, + symbol: Vec, + decimal: u8, + ) -> DispatchResult { + T::GovernanceOrigin::ensure_origin(origin)?; + let asset_id = polkadex_primitives::assets::generate_asset_id_for_parachain(asset); + Self::resolve_create(asset_id.into(), Self::thea_account(), 1u128)?; + Self::set_token_metadata( + asset_id.into(), + &Self::thea_account(), + name, + symbol, + decimal, + )?; + let metadata = AssetMetadata::new(decimal).ok_or(Error::::InvalidDecimal)?; + >::insert(asset_id, metadata); + Self::deposit_event(Event::::AssetMetadataSet(metadata)); + Ok(()) + } } impl Pallet { diff --git a/pallets/thea-executor/src/tests.rs b/pallets/thea-executor/src/tests.rs index 2d0e26c7a..2cbde072e 100644 --- a/pallets/thea-executor/src/tests.rs +++ b/pallets/thea-executor/src/tests.rs @@ -20,6 +20,7 @@ use crate::{ mock::{new_test_ext, Assets, Test, *}, PendingWithdrawals, WithdrawalFees, *, }; +use frame_support::traits::fungibles::Inspect; use frame_support::{ assert_noop, assert_ok, traits::{fungible::Mutate as FungibleMutate, fungibles::Mutate as FungiblesMutate}, @@ -33,6 +34,7 @@ use sp_runtime::{ }; use thea_primitives::types::NewWithdraw; use thea_primitives::types::{AssetMetadata, Deposit}; +use xcm::v3::Junction; use xcm::{opaque::lts::Junctions, v3::MultiLocation, VersionedMultiLocation}; fn assert_last_event(generic_event: ::RuntimeEvent) { @@ -517,6 +519,37 @@ fn test_claim_deposit_returns_asset_not_registered() { }) } +#[test] +fn test_create_parachain_asset() { + new_test_ext().execute_with(|| { + let multilocation = + MultiLocation { parents: 1, interior: Junctions::X1(Junction::Parachain(100)) }; + let asset = xcm::v3::AssetId::Concrete(multilocation); + Balances::set_balance(&TheaExecutor::thea_account(), 1_000_000_000_000_000_000); + assert_ok!(TheaExecutor::create_parachain_asset( + RuntimeOrigin::root(), + Box::new(asset), + Default::default(), + Default::default(), + 10 + )); + let asset_id = + polkadex_primitives::assets::generate_asset_id_for_parachain(Box::new(asset)); + assert!(Assets::asset_exists(asset_id)); + let expected_metadata = AssetMetadata::new(10); + let actual_metadata = >::get(asset_id); + assert_eq!(expected_metadata, actual_metadata); + assert!(TheaExecutor::create_parachain_asset( + RuntimeOrigin::root(), + Box::new(asset), + Default::default(), + Default::default(), + 10 + ) + .is_err()); + }) +} + fn setup_pool() { let asset_id = 1u128; let admin = 1u64; diff --git a/pallets/xcm-helper/src/benchmarking.rs b/pallets/xcm-helper/src/benchmarking.rs index 7960aa457..376e8cea2 100644 --- a/pallets/xcm-helper/src/benchmarking.rs +++ b/pallets/xcm-helper/src/benchmarking.rs @@ -109,6 +109,9 @@ benchmarks! { // assert!(failed_withdrawals.is_empty()); // assert!(withdrawals.is_empty()) // } + + + } #[cfg(test)] diff --git a/pallets/xcm-helper/src/lib.rs b/pallets/xcm-helper/src/lib.rs index 75ac44201..cb6833941 100644 --- a/pallets/xcm-helper/src/lib.rs +++ b/pallets/xcm-helper/src/lib.rs @@ -184,7 +184,8 @@ pub mod pallet { /// Assets type Assets: frame_support::traits::tokens::fungibles::Mutate + frame_support::traits::tokens::fungibles::Create - + frame_support::traits::tokens::fungibles::Inspect; + + frame_support::traits::tokens::fungibles::Inspect + + frame_support::traits::tokens::fungibles::metadata::Mutate; /// Asset Id type AssetId: Member + Parameter @@ -552,7 +553,8 @@ pub mod pallet { return T::NativeAssetId::get().into(); } // If it's not native, then hash and generate the asset id - let asset_id = u128::from_be_bytes(sp_io::hashing::blake2_128(&asset.encode()[..])); + let asset_id = + polkadex_primitives::assets::generate_asset_id_for_parachain(Box::new(asset)); if !>::contains_key(asset_id) { // Store the mapping >::insert(asset_id, asset); diff --git a/primitives/polkadex/Cargo.toml b/primitives/polkadex/Cargo.toml index 3877e18bb..11652d1f2 100644 --- a/primitives/polkadex/Cargo.toml +++ b/primitives/polkadex/Cargo.toml @@ -22,6 +22,7 @@ rust_decimal = { git = "https://github.com/Polkadex-Substrate/rust-decimal.git", "scale-codec", "serde", ], default-features = false } +xcm = { workspace = true, default-features = false } [dev-dependencies] pretty_assertions = "1.2.1" @@ -45,5 +46,6 @@ std = [ "sp-runtime/std", "rust_decimal/std", "rust_decimal/serde", + "xcm/std" ] full_crypto = ['sp-core/full_crypto'] diff --git a/primitives/polkadex/src/assets.rs b/primitives/polkadex/src/assets.rs index 1b83c23cc..e51084e31 100644 --- a/primitives/polkadex/src/assets.rs +++ b/primitives/polkadex/src/assets.rs @@ -20,6 +20,7 @@ use crate::Balance; #[cfg(not(feature = "std"))] use codec::alloc::string::ToString; use codec::{Decode, Encode, MaxEncodedLen}; +use frame_support::__private::sp_io; use frame_support::{ ensure, traits::{ @@ -46,6 +47,7 @@ pub trait Resolver< + frame_support::traits::tokens::fungible::Inspect, Others: frame_support::traits::tokens::fungibles::Mutate + frame_support::traits::tokens::fungibles::Inspect + + frame_support::traits::tokens::fungibles::metadata::Mutate + frame_support::traits::tokens::fungibles::Create, AssetId: Into + sp_std::cmp::PartialEq + Copy, NativeAssetId: Get, @@ -149,6 +151,16 @@ pub trait Resolver< } Ok(()) } + + fn set_token_metadata( + asset: AssetId, + from: &AccountId, + name: sp_std::vec::Vec, + symbol: sp_std::vec::Vec, + decimal: u8, + ) -> Result<(), DispatchError> { + Others::set(asset.into(), from, name, symbol, decimal) + } } /// Enumerated asset on chain @@ -275,6 +287,10 @@ impl<'de> Visitor<'de> for AssetId { } } +pub fn generate_asset_id_for_parachain(asset: sp_std::boxed::Box) -> u128 { + u128::from_be_bytes(sp_io::hashing::blake2_128(&asset.encode()[..])) +} + #[cfg(feature = "std")] impl TryFrom for AssetId { type Error = anyhow::Error;