Skip to content

Commit

Permalink
[SC-375] Add arbitrum (#7)
Browse files Browse the repository at this point in the history
* add interface, base and mainnet implementation

* add tests for all dsr oracle

* add fuzz test with some error bounds

* use longer duration and compare binomial to exact

* add natspec to interface

* update xchain helpers

* add gas metering tests

* add 1 hour gas tests

* add comments about source of conversion rate compute functions

* change constant names to be less confusing

* add notes about why the value is what it is

* started on gnosis

* begin gnosis chain dsr oracle

* add integration test for mainnet and gnosis

* refactor integration tests into separate files

* spacing fix

* remove maker blurb

* use more specific revert

* alignment

* alignment and slight change to final compare

* fix for checking past timestamp reverts; fix formula for linear approx; more explicit casting to uint256 to prevent subtle overflows

* remove the zero dsr check

* use explicit error vs subtle underflow for timestamps

* use explicit error vs subtle underflow for timestamps

* optimize the gas on the no elapsed time scenario

* tighter boundary condition

* align

* align

* cache one year timestamp

* align

* rm extra space

* add a bunch of sanity checks to updates to minimize damage during an oracle attack

* update xchain-helpers

* fix tests

* add failure case tests

* dont use the sanity checks for mainnet oracle

* refactoring the structure

* forge install: openzeppelin-contracts

v5.0.0

* make a generic auth oracle and split out gnosis-specific bridging behaviour to a separate contract

* bump forge-std to fix integration tests

* add optimism

* add assert

* store last sent data to assist with keepers

* fix timestamp issue

* fix ci

* remove unused import

* add arbitrum

* formatting
  • Loading branch information
hexonaut authored Apr 10, 2024
1 parent 240a80e commit a634415
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 12 deletions.
28 changes: 28 additions & 0 deletions src/forwarders/DSROracleForwarderArbitrumOne.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity ^0.8.0;

import { XChainForwarders } from 'xchain-helpers/XChainForwarders.sol';

import { DSROracleForwarderBase } from './DSROracleForwarderBase.sol';

contract DSROracleForwarderArbitrumOne is DSROracleForwarderBase {

constructor(address _pot, address _l2Oracle) DSROracleForwarderBase(_pot, _l2Oracle) {
// Intentionally left blank
}

function refresh(
uint256 gasLimit,
uint256 maxFeePerGas,
uint256 baseFee
) public payable {
XChainForwarders.sendMessageArbitrumOne(
address(l2Oracle),
_packMessage(),
gasLimit,
maxFeePerGas,
baseFee
);
}

}
23 changes: 23 additions & 0 deletions src/receivers/DSROracleReceiverArbitrum.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity ^0.8.0;

import { ArbitrumReceiver } from 'xchain-helpers/ArbitrumReceiver.sol';

import { IDSRAuthOracle, IDSROracle } from '../interfaces/IDSRAuthOracle.sol';

contract DSROracleReceiverArbitrum is ArbitrumReceiver {

IDSRAuthOracle public oracle;

constructor(
address _l1Authority,
IDSRAuthOracle _oracle
) ArbitrumReceiver(_l1Authority) {
oracle = _oracle;
}

function setPotData(IDSROracle.PotData calldata data) external onlyCrossChainMessage {
oracle.setPotData(data);
}

}
38 changes: 38 additions & 0 deletions test/DSROracleIntegrationArbitrum.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity ^0.8.0;

import { ArbitrumDomain } from "xchain-helpers/testing/ArbitrumDomain.sol";

import { DSROracleForwarderArbitrumOne } from "src/forwarders/DSROracleForwarderArbitrumOne.sol";
import { DSROracleReceiverArbitrum } from "src/receivers/DSROracleReceiverArbitrum.sol";

import "./DSROracleXChainIntegrationBase.t.sol";

contract DSROracleIntegrationArbitrumTest is DSROracleXChainIntegrationBaseTest {

DSROracleForwarderArbitrumOne forwarder;
DSROracleReceiverArbitrum receiver;

function setupDomain() internal override {
remote = new ArbitrumDomain(getChain('arbitrum_one'), mainnet);

mainnet.selectFork();

address expectedReceiver = computeCreateAddress(address(this), 5);
forwarder = new DSROracleForwarderArbitrumOne(address(pot), expectedReceiver);

remote.selectFork();

oracle = new DSRAuthOracle();
receiver = new DSROracleReceiverArbitrum(address(forwarder), oracle);

oracle.grantRole(oracle.DATA_PROVIDER_ROLE(), address(receiver));

assertEq(address(receiver), expectedReceiver);
}

function doRefresh() internal override {
forwarder.refresh{value:1 ether}(500_000, 1 gwei, block.basefee + 10 gwei);
}

}
13 changes: 7 additions & 6 deletions test/DSROracleIntegrationGnosis.t.sol
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity ^0.8.0;

import "./DSROracleXChainIntegrationBase.t.sol";

import { GnosisDomain } from "xchain-helpers/testing/GnosisDomain.sol";

import { DSROracleForwarderGnosis } from "../src/forwarders/DSROracleForwarderGnosis.sol";
import { DSROracleReceiverGnosis } from "../src/receivers/DSROracleReceiverGnosis.sol";
import { DSROracleForwarderGnosis } from "src/forwarders/DSROracleForwarderGnosis.sol";
import { DSROracleReceiverGnosis } from "src/receivers/DSROracleReceiverGnosis.sol";

import "./DSROracleXChainIntegrationBase.t.sol";

contract DSROracleIntegrationGnosisTest is DSROracleXChainIntegrationBaseTest {

address constant AMB = 0x75Df5AF045d91108662D8080fD1FEFAd6aA0bb59;

DSROracleForwarderGnosis forwarder;
DSROracleReceiverGnosis receiver;
DSROracleReceiverGnosis receiver;

function setupDomain() internal override {
remote = new GnosisDomain(getChain('gnosis_chain'), mainnet);
Expand All @@ -24,8 +24,9 @@ contract DSROracleIntegrationGnosisTest is DSROracleXChainIntegrationBaseTest {

remote.selectFork();

oracle = new DSRAuthOracle();
oracle = new DSRAuthOracle();
receiver = new DSROracleReceiverGnosis(AMB, 1, address(forwarder), oracle);

oracle.grantRole(oracle.DATA_PROVIDER_ROLE(), address(receiver));
}

Expand Down
13 changes: 7 additions & 6 deletions test/DSROracleIntegrationOptimism.t.sol
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity ^0.8.0;

import "./DSROracleXChainIntegrationBase.t.sol";

import { OptimismDomain } from "xchain-helpers/testing/OptimismDomain.sol";

import { DSROracleForwarderOptimism } from "../src/forwarders/DSROracleForwarderOptimism.sol";
import { DSROracleReceiverOptimism } from "../src/receivers/DSROracleReceiverOptimism.sol";
import { DSROracleForwarderOptimism } from "src/forwarders/DSROracleForwarderOptimism.sol";
import { DSROracleReceiverOptimism } from "src/receivers/DSROracleReceiverOptimism.sol";

import "./DSROracleXChainIntegrationBase.t.sol";

contract DSROracleIntegrationOptimismTest is DSROracleXChainIntegrationBaseTest {

DSROracleForwarderOptimism forwarder;
DSROracleReceiverOptimism receiver;
DSROracleReceiverOptimism receiver;

function setupDomain() internal override {
remote = new OptimismDomain(getChain('optimism'), mainnet);
Expand All @@ -23,8 +23,9 @@ contract DSROracleIntegrationOptimismTest is DSROracleXChainIntegrationBaseTest

remote.selectFork();

oracle = new DSRAuthOracle();
oracle = new DSRAuthOracle();
receiver = new DSROracleReceiverOptimism(address(forwarder), oracle);

oracle.grantRole(oracle.DATA_PROVIDER_ROLE(), address(receiver));

assertEq(address(receiver), expectedReceiver);
Expand Down

0 comments on commit a634415

Please sign in to comment.