Skip to content

Commit

Permalink
upgrade transfer-allowlist
Browse files Browse the repository at this point in the history
  • Loading branch information
lemunozm committed May 13, 2024
1 parent a38bfb6 commit 5ccb3d0
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 20 deletions.
19 changes: 19 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ members = [
"pallets/rewards",
"pallets/swaps",
"pallets/token-mux",
#"pallets/transfer-allowlist",
"pallets/transfer-allowlist",
#"runtime/altair",
#"runtime/centrifuge",
#"runtime/development",
Expand Down
22 changes: 17 additions & 5 deletions pallets/transfer-allowlist/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,14 @@ pub mod pallet {

#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]

pub struct Pallet<T>(_);

/// 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<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
Expand All @@ -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<Self::AccountId>;
type ReserveCurrency: fungible::hold::Mutate<
Self::AccountId,
Reason = Self::RuntimeHoldReason,
>;

/// The identifier to be used for holding.
type HoldId: Get<ReasonOf<Self>>;
type RuntimeHoldReason: From<HoldReason>;

/// Deposit amount
type Deposit: Get<DepositBalanceOf<Self>>;
Expand Down Expand Up @@ -348,7 +356,11 @@ pub mod pallet {
&receiver,
)) {
Self::increment_or_create_allowance_count(&account_id, &currency_id)?;
T::ReserveCurrency::hold(&T::HoldId::get(), &account_id, T::Deposit::get())?;
T::ReserveCurrency::hold(
&HoldReason::TransferAllowance.into(),
&account_id,
T::Deposit::get(),
)?;
};
<AccountCurrencyTransferAllowance<T>>::insert(
(&account_id, &currency_id, &receiver),
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 2 additions & 14 deletions pallets/transfer-allowlist/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -71,20 +67,12 @@ impl From<u64> 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;
Expand Down

0 comments on commit 5ccb3d0

Please sign in to comment.