Verified contractExactMIT
SwappingRelay
Address0x142e34522b1e97d266679beee95baf64ac935d56
- Balance
0 ETH
- Transactions
392
- Compiler
solc 0.8.27
- Same code
Only this contract
Details
- Compiler
- solc 0.8.27+commit.40a35a09
- Language
- solidity
- Optimization
- No
- EVM version
- prague
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,003,786
- Creation transaction
- 0x73b8eacbdc…846bc9e4a7
11 files
- contracts/bridge/SwappingRelay.solmain9.05 KB
- contracts/interfaces/IBeefySwapper.sol503 B
- contracts/interfaces/IBeefyZapRouter.sol3.62 KB
- contracts/interfaces/ICircleBeefyZapReceiver.sol7.29 KB
- contracts/interfaces/IPermit2.sol2.01 KB
- node_modules/@openzeppelin/contracts/access/Ownable.sol2.62 KB
- node_modules/@openzeppelin/contracts/token/ERC20/IERC20.sol2.74 KB
- node_modules/@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol2.26 KB
- node_modules/@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol6.91 KB
- node_modules/@openzeppelin/contracts/utils/Address.sol9.36 KB
- node_modules/@openzeppelin/contracts/utils/Context.sol844 B
contracts/bridge/SwappingRelay.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {SafeERC20, IERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {ICircleBeefyZapReceiver} from "../interfaces/ICircleBeefyZapReceiver.sol";
import {IBeefySwapper} from "../interfaces/IBeefySwapper.sol";
interface IWETH {
function withdraw(uint256 wad) external;
}
/**
* @title SwappingRelay
* @author BeefyFinance
* @notice Owner-only relay for Circle CCTP messages; after relaying, converts received USDC fees to native and forwards to owner.
* @dev Flow: owner calls relay(message, attestation) -> receiver.relay() mints USDC and pays fee to this contract -> if USDC balance
* is at least unwrapTriggerThreshold, swaps USDC -> wnative via BeefySwapper, unwraps wnative to native, sends native to owner.
* The swap step is wrapped in try/catch so a failed swap does not revert the relay. estimateRelay() is an eth_call helper that
* returns zap outcome plus split zap/swap gas. triggerSwap() runs only the swap/unwrap/send.
* On Arc, USDC is already native (usdc == wnative): swapAndUnwrap skips the swap and forwards native to owner.
*/
contract SwappingRelay is Ownable {
using SafeERC20 for IERC20;
/// @notice USDC token (chain-specific).
IERC20 public immutable usdc;
/// @notice Wrapped native token (e.g. WETH, WMATIC) to swap into and unwrap.
address public immutable wnative;
/// @notice Circle CCTP receiver used to relay messages and receive USDC fees.
ICircleBeefyZapReceiver public receiver;
/// @notice Swapper used to convert USDC to wnative.
IBeefySwapper public swapper;
/// @notice Minimum USDC balance required to run the swap (avoids swapping dust).
uint256 public unwrapTriggerThreshold;
error ZeroAddress();
error NativeTransferFailed();
error OnlySelf();
event Relayed(bool zapSuccess, bool swapSuccess, uint256 nativeSent);
/**
* @param _owner Owner of the contract (receives native from swaps).
* @param _receiver CircleBeefyZapReceiver address.
* @param _swapper BeefySwapper address.
* @param _usdc USDC token address.
* @param _wnative Wrapped native token address.
* @param _unwrapTriggerThreshold Min USDC balance to trigger swap; below this the swap is skipped.
*/
constructor(
address _owner,
address _receiver,
address _swapper,
address _usdc,
address _wnative,
uint256 _unwrapTriggerThreshold
) {
if (_owner == address(0)) revert ZeroAddress();
if (_receiver == address(0)) revert ZeroAddress();
if (_swapper == address(0)) revert ZeroAddress();
if (_usdc == address(0)) revert ZeroAddress();
if (_wnative == address(0)) revert ZeroAddress();
_transferOwnership(_owner);
receiver = ICircleBeefyZapReceiver(_receiver);
swapper = IBeefySwapper(_swapper);
usdc = IERC20(_usdc);
wnative = _wnative;
unwrapTriggerThreshold = _unwrapTriggerThreshold;
}
/**
* @notice Relay a CCTP message then optionally convert USDC fee to native gas for the owner.
* @param message Raw CCTP message bytes.
* @param attestation Circle attestation bytes.
* Emits Relayed(zapSuccess, swapSuccess, nativeSent) with: zapSuccess = true if CCTP zap succeeded; swapSuccess = false only when swap was attempted and failed; nativeSent = amount of native sent to owner (0 if swap skipped or failed).
*/
function relay(bytes calldata message, bytes calldata attestation) external onlyOwner {
bool zapSuccess = receiver.relay(message, attestation);
(bool swapSuccess, uint256 nativeSent) = _doSwap(false);
emit Relayed(zapSuccess, swapSuccess, nativeSent);
}
/**
* @notice Simulation helper: run zap then fee swap and return split gas usage.
* @dev Intended for eth_call / simulateContract only. Still emits Relayed if broadcast by mistake so the outcome is observable.
* Measures swap gas with the unwrap threshold ignored so sub-threshold balances still produce a representative swap cost.
*/
function estimateRelay(bytes calldata message, bytes calldata attestation)
external
onlyOwner
returns (bool zapSuccess, uint256 zapGasUsed, uint256 swapGasUsed)
{
uint256 zapStart = gasleft();
zapSuccess = receiver.relay(message, attestation);
zapGasUsed = zapStart - gasleft();
uint256 swapStart = gasleft();
(bool swapSuccess, uint256 nativeSent) = _doSwap(true);
swapGasUsed = swapStart - gasleft();
emit Relayed(zapSuccess, swapSuccess, nativeSent);
}
/**
* @notice Get the fee as native.
* @return nativeSent Amount of native sent to owner.
*/
function getFeeAsNative() external view returns (uint256 nativeSent) {
uint256 fee = receiver.fee();
if (fee == 0) return 0;
// Arc: usdc == wnative. Oracle has no price → getAmountOut div0. ERC-20 is 6dp, native is 18dp.
if (address(usdc) == wnative) return fee * 1e12;
return swapper.getAmountOut(address(usdc), wnative, fee);
}
/**
* @notice Run only the swap path: USDC -> wnative -> unwrap -> send native to owner.
* @dev No CCTP relay; use when the contract already holds USDC above the threshold.
* @return success False only when the swap was attempted and failed.
* @return nativeSent Amount of native sent to owner (0 if swap skipped or failed).
*/
function triggerSwap() external onlyOwner returns (bool success, uint256 nativeSent) {
return _doSwap(true);
}
/**
* @dev Runs swap logic when USDC balance is non-zero. If `ignoreThreshold` is false, also requires
* balance >= unwrapTriggerThreshold. Uses external self-call so failures in swapAndUnwrap can be
* caught without reverting the caller (e.g. relay).
*/
function _doSwap(bool ignoreThreshold) internal returns (bool success, uint256 nativeSent) {
uint256 usdcBalance = usdc.balanceOf(address(this));
if (usdcBalance == 0) return (true, 0);
if (!ignoreThreshold && usdcBalance < unwrapTriggerThreshold) return (true, 0);
try this.swapAndUnwrap(usdcBalance) returns (uint256 _nativeSent) {
return (true, _nativeSent);
} catch {
return (false, 0);
}
}
/**
* @dev Swap USDC to wnative, unwrap wnative to native, send native to owner. Callable only by this contract
* (used via this.swapAndUnwrap() so the whole sequence can be try/catch'd).
* @param usdcAmount Amount of USDC to swap.
* @return nativeSent Amount of native sent to owner.
*/
function swapAndUnwrap(uint256 usdcAmount) external returns (uint256 nativeSent) {
if (msg.sender != address(this)) revert OnlySelf();
// Arc: USDC is native (same address, no wrap). Swap/withdraw revert; the ERC-20
// credit is already the native balance, so skip straight to the owner send.
if (address(usdc) != wnative) {
usdc.forceApprove(address(swapper), usdcAmount);
swapper.swap(address(usdc), wnative, usdcAmount);
uint256 wnativeBalance = IERC20(wnative).balanceOf(address(this));
if (wnativeBalance == 0) return 0;
IWETH(wnative).withdraw(wnativeBalance);
}
nativeSent = address(this).balance;
if (nativeSent > 0) {
(bool ok,) = payable(owner()).call{value: nativeSent}("");
if (!ok) revert NativeTransferFailed();
}
}
/// @dev Accepts native when unwrapping wnative.
receive() external payable {}
/**
* @notice Transfer out ERC20 tokens sent to this contract by mistake.
* @param _token Token to transfer.
* @param _amount Amount to transfer.
* @param _to Recipient.
*/
function recoverERC20(address _token, uint256 _amount, address _to) external onlyOwner {
if (_to == address(0)) revert ZeroAddress();
IERC20(_token).safeTransfer(_to, _amount);
}
/// @notice Set the Circle CCTP receiver address.
function setReceiver(address _receiver) external onlyOwner {
if (_receiver == address(0)) revert ZeroAddress();
receiver = ICircleBeefyZapReceiver(_receiver);
}
/// @notice Set the swapper address. Clears allowance for the previous swapper; the new swapper is approved when swapping.
function setSwapper(address _swapper) external onlyOwner {
if (_swapper == address(0)) revert ZeroAddress();
usdc.forceApprove(address(swapper), 0);
swapper = IBeefySwapper(_swapper);
}
/// @notice Set the minimum USDC balance required to run the swap.
function setUnwrapTriggerThreshold(uint256 _unwrapTriggerThreshold) external onlyOwner {
unwrapTriggerThreshold = _unwrapTriggerThreshold;
}
}
contracts/interfaces/IBeefySwapper.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
interface IBeefySwapper {
function swap(address _fromToken, address _toToken, uint256 _amountIn) external returns (uint256 amountOut);
function swap(address _fromToken, address _toToken, uint256 _amountIn, uint256 _minAmountOut)
external
returns (uint256 amountOut);
function getAmountOut(address _fromToken, address _toToken, uint256 _amountIn)
external
view
returns (uint256 amountOut);
}
contracts/interfaces/IBeefyZapRouter.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import { IPermit2 } from "./IPermit2.sol";
/**
* @title Zap router interface
* @author kexley, Beefy
* @notice Interface for zap router that contains the structs for orders and routes
*/
interface IBeefyZapRouter {
/**
* @dev Input token and amount used in a step of the zap
* @param token Address of token
* @param amount Amount of token
*/
struct Input {
address token;
uint256 amount;
}
/**
* @dev Output token and amount from the end of the zap
* @param token Address of token
* @param minOutputAmount Minimum amount of token received
*/
struct Output {
address token;
uint256 minOutputAmount;
}
/**
* @dev External call at the end of zap
* @param target Target address to be called
* @param value Ether value of the call
* @param data Payload to call target address with
*/
struct Relay {
address target;
uint256 value;
bytes data;
}
/**
* @dev Token relevant to the current step of the route
* @param token Address of token
* @param index Location in the data that the balance of the token should be inserted
*/
struct StepToken {
address token;
int32 index;
}
/**
* @dev Step in a route
* @param target Target address to be called
* @param value Ether value to call the target address with
* @param data Payload to call target address with
* @param tokens Tokens relevant to the step that require approvals or their balances inserted
* into the data
*/
struct Step {
address target;
uint256 value;
bytes data;
StepToken[] tokens;
}
/**
* @dev Order created by the user
* @param inputs Tokens and amounts to be pulled from the user
* @param outputs Tokens and minimums to be sent to recipient
* @param relay External call to make after zap is completed
* @param user Source of input tokens
* @param recipient Destination of output tokens
*/
struct Order {
Input[] inputs;
Output[] outputs;
Relay relay;
address user;
address recipient;
}
/**
* @notice Execute an order directly
* @param _order Order created by the user
* @param _route Route supplied by user
*/
function executeOrder(Order calldata _order, Step[] calldata _route) external payable;
/**
* @notice Execute an order on behalf of a user
* @param _permit Token permits from Permit2 with the order as witness data signed by user
* @param _order Order created by user that was signed in the permit
* @param _signature Signature from user of combined permit and order
* @param _route Route supplied by user or third-party
*/
function executeOrder(
IPermit2.PermitBatchTransferFrom calldata _permit,
Order calldata _order,
bytes calldata _signature,
Step[] calldata _route
) external;
/**
* @notice Pause the contract from carrying out any more zaps
* @dev Only owner can pause
*/
function pause() external;
/**
* @notice Unpause the contract to allow new zaps
* @dev Only owner can unpause
*/
function unpause() external;
/**
* @notice Permit2 immutable address
*/
function permit2() external view returns (address);
/**
* @notice Token manager immutable address
*/
function tokenManager() external view returns (address);
}
contracts/interfaces/ICircleBeefyZapReceiver.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import { IBeefyZapRouter } from "./IBeefyZapRouter.sol";
/**
* @title Circle Beefy Zap Receiver Interface
* @author weso, Beefy
* @notice Interface for the Circle CCTP receiver used to relay minted USDC into a Beefy Zap route.
* @dev The receiver is intended to be the `target` in Circle's hook data.
* The hook calldata is decoded as `ZapPayload` and then used to build a Beefy Zap order.
*/
interface ICircleBeefyZapReceiver {
/**
* @notice Reverts when a zap address is invalid.
* @param zap The zap address that was provided.
*/
error InvalidZap(address zap);
/**
* @notice Reverts when the decoded recipient is the zero address.
*/
error InvalidRecipient();
/**
* @notice Reverts when the CCTP message is malformed (too short to contain expected fields).
*/
error InvalidMessage();
/**
* @notice Reverts when the CCTP burn message body is malformed.
*/
error InvalidBurnMessage();
/**
* @notice Reverts when the hook data is malformed or targets a different contract.
*/
error InvalidHookData();
/**
* @notice Reverts when a function restricted to internal self-calls is called externally.
*/
error InvalidCaller();
/**
* @notice Reverts when the CCTP message relay fails.
*/
error RelayFailure();
/**
* @notice Reverts when the CCTP message amount is invalid.
*/
error InvalidAmount();
/**
* @notice Emitted when the recovery address is updated.
* @param oldRecovery Previous recovery address.
* @param newRecovery New recovery address.
*/
event RecoveryAddressUpdated(address indexed oldRecovery, address indexed newRecovery);
/**
* @notice Emitted after a zap attempt.
* @param nonce CCTP message header nonce.
* @param recipient Recipient from the decoded `ZapPayload`.
* @param success True if the zap succeeded; false if it reverted and funds were refunded.
* @param amountIn Amount of USDC observed in the receiver at time of execution.
* @param refundedAmount Amount of USDC refunded to recipient on zap failure.
* @param recoveredAmount Amount of USDC recovered to recovery address on relay/hook failure.
*/
event ZapExecuted(
bytes32 indexed nonce,
address indexed recipient,
bool success,
uint256 amountIn,
uint256 refundedAmount,
uint256 recoveredAmount
);
/**
* @notice Emitted when the fee is updated.
* @param oldFee Previous fee amount.
* @param newFee New fee amount.
*/
event FeeUpdated(uint256 indexed oldFee, uint256 indexed newFee);
/**
* @notice Emitted when the fee is paid to the relayer.
* @param nonce CCTP message header nonce.
* @param relayer Relay address.
* @param amount Amount of USDC paid.
*/
event FeePaid(bytes32 indexed nonce, address indexed relayer, uint256 amount);
/**
* @notice Decoded hook payload used to construct and execute a Beefy Zap order.
* @dev This struct is ABI-decoded from the hook calldata portion of the CCTP message.
* @param recipient Final recipient of the zap outputs (or USDC refund on failure).
* @param outputs Desired output tokens/amounts configuration (see `IBeefyZapRouter`).
* @param relay Relay configuration (see `IBeefyZapRouter`).
* @param route Steps to execute in the zap (see `IBeefyZapRouter`).
*/
struct ZapPayload {
address recipient;
IBeefyZapRouter.Output[] outputs;
IBeefyZapRouter.Relay relay;
IBeefyZapRouter.Step[] route;
}
/**
* @notice Storage layout for the Circle receiver.
* @dev Used with a namespaced storage slot via `CircleBeefyReceiverStorageUtils`.
* @param usdc USDC token address on the destination chain.
* @param messageTransmitter Circle CCTP MessageTransmitter address.
* @param zap Beefy ZapRouter address to execute orders against.
* @param tokenManager Beefy TokenManager address pulled from the zap router.
* @param recovery Recovery address.
* @param fee Fixed fee amount in USDC for relayer.
*/
struct CircleBeefyReceiverStorage {
address usdc;
address messageTransmitter;
address zap;
address tokenManager;
address recovery;
uint256 fee;
}
/**
* @notice USDC token address used by the receiver.
*/
function usdc() external view returns (address);
/**
* @notice Fixed fee amount in USDC for relayer.
*/
function fee() external view returns (uint256);
/**
* @notice Circle CCTP MessageTransmitter used to verify and mint USDC from messages.
*/
function messageTransmitter() external view returns (address);
/**
* @notice Beefy ZapRouter used to execute zap orders.
*/
function zap() external view returns (address);
/**
* @notice Beefy TokenManager used by the ZapRouter.
*/
function tokenManager() external view returns (address);
function recovery() external view returns (address);
function setRecovery(address _recovery) external;
function setFee(uint256 _fee) external;
/**
* @notice Receives a Circle CCTP message and attempts to execute a zap with the minted USDC.
* @dev Typical flow:
* - Calls MessageTransmitter.receiveMessage(message, attestation)
* - Extracts hook data (target + flags + calldata)
* - Requires target == address(this)
* - ABI-decodes calldata into `ZapPayload`
* - Executes the zap; on failure, refunds remaining USDC to `recipient`
* @param message Raw CCTP message bytes.
* @param attestation Circle attestation bytes for the message.
* @return zapSuccess True if zap execution succeeded; false if it failed and refunded USDC.
*/
function relay(
bytes calldata message,
bytes calldata attestation
) external returns (bool zapSuccess);
/**
* @notice Processes the hook data and executes the zap.
* @dev Typical flow:
* - Extracts hook data (target + calldata)
* - Requires target == address(this)
* - ABI-decodes calldata into `ZapPayload`
* - Executes the zap with the minted USDC
* @param message Raw CCTP message bytes.
* @return recipient Recipient from the decoded `ZapPayload`.
*/
function processHook(bytes calldata message) external returns (address recipient, bool zapSuccess);
/**
* @notice Recovers tokens from the receiver and transfers them to the recipient. Only callable by the recipient.
* @dev Typical flow:
* - Calls MessageTransmitter.receiveMessage(message, attestation)
* - Requires recipient == msg.sender
* - Transfers remaining USDC to `recipient`
* @param message Raw CCTP message bytes.
* @param attestation Circle attestation bytes for the message.
* @return success True if the tokens were recovered successfully; false if it failed.
*/
function recoverTokens(bytes calldata message, bytes calldata attestation) external returns (bool success);
}contracts/interfaces/IPermit2.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
/**
* @title Permit2 interface
* @author kexley, Beefy
* @notice Interface for Permit2
*/
interface IPermit2 {
/**
* @dev Token and amount in a permit message
* @param token Address of token to transfer
* @param amount Amount of token to transfer
*/
struct TokenPermissions {
address token;
uint256 amount;
}
/**
* @dev Batched permit with the unique nonce and deadline
* @param permitted Tokens and corresponding amounts permitted for a transfer
* @param nonce Unique value for every token owner's signature to prevent signature replays
* @param deadline Deadline on the permit signature
*/
struct PermitBatchTransferFrom {
TokenPermissions[] permitted;
uint256 nonce;
uint256 deadline;
}
/**
* @dev Transfer details for permitBatchTransferFrom
* @param to Recipient of tokens
* @param requestedAmount Amount to transfer
*/
struct SignatureTransferDetails {
address to;
uint256 requestedAmount;
}
/**
* @notice Consume a permit2 message and transfer tokens
* @param permit Batched permit
* @param transferDetails Recipient and amount of tokens to transfer
* @param owner Source of tokens
* @param witness Verified order data that was witnessed in the permit2 signature
* @param witnessTypeString Order function string used to create EIP-712 type string
* @param signature Signature from user
*/
function permitWitnessTransferFrom(
PermitBatchTransferFrom memory permit,
SignatureTransferDetails[] calldata transferDetails,
address owner,
bytes32 witness,
string calldata witnessTypeString,
bytes calldata signature
) external;
/**
* @notice Domain separator to differentiate the chain a permit exists on
*/
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
node_modules/@openzeppelin/contracts/access/Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
node_modules/@openzeppelin/contracts/token/ERC20/IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 amount) external returns (bool);
}
node_modules/@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
node_modules/@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/IERC20Permit.sol";
import "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(IERC20 token, address spender, uint256 value) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Compatible with tokens that require the approval to be set to
* 0 before setting it to a non-zero value.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
* Revert on invalid signature.
*/
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return
success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
}
}
node_modules/@openzeppelin/contracts/utils/Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
node_modules/@openzeppelin/contracts/utils/Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
Compiler settingsShow
{
"viaIR": false,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": false
},
"evmVersion": "prague",
"remappings": [
"@openzeppelin/=node_modules/@openzeppelin/",
"forge-std/=node_modules/forge-std/src/",
"ds-test/=node_modules/ds-test/src/",
"evm-cctp-contracts/=lib/evm-cctp-contracts/src/",
"@memview-sol/=lib/evm-cctp-contracts/lib/memview-sol/",
"centre-tokens.git/=lib/evm-cctp-contracts/lib/centre-tokens.git/",
"eth-gas-reporter/=node_modules/eth-gas-reporter/",
"hardhat/=node_modules/hardhat/",
"memview-sol/=lib/evm-cctp-contracts/lib/memview-sol/contracts/",
"openzeppelin-contracts/=lib/evm-cctp-contracts/lib/openzeppelin-contracts/contracts/",
"solidity-bytes-utils/=node_modules/solidity-bytes-utils/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.