-
Notifications
You must be signed in to change notification settings - Fork 347
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
Adds ParachainStaking auto-compound feature #1828
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nbaztec
added
B7-runtimenoteworthy
Changes should be noted in any runtime-upgrade release notes
D9-needsaudit👮
PR contains changes to fund-managing logic that should be properly reviewed and externally audited
labels
Sep 23, 2022
…beam into nish-staking-autocompound
notlesh
reviewed
Oct 11, 2022
notlesh
reviewed
Oct 11, 2022
notlesh
reviewed
Oct 11, 2022
notlesh
approved these changes
Oct 12, 2022
nanocryk
reviewed
Oct 12, 2022
librelois
reviewed
Oct 12, 2022
librelois
reviewed
Oct 12, 2022
librelois
reviewed
Oct 12, 2022
librelois
reviewed
Oct 12, 2022
librelois
approved these changes
Oct 12, 2022
timbrinded
pushed a commit
that referenced
this pull request
Oct 14, 2022
* include analyze functionality in pov tool * add extrinsics for handling auto-compounding * user percent based compounding Co-authored-by: Crystalin <[email protected]>
crystalin
changed the title
[MOON-1902] autocompound staking rewards
Adds ParachainStaking auto-compound feature
Oct 20, 2022
notlesh
added
D1-audited👍
PR contains changes to fund-managing logic that has been properly reviewed and externally audited
and removed
D9-needsaudit👮
PR contains changes to fund-managing logic that should be properly reviewed and externally audited
labels
Dec 14, 2022
imstar15
pushed a commit
to AvaProtocol/moonbeam
that referenced
this pull request
May 16, 2023
* include analyze functionality in pov tool * add extrinsics for handling auto-compounding * user percent based compounding Co-authored-by: Crystalin <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
B7-runtimenoteworthy
Changes should be noted in any runtime-upgrade release notes
D1-audited👍
PR contains changes to fund-managing logic that has been properly reviewed and externally audited
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does it do?
autocompounds staking rewards for delegators based on a user-defined setting. Collator rewards will not be auto-compounded.
Extrinsics
✔️
set_auto_compound
- sets auto-compounding reward for an existing delegation.✔️
delegate_with_auto_compound
- delegates and sets auto-compounding reward for a new delegation.Precompiles
✔️
delegationAutoCompound(address delegator, address candidate)
- returns auint8
respresenting the auto-compound value for that delegation.✔️
delegateWithAutoCompound(address candidate, uint256 amount, uint8 autoCompound, uint256 candidateDelegationCount, uint256 candidateAutoCompoundingDelegationCount, uint256 delegatorDelegationCount)
- delegates to a candidate with a specific auto-compound value.✔️
setAutoCompound(address candidate, uint8 value, uint256 candidateAutoCompoundingDelegationCount, uint256 delegatorDelegationCount)
- sets an auto-compound value for an existing delegation.Storage
✔️
AutoCompoundingDelegations
-ValueQuery
, indexed by candidate id and contains the delegation auto compound config as a vec.✔️
MigratedAtStake
-OptionQuery
, stores the firstRound
where theCollatorSnapshot
was migrated. This is a temporary storage item, that will be removed in the subsequent RT update.AtStake
- change indelegations
field to also support auto-compound percentage.Before
After
Events
✔️
DelegationAutoCompoundingSet
- whenset_auto_compound
is called.✔️
Compounded
- emitted when a reward is paid out which also has auto-compounding set. ❗ Delegators having auto-compound enabled (and not 0%) will emitCompounded
in addition to theRewarded
event.Delegation
- adds new fieldauto_compound
. If the extrinsicdelegate(...)
is called then the field has value of0
, else if extrinsicdelegate_with_auto_compound(...)
is called then the field has the user-provided value.Errors
✔️
TooLowCandidateAutoCompoundingDelegationCountToDelegate
- emitted ifdelegate_with_auto_compound
is called with an incorrectcandidate_auto_compounding_delegation_count
.✔️
TooLowDelegationCountToAutoCompound
- emitted ifdelegation_set_auto_compounding_reward
is called with an incorrectdelegation_count
.✔️
TooLowCandidateAutoCompoundingDelegationCountToAutoCompound
- emitted ifdelegation_set_auto_compounding_reward
is called with an incorrectcandidate_auto_compounding_delegation_count
.What important points reviewers should know?
Current approach uses a similar strategy to scheduled requests by introducing the
AutoCompoundingDelegations
storage item. It's indexed by a collator and contains the delegations as a vec.The compound code is, plugged into the bondMore functionality (
delegator_bond_more
) but noDelegationIncreased
will be emitted when auto-compounding. Reusing the same bondMore extrinsics gives us the benefit of having consistent validation.If an auto-compound config exists then a
Rewarded
event is emitted with the reward amount and aCompounded
event is emitted containing the compounded amount, if no config exists then the reward is simply minted andRewarded
event is emitted.The compound percentage is stored per round, following the usual snapshot rules. This leads to extra runtime weight during round's
on_initialize
but was found to be "low-enough" (500 bytes in worst case) with zstd compression.Since we're doing additional work on
on_initialize
, the PoV size and extrinsic time increase sub-quadratically.1
,10
,100
,250
delegators paid out.staking-mint
: existing implementation (only mint) - no delegator has auto-compoundstaking-compound
: suggested implementation (mint+compound) - all delegators have 100% auto-compoundWorst case analysis
350,0
: 350 delegations, 0 auto-compounding350,175
: 350 delegations, 175 auto-compounding350,350
: 350 delegations, 350 auto-compoundingstaking-mint
: existing implementation (only mint)staking-compound
: suggested implementation (mint+compound)The runtime-complexity is sub-quadratic, as defined below:
Is there something left for follow-up PRs?
What alternative implementations were considered?
Are there relevant PRs or issues in other repositories (Substrate, Polkadot, Frontier, Cumulus)?
What value does it bring to the blockchain users?
Allows delegators to auto-compound a percentage of their staking rewards towards a collator.
TODO