diff --git a/Cargo.lock b/Cargo.lock index 3c58ffa..5406b0d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2284,6 +2284,7 @@ version = "0.9.0" dependencies = [ "frame-benchmarking", "frame-benchmarking-cli", + "hex-literal", "integritee-node-runtime", "jsonrpc-core", "pallet-transaction-payment-rpc", @@ -3982,6 +3983,7 @@ name = "pallet-treasury" version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate.git?branch=master#b391b82954ad95a927a921035e3017c4a0aad516" dependencies = [ + "frame-benchmarking", "frame-support", "frame-system", "impl-trait-for-tuples", diff --git a/node/Cargo.toml b/node/Cargo.toml index e52864f..9082fd8 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -36,6 +36,7 @@ sp-finality-grandpa = { version = "4.0.0-dev", git = "https://github.com/parityt sc-client-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "master" } sp-runtime = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "master" } sp-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "master" } +hex-literal = { version = "0.3.1"} # These dependencies are used for the node template's RPCs jsonrpc-core = "18.0.0" diff --git a/node/src/chain_spec.rs b/node/src/chain_spec.rs index 1628dd8..56196b3 100644 --- a/node/src/chain_spec.rs +++ b/node/src/chain_spec.rs @@ -1,19 +1,17 @@ -use integritee_node_runtime::{ - AccountId, AuraConfig, BalancesConfig, GenesisConfig, GrandpaConfig, Signature, SudoConfig, - SystemConfig, WASM_BINARY, -}; +use integritee_node_runtime::{AccountId, AuraConfig, BalancesConfig, GenesisConfig, GrandpaConfig, Signature, SudoConfig, SystemConfig, WASM_BINARY, TreasuryPalletId}; use sc_service::ChainType; use sp_consensus_aura::sr25519::AuthorityId as AuraId; use sp_core::{sr25519, Pair, Public}; use sp_finality_grandpa::AuthorityId as GrandpaId; -use sp_runtime::traits::{IdentifyAccount, Verify}; +use sp_runtime::traits::{IdentifyAccount, Verify, AccountIdConversion}; // The URL for the telemetry server. // const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/"; /// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type. pub type ChainSpec = sc_service::GenericChainSpec; - +pub const TREASURY_FUNDING_PERCENT: u128 = 5; +pub const ENDOWED_FUNDING: u128 = 1 << 60; /// Generate a crypto pair from seed. pub fn get_from_seed(seed: &str) -> ::Public { TPublic::Pair::from_string(&format!("//{}", seed), None) @@ -35,10 +33,13 @@ where pub fn authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId) { (get_from_seed::(s), get_from_seed::(s)) } +///Get the account id for the treasury +pub fn treasury_account_id() -> AccountId { + TreasuryPalletId::get().into_account() +} pub fn development_config() -> Result { let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?; - Ok(ChainSpec::from_genesis( // Name "Development", @@ -58,6 +59,7 @@ pub fn development_config() -> Result { get_account_id_from_seed::("Bob"), get_account_id_from_seed::("Alice//stash"), get_account_id_from_seed::("Bob//stash"), + treasury_account_id(), ], true, ) @@ -77,7 +79,6 @@ pub fn development_config() -> Result { pub fn local_testnet_config() -> Result { let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?; - Ok(ChainSpec::from_genesis( // Name "Local Testnet", @@ -105,6 +106,7 @@ pub fn local_testnet_config() -> Result { get_account_id_from_seed::("Dave//stash"), get_account_id_from_seed::("Eve//stash"), get_account_id_from_seed::("Ferdie//stash"), + treasury_account_id(), ], true, ) @@ -130,6 +132,8 @@ fn testnet_genesis( endowed_accounts: Vec, _enable_println: bool, ) -> GenesisConfig { + + let treasury_funding = (endowed_accounts.len() as u128 - 1u128)* ENDOWED_FUNDING * TREASURY_FUNDING_PERCENT /100u128; GenesisConfig { system: SystemConfig { // Add Wasm runtime to storage. @@ -137,8 +141,15 @@ fn testnet_genesis( changes_trie_config: Default::default(), }, balances: BalancesConfig { - // Configure endowed accounts with initial balance of 1 << 60. - balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(), + // Configure endowed accounts with initial balance of ENDOWED_FUNDING and allocate the treasury TREASURY_FUNDING_PERCENT of total supply . + balances: endowed_accounts.iter().cloned().map(|k| { + if k == treasury_account_id() + { + (k, treasury_funding) + } else { + (k, ENDOWED_FUNDING) + } + }).collect(), }, aura: AuraConfig { authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect(), @@ -150,5 +161,6 @@ fn testnet_genesis( // Assign network admin rights. key: root_key, }, + treasury: Default::default(), } } diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 31dfca8..7cf0374 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -97,5 +97,6 @@ runtime-benchmarks = [ "hex-literal", "pallet-balances/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", + "pallet-treasury/runtime-benchmarks", "sp-runtime/runtime-benchmarks", ] diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 5e15729..9915477 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -31,7 +31,7 @@ pub use frame_support::{ constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND}, IdentityFee, Weight, }, - StorageValue, + PalletId, StorageValue, }; pub use pallet_balances::Call as BalancesCall; pub use pallet_timestamp::Call as TimestampCall; @@ -39,9 +39,12 @@ use pallet_transaction_payment::CurrencyAdapter; #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; pub use sp_runtime::{Perbill, Permill}; +use frame_system::EnsureRoot; /// added by SCS pub use pallet_teerex; +use frame_support::traits::OnUnbalanced; + /// An index to a block. pub type BlockNumber = u32; @@ -155,6 +158,27 @@ pub fn native_version() -> NativeVersion { NativeVersion { runtime_version: VERSION, can_author_with: Default::default() } } +pub struct DealWithFees; +impl OnUnbalanced> for DealWithFees +{ + fn on_unbalanceds( + mut fees_then_tips: impl Iterator>, + ) { + if let Some(fees) = fees_then_tips.next() { + // for fees, 80% to treasury, 20% to author + //let mut split = fees.ration(80, 20); + /* if let Some(tips) = fees_then_tips.next() { + // for tips, if any, 80% to treasury, 20% to author (though this can be anything) + tips.ration_merge_into(80, 20, &mut split); + } + */ + //everything to the Treasury + Treasury::on_unbalanced(fees); +// Author::on_unbalanced(split.1); + } + } +} + const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); parameter_types! { @@ -288,7 +312,7 @@ impl pallet_balances::Config for Runtime { } impl pallet_transaction_payment::Config for Runtime { - type OnChargeTransaction = CurrencyAdapter; + type OnChargeTransaction = CurrencyAdapter; type TransactionByteFee = TransactionByteFee; type WeightToFee = IdentityFee; type FeeMultiplierUpdate = (); @@ -314,6 +338,34 @@ impl pallet_teerex::Config for Runtime { type WeightInfo = pallet_teerex::weights::IntegriteeWeight; } +parameter_types! { + pub const ProposalBond: Permill = Permill::from_percent(5); + pub const ProposalBondMinimum: Balance = 100 * MILLITEER; + pub const SpendPeriod: BlockNumber = 24 * DAYS; + pub const Burn: Permill = Permill::from_percent(1); + pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry"); + pub const MaxApprovals: u32 = 0; //100 +} + +type RootOrigin = EnsureRoot; + +impl pallet_treasury::Config for Runtime { + type PalletId = TreasuryPalletId; + type Currency = pallet_balances::Pallet; + type ApproveOrigin = RootOrigin; + type RejectOrigin = RootOrigin; + type Event = Event; + type OnSlash = (); //No proposal + type ProposalBond = (); //No proposal + type ProposalBondMinimum = (); //No proposal + type SpendPeriod = SpendPeriod; //Cannot be 0: Error: Thread 'tokio-runtime-worker' panicked at 'attempt to calculate the remainder with a divisor of zero + type Burn = (); //No burn + type BurnDestination = (); //No burn + type SpendFunds = (); //No spend, no bounty + type MaxApprovals = MaxApprovals; //0:cannot approve any proposal + type WeightInfo = (); +} + // Create the runtime by composing the FRAME pallets that were previously configured. construct_runtime!( pub enum Runtime where @@ -331,6 +383,7 @@ construct_runtime!( Sudo: pallet_sudo::{Pallet, Call, Config, Storage, Event}, // added by SCS Teerex: pallet_teerex::{Pallet, Call, Storage, Event}, + Treasury: pallet_treasury::{Pallet, Call, Storage, Config, Event}, } ); @@ -507,6 +560,7 @@ impl_runtime_apis! { list_benchmark!(list, extra, frame_system, SystemBench::); list_benchmark!(list, extra, pallet_balances, Balances); list_benchmark!(list, extra, pallet_timestamp, Timestamp); + list_benchmark!(list, extra, pallet_treasury, Treasury); let storage_info = AllPalletsWithSystem::storage_info(); @@ -532,6 +586,8 @@ impl_runtime_apis! { hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(), // System Events hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(), + // Treasury Account + hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da95ecffd7b6c0f78751baa9d281e0bfa3a6d6f646c70792f74727372790000000000000000000000000000000000000000").to_vec().into(), ]; let mut batches = Vec::::new(); @@ -540,6 +596,7 @@ impl_runtime_apis! { add_benchmark!(params, batches, frame_system, SystemBench::); add_benchmark!(params, batches, pallet_balances, Balances); add_benchmark!(params, batches, pallet_timestamp, Timestamp); + add_benchmark!(params, batches, pallet_treasury, Treasury); if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } Ok(batches)