Skip to content

Instantly share code, notes, and snippets.

@fredlacs
Created August 30, 2021 13:36
Show Gist options
  • Select an option

  • Save fredlacs/7abd3569be1e1dc8cb2a702fdda663d8 to your computer and use it in GitHub Desktop.

Select an option

Save fredlacs/7abd3569be1e1dc8cb2a702fdda663d8 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.6.11+commit.5ef660b1.js&optimize=false&runs=200&gist=
pragma solidity ^0.6.11;
import "./ArbSys.sol";
import "./IInbox.sol";
contract L1Contract {
address constant ARBSYS_ADDR = address(0x0000000000000000000000000000000000000064);
address inbox;
event WithdrawalCreated(uint256 amount, uint256 indexed id);
function withdrawEthFromL2(
uint256 _amountToWithdraw,
uint256 maxSubmissionCost,
uint256 maxGas,
uint256 gasPriceBid,
address refundAddr
) external returns (uint256 id) {
// we want the L1 to L2 tx to trigger the Arbsys precompile
// then create a L2 to L1 transaction transferring `_amountToWithdraw`
bytes memory l1ToL2Calldata = abi.encodeWithSelector(
ArbSys.sendTxToL1.selector,
address(this),
L1Contract.receiveETH.selector
);
id = IInbox(inbox).createRetryableTicketNoRefundAliasRewrite(
ARBSYS_ADDR,
_amountToWithdraw,
maxSubmissionCost,
refundAddr,
refundAddr,
maxGas,
gasPriceBid,
l1ToL2Calldata
);
emit WithdrawalCreated(_amountToWithdraw, id);
return id;
}
function receiveETH() external payable {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment