Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0x14163d7019595DC1a76e9d88Ef13F66dc220577E
Balance 0 ETH
Nonce 1
Code Size 5771 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

5771 bytes
0x6080604052600436106100ec5760003560e01c8063715018a61161008a578063b0f479a111610059578063b0f479a1146102b0578063dc4ca20c146102e3578063e94e1b8514610311578063f2fde38b1461032457600080fd5b8063715018a61461023d57806385572ffb146102525780638da5cb5b14610272578063a522ad251461029057600080fd5b8063200d2ed2116100c6578063200d2ed21461019b57806325e16063146101c257806335bc2529146101e25780634c2aebdb1461020257600080fd5b806301ffc9a7146100f857806309f452361461012d578063110a5a0b1461017957600080fd5b366100f357005b600080fd5b34801561010457600080fd5b50610118610113366004610f91565b610344565b60405190151581526020015b60405180910390f35b34801561013957600080fd5b506101617f000000000000000000000000243c9be13faba09f945ccc565547293337da0ad781565b6040516001600160a01b039091168152602001610124565b34801561018557600080fd5b50610199610194366004610fc9565b61037b565b005b3480156101a757600080fd5b506002546101b59060ff1681565b6040516101249190610ffc565b3480156101ce57600080fd5b506101996101dd366004611039565b6103b5565b3480156101ee57600080fd5b506101996101fd366004611056565b610459565b34801561020e57600080fd5b5061011861021d366004611108565b600160209081526000928352604080842090915290825290205460ff1681565b34801561024957600080fd5b506101996104e5565b34801561025e57600080fd5b5061019961026d36600461113f565b6104f9565b34801561027e57600080fd5b506000546001600160a01b0316610161565b34801561029c57600080fd5b506101996102ab366004611179565b61055d565b3480156102bc57600080fd5b507f00000000000000000000000080226fc0ee2b096224eeac085bb9a8cba1146f7d610161565b3480156102ef57600080fd5b506103036102fe366004611197565b610607565b604051908152602001610124565b61019961031f366004611197565b610737565b34801561033057600080fd5b5061019961033f366004611039565b6109fa565b60006001600160e01b031982166385572ffb60e01b148061037557506001600160e01b031982166301ffc9a760e01b145b92915050565b610383610a35565b8061038f576001610392565b60025b6002805460ff1916600183838111156103ad576103ad610fe6565b021790555050565b6103bd610a35565b4760008190036103e057604051630686827b60e51b815260040160405180910390fd5b6000826001600160a01b03168260405160006040518083038185875af1925050503d806000811461042d576040519150601f19603f3d011682016040523d82523d6000602084013e610432565b606091505b5050905080610454576040516305828f5560e11b815260040160405180910390fd5b505050565b610461610a35565b60005b838110156104de578160016000878785818110610483576104836111e6565b905060200201602081019061049891906111fc565b6001600160401b03168152602080820192909252604090810160009081206001600160a01b03881682529092529020805460ff1916911515919091179055600101610464565b5050505050565b6104ed610a35565b6104f76000610a62565b565b336001600160a01b037f00000000000000000000000080226fc0ee2b096224eeac085bb9a8cba1146f7d1614610549576040516335fdcccd60e21b81523360048201526024015b60405180910390fd5b61055a610555826113c2565b610ab2565b50565b610565610a35565b6040516370a0823160e01b81523060048201526000906001600160a01b038316906370a0823190602401602060405180830381865afa1580156105ac573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105d0919061146e565b9050806000036105f357604051630686827b60e51b815260040160405180910390fd5b6104546001600160a01b0383168483610bc8565b6001600160401b03841660009081526001602090815260408083206001600160a01b03871684529091528120548590859060ff161515830361065f57604051600162f5878f60e01b0319815260040160405180910390fd5b7f00000000000000000000000080226fc0ee2b096224eeac085bb9a8cba1146f7d6001600160a01b03166320487ded886106ce8989896040516020016106ba9291906001600160a01b03929092168252602082015260400190565b604051602081830303815290604052610c27565b6040518363ffffffff1660e01b81526004016106eb9291906114d7565b602060405180830381865afa158015610708573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061072c919061146e565b979650505050505050565b6001600160401b03841660009081526001602090815260408083206001600160a01b03871684529091528120548591859160ff161515900361078f57604051600162f5878f60e01b0319815260040160405180910390fd5b6002805460ff16818111156107a6576107a6610fe6565b146107c457604051633ac4266d60e11b815260040160405180910390fd5b604080516001600160a01b03861660208201529081018490526000906107ee9087906060016106ba565b6040516320487ded60e01b81529091507f00000000000000000000000080226fc0ee2b096224eeac085bb9a8cba1146f7d906000906001600160a01b038316906320487ded90610844908c9087906004016114d7565b602060405180830381865afa158015610861573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610885919061146e565b9050803411156108f15760003361089c83346115b0565b604051600081818185875af1925050503d80600081146108d8576040519150601f19603f3d011682016040523d82523d6000602084013e6108dd565b606091505b50509050806108eb57600080fd5b50610912565b80341015610912576040516324e74b3d60e21b815260040160405180910390fd5b61091c3387610d4b565b886001600160401b0316826001600160a01b03166396f4e9f9838c876040518463ffffffff1660e01b81526004016109559291906114d7565b60206040518083038185885af1158015610973573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190610998919061146e565b604080516001600160a01b038c811682523360208301528b1681830152606081018a90526080810185905290517f1d32806d668de01d241d7deade2ddebd4d32aedbb6929076c2849c5e96c0d4a19181900360a00190a3505050505050505050565b610a02610a35565b6001600160a01b038116610a2c57604051631e4fbdf760e01b815260006004820152602401610540565b61055a81610a62565b6000546001600160a01b031633146104f75760405163118cdaa760e01b8152336004820152602401610540565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b80602001518160400151806020019051810190610acf91906115d1565b6001600160401b03821660009081526001602090815260408083206001600160a01b038516845290915281205460ff1615159003610b2357604051600162f5878f60e01b0319815260040160405180910390fd5b6000808460600151806020019051810190610b3e91906115ee565b91509150610b4c8282610d84565b84602001516001600160401b031685600001517f1eb7d864650f669fdc7cb97942971fadf1983930d028aaa76b73c62547adcf588760400151806020019051810190610b9891906115d1565b604080516001600160a01b0392831681529187166020830152810185905260600160405180910390a35050505050565b6040516001600160a01b0383811660248301526044820183905261045491859182169063a9059cbb906064015b604051602081830303815290604052915060e01b6020820180516001600160e01b038381831617835250505050610db8565b610c626040518060a0016040528060608152602001606081526020016060815260200160006001600160a01b03168152602001606081525090565b6040805160a081019091526001600160a01b03841660c08201528060e0810160408051808303601f190181529181529082526020808301869052815160008082529181018352929091019190610cda565b6040805180820190915260008082526020820152815260200190600190039081610cb35790505b50815260200160006001600160a01b03168152602001610d426040518060200160405280620222e081525060408051915160248084019190915281518084039091018152604490920190526020810180516001600160e01b03166397a657c960e01b17905290565b90529392505050565b610d806001600160a01b037f000000000000000000000000243c9be13faba09f945ccc565547293337da0ad716833084610e1b565b5050565b610d806001600160a01b037f000000000000000000000000243c9be13faba09f945ccc565547293337da0ad7168383610bc8565b6000610dcd6001600160a01b03841683610e5a565b90508051600014158015610df2575080806020019051810190610df0919061161c565b155b1561045457604051635274afe760e01b81526001600160a01b0384166004820152602401610540565b6040516001600160a01b038481166024830152838116604483015260648201839052610e549186918216906323b872dd90608401610bf5565b50505050565b6060610e6883836000610e6f565b9392505050565b606081471015610e945760405163cd78605960e01b8152306004820152602401610540565b600080856001600160a01b03168486604051610eb09190611639565b60006040518083038185875af1925050503d8060008114610eed576040519150601f19603f3d011682016040523d82523d6000602084013e610ef2565b606091505b5091509150610f02868383610f0c565b9695505050505050565b606082610f2157610f1c82610f68565b610e68565b8151158015610f3857506001600160a01b0384163b155b15610f6157604051639996b31560e01b81526001600160a01b0385166004820152602401610540565b5080610e68565b805115610f785780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b600060208284031215610fa357600080fd5b81356001600160e01b031981168114610e6857600080fd5b801515811461055a57600080fd5b600060208284031215610fdb57600080fd5b8135610e6881610fbb565b634e487b7160e01b600052602160045260246000fd5b602081016003831061101e57634e487b7160e01b600052602160045260246000fd5b91905290565b6001600160a01b038116811461055a57600080fd5b60006020828403121561104b57600080fd5b8135610e6881611024565b6000806000806060858703121561106c57600080fd5b84356001600160401b038082111561108357600080fd5b818701915087601f83011261109757600080fd5b8135818111156110a657600080fd5b8860208260051b85010111156110bb57600080fd5b602092830196509450508501356110d181611024565b915060408501356110e181610fbb565b939692955090935050565b80356001600160401b038116811461110357600080fd5b919050565b6000806040838503121561111b57600080fd5b611124836110ec565b9150602083013561113481611024565b809150509250929050565b60006020828403121561115157600080fd5b81356001600160401b0381111561116757600080fd5b820160a08185031215610e6857600080fd5b6000806040838503121561118c57600080fd5b823561112481611024565b600080600080608085870312156111ad57600080fd5b6111b6856110ec565b935060208501356111c681611024565b925060408501356111d681611024565b9396929550929360600135925050565b634e487b7160e01b600052603260045260246000fd5b60006020828403121561120e57600080fd5b610e68826110ec565b634e487b7160e01b600052604160045260246000fd5b604080519081016001600160401b038111828210171561124f5761124f611217565b60405290565b60405160a081016001600160401b038111828210171561124f5761124f611217565b604051601f8201601f191681016001600160401b038111828210171561129f5761129f611217565b604052919050565b600082601f8301126112b857600080fd5b81356001600160401b038111156112d1576112d1611217565b6112e4601f8201601f1916602001611277565b8181528460208386010111156112f957600080fd5b816020850160208301376000918101602001919091529392505050565b600082601f83011261132757600080fd5b813560206001600160401b0382111561134257611342611217565b611350818360051b01611277565b82815260069290921b8401810191818101908684111561136f57600080fd5b8286015b848110156113b7576040818903121561138c5760008081fd5b61139461122d565b813561139f81611024565b81528185013585820152835291830191604001611373565b509695505050505050565b600060a082360312156113d457600080fd5b6113dc611255565b823581526113ec602084016110ec565b602082015260408301356001600160401b038082111561140b57600080fd5b611417368387016112a7565b6040840152606085013591508082111561143057600080fd5b61143c368387016112a7565b6060840152608085013591508082111561145557600080fd5b5061146236828601611316565b60808301525092915050565b60006020828403121561148057600080fd5b5051919050565b60005b838110156114a257818101518382015260200161148a565b50506000910152565b600081518084526114c3816020860160208601611487565b601f01601f19169290920160200192915050565b600060406001600160401b038516835260208181850152845160a08386015261150360e08601826114ab565b905081860151603f198087840301606088015261152083836114ab565b88860151888203830160808a01528051808352908601945060009350908501905b8084101561157357845180516001600160a01b0316835286015186830152938501936001939093019290860190611541565b5060608901516001600160a01b031660a08901526080890151888203830160c08a015295506115a281876114ab565b9a9950505050505050505050565b8181038181111561037557634e487b7160e01b600052601160045260246000fd5b6000602082840312156115e357600080fd5b8151610e6881611024565b6000806040838503121561160157600080fd5b825161160c81611024565b6020939093015192949293505050565b60006020828403121561162e57600080fd5b8151610e6881610fbb565b6000825161164b818460208701611487565b919091019291505056fea2646970667358221220730e19c29eac467cb4d7553ca32dc2c1dc9c577dec79d89a8324a64ed18f464664736f6c63430008140033

Verified Source Code Full Match

Compiler: v0.8.20+commit.a1b79de6 EVM: paris Optimization: Yes (200 runs)
TrufMessageBridgeLock.sol 25 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;

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

import { BaseTRUFMessageBridge } from './BaseTRUFMessageBridge.sol';

contract TrufMessageBridgeLock is BaseTRUFMessageBridge {
    using SafeERC20 for IERC20;

    IERC20 public immutable TRUF_TOKEN;

    constructor(IERC20 trufToken, address router) BaseTRUFMessageBridge(router) {
        TRUF_TOKEN = trufToken;
    }

    function _takeTRUF(address from, uint256 amount) internal override {
        TRUF_TOKEN.safeTransferFrom(from, address(this), amount);
    }

    function _sendTRUF(address to, uint256 amount) internal override {
        TRUF_TOKEN.safeTransfer(to, amount);
    }
}
IERC20.sol 79 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.20;

/**
 * @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 value of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the value of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves a `value` amount of 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 value) 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 a `value` amount of tokens 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 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the
     * allowance mechanism. `value` 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 value) external returns (bool);
}
SafeERC20.sol 118 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../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 An operation with an ERC20 token failed.
     */
    error SafeERC20FailedOperation(address token);

    /**
     * @dev Indicates a failed `decreaseAllowance` request.
     */
    error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);

    /**
     * @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.encodeCall(token.transfer, (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.encodeCall(token.transferFrom, (from, to, 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);
        forceApprove(token, spender, oldAllowance + value);
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
     * value, non-reverting calls are assumed to be successful.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
        unchecked {
            uint256 currentAllowance = token.allowance(address(this), spender);
            if (currentAllowance < requestedDecrease) {
                revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
            }
            forceApprove(token, spender, currentAllowance - requestedDecrease);
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
     * to be set to zero before setting it to a non-zero value, such as USDT.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));

        if (!_callOptionalReturnBool(token, approvalCall)) {
            _callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
            _callOptionalReturn(token, approvalCall);
        }
    }

    /**
     * @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);
        if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @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(token).code.length > 0;
    }
}
BaseTRUFMessageBridge.sol 194 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;

import { IRouterClient } from '@ccip/interfaces/IRouterClient.sol';
import { Client } from '@ccip/libraries/Client.sol';
import { CCIPReceiver } from '@ccip/applications/CCIPReceiver.sol';

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

abstract contract BaseTRUFMessageBridge is Ownable, CCIPReceiver {
    using SafeERC20 for IERC20;

    enum Status {
        UNSET,
        DISABLED,
        ENABLED
    }

    error NotEnoughEthForFees();
    error NothingToWithdraw();
    error FailedToWithdrawEth();
    error InvalidMessageBridge();
    error Disabled();

    event TokensSent(
        bytes32 indexed messageId, // The unique ID of the CCIP message.
        uint64 indexed destinationChainSelector, // The chain selector of the destination chain.
        address bridge, // The address of the message bridge on the destination chain.
        address sender, // The sender of the tokens.
        address recipient, // The sender of the tokens.
        uint256 amount, // The token amount that was transferred.
        uint256 fees // The fees paid for sending the message.
    );

    event TokensReceived(
        bytes32 indexed messageId, // The unique ID of the CCIP message.
        uint64 indexed sourceChainSelector, // The chain selector of the source chain.
        address bridge, // The address of the message bridge from the source chain.
        address recipient, // The recipient of the tokens.
        uint256 amount // The token amount that was transferred.
    );

    mapping(uint64 => mapping(address => bool)) public isMessageBridge;

    Status public status;

    constructor(address router) Ownable(msg.sender) CCIPReceiver(router) {
        status = Status.ENABLED;
    }

    modifier verifyMessageBridge(uint64 chainSelector, address messageBridge) {
        if (isMessageBridge[chainSelector][messageBridge] == false) revert InvalidMessageBridge();
        _;
    }

    /// @notice Sends data and transfer tokens to recipient on the destination chain.
    /// @notice Pay for fees in native gas.
    /// @param destinationChainSelector The identifier (aka selector) for the destination blockchain.
    /// @param messageBridge The address of the messageBridge on the destination blockchain.
    /// @param recipient The address of the recipient on the destination blockchain.
    /// @param amount token amount.
    function sendMessagePayNative(
        uint64 destinationChainSelector,
        address messageBridge,
        address recipient,
        uint256 amount
    ) external payable verifyMessageBridge(destinationChainSelector, messageBridge) {
        if (status != Status.ENABLED) revert Disabled();
        Client.EVM2AnyMessage memory evm2AnyMessage = _buildCCIPMessage(messageBridge, abi.encode(recipient, amount));

        IRouterClient router = IRouterClient(getRouter());

        uint256 fees = router.getFee(destinationChainSelector, evm2AnyMessage);

        if (msg.value > fees) {
            (bool success, ) = msg.sender.call{ value: msg.value - fees }('');
            require(success);
        } else if (msg.value < fees) {
            revert NotEnoughEthForFees();
        }

        _takeTRUF(msg.sender, amount);

        emit TokensSent(
            router.ccipSend{ value: fees }(destinationChainSelector, evm2AnyMessage),
            destinationChainSelector,
            messageBridge,
            msg.sender,
            recipient,
            amount,
            fees
        );
    }

    /// @notice Sends data and transfer tokens to recipient on the destination chain.
    /// @notice Pay for fees in native gas.
    /// @param destinationChainSelector The identifier (aka selector) for the destination blockchain.
    /// @param messageBridge The address of the messageBridge on the destination blockchain.
    /// @param recipient The address of the recipient on the destination blockchain.
    /// @param amount token amount.
    function getFee(
        uint64 destinationChainSelector,
        address messageBridge,
        address recipient,
        uint256 amount
    ) external view verifyMessageBridge(destinationChainSelector, messageBridge) returns (uint256) {
        return
            IRouterClient(getRouter()).getFee(
                destinationChainSelector,
                _buildCCIPMessage(messageBridge, abi.encode(recipient, amount))
            );
    }

    /// @notice Allows the contract owner to withdraw the entire balance of Ether from the contract.
    /// @dev This function reverts if there are no funds to withdraw or if the transfer fails.
    /// It should only be callable by the owner of the contract.
    /// @param beneficiary The address to which the Ether should be sent.
    function withdrawEth(address beneficiary) public onlyOwner {
        uint256 amount = address(this).balance;
        if (amount == 0) revert NothingToWithdraw();

        (bool sent, ) = beneficiary.call{ value: amount }('');
        if (!sent) revert FailedToWithdrawEth();
    }

    /// @notice Allows the owner of the contract to withdraw all tokens of a specific ERC20 token.
    /// @param beneficiary The address to which the tokens will be sent.
    /// @param token The contract address of the ERC20 token to be withdrawn.
    function withdrawTokens(address beneficiary, address token) public onlyOwner {
        uint256 amount = IERC20(token).balanceOf(address(this));
        if (amount == 0) revert NothingToWithdraw();

        IERC20(token).safeTransfer(beneficiary, amount);
    }

    /// @notice Allows the owner of the contract to add/remove a message bridge.
    /// @param chainSelectors The chain selectors of the message bridges.
    /// @param setActive Whether or not the bridges should be set as active.
    function setMessageBridges(uint64[] calldata chainSelectors, address messageBridge, bool setActive) external onlyOwner {
        for (uint256 i = 0; i < chainSelectors.length; ) {
            isMessageBridge[chainSelectors[i]][messageBridge] = setActive;
            unchecked {
                ++i;
            }
        }
    }

    /// @notice Allows the owner of the contract to enable/disable the off-ramp.
    /// @param isEnabled True if should be set as enabled.
    function setMessageBridges(bool isEnabled) external onlyOwner {
        status = isEnabled ? Status.ENABLED : Status.DISABLED;
    }

    function _ccipReceive(
        Client.Any2EVMMessage memory message
    ) internal override verifyMessageBridge(message.sourceChainSelector, abi.decode(message.sender, (address))) {
        (address recipient, uint256 amount) = abi.decode(message.data, (address, uint256));

        _sendTRUF(recipient, amount);

        emit TokensReceived(
            message.messageId,
            message.sourceChainSelector,
            abi.decode(message.sender, (address)),
            recipient,
            amount
        );
    }

    /// @notice Construct a CCIP message.
    /// @dev This function will create an EVM2AnyMessage struct with all the necessary information for programmable tokens transfer.
    /// @param messageBridge The address of the messageBridge.
    /// @param data The data to be sent.
    /// @return Client.EVM2AnyMessage Returns an EVM2AnyMessage struct which contains information for sending a CCIP message.
    function _buildCCIPMessage(address messageBridge, bytes memory data) internal pure returns (Client.EVM2AnyMessage memory) {
        return
            Client.EVM2AnyMessage({
                receiver: abi.encode(messageBridge),
                data: data,
                tokenAmounts: new Client.EVMTokenAmount[](0),
                extraArgs: Client._argsToBytes(Client.EVMExtraArgsV1({ gasLimit: 140_000 })),
                feeToken: address(0)
            });
    }

    function _takeTRUF(address from, uint256 amount) internal virtual;

    function _sendTRUF(address to, uint256 amount) internal virtual;

    /// @notice Fallback function to allow the contract to receive Ether.
    receive() external payable {}
}
IERC20Permit.sol 90 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity ^0.8.20;

/**
 * @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.
 *
 * ==== Security Considerations
 *
 * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
 * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
 * considered as an intention to spend the allowance in any specific way. The second is that because permits have
 * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
 * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
 * generally recommended is:
 *
 * ```solidity
 * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
 *     try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
 *     doThing(..., value);
 * }
 *
 * function doThing(..., uint256 value) public {
 *     token.safeTransferFrom(msg.sender, address(this), value);
 *     ...
 * }
 * ```
 *
 * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
 * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
 * {SafeERC20-safeTransferFrom}).
 *
 * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
 * contracts should have entry points that don't rely on permit.
 */
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].
     *
     * CAUTION: See Security Considerations above.
     */
    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);
}
Address.sol 159 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)

pragma solidity ^0.8.20;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev The ETH balance of the account is not enough to perform the operation.
     */
    error AddressInsufficientBalance(address account);

    /**
     * @dev There's no code at `target` (it is not a contract).
     */
    error AddressEmptyCode(address target);

    /**
     * @dev A call to an address target failed. The target may have reverted.
     */
    error FailedInnerCall();

    /**
     * @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.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        if (address(this).balance < amount) {
            revert AddressInsufficientBalance(address(this));
        }

        (bool success, ) = recipient.call{value: amount}("");
        if (!success) {
            revert FailedInnerCall();
        }
    }

    /**
     * @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 or custom error, it is bubbled
     * up by this function (like regular Solidity function calls). However, if
     * the call reverted with no returned reason, this function reverts with a
     * {FailedInnerCall} error.
     *
     * 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.
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0);
    }

    /**
     * @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`.
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        if (address(this).balance < value) {
            revert AddressInsufficientBalance(address(this));
        }
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
     * was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
     * unsuccessful call.
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata
    ) internal view returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            // only check if target is a contract if the call was successful and the return data is empty
            // otherwise we already know that it was a contract
            if (returndata.length == 0 && target.code.length == 0) {
                revert AddressEmptyCode(target);
            }
            return returndata;
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
     * revert reason or with a default {FailedInnerCall} error.
     */
    function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            return returndata;
        }
    }

    /**
     * @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
     */
    function _revert(bytes memory returndata) 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 FailedInnerCall();
        }
    }
}
IRouterClient.sol 43 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {Client} from "../libraries/Client.sol";

interface IRouterClient {
  error UnsupportedDestinationChain(uint64 destChainSelector);
  error InsufficientFeeTokenAmount();
  error InvalidMsgValue();

  /// @notice Checks if the given chain ID is supported for sending/receiving.
  /// @param chainSelector The chain to check.
  /// @return supported is true if it is supported, false if not.
  function isChainSupported(uint64 chainSelector) external view returns (bool supported);

  /// @notice Gets a list of all supported tokens which can be sent or received
  /// to/from a given chain id.
  /// @param chainSelector The chainSelector.
  /// @return tokens The addresses of all tokens that are supported.
  function getSupportedTokens(uint64 chainSelector) external view returns (address[] memory tokens);

  /// @param destinationChainSelector The destination chainSelector
  /// @param message The cross-chain CCIP message including data and/or tokens
  /// @return fee returns execution fee for the message
  /// delivery to destination chain, denominated in the feeToken specified in the message.
  /// @dev Reverts with appropriate reason upon invalid message.
  function getFee(
    uint64 destinationChainSelector,
    Client.EVM2AnyMessage memory message
  ) external view returns (uint256 fee);

  /// @notice Request a message to be sent to the destination chain
  /// @param destinationChainSelector The destination chain ID
  /// @param message The cross-chain CCIP message including data and/or tokens
  /// @return messageId The message ID
  /// @dev Note if msg.value is larger than the required fee (from getFee) we accept
  /// the overpayment with no refund.
  /// @dev Reverts with appropriate reason upon invalid message.
  function ccipSend(
    uint64 destinationChainSelector,
    Client.EVM2AnyMessage calldata message
  ) external payable returns (bytes32);
}
Client.sol 38 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

// End consumer library.
library Client {
  /// @dev RMN depends on this struct, if changing, please notify the RMN maintainers.
  struct EVMTokenAmount {
    address token; // token address on the local chain.
    uint256 amount; // Amount of tokens.
  }

  struct Any2EVMMessage {
    bytes32 messageId; // MessageId corresponding to ccipSend on source.
    uint64 sourceChainSelector; // Source chain selector.
    bytes sender; // abi.decode(sender) if coming from an EVM chain.
    bytes data; // payload sent in original message.
    EVMTokenAmount[] destTokenAmounts; // Tokens and their amounts in their destination chain representation.
  }

  // If extraArgs is empty bytes, the default is 200k gas limit.
  struct EVM2AnyMessage {
    bytes receiver; // abi.encode(receiver address) for dest EVM chains
    bytes data; // Data payload
    EVMTokenAmount[] tokenAmounts; // Token transfers
    address feeToken; // Address of feeToken. address(0) means you will send msg.value.
    bytes extraArgs; // Populate this with _argsToBytes(EVMExtraArgsV1)
  }

  // bytes4(keccak256("CCIP EVMExtraArgsV1"));
  bytes4 public constant EVM_EXTRA_ARGS_V1_TAG = 0x97a657c9;
  struct EVMExtraArgsV1 {
    uint256 gasLimit;
  }

  function _argsToBytes(EVMExtraArgsV1 memory extraArgs) internal pure returns (bytes memory bts) {
    return abi.encodeWithSelector(EVM_EXTRA_ARGS_V1_TAG, extraArgs);
  }
}
CCIPReceiver.sol 59 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {IAny2EVMMessageReceiver} from "../interfaces/IAny2EVMMessageReceiver.sol";

import {Client} from "../libraries/Client.sol";

import {IERC165} from "../../vendor/openzeppelin-solidity/v4.8.3/contracts/utils/introspection/IERC165.sol";

/// @title CCIPReceiver - Base contract for CCIP applications that can receive messages.
abstract contract CCIPReceiver is IAny2EVMMessageReceiver, IERC165 {
  address internal immutable i_ccipRouter;

  constructor(address router) {
    if (router == address(0)) revert InvalidRouter(address(0));
    i_ccipRouter = router;
  }

  /// @notice IERC165 supports an interfaceId
  /// @param interfaceId The interfaceId to check
  /// @return true if the interfaceId is supported
  /// @dev Should indicate whether the contract implements IAny2EVMMessageReceiver
  /// e.g. return interfaceId == type(IAny2EVMMessageReceiver).interfaceId || interfaceId == type(IERC165).interfaceId
  /// This allows CCIP to check if ccipReceive is available before calling it.
  /// If this returns false or reverts, only tokens are transferred to the receiver.
  /// If this returns true, tokens are transferred and ccipReceive is called atomically.
  /// Additionally, if the receiver address does not have code associated with
  /// it at the time of execution (EXTCODESIZE returns 0), only tokens will be transferred.
  function supportsInterface(bytes4 interfaceId) public pure virtual override returns (bool) {
    return interfaceId == type(IAny2EVMMessageReceiver).interfaceId || interfaceId == type(IERC165).interfaceId;
  }

  /// @inheritdoc IAny2EVMMessageReceiver
  function ccipReceive(Client.Any2EVMMessage calldata message) external virtual override onlyRouter {
    _ccipReceive(message);
  }

  /// @notice Override this function in your implementation.
  /// @param message Any2EVMMessage
  function _ccipReceive(Client.Any2EVMMessage memory message) internal virtual;

  /////////////////////////////////////////////////////////////////////
  // Plumbing
  /////////////////////////////////////////////////////////////////////

  /// @notice Return the current router
  /// @return CCIP router address
  function getRouter() public view returns (address) {
    return address(i_ccipRouter);
  }

  error InvalidRouter(address router);

  /// @dev only calls from the set router are accepted.
  modifier onlyRouter() {
    if (msg.sender != address(i_ccipRouter)) revert InvalidRouter(msg.sender);
    _;
  }
}
Ownable.sol 100 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;

import {Context} from "../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.
 *
 * The initial owner is set to the address provided by the deployer. 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;

    /**
     * @dev The caller account is not authorized to perform an operation.
     */
    error OwnableUnauthorizedAccount(address account);

    /**
     * @dev The owner is not a valid owner account. (eg. `address(0)`)
     */
    error OwnableInvalidOwner(address owner);

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.
     */
    constructor(address initialOwner) {
        if (initialOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(initialOwner);
    }

    /**
     * @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 {
        if (owner() != _msgSender()) {
            revert OwnableUnauthorizedAccount(_msgSender());
        }
    }

    /**
     * @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 {
        if (newOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _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);
    }
}
IAny2EVMMessageReceiver.sol 15 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {Client} from "../libraries/Client.sol";

/// @notice Application contracts that intend to receive messages from
/// the router should implement this interface.
interface IAny2EVMMessageReceiver {
  /// @notice Called by the Router to deliver a message.
  /// If this reverts, any token transfers also revert. The message
  /// will move to a FAILED state and become available for manual execution.
  /// @param message CCIP Message
  /// @dev Note ensure you check the msg.sender is the OffRampRouter
  function ccipReceive(Client.Any2EVMMessage calldata message) external;
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
Context.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;

/**
 * @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;
    }

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}

Read Contract

TRUF_TOKEN 0x09f45236 → address
getFee 0xdc4ca20c → uint256
getRouter 0xb0f479a1 → address
isMessageBridge 0x4c2aebdb → bool
owner 0x8da5cb5b → address
status 0x200d2ed2 → uint8
supportsInterface 0x01ffc9a7 → bool

Write Contract 8 functions

These functions modify contract state and require a wallet transaction to execute.

ccipReceive 0xb503dfa3
tuple message
renounceOwnership 0x715018a6
No parameters
sendMessagePayNative 0xe94e1b85
uint64 destinationChainSelector
address messageBridge
address recipient
uint256 amount
setMessageBridges 0x110a5a0b
bool isEnabled
setMessageBridges 0x35bc2529
uint64[] chainSelectors
address messageBridge
bool setActive
transferOwnership 0xf2fde38b
address newOwner
withdrawEth 0x25e16063
address beneficiary
withdrawTokens 0xa522ad25
address beneficiary
address token

Recent Transactions

No transactions found for this address