Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0xd737D99D86b1814dfB3cA2307f3C0Ea28f26B716
Balance 0 ETH
Nonce 1
Code Size 10008 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

10008 bytes
0x608060405260043610610170575f3560e01c806365f20454116100c6578063a2011b3f1161007c578063d547741f11610057578063d547741f14610581578063e26bbe80146105a0578063f887ea40146105bf575f5ffd5b8063a2011b3f14610508578063a217fddf1461053b578063b1a9f8091461054e575f5ffd5b8063752d5181116100ac578063752d5181146104655780637770ff9b146104a657806391d14854146104b9575f5ffd5b806365f20454146104135780636df4200714610446575f5ffd5b806325f5042c1161012657806336568abe1161010157806336568abe146103ae5780633fc8cef3146103cd5780634f1ffc6414610400575f5ffd5b806325f5042c1461033d5780632f2ff15d1461035c5780632f90b1841461037b575f5ffd5b80630ddc5216116101565780630ddc5216146101d0578063210452c514610247578063248a9ca314610301575f5ffd5b806301ffc9a71461017b5780630b799d95146101af575f5ffd5b3661017757005b5f5ffd5b348015610186575f5ffd5b5061019a6101953660046121b9565b6105eb565b60405190151581526020015b60405180910390f35b3480156101ba575f5ffd5b506101ce6101c9366004612220565b610683565b005b3480156101db575f5ffd5b506102226101ea36600461225f565b5f91825260026020908152604080842073ffffffffffffffffffffffffffffffffffffffff9384168552600101909152909120541690565b60405173ffffffffffffffffffffffffffffffffffffffff90911681526020016101a6565b348015610252575f5ffd5b506102bd61026136600461228d565b600160208190525f9182526040909120805491015473ffffffffffffffffffffffffffffffffffffffff8083169263ffffffff740100000000000000000000000000000000000000009182900481169392831692919091041684565b6040805173ffffffffffffffffffffffffffffffffffffffff958616815263ffffffff948516602082015294909216918401919091521660608201526080016101a6565b34801561030c575f5ffd5b5061032f61031b36600461228d565b5f9081526020819052604090206001015490565b6040519081526020016101a6565b348015610348575f5ffd5b506101ce6103573660046122bc565b610820565b348015610367575f5ffd5b506101ce61037636600461225f565b610b6f565b348015610386575f5ffd5b5061032f7f000000000000000000000000000000000000000000000000000000000000000181565b3480156103b9575f5ffd5b506101ce6103c836600461225f565b610b99565b3480156103d8575f5ffd5b506102227f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281565b6101ce61040e36600461235f565b610bf7565b34801561041e575f5ffd5b5061019a7f000000000000000000000000000000000000000000000000000000000000000081565b348015610451575f5ffd5b506101ce6104603660046123d6565b611166565b348015610470575f5ffd5b5061022261047f36600461228d565b60026020525f908152604090205473ffffffffffffffffffffffffffffffffffffffff1681565b6101ce6104b43660046123f1565b61124c565b3480156104c4575f5ffd5b5061019a6104d336600461225f565b5f9182526020828152604080842073ffffffffffffffffffffffffffffffffffffffff93909316845291905290205460ff1690565b348015610513575f5ffd5b5061032f7f61c92169ef077349011ff0b1383c894d86c5f0b41d986366b58a6cf31e93beda81565b348015610546575f5ffd5b5061032f5f81565b348015610559575f5ffd5b5061032f7fc4c453d647953c0fd35db5a34ee76e60fb4abc3a8fb891a25936b70b38f2925381565b34801561058c575f5ffd5b506101ce61059b36600461225f565b611515565b3480156105ab575f5ffd5b506101ce6105ba36600461225f565b611539565b3480156105ca575f5ffd5b506003546102229073ffffffffffffffffffffffffffffffffffffffff1681565b5f7fffffffff0000000000000000000000000000000000000000000000000000000082167f7965db0b00000000000000000000000000000000000000000000000000000000148061067d57507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008316145b92915050565b7f61c92169ef077349011ff0b1383c894d86c5f0b41d986366b58a6cf31e93beda6106ad816116a0565b73ffffffffffffffffffffffffffffffffffffffff831615806106e4575073ffffffffffffffffffffffffffffffffffffffff8216155b1561071b576040517fd92e233d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b468403610754576040517f8f3019f900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b835f0361078d576040517fc84885d400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f84815260026020908152604080832073ffffffffffffffffffffffffffffffffffffffff878116808652600190920190935281842080547fffffffffffffffffffffffff000000000000000000000000000000000000000016938716938417905590519192909187917f4cc69fdfa9b0adfd49c511145d4a4a32a08af5627208393e7d8fe525347a559a91a450505050565b7f61c92169ef077349011ff0b1383c894d86c5f0b41d986366b58a6cf31e93beda61084a816116a0565b73ffffffffffffffffffffffffffffffffffffffff85161580610881575073ffffffffffffffffffffffffffffffffffffffff8416155b156108b8576040517fd92e233d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b63ffffffff831615806108cf575063ffffffff8216155b15610906576040517f3e267f9500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b7f0000000000000000000000000000000000000000000000000000000000000000801561095357507f00000000000000000000000000000000000000000000000000000000000000018614155b15610992576040517f6d09e79d000000000000000000000000000000000000000000000000000000008152600481018790526024015b60405180910390fd5b4686036109cb576040517f8f3019f900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b855f03610a04576040517fc84885d400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8460015f8881526020019081526020015f205f015f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508360015f8881526020019081526020015f206001015f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508260015f8881526020019081526020015f205f0160146101000a81548163ffffffff021916908363ffffffff1602179055508160015f8881526020019081526020015f2060010160146101000a81548163ffffffff021916908363ffffffff1602179055508373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff16877f404a32a413943cc7c44f18efafa9cb94bde0b81d566bfb7bd6f8304616a3ebd860405160405180910390a4505050505050565b5f82815260208190526040902060010154610b89816116a0565b610b9383836116ad565b50505050565b73ffffffffffffffffffffffffffffffffffffffff81163314610be8576040517f6697b23200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610bf282826117a6565b505050565b335f9081527f266cad2a07820380da249144ee0922486396c59c16dc4ab5f4c00611d746e9b76020526040902054859060ff16610dd3575f81815260016020818152604080842090920154600290915291205473ffffffffffffffffffffffffffffffffffffffff91821691163382141580610d0b57508073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16636e296e456040518163ffffffff1660e01b8152600401602060405180830381865afa158015610cce573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610cf2919061245f565b73ffffffffffffffffffffffffffffffffffffffff1614155b15610dd057338273ffffffffffffffffffffffffffffffffffffffff16636e296e456040518163ffffffff1660e01b8152600401602060405180830381865afa158015610d5a573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610d7e919061245f565b6040517f3ef0b10900000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff928316600482015291166024820152604401610989565b50505b6003545f9073ffffffffffffffffffffffffffffffffffffffff908116908a167fffffffffffffffffffffffff111111111111111111111111111111111111111201610e81574789811015610e78576040517f5c54305e00000000000000000000000000000000000000000000000000000000815273eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee600482015260248101829052604481018b9052606401610989565b899250506110cc565b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc273ffffffffffffffffffffffffffffffffffffffff168a73ffffffffffffffffffffffffffffffffffffffff1603610fb9574789811015610f33576040517f5c54305e00000000000000000000000000000000000000000000000000000000815273eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee600482015260248101829052604481018b9052606401610989565b8a73ffffffffffffffffffffffffffffffffffffffff1663d0e30db08b6040518263ffffffff1660e01b81526004015f604051808303818588803b158015610f79575f5ffd5b505af1158015610f8b573d5f5f3e3d5ffd5b50610fb39350505073ffffffffffffffffffffffffffffffffffffffff8d169050838c61185f565b506110cc565b6040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201525f9073ffffffffffffffffffffffffffffffffffffffff8c16906370a0823190602401602060405180830381865afa158015611023573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611047919061247a565b9050898110156110a9576040517f5c54305e00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8c16600482015260248101829052604481018b9052606401610989565b6110ca73ffffffffffffffffffffffffffffffffffffffff8c16838c61185f565b505b6040517f081afce400000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff82169063081afce490849061112c908e908e908e908e908e908e908e906004016124d8565b5f604051808303818588803b158015611143575f5ffd5b505af1158015611155573d5f5f3e3d5ffd5b505050505050505050505050505050565b7f61c92169ef077349011ff0b1383c894d86c5f0b41d986366b58a6cf31e93beda611190816116a0565b73ffffffffffffffffffffffffffffffffffffffff82166111dd576040517fd92e233d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600380547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff84169081179091556040517f69edca9b1bff03431f01e75df74158637c387906f7a0d567c810bd6c74f88395905f90a25050565b60035473ffffffffffffffffffffffffffffffffffffffff16331461129f576040517ffb217bcd000000000000000000000000000000000000000000000000000000008152336004820152602401610989565b7fffffffffffffffffffffffff111111111111111111111111111111111111111273ffffffffffffffffffffffffffffffffffffffff8716016113235761131e8686868686868080601f0160208091040260200160405190810160405280939291908181526020018383808284375f920191909152506118ba92505050565b6114b9565b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc273ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff16036114555761139873ffffffffffffffffffffffffffffffffffffffff8716333088611c3c565b6040517f2e1a7d4d0000000000000000000000000000000000000000000000000000000081526004810186905273ffffffffffffffffffffffffffffffffffffffff871690632e1a7d4d906024015f604051808303815f87803b1580156113fd575f5ffd5b505af115801561140f573d5f5f3e3d5ffd5b5050505061131e8686868686868080601f0160208091040260200160405190810160405280939291908181526020018383808284375f920191909152506118ba92505050565b61147773ffffffffffffffffffffffffffffffffffffffff8716333088611c3c565b6114b98686868686868080601f0160208091040260200160405190810160405280939291908181526020018383808284375f92019190915250611c9892505050565b82848773ffffffffffffffffffffffffffffffffffffffff167fd9f08efabccca6e1095f294adb587b14471343c38b480ce123931e3bc3d6680f8886866040516115059392919061252c565b60405180910390a4505050505050565b5f8281526020819052604090206001015461152f816116a0565b610b9383836117a6565b7f61c92169ef077349011ff0b1383c894d86c5f0b41d986366b58a6cf31e93beda611563816116a0565b46830361159c576040517f8f3019f900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff82166115e9576040517fd92e233d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b825f03611622576040517fc84885d400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f8381526002602052604080822080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff86169081179091559051909185917f49a5f7c5a0962809e89a76c379707f1f0082ae35dc525c0b9aaa8701b79cec7f9190a3505050565b6116aa8133611f31565b50565b5f8281526020818152604080832073ffffffffffffffffffffffffffffffffffffffff8516845290915281205460ff1661179f575f8381526020818152604080832073ffffffffffffffffffffffffffffffffffffffff86168452909152902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016600117905561173d3390565b73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16847f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a450600161067d565b505f61067d565b5f8281526020818152604080832073ffffffffffffffffffffffffffffffffffffffff8516845290915281205460ff161561179f575f8381526020818152604080832073ffffffffffffffffffffffffffffffffffffffff8616808552925280832080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016905551339286917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a450600161067d565b61186c8383836001611fba565b610bf2576040517f5274afe700000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff84166004820152602401610989565b5f7f00000000000000000000000000000000000000000000000000000000000000006118e65783611908565b7f00000000000000000000000000000000000000000000000000000000000000015b5f8181526001602081815260408084206002835281852073ffffffffffffffffffffffffffffffffffffffff808e168752948101909352932054815494955092939092821691168161199e576040517f359ff56f00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8b166004820152602401610989565b73ffffffffffffffffffffffffffffffffffffffff81166119ee576040517f6d09e79d00000000000000000000000000000000000000000000000000000000815260048101869052602401610989565b835473ffffffffffffffffffffffffffffffffffffffff161580611a2a5750600184015473ffffffffffffffffffffffffffffffffffffffff16155b15611a64576040517f6d09e79d00000000000000000000000000000000000000000000000000000000815260048101869052602401610989565b83546040517fe11013dd00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff82169163e11013dd918c91611adb91869174010000000000000000000000000000000000000000900463ffffffff16908c9060040161259a565b5f604051808303818588803b158015611af2575f5ffd5b505af1158015611b04573d5f5f3e3d5ffd5b50505050505f634f1ffc6460e01b838b468c8c8c604051602401611b2d969594939291906125d4565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff0000000000000000000000000000000000000000000000000000000090941693909317909252600187015491517f3dbb202b00000000000000000000000000000000000000000000000000000000815290925073ffffffffffffffffffffffffffffffffffffffff821691633dbb202b91611c25918691869163ffffffff740100000000000000000000000000000000000000009091041690600401612626565b5f604051808303815f87803b158015611143575f5ffd5b611c4a848484846001612042565b610b93576040517f5274afe700000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff85166004820152602401610989565b5f7f0000000000000000000000000000000000000000000000000000000000000000611cc45783611ce6565b7f00000000000000000000000000000000000000000000000000000000000000015b5f8181526001602081815260408084206002835281852073ffffffffffffffffffffffffffffffffffffffff808e1687529481019093529320548154949550929390928216911681611d7c576040517f359ff56f00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8b166004820152602401610989565b73ffffffffffffffffffffffffffffffffffffffff8116611dcc576040517f6d09e79d00000000000000000000000000000000000000000000000000000000815260048101869052602401610989565b835473ffffffffffffffffffffffffffffffffffffffff161580611e085750600184015473ffffffffffffffffffffffffffffffffffffffff16155b15611e42576040517f6d09e79d00000000000000000000000000000000000000000000000000000000815260048101869052602401610989565b8354611e689073ffffffffffffffffffffffffffffffffffffffff8c811691168b6120d5565b835f015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663540abf738b84848d895f0160149054906101000a900463ffffffff168c6040518763ffffffff1660e01b8152600401611ee09695949392919061266a565b5f604051808303815f87803b158015611ef7575f5ffd5b505af1158015611f09573d5f5f3e3d5ffd5b505050505f634f1ffc6460e01b838b468c8c8c604051602401611b2d969594939291906125d4565b5f8281526020818152604080832073ffffffffffffffffffffffffffffffffffffffff8516845290915290205460ff16611fb6576040517fe2517d3f00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8216600482015260248101839052604401610989565b5050565b6040517fa9059cbb000000000000000000000000000000000000000000000000000000005f81815273ffffffffffffffffffffffffffffffffffffffff8616600452602485905291602083604481808b5af1925060015f5114831661203657838315161561202a573d5f823e3d81fd5b5f873b113d1516831692505b60405250949350505050565b6040517f23b872dd000000000000000000000000000000000000000000000000000000005f81815273ffffffffffffffffffffffffffffffffffffffff8781166004528616602452604485905291602083606481808c5af1925060015f511483166120c45783831516156120b8573d5f823e3d81fd5b5f883b113d1516831692505b604052505f60605295945050505050565b6120e18383835f612149565b610bf2576120f283835f6001612149565b612140576040517f5274afe700000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff84166004820152602401610989565b61186c83838360015b6040517f095ea7b3000000000000000000000000000000000000000000000000000000005f81815273ffffffffffffffffffffffffffffffffffffffff8616600452602485905291602083604481808b5af1925060015f5114831661203657838315161561202a573d5f823e3d81fd5b5f602082840312156121c9575f5ffd5b81357fffffffff00000000000000000000000000000000000000000000000000000000811681146121f8575f5ffd5b9392505050565b73ffffffffffffffffffffffffffffffffffffffff811681146116aa575f5ffd5b5f5f5f60608486031215612232575f5ffd5b833592506020840135612244816121ff565b91506040840135612254816121ff565b809150509250925092565b5f5f60408385031215612270575f5ffd5b823591506020830135612282816121ff565b809150509250929050565b5f6020828403121561229d575f5ffd5b5035919050565b803563ffffffff811681146122b7575f5ffd5b919050565b5f5f5f5f5f60a086880312156122d0575f5ffd5b8535945060208601356122e2816121ff565b935060408601356122f2816121ff565b9250612300606087016122a4565b915061230e608087016122a4565b90509295509295909350565b5f5f83601f84011261232a575f5ffd5b50813567ffffffffffffffff811115612341575f5ffd5b602083019150836020828501011115612358575f5ffd5b9250929050565b5f5f5f5f5f5f5f60c0888a031215612375575f5ffd5b8735612380816121ff565b96506020880135955060408801359450606088013593506080880135925060a088013567ffffffffffffffff8111156123b7575f5ffd5b6123c38a828b0161231a565b989b979a50959850939692959293505050565b5f602082840312156123e6575f5ffd5b81356121f8816121ff565b5f5f5f5f5f5f60a08789031215612406575f5ffd5b8635612411816121ff565b9550602087013594506040870135935060608701359250608087013567ffffffffffffffff811115612441575f5ffd5b61244d89828a0161231a565b979a9699509497509295939492505050565b5f6020828403121561246f575f5ffd5b81516121f8816121ff565b5f6020828403121561248a575f5ffd5b5051919050565b81835281816020850137505f602082840101525f60207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f840116840101905092915050565b73ffffffffffffffffffffffffffffffffffffffff8816815286602082015285604082015284606082015283608082015260c060a08201525f61251f60c083018486612491565b9998505050505050505050565b838152604060208201525f612545604083018486612491565b95945050505050565b5f81518084528060208401602086015e5f6020828601015260207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f83011685010191505092915050565b73ffffffffffffffffffffffffffffffffffffffff8416815263ffffffff83166020820152606060408201525f612545606083018461254e565b73ffffffffffffffffffffffffffffffffffffffff8716815285602082015284604082015283606082015282608082015260c060a08201525f61261a60c083018461254e565b98975050505050505050565b73ffffffffffffffffffffffffffffffffffffffff84168152606060208201525f612654606083018561254e565b905063ffffffff83166040830152949350505050565b73ffffffffffffffffffffffffffffffffffffffff8716815273ffffffffffffffffffffffffffffffffffffffff8616602082015273ffffffffffffffffffffffffffffffffffffffff8516604082015283606082015263ffffffff8316608082015260c060a08201525f61261a60c083018461254e56fea2646970667358221220dc15e88aad4e0ad553fa93cdddab9356d93b1ae38a5fddda38604e988cbc5c7a64736f6c634300081e0033

Verified Source Code Full Match

Compiler: v0.8.30+commit.73712a01 EVM: prague Optimization: Yes (20000 runs)
OptimismBridgeAdapter.sol 372 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.30;

import { AccessControl } from "@openzeppelin/contracts/access/AccessControl.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { IOptimismBridge } from "../interfaces/IOptimismBridge.sol";
import { IBridgeAdapter } from "../interfaces/IBridgeAdapter.sol";
import { IBridgeRouter } from "../interfaces/IBridgeRouter.sol";
import { Constants } from "../Constants.sol";

interface IWETH9 {
    function deposit() external payable;

    function withdraw(uint256) external;
}

interface ICrossDomainMessenger {
    function sendMessage(address _target, bytes calldata _message, uint32 _minGasLimit) external;

    function xDomainMessageSender() external view returns (address);
}

/**
 * @title OptimismBridgeAdapter
 *
 * @dev This contract works identically on both L1 and L2. The main difference is
 *      the configuration of the peer chains.
 *
 * FOR L1 DEPLOYMENT:
 * - deploymentsForPeer[l2ChainId] = bridge and messenger addresses for the L2 chain.
 * - peerChains[l2ChainId] = L2 adapter and token mappings.
 * - Can manage multiple L2 connections.
 *
 * FOR L2 DEPLOYMENT:
 * - deploymentsForPeer[1] = bridge and messenger addresses for Ethereum.
 * - peerChains[1] = L1 adapter and token mappings.
 * - It should only manage a single connection.
 */
contract OptimismBridgeAdapter is IBridgeAdapter, AccessControl {
    using SafeERC20 for IERC20;

    bytes32 public constant SETTER_ROLE = keccak256("SETTER_ROLE");
    bytes32 public constant RESCUE_ROLE = keccak256("RESCUE_ROLE");

    error ZeroAmount();
    error ZeroAddress();
    error ZeroChainId();
    error ZeroGasLimit();
    error ZeroIdentifier();
    error ChainIdCannotBeThis();
    error CallerNotRouter(address caller);
    error InvalidRemoteToken(address token);
    error UnsupportedRemote(uint256 chainId);
    error CallerNotOtherAdapter(address caller, address messengerSender);
    error InsufficientFunds(address token, uint256 available, uint256 required);

    event PeerAdapterSet(uint256 indexed chainId, address indexed adapter);
    event PeerTokenSet(uint256 indexed chainId, address indexed localToken, address indexed remoteToken);
    event PeerDeploymentSet(uint256 indexed chainId, address indexed l1Bridge, address indexed messenger);
    event BridgeRouterSet(address indexed bridgeRouter);

    event OptimismAdapterTriggered(
        address indexed localToken,
        uint256 amount,
        uint256 indexed destChainId,
        bytes32 indexed destAddress,
        bytes data
    );

    /// @notice Peer chain configuration
    /// @dev This contract communicates with its instance on the peer chain.
    ///      That is why we need to know the peer adapter.
    ///      Also, the optimism bridge requires knowing the token addresses on both chains.
    struct PeerChain {
        address adapter;
        mapping(address => address) localToRemoteToken;
    }

    /// @notice Bridge and messenger configuration for peer chains.
    /// @dev There is a bridge and messenger on L1 for each L2 chain.
    ///      For L2 chains, there is a single bridge and messenger that connect to Ethereum.
    ///      Since it is the same format, we can use the same data structures for both.
    /// @param bridge Address of the optimism bridge contract for peer chain
    /// @param bridgeMinGasLimit Minimum gas limit for bridge operations
    /// @param messenger Address of the CrossDomainMessenger contract for peer chain
    /// @param messengerMinGasLimit Minimum gas limit for messenger operations
    struct PeerDeployments {
        address bridge;
        uint32 bridgeMinGasLimit;
        address messenger;
        uint32 messengerMinGasLimit;
    }

    /// @dev Bridge/messenger addresses for each peer chain
    mapping(uint256 chainId => PeerDeployments) public deploymentsForPeer;

    /// @dev Adapter and token mappings for each peer chain
    mapping(uint256 chainId => PeerChain) public peerChains;

    /// @dev the router is only contract allowed to call the bridge function
    IBridgeRouter public router;

    /// @notice L1 chain ID
    /// @dev L2s need to first send funds to L1 even if the dest chain is not L1‚
    uint256 public immutable L1_CHAIN_ID;
    bool public immutable IS_L2;
    address public immutable weth;

    modifier onlyRouter() {
        if (msg.sender != address(router)) revert CallerNotRouter(msg.sender);
        _;
    }

    modifier onlyMessengerOrRescue(uint256 srcChainId) {
        if (!hasRole(RESCUE_ROLE, msg.sender)) {
            address messenger = deploymentsForPeer[srcChainId].messenger;
            address peerAdapter = peerChains[srcChainId].adapter;

            if (messenger != msg.sender || ICrossDomainMessenger(messenger).xDomainMessageSender() != peerAdapter) {
                revert CallerNotOtherAdapter(msg.sender, ICrossDomainMessenger(messenger).xDomainMessageSender());
            }
        }
        _;
    }

    constructor(address admin, address _weth, uint256 l1ChainId) {
        if (_weth == address(0) || admin == address(0)) revert ZeroAddress();
        if (l1ChainId == 0) revert ZeroChainId();

        weth = _weth;
        L1_CHAIN_ID = l1ChainId;
        IS_L2 = block.chainid != L1_CHAIN_ID;

        _grantRole(DEFAULT_ADMIN_ROLE, admin);
    }

    function forwardFunds(
        address localToken,
        uint256 amount,
        uint256 destChainId,
        bytes32 destAddress,
        bytes calldata data
    ) external payable onlyRouter {
        if (localToken == Constants.ETH_ADDRESS) {
            _bridgeETH(localToken, amount, destChainId, destAddress, data);
        } else if (localToken == weth) {
            // pull WETH from caller
            IERC20(localToken).safeTransferFrom(msg.sender, address(this), amount);

            // unwrap to ETH
            IWETH9(localToken).withdraw(amount);

            // then bridge ETH
            _bridgeETH(localToken, amount, destChainId, destAddress, data);
        } else {
            IERC20(localToken).safeTransferFrom(msg.sender, address(this), amount);
            _bridgeERC20(localToken, amount, destChainId, destAddress, data);
        }

        emit OptimismAdapterTriggered(localToken, amount, destChainId, destAddress, data);
    }

    function _bridgeERC20(
        address localToken,
        uint256 amount,
        uint256 destChainId,
        bytes32 destAddress,
        bytes memory data
    ) internal {
        // if this contract is deployed on L2, the funds go through ethereum
        // therefore, hopChainId should be set to the Ethereum chain ID
        uint256 hopChainId = IS_L2 ? L1_CHAIN_ID : destChainId;

        // The usage of "storage" is for optimization.
        // These two variables should NOT BE modified.
        PeerDeployments storage destDeployment = deploymentsForPeer[hopChainId];
        PeerChain storage destPeer = peerChains[hopChainId];

        address remoteToken = destPeer.localToRemoteToken[localToken];
        address remoteAdapter = destPeer.adapter;

        if (remoteToken == address(0)) revert InvalidRemoteToken(localToken);
        if (remoteAdapter == address(0)) revert UnsupportedRemote(hopChainId);
        if (destDeployment.bridge == address(0) || destDeployment.messenger == address(0))
            revert UnsupportedRemote(hopChainId);

        IERC20(localToken).forceApprove(address(destDeployment.bridge), amount);
        IOptimismBridge(destDeployment.bridge).bridgeERC20To(
            localToken,
            remoteToken,
            remoteAdapter,
            amount,
            destDeployment.bridgeMinGasLimit,
            data
        );

        bytes memory message = abi.encodeWithSelector(
            this.receiveFunds.selector,
            remoteToken,
            amount,
            block.chainid,
            destChainId,
            destAddress,
            data
        );

        ICrossDomainMessenger(destDeployment.messenger).sendMessage({
            _target: remoteAdapter,
            _message: message,
            _minGasLimit: destDeployment.messengerMinGasLimit
        });
    }

    function _bridgeETH(
        address localToken,
        uint256 amount,
        uint256 destChainId,
        bytes32 destAddress,
        bytes memory data
    ) internal {
        // if this contract is deployed on L2, the funds go through ethereum
        // therefore, hopChainId should be set to the Ethereum chain ID
        uint256 hopChainId = IS_L2 ? L1_CHAIN_ID : destChainId;

        // The usage of "storage" is for optimization.
        // These variables should NOT BE modified.
        PeerDeployments storage destDeployment = deploymentsForPeer[hopChainId];
        PeerChain storage destPeer = peerChains[hopChainId];

        address remoteToken = destPeer.localToRemoteToken[localToken];
        address remoteAdapter = destPeer.adapter;

        if (remoteToken == address(0)) revert InvalidRemoteToken(localToken);
        if (remoteAdapter == address(0)) revert UnsupportedRemote(hopChainId);
        if (destDeployment.bridge == address(0) || destDeployment.messenger == address(0))
            revert UnsupportedRemote(hopChainId);

        IOptimismBridge(destDeployment.bridge).bridgeETHTo{ value: amount }(
            remoteAdapter,
            destDeployment.bridgeMinGasLimit,
            data
        );

        bytes memory message = abi.encodeWithSelector(
            this.receiveFunds.selector,
            remoteToken, // should be ETH_ADDRESS or WETH address on the remote chain
            amount,
            block.chainid,
            destChainId,
            destAddress,
            data
        );

        ICrossDomainMessenger(destDeployment.messenger).sendMessage({
            _target: remoteAdapter,
            _message: message,
            _minGasLimit: destDeployment.messengerMinGasLimit
        });
    }

    /// @notice This function gets called by the messenger of the respective peer chain.
    /// @dev    The funds should have been sent already by the bridge operation by the time this function is called.
    /// @param localToken Address of the token token received
    /// @param amount Amount of the token received
    /// @param srcChainId ID of the source chain
    /// @param destChainId ID of the destination chain
    /// @param destAddress Address on the destination chain to receive the tokens
    /// @param data Additional data to include with the message
    function receiveFunds(
        address localToken,
        uint256 amount,
        uint256 srcChainId,
        uint256 destChainId,
        bytes32 destAddress,
        bytes calldata data
    ) external payable onlyMessengerOrRescue(srcChainId) {
        uint256 ethAmount;

        IBridgeRouter bridgeRouter = router;

        if (localToken == Constants.ETH_ADDRESS) {
            uint256 ethBalance = address(this).balance;
            if (ethBalance < amount) revert InsufficientFunds(Constants.ETH_ADDRESS, ethBalance, amount);
            ethAmount = amount;
        } else if (localToken == weth) {
            uint256 ethBalance = address(this).balance;
            if (ethBalance < amount) revert InsufficientFunds(Constants.ETH_ADDRESS, ethBalance, amount);

            // wrap to WETH
            IWETH9(localToken).deposit{ value: amount }();

            // Transfer tokens to the bridgeRouter
            IERC20(localToken).safeTransfer(address(bridgeRouter), amount);
        } else {
            uint256 tokenBalance = IERC20(localToken).balanceOf(address(this));
            if (tokenBalance < amount) revert InsufficientFunds(localToken, tokenBalance, amount);

            // Transfer tokens to the bridgeRouter
            IERC20(localToken).safeTransfer(address(bridgeRouter), amount);
        }

        bridgeRouter.handleReceivedFunds{ value: ethAmount }(
            localToken,
            amount,
            srcChainId,
            destChainId,
            destAddress,
            data
        );
    }

    // ========= ADMIN FUNCTIONS ========= //

    function setBridgeRouter(address _router) external onlyRole(SETTER_ROLE) {
        if (_router == address(0)) revert ZeroAddress();
        router = IBridgeRouter(_router);
        emit BridgeRouterSet(_router);
    }

    function setAdapter(uint256 chainId, address adapter) external onlyRole(SETTER_ROLE) {
        if (chainId == block.chainid) revert ChainIdCannotBeThis();
        if (adapter == address(0)) revert ZeroAddress();
        if (chainId == 0) revert ZeroChainId();

        peerChains[chainId].adapter = adapter;
        emit PeerAdapterSet(chainId, adapter);
    }

    function setLocalToRemoteToken(
        uint256 chainId,
        address localToken,
        address remoteToken
    ) external onlyRole(SETTER_ROLE) {
        if (localToken == address(0) || remoteToken == address(0)) revert ZeroAddress();
        if (chainId == block.chainid) revert ChainIdCannotBeThis();
        if (chainId == 0) revert ZeroChainId();

        peerChains[chainId].localToRemoteToken[localToken] = remoteToken;
        emit PeerTokenSet(chainId, localToken, remoteToken);
    }

    function setPeerDeployments(
        uint256 chainId,
        address _bridge,
        address messenger,
        uint32 bridgeGasLimit,
        uint32 messengerGasLimit
    ) external onlyRole(SETTER_ROLE) {
        if (_bridge == address(0) || messenger == address(0)) revert ZeroAddress();
        if (bridgeGasLimit == 0 || messengerGasLimit == 0) revert ZeroGasLimit();
        if (IS_L2 && chainId != L1_CHAIN_ID) revert UnsupportedRemote(chainId);
        if (chainId == block.chainid) revert ChainIdCannotBeThis();
        if (chainId == 0) revert ZeroChainId();

        deploymentsForPeer[chainId].bridge = _bridge;
        deploymentsForPeer[chainId].messenger = messenger;
        deploymentsForPeer[chainId].bridgeMinGasLimit = bridgeGasLimit;
        deploymentsForPeer[chainId].messengerMinGasLimit = messengerGasLimit;

        emit PeerDeploymentSet(chainId, _bridge, messenger);
    }

    // ========= GETTER FUNCTIONS ========= //

    function getPeerChainRemoteToken(uint256 chainId, address localToken) external view returns (address) {
        return peerChains[chainId].localToRemoteToken[localToken];
    }

    /// @notice Allow contract to receive ETH from bridge operations
    receive() external payable {}
}
AccessControl.sol 207 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (access/AccessControl.sol)

pragma solidity ^0.8.20;

import {IAccessControl} from "./IAccessControl.sol";
import {Context} from "../utils/Context.sol";
import {IERC165, ERC165} from "../utils/introspection/ERC165.sol";

/**
 * @dev Contract module that allows children to implement role-based access
 * control mechanisms. This is a lightweight version that doesn't allow enumerating role
 * members except through off-chain means by accessing the contract event logs. Some
 * applications may benefit from on-chain enumerability, for those cases see
 * {AccessControlEnumerable}.
 *
 * Roles are referred to by their `bytes32` identifier. These should be exposed
 * in the external API and be unique. The best way to achieve this is by
 * using `public constant` hash digests:
 *
 * ```solidity
 * bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
 * ```
 *
 * Roles can be used to represent a set of permissions. To restrict access to a
 * function call, use {hasRole}:
 *
 * ```solidity
 * function foo() public {
 *     require(hasRole(MY_ROLE, msg.sender));
 *     ...
 * }
 * ```
 *
 * Roles can be granted and revoked dynamically via the {grantRole} and
 * {revokeRole} functions. Each role has an associated admin role, and only
 * accounts that have a role's admin role can call {grantRole} and {revokeRole}.
 *
 * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
 * that only accounts with this role will be able to grant or revoke other
 * roles. More complex role relationships can be created by using
 * {_setRoleAdmin}.
 *
 * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
 * grant and revoke this role. Extra precautions should be taken to secure
 * accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules}
 * to enforce additional security measures for this role.
 */
abstract contract AccessControl is Context, IAccessControl, ERC165 {
    struct RoleData {
        mapping(address account => bool) hasRole;
        bytes32 adminRole;
    }

    mapping(bytes32 role => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

    /**
     * @dev Modifier that checks that an account has a specific role. Reverts
     * with an {AccessControlUnauthorizedAccount} error including the required role.
     */
    modifier onlyRole(bytes32 role) {
        _checkRole(role);
        _;
    }

    /// @inheritdoc IERC165
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
    }

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) public view virtual returns (bool) {
        return _roles[role].hasRole[account];
    }

    /**
     * @dev Reverts with an {AccessControlUnauthorizedAccount} error if `_msgSender()`
     * is missing `role`. Overriding this function changes the behavior of the {onlyRole} modifier.
     */
    function _checkRole(bytes32 role) internal view virtual {
        _checkRole(role, _msgSender());
    }

    /**
     * @dev Reverts with an {AccessControlUnauthorizedAccount} error if `account`
     * is missing `role`.
     */
    function _checkRole(bytes32 role, address account) internal view virtual {
        if (!hasRole(role, account)) {
            revert AccessControlUnauthorizedAccount(account, role);
        }
    }

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) public view virtual returns (bytes32) {
        return _roles[role].adminRole;
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     *
     * May emit a {RoleGranted} event.
     */
    function grantRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
        _grantRole(role, account);
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     *
     * May emit a {RoleRevoked} event.
     */
    function revokeRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
        _revokeRole(role, account);
    }

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been revoked `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `callerConfirmation`.
     *
     * May emit a {RoleRevoked} event.
     */
    function renounceRole(bytes32 role, address callerConfirmation) public virtual {
        if (callerConfirmation != _msgSender()) {
            revert AccessControlBadConfirmation();
        }

        _revokeRole(role, callerConfirmation);
    }

    /**
     * @dev Sets `adminRole` as ``role``'s admin role.
     *
     * Emits a {RoleAdminChanged} event.
     */
    function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
        bytes32 previousAdminRole = getRoleAdmin(role);
        _roles[role].adminRole = adminRole;
        emit RoleAdminChanged(role, previousAdminRole, adminRole);
    }

    /**
     * @dev Attempts to grant `role` to `account` and returns a boolean indicating if `role` was granted.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleGranted} event.
     */
    function _grantRole(bytes32 role, address account) internal virtual returns (bool) {
        if (!hasRole(role, account)) {
            _roles[role].hasRole[account] = true;
            emit RoleGranted(role, account, _msgSender());
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Attempts to revoke `role` from `account` and returns a boolean indicating if `role` was revoked.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleRevoked} event.
     */
    function _revokeRole(bytes32 role, address account) internal virtual returns (bool) {
        if (hasRole(role, account)) {
            _roles[role].hasRole[account] = false;
            emit RoleRevoked(role, account, _msgSender());
            return true;
        } else {
            return false;
        }
    }
}
SafeERC20.sol 280 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.5.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC-20 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 {
    /**
     * @dev An operation with an ERC-20 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 {
        if (!_safeTransfer(token, to, value, true)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @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 {
        if (!_safeTransferFrom(token, from, to, value, true)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.
     */
    function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {
        return _safeTransfer(token, to, value, false);
    }

    /**
     * @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.
     */
    function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {
        return _safeTransferFrom(token, from, to, value, false);
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     *
     * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
     * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
     * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
     * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
     */
    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.
     *
     * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
     * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
     * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
     * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
     */
    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.
     *
     * NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
     * only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
     * set here.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        if (!_safeApprove(token, spender, value, false)) {
            if (!_safeApprove(token, spender, 0, true)) revert SafeERC20FailedOperation(address(token));
            if (!_safeApprove(token, spender, value, true)) revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
     * code. This can be used to implement an {ERC721}-like safe transfer that relies on {ERC1363} checks when
     * targeting contracts.
     *
     * Reverts if the returned value is other than `true`.
     */
    function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
        if (to.code.length == 0) {
            safeTransfer(token, to, value);
        } else if (!token.transferAndCall(to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
     * has no code. This can be used to implement an {ERC721}-like safe transfer that relies on {ERC1363} checks when
     * targeting contracts.
     *
     * Reverts if the returned value is other than `true`.
     */
    function transferFromAndCallRelaxed(
        IERC1363 token,
        address from,
        address to,
        uint256 value,
        bytes memory data
    ) internal {
        if (to.code.length == 0) {
            safeTransferFrom(token, from, to, value);
        } else if (!token.transferFromAndCall(from, to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
     * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
     * targeting contracts.
     *
     * NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
     * Oppositely, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
     * once without retrying, and relies on the returned value to be true.
     *
     * Reverts if the returned value is other than `true`.
     */
    function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
        if (to.code.length == 0) {
            forceApprove(token, to, value);
        } else if (!token.approveAndCall(to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Imitates a Solidity `token.transfer(to, value)` call, 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 to The recipient of the tokens
     * @param value The amount of token to transfer
     * @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
     */
    function _safeTransfer(IERC20 token, address to, uint256 value, bool bubble) private returns (bool success) {
        bytes4 selector = IERC20.transfer.selector;

        assembly ("memory-safe") {
            let fmp := mload(0x40)
            mstore(0x00, selector)
            mstore(0x04, and(to, shr(96, not(0))))
            mstore(0x24, value)
            success := call(gas(), token, 0, 0x00, 0x44, 0x00, 0x20)
            // if call success and return is true, all is good.
            // otherwise (not success or return is not true), we need to perform further checks
            if iszero(and(success, eq(mload(0x00), 1))) {
                // if the call was a failure and bubble is enabled, bubble the error
                if and(iszero(success), bubble) {
                    returndatacopy(fmp, 0x00, returndatasize())
                    revert(fmp, returndatasize())
                }
                // if the return value is not true, then the call is only successful if:
                // - the token address has code
                // - the returndata is empty
                success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
            }
            mstore(0x40, fmp)
        }
    }

    /**
     * @dev Imitates a Solidity `token.transferFrom(from, to, value)` call, 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 from The sender of the tokens
     * @param to The recipient of the tokens
     * @param value The amount of token to transfer
     * @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
     */
    function _safeTransferFrom(
        IERC20 token,
        address from,
        address to,
        uint256 value,
        bool bubble
    ) private returns (bool success) {
        bytes4 selector = IERC20.transferFrom.selector;

        assembly ("memory-safe") {
            let fmp := mload(0x40)
            mstore(0x00, selector)
            mstore(0x04, and(from, shr(96, not(0))))
            mstore(0x24, and(to, shr(96, not(0))))
            mstore(0x44, value)
            success := call(gas(), token, 0, 0x00, 0x64, 0x00, 0x20)
            // if call success and return is true, all is good.
            // otherwise (not success or return is not true), we need to perform further checks
            if iszero(and(success, eq(mload(0x00), 1))) {
                // if the call was a failure and bubble is enabled, bubble the error
                if and(iszero(success), bubble) {
                    returndatacopy(fmp, 0x00, returndatasize())
                    revert(fmp, returndatasize())
                }
                // if the return value is not true, then the call is only successful if:
                // - the token address has code
                // - the returndata is empty
                success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
            }
            mstore(0x40, fmp)
            mstore(0x60, 0)
        }
    }

    /**
     * @dev Imitates a Solidity `token.approve(spender, value)` call, 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 spender The spender of the tokens
     * @param value The amount of token to transfer
     * @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
     */
    function _safeApprove(IERC20 token, address spender, uint256 value, bool bubble) private returns (bool success) {
        bytes4 selector = IERC20.approve.selector;

        assembly ("memory-safe") {
            let fmp := mload(0x40)
            mstore(0x00, selector)
            mstore(0x04, and(spender, shr(96, not(0))))
            mstore(0x24, value)
            success := call(gas(), token, 0, 0x00, 0x44, 0x00, 0x20)
            // if call success and return is true, all is good.
            // otherwise (not success or return is not true), we need to perform further checks
            if iszero(and(success, eq(mload(0x00), 1))) {
                // if the call was a failure and bubble is enabled, bubble the error
                if and(iszero(success), bubble) {
                    returndatacopy(fmp, 0x00, returndatasize())
                    revert(fmp, returndatasize())
                }
                // if the return value is not true, then the call is only successful if:
                // - the token address has code
                // - the returndata is empty
                success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
            }
            mstore(0x40, fmp)
        }
    }
}
IERC20.sol 79 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/IERC20.sol)

pragma solidity >=0.4.16;

/**
 * @dev Interface of the ERC-20 standard as defined in the ERC.
 */
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);
}
IOptimismBridge.sol 15 lines
// SPDX-License-Identifier: AGPL-3.0
pragma solidity 0.8.30;

interface IOptimismBridge {
    function bridgeERC20To(
        address _localToken,
        address _remoteToken,
        address _to,
        uint256 _amount,
        uint32 _minGasLimit,
        bytes calldata _extraData
    ) external;

    function bridgeETHTo(address _to, uint32 _minGasLimit, bytes calldata _extraData) external payable;
}
IBridgeAdapter.sol 27 lines
// SPDX-License-Identifier: AGPL-3.0
pragma solidity 0.8.30;

interface IBridgeAdapter {
    struct CrossChainData {
        uint256 amount;
        address localToken;
        uint256 srcChainId;
        uint256 destChainId;
    }

    /**
     * @notice Executes a bridge operation.
     * @param token The address of the token to bridge.
     * @param amount The amount of tokens to bridge.
     * @param destChainId The ID of the destination chain.
     * @param destAddress The destination identifier (low 20 bytes MUST encode an EVM address when applicable).
     * @param data Additional data to be passed to destAddress.
     */
    function forwardFunds(
        address token,
        uint256 amount,
        uint256 destChainId,
        bytes32 destAddress,
        bytes calldata data
    ) external payable;
}
IBridgeRouter.sol 22 lines
// SPDX-License-Identifier: AGPL-3.0
pragma solidity 0.8.30;

/// @notice Interface for the IBridgeRouter
interface IBridgeRouter {
    function bridge(
        address token,
        uint256 amount,
        uint256 destChainId,
        bytes32 destAddress,
        bytes calldata extraData
    ) external payable;

    function handleReceivedFunds(
        address token,
        uint256 amount,
        uint256 srcChainId,
        uint256 destChainId,
        bytes32 destAddress,
        bytes calldata extraData
    ) external payable;
}
Constants.sol 7 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.30;

library Constants {
    /// @notice ETH sentinel address for consistent ETH handling
    address public constant ETH_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
}
IAccessControl.sol 98 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (access/IAccessControl.sol)

pragma solidity >=0.8.4;

/**
 * @dev External interface of AccessControl declared to support ERC-165 detection.
 */
interface IAccessControl {
    /**
     * @dev The `account` is missing a role.
     */
    error AccessControlUnauthorizedAccount(address account, bytes32 neededRole);

    /**
     * @dev The caller of a function is not the expected one.
     *
     * NOTE: Don't confuse with {AccessControlUnauthorizedAccount}.
     */
    error AccessControlBadConfirmation();

    /**
     * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
     *
     * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
     * {RoleAdminChanged} not being emitted to signal this.
     */
    event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);

    /**
     * @dev Emitted when `account` is granted `role`.
     *
     * `sender` is the account that originated the contract call. This account bears the admin role (for the granted role).
     * Expected in cases where the role was granted using the internal {AccessControl-_grantRole}.
     */
    event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Emitted when `account` is revoked `role`.
     *
     * `sender` is the account that originated the contract call:
     *   - if using `revokeRole`, it is the admin role bearer
     *   - if using `renounceRole`, it is the role bearer (i.e. `account`)
     */
    event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) external view returns (bool);

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {AccessControl-_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) external view returns (bytes32);

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function grantRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function revokeRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been granted `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `callerConfirmation`.
     */
    function renounceRole(bytes32 role, address callerConfirmation) external;
}
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;
    }
}
ERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/introspection/ERC165.sol)

pragma solidity ^0.8.20;

import {IERC165} from "./IERC165.sol";

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC-165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 */
abstract contract ERC165 is IERC165 {
    /// @inheritdoc IERC165
    function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}
IERC1363.sol 86 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC1363.sol)

pragma solidity >=0.6.2;

import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";

/**
 * @title IERC1363
 * @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
 *
 * Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
 * after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
 */
interface IERC1363 is IERC20, IERC165 {
    /*
     * Note: the ERC-165 identifier for this interface is 0xb0202a11.
     * 0xb0202a11 ===
     *   bytes4(keccak256('transferAndCall(address,uint256)')) ^
     *   bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
     *   bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
     *   bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
     *   bytes4(keccak256('approveAndCall(address,uint256)')) ^
     *   bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
     */

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferAndCall(address to, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @param data Additional data with no specified format, sent in call to `to`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param from The address which you want to send tokens from.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferFromAndCall(address from, address to, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param from The address which you want to send tokens from.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @param data Additional data with no specified format, sent in call to `to`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
     * @param spender The address which will spend the funds.
     * @param value The amount of tokens to be spent.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function approveAndCall(address spender, uint256 value) external returns (bool);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
     * @param spender The address which will spend the funds.
     * @param value The amount of tokens to be spent.
     * @param data Additional data with no specified format, sent in call to `spender`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/introspection/IERC165.sol)

pragma solidity >=0.4.16;

/**
 * @dev Interface of the ERC-165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[ERC].
 *
 * 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[ERC 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);
}
IERC20.sol 6 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC20.sol)

pragma solidity >=0.4.16;

import {IERC20} from "../token/ERC20/IERC20.sol";
IERC165.sol 6 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC165.sol)

pragma solidity >=0.4.16;

import {IERC165} from "../utils/introspection/IERC165.sol";

Read Contract

DEFAULT_ADMIN_ROLE 0xa217fddf → bytes32
IS_L2 0x65f20454 → bool
L1_CHAIN_ID 0x2f90b184 → uint256
RESCUE_ROLE 0xb1a9f809 → bytes32
SETTER_ROLE 0xa2011b3f → bytes32
deploymentsForPeer 0x210452c5 → address, uint32, address, uint32
getPeerChainRemoteToken 0x0ddc5216 → address
getRoleAdmin 0x248a9ca3 → bytes32
hasRole 0x91d14854 → bool
peerChains 0x752d5181 → address
router 0xf887ea40 → address
supportsInterface 0x01ffc9a7 → bool
weth 0x3fc8cef3 → address

Write Contract 9 functions

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

forwardFunds 0x7770ff9b
address localToken
uint256 amount
uint256 destChainId
bytes32 destAddress
bytes data
grantRole 0x2f2ff15d
bytes32 role
address account
receiveFunds 0x4f1ffc64
address localToken
uint256 amount
uint256 srcChainId
uint256 destChainId
bytes32 destAddress
bytes data
renounceRole 0x36568abe
bytes32 role
address callerConfirmation
revokeRole 0xd547741f
bytes32 role
address account
setAdapter 0xe26bbe80
uint256 chainId
address adapter
setBridgeRouter 0x6df42007
address _router
setLocalToRemoteToken 0x0b799d95
uint256 chainId
address localToken
address remoteToken
setPeerDeployments 0x25f5042c
uint256 chainId
address _bridge
address messenger
uint32 bridgeGasLimit
uint32 messengerGasLimit

Recent Transactions

No transactions found for this address