Skip to content

Commit

Permalink
setup recipient
Browse files Browse the repository at this point in the history
  • Loading branch information
1xstj committed Nov 21, 2024
1 parent 68168f2 commit 668e8f3
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pallets/multi-asset-delegation/src/functions/delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// along with Tangle. If not, see <http://www.gnu.org/licenses/>.
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;
Expand Down Expand Up @@ -387,6 +389,15 @@ impl<T: Config> Pallet<T> {
.checked_sub(&slash_amount)
.ok_or(Error::<T>::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(),
Expand Down
11 changes: 11 additions & 0 deletions pallets/multi-asset-delegation/src/functions/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -324,6 +326,15 @@ impl<T: Config> Pallet<T> {
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 });

Expand Down
3 changes: 3 additions & 0 deletions pallets/multi-asset-delegation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ pub mod pallet {
/// The origin with privileged access
type ForceOrigin: EnsureOrigin<Self::RuntimeOrigin>;

/// The address that receives slashed funds
type SlashedAmountRecipient: Get<Self::AccountId>;

/// A type representing the weights required by the dispatchables of this pallet.
type WeightInfo: crate::weights::WeightInfo;
}
Expand Down
2 changes: 2 additions & 0 deletions pallets/multi-asset-delegation/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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 = ();
}

Expand Down
2 changes: 2 additions & 0 deletions precompiles/multi-asset-delegation/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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 = ();
}
Expand Down
1 change: 1 addition & 0 deletions runtime/mainnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,7 @@ impl pallet_multi_asset_delegation::Config for Runtime {
type ForceOrigin = frame_system::EnsureRoot<Self::AccountId>;
type PalletId = PID;
type VaultId = AssetId;
type SlashedAmountRecipient = TreasuryAccount;
type MaxDelegatorBlueprints = MaxDelegatorBlueprints;
type MaxOperatorBlueprints = MaxOperatorBlueprints;
type MaxWithdrawRequests = MaxWithdrawRequests;
Expand Down
1 change: 1 addition & 0 deletions runtime/testnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self::AccountId>;
type PalletId = PID;
type VaultId = AssetId;
Expand Down

0 comments on commit 668e8f3

Please sign in to comment.