diff --git a/.gitignore b/.gitignore index 124002eb..74c5db97 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,6 @@ __pycache__ build/ reports/ venv/ -.vscode/ node_modules/ artifacts/ cache/ diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 00000000..caba825d --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,16 @@ +{ + "plugins": ["prettier-plugin-solidity"], + "overrides": [ + { + "files": "*.sol", + "options": { + "parser": "solidity-parse", + "printWidth": 80, + "tabWidth": 4, + "useTabs": false, + "singleQuote": false, + "bracketSpacing": false + } + } + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..0959db72 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "solidity.formatter": "prettier" +} diff --git a/contracts/BadgerVotingShare.sol b/contracts/BadgerVotingShare.sol index 3fc152aa..c549b949 100644 --- a/contracts/BadgerVotingShare.sol +++ b/contracts/BadgerVotingShare.sol @@ -163,6 +163,10 @@ contract BadgerVotingShare { function _sushiswapBalanceOf( address _voter ) internal view returns (uint256) { + uint256 total = badger_wBTC_SLP.totalSupply(); + if (total == 0) { + return 0; + } uint256 bSLPPricePerShare = sett_badger_wBTC_SLP.getPricePerFullShare(); (, uint112 reserve1, ) = badger_wBTC_SLP.getReserves(); uint256 totalSLPBalance = badger_wBTC_SLP.balanceOf(_voter) + @@ -171,7 +175,7 @@ contract BadgerVotingShare { (geyser_badger_wBTC_SLP.totalStakedFor(_voter) * bSLPPricePerShare) / 1e18; - return (totalSLPBalance * reserve1) / badger_wBTC_SLP.totalSupply(); + return (totalSLPBalance * reserve1) / total; } /* @@ -182,15 +186,17 @@ contract BadgerVotingShare { After adding the 2 balances we calculate how much BADGER it corresponds to using the pool's reserves. */ function _curveBalanceOf(address _voter) internal view returns (uint256) { + uint256 total = badger_wBTC_crv_token.totalSupply(); + if (total == 0) { + return 0; + } // coin 0 is BADGER uint256 bCrvPricePerShare = sett_badger_wBTC_crv.getPricePerFullShare(); uint256 poolBadgerBalance = badger_wBTC_crv_pool.balances(0); uint256 voterLpBalance = badger_wBTC_crv_token.balanceOf(_voter) + (sett_badger_wBTC_crv.balanceOf(_voter) * bCrvPricePerShare) / 1e18; - return - (voterLpBalance * poolBadgerBalance) / - badger_wBTC_crv_token.totalSupply(); + return (voterLpBalance * poolBadgerBalance) / total; } /* @@ -233,11 +239,14 @@ contract BadgerVotingShare { The voter may have deposited BADGER into the across pool: */ function _acrossBalanceOf(address _voter) internal view returns (uint256) { + uint256 total = aBADGER.totalSupply(); + if (total == 0) { + return 0; + } int256 numerator = int256(aBADGER.liquidReserves()) + int256(aBADGER.utilizedReserves()) - int256(aBADGER.undistributedLpFees()); - uint256 exchangeRateCurrent = (uint256(numerator) * 1e18) / - aBADGER.totalSupply(); + uint256 exchangeRateCurrent = (uint256(numerator) * 1e18) / total; return (exchangeRateCurrent * aBADGER.balanceOf(_voter)) / 1e18; } @@ -257,7 +266,7 @@ contract BadgerVotingShare { (IERC20[] memory tokens, uint256[] memory balances, ) = balancer_vault .getPoolTokens(poolId); uint256 poolBadgerAmount; - for (uint i = 0; i < tokens.length; i++) { + for (uint256 i = 0; i < tokens.length; i++) { if (tokens[i] == badger) { poolBadgerAmount = balances[i]; break; @@ -265,6 +274,9 @@ contract BadgerVotingShare { } uint256 bptTotalSupply = badger_wBTC_balancer.totalSupply(); + if (bptTotalSupply == 0) { + return 0; + } uint256 voterBalance = badger_wBTC_balancer.balanceOf(_voter); uint256 voterVaultBalance = sett_badger_wBTC_balancer.balanceOf(_voter); uint256 voterStakedBalance = bptStakedBadgerWbtc.balanceOf(_voter); @@ -306,6 +318,9 @@ contract BadgerVotingShare { } uint256 bptTotalSupply = badgerRethBalancer.totalSupply(); + if (bptTotalSupply == 0) { + return 0; + } uint256 voterBalance = badgerRethBalancer.balanceOf(_voter); uint256 bptVotes = (voterBalance * poolBadgerAmount) / bptTotalSupply;