From d522c67c0e5fd71b8dfe45ab7ccf383a6daa81f9 Mon Sep 17 00:00:00 2001 From: Szegoo Date: Tue, 27 Aug 2024 18:21:31 +0200 Subject: [PATCH] fungibles --- pallets/rewards/src/lib.rs | 42 +++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/pallets/rewards/src/lib.rs b/pallets/rewards/src/lib.rs index 8a1e136..becbe17 100644 --- a/pallets/rewards/src/lib.rs +++ b/pallets/rewards/src/lib.rs @@ -15,7 +15,7 @@ #![cfg_attr(not(feature = "std"), no_std)] -use frame_support::traits::Currency; +use frame_support::traits::fungibles; use frame_system::WeightInfo; use order_primitives::{OrderFactory, OrderId, OrderInspect}; pub use pallet::*; @@ -25,19 +25,20 @@ mod types; const LOG_TARGET: &str = "runtime::rewards"; -pub type BalanceOf = - <::Currency as Currency<::AccountId>>::Balance; +pub type BalanceOf = <::Assets as fungibles::Inspect< + ::AccountId, +>>::Balance; + +pub type AssetIdOf = <::Assets as fungibles::Inspect< + ::AccountId, +>>::AssetId; #[frame_support::pallet] pub mod pallet { use super::*; use frame_support::{ pallet_prelude::*, - traits::{ - fungible::{Inspect, Mutate}, - tokens::Balance, - ReservableCurrency, - }, + traits::{fungibles::Inspect, tokens::Balance}, }; use frame_system::pallet_prelude::*; use types::PrizePoolDetails; @@ -48,23 +49,14 @@ pub mod pallet { /// The overarching event type. type RuntimeEvent: From> + IsType<::RuntimeEvent>; - /// The type used as a unique asset id, - type AssetId: Parameter - + Member - + Default - + TypeInfo - + MaybeSerializeDeserialize - + MaxEncodedLen - + Zero; - - /// TODO: remove and replace with a multicurrency type. - type Currency: Mutate + ReservableCurrency; - /// Relay chain balance type type Balance: Balance - + Into<>::Balance> + + Into<>::Balance> + Into; + /// The type should provide access to assets which can be used as reward. + type Assets: Inspect; + /// Type over which we can access order data. type Orders: OrderInspect + OrderFactory; @@ -80,7 +72,7 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn order_rewards)] pub type PrizePools = - StorageMap<_, Blake2_128Concat, OrderId, PrizePoolDetails>>; + StorageMap<_, Blake2_128Concat, OrderId, PrizePoolDetails, BalanceOf>>; #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] @@ -100,6 +92,8 @@ pub mod pallet { CantConfigure, /// The reward pool of an order was not found. PrizePoolNotFound, + /// The asset the user wanted to use for rewards does not exist. + AssetNotFound, } #[pallet::call] @@ -110,7 +104,7 @@ pub mod pallet { pub fn configure_rewards( origin: OriginFor, order_id: OrderId, - asset_id: T::AssetId, + asset_id: AssetIdOf, ) -> DispatchResult { let caller = ensure_signed(origin)?; @@ -125,6 +119,8 @@ pub mod pallet { ensure!(pool.amount == Zero::zero(), Error::::CantConfigure); } + ensure!(T::Assets::asset_exists(asset_id.clone()) == true, Error::::AssetNotFound); + PrizePools::::insert(order_id, PrizePoolDetails { asset_id, amount: Zero::zero() }); // TODO: deposit event