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

Added create_parachain_asset ext and removed sanity check from Rewards Pallet #950

Merged
merged 8 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions pallets/rewards/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,6 @@ impl<T: Config> Pallet<T> {
.saturating_sub(user_reward_info.claim_amount),
);

//ensure the claimable amount is greater than min claimable amount
ensure!(
rewards_claimable.saturated_into::<u128>() > MIN_REWARDS_CLAIMABLE_AMOUNT,
Error::<T>::AmountToLowToRedeem
);

//remove lock
T::NativeCurrency::remove_lock(user_reward_info.lock_id, &user);

Expand Down
22 changes: 22 additions & 0 deletions pallets/thea-executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -470,6 +471,23 @@ pub mod pallet {

Ok(())
}

#[pallet::call_index(7)]
#[pallet::weight(< T as Config >::TheaExecWeightInfo::claim_deposit(1))]
#[transactional]
pub fn create_parachain_asset(
zktony marked this conversation as resolved.
Show resolved Hide resolved
origin: OriginFor<T>,
asset: Box<XcmAssetId>,
decimal: u8,
) -> DispatchResult {
T::GovernanceOrigin::ensure_origin(origin)?;
let asset_id = Self::generate_asset_id_for_parachain(asset);
Self::resolve_create(asset_id.into(), Self::thea_account(), 1u128)?;
let metadata = AssetMetadata::new(decimal).ok_or(Error::<T>::InvalidDecimal)?;
<Metadata<T>>::insert(asset_id, metadata);
Self::deposit_event(Event::<T>::AssetMetadataSet(metadata));
Ok(())
}
}

impl<T: Config> Pallet<T> {
Expand Down Expand Up @@ -677,6 +695,10 @@ pub mod pallet {
));
Ok(())
}

pub fn generate_asset_id_for_parachain(asset: Box<XcmAssetId>) -> u128 {
u128::from_be_bytes(sp_io::hashing::blake2_128(&asset.encode()[..]))
}
}

impl<T: Config> TheaIncomingExecutor for Pallet<T> {
Expand Down
21 changes: 20 additions & 1 deletion pallets/thea-executor/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,22 @@ 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},
};
use frame_system::EventRecord;
use parity_scale_codec::Encode;
use sp_core::H160;
use sp_runtime::legacy::byte_sized_error::DispatchError;
use sp_runtime::{
traits::{AccountIdConversion, BadOrigin},
SaturatedConversion,
SaturatedConversion, TokenError,
};
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<T: crate::Config>(generic_event: <T as crate::Config>::RuntimeEvent) {
Expand Down Expand Up @@ -517,6 +520,22 @@ 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);
assert_ok!(TheaExecutor::create_parachain_asset(RuntimeOrigin::root(), asset, 10));
let asset_id = TheaExecutor::generate_asset_id_for_parachain(asset);
assert!(Assets::asset_exists(asset_id));
let expected_metadata = AssetMetadata::new(10);
let actual_metadata = <Metadata<Test>>::get(asset_id);
assert_eq!(expected_metadata, actual_metadata);
assert!(TheaExecutor::create_parachain_asset(RuntimeOrigin::root(), asset, 10).is_err());
})
}

fn setup_pool() {
let asset_id = 1u128;
let admin = 1u64;
Expand Down
3 changes: 3 additions & 0 deletions pallets/xcm-helper/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ benchmarks! {
// assert!(failed_withdrawals.is_empty());
// assert!(withdrawals.is_empty())
// }



}

#[cfg(test)]
Expand Down
Loading