Skip to content
Snippets Groups Projects
Commit b1b44b9b authored by Éloïs's avatar Éloïs
Browse files

feat: add treasury

parent 89f21b27
No related branches found
No related tags found
No related merge requests found
Showing
with 202 additions and 14 deletions
......@@ -840,6 +840,7 @@ dependencies = [
"pallet-membership",
"pallet-provide-randomness",
"pallet-session",
"pallet-treasury",
"pallet-ud-accounts-storage",
"parity-scale-codec",
"scale-info",
......@@ -1976,6 +1977,7 @@ dependencies = [
"pallet-timestamp",
"pallet-transaction-payment",
"pallet-transaction-payment-rpc-runtime-api",
"pallet-treasury",
"pallet-ud-accounts-storage",
"pallet-universal-dividend",
"pallet-utility",
......@@ -2037,6 +2039,7 @@ dependencies = [
"pallet-timestamp",
"pallet-transaction-payment",
"pallet-transaction-payment-rpc-runtime-api",
"pallet-treasury",
"pallet-ud-accounts-storage",
"pallet-universal-dividend",
"pallet-upgrade-origin",
......@@ -2240,6 +2243,7 @@ dependencies = [
"pallet-timestamp",
"pallet-transaction-payment",
"pallet-transaction-payment-rpc-runtime-api",
"pallet-treasury",
"pallet-ud-accounts-storage",
"pallet-universal-dividend",
"pallet-utility",
......@@ -4440,9 +4444,11 @@ dependencies = [
"frame-benchmarking",
"frame-support",
"frame-system",
"log",
"maplit",
"pallet-balances",
"pallet-provide-randomness",
"pallet-treasury",
"parity-scale-codec",
"scale-info",
"serde",
......@@ -4747,6 +4753,23 @@ dependencies = [
"sp-runtime",
]
[[package]]
name = "pallet-treasury"
version = "4.0.0-dev"
source = "git+https://github.com/librelois/substrate.git?branch=duniter-monthly-2022-02#8fbc011c06ee051577022c8fd84f2a018123efd3"
dependencies = [
"frame-benchmarking",
"frame-support",
"frame-system",
"impl-trait-for-tuples",
"pallet-balances",
"parity-scale-codec",
"scale-info",
"serde",
"sp-runtime",
"sp-std",
]
[[package]]
name = "pallet-ud-accounts-storage"
version = "3.0.0"
......
......@@ -378,6 +378,7 @@ fn gen_genesis_conf(
first_ud: 1_000,
initial_monetary_mass: 0,
},
treasury: Default::default(),
}
}
......@@ -482,5 +483,6 @@ fn genesis_data_to_gdev_genesis_conf(
first_ud,
initial_monetary_mass,
},
treasury: Default::default(),
}
}
......@@ -19,6 +19,7 @@ std = [
'frame-benchmarking/std',
'pallet-balances/std',
'pallet-provide-randomness/std',
'pallet-treasury/std',
'serde',
'sp-core/std',
'sp-io/std',
......@@ -33,6 +34,7 @@ pallet-provide-randomness = { path = "../provide-randomness", default-features =
# crates.io
codec = { package = 'parity-scale-codec', version = "2.3.1", default-features = false, features = ["derive"] }
log = { version = "0.4.14", default-features = false }
scale-info = { version = "1.0", default-features = false, features = ["derive"] }
# substrate
......@@ -57,6 +59,11 @@ default-features = false
git = 'https://github.com/librelois/substrate.git'
branch = 'duniter-monthly-2022-02'
[dependencies.pallet-treasury]
default-features = false
git = 'https://github.com/librelois/substrate.git'
branch = 'duniter-monthly-2022-02'
[dependencies.serde]
version = "1.0.101"
optional = true
......
......@@ -49,6 +49,7 @@ pub mod pallet {
frame_system::Config<AccountData = AccountData<Self::Balance>>
+ pallet_balances::Config
+ pallet_provide_randomness::Config<Currency = pallet_balances::Pallet<Self>>
+ pallet_treasury::Config<Currency = pallet_balances::Pallet<Self>>
{
type AccountIdToSalt: Convert<Self::AccountId, [u8; 32]>;
/// The overarching event type.
......@@ -89,6 +90,16 @@ pub mod pallet {
#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig<T> {
fn build(&self) {
// Treasury
frame_system::Account::<T>::mutate(
pallet_treasury::Pallet::<T>::account_id(),
|account| {
account.data.random_id = None;
account.data.free = T::ExistentialDeposit::get();
account.providers = 1;
},
);
// Classic accounts
for (
account_id,
GenesisAccountData {
......@@ -146,7 +157,7 @@ pub mod pallet {
} else {
// If the account is not self-sufficient, it must pay the account creation fees
frame_system::Pallet::<T>::inc_providers(&account_id);
let res = T::Currency::withdraw(
let res = <pallet_balances::Pallet<T> as Currency<T::AccountId>>::withdraw(
&account_id,
T::NewAccountPrice::get(),
frame_support::traits::WithdrawReasons::FEE,
......@@ -180,12 +191,20 @@ pub mod pallet {
"Cannot fail because providers are incremented just before"
);
let account_data = frame_system::Pallet::<T>::get(&account_id);
let (imbalance, rest) = pallet_balances::Pallet::<T>::slash(
let res = <pallet_balances::Pallet<T> as Currency<T::AccountId>>::withdraw(
&account_id,
account_data.free.saturating_add(account_data.reserved),
frame_support::traits::WithdrawReasons::FEE,
ExistenceRequirement::AllowDeath,
);
debug_assert!(rest.is_zero());
T::OnUnbalanced::on_unbalanced(imbalance);
if let Ok(imbalance) = res {
T::OnUnbalanced::on_unbalanced(imbalance);
} else {
log::warn!(
"Unexpected withdraw fail to destroy account {:?}",
&account_id
);
}
total_weight += 300_000;
}
}
......
......@@ -14,6 +14,7 @@ runtime-benchmarks = [
'pallet-duniter-wot/runtime-benchmarks',
'pallet-identity/runtime-benchmarks',
'pallet-membership/runtime-benchmarks',
'pallet-treasury/std',
'pallet-ud-accounts-storage/runtime-benchmarks',
'sp-runtime/runtime-benchmarks',
]
......@@ -31,6 +32,7 @@ std = [
'pallet-identity/std',
'pallet-membership/std',
'pallet-provide-randomness/std',
'pallet-treasury/std',
'pallet-ud-accounts-storage/std',
'serde',
'sp-arithmetic/std',
......@@ -90,6 +92,11 @@ features = ["historical"]
git = 'https://github.com/librelois/substrate.git'
branch = 'duniter-monthly-2022-02'
[dependencies.pallet-treasury]
default-features = false
git = 'https://github.com/librelois/substrate.git'
branch = 'duniter-monthly-2022-02'
[dependencies.serde]
version = "1.0.101"
optional = true
......
......@@ -188,3 +188,18 @@ where
0
}
}
pub struct TreasurySpendFunds<Runtime>(core::marker::PhantomData<Runtime>);
impl<Runtime> pallet_treasury::SpendFunds<Runtime> for TreasurySpendFunds<Runtime>
where
Runtime: pallet_treasury::Config,
{
fn spend_funds(
_budget_remaining: &mut pallet_treasury::BalanceOf<Runtime>,
_imbalance: &mut pallet_treasury::PositiveImbalanceOf<Runtime>,
_total_weight: &mut Weight,
missed_any: &mut bool,
) {
*missed_any = true;
}
}
......@@ -155,7 +155,7 @@ macro_rules! pallets_config {
type Balance = Balance;
/// The ubiquitous event type.
type Event = Event;
type DustRemoval = ();
type DustRemoval = Treasury;
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = Account;
type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>;
......@@ -272,7 +272,7 @@ macro_rules! pallets_config {
type MaxRequests = frame_support::traits::ConstU32<1_000>;
type RequestPrice = frame_support::traits::ConstU64<200>;
type OnFilledRandomness = Account;
type OnUnbalanced = ();
type OnUnbalanced = Treasury;
type CurrentBlockRandomness = pallet_babe::CurrentBlockRandomness<Self>;
type RandomnessFromOneEpochAgo = pallet_babe::RandomnessFromOneEpochAgo<Self>;
}
......@@ -321,6 +321,33 @@ macro_rules! pallets_config {
type WeightInfo = pallet_utility::weights::SubstrateWeight<Self>;
}
parameter_types! {
pub const Burn: Permill = Permill::zero();
pub const ProposalBond: Permill = Permill::from_percent(1);
pub const ProposalBondMaximum: Option<Balance> = None;
pub const SpendPeriod: BlockNumber = DAYS;
// Treasury account address:
// gdev/gtest: 5EYCAe5ijiYfyeZ2JJCGq56LmPyNRAKzpG4QkoQkkQNB5e6Z
pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry");
}
impl pallet_treasury::Config for Runtime {
type ApproveOrigin = TreasuryApproveOrigin;
type Burn = Burn;
type BurnDestination = ();
type Currency = Balances;
type Event = Event;
type OnSlash = Treasury;
type ProposalBond = ProposalBond;
type ProposalBondMinimum = frame_support::traits::ConstU64<10_000>;
type ProposalBondMaximum = ProposalBondMaximum;
type MaxApprovals = frame_support::traits::ConstU32<10>;
type PalletId = TreasuryPalletId;
type RejectOrigin = TreasuryRejectOrigin;
type SpendFunds = TreasurySpendFunds<Self>;
type SpendPeriod = SpendPeriod;
type WeightInfo = pallet_treasury::weights::SubstrateWeight<Self>;
}
// UNIVERSAL DIVIDEND //
impl pallet_universal_dividend::Config for Runtime {
......
......@@ -22,8 +22,9 @@ runtime-benchmarks = [
'frame-system/runtime-benchmarks',
'hex-literal',
'pallet-balances/runtime-benchmarks',
'pallet-universal-dividend/runtime-benchmarks',
'pallet-timestamp/runtime-benchmarks',
'pallet-treasury/runtime-benchmarks',
'pallet-universal-dividend/runtime-benchmarks',
'sp-runtime/runtime-benchmarks',
]
std = [
......@@ -50,10 +51,11 @@ std = [
'pallet-proxy/std',
'pallet-session/std',
'pallet-sudo/std',
'pallet-universal-dividend/std',
'pallet-timestamp/std',
'pallet-transaction-payment-rpc-runtime-api/std',
'pallet-transaction-payment/std',
'pallet-treasury/std',
'pallet-universal-dividend/std',
'common-runtime/std',
'serde',
'sp-api/std',
......@@ -217,6 +219,11 @@ default-features = false
git = 'https://github.com/librelois/substrate.git'
branch = 'duniter-monthly-2022-02'
[dependencies.pallet-treasury]
default-features = false
git = 'https://github.com/librelois/substrate.git'
branch = 'duniter-monthly-2022-02'
[dependencies.pallet-utility]
default-features = false
git = 'https://github.com/librelois/substrate.git'
......
......@@ -42,6 +42,7 @@ pub use sp_runtime::{KeyTypeId, Perbill, Permill};
use common_runtime::IdtyNameValidatorImpl;
use frame_support::traits::Contains;
use frame_support::PalletId;
use frame_system::EnsureRoot;
use pallet_grandpa::fg_primitives;
use pallet_grandpa::{AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList};
......@@ -121,6 +122,8 @@ pub type Executive = frame_executive::Executive<
AllPalletsWithSystem,
>;
pub type SmithsInstance = Instance2;
pub struct BaseCallFilter;
impl Contains<Call> for BaseCallFilter {
fn contains(call: &Call) -> bool {
......@@ -241,6 +244,7 @@ construct_runtime!(
ProvideRandomness: pallet_provide_randomness::{Pallet, Call, Storage, Event} = 62,
Proxy: pallet_proxy::{Pallet, Call, Storage, Event<T>} = 63,
Utility: pallet_utility::{Pallet, Call, Event} = 64,
Treasury: pallet_treasury::{Pallet, Call, Config, Storage, Event<T>} = 65,
}
);
......
......@@ -14,11 +14,13 @@
// You should have received a copy of the GNU Affero General Public License
// along with Substrate-Libre-Currency. If not, see <https://www.gnu.org/licenses/>.
use crate::*;
use common_runtime::constants::*;
use common_runtime::{Balance, BlockNumber};
use frame_support::parameter_types;
use frame_support::weights::constants::WEIGHT_PER_SECOND;
use sp_arithmetic::Perbill;
use sp_core::u32_trait::*;
use sp_runtime::transaction_validity::TransactionPriority;
parameter_types! {
......@@ -146,7 +148,17 @@ parameter_types! {
pub const SmithValidityPeriod: BlockNumber = 146 * DAYS;
}
/*************/
/* UTILITIES */
/*************/
// Multisig
parameter_types! {
pub const MaxSignatories: u16 = 5;
}
// Treasury
pub type TreasuryApproveOrigin =
pallet_collective::EnsureProportionMoreThan<_1, _2, AccountId, SmithsInstance>;
pub type TreasuryRejectOrigin =
pallet_collective::EnsureProportionMoreThan<_1, _3, AccountId, SmithsInstance>;
......@@ -23,6 +23,7 @@ runtime-benchmarks = [
'hex-literal',
'pallet-balances/runtime-benchmarks',
'pallet-identity/runtime-benchmarks',
'pallet-treasury/runtime-benchmarks',
'pallet-universal-dividend/runtime-benchmarks',
'common-runtime/runtime-benchmarks',
'sp-runtime/runtime-benchmarks',
......@@ -57,6 +58,7 @@ std = [
'pallet-timestamp/std',
'pallet-transaction-payment-rpc-runtime-api/std',
'pallet-transaction-payment/std',
'pallet-treasury/std',
'common-runtime/std',
'serde',
'sp-api/std',
......@@ -227,6 +229,12 @@ default-features = false
git = 'https://github.com/librelois/substrate.git'
branch = 'duniter-monthly-2022-02'
[dependencies.pallet-treasury]
default-features = false
git = 'https://github.com/librelois/substrate.git'
branch = 'duniter-monthly-2022-02'
[dependencies.pallet-utility]
default-features = false
git = 'https://github.com/librelois/substrate.git'
......
......@@ -42,6 +42,7 @@ pub use sp_runtime::{KeyTypeId, Perbill, Permill};
use common_runtime::IdtyNameValidatorImpl;
use frame_support::traits::Contains;
use frame_support::PalletId;
use frame_system::EnsureRoot;
use pallet_grandpa::fg_primitives;
use pallet_grandpa::{AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList};
......@@ -123,6 +124,8 @@ pub type Executive = frame_executive::Executive<
AllPalletsWithSystem,
>;
pub type SmithsInstance = Instance2;
pub struct BaseCallFilter;
impl Contains<Call> for BaseCallFilter {
fn contains(call: &Call) -> bool {
......@@ -131,7 +134,8 @@ impl Contains<Call> for BaseCallFilter {
Call::System(
frame_system::Call::remark { .. } | frame_system::Call::remark_with_event { .. }
) | Call::Membership(
pallet_membership::Call::claim_membership { .. }
pallet_membership::Call::request_membership { .. }
| pallet_membership::Call::claim_membership { .. }
| pallet_membership::Call::revoke_membership { .. }
) | Call::Session(_)
| Call::SmithsMembership(pallet_membership::Call::claim_membership { .. })
......@@ -232,7 +236,7 @@ common_runtime::pallets_config! {
impl pallet_upgrade_origin::Config for Runtime {
type Event = Event;
type Call = Call;
type UpgradableOrigin = pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, Instance2>;
type UpgradableOrigin = pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, SmithsInstance>;
}
}
......@@ -295,6 +299,7 @@ construct_runtime!(
ProvideRandomness: pallet_provide_randomness::{Pallet, Call, Storage, Event} = 62,
Proxy: pallet_proxy::{Pallet, Call, Storage, Event<T>} = 63,
Utility: pallet_utility::{Pallet, Call, Event} = 64,
Treasury: pallet_treasury::{Pallet, Call, Config, Storage, Event<T>} = 65,
}
);
......
......@@ -14,11 +14,13 @@
// You should have received a copy of the GNU Affero General Public License
// along with Substrate-Libre-Currency. If not, see <https://www.gnu.org/licenses/>.
use crate::*;
use common_runtime::constants::*;
use common_runtime::{Balance, BlockNumber};
use frame_support::parameter_types;
use frame_support::weights::constants::WEIGHT_PER_SECOND;
use sp_arithmetic::Perbill;
use sp_core::u32_trait::*;
use sp_runtime::transaction_validity::TransactionPriority;
parameter_types! {
......@@ -84,7 +86,17 @@ parameter_types! {
pub const SquareMoneyGrowthRate: Perbill = Perbill::from_parts(2_381_440);
}
/*************/
/* UTILITIES */
/*************/
// Multisig
parameter_types! {
pub const MaxSignatories: u16 = 5;
}
// Treasury
pub type TreasuryApproveOrigin =
pallet_collective::EnsureProportionMoreThan<_1, _2, AccountId, SmithsInstance>;
pub type TreasuryRejectOrigin =
pallet_collective::EnsureProportionMoreThan<_1, _3, AccountId, SmithsInstance>;
......@@ -24,6 +24,11 @@ use gdev_runtime::*;
use sp_keyring::AccountKeyring;
use sp_runtime::MultiAddress;
#[test]
fn verify_treasury_account() {
println!("{}", Treasury::account_id());
}
#[test]
fn verify_pallet_prefixes() {
let prefix = |pallet_name, storage_name| {
......@@ -179,8 +184,8 @@ fn test_create_new_account() {
// and new account tax should be collected
run_to_block(3);
let events = System::events();
//println!("{:#?}", events);
assert_eq!(events.len(), 2);
println!("{:#?}", events);
assert_eq!(events.len(), 4);
assert_eq!(
System::events()[0].event,
Event::System(frame_system::Event::NewAccount {
......@@ -194,10 +199,22 @@ fn test_create_new_account() {
amount: 300,
})
);
assert_eq!(
System::events()[2].event,
Event::Balances(pallet_balances::Event::Deposit {
who: Treasury::account_id(),
amount: 300,
})
);
assert_eq!(
System::events()[3].event,
Event::Treasury(pallet_treasury::Event::Deposit { value: 300 })
);
assert_eq!(
Balances::free_balance(AccountKeyring::Eve.to_account_id()),
200
);
assert_eq!(Balances::free_balance(Treasury::account_id()), 500);
// A random id request should be registered
assert_eq!(
......
......@@ -22,8 +22,9 @@ runtime-benchmarks = [
'frame-system/runtime-benchmarks',
'hex-literal',
'pallet-balances/runtime-benchmarks',
'pallet-universal-dividend/runtime-benchmarks',
'pallet-timestamp/runtime-benchmarks',
'pallet-treasury/runtime-benchmarks',
'pallet-universal-dividend/runtime-benchmarks',
'sp-runtime/runtime-benchmarks',
]
std = [
......@@ -50,10 +51,11 @@ std = [
'pallet-multisig/std',
'pallet-session/std',
'pallet-sudo/std',
'pallet-universal-dividend/std',
'pallet-timestamp/std',
'pallet-transaction-payment-rpc-runtime-api/std',
'pallet-transaction-payment/std',
'pallet-treasury/std',
'pallet-universal-dividend/std',
'common-runtime/std',
'serde',
'sp-api/std',
......@@ -217,6 +219,11 @@ default-features = false
git = 'https://github.com/librelois/substrate.git'
branch = 'duniter-monthly-2022-02'
[dependencies.pallet-treasury]
default-features = false
git = 'https://github.com/librelois/substrate.git'
branch = 'duniter-monthly-2022-02'
[dependencies.pallet-utility]
default-features = false
git = 'https://github.com/librelois/substrate.git'
......
......@@ -42,6 +42,7 @@ pub use sp_runtime::{KeyTypeId, Perbill, Permill};
use common_runtime::IdtyNameValidatorImpl;
use frame_support::traits::Contains;
use frame_support::PalletId;
use frame_system::EnsureRoot;
use pallet_grandpa::fg_primitives;
use pallet_grandpa::{AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList};
......@@ -122,6 +123,8 @@ pub type Executive = frame_executive::Executive<
AllPalletsWithSystem,
>;
pub type SmithsInstance = Instance2;
pub struct BaseCallFilter;
impl Contains<Call> for BaseCallFilter {
fn contains(call: &Call) -> bool {
......@@ -242,6 +245,7 @@ construct_runtime!(
ProvideRandomness: pallet_provide_randomness::{Pallet, Call, Storage, Event} = 62,
Proxy: pallet_proxy::{Pallet, Call, Storage, Event<T>} = 63,
Utility: pallet_utility::{Pallet, Call, Event} = 64,
Treasury: pallet_treasury::{Pallet, Call, Config, Storage, Event<T>} = 65,
}
);
......
......@@ -14,11 +14,13 @@
// You should have received a copy of the GNU Affero General Public License
// along with Substrate-Libre-Currency. If not, see <https://www.gnu.org/licenses/>.
use crate::*;
use common_runtime::constants::*;
use common_runtime::{Balance, BlockNumber};
use frame_support::parameter_types;
use frame_support::weights::constants::WEIGHT_PER_SECOND;
use sp_arithmetic::Perbill;
use sp_core::u32_trait::*;
use sp_runtime::transaction_validity::TransactionPriority;
parameter_types! {
......@@ -146,7 +148,17 @@ parameter_types! {
pub const SmithValidityPeriod: BlockNumber = 146 * DAYS;
}
/*************/
/* UTILITIES */
/*************/
// Multisig
parameter_types! {
pub const MaxSignatories: u16 = 5;
}
// Treasury
pub type TreasuryApproveOrigin =
pallet_collective::EnsureProportionMoreThan<_1, _2, AccountId, SmithsInstance>;
pub type TreasuryRejectOrigin =
pallet_collective::EnsureProportionMoreThan<_1, _3, AccountId, SmithsInstance>;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment