Skip to content

Commit

Permalink
use constructor for l1 cross domain instead of one contract per domai…
Browse files Browse the repository at this point in the history
…n to save new code (#27)
  • Loading branch information
hexonaut authored Sep 6, 2024
1 parent 5588f15 commit 39d5454
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 90 deletions.
17 changes: 7 additions & 10 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand Down
23 changes: 0 additions & 23 deletions src/forwarders/DSROracleForwarderBaseChain.sol

This file was deleted.

8 changes: 5 additions & 3 deletions src/forwarders/DSROracleForwarderOptimism.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 0 additions & 23 deletions src/forwarders/DSROracleForwarderWorldChain.sol

This file was deleted.

8 changes: 4 additions & 4 deletions test/DSROracleIntegrationArbitrumOne.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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();

Expand All @@ -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 {
Expand Down
13 changes: 3 additions & 10 deletions test/DSROracleIntegrationBaseChain.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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();

Expand All @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions test/DSROracleIntegrationOptimism.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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();

Expand All @@ -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"));
Expand Down
13 changes: 3 additions & 10 deletions test/DSROracleIntegrationWorldChain.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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();

Expand All @@ -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 {
Expand Down

0 comments on commit 39d5454

Please sign in to comment.