Skip to content

Commit ea661a7

Browse files
committed
fix: ownable constructor invocation
1 parent 9af82ed commit ea661a7

File tree

6 files changed

+41
-17
lines changed

6 files changed

+41
-17
lines changed

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,3 @@
77
[submodule "lib/zenith"]
88
path = lib/zenith
99
url = https://github.com/init4tech/zenith
10-
[submodule "lib/simple-erc20"]
11-
path = lib/simple-erc20
12-
url = https://github.com/init4tech/simple-erc20

lib/simple-erc20

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/apps/Bridge.sol

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ abstract contract BridgeL2 is SignetL2, BurnMintERC20 {
2222

2323
/// @notice Bridges assets into the rollup for a given recipient.
2424
function _bridgeIn(address recipient, uint256 amount, RollupOrders.Input[] memory inputs) internal virtual {
25+
_mint(recipient, amount);
26+
2527
RollupOrders.Output[] memory outputs = new RollupOrders.Output[](1);
2628
outputs[0] = makeHostOutput(HOST_ASSET, amount, HOST_BANK);
2729

2830
ORDERS.initiate(block.timestamp, inputs, outputs);
29-
30-
_mint(recipient, amount);
3131
}
3232

3333
/// @notice Bridges assets into the rollup for a given recipient.
@@ -40,21 +40,38 @@ abstract contract BridgeL2 is SignetL2, BurnMintERC20 {
4040
///
4141
/// This transaction should be paired with some off-chain logic that fills
4242
/// orders from the L1 bank.
43-
function _bridgeOut(address recipient, uint256 amount, RollupOrders.Input[] memory inputs) internal virtual {
43+
function _bridgeOut(address sender, address recipient, uint256 amount, RollupOrders.Input[] memory inputs)
44+
internal
45+
virtual
46+
{
47+
if (_msgSender() != sender) {
48+
_spendAllowance(sender, _msgSender(), amount);
49+
}
50+
51+
_burn(msg.sender, amount);
52+
4453
RollupOrders.Output[] memory outputs = new RollupOrders.Output[](1);
4554
outputs[0] = makeHostOutput(HOST_ASSET, amount, recipient);
4655

4756
ORDERS.initiate(block.timestamp, inputs, outputs);
48-
49-
_burn(msg.sender, amount);
5057
}
5158

52-
/// @notice Burn asset on L2, and create an order to bridge out asset to
59+
/// @notice Burn asset on L2, and create an order to bridge out assets to
5360
/// L1. If the order is not filled, the asset will not be burned.
5461
///
5562
/// This transaction should be paired with some off-chain logic that fills
5663
/// orders from the L1 bank.
5764
function bridgeOut(address recipient, uint256 amount) public virtual {
58-
_bridgeOut(recipient, amount, new RollupOrders.Input[](0));
65+
_bridgeOut(msg.sender, recipient, amount, new RollupOrders.Input[](0));
66+
}
67+
68+
/// @notice Burn asset on L2 from `sender`, and create an order to bridge
69+
/// out assets to L1. If the order is not filled, the asset will not be
70+
/// burned. Used when the caller is not the sender.
71+
///
72+
/// This transaction should be paired with some off-chain logic that fills
73+
/// orders from the L1 bank.
74+
function bridgeOutFrom(address sender, address recipient, uint256 amount) public virtual {
75+
_bridgeOut(sender, recipient, amount, new RollupOrders.Input[](0));
5976
}
6077
}

src/apps/Lido.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ contract LidoL2 is BridgeL2 {
3535

3636
/// @notice Transfer WETH from `funder`, create an order to convert it to
3737
/// wstETH on L1 and bridge it to L2, and mint stETH to `recipient`.
38-
function enter(address funder, uint256 amountIn, address recipient, uint256 amountOut) external {
39-
WETH.safeTransferFrom(funder, address(this), amountIn);
38+
function enter(uint256 amountIn, address recipient, uint256 amountOut) external {
39+
WETH.safeTransferFrom(msg.sender, address(this), amountIn);
4040

4141
RollupOrders.Input[] memory inputs = new RollupOrders.Input[](1);
4242
inputs[0] = makeWethInput(amountIn);

src/l2/SelfOwned.sol

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,5 @@ import {Ownable} from "openzeppelin-contracts/contracts/access/Ownable.sol";
66
import {SignetL2} from "./Signet.sol";
77

88
abstract contract SelfOwned is SignetL2, Ownable {
9-
constructor() {
10-
Ownable(aliasedSelf());
11-
}
9+
constructor() Ownable(aliasedSelf()) {}
1210
}

test/SelfOwned.sol

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@ pragma solidity ^0.8.13;
44
import {SimpleERC20} from "simple-erc20/SimpleERC20.sol";
55

66
import {PecorinoTest} from "./Base.sol";
7+
78
import {SignetL2} from "../src/l2/Signet.sol";
9+
import {SelfOwned} from "../src/l2/SelfOwned.sol";
810
import {AddressAliasHelper} from "../src/vendor/AddressAliasHelper.sol";
911

12+
contract SelfOwnedNothing is SelfOwned {
13+
constructor() {}
14+
}
15+
1016
contract SelfOwnedToken is SignetL2, SimpleERC20 {
1117
constructor() SimpleERC20(aliasedSelf(), "My Token", "MTK", 18) {
1218
assert(HOST_WETH != address(0));
@@ -16,11 +22,18 @@ contract SelfOwnedToken is SignetL2, SimpleERC20 {
1622
contract TestSelfOwned is PecorinoTest {
1723
SelfOwnedToken token;
1824

25+
SelfOwnedNothing nothing;
26+
1927
constructor() {
2028
token = new SelfOwnedToken();
29+
nothing = new SelfOwnedNothing();
2130
}
2231

23-
function test_ownerIsSelfOnL1() public view {
32+
function test_tokenOwnerIsSelfOnL1() public view {
2433
assertEq(token.owner(), AddressAliasHelper.applyL1ToL2Alias(address(token)));
2534
}
35+
36+
function test_nothingOwnerIsSelfOnL1() public view {
37+
assertEq(nothing.owner(), AddressAliasHelper.applyL1ToL2Alias(address(nothing)));
38+
}
2639
}

0 commit comments

Comments
 (0)