Skip to content

Commit

Permalink
fix: adapter blast
Browse files Browse the repository at this point in the history
  • Loading branch information
prathmeshkhandelwal1 committed Mar 27, 2024
1 parent 6292d8d commit 5ba730f
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions contracts/integration/LockboxAdapterBlast.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// 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();
error ValueLessThanAmount(uint256 value, uint256 amount);
error InvalidRemoteToken(address _remoteToken)

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);
if(xerc20 != _remoteToken) {
revert InvalidRemoteToken(_remoteToken);
}
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);
}
}

0 comments on commit 5ba730f

Please sign in to comment.