From 8efab16dcc2c736ca8b44b9ca8d5a5cd3fcd6660 Mon Sep 17 00:00:00 2001 From: shotaro <10378902+shotaronowhere@users.noreply.github.com> Date: Fri, 12 Apr 2024 16:43:40 -0300 Subject: [PATCH] chore: bridge creator refactor --- src/rollup/BridgeCreator.sol | 28 +++++++++++++++++----------- test/foundry/BridgeCreator.t.sol | 25 +++++++++++++------------ test/foundry/RollupCreator.t.sol | 8 ++++---- test/signatures/BridgeCreator | 13 +++++++------ 4 files changed, 41 insertions(+), 33 deletions(-) diff --git a/src/rollup/BridgeCreator.sol b/src/rollup/BridgeCreator.sol index 88361fda6..10fe0b9bc 100644 --- a/src/rollup/BridgeCreator.sol +++ b/src/rollup/BridgeCreator.sol @@ -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; @@ -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; @@ -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 diff --git a/test/foundry/BridgeCreator.t.sol b/test/foundry/BridgeCreator.t.sol index e9eebeeac..005687a8f 100644 --- a/test/foundry/BridgeCreator.t.sol +++ b/test/foundry/BridgeCreator.t.sol @@ -15,8 +15,8 @@ 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), @@ -24,8 +24,8 @@ contract BridgeCreatorTest is Test { 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), @@ -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, @@ -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, @@ -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), @@ -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)), @@ -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)), diff --git a/test/foundry/RollupCreator.t.sol b/test/foundry/RollupCreator.t.sol index 33df2c175..8c808d767 100644 --- a/test/foundry/RollupCreator.t.sol +++ b/test/foundry/RollupCreator.t.sol @@ -33,8 +33,8 @@ 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), @@ -42,8 +42,8 @@ contract RollupCreatorTest is Test { 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), diff --git a/test/signatures/BridgeCreator b/test/signatures/BridgeCreator index fd4cc2cbd..65ef585b3 100644 --- a/test/signatures/BridgeCreator +++ b/test/signatures/BridgeCreator @@ -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" }