Verified contractPartialBSL
L1BlastBridge
Address0xc245b4994cd229ad6ab7b464205d71bfe85a96b7
- Balance
0 ETH
- Transactions
0
- Compiler
solc 0.8.15
- Same code
Only this contract
Details
- Compiler
- solc 0.8.15+commit.e14f2714
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- london
- License
- BSL
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,330,229
- Creation transaction
- 0x65df6bb8e0…84bba319d8
75 files
The source code is large: one file is shown at a time. Choose a file in the list.
- src/mainnet-bridge/L1BlastBridge.solmain16.49 KB
- lib/openzeppelin-contracts-upgradeable/contracts/access/Ownable2StepUpgradeable.sol2.52 KB
- lib/openzeppelin-contracts-upgradeable/contracts/access/OwnableUpgradeable.sol3.15 KB
- lib/openzeppelin-contracts-upgradeable/contracts/interfaces/IERC5267Upgradeable.sol749 B
- lib/openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol6.64 KB
- lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/ERC20Upgradeable.sol13.47 KB
- lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/IERC20Upgradeable.sol2.75 KB
- lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/extensions/IERC20MetadataUpgradeable.sol716 B
- lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/extensions/IERC20PermitUpgradeable.sol2.27 KB
- lib/openzeppelin-contracts-upgradeable/contracts/utils/AddressUpgradeable.sol9.38 KB
- lib/openzeppelin-contracts-upgradeable/contracts/utils/ContextUpgradeable.sol1.35 KB
- lib/openzeppelin-contracts-upgradeable/contracts/utils/CountersUpgradeable.sol1.41 KB
- lib/openzeppelin-contracts-upgradeable/contracts/utils/StringsUpgradeable.sol2.85 KB
- lib/openzeppelin-contracts-upgradeable/contracts/utils/cryptography/ECDSAUpgradeable.sol9.16 KB
- lib/openzeppelin-contracts-upgradeable/contracts/utils/cryptography/EIP712Upgradeable.sol8.04 KB
- lib/openzeppelin-contracts-upgradeable/contracts/utils/math/MathUpgradeable.sol12.8 KB
- lib/openzeppelin-contracts-upgradeable/contracts/utils/math/SignedMathUpgradeable.sol1.27 KB
- lib/openzeppelin-contracts/contracts/interfaces/IERC20.sol151 B
- lib/openzeppelin-contracts/contracts/proxy/utils/Initializable.sol5.65 KB
- lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol12.62 KB
- lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol2.77 KB
- lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol683 B
- lib/openzeppelin-contracts/contracts/token/ERC20/extensions/draft-IERC20Permit.sol2.25 KB
- lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol4.46 KB
- lib/openzeppelin-contracts/contracts/utils/Address.sol8.31 KB
- lib/openzeppelin-contracts/contracts/utils/Context.sol844 B
- lib/openzeppelin-contracts/contracts/utils/Strings.sol2.4 KB
- lib/openzeppelin-contracts/contracts/utils/introspection/ERC165Checker.sol4.86 KB
- lib/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol853 B
- lib/openzeppelin-contracts/contracts/utils/math/Math.sol8.83 KB
- lib/openzeppelin-contracts/contracts/utils/math/SafeCast.sol35.53 KB
- lib/openzeppelin-contracts/contracts/utils/math/SignedMath.sol1.26 KB
- lib/openzeppelin-contracts/contracts/utils/structs/EnumerableSet.sol12.68 KB
- lib/solmate/src/tokens/ERC20.sol6.8 KB
- lib/solmate/src/utils/FixedPointMathLib.sol15.91 KB
- lib/solmate/src/utils/SafeTransferLib.sol5.44 KB
- src/L1/L2OutputOracle.sol13.78 KB
- src/L1/OptimismPortal.sol24.49 KB
- src/L1/ResourceMetering.sol8.64 KB
- src/L1/SystemConfig.sol17.59 KB
- src/L2/Blast.sol16.43 KB
- src/L2/ERC20PermitUpgradeable.sol4.42 KB
- src/L2/ERC20Rebasing.sol15.71 KB
- src/L2/Gas.sol14.89 KB
- src/L2/Shares.sol4.29 KB
- src/L2/USDB.sol4.39 KB
- src/libraries/Arithmetic.sol1.31 KB
- src/libraries/Burn.sol1.01 KB
- src/libraries/Bytes.sol6.76 KB
- src/libraries/Constants.sol2.91 KB
- src/libraries/Encoding.sol6.86 KB
- src/libraries/Hashing.sol5.37 KB
- src/libraries/Predeploys.sol4.87 KB
- src/libraries/SafeCall.sol6.78 KB
- src/libraries/Storage.sol2.79 KB
- src/libraries/Types.sol3.3 KB
- src/libraries/rlp/RLPReader.sol10.41 KB
- src/libraries/rlp/RLPWriter.sol5.72 KB
- src/libraries/trie/MerkleTrie.sol11.26 KB
- src/libraries/trie/SecureMerkleTrie.sol2.24 KB
- src/mainnet-bridge/DelegateCalls.sol1.88 KB
- src/mainnet-bridge/ETHYieldManager.sol1.79 KB
- src/mainnet-bridge/L2BlastBridge.sol3.78 KB
- src/mainnet-bridge/USDConversions.sol9.62 KB
- src/mainnet-bridge/USDYieldManager.sol2.41 KB
- src/mainnet-bridge/YieldManager.sol20.21 KB
- src/mainnet-bridge/withdrawal-queue/WithdrawalQueue.sol18.23 KB
- src/mainnet-bridge/yield-providers/YieldProvider.sol7.7 KB
- src/universal/CrossDomainMessenger.sol20.16 KB
- src/universal/IOptimismMintableERC20.sol1.18 KB
- src/universal/ISemver.sol560 B
- src/universal/OptimismMintableERC20.sol5.33 KB
- src/universal/Semver.sol1.31 KB
- src/universal/StandardBridge.sol22.47 KB
- src/vendor/AddressAliasHelper.sol1.73 KB
src/mainnet-bridge/L1BlastBridge.sol
// SPDX-License-Identifier: BSL 1.1 - Copyright 2024 MetaLayer Labs Ltd.
pragma solidity 0.8.15;
import { Address } from "@openzeppelin/contracts/utils/Address.sol";
import { IERC20 } from "@openzeppelin/contracts/interfaces/IERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { Predeploys } from "src/libraries/Predeploys.sol";
import { SafeCall } from "src/libraries/SafeCall.sol";
import { StandardBridge } from "src/universal/StandardBridge.sol";
import { L2BlastBridge } from "src/mainnet-bridge/L2BlastBridge.sol";
import { ISemver } from "src/universal/ISemver.sol";
import { CrossDomainMessenger } from "src/universal/CrossDomainMessenger.sol";
import { OptimismPortal } from "src/L1/OptimismPortal.sol";
import { Predeploys } from "src/libraries/Predeploys.sol";
import { USDYieldManager } from "src/mainnet-bridge/USDYieldManager.sol";
import { ETHYieldManager } from "src/mainnet-bridge/ETHYieldManager.sol";
import { USDB } from "src/L2/USDB.sol";
import { USDConversions } from "src/mainnet-bridge/USDConversions.sol";
/// @custom:proxied
/// @title L1BlastBridge
/// @notice The L1BlastBridge is responsible for transferring ETH and yield-bearing ERC20 tokens between L1 and L2.
///
/// The current implementation converts all deposited USD tokens to DAI before bridging them to L2 to mint USDB.
/// Hence, the amount of USDB that is minted on L2 will be equal to the amount of DAI that is received on L1.
/// This is done to simplify the yield management, as DSR is the only yield provider that is currently supported.
/// When non-DAI USD tokens are deposited, the user is expected to provide the minimum amount of DAI that should
/// be received (i.e. the minimum amount of USDB that should be minted on L2). This amount must be specified
/// in the extraData field of the deposit transaction (uint256 minAmountInWad).
contract L1BlastBridge is StandardBridge, ISemver {
using SafeERC20 for IERC20;
struct YieldToken {
bool approved;
uint8 decimals;
address provider;
bool reportStakedBalance;
}
/// @notice Numerator for dynamic overhead added to the base gas for a message.
uint64 public constant MIN_GAS_DYNAMIC_OVERHEAD_NUMERATOR = 64;
/// @notice Denominator for dynamic overhead added to the base gas for a message.
uint64 public constant MIN_GAS_DYNAMIC_OVERHEAD_DENOMINATOR = 63;
/// @notice Mapping of potential deposit tokens to whether they're
/// approved as USD yield tokens and additional metadata.
mapping(address => YieldToken) public usdYieldTokens;
/// @notice Mapping of potential deposit tokens to whether they're
/// approved as ETH yield tokens and additional metadata.
mapping(address => YieldToken) public ethYieldTokens;
/// @notice Address of the USD Yield Manager.
USDYieldManager public usdYieldManager;
/// @notice Address of the ETH Yield Manager.
ETHYieldManager public ethYieldManager;
/// @notice Address of the OptimismPortal.
OptimismPortal public portal;
/// @notice Last L1 block number at which deposits are accepted. Any deposit initiated in a
/// block after this one reverts. Withdrawal finalization is unaffected.
uint256 public constant DEPOSIT_CUTOFF_BLOCK = 26298276;
/// @notice Semantic version.
/// @custom:semver 1.0.0
string public constant version = "1.0.0";
/// @custom:semver 1.0.0
/// @notice Constructs the L1BlastBridge contract.
constructor() StandardBridge(StandardBridge(payable(Predeploys.L2_BLAST_BRIDGE))) {
initialize({
_portal: OptimismPortal(payable(address(0))),
_messenger: CrossDomainMessenger(address(0)),
_usdYieldManager: USDYieldManager(payable(address(0))),
_ethYieldManager: ETHYieldManager(payable(address(0)))
});
}
/// @notice Initializer
/// @param _portal Address of the OptimismPortal.
/// @param _messenger Address of the L1CrossDomainMessenger.
/// @param _usdYieldManager Address of the USDYieldManager.
/// @param _ethYieldManager Address of the ETHYieldManager.
function initialize(
OptimismPortal _portal,
CrossDomainMessenger _messenger,
USDYieldManager _usdYieldManager,
ETHYieldManager _ethYieldManager
) public initializer {
portal = _portal;
__StandardBridge_init(_messenger);
usdYieldManager = _usdYieldManager;
ethYieldManager = _ethYieldManager;
}
/// @notice Add/remove an approved USD yield token.
/// @param token Address of token.
/// @param approved Whether the token is an approved yield token.
/// @param decimals Number of token decimals.
/// @param provider Address of the yield provider for the token.
/// @param reportStakedBalance Whether a deposit needs to be reported to the yield provider.
function setUSDYieldToken(
address token,
bool approved,
uint8 decimals,
address provider,
bool reportStakedBalance
) external {
require(msg.sender == usdYieldManager.owner(), "L1BlastBridge: only USDYieldManager owner can call");
usdYieldTokens[token] = YieldToken({
approved: approved,
decimals: decimals,
provider: provider,
reportStakedBalance: reportStakedBalance
});
}
/// @notice Add/remove an approved ETH yield token.
/// @param token Address of token.
/// @param approved Whether the token is an approved yield token.
/// @param decimals Number of token decimals.
/// @param provider Address of the yield provider for the token.
/// @param reportStakedBalance Whether a deposit needs to be reported to the yield provider.
function setETHYieldToken(
address token,
bool approved,
uint8 decimals,
address provider,
bool reportStakedBalance
) external {
require(msg.sender == ethYieldManager.owner(), "L1BlastBridge: only ETHYieldManager owner can call");
require(token != address(0));
ethYieldTokens[token] = YieldToken({
approved: approved,
decimals: decimals,
provider: provider,
reportStakedBalance: reportStakedBalance
});
}
/// @notice Reverts if deposits are no longer accepted.
modifier depositsOpen() {
require(block.number <= DEPOSIT_CUTOFF_BLOCK, "L1BlastBridge: deposits are disabled");
_;
}
/// @notice Withdrawal finalization is permanently disabled. A reverted finalization is
/// recorded as a failed message by the L1CrossDomainMessenger and can be replayed
/// against a future implementation, so no withdrawal is lost.
modifier withdrawalsDisabled() {
revert("L1BlastBridge: withdrawals are disabled");
_;
}
/// @notice Allows EOAs to bridge ETH by sending directly to the bridge.
receive() external payable override onlyEOA {
_initiateBridgeETH(msg.sender, msg.sender, msg.value, RECEIVE_DEFAULT_GAS_LIMIT, hex"");
}
/// @notice Initiates a bridge of ETH. All ETH deposit entry points (receive, bridgeETH,
/// bridgeETHTo) route through this function, which reverts after DEPOSIT_CUTOFF_BLOCK.
function _initiateBridgeETH(
address _from,
address _to,
uint256 _amount,
uint32 _minGasLimit,
bytes memory _extraData
)
internal
override
depositsOpen
{
super._initiateBridgeETH(_from, _to, _amount, _minGasLimit, _extraData);
}
/// Blast: This function is modified from StandardBridge to enable
/// discounted withdrawals on L1. The `msg.value` check is
/// less strict and `msg.value` is used instead of `_amount`
/// in the following steps.
/// @inheritdoc StandardBridge
function finalizeBridgeETH(
address _from,
address _to,
uint256 _amount,
bytes calldata _extraData
)
public
payable
override
onlyOtherBridge
withdrawalsDisabled
{
// Blast: Accept discounted `msg.value`
require(msg.value <= _amount, "L1BlastBridge: amount sent exceeds amount required");
require(_to != address(this), "L1BlastBridge: cannot send to self");
require(_to != address(messenger), "L1BlastBridge: cannot send to messenger");
// Emit the correct events. By default this will be _amount, but child
// contracts may override this function in order to emit legacy events as well.
// Blast: replace `_amount` with `msg.value`
_emitETHBridgeFinalized(_from, _to, msg.value, _extraData);
// Blast: replace `_amount` with `msg.value`
bool success = SafeCall.call(_to, gasleft(), msg.value, hex"");
require(success, "L2BlastBridge: ETH transfer failed");
}
/// @notice Finalizes an ERC20 bridge on this chain. Can only be triggered by the other
/// BlastBridge contract on the remote chain.
/// @param _localToken Address of the ERC20 on this chain.
/// @param _remoteToken Address of the corresponding token on the remote chain.
/// @param _from Address of the sender.
/// @param _to Address of the receiver.
/// @param _amount Amount of the ERC20 being bridged.
/// @param _extraData Extra data to be sent with the transaction. Note that the recipient will
/// not be triggered with this data, but it will be emitted and can be used
/// to identify the transaction.
function finalizeBridgeERC20(
address _localToken,
address _remoteToken,
address _from,
address _to,
uint256 _amount,
bytes calldata _extraData
)
public
override
onlyOtherBridge
withdrawalsDisabled
{
require(_to != address(this), "StandardBridge: cannot send to self");
require(_to != address(messenger), "StandardBridge: cannot send to messenger");
require(_localToken == usdYieldManager.TOKEN(), "L1BlastBridge: unsupported local token");
require(_remoteToken == Predeploys.USDB, "L1BlastBridge: only USDB can be withdrawn through this bridge");
// Emit the correct events. By default this will be ERC20BridgeFinalized, but child
// contracts may override this function in order to emit legacy events as well.
_emitERC20BridgeFinalized(_localToken, _remoteToken, _from, _to, _amount, _extraData);
usdYieldManager.requestWithdrawal(_to, _amount);
}
/// @notice Sends approved yield-bearing ERC20 tokens to a receiver's address on the other chain.
/// Only USDB or ETH are accepted as _remoteToken. ETH-based tokens are sent to the
/// Optimism Portal.
/// @param _localToken Address of the ERC20 on this chain.
/// @param _remoteToken Address of the corresponding token on the remote chain.
/// @param _to Address of the receiver.
/// @param _amount Amount of local tokens to deposit.
/// @param _minGasLimit Minimum amount of gas that the bridge can be relayed with.
/// @param _extraData Extra data to be sent with the transaction. Note that the recipient will
/// not be triggered with this data, but it will be emitted and can be used
/// to identify the transaction. For bridging yield-bearing USD tokens (except DAI),
/// the extra data should contain the minimum amount of tokens in WAD to be minted.
/// When the deposited USD tokens are converted to DAI, it ensures that the amount
/// of DAI received (and hence the amount of USDB minted) is at least the minimum
/// amount specified. All ERC20 deposit entry points (bridgeERC20, bridgeERC20To)
/// route through this function, which reverts after DEPOSIT_CUTOFF_BLOCK.
function _initiateBridgeERC20(
address _localToken,
address _remoteToken,
address _from,
address _to,
uint256 _amount,
uint32 _minGasLimit,
bytes memory _extraData
)
internal
override
depositsOpen
{
YieldToken memory usdYieldToken = usdYieldTokens[_localToken];
YieldToken memory ethYieldToken = ethYieldTokens[_localToken];
if (usdYieldToken.approved) {
require(_remoteToken == Predeploys.USDB, "L1BlastBridge: this token can only be bridged to USDB");
IERC20(_localToken).safeTransferFrom(_from, address(usdYieldManager), _amount);
uint256 amountWad = USDConversions._convertDecimals(_amount, usdYieldToken.decimals, USDConversions.WAD_DECIMALS);
uint256 amountToMintWad = usdYieldManager.convert(_localToken, amountWad, _extraData);
// Update the yield provider with the staked deposit.
if (usdYieldToken.reportStakedBalance) {
require(usdYieldToken.provider != address(0));
usdYieldManager.recordStakedDeposit(usdYieldToken.provider, amountToMintWad);
}
// Emit the correct events. By default this will be ERC20BridgeInitiated, but child
// contracts may override this function in order to emit legacy events as well.
_emitERC20BridgeInitiated(_localToken, _remoteToken, _from, _to, amountToMintWad, _extraData);
messenger.sendMessage(
Predeploys.L2_BLAST_BRIDGE,
abi.encodeWithSelector(
StandardBridge.finalizeBridgeERC20.selector,
Predeploys.USDB,
usdYieldManager.TOKEN(),
_from,
_to,
amountToMintWad,
_extraData
),
_minGasLimit
);
} else if (ethYieldToken.approved) {
require(_remoteToken == address(0), "L1BlastBridge: this token can only be bridged to ETH");
IERC20(_localToken).safeTransferFrom(_from, address(ethYieldManager), _amount);
// Update the yield provider with the staked deposit.
if (ethYieldToken.reportStakedBalance) {
require(ethYieldToken.provider != address(0));
ethYieldManager.recordStakedDeposit(ethYieldToken.provider, _amount);
}
uint256 amountWad = USDConversions._convertDecimals(_amount, ethYieldToken.decimals, USDConversions.WAD_DECIMALS);
// Emit the correct events. By default this will be ERC20BridgeInitiated, but child
// contracts may override this function in order to emit legacy events as well.
_emitERC20BridgeInitiated(_localToken, _remoteToken, _from, _to, amountWad, _extraData);
// Message has to be sent to the OptimismPortal directly because we have to
// request the L2 message has value without sending ETH.
portal.depositTransaction(
Predeploys.L2_BLAST_BRIDGE,
amountWad,
baseGas(_minGasLimit),
false,
abi.encodeWithSelector(
L2BlastBridge.finalizeBridgeETHDirect.selector,
_from,
_to,
amountWad,
_extraData
)
);
} else {
revert("L1BlastBridge: bridge token is not supported");
}
}
/// @notice Computes the amount of gas required to guarantee that a given deposit will be
/// received on the other chain without running out of gas.
/// @param _minGasLimit Minimum desired gas limit when deposit goes to target.
/// @return Amount of gas required to guarantee deposit receipt.
function baseGas(uint32 _minGasLimit) public pure returns (uint64) {
return
// Constant overhead
RECEIVE_DEFAULT_GAS_LIMIT
// Dynamic overhead (EIP-150)
+ ((_minGasLimit * MIN_GAS_DYNAMIC_OVERHEAD_NUMERATOR) / MIN_GAS_DYNAMIC_OVERHEAD_DENOMINATOR);
}
}
Compiler settingsShow
{
"viaIR": false,
"metadata": {
"bytecodeHash": "none",
"useLiteralContent": false
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "london",
"remappings": [
"@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"@rari-capital/solmate/=lib/solmate/",
"@cwia/=lib/clones-with-immutable-args/src/",
"forge-std/=lib/forge-std/src/",
"ds-test/=lib/forge-std/lib/ds-test/src/",
"safe-contracts/=lib/safe-contracts/contracts/",
"clones-with-immutable-args/=lib/clones-with-immutable-args/src/",
"erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
"openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"openzeppelin/=lib/openzeppelin-contracts-upgradeable/contracts/",
"solmate/=lib/solmate/src/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.