Skip to content

CS-V2Gov-052: Possible Code Simplifications #119

@danielattilasimon

Description

@danielattilasimon

Some parts of the code may be simplified, to make them more easily understandable and maintainable. Below is a non-exhaustive list of such snippets:

  1. In withdrawLQTY() there is an if-else clause ensuring that the user's unallocatedOffset goes to 0 in case of a complete withdrawal. However, the fraction formula used in the if branch would already yield offsetDecrease == unallocatedOffset in this case, without the need for a special case.

  2. In allocateLQTY(), the FSM check on DISABLED initiatives is redundant: the require will never fail. This is because the previous check on "active votes" already implies that, for all other states, both deltas should be non-positive. In fact, this holds not just for the DISABLED state, but also UNREGISTERABLE.

  3. In _allocateLQTY(), updating the GlobalState is done by subtracting the prevInitiativeState and adding the new initiativeState. However, this could be simplified by simply adding the relevant user-supplied delta, and suppressing the prevInitiativeState altogether.

  4. All payout snippets (in claimForInitiative(), BribeInitiative.claimBribes(), CurveV2GaugeRewards._depositIntoGauge()) include some capping logic, to account for potential errors leading to insolvency. However, the main source of rounding errors that led to broken accounting (i.e. using the average timestamp to represent lines) has been removed in [Version 3]. Moreover, should some other sources of error be left undiscovered, this mitigation still does not adequately protect against them: it only makes sure that the "last" payout does not revert, possibly at the expense of other destinations of those funds, without addressing the root cause that led to incorrect payout calculations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions