Skip to content

Commit

Permalink
Simplify Crab token system (#1310)
Browse files Browse the repository at this point in the history
* Stash

* Simplify Crab token system

* Doc

* Fix benchmarks

* Emit an event instead of a log

* Add more tests
  • Loading branch information
aurexav authored Nov 8, 2023
1 parent df16a59 commit 989beb8
Show file tree
Hide file tree
Showing 14 changed files with 442 additions and 189 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

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

10 changes: 1 addition & 9 deletions pallet/account-migration/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ impl darwinia_staking::Stake for Dummy {
Ok(())
}
}
impl frame_support::traits::UnixTime for Dummy {
fn now() -> core::time::Duration {
core::time::Duration::new(0, 0)
}
}

#[sp_version::runtime_version]
pub const VERSION: sp_version::RuntimeVersion = sp_version::RuntimeVersion {
Expand Down Expand Up @@ -171,12 +166,9 @@ impl darwinia_staking::Config for Runtime {
type MaxDeposits = ();
type MaxUnstakings = ();
type MinStakingDuration = ();
type PayoutFraction = ();
type RewardRemainder = ();
type OnSessionEnd = ();
type Ring = Dummy;
type RingCurrency = Balances;
type RuntimeEvent = RuntimeEvent;
type UnixTime = Dummy;
type WeightInfo = ();
}
#[cfg(not(feature = "runtime-benchmarks"))]
Expand Down
4 changes: 2 additions & 2 deletions pallet/staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ scale-info = { workspace = true }

# darwinia
darwinia-staking-traits = { workspace = true }
dc-inflation = { workspace = true }
dc-types = { workspace = true }
# darwinia optional
darwinia-deposit = { workspace = true, optional = true }
Expand All @@ -36,10 +35,12 @@ pretty_env_logger = { version = "0.4" }
darwinia-deposit = { workspace = true, features = ["std"] }

# substrate
dc-inflation = { workspace = true, features = ["std"] }
pallet-assets = { workspace = true, features = ["std"] }
pallet-balances = { workspace = true, features = ["std"] }
pallet-session = { workspace = true, features = ["std"] }
pallet-timestamp = { workspace = true, features = ["std"] }
pallet-treasury = { workspace = true, features = ["std"] }
sp-core = { workspace = true, features = ["std"] }
sp-io = { workspace = true, features = ["std"] }
substrate-test-utils = { workspace = true }
Expand All @@ -53,7 +54,6 @@ std = [

# darwinia
"darwinia-staking-traits/std",
"dc-inflation/std",
# darwinia optional
"darwinia-deposit?/std",

Expand Down
14 changes: 8 additions & 6 deletions pallet/staking/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ use sp_std::prelude::*;
mod benchmarks {
// darwinia
use super::*;
// substrate
use frame_support::traits::Currency;

fn deposit_for<T>(who: &T::AccountId, count: u32) -> Vec<DepositId<T>>
where
Expand All @@ -53,7 +55,7 @@ mod benchmarks {
let a = frame_benchmarking::whitelisted_caller();

// Remove `+ 1` after https://github.com/paritytech/substrate/pull/13655.
T::RingCurrency::make_free_balance_be(&a, 1_024 * UNIT + 1);
<T as darwinia_deposit::Config>::Ring::make_free_balance_be(&a, 1_024 * UNIT + 1);
<T as darwinia_deposit::Config>::Kton::mint(&a, UNIT).unwrap();

let deposits = deposit_for::<T>(&a, x);
Expand All @@ -70,7 +72,7 @@ mod benchmarks {
let a = frame_benchmarking::whitelisted_caller();

// Remove `+ 1` after https://github.com/paritytech/substrate/pull/13655.
T::RingCurrency::make_free_balance_be(&a, 1_024 * UNIT + 1);
<T as darwinia_deposit::Config>::Ring::make_free_balance_be(&a, 1_024 * UNIT + 1);
<T as darwinia_deposit::Config>::Kton::mint(&a, UNIT).unwrap();

let deposits = deposit_for::<T>(&a, x);
Expand All @@ -90,7 +92,7 @@ mod benchmarks {
let a = frame_benchmarking::whitelisted_caller();

// Remove `+ 1` after https://github.com/paritytech/substrate/pull/13655.
T::RingCurrency::make_free_balance_be(&a, 1_024 * UNIT + 1);
<T as darwinia_deposit::Config>::Ring::make_free_balance_be(&a, 1_024 * UNIT + 1);
<T as darwinia_deposit::Config>::Kton::mint(&a, UNIT).unwrap();

let deposits = deposit_for::<T>(&a, x);
Expand All @@ -112,7 +114,7 @@ mod benchmarks {
let a = frame_benchmarking::whitelisted_caller();

// Remove `+ 1` after https://github.com/paritytech/substrate/pull/13655.
T::RingCurrency::make_free_balance_be(&a, 1_024 * UNIT + 1);
<T as darwinia_deposit::Config>::Ring::make_free_balance_be(&a, 1_024 * UNIT + 1);
<T as darwinia_deposit::Config>::Kton::mint(&a, UNIT).unwrap();

let deposits = deposit_for::<T>(&a, <T as Config>::MaxUnstakings::get());
Expand Down Expand Up @@ -154,7 +156,7 @@ mod benchmarks {
let a_cloned = a.clone();

// Remove `+ 1` after https://github.com/paritytech/substrate/pull/13655.
T::RingCurrency::make_free_balance_be(&a, UNIT + 1);
<T as darwinia_deposit::Config>::Ring::make_free_balance_be(&a, UNIT + 1);

<Pallet<T>>::stake(
RawOrigin::Signed(a.clone()).into(),
Expand All @@ -177,7 +179,7 @@ mod benchmarks {
let a = frame_benchmarking::whitelisted_caller::<T::AccountId>();

// Remove `+ 1` after https://github.com/paritytech/substrate/pull/13655.
T::RingCurrency::make_free_balance_be(&a, UNIT + 1);
<T as darwinia_deposit::Config>::Ring::make_free_balance_be(&a, UNIT + 1);

<Pallet<T>>::stake(
RawOrigin::Signed(a.clone()).into(),
Expand Down
Loading

0 comments on commit 989beb8

Please sign in to comment.