Skip to content

Commit

Permalink
🩹 Send the slashed PLMC to the Blockchain Operation Treasury (#347)
Browse files Browse the repository at this point in the history
* feat: send the slashed PLMC to the Blockchain Operation Treasury

* chore: change name to avoid future confusion

* chore: clarify the comment
  • Loading branch information
lrazovic authored Jul 1, 2024
1 parent 8eb81d3 commit 66262af
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 37 deletions.
4 changes: 2 additions & 2 deletions integration-tests/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ pub mod polimec {
use super::*;
use crate::{PolimecNet, PolimecOrigin, PolimecRuntime};
use pallet_funding::AcceptedFundingAsset;
use polimec_runtime::{PayMaster, TreasuryAccount};
use polimec_runtime::{BlockchainOperationTreasury, TreasuryAccount};
use xcm::v3::Parent;
use xcm_emulator::TestExt;

Expand Down Expand Up @@ -446,7 +446,7 @@ pub mod polimec {
funded_accounts.extend(accounts::init_balances().iter().cloned().map(|k| (k, INITIAL_DEPOSIT)));
funded_accounts.extend(collators::initial_authorities().iter().cloned().map(|(acc, _)| (acc, 20_005 * PLMC)));
funded_accounts.push((TreasuryAccount::get(), 20_005 * PLMC));
funded_accounts.push((PayMaster::get(), 20_005 * PLMC));
funded_accounts.push((BlockchainOperationTreasury::get(), 20_005 * PLMC));

let genesis_config = polimec_runtime::RuntimeGenesisConfig {
system: Default::default(),
Expand Down
6 changes: 3 additions & 3 deletions integration-tests/src/tests/vest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use frame_support::traits::fungible::Mutate;
use macros::generate_accounts;
use pallet_funding::assert_close_enough;
use pallet_vesting::VestingInfo;
use polimec_runtime::{Balances, ParachainStaking, PayMaster, RuntimeOrigin, Vesting, PLMC};
use polimec_runtime::{Balances, BlockchainOperationTreasury, ParachainStaking, RuntimeOrigin, Vesting, PLMC};
use sp_runtime::Perquintill;
use xcm_emulator::helpers::get_account_id_from_seed;

Expand Down Expand Up @@ -160,7 +160,7 @@ fn dust_to_treasury() {

// Get the total issuance and Treasury balance before the transfer.
let initial_total_issuance = Balances::total_issuance();
let initial_treasury_balance = Balances::free_balance(PayMaster::get());
let initial_treasury_balance = Balances::free_balance(BlockchainOperationTreasury::get());

// Transfer funds from sender to receiver, designed to deplete the sender's balance below the ED.
// The sender account will be killed and the dust will be sent to the treasury.
Expand All @@ -176,7 +176,7 @@ fn dust_to_treasury() {
assert_eq!(initial_total_issuance, post_total_issuance);

// Verify the Treasury has received the dust from the sender's account.
let final_treasury_balance = Balances::free_balance(PayMaster::get());
let final_treasury_balance = Balances::free_balance(BlockchainOperationTreasury::get());
assert_eq!(initial_treasury_balance + ED - 1, final_treasury_balance);
})
}
2 changes: 1 addition & 1 deletion nodes/parachain/src/chain_spec/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub fn genesis_config(genesis_config_params: GenesisConfigParams) -> serde_json:

let system_accounts = vec![
(
<Runtime as pallet_funding::Config>::ProtocolGrowthTreasury::get(),
<Runtime as pallet_funding::Config>::BlockchainOperationTreasury::get(),
<Runtime as pallet_funding::Config>::NativeCurrency::minimum_balance(),
),
(
Expand Down
4 changes: 2 additions & 2 deletions pallets/funding/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1540,7 +1540,7 @@ mod benchmarks {
let evaluation_to_settle =
inst.execute(|| Evaluations::<T>::iter_prefix_values((project_id, evaluator.clone())).next().unwrap());

let treasury_account = T::ProtocolGrowthTreasury::get();
let treasury_account = T::BlockchainOperationTreasury::get();
let free_treasury_plmc = inst.get_free_plmc_balances_for(vec![treasury_account])[0].plmc_amount;
assert_eq!(free_treasury_plmc, inst.get_ed());

Expand All @@ -1563,7 +1563,7 @@ mod benchmarks {
.plmc_amount;
assert_eq!(reserved_plmc, 0.into());

let treasury_account = T::ProtocolGrowthTreasury::get();
let treasury_account = T::BlockchainOperationTreasury::get();
let free_treasury_plmc = inst.get_free_plmc_balances_for(vec![treasury_account])[0].plmc_amount;
let ed = inst.get_ed();
assert_eq!(free_treasury_plmc, slashed_amount + ed);
Expand Down
2 changes: 1 addition & 1 deletion pallets/funding/src/functions/6_settlement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ impl<T: Config> Pallet<T> {

fn slash_evaluator(project_id: ProjectId, evaluation: &EvaluationInfoOf<T>) -> Result<BalanceOf<T>, DispatchError> {
let slash_percentage = T::EvaluatorSlash::get();
let treasury_account = T::ProtocolGrowthTreasury::get();
let treasury_account = T::BlockchainOperationTreasury::get();

// * Calculate variables *
// We need to make sure that the current PLMC bond is always >= than the slash amount.
Expand Down
4 changes: 2 additions & 2 deletions pallets/funding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,9 @@ pub mod pallet {
#[pallet::constant]
type SuccessToSettlementTime: Get<BlockNumberFor<Self>>;

/// Treasury account holding PLMC at TGE.
/// Account that receive the PLMC slashed from failed evaluations.
#[pallet::constant]
type ProtocolGrowthTreasury: Get<AccountIdOf<Self>>;
type BlockchainOperationTreasury: Get<AccountIdOf<Self>>;

/// Treasury account holding the CT fees charged to issuers.
#[pallet::constant]
Expand Down
6 changes: 3 additions & 3 deletions pallets/funding/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ parameter_types! {
];
pub EarlyEvaluationThreshold: Percent = Percent::from_percent(10);
pub EvaluatorSlash: Percent = Percent::from_percent(20);
pub ProtocolGrowthTreasuryAccount: AccountId = AccountId::from(696969u32);
pub BlockchainOperationTreasuryAccount: AccountId = AccountId::from(696969u32);
pub ContributionTreasury: AccountId = AccountId::from(4204204206u32);
}

Expand Down Expand Up @@ -400,6 +400,7 @@ impl Config for TestRuntime {
type Balance = Balance;
type BlockNumber = BlockNumber;
type BlockNumberToBalance = ConvertInto;
type BlockchainOperationTreasury = BlockchainOperationTreasuryAccount;
type CommunityFundingDuration = CommunityRoundDuration;
type ContributionTokenCurrency = ContributionTokens;
type ContributionTreasury = ContributionTreasury;
Expand Down Expand Up @@ -427,7 +428,6 @@ impl Config for TestRuntime {
type PreImageLimit = ConstU32<1024>;
type Price = FixedU128;
type PriceProvider = ConstPriceProvider;
type ProtocolGrowthTreasury = ProtocolGrowthTreasuryAccount;
type Randomness = RandomnessCollectiveFlip;
type RemainderFundingDuration = RemainderFundingDuration;
type RequiredMaxCapacity = RequiredMaxCapacity;
Expand Down Expand Up @@ -470,7 +470,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
balances: vec![
(<TestRuntime as Config>::PalletId::get().into_account_truncating(), ed),
(<TestRuntime as Config>::ContributionTreasury::get(), ed),
(<TestRuntime as Config>::ProtocolGrowthTreasury::get(), ed),
(<TestRuntime as Config>::BlockchainOperationTreasury::get(), ed),
],
},
foreign_assets: ForeignAssetsConfig {
Expand Down
2 changes: 1 addition & 1 deletion pallets/funding/src/tests/2_evaluation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ mod evaluate_extrinsic {
assert_eq!(evaluation_held_balance, frozen_amount);
assert_eq!(frozen_balance, frozen_amount);

let treasury_account = <TestRuntime as Config>::ProtocolGrowthTreasury::get();
let treasury_account = <TestRuntime as Config>::BlockchainOperationTreasury::get();
let pre_slash_treasury_balance = inst.get_free_plmc_balance_for(treasury_account);

let settlement_block = inst.get_update_block(project_id, &UpdateType::StartSettlement).unwrap();
Expand Down
18 changes: 9 additions & 9 deletions pallets/linear-release/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ fn check_vesting_status_for_multi_schedule_account() {
assert_eq!(Balances::balance_on_hold(&MockRuntimeHoldReason::Reason, &2), 20 * ED);
assert_ok!(Vesting::vested_transfer(Some(4).into(), 2, sched1, MockRuntimeHoldReason::Reason));
assert_eq!(Balances::balance_on_hold(&MockRuntimeHoldReason::Reason, &2), 29 * ED); // Why 29 and not 30? Because sched1 is already unlocking.
// Free balance is the one set in Genesis inside the Balances pallet
// + the one from the vested transfer.
// BUT NOT the one in sched0, since the vesting will start at block #10.
// Free balance is the one set in Genesis inside the Balances pallet
// + the one from the vested transfer.
// BUT NOT the one in sched0, since the vesting will start at block #10.
let balance = Balances::balance(&2);
assert_eq!(balance, ED * (2));
// The most recently added schedule exists.
Expand Down Expand Up @@ -193,7 +193,7 @@ fn unvested_balance_should_not_transfer() {
ExtBuilder::default().existential_deposit(10).build().execute_with(|| {
let user1_free_balance = Balances::free_balance(1);
assert_eq!(user1_free_balance, 50); // Account 1 has free balance
// Account 1 has only 5 units vested at block 1 (plus 50 unvested)
// Account 1 has only 5 units vested at block 1 (plus 50 unvested)
assert_eq!(Vesting::vesting_balance(&1, MockRuntimeHoldReason::Reason), Some(5)); // Account 1 cannot send more than vested amount...
assert_noop!(Balances::transfer_allow_death(Some(1).into(), 2, 56), TokenError::FundsUnavailable);
});
Expand All @@ -205,13 +205,13 @@ fn vested_balance_should_transfer() {
assert_eq!(System::block_number(), 1);
let user1_free_balance = Balances::free_balance(1);
assert_eq!(user1_free_balance, 50); // Account 1 has free balance
// Account 1 has only 5 units vested at block 1 (plus 50 unvested)
// Account 1 has only 5 units vested at block 1 (plus 50 unvested)
assert_eq!(Vesting::vesting_balance(&1, MockRuntimeHoldReason::Reason), Some(5));
assert_noop!(Balances::transfer_allow_death(Some(1).into(), 2, 45), TokenError::Frozen); // Account 1 free balance - ED is < 45
assert_ok!(Vesting::vest(Some(1).into(), MockRuntimeHoldReason::Reason));
let user1_free_balance = Balances::free_balance(1);
assert_eq!(user1_free_balance, 55); // Account 1 has free balance
// Account 1 has vested 1 unit at block 1 (plus 50 unvested)
// Account 1 has vested 1 unit at block 1 (plus 50 unvested)
assert_ok!(Balances::transfer_allow_death(Some(1).into(), 2, 45)); // After the vest it can now send the 45 UNIT
});
}
Expand Down Expand Up @@ -259,7 +259,7 @@ fn vested_balance_should_transfer_using_vest_other() {
ExtBuilder::default().existential_deposit(10).build().execute_with(|| {
let user1_free_balance = Balances::free_balance(1);
assert_eq!(user1_free_balance, 50); // Account 1 has free balance
// Account 1 has only 5 units vested at block 1 (plus 50 unvested)
// Account 1 has only 5 units vested at block 1 (plus 50 unvested)
assert_eq!(Vesting::vesting_balance(&1, MockRuntimeHoldReason::Reason), Some(5));
assert_ok!(Vesting::vest_other(Some(2).into(), 1, MockRuntimeHoldReason::Reason));
assert_ok!(Balances::transfer_allow_death(Some(1).into(), 2, 55 - 10));
Expand Down Expand Up @@ -317,7 +317,7 @@ fn extra_balance_should_transfer() {

// Account 2 has no units vested at block 1, but gained 100
assert_ok!(Balances::transfer_allow_death(Some(2).into(), 3, 100 - 10)); // Account 2 can send extra
// units gained
// units gained
});
}

Expand All @@ -327,7 +327,7 @@ fn liquid_funds_should_transfer_with_delayed_vesting() {
let user12_free_balance = Balances::free_balance(12);

assert_eq!(user12_free_balance, 1280); // Account 12 has free balance
// Account 12 has liquid funds
// Account 12 has liquid funds
assert_eq!(Vesting::vesting_balance(&12, MockRuntimeHoldReason::Reason), Some(0));

// Account 12 has delayed vesting
Expand Down
8 changes: 4 additions & 4 deletions pallets/parachain-staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ parameter_types! {
pub const MinCandidateStk: u128 = 10;
pub const MinDelegatorStk: u128 = 5;
pub const MinDelegation: u128 = 3;
pub const PayMaster: AccountId = 1337;
pub const BlockchainOperationTreasury: AccountId = 1337;
}
impl_opaque_keys! {
pub struct MockSessionKeys {
Expand Down Expand Up @@ -176,7 +176,7 @@ impl Config for Test {
type MonetaryGovernanceOrigin = frame_system::EnsureRoot<AccountId>;
type OnCollatorPayout = ();
type OnNewRound = ();
type PayMaster = PayMaster;
type PayMaster = BlockchainOperationTreasury;
type PayoutCollatorReward = ();
type RevokeDelegationDelay = RevokeDelegationDelay;
type RewardPaymentDelay = RewardPaymentDelay;
Expand Down Expand Up @@ -223,8 +223,8 @@ impl Default for ExtBuilder {

impl ExtBuilder {
pub(crate) fn with_balances(mut self, mut balances: Vec<(AccountId, Balance)>) -> Self {
if !balances.iter().any(|(acc, _)| *acc == PayMaster::get()) {
balances.push((PayMaster::get(), 300));
if !balances.iter().any(|(acc, _)| *acc == BlockchainOperationTreasury::get()) {
balances.push((BlockchainOperationTreasury::get(), 300));
}
self.balances = balances;
self
Expand Down
4 changes: 2 additions & 2 deletions pallets/parachain-staking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2893,7 +2893,7 @@ fn payout_distribution_to_solo_collators() {
(7, 33),
(8, 33),
(9, 33),
(crate::mock::PayMaster::get(), 1000),
(crate::mock::BlockchainOperationTreasury::get(), 1000),
])
.with_candidates(vec![(1, 100), (2, 90), (3, 80), (4, 70)])
.build()
Expand Down Expand Up @@ -3120,7 +3120,7 @@ fn payouts_follow_delegation_changes() {
(8, 100),
(9, 100),
(10, 100),
(crate::mock::PayMaster::get(), 1000),
(crate::mock::BlockchainOperationTreasury::get(), 1000),
])
.with_candidates(vec![(1, 20), (2, 20), (3, 20), (4, 20)])
.with_delegations(vec![(6, 1, 10), (7, 1, 10), (8, 2, 10), (9, 2, 10), (10, 1, 10)])
Expand Down
2 changes: 1 addition & 1 deletion runtimes/polimec/src/custom_migrations/deposit_dust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl frame_support::traits::OnRuntimeUpgrade for DepositDust {
if total_issuance != 100_000_000 * PLMC {
log::info!("⚠️ Correcting total issuance from {} to {}", total_issuance, 100_000_000 * PLMC);
// +1 R
let treasury_account = PayMaster::get();
let treasury_account = BlockchainOperationTreasury::get();
// +1 W
// The values are coming from these `DustLost` events:
// - https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Frpc.polimec.org#/explorer/query/0x6fec4ce782f42afae1437f53e3382d9e6804692de868a28908ed6b9104bdd536
Expand Down
8 changes: 4 additions & 4 deletions runtimes/polimec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ pub struct DustRemovalAdapter;

impl tokens::imbalance::OnUnbalanced<CreditOf<Runtime>> for DustRemovalAdapter {
fn on_nonzero_unbalanced(amount: CreditOf<Runtime>) {
let treasury_account = PayMaster::get();
let treasury_account = BlockchainOperationTreasury::get();
let _ = <Balances as tokens::fungible::Balanced<AccountId>>::resolve(&treasury_account, amount);
}
}
Expand Down Expand Up @@ -670,7 +670,7 @@ impl GetElectorate<Balance> for Electorate {
fn get_electorate() -> Balance {
let total_issuance = Balances::total_issuance();
let growth_treasury_balance = Balances::balance(&Treasury::account_id());
let protocol_treasury_balance = Balances::balance(&PayMaster::get());
let protocol_treasury_balance = Balances::balance(&BlockchainOperationTreasury::get());
total_issuance.saturating_sub(growth_treasury_balance).saturating_sub(protocol_treasury_balance)
}
}
Expand Down Expand Up @@ -789,7 +789,7 @@ impl pallet_parachain_staking::Config for Runtime {
type MonetaryGovernanceOrigin = frame_system::EnsureRoot<AccountId>;
type OnCollatorPayout = ();
type OnNewRound = ();
type PayMaster = PayMaster;
type PayMaster = BlockchainOperationTreasury;
// We use the default implementation, so we leave () here.
type PayoutCollatorReward = ();
type RevokeDelegationDelay = RevokeDelegationDelay;
Expand Down Expand Up @@ -1036,6 +1036,7 @@ impl pallet_funding::Config for Runtime {
type Balance = Balance;
type BlockNumber = BlockNumber;
type BlockNumberToBalance = ConvertInto;
type BlockchainOperationTreasury = BlockchainOperationTreasury;
type CommunityFundingDuration = CommunityFundingDuration;
type ContributionTokenCurrency = ContributionTokens;
type ContributionTreasury = ContributionTreasuryAccount;
Expand Down Expand Up @@ -1063,7 +1064,6 @@ impl pallet_funding::Config for Runtime {
type PreImageLimit = ConstU32<1024>;
type Price = Price;
type PriceProvider = OraclePriceProvider<AssetId, Price, Oracle>;
type ProtocolGrowthTreasury = TreasuryAccount;
type Randomness = Random;
type RemainderFundingDuration = RemainderFundingDuration;
type RequiredMaxCapacity = RequiredMaxCapacity;
Expand Down
4 changes: 2 additions & 2 deletions runtimes/shared-configuration/src/fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ parameter_types! {
}

ord_parameter_types! {
pub const PayMaster: AccountId =
pub const BlockchainOperationTreasury: AccountId =
AccountIdConversion::<AccountId>::into_account_truncating(&StakingPalletId::get());
}

Expand Down Expand Up @@ -125,7 +125,7 @@ where
<R as frame_system::Config>::AccountId: Into<AccountId>,
{
fn on_nonzero_unbalanced(amount: Credit<<R as frame_system::Config>::AccountId, pallet_balances::Pallet<R>>) {
let staking_pot = PayMaster::get().into();
let staking_pot = BlockchainOperationTreasury::get().into();
let _ = <pallet_balances::Pallet<R>>::resolve(&staking_pot, amount);
}
}
Expand Down

0 comments on commit 66262af

Please sign in to comment.