Skip to content

Commit f2a68ea

Browse files
authored
Merge pull request #25 from Sean329/main
Fixed a potential mistake in the fee calculation with round up
2 parents 923763f + 178fa9f commit f2a68ea

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

patterns/flash-loans/FlashLoanPool.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ contract FlashLoanPool {
4848
uint256 balanceBefore = token.balanceOf(address(this));
4949
require(balanceBefore >= borrowAmount, 'too much');
5050
// Compute the fee, rounded up.
51-
uint256 fee = FEE_BPS * (borrowAmount + 1e4-1) / 1e4;
51+
uint256 fee = (FEE_BPS * borrowAmount + 1e4-1) / 1e4;
5252
// Transfer tokens to the borrower contract.
5353
token.transfer(address(borrower), borrowAmount);
5454
// Let the borrower do its thing.

patterns/flash-loans/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function flashLoan(
7676
uint256 balanceBefore = token.balanceOf(address(this));
7777
require(balanceBefore >= borrowAmount, 'too much');
7878
// Compute the fee, rounded up.
79-
uint256 fee = FEE_BPS * (borrowAmount + 1e4-1) / 1e4;
79+
uint256 fee = (FEE_BPS * borrowAmount + 1e4-1) / 1e4;
8080
// Transfer tokens to the borrower contract.
8181
token.transfer(address(borrower), borrowAmount);
8282
// Let the borrower do its thing.

test/FlashLoanPool.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ contract FlashLoanPoolTest is TestUtils, FlashLoanValidator {
161161
}
162162

163163
function _getFee(uint256 amount) private view returns (uint256) {
164-
return pool.FEE_BPS() * (amount + 1e4-1) / 1e4;
164+
return (pool.FEE_BPS() * amount + 1e4-1) / 1e4;
165165
}
166166

167167
function test_canWithdraw() external {

0 commit comments

Comments
 (0)