Skip to content

Commit

Permalink
chore: bridge creator refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
shotaronowhere committed Apr 12, 2024
1 parent e494578 commit 8efab16
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 33 deletions.
28 changes: 17 additions & 11 deletions src/rollup/BridgeCreator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";

contract BridgeCreator is Ownable {
BridgeContracts public ethBasedTemplates;
BridgeContracts public erc20BasedTemplates;
BridgeTemplates public ethBasedTemplates;
BridgeTemplates public erc20BasedTemplates;

event TemplatesUpdated();
event ERC20TemplatesUpdated();
event DelayBufferableTemplatesUpdated();
event ERC20DelayBufferableTemplatesUpdated();

struct BridgeContracts {
struct BridgeTemplates {
IBridge bridge;
ISequencerInbox sequencerInbox;
ISequencerInbox delayBufferableSequencerInbox;
Expand All @@ -36,27 +34,35 @@ contract BridgeCreator is Ownable {
IOutbox outbox;
}

struct BridgeContracts {
IBridge bridge;
IInboxBase inbox;
ISequencerInbox sequencerInbox;
IRollupEventInbox rollupEventInbox;
IOutbox outbox;
}

constructor(
BridgeContracts memory _ethBasedTemplates,
BridgeContracts memory _erc20BasedTemplates
BridgeTemplates memory _ethBasedTemplates,
BridgeTemplates memory _erc20BasedTemplates
) Ownable() {
ethBasedTemplates = _ethBasedTemplates;
erc20BasedTemplates = _erc20BasedTemplates;
}

function updateTemplates(BridgeContracts calldata _newTemplates) external onlyOwner {
function updateTemplates(BridgeTemplates calldata _newTemplates) external onlyOwner {
ethBasedTemplates = _newTemplates;
emit TemplatesUpdated();
}

function updateERC20Templates(BridgeContracts calldata _newTemplates) external onlyOwner {
function updateERC20Templates(BridgeTemplates calldata _newTemplates) external onlyOwner {
erc20BasedTemplates = _newTemplates;
emit ERC20TemplatesUpdated();
}

function _createBridge(
address adminProxy,
BridgeContracts memory templates,
BridgeTemplates memory templates,
bool isDelayBufferable
) internal returns (BridgeContracts memory) {
BridgeContracts memory frame;
Expand Down Expand Up @@ -97,7 +103,7 @@ contract BridgeCreator is Ownable {
ISequencerInbox.MaxTimeVariation calldata maxTimeVariation,
BufferConfig calldata bufferConfig
) external returns (BridgeContracts memory) {
// create delay bufferable sequencer inbox if threshold is set
// create delay bufferable sequencer inbox if threshold is non-zero
bool isDelayBufferable = bufferConfig.threshold != 0;

// create ETH-based bridge if address zero is provided for native token, otherwise create ERC20-based bridge
Expand Down
25 changes: 13 additions & 12 deletions test/foundry/BridgeCreator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ contract BridgeCreatorTest is Test {
uint256 public constant MAX_DATA_SIZE = 117_964;
IReader4844 dummyReader4844 = IReader4844(address(137));

BridgeCreator.BridgeContracts ethBasedTemplates =
BridgeCreator.BridgeContracts({
BridgeCreator.BridgeTemplates ethBasedTemplates =
BridgeCreator.BridgeTemplates({
bridge: new Bridge(),
sequencerInbox: new SequencerInbox(MAX_DATA_SIZE, dummyReader4844, false, false),
delayBufferableSequencerInbox: new SequencerInbox(MAX_DATA_SIZE, dummyReader4844, false, true),
inbox: new Inbox(MAX_DATA_SIZE),
rollupEventInbox: new RollupEventInbox(),
outbox: new Outbox()
});
BridgeCreator.BridgeContracts erc20BasedTemplates =
BridgeCreator.BridgeContracts({
BridgeCreator.BridgeTemplates erc20BasedTemplates =
BridgeCreator.BridgeTemplates({
bridge: new ERC20Bridge(),
sequencerInbox: new SequencerInbox(MAX_DATA_SIZE, dummyReader4844, true, false),
delayBufferableSequencerInbox: new SequencerInbox(MAX_DATA_SIZE, dummyReader4844, true, true),
Expand All @@ -39,8 +39,8 @@ contract BridgeCreatorTest is Test {
creator = new BridgeCreator(ethBasedTemplates, erc20BasedTemplates);
}

function getEthBasedTemplates() internal view returns (BridgeCreator.BridgeContracts memory) {
BridgeCreator.BridgeContracts memory templates;
function getEthBasedTemplates() internal view returns (BridgeCreator.BridgeTemplates memory) {
BridgeCreator.BridgeTemplates memory templates;
(
templates.bridge,
templates.sequencerInbox,
Expand All @@ -52,8 +52,8 @@ contract BridgeCreatorTest is Test {
return templates;
}

function getErc20BasedTemplates() internal view returns (BridgeCreator.BridgeContracts memory) {
BridgeCreator.BridgeContracts memory templates;
function getErc20BasedTemplates() internal view returns (BridgeCreator.BridgeTemplates memory) {
BridgeCreator.BridgeTemplates memory templates;
(
templates.bridge,
templates.sequencerInbox,
Expand All @@ -66,11 +66,12 @@ contract BridgeCreatorTest is Test {
}

function assertEq(
BridgeCreator.BridgeContracts memory a,
BridgeCreator.BridgeContracts memory b
BridgeCreator.BridgeTemplates memory a,
BridgeCreator.BridgeTemplates memory b
) internal {
assertEq(address(a.bridge), address(b.bridge), "Invalid bridge");
assertEq(address(a.sequencerInbox), address(b.sequencerInbox), "Invalid seqInbox");
assertEq(address(a.delayBufferableSequencerInbox), address(b.delayBufferableSequencerInbox), "Invalid delayBuffSeqInbox");
assertEq(address(a.inbox), address(b.inbox), "Invalid inbox");
assertEq(
address(a.rollupEventInbox),
Expand All @@ -87,7 +88,7 @@ contract BridgeCreatorTest is Test {
}

function test_updateTemplates() public {
BridgeCreator.BridgeContracts memory templs = BridgeCreator.BridgeContracts({
BridgeCreator.BridgeTemplates memory templs = BridgeCreator.BridgeTemplates({
bridge: Bridge(address(200)),
sequencerInbox: SequencerInbox(address(201)),
delayBufferableSequencerInbox: SequencerInbox(address(202)),
Expand All @@ -103,7 +104,7 @@ contract BridgeCreatorTest is Test {
}

function test_updateERC20Templates() public {
BridgeCreator.BridgeContracts memory templs = BridgeCreator.BridgeContracts({
BridgeCreator.BridgeTemplates memory templs = BridgeCreator.BridgeTemplates({
bridge: ERC20Bridge(address(400)),
sequencerInbox: SequencerInbox(address(401)),
delayBufferableSequencerInbox: SequencerInbox(address(402)),
Expand Down
8 changes: 4 additions & 4 deletions test/foundry/RollupCreator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ contract RollupCreatorTest is Test {
uint256 public constant MAX_FEE_PER_GAS = 1_000_000_000;
uint256 public constant MAX_DATA_SIZE = 117_964;

BridgeCreator.BridgeContracts public ethBasedTemplates =
BridgeCreator.BridgeContracts({
BridgeCreator.BridgeTemplates public ethBasedTemplates =
BridgeCreator.BridgeTemplates({
bridge: new Bridge(),
sequencerInbox: new SequencerInbox(MAX_DATA_SIZE, dummyReader4844, false, false),
delayBufferableSequencerInbox: new SequencerInbox(MAX_DATA_SIZE, dummyReader4844, false, true),
inbox: new Inbox(MAX_DATA_SIZE),
rollupEventInbox: new RollupEventInbox(),
outbox: new Outbox()
});
BridgeCreator.BridgeContracts public erc20BasedTemplates =
BridgeCreator.BridgeContracts({
BridgeCreator.BridgeTemplates public erc20BasedTemplates =
BridgeCreator.BridgeTemplates({
bridge: new ERC20Bridge(),
sequencerInbox: new SequencerInbox(MAX_DATA_SIZE, dummyReader4844, true, false),
delayBufferableSequencerInbox: new SequencerInbox(MAX_DATA_SIZE, dummyReader4844, true, true),
Expand Down
13 changes: 7 additions & 6 deletions test/signatures/BridgeCreator
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"createBridge(address,address,address,(uint256,uint256,uint256,uint256),(uint64,uint64,uint64))": "57d3a200",
"erc20BasedDelayBufferableTemplates()": "b7b75abb",
"erc20BasedDelayBufferableSequencerInboxTemplate()": "5686e81d",
"erc20BasedSequencerInboxTemplate()": "23ff1318",
"erc20BasedTemplates()": "76768ab9",
"ethBasedDelayBufferableTemplates()": "1f03c676",
"ethBasedDelayBufferableSequencerInboxTemplate()": "3c08e071",
"ethBasedSequencerInboxTemplate()": "74bc9296",
"ethBasedTemplates()": "11f02227",
"owner()": "8da5cb5b",
"renounceOwnership()": "715018a6",
"transferOwnership(address)": "f2fde38b",
"updateDelayBufferableTemplates((address,address,address,address,address))": "e0061112",
"updateERC20DelayBufferableTemplates((address,address,address,address,address))": "b8ce7934",
"updateERC20Templates((address,address,address,address,address))": "1bb7c6cc",
"updateTemplates((address,address,address,address,address))": "d94d6e0a"
"updateERC20Templates((address,address,address,address))": "3aedb404",
"updateSequencerInboxTemplates(address,address,address,address)": "015fe658",
"updateTemplates((address,address,address,address))": "e7c681f3"
}

0 comments on commit 8efab16

Please sign in to comment.