Skip to content

Commit

Permalink
Merge pull request #56 from 0xmichalis/audit-review
Browse files Browse the repository at this point in the history
[LILA-6854] Address Team Omega comments, update emails and versions
  • Loading branch information
0xmichalis authored Jun 10, 2024
2 parents 4857231 + d1409bd commit 028495a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 22 deletions.
18 changes: 7 additions & 11 deletions src/FeeCalculator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: UNLICENSED

// If you encounter a vulnerability or an issue, please contact <info@neutralx.com>
// If you encounter a vulnerability or an issue, please contact <security@toucan.earth> or visit security.toucan.earth
pragma solidity 0.8.19;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
Expand All @@ -180,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];
}
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -405,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
14 changes: 5 additions & 9 deletions src/FlatFeeCalculator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: UNLICENSED

// If you encounter a vulnerability or an issue, please contact <info@neutralx.com>
// If you encounter a vulnerability or an issue, please contact <security@toucan.earth> or visit security.toucan.earth
pragma solidity 0.8.19;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
Expand All @@ -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;

Expand All @@ -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 @@ -79,8 +79,6 @@ contract FlatFeeCalculator is IFeeCalculator, Ownable {
override
returns (FeeDistribution memory feeDistribution)
{
require(depositAmount > 0, "depositAmount must be > 0");

feeDistribution = _calculateFee(depositAmount);
}

Expand Down Expand Up @@ -135,8 +133,6 @@ contract FlatFeeCalculator is IFeeCalculator, Ownable {
override
returns (FeeDistribution memory feeDistribution)
{
require(depositAmount > 0, "depositAmount must be > 0");

feeDistribution = _calculateFee(depositAmount);
}

Expand Down Expand Up @@ -171,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
2 changes: 1 addition & 1 deletion test/FeeCalculator/AbstractFeeCalculator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 028495a

Please sign in to comment.