Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blast lockbox adapter #50

Merged
merged 2 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions contracts/integration/LockboxAdapterBlast.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IXERC20} from "../shared/IXERC20/IXERC20.sol";
import {IXERC20Lockbox} from "../shared/IXERC20/IXERC20Lockbox.sol";

interface IXERC20Registry {
function getXERC20(address erc20) external view returns (address xerc20);

function getERC20(address xerc20) external view returns (address erc20);

function getLockbox(address erc20) external view returns (address xerc20);
}

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

/// @notice This adapter is only used for sending assets from Ethereum mainnet to Blast.
/// @dev Combines Lockbox deposit and Blast bridge's BridgeERC20 call.
contract LockboxAdapterBlast {
address immutable blastStandardBridge;
address immutable registry;

// ERRORS
error AmountLessThanZero();

constructor(address _blastStandardBridge, address _registry) {
blastStandardBridge = _blastStandardBridge;
registry = _registry;
}

/// @dev Combines Lockbox deposit and Blast bridge's BridgeERC20To call.
/// @param _to The recipient or contract address on destination.
/// @param _erc20 The address of the adopted ERC20 on the origin chain.
/// @param _remoteToken The address of the asset to be received on the destination chain.
/// @param _amount The amount of asset to bridge.
/// @param _minGasLimit Minimum amount of gas that the bridge can be relayed with.
/// @param _extraData Extra data to be sent with the transaction.
function bridgeTo(
address _to,
address _erc20,
address _remoteToken,
uint256 _amount,
uint32 _minGasLimit,
bytes calldata _extraData
) external {
if (_amount <= 0) {
revert AmountLessThanZero();
}

address xerc20 = IXERC20Registry(registry).getXERC20(_erc20);
address lockbox = IXERC20Registry(registry).getLockbox(xerc20);

SafeERC20.safeTransferFrom(IERC20(_erc20), msg.sender, address(this), _amount);
IERC20(_erc20).approve(lockbox, _amount);
IXERC20Lockbox(lockbox).deposit(_amount);
IERC20(xerc20).approve(blastStandardBridge, _amount);
L1StandardBridge(blastStandardBridge).bridgeERC20To(xerc20, _remoteToken, _to, _amount, _minGasLimit, _extraData);
}
}
18 changes: 18 additions & 0 deletions script/DeployLockboxAdapterBlast.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import "forge-std/Script.sol";
import {LockboxAdapterBlast} from "../contracts/integration/LockboxAdapterBlast.sol";

contract DeployLockboxAdapterBlast is Script {
function run() public {
vm.startBroadcast();

new LockboxAdapterBlast(
address(0x697402166Fbf2F22E970df8a6486Ef171dbfc524), // blastStandardBridge
address(0xBf29A2D67eFb6766E44c163B19C6F4118b164702) // registry
);

vm.stopBroadcast();
}
}
Loading