¡El código fuente de este contrato está verificado!
Metadatos del Contrato
Compilador
0.7.6+commit.7338295f
Idioma
Solidity
Código Fuente del Contrato
Archivo 1 de 6: Address.sol
// SPDX-License-Identifier: MITpragmasolidity >=0.6.2 <0.8.0;/**
* @dev Collection of functions related to the address type
*/libraryAddress{
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/functionisContract(address account) internalviewreturns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in// construction, since the code is only stored at the end of the// constructor execution.uint256 size;
// solhint-disable-next-line no-inline-assemblyassembly { size :=extcodesize(account) }
return size >0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/functionsendValue(addresspayable recipient, uint256 amount) internal{
require(address(this).balance>= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/functionfunctionCall(address target, bytesmemory data) internalreturns (bytesmemory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/functionfunctionCall(address target, bytesmemory data, stringmemory errorMessage) internalreturns (bytesmemory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/functionfunctionCallWithValue(address target, bytesmemory data, uint256 value) internalreturns (bytesmemory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/functionfunctionCallWithValue(address target, bytesmemory data, uint256 value, stringmemory errorMessage) internalreturns (bytesmemory) {
require(address(this).balance>= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytesmemory returndata) = target.call{ value: value }(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/functionfunctionStaticCall(address target, bytesmemory data) internalviewreturns (bytesmemory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/functionfunctionStaticCall(address target, bytesmemory data, stringmemory errorMessage) internalviewreturns (bytesmemory) {
require(isContract(target), "Address: static call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytesmemory returndata) = target.staticcall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/functionfunctionDelegateCall(address target, bytesmemory data) internalreturns (bytesmemory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/functionfunctionDelegateCall(address target, bytesmemory data, stringmemory errorMessage) internalreturns (bytesmemory) {
require(isContract(target), "Address: delegate call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytesmemory returndata) = target.delegatecall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function_verifyCallResult(bool success, bytesmemory returndata, stringmemory errorMessage) privatepurereturns(bytesmemory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if presentif (returndata.length>0) {
// The easiest way to bubble the revert reason is using memory via assembly// solhint-disable-next-line no-inline-assemblyassembly {
let returndata_size :=mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
Código Fuente del Contrato
Archivo 2 de 6: L1DAITokenBridge.sol
// SPDX-License-Identifier: AGPL-3.0-or-later// Copyright (C) 2021 Dai Foundation// @unsupported: ovm// This program is free software: you can redistribute it and/or modify// it under the terms of the GNU Affero General Public License as published by// the Free Software Foundation, either version 3 of the License, or// (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU Affero General Public License for more details.//// You should have received a copy of the GNU Affero General Public License// along with this program. If not, see <https://www.gnu.org/licenses/>.pragmasolidity >=0.7.6;import {iOVM_L1ERC20Bridge} from"@eth-optimism/contracts/iOVM/bridge/tokens/iOVM_L1ERC20Bridge.sol";
import {iOVM_L2ERC20Bridge} from"@eth-optimism/contracts/iOVM/bridge/tokens/iOVM_L2ERC20Bridge.sol";
import {OVM_CrossDomainEnabled} from"@eth-optimism/contracts/libraries/bridge/OVM_CrossDomainEnabled.sol";
import { Address } from"@openzeppelin/contracts/utils/Address.sol";
interfaceTokenLike{
functiontransferFrom(address _from, address _to, uint256 _value) externalreturns (bool success);
}
// Managed locked funds in L1Escrow and send / receive messages to L2DAITokenBridge counterpart// Note: when bridge is closed it will still process in progress messagescontractL1DAITokenBridgeisiOVM_L1ERC20Bridge, OVM_CrossDomainEnabled{
// --- Auth ---mapping (address=>uint256) public wards;
functionrely(address usr) externalauth{
wards[usr] =1;
emit Rely(usr);
}
functiondeny(address usr) externalauth{
wards[usr] =0;
emit Deny(usr);
}
modifierauth{
require(wards[msg.sender] ==1, "L1DAITokenBridge/not-authorized");
_;
}
eventRely(addressindexed usr);
eventDeny(addressindexed usr);
addresspublicimmutable l1Token;
addresspublicimmutable l2DAITokenBridge;
addresspublicimmutable l2Token;
addresspublicimmutable escrow;
uint256public isOpen =1;
eventClosed();
constructor(address _l1Token,
address _l2DAITokenBridge,
address _l2Token,
address _l1messenger,
address _escrow
) OVM_CrossDomainEnabled(_l1messenger) {
wards[msg.sender] =1;
emit Rely(msg.sender);
l1Token = _l1Token;
l2DAITokenBridge = _l2DAITokenBridge;
l2Token = _l2Token;
escrow = _escrow;
}
functionclose() externalauth{
isOpen =0;
emit Closed();
}
functiondepositERC20(address _l1Token,
address _l2Token,
uint256 _amount,
uint32 _l2Gas,
bytescalldata _data
) externalvirtualoverride{
// Used to stop deposits from contracts (avoid accidentally lost tokens)// Note: This check could be bypassed by a malicious contract via initcode, but it takes care of the user error we want to avoid.require(!Address.isContract(msg.sender), "L1DAITokenBridge/Sender-not-EOA");
require(_l1Token == l1Token && _l2Token == l2Token, "L1DAITokenBridge/token-not-dai");
_initiateERC20Deposit(msg.sender, msg.sender, _amount, _l2Gas, _data);
}
functiondepositERC20To(address _l1Token,
address _l2Token,
address _to,
uint256 _amount,
uint32 _l2Gas,
bytescalldata _data
) externalvirtualoverride{
require(_l1Token == l1Token && _l2Token == l2Token, "L1DAITokenBridge/token-not-dai");
_initiateERC20Deposit(msg.sender, _to, _amount, _l2Gas, _data);
}
function_initiateERC20Deposit(address _from,
address _to,
uint256 _amount,
uint32 _l2Gas,
bytescalldata _data
) internal{
// do not allow initiating new xchain messages if bridge is closedrequire(isOpen ==1, "L1DAITokenBridge/closed");
TokenLike(l1Token).transferFrom(_from, escrow, _amount);
bytesmemory message =abi.encodeWithSelector(iOVM_L2ERC20Bridge.finalizeDeposit.selector, l1Token, l2Token, _from, _to, _amount, _data);
sendCrossDomainMessage(l2DAITokenBridge, _l2Gas, message);
emit ERC20DepositInitiated(l1Token, l2Token, _from, _to, _amount, _data);
}
functionfinalizeERC20Withdrawal(address _l1Token,
address _l2Token,
address _from,
address _to,
uint256 _amount,
bytescalldata _data
) externaloverrideonlyFromCrossDomainAccount(l2DAITokenBridge) {
require(_l1Token == l1Token && _l2Token == l2Token, "L1DAITokenBridge/token-not-dai");
TokenLike(l1Token).transferFrom(escrow, _to, _amount);
emit ERC20WithdrawalFinalized(l1Token, l2Token, _from, _to, _amount, _data);
}
}
Código Fuente del Contrato
Archivo 3 de 6: OVM_CrossDomainEnabled.sol
// SPDX-License-Identifier: MITpragmasolidity >0.5.0 <0.8.0;/* Interface Imports */import { iOVM_CrossDomainMessenger } from"../../iOVM/bridge/messaging/iOVM_CrossDomainMessenger.sol";
/**
* @title OVM_CrossDomainEnabled
* @dev Helper contract for contracts performing cross-domain communications
*
* Compiler used: defined by inheriting contract
* Runtime target: defined by inheriting contract
*/contractOVM_CrossDomainEnabled{
/*************
* Variables *
*************/// Messenger contract used to send and recieve messages from the other domain.addresspublic messenger;
/***************
* Constructor *
***************//**
* @param _messenger Address of the CrossDomainMessenger on the current layer.
*/constructor(address _messenger
) {
messenger = _messenger;
}
/**********************
* Function Modifiers *
**********************//**
* Enforces that the modified function is only callable by a specific cross-domain account.
* @param _sourceDomainAccount The only account on the originating domain which is
* authenticated to call this function.
*/modifieronlyFromCrossDomainAccount(address _sourceDomainAccount
) {
require(
msg.sender==address(getCrossDomainMessenger()),
"OVM_XCHAIN: messenger contract unauthenticated"
);
require(
getCrossDomainMessenger().xDomainMessageSender() == _sourceDomainAccount,
"OVM_XCHAIN: wrong sender of cross-domain message"
);
_;
}
/**********************
* Internal Functions *
**********************//**
* Gets the messenger, usually from storage. This function is exposed in case a child contract
* needs to override.
* @return The address of the cross-domain messenger contract which should be used.
*/functiongetCrossDomainMessenger()
internalvirtualreturns (
iOVM_CrossDomainMessenger
)
{
return iOVM_CrossDomainMessenger(messenger);
}
/**
* Sends a message to an account on another domain
* @param _crossDomainTarget The intended recipient on the destination domain
* @param _message The data to send to the target (usually calldata to a function with
* `onlyFromCrossDomainAccount()`)
* @param _gasLimit The gasLimit for the receipt of the message on the target domain.
*/functionsendCrossDomainMessage(address _crossDomainTarget,
uint32 _gasLimit,
bytesmemory _message
)
internal{
getCrossDomainMessenger().sendMessage(_crossDomainTarget, _message, _gasLimit);
}
}
Código Fuente del Contrato
Archivo 4 de 6: iOVM_CrossDomainMessenger.sol
// SPDX-License-Identifier: MITpragmasolidity >0.5.0 <0.8.0;pragmaexperimentalABIEncoderV2;/**
* @title iOVM_CrossDomainMessenger
*/interfaceiOVM_CrossDomainMessenger{
/**********
* Events *
**********/eventSentMessage(bytes message);
eventRelayedMessage(bytes32 msgHash);
eventFailedRelayedMessage(bytes32 msgHash);
/*************
* Variables *
*************/functionxDomainMessageSender() externalviewreturns (address);
/********************
* Public Functions *
********************//**
* Sends a cross domain message to the target messenger.
* @param _target Target contract address.
* @param _message Message to send to the target.
* @param _gasLimit Gas limit for the provided message.
*/functionsendMessage(address _target,
bytescalldata _message,
uint32 _gasLimit
) external;
}
Código Fuente del Contrato
Archivo 5 de 6: iOVM_L1ERC20Bridge.sol
// SPDX-License-Identifier: MITpragmasolidity >0.5.0;pragmaexperimentalABIEncoderV2;/**
* @title iOVM_L1ERC20Bridge
*/interfaceiOVM_L1ERC20Bridge{
/**********
* Events *
**********/eventERC20DepositInitiated (addressindexed _l1Token,
addressindexed _l2Token,
addressindexed _from,
address _to,
uint256 _amount,
bytes _data
);
eventERC20WithdrawalFinalized (addressindexed _l1Token,
addressindexed _l2Token,
addressindexed _from,
address _to,
uint256 _amount,
bytes _data
);
/********************
* Public Functions *
********************//**
* @dev deposit an amount of the ERC20 to the caller's balance on L2.
* @param _l1Token Address of the L1 ERC20 we are depositing
* @param _l2Token Address of the L1 respective L2 ERC20
* @param _amount Amount of the ERC20 to deposit
* @param _l2Gas Gas limit required to complete the deposit on L2.
* @param _data Optional data to forward to L2. This data is provided
* solely as a convenience for external contracts. Aside from enforcing a maximum
* length, these contracts provide no guarantees about its content.
*/functiondepositERC20 (address _l1Token,
address _l2Token,
uint _amount,
uint32 _l2Gas,
bytescalldata _data
)
external;
/**
* @dev deposit an amount of ERC20 to a recipient's balance on L2.
* @param _l1Token Address of the L1 ERC20 we are depositing
* @param _l2Token Address of the L1 respective L2 ERC20
* @param _to L2 address to credit the withdrawal to.
* @param _amount Amount of the ERC20 to deposit.
* @param _l2Gas Gas limit required to complete the deposit on L2.
* @param _data Optional data to forward to L2. This data is provided
* solely as a convenience for external contracts. Aside from enforcing a maximum
* length, these contracts provide no guarantees about its content.
*/functiondepositERC20To (address _l1Token,
address _l2Token,
address _to,
uint _amount,
uint32 _l2Gas,
bytescalldata _data
)
external;
/*************************
* Cross-chain Functions *
*************************//**
* @dev Complete a withdrawal from L2 to L1, and credit funds to the recipient's balance of the
* L1 ERC20 token.
* This call will fail if the initialized withdrawal from L2 has not been finalized.
*
* @param _l1Token Address of L1 token to finalizeWithdrawal for.
* @param _l2Token Address of L2 token where withdrawal was initiated.
* @param _from L2 address initiating the transfer.
* @param _to L1 address to credit the withdrawal to.
* @param _amount Amount of the ERC20 to deposit.
* @param _data Data provided by the sender on L2. This data is provided
* solely as a convenience for external contracts. Aside from enforcing a maximum
* length, these contracts provide no guarantees about its content.
*/functionfinalizeERC20Withdrawal (address _l1Token,
address _l2Token,
address _from,
address _to,
uint _amount,
bytescalldata _data
)
external;
}
Código Fuente del Contrato
Archivo 6 de 6: iOVM_L2ERC20Bridge.sol
// SPDX-License-Identifier: MITpragmasolidity >0.5.0;pragmaexperimentalABIEncoderV2;/**
* @title iOVM_L2ERC20Bridge
*/interfaceiOVM_L2ERC20Bridge{
/**********
* Events *
**********/eventWithdrawalInitiated (addressindexed _l1Token,
addressindexed _l2Token,
addressindexed _from,
address _to,
uint256 _amount,
bytes _data
);
eventDepositFinalized (addressindexed _l1Token,
addressindexed _l2Token,
addressindexed _from,
address _to,
uint256 _amount,
bytes _data
);
eventDepositFailed (addressindexed _l1Token,
addressindexed _l2Token,
addressindexed _from,
address _to,
uint256 _amount,
bytes _data
);
/********************
* Public Functions *
********************//**
* @dev initiate a withdraw of some tokens to the caller's account on L1
* @param _l2Token Address of L2 token where withdrawal was initiated.
* @param _amount Amount of the token to withdraw.
* param _l1Gas Unused, but included for potential forward compatibility considerations.
* @param _data Optional data to forward to L1. This data is provided
* solely as a convenience for external contracts. Aside from enforcing a maximum
* length, these contracts provide no guarantees about its content.
*/functionwithdraw (address _l2Token,
uint _amount,
uint32 _l1Gas,
bytescalldata _data
)
external;
/**
* @dev initiate a withdraw of some token to a recipient's account on L1.
* @param _l2Token Address of L2 token where withdrawal is initiated.
* @param _to L1 adress to credit the withdrawal to.
* @param _amount Amount of the token to withdraw.
* param _l1Gas Unused, but included for potential forward compatibility considerations.
* @param _data Optional data to forward to L1. This data is provided
* solely as a convenience for external contracts. Aside from enforcing a maximum
* length, these contracts provide no guarantees about its content.
*/functionwithdrawTo (address _l2Token,
address _to,
uint _amount,
uint32 _l1Gas,
bytescalldata _data
)
external;
/*************************
* Cross-chain Functions *
*************************//**
* @dev Complete a deposit from L1 to L2, and credits funds to the recipient's balance of this
* L2 token.
* This call will fail if it did not originate from a corresponding deposit in OVM_l1TokenGateway.
* @param _l1Token Address for the l1 token this is called with
* @param _l2Token Address for the l2 token this is called with
* @param _from Account to pull the deposit from on L2.
* @param _to Address to receive the withdrawal at
* @param _amount Amount of the token to withdraw
* @param _data Data provider by the sender on L1. This data is provided
* solely as a convenience for external contracts. Aside from enforcing a maximum
* length, these contracts provide no guarantees about its content.
*/functionfinalizeDeposit (address _l1Token,
address _l2Token,
address _from,
address _to,
uint _amount,
bytescalldata _data
)
external;
}