ETH Price: $2,606.57 (-0.34%)

Contract

0xD04FCC255AaDF72EEef511454501b5ecE7FA0dba

Overview

ETH Balance

0 ETH

ETH Value

$0.00

Sponsored

Transaction Hash
Method
Block
From
To
0x60806040283445052022-10-09 6:41:48738 days ago1665297708IN
 Contract Creation
0 ETH0.0038508210380.001

Advanced mode:
Parent Transaction Hash Block From To
View All Internal Transactions

Loading...
Loading

Similar Match Source Code
This contract matches the deployed Bytecode of the Source Code for Contract 0xB818378d...b809c61B9
The constructor portion of the code might be different and could alter the actual behaviour of the contract

Contract Name:
StargateAdapter

Compiler Version
v0.8.15+commit.e14f2714

Optimization Enabled:
Yes with 800 runs

Other Settings:
default evmVersion
File 1 of 12 : StargateAdapter.sol
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity >=0.8.15;

import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

import "../interfaces/IBridgeAdapter.sol";
import "../interfaces/IBridgeStargate.sol";
import "../interfaces/ITransferSwapper.sol";
import "../interfaces/IWETH.sol";

contract StargateAdapter is IBridgeAdapter, Ownable {
    using SafeERC20 for IERC20;
    
    address public mainContract;
    mapping(address => bool) public supportedRouters;
    mapping(bytes32 => bool) public transfers;

    event MainContractUpdated(address mainContract);
    event SupportedRouterUpdated(address router, bool enabled);

    modifier onlyMainContract() {
        require(msg.sender == mainContract, "caller is not main contract");
        _;
    }

    constructor(address _mainContract, address[] memory _routers) {
        mainContract = _mainContract;
        for (uint256 i = 0; i < _routers.length; i++) {
            require(_routers[i] != address(0), "nop");
            supportedRouters[_routers[i]] = true;
        }
    }

    struct StargateParams {
        // a unique identifier that is uses to dedup transfers
        // this value is the a timestamp sent from frontend, but in theory can be any unique number
        uint64 nonce;
        uint256 srcPoolId;
        uint256 dstPoolId;
        uint256 minReceivedAmt; // defines the slippage, the min qty you would accept on the destination
        uint16 stargateDstChainId; // stargate defines chain id in its way
        address router; // the target router, should be in the <ref>supportedRouters</ref>
    }

    function bridge(
        uint64 _dstChainId,
        address _receiver,
        uint256 _amount,
        address _token,
        bytes memory _bridgeParams,
        bytes memory //_requestMessage // Not used for now, as stargate messaging is not supported in this version
    ) external payable onlyMainContract returns (bytes memory bridgeResp) {
        StargateParams memory params = abi.decode((_bridgeParams), (StargateParams));
        require(supportedRouters[params.router], "illegal router");
        
        bytes32 transferId = keccak256(
            abi.encodePacked(_receiver, _token, _amount, _dstChainId, params.nonce, uint64(block.chainid))
        );
        require(transfers[transferId] == false, "transfer exists");
        transfers[transferId] = true;
        IERC20(_token).safeTransferFrom(msg.sender, address(this), _amount);
        uint64 outboundNonce = swap(_token, _receiver, _amount, params);
        return abi.encodePacked(outboundNonce);
    }

    function swap(
        address _token, 
        address _receiver,
        uint256 _amount,
        StargateParams memory params) private returns (uint64 outboundNonce) {
        IBridgeStargate router = IBridgeStargate(params.router);
        ITransferSwapper main = ITransferSwapper(mainContract);
        if (_token == main.nativeWrap()) {
            IWETH(_token).withdraw(_amount);
            router.swapETH{value: msg.value + _amount}(
                params.stargateDstChainId, 
                payable(mainContract),
                abi.encodePacked(_receiver), 
                _amount, 
                params.minReceivedAmt);
        } else {
            IERC20(_token).safeApprove(params.router, _amount);
            router.swap{value: msg.value}(
                params.stargateDstChainId, 
                params.srcPoolId, 
                params.dstPoolId, 
                payable(mainContract), // default to refund to main contract
                _amount,
                params.minReceivedAmt, 
                IBridgeStargate.lzTxObj(0, 0, "0x"), 
                abi.encodePacked(_receiver), 
                bytes("") // not supported additional msg in this version
            );
            IERC20(_token).safeApprove(params.router, 0);
        }

        // query current nonce
        address stargateInternalBridge;
        if (_token == main.nativeWrap()) {
            stargateInternalBridge = IBridgeStargate(router.stargateRouter()).bridge();
        } else {
            stargateInternalBridge = router.bridge();
        }
        address layerZeroEndpoint = IStargateInternalBridge(stargateInternalBridge).layerZeroEndpoint();
        outboundNonce = ILayerZeroEndpoint(layerZeroEndpoint).getOutboundNonce(params.stargateDstChainId, stargateInternalBridge);
    }

    function updateMainContract(address _mainContract) external onlyOwner {
        mainContract = _mainContract;
        emit MainContractUpdated(_mainContract);
    }

    function setSupportedRouter(address _router, bool _enabled) external onlyOwner {
        bool enabled = supportedRouters[_router];
        require(enabled != _enabled, "nop");
        supportedRouters[_router] = _enabled;
        emit SupportedRouterUpdated(_router, _enabled);
    }

    // This is needed to receive ETH when calling `IWETH.withdraw`
    receive() external payable {}
}

File 2 of 12 : SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../extensions/draft-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;

    function safeTransfer(
        IERC20 token,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    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));
    }

    function safeIncreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        uint256 newAllowance = token.allowance(address(this), spender) + value;
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    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");
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
        }
    }

    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");
        if (returndata.length > 0) {
            // Return data is optional
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}

File 3 of 12 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.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);
}

File 4 of 12 : Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.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 anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing 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);
    }
}

File 5 of 12 : IBridgeAdapter.sol
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity >=0.8.15;

interface IBridgeAdapter {
    function bridge(
        uint64 _dstChainId,
        // the address that the fund is transfered to on the destination chain
        address _receiver,
        uint256 _amount,
        address _token,
        // Bridge transfers quoted and abi encoded by chainhop backend server.
        // Bridge adapter implementations need to decode this themselves.
        bytes memory _bridgeParams,
        // The message to be bridged alongside the transfer.
        // Note if the bridge adapter doesn't support message passing, the call should revert when
        // this field is set.
        bytes memory _requestMessage
    ) external payable returns (bytes memory bridgeResp);
}

File 6 of 12 : IBridgeStargate.sol
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity >=0.8.15;

interface IBridgeStargate {
    struct lzTxObj {
        uint256 dstGasForCall;
        uint256 dstNativeAmount;
        bytes dstNativeAddr;
    }

    // only in non RouterETH
    function swap(
        uint16 _dstChainId,
        uint256 _srcPoolId,
        uint256 _dstPoolId,
        address payable _refundAddress,
        uint256 _amountLD,
        uint256 _minAmountLD,
        lzTxObj memory _lzTxParams,
        bytes calldata _to,
        bytes calldata _payload
    ) external payable;
    // only in non RouterETH
    function bridge() external pure returns (address);

    // only in RouterETH
    function swapETH(
        uint16 _dstChainId,                         // destination Stargate chainId
        address payable _refundAddress,             // refund additional messageFee to this address
        bytes calldata _toAddress,                  // the receiver of the destination ETH
        uint256 _amountLD,                          // the amount, in Local Decimals, to be swapped
        uint256 _minAmountLD                        // the minimum amount accepted out on destination
    ) external payable;
    // only in RouterETH
    function stargateRouter() external pure returns (address);
}

interface IStargateInternalBridge {
    function layerZeroEndpoint() external pure returns (address);
}

interface ILayerZeroEndpoint {
    function getOutboundNonce(uint16 _dstChainId, address _srcAddress) external view returns (uint64);
}

File 7 of 12 : ITransferSwapper.sol
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity >=0.8.15;

import "./IMessageReceiverApp.sol";

interface ITransferSwapper {
    function nativeWrap() external view returns (address);

    /**
     * @notice Called by MessageBus (MessageBusReceiver) to process refund of the original transfer from this contract
     * @param _token The token address of the original transfer
     * @param _amount The amount of the original transfer
     * @param _message The same message associated with the original transfer
     * @param _executor Address who called the MessageBus execution function
     */
    function executeMessageWithTransferRefundFromAdapter(
        address _token,
        uint256 _amount,
        bytes calldata _message,
        address _executor
    ) external payable returns (IMessageReceiverApp.ExecutionStatus);
}

File 8 of 12 : IWETH.sol
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity >=0.8.15;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

interface IWETH is IERC20 {
    function deposit() external payable;

    function withdraw(uint256) external;
}

File 9 of 12 : draft-IERC20Permit.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-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);
}

File 10 of 12 : Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.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
     * ====
     *
     * [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://diligence.consensys.net/posts/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.5.11/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 functionCall(target, data, "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");
        require(isContract(target), "Address: call to non-contract");

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(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) {
        require(isContract(target), "Address: static call to non-contract");

        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResult(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) {
        require(isContract(target), "Address: delegate call to non-contract");

        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason 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 {
            // 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);
            }
        }
    }
}

File 11 of 12 : 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;
    }
}

File 12 of 12 : IMessageReceiverApp.sol
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity >=0.8.0;

interface IMessageReceiverApp {
    enum ExecutionStatus {
        Fail, // execution failed, finalized
        Success, // execution succeeded, finalized
        Retry // execution rejected, can retry later
    }

    /**
     * @notice Called by MessageBus (MessageBusReceiver) if the process is originated from MessageBus (MessageBusSender)'s
     *         sendMessageWithTransfer it is only called when the tokens are checked to be arrived at this contract's address.
     * @param _sender The address of the source app contract
     * @param _token The address of the token that comes out of the bridge
     * @param _amount The amount of tokens received at this contract through the cross-chain bridge.
     *        the contract that implements this contract can safely assume that the tokens will arrive before this
     *        function is called.
     * @param _srcChainId The source chain ID where the transfer is originated from
     * @param _message Arbitrary message bytes originated from and encoded by the source app contract
     * @param _executor Address who called the MessageBus execution function
     */
    function executeMessageWithTransfer(
        address _sender,
        address _token,
        uint256 _amount,
        uint64 _srcChainId,
        bytes calldata _message,
        address _executor
    ) external payable returns (ExecutionStatus);

    /**
     * @notice Only called by MessageBus (MessageBusReceiver) if
     *         1. executeMessageWithTransfer reverts, or
     *         2. executeMessageWithTransfer returns ExecutionStatus.Fail
     * @param _sender The address of the source app contract
     * @param _token The address of the token that comes out of the bridge
     * @param _amount The amount of tokens received at this contract through the cross-chain bridge.
     *        the contract that implements this contract can safely assume that the tokens will arrive before this
     *        function is called.
     * @param _srcChainId The source chain ID where the transfer is originated from
     * @param _message Arbitrary message bytes originated from and encoded by the source app contract
     * @param _executor Address who called the MessageBus execution function
     */
    function executeMessageWithTransferFallback(
        address _sender,
        address _token,
        uint256 _amount,
        uint64 _srcChainId,
        bytes calldata _message,
        address _executor
    ) external payable returns (ExecutionStatus);

    /**
     * @notice Called by MessageBus (MessageBusReceiver) to process refund of the original transfer from this contract
     * @param _token The token address of the original transfer
     * @param _amount The amount of the original transfer
     * @param _message The same message associated with the original transfer
     * @param _executor Address who called the MessageBus execution function
     */
    function executeMessageWithTransferRefund(
        address _token,
        uint256 _amount,
        bytes calldata _message,
        address _executor
    ) external payable returns (ExecutionStatus);

    /**
     * @notice Called by MessageBus (MessageBusReceiver)
     * @param _sender The address of the source app contract
     * @param _srcChainId The source chain ID where the transfer is originated from
     * @param _message Arbitrary message bytes originated from and encoded by the source app contract
     * @param _executor Address who called the MessageBus execution function
     */
    function executeMessage(
        address _sender,
        uint64 _srcChainId,
        bytes calldata _message,
        address _executor
    ) external payable returns (ExecutionStatus);
}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 800,
    "details": {
      "yul": false
    }
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "metadata": {
    "useLiteralContent": true
  },
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"_mainContract","type":"address"},{"internalType":"address[]","name":"_routers","type":"address[]"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"mainContract","type":"address"}],"name":"MainContractUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"router","type":"address"},{"indexed":false,"internalType":"bool","name":"enabled","type":"bool"}],"name":"SupportedRouterUpdated","type":"event"},{"inputs":[{"internalType":"uint64","name":"_dstChainId","type":"uint64"},{"internalType":"address","name":"_receiver","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"address","name":"_token","type":"address"},{"internalType":"bytes","name":"_bridgeParams","type":"bytes"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"bridge","outputs":[{"internalType":"bytes","name":"bridgeResp","type":"bytes"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"mainContract","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_router","type":"address"},{"internalType":"bool","name":"_enabled","type":"bool"}],"name":"setSupportedRouter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"supportedRouters","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"transfers","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_mainContract","type":"address"}],"name":"updateMainContract","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]

Deployed Bytecode

0x60806040526004361061009a5760003560e01c80639879c48d11610069578063df8bbc591161004e578063df8bbc591461019a578063f2fde38b146101ba578063f8e9c5c0146101da57600080fd5b80639879c48d1461014a578063d270e7ab1461017a57600080fd5b80633c64f04b146100a6578063715018a6146100ec578063834bc3ea146101035780638da5cb5b1461012357600080fd5b366100a157005b600080fd5b3480156100b257600080fd5b506100d66100c1366004610db4565b60036020526000908152604090205460ff1681565b6040516100e39190610ddf565b60405180910390f35b3480156100f857600080fd5b506101016101fa565b005b610116610111366004610f28565b61020e565b6040516100e39190611046565b34801561012f57600080fd5b506000546001600160a01b03165b6040516100e39190611060565b34801561015657600080fd5b506100d661016536600461106e565b60026020526000908152604090205460ff1681565b34801561018657600080fd5b5060015461013d906001600160a01b031681565b3480156101a657600080fd5b506101016101b536600461106e565b61036d565b3480156101c657600080fd5b506101016101d536600461106e565b6103d8565b3480156101e657600080fd5b506101016101f53660046110a2565b610412565b6102026104bc565b61020c60006104e6565b565b6001546060906001600160a01b031633146102445760405162461bcd60e51b815260040161023b90611116565b60405180910390fd5b60008380602001905181019061025a91906111f6565b60a08101516001600160a01b031660009081526002602052604090205490915060ff166102995760405162461bcd60e51b815260040161023b9061124b565b80516040516000916102b7918a9189918b918e9146906020016112a8565b60408051601f1981840301815291815281516020928301206000818152600390935291205490915060ff16156102ff5760405162461bcd60e51b815260040161023b90611346565b6000818152600360205260409020805460ff1916600117905561032d6001600160a01b03871633308a610543565b600061033b878a8a866105ce565b90508060405160200161034e9190611356565b60405160208183030381529060405293505050505b9695505050505050565b6103756104bc565b6001805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b0383161790556040517f50d0cbf2750e0276715bec254c588e057e0b05e87927eab7ebbad47fe1e88b4b906103cd908390611060565b60405180910390a150565b6103e06104bc565b6001600160a01b0381166104065760405162461bcd60e51b815260040161023b906113c8565b61040f816104e6565b50565b61041a6104bc565b6001600160a01b03821660009081526002602052604090205460ff16811515811515036104595760405162461bcd60e51b815260040161023b906113f2565b6001600160a01b03831660009081526002602052604090819020805460ff1916841515179055517f19df4f9d38a9b103263e051a2824d8cd9cd6dc4205d136abbd3932a9eeede061906104af9085908590611402565b60405180910390a1505050565b6000546001600160a01b0316331461020c5760405162461bcd60e51b815260040161023b9061144f565b600080546001600160a01b0383811673ffffffffffffffffffffffffffffffffffffffff19831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6105c8846323b872dd60e01b8585856040516024016105649392919061145f565b60408051601f198184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff0000000000000000000000000000000000000000000000000000000090931692909217909152610b38565b50505050565b60a08101516001546040805163457bfa2f60e01b81529051600093926001600160a01b031691829163457bfa2f916004808201926020929091908290030181865afa158015610621573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106459190611487565b6001600160a01b0316876001600160a01b03160361076757604051632e1a7d4d60e01b81526001600160a01b03881690632e1a7d4d906106899088906004016114a8565b600060405180830381600087803b1580156106a357600080fd5b505af11580156106b7573d6000803e3d6000fd5b50505050816001600160a01b0316631114cd2a86346106d691906114cc565b60808701516001546040516001600160a01b03909116906106fb908c906020016114e4565b6040516020818303038152906040528a8a606001516040518763ffffffff1660e01b8152600401610730959493929190611503565b6000604051808303818588803b15801561074957600080fd5b505af115801561075d573d6000803e3d6000fd5b50505050506108a7565b60a0840151610781906001600160a01b0389169087610bcc565b816001600160a01b0316639fbf10fc34866080015187602001518860400151600160009054906101000a90046001600160a01b03168b8b606001516040518060600160405280600081526020016000815260200160405180604001604052806002815260200161060f60f31b8152508152508f60405160200161080491906114e4565b60408051601f198184030181526020830182526000835290517fffffffff0000000000000000000000000000000000000000000000000000000060e08d901b16815261085a999897969594939290600401611594565b6000604051808303818588803b15801561087357600080fd5b505af1158015610887573d6000803e3d6000fd5b50505060a08601516108a792506001600160a01b038a1691506000610bcc565b6000816001600160a01b031663457bfa2f6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156108e7573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061090b9190611487565b6001600160a01b0316886001600160a01b0316036109ed57826001600160a01b031663a9e56f3c6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610961573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109859190611487565b6001600160a01b031663e78cea926040518163ffffffff1660e01b8152600401602060405180830381865afa1580156109c2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109e69190611487565b9050610a52565b826001600160a01b031663e78cea926040518163ffffffff1660e01b8152600401602060405180830381865afa158015610a2b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a4f9190611487565b90505b6000816001600160a01b03166307968db16040518163ffffffff1660e01b8152600401602060405180830381865afa158015610a92573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ab69190611487565b6080870151604051630f428ae960e31b81529192506001600160a01b03831691637a14574891610aea91869060040161162e565b602060405180830381865afa158015610b07573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b2b9190611649565b9998505050505050505050565b6000610b8d826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316610c809092919063ffffffff16565b805190915015610bc75780806020019051810190610bab9190611675565b610bc75760405162461bcd60e51b815260040161023b906116f0565b505050565b801580610c455750604051636eb1769f60e11b81526001600160a01b0384169063dd62ed3e90610c029030908690600401611700565b602060405180830381865afa158015610c1f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c43919061170e565b155b610c615760405162461bcd60e51b815260040161023b90611789565b610bc78363095ea7b360e01b8484604051602401610564929190611799565b6060610c8f8484600085610c99565b90505b9392505050565b606082471015610cbb5760405162461bcd60e51b815260040161023b9061180e565b6001600160a01b0385163b610ce25760405162461bcd60e51b815260040161023b90611852565b600080866001600160a01b03168587604051610cfe9190611884565b60006040518083038185875af1925050503d8060008114610d3b576040519150601f19603f3d011682016040523d82523d6000602084013e610d40565b606091505b5091509150610d50828286610d5d565b925050505b949350505050565b60608315610d6c575081610c92565b825115610d7c5782518084602001fd5b8160405162461bcd60e51b815260040161023b9190611046565b805b811461040f57600080fd5b8035610dae81610d96565b92915050565b600060208284031215610dc957610dc9600080fd5b6000610d558484610da3565b8015155b82525050565b60208101610dae8284610dd5565b67ffffffffffffffff8116610d98565b8035610dae81610ded565b60006001600160a01b038216610dae565b610d9881610e08565b8035610dae81610e19565b634e487b7160e01b600052604160045260246000fd5b601f19601f830116810181811067ffffffffffffffff82111715610e6957610e69610e2d565b6040525050565b6000610e7b60405190565b9050610e878282610e43565b919050565b600067ffffffffffffffff821115610ea657610ea6610e2d565b601f19601f83011660200192915050565b82818337506000910152565b6000610ed6610ed184610e8c565b610e70565b905082815260208101848484011115610ef157610ef1600080fd5b610efc848285610eb7565b509392505050565b600082601f830112610f1857610f18600080fd5b8135610d55848260208601610ec3565b60008060008060008060c08789031215610f4457610f44600080fd5b6000610f508989610dfd565b9650506020610f6189828a01610e22565b9550506040610f7289828a01610da3565b9450506060610f8389828a01610e22565b935050608087013567ffffffffffffffff811115610fa357610fa3600080fd5b610faf89828a01610f04565b92505060a087013567ffffffffffffffff811115610fcf57610fcf600080fd5b610fdb89828a01610f04565b9150509295509295509295565b60005b83811015611003578181015183820152602001610feb565b838111156105c85750506000910152565b600061101e825190565b808452602084019350611035818560208601610fe8565b601f01601f19169290920192915050565b60208082528101610c928184611014565b610dd981610e08565b60208101610dae8284611057565b60006020828403121561108357611083600080fd5b6000610d558484610e22565b801515610d98565b8035610dae8161108f565b600080604083850312156110b8576110b8600080fd5b60006110c48585610e22565b92505060206110d585828601611097565b9150509250929050565b601b81526000602082017f63616c6c6572206973206e6f74206d61696e20636f6e74726163740000000000815291505b5060200190565b60208082528101610dae816110df565b8051610dae81610ded565b8051610dae81610d96565b61ffff8116610d98565b8051610dae8161113c565b8051610dae81610e19565b600060c0828403121561117157611171600080fd5b61117b60c0610e70565b905060006111898484611126565b825250602061119a84848301611131565b60208301525060406111ae84828501611131565b60408301525060606111c284828501611131565b60608301525060806111d684828501611146565b60808301525060a06111ea84828501611151565b60a08301525092915050565b600060c0828403121561120b5761120b600080fd5b6000610d55848461115c565b600e81526000602082017f696c6c6567616c20726f757465720000000000000000000000000000000000008152915061110f565b60208082528101610dae81611217565b6000610dae8260601b90565b6000610dae8261125b565b610dd961127e82610e08565b611267565b80610dd9565b6000610dae8260c01b90565b610dd967ffffffffffffffff8216611289565b60006112b48289611272565b6014820191506112c48288611272565b6014820191506112d48287611283565b6020820191506112e48286611295565b6008820191506112f48285611295565b6008820191506113048284611295565b506008019695505050505050565b600f81526000602082017f7472616e736665722065786973747300000000000000000000000000000000008152915061110f565b60208082528101610dae81611312565b60006113628284611295565b50600801919050565b602681526000602082017f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206181527f6464726573730000000000000000000000000000000000000000000000000000602082015291505b5060400190565b60208082528101610dae8161136b565b600381526000602082016206e6f760ec1b8152915061110f565b60208082528101610dae816113d8565b604081016114108285611057565b610c926020830184610dd5565b60208082527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65729101908152600061110f565b60208082528101610dae8161141d565b6060810161146d8286611057565b61147a6020830185611057565b610d556040830184611283565b60006020828403121561149c5761149c600080fd5b6000610d558484611151565b60208101610dae8284611283565b634e487b7160e01b600052601160045260246000fd5b600082198211156114df576114df6114b6565b500190565b60006114f08284611272565b50601401919050565b61ffff8116610dd9565b60a0810161151182886114f9565b61151e6020830187611057565b81810360408301526115308186611014565b905061153f6060830185611283565b6103636080830184611283565b805160009060608401906115608582611283565b5060208301516115736020860182611283565b506040830151848203604086015261158b8282611014565b95945050505050565b61012081016115a3828c6114f9565b6115b0602083018b611283565b6115bd604083018a611283565b6115ca6060830189611057565b6115d76080830188611283565b6115e460a0830187611283565b81810360c08301526115f6818661154c565b905081810360e083015261160a8185611014565b905081810361010083015261161f8184611014565b9b9a5050505050505050505050565b6040810161163c82856114f9565b610c926020830184611057565b60006020828403121561165e5761165e600080fd5b6000610d558484611126565b8051610dae8161108f565b60006020828403121561168a5761168a600080fd5b6000610d55848461166a565b602a81526000602082017f5361666545524332303a204552433230206f7065726174696f6e20646964206e81527f6f74207375636365656400000000000000000000000000000000000000000000602082015291506113c1565b60208082528101610dae81611696565b6040810161163c8285611057565b60006020828403121561172357611723600080fd5b6000610d558484611131565b603681526000602082017f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f81527f20746f206e6f6e2d7a65726f20616c6c6f77616e636500000000000000000000602082015291506113c1565b60208082528101610dae8161172f565b604081016117a78285611057565b610c926020830184611283565b602681526000602082017f416464726573733a20696e73756666696369656e742062616c616e636520666f81527f722063616c6c0000000000000000000000000000000000000000000000000000602082015291506113c1565b60208082528101610dae816117b4565b601d81526000602082017f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000008152915061110f565b60208082528101610dae8161181e565b600061186c825190565b61187a818560208601610fe8565b9290920192915050565b6000610c92828461186256fea2646970667358221220c57933341ff66d5c2346f0260999e4832000646ffb77831e65dee62de057e9f964736f6c634300080f0033

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
[ Download: CSV Export  ]

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.