@@ -112,14 +112,28 @@ contract TokenTransferor is OwnerIsCreator {
112112 evm2AnyMessage
113113 );
114114
115- if (fees > s_linkToken.balanceOf (address (this )))
115+ uint256 requiredLinkBalance;
116+ if (_token == address (s_linkToken)) {
117+ // Required LINK Balance is the sum of fees and amount to transfer, if the token to transfer is LINK
118+ requiredLinkBalance = fees + _amount;
119+ } else {
120+ requiredLinkBalance = fees;
121+ }
122+
123+ uint256 linkBalance = s_linkToken.balanceOf (address (this ));
124+
125+ if (requiredLinkBalance > linkBalance) {
116126 revert NotEnoughBalance (s_linkToken.balanceOf (address (this )), fees);
127+ }
117128
118- // approve the Router to transfer LINK tokens on contract's behalf. It will spend the fees in LINK
119- s_linkToken.approve (address (s_router), fees );
129+ // approve the Router to transfer LINK tokens on contract's behalf. It will spend the requiredLinkBalance
130+ s_linkToken.approve (address (s_router), requiredLinkBalance );
120131
121- // approve the Router to spend tokens on contract's behalf. It will spend the amount of the given token
122- IERC20 (_token).approve (address (s_router), _amount);
132+ // If sending a token other than LINK, approve it separately
133+ if (_token != address (s_linkToken)) {
134+ // approve the Router to spend tokens on contract's behalf. It will spend the amount of the given token
135+ IERC20 (_token).approve (address (s_router), _amount);
136+ }
123137
124138 // Send the message through the router and store the returned message ID
125139 messageId = s_router.ccipSend (
0 commit comments