Skip to content

Commit f48b4fc

Browse files
authored
Merge pull request #287 from AurevoirXavier/canary
add: treasury
2 parents f104129 + 89f9150 commit f48b4fc

File tree

9 files changed

+347
-275
lines changed

9 files changed

+347
-275
lines changed

Cargo.lock

+18-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/node/cli/res/canary.json

+62-61
Large diffs are not rendered by default.

bin/node/cli/src/chain_spec.rs

+18-16
Original file line numberDiff line numberDiff line change
@@ -166,20 +166,33 @@ pub fn darwinia_genesis(
166166
pallet_im_online: Some(ImOnlineConfig { keys: vec![] }),
167167
pallet_authority_discovery: Some(AuthorityDiscoveryConfig { keys: vec![] }),
168168
pallet_grandpa: Some(GrandpaConfig { authorities: vec![] }),
169-
pallet_ring: Some(BalancesConfig {
169+
170+
pallet_eth_backing: Some(EthBackingConfig {
171+
ring_redeem_address: hex!["dbc888d701167cbfb86486c516aafbefc3a4de6e"].into(),
172+
kton_redeem_address: hex!["dbc888d701167cbfb86486c516aafbefc3a4de6e"].into(),
173+
deposit_redeem_address: hex!["6ef538314829efa8386fc43386cb13b4e0a67d1e"].into(),
174+
ring_locked: 2_000_000_000 * COIN,
175+
kton_locked: 50_000 * COIN,
176+
..Default::default()
177+
}),
178+
pallet_eth_relay: Some(EthRelayConfig {
179+
authorities: eth_relay_authorities,
180+
..Default::default()
181+
}),
182+
pallet_kton: Some(KtonConfig {
170183
balances: endowed_accounts
171184
.iter()
172185
.cloned()
173-
.map(|k| (k, RING_ENDOWMENT))
186+
.map(|k| (k, KTON_ENDOWMENT))
174187
.chain(initial_authorities.iter().map(|x| (x.0.clone(), STASH)))
175188
.collect(),
176189
vesting: vec![],
177190
}),
178-
pallet_kton: Some(KtonConfig {
191+
pallet_ring: Some(BalancesConfig {
179192
balances: endowed_accounts
180193
.iter()
181194
.cloned()
182-
.map(|k| (k, KTON_ENDOWMENT))
195+
.map(|k| (k, RING_ENDOWMENT))
183196
.chain(initial_authorities.iter().map(|x| (x.0.clone(), STASH)))
184197
.collect(),
185198
vesting: vec![],
@@ -196,18 +209,7 @@ pub fn darwinia_genesis(
196209
slash_reward_fraction: Perbill::from_percent(10),
197210
..Default::default()
198211
}),
199-
pallet_eth_relay: Some(EthRelayConfig {
200-
authorities: eth_relay_authorities,
201-
..Default::default()
202-
}),
203-
pallet_eth_backing: Some(EthBackingConfig {
204-
ring_redeem_address: hex!["dbc888d701167cbfb86486c516aafbefc3a4de6e"].into(),
205-
kton_redeem_address: hex!["dbc888d701167cbfb86486c516aafbefc3a4de6e"].into(),
206-
deposit_redeem_address: hex!["6ef538314829efa8386fc43386cb13b4e0a67d1e"].into(),
207-
ring_locked: 2_000_000_000 * COIN,
208-
kton_locked: 50_000 * COIN,
209-
..Default::default()
210-
}),
212+
pallet_treasury: Some(Default::default()),
211213
}
212214
}
213215

bin/node/runtime/Cargo.toml

+6-4
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@ pallet-transaction-payment = { version = "2.0.0", default-features = false, git
5858
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" }
5959
pallet-utility = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
6060

61+
pallet-eth-backing = { package = "darwinia-eth-backing", default-features = false, path = "../../../frame/chainrelay/eth/backing" }
62+
pallet-eth-relay = { package = "darwinia-eth-relay", default-features = false, path = "../../../frame/chainrelay/eth/relay" }
6163
pallet-kton = { package = "darwinia-kton", default-features = false, path = "../../../frame/balances/kton" }
6264
pallet-ring = { package = "darwinia-ring", default-features = false, path = "../../../frame/balances/ring" }
6365
pallet-staking = { package = "darwinia-staking", default-features = false, features = ["migrate"], path = "../../../frame/staking" }
64-
pallet-eth-relay = { package = "darwinia-eth-relay", default-features = false, path = "../../../frame/chainrelay/eth/relay" }
65-
pallet-eth-backing = { package = "darwinia-eth-backing", default-features = false, path = "../../../frame/chainrelay/eth/backing" }
66+
pallet-treasury = { package = "darwinia-treasury", default-features = false, path = "../../../frame/treasury" }
6667

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

100+
"pallet-eth-backing/std",
101+
"pallet-eth-relay/std",
99102
"pallet-kton/std",
100103
"pallet-ring/std",
101104
"pallet-staking/std",
102-
"pallet-eth-relay/std",
103-
"pallet-eth-backing/std",
105+
"pallet-treasury/std",
104106

105107
"node-primitives/std",
106108
"rustc-hex",

bin/node/runtime/src/lib.rs

+64-81
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,4 @@
1-
// Copyright 2018-2020 Parity Technologies (UK) Ltd.
2-
// This file is part of Substrate.
3-
4-
// Substrate is free software: you can redistribute it and/or modify
5-
// it under the terms of the GNU General Public License as published by
6-
// the Free Software Foundation, either version 3 of the License, or
7-
// (at your option) any later version.
8-
9-
// Substrate is distributed in the hope that it will be useful,
10-
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12-
// GNU General Public License for more details.
13-
14-
// You should have received a copy of the GNU General Public License
15-
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
16-
17-
//! The Substrate runtime. This can be compiled with ``#[no_std]`, ready for Wasm.
1+
//! The Darwinia runtime. This can be compiled with ``#[no_std]`, ready for Wasm.
182
193
#![cfg_attr(not(feature = "std"), no_std)]
204
// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256.
@@ -37,7 +21,7 @@ pub use pallet_staking::StakerStatus;
3721
use constants::{currency::*, supply::*, time::*};
3822
use frame_support::{
3923
construct_runtime, parameter_types,
40-
traits::{Currency, OnUnbalanced, Randomness, SplitTwoWays},
24+
traits::{Currency, Randomness, SplitTwoWays},
4125
weights::Weight,
4226
};
4327
use frame_system::offchain::TransactionSubmitter;
@@ -49,15 +33,15 @@ use pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo;
4933
use sp_api::impl_runtime_apis;
5034
use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
5135
use sp_core::{
52-
u32_trait::{_1, _3, _4},
36+
u32_trait::{_1, _2, _3, _4},
5337
OpaqueMetadata,
5438
};
5539
use sp_inherents::{CheckInherentsResult, InherentData};
5640
use sp_runtime::{
5741
create_runtime_str, generic, impl_opaque_keys,
5842
traits::{self, BlakeTwo256, Block as BlockT, NumberFor, OpaqueKeys, SaturatedConversion, StaticLookup},
5943
transaction_validity::TransactionValidity,
60-
ApplyExtrinsicResult, Perbill,
44+
ApplyExtrinsicResult, Perbill, Permill,
6145
};
6246
use sp_staking::SessionIndex;
6347
use sp_std::vec::Vec;
@@ -81,8 +65,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
8165
// and set impl_version to equal spec_version. If only runtime
8266
// implementation changes and behavior does not, then leave spec_version as
8367
// is and increment impl_version.
84-
spec_version: 85,
85-
impl_version: 85,
68+
spec_version: 86,
69+
impl_version: 86,
8670
apis: RUNTIME_API_VERSIONS,
8771
};
8872

@@ -102,18 +86,11 @@ pub type DealWithFees = SplitTwoWays<
10286
NegativeImbalance,
10387
_4,
10488
// Treasury, // 4 parts (80%) goes to the treasury.
105-
MockTreasury,
89+
Treasury,
10690
_1,
10791
Author, // 1 part (20%) goes to the block author.
10892
>;
10993

110-
pub struct MockTreasury;
111-
impl OnUnbalanced<NegativeImbalance> for MockTreasury {
112-
fn on_nonzero_unbalanced(amount: NegativeImbalance) {
113-
Balances::resolve_creating(&Sudo::key(), amount);
114-
}
115-
}
116-
11794
parameter_types! {
11895
pub const BlockHashCount: BlockNumber = 250;
11996
pub const MaximumBlockWeight: Weight = 1_000_000_000;
@@ -268,25 +245,6 @@ impl pallet_collective::Trait<CouncilCollective> for Runtime {
268245
// type MembershipChanged = TechnicalCommittee;
269246
//}
270247

271-
//parameter_types! {
272-
// pub const ProposalBond: Permill = Permill::from_percent(5);
273-
// pub const ProposalBondMinimum: Balance = 1 * COIN;
274-
// pub const SpendPeriod: BlockNumber = 1 * DAYS;
275-
// pub const Burn: Permill = Permill::from_percent(50);
276-
//}
277-
//
278-
//impl pallet_treasury::Trait for Runtime {
279-
// type Currency = Balances;
280-
// type ApproveOrigin = pallet_collective::EnsureMembers<_4, AccountId, CouncilCollective>;
281-
// type RejectOrigin = pallet_collective::EnsureMembers<_2, AccountId, CouncilCollective>;
282-
// type Event = Event;
283-
// type ProposalRejection = ();
284-
// type ProposalBond = ProposalBond;
285-
// type ProposalBondMinimum = ProposalBondMinimum;
286-
// type SpendPeriod = SpendPeriod;
287-
// type Burn = Burn;
288-
//}
289-
290248
parameter_types! {
291249
pub const ContractTransferFee: Balance = 1 * MILLI;
292250
pub const ContractCreationFee: Balance = 1 * MILLI;
@@ -381,7 +339,7 @@ impl pallet_nicks::Trait for Runtime {
381339
type Event = Event;
382340
type Currency = Balances;
383341
type ReservationFee = ReservationFee;
384-
type Slashed = MockTreasury;
342+
type Slashed = Treasury;
385343
type ForceOrigin = pallet_collective::EnsureMember<AccountId, CouncilCollective>;
386344
type MinLength = MinLength;
387345
type MaxLength = MaxLength;
@@ -421,12 +379,43 @@ impl frame_system::offchain::CreateTransaction<Runtime, UncheckedExtrinsic> for
421379
}
422380
}
423381

382+
impl pallet_eth_backing::Trait for Runtime {
383+
type Event = Event;
384+
type Time = Timestamp;
385+
type DetermineAccountId = pallet_eth_backing::AccountIdDeterminator<Runtime>;
386+
type EthRelay = EthRelay;
387+
type OnDepositRedeem = Staking;
388+
type Ring = Balances;
389+
type RingReward = ();
390+
type Kton = Kton;
391+
type KtonReward = ();
392+
}
393+
394+
parameter_types! {
395+
pub const EthMainet: u64 = 0;
396+
pub const EthRopsten: u64 = 1;
397+
}
398+
399+
impl pallet_eth_relay::Trait for Runtime {
400+
type Event = Event;
401+
type EthNetwork = EthRopsten;
402+
}
403+
424404
parameter_types! {
425405
pub const ExistentialDeposit: Balance = 1 * COIN;
426406
pub const TransferFee: Balance = 1 * MILLI;
427407
pub const CreationFee: Balance = 1 * MILLI;
428408
}
429409

410+
impl pallet_kton::Trait for Runtime {
411+
type Balance = Balance;
412+
type Event = Event;
413+
type RingCurrency = Balances;
414+
type TransferPayment = Balances;
415+
type ExistentialDeposit = ExistentialDeposit;
416+
type TransferFee = TransferFee;
417+
}
418+
430419
impl pallet_ring::Trait for Runtime {
431420
type Balance = Balance;
432421
type OnFreeBalanceZero = ((Staking, Contracts), Session);
@@ -438,14 +427,6 @@ impl pallet_ring::Trait for Runtime {
438427
type TransferFee = TransferFee;
439428
type CreationFee = CreationFee;
440429
}
441-
impl pallet_kton::Trait for Runtime {
442-
type Balance = Balance;
443-
type Event = Event;
444-
type RingCurrency = Balances;
445-
type TransferPayment = Balances;
446-
type ExistentialDeposit = ExistentialDeposit;
447-
type TransferFee = TransferFee;
448-
}
449430

450431
parameter_types! {
451432
pub const SessionsPerEra: SessionIndex = SESSIONS_PER_ERA;
@@ -469,37 +450,39 @@ impl pallet_staking::Trait for Runtime {
469450
type SlashCancelOrigin = pallet_collective::EnsureProportionAtLeast<_3, _4, AccountId, CouncilCollective>;
470451
type SessionInterface = Self;
471452
type RingCurrency = Balances;
472-
type RingRewardRemainder = ();
473-
type RingSlash = ();
453+
type RingRewardRemainder = Treasury;
454+
// send the slashed funds to the treasury.
455+
type RingSlash = Treasury;
456+
// rewards are minted from the void
474457
type RingReward = ();
475458
type KtonCurrency = Kton;
476-
type KtonSlash = ();
459+
// send the slashed funds to the treasury.
460+
type KtonSlash = Treasury;
461+
// rewards are minted from the void
477462
type KtonReward = ();
478463
type Cap = Cap;
479464
type TotalPower = TotalPower;
480465
type GenesisTime = GenesisTime;
481466
}
482467

483468
parameter_types! {
484-
pub const EthMainet: u64 = 0;
485-
pub const EthRopsten: u64 = 1;
469+
pub const ProposalBond: Permill = Permill::from_percent(5);
470+
pub const ProposalBondMinimum: Balance = 1 * COIN;
471+
pub const SpendPeriod: BlockNumber = 1 * DAYS;
472+
pub const Burn: Permill = Permill::from_percent(50);
486473
}
487474

488-
impl pallet_eth_relay::Trait for Runtime {
489-
type Event = Event;
490-
type EthNetwork = EthRopsten;
491-
}
492-
493-
impl pallet_eth_backing::Trait for Runtime {
475+
impl pallet_treasury::Trait for Runtime {
476+
type RingCurrency = Balances;
477+
type KtonCurrency = Kton;
478+
type ApproveOrigin = pallet_collective::EnsureMembers<_4, AccountId, CouncilCollective>;
479+
type RejectOrigin = pallet_collective::EnsureMembers<_2, AccountId, CouncilCollective>;
494480
type Event = Event;
495-
type Time = Timestamp;
496-
type DetermineAccountId = pallet_eth_backing::AccountIdDeterminator<Runtime>;
497-
type EthRelay = EthRelay;
498-
type OnDepositRedeem = Staking;
499-
type Ring = Balances;
500-
type RingReward = ();
501-
type Kton = Kton;
502-
type KtonReward = ();
481+
type ProposalRejection = ();
482+
type ProposalBond = ProposalBond;
483+
type ProposalBondMinimum = ProposalBondMinimum;
484+
type SpendPeriod = SpendPeriod;
485+
type Burn = Burn;
503486
}
504487

505488
construct_runtime!(
@@ -521,7 +504,6 @@ construct_runtime!(
521504
// TechnicalMembership: pallet_membership::<Instance1>::{Module, Call, Storage, Event<T>, Config<T>},
522505
FinalityTracker: pallet_finality_tracker::{Module, Call, Inherent},
523506
Grandpa: pallet_grandpa::{Module, Call, Storage, Config, Event},
524-
// Treasury: pallet_treasury::{Module, Call, Storage, Config, Event<T>},
525507
Contracts: pallet_contracts,
526508
Sudo: pallet_sudo,
527509
ImOnline: pallet_im_online::{Module, Call, Storage, Event<T>, ValidateUnsigned, Config<T>},
@@ -530,11 +512,12 @@ construct_runtime!(
530512
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Module, Call, Storage},
531513
Nicks: pallet_nicks::{Module, Call, Storage, Event<T>},
532514

533-
Balances: pallet_ring,
515+
EthBacking: pallet_eth_backing,
516+
EthRelay: pallet_eth_relay,
534517
Kton: pallet_kton,
518+
Balances: pallet_ring,
535519
Staking: pallet_staking,
536-
EthRelay: pallet_eth_relay,
537-
EthBacking: pallet_eth_backing,
520+
Treasury: pallet_treasury::{Module, Call, Storage, Config, Event<T>},
538521
}
539522
);
540523

0 commit comments

Comments
 (0)