Skip to content

Commit

Permalink
perf(sol): optimize zero amount checks
Browse files Browse the repository at this point in the history
  • Loading branch information
0xmichalis committed Jun 10, 2024
1 parent d433852 commit d1409bd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/FeeCalculator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -401,12 +401,12 @@ contract FeeCalculator is IFeeCalculator, Ownable {
uint256 totalPoolSupply,
function(uint256, uint256, uint256) view returns (uint256) calculator
) internal view returns (FeeDistribution memory) {
require(requestedAmount > 0, "requested amount must be > 0");
require(requestedAmount != 0, "requested amount must be > 0");

uint256 feeAmount = calculator(requestedAmount, projectSupply, totalPoolSupply);

require(feeAmount <= requestedAmount, "Fee must be lower or equal to requested amount");
require(feeAmount > 0, "Fee must be greater than 0");
require(feeAmount != 0, "Fee must be greater than 0");

return calculateFeeShares(feeAmount);
}
Expand Down
6 changes: 3 additions & 3 deletions src/FlatFeeCalculator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ contract FlatFeeCalculator is IFeeCalculator, Ownable {
constructor() Ownable() {}

function setFeeToUnderlyingDecimalsScale(uint256 _feeToUnderlyingDecimalsScale) external onlyOwner {
require(_feeToUnderlyingDecimalsScale > 0, "Fee to underlying decimals scale must be greater than 0");
require(_feeToUnderlyingDecimalsScale != 0, "Fee to underlying decimals scale must be greater than 0");

feeToUnderlyingDecimalsScale = _feeToUnderlyingDecimalsScale;
}
Expand Down Expand Up @@ -167,13 +167,13 @@ contract FlatFeeCalculator is IFeeCalculator, Ownable {
/// @param requestedAmount The amount to be used for the fee calculation.
/// @return feeDistribution How the fee is meant to be
function _calculateFee(uint256 requestedAmount) internal view returns (FeeDistribution memory) {
require(requestedAmount > 0, "requested amount must be > 0");
require(requestedAmount != 0, "requested amount must be > 0");

uint256 adjustedAmount = requestedAmount * feeToUnderlyingDecimalsScale;
uint256 feeAmount = adjustedAmount * feeBasisPoints / 10000;

require(feeAmount <= adjustedAmount, "Fee must be lower or equal to requested amount");
require(feeAmount > 0, "Fee must be greater than 0");
require(feeAmount != 0, "Fee must be greater than 0");

return calculateFeeShares(feeAmount);
}
Expand Down

0 comments on commit d1409bd

Please sign in to comment.