From 5998e9bd02a68ec3532438e6f3d69c05210a7df4 Mon Sep 17 00:00:00 2001 From: Michalis Kargakis Date: Mon, 10 Jun 2024 11:27:39 +0200 Subject: [PATCH 1/5] chore(sol): remove redundant require statements Already checked by _calculateFee. --- src/FeeCalculator.sol | 4 ---- src/FlatFeeCalculator.sol | 4 ---- test/FeeCalculator/AbstractFeeCalculator.t.sol | 2 +- .../AbstractFeeCalculatorLaunchParams.t.sol | 2 +- 4 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/FeeCalculator.sol b/src/FeeCalculator.sol index 1972606..95468b9 100644 --- a/src/FeeCalculator.sol +++ b/src/FeeCalculator.sol @@ -169,8 +169,6 @@ contract FeeCalculator is IFeeCalculator, Ownable { override returns (FeeDistribution memory feeDistribution) { - require(depositAmount > 0, "depositAmount must be > 0"); - feeDistribution = _calculateFee(depositAmount, IPool(pool).totalPerProjectSupply(tco2), _getTotalSupply(pool), _getDepositFee); } @@ -233,8 +231,6 @@ contract FeeCalculator is IFeeCalculator, Ownable { override returns (FeeDistribution memory feeDistribution) { - require(depositAmount > 0, "depositAmount must be > 0"); - feeDistribution = _calculateFee( depositAmount, IPool(pool).totalPerProjectSupply(erc1155, tokenId), _getTotalSupply(pool), _getDepositFee ); diff --git a/src/FlatFeeCalculator.sol b/src/FlatFeeCalculator.sol index 6679dd0..0e68f73 100644 --- a/src/FlatFeeCalculator.sol +++ b/src/FlatFeeCalculator.sol @@ -79,8 +79,6 @@ contract FlatFeeCalculator is IFeeCalculator, Ownable { override returns (FeeDistribution memory feeDistribution) { - require(depositAmount > 0, "depositAmount must be > 0"); - feeDistribution = _calculateFee(depositAmount); } @@ -135,8 +133,6 @@ contract FlatFeeCalculator is IFeeCalculator, Ownable { override returns (FeeDistribution memory feeDistribution) { - require(depositAmount > 0, "depositAmount must be > 0"); - feeDistribution = _calculateFee(depositAmount); } diff --git a/test/FeeCalculator/AbstractFeeCalculator.t.sol b/test/FeeCalculator/AbstractFeeCalculator.t.sol index 96d6a84..53f55de 100644 --- a/test/FeeCalculator/AbstractFeeCalculator.t.sol +++ b/test/FeeCalculator/AbstractFeeCalculator.t.sol @@ -451,7 +451,7 @@ abstract contract AbstractFeeCalculatorTest is Test { setProjectSupply(address(mockToken), 500 * 1e18); // Act - vm.expectRevert("depositAmount must be > 0"); + vm.expectRevert("requested amount must be > 0"); calculateDepositFees(address(mockPool), address(mockToken), depositAmount); } diff --git a/test/FeeCalculatorLaunchParams/AbstractFeeCalculatorLaunchParams.t.sol b/test/FeeCalculatorLaunchParams/AbstractFeeCalculatorLaunchParams.t.sol index 5e4bc44..6215b02 100644 --- a/test/FeeCalculatorLaunchParams/AbstractFeeCalculatorLaunchParams.t.sol +++ b/test/FeeCalculatorLaunchParams/AbstractFeeCalculatorLaunchParams.t.sol @@ -349,7 +349,7 @@ abstract contract AbstractFeeCalculatorLaunchParamsTest is Test { setProjectSupply(address(mockToken), 500 * 1e18); // Act - vm.expectRevert("depositAmount must be > 0"); + vm.expectRevert("requested amount must be > 0"); calculateDepositFees(address(mockPool), address(mockToken), depositAmount); } From ab49e643a9a78f3034f8aa97c69f361fd0c134c6 Mon Sep 17 00:00:00 2001 From: Michalis Kargakis Date: Mon, 10 Jun 2024 11:29:22 +0200 Subject: [PATCH 2/5] chore(sol): fix typo --- src/FeeCalculator.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/FeeCalculator.sol b/src/FeeCalculator.sol index 95468b9..47723c8 100644 --- a/src/FeeCalculator.sol +++ b/src/FeeCalculator.sol @@ -178,11 +178,11 @@ contract FeeCalculator is IFeeCalculator, Ownable { /// @return feeDistribution The recipients and the amount of fees each /// recipient should receive. function calculateFeeShares(uint256 totalFee) internal view returns (FeeDistribution memory feeDistribution) { - uint256 recipientsLenght = _recipients.length; - uint256[] memory shares = new uint256[](recipientsLenght); + uint256 recipientsLength = _recipients.length; + uint256[] memory shares = new uint256[](recipientsLength); uint256 restFee = totalFee; - for (uint256 i = 0; i < recipientsLenght; i++) { + for (uint256 i = 0; i < recipientsLength; i++) { shares[i] = (totalFee * _shares[i]) / 100; restFee -= shares[i]; } From 8ba0aa4699e1343f8f78010ef13047f533638d5f Mon Sep 17 00:00:00 2001 From: Michalis Kargakis Date: Mon, 10 Jun 2024 11:31:32 +0200 Subject: [PATCH 3/5] chore(sol): update security emails in contract headers --- src/FeeCalculator.sol | 2 +- src/FlatFeeCalculator.sol | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/FeeCalculator.sol b/src/FeeCalculator.sol index 47723c8..5cf86e7 100644 --- a/src/FeeCalculator.sol +++ b/src/FeeCalculator.sol @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: UNLICENSED -// If you encounter a vulnerability or an issue, please contact +// If you encounter a vulnerability or an issue, please contact or visit security.toucan.earth pragma solidity 0.8.19; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; diff --git a/src/FlatFeeCalculator.sol b/src/FlatFeeCalculator.sol index 0e68f73..e444b83 100644 --- a/src/FlatFeeCalculator.sol +++ b/src/FlatFeeCalculator.sol @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: UNLICENSED -// If you encounter a vulnerability or an issue, please contact +// If you encounter a vulnerability or an issue, please contact or visit security.toucan.earth pragma solidity 0.8.19; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; From d433852639a33612226bafe98cea3271dccc3ac2 Mon Sep 17 00:00:00 2001 From: Michalis Kargakis Date: Mon, 10 Jun 2024 11:55:05 +0200 Subject: [PATCH 4/5] chore(sol): bump versions --- src/FeeCalculator.sol | 2 +- src/FlatFeeCalculator.sol | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/FeeCalculator.sol b/src/FeeCalculator.sol index 5cf86e7..3eb4bbc 100644 --- a/src/FeeCalculator.sol +++ b/src/FeeCalculator.sol @@ -20,7 +20,7 @@ contract FeeCalculator is IFeeCalculator, Ownable { /// @dev Version-related parameters. VERSION keeps track of production /// releases. VERSION_RELEASE_CANDIDATE keeps track of iterations /// of a VERSION in our staging environment. - string public constant VERSION = "1.0.0"; + string public constant VERSION = "1.1.0"; uint256 public constant VERSION_RELEASE_CANDIDATE = 1; SD59x18 private _zero = sd(0); diff --git a/src/FlatFeeCalculator.sol b/src/FlatFeeCalculator.sol index e444b83..4a30f5c 100644 --- a/src/FlatFeeCalculator.sol +++ b/src/FlatFeeCalculator.sol @@ -20,7 +20,7 @@ contract FlatFeeCalculator is IFeeCalculator, Ownable { /// releases. VERSION_RELEASE_CANDIDATE keeps track of iterations /// of a VERSION in our staging environment. string public constant VERSION = "1.0.0"; - uint256 public constant VERSION_RELEASE_CANDIDATE = 1; + uint256 public constant VERSION_RELEASE_CANDIDATE = 2; uint256 public feeBasisPoints = 300; From d1409bdc268353f0779a8fc3e98ea4a5f4e33904 Mon Sep 17 00:00:00 2001 From: Michalis Kargakis Date: Mon, 10 Jun 2024 12:13:13 +0200 Subject: [PATCH 5/5] perf(sol): optimize zero amount checks --- src/FeeCalculator.sol | 4 ++-- src/FlatFeeCalculator.sol | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/FeeCalculator.sol b/src/FeeCalculator.sol index 3eb4bbc..9768a61 100644 --- a/src/FeeCalculator.sol +++ b/src/FeeCalculator.sol @@ -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); } diff --git a/src/FlatFeeCalculator.sol b/src/FlatFeeCalculator.sol index 4a30f5c..04f8b36 100644 --- a/src/FlatFeeCalculator.sol +++ b/src/FlatFeeCalculator.sol @@ -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; } @@ -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); }