Skip to content

Commit 2097abe

Browse files
committed
Revert "Revert "[LILA-7980] Do not throw on zero fee returned""
1 parent b1b1249 commit 2097abe

11 files changed

+74
-73
lines changed

src/FeeCalculator.sol

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ contract FeeCalculator is IFeeCalculator, Ownable {
2020
/// @dev Version-related parameters. VERSION keeps track of production
2121
/// releases. VERSION_RELEASE_CANDIDATE keeps track of iterations
2222
/// of a VERSION in our staging environment.
23-
string public constant VERSION = "1.1.0";
23+
string public constant VERSION = "1.2.0";
2424
uint256 public constant VERSION_RELEASE_CANDIDATE = 1;
2525

2626
SD59x18 private _zero = sd(0);
@@ -406,7 +406,9 @@ contract FeeCalculator is IFeeCalculator, Ownable {
406406
uint256 feeAmount = calculator(requestedAmount, projectSupply, totalPoolSupply);
407407

408408
require(feeAmount <= requestedAmount, "Fee must be lower or equal to requested amount");
409-
require(feeAmount != 0, "Fee must be greater than 0");
409+
if (feeAmount == 0) {
410+
return FeeDistribution(new address[](0), new uint256[](0));
411+
}
410412

411413
return calculateFeeShares(feeAmount);
412414
}

src/FlatFeeCalculator.sol

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ contract FlatFeeCalculator is IFeeCalculator, Ownable {
1919
/// @dev Version-related parameters. VERSION keeps track of production
2020
/// releases. VERSION_RELEASE_CANDIDATE keeps track of iterations
2121
/// of a VERSION in our staging environment.
22-
string public constant VERSION = "1.0.0";
22+
string public constant VERSION = "1.1.0";
2323
uint256 public constant VERSION_RELEASE_CANDIDATE = 2;
2424

2525
uint256 public feeBasisPoints = 300;
@@ -158,7 +158,9 @@ contract FlatFeeCalculator is IFeeCalculator, Ownable {
158158
require(requestedAmount != 0, "requested amount must be > 0");
159159

160160
uint256 feeAmount = requestedAmount * feeBasisPoints / 10000;
161-
require(feeAmount != 0, "Fee must be greater than 0");
161+
if (feeAmount == 0) {
162+
return FeeDistribution(new address[](0), new uint256[](0));
163+
}
162164

163165
return calculateFeeShares(feeAmount);
164166
}

test/FeeCalculator/AbstractFeeCalculator.t.sol

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ abstract contract AbstractFeeCalculatorTest is Test {
254254
assertEq(fees[0], 46413457506542766270);
255255
}
256256

257-
function testCalculateDepositFees_DepositOfOneWei_ShouldThrowException() public {
257+
function testCalculateDepositFees_DepositOfOneWei_ShouldNotThrowException() public {
258258
// Arrange
259259
// Set up your test data
260260
uint256 depositAmount = 1;
@@ -264,11 +264,13 @@ abstract contract AbstractFeeCalculatorTest is Test {
264264
setProjectSupply(address(mockToken), 1e4 * 1e18);
265265

266266
// Act
267-
vm.expectRevert("Fee must be greater than 0");
268-
calculateDepositFees(address(mockPool), address(mockToken), depositAmount);
267+
FeeDistribution memory feeDistribution =
268+
calculateDepositFees(address(mockPool), address(mockToken), depositAmount);
269+
assertEq(feeDistribution.recipients.length, 0);
270+
assertEq(feeDistribution.shares.length, 0);
269271
}
270272

271-
function testCalculateDepositFees_DepositOfHundredWei_ShouldThrowError() public {
273+
function testCalculateDepositFees_DepositOfHundredWei_ShouldNotThrowError() public {
272274
//Note! This is a bug, where a very small deposit to a very large pool
273275
//causes a == b because of precision limited by ratioDenominator in FeeCalculator
274276

@@ -281,8 +283,10 @@ abstract contract AbstractFeeCalculatorTest is Test {
281283
setProjectSupply(address(mockToken), 1e4 * 1e18);
282284

283285
// Act
284-
vm.expectRevert("Fee must be greater than 0");
285-
calculateDepositFees(address(mockPool), address(mockToken), depositAmount);
286+
FeeDistribution memory feeDistribution =
287+
calculateDepositFees(address(mockPool), address(mockToken), depositAmount);
288+
assertEq(feeDistribution.recipients.length, 0);
289+
assertEq(feeDistribution.shares.length, 0);
286290
}
287291

288292
function testCalculateDepositFees_DepositOfHundredThousandsPartOfOne_NonzeroFee() public {

test/FeeCalculatorFuzzy/AbstractFeeCalculator.fuzzy.t.sol

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ abstract contract AbstractFeeCalculatorTestFuzzy is Test {
5050
uint256 total
5151
) public virtual;
5252

53-
function testCalculateDepositFees_FuzzyExtremelySmallDepositsToLargePool_ShouldThrowError(uint256 depositAmount)
53+
function testCalculateDepositFees_FuzzyExtremelySmallDepositsToLargePool_ShouldNotThrowError(uint256 depositAmount)
5454
public
5555
{
5656
vm.assume(depositAmount <= 1e-14 * 1e18);
@@ -66,8 +66,10 @@ abstract contract AbstractFeeCalculatorTestFuzzy is Test {
6666
mockPool.setTotalSupply(1e12 * 1e18);
6767
setProjectSupply(address(mockToken), 1e9 * 1e18);
6868

69-
vm.expectRevert("Fee must be greater than 0");
70-
calculateDepositFees(address(mockPool), address(mockToken), depositAmount);
69+
FeeDistribution memory feeDistribution =
70+
calculateDepositFees(address(mockPool), address(mockToken), depositAmount);
71+
assertEq(feeDistribution.recipients.length, 0);
72+
assertEq(feeDistribution.shares.length, 0);
7173
}
7274

7375
function testCalculateRedemptionFeesFuzzy_RedemptionDividedIntoOneChunkFeesGreaterOrEqualToOneRedemption(

test/FeeCalculatorFuzzy/FeeCalculatorERC1155.fuzzy.t.sol

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ contract FeeCalculatorERC1155TestFuzzy is AbstractFeeCalculatorTestFuzzy {
4343
try feeCalculator.calculateDepositFees(address(mockPool), address(mockToken), 1, depositAmount) {}
4444
catch Error(string memory reason) {
4545
assertTrue(
46-
keccak256(bytes("Fee must be greater than 0")) == keccak256(bytes(reason))
47-
|| keccak256(bytes("Fee must be lower or equal to requested amount")) == keccak256(bytes(reason)),
48-
"error should be 'Fee must be greater than 0' or 'Fee must be lower or equal to requested amount'"
46+
keccak256(bytes("Fee must be lower or equal to requested amount")) == keccak256(bytes(reason)),
47+
"error should be 'Fee must be lower or equal to requested amount'"
4948
);
5049
}
5150
}
@@ -116,9 +115,8 @@ contract FeeCalculatorERC1155TestFuzzy is AbstractFeeCalculatorTestFuzzy {
116115
} catch Error(string memory reason) {
117116
args.oneTimeRedemptionFailed = true;
118117
assertTrue(
119-
keccak256(bytes("Fee must be greater than 0")) == keccak256(bytes(reason))
120-
|| keccak256(bytes("Fee must be lower or equal to requested amount")) == keccak256(bytes(reason)),
121-
"error should be 'Fee must be greater than 0' or 'Fee must be lower or equal to requested amount'"
118+
keccak256(bytes("Fee must be lower or equal to requested amount")) == keccak256(bytes(reason)),
119+
"error should be 'Fee must be lower or equal to requested amount'"
122120
);
123121
}
124122

@@ -147,9 +145,8 @@ contract FeeCalculatorERC1155TestFuzzy is AbstractFeeCalculatorTestFuzzy {
147145
} catch Error(string memory reason) {
148146
args.multipleTimesRedemptionFailedCount++;
149147
assertTrue(
150-
keccak256(bytes("Fee must be greater than 0")) == keccak256(bytes(reason))
151-
|| keccak256(bytes("Fee must be lower or equal to requested amount")) == keccak256(bytes(reason)),
152-
"error should be 'Fee must be greater than 0' or 'Fee must be lower or equal to requested amount'"
148+
keccak256(bytes("Fee must be lower or equal to requested amount")) == keccak256(bytes(reason)),
149+
"error should be 'Fee must be lower or equal to requested amount'"
153150
);
154151
}
155152
}
@@ -190,9 +187,8 @@ contract FeeCalculatorERC1155TestFuzzy is AbstractFeeCalculatorTestFuzzy {
190187
} catch Error(string memory reason) {
191188
oneTimeDepositFailed = true;
192189
assertTrue(
193-
keccak256(bytes("Fee must be greater than 0")) == keccak256(bytes(reason))
194-
|| keccak256(bytes("Fee must be lower or equal to requested amount")) == keccak256(bytes(reason)),
195-
"error should be 'Fee must be greater than 0' or 'Fee must be lower or equal to requested amount'"
190+
keccak256(bytes("Fee must be lower or equal to requested amount")) == keccak256(bytes(reason)),
191+
"error should be 'Fee must be lower or equal to requested amount'"
196192
);
197193
}
198194

@@ -214,9 +210,8 @@ contract FeeCalculatorERC1155TestFuzzy is AbstractFeeCalculatorTestFuzzy {
214210
} catch Error(string memory reason) {
215211
multipleTimesDepositFailedCount++;
216212
assertTrue(
217-
keccak256(bytes("Fee must be greater than 0")) == keccak256(bytes(reason))
218-
|| keccak256(bytes("Fee must be lower or equal to requested amount")) == keccak256(bytes(reason)),
219-
"error should be 'Fee must be greater than 0' or 'Fee must be lower or equal to requested amount'"
213+
keccak256(bytes("Fee must be lower or equal to requested amount")) == keccak256(bytes(reason)),
214+
"error should be 'Fee must be lower or equal to requested amount'"
220215
);
221216
}
222217
}

test/FeeCalculatorFuzzy/FeeCalculatorTCO2.fuzzy.t.sol

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ contract FeeCalculatorTCO2TestFuzzy is AbstractFeeCalculatorTestFuzzy {
4040
try feeCalculator.calculateDepositFees(address(mockPool), address(mockToken), depositAmount) {}
4141
catch Error(string memory reason) {
4242
assertTrue(
43-
keccak256(bytes("Fee must be greater than 0")) == keccak256(bytes(reason))
44-
|| keccak256(bytes("Fee must be lower or equal to requested amount")) == keccak256(bytes(reason)),
45-
"error should be 'Fee must be greater than 0' or 'Fee must be lower or equal to requested amount'"
43+
keccak256(bytes("Fee must be lower or equal to requested amount")) == keccak256(bytes(reason)),
44+
"error should be 'Fee must be lower or equal to requested amount'"
4645
);
4746
}
4847
}
@@ -111,9 +110,8 @@ contract FeeCalculatorTCO2TestFuzzy is AbstractFeeCalculatorTestFuzzy {
111110
} catch Error(string memory reason) {
112111
args.oneTimeRedemptionFailed = true;
113112
assertTrue(
114-
keccak256(bytes("Fee must be greater than 0")) == keccak256(bytes(reason))
115-
|| keccak256(bytes("Fee must be lower or equal to requested amount")) == keccak256(bytes(reason)),
116-
"error should be 'Fee must be greater than 0' or 'Fee must be lower or equal to requested amount'"
113+
keccak256(bytes("Fee must be lower or equal to requested amount")) == keccak256(bytes(reason)),
114+
"error should be 'Fee must be lower or equal to requested amount'"
117115
);
118116
}
119117

@@ -142,9 +140,8 @@ contract FeeCalculatorTCO2TestFuzzy is AbstractFeeCalculatorTestFuzzy {
142140
} catch Error(string memory reason) {
143141
args.multipleTimesRedemptionFailedCount++;
144142
assertTrue(
145-
keccak256(bytes("Fee must be greater than 0")) == keccak256(bytes(reason))
146-
|| keccak256(bytes("Fee must be lower or equal to requested amount")) == keccak256(bytes(reason)),
147-
"error should be 'Fee must be greater than 0' or 'Fee must be lower or equal to requested amount'"
143+
keccak256(bytes("Fee must be lower or equal to requested amount")) == keccak256(bytes(reason)),
144+
"error should be 'Fee must be lower or equal to requested amount'"
148145
);
149146
}
150147
}
@@ -185,9 +182,8 @@ contract FeeCalculatorTCO2TestFuzzy is AbstractFeeCalculatorTestFuzzy {
185182
} catch Error(string memory reason) {
186183
oneTimeDepositFailed = true;
187184
assertTrue(
188-
keccak256(bytes("Fee must be greater than 0")) == keccak256(bytes(reason))
189-
|| keccak256(bytes("Fee must be lower or equal to requested amount")) == keccak256(bytes(reason)),
190-
"error should be 'Fee must be greater than 0' or 'Fee must be lower or equal to requested amount'"
185+
keccak256(bytes("Fee must be lower or equal to requested amount")) == keccak256(bytes(reason)),
186+
"error should be 'Fee must be lower or equal to requested amount'"
191187
);
192188
}
193189

@@ -209,9 +205,8 @@ contract FeeCalculatorTCO2TestFuzzy is AbstractFeeCalculatorTestFuzzy {
209205
} catch Error(string memory reason) {
210206
multipleTimesDepositFailedCount++;
211207
assertTrue(
212-
keccak256(bytes("Fee must be greater than 0")) == keccak256(bytes(reason))
213-
|| keccak256(bytes("Fee must be lower or equal to requested amount")) == keccak256(bytes(reason)),
214-
"error should be 'Fee must be greater than 0' or 'Fee must be lower or equal to requested amount'"
208+
keccak256(bytes("Fee must be lower or equal to requested amount")) == keccak256(bytes(reason)),
209+
"error should be 'Fee must be lower or equal to requested amount'"
215210
);
216211
}
217212
}

test/FeeCalculatorLaunchParams/AbstractFeeCalculatorLaunchParams.t.sol

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ abstract contract AbstractFeeCalculatorLaunchParamsTest is Test {
147147
assertEq(fees[0], 53013879215838797358);
148148
}
149149

150-
function testCalculateDepositFees_DepositOfOneWei_ShouldThrowException() public {
150+
function testCalculateDepositFees_DepositOfOneWei_ShouldNotThrowException() public {
151151
// Arrange
152152
// Set up your test data
153153
uint256 depositAmount = 1;
@@ -157,11 +157,13 @@ abstract contract AbstractFeeCalculatorLaunchParamsTest is Test {
157157
setProjectSupply(address(mockToken), 1e4 * 1e18);
158158

159159
// Act
160-
vm.expectRevert("Fee must be greater than 0");
161-
calculateDepositFees(address(mockPool), address(mockToken), depositAmount);
160+
FeeDistribution memory feeDistribution =
161+
calculateDepositFees(address(mockPool), address(mockToken), depositAmount);
162+
assertEq(feeDistribution.recipients.length, 0);
163+
assertEq(feeDistribution.shares.length, 0);
162164
}
163165

164-
function testCalculateDepositFees_DepositOfHundredWei_ShouldThrowError() public {
166+
function testCalculateDepositFees_DepositOfHundredWei_ShouldNotThrowError() public {
165167
//Note! This is a bug, where a very small deposit to a very large pool
166168
//causes a == b because of precision limited by ratioDenominator in FeeCalculator
167169

@@ -174,8 +176,10 @@ abstract contract AbstractFeeCalculatorLaunchParamsTest is Test {
174176
setProjectSupply(address(mockToken), 1e4 * 1e18);
175177

176178
// Act
177-
vm.expectRevert("Fee must be greater than 0");
178-
calculateDepositFees(address(mockPool), address(mockToken), depositAmount);
179+
FeeDistribution memory feeDistribution =
180+
calculateDepositFees(address(mockPool), address(mockToken), depositAmount);
181+
assertEq(feeDistribution.recipients.length, 0);
182+
assertEq(feeDistribution.shares.length, 0);
179183
}
180184

181185
function testCalculateDepositFees_DepositOfHundredThousandsPartOfOne_NonzeroFee() public {

test/FeeCalculatorLaunchParamsFuzzy/AbstractFeeCalculatorLaunchParams.fuzzy.t.sol

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ abstract contract AbstractFeeCalculatorLaunchParamsTestFuzzy is Test {
4747
uint256 total
4848
) public virtual;
4949

50-
function testCalculateDepositFees_FuzzyExtremelySmallDepositsToLargePool_ShouldThrowError(uint256 depositAmount)
50+
function testCalculateDepositFees_FuzzyExtremelySmallDepositsToLargePool_ShouldNotThrowError(uint256 depositAmount)
5151
public
5252
{
5353
vm.assume(depositAmount <= 1e-14 * 1e18);
@@ -63,8 +63,10 @@ abstract contract AbstractFeeCalculatorLaunchParamsTestFuzzy is Test {
6363
mockPool.setTotalSupply(1e12 * 1e18);
6464
setProjectSupply(address(mockToken), 1e9 * 1e18);
6565

66-
vm.expectRevert("Fee must be greater than 0");
67-
calculateDepositFees(address(mockPool), address(mockToken), depositAmount);
66+
FeeDistribution memory feeDistribution =
67+
calculateDepositFees(address(mockPool), address(mockToken), depositAmount);
68+
assertEq(feeDistribution.recipients.length, 0);
69+
assertEq(feeDistribution.shares.length, 0);
6870
}
6971

7072
function testCalculateDepositFeesFuzzy_DepositDividedIntoOneChunkFeesGreaterOrEqualToOneDeposit(

test/FeeCalculatorLaunchParamsFuzzy/FeeCalculatorLaunchParamsERC1155.fuzzy.t.sol

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,9 @@ contract FeeCalculatorLaunchParamsERC1155TestFuzzy is AbstractFeeCalculatorLaunc
4040
try feeCalculator.calculateDepositFees(address(mockPool), address(mockToken), 1, depositAmount) {}
4141
catch Error(string memory reason) {
4242
assertTrue(
43-
keccak256(bytes("Fee must be greater than 0")) == keccak256(bytes(reason))
44-
|| keccak256(bytes("Fee must be lower or equal to requested amount")) == keccak256(bytes(reason))
43+
keccak256(bytes("Fee must be lower or equal to requested amount")) == keccak256(bytes(reason))
4544
|| keccak256(bytes("Deposit outside range")) == keccak256(bytes(reason)),
46-
"error should be 'Fee must be greater than 0' or 'Fee must be lower or equal to requested amount' or 'Deposit outside range'"
45+
"error should be 'Fee must be lower or equal to requested amount' or 'Deposit outside range'"
4746
);
4847
}
4948
}
@@ -80,10 +79,9 @@ contract FeeCalculatorLaunchParamsERC1155TestFuzzy is AbstractFeeCalculatorLaunc
8079
} catch Error(string memory reason) {
8180
oneTimeDepositFailed = true;
8281
assertTrue(
83-
keccak256(bytes("Fee must be greater than 0")) == keccak256(bytes(reason))
84-
|| keccak256(bytes("Fee must be lower or equal to requested amount")) == keccak256(bytes(reason))
82+
keccak256(bytes("Fee must be lower or equal to requested amount")) == keccak256(bytes(reason))
8583
|| keccak256(bytes("Deposit outside range")) == keccak256(bytes(reason)),
86-
"error should be 'Fee must be greater than 0' or 'Fee must be lower or equal to requested amount' or 'Deposit outside range'"
84+
"error should be 'Fee must be lower or equal to requested amount' or 'Deposit outside range'"
8785
);
8886
}
8987

@@ -105,10 +103,9 @@ contract FeeCalculatorLaunchParamsERC1155TestFuzzy is AbstractFeeCalculatorLaunc
105103
} catch Error(string memory reason) {
106104
multipleTimesDepositFailedCount++;
107105
assertTrue(
108-
keccak256(bytes("Fee must be greater than 0")) == keccak256(bytes(reason))
109-
|| keccak256(bytes("Fee must be lower or equal to requested amount")) == keccak256(bytes(reason))
106+
keccak256(bytes("Fee must be lower or equal to requested amount")) == keccak256(bytes(reason))
110107
|| keccak256(bytes("Deposit outside range")) == keccak256(bytes(reason)),
111-
"error should be 'Fee must be greater than 0' or 'Fee must be lower or equal to requested amount' or 'Deposit outside range'"
108+
"error should be 'Fee must be lower or equal to requested amount' or 'Deposit outside range'"
112109
);
113110
}
114111
}

0 commit comments

Comments
 (0)