@@ -3,6 +3,7 @@ pragma solidity =0.8.19;
3
3
pragma abicoder v2;
4
4
5
5
import "solmate/tokens/ERC20.sol " ;
6
+ import "solmate/utils/SafeTransferLib.sol " ;
6
7
import "v2-core/interfaces/IUniswapV2Pair.sol " ;
7
8
import "./lib/UniswapV2Library.sol " ;
8
9
@@ -13,6 +14,8 @@ struct TokenFees {
13
14
14
15
/// @notice Detects the buy and sell fee for a fee-on-transfer token
15
16
contract FeeOnTransferDetector {
17
+ using SafeTransferLib for ERC20 ;
18
+
16
19
error SameToken ();
17
20
error PairLookupFailed ();
18
21
@@ -98,7 +101,7 @@ contract FeeOnTransferDetector {
98
101
uint256 buyFeeBps = (amountRequestedToBorrow - amountBorrowed) * BPS / amountRequestedToBorrow;
99
102
balanceBeforeLoan = tokenBorrowed.balanceOf (address (pair));
100
103
uint256 sellFeeBps;
101
- try tokenBorrowed. transfer ( address (pair), amountBorrowed) {
104
+ try this . callTransfer (tokenBorrowed, address (pair), amountBorrowed) {
102
105
uint256 sellFee = amountBorrowed - (tokenBorrowed.balanceOf (address (pair)) - balanceBeforeLoan);
103
106
sellFeeBps = sellFee * BPS / amountBorrowed;
104
107
} catch (bytes memory ) {
@@ -112,4 +115,10 @@ contract FeeOnTransferDetector {
112
115
revert (add (32 , fees), mload (fees))
113
116
}
114
117
}
118
+
119
+ // external wrapper around safeTransfer
120
+ // because try/catch does not handle calling libraries
121
+ function callTransfer (ERC20 token , address to , uint256 amount ) external {
122
+ token.safeTransfer (to, amount);
123
+ }
115
124
}
0 commit comments