@@ -5,62 +5,52 @@ import {Owned} from "solmate/auth/Owned.sol";
5
5
import {ERC20 } from "solmate/tokens/ERC20.sol " ;
6
6
import {SafeTransferLib} from "solmate/utils/SafeTransferLib.sol " ;
7
7
import {IFeeCollector} from "./interfaces/IFeeCollector.sol " ;
8
- import {IPermit2} from "./external/IPermit2.sol " ;
9
8
10
9
/// @notice The collector of protocol fees that will be used to swap and send to a fee recipient address.
11
10
contract FeeCollector is Owned , IFeeCollector {
12
11
using SafeTransferLib for ERC20 ;
13
12
14
- error UniversalRouterCallFailed ();
13
+ error CallFailed ();
15
14
16
- address private immutable universalRouter;
15
+ struct Call {
16
+ address to;
17
+ bytes data;
18
+ }
17
19
20
+ address public feeRecipient;
21
+ uin256 public feeTokenAmount;
18
22
ERC20 private immutable feeToken;
19
- IPermit2 private immutable permit2;
20
-
21
- uint256 private constant MAX_APPROVAL_AMOUNT = type (uint256 ).max;
22
- uint160 private constant MAX_PERMIT2_APPROVAL_AMOUNT = type (uint160 ).max;
23
- uint48 private constant MAX_PERMIT2_DEADLINE = type (uint48 ).max;
24
23
25
- constructor (address _owner , address _universalRouter , address _permit2 , address _feeToken ) Owned (_owner) {
26
- universalRouter = _universalRouter;
24
+ constructor (address _owner , address _feeToken , uint256 _feeTokenAmount ) Owned (_owner) {
27
25
feeToken = ERC20 (_feeToken);
28
- permit2 = IPermit2 (_permit2);
29
- }
30
-
31
- /// @inheritdoc IFeeCollector
32
- function swapBalance (bytes calldata swapData , uint256 nativeValue ) external onlyOwner {
33
- _execute (swapData, nativeValue);
26
+ feeTokenAmount = _feeTokenAmount;
34
27
}
35
28
36
- /// @inheritdoc IFeeCollector
37
- function swapBalance (bytes calldata swapData , uint256 nativeValue , ERC20 [] calldata tokensToApprove )
38
- external
39
- onlyOwner
40
- {
41
- unchecked {
42
- for (uint256 i = 0 ; i < tokensToApprove.length ; i++ ) {
43
- tokensToApprove[i].safeApprove (address (permit2), MAX_APPROVAL_AMOUNT);
44
- permit2.approve (
45
- address (tokensToApprove[i]), universalRouter, MAX_PERMIT2_APPROVAL_AMOUNT, MAX_PERMIT2_DEADLINE
46
- );
29
+ /// @notice allow anyone to make any arbitrary calls from this address
30
+ /// @dev as long as they pay `feeTokenAmount` to the `feeRecipient`
31
+ /// this creates a competitive auction as the balances of this contract increase
32
+ /// to find the optimal path for the swap
33
+ function swapBalances (Call[] calldata calls ) external {
34
+ for (uint256 i = 0 ; i < calls.length ; i++ ) {
35
+ (bool success , ) = calls[i].to.call (calls[i].data);
36
+ if (! success) {
37
+ revert CallFailed ();
47
38
}
48
39
}
49
40
50
- _execute (swapData, nativeValue);
41
+ feeToken.safeTransferFrom (msg .sender , feeRecipient, feeTokenAmount);
42
+ }
43
+
44
+ function setFeeRecipient (address _feeRecipient ) external onlyOwner {
45
+ feeRecipient = _feeRecipient;
51
46
}
52
47
53
- /// @notice Helper function to call UniversalRouter.
54
- /// @param swapData The bytes call data to be forwarded to UniversalRouter.
55
- /// @param nativeValue The amount of native currency to send to UniversalRouter.
56
- function _execute (bytes calldata swapData , uint256 nativeValue ) internal {
57
- (bool success ,) = universalRouter.call {value: nativeValue}(swapData);
58
- if (! success) revert UniversalRouterCallFailed ();
48
+ function setFeeToken (uint256 _feeTokenAmount ) external onlyOwner {
49
+ feeTokenAmount = _feeTokenAmount;
59
50
}
60
51
61
- /// @inheritdoc IFeeCollector
62
- function withdrawFeeToken (address feeRecipient , uint256 amount ) external onlyOwner {
63
- feeToken.safeTransfer (feeRecipient, amount);
52
+ function setFeeTokenAmount (uint256 _feeTokenAmount ) external onlyOwner {
53
+ feeTokenAmount = _feeTokenAmount;
64
54
}
65
55
66
56
receive () external payable {}
0 commit comments