Skip to content

Commit

Permalink
Merge pull request #26 from OriginTrail/upgrade/102/vesting-treasury-…
Browse files Browse the repository at this point in the history
…pots

Runtime upgrade 1.0.2 for Develop - Treasury, Vesting and Pots
  • Loading branch information
NZT48 authored Jul 11, 2022
2 parents 7c56cf4 + 653b93a commit 1174d98
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 2 additions & 0 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,5 +222,7 @@ fn testnet_genesis(
// Assign network admin rights.
key: Some(root_key),
},
vesting: Default::default(),
treasury: Default::default(),
}
}
47 changes: 26 additions & 21 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "origintrail-parachain-runtime"
version = "1.0.0"
version = "1.0.2"
authors = ["TraceLabs"]
description = "OriginTrail Parachain Runtime - Cumulus FRAME-based Substrate Runtime"
license = "GPL-3.0-only"
Expand All @@ -15,10 +15,14 @@ targets = ["x86_64-unknown-linux-gnu"]
substrate-wasm-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.18" }

[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = [
"derive",
] }
hex-literal = { version = "0.3.4", optional = true }
log = { version = "0.4.14", default-features = false }
scale-info = { version = "2.0.0", default-features = false, features = ["derive"] }
scale-info = { version = "2.0.0", default-features = false, features = [
"derive",
] }
serde = { version = "1.0.132", optional = true, features = ["derive"] }
smallvec = "1.6.1"

Expand All @@ -42,6 +46,8 @@ pallet-sudo = { git = "https://github.com/paritytech/substrate", default-feature
pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.18" }
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.18" }
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.18" }
pallet-treasury = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.18" }
pallet-vesting = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.18" }
sp-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.18" }
sp-block-builder = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.18" }
sp-consensus-aura = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.18" }
Expand All @@ -64,22 +70,20 @@ xcm-builder = { git = "https://github.com/paritytech/polkadot", default-features
xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.18" }

# Cumulus
cumulus-pallet-aura-ext = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.18" }
cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.18" }
cumulus-pallet-parachain-system = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.18" }
cumulus-pallet-session-benchmarking = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.18" }
cumulus-pallet-xcm = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.18" }
cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.18" }
cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.18" }
cumulus-primitives-timestamp = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.18" }
cumulus-primitives-utility = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.18" }
pallet-collator-selection = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.18" }
parachain-info = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.18" }
cumulus-pallet-aura-ext = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.18" }
cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.18" }
cumulus-pallet-parachain-system = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.18" }
cumulus-pallet-session-benchmarking = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.18" }
cumulus-pallet-xcm = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.18" }
cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.18" }
cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.18" }
cumulus-primitives-timestamp = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.18" }
cumulus-primitives-utility = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.18" }
pallet-collator-selection = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.18" }
parachain-info = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.18" }

[features]
default = [
"std",
]
default = ["std"]
std = [
"codec/std",
"log/std",
Expand Down Expand Up @@ -108,6 +112,8 @@ std = [
"pallet-timestamp/std",
"pallet-transaction-payment-rpc-runtime-api/std",
"pallet-transaction-payment/std",
"pallet-treasury/std",
"pallet-vesting/std",
"pallet-xcm/std",
"parachain-info/std",
"polkadot-parachain/std",
Expand Down Expand Up @@ -139,14 +145,13 @@ runtime-benchmarks = [
"pallet-collator-selection/runtime-benchmarks",
"pallet-template/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-treasury/runtime-benchmarks",
"pallet-vesting/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
"cumulus-pallet-session-benchmarking/runtime-benchmarks",
"cumulus-pallet-xcmp-queue/runtime-benchmarks",
]

try-runtime = [
"frame-executive/try-runtime",
"frame-try-runtime",
]
try-runtime = ["frame-executive/try-runtime", "frame-try-runtime"]
115 changes: 109 additions & 6 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use sp_api::impl_runtime_apis;
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, IdentifyAccount, Verify},
traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, ConvertInto, IdentifyAccount, Verify},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, MultiSignature,
};
Expand All @@ -25,7 +25,7 @@ use sp_version::RuntimeVersion;

use frame_support::{
construct_runtime, parameter_types,
traits::Everything,
traits::{Everything, Currency as PalletCurrency, OnUnbalanced, Imbalance},
weights::{
constants::{BlockExecutionWeight, ExtrinsicBaseWeight, WEIGHT_PER_SECOND},
DispatchClass, Weight, WeightToFeeCoefficient, WeightToFeeCoefficients,
Expand All @@ -38,7 +38,7 @@ use frame_system::{
EnsureRoot,
};
pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
pub use sp_runtime::{MultiAddress, Perbill, Permill};
pub use sp_runtime::{MultiAddress, Perbill, Permill, traits::AccountIdConversion };
pub use frame_support::traits::EqualPrivilegeOnly;
use xcm_config::{XcmConfig, XcmOriginToTransactDispatchOrigin};

Expand Down Expand Up @@ -171,7 +171,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("origintrail-parachain"),
impl_name: create_runtime_str!("origintrail-parachain"),
authoring_version: 1,
spec_version: 100,
spec_version: 102,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down Expand Up @@ -250,6 +250,15 @@ parameter_types! {
pub const SS58Prefix: u16 = 101;
}

// Pallet accounts of runtime
parameter_types! {
pub const TreasuryPalletId: PalletId = PalletId(*b"otp/trea");
pub const DkgIncentivesPalletId: PalletId = PalletId(*b"otp/dkgi");
pub const FutureAuctionsPalletId: PalletId = PalletId(*b"otp/fauc");
pub const CollatorsIncentivesPalletId: PalletId = PalletId(*b"otp/coli");
pub const PotId: PalletId = PalletId(*b"PotStake");
}

// Configure FRAME pallets to include in runtime.

impl frame_system::Config for Runtime {
Expand Down Expand Up @@ -345,14 +354,65 @@ impl pallet_balances::Config for Runtime {
type ReserveIdentifier = [u8; 8];
}

pub struct ToStakingPot;
impl OnUnbalanced<NegativeImbalance> for ToStakingPot {
fn on_nonzero_unbalanced(amount: NegativeImbalance) {
let staking_pot = PotId::get().into_account();
Balances::resolve_creating(&staking_pot, amount);
}
}

pub struct FutureAuctionsPot;
impl OnUnbalanced<NegativeImbalance> for FutureAuctionsPot {
fn on_nonzero_unbalanced(amount: NegativeImbalance) {
let future_auctions_pot = FutureAuctionsPalletId::get().into_account();
Balances::resolve_creating(&future_auctions_pot, amount);
}
}

pub struct DkgIncentivesPot;
impl OnUnbalanced<NegativeImbalance> for DkgIncentivesPot {
fn on_nonzero_unbalanced(amount: NegativeImbalance) {
let dkg_incentives_pot = DkgIncentivesPalletId::get().into_account();
Balances::resolve_creating(&dkg_incentives_pot, amount);
}
}

type NegativeImbalance = <Balances as PalletCurrency<AccountId>>::NegativeImbalance;

pub struct DealWithFees;
impl OnUnbalanced<NegativeImbalance> for DealWithFees {
fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item = NegativeImbalance>) {
if let Some(mut fees) = fees_then_tips.next() {
if let Some(tips) = fees_then_tips.next() {
tips.merge_into(&mut fees);
}
// for fees and tips:
// - 30% to DKG Incentives pool
// - 30% to Collators Incentives pool (currently staking_pot)
// - 30% to Future Auctions pool
// - 10% to Treasury
let split = fees.ration(60, 40);
let (dkg_incentives_fees, collators_incentives_fees) = split.0.ration(50, 50);
let (future_auctions_fees, treasury_fees) = split.1.ration(75, 25);


Treasury::on_unbalanced(treasury_fees);
<ToStakingPot as OnUnbalanced<_>>::on_unbalanced(collators_incentives_fees);
<FutureAuctionsPot as OnUnbalanced<_>>::on_unbalanced(future_auctions_fees);
<DkgIncentivesPot as OnUnbalanced<_>>::on_unbalanced(dkg_incentives_fees);
}
}
}

parameter_types! {
/// Relay Chain `TransactionByteFee` / 10
pub const TransactionByteFee: Balance = 10 * MICROOTP;
pub const OperationalFeeMultiplier: u8 = 5;
}

impl pallet_transaction_payment::Config for Runtime {
type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, ()>;
type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, DealWithFees>;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = WeightToFee;
type FeeMultiplierUpdate = SlowAdjustingFeeUpdate<Self>;
Expand Down Expand Up @@ -423,7 +483,6 @@ impl pallet_aura::Config for Runtime {
}

parameter_types! {
pub const PotId: PalletId = PalletId(*b"PotStake");
pub const MaxCandidates: u32 = 1000;
pub const MinCandidates: u32 = 5;
pub const SessionLength: BlockNumber = 6 * HOURS;
Expand Down Expand Up @@ -476,6 +535,48 @@ impl pallet_sudo::Config for Runtime {
type Call = Call;
}

parameter_types! {
pub const MinVestedTransfer: Balance = 15 * OTP;
}

impl pallet_vesting::Config for Runtime {
type Event = Event;
type Currency = Balances;
type BlockNumberToBalance = ConvertInto;
type MinVestedTransfer = MinVestedTransfer;
type WeightInfo = pallet_vesting::weights::SubstrateWeight<Runtime>;
// `VestingInfo` encode length is 36bytes. 28 schedules gets encoded as 1009 bytes, which is the
// highest number of schedules that encodes less than 2^10.
const MAX_VESTING_SCHEDULES: u32 = 28;
}

parameter_types! {
pub const ProposalBond: Permill = Permill::from_percent(5);
pub const ProposalBondMinimum: Balance = 100 * OTP;
pub const ProposalBondMaximum: Balance = 500 * OTP;
pub const SpendPeriod: BlockNumber = 24 * DAYS;
pub const MaxApprovals: u32 = 100;
}


impl pallet_treasury::Config for Runtime {
type PalletId = TreasuryPalletId;
type Currency = Balances;
type ApproveOrigin = EnsureRoot<AccountId>;
type RejectOrigin = EnsureRoot<AccountId>;
type Event = Event;
type OnSlash = ();
type ProposalBond = ProposalBond;
type ProposalBondMinimum = ProposalBondMinimum;
type ProposalBondMaximum = ProposalBondMaximum;
type SpendPeriod = SpendPeriod;
type Burn = ();
type BurnDestination = ();
type SpendFunds = ();
type WeightInfo = pallet_treasury::weights::SubstrateWeight<Runtime>;
type MaxApprovals = MaxApprovals;
}

/// Configure the pallet template in pallets/template.
impl pallet_template::Config for Runtime {
type Event = Event;
Expand All @@ -499,6 +600,8 @@ construct_runtime!(
// Monetary stuff.
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>} = 10,
TransactionPayment: pallet_transaction_payment::{Pallet, Storage} = 11,
Vesting: pallet_vesting::{Pallet, Call, Storage, Event<T>, Config<T>} = 12,
Treasury: pallet_treasury::{Pallet, Call, Storage, Config, Event<T>} = 13,

// Collator support. The order of these 4 are important and shall not change.
Authorship: pallet_authorship::{Pallet, Call, Storage} = 20,
Expand Down

0 comments on commit 1174d98

Please sign in to comment.