Address Contract Verified
Address
0x17dacAD8AA962963830136422E2EAa8d27D014f8
Balance
0 ETH
Nonce
1
Code Size
4646 bytes
Creator
0x65b5cFaa...6cf5 at tx 0x9b0520b1...2ba13c
Indexed Transactions
0
Contract Bytecode
4646 bytes
0x6080604052600436106100a75760003560e01c80638456cb59116100645780638456cb59146101755780638da5cb5b1461018a578063a504d2af146101b0578063a6365e8b146101d0578063f2fde38b146101f0578063f4b9fa751461021057600080fd5b80632f48ab7d146100ac5780633e413bee146100e25780633f4ba83a146101025780635c975abb14610119578063715018a6146101405780637c37088d14610155575b600080fd5b3480156100b857600080fd5b506003546100cc906001600160a01b031681565b6040516100d99190610ed2565b60405180910390f35b3480156100ee57600080fd5b506004546100cc906001600160a01b031681565b34801561010e57600080fd5b50610117610230565b005b34801561012557600080fd5b50600054600160a01b900460ff166040516100d99190610ee8565b34801561014c57600080fd5b50610117610421565b610168610163366004610f51565b610433565b6040516100d99190610ff6565b34801561018157600080fd5b506101176108d9565b34801561019657600080fd5b506000546001600160a01b03166040516100d9919061100d565b3480156101bc57600080fd5b506005546100cc906001600160a01b031681565b3480156101dc57600080fd5b506006546100cc906001600160a01b031681565b3480156101fc57600080fd5b5061011761020b36600461101b565b610ac4565b34801561021c57600080fd5b506002546100cc906001600160a01b031681565b610238610b0b565b60025460055460405163095ea7b360e01b81526001600160a01b039283169263095ea7b3926102709291169060001990600401611044565b6020604051808303816000875af115801561028f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102b39190611072565b5060035460055460405163095ea7b360e01b81526001600160a01b039283169263095ea7b3926102ec9291169060001990600401611044565b600060405180830381600087803b15801561030657600080fd5b505af115801561031a573d6000803e3d6000fd5b50506004805460055460405163095ea7b360e01b81526001600160a01b03928316955063095ea7b394506103579391909216916000199101611044565b6020604051808303816000875af1158015610376573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061039a9190611072565b5060055460065460405163095ea7b360e01b81526001600160a01b039283169263095ea7b3926103d39291169060001990600401611044565b6020604051808303816000875af11580156103f2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104169190611072565b5061041f610b38565b565b610429610b0b565b61041f6000610b87565b600061043d610bd7565b610445610c02565b60006001600160a01b038916158061046457506001600160a01b038316155b156104825760405163538ba4f960e01b815260040160405180910390fd5b87158061048d575084155b80610496575083155b156104b457604051630f6fa54560e41b815260040160405180910390fd5b866001600160801b03166000036105e7576002546040516370a0823160e01b815289916001600160a01b0316906370a08231906104f590339060040161100d565b602060405180830381865afa158015610512573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610536919061109e565b101561055557604051632858f9ab60e11b815260040160405180910390fd5b60025461056d906001600160a01b031633308b610c2c565b60055460405163b6b55f2560e01b81526001600160a01b039091169063b6b55f259061059d908b90600401610ff6565b6020604051808303816000875af11580156105bc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105e0919061109e565b90506107f3565b866001600160801b0316600114806106085750866001600160801b03166002145b156107da578560000361062e57604051630f6fa54560e41b815260040160405180910390fd5b866001600160801b03166001036106ed57600480546040516370a0823160e01b81528a926001600160a01b03909216916370a08231916106709133910161100d565b602060405180830381865afa15801561068d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106b1919061109e565b10156106d057604051632858f9ab60e11b815260040160405180910390fd5b6004546106e8906001600160a01b031633308b610c2c565b6107a6565b866001600160801b03166002036107a6576003546040516370a0823160e01b815289916001600160a01b0316906370a082319061072e90339060040161100d565b602060405180830381865afa15801561074b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061076f919061109e565b101561078e57604051632858f9ab60e11b815260040160405180910390fd5b6003546107a6906001600160a01b031633308b610c2c565b6005546040516366956b0560e11b81526001600160a01b039091169063cd2ad60a9061059d908a908c908b906004016110ce565b60405163b49aa3b560e01b815260040160405180910390fd5b600654600554604051634558de4f60e11b81526001600160a01b0392831692638ab1bc9e923492610832928f92169087908c908c908c906004016110f6565b60206040518083038185885af1158015610850573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190610875919061109e565b9150886001600160a01b0316336001600160a01b03167f246c050bc7f8460805c071235f1a32b8ffd2350ce7818fee4d0094bdb27b3adf83856040516108bc929190611145565b60405180910390a3506108ce60018055565b979650505050505050565b6108e1610b0b565b60025460055460405163095ea7b360e01b81526001600160a01b039283169263095ea7b39261091892911690600090600401611168565b6020604051808303816000875af1158015610937573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061095b9190611072565b5060035460055460405163095ea7b360e01b81526001600160a01b039283169263095ea7b39261099392911690600090600401611168565b600060405180830381600087803b1580156109ad57600080fd5b505af11580156109c1573d6000803e3d6000fd5b50506004805460055460405163095ea7b360e01b81526001600160a01b03928316955063095ea7b394506109fd93919092169160009101611168565b6020604051808303816000875af1158015610a1c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a409190611072565b5060055460065460405163095ea7b360e01b81526001600160a01b039283169263095ea7b392610a7892911690600090600401611168565b6020604051808303816000875af1158015610a97573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610abb9190611072565b5061041f610c8c565b610acc610b0b565b6001600160a01b038116610aff576000604051631e4fbdf760e01b8152600401610af6919061100d565b60405180910390fd5b610b0881610b87565b50565b6000546001600160a01b0316331461041f573360405163118cdaa760e01b8152600401610af6919061100d565b610b40610ccf565b6000805460ff60a01b191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b604051610b7d919061100d565b60405180910390a1565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b600054600160a01b900460ff161561041f5760405163d93c066560e01b815260040160405180910390fd5b600260015403610c2557604051633ee5aeb560e01b815260040160405180910390fd5b6002600155565b610c8684856001600160a01b03166323b872dd868686604051602401610c5493929190611183565b604051602081830303815290604052915060e01b6020820180516001600160e01b038381831617835250505050610cf9565b50505050565b610c94610bd7565b6000805460ff60a01b1916600160a01b1790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258610b703390565b600054600160a01b900460ff1661041f57604051638dfc202b60e01b815260040160405180910390fd5b6000610d0e6001600160a01b03841683610d58565b90508051600014158015610d33575080806020019051810190610d319190611072565b155b15610d535782604051635274afe760e01b8152600401610af6919061100d565b505050565b6060610d6683836000610d6f565b90505b92915050565b606081471015610d94573060405163cd78605960e01b8152600401610af6919061100d565b600080856001600160a01b03168486604051610db091906111e4565b60006040518083038185875af1925050503d8060008114610ded576040519150601f19603f3d011682016040523d82523d6000602084013e610df2565b606091505b5091509150610e02868383610e0e565b925050505b9392505050565b606082610e2357610e1e82610e61565b610e07565b8151158015610e3a57506001600160a01b0384163b155b15610e5a5783604051639996b31560e01b8152600401610af6919061100d565b5080610e07565b805115610e715780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b6000610d696001600160a01b038316610ea1565b90565b6001600160a01b031690565b6000610d6982610e8a565b6000610d6982610ead565b610ecc81610eb8565b82525050565b60208101610d698284610ec3565b801515610ecc565b60208101610d698284610ee0565b60006001600160a01b038216610d69565b610f1081610ef6565b8114610b0857600080fd5b8035610d6981610f07565b80610f10565b8035610d6981610f26565b6001600160801b038116610f10565b8035610d6981610f37565b600080600080600080600060e0888a031215610f6f57610f6f600080fd5b6000610f7b8a8a610f1b565b9750506020610f8c8a828b01610f2c565b9650506040610f9d8a828b01610f46565b9550506060610fae8a828b01610f2c565b9450506080610fbf8a828b01610f2c565b93505060a0610fd08a828b01610f2c565b92505060c0610fe18a828b01610f1b565b91505092959891949750929550565b80610ecc565b60208101610d698284610ff0565b610ecc81610ef6565b60208101610d698284611004565b60006020828403121561103057611030600080fd5b600061103c8484610f1b565b949350505050565b604081016110528285611004565b610e076020830184610ff0565b801515610f10565b8051610d698161105f565b60006020828403121561108757611087600080fd5b600061103c8484611067565b8051610d6981610f26565b6000602082840312156110b3576110b3600080fd5b600061103c8484611093565b6001600160801b038116610ecc565b606081016110dc82866110bf565b6110e96020830185610ff0565b61103c6040830184610ff0565b60c081016111048289611004565b6111116020830188611004565b61111e6040830187610ff0565b61112b6060830186610ff0565b6111386080830185610ff0565b6108ce60a0830184611004565b604081016110528285610ff0565b6000610d69610e9e8381565b610ecc81611153565b604081016111768285611004565b610e07602083018461115f565b606081016111918286611004565b6110e96020830185611004565b60005b838110156111b95781810151838201526020016111a1565b50506000910152565b60006111cc825190565b6111da81856020860161119e565b9290920192915050565b6000610e0782846111c256fea26469706673582212202236f04225b719be0ae338c706abb3057dfdf869496c03d3822ee54ac7bdd82564736f6c63430008180033
Verified Source Code Full Match
Compiler: v0.8.24+commit.e11b9ed9
EVM: paris
YBUSDBridge.sol 165 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IYBUSD} from "./interface/IYBUSD.sol";
import {IBridgeMiddleware} from "./interface/IBridgeMiddleware.sol";
interface ITetherToken {
function approve(address _spender, uint256 _value) external;
}
contract YBUSDBridge is Ownable, Pausable, ReentrancyGuard {
using SafeERC20 for IERC20;
error ZERO_ADDRESS();
error ZERO_AMOUNT();
error INVALID_TOKEN_ID();
error INSUFFICIENT_BALANCE();
// @dev Emitted when MintAndBridge L1 tx success. This doesn't mean that the conterpart L2 tx will success
// `canonicalTxHash` is the L2 tx hash, which can be used to check if the L2 tx is processed successfully.
event MintAndBridge(
address indexed sender,
address indexed l2Recevier,
uint256 amount,
bytes32 canonicalTxHash
);
IERC20 public dai;
IERC20 public usdt;
IERC20 public usdc;
IYBUSD public ybUSD;
IBridgeMiddleware public bridgeMiddleware;
/// @param _ybUSD ybUSD address
/// @param _bridgeMiddleware bridgeMiddleware address
constructor(
address _dai,
address _usdc,
address _usdt,
address _ybUSD,
address _bridgeMiddleware
) Ownable(msg.sender) {
if (
_dai == address(0) ||
_usdc == address(0) ||
_usdt == address(0) ||
_ybUSD == address(0) ||
_bridgeMiddleware == address(0)
) {
revert ZERO_ADDRESS();
}
dai = IERC20(_dai);
usdc = IERC20(_usdc);
usdt = IERC20(_usdt);
ybUSD = IYBUSD(_ybUSD);
bridgeMiddleware = IBridgeMiddleware(_bridgeMiddleware);
dai.approve(address(ybUSD), type(uint256).max);
ITetherToken(_usdt).approve(address(ybUSD), type(uint256).max);
usdc.approve(address(ybUSD), type(uint256).max);
// Approve the bridgeMiddleware to transfer ybUSD from this contract
ybUSD.approve(address(bridgeMiddleware), type(uint256).max);
}
/// @dev Pause the contract
function pause() external onlyOwner {
dai.approve(address(ybUSD), 0);
ITetherToken(address(usdt)).approve(address(ybUSD), 0);
usdc.approve(address(ybUSD), 0);
ybUSD.approve(address(bridgeMiddleware), 0);
return _pause();
}
/// @dev Unpause the contract
function unpause() external onlyOwner {
dai.approve(address(ybUSD), type(uint256).max);
ITetherToken(address(usdt)).approve(address(ybUSD), type(uint256).max);
usdc.approve(address(ybUSD), type(uint256).max);
ybUSD.approve(address(bridgeMiddleware), type(uint256).max);
return _unpause();
}
/// Deposit DAI/USDC/USDT to mint ybUSD and bridge them to L2 within the same transaction
///
/// @param _l2Receiver The receiver that will receive the minted tokens on L2
/// @param _amount The amount of DAI/(USDC/USDT swapped to DAI) to deposit into the ybUSD contract
/// @param _stableCoinType 0 = DAI, 1 = USDC, 2 = USDT
/// @param _minAmountAccepted minimum Amount user like to accept when swapping USDC/USDT to DAI
/// @param _l2GasLimit The estimated gas limit of the L2 tx
/// @param _refundRecipient who can retreive if the L1 to L2 transfer failed
/// @return canonicalTxHash The canonical L2 tx hash, which can be used to track the L2 tx status.
function mintAndBridge(
address _l2Receiver,
uint256 _amount,
uint128 _stableCoinType,
uint256 _minAmountAccepted,
uint256 _l2GasLimit,
uint256 _l2GasPerPubdataByteLimit,
address _refundRecipient
)
external
payable
whenNotPaused
nonReentrant
returns (bytes32 canonicalTxHash)
{
uint256 ybUSDAmount;
if (_l2Receiver == address(0) || _refundRecipient == address(0)) {
revert ZERO_ADDRESS();
}
if (
_amount == 0 || _l2GasLimit == 0 || _l2GasPerPubdataByteLimit == 0
) {
revert ZERO_AMOUNT();
}
if (_stableCoinType == 0) {
if (dai.balanceOf(msg.sender) < _amount)
revert INSUFFICIENT_BALANCE();
dai.safeTransferFrom(msg.sender, address(this), _amount);
ybUSDAmount = ybUSD.deposit(_amount);
} else if (_stableCoinType == 1 || _stableCoinType == 2) {
if (_minAmountAccepted == 0) {
revert ZERO_AMOUNT();
}
if (_stableCoinType == 1) {
if (usdc.balanceOf(msg.sender) < _amount)
revert INSUFFICIENT_BALANCE();
usdc.safeTransferFrom(msg.sender, address(this), _amount);
} else if (_stableCoinType == 2) {
if (usdt.balanceOf(msg.sender) < _amount)
revert INSUFFICIENT_BALANCE();
usdt.safeTransferFrom(msg.sender, address(this), _amount);
}
ybUSDAmount = ybUSD.swapAndDeposit(
_stableCoinType,
_amount,
_minAmountAccepted
);
} else {
revert INVALID_TOKEN_ID();
}
// Bridge the minted ybUSD to L2
canonicalTxHash = bridgeMiddleware.bridge{value: msg.value}(
_l2Receiver,
address(ybUSD),
ybUSDAmount,
_l2GasLimit,
_l2GasPerPubdataByteLimit,
_refundRecipient
);
emit MintAndBridge(
msg.sender,
_l2Receiver,
ybUSDAmount,
canonicalTxHash
);
}
}
IYBUSD.sol 10 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
interface IYBUSD is IERC20Metadata {
function deposit(uint256 _amount) external returns (uint256);
function swapAndDeposit(uint128 j, uint256 dx, uint256 min_dy) external returns (uint256);
}
IBridgeMiddleware.sol 14 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;
interface IBridgeMiddleware {
function bridgehub() external view returns (address);
function bridge(
address _l2Receiver,
address _token,
uint256 _amount,
uint256 _l2GasLimit,
uint256 _l2GasPerPubdataByteLimit,
address _refundRecipient
) external payable returns (bytes32 canonicalTxHash);
}
Address.sol 159 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error AddressInsufficientBalance(address account);
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedInnerCall();
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert AddressInsufficientBalance(address(this));
}
(bool success, ) = recipient.call{value: amount}("");
if (!success) {
revert FailedInnerCall();
}
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason or custom error, it is bubbled
* up by this function (like regular Solidity function calls). However, if
* the call reverted with no returned reason, this function reverts with a
* {FailedInnerCall} error.
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert AddressInsufficientBalance(address(this));
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
* was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
* unsuccessful call.
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
// only check if target is a contract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
/**
* @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
* revert reason or with a default {FailedInnerCall} error.
*/
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
/**
* @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
*/
function _revert(bytes memory returndata) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert FailedInnerCall();
}
}
}
Context.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
Ownable.sol 100 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
Pausable.sol 119 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Pausable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which allows children to implement an emergency stop
* mechanism that can be triggered by an authorized account.
*
* This module is used through inheritance. It will make available the
* modifiers `whenNotPaused` and `whenPaused`, which can be applied to
* the functions of your contract. Note that they will not be pausable by
* simply including this module, only once the modifiers are put in place.
*/
abstract contract Pausable is Context {
bool private _paused;
/**
* @dev Emitted when the pause is triggered by `account`.
*/
event Paused(address account);
/**
* @dev Emitted when the pause is lifted by `account`.
*/
event Unpaused(address account);
/**
* @dev The operation failed because the contract is paused.
*/
error EnforcedPause();
/**
* @dev The operation failed because the contract is not paused.
*/
error ExpectedPause();
/**
* @dev Initializes the contract in unpaused state.
*/
constructor() {
_paused = false;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
_requireNotPaused();
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
_requirePaused();
_;
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
return _paused;
}
/**
* @dev Throws if the contract is paused.
*/
function _requireNotPaused() internal view virtual {
if (paused()) {
revert EnforcedPause();
}
}
/**
* @dev Throws if the contract is not paused.
*/
function _requirePaused() internal view virtual {
if (!paused()) {
revert ExpectedPause();
}
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
*/
function _pause() internal virtual whenNotPaused {
_paused = true;
emit Paused(_msgSender());
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/
function _unpause() internal virtual whenPaused {
_paused = false;
emit Unpaused(_msgSender());
}
}
IERC20.sol 79 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
ReentrancyGuard.sol 84 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/ReentrancyGuard.sol)
pragma solidity ^0.8.20;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant NOT_ENTERED = 1;
uint256 private constant ENTERED = 2;
uint256 private _status;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
constructor() {
_status = NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be NOT_ENTERED
if (_status == ENTERED) {
revert ReentrancyGuardReentrantCall();
}
// Any calls to nonReentrant after this point will fail
_status = ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == ENTERED;
}
}
SafeERC20.sol 118 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
/**
* @dev An operation with an ERC20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data);
if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;
}
}
IERC20Permit.sol 90 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*
* ==== Security Considerations
*
* There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
* expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
* considered as an intention to spend the allowance in any specific way. The second is that because permits have
* built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
* take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
* generally recommended is:
*
* ```solidity
* function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
* try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
* doThing(..., value);
* }
*
* function doThing(..., uint256 value) public {
* token.safeTransferFrom(msg.sender, address(this), value);
* ...
* }
* ```
*
* Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
* `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
* {SafeERC20-safeTransferFrom}).
*
* Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
* contracts should have entry points that don't rely on permit.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*
* CAUTION: See Security Considerations above.
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
IERC20Metadata.sol 26 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
Read Contract
bridgeMiddleware 0xa6365e8b → address
dai 0xf4b9fa75 → address
owner 0x8da5cb5b → address
paused 0x5c975abb → bool
usdc 0x3e413bee → address
usdt 0x2f48ab7d → address
ybUSD 0xa504d2af → address
Write Contract 5 functions
These functions modify contract state and require a wallet transaction to execute.
mintAndBridge 0x7c37088d
address _l2Receiver
uint256 _amount
uint128 _stableCoinType
uint256 _minAmountAccepted
uint256 _l2GasLimit
uint256 _l2GasPerPubdataByteLimit
address _refundRecipient
returns: bytes32
pause 0x8456cb59
No parameters
renounceOwnership 0x715018a6
No parameters
transferOwnership 0xf2fde38b
address newOwner
unpause 0x3f4ba83a
No parameters
Recent Transactions
No transactions found for this address