Skip to content

Commit 6b83737

Browse files
authored
feat: transact flow (#45)
* WIP: feat: transact flow * fix: update 1559 fields * option: handling enter + transact * feat: add option to specify ether recipient * handle zero value, docs
1 parent c6d998f commit 6b83737

File tree

2 files changed

+67
-7
lines changed

2 files changed

+67
-7
lines changed

.gas-snapshot

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
ZenithTest:test_badSequence() (gas: 60199)
2-
ZenithTest:test_badSignature() (gas: 66867)
3-
ZenithTest:test_blockExpired() (gas: 55430)
4-
ZenithTest:test_notSequencer() (gas: 58572)
5-
ZenithTest:test_onePerBlock() (gas: 104311)
6-
ZenithTest:test_submitBlock() (gas: 88457)
1+
ZenithTest:test_badSequence() (gas: 60268)
2+
ZenithTest:test_badSignature() (gas: 66936)
3+
ZenithTest:test_blockExpired() (gas: 55499)
4+
ZenithTest:test_notSequencer() (gas: 58618)
5+
ZenithTest:test_onePerBlock() (gas: 104426)
6+
ZenithTest:test_submitBlock() (gas: 88526)

src/Passage.sol

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ contract Passage {
2020
/// @param amount - The amount of Ether entering the rollup.
2121
event Enter(uint256 indexed rollupChainId, address indexed rollupRecipient, uint256 amount);
2222

23+
/// @notice Emitted to send a special transaction to the rollup.
24+
event Transact(
25+
uint256 indexed rollupChainId,
26+
address indexed sender,
27+
address indexed to,
28+
bytes data,
29+
uint256 value,
30+
uint256 gas,
31+
uint256 maxFeePerGas
32+
);
33+
2334
/// @notice Emitted when the admin withdraws tokens from the contract.
2435
event Withdrawal(address indexed token, address indexed recipient, uint256 amount);
2536

@@ -45,15 +56,64 @@ contract Passage {
4556
/// @param rollupRecipient - The recipient of the Ether on the rollup.
4657
/// @custom:emits Enter indicating the amount of Ether to mint on the rollup & its recipient.
4758
function enter(uint256 rollupChainId, address rollupRecipient) public payable {
59+
if (msg.value == 0) return;
4860
emit Enter(rollupChainId, rollupRecipient, msg.value);
4961
}
5062

5163
/// @notice Allows native Ether to enter the default rollup.
52-
/// @dev see `enter` above for docs.
64+
/// @dev see `enter` for docs.
5365
function enter(address rollupRecipient) external payable {
5466
enter(defaultRollupChainId, rollupRecipient);
5567
}
5668

69+
/// @notice Allows a special transaction to be sent to the rollup with sender == L1 msg.sender.
70+
/// @dev Transaction is processed after normal rollup block execution.
71+
/// @dev See `enterTransact` for docs.
72+
function transact(
73+
uint256 rollupChainId,
74+
address to,
75+
bytes calldata data,
76+
uint256 value,
77+
uint256 gas,
78+
uint256 maxFeePerGas
79+
) public payable {
80+
enterTransact(rollupChainId, msg.sender, to, data, value, gas, maxFeePerGas);
81+
}
82+
83+
/// @dev See `transact` for docs.
84+
function transact(address to, bytes calldata data, uint256 value, uint256 gas, uint256 maxFeePerGas)
85+
external
86+
payable
87+
{
88+
enterTransact(defaultRollupChainId, msg.sender, to, data, value, gas, maxFeePerGas);
89+
}
90+
91+
/// @notice Send Ether on the rollup, send a special transaction to be sent to the rollup with sender == L1 msg.sender.
92+
/// @dev Enter and Transact are processed after normal rollup block execution.
93+
/// @dev See `enter` for Enter docs.
94+
/// @param rollupChainId - The rollup chain to send the transaction to.
95+
/// @param etherRecipient - The recipient of the ether.
96+
/// @param to - The address to call on the rollup.
97+
/// @param data - The data to send to the rollup.
98+
/// @param value - The amount of Ether to send on the rollup.
99+
/// @param gas - The gas limit for the transaction.
100+
/// @param maxFeePerGas - The maximum fee per gas for the transaction (per EIP-1559).
101+
/// @custom:emits Transact indicating the transaction to mine on the rollup.
102+
function enterTransact(
103+
uint256 rollupChainId,
104+
address etherRecipient,
105+
address to,
106+
bytes calldata data,
107+
uint256 value,
108+
uint256 gas,
109+
uint256 maxFeePerGas
110+
) public payable {
111+
// if msg.value is attached, Enter
112+
enter(rollupChainId, etherRecipient);
113+
// emit Transact event
114+
emit Transact(rollupChainId, msg.sender, to, data, value, gas, maxFeePerGas);
115+
}
116+
57117
/// @notice Allows the admin to withdraw ETH or ERC20 tokens from the contract.
58118
/// @dev Only the admin can call this function.
59119
function withdraw(address token, address recipient, uint256 amount) external {

0 commit comments

Comments
 (0)