From 39d5454710717c5f76c67ef124c34818e30503b3 Mon Sep 17 00:00:00 2001 From: Sam MacPherson Date: Fri, 6 Sep 2024 23:01:54 +0900 Subject: [PATCH] use constructor for l1 cross domain instead of one contract per domain to save new code (#27) --- script/Deploy.s.sol | 17 ++++++-------- ...One.sol => DSROracleForwarderArbitrum.sol} | 10 ++++---- .../DSROracleForwarderBaseChain.sol | 23 ------------------- src/forwarders/DSROracleForwarderOptimism.sol | 8 ++++--- .../DSROracleForwarderWorldChain.sol | 23 ------------------- test/DSROracleIntegrationArbitrumOne.t.sol | 8 +++---- test/DSROracleIntegrationBaseChain.t.sol | 13 +++-------- test/DSROracleIntegrationOptimism.t.sol | 6 ++--- test/DSROracleIntegrationWorldChain.t.sol | 13 +++-------- 9 files changed, 31 insertions(+), 90 deletions(-) rename src/forwarders/{DSROracleForwarderArbitrumOne.sol => DSROracleForwarderArbitrum.sol} (65%) delete mode 100644 src/forwarders/DSROracleForwarderBaseChain.sol delete mode 100644 src/forwarders/DSROracleForwarderWorldChain.sol diff --git a/script/Deploy.s.sol b/script/Deploy.s.sol index 55eba01..5bcf52c 100644 --- a/script/Deploy.s.sol +++ b/script/Deploy.s.sol @@ -5,15 +5,12 @@ import "forge-std/Script.sol"; import { Gnosis } from "sparklend-address-registry/src/Gnosis.sol"; -import { IDSRAuthOracle } from "src/interfaces/IDSRAuthOracle.sol"; import { DSRBalancerRateProviderAdapter } from "src/adapters/DSRBalancerRateProviderAdapter.sol"; import { DSRAuthOracle } from "src/DSRAuthOracle.sol"; -import { DSROracleForwarderOptimism } from "src/forwarders/DSROracleForwarderOptimism.sol"; -import { DSROracleForwarderBaseChain } from "src/forwarders/DSROracleForwarderBaseChain.sol"; -import { DSROracleForwarderWorldChain } from "src/forwarders/DSROracleForwarderWorldChain.sol"; -import { DSROracleForwarderGnosis } from "src/forwarders/DSROracleForwarderGnosis.sol"; -import { DSROracleForwarderArbitrumOne } from "src/forwarders/DSROracleForwarderArbitrumOne.sol"; +import { DSROracleForwarderOptimism, OptimismForwarder } from "src/forwarders/DSROracleForwarderOptimism.sol"; +import { DSROracleForwarderGnosis } from "src/forwarders/DSROracleForwarderGnosis.sol"; +import { DSROracleForwarderArbitrum, ArbitrumForwarder } from "src/forwarders/DSROracleForwarderArbitrum.sol"; import { AMBReceiver } from "xchain-helpers/receivers/AMBReceiver.sol"; import { ArbitrumReceiver } from "xchain-helpers/receivers/ArbitrumReceiver.sol"; @@ -77,7 +74,7 @@ contract DeployOptimism is Deploy { } function deployForwarder(address receiver) internal override returns (address) { - return address(new DSROracleForwarderOptimism(MCD_POT, receiver)); + return address(new DSROracleForwarderOptimism(MCD_POT, receiver, OptimismForwarder.L1_CROSS_DOMAIN_OPTIMISM)); } function deployReceiver(address forwarder, address oracle) internal override returns (address) { @@ -93,7 +90,7 @@ contract DeployBase is Deploy { } function deployForwarder(address receiver) internal override returns (address) { - return address(new DSROracleForwarderBaseChain(MCD_POT, receiver)); + return address(new DSROracleForwarderOptimism(MCD_POT, receiver, OptimismForwarder.L1_CROSS_DOMAIN_BASE)); } function deployReceiver(address forwarder, address oracle) internal override returns (address) { @@ -109,7 +106,7 @@ contract DeployWorldChain is Deploy { } function deployForwarder(address receiver) internal override returns (address) { - return address(new DSROracleForwarderWorldChain(MCD_POT, receiver)); + return address(new DSROracleForwarderOptimism(MCD_POT, receiver, OptimismForwarder.L1_CROSS_DOMAIN_WORLD_CHAIN)); } function deployReceiver(address forwarder, address oracle) internal override returns (address) { @@ -141,7 +138,7 @@ contract DeployArbitrumOne is Deploy { } function deployForwarder(address receiver) internal override returns (address) { - return address(new DSROracleForwarderArbitrumOne(MCD_POT, receiver)); + return address(new DSROracleForwarderArbitrum(MCD_POT, receiver, ArbitrumForwarder.L1_CROSS_DOMAIN_ARBITRUM_ONE)); } function deployReceiver(address forwarder, address oracle) internal override returns (address) { diff --git a/src/forwarders/DSROracleForwarderArbitrumOne.sol b/src/forwarders/DSROracleForwarderArbitrum.sol similarity index 65% rename from src/forwarders/DSROracleForwarderArbitrumOne.sol rename to src/forwarders/DSROracleForwarderArbitrum.sol index 51fad59..0d0c8bd 100644 --- a/src/forwarders/DSROracleForwarderArbitrumOne.sol +++ b/src/forwarders/DSROracleForwarderArbitrum.sol @@ -5,10 +5,12 @@ import { ArbitrumForwarder } from 'xchain-helpers/forwarders/ArbitrumForwarder.s import { DSROracleForwarderBase } from './DSROracleForwarderBase.sol'; -contract DSROracleForwarderArbitrumOne is DSROracleForwarderBase { +contract DSROracleForwarderArbitrum is DSROracleForwarderBase { - constructor(address _pot, address _l2Oracle) DSROracleForwarderBase(_pot, _l2Oracle) { - // Intentionally left blank + address public immutable l1CrossDomain; + + constructor(address _pot, address _l2Oracle, address _l1CrossDomain) DSROracleForwarderBase(_pot, _l2Oracle) { + l1CrossDomain = _l1CrossDomain; } function refresh( @@ -17,7 +19,7 @@ contract DSROracleForwarderArbitrumOne is DSROracleForwarderBase { uint256 baseFee ) public payable { ArbitrumForwarder.sendMessageL1toL2( - ArbitrumForwarder.L1_CROSS_DOMAIN_ARBITRUM_ONE, + l1CrossDomain, address(l2Oracle), _packMessage(), gasLimit, diff --git a/src/forwarders/DSROracleForwarderBaseChain.sol b/src/forwarders/DSROracleForwarderBaseChain.sol deleted file mode 100644 index 2dd705e..0000000 --- a/src/forwarders/DSROracleForwarderBaseChain.sol +++ /dev/null @@ -1,23 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-or-later -pragma solidity ^0.8.0; - -import { OptimismForwarder } from 'xchain-helpers/forwarders/OptimismForwarder.sol'; - -import { DSROracleForwarderBase } from './DSROracleForwarderBase.sol'; - -contract DSROracleForwarderBaseChain is DSROracleForwarderBase { - - constructor(address _pot, address _l2Oracle) DSROracleForwarderBase(_pot, _l2Oracle) { - // Intentionally left blank - } - - function refresh(uint32 gasLimit) public { - OptimismForwarder.sendMessageL1toL2( - OptimismForwarder.L1_CROSS_DOMAIN_BASE, - address(l2Oracle), - _packMessage(), - gasLimit - ); - } - -} diff --git a/src/forwarders/DSROracleForwarderOptimism.sol b/src/forwarders/DSROracleForwarderOptimism.sol index 4a4a4b4..b0a33fe 100644 --- a/src/forwarders/DSROracleForwarderOptimism.sol +++ b/src/forwarders/DSROracleForwarderOptimism.sol @@ -7,13 +7,15 @@ import { DSROracleForwarderBase } from './DSROracleForwarderBase.sol'; contract DSROracleForwarderOptimism is DSROracleForwarderBase { - constructor(address _pot, address _l2Oracle) DSROracleForwarderBase(_pot, _l2Oracle) { - // Intentionally left blank + address public immutable l1CrossDomain; + + constructor(address _pot, address _l2Oracle, address _l1CrossDomain) DSROracleForwarderBase(_pot, _l2Oracle) { + l1CrossDomain = _l1CrossDomain; } function refresh(uint32 gasLimit) public { OptimismForwarder.sendMessageL1toL2( - OptimismForwarder.L1_CROSS_DOMAIN_OPTIMISM, + l1CrossDomain, address(l2Oracle), _packMessage(), gasLimit diff --git a/src/forwarders/DSROracleForwarderWorldChain.sol b/src/forwarders/DSROracleForwarderWorldChain.sol deleted file mode 100644 index 147134a..0000000 --- a/src/forwarders/DSROracleForwarderWorldChain.sol +++ /dev/null @@ -1,23 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-or-later -pragma solidity ^0.8.0; - -import { OptimismForwarder } from 'xchain-helpers/forwarders/OptimismForwarder.sol'; - -import { DSROracleForwarderBase } from './DSROracleForwarderBase.sol'; - -contract DSROracleForwarderWorldChain is DSROracleForwarderBase { - - constructor(address _pot, address _l2Oracle) DSROracleForwarderBase(_pot, _l2Oracle) { - // Intentionally left blank - } - - function refresh(uint32 gasLimit) public { - OptimismForwarder.sendMessageL1toL2( - OptimismForwarder.L1_CROSS_DOMAIN_WORLD_CHAIN, - address(l2Oracle), - _packMessage(), - gasLimit - ); - } - -} diff --git a/test/DSROracleIntegrationArbitrumOne.t.sol b/test/DSROracleIntegrationArbitrumOne.t.sol index 1e01ddd..654c2e3 100644 --- a/test/DSROracleIntegrationArbitrumOne.t.sol +++ b/test/DSROracleIntegrationArbitrumOne.t.sol @@ -6,7 +6,7 @@ import "./DSROracleXChainIntegrationBase.t.sol"; import { ArbitrumBridgeTesting } from "xchain-helpers/testing/bridges/ArbitrumBridgeTesting.sol"; import { ArbitrumReceiver } from "xchain-helpers/receivers/ArbitrumReceiver.sol"; -import { DSROracleForwarderArbitrumOne } from "src/forwarders/DSROracleForwarderArbitrumOne.sol"; +import { DSROracleForwarderArbitrum, ArbitrumForwarder } from "src/forwarders/DSROracleForwarderArbitrum.sol"; contract DSROracleIntegrationArbitrumOneTest is DSROracleXChainIntegrationBaseTest { @@ -20,7 +20,7 @@ contract DSROracleIntegrationArbitrumOneTest is DSROracleXChainIntegrationBaseTe mainnet.selectFork(); address expectedReceiver = computeCreateAddress(address(this), 4); - forwarder = new DSROracleForwarderArbitrumOne(address(pot), expectedReceiver); + forwarder = new DSROracleForwarderArbitrum(address(pot), expectedReceiver, ArbitrumForwarder.L1_CROSS_DOMAIN_ARBITRUM_ONE); remote.selectFork(); @@ -33,14 +33,14 @@ contract DSROracleIntegrationArbitrumOneTest is DSROracleXChainIntegrationBaseTe } function test_constructor_forwarder() public { - DSROracleForwarderArbitrumOne forwarder = new DSROracleForwarderArbitrumOne(address(pot), makeAddr("receiver")); + DSROracleForwarderArbitrum forwarder = new DSROracleForwarderArbitrum(address(pot), makeAddr("receiver"), ArbitrumForwarder.L1_CROSS_DOMAIN_ARBITRUM_ONE); assertEq(address(forwarder.pot()), address(pot)); assertEq(forwarder.l2Oracle(), makeAddr("receiver")); } function doRefresh() internal override { - DSROracleForwarderArbitrumOne(address(forwarder)).refresh{value:1 ether}(500_000, 1 gwei, block.basefee + 10 gwei); + DSROracleForwarderArbitrum(address(forwarder)).refresh{value:1 ether}(500_000, 1 gwei, block.basefee + 10 gwei); } function relayMessagesAcrossBridge() internal override { diff --git a/test/DSROracleIntegrationBaseChain.t.sol b/test/DSROracleIntegrationBaseChain.t.sol index cd0dd3e..c0fd4cb 100644 --- a/test/DSROracleIntegrationBaseChain.t.sol +++ b/test/DSROracleIntegrationBaseChain.t.sol @@ -6,7 +6,7 @@ import "./DSROracleXChainIntegrationBase.t.sol"; import { OptimismBridgeTesting } from "xchain-helpers/testing/bridges/OptimismBridgeTesting.sol"; import { OptimismReceiver } from "xchain-helpers/receivers/OptimismReceiver.sol"; -import { DSROracleForwarderBaseChain } from "src/forwarders/DSROracleForwarderBaseChain.sol"; +import { DSROracleForwarderOptimism, OptimismForwarder } from "src/forwarders/DSROracleForwarderOptimism.sol"; contract DSROracleIntegrationBaseChainTest is DSROracleXChainIntegrationBaseTest { @@ -20,7 +20,7 @@ contract DSROracleIntegrationBaseChainTest is DSROracleXChainIntegrationBaseTest mainnet.selectFork(); address expectedReceiver = vm.computeCreateAddress(address(this), 3); - forwarder = new DSROracleForwarderBaseChain(address(pot), expectedReceiver); + forwarder = new DSROracleForwarderOptimism(address(pot), expectedReceiver, OptimismForwarder.L1_CROSS_DOMAIN_BASE); remote.selectFork(); @@ -31,15 +31,8 @@ contract DSROracleIntegrationBaseChainTest is DSROracleXChainIntegrationBaseTest assertEq(address(receiver), expectedReceiver); } - function test_constructor_forwarder() public { - DSROracleForwarderBaseChain forwarder = new DSROracleForwarderBaseChain(address(pot), makeAddr("receiver")); - - assertEq(address(forwarder.pot()), address(pot)); - assertEq(forwarder.l2Oracle(), makeAddr("receiver")); - } - function doRefresh() internal override { - DSROracleForwarderBaseChain(address(forwarder)).refresh(500_000); + DSROracleForwarderOptimism(address(forwarder)).refresh(500_000); } function relayMessagesAcrossBridge() internal override { diff --git a/test/DSROracleIntegrationOptimism.t.sol b/test/DSROracleIntegrationOptimism.t.sol index 283be7c..5f72dd8 100644 --- a/test/DSROracleIntegrationOptimism.t.sol +++ b/test/DSROracleIntegrationOptimism.t.sol @@ -6,7 +6,7 @@ import "./DSROracleXChainIntegrationBase.t.sol"; import { OptimismBridgeTesting } from "xchain-helpers/testing/bridges/OptimismBridgeTesting.sol"; import { OptimismReceiver } from "xchain-helpers/receivers/OptimismReceiver.sol"; -import { DSROracleForwarderOptimism } from "src/forwarders/DSROracleForwarderOptimism.sol"; +import { DSROracleForwarderOptimism, OptimismForwarder } from "src/forwarders/DSROracleForwarderOptimism.sol"; contract DSROracleIntegrationOptimismTest is DSROracleXChainIntegrationBaseTest { @@ -20,7 +20,7 @@ contract DSROracleIntegrationOptimismTest is DSROracleXChainIntegrationBaseTest mainnet.selectFork(); address expectedReceiver = vm.computeCreateAddress(address(this), 3); - forwarder = new DSROracleForwarderOptimism(address(pot), expectedReceiver); + forwarder = new DSROracleForwarderOptimism(address(pot), expectedReceiver, OptimismForwarder.L1_CROSS_DOMAIN_OPTIMISM); remote.selectFork(); @@ -32,7 +32,7 @@ contract DSROracleIntegrationOptimismTest is DSROracleXChainIntegrationBaseTest } function test_constructor_forwarder() public { - DSROracleForwarderOptimism forwarder = new DSROracleForwarderOptimism(address(pot), makeAddr("receiver")); + DSROracleForwarderOptimism forwarder = new DSROracleForwarderOptimism(address(pot), makeAddr("receiver"), OptimismForwarder.L1_CROSS_DOMAIN_OPTIMISM); assertEq(address(forwarder.pot()), address(pot)); assertEq(forwarder.l2Oracle(), makeAddr("receiver")); diff --git a/test/DSROracleIntegrationWorldChain.t.sol b/test/DSROracleIntegrationWorldChain.t.sol index 9bfd20b..42ce9e0 100644 --- a/test/DSROracleIntegrationWorldChain.t.sol +++ b/test/DSROracleIntegrationWorldChain.t.sol @@ -6,7 +6,7 @@ import "./DSROracleXChainIntegrationBase.t.sol"; import { OptimismBridgeTesting } from "xchain-helpers/testing/bridges/OptimismBridgeTesting.sol"; import { OptimismReceiver } from "xchain-helpers/receivers/OptimismReceiver.sol"; -import { DSROracleForwarderWorldChain } from "src/forwarders/DSROracleForwarderWorldChain.sol"; +import { DSROracleForwarderOptimism, OptimismForwarder } from "src/forwarders/DSROracleForwarderOptimism.sol"; contract DSROracleIntegrationWorldChainTest is DSROracleXChainIntegrationBaseTest { @@ -25,7 +25,7 @@ contract DSROracleIntegrationWorldChainTest is DSROracleXChainIntegrationBaseTes mainnet.selectFork(); address expectedReceiver = vm.computeCreateAddress(address(this), 3); - forwarder = new DSROracleForwarderWorldChain(address(pot), expectedReceiver); + forwarder = new DSROracleForwarderOptimism(address(pot), expectedReceiver, OptimismForwarder.L1_CROSS_DOMAIN_WORLD_CHAIN); remote.selectFork(); @@ -36,15 +36,8 @@ contract DSROracleIntegrationWorldChainTest is DSROracleXChainIntegrationBaseTes assertEq(address(receiver), expectedReceiver); } - function test_constructor_forwarder() public { - DSROracleForwarderWorldChain forwarder = new DSROracleForwarderWorldChain(address(pot), makeAddr("receiver")); - - assertEq(address(forwarder.pot()), address(pot)); - assertEq(forwarder.l2Oracle(), makeAddr("receiver")); - } - function doRefresh() internal override { - DSROracleForwarderWorldChain(address(forwarder)).refresh(500_000); + DSROracleForwarderOptimism(address(forwarder)).refresh(500_000); } function relayMessagesAcrossBridge() internal override {