zellic-audit
Initial commit
f998fcd
raw
history blame
131 kB
{
"language": "Solidity",
"sources": {
"contracts/arbitrum/L1CustomGatewayWithMint.sol": {
"content": "/*\n SPDX-License-Identifier: Apache-2.0\n\n Copyright 2021 Reddit, Inc\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*/\n\npragma solidity ^0.8.9;\n\nimport \"./arb-peripherals/L1CustomGateway.sol\";\nimport \"./IEthBridgedToken.sol\";\n\n/*\n L1CustomGatewayWithMint is arbitrum L1 gateway that mints new points in L1 whenever they're deposited from L2 and\n burns them when they're withdrawn back to L2\n*/\n\ncontract L1CustomGatewayWithMint is L1CustomGateway {\n function postUpgradeInit() external override {}\n\n function initialize(\n address _l1Counterpart,\n address _l1Router,\n address _inbox,\n address _owner\n ) public virtual override {\n L1CustomGateway.initialize(_l1Counterpart, _l1Router, _inbox, _owner);\n }\n\n function inboundEscrowTransfer(\n address _token,\n address _dest,\n uint256 _amount\n ) internal virtual override {\n IEthBridgedToken(_token).bridgeMint(_dest, _amount);\n }\n\n function outboundEscrowTransfer(\n address _token,\n address _from,\n uint256 _amount\n ) internal virtual override returns (uint256 amountBurnt) {\n // burns L1 tokens in order to transfer L1 -> L2\n IEthBridgedToken(_token).bridgeBurn(_from, _amount);\n return _amount;\n }\n}\n"
},
"contracts/arbitrum/arb-peripherals/L1CustomGateway.sol": {
"content": "// SPDX-License-Identifier: Apache-2.0\n\n/*\n * Copyright 2020, Offchain Labs, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npragma solidity ^0.8.9;\n\nimport \"@openzeppelin/contracts/utils/Address.sol\";\n\nimport { ArbitrumEnabledToken } from \"./interfaces/ICustomToken.sol\";\nimport \"./interfaces/ICustomGateway.sol\";\nimport \"./libraries/Whitelist.sol\";\nimport \"./L1ArbitrumExtendedGateway.sol\";\nimport \"./L2CustomGateway.sol\";\n\n/**\n * @title Gatway for \"custom\" bridging functionality\n * @notice Handles some (but not all!) custom Gateway needs.\n */\ncontract L1CustomGateway is L1ArbitrumExtendedGateway, ICustomGateway {\n using Address for address;\n // stores addresses of L2 tokens to be used\n mapping(address => address) public override l1ToL2Token;\n // owner is able to force add custom mappings\n address public owner;\n\n // whitelist not used anymore\n address public whitelist;\n\n // start of inline reentrancy guard\n // https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.4.2/contracts/utils/ReentrancyGuard.sol\n uint256 private constant _NOT_ENTERED = 1;\n uint256 private constant _ENTERED = 2;\n uint256 private _status;\n\n modifier nonReentrant() {\n // On the first call to nonReentrant, _notEntered will be true\n require(_status != _ENTERED, \"ReentrancyGuard: reentrant call\");\n // Any calls to nonReentrant after this point will fail\n _status = _ENTERED;\n _;\n _status = _NOT_ENTERED;\n }\n\n // end of inline reentrancy guard\n\n function outboundTransfer(\n address _l1Token,\n address _to,\n uint256 _amount,\n uint256 _maxGas,\n uint256 _gasPriceBid,\n bytes calldata _data\n ) public payable override nonReentrant returns (bytes memory res) {\n return super.outboundTransfer(_l1Token, _to, _amount, _maxGas, _gasPriceBid, _data);\n }\n\n function finalizeInboundTransfer(\n address _token,\n address _from,\n address _to,\n uint256 _amount,\n bytes calldata _data\n ) public payable virtual override nonReentrant {\n // the superclass checks onlyCounterpartGateway\n super.finalizeInboundTransfer(_token, _from, _to, _amount, _data);\n }\n\n function initialize(\n address _l1Counterpart,\n address _l1Router,\n address _inbox,\n address _owner\n ) virtual public {\n L1ArbitrumExtendedGateway._initialize(_l1Counterpart, _l1Router, _inbox);\n owner = _owner;\n // disable whitelist by default\n whitelist = address(0);\n // reentrancy guard\n _status = _NOT_ENTERED;\n }\n\n /**\n * @notice Calculate the address used when bridging an ERC20 token\n * @dev the L1 and L2 address oracles may not always be in sync.\n * For example, a custom token may have been registered but not deploy or the contract self destructed.\n * @param l1ERC20 address of L1 token\n * @return L2 address of a bridged ERC20 token\n */\n function calculateL2TokenAddress(address l1ERC20) public view override returns (address) {\n return l1ToL2Token[l1ERC20];\n }\n\n /**\n * @notice Allows L1 Token contract to trustlessly register its custom L2 counterpart. (other registerTokenToL2 method allows excess eth recovery from _maxSubmissionCost and is recommended)\n * @param _l2Address counterpart address of L1 token\n * @param _maxGas max gas for L2 retryable exrecution\n * @param _gasPriceBid gas price for L2 retryable ticket\n * @param _maxSubmissionCost base submission cost L2 retryable tick3et\n * @return Retryable ticket ID\n */\n function registerTokenToL2(\n address _l2Address,\n uint256 _maxGas,\n uint256 _gasPriceBid,\n uint256 _maxSubmissionCost\n ) external payable returns (uint256) {\n return registerTokenToL2(_l2Address, _maxGas, _gasPriceBid, _maxSubmissionCost, msg.sender);\n }\n\n /**\n * @notice Allows L1 Token contract to trustlessly register its custom L2 counterpart.\n * param _l2Address counterpart address of L1 token\n * param _maxGas max gas for L2 retryable exrecution\n * param _gasPriceBid gas price for L2 retryable ticket\n * param _maxSubmissionCost base submission cost L2 retryable tick3et\n * param _creditBackAddress address for crediting back overpayment of _maxSubmissionCost\n * return Retryable ticket ID\n */\n function registerTokenToL2(\n address _l2Address,\n uint256 _maxGas,\n uint256 _gasPriceBid,\n uint256 _maxSubmissionCost,\n address _creditBackAddress\n ) public payable returns (uint256) {\n require(\n ArbitrumEnabledToken(msg.sender).isArbitrumEnabled() == uint8(uint16(0xa4b1)),\n \"NOT_ARB_ENABLED\"\n );\n\n address currL2Addr = l1ToL2Token[msg.sender];\n if (currL2Addr != address(0)) {\n // if token is already set, don't allow it to set a different L2 address\n require(currL2Addr == _l2Address, \"NO_UPDATE_TO_DIFFERENT_ADDR\");\n }\n\n l1ToL2Token[msg.sender] = _l2Address;\n\n address[] memory l1Addresses = new address[](1);\n address[] memory l2Addresses = new address[](1);\n l1Addresses[0] = msg.sender;\n l2Addresses[0] = _l2Address;\n\n emit TokenSet(l1Addresses[0], l2Addresses[0]);\n\n bytes memory _data = abi.encodeWithSelector(\n L2CustomGateway.registerTokenFromL1.selector,\n l1Addresses,\n l2Addresses\n );\n\n return\n sendTxToL2(\n inbox,\n counterpartGateway,\n _creditBackAddress,\n msg.value,\n 0,\n _maxSubmissionCost,\n _maxGas,\n _gasPriceBid,\n _data\n );\n }\n\n /**\n * @notice Allows owner to force register a custom L1/L2 token pair.\n * @dev _l1Addresses[i] counterpart is assumed to be _l2Addresses[i]\n * @param _l1Addresses array of L1 addresses\n * @param _l2Addresses array of L2 addresses\n * @param _maxGas max gas for L2 retryable exrecution\n * @param _gasPriceBid gas price for L2 retryable ticket\n * @param _maxSubmissionCost base submission cost L2 retryable tick3et\n * @return Retryable ticket ID\n */\n function forceRegisterTokenToL2(\n address[] calldata _l1Addresses,\n address[] calldata _l2Addresses,\n uint256 _maxGas,\n uint256 _gasPriceBid,\n uint256 _maxSubmissionCost\n ) external payable returns (uint256) {\n require(msg.sender == owner, \"ONLY_OWNER\");\n require(_l1Addresses.length == _l2Addresses.length, \"INVALID_LENGTHS\");\n\n for (uint256 i = 0; i < _l1Addresses.length; i++) {\n // here we assume the owner checked both addresses offchain before force registering\n // require(address(_l1Addresses[i]).isContract(), \"MUST_BE_CONTRACT\");\n l1ToL2Token[_l1Addresses[i]] = _l2Addresses[i];\n emit TokenSet(_l1Addresses[i], _l2Addresses[i]);\n }\n\n bytes memory _data = abi.encodeWithSelector(\n L2CustomGateway.registerTokenFromL1.selector,\n _l1Addresses,\n _l2Addresses\n );\n\n return\n sendTxToL2(\n inbox,\n counterpartGateway,\n msg.sender,\n msg.value,\n 0,\n _maxSubmissionCost,\n _maxGas,\n _gasPriceBid,\n _data\n );\n }\n}\n"
},
"contracts/arbitrum/IEthBridgedToken.sol": {
"content": "/*\n SPDX-License-Identifier: Apache-2.0\n\n Copyright 2021 Reddit, Inc\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*/\n\npragma solidity ^0.8.9;\n\ninterface IEthBridgedToken {\n /**\n * @notice should increase token supply by amount, and should only be callable by the L2 bridge.\n */\n function bridgeMint(address account, uint256 amount) external;\n\n /**\n * @notice should decrease token supply by amount, and should only be callable by the L2 bridge.\n */\n function bridgeBurn(address account, uint256 amount) external;\n\n /**\n * @return address of layer 2 token\n */\n function l2Address() external view returns (address);\n}\n"
},
"@openzeppelin/contracts/utils/Address.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol)\n\npragma solidity ^0.8.1;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n /**\n * @dev Returns true if `account` is a contract.\n *\n * [IMPORTANT]\n * ====\n * It is unsafe to assume that an address for which this function returns\n * false is an externally-owned account (EOA) and not a contract.\n *\n * Among others, `isContract` will return false for the following\n * types of addresses:\n *\n * - an externally-owned account\n * - a contract in construction\n * - an address where a contract will be created\n * - an address where a contract lived, but was destroyed\n * ====\n *\n * [IMPORTANT]\n * ====\n * You shouldn't rely on `isContract` to protect against flash loan attacks!\n *\n * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n * constructor.\n * ====\n */\n function isContract(address account) internal view returns (bool) {\n // This method relies on extcodesize/address.code.length, which returns 0\n // for contracts in construction, since the code is only stored at the end\n // of the constructor execution.\n\n return account.code.length > 0;\n }\n\n /**\n * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n * `recipient`, forwarding all available gas and reverting on errors.\n *\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\n * imposed by `transfer`, making them unable to receive funds via\n * `transfer`. {sendValue} removes this limitation.\n *\n * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n *\n * IMPORTANT: because control is transferred to `recipient`, care must be\n * taken to not create reentrancy vulnerabilities. Consider using\n * {ReentrancyGuard} or the\n * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n */\n function sendValue(address payable recipient, uint256 amount) internal {\n require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n (bool success, ) = recipient.call{value: amount}(\"\");\n require(success, \"Address: unable to send value, recipient may have reverted\");\n }\n\n /**\n * @dev Performs a Solidity function call using a low level `call`. A\n * plain `call` is an unsafe replacement for a function call: use this\n * function instead.\n *\n * If `target` reverts with a revert reason, it is bubbled up by this\n * function (like regular Solidity function calls).\n *\n * Returns the raw returned data. To convert to the expected return value,\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n *\n * Requirements:\n *\n * - `target` must be a contract.\n * - calling `target` with `data` must not revert.\n *\n * _Available since v3.1._\n */\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionCall(target, data, \"Address: low-level call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n * `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but also transferring `value` wei to `target`.\n *\n * Requirements:\n *\n * - the calling contract must have an ETH balance of at least `value`.\n * - the called Solidity function must be `payable`.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n * with `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(address(this).balance >= value, \"Address: insufficient balance for call\");\n require(isContract(target), \"Address: call to non-contract\");\n\n (bool success, bytes memory returndata) = target.call{value: value}(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n return functionStaticCall(target, data, \"Address: low-level static call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal view returns (bytes memory) {\n require(isContract(target), \"Address: static call to non-contract\");\n\n (bool success, bytes memory returndata) = target.staticcall(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function functionDelegateCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(isContract(target), \"Address: delegate call to non-contract\");\n\n (bool success, bytes memory returndata) = target.delegatecall(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the\n * revert reason using the provided one.\n *\n * _Available since v4.3._\n */\n function verifyCallResult(\n bool success,\n bytes memory returndata,\n string memory errorMessage\n ) internal pure returns (bytes memory) {\n if (success) {\n return returndata;\n } else {\n // Look for revert reason and bubble it up if present\n if (returndata.length > 0) {\n // The easiest way to bubble the revert reason is using memory via assembly\n\n assembly {\n let returndata_size := mload(returndata)\n revert(add(32, returndata), returndata_size)\n }\n } else {\n revert(errorMessage);\n }\n }\n }\n}\n"
},
"contracts/arbitrum/arb-peripherals/interfaces/ICustomToken.sol": {
"content": "// SPDX-License-Identifier: Apache-2.0\n\n/*\n * Copyright 2020, Offchain Labs, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npragma solidity ^0.8.9;\n\ninterface ArbitrumEnabledToken {\n /// @notice should return `0xa4b1` if token is enabled for arbitrum gateways\n function isArbitrumEnabled() external view returns (uint8);\n}\n\n/**\n * @title Minimum expected interface for L1 custom token (see TestCustomTokenL1.sol for an example implementation)\n */\ninterface ICustomToken is ArbitrumEnabledToken {\n /**\n * @notice Should make an external call to EthERC20Bridge.registerCustomL2Token\n */\n function registerTokenOnL2(\n address l2CustomTokenAddress,\n uint256 maxSubmissionCostForCustomBridge,\n uint256 maxSubmissionCostForRouter,\n uint256 maxGasForCustomBridge,\n uint256 maxGasForRouter,\n uint256 gasPriceBid,\n uint256 valueForGateway,\n uint256 valueForRouter,\n address creditBackAddress\n ) external payable;\n\n function transferFrom(\n address sender,\n address recipient,\n uint256 amount\n ) external returns (bool);\n\n function balanceOf(address account) external view returns (uint256);\n}\n"
},
"contracts/arbitrum/arb-peripherals/interfaces/ICustomGateway.sol": {
"content": "// SPDX-License-Identifier: Apache-2.0\n\n/*\n * Copyright 2020, Offchain Labs, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npragma solidity ^0.8.9;\n\n// import \"./ITokenGateway.sol\";\n\ninterface ICustomGateway {\n function l1ToL2Token(address _l1Token) external view returns (address _l2Token);\n\n event TokenSet(address indexed l1Address, address indexed l2Address);\n}\n"
},
"contracts/arbitrum/arb-peripherals/libraries/Whitelist.sol": {
"content": "// SPDX-License-Identifier: Apache-2.0\n\n/*\n * Copyright 2021, Offchain Labs, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npragma solidity ^0.8.9;\n\nabstract contract WhitelistConsumer {\n address public whitelist;\n\n event WhitelistSourceUpdated(address newSource);\n\n modifier onlyWhitelisted() {\n if (whitelist != address(0)) {\n require(Whitelist(whitelist).isAllowed(msg.sender), \"NOT_WHITELISTED\");\n }\n _;\n }\n\n function updateWhitelistSource(address newSource) external {\n require(msg.sender == whitelist, \"NOT_FROM_LIST\");\n whitelist = newSource;\n emit WhitelistSourceUpdated(newSource);\n }\n}\n\ncontract Whitelist {\n address public owner;\n mapping(address => bool) public isAllowed;\n\n event OwnerUpdated(address newOwner);\n event WhitelistUpgraded(address newWhitelist, address[] targets);\n\n constructor() {\n owner = msg.sender;\n }\n\n modifier onlyOwner() {\n require(msg.sender == owner, \"ONLY_OWNER\");\n _;\n }\n\n function setOwner(address newOwner) external onlyOwner {\n owner = newOwner;\n emit OwnerUpdated(newOwner);\n }\n\n function setWhitelist(address[] memory user, bool[] memory val) external onlyOwner {\n require(user.length == val.length, \"INVALID_INPUT\");\n\n for (uint256 i = 0; i < user.length; i++) {\n isAllowed[user[i]] = val[i];\n }\n }\n\n // set new whitelist to address(0) to disable whitelist\n function triggerConsumers(address newWhitelist, address[] memory targets) external onlyOwner {\n for (uint256 i = 0; i < targets.length; i++) {\n WhitelistConsumer(targets[i]).updateWhitelistSource(newWhitelist);\n }\n emit WhitelistUpgraded(newWhitelist, targets);\n }\n}\n"
},
"contracts/arbitrum/arb-peripherals/L1ArbitrumExtendedGateway.sol": {
"content": "// SPDX-License-Identifier: Apache-2.0\n\n/*\n * Copyright 2020, Offchain Labs, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npragma solidity ^0.8.9;\n\nimport \"./interfaces/ITransferAndCall.sol\";\nimport \"./L1ArbitrumGateway.sol\";\nimport \"@openzeppelin/contracts/utils/Address.sol\";\n\ninterface ITradeableExitReceiver {\n function onExitTransfer(\n address sender,\n uint256 exitNum,\n bytes calldata data\n ) external returns (bool);\n}\n\nabstract contract L1ArbitrumExtendedGateway is L1ArbitrumGateway {\n\n using Address for address;\n\n struct ExitData {\n bool isExit;\n address _newTo;\n bytes _newData;\n }\n\n mapping(bytes32 => ExitData) public redirectedExits;\n\n function _initialize(\n address _l2Counterpart,\n address _router,\n address _inbox\n ) internal virtual override {\n L1ArbitrumGateway._initialize(_l2Counterpart, _router, _inbox);\n }\n\n event WithdrawRedirected(\n address indexed from,\n address indexed to,\n uint256 indexed exitNum,\n bytes newData,\n bytes data,\n bool madeExternalCall\n );\n\n /**\n * @notice Allows a user to redirect their right to claim a withdrawal to another address.\n * @dev This method also allows you to make an arbitrary call after the transfer.\n * This does not validate if the exit was already triggered. It is assumed the `_exitNum` is\n * validated off-chain to ensure this was not yet triggered.\n * @param _exitNum Sequentially increasing exit counter determined by the L2 bridge\n * @param _initialDestination address the L2 withdrawal call initially set as the destination.\n * @param _newDestination address the L1 will now call instead of the previously set destination\n * @param _newData data to be used in inboundEscrowAndCall\n * @param _data optional data for external call upon transfering the exit\n */\n function transferExitAndCall(\n uint256 _exitNum,\n address _initialDestination,\n address _newDestination,\n bytes calldata _newData,\n bytes calldata _data\n ) external {\n // the initial data doesn't make a difference when transfering you exit\n // since the L2 bridge gives a unique exit ID to each exit\n (address expectedSender, ) = getExternalCall(_exitNum, _initialDestination, \"\");\n\n // if you want to transfer your exit, you must be the current destination\n require(msg.sender == expectedSender, \"NOT_EXPECTED_SENDER\");\n // the inboundEscrowAndCall functionality has been disabled, so no data is allowed\n require(_newData.length == 0, \"NO_DATA_ALLOWED\");\n\n setRedirectedExit(_exitNum, _initialDestination, _newDestination, _newData);\n\n if (_data.length > 0) {\n require(_newDestination.isContract(), \"TO_NOT_CONTRACT\");\n bool success = ITradeableExitReceiver(_newDestination).onExitTransfer(\n expectedSender,\n _exitNum,\n _data\n );\n require(success, \"TRANSFER_HOOK_FAIL\");\n }\n\n emit WithdrawRedirected(\n expectedSender,\n _newDestination,\n _exitNum,\n _newData,\n _data,\n _data.length > 0\n );\n }\n\n /// @notice this does not verify if the external call was already done\n function getExternalCall(\n uint256 _exitNum,\n address _initialDestination,\n bytes memory _initialData\n ) public view virtual override returns (address target, bytes memory data) {\n // this function is virtual so that subclasses can override it with custom logic where necessary\n bytes32 withdrawData = encodeWithdrawal(_exitNum, _initialDestination);\n ExitData storage exit = redirectedExits[withdrawData];\n\n // here we don't authenticate `_initialData`. we could hash it into `withdrawData` but would increase gas costs\n // this is safe because if the exit isn't overriden, the _initialData coming from L2 is trusted\n // but if the exit is traded, all we care about is the latest user calldata\n if (exit.isExit) {\n return (exit._newTo, exit._newData);\n } else {\n return (_initialDestination, _initialData);\n }\n }\n\n function setRedirectedExit(\n uint256 _exitNum,\n address _initialDestination,\n address _newDestination,\n bytes memory _newData\n ) internal {\n bytes32 withdrawData = encodeWithdrawal(_exitNum, _initialDestination);\n redirectedExits[withdrawData] = ExitData(true, _newDestination, _newData);\n }\n\n function encodeWithdrawal(uint256 _exitNum, address _initialDestination)\n public\n pure\n returns (bytes32)\n {\n // here we assume the L2 bridge gives a unique exitNum to each exit\n return keccak256(abi.encode(_exitNum, _initialDestination));\n }\n}\n"
},
"contracts/arbitrum/arb-peripherals/L2CustomGateway.sol": {
"content": "// SPDX-License-Identifier: Apache-2.0\n\n/*\n * Copyright 2020, Offchain Labs, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npragma solidity ^0.8.9;\n\nimport \"@openzeppelin/contracts/utils/math/SafeMath.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\n\nimport \"./L2ArbitrumGateway.sol\";\nimport \"./interfaces/ICustomGateway.sol\";\n\n\ncontract L2CustomGateway is L2ArbitrumGateway, ICustomGateway {\n // stores addresses of L2 tokens to be used\n mapping(address => address) public override l1ToL2Token;\n\n function initialize(address _l1Counterpart, address _router) public {\n L2ArbitrumGateway._initialize(_l1Counterpart, _router);\n }\n\n /**\n * @notice internal utility function used to handle when no contract is deployed at expected address\n */\n function handleNoContract(\n address _l1Token,\n address, /* expectedL2Address */\n address _from,\n address, /* _to */\n uint256 _amount,\n bytes memory /* gatewayData */\n ) internal override returns (bool shouldHalt) {\n // it is assumed that the custom token is deployed in the L2 before deposits are made\n // trigger withdrawal\n // we don't need the return value from triggerWithdrawal since this is forcing a withdrawal back to the L1\n // instead of composing with a L2 dapp\n triggerWithdrawal(_l1Token, address(this), _from, _amount, \"\");\n return true;\n }\n\n function outboundEscrowTransfer(\n address _l2Token,\n address _from,\n uint256 _amount\n ) internal override virtual returns (uint256 amountBurnt) {\n uint256 prevBalance = IERC20(_l2Token).balanceOf(_from);\n\n // in the custom gateway, we do the same behaviour as the superclass, but actually check\n // for the balances of tokens to ensure that inflationary / deflationary changes in the amount\n // are taken into account\n // we ignore the return value since we actually query the token before and after to calculate\n // the amount of tokens that were burnt\n super.outboundEscrowTransfer(_l2Token, _from, _amount);\n\n uint256 postBalance = IERC20(_l2Token).balanceOf(_from);\n return SafeMath.sub(prevBalance, postBalance);\n }\n\n /**\n * @notice Calculate the address used when bridging an ERC20 token\n * @dev the L1 and L2 address oracles may not always be in sync.\n * For example, a custom token may have been registered but not deploy or the contract self destructed.\n * @param l1ERC20 address of L1 token\n * @return L2 address of a bridged ERC20 token\n */\n function calculateL2TokenAddress(address l1ERC20) public view override returns (address) {\n return l1ToL2Token[l1ERC20];\n }\n\n function registerTokenFromL1(address[] calldata l1Address, address[] calldata l2Address)\n external\n onlyCounterpartGateway\n {\n // we assume both arrays are the same length, safe since its encoded by the L1\n for (uint256 i = 0; i < l1Address.length; i++) {\n // here we don't check if l2Address is a contract and instead deal with that behaviour\n // in `handleNoContract` this way we keep the l1 and l2 address oracles in sync\n l1ToL2Token[l1Address[i]] = l2Address[i];\n emit TokenSet(l1Address[i], l2Address[i]);\n }\n }\n}\n"
},
"contracts/arbitrum/arb-peripherals/interfaces/ITransferAndCall.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.9;\n\nimport \"@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol\";\n\ninterface ITransferAndCall is IERC20Upgradeable {\n function transferAndCall(\n address to,\n uint256 value,\n bytes memory data\n ) external returns (bool success);\n\n event Transfer(address indexed from, address indexed to, uint256 value, bytes data);\n}\n\n/**\n * @notice note that implementation of ITransferAndCallReceiver is not expected to return a success bool\n */\ninterface ITransferAndCallReceiver {\n function onTokenTransfer(\n address _sender,\n uint256 _value,\n bytes memory _data\n ) external;\n}\n"
},
"contracts/arbitrum/arb-peripherals/L1ArbitrumGateway.sol": {
"content": "// SPDX-License-Identifier: Apache-2.0\n\n/*\n * Copyright 2020, Offchain Labs, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npragma solidity ^0.8.9;\n\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\nimport \"@openzeppelin/contracts/utils/Create2.sol\";\nimport \"@openzeppelin/contracts/utils/Address.sol\";\nimport \"@openzeppelin/contracts/utils/math/SafeMath.sol\";\n\nimport \"./interfaces/IInbox.sol\";\nimport \"./interfaces/ITransferAndCall.sol\";\nimport \"./libraries/ProxyUtil.sol\";\nimport \"./libraries/GatewayMessageHandler.sol\";\nimport \"./libraries/TokenGateway.sol\";\nimport \"./L1ArbitrumMessenger.sol\";\n\n/**\n * @title Common interface for gatways on L1 messaging to Arbitrum.\n */\nabstract contract L1ArbitrumGateway is L1ArbitrumMessenger, TokenGateway {\n using SafeERC20 for IERC20;\n using Address for address;\n\n address public inbox;\n\n event DepositInitiated(\n address l1Token,\n address indexed _from,\n address indexed _to,\n uint256 indexed _sequenceNumber,\n uint256 _amount\n );\n\n event WithdrawalFinalized(\n address l1Token,\n address indexed _from,\n address indexed _to,\n uint256 indexed _exitNum,\n uint256 _amount\n );\n\n modifier onlyCounterpartGateway() override {\n address _inbox = inbox;\n\n // a message coming from the counterpart gateway was executed by the bridge\n address bridge = address(super.getBridge(_inbox));\n require(msg.sender == bridge, \"NOT_FROM_BRIDGE\");\n\n // and the outbox reports that the L2 address of the sender is the counterpart gateway\n address l2ToL1Sender = super.getL2ToL1Sender(_inbox);\n require(l2ToL1Sender == counterpartGateway, \"ONLY_COUNTERPART_GATEWAY\");\n _;\n }\n\n function postUpgradeInit() virtual external {\n // it is assumed the L1 Arbitrum Gateway contract is behind a Proxy controlled by a proxy admin\n // this function can only be called by the proxy admin contract\n address proxyAdmin = ProxyUtil.getProxyAdmin();\n require(msg.sender == proxyAdmin, \"NOT_FROM_ADMIN\");\n // this has no other logic since the current upgrade doesn't require this logic\n }\n\n function _initialize(\n address _l2Counterpart,\n address _router,\n address _inbox\n ) internal virtual {\n TokenGateway._initialize(_l2Counterpart, _router);\n // L1 gateway must have a router\n require(_router != address(0), \"BAD_ROUTER\");\n require(_inbox != address(0), \"BAD_INBOX\");\n inbox = _inbox;\n }\n\n /**\n * @notice Finalizes a withdrawal via Outbox message; callable only by L2Gateway.outboundTransfer\n * @param _token L1 address of token being withdrawn from\n * @param _from initiator of withdrawal\n * @param _to address the L2 withdrawal call set as the destination.\n * @param _amount Token amount being withdrawn\n * @param _data encoded exitNum (Sequentially increasing exit counter determined by the L2Gateway) and additinal hook data\n */\n function finalizeInboundTransfer(\n address _token,\n address _from,\n address _to,\n uint256 _amount,\n bytes calldata _data\n ) public payable virtual override onlyCounterpartGateway {\n // this function is marked as virtual so superclasses can override it to add modifiers\n (uint256 exitNum, bytes memory callHookData) = GatewayMessageHandler.parseToL1GatewayMsg(\n _data\n );\n\n if (callHookData.length != 0) {\n // callHookData should always be 0 since inboundEscrowAndCall is disabled\n callHookData = bytes(\"\");\n }\n\n // we ignore the returned data since the callHook feature is now disabled\n (_to, ) = getExternalCall(exitNum, _to, callHookData);\n inboundEscrowTransfer(_token, _to, _amount);\n\n emit WithdrawalFinalized(_token, _from, _to, exitNum, _amount);\n }\n\n function getExternalCall(\n uint256, /* _exitNum */\n address _initialDestination,\n bytes memory _initialData\n ) public view virtual returns (address target, bytes memory data) {\n // this method is virtual so the destination of a call can be changed\n // using tradeable exits in a subclass (L1ArbitrumExtendedGateway)\n target = _initialDestination;\n data = _initialData;\n }\n\n function inboundEscrowTransfer(\n address _l1Token,\n address _dest,\n uint256 _amount\n ) internal virtual {\n // this method is virtual since different subclasses can handle escrow differently\n IERC20(_l1Token).safeTransfer(_dest, _amount);\n }\n\n function createOutboundTx(\n address _from,\n uint256, /* _tokenAmount */\n uint256 _maxGas,\n uint256 _gasPriceBid,\n uint256 _maxSubmissionCost,\n bytes memory _outboundCalldata\n ) internal virtual returns (uint256) {\n // We make this function virtual since outboundTransfer logic is the same for many gateways\n // but sometimes (ie weth) you construct the outgoing message differently.\n\n // msg.value is sent, but 0 is set to the L2 call value\n // the eth sent is used to pay for the tx's gas\n return\n sendTxToL2(\n inbox,\n counterpartGateway,\n _from,\n msg.value, // we forward the L1 call value to the inbox\n 0, // l2 call value 0 by default\n L2GasParams({\n _maxSubmissionCost: _maxSubmissionCost,\n _maxGas: _maxGas,\n _gasPriceBid: _gasPriceBid\n }),\n _outboundCalldata\n );\n }\n\n /**\n * @notice Deposit ERC20 token from Ethereum into Arbitrum. If L2 side hasn't been deployed yet, includes name/symbol/decimals data for initial L2 deploy. Initiate by GatewayRouter.\n * @param _l1Token L1 address of ERC20\n * @param _to account to be credited with the tokens in the L2 (can be the user's L2 account or a contract)\n * @param _amount Token Amount\n * @param _maxGas Max gas deducted from user's L2 balance to cover L2 execution\n * @param _gasPriceBid Gas price for L2 execution\n * @param _data encoded data from router and user\n * @return res abi encoded inbox sequence number\n */\n // * @param maxSubmissionCost Max gas deducted from user's L2 balance to cover base submission fee\n function outboundTransfer(\n address _l1Token,\n address _to,\n uint256 _amount,\n uint256 _maxGas,\n uint256 _gasPriceBid,\n bytes calldata _data\n ) public payable virtual override returns (bytes memory res) {\n require(isRouter(msg.sender), \"NOT_FROM_ROUTER\");\n // This function is set as public and virtual so that subclasses can override\n // it and add custom validation for callers (ie only whitelisted users)\n address _from;\n uint256 seqNum;\n bytes memory extraData;\n {\n uint256 _maxSubmissionCost;\n if (super.isRouter(msg.sender)) {\n // router encoded\n (_from, extraData) = GatewayMessageHandler.parseFromRouterToGateway(_data);\n } else {\n _from = msg.sender;\n extraData = _data;\n }\n // user encoded\n (_maxSubmissionCost, extraData) = abi.decode(extraData, (uint256, bytes));\n // the inboundEscrowAndCall functionality has been disabled, so no data is allowed\n require(extraData.length == 0, \"EXTRA_DATA_DISABLED\");\n\n require(_l1Token.isContract(), \"L1_NOT_CONTRACT\");\n address l2Token = calculateL2TokenAddress(_l1Token);\n require(l2Token != address(0), \"NO_L2_TOKEN_SET\");\n\n _amount = outboundEscrowTransfer(_l1Token, _from, _amount);\n\n // we override the res field to save on the stack\n res = getOutboundCalldata(_l1Token, _from, _to, _amount, extraData);\n\n seqNum = createOutboundTx(\n _from,\n _amount,\n _maxGas,\n _gasPriceBid,\n _maxSubmissionCost,\n res\n );\n }\n emit DepositInitiated(_l1Token, _from, _to, seqNum, _amount);\n return abi.encode(seqNum);\n }\n\n function outboundEscrowTransfer(\n address _l1Token,\n address _from,\n uint256 _amount\n ) internal virtual returns (uint256 amountReceived) {\n // this method is virtual since different subclasses can handle escrow differently\n // user funds are escrowed on the gateway using this function\n uint256 prevBalance = IERC20(_l1Token).balanceOf(address(this));\n IERC20(_l1Token).safeTransferFrom(_from, address(this), _amount);\n uint256 postBalance = IERC20(_l1Token).balanceOf(address(this));\n return SafeMath.sub(postBalance, prevBalance);\n }\n\n function getOutboundCalldata(\n address _l1Token,\n address _from,\n address _to,\n uint256 _amount,\n bytes memory _data\n ) public view virtual override returns (bytes memory outboundCalldata) {\n // this function is public so users can query how much calldata will be sent to the L2\n // before execution\n // it is virtual since different gateway subclasses can build this calldata differently\n // ( ie the standard ERC20 gateway queries for a tokens name/symbol/decimals )\n bytes memory emptyBytes = \"\";\n\n outboundCalldata = abi.encodeWithSelector(\n TokenGateway.finalizeInboundTransfer.selector,\n _l1Token,\n _from,\n _to,\n _amount,\n GatewayMessageHandler.encodeToL2GatewayMsg(emptyBytes, _data)\n );\n\n return outboundCalldata;\n }\n}\n"
},
"@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20Upgradeable {\n /**\n * @dev Returns the amount of tokens in existence.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns the amount of tokens owned by `account`.\n */\n function balanceOf(address account) external view returns (uint256);\n\n /**\n * @dev Moves `amount` tokens from the caller's account to `to`.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transfer(address to, uint256 amount) external returns (bool);\n\n /**\n * @dev Returns the remaining number of tokens that `spender` will be\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\n * zero by default.\n *\n * This value changes when {approve} or {transferFrom} are called.\n */\n function allowance(address owner, address spender) external view returns (uint256);\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\n * that someone may use both the old and the new allowance by unfortunate\n * transaction ordering. One possible solution to mitigate this race\n * condition is to first reduce the spender's allowance to 0 and set the\n * desired value afterwards:\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n *\n * Emits an {Approval} event.\n */\n function approve(address spender, uint256 amount) external returns (bool);\n\n /**\n * @dev Moves `amount` tokens from `from` to `to` using the\n * allowance mechanism. `amount` is then deducted from the caller's\n * allowance.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(\n address from,\n address to,\n uint256 amount\n ) external returns (bool);\n\n /**\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\n * another (`to`).\n *\n * Note that `value` may be zero.\n */\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n /**\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n * a call to {approve}. `value` is the new allowance.\n */\n event Approval(address indexed owner, address indexed spender, uint256 value);\n}\n"
},
"@openzeppelin/contracts/token/ERC20/ERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/ERC20.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC20.sol\";\nimport \"./extensions/IERC20Metadata.sol\";\nimport \"../../utils/Context.sol\";\n\n/**\n * @dev Implementation of the {IERC20} interface.\n *\n * This implementation is agnostic to the way tokens are created. This means\n * that a supply mechanism has to be added in a derived contract using {_mint}.\n * For a generic mechanism see {ERC20PresetMinterPauser}.\n *\n * TIP: For a detailed writeup see our guide\n * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How\n * to implement supply mechanisms].\n *\n * We have followed general OpenZeppelin Contracts guidelines: functions revert\n * instead returning `false` on failure. This behavior is nonetheless\n * conventional and does not conflict with the expectations of ERC20\n * applications.\n *\n * Additionally, an {Approval} event is emitted on calls to {transferFrom}.\n * This allows applications to reconstruct the allowance for all accounts just\n * by listening to said events. Other implementations of the EIP may not emit\n * these events, as it isn't required by the specification.\n *\n * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}\n * functions have been added to mitigate the well-known issues around setting\n * allowances. See {IERC20-approve}.\n */\ncontract ERC20 is Context, IERC20, IERC20Metadata {\n mapping(address => uint256) private _balances;\n\n mapping(address => mapping(address => uint256)) private _allowances;\n\n uint256 private _totalSupply;\n\n string private _name;\n string private _symbol;\n\n /**\n * @dev Sets the values for {name} and {symbol}.\n *\n * The default value of {decimals} is 18. To select a different value for\n * {decimals} you should overload it.\n *\n * All two of these values are immutable: they can only be set once during\n * construction.\n */\n constructor(string memory name_, string memory symbol_) {\n _name = name_;\n _symbol = symbol_;\n }\n\n /**\n * @dev Returns the name of the token.\n */\n function name() public view virtual override returns (string memory) {\n return _name;\n }\n\n /**\n * @dev Returns the symbol of the token, usually a shorter version of the\n * name.\n */\n function symbol() public view virtual override returns (string memory) {\n return _symbol;\n }\n\n /**\n * @dev Returns the number of decimals used to get its user representation.\n * For example, if `decimals` equals `2`, a balance of `505` tokens should\n * be displayed to a user as `5.05` (`505 / 10 ** 2`).\n *\n * Tokens usually opt for a value of 18, imitating the relationship between\n * Ether and Wei. This is the value {ERC20} uses, unless this function is\n * overridden;\n *\n * NOTE: This information is only used for _display_ purposes: it in\n * no way affects any of the arithmetic of the contract, including\n * {IERC20-balanceOf} and {IERC20-transfer}.\n */\n function decimals() public view virtual override returns (uint8) {\n return 18;\n }\n\n /**\n * @dev See {IERC20-totalSupply}.\n */\n function totalSupply() public view virtual override returns (uint256) {\n return _totalSupply;\n }\n\n /**\n * @dev See {IERC20-balanceOf}.\n */\n function balanceOf(address account) public view virtual override returns (uint256) {\n return _balances[account];\n }\n\n /**\n * @dev See {IERC20-transfer}.\n *\n * Requirements:\n *\n * - `to` cannot be the zero address.\n * - the caller must have a balance of at least `amount`.\n */\n function transfer(address to, uint256 amount) public virtual override returns (bool) {\n address owner = _msgSender();\n _transfer(owner, to, amount);\n return true;\n }\n\n /**\n * @dev See {IERC20-allowance}.\n */\n function allowance(address owner, address spender) public view virtual override returns (uint256) {\n return _allowances[owner][spender];\n }\n\n /**\n * @dev See {IERC20-approve}.\n *\n * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on\n * `transferFrom`. This is semantically equivalent to an infinite approval.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function approve(address spender, uint256 amount) public virtual override returns (bool) {\n address owner = _msgSender();\n _approve(owner, spender, amount);\n return true;\n }\n\n /**\n * @dev See {IERC20-transferFrom}.\n *\n * Emits an {Approval} event indicating the updated allowance. This is not\n * required by the EIP. See the note at the beginning of {ERC20}.\n *\n * NOTE: Does not update the allowance if the current allowance\n * is the maximum `uint256`.\n *\n * Requirements:\n *\n * - `from` and `to` cannot be the zero address.\n * - `from` must have a balance of at least `amount`.\n * - the caller must have allowance for ``from``'s tokens of at least\n * `amount`.\n */\n function transferFrom(\n address from,\n address to,\n uint256 amount\n ) public virtual override returns (bool) {\n address spender = _msgSender();\n _spendAllowance(from, spender, amount);\n _transfer(from, to, amount);\n return true;\n }\n\n /**\n * @dev Atomically increases the allowance granted to `spender` by the caller.\n *\n * This is an alternative to {approve} that can be used as a mitigation for\n * problems described in {IERC20-approve}.\n *\n * Emits an {Approval} event indicating the updated allowance.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {\n address owner = _msgSender();\n _approve(owner, spender, _allowances[owner][spender] + addedValue);\n return true;\n }\n\n /**\n * @dev Atomically decreases the allowance granted to `spender` by the caller.\n *\n * This is an alternative to {approve} that can be used as a mitigation for\n * problems described in {IERC20-approve}.\n *\n * Emits an {Approval} event indicating the updated allowance.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n * - `spender` must have allowance for the caller of at least\n * `subtractedValue`.\n */\n function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {\n address owner = _msgSender();\n uint256 currentAllowance = _allowances[owner][spender];\n require(currentAllowance >= subtractedValue, \"ERC20: decreased allowance below zero\");\n unchecked {\n _approve(owner, spender, currentAllowance - subtractedValue);\n }\n\n return true;\n }\n\n /**\n * @dev Moves `amount` of tokens from `sender` to `recipient`.\n *\n * This internal function is equivalent to {transfer}, and can be used to\n * e.g. implement automatic token fees, slashing mechanisms, etc.\n *\n * Emits a {Transfer} event.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `from` must have a balance of at least `amount`.\n */\n function _transfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual {\n require(from != address(0), \"ERC20: transfer from the zero address\");\n require(to != address(0), \"ERC20: transfer to the zero address\");\n\n _beforeTokenTransfer(from, to, amount);\n\n uint256 fromBalance = _balances[from];\n require(fromBalance >= amount, \"ERC20: transfer amount exceeds balance\");\n unchecked {\n _balances[from] = fromBalance - amount;\n }\n _balances[to] += amount;\n\n emit Transfer(from, to, amount);\n\n _afterTokenTransfer(from, to, amount);\n }\n\n /** @dev Creates `amount` tokens and assigns them to `account`, increasing\n * the total supply.\n *\n * Emits a {Transfer} event with `from` set to the zero address.\n *\n * Requirements:\n *\n * - `account` cannot be the zero address.\n */\n function _mint(address account, uint256 amount) internal virtual {\n require(account != address(0), \"ERC20: mint to the zero address\");\n\n _beforeTokenTransfer(address(0), account, amount);\n\n _totalSupply += amount;\n _balances[account] += amount;\n emit Transfer(address(0), account, amount);\n\n _afterTokenTransfer(address(0), account, amount);\n }\n\n /**\n * @dev Destroys `amount` tokens from `account`, reducing the\n * total supply.\n *\n * Emits a {Transfer} event with `to` set to the zero address.\n *\n * Requirements:\n *\n * - `account` cannot be the zero address.\n * - `account` must have at least `amount` tokens.\n */\n function _burn(address account, uint256 amount) internal virtual {\n require(account != address(0), \"ERC20: burn from the zero address\");\n\n _beforeTokenTransfer(account, address(0), amount);\n\n uint256 accountBalance = _balances[account];\n require(accountBalance >= amount, \"ERC20: burn amount exceeds balance\");\n unchecked {\n _balances[account] = accountBalance - amount;\n }\n _totalSupply -= amount;\n\n emit Transfer(account, address(0), amount);\n\n _afterTokenTransfer(account, address(0), amount);\n }\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.\n *\n * This internal function is equivalent to `approve`, and can be used to\n * e.g. set automatic allowances for certain subsystems, etc.\n *\n * Emits an {Approval} event.\n *\n * Requirements:\n *\n * - `owner` cannot be the zero address.\n * - `spender` cannot be the zero address.\n */\n function _approve(\n address owner,\n address spender,\n uint256 amount\n ) internal virtual {\n require(owner != address(0), \"ERC20: approve from the zero address\");\n require(spender != address(0), \"ERC20: approve to the zero address\");\n\n _allowances[owner][spender] = amount;\n emit Approval(owner, spender, amount);\n }\n\n /**\n * @dev Spend `amount` form the allowance of `owner` toward `spender`.\n *\n * Does not update the allowance amount in case of infinite allowance.\n * Revert if not enough allowance is available.\n *\n * Might emit an {Approval} event.\n */\n function _spendAllowance(\n address owner,\n address spender,\n uint256 amount\n ) internal virtual {\n uint256 currentAllowance = allowance(owner, spender);\n if (currentAllowance != type(uint256).max) {\n require(currentAllowance >= amount, \"ERC20: insufficient allowance\");\n unchecked {\n _approve(owner, spender, currentAllowance - amount);\n }\n }\n }\n\n /**\n * @dev Hook that is called before any transfer of tokens. This includes\n * minting and burning.\n *\n * Calling conditions:\n *\n * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n * will be transferred to `to`.\n * - when `from` is zero, `amount` tokens will be minted for `to`.\n * - when `to` is zero, `amount` of ``from``'s tokens will be burned.\n * - `from` and `to` are never both zero.\n *\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n */\n function _beforeTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual {}\n\n /**\n * @dev Hook that is called after any transfer of tokens. This includes\n * minting and burning.\n *\n * Calling conditions:\n *\n * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n * has been transferred to `to`.\n * - when `from` is zero, `amount` tokens have been minted for `to`.\n * - when `to` is zero, `amount` of ``from``'s tokens have been burned.\n * - `from` and `to` are never both zero.\n *\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n */\n function _afterTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual {}\n}\n"
},
"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20.sol\";\nimport \"../../../utils/Address.sol\";\n\n/**\n * @title SafeERC20\n * @dev Wrappers around ERC20 operations that throw on failure (when the token\n * contract returns false). Tokens that return no value (and instead revert or\n * throw on failure) are also supported, non-reverting calls are assumed to be\n * successful.\n * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,\n * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.\n */\nlibrary SafeERC20 {\n using Address for address;\n\n function safeTransfer(\n IERC20 token,\n address to,\n uint256 value\n ) internal {\n _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));\n }\n\n function safeTransferFrom(\n IERC20 token,\n address from,\n address to,\n uint256 value\n ) internal {\n _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));\n }\n\n /**\n * @dev Deprecated. This function has issues similar to the ones found in\n * {IERC20-approve}, and its usage is discouraged.\n *\n * Whenever possible, use {safeIncreaseAllowance} and\n * {safeDecreaseAllowance} instead.\n */\n function safeApprove(\n IERC20 token,\n address spender,\n uint256 value\n ) internal {\n // safeApprove should only be called when setting an initial allowance,\n // or when resetting it to zero. To increase and decrease it, use\n // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'\n require(\n (value == 0) || (token.allowance(address(this), spender) == 0),\n \"SafeERC20: approve from non-zero to non-zero allowance\"\n );\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));\n }\n\n function safeIncreaseAllowance(\n IERC20 token,\n address spender,\n uint256 value\n ) internal {\n uint256 newAllowance = token.allowance(address(this), spender) + value;\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\n }\n\n function safeDecreaseAllowance(\n IERC20 token,\n address spender,\n uint256 value\n ) internal {\n unchecked {\n uint256 oldAllowance = token.allowance(address(this), spender);\n require(oldAllowance >= value, \"SafeERC20: decreased allowance below zero\");\n uint256 newAllowance = oldAllowance - value;\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\n }\n }\n\n /**\n * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n * on the return value: the return value is optional (but if data is returned, it must not be false).\n * @param token The token targeted by the call.\n * @param data The call data (encoded using abi.encode or one of its variants).\n */\n function _callOptionalReturn(IERC20 token, bytes memory data) private {\n // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since\n // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that\n // the target address contains contract code and also asserts for success in the low-level call.\n\n bytes memory returndata = address(token).functionCall(data, \"SafeERC20: low-level call failed\");\n if (returndata.length > 0) {\n // Return data is optional\n require(abi.decode(returndata, (bool)), \"SafeERC20: ERC20 operation did not succeed\");\n }\n }\n}\n"
},
"@openzeppelin/contracts/utils/Create2.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Create2.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Helper to make usage of the `CREATE2` EVM opcode easier and safer.\n * `CREATE2` can be used to compute in advance the address where a smart\n * contract will be deployed, which allows for interesting new mechanisms known\n * as 'counterfactual interactions'.\n *\n * See the https://eips.ethereum.org/EIPS/eip-1014#motivation[EIP] for more\n * information.\n */\nlibrary Create2 {\n /**\n * @dev Deploys a contract using `CREATE2`. The address where the contract\n * will be deployed can be known in advance via {computeAddress}.\n *\n * The bytecode for a contract can be obtained from Solidity with\n * `type(contractName).creationCode`.\n *\n * Requirements:\n *\n * - `bytecode` must not be empty.\n * - `salt` must have not been used for `bytecode` already.\n * - the factory must have a balance of at least `amount`.\n * - if `amount` is non-zero, `bytecode` must have a `payable` constructor.\n */\n function deploy(\n uint256 amount,\n bytes32 salt,\n bytes memory bytecode\n ) internal returns (address) {\n address addr;\n require(address(this).balance >= amount, \"Create2: insufficient balance\");\n require(bytecode.length != 0, \"Create2: bytecode length is zero\");\n assembly {\n addr := create2(amount, add(bytecode, 0x20), mload(bytecode), salt)\n }\n require(addr != address(0), \"Create2: Failed on deploy\");\n return addr;\n }\n\n /**\n * @dev Returns the address where a contract will be stored if deployed via {deploy}. Any change in the\n * `bytecodeHash` or `salt` will result in a new destination address.\n */\n function computeAddress(bytes32 salt, bytes32 bytecodeHash) internal view returns (address) {\n return computeAddress(salt, bytecodeHash, address(this));\n }\n\n /**\n * @dev Returns the address where a contract will be stored if deployed via {deploy} from a contract located at\n * `deployer`. If `deployer` is this contract's address, returns the same value as {computeAddress}.\n */\n function computeAddress(\n bytes32 salt,\n bytes32 bytecodeHash,\n address deployer\n ) internal pure returns (address) {\n bytes32 _data = keccak256(abi.encodePacked(bytes1(0xff), deployer, salt, bytecodeHash));\n return address(uint160(uint256(_data)));\n }\n}\n"
},
"@openzeppelin/contracts/utils/math/SafeMath.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/math/SafeMath.sol)\n\npragma solidity ^0.8.0;\n\n// CAUTION\n// This version of SafeMath should only be used with Solidity 0.8 or later,\n// because it relies on the compiler's built in overflow checks.\n\n/**\n * @dev Wrappers over Solidity's arithmetic operations.\n *\n * NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler\n * now has built in overflow checking.\n */\nlibrary SafeMath {\n /**\n * @dev Returns the addition of two unsigned integers, with an overflow flag.\n *\n * _Available since v3.4._\n */\n function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n unchecked {\n uint256 c = a + b;\n if (c < a) return (false, 0);\n return (true, c);\n }\n }\n\n /**\n * @dev Returns the substraction of two unsigned integers, with an overflow flag.\n *\n * _Available since v3.4._\n */\n function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n unchecked {\n if (b > a) return (false, 0);\n return (true, a - b);\n }\n }\n\n /**\n * @dev Returns the multiplication of two unsigned integers, with an overflow flag.\n *\n * _Available since v3.4._\n */\n function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n unchecked {\n // Gas optimization: this is cheaper than requiring 'a' not being zero, but the\n // benefit is lost if 'b' is also tested.\n // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522\n if (a == 0) return (true, 0);\n uint256 c = a * b;\n if (c / a != b) return (false, 0);\n return (true, c);\n }\n }\n\n /**\n * @dev Returns the division of two unsigned integers, with a division by zero flag.\n *\n * _Available since v3.4._\n */\n function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n unchecked {\n if (b == 0) return (false, 0);\n return (true, a / b);\n }\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.\n *\n * _Available since v3.4._\n */\n function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n unchecked {\n if (b == 0) return (false, 0);\n return (true, a % b);\n }\n }\n\n /**\n * @dev Returns the addition of two unsigned integers, reverting on\n * overflow.\n *\n * Counterpart to Solidity's `+` operator.\n *\n * Requirements:\n *\n * - Addition cannot overflow.\n */\n function add(uint256 a, uint256 b) internal pure returns (uint256) {\n return a + b;\n }\n\n /**\n * @dev Returns the subtraction of two unsigned integers, reverting on\n * overflow (when the result is negative).\n *\n * Counterpart to Solidity's `-` operator.\n *\n * Requirements:\n *\n * - Subtraction cannot overflow.\n */\n function sub(uint256 a, uint256 b) internal pure returns (uint256) {\n return a - b;\n }\n\n /**\n * @dev Returns the multiplication of two unsigned integers, reverting on\n * overflow.\n *\n * Counterpart to Solidity's `*` operator.\n *\n * Requirements:\n *\n * - Multiplication cannot overflow.\n */\n function mul(uint256 a, uint256 b) internal pure returns (uint256) {\n return a * b;\n }\n\n /**\n * @dev Returns the integer division of two unsigned integers, reverting on\n * division by zero. The result is rounded towards zero.\n *\n * Counterpart to Solidity's `/` operator.\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function div(uint256 a, uint256 b) internal pure returns (uint256) {\n return a / b;\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n * reverting when dividing by zero.\n *\n * Counterpart to Solidity's `%` operator. This function uses a `revert`\n * opcode (which leaves remaining gas untouched) while Solidity uses an\n * invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function mod(uint256 a, uint256 b) internal pure returns (uint256) {\n return a % b;\n }\n\n /**\n * @dev Returns the subtraction of two unsigned integers, reverting with custom message on\n * overflow (when the result is negative).\n *\n * CAUTION: This function is deprecated because it requires allocating memory for the error\n * message unnecessarily. For custom revert reasons use {trySub}.\n *\n * Counterpart to Solidity's `-` operator.\n *\n * Requirements:\n *\n * - Subtraction cannot overflow.\n */\n function sub(\n uint256 a,\n uint256 b,\n string memory errorMessage\n ) internal pure returns (uint256) {\n unchecked {\n require(b <= a, errorMessage);\n return a - b;\n }\n }\n\n /**\n * @dev Returns the integer division of two unsigned integers, reverting with custom message on\n * division by zero. The result is rounded towards zero.\n *\n * Counterpart to Solidity's `/` operator. Note: this function uses a\n * `revert` opcode (which leaves remaining gas untouched) while Solidity\n * uses an invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function div(\n uint256 a,\n uint256 b,\n string memory errorMessage\n ) internal pure returns (uint256) {\n unchecked {\n require(b > 0, errorMessage);\n return a / b;\n }\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n * reverting with custom message when dividing by zero.\n *\n * CAUTION: This function is deprecated because it requires allocating memory for the error\n * message unnecessarily. For custom revert reasons use {tryMod}.\n *\n * Counterpart to Solidity's `%` operator. This function uses a `revert`\n * opcode (which leaves remaining gas untouched) while Solidity uses an\n * invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function mod(\n uint256 a,\n uint256 b,\n string memory errorMessage\n ) internal pure returns (uint256) {\n unchecked {\n require(b > 0, errorMessage);\n return a % b;\n }\n }\n}\n"
},
"contracts/arbitrum/arb-peripherals/interfaces/IInbox.sol": {
"content": "// Copyright 2021-2022, Offchain Labs, Inc.\n// For license information, see https://github.com/nitro/blob/master/LICENSE\n// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity ^0.8.4;\n\nimport \"./IBridge.sol\";\nimport \"./IDelayedMessageProvider.sol\";\nimport {AlreadyInit, NotOrigin, DataTooLarge} from \"../libraries/Error.sol\";\n\n/// @dev The contract is paused, so cannot be paused\nerror AlreadyPaused();\n\n/// @dev The contract is unpaused, so cannot be unpaused\nerror AlreadyUnpaused();\n\n/// @dev The contract is paused\nerror Paused();\n\n/// @dev msg.value sent to the inbox isn't high enough\nerror InsufficientValue(uint256 expected, uint256 actual);\n\n/// @dev submission cost provided isn't enough to create retryable ticket\nerror InsufficientSubmissionCost(uint256 expected, uint256 actual);\n\n/// @dev address not allowed to interact with the given contract\nerror NotAllowedOrigin(address origin);\n\n/// @dev used to convey retryable tx data in eth calls without requiring a tx trace\n/// this follows a pattern similar to EIP-3668 where reverts surface call information\nerror RetryableData(\n address from,\n address to,\n uint256 l2CallValue,\n uint256 deposit,\n uint256 maxSubmissionCost,\n address excessFeeRefundAddress,\n address callValueRefundAddress,\n uint256 gasLimit,\n uint256 maxFeePerGas,\n bytes data\n);\n\ninterface IInbox is IDelayedMessageProvider {\n function sendL2Message(bytes calldata messageData) external returns (uint256);\n\n function sendUnsignedTransaction(\n uint256 gasLimit,\n uint256 maxFeePerGas,\n uint256 nonce,\n address to,\n uint256 value,\n bytes calldata data\n ) external returns (uint256);\n\n function sendContractTransaction(\n uint256 gasLimit,\n uint256 maxFeePerGas,\n address to,\n uint256 value,\n bytes calldata data\n ) external returns (uint256);\n\n function sendL1FundedUnsignedTransaction(\n uint256 gasLimit,\n uint256 maxFeePerGas,\n uint256 nonce,\n address to,\n bytes calldata data\n ) external payable returns (uint256);\n\n function sendL1FundedContractTransaction(\n uint256 gasLimit,\n uint256 maxFeePerGas,\n address to,\n bytes calldata data\n ) external payable returns (uint256);\n\n /// @dev Gas limit and maxFeePerGas should not be set to 1 as that is used to trigger the RetryableData error\n function createRetryableTicket(\n address to,\n uint256 arbTxCallValue,\n uint256 maxSubmissionCost,\n address submissionRefundAddress,\n address valueRefundAddress,\n uint256 gasLimit,\n uint256 maxFeePerGas,\n bytes calldata data\n ) external payable returns (uint256);\n\n /// @notice TEMPORARILY DISABLED as exact mechanics are being worked out\n /// @dev Gas limit and maxFeePerGas should not be set to 1 as that is used to trigger the RetryableData error\n function unsafeCreateRetryableTicket(\n address to,\n uint256 arbTxCallValue,\n uint256 maxSubmissionCost,\n address submissionRefundAddress,\n address valueRefundAddress,\n uint256 gasLimit,\n uint256 maxFeePerGas,\n bytes calldata data\n ) external payable returns (uint256);\n\n function depositEth() external payable returns (uint256);\n\n /// @notice deprecated in favour of depositEth with no parameters\n function depositEth(uint256 maxSubmissionCost) external payable returns (uint256);\n\n function bridge() external view returns (IBridge);\n\n function calculateRetryableSubmissionFee(uint256 dataLength, uint256 baseFee) external pure returns (uint256);\n}"
},
"contracts/arbitrum/arb-peripherals/libraries/ProxyUtil.sol": {
"content": "// SPDX-License-Identifier: Apache-2.0\n\n/*\n * Copyright 2021, Offchain Labs, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npragma solidity ^0.8.9;\n\nlibrary ProxyUtil {\n function getProxyAdmin() internal view returns (address admin) {\n // https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.4.0/contracts/proxy/TransparentUpgradeableProxy.sol#L48\n // Storage slot with the admin of the proxy contract.\n // This is the keccak-256 hash of \"eip1967.proxy.admin\" subtracted by 1, and is\n bytes32 slot = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;\n assembly {\n admin := sload(slot)\n }\n }\n}\n"
},
"contracts/arbitrum/arb-peripherals/libraries/GatewayMessageHandler.sol": {
"content": "// SPDX-License-Identifier: Apache-2.0\n\n/*\n * Copyright 2021, Offchain Labs, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npragma solidity ^0.8.9;\n\n/// @notice this library manages encoding and decoding of gateway communication\nlibrary GatewayMessageHandler {\n // these are for communication from L1 to L2 gateway\n\n function encodeToL2GatewayMsg(bytes memory gatewayData, bytes memory callHookData)\n internal\n pure\n returns (bytes memory res)\n {\n res = abi.encode(gatewayData, callHookData);\n }\n\n function parseFromL1GatewayMsg(bytes calldata _data)\n internal\n pure\n returns (bytes memory gatewayData, bytes memory callHookData)\n {\n // abi decode may revert, but the encoding is done by L1 gateway, so we trust it\n (gatewayData, callHookData) = abi.decode(_data, (bytes, bytes));\n }\n\n // these are for communication from L2 to L1 gateway\n\n function encodeFromL2GatewayMsg(uint256 exitNum, bytes memory callHookData)\n internal\n pure\n returns (bytes memory res)\n {\n res = abi.encode(exitNum, callHookData);\n }\n\n function parseToL1GatewayMsg(bytes calldata _data)\n internal\n pure\n returns (uint256 exitNum, bytes memory callHookData)\n {\n // abi decode may revert, but the encoding is done by L1 gateway, so we trust it\n (exitNum, callHookData) = abi.decode(_data, (uint256, bytes));\n }\n\n // these are for communication from router to gateway\n\n function encodeFromRouterToGateway(address _from, bytes calldata _data)\n internal\n pure\n returns (bytes memory res)\n {\n // abi decode may revert, but the encoding is done by L1 gateway, so we trust it\n return abi.encode(_from, _data);\n }\n\n function parseFromRouterToGateway(bytes calldata _data)\n internal\n pure\n returns (address, bytes memory res)\n {\n // abi decode may revert, but the encoding is done by L1 gateway, so we trust it\n return abi.decode(_data, (address, bytes));\n }\n}\n"
},
"contracts/arbitrum/arb-peripherals/libraries/TokenGateway.sol": {
"content": "// SPDX-License-Identifier: Apache-2.0\n\n/*\n * Copyright 2020, Offchain Labs, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npragma solidity ^0.8.9;\n\nimport \"../interfaces/ITokenGateway.sol\";\nimport \"@openzeppelin/contracts/utils/Address.sol\";\n\nabstract contract TokenGateway is ITokenGateway {\n using Address for address;\n\n address public counterpartGateway;\n address public router;\n\n modifier onlyCounterpartGateway() virtual {\n // this method is overriden in gateways that require special logic for validation\n // ie L2 to L1 messages need to be validated against the outbox\n require(msg.sender == counterpartGateway, \"ONLY_COUNTERPART_GATEWAY\");\n _;\n }\n\n function _initialize(address _counterpartGateway, address _router) internal virtual {\n // This initializes internal variables of the abstract contract it can be chained together with other functions.\n // It is virtual so subclasses can override or wrap around this logic.\n // An example where this is useful is different subclasses that validate the router address differently\n require(_counterpartGateway != address(0), \"INVALID_COUNTERPART\");\n require(counterpartGateway == address(0), \"ALREADY_INIT\");\n counterpartGateway = _counterpartGateway;\n router = _router;\n }\n\n function isRouter(address _target) internal view returns (bool isTargetRouter) {\n return _target == router;\n }\n\n /**\n * @notice Calculate the address used when bridging an ERC20 token\n * @dev the L1 and L2 address oracles may not always be in sync.\n * For example, a custom token may have been registered but not deploy or the contract self destructed.\n * @param l1ERC20 address of L1 token\n * @return L2 address of a bridged ERC20 token\n */\n function calculateL2TokenAddress(address l1ERC20)\n public\n view\n virtual\n override\n returns (address);\n\n function outboundTransfer(\n address _token,\n address _to,\n uint256 _amount,\n uint256 _maxGas,\n uint256 _gasPriceBid,\n bytes calldata _data\n ) external payable virtual override returns (bytes memory);\n\n function getOutboundCalldata(\n address _token,\n address _from,\n address _to,\n uint256 _amount,\n bytes memory _data\n ) public view virtual returns (bytes memory);\n\n function finalizeInboundTransfer(\n address _token,\n address _from,\n address _to,\n uint256 _amount,\n bytes calldata _data\n ) external payable virtual override;\n}\n"
},
"contracts/arbitrum/arb-peripherals/L1ArbitrumMessenger.sol": {
"content": "// SPDX-License-Identifier: Apache-2.0\n\n/*\n * Copyright 2020, Offchain Labs, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npragma solidity ^0.8.9;\n\nimport \"./interfaces/IInbox.sol\";\nimport \"./interfaces/IOutbox.sol\";\n\n/// @notice L1 utility contract to assist with L1 <=> L2 interactions\n/// @dev this is an abstract contract instead of library so the functions can be easily overriden when testing\nabstract contract L1ArbitrumMessenger {\n event TxToL2(address indexed _from, address indexed _to, uint256 indexed _seqNum, bytes _data);\n\n struct L2GasParams {\n uint256 _maxSubmissionCost;\n uint256 _maxGas;\n uint256 _gasPriceBid;\n }\n\n function sendTxToL2(\n address _inbox,\n address _to,\n address _user,\n uint256 _l1CallValue,\n uint256 _l2CallValue,\n L2GasParams memory _l2GasParams,\n bytes memory _data\n ) internal virtual returns (uint256) {\n // alternative function entry point when struggling with the stack size\n return\n sendTxToL2(\n _inbox,\n _to,\n _user,\n _l1CallValue,\n _l2CallValue,\n _l2GasParams._maxSubmissionCost,\n _l2GasParams._maxGas,\n _l2GasParams._gasPriceBid,\n _data\n );\n }\n\n function sendTxToL2(\n address _inbox,\n address _to,\n address _user,\n uint256 _l1CallValue,\n uint256 _l2CallValue,\n uint256 _maxSubmissionCost,\n uint256 _maxGas,\n uint256 _gasPriceBid,\n bytes memory _data\n ) internal virtual returns (uint256) {\n uint256 seqNum = IInbox(_inbox).createRetryableTicket{ value: _l1CallValue }(\n _to,\n _l2CallValue,\n _maxSubmissionCost,\n _user,\n _user,\n _maxGas,\n _gasPriceBid,\n _data\n );\n emit TxToL2(_user, _to, seqNum, _data);\n return seqNum;\n }\n\n function getBridge(address _inbox) internal view virtual returns (IBridge) {\n return IInbox(_inbox).bridge();\n }\n\n /// @dev the l2ToL1Sender behaves as the tx.origin, the msg.sender should be validated to protect against reentrancies\n function getL2ToL1Sender(address _inbox) internal view virtual returns (address) {\n IOutbox outbox = IOutbox(getBridge(_inbox).activeOutbox());\n address l2ToL1Sender = outbox.l2ToL1Sender();\n\n require(l2ToL1Sender != address(0), \"NO_SENDER\");\n return l2ToL1Sender;\n }\n}\n"
},
"@openzeppelin/contracts/token/ERC20/IERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n /**\n * @dev Returns the amount of tokens in existence.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns the amount of tokens owned by `account`.\n */\n function balanceOf(address account) external view returns (uint256);\n\n /**\n * @dev Moves `amount` tokens from the caller's account to `to`.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transfer(address to, uint256 amount) external returns (bool);\n\n /**\n * @dev Returns the remaining number of tokens that `spender` will be\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\n * zero by default.\n *\n * This value changes when {approve} or {transferFrom} are called.\n */\n function allowance(address owner, address spender) external view returns (uint256);\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\n * that someone may use both the old and the new allowance by unfortunate\n * transaction ordering. One possible solution to mitigate this race\n * condition is to first reduce the spender's allowance to 0 and set the\n * desired value afterwards:\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n *\n * Emits an {Approval} event.\n */\n function approve(address spender, uint256 amount) external returns (bool);\n\n /**\n * @dev Moves `amount` tokens from `from` to `to` using the\n * allowance mechanism. `amount` is then deducted from the caller's\n * allowance.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(\n address from,\n address to,\n uint256 amount\n ) external returns (bool);\n\n /**\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\n * another (`to`).\n *\n * Note that `value` may be zero.\n */\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n /**\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n * a call to {approve}. `value` is the new allowance.\n */\n event Approval(address indexed owner, address indexed spender, uint256 value);\n}\n"
},
"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20.sol\";\n\n/**\n * @dev Interface for the optional metadata functions from the ERC20 standard.\n *\n * _Available since v4.1._\n */\ninterface IERC20Metadata is IERC20 {\n /**\n * @dev Returns the name of the token.\n */\n function name() external view returns (string memory);\n\n /**\n * @dev Returns the symbol of the token.\n */\n function symbol() external view returns (string memory);\n\n /**\n * @dev Returns the decimals places of the token.\n */\n function decimals() external view returns (uint8);\n}\n"
},
"@openzeppelin/contracts/utils/Context.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n}\n"
},
"contracts/arbitrum/arb-peripherals/interfaces/IBridge.sol": {
"content": "// Copyright 2021-2022, Offchain Labs, Inc.\n// For license information, see https://github.com/nitro/blob/master/LICENSE\n// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity ^0.8.4;\n\nimport {NotContract, NotRollupOrOwner} from \"../libraries/Error.sol\";\nimport \"./IOwnable.sol\";\n\n/// @dev Thrown when an un-authorized address tries to access an only-inbox function\n/// @param sender The un-authorized sender\nerror NotDelayedInbox(address sender);\n\n/// @dev Thrown when an un-authorized address tries to access an only-sequencer-inbox function\n/// @param sender The un-authorized sender\nerror NotSequencerInbox(address sender);\n\n/// @dev Thrown when an un-authorized address tries to access an only-outbox function\n/// @param sender The un-authorized sender\nerror NotOutbox(address sender);\n\n/// @dev the provided outbox address isn't valid\n/// @param outbox address of outbox being set\nerror InvalidOutboxSet(address outbox);\n\ninterface IBridge {\n event MessageDelivered(\n uint256 indexed messageIndex,\n bytes32 indexed beforeInboxAcc,\n address inbox,\n uint8 kind,\n address sender,\n bytes32 messageDataHash,\n uint256 baseFeeL1,\n uint64 timestamp\n );\n\n event BridgeCallTriggered(\n address indexed outbox,\n address indexed to,\n uint256 value,\n bytes data\n );\n\n event InboxToggle(address indexed inbox, bool enabled);\n\n event OutboxToggle(address indexed outbox, bool enabled);\n\n event SequencerInboxUpdated(address newSequencerInbox);\n\n function enqueueDelayedMessage(\n uint8 kind,\n address sender,\n bytes32 messageDataHash\n ) external payable returns (uint256);\n\n function enqueueSequencerMessage(bytes32 dataHash, uint256 afterDelayedMessagesRead)\n external\n returns (\n uint256 seqMessageIndex,\n bytes32 beforeAcc,\n bytes32 delayedAcc,\n bytes32 acc\n );\n\n function submitBatchSpendingReport(address batchPoster, bytes32 dataHash)\n external\n returns (uint256 msgNum);\n\n function executeCall(\n address to,\n uint256 value,\n bytes calldata data\n ) external returns (bool success, bytes memory returnData);\n\n // These are only callable by the admin\n function setDelayedInbox(address inbox, bool enabled) external;\n\n function setOutbox(address inbox, bool enabled) external;\n\n function setSequencerInbox(address _sequencerInbox) external;\n\n // View functions\n\n function sequencerInbox() external view returns (address);\n\n function activeOutbox() external view returns (address);\n\n function allowedDelayedInboxes(address inbox) external view returns (bool);\n\n function allowedOutboxes(address outbox) external view returns (bool);\n\n function delayedInboxAccs(uint256 index) external view returns (bytes32);\n\n function sequencerInboxAccs(uint256 index) external view returns (bytes32);\n\n function delayedMessageCount() external view returns (uint256);\n\n function sequencerMessageCount() external view returns (uint256);\n\n function rollup() external view returns (IOwnable);\n}"
},
"contracts/arbitrum/arb-peripherals/interfaces/IDelayedMessageProvider.sol": {
"content": "// Copyright 2021-2022, Offchain Labs, Inc.\n// For license information, see https://github.com/nitro/blob/master/LICENSE\n// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity ^0.8.0;\n\ninterface IDelayedMessageProvider {\n /// @dev event emitted when a inbox message is added to the Bridge's delayed accumulator\n event InboxMessageDelivered(uint256 indexed messageNum, bytes data);\n\n /// @dev event emitted when a inbox message is added to the Bridge's delayed accumulator\n /// same as InboxMessageDelivered but the batch data is available in tx.input\n event InboxMessageDeliveredFromOrigin(uint256 indexed messageNum);\n}"
},
"contracts/arbitrum/arb-peripherals/libraries/Error.sol": {
"content": "// Copyright 2021-2022, Offchain Labs, Inc.\n// For license information, see https://github.com/nitro/blob/master/LICENSE\n// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity ^0.8.4;\n\n/// @dev Init was already called\nerror AlreadyInit();\n\n/// Init was called with param set to zero that must be nonzero\nerror HadZeroInit();\n\n/// @dev Thrown when non owner tries to access an only-owner function\n/// @param sender The msg.sender who is not the owner\n/// @param owner The owner address\nerror NotOwner(address sender, address owner);\n\n/// @dev Thrown when an address that is not the rollup tries to call an only-rollup function\n/// @param sender The sender who is not the rollup\n/// @param rollup The rollup address authorized to call this function\nerror NotRollup(address sender, address rollup);\n\n/// @dev Thrown when the contract was not called directly from the origin ie msg.sender != tx.origin\nerror NotOrigin();\n\n/// @dev Provided data was too large\n/// @param dataLength The length of the data that is too large\n/// @param maxDataLength The max length the data can be\nerror DataTooLarge(uint256 dataLength, uint256 maxDataLength);\n\n/// @dev The provided is not a contract and was expected to be\n/// @param addr The adddress in question\nerror NotContract(address addr);\n\n/// @dev The merkle proof provided was too long\n/// @param actualLength The length of the merkle proof provided\n/// @param maxProofLength The max length a merkle proof can have\nerror MerkleProofTooLong(uint256 actualLength, uint256 maxProofLength);\n\n/// @dev Thrown when an un-authorized address tries to access an admin function\n/// @param sender The un-authorized sender\n/// @param rollup The rollup, which would be authorized\n/// @param owner The rollup's owner, which would be authorized\nerror NotRollupOrOwner(address sender, address rollup, address owner);"
},
"contracts/arbitrum/arb-peripherals/interfaces/IOwnable.sol": {
"content": "// Copyright 2021-2022, Offchain Labs, Inc.\n// For license information, see https://github.com/nitro/blob/master/LICENSE\n// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity ^0.8.4;\n\ninterface IOwnable {\n function owner() external view returns (address);\n}"
},
"contracts/arbitrum/arb-peripherals/interfaces/ITokenGateway.sol": {
"content": "// SPDX-License-Identifier: Apache-2.0\n\n/*\n * Copyright 2020, Offchain Labs, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npragma solidity ^0.8.9;\n\ninterface ITokenGateway {\n /// @notice event deprecated in favor of DepositInitiated and WithdrawalInitiated\n // event OutboundTransferInitiated(\n // address token,\n // address indexed _from,\n // address indexed _to,\n // uint256 indexed _transferId,\n // uint256 _amount,\n // bytes _data\n // );\n\n /// @notice event deprecated in favor of DepositFinalized and WithdrawalFinalized\n // event InboundTransferFinalized(\n // address token,\n // address indexed _from,\n // address indexed _to,\n // uint256 indexed _transferId,\n // uint256 _amount,\n // bytes _data\n // );\n\n function outboundTransfer(\n address _token,\n address _to,\n uint256 _amount,\n uint256 _maxGas,\n uint256 _gasPriceBid,\n bytes calldata _data\n ) external payable returns (bytes memory);\n\n function finalizeInboundTransfer(\n address _token,\n address _from,\n address _to,\n uint256 _amount,\n bytes calldata _data\n ) external payable;\n\n /**\n * @notice Calculate the address used when bridging an ERC20 token\n * @dev the L1 and L2 address oracles may not always be in sync.\n * For example, a custom token may have been registered but not deploy or the contract self destructed.\n * @param l1ERC20 address of L1 token\n * @return L2 address of a bridged ERC20 token\n */\n function calculateL2TokenAddress(address l1ERC20) external view returns (address);\n}\n"
},
"contracts/arbitrum/arb-peripherals/interfaces/IOutbox.sol": {
"content": "// SPDX-License-Identifier: Apache-2.0\n\n/*\n * Copyright 2021, Offchain Labs, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npragma solidity ^0.8.9;\n\ninterface IOutbox {\n event OutboxEntryCreated(\n uint256 indexed batchNum,\n uint256 outboxEntryIndex,\n bytes32 outputRoot,\n uint256 numInBatch\n );\n event OutBoxTransactionExecuted(\n address indexed destAddr,\n address indexed l2Sender,\n uint256 indexed outboxEntryIndex,\n uint256 transactionIndex\n );\n\n function l2ToL1Sender() external view returns (address);\n\n function l2ToL1Block() external view returns (uint256);\n\n function l2ToL1EthBlock() external view returns (uint256);\n\n function l2ToL1Timestamp() external view returns (uint256);\n\n function l2ToL1BatchNum() external view returns (uint256);\n\n function l2ToL1OutputId() external view returns (bytes32);\n\n function processOutgoingMessages(bytes calldata sendsData, uint256[] calldata sendLengths)\n external;\n\n function outboxEntryExists(uint256 batchNum) external view returns (bool);\n}\n"
},
"contracts/arbitrum/arb-peripherals/L2ArbitrumGateway.sol": {
"content": "// SPDX-License-Identifier: Apache-2.0\n\n/*\n * Copyright 2020, Offchain Labs, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npragma solidity ^0.8.9;\n\nimport \"@openzeppelin/contracts/utils/Address.sol\";\nimport \"./interfaces/IArbToken.sol\";\nimport \"./libraries/BytesLib.sol\";\nimport \"./libraries/ProxyUtil.sol\";\nimport \"./libraries/AddressAliasHelper.sol\";\nimport \"./libraries/GatewayMessageHandler.sol\";\nimport \"./libraries/TokenGateway.sol\";\nimport \"./L2ArbitrumMessenger.sol\";\n\n/**\n * @title Common interface for gatways on Arbitrum messaging to L1.\n */\nabstract contract L2ArbitrumGateway is L2ArbitrumMessenger, TokenGateway {\n using Address for address;\n\n uint256 public exitNum;\n\n event DepositFinalized(\n address indexed l1Token,\n address indexed _from,\n address indexed _to,\n uint256 _amount\n );\n\n event WithdrawalInitiated(\n address l1Token,\n address indexed _from,\n address indexed _to,\n uint256 indexed _l2ToL1Id,\n uint256 _exitNum,\n uint256 _amount\n );\n\n modifier onlyCounterpartGateway() override {\n require(\n msg.sender == counterpartGateway ||\n AddressAliasHelper.undoL1ToL2Alias(msg.sender) == counterpartGateway,\n \"ONLY_COUNTERPART_GATEWAY\"\n );\n _;\n }\n\n function postUpgradeInit() virtual external {\n // it is assumed the L2 Arbitrum Gateway contract is behind a Proxy controlled by a proxy admin\n // this function can only be called by the proxy admin contract\n address proxyAdmin = ProxyUtil.getProxyAdmin();\n require(msg.sender == proxyAdmin, \"NOT_FROM_ADMIN\");\n // this has no other logic since the current upgrade doesn't require this logic\n }\n\n function _initialize(address _l1Counterpart, address _router) internal virtual override {\n TokenGateway._initialize(_l1Counterpart, _router);\n // L1 gateway must have a router\n require(_router != address(0), \"BAD_ROUTER\");\n }\n\n function createOutboundTx(\n address _from,\n uint256, /* _tokenAmount */\n bytes memory _outboundCalldata\n ) internal virtual returns (uint256) {\n // We make this function virtual since outboundTransfer logic is the same for many gateways\n // but sometimes (ie weth) you construct the outgoing message differently.\n\n // exitNum incremented after being included in _outboundCalldata\n exitNum++;\n return\n sendTxToL1(\n // default to sending no callvalue to the L1\n 0,\n _from,\n counterpartGateway,\n _outboundCalldata\n );\n }\n\n function getOutboundCalldata(\n address _token,\n address _from,\n address _to,\n uint256 _amount,\n bytes memory _data\n ) public view override returns (bytes memory outboundCalldata) {\n outboundCalldata = abi.encodeWithSelector(\n TokenGateway.finalizeInboundTransfer.selector,\n _token,\n _from,\n _to,\n _amount,\n GatewayMessageHandler.encodeFromL2GatewayMsg(exitNum, _data)\n );\n\n return outboundCalldata;\n }\n\n function outboundTransfer(\n address _l1Token,\n address _to,\n uint256 _amount,\n bytes calldata _data\n ) public payable virtual returns (bytes memory) {\n return outboundTransfer(_l1Token, _to, _amount, 0, 0, _data);\n }\n\n /**\n * @notice Initiates a token withdrawal from Arbitrum to Ethereum\n * @param _l1Token l1 address of token\n * @param _to destination address\n * @param _amount amount of tokens withdrawn\n * @return res encoded unique identifier for withdrawal\n */\n function outboundTransfer(\n address _l1Token,\n address _to,\n uint256 _amount,\n uint256, /* _maxGas */\n uint256, /* _gasPriceBid */\n bytes calldata _data\n ) public payable virtual override returns (bytes memory res) {\n // This function is set as public and virtual so that subclasses can override\n // it and add custom validation for callers (ie only whitelisted users)\n\n // the function is marked as payable to conform to the inheritance setup\n // this particular code path shouldn't have a msg.value > 0\n // TODO: remove this invariant for execution markets\n require(msg.value == 0, \"NO_VALUE\");\n\n address _from;\n bytes memory _extraData;\n {\n if (isRouter(msg.sender)) {\n (_from, _extraData) = GatewayMessageHandler.parseFromRouterToGateway(_data);\n } else {\n _from = msg.sender;\n _extraData = _data;\n }\n }\n // the inboundEscrowAndCall functionality has been disabled, so no data is allowed\n require(_extraData.length == 0, \"EXTRA_DATA_DISABLED\");\n\n uint256 id;\n {\n address l2Token = calculateL2TokenAddress(_l1Token);\n require(l2Token.isContract(), \"TOKEN_NOT_DEPLOYED\");\n require(IArbToken(l2Token).l1Address() == _l1Token, \"NOT_EXPECTED_L1_TOKEN\");\n\n _amount = outboundEscrowTransfer(l2Token, _from, _amount);\n id = triggerWithdrawal(_l1Token, _from, _to, _amount, _extraData);\n }\n return abi.encode(id);\n }\n\n function triggerWithdrawal(\n address _l1Token,\n address _from,\n address _to,\n uint256 _amount,\n bytes memory _data\n ) internal returns (uint256) {\n // exit number used for tradeable exits\n uint256 currExitNum = exitNum;\n // unique id used to identify the L2 to L1 tx\n uint256 id = createOutboundTx(\n _from,\n _amount,\n getOutboundCalldata(_l1Token, _from, _to, _amount, _data)\n );\n emit WithdrawalInitiated(_l1Token, _from, _to, id, currExitNum, _amount);\n return id;\n }\n\n function outboundEscrowTransfer(\n address _l2Token,\n address _from,\n uint256 _amount\n ) internal virtual returns (uint256 amountBurnt) {\n // this method is virtual since different subclasses can handle escrow differently\n // user funds are escrowed on the gateway using this function\n // burns L2 tokens in order to release escrowed L1 tokens\n IArbToken(_l2Token).bridgeBurn(_from, _amount);\n // by default we assume that the amount we send to bridgeBurn is the amount burnt\n // this might not be the case for every token\n return _amount;\n }\n\n function inboundEscrowTransfer(\n address _l2Address,\n address _dest,\n uint256 _amount\n ) internal virtual {\n // this method is virtual since different subclasses can handle escrow differently\n IArbToken(_l2Address).bridgeMint(_dest, _amount);\n }\n\n /**\n * @notice Mint on L2 upon L1 deposit.\n * If token not yet deployed and symbol/name/decimal data is included, deploys StandardArbERC20\n * @dev Callable only by the L1ERC20Gateway.outboundTransfer method. For initial deployments of a token the L1 L1ERC20Gateway\n * is expected to include the deployData. If not a L1 withdrawal is automatically triggered for the user\n * @param _token L1 address of ERC20\n * @param _from account that initiated the deposit in the L1\n * @param _to account to be credited with the tokens in the L2 (can be the user's L2 account or a contract)\n * @param _amount token amount to be minted to the user\n * @param _data encoded symbol/name/decimal data for deploy, in addition to any additional callhook data\n */\n function finalizeInboundTransfer(\n address _token,\n address _from,\n address _to,\n uint256 _amount,\n bytes calldata _data\n ) external payable override onlyCounterpartGateway {\n (bytes memory gatewayData, bytes memory callHookData) = GatewayMessageHandler\n .parseFromL1GatewayMsg(_data);\n\n if (callHookData.length != 0) {\n // callHookData should always be 0 since inboundEscrowAndCall is disabled\n callHookData = bytes(\"\");\n }\n\n address expectedAddress = calculateL2TokenAddress(_token);\n\n if (!expectedAddress.isContract()) {\n bool shouldHalt = handleNoContract(\n _token,\n expectedAddress,\n _from,\n _to,\n _amount,\n gatewayData\n );\n if (shouldHalt) return;\n }\n // ignores gatewayData if token already deployed\n\n {\n // validate if L1 address supplied matches that of the expected L2 address\n (bool success, bytes memory _l1AddressData) = expectedAddress.staticcall(\n abi.encodeWithSelector(IArbToken.l1Address.selector)\n );\n\n bool shouldWithdraw;\n if (!success || _l1AddressData.length < 32) {\n shouldWithdraw = true;\n } else {\n // we do this in the else branch since we want to avoid reverts\n // and `toAddress` reverts if _l1AddressData has a short length\n // `_l1AddressData` should be 12 bytes of padding then 20 bytes for the address\n address expectedL1Address = BytesLib.toAddress(_l1AddressData, 12);\n if (expectedL1Address != _token) {\n shouldWithdraw = true;\n }\n }\n\n if (shouldWithdraw) {\n // we don't need the return value from triggerWithdrawal since this is forcing\n // a withdrawal back to the L1 instead of composing with a L2 dapp\n triggerWithdrawal(_token, address(this), _from, _amount, \"\");\n return;\n }\n }\n\n inboundEscrowTransfer(expectedAddress, _to, _amount);\n emit DepositFinalized(_token, _from, _to, _amount);\n\n return;\n }\n\n // returns if function should halt after\n function handleNoContract(\n address _l1Token,\n address expectedL2Address,\n address _from,\n address _to,\n uint256 _amount,\n bytes memory gatewayData\n ) internal virtual returns (bool shouldHalt);\n}\n"
},
"contracts/arbitrum/arb-peripherals/interfaces/IArbToken.sol": {
"content": "// SPDX-License-Identifier: Apache-2.0\n\n/*\n * Copyright 2020, Offchain Labs, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * @title Minimum expected interface for L2 token that interacts with the L2 token bridge (this is the interface necessary\n * for a custom token that interacts with the bridge, see TestArbCustomToken.sol for an example implementation).\n */\npragma solidity ^0.8.9;\n\ninterface IArbToken {\n /**\n * @notice should increase token supply by amount, and should (probably) only be callable by the L1 bridge.\n */\n function bridgeMint(address account, uint256 amount) external;\n\n /**\n * @notice should decrease token supply by amount, and should (probably) only be callable by the L1 bridge.\n */\n function bridgeBurn(address account, uint256 amount) external;\n\n /**\n * @return address of layer 1 token\n */\n function l1Address() external view returns (address);\n}\n"
},
"contracts/arbitrum/arb-peripherals/libraries/BytesLib.sol": {
"content": "// SPDX-License-Identifier: MIT\n\n/*\n * @title Solidity Bytes Arrays Utils\n * @author Gonçalo Sá <[email protected]>\n *\n * @dev Bytes tightly packed arrays utility library for ethereum contracts written in Solidity.\n * The library lets you concatenate, slice and type cast bytes arrays both in memory and storage.\n */\n\npragma solidity ^0.8.9;\n\n/* solhint-disable no-inline-assembly */\nlibrary BytesLib {\n function toAddress(bytes memory _bytes, uint256 _start) internal pure returns (address) {\n require(_bytes.length >= (_start + 20), \"Read out of bounds\");\n address tempAddress;\n\n assembly {\n tempAddress := div(mload(add(add(_bytes, 0x20), _start)), 0x1000000000000000000000000)\n }\n\n return tempAddress;\n }\n\n function toUint8(bytes memory _bytes, uint256 _start) internal pure returns (uint8) {\n require(_bytes.length >= (_start + 1), \"Read out of bounds\");\n uint8 tempUint;\n\n assembly {\n tempUint := mload(add(add(_bytes, 0x1), _start))\n }\n\n return tempUint;\n }\n\n function toUint(bytes memory _bytes, uint256 _start) internal pure returns (uint256) {\n require(_bytes.length >= (_start + 32), \"Read out of bounds\");\n uint256 tempUint;\n\n assembly {\n tempUint := mload(add(add(_bytes, 0x20), _start))\n }\n\n return tempUint;\n }\n\n function toBytes32(bytes memory _bytes, uint256 _start) internal pure returns (bytes32) {\n require(_bytes.length >= (_start + 32), \"Read out of bounds\");\n bytes32 tempBytes32;\n\n assembly {\n tempBytes32 := mload(add(add(_bytes, 0x20), _start))\n }\n\n return tempBytes32;\n }\n}\n/* solhint-enable no-inline-assembly */\n"
},
"contracts/arbitrum/arb-peripherals/libraries/AddressAliasHelper.sol": {
"content": "// SPDX-License-Identifier: Apache-2.0\n\n/*\n * Copyright 2019-2021, Offchain Labs, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npragma solidity ^0.8.9;\n\nlibrary AddressAliasHelper {\n uint160 constant offset = uint160(0x1111000000000000000000000000000000001111);\n\n /// @notice Utility function that converts the address in the L1 that submitted a tx to\n /// the inbox to the msg.sender viewed in the L2\n /// @param l1Address the address in the L1 that triggered the tx to L2\n /// @return l2Address L2 address as viewed in msg.sender\n function applyL1ToL2Alias(address l1Address) internal pure returns (address l2Address) {\n l2Address = address(uint160(l1Address) + offset);\n }\n\n /// @notice Utility function that converts the msg.sender viewed in the L2 to the\n /// address in the L1 that submitted a tx to the inbox\n /// @param l2Address L2 address as viewed in msg.sender\n /// @return l1Address the address in the L1 that triggered the tx to L2\n function undoL1ToL2Alias(address l2Address) internal pure returns (address l1Address) {\n l1Address = address(uint160(l2Address) - offset);\n }\n}\n"
},
"contracts/arbitrum/arb-peripherals/L2ArbitrumMessenger.sol": {
"content": "// SPDX-License-Identifier: Apache-2.0\n\n/*\n * Copyright 2020, Offchain Labs, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npragma solidity ^0.8.9;\n\nimport \"../precompiles/ArbSys.sol\";\n\n/// @notice L2 utility contract to assist with L1 <=> L2 interactions\n/// @dev this is an abstract contract instead of library so the functions can be easily overriden when testing\nabstract contract L2ArbitrumMessenger {\n address internal constant ARB_SYS_ADDRESS = address(100);\n\n event TxToL1(address indexed _from, address indexed _to, uint256 indexed _id, bytes _data);\n\n function sendTxToL1(\n uint256 _l1CallValue,\n address _from,\n address _to,\n bytes memory _data\n ) internal virtual returns (uint256) {\n uint256 _id = ArbSys(ARB_SYS_ADDRESS).sendTxToL1{ value: _l1CallValue }(_to, _data);\n emit TxToL1(_from, _to, _id, _data);\n return _id;\n }\n}\n"
},
"contracts/arbitrum/precompiles/ArbSys.sol": {
"content": "// Copyright 2021-2022, Offchain Labs, Inc.\n// For license information, see https://github.com/nitro/blob/master/LICENSE\n// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity >=0.4.21 <0.9.0;\n\n/**\n * @title System level functionality\n * @notice For use by contracts to interact with core L2-specific functionality.\n * Precompiled contract that exists in every Arbitrum chain at address(100), 0x0000000000000000000000000000000000000064.\n */\ninterface ArbSys {\n /**\n * @notice Get Arbitrum block number (distinct from L1 block number; Arbitrum genesis block has block number 0)\n * @return block number as int\n */\n function arbBlockNumber() external view returns (uint256);\n\n /**\n * @notice Get Arbitrum block hash (reverts unless currentBlockNum-256 <= arbBlockNum < currentBlockNum)\n * @return block hash\n */\n function arbBlockHash(uint256 arbBlockNum) external view returns (bytes32);\n\n /**\n * @notice Gets the rollup's unique chain identifier\n * @return Chain identifier as int\n */\n function arbChainID() external view returns (uint256);\n\n /**\n * @notice Get internal version number identifying an ArbOS build\n * @return version number as int\n */\n function arbOSVersion() external view returns (uint256);\n\n /**\n * @notice Returns 0 since Nitro has no concept of storage gas\n * @return int 0\n */\n function getStorageGasAvailable() external view returns (uint256);\n\n /**\n * @notice check if current call is coming from l1\n * @return true if the caller of this was called directly from L1\n */\n function isTopLevelCall() external view returns (bool);\n\n /**\n * @notice map L1 sender contract address to its L2 alias\n * @param sender sender address\n * @param unused argument no longer used\n * @return aliased sender address\n */\n function mapL1SenderContractAddressToL2Alias(address sender, address unused)\n external\n pure\n returns (address);\n\n /**\n * @notice check if the caller (of this caller of this) is an aliased L1 contract address\n * @return true iff the caller's address is an alias for an L1 contract address\n */\n function wasMyCallersAddressAliased() external view returns (bool);\n\n /**\n * @notice return the address of the caller (of this caller of this), without applying L1 contract address aliasing\n * @return address of the caller's caller, without applying L1 contract address aliasing\n */\n function myCallersAddressWithoutAliasing() external view returns (address);\n\n /**\n * @notice Send given amount of Eth to dest from sender.\n * This is a convenience function, which is equivalent to calling sendTxToL1 with empty data.\n * @param destination recipient address on L1\n * @return unique identifier for this L2-to-L1 transaction.\n */\n function withdrawEth(address destination) external payable returns (uint256);\n\n /**\n * @notice Send a transaction to L1\n * @param destination recipient address on L1\n * @param data (optional) calldata for L1 contract call\n * @return a unique identifier for this L2-to-L1 transaction.\n */\n function sendTxToL1(address destination, bytes calldata data)\n external\n payable\n returns (uint256);\n\n /**\n * @notice Get send Merkle tree state\n * @return size number of sends in the history\n * @return root root hash of the send history\n * @return partials hashes of partial subtrees in the send history tree\n */\n function sendMerkleTreeState()\n external\n view\n returns (\n uint256 size,\n bytes32 root,\n bytes32[] memory partials\n );\n\n /**\n * @notice creates a send txn from L2 to L1\n * @param position = (level << 192) + leaf = (0 << 192) + leaf = leaf\n */\n event L2ToL1Tx(\n address caller,\n address indexed destination,\n uint256 indexed hash,\n uint256 indexed position,\n uint256 arbBlockNum,\n uint256 ethBlockNum,\n uint256 timestamp,\n uint256 callvalue,\n bytes data\n );\n\n /// @dev DEPRECATED in favour of the new L2ToL1Tx event above after the nitro upgrade\n event L2ToL1Transaction(\n address caller,\n address indexed destination,\n uint256 indexed uniqueId,\n uint256 indexed batchNumber,\n uint256 indexInBatch,\n uint256 arbBlockNum,\n uint256 ethBlockNum,\n uint256 timestamp,\n uint256 callvalue,\n bytes data\n );\n\n /**\n * @notice logs a merkle branch for proof sythesis\n * @param reserved an index meant only to align the 4th index with L2ToL1Transaction's 4th event\n * @param hash the merkle hash\n * @param position = (level << 192) + leaf\n */\n event SendMerkleUpdate(\n uint256 indexed reserved,\n bytes32 indexed hash,\n uint256 indexed position\n );\n}\n"
}
},
"settings": {
"optimizer": {
"enabled": true,
"runs": 10
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"libraries": {}
}
}