Skip to content

Commit

Permalink
Merge pull request #25 from Sean329/main
Browse files Browse the repository at this point in the history
Fixed a potential mistake in the fee calculation with round up
  • Loading branch information
merklejerk authored Nov 21, 2023
2 parents 923763f + 178fa9f commit f2a68ea
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion patterns/flash-loans/FlashLoanPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ contract FlashLoanPool {
uint256 balanceBefore = token.balanceOf(address(this));
require(balanceBefore >= borrowAmount, 'too much');
// Compute the fee, rounded up.
uint256 fee = FEE_BPS * (borrowAmount + 1e4-1) / 1e4;
uint256 fee = (FEE_BPS * borrowAmount + 1e4-1) / 1e4;
// Transfer tokens to the borrower contract.
token.transfer(address(borrower), borrowAmount);
// Let the borrower do its thing.
Expand Down
2 changes: 1 addition & 1 deletion patterns/flash-loans/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function flashLoan(
uint256 balanceBefore = token.balanceOf(address(this));
require(balanceBefore >= borrowAmount, 'too much');
// Compute the fee, rounded up.
uint256 fee = FEE_BPS * (borrowAmount + 1e4-1) / 1e4;
uint256 fee = (FEE_BPS * borrowAmount + 1e4-1) / 1e4;
// Transfer tokens to the borrower contract.
token.transfer(address(borrower), borrowAmount);
// Let the borrower do its thing.
Expand Down
2 changes: 1 addition & 1 deletion test/FlashLoanPool.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ contract FlashLoanPoolTest is TestUtils, FlashLoanValidator {
}

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

function test_canWithdraw() external {
Expand Down

0 comments on commit f2a68ea

Please sign in to comment.