Skip to content

Commit

Permalink
Merge pull request #4 from taurusgroup/first-draft
Browse files Browse the repository at this point in the history
Use safe for approval
  • Loading branch information
rya-sge authored Apr 23, 2024
2 parents ffcf317 + 2cbbb9f commit 6b153c6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
5 changes: 1 addition & 4 deletions src/bridge/CCIPBaseSender.sol
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,7 @@ abstract contract CCIPBaseSender is CCIPAllowlistedChain, CCIPSenderBuild, CCIPR
// transfer tokens to the contract
IERC20(tokenAmounts[i].token).safeTransferFrom(_msgSender(), address(this), tokenAmounts[i].amount);
// approve the Router to spend tokens on contract's behalf. It will spend the amount of the given token
bool result = IERC20(tokenAmounts[i].token).approve(address(router), tokenAmounts[i].amount);
if(!result){
revert CCIPErrors.CCIP_BaseSender_FailApproval();
}
IERC20(tokenAmounts[i].token).safeIncreaseAllowance(address(router), tokenAmounts[i].amount);
}
// Send CCIP Message
messageId = router.ccipSend(_destinationChainSelector, message);
Expand Down
8 changes: 3 additions & 5 deletions src/bridge/modules/configuration/CCIPSenderPayment.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
pragma solidity ^0.8.20;

import {IERC20} from "ccip-v08/vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "ccip-v08/vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/utils/SafeERC20.sol";
import {Client} from "ccip/libraries/Client.sol";
import {IRouterClient} from "ccip/interfaces/IRouterClient.sol";
import "../libraries/CCIPErrors.sol";
import "../security/AuthorizationModule.sol";

abstract contract CCIPSenderPayment is AuthorizationModule{
using SafeERC20 for IERC20;
uint256 private paymentIdCounter = 1;
struct FEE_PAYMENT_TOKEN {
uint256 id;
Expand Down Expand Up @@ -77,11 +79,7 @@ abstract contract CCIPSenderPayment is AuthorizationModule{
revert CCIPErrors.CCIP_SenderPayment_ContractNotEnoughBalance(contractBalance, fees);
}
// External call
bool result = paymentTokens[paymentMethodId].tokenAddress.approve(address(router), fees);
if(!result){
revert CCIPErrors.CCIP_SenderPayment_FailApproval();
}

paymentTokens[paymentMethodId].tokenAddress.safeIncreaseAllowance(address(router), fees);
} else { // Native token
uint256 contractBalance = address(this).balance;
if (fees > contractBalance){
Expand Down

0 comments on commit 6b153c6

Please sign in to comment.