Skip to content

Commit

Permalink
Implement on-chain accounts and update runtime version to 1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
NZT48 committed Jun 27, 2022
1 parent 8a116f0 commit 653b93a
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 7 deletions.
2 changes: 1 addition & 1 deletion 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.1"
version = "1.0.2"
authors = ["TraceLabs"]
description = "OriginTrail Parachain Runtime - Cumulus FRAME-based Substrate Runtime"
license = "GPL-3.0-only"
Expand Down
70 changes: 64 additions & 6 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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: 101,
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 @@ -496,7 +555,6 @@ parameter_types! {
pub const ProposalBondMinimum: Balance = 100 * OTP;
pub const ProposalBondMaximum: Balance = 500 * OTP;
pub const SpendPeriod: BlockNumber = 24 * DAYS;
pub const TreasuryPalletId: PalletId = PalletId(*b"otp/trea");
pub const MaxApprovals: u32 = 100;
}

Expand Down

0 comments on commit 653b93a

Please sign in to comment.