Skip to content
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

Feat/delegation impr v3 #6605

Open
wants to merge 28 commits into
base: rc/barnard
Choose a base branch
from
Open

Conversation

sasurobert
Copy link
Contributor

@sasurobert sasurobert commented Nov 14, 2024

Reasoning behind the pull request

Delegation improvements after Staking Phase 4.0:

Proposed changes

Delegation Fixes after Staking Phase 4.0:

  1. claimRewards with callValue should return an error.
    Add a flag and check for call value
  2. Staking Providers should not change their fees frequently, there were cases when they changed exactly before epoch change.
    Proposal: add storage for last epoch when change happened and do not allow a new change of FEE for the next 30 days.
    There are always errors, so will always change the fee downwards, but upwards only once per 30 days.

Delegation improvements after Staking Phase 4.0:
MIP-18 - Migration feature for delegated EGLD to improve the efficiency of the dynamic validator market
This is a feature request asked by a lot of community members and someone has written a proposal as well. The solution I propose is to enable users to move funds from one provider to another once per 30 days.
changeStakingProvider@amount@sourceSCAddress@destinationSCAddress
vmInput.Caller address is the delegator, it is the user address, or the SC address in case of liquid staking contracts or DAO.
vmInput.RecipientAddress is the delegation manager contract, which will forward the call to the delegation contract the user wants to move his funds.
sourceSCAddress and destinationSCAddress are verified to be a system delegation contract.
removeDelegationFromSource@delegatorAddress@amount: does basic checks, can be called by delegation manager address only, and removes from the user the specified amount if the user has enough delegation there.
The system checks what was the last time the delegator moved funds to this contract, by checking a new storage in which the epoch was saved.
If epoch == 0 or epoch + 30 < currentEpoch we can go to the next step of moving.
Rewards are calculated for the user and saved into claimable rewards (this code already exists and used when user delegates more), and the new amount of delegation is computed by subtracting the amount value.
moveDelegationToDestination@delegatorAddress@amount: does basic checks, can be called by delegation manager address only, adds the stated amount to the user’s delegation. It creates new storage where the current epoch is saved, the user cannot changeProvider from this place for the next 30 days.He can always unStake and unBond.
It will call the internal delegate function, compute rewards for the user if the user already had delegation, increase the delegation amount for the user
New function in ValidatorSC is called which makes unStake and unBond in one call for the staking provider, actually the only thing it needs to do is to change the TotalStakedAmount from the staking provider, without adding it to the unStakedFunds. Unstaking of nodes is happening at the end of the epoch if the SP does not have enough funds (this process is the existing code - which works like this even now).
moveStakeFromValidatorToValidator@stakeAmount@valiadtorA@validatorB - it can be called by system delegationContracts only. The caller is the delegation contract from which the funds are moved out.
This function will also increase the TotalStakedAmount for validatorB. Nothing else to do.
removeDelegationFromSource, moveDelegationToDestination and moveStakeFromValidatorToValidator are called synchronously. If one of them fails, no changes are made.
Process finished.

Testing procedure

  1. try claimRewards with callValue before and after activation flag. After it should fail.
  2. try to change increase service fee multiple times in the same time period, it should fail after activation, but decreasing it should work.
  3. Create multiple staking providers, delegate from various users to these staking providers and start to migrate delegation amounts from one to another.
    • if a user moves from SP 1 to SP 2, it cannot move from SP 2 towards SP 3 for the next 30 days.
    • the user can move any number of times from SP 1 to any number of providers
    • the user can move into SP 2 from other SPs.
    • after 30 days cooldown period user can move from SP2 again. Unstake and UnBond in the cooldown period should work

Pre-requisites

Based on the Contributing Guidelines the PR author and the reviewers must check the following requirements are met:

  • was the PR targeted to the correct branch?
  • if this is a larger feature that probably needs more than one PR, is there a feat branch created?
  • if this is a feat branch merging, do all satellite projects have a proper tag inside go.mod?

sasurobert and others added 27 commits September 25, 2024 16:43
…should-err

Claim rewards with call value should err
# Conflicts:
#	common/enablers/enableEpochsHandler_test.go
#	config/tomlConfig_test.go
#	node/metrics/metrics.go
#	node/metrics/metrics_test.go
#	statusHandler/statusMetricsProvider.go
#	statusHandler/statusMetricsProvider_test.go
# Conflicts:
#	vm/systemSmartContracts/delegation.go
Copy link

📊 MultiversX Automated Test Report: View Report

🔄 Build Details:

  • mx-chain-go Commit Hash: bdaaf5593e9f9b3ab3edf5578d1b9973903a27a6
  • Current Branch: feat/delegation-impr-v3
  • mx-chain-go Target Branch: rc/barnard
  • mx-chain-simulator-go Target Branch: rc/barnard
  • mx-chain-testing-suite Target Branch: rc/barnard

🚀 Environment Variables:

  • TIMESTAMP: 14112024-083006
  • PYTEST_EXIT_CODE: 0
    🎉 MultiversX CI/CD Workflow Complete!

Copy link

📊 MultiversX Automated Test Report: View Report

🔄 Build Details:

  • mx-chain-go Commit Hash: 16d3ec34175ef6019d27f5a1fb251e9bdc434efe
  • Current Branch: feat/delegation-impr-v3
  • mx-chain-go Target Branch: rc/barnard
  • mx-chain-simulator-go Target Branch: rc/barnard
  • mx-chain-testing-suite Target Branch: rc/barnard

🚀 Environment Variables:

  • TIMESTAMP: 14112024-090703
  • PYTEST_EXIT_CODE: 0
    🎉 MultiversX CI/CD Workflow Complete!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants