Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Allocate 500'000 TEER to treasury in the gensis config
COnfig treasury pallet and collect fees in the treasury
  • Loading branch information
echevrier committed Sep 14, 2021
commit 85df99846799ca2a96fc5554c8e6c51bb3e5a5ed
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 node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 15 additions & 5 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
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, TEER, Balance};
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 hex_literal::hex;

// 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<GenesisConfig>;
pub const TREASURY_ACCOUNT_ID: [u8; 32] = hex!("6d6f646c70792f74727372790000000000000000000000000000000000000000");
pub const TREASURY_INITIAL_FUNDING: Balance = 500_000*TEER;

/// Generate a crypto pair from seed.
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
Expand Down Expand Up @@ -58,6 +58,7 @@ pub fn development_config() -> Result<ChainSpec, String> {
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
TREASURY_ACCOUNT_ID.into(),
],
true,
)
Expand Down Expand Up @@ -138,7 +139,15 @@ fn testnet_genesis(
},
balances: BalancesConfig {
// Configure endowed accounts with initial balance of 1 << 60.
balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(),
// balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(),
balances: endowed_accounts.iter().cloned().map(|k| {
if k == TREASURY_ACCOUNT_ID.into()
{
return (k, TREASURY_INITIAL_FUNDING);
} else {
return (k, 1 << 60);
}
}).collect(),
},
aura: AuraConfig {
authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect(),
Expand All @@ -150,5 +159,6 @@ fn testnet_genesis(
// Assign network admin rights.
key: root_key,
},
treasury: Default::default(),
}
}
1 change: 1 addition & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,6 @@ runtime-benchmarks = [
"hex-literal",
"pallet-balances/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-treasury/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
61 changes: 59 additions & 2 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,20 @@ 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;
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;
Expand Down Expand Up @@ -155,6 +158,27 @@ pub fn native_version() -> NativeVersion {
NativeVersion { runtime_version: VERSION, can_author_with: Default::default() }
}

pub struct DealWithFees;
impl OnUnbalanced<pallet_balances::NegativeImbalance<Runtime>> for DealWithFees
{
fn on_unbalanceds<B>(
mut fees_then_tips: impl Iterator<Item = pallet_balances::NegativeImbalance<Runtime>>,
) {
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! {
Expand Down Expand Up @@ -288,7 +312,7 @@ impl pallet_balances::Config for Runtime {
}

impl pallet_transaction_payment::Config for Runtime {
type OnChargeTransaction = CurrencyAdapter<Balances, ()>;
type OnChargeTransaction = CurrencyAdapter<Balances, DealWithFees>;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = IdentityFee<Balance>;
type FeeMultiplierUpdate = ();
Expand All @@ -314,6 +338,34 @@ impl pallet_teerex::Config for Runtime {
type WeightInfo = pallet_teerex::weights::IntegriteeWeight<Runtime>;
}

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<AccountId>;

impl pallet_treasury::Config for Runtime {
type PalletId = TreasuryPalletId;
type Currency = pallet_balances::Pallet<Runtime>;
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;
type WeightInfo = pallet_treasury::weights::SubstrateWeight<Runtime>;
}

// Create the runtime by composing the FRAME pallets that were previously configured.
construct_runtime!(
pub enum Runtime where
Expand All @@ -331,6 +383,7 @@ construct_runtime!(
Sudo: pallet_sudo::{Pallet, Call, Config<T>, Storage, Event<T>},
// added by SCS
Teerex: pallet_teerex::{Pallet, Call, Storage, Event<T>},
Treasury: pallet_treasury::{Pallet, Call, Storage, Config, Event<T>},
}
);

Expand Down Expand Up @@ -507,6 +560,7 @@ impl_runtime_apis! {
list_benchmark!(list, extra, frame_system, SystemBench::<Runtime>);
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();

Expand All @@ -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::<BenchmarkBatch>::new();
Expand All @@ -540,6 +596,7 @@ impl_runtime_apis! {
add_benchmark!(params, batches, frame_system, SystemBench::<Runtime>);
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)
Expand Down