Skip to content
Open
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
20 changes: 16 additions & 4 deletions src/bridge/ERC20Inbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,15 @@ contract ERC20Inbox is AbsInbox, IERC20Inbox {
dest = AddressAliasHelper.applyL1ToL2Alias(msg.sender);
}

uint256 amountToMintOnL2 = _fromNativeTo18Decimals(amount);
return _deliverMessage(
L1MessageType_ethDeposit, msg.sender, abi.encodePacked(dest, amountToMintOnL2), amount
);
return _depositERC20(dest, amount);
}

/// @inheritdoc IERC20Inbox
function depositERC20(
address to,
uint256 amount
) public whenNotPaused onlyAllowed returns (uint256) {
return _depositERC20(to, amount);
}

/// @inheritdoc IERC20Inbox
Expand Down Expand Up @@ -119,6 +124,13 @@ contract ERC20Inbox is AbsInbox, IERC20Inbox {
return 0;
}

function _depositERC20(address dest, uint256 amount) internal returns (uint256) {
uint256 amountToMintOnL2 = _fromNativeTo18Decimals(amount);
return _deliverMessage(
L1MessageType_ethDeposit, msg.sender, abi.encodePacked(dest, amountToMintOnL2), amount
);
}

function _deliverToBridge(
uint8 kind,
address sender,
Expand Down
7 changes: 7 additions & 0 deletions src/bridge/IERC20Inbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ interface IERC20Inbox is IInboxBase {
uint256 amount
) external returns (uint256);

/**
* @notice Deposit native token from L1 to L2 to the specified destination address. The destination is never aliased.
* @dev This does not trigger the fallback function when receiving in the L2 side.
* Look into retryable tickets if you are interested in this functionality.
*/
function depositERC20(address to, uint256 amount) external returns (uint256);

/**
* @notice Put a message in the L2 inbox that can be reexecuted for some fixed amount of time if it reverts
* @dev all tokenTotalFeeAmount will be deposited to callValueRefundAddress on L2
Expand Down
9 changes: 9 additions & 0 deletions src/bridge/IInbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ interface IInbox is IInboxBase {
*/
function depositEth() external payable returns (uint256);

/**
* @notice Deposit eth from L1 to L2 to the specified destination address. The destination is never aliased.
* @dev This does not trigger the fallback function when receiving in the L2 side.
* Look into retryable tickets if you are interested in this functionality.
*/
function depositEth(
address destination
) external payable returns (uint256);

/**
* @notice Put a message in the L2 inbox that can be reexecuted for some fixed amount of time if it reverts
* @dev all msg.value will deposited to callValueRefundAddress on L2
Expand Down
19 changes: 16 additions & 3 deletions src/bridge/Inbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,14 @@ contract Inbox is AbsInbox, IInbox {
dest = AddressAliasHelper.applyL1ToL2Alias(msg.sender);
}

return _deliverMessage(
L1MessageType_ethDeposit, msg.sender, abi.encodePacked(dest, msg.value), msg.value
);
return _depositEth(dest);
}

/// @inheritdoc IInbox
function depositEth(
address to
) external payable whenNotPaused onlyAllowed returns (uint256) {
return _depositEth(to);
}

/// @notice deprecated in favour of depositEth with no parameters
Expand Down Expand Up @@ -314,6 +319,14 @@ contract Inbox is AbsInbox, IInbox {
return (1400 + 6 * dataLength) * (baseFee == 0 ? block.basefee : baseFee);
}

function _depositEth(
address dest
) internal returns (uint256) {
return _deliverMessage(
L1MessageType_ethDeposit, msg.sender, abi.encodePacked(dest, msg.value), msg.value
);
}

function _deliverToBridge(
uint8 kind,
address sender,
Expand Down
6 changes: 6 additions & 0 deletions src/mocks/InboxStub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ contract InboxStub is IInboxBase, IInbox {
revert("NOT_IMPLEMENTED");
}

function depositEth(
address
) external payable override returns (uint256) {
revert("NOT_IMPLEMENTED");
}

function postUpgradeInit(
IBridge _bridge
) external {}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/orbitChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ describe('Orbit Chain', () => {
depositTx = await ERC20Inbox__factory.connect(
l2Network.ethBridge.inbox,
userL1Wallet
).depositERC20(amountToDeposit)
)['depositERC20(uint256)'](amountToDeposit)
} else {
depositTx = await Inbox__factory.connect(
l2Network.ethBridge.inbox,
Expand Down
Loading
Loading