Skip to content

Commit

Permalink
Add pallet-treasury
Browse files Browse the repository at this point in the history
  • Loading branch information
khssnv committed Dec 8, 2023
1 parent b0220f5 commit 377165f
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 11 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pallet-timestamp = { version = "23.0.0", default-features = false }
pallet-transaction-payment = { version = "24.0.0", default-features = false }
pallet-transaction-payment-rpc = { version = "26.0.0" }
pallet-transaction-payment-rpc-runtime-api = { version = "24.0.0", default-features = false }
pallet-treasury = { version = "23.0.0", default-features = false}
pallet-utility = { version = "24.0.0", default-features = false }
sc-basic-authorship = { version = "0.30.0" }
sc-chain-spec = { version = "23.0.0" }
Expand Down
2 changes: 2 additions & 0 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ pub mod devnet {
..Default::default()
},
transaction_payment: Default::default(),
treasury: Default::default(),
}
}
}
Expand Down Expand Up @@ -461,6 +462,7 @@ pub mod mainnet {
..Default::default()
},
transaction_payment: Default::default(),
treasury: Default::default(),
}
}
}
6 changes: 5 additions & 1 deletion runtime/devnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ scale-info = { workspace = true, default-features = false, features = [
smallvec = { workspace = true }

# Local
runtime-common = { path = "../common", default-features = false }
runtime-common = { workspace = true, default-features = false }

# Substrate
frame-benchmarking = { workspace = true, default-features = false, optional = true }
Expand All @@ -52,6 +52,7 @@ pallet-sudo = { workspace = true, default-features = false }
pallet-timestamp = { workspace = true, default-features = false }
pallet-transaction-payment = { workspace = true, default-features = false }
pallet-transaction-payment-rpc-runtime-api = { workspace = true, default-features = false }
pallet-treasury = { workspace = true, default-features = false }
pallet-utility = { workspace = true, default-features = false }
sp-api = { workspace = true, default-features = false }
sp-block-builder = { workspace = true, default-features = false }
Expand Down Expand Up @@ -123,6 +124,7 @@ std = [
"pallet-timestamp/std",
"pallet-transaction-payment-rpc-runtime-api/std",
"pallet-transaction-payment/std",
"pallet-treasury/std",
"pallet-utility/std",
"pallet-xcm/std",
"parachain-info/std",
Expand Down Expand Up @@ -167,6 +169,7 @@ runtime-benchmarks = [
"pallet-preimage/runtime-benchmarks",
"pallet-scheduler/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-treasury/runtime-benchmarks",
"pallet-utility/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
Expand Down Expand Up @@ -198,6 +201,7 @@ try-runtime = [
"pallet-sudo/try-runtime",
"pallet-timestamp/try-runtime",
"pallet-transaction-payment/try-runtime",
"pallet-treasury/try-runtime",
"pallet-utility/try-runtime",
"pallet-xcm/try-runtime",
"parachain-info/try-runtime",
Expand Down
49 changes: 44 additions & 5 deletions runtime/devnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use frame_support::{
};
use frame_system::{
limits::{BlockLength, BlockWeights},
EnsureRoot, EnsureSigned,
EnsureRoot, EnsureSigned, EnsureWithSuccess,
};
use pallet_nfts::PalletFeatures;
use pallet_xcm::{EnsureXcm, IsVoiceOfBody};
Expand All @@ -48,7 +48,7 @@ pub use runtime_common::{
NORMAL_DISPATCH_RATIO, SLOT_DURATION,
};
pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
pub use sp_runtime::{MultiAddress, Perbill, Permill};
pub use sp_runtime::{MultiAddress, Perbill, Percent, Permill};
use xcm_config::{RelayLocation, XcmConfig, XcmOriginToTransactDispatchOrigin};

#[cfg(any(feature = "std", test))]
Expand Down Expand Up @@ -615,9 +615,7 @@ impl pallet_identity::Config for Runtime {
type MaxSubAccounts = ConstU32<100>;
type MaxAdditionalFields = ConstU32<100>;
type MaxRegistrars = ConstU32<20>;
// SBP-M1 review: consider what happens with slashed funds - e.g. treasury
// TODO (@khssnv)
type Slashed = ();
type Slashed = Treasury;
type ForceOrigin = EnsureRoot<AccountId>;
// SBP-M1 review: should be EnsureRoot or MQTY admin origin to maintain registrar integrity
// TODO (@khssnv): consider Verifier origin
Expand Down Expand Up @@ -701,6 +699,46 @@ impl pallet_nft_fractionalization::Config for Runtime {
type WeightInfo = pallet_nft_fractionalization::weights::SubstrateWeight<Runtime>;
}

parameter_types! {
pub const ProposalBond: Permill = Permill::from_percent(5);
pub const ProposalBondMinimum: Balance = 1 * MQTY;
pub const SpendPeriod: BlockNumber = 1 * DAYS;
pub const Burn: Permill = Permill::from_percent(50);
pub const TipCountdown: BlockNumber = 1 * DAYS;
pub const TipFindersFee: Percent = Percent::from_percent(20);
pub const TipReportDepositBase: Balance = 1 * MQTY;
pub const DataDepositPerByte: Balance = deposit(0, 1);
pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry");
pub const MaximumReasonLength: u32 = 300;
pub const MaxApprovals: u32 = 100;
pub const MaxBalance: Balance = Balance::max_value();
}

impl pallet_treasury::Config for Runtime {
type PalletId = TreasuryPalletId;
type Currency = Balances;
type ApproveOrigin = EitherOfDiverse<
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<AccountId, CouncilCollective, 3, 5>,
>;
type RejectOrigin = EitherOfDiverse<
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionMoreThan<AccountId, CouncilCollective, 1, 2>,
>;
type RuntimeEvent = RuntimeEvent;
type OnSlash = ();
type ProposalBond = ProposalBond;
type ProposalBondMinimum = ProposalBondMinimum;
type ProposalBondMaximum = ();
type SpendPeriod = SpendPeriod;
type Burn = Burn;
type BurnDestination = ();
type SpendFunds = ();
type WeightInfo = pallet_treasury::weights::SubstrateWeight<Runtime>;
type MaxApprovals = MaxApprovals;
type SpendOrigin = EnsureWithSuccess<EnsureRoot<AccountId>, AccountId, MaxBalance>;
}

// Create the runtime by composing the FRAME pallets that were previously configured.
construct_runtime!(
pub struct Runtime {
Expand All @@ -720,6 +758,7 @@ construct_runtime!(
Balances: pallet_balances = 10,
TransactionPayment: pallet_transaction_payment = 11,
Assets: pallet_assets = 12,
Treasury: pallet_treasury = 13,

// Governance
Sudo: pallet_sudo = 15,
Expand Down
5 changes: 5 additions & 0 deletions runtime/mainnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pallet-sudo = { workspace = true, default-features = false }
pallet-timestamp = { workspace = true, default-features = false }
pallet-transaction-payment = { workspace = true, default-features = false }
pallet-transaction-payment-rpc-runtime-api = { workspace = true, default-features = false }
pallet-treasury = { workspace = true, default-features = false }
pallet-utility = { workspace = true, default-features = false }
sp-api = { workspace = true, default-features = false }
sp-block-builder = { workspace = true, default-features = false }
Expand Down Expand Up @@ -116,12 +117,14 @@ std = [
"pallet-multisig/std",
"pallet-nft-fractionalization/std",
"pallet-nfts/std",
"pallet-preimage/std",
"pallet-scheduler/std",
"pallet-session/std",
"pallet-sudo/std",
"pallet-timestamp/std",
"pallet-transaction-payment-rpc-runtime-api/std",
"pallet-transaction-payment/std",
"pallet-treasury/std",
"pallet-utility/std",
"pallet-xcm/std",
"parachain-info/std",
Expand Down Expand Up @@ -166,6 +169,7 @@ runtime-benchmarks = [
"pallet-preimage/runtime-benchmarks",
"pallet-scheduler/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-treasury/runtime-benchmarks",
"pallet-utility/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
Expand Down Expand Up @@ -197,6 +201,7 @@ try-runtime = [
"pallet-sudo/try-runtime",
"pallet-timestamp/try-runtime",
"pallet-transaction-payment/try-runtime",
"pallet-treasury/try-runtime",
"pallet-utility/try-runtime",
"pallet-xcm/try-runtime",
"parachain-info/try-runtime",
Expand Down
50 changes: 45 additions & 5 deletions runtime/mainnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use frame_support::{
};
use frame_system::{
limits::{BlockLength, BlockWeights},
EnsureRoot, EnsureSigned,
EnsureRoot, EnsureSigned, EnsureWithSuccess,
};
use pallet_nfts::PalletFeatures;
use pallet_xcm::{EnsureXcm, IsVoiceOfBody};
Expand All @@ -48,7 +48,7 @@ pub use runtime_common::{
NORMAL_DISPATCH_RATIO, SLOT_DURATION,
};
pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
pub use sp_runtime::{MultiAddress, Perbill, Permill};
pub use sp_runtime::{MultiAddress, Perbill, Percent, Permill};
use xcm_config::{RelayLocation, XcmConfig, XcmOriginToTransactDispatchOrigin};

#[cfg(any(feature = "std", test))]
Expand Down Expand Up @@ -615,9 +615,7 @@ impl pallet_identity::Config for Runtime {
type MaxSubAccounts = ConstU32<100>;
type MaxAdditionalFields = ConstU32<100>;
type MaxRegistrars = ConstU32<20>;
// SBP-M1 review: consider what happens with slashed funds - e.g. treasury
// TODO (@khssnv)
type Slashed = ();
type Slashed = Treasury;
type ForceOrigin = EnsureRoot<AccountId>;
// SBP-M1 review: should be EnsureRoot or MQTY admin origin to maintain registrar integrity
// TODO (@khssnv): consider Verifier origin
Expand Down Expand Up @@ -701,6 +699,46 @@ impl pallet_nft_fractionalization::Config for Runtime {
type WeightInfo = pallet_nft_fractionalization::weights::SubstrateWeight<Runtime>;
}

parameter_types! {
pub const ProposalBond: Permill = Permill::from_percent(5);
pub const ProposalBondMinimum: Balance = 1 * MQTY;
pub const SpendPeriod: BlockNumber = 1 * DAYS;
pub const Burn: Permill = Permill::from_percent(50);
pub const TipCountdown: BlockNumber = 1 * DAYS;
pub const TipFindersFee: Percent = Percent::from_percent(20);
pub const TipReportDepositBase: Balance = 1 * MQTY;
pub const DataDepositPerByte: Balance = deposit(0, 1);
pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry");
pub const MaximumReasonLength: u32 = 300;
pub const MaxApprovals: u32 = 100;
pub const MaxBalance: Balance = Balance::max_value();
}

impl pallet_treasury::Config for Runtime {
type PalletId = TreasuryPalletId;
type Currency = Balances;
type ApproveOrigin = EitherOfDiverse<
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<AccountId, CouncilCollective, 3, 5>,
>;
type RejectOrigin = EitherOfDiverse<
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionMoreThan<AccountId, CouncilCollective, 1, 2>,
>;
type RuntimeEvent = RuntimeEvent;
type OnSlash = ();
type ProposalBond = ProposalBond;
type ProposalBondMinimum = ProposalBondMinimum;
type ProposalBondMaximum = ();
type SpendPeriod = SpendPeriod;
type Burn = Burn;
type BurnDestination = ();
type SpendFunds = ();
type WeightInfo = pallet_treasury::weights::SubstrateWeight<Runtime>;
type MaxApprovals = MaxApprovals;
type SpendOrigin = EnsureWithSuccess<EnsureRoot<AccountId>, AccountId, MaxBalance>;
}

// Create the runtime by composing the FRAME pallets that were previously configured.
construct_runtime!(
pub struct Runtime {
Expand All @@ -720,6 +758,7 @@ construct_runtime!(
Balances: pallet_balances = 10,
TransactionPayment: pallet_transaction_payment = 11,
Assets: pallet_assets = 12,
Treasury: pallet_treasury = 13,

// Governance
Sudo: pallet_sudo = 15,
Expand Down Expand Up @@ -756,6 +795,7 @@ mod benches {
[pallet_session, SessionBench::<Runtime>]
[pallet_scheduler, Scheduler]
[pallet_timestamp, Timestamp]
[pallet_treasury, Treasury]
[pallet_collator_selection, CollatorSelection]
[pallet_multisig, Multisig]
[pallet_preimage, Preimage]
Expand Down

0 comments on commit 377165f

Please sign in to comment.