Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ members = [
"pallets/qpow",
"pallets/reversible-transfers",
"pallets/scheduler",
"pallets/treasury",
"pallets/wormhole",
"primitives/consensus/pow",
"primitives/consensus/qpow",
Expand Down Expand Up @@ -136,6 +137,7 @@ pallet-multisig = { path = "./pallets/multisig", default-features = false }
pallet-qpow = { path = "./pallets/qpow", default-features = false }
pallet-reversible-transfers = { path = "./pallets/reversible-transfers", default-features = false }
pallet-scheduler = { path = "./pallets/scheduler", default-features = false }
pallet-treasury = { path = "./pallets/treasury", default-features = false }
pallet-wormhole = { path = "./pallets/wormhole", default-features = false }
qp-dilithium-crypto = { path = "./primitives/dilithium-crypto", version = "0.2.0", default-features = false }
qp-header = { path = "./primitives/header", default-features = false }
Expand Down Expand Up @@ -184,7 +186,6 @@ pallet-timestamp = { version = "40.0.0", default-features = false }
pallet-transaction-payment = { version = "41.0.0", default-features = false }
pallet-transaction-payment-rpc = { version = "44.0.0", default-features = false }
pallet-transaction-payment-rpc-runtime-api = { version = "41.0.0", default-features = false }
pallet-treasury = { version = "40.0.0", default-features = false }
pallet-utility = { version = "41.0.0", default-features = false }
prometheus-endpoint = { version = "0.17.2", default-features = false, package = "substrate-prometheus-endpoint" }
sc-basic-authorship = { version = "0.50.0", default-features = false }
Expand Down
13 changes: 9 additions & 4 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use sp_core::{
H256,
};
use sp_keyring::Sr25519Keyring;
use sp_runtime::traits::{AccountIdConversion, IdentifyAccount};
use sp_runtime::traits::IdentifyAccount;

#[derive(Debug, PartialEq)]
pub struct QuantusKeyDetails {
Expand Down Expand Up @@ -459,9 +459,14 @@ pub fn run() -> sc_cli::Result<()> {
None => {
// Automatically set rewards_address to Treasury when --dev is used
if cli.run.shared_params.is_dev() {
let treasury_account =
quantus_runtime::configs::TreasuryPalletId::get()
.into_account_truncating();
let chain_id = config.chain_spec.id();
let treasury_account = quantus_runtime::genesis_config_presets::get_treasury_account_for_chain(chain_id)
.ok_or_else(|| {
sc_cli::Error::Input(format!(
"Unknown chain ID for treasury config: {}",
chain_id
))
})?;
log::info!(
"⛏️ Using treasury address for rewards: {:?}",
treasury_account
Expand Down
4 changes: 4 additions & 0 deletions pallets/mining-rewards/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ frame-benchmarking = { optional = true, workspace = true, default-features = fal
frame-support.workspace = true
frame-system.workspace = true
log.workspace = true
pallet-treasury = { workspace = true, default-features = false }
qp-wormhole.workspace = true
scale-info = { workspace = true, default-features = false, features = ["derive"] }
sp-consensus-pow.workspace = true
Expand All @@ -30,6 +31,8 @@ sp-runtime.workspace = true
[dev-dependencies]
pallet-balances.features = ["std"]
pallet-balances.workspace = true
pallet-treasury.features = ["std"]
pallet-treasury.workspace = true
sp-core.workspace = true
sp-io.workspace = true

Expand All @@ -45,6 +48,7 @@ std = [
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"pallet-treasury/std",
"qp-wormhole/std",
"scale-info/std",
"sp-consensus-pow/std",
Expand Down
10 changes: 4 additions & 6 deletions pallets/mining-rewards/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ use frame_benchmarking::{account, v2::*, BenchmarkError};
use frame_support::traits::fungible::{Inspect, Mutate};
use frame_system::{pallet_prelude::BlockNumberFor, Pallet as SystemPallet};
use sp_consensus_pow::POW_ENGINE_ID;
use sp_runtime::{
generic::{Digest, DigestItem},
traits::AccountIdConversion,
};
use sp_runtime::generic::{Digest, DigestItem};

#[benchmarks]
mod benchmarks {
use super::*;
use codec::Encode;
use frame_support::traits::{Get, OnFinalize};
use frame_support::traits::OnFinalize;
use pallet_treasury::TreasuryProvider;
use sp_runtime::Saturating;

#[benchmark]
Expand All @@ -37,7 +35,7 @@ mod benchmarks {
);

// Pre-fund Treasury account to ensure it exists
let treasury_account = T::TreasuryPalletId::get().into_account_truncating();
let treasury_account = T::Treasury::account_id();
let ed = T::Currency::minimum_balance();
let _ = T::Currency::mint_into(&treasury_account, ed.saturating_mul(1000u32.into()));
let _ = T::Currency::mint_into(&miner, ed.saturating_mul(1000u32.into()));
Expand Down
19 changes: 6 additions & 13 deletions pallets/mining-rewards/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ pub mod pallet {
},
};
use frame_system::pallet_prelude::*;
use pallet_treasury::TreasuryProvider;
use qp_wormhole::TransferProofs;
use sp_consensus_pow::POW_ENGINE_ID;
use sp_runtime::{
generic::DigestItem,
traits::{AccountIdConversion, Saturating},
};
use sp_runtime::{generic::DigestItem, traits::Saturating};

const UNIT: u128 = 1_000_000_000_000u128;

Expand Down Expand Up @@ -62,13 +60,8 @@ pub mod pallet {
#[pallet::constant]
type EmissionDivisor: Get<BalanceOf<Self>>;

/// The portion of rewards that goes to treasury (out of 100)
#[pallet::constant]
type TreasuryPortion: Get<u8>;

/// The treasury pallet ID
#[pallet::constant]
type TreasuryPalletId: Get<frame_support::PalletId>;
/// Provides treasury account and portion (from pallet_treasury or mock)
type Treasury: pallet_treasury::TreasuryProvider<AccountId = Self::AccountId>;

/// Account ID used as the "from" account when creating transfer proofs for minted tokens
#[pallet::constant]
Expand Down Expand Up @@ -126,7 +119,7 @@ pub mod pallet {
.unwrap_or_else(BalanceOf::<T>::zero);

// Split the reward between treasury and miner
let treasury_portion = T::TreasuryPortion::get();
let treasury_portion = T::Treasury::portion();
let treasury_reward =
total_reward.saturating_mul(treasury_portion.into()) / 100u32.into();
let miner_reward = total_reward.saturating_sub(treasury_reward);
Expand Down Expand Up @@ -213,7 +206,7 @@ pub mod pallet {
Self::deposit_event(Event::MinerRewarded { miner: miner.clone(), reward });
},
None => {
let treasury = T::TreasuryPalletId::get().into_account_truncating();
let treasury = T::Treasury::account_id();
let _ = T::Currency::mint_into(&treasury, reward).defensive();

T::Currency::store_transfer_proof(&mint_account, &treasury, reward);
Expand Down
25 changes: 19 additions & 6 deletions pallets/mining-rewards/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use codec::Encode;
use frame_support::{
parameter_types,
traits::{ConstU32, Everything, Hooks},
PalletId,
};
use sp_consensus_pow::POW_ENGINE_ID;
use sp_runtime::{
Expand Down Expand Up @@ -32,7 +31,19 @@ parameter_types! {
pub const MaxSupply: u128 = 21_000_000 * UNIT;
pub const EmissionDivisor: u128 = 26_280_000;
pub const ExistentialDeposit: Balance = 1;
pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry");
pub const TreasuryAccount: sp_core::crypto::AccountId32 = sp_core::crypto::AccountId32::new([42u8; 32]);
}

/// Mock treasury for mining-rewards tests
pub struct MockTreasury;
impl pallet_treasury::TreasuryProvider for MockTreasury {
type AccountId = sp_core::crypto::AccountId32;
fn account_id() -> Self::AccountId {
TreasuryAccount::get()
}
fn portion() -> u8 {
50
}
}

impl frame_system::Config for Test {
Expand Down Expand Up @@ -86,7 +97,6 @@ impl pallet_balances::Config for Test {
}

parameter_types! {
pub const TreasuryPortion: u8 = 50; // 50% goes to treasury in tests (matching runtime)
pub const MintingAccount: sp_core::crypto::AccountId32 = sp_core::crypto::AccountId32::new([99u8; 32]);
}

Expand All @@ -95,8 +105,7 @@ impl pallet_mining_rewards::Config for Test {
type WeightInfo = ();
type MaxSupply = MaxSupply;
type EmissionDivisor = EmissionDivisor;
type TreasuryPortion = TreasuryPortion;
type TreasuryPalletId = TreasuryPalletId;
type Treasury = MockTreasury;
type MintingAccount = MintingAccount;
}

Expand All @@ -118,7 +127,11 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();

pallet_balances::GenesisConfig::<Test> {
balances: vec![(miner(), ExistentialDeposit::get()), (miner2(), ExistentialDeposit::get())],
balances: vec![
(miner(), ExistentialDeposit::get()),
(miner2(), ExistentialDeposit::get()),
(TreasuryAccount::get(), ExistentialDeposit::get()),
],
}
.assimilate_storage(&mut t)
.unwrap();
Expand Down
Loading
Loading