Skip to content

Commit

Permalink
fix: round up when calculating curation fees and the protocol tax (OZ…
Browse files Browse the repository at this point in the history
… L-01)
  • Loading branch information
pcarranzav committed Nov 20, 2023
1 parent 3882b35 commit f9af7eb
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions contracts/staking/Staking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,13 @@ abstract contract Staking is StakingV4Storage, GraphUpgradeable, IStakingBase, M
bool isCurationEnabled = _curationPercentage > 0 && address(curation) != address(0);

if (isCurationEnabled && curation.isCurated(_subgraphDeploymentID)) {
uint256 curationFees = uint256(_curationPercentage).mul(_tokens).div(MAX_PPM);
// Calculate the tokens after curation fees first, and subtact that,
// to prevent curation fees from rounding down to zero
uint256 tokensAfterCurationFees = uint256(MAX_PPM)
.sub(_curationPercentage)
.mul(_tokens)
.div(MAX_PPM);
uint256 curationFees = _tokens.sub(tokensAfterCurationFees);
if (curationFees > 0) {
// Transfer and call collect()
// This function transfer tokens to a trusted protocol contracts
Expand All @@ -976,7 +982,10 @@ abstract contract Staking is StakingV4Storage, GraphUpgradeable, IStakingBase, M
uint256 _tokens,
uint256 _percentage
) private returns (uint256) {
uint256 tax = uint256(_percentage).mul(_tokens).div(MAX_PPM);
// Calculate tokens after tax first, and subtract that,
// to prevent the tax from rounding down to zero
uint256 tokensAfterTax = uint256(MAX_PPM).sub(_percentage).mul(_tokens).div(MAX_PPM);
uint256 tax = _tokens.sub(tokensAfterTax);
TokenUtils.burnTokens(_graphToken, tax); // Burn tax if any
return tax;
}
Expand Down

0 comments on commit f9af7eb

Please sign in to comment.