Skip to content

Commit

Permalink
evm: remove safeTransferFrom
Browse files Browse the repository at this point in the history
  • Loading branch information
a5-pickle committed Jan 4, 2024
1 parent fb9460c commit 2d07286
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// SPDX-License-Identifier: Apache 2

pragma solidity ^0.8.22;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
Expand Down
8 changes: 7 additions & 1 deletion evm/forge/tests/integrations/InheritingWormholeCctp.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// SPDX-License-Identifier: Apache 2

pragma solidity ^0.8.22;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

import {IWormhole} from "src/interfaces/IWormhole.sol";

import {Utils} from "src/libraries/Utils.sol";
Expand All @@ -10,6 +12,7 @@ import {WormholeCctpTokenMessenger} from "src/contracts/WormholeCctpTokenMesseng

contract InheritingWormholeCctp is WormholeCctpTokenMessenger {
using Utils for address;
using SafeERC20 for IERC20;

uint32 constant _MY_BFF_DOMAIN = 1;
bytes32 constant _MY_BFF_ADDR =
Expand All @@ -31,6 +34,9 @@ contract InheritingWormholeCctp is WormholeCctpTokenMessenger {
payable
returns (uint64 wormholeSequence)
{
// Deposit tokens into this contract to prepare for burning.
IERC20(_usdcAddress).safeTransferFrom(msg.sender, address(this), amount);

(wormholeSequence,) = burnAndPublish(
_MY_BFF_ADDR,
_MY_BFF_DOMAIN,
Expand Down
9 changes: 9 additions & 0 deletions evm/src/contracts/CircleIntegration/Logic.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// SPDX-License-Identifier: Apache 2
pragma solidity ^0.8.22;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

import {IWormhole} from "src/interfaces/IWormhole.sol";
import {IMessageTransmitter} from "src/interfaces/IMessageTransmitter.sol";
import {ITokenMessenger} from "src/interfaces/ITokenMessenger.sol";
Expand All @@ -21,6 +24,7 @@ import {

abstract contract Logic is ICircleIntegration, Governance {
using Utils for address;
using SafeERC20 for IERC20;
using WormholeCctpMessages for *;

/// @inheritdoc ICircleIntegration
Expand All @@ -33,6 +37,11 @@ abstract contract Logic is ICircleIntegration, Governance {
bytes32 destinationCaller = getRegisteredEmitters()[transferParams.targetChain];
require(destinationCaller != 0, "target contract not registered");

// Deposit tokens into this contract to prepare for burning.
IERC20(transferParams.token).safeTransferFrom(
msg.sender, address(this), transferParams.amount
);

// Approve the Token Messenger to spend tokens.
setTokenMessengerApproval(transferParams.token, transferParams.amount);

Expand Down
3 changes: 0 additions & 3 deletions evm/src/contracts/WormholeCctpTokenMessenger.sol
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,6 @@ abstract contract WormholeCctpTokenMessenger {
bytes memory payload,
uint256 wormholeFee
) internal returns (uint64 wormholeSequence, uint64 cctpNonce) {
// Deposit tokens into this contract to prepare for burning.
IERC20(token).safeTransferFrom(msg.sender, address(this), amount);

// Invoke Token Messenger to burn tokens and emit a CCTP token burn message.
cctpNonce = _tokenMessenger.depositForBurnWithCaller(
amount, destinationCctpDomain, mintRecipient, token, destinationCaller
Expand Down

0 comments on commit 2d07286

Please sign in to comment.