@@ -6,6 +6,7 @@ import {TypeCasts} from "../../libs/TypeCasts.sol";
66import  {GasRouter} from  "../../client/GasRouter.sol " ;
77import  {TokenMessage} from  "./TokenMessage.sol " ;
88import  {Quote, ITokenBridge, ITokenFee} from  "../../interfaces/ITokenBridge.sol " ;
9+ import  {Quotes} from  "./Quotes.sol " ;
910import  {StorageSlot} from  "@openzeppelin/contracts/utils/StorageSlot.sol " ;
1011
1112/** 
@@ -24,6 +25,7 @@ abstract contract TokenRouter is GasRouter, ITokenBridge {
2425    using TypeCasts   for  address ;
2526    using TokenMessage   for  bytes ;
2627    using StorageSlot   for  bytes32 ;
28+     using Quotes   for  Quote[];
2729
2830    /** 
2931     * @dev Emitted on `transferRemote` when a transfer message is dispatched. 
@@ -80,7 +82,7 @@ abstract contract TokenRouter is GasRouter, ITokenBridge {
8082    /** 
8183     * @inheritdoc ITokenFee 
8284     * @notice Implements the standardized fee quoting interface for token transfers based on 
83-      * overridable internal functions of _quoteGasPayment, _feeRecipientAmount , and _externalFeeAmount. 
85+      * overridable internal functions of _quoteGasPayment, _feeRecipientAndAmount , and _externalFeeAmount. 
8486     * @param _destination The identifier of the destination chain. 
8587     * @param _recipient The address of the recipient on the destination chain. 
8688     * @param _amount The amount or identifier of tokens to be sent to the remote recipient 
@@ -103,11 +105,12 @@ abstract contract TokenRouter is GasRouter, ITokenBridge {
103105            token: address (0 ),
104106            amount: _quoteGasPayment (_destination, _recipient, _amount)
105107        });
106-         quotes[1 ] =  Quote ({
107-             token: token (),
108-             amount: _amount + 
109-                 _feeRecipientAmount (_destination, _recipient, _amount)
110-         });
108+         (, uint256  feeAmount ) =  _feeRecipientAndAmount (
109+             _destination,
110+             _recipient,
111+             _amount
112+         );
113+         quotes[1 ] =  Quote ({token: token (), amount: _amount +  feeAmount});
111114        quotes[2 ] =  Quote ({
112115            token: token (),
113116            amount: _externalFeeAmount (_destination, _recipient, _amount)
@@ -175,18 +178,18 @@ abstract contract TokenRouter is GasRouter, ITokenBridge {
175178        uint256  _amount ,
176179        uint256  _msgValue 
177180    ) internal  returns  (uint256  externalFee , uint256  remainingNativeValue ) {
178-         uint256  feeRecipientFee  =  _feeRecipientAmount (
181+         ( address   _feeRecipient ,  uint256  feeAmount )  =  _feeRecipientAndAmount (
179182            _destination,
180183            _recipient,
181184            _amount
182185        );
183186        externalFee =  _externalFeeAmount (_destination, _recipient, _amount);
184-         uint256  charge =  _amount +  feeRecipientFee  +  externalFee;
187+         uint256  charge =  _amount +  feeAmount  +  externalFee;
185188        _transferFromSender (charge);
186-         if  (feeRecipientFee  >  0 ) {
189+         if  (feeAmount  >  0 ) {
187190            // transfer atomically so we don't need to keep track of collateral 
188191            // and fee balances separately 
189-             _transferTo (feeRecipient (), feeRecipientFee );
192+             _transferTo (_feeRecipient, feeAmount );
190193        }
191194        remainingNativeValue =  token () !=  address (0 )
192195            ?  _msgValue
@@ -221,11 +224,12 @@ abstract contract TokenRouter is GasRouter, ITokenBridge {
221224    /** 
222225     * @notice Sets the fee recipient for the router. 
223226     * @dev Allows for address(0) to be set, which disables fees. 
224-      * @param _feeRecipient  The address of the fee recipient . 
227+      * @param recipient  The address that receives fees . 
225228     */ 
226-     function setFeeRecipient  (address  _feeRecipient ) public  onlyOwner {
227-         FEE_RECIPIENT_SLOT.getAddressSlot ().value =  _feeRecipient;
228-         emit  FeeRecipientSet (_feeRecipient);
229+     function setFeeRecipient  (address  recipient ) public  onlyOwner {
230+         require (recipient !=  address (this ), "Fee recipient cannot be self " );
231+         FEE_RECIPIENT_SLOT.getAddressSlot ().value =  recipient;
232+         emit  FeeRecipientSet (recipient);
229233    }
230234
231235    /** 
@@ -264,32 +268,34 @@ abstract contract TokenRouter is GasRouter, ITokenBridge {
264268     * @param _destination The identifier of the destination chain. 
265269     * @param _recipient The address of the recipient on the destination chain. 
266270     * @param _amount The amount or identifier of tokens to be sent to the remote recipient 
271+      * @return _feeRecipient The address of the fee recipient. 
267272     * @return feeAmount The fee recipient amount. 
268273     * @dev This function is is not intended to be overridden as storage and logic is contained in TokenRouter. 
269274     */ 
270-     function _feeRecipientAmount   (
275+     function _feeRecipientAndAmount   (
271276        uint32  _destination ,
272277        bytes32  _recipient ,
273278        uint256  _amount 
274-     ) internal  view  returns  (uint256  feeAmount ) {
275-         if  (feeRecipient () ==  address (0 )) {
276-             return  0 ;
279+     ) internal  view  returns  (address  _feeRecipient , uint256  feeAmount ) {
280+         _feeRecipient =  feeRecipient ();
281+         if  (_feeRecipient ==  address (0 )) {
282+             return  (_feeRecipient, 0 );
277283        }
278284
279-         Quote[] memory  quotes =  ITokenFee (feeRecipient () ).quoteTransferRemote (
285+         Quote[] memory  quotes =  ITokenFee (_feeRecipient ).quoteTransferRemote (
280286            _destination,
281287            _recipient,
282288            _amount
283289        );
284290        if  (quotes.length  ==  0 ) {
285-             return  0 ;
291+             return  (_feeRecipient,  0 ) ;
286292        }
287293
288294        require (
289295            quotes.length  ==  1  &&  quotes[0 ].token ==  token (),
290296            "FungibleTokenRouter: fee must match token " 
291297        );
292-         return  quotes[0 ].amount;
298+         feeAmount  =  quotes[0 ].amount;
293299    }
294300
295301    /** 
0 commit comments