-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Introduces: Delegated Staking Pallet #3904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
dda12d4
802784c
d2b680e
646c7f4
bc92a19
2528da7
4ddcb77
0cbec7d
e6152ed
a91a417
d6069a4
3e37916
79c4a86
35c5e80
c5a5d32
f82b349
b550031
b87fc08
bfd3434
7104faf
aed693c
989bc50
731f5a1
4226b9b
6f05a52
3d0e0ba
4d00b04
264f71a
f9a52f1
1d58711
7bf4d34
40a5132
e8e498c
5ece9c7
23c65c4
4f441d5
58b50c9
b946c4a
0aa9006
d242356
4fcafd0
6bd5e2c
2fb04c5
7962aac
8bd3bc3
11da089
15a9fc6
1a34d28
2a75dc5
0bf4dba
7800446
84fb918
e55cea3
fbccd0f
0c83496
765278a
e46b01b
0e41b01
67a541c
444dc76
9e5bdfa
b1312d7
9079d82
616dfa7
6bcf0ab
afe8c87
e7d65e2
474c1de
6a019d6
8d481a6
6940f88
a884846
d4633c2
c013cde
b2588a5
ac3cadf
8cee25c
0537e9c
fb5d64c
bb93c8c
cba250e
9897437
09d3359
e75c2e6
e31866e
078cf5f
3790a40
796c848
666be52
be76a6b
c6070d8
886a1a7
a69d620
4b2daa2
0e17037
4e3b8cd
b1b1e1d
1e6cdad
3cef018
24d05ad
bd56eb3
d4ef271
fe0b657
464cea0
7782cab
6e3045f
159d1bf
52ae957
77eb34c
9e035ba
78fac9e
3264782
cd5eb94
8314177
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,9 +54,9 @@ | |
| //! - **Delegatee**: An account who accepts delegations from other accounts. | ||
| //! - **Delegator**: An account who delegates their funds to a `delegatee`. | ||
| //! - **DelegateeLedger**: A data structure that stores important information about the `delegatee` | ||
| //! such as their total delegated stake. | ||
| //! such as their total delegated stake. | ||
| //! - **Delegation**: A data structure that stores the amount of funds delegated to a `delegatee` by | ||
| //! a `delegator`. | ||
| //! a `delegator`. | ||
| //! | ||
| //! ## Interface | ||
| //! | ||
|
|
@@ -129,7 +129,7 @@ | |
| //! ## Limitations | ||
| //! - Rewards can not be auto-compounded. | ||
| //! - Slashes are lazy and hence there could be a period of time when an account can use funds for | ||
| //! operations such as voting in governance even though they should be slashed. | ||
| //! operations such as voting in governance even though they should be slashed. | ||
|
|
||
| #![cfg_attr(not(feature = "std"), no_std)] | ||
| #![deny(rustdoc::broken_intra_doc_links)] | ||
|
|
@@ -469,7 +469,7 @@ impl<T: Config> Pallet<T> { | |
|
|
||
| /// Returns true if who is not already staking on [`Config::CoreStaking`]. | ||
| fn not_direct_staker(who: &T::AccountId) -> bool { | ||
| T::CoreStaking::status(&who).is_err() | ||
| T::CoreStaking::status(who).is_err() | ||
| } | ||
|
|
||
| /// Returns true if who is a [`StakerStatus::Nominator`] on [`Config::CoreStaking`]. | ||
|
|
@@ -531,7 +531,7 @@ impl<T: Config> Pallet<T> { | |
| if delegatee.is_bonded() { | ||
| T::CoreStaking::bond_extra(&delegatee.key, amount) | ||
| } else { | ||
| T::CoreStaking::virtual_bond(&delegatee.key, amount, &delegatee.reward_account()) | ||
| T::CoreStaking::virtual_bond(&delegatee.key, amount, delegatee.reward_account()) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -605,7 +605,7 @@ impl<T: Config> Pallet<T> { | |
|
|
||
| let released = T::Currency::release( | ||
| &HoldReason::Delegating.into(), | ||
| &delegator, | ||
| delegator, | ||
| amount, | ||
| Precision::BestEffort, | ||
| )?; | ||
|
|
@@ -658,7 +658,7 @@ impl<T: Config> Pallet<T> { | |
| amount: BalanceOf<T>, | ||
| ) -> DispatchResult { | ||
| let source_delegation = | ||
| Delegators::<T>::get(&source_delegator).defensive_ok_or(Error::<T>::BadState)?; | ||
| Delegators::<T>::get(source_delegator).defensive_ok_or(Error::<T>::BadState)?; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit but not sure if
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The pattern I have tried to follow is:
The delegator checks are already done by the caller and this function assumes it must be a delegator or returns
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Least assumptions about the call site generally better. |
||
|
|
||
| // some checks that must have already been checked before. | ||
| ensure!(source_delegation.amount >= amount, Error::<T>::NotEnoughFunds); | ||
|
|
@@ -679,7 +679,7 @@ impl<T: Config> Pallet<T> { | |
| // release funds from source | ||
| let released = T::Currency::release( | ||
| &HoldReason::Delegating.into(), | ||
| &source_delegator, | ||
| source_delegator, | ||
| amount, | ||
| Precision::BestEffort, | ||
| )?; | ||
|
|
@@ -689,15 +689,15 @@ impl<T: Config> Pallet<T> { | |
| // transfer the released amount to `destination_delegator`. | ||
| // Note: The source should have been funded ED in the beginning so it should not be dusted. | ||
| T::Currency::transfer( | ||
| &source_delegator, | ||
| source_delegator, | ||
| destination_delegator, | ||
| amount, | ||
| Preservation::Preserve, | ||
| ) | ||
| .map_err(|_| Error::<T>::BadState)?; | ||
|
|
||
| // hold the funds again in the new delegator account. | ||
| T::Currency::hold(&HoldReason::Delegating.into(), &destination_delegator, amount)?; | ||
| T::Currency::hold(&HoldReason::Delegating.into(), destination_delegator, amount)?; | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should mention here that, along the compounding limitation, the rewards can't be received in the same stash account.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really see it as a limitation. Given that stash account is a keyless account, does not really mean anything by paying rewards there.