mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 17:31:05 +00:00
Deprecate Currency; introduce holds and freezing into fungible traits (#12951)
* First reworking of fungibles API * New API and docs * More fungible::* API improvements * New ref-counting logic for old API * Missing files * Fixes * Use the new transfer logic * Use fungibles for the dispatchables * Use shelve/restore names * Locking works with total balance. * repotting and removal * Separate Holds from Reserves * Introduce freezes * Missing files * Tests for freezing * Fix hold+freeze combo * More tests * Fee-free dispatchable for upgrading accounts * Benchmarks and a few fixes * Another test * Docs and refactor to avoid blanket impls * Repot * Fit out ItemOf fully * Add events to Balanced traits * Introduced events into Hold traits * Fix Assets pallet tests * Assets benchmarks pass * Missing files and fixes * Fixes * Fixes * Benchmarks fixes * Fix balance benchmarks * Formatting * Expose fungible sub modules * Move NIS to fungible API * Fix broken impl and add test * Fix tests * API for `transfer_and_hold` * Use composite APIs * Formatting * Upgraded event * Fixes * Fixes * Fixes * Fixes * Repot tests and some fixed * Fix some bits * Fix dust tests * Rename `set_balance` - `Balances::set_balance` becomes `Balances::force_set_balance` - `Unbalanced::set_balance` becomes `Unbalances::write_balance` * becomes * Move dust handling to fungibles API * Formatting * Fixes and more refactoring * Fixes * Fixes * Fixes * Fixes * Fixes * Fixes * Fixes * Fixes * Fixes * Use reducible_balance for better correctness on fees * Reducing hold to zero should remove entry. * Add test * Docs * Update frame/support/src/traits/tokens/fungibles/hold.rs Co-authored-by: Muharem Ismailov <ismailov.m.h@gmail.com> * Update frame/support/src/traits/tokens/fungibles/regular.rs Co-authored-by: Muharem Ismailov <ismailov.m.h@gmail.com> * Update frame/support/src/traits/tokens/fungible/hold.rs Co-authored-by: Muharem Ismailov <ismailov.m.h@gmail.com> * Update frame/support/src/traits/tokens/fungible/regular.rs Co-authored-by: Muharem Ismailov <ismailov.m.h@gmail.com> * Docs * Docs * Docs * Fix NIS benchmarks * Doc comment * Remove post_mutation * Fix some tests * Fix some grumbles * Enumify bool args to fungible(s) functions * Fix up assets and balances * Formatting * Fix contracts * Fix tests & benchmarks build * Typify minted boolean arg * Typify on_hold boolean arg; renames * Fix numerous tests * Fix dependency issue * Privatize dangerous API mutate_account * Fix contracts (@alext - please check this commit) * Remove println * Fix tests for contracts * Fix broken rename * Fix broken rename * Fix broken rename * Docs * Update frame/support/src/traits/tokens/fungible/hold.rs Co-authored-by: Anthony Alaribe <anthonyalaribe@gmail.com> * remove from_ref_time * Update frame/executive/src/lib.rs Co-authored-by: Anthony Alaribe <anthonyalaribe@gmail.com> * Update frame/executive/src/lib.rs Co-authored-by: Anthony Alaribe <anthonyalaribe@gmail.com> * Reenable test * Update frame/support/src/traits/tokens/fungibles/hold.rs Co-authored-by: Anthony Alaribe <anthonyalaribe@gmail.com> * Update frame/support/src/traits/tokens/fungible/hold.rs Co-authored-by: Anthony Alaribe <anthonyalaribe@gmail.com> * Update frame/support/src/traits/tokens/fungible/hold.rs Co-authored-by: Anthony Alaribe <anthonyalaribe@gmail.com> * Update frame/support/src/traits/tokens/fungible/hold.rs Co-authored-by: Anthony Alaribe <anthonyalaribe@gmail.com> * Update frame/support/src/traits/tokens/currency.rs Co-authored-by: Anthony Alaribe <anthonyalaribe@gmail.com> * Update frame/lottery/src/tests.rs Co-authored-by: Anthony Alaribe <anthonyalaribe@gmail.com> * Update frame/support/src/traits/tokens/fungible/mod.rs Co-authored-by: Anthony Alaribe <anthonyalaribe@gmail.com> * Update frame/support/src/traits/tokens/fungible/regular.rs Co-authored-by: Anthony Alaribe <anthonyalaribe@gmail.com> * Update frame/support/src/traits/tokens/fungibles/freeze.rs Co-authored-by: Anthony Alaribe <anthonyalaribe@gmail.com> * Update frame/support/src/traits/tokens/fungible/regular.rs Co-authored-by: Anthony Alaribe <anthonyalaribe@gmail.com> * Update frame/support/src/traits/tokens/fungibles/hold.rs Co-authored-by: Anthony Alaribe <anthonyalaribe@gmail.com> * Update frame/support/src/traits/tokens/fungibles/hold.rs Co-authored-by: Anthony Alaribe <anthonyalaribe@gmail.com> * Update frame/support/src/traits/tokens/fungibles/hold.rs Co-authored-by: Anthony Alaribe <anthonyalaribe@gmail.com> * Rename UnwantedRemoval to UnwantedAccountRemoval * Docs * Formatting * Update frame/balances/src/lib.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update primitives/runtime/src/lib.rs Co-authored-by: Keith Yeung <kungfukeith11@gmail.com> * handle_raw_dust oes nothing * Formatting * Fixes * Grumble * Fixes * Add test * Add test * Tests for reducible_balance * Fixes * Fix Salary * Fixes * Disable broken test * Disable nicely * Fixes * Fixes * Fixes * Rename some events * Fix nomination pools breakage * Add compatibility stub for transfer tx * Reinstate a safely compatible version of Balances set_balance * Fixes * Grumble * Update frame/nis/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * ".git/.scripts/commands/bench/bench.sh" pallet dev pallet_balances * disable flakey tests * Update frame/balances/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Grumbles * Grumble --------- Co-authored-by: Muharem Ismailov <ismailov.m.h@gmail.com> Co-authored-by: Alexander Theißen <alex.theissen@me.com> Co-authored-by: Anthony Alaribe <anthonyalaribe@gmail.com> Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: Keith Yeung <kungfukeith11@gmail.com> Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Co-authored-by: command-bot <>
This commit is contained in:
@@ -196,6 +196,10 @@ impl pallet_balances::Config for Runtime {
|
||||
type ExistentialDeposit = ExistentialDeposit;
|
||||
type AccountStore = System;
|
||||
type WeightInfo = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
|
||||
pub struct BalanceToU256;
|
||||
|
||||
@@ -39,6 +39,16 @@ macro_rules! member_unbonding_eras {
|
||||
pub const DEFAULT_ROLES: PoolRoles<AccountId> =
|
||||
PoolRoles { depositor: 10, root: Some(900), nominator: Some(901), bouncer: Some(902) };
|
||||
|
||||
fn deposit_rewards(r: u128) {
|
||||
let b = Balances::free_balance(&default_reward_account()).checked_add(r).unwrap();
|
||||
Balances::make_free_balance_be(&default_reward_account(), b);
|
||||
}
|
||||
|
||||
fn remove_rewards(r: u128) {
|
||||
let b = Balances::free_balance(&default_reward_account()).checked_sub(r).unwrap();
|
||||
Balances::make_free_balance_be(&default_reward_account(), b);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_setup_works() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
@@ -469,6 +479,8 @@ mod sub_pools {
|
||||
}
|
||||
|
||||
mod join {
|
||||
use sp_runtime::TokenError;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
@@ -592,7 +604,7 @@ mod join {
|
||||
// Balance needs to be gt Balance::MAX / `MaxPointsToBalance`
|
||||
assert_noop!(
|
||||
Pools::join(RuntimeOrigin::signed(11), 5, 123),
|
||||
pallet_balances::Error::<Runtime>::InsufficientBalance,
|
||||
TokenError::FundsUnavailable,
|
||||
);
|
||||
|
||||
StakingMock::set_bonded_balance(Pools::create_bonded_account(1), max_points_to_balance);
|
||||
@@ -749,7 +761,7 @@ mod claim_payout {
|
||||
|
||||
// and the reward pool has earned 100 in rewards
|
||||
assert_eq!(Balances::free_balance(default_reward_account()), ed);
|
||||
assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 100));
|
||||
deposit_rewards(100);
|
||||
|
||||
let _ = pool_events_since_last_call();
|
||||
|
||||
@@ -796,7 +808,7 @@ mod claim_payout {
|
||||
assert_eq!(Balances::free_balance(&default_reward_account()), ed);
|
||||
|
||||
// Given the reward pool has some new rewards
|
||||
assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 50));
|
||||
deposit_rewards(50);
|
||||
|
||||
// When
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10)));
|
||||
@@ -825,7 +837,7 @@ mod claim_payout {
|
||||
assert_eq!(Balances::free_balance(&default_reward_account()), ed + 25);
|
||||
|
||||
// Given del 50 hasn't claimed and the reward pools has just earned 50
|
||||
assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 50));
|
||||
deposit_rewards(50);
|
||||
assert_eq!(Balances::free_balance(&default_reward_account()), ed + 75);
|
||||
|
||||
// When
|
||||
@@ -855,7 +867,7 @@ mod claim_payout {
|
||||
assert_eq!(Balances::free_balance(&default_reward_account()), ed + 20);
|
||||
|
||||
// Given del 40 hasn't claimed and the reward pool has just earned 400
|
||||
assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 400));
|
||||
deposit_rewards(400);
|
||||
assert_eq!(Balances::free_balance(&default_reward_account()), ed + 420);
|
||||
|
||||
// When
|
||||
@@ -874,7 +886,7 @@ mod claim_payout {
|
||||
assert_eq!(Balances::free_balance(&default_reward_account()), ed + 380);
|
||||
|
||||
// Given del 40 + del 50 haven't claimed and the reward pool has earned 20
|
||||
assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 20));
|
||||
deposit_rewards(20);
|
||||
assert_eq!(Balances::free_balance(&default_reward_account()), ed + 400);
|
||||
|
||||
// When
|
||||
@@ -974,7 +986,7 @@ mod claim_payout {
|
||||
);
|
||||
|
||||
// The pool earns 10 points
|
||||
assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 10));
|
||||
deposit_rewards(10);
|
||||
|
||||
assert_ok!(Pools::do_reward_payout(
|
||||
&10,
|
||||
@@ -1010,7 +1022,7 @@ mod claim_payout {
|
||||
assert_eq!(reward_pool, rew(0, 0, 0));
|
||||
|
||||
// Given the pool has earned some rewards for the first time
|
||||
assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 5));
|
||||
deposit_rewards(5);
|
||||
|
||||
// When
|
||||
let payout =
|
||||
@@ -1031,7 +1043,7 @@ mod claim_payout {
|
||||
assert_eq!(member, del(0.5));
|
||||
|
||||
// Given the pool has earned rewards again
|
||||
assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 10));
|
||||
deposit_rewards(10);
|
||||
|
||||
// When
|
||||
let payout =
|
||||
@@ -1090,7 +1102,7 @@ mod claim_payout {
|
||||
assert_eq!(bonded_pool.points, 100);
|
||||
|
||||
// and the reward pool has earned 100 in rewards
|
||||
assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 100));
|
||||
deposit_rewards(100);
|
||||
|
||||
// When
|
||||
let payout =
|
||||
@@ -1135,7 +1147,7 @@ mod claim_payout {
|
||||
assert_eq!(reward_pool, rew(0, 0, 100));
|
||||
|
||||
// Given the reward pool has some new rewards
|
||||
assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 50));
|
||||
deposit_rewards(50);
|
||||
|
||||
// When
|
||||
let payout =
|
||||
@@ -1166,7 +1178,7 @@ mod claim_payout {
|
||||
assert_eq!(reward_pool, rew(0, 0, 125));
|
||||
|
||||
// Given del_50 hasn't claimed and the reward pools has just earned 50
|
||||
assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 50));
|
||||
deposit_rewards(50);
|
||||
|
||||
// When
|
||||
let payout =
|
||||
@@ -1197,7 +1209,7 @@ mod claim_payout {
|
||||
assert_eq!(reward_pool, rew(0, 0, 180));
|
||||
|
||||
// Given del_40 hasn't claimed and the reward pool has just earned 400
|
||||
assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 400));
|
||||
deposit_rewards(400);
|
||||
|
||||
// When
|
||||
let payout =
|
||||
@@ -1214,7 +1226,7 @@ mod claim_payout {
|
||||
assert_eq!(reward_pool, rew(0, 0, 220));
|
||||
|
||||
// Given del_40 + del_50 haven't claimed and the reward pool has earned 20
|
||||
assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 20));
|
||||
deposit_rewards(20);
|
||||
|
||||
// When
|
||||
let payout =
|
||||
@@ -1252,14 +1264,14 @@ mod claim_payout {
|
||||
fn rewards_distribution_is_fair_basic() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
// reward pool by 10.
|
||||
Balances::mutate_account(&default_reward_account(), |f| f.free += 10).unwrap();
|
||||
deposit_rewards(10);
|
||||
|
||||
// 20 joins afterwards.
|
||||
Balances::make_free_balance_be(&20, Balances::minimum_balance() + 10);
|
||||
assert_ok!(Pools::join(RuntimeOrigin::signed(20), 10, 1));
|
||||
|
||||
// reward by another 20
|
||||
Balances::mutate_account(&default_reward_account(), |f| f.free += 20).unwrap();
|
||||
deposit_rewards(20);
|
||||
|
||||
// 10 should claim 10 + 10, 20 should claim 20 / 2.
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10)));
|
||||
@@ -1276,7 +1288,7 @@ mod claim_payout {
|
||||
);
|
||||
|
||||
// any upcoming rewards are shared equally.
|
||||
Balances::mutate_account(&default_reward_account(), |f| f.free += 20).unwrap();
|
||||
deposit_rewards(20);
|
||||
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10)));
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(20)));
|
||||
@@ -1296,12 +1308,12 @@ mod claim_payout {
|
||||
// basically checks the case where the amount of rewards is less than the pool shares. for
|
||||
// this, we have to rely on fixed point arithmetic.
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
Balances::mutate_account(&default_reward_account(), |f| f.free += 3).unwrap();
|
||||
deposit_rewards(3);
|
||||
|
||||
Balances::make_free_balance_be(&20, Balances::minimum_balance() + 10);
|
||||
assert_ok!(Pools::join(RuntimeOrigin::signed(20), 10, 1));
|
||||
|
||||
Balances::mutate_account(&default_reward_account(), |f| f.free += 6).unwrap();
|
||||
deposit_rewards(6);
|
||||
|
||||
// 10 should claim 3, 20 should claim 3 + 3.
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10)));
|
||||
@@ -1319,7 +1331,7 @@ mod claim_payout {
|
||||
);
|
||||
|
||||
// any upcoming rewards are shared equally.
|
||||
Balances::mutate_account(&default_reward_account(), |f| f.free += 8).unwrap();
|
||||
deposit_rewards(8);
|
||||
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10)));
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(20)));
|
||||
@@ -1333,7 +1345,7 @@ mod claim_payout {
|
||||
);
|
||||
|
||||
// uneven upcoming rewards are shared equally, rounded down.
|
||||
Balances::mutate_account(&default_reward_account(), |f| f.free += 7).unwrap();
|
||||
deposit_rewards(7);
|
||||
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10)));
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(20)));
|
||||
@@ -1353,17 +1365,17 @@ mod claim_payout {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
let ed = Balances::minimum_balance();
|
||||
|
||||
Balances::mutate_account(&default_reward_account(), |f| f.free += 30).unwrap();
|
||||
deposit_rewards(30);
|
||||
|
||||
Balances::make_free_balance_be(&20, ed + 10);
|
||||
assert_ok!(Pools::join(RuntimeOrigin::signed(20), 10, 1));
|
||||
|
||||
Balances::mutate_account(&default_reward_account(), |f| f.free += 100).unwrap();
|
||||
deposit_rewards(100);
|
||||
|
||||
Balances::make_free_balance_be(&30, ed + 10);
|
||||
assert_ok!(Pools::join(RuntimeOrigin::signed(30), 10, 1));
|
||||
|
||||
Balances::mutate_account(&default_reward_account(), |f| f.free += 60).unwrap();
|
||||
deposit_rewards(60);
|
||||
|
||||
// 10 should claim 10, 20 should claim nothing.
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10)));
|
||||
@@ -1384,7 +1396,7 @@ mod claim_payout {
|
||||
);
|
||||
|
||||
// any upcoming rewards are shared equally.
|
||||
Balances::mutate_account(&default_reward_account(), |f| f.free += 30).unwrap();
|
||||
deposit_rewards(30);
|
||||
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10)));
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(20)));
|
||||
@@ -1407,7 +1419,7 @@ mod claim_payout {
|
||||
let ed = Balances::minimum_balance();
|
||||
|
||||
assert_eq!(Pools::api_pending_rewards(10), Some(0));
|
||||
Balances::mutate_account(&default_reward_account(), |f| f.free += 30).unwrap();
|
||||
deposit_rewards(30);
|
||||
assert_eq!(Pools::api_pending_rewards(10), Some(30));
|
||||
assert_eq!(Pools::api_pending_rewards(20), None);
|
||||
|
||||
@@ -1417,7 +1429,7 @@ mod claim_payout {
|
||||
assert_eq!(Pools::api_pending_rewards(10), Some(30));
|
||||
assert_eq!(Pools::api_pending_rewards(20), Some(0));
|
||||
|
||||
Balances::mutate_account(&default_reward_account(), |f| f.free += 100).unwrap();
|
||||
deposit_rewards(100);
|
||||
|
||||
assert_eq!(Pools::api_pending_rewards(10), Some(30 + 50));
|
||||
assert_eq!(Pools::api_pending_rewards(20), Some(50));
|
||||
@@ -1430,7 +1442,7 @@ mod claim_payout {
|
||||
assert_eq!(Pools::api_pending_rewards(20), Some(50));
|
||||
assert_eq!(Pools::api_pending_rewards(30), Some(0));
|
||||
|
||||
Balances::mutate_account(&default_reward_account(), |f| f.free += 60).unwrap();
|
||||
deposit_rewards(60);
|
||||
|
||||
assert_eq!(Pools::api_pending_rewards(10), Some(30 + 50 + 20));
|
||||
assert_eq!(Pools::api_pending_rewards(20), Some(50 + 20));
|
||||
@@ -1464,7 +1476,7 @@ mod claim_payout {
|
||||
Balances::make_free_balance_be(&30, ed + 20);
|
||||
assert_ok!(Pools::join(RuntimeOrigin::signed(30), 10, 1));
|
||||
|
||||
Balances::mutate_account(&default_reward_account(), |f| f.free += 40).unwrap();
|
||||
deposit_rewards(40);
|
||||
|
||||
// everyone claims.
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10)));
|
||||
@@ -1488,7 +1500,7 @@ mod claim_payout {
|
||||
assert_ok!(Pools::bond_extra(RuntimeOrigin::signed(30), BondExtra::FreeBalance(10)));
|
||||
|
||||
// more rewards come in.
|
||||
Balances::mutate_account(&default_reward_account(), |f| f.free += 100).unwrap();
|
||||
deposit_rewards(100);
|
||||
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10)));
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(20)));
|
||||
@@ -1514,7 +1526,7 @@ mod claim_payout {
|
||||
Balances::make_free_balance_be(&20, ed + 20);
|
||||
assert_ok!(Pools::join(RuntimeOrigin::signed(20), 20, 1));
|
||||
|
||||
Balances::mutate_account(&default_reward_account(), |f| f.free += 30).unwrap();
|
||||
deposit_rewards(30);
|
||||
|
||||
// everyone claims.
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10)));
|
||||
@@ -1535,7 +1547,7 @@ mod claim_payout {
|
||||
assert_ok!(Pools::unbond(RuntimeOrigin::signed(20), 20, 10));
|
||||
|
||||
// more rewards come in.
|
||||
Balances::mutate_account(&default_reward_account(), |f| f.free += 100).unwrap();
|
||||
deposit_rewards(100);
|
||||
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10)));
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(20)));
|
||||
@@ -1562,7 +1574,7 @@ mod claim_payout {
|
||||
assert_ok!(Pools::join(RuntimeOrigin::signed(30), 10, 1));
|
||||
|
||||
// 10 gets 10, 20 gets 20, 30 gets 10
|
||||
Balances::mutate_account(&default_reward_account(), |f| f.free += 40).unwrap();
|
||||
deposit_rewards(40);
|
||||
|
||||
// some claim.
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10)));
|
||||
@@ -1581,7 +1593,7 @@ mod claim_payout {
|
||||
);
|
||||
|
||||
// 10 gets 20, 20 gets 40, 30 gets 20
|
||||
Balances::mutate_account(&default_reward_account(), |f| f.free += 80).unwrap();
|
||||
deposit_rewards(80);
|
||||
|
||||
// some claim.
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10)));
|
||||
@@ -1596,7 +1608,7 @@ mod claim_payout {
|
||||
);
|
||||
|
||||
// 10 gets 20, 20 gets 40, 30 gets 20
|
||||
Balances::mutate_account(&default_reward_account(), |f| f.free += 80).unwrap();
|
||||
deposit_rewards(80);
|
||||
|
||||
// some claim.
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10)));
|
||||
@@ -1629,7 +1641,7 @@ mod claim_payout {
|
||||
assert_ok!(Pools::join(RuntimeOrigin::signed(20), 20, 1));
|
||||
|
||||
// 10 gets 10, 20 gets 20, 30 gets 10
|
||||
Balances::mutate_account(&default_reward_account(), |f| f.free += 30).unwrap();
|
||||
deposit_rewards(30);
|
||||
|
||||
// some claim.
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10)));
|
||||
@@ -1645,7 +1657,7 @@ mod claim_payout {
|
||||
);
|
||||
|
||||
// 20 has not claimed yet, more reward comes
|
||||
Balances::mutate_account(&default_reward_account(), |f| f.free += 60).unwrap();
|
||||
deposit_rewards(60);
|
||||
|
||||
// and 20 bonds more -- they should not have more share of this reward.
|
||||
assert_ok!(Pools::bond_extra(RuntimeOrigin::signed(20), BondExtra::FreeBalance(10)));
|
||||
@@ -1665,7 +1677,7 @@ mod claim_payout {
|
||||
);
|
||||
|
||||
// but in the next round of rewards, the extra10 they bonded has an impact.
|
||||
Balances::mutate_account(&default_reward_account(), |f| f.free += 60).unwrap();
|
||||
deposit_rewards(60);
|
||||
|
||||
// everyone claim.
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10)));
|
||||
@@ -1695,7 +1707,7 @@ mod claim_payout {
|
||||
assert_eq!(member_10.last_recorded_reward_counter, 0.into());
|
||||
|
||||
// transfer some reward to pool 1.
|
||||
Balances::mutate_account(&default_reward_account(), |f| f.free += 60).unwrap();
|
||||
deposit_rewards(60);
|
||||
|
||||
// create pool 2
|
||||
Balances::make_free_balance_be(&20, 100);
|
||||
@@ -1779,7 +1791,7 @@ mod claim_payout {
|
||||
}
|
||||
|
||||
// transfer some reward to pool 1.
|
||||
Balances::mutate_account(&default_reward_account(), |f| f.free += 60).unwrap();
|
||||
deposit_rewards(60);
|
||||
|
||||
{
|
||||
join(30, 10);
|
||||
@@ -1849,7 +1861,7 @@ mod claim_payout {
|
||||
|
||||
// 10 bonds extra again with some rewards. This reward should be split equally between
|
||||
// 10 and 20, as they both have equal points now.
|
||||
Balances::mutate_account(&default_reward_account(), |f| f.free += 30).unwrap();
|
||||
deposit_rewards(30);
|
||||
|
||||
{
|
||||
assert_ok!(Pools::bond_extra(
|
||||
@@ -1905,7 +1917,7 @@ mod claim_payout {
|
||||
MaxPoolMembersPerPool::<Runtime>::set(None);
|
||||
|
||||
// pool receives some rewards.
|
||||
Balances::mutate_account(&default_reward_account(), |f| f.free += 30).unwrap();
|
||||
deposit_rewards(30);
|
||||
System::reset_events();
|
||||
|
||||
// 10 cashes it out, and bonds it.
|
||||
@@ -1975,7 +1987,7 @@ mod claim_payout {
|
||||
}
|
||||
|
||||
// some rewards come in.
|
||||
Balances::mutate_account(&default_reward_account(), |f| f.free += 30).unwrap();
|
||||
deposit_rewards(30);
|
||||
|
||||
// and 30 also unbonds half.
|
||||
{
|
||||
@@ -2058,7 +2070,7 @@ mod claim_payout {
|
||||
);
|
||||
|
||||
// some rewards come in.
|
||||
Balances::mutate_account(&default_reward_account(), |f| f.free += 40).unwrap();
|
||||
deposit_rewards(40);
|
||||
|
||||
// everyone claims
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10)));
|
||||
@@ -2120,8 +2132,7 @@ mod claim_payout {
|
||||
.build_and_execute(|| {
|
||||
// some rewards come in.
|
||||
assert_eq!(Balances::free_balance(&default_reward_account()), unit);
|
||||
Balances::mutate_account(&default_reward_account(), |f| f.free += unit / 1000)
|
||||
.unwrap();
|
||||
deposit_rewards(unit / 1000);
|
||||
|
||||
// everyone claims
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10)));
|
||||
@@ -3329,11 +3340,7 @@ mod withdraw_unbonded {
|
||||
);
|
||||
assert_eq!(
|
||||
balances_events_since_last_call(),
|
||||
vec![BEvent::BalanceSet {
|
||||
who: default_bonded_account(),
|
||||
free: 300,
|
||||
reserved: 0
|
||||
}]
|
||||
vec![BEvent::BalanceSet { who: default_bonded_account(), free: 300 }]
|
||||
);
|
||||
|
||||
// When
|
||||
@@ -3447,11 +3454,7 @@ mod withdraw_unbonded {
|
||||
);
|
||||
assert_eq!(
|
||||
balances_events_since_last_call(),
|
||||
vec![BEvent::BalanceSet {
|
||||
who: default_bonded_account(),
|
||||
free: 300,
|
||||
reserved: 0
|
||||
},]
|
||||
vec![BEvent::BalanceSet { who: default_bonded_account(), free: 300 },]
|
||||
);
|
||||
|
||||
CurrentEra::set(StakingMock::bonding_duration());
|
||||
@@ -5078,18 +5081,15 @@ mod reward_counter_precision {
|
||||
let expected_smallest_reward = inflation(50) / 10u128.pow(18);
|
||||
|
||||
// tad bit less. cannot be paid out.
|
||||
assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free +=
|
||||
expected_smallest_reward - 1));
|
||||
deposit_rewards(expected_smallest_reward - 1);
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10)));
|
||||
assert_eq!(pool_events_since_last_call(), vec![]);
|
||||
// revert it.
|
||||
|
||||
assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -=
|
||||
expected_smallest_reward - 1));
|
||||
remove_rewards(expected_smallest_reward - 1);
|
||||
|
||||
// tad bit more. can be claimed.
|
||||
assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free +=
|
||||
expected_smallest_reward + 1));
|
||||
deposit_rewards(expected_smallest_reward + 1);
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10)));
|
||||
assert_eq!(
|
||||
pool_events_since_last_call(),
|
||||
@@ -5114,9 +5114,7 @@ mod reward_counter_precision {
|
||||
assert_ok!(Pools::join(RuntimeOrigin::signed(20), tiny_bond / 2, 1));
|
||||
|
||||
// Suddenly, add a shit ton of rewards.
|
||||
assert_ok!(
|
||||
Balances::mutate_account(&default_reward_account(), |a| a.free += inflation(1))
|
||||
);
|
||||
deposit_rewards(inflation(1));
|
||||
|
||||
// now claim.
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10)));
|
||||
@@ -5155,8 +5153,7 @@ mod reward_counter_precision {
|
||||
// is earning all of the inflation per year (which is really unrealistic, but worse
|
||||
// case), that will be:
|
||||
let pool_total_earnings_10_years = inflation(10) - POLKADOT_TOTAL_ISSUANCE_GENESIS;
|
||||
assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free +=
|
||||
pool_total_earnings_10_years));
|
||||
deposit_rewards(pool_total_earnings_10_years);
|
||||
|
||||
// some whale now joins with the other half ot the total issuance. This will bloat all
|
||||
// the calculation regarding current reward counter.
|
||||
@@ -5186,7 +5183,7 @@ mod reward_counter_precision {
|
||||
assert_ok!(Pools::join(RuntimeOrigin::signed(30), 10 * DOT, 1));
|
||||
|
||||
// and give a reasonably small reward to the pool.
|
||||
assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += DOT));
|
||||
deposit_rewards(DOT);
|
||||
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(30)));
|
||||
assert_eq!(
|
||||
@@ -5258,9 +5255,7 @@ mod reward_counter_precision {
|
||||
assert_ok!(Pools::join(RuntimeOrigin::signed(20), 10 * DOT, 1));
|
||||
|
||||
// earn some small rewards
|
||||
assert_ok!(
|
||||
Balances::mutate_account(&default_reward_account(), |a| a.free += DOT / 1000)
|
||||
);
|
||||
deposit_rewards(DOT / 1000);
|
||||
|
||||
// no point in claiming for 20 (nonetheless, it should be harmless)
|
||||
assert!(pending_rewards(20).unwrap().is_zero());
|
||||
@@ -5280,9 +5275,7 @@ mod reward_counter_precision {
|
||||
|
||||
// earn some small more, still nothing can be claimed for 20, but 10 claims their
|
||||
// share.
|
||||
assert_ok!(
|
||||
Balances::mutate_account(&default_reward_account(), |a| a.free += DOT / 1000)
|
||||
);
|
||||
deposit_rewards(DOT / 1000);
|
||||
assert!(pending_rewards(20).unwrap().is_zero());
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10)));
|
||||
assert_eq!(
|
||||
@@ -5291,9 +5284,7 @@ mod reward_counter_precision {
|
||||
);
|
||||
|
||||
// earn some more rewards, this time 20 can also claim.
|
||||
assert_ok!(
|
||||
Balances::mutate_account(&default_reward_account(), |a| a.free += DOT / 1000)
|
||||
);
|
||||
deposit_rewards(DOT / 1000);
|
||||
assert_eq!(pending_rewards(20).unwrap(), 1);
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10)));
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(20)));
|
||||
@@ -5332,9 +5323,7 @@ mod reward_counter_precision {
|
||||
assert_ok!(Pools::join(RuntimeOrigin::signed(20), 10 * DOT, 1));
|
||||
|
||||
// earn some small rewards
|
||||
assert_ok!(
|
||||
Balances::mutate_account(&default_reward_account(), |a| a.free += DOT / 1000)
|
||||
);
|
||||
deposit_rewards(DOT / 1000);
|
||||
|
||||
// if 20 claims now, their reward counter should stay the same, so that they have a
|
||||
// chance of claiming this if they let it accumulate. Also see
|
||||
@@ -5442,7 +5431,7 @@ mod commission {
|
||||
// Pool earns 80 points and a payout is triggered.
|
||||
|
||||
// Given:
|
||||
assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 80));
|
||||
deposit_rewards(80);
|
||||
assert_eq!(
|
||||
PoolMembers::<Runtime>::get(10).unwrap(),
|
||||
PoolMember::<Runtime> { pool_id, points: 10, ..Default::default() }
|
||||
@@ -5489,7 +5478,7 @@ mod commission {
|
||||
// is next called, which is not done in this test segment..
|
||||
|
||||
// Given:
|
||||
assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 100));
|
||||
deposit_rewards(100);
|
||||
|
||||
// When:
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10)));
|
||||
@@ -5625,7 +5614,7 @@ mod commission {
|
||||
1,
|
||||
Some((Perbill::from_percent(10), root)),
|
||||
));
|
||||
assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 40));
|
||||
deposit_rewards(40);
|
||||
|
||||
// When:
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10)));
|
||||
@@ -6377,7 +6366,7 @@ mod commission {
|
||||
);
|
||||
|
||||
// The pool earns 10 points
|
||||
assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 10));
|
||||
deposit_rewards(10);
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10)));
|
||||
|
||||
// Then:
|
||||
@@ -6387,7 +6376,7 @@ mod commission {
|
||||
);
|
||||
|
||||
// The pool earns 17 points
|
||||
assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 17));
|
||||
deposit_rewards(17);
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10)));
|
||||
|
||||
// Then:
|
||||
@@ -6397,7 +6386,7 @@ mod commission {
|
||||
);
|
||||
|
||||
// The pool earns 50 points
|
||||
assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 50));
|
||||
deposit_rewards(50);
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10)));
|
||||
|
||||
// Then:
|
||||
@@ -6407,7 +6396,7 @@ mod commission {
|
||||
);
|
||||
|
||||
// The pool earns 10439 points
|
||||
assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 10439));
|
||||
deposit_rewards(10439);
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10)));
|
||||
|
||||
// Then:
|
||||
@@ -6427,7 +6416,7 @@ mod commission {
|
||||
));
|
||||
|
||||
// Given:
|
||||
assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 200));
|
||||
deposit_rewards(200);
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10)));
|
||||
|
||||
// Then:
|
||||
@@ -6469,7 +6458,7 @@ mod commission {
|
||||
// When:
|
||||
|
||||
// The pool earns 100 points
|
||||
assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 100));
|
||||
deposit_rewards(100);
|
||||
|
||||
// Change commission to 20%
|
||||
assert_ok!(Pools::set_commission(
|
||||
@@ -6486,7 +6475,7 @@ mod commission {
|
||||
);
|
||||
|
||||
// The pool earns 100 points
|
||||
assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 100));
|
||||
deposit_rewards(100);
|
||||
|
||||
// Then:
|
||||
|
||||
@@ -6535,7 +6524,7 @@ mod commission {
|
||||
// When:
|
||||
|
||||
// The pool earns 100 points
|
||||
assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 100));
|
||||
deposit_rewards(100);
|
||||
|
||||
// Claim payout:
|
||||
assert_ok!(Pools::claim_payout(RuntimeOrigin::signed(10)));
|
||||
@@ -6592,7 +6581,7 @@ mod commission {
|
||||
);
|
||||
|
||||
// The pool earns 10 points
|
||||
assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 10));
|
||||
deposit_rewards(10);
|
||||
|
||||
// execute the payout
|
||||
assert_ok!(Pools::do_reward_payout(
|
||||
@@ -6634,7 +6623,7 @@ mod commission {
|
||||
);
|
||||
|
||||
// The pool earns 10 points
|
||||
assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 10));
|
||||
deposit_rewards(10);
|
||||
|
||||
// execute the payout
|
||||
assert_ok!(Pools::do_reward_payout(
|
||||
@@ -6677,7 +6666,7 @@ mod commission {
|
||||
);
|
||||
|
||||
// Pool earns 80 points, payout is triggered.
|
||||
assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 80));
|
||||
deposit_rewards(80);
|
||||
assert_eq!(
|
||||
PoolMembers::<Runtime>::get(10).unwrap(),
|
||||
PoolMember::<Runtime> { pool_id, points: 10, ..Default::default() }
|
||||
|
||||
Reference in New Issue
Block a user