MooniswapGovernance - _beforeTokenTransfer should not update voting power on transfers to self Unverified
Mooniswap governance is based on the liquidity voting system that is also employed by the mothership or for factory governance. In contrast to traditional voting systems where users vote for discrete values, the liquidity voting system derives a continuous weighted averaged “consensus” value from all the votes. Thus it is required that whenever stake changes in the system, all the parameters that can be voted upon are updated with the new weights for a specific user.\\nThe Mooniswap pool is governed by liquidity providers and liquidity tokens are the stake that gives voting rights in `MooniswapGovernance`. Thus whenever liquidity tokens are transferred to another address, stake and voting values need to be updated. This is handled by `MooniswapGovernance._beforeTokenTransfer()`.\\nIn the special case where someone triggers a token transfer where the `from` address equals the `to` address, effectively sending the token `to` themselves, no update on voting power should be performed. Instead, voting power is first updated with `balance - amount` and then with `balance + amount` which in the worst case means it is updating first `to` a zero balance and then `to` 2x the balance.\\nUltimately this should not have an effect on the overall outcome but is unnecessary and wasting gas.\\n`beforeTokenTransfer` callback in `Mooniswap` does not check for the NOP case where `from==to`\\n```\\nfunction \\_beforeTokenTransfer(address from, address to, uint256 amount) internal override {\\n    uint256 balanceFrom = (from != address(0)) ? balanceOf(from) : 0;\\n    uint256 balanceTo = (from != address(0)) ? balanceOf(to) : 0;\\n    uint256 newTotalSupply = totalSupply()\\n        .add(from == address(0) ? amount : 0)\\n        .sub(to == address(0) ? amount : 0);\\n\\n    ParamsHelper memory params = ParamsHelper({\\n        from: from,\\n        to: to,\\n        amount: amount,\\n        balanceFrom: balanceFrom,\\n        balanceTo: balanceTo,\\n        newTotalSupply: newTotalSupply\\n    });\\n\\n    \\_updateOnTransfer(params, mooniswapFactoryGovernance.defaultFee, \\_emitFeeVoteUpdate, \\_fee);\\n    \\_updateOnTransfer(params, mooniswapFactoryGovernance.defaultSlippageFee, \\_emitSlippageFeeVoteUpdate, \\_slippageFee);\\n    \\_updateOnTransfer(params, mooniswapFactoryGovernance.defaultDecayPeriod, \\_emitDecayPeriodVoteUpdate, \\_decayPeriod);\\n}\\n```\\n\\nwhich leads to `updateBalance` being called on the same address twice, first with `currentBalance - amountTransferred` and then with `currentBalance + amountTransferred`.\\n```\\nif (params.from != address(0)) {\\n    votingData.updateBalance(params.from, voteFrom, params.balanceFrom, params.balanceFrom.sub(params.amount), params.newTotalSupply, defaultValue, emitEvent);\\n}\\n\\nif (params.to != address(0)) {\\n    votingData.updateBalance(params.to, voteTo, params.balanceTo, params.balanceTo.add(params.amount), params.newTotalSupply, defaultValue, emitEvent);\\n}\\n```\\n
Do not update voting power on LP token transfers where `from == to`.
```\\nfunction \\_beforeTokenTransfer(address from, address to, uint256 amount) internal override {\\n    uint256 balanceFrom = (from != address(0)) ? balanceOf(from) : 0;\\n    uint256 balanceTo = (from != address(0)) ? balanceOf(to) : 0;\\n    uint256 newTotalSupply = totalSupply()\\n        .add(from == address(0) ? amount : 0)\\n        .sub(to == address(0) ? amount : 0);\\n\\n    ParamsHelper memory params = ParamsHelper({\\n        from: from,\\n        to: to,\\n        amount: amount,\\n        balanceFrom: balanceFrom,\\n        balanceTo: balanceTo,\\n        newTotalSupply: newTotalSupply\\n    });\\n\\n    \\_updateOnTransfer(params, mooniswapFactoryGovernance.defaultFee, \\_emitFeeVoteUpdate, \\_fee);\\n    \\_updateOnTransfer(params, mooniswapFactoryGovernance.defaultSlippageFee, \\_emitSlippageFeeVoteUpdate, \\_slippageFee);\\n    \\_updateOnTransfer(params, mooniswapFactoryGovernance.defaultDecayPeriod, \\_emitDecayPeriodVoteUpdate, \\_decayPeriod);\\n}\\n```\\n