diff --git a/Cargo.lock b/Cargo.lock index 5d9fb4585e..b84c1daa9b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2850,6 +2850,25 @@ dependencies = [ "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.2)", ] +[[package]] +name = "pallet-transfer-allowlist" +version = "0.1.0" +dependencies = [ + "cfg-traits", + "cfg-types", + "frame-benchmarking", + "frame-support", + "frame-system", + "pallet-balances", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.7.2)", +] + [[package]] name = "pallet-treasury" version = "27.0.0" diff --git a/Cargo.toml b/Cargo.toml index 748522273a..cc114a54d5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,7 +39,7 @@ members = [ "pallets/rewards", "pallets/swaps", "pallets/token-mux", - #"pallets/transfer-allowlist", + "pallets/transfer-allowlist", #"runtime/altair", #"runtime/centrifuge", #"runtime/development", diff --git a/pallets/transfer-allowlist/src/lib.rs b/pallets/transfer-allowlist/src/lib.rs index 32127d411c..230f8f9aa2 100644 --- a/pallets/transfer-allowlist/src/lib.rs +++ b/pallets/transfer-allowlist/src/lib.rs @@ -81,9 +81,14 @@ pub mod pallet { #[pallet::pallet] #[pallet::storage_version(STORAGE_VERSION)] - pub struct Pallet(_); + /// A reason for this pallet placing a hold on funds. + #[pallet::composite_enum] + pub enum HoldReason { + TransferAllowance, + } + #[pallet::config] pub trait Config: frame_system::Config { type RuntimeEvent: From> + IsType<::RuntimeEvent>; @@ -92,10 +97,13 @@ pub mod pallet { /// Currency for holding/unholding with allowlist adding/removal, /// given that the allowlist will be in storage - type ReserveCurrency: fungible::hold::Mutate; + type ReserveCurrency: fungible::hold::Mutate< + Self::AccountId, + Reason = Self::RuntimeHoldReason, + >; /// The identifier to be used for holding. - type HoldId: Get>; + type RuntimeHoldReason: From; /// Deposit amount type Deposit: Get>; @@ -348,7 +356,11 @@ pub mod pallet { &receiver, )) { Self::increment_or_create_allowance_count(&account_id, ¤cy_id)?; - T::ReserveCurrency::hold(&T::HoldId::get(), &account_id, T::Deposit::get())?; + T::ReserveCurrency::hold( + &HoldReason::TransferAllowance.into(), + &account_id, + T::Deposit::get(), + )?; }; >::insert( (&account_id, ¤cy_id, &receiver), @@ -428,7 +440,7 @@ pub mod pallet { { Some(AllowanceDetails { blocked_at, .. }) if blocked_at < current_block => { T::ReserveCurrency::release( - &T::HoldId::get(), + &HoldReason::TransferAllowance.into(), &account_id, T::Deposit::get(), Precision::BestEffort, diff --git a/pallets/transfer-allowlist/src/mock.rs b/pallets/transfer-allowlist/src/mock.rs index fb372559e7..cca1676076 100644 --- a/pallets/transfer-allowlist/src/mock.rs +++ b/pallets/transfer-allowlist/src/mock.rs @@ -11,11 +11,7 @@ // GNU General Public License for more details. use cfg_types::tokens::FilterCurrency; -use frame_support::{ - derive_impl, parameter_types, - traits::{ConstU32, ConstU64}, - Deserialize, Serialize, -}; +use frame_support::{derive_impl, traits::ConstU64, Deserialize, Serialize}; use frame_system::pallet_prelude::BlockNumberFor; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; @@ -71,20 +67,12 @@ impl From for Location { #[derive_impl(pallet_balances::config_preludes::TestDefaultConfig as pallet_balances::DefaultConfig)] impl pallet_balances::Config for Runtime { type AccountStore = System; - type DustRemoval = (); - type ExistentialDeposit = ConstU64<1>; - type MaxHolds = ConstU32<1>; - type RuntimeHoldReason = (); -} - -parameter_types! { - pub const HoldId: () = (); } impl transfer_allowlist::Config for Runtime { type CurrencyId = FilterCurrency; type Deposit = ConstU64<10>; - type HoldId = HoldId; + type RuntimeHoldReason = RuntimeHoldReason; type Location = Location; type ReserveCurrency = Balances; type RuntimeEvent = RuntimeEvent;