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: Batch NXM withdrawals #1201

Merged
merged 51 commits into from
Aug 16, 2024
Merged

Conversation

roxdanila
Copy link
Contributor

@roxdanila roxdanila commented Aug 1, 2024

Context

Closes #1173

Add TokenController.withdrawNXM to withdraw all NXM from the platform. The caller must do the checks if the NXM is withdrawable and modify params accordingly to skip / include specific NXM withdrawals.

Changes proposed in this pull request

  • Assessment
    • add unstakeForAll
    • convert requires to custom error
    • remove redundant isMember check in withdrawRewardsTo
  • TokenController
    • add withdrawNXM
    • add _withdrawClaimAssessmentTokensForUser internal function
    • remove withdrawPendingRewards in favour of withdrawNXM

Test plan

  • integration tests
  • fork tests

Checklist

  • Rebased the base branch
  • Attached corresponding Github issue
  • Prefixed the name with the type of change (i.e. feat, chore, test)
  • Performed a self-review of my own code
  • Followed the style guidelines of this project
  • Made corresponding changes to the documentation
  • Didn't generate new warnings
  • Didn't generate failures on existing tests
  • Added tests that prove my fix is effective or that my feature works

Review

When reviewing a PR, please indicate intention in comments using the following emojis:

  • 🍰 = Nice to have but not essential.
  • 💡 = Suggestion or a comment based on personal opinion
  • 🔨 = I believe this should be changed.
  • 🤔 = I don’t understand something, do you mind giving me more context?
  • 🚀 = Feedback

@roxdanila roxdanila requested a review from shark0der August 1, 2024 10:45
@roxdanila roxdanila linked an issue Aug 1, 2024 that may be closed by this pull request
if (withdrawOptions.assessmentStake) {
IAssessment _assessment = assessment();
(uint96 amount, , ) = _assessment.stakeOf(msg.sender);
_assessment.unstakeFor(msg.sender, amount, msg.sender);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd create one more function that doesn't need the amount as an input and withdraws all to avoid extra calls and extraneous validations.

Copy link
Contributor

@rackstar rackstar Aug 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new assessment.unstakeAllFor function:

  • drop all checks except for assessment vote locked check

is it worth adding validation that only TokenController can call assessment.unstakeAllFor?

Could it be considered a griefing attack if anyone can unstake the staker? (staker receives the stake so funds are safe)

@roxdanila roxdanila linked an issue Aug 1, 2024 that may be closed by this pull request
@rackstar rackstar force-pushed the feat/batch-nxm-withdrawal branch 4 times, most recently from ff727b7 to ef35f46 Compare August 6, 2024 12:44
@rackstar rackstar changed the title [draft] Feat: Batch NXM withdrawals feat: Batch NXM withdrawals Aug 7, 2024
@rackstar rackstar marked this pull request as ready for review August 7, 2024 08:59
@rackstar rackstar force-pushed the feat/batch-nxm-withdrawal branch 2 times, most recently from 65106fb to 507a140 Compare August 7, 2024 13:24
@@ -189,20 +213,14 @@ contract Assessment is IAssessment, MasterAwareV2 {
address destination,
uint104 batchSize
) internal returns (uint withdrawn, uint withdrawnUntilIndex) {
require(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this removed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its a redundant check as it duplicates the check that TokenController.mint does.

relevant discussion: #1201 (comment)

@rackstar rackstar force-pushed the feat/batch-nxm-withdrawal branch 4 times, most recently from 80a427e to 6223456 Compare August 8, 2024 17:05
Comment on lines 317 to 332
if (withdrawAssessment.rewards) {
// pass in 0 batchSize to withdraw ALL Assessment rewards
assessment().withdrawRewards(msg.sender, 0);
}

// governance rewards
uint governanceRewards = governance().claimReward(msg.sender, govRewardsBatchSize);
Copy link
Contributor

@rackstar rackstar Aug 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We separated the batchSize that is passed to the assessment and governance rewards to fix the batchSize issue.

Hardcoded 0 batchSize for assessment.withdrawRewards, which effectively withdraws ALL assessment rewards.

And the batchSize from the parameters (govRewardsBatchSize ) will now only be used in governance rewards.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible that all assessment rewards withdrawal won't fit in a block? I guess that's why the batchSize argument was implemented in the first place

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There has been only 21 assessment so far so it seemed relatively safe to hardcode 0. but now in hindsight, this is a bad design.

it better to expose the assessment batchSize and let the caller (FE) have the option to withdraw all or in batches.

i will add a new assessmentRewardsBatchSize param. the withdrawNxm will now look like:

  function withdrawNXM(
    WithdrawAssessment calldata withdrawAssessment,
    StakingPoolDeposit[] calldata stakingPoolDeposits,
    StakingPoolManagerReward[] calldata stakingPoolManagerRewards,
    uint assessmentRewardsBatchSize,
    uint govRewardsBatchSize
  ) external {

@rackstar rackstar requested a review from MilGard91 August 9, 2024 08:37
@rackstar rackstar force-pushed the feat/batch-nxm-withdrawal branch from 6223456 to 6cd1e3b Compare August 9, 2024 09:05
@rackstar rackstar changed the base branch from release-candidate to feat/move-staking-pool-metadata August 9, 2024 09:05
@rackstar rackstar force-pushed the feat/batch-nxm-withdrawal branch 2 times, most recently from cd0d12e to 22e1d99 Compare August 9, 2024 11:30
@rackstar rackstar force-pushed the feat/batch-nxm-withdrawal branch from c37d784 to fea86de Compare August 16, 2024 12:38
Base automatically changed from feat/move-staking-pool-metadata to fix/reward-shares August 16, 2024 12:39
@rackstar rackstar merged commit fea86de into fix/reward-shares Aug 16, 2024
4 checks passed
@rackstar rackstar deleted the feat/batch-nxm-withdrawal branch August 16, 2024 12:39
@rackstar rackstar mentioned this pull request Aug 16, 2024
9 tasks
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.

Allow batch withdrawal of claimable NXM
3 participants