Skip to content

Commit

Permalink
Merge pull request #287 from AurevoirXavier/canary
Browse files Browse the repository at this point in the history
add: treasury
  • Loading branch information
hackfisher authored Feb 25, 2020
2 parents f104129 + 89f9150 commit f48b4fc
Show file tree
Hide file tree
Showing 9 changed files with 347 additions and 275 deletions.
33 changes: 18 additions & 15 deletions Cargo.lock

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

123 changes: 62 additions & 61 deletions bin/node/cli/res/canary.json

Large diffs are not rendered by default.

34 changes: 18 additions & 16 deletions bin/node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,20 +166,33 @@ pub fn darwinia_genesis(
pallet_im_online: Some(ImOnlineConfig { keys: vec![] }),
pallet_authority_discovery: Some(AuthorityDiscoveryConfig { keys: vec![] }),
pallet_grandpa: Some(GrandpaConfig { authorities: vec![] }),
pallet_ring: Some(BalancesConfig {

pallet_eth_backing: Some(EthBackingConfig {
ring_redeem_address: hex!["dbc888d701167cbfb86486c516aafbefc3a4de6e"].into(),
kton_redeem_address: hex!["dbc888d701167cbfb86486c516aafbefc3a4de6e"].into(),
deposit_redeem_address: hex!["6ef538314829efa8386fc43386cb13b4e0a67d1e"].into(),
ring_locked: 2_000_000_000 * COIN,
kton_locked: 50_000 * COIN,
..Default::default()
}),
pallet_eth_relay: Some(EthRelayConfig {
authorities: eth_relay_authorities,
..Default::default()
}),
pallet_kton: Some(KtonConfig {
balances: endowed_accounts
.iter()
.cloned()
.map(|k| (k, RING_ENDOWMENT))
.map(|k| (k, KTON_ENDOWMENT))
.chain(initial_authorities.iter().map(|x| (x.0.clone(), STASH)))
.collect(),
vesting: vec![],
}),
pallet_kton: Some(KtonConfig {
pallet_ring: Some(BalancesConfig {
balances: endowed_accounts
.iter()
.cloned()
.map(|k| (k, KTON_ENDOWMENT))
.map(|k| (k, RING_ENDOWMENT))
.chain(initial_authorities.iter().map(|x| (x.0.clone(), STASH)))
.collect(),
vesting: vec![],
Expand All @@ -196,18 +209,7 @@ pub fn darwinia_genesis(
slash_reward_fraction: Perbill::from_percent(10),
..Default::default()
}),
pallet_eth_relay: Some(EthRelayConfig {
authorities: eth_relay_authorities,
..Default::default()
}),
pallet_eth_backing: Some(EthBackingConfig {
ring_redeem_address: hex!["dbc888d701167cbfb86486c516aafbefc3a4de6e"].into(),
kton_redeem_address: hex!["dbc888d701167cbfb86486c516aafbefc3a4de6e"].into(),
deposit_redeem_address: hex!["6ef538314829efa8386fc43386cb13b4e0a67d1e"].into(),
ring_locked: 2_000_000_000 * COIN,
kton_locked: 50_000 * COIN,
..Default::default()
}),
pallet_treasury: Some(Default::default()),
}
}

Expand Down
10 changes: 6 additions & 4 deletions bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@ pallet-transaction-payment = { version = "2.0.0", default-features = false, git
pallet-transaction-payment-rpc-runtime-api = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
pallet-utility = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }

pallet-eth-backing = { package = "darwinia-eth-backing", default-features = false, path = "../../../frame/chainrelay/eth/backing" }
pallet-eth-relay = { package = "darwinia-eth-relay", default-features = false, path = "../../../frame/chainrelay/eth/relay" }
pallet-kton = { package = "darwinia-kton", default-features = false, path = "../../../frame/balances/kton" }
pallet-ring = { package = "darwinia-ring", default-features = false, path = "../../../frame/balances/ring" }
pallet-staking = { package = "darwinia-staking", default-features = false, features = ["migrate"], path = "../../../frame/staking" }
pallet-eth-relay = { package = "darwinia-eth-relay", default-features = false, path = "../../../frame/chainrelay/eth/relay" }
pallet-eth-backing = { package = "darwinia-eth-backing", default-features = false, path = "../../../frame/chainrelay/eth/backing" }
pallet-treasury = { package = "darwinia-treasury", default-features = false, path = "../../../frame/treasury" }

[build-dependencies]
wasm-builder-runner = { version = "1.0.4", package = "substrate-wasm-builder-runner", git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
Expand Down Expand Up @@ -96,11 +97,12 @@ std = [
"pallet-transaction-payment/std",
"pallet-utility/std",

"pallet-eth-backing/std",
"pallet-eth-relay/std",
"pallet-kton/std",
"pallet-ring/std",
"pallet-staking/std",
"pallet-eth-relay/std",
"pallet-eth-backing/std",
"pallet-treasury/std",

"node-primitives/std",
"rustc-hex",
Expand Down
145 changes: 64 additions & 81 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,4 @@
// Copyright 2018-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.

// Substrate is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Substrate is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.

//! The Substrate runtime. This can be compiled with ``#[no_std]`, ready for Wasm.
//! The Darwinia runtime. This can be compiled with ``#[no_std]`, ready for Wasm.

#![cfg_attr(not(feature = "std"), no_std)]
// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256.
Expand All @@ -37,7 +21,7 @@ pub use pallet_staking::StakerStatus;
use constants::{currency::*, supply::*, time::*};
use frame_support::{
construct_runtime, parameter_types,
traits::{Currency, OnUnbalanced, Randomness, SplitTwoWays},
traits::{Currency, Randomness, SplitTwoWays},
weights::Weight,
};
use frame_system::offchain::TransactionSubmitter;
Expand All @@ -49,15 +33,15 @@ use pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo;
use sp_api::impl_runtime_apis;
use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
use sp_core::{
u32_trait::{_1, _3, _4},
u32_trait::{_1, _2, _3, _4},
OpaqueMetadata,
};
use sp_inherents::{CheckInherentsResult, InherentData};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{self, BlakeTwo256, Block as BlockT, NumberFor, OpaqueKeys, SaturatedConversion, StaticLookup},
transaction_validity::TransactionValidity,
ApplyExtrinsicResult, Perbill,
ApplyExtrinsicResult, Perbill, Permill,
};
use sp_staking::SessionIndex;
use sp_std::vec::Vec;
Expand All @@ -81,8 +65,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
// and set impl_version to equal spec_version. If only runtime
// implementation changes and behavior does not, then leave spec_version as
// is and increment impl_version.
spec_version: 85,
impl_version: 85,
spec_version: 86,
impl_version: 86,
apis: RUNTIME_API_VERSIONS,
};

Expand All @@ -102,18 +86,11 @@ pub type DealWithFees = SplitTwoWays<
NegativeImbalance,
_4,
// Treasury, // 4 parts (80%) goes to the treasury.
MockTreasury,
Treasury,
_1,
Author, // 1 part (20%) goes to the block author.
>;

pub struct MockTreasury;
impl OnUnbalanced<NegativeImbalance> for MockTreasury {
fn on_nonzero_unbalanced(amount: NegativeImbalance) {
Balances::resolve_creating(&Sudo::key(), amount);
}
}

parameter_types! {
pub const BlockHashCount: BlockNumber = 250;
pub const MaximumBlockWeight: Weight = 1_000_000_000;
Expand Down Expand Up @@ -268,25 +245,6 @@ impl pallet_collective::Trait<CouncilCollective> for Runtime {
// type MembershipChanged = TechnicalCommittee;
//}

//parameter_types! {
// pub const ProposalBond: Permill = Permill::from_percent(5);
// pub const ProposalBondMinimum: Balance = 1 * COIN;
// pub const SpendPeriod: BlockNumber = 1 * DAYS;
// pub const Burn: Permill = Permill::from_percent(50);
//}
//
//impl pallet_treasury::Trait for Runtime {
// type Currency = Balances;
// type ApproveOrigin = pallet_collective::EnsureMembers<_4, AccountId, CouncilCollective>;
// type RejectOrigin = pallet_collective::EnsureMembers<_2, AccountId, CouncilCollective>;
// type Event = Event;
// type ProposalRejection = ();
// type ProposalBond = ProposalBond;
// type ProposalBondMinimum = ProposalBondMinimum;
// type SpendPeriod = SpendPeriod;
// type Burn = Burn;
//}

parameter_types! {
pub const ContractTransferFee: Balance = 1 * MILLI;
pub const ContractCreationFee: Balance = 1 * MILLI;
Expand Down Expand Up @@ -381,7 +339,7 @@ impl pallet_nicks::Trait for Runtime {
type Event = Event;
type Currency = Balances;
type ReservationFee = ReservationFee;
type Slashed = MockTreasury;
type Slashed = Treasury;
type ForceOrigin = pallet_collective::EnsureMember<AccountId, CouncilCollective>;
type MinLength = MinLength;
type MaxLength = MaxLength;
Expand Down Expand Up @@ -421,12 +379,43 @@ impl frame_system::offchain::CreateTransaction<Runtime, UncheckedExtrinsic> for
}
}

impl pallet_eth_backing::Trait for Runtime {
type Event = Event;
type Time = Timestamp;
type DetermineAccountId = pallet_eth_backing::AccountIdDeterminator<Runtime>;
type EthRelay = EthRelay;
type OnDepositRedeem = Staking;
type Ring = Balances;
type RingReward = ();
type Kton = Kton;
type KtonReward = ();
}

parameter_types! {
pub const EthMainet: u64 = 0;
pub const EthRopsten: u64 = 1;
}

impl pallet_eth_relay::Trait for Runtime {
type Event = Event;
type EthNetwork = EthRopsten;
}

parameter_types! {
pub const ExistentialDeposit: Balance = 1 * COIN;
pub const TransferFee: Balance = 1 * MILLI;
pub const CreationFee: Balance = 1 * MILLI;
}

impl pallet_kton::Trait for Runtime {
type Balance = Balance;
type Event = Event;
type RingCurrency = Balances;
type TransferPayment = Balances;
type ExistentialDeposit = ExistentialDeposit;
type TransferFee = TransferFee;
}

impl pallet_ring::Trait for Runtime {
type Balance = Balance;
type OnFreeBalanceZero = ((Staking, Contracts), Session);
Expand All @@ -438,14 +427,6 @@ impl pallet_ring::Trait for Runtime {
type TransferFee = TransferFee;
type CreationFee = CreationFee;
}
impl pallet_kton::Trait for Runtime {
type Balance = Balance;
type Event = Event;
type RingCurrency = Balances;
type TransferPayment = Balances;
type ExistentialDeposit = ExistentialDeposit;
type TransferFee = TransferFee;
}

parameter_types! {
pub const SessionsPerEra: SessionIndex = SESSIONS_PER_ERA;
Expand All @@ -469,37 +450,39 @@ impl pallet_staking::Trait for Runtime {
type SlashCancelOrigin = pallet_collective::EnsureProportionAtLeast<_3, _4, AccountId, CouncilCollective>;
type SessionInterface = Self;
type RingCurrency = Balances;
type RingRewardRemainder = ();
type RingSlash = ();
type RingRewardRemainder = Treasury;
// send the slashed funds to the treasury.
type RingSlash = Treasury;
// rewards are minted from the void
type RingReward = ();
type KtonCurrency = Kton;
type KtonSlash = ();
// send the slashed funds to the treasury.
type KtonSlash = Treasury;
// rewards are minted from the void
type KtonReward = ();
type Cap = Cap;
type TotalPower = TotalPower;
type GenesisTime = GenesisTime;
}

parameter_types! {
pub const EthMainet: u64 = 0;
pub const EthRopsten: u64 = 1;
pub const ProposalBond: Permill = Permill::from_percent(5);
pub const ProposalBondMinimum: Balance = 1 * COIN;
pub const SpendPeriod: BlockNumber = 1 * DAYS;
pub const Burn: Permill = Permill::from_percent(50);
}

impl pallet_eth_relay::Trait for Runtime {
type Event = Event;
type EthNetwork = EthRopsten;
}

impl pallet_eth_backing::Trait for Runtime {
impl pallet_treasury::Trait for Runtime {
type RingCurrency = Balances;
type KtonCurrency = Kton;
type ApproveOrigin = pallet_collective::EnsureMembers<_4, AccountId, CouncilCollective>;
type RejectOrigin = pallet_collective::EnsureMembers<_2, AccountId, CouncilCollective>;
type Event = Event;
type Time = Timestamp;
type DetermineAccountId = pallet_eth_backing::AccountIdDeterminator<Runtime>;
type EthRelay = EthRelay;
type OnDepositRedeem = Staking;
type Ring = Balances;
type RingReward = ();
type Kton = Kton;
type KtonReward = ();
type ProposalRejection = ();
type ProposalBond = ProposalBond;
type ProposalBondMinimum = ProposalBondMinimum;
type SpendPeriod = SpendPeriod;
type Burn = Burn;
}

construct_runtime!(
Expand All @@ -521,7 +504,6 @@ construct_runtime!(
// TechnicalMembership: pallet_membership::<Instance1>::{Module, Call, Storage, Event<T>, Config<T>},
FinalityTracker: pallet_finality_tracker::{Module, Call, Inherent},
Grandpa: pallet_grandpa::{Module, Call, Storage, Config, Event},
// Treasury: pallet_treasury::{Module, Call, Storage, Config, Event<T>},
Contracts: pallet_contracts,
Sudo: pallet_sudo,
ImOnline: pallet_im_online::{Module, Call, Storage, Event<T>, ValidateUnsigned, Config<T>},
Expand All @@ -530,11 +512,12 @@ construct_runtime!(
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Module, Call, Storage},
Nicks: pallet_nicks::{Module, Call, Storage, Event<T>},

Balances: pallet_ring,
EthBacking: pallet_eth_backing,
EthRelay: pallet_eth_relay,
Kton: pallet_kton,
Balances: pallet_ring,
Staking: pallet_staking,
EthRelay: pallet_eth_relay,
EthBacking: pallet_eth_backing,
Treasury: pallet_treasury::{Module, Call, Storage, Config, Event<T>},
}
);

Expand Down
Loading

0 comments on commit f48b4fc

Please sign in to comment.