Skip to content

Commit

Permalink
Ensure fee does not exceed fromAmount in swap contract
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrwitek committed Oct 16, 2024
1 parent 77f0636 commit 8c8b6b5
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/dma-contracts/contracts/swap/Swap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,17 @@ contract Swap {
uint256 fromAmount,
uint256 fee
) internal returns (uint256 amount) {
amount = fromAmount.sub(fee);

// if fee gt fromAmount, fee should eq fromAmount
if (fee > fromAmount) {
fee = fromAmount;
}

if (fee > 0) {
IERC20(asset).safeTransfer(feeBeneficiaryAddress, fee);
emit FeePaid(feeBeneficiaryAddress, fee, asset);
}

amount = fromAmount.sub(fee);
}

function _collectFee(
Expand Down

0 comments on commit 8c8b6b5

Please sign in to comment.