From 668e8f3f5b175fa957a17221a69d33e1fcdaeb3a Mon Sep 17 00:00:00 2001 From: 1xstj <106580853+1xstj@users.noreply.github.com> Date: Thu, 21 Nov 2024 23:44:51 +0000 Subject: [PATCH] setup recipient --- .../multi-asset-delegation/src/functions/delegate.rs | 11 +++++++++++ .../multi-asset-delegation/src/functions/operator.rs | 11 +++++++++++ pallets/multi-asset-delegation/src/lib.rs | 3 +++ pallets/multi-asset-delegation/src/mock.rs | 2 ++ precompiles/multi-asset-delegation/src/mock.rs | 2 ++ runtime/mainnet/src/lib.rs | 1 + runtime/testnet/src/lib.rs | 1 + 7 files changed, 31 insertions(+) diff --git a/pallets/multi-asset-delegation/src/functions/delegate.rs b/pallets/multi-asset-delegation/src/functions/delegate.rs index f9fc8b18..501a70aa 100644 --- a/pallets/multi-asset-delegation/src/functions/delegate.rs +++ b/pallets/multi-asset-delegation/src/functions/delegate.rs @@ -15,6 +15,8 @@ // along with Tangle. If not, see . use super::*; use crate::{types::*, Pallet}; +use frame_support::traits::fungibles::Mutate; +use frame_support::traits::tokens::Preservation; use frame_support::{ensure, pallet_prelude::DispatchResult, traits::Get}; use sp_runtime::traits::{CheckedSub, Zero}; use sp_runtime::DispatchError; @@ -387,6 +389,15 @@ impl Pallet { .checked_sub(&slash_amount) .ok_or(Error::::InsufficientStakeRemaining)?; + // Transfer slashed amount to the treasury + let _ = T::Fungibles::transfer( + delegation.asset_id, + &Self::pallet_account(), + &T::SlashedAmountRecipient::get(), + slash_amount, + Preservation::Expendable, + ); + // emit event Self::deposit_event(Event::DelegatorSlashed { who: delegator.clone(), diff --git a/pallets/multi-asset-delegation/src/functions/operator.rs b/pallets/multi-asset-delegation/src/functions/operator.rs index 4788c01f..605fa14d 100644 --- a/pallets/multi-asset-delegation/src/functions/operator.rs +++ b/pallets/multi-asset-delegation/src/functions/operator.rs @@ -17,6 +17,8 @@ /// Functions for the pallet. use super::*; use crate::{types::*, Pallet}; +use frame_support::traits::Currency; +use frame_support::traits::ExistenceRequirement; use frame_support::BoundedVec; use frame_support::{ ensure, @@ -324,6 +326,15 @@ impl Pallet { Self::slash_delegator(&delegator.delegator, operator, blueprint_id, percentage); } + // transfer the slashed amount to the treasury + T::Currency::unreserve(&operator, amount); + let _ = T::Currency::transfer( + operator, + &T::SlashedAmountRecipient::get(), + amount, + ExistenceRequirement::AllowDeath, + ); + // emit event Self::deposit_event(Event::OperatorSlashed { who: operator.clone(), amount }); diff --git a/pallets/multi-asset-delegation/src/lib.rs b/pallets/multi-asset-delegation/src/lib.rs index 05e825a0..e6aa0748 100644 --- a/pallets/multi-asset-delegation/src/lib.rs +++ b/pallets/multi-asset-delegation/src/lib.rs @@ -185,6 +185,9 @@ pub mod pallet { /// The origin with privileged access type ForceOrigin: EnsureOrigin; + /// The address that receives slashed funds + type SlashedAmountRecipient: Get; + /// A type representing the weights required by the dispatchables of this pallet. type WeightInfo: crate::weights::WeightInfo; } diff --git a/pallets/multi-asset-delegation/src/mock.rs b/pallets/multi-asset-delegation/src/mock.rs index 321538e4..397a8989 100644 --- a/pallets/multi-asset-delegation/src/mock.rs +++ b/pallets/multi-asset-delegation/src/mock.rs @@ -122,6 +122,7 @@ parameter_types! { pub const MinOperatorBondAmount: u64 = 10_000; pub const BondDuration: u32 = 10; pub PID: PalletId = PalletId(*b"PotStake"); + pub const SlashedAmountRecipient : u64 = 0; #[derive(PartialEq, Eq, Clone, Copy, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)] pub const MaxDelegatorBlueprints : u32 = 50; #[derive(PartialEq, Eq, Clone, Copy, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)] @@ -155,6 +156,7 @@ impl pallet_multi_asset_delegation::Config for Test { type MaxWithdrawRequests = MaxWithdrawRequests; type MaxUnstakeRequests = MaxUnstakeRequests; type MaxDelegations = MaxDelegations; + type SlashedAmountRecipient = SlashedAmountRecipient; type WeightInfo = (); } diff --git a/precompiles/multi-asset-delegation/src/mock.rs b/precompiles/multi-asset-delegation/src/mock.rs index 9698c68a..a999578d 100644 --- a/precompiles/multi-asset-delegation/src/mock.rs +++ b/precompiles/multi-asset-delegation/src/mock.rs @@ -334,6 +334,7 @@ parameter_types! { pub const MinOperatorBondAmount: u64 = 10_000; pub const BondDuration: u32 = 10; pub PID: PalletId = PalletId(*b"PotStake"); + pub SlashedAmountRecipient : AccountId = TestAccount::Alex.into(); #[derive(PartialEq, Eq, Clone, Copy, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)] pub const MaxDelegatorBlueprints : u32 = 50; #[derive(PartialEq, Eq, Clone, Copy, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)] @@ -366,6 +367,7 @@ impl pallet_multi_asset_delegation::Config for Runtime { type MaxWithdrawRequests = MaxWithdrawRequests; type MaxUnstakeRequests = MaxUnstakeRequests; type MaxDelegations = MaxDelegations; + type SlashedAmountRecipient = SlashedAmountRecipient; type PalletId = PID; type WeightInfo = (); } diff --git a/runtime/mainnet/src/lib.rs b/runtime/mainnet/src/lib.rs index a11a7f8b..59b5818e 100644 --- a/runtime/mainnet/src/lib.rs +++ b/runtime/mainnet/src/lib.rs @@ -1267,6 +1267,7 @@ impl pallet_multi_asset_delegation::Config for Runtime { type ForceOrigin = frame_system::EnsureRoot; type PalletId = PID; type VaultId = AssetId; + type SlashedAmountRecipient = TreasuryAccount; type MaxDelegatorBlueprints = MaxDelegatorBlueprints; type MaxOperatorBlueprints = MaxOperatorBlueprints; type MaxWithdrawRequests = MaxWithdrawRequests; diff --git a/runtime/testnet/src/lib.rs b/runtime/testnet/src/lib.rs index 6f24c052..da36b14c 100644 --- a/runtime/testnet/src/lib.rs +++ b/runtime/testnet/src/lib.rs @@ -1484,6 +1484,7 @@ impl pallet_multi_asset_delegation::Config for Runtime { type MinDelegateAmount = MinDelegateAmount; type Fungibles = Assets; type AssetId = AssetId; + type SlashedAmountRecipient = TreasuryAccount; type ForceOrigin = frame_system::EnsureRoot; type PalletId = PID; type VaultId = AssetId;