From 2d07286c610a9359d85c06f808f02a87bea02502 Mon Sep 17 00:00:00 2001 From: A5 Pickle Date: Thu, 4 Jan 2024 10:51:34 -0600 Subject: [PATCH] evm: remove safeTransferFrom --- .../integrations/ComposingWithCircleIntegration.sol | 1 - evm/forge/tests/integrations/InheritingWormholeCctp.sol | 8 +++++++- evm/src/contracts/CircleIntegration/Logic.sol | 9 +++++++++ evm/src/contracts/WormholeCctpTokenMessenger.sol | 3 --- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/evm/forge/tests/integrations/ComposingWithCircleIntegration.sol b/evm/forge/tests/integrations/ComposingWithCircleIntegration.sol index 14b0972..bf3c521 100644 --- a/evm/forge/tests/integrations/ComposingWithCircleIntegration.sol +++ b/evm/forge/tests/integrations/ComposingWithCircleIntegration.sol @@ -1,5 +1,4 @@ // SPDX-License-Identifier: Apache 2 - pragma solidity ^0.8.22; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; diff --git a/evm/forge/tests/integrations/InheritingWormholeCctp.sol b/evm/forge/tests/integrations/InheritingWormholeCctp.sol index 6d4b2e7..40c515b 100644 --- a/evm/forge/tests/integrations/InheritingWormholeCctp.sol +++ b/evm/forge/tests/integrations/InheritingWormholeCctp.sol @@ -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"; @@ -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 = @@ -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, diff --git a/evm/src/contracts/CircleIntegration/Logic.sol b/evm/src/contracts/CircleIntegration/Logic.sol index b770b5c..703292f 100644 --- a/evm/src/contracts/CircleIntegration/Logic.sol +++ b/evm/src/contracts/CircleIntegration/Logic.sol @@ -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"; @@ -21,6 +24,7 @@ import { abstract contract Logic is ICircleIntegration, Governance { using Utils for address; + using SafeERC20 for IERC20; using WormholeCctpMessages for *; /// @inheritdoc ICircleIntegration @@ -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); diff --git a/evm/src/contracts/WormholeCctpTokenMessenger.sol b/evm/src/contracts/WormholeCctpTokenMessenger.sol index da71f68..fdc88a1 100644 --- a/evm/src/contracts/WormholeCctpTokenMessenger.sol +++ b/evm/src/contracts/WormholeCctpTokenMessenger.sol @@ -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