liquity / V2-gov

MIT License
3 stars 4 forks source link

Fix bribing accounting by converting lqty to votes #13

Closed jltqy closed 1 day ago

GalloDaSballo commented 3 days ago

You can further simplify the logic of onAfterAllocateLQTY

By writing the following:

function onAfterAllocateLQTY(
        uint16 _currentEpoch,
        address _user,
        IGovernance.UserState calldata _userState,
        IGovernance.Allocation calldata _allocation,
        IGovernance.InitiativeState calldata _initiativeState
    ) external virtual onlyGovernance {

        if (_currentEpoch == 0) return;

        uint16 mostRecentUserEpoch = lqtyAllocationByUserAtEpoch[_user].getHead();
        uint16 mostRecentTotalEpoch = totalLQTYAllocationByEpoch.getHead();

        _setTotalLQTYAllocationByEpoch(
            _currentEpoch, 
            _initiativeState.voteLQTY, 
            _initiativeState.averageStakingTimestampVoteLQTY, 
            mostRecentTotalEpoch != _currentEpoch /// Insert if current > recent
        );

        _setLQTYAllocationByUserAtEpoch(
            _user, 
            _currentEpoch, 
            _allocation.voteLQTY, 
            _userState.averageStakingTimestamp, 
            mostRecentUserEpoch != _currentEpoch /// Insert if user current > recent
        );
    }