Skip to content

Commit

Permalink
fix build/tests
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Rice <[email protected]>
  • Loading branch information
mrice32 committed May 20, 2024
1 parent 424d94e commit 8af05b6
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 45 deletions.
13 changes: 12 additions & 1 deletion src/controllers/MutableUnlockersController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,22 @@ abstract contract MutableUnlockersController is Ownable, Oval {
// these don't need to be public since they can be accessed via the accessor functions below.
uint256 private immutable LOCK_WINDOW; // The lockWindow in seconds.
uint256 private immutable MAX_TRAVERSAL; // The maximum number of rounds to traverse when looking for historical data.
uint256 private immutable MAX_AGE; // Max age for a historical price used by Oval instead of the current price.

mapping(address => bool) public unlockers;

constructor(uint256 _lockWindow, uint256 _maxTraversal, address[] memory _unlockers) {
constructor(uint256 _lockWindow, uint256 _maxTraversal, address[] memory _unlockers, uint256 _maxAge) {
LOCK_WINDOW = _lockWindow;
MAX_TRAVERSAL = _maxTraversal;
MAX_AGE = _maxAge;

for (uint256 i = 0; i < _unlockers.length; i++) {
setUnlocker(_unlockers[i], true);
}

emit LockWindowSet(_lockWindow);
emit MaxTraversalSet(_maxTraversal);
emit MaxAgeSet(_maxAge);
}

/**
Expand Down Expand Up @@ -65,4 +69,11 @@ abstract contract MutableUnlockersController is Ownable, Oval {
function maxTraversal() public view override returns (uint256) {
return MAX_TRAVERSAL;
}

/**
* @notice Max age of a historical price that can be used instead of the current price.
*/
function maxAge() public view override returns (uint256) {
return MAX_AGE;
}
}
9 changes: 6 additions & 3 deletions src/factories/StandardChainlinkFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ contract OvalChainlink is MutableUnlockersController, ChainlinkSourceAdapter, Ch
address[] memory unlockers,
uint256 lockWindow,
uint256 maxTraversal,
uint256 maxAge,
address owner
)
ChainlinkSourceAdapter(source)
MutableUnlockersController(lockWindow, maxTraversal, unlockers)
MutableUnlockersController(lockWindow, maxTraversal, unlockers, maxAge)
ChainlinkDestinationAdapter(18)
{
_transferOwnership(owner);
Expand All @@ -44,10 +45,12 @@ contract StandardChainlinkFactory is Ownable, BaseFactory {
* @param source the Chainlink oracle source contract.
* @param lockWindow the lockWindow used for this Oval instance. This is the length of the window
* for the Oval auction to be run and, thus, the maximum time that prices will be delayed.
* @param maxAge max age of a price that is used in place of the current price. If the only available price is
* older than this, OEV is not captured and the current price is provided.
* @return oval deployed oval address.
*/
function create(IAggregatorV3Source source, uint256 lockWindow) external returns (address oval) {
oval = address(new OvalChainlink(source, defaultUnlockers, lockWindow, MAX_TRAVERSAL, owner()));
function create(IAggregatorV3Source source, uint256 lockWindow, uint256 maxAge) external returns (address oval) {
oval = address(new OvalChainlink(source, defaultUnlockers, lockWindow, MAX_TRAVERSAL, maxAge, owner()));
emit OvalDeployed(msg.sender, oval, lockWindow, MAX_TRAVERSAL, owner(), defaultUnlockers);
}
}
9 changes: 6 additions & 3 deletions src/factories/StandardChronicleFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ contract OvalChronicle is MutableUnlockersController, ChronicleMedianSourceAdapt
address[] memory _unlockers,
uint256 _lockWindow,
uint256 _maxTraversal,
uint256 _maxAge,
address _owner
)
ChronicleMedianSourceAdapter(_source)
MutableUnlockersController(_lockWindow, _maxTraversal, _unlockers)
MutableUnlockersController(_lockWindow, _maxTraversal, _unlockers, _maxAge)
ChainlinkDestinationAdapter(18)
{
_transferOwnership(_owner);
Expand All @@ -45,10 +46,12 @@ contract StandardChronicleFactory is Ownable, BaseFactory {
* @param chronicle Chronicle source contract.
* @param lockWindow the lockWindow used for this Oval instance. This is the length of the window
* for the Oval auction to be run and, thus, the maximum time that prices will be delayed.
* @param maxAge max age of a price that is used in place of the current price. If the only available price is
* older than this, OEV is not captured and the current price is provided.
* @return oval deployed oval address.
*/
function create(IMedian chronicle, uint256 lockWindow) external returns (address oval) {
oval = address(new OvalChronicle(chronicle, defaultUnlockers, lockWindow, MAX_TRAVERSAL, owner()));
function create(IMedian chronicle, uint256 lockWindow, uint256 maxAge) external returns (address oval) {
oval = address(new OvalChronicle(chronicle, defaultUnlockers, lockWindow, MAX_TRAVERSAL, maxAge, owner()));
emit OvalDeployed(msg.sender, oval, lockWindow, MAX_TRAVERSAL, owner(), defaultUnlockers);
}
}
9 changes: 6 additions & 3 deletions src/factories/StandardCoinbaseFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ contract OvalCoinbase is MutableUnlockersController, CoinbaseSourceAdapter, Chai
address[] memory _unlockers,
uint256 _lockWindow,
uint256 _maxTraversal,
uint256 _maxAge,
address _owner
)
CoinbaseSourceAdapter(_source, _ticker)
MutableUnlockersController(_lockWindow, _maxTraversal, _unlockers)
MutableUnlockersController(_lockWindow, _maxTraversal, _unlockers, _maxAge)
ChainlinkDestinationAdapter(18)
{
_transferOwnership(_owner);
Expand All @@ -49,10 +50,12 @@ contract StandardCoinbaseFactory is Ownable, BaseFactory {
* @param ticker the Coinbase oracle's ticker.
* @param lockWindow the lockWindow used for this Oval instance. This is the length of the window
* for the Oval auction to be run and, thus, the maximum time that prices will be delayed.
* @param maxAge max age of a price that is used in place of the current price. If the only available price is
* older than this, OEV is not captured and the current price is provided.
* @return oval deployed oval address.
*/
function create(string memory ticker, uint256 lockWindow) external returns (address oval) {
oval = address(new OvalCoinbase(SOURCE, ticker, defaultUnlockers, lockWindow, MAX_TRAVERSAL, owner()));
function create(string memory ticker, uint256 lockWindow, uint256 maxAge) external returns (address oval) {
oval = address(new OvalCoinbase(SOURCE, ticker, defaultUnlockers, lockWindow, MAX_TRAVERSAL, maxAge, owner()));
emit OvalDeployed(msg.sender, oval, lockWindow, MAX_TRAVERSAL, owner(), defaultUnlockers);
}
}
9 changes: 6 additions & 3 deletions src/factories/StandardPythFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ contract OvalPyth is MutableUnlockersController, PythSourceAdapter, ChainlinkDes
address[] memory unlockers,
uint256 lockWindow,
uint256 maxTraversal,
uint256 maxAge,
address owner
)
PythSourceAdapter(source, pythPriceId)
MutableUnlockersController(lockWindow, maxTraversal, unlockers)
MutableUnlockersController(lockWindow, maxTraversal, unlockers, maxAge)
ChainlinkDestinationAdapter(18)
{
_transferOwnership(owner);
Expand All @@ -50,10 +51,12 @@ contract StandardPythFactory is Ownable, BaseFactory {
* @param pythPriceId the Pyth price id.
* @param lockWindow the lockWindow used for this Oval instance. This is the length of the window
* for the Oval auction to be run and, thus, the maximum time that prices will be delayed.
* @param maxAge max age of a price that is used in place of the current price. If the only available price is
* older than this, OEV is not captured and the current price is provided.
* @return oval deployed oval address.
*/
function create(bytes32 pythPriceId, uint256 lockWindow) external returns (address oval) {
oval = address(new OvalPyth(pyth, pythPriceId, defaultUnlockers, lockWindow, MAX_TRAVERSAL, owner()));
function create(bytes32 pythPriceId, uint256 lockWindow, uint256 maxAge) external returns (address oval) {
oval = address(new OvalPyth(pyth, pythPriceId, defaultUnlockers, lockWindow, MAX_TRAVERSAL, maxAge, owner()));
emit OvalDeployed(msg.sender, oval, lockWindow, MAX_TRAVERSAL, owner(), defaultUnlockers);
}
}
12 changes: 1 addition & 11 deletions test/fork/adapters/RedStoneAsChainlinkSourceAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,8 @@ import {IAggregatorV3Source} from "../../../src/interfaces/chainlink/IAggregator
import {MergedPriceFeedAdapterWithRounds} from
"redstone-oracle/on-chain-relayer/contracts/price-feeds/with-rounds/MergedPriceFeedAdapterWithRounds.sol";

contract TestedSourceAdapter is ChainlinkSourceAdapter {
contract TestedSourceAdapter is ChainlinkSourceAdapter, BaseController {
constructor(IAggregatorV3Source source) ChainlinkSourceAdapter(source) {}

function internalLatestData() public view override returns (int256, uint256, uint256) {}

function internalDataAtRound(uint256 roundId) public view override returns (int256, uint256) {}

function canUnlock(address caller, uint256 cachedLatestTimestamp) public view virtual override returns (bool) {}

function lockWindow() public view virtual override returns (uint256) {}

function maxTraversal() public view virtual override returns (uint256) {}
}

contract RedstoneAsChainlinkSourceAdapterTest is CommonTest {
Expand Down
12 changes: 1 addition & 11 deletions test/unit/CoinbaseSourceAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,8 @@ import {DecimalLib} from "../../src/adapters/lib/DecimalLib.sol";
import {IAggregatorV3SourceCoinbase} from "../../src/interfaces/coinbase/IAggregatorV3SourceCoinbase.sol";
import {CoinbaseOracle} from "../../src/oracles/CoinbaseOracle.sol";

contract TestedSourceAdapter is CoinbaseSourceAdapter {
contract TestedSourceAdapter is CoinbaseSourceAdapter, BaseController {
constructor(IAggregatorV3SourceCoinbase source, string memory ticker) CoinbaseSourceAdapter(source, ticker) {}

function internalLatestData() public view override returns (int256, uint256, uint256) {}

function canUnlock(address caller, uint256 cachedLatestTimestamp) public view virtual override returns (bool) {}

function lockWindow() public view virtual override returns (uint256) {}

function maxTraversal() public view virtual override returns (uint256) {}

function internalDataAtRound(uint256 roundId) public view override returns (int256, uint256) {}
}

contract CoinbaseSourceAdapterTest is CommonTest {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/MutableUnlockersController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {BaseDestinationAdapter} from "../../src/adapters/destination-adapters/Ba

contract TestMutableUnlockersController is MutableUnlockersController, MockSourceAdapter, BaseDestinationAdapter {
constructor(address[] memory _unlockers)
MutableUnlockersController(300, 15, _unlockers)
MutableUnlockersController(300, 15, _unlockers, 86400)
MockSourceAdapter(18) // Assuming 18 decimals for the mock source adapter
BaseDestinationAdapter()
{}
Expand Down
1 change: 0 additions & 1 deletion test/unit/RedStoneOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {IAggregatorV3Source} from "../../src/interfaces/chainlink/IAggregatorV3S

import {TestedSourceAdapter} from "../fork/adapters/ChainlinkSourceAdapter.sol";


contract MockRedstonePayload is CommonTest {
function getRedstonePayload(string memory priceFeed) public returns (bytes memory) {
string[] memory args = new string[](4);
Expand Down
5 changes: 3 additions & 2 deletions test/unit/StandardChainlinkFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ contract StandardChainlinkFactoryTest is CommonTest {
address[] unlockers;
uint256 lockWindow = 300;
uint256 maxTraversal = 15;
uint256 maxAge = 86400;

function setUp() public {
mockSource = new MockChainlinkV3Aggregator(8, 420);
Expand All @@ -21,7 +22,7 @@ contract StandardChainlinkFactoryTest is CommonTest {
}

function testCreateMutableUnlockerOvalChainlink() public {
address created = factory.create(IAggregatorV3Source(address(mockSource)), lockWindow);
address created = factory.create(IAggregatorV3Source(address(mockSource)), lockWindow, maxAge);

assertTrue(created != address(0)); // Check if the address is set, non-zero.

Expand All @@ -37,7 +38,7 @@ contract StandardChainlinkFactoryTest is CommonTest {
}

function testOwnerCanChangeUnlockers() public {
address created = factory.create(IAggregatorV3Source(address(mockSource)), lockWindow);
address created = factory.create(IAggregatorV3Source(address(mockSource)), lockWindow, maxAge);
OvalChainlink instance = OvalChainlink(created);

address newUnlocker = address(0x789);
Expand Down
5 changes: 3 additions & 2 deletions test/unit/StandardChronicleFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ contract StandardChronicleFactoryTest is CommonTest {
address[] unlockers;
uint256 lockWindow = 300;
uint256 maxTraversal = 15;
uint256 maxAge = 86400;

function setUp() public {
mockSource = IMedian(address(0x456));
Expand All @@ -20,7 +21,7 @@ contract StandardChronicleFactoryTest is CommonTest {
}

function testCreateMutableUnlockerOvalChronicle() public {
address created = factory.create(mockSource, lockWindow);
address created = factory.create(mockSource, lockWindow, maxAge);

assertTrue(created != address(0)); // Check if the address is set, non-zero.

Expand All @@ -36,7 +37,7 @@ contract StandardChronicleFactoryTest is CommonTest {
}

function testOwnerCanChangeUnlockers() public {
address created = factory.create(mockSource, lockWindow);
address created = factory.create(mockSource, lockWindow, maxAge);
OvalChronicle instance = OvalChronicle(created);

address newUnlocker = address(0x789);
Expand Down
5 changes: 3 additions & 2 deletions test/unit/StandardCoinbaseFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ contract StandardCoinbaseFactoryTest is CommonTest {
uint256 lockWindow = 300;
uint256 maxTraversal = 15;
string ticker = "test ticker";
uint256 maxAge = 86400;

function setUp() public {
mockSource = IAggregatorV3SourceCoinbase(address(new MockChainlinkV3Aggregator(8, 420)));
Expand All @@ -22,7 +23,7 @@ contract StandardCoinbaseFactoryTest is CommonTest {
}

function testCreateMutableUnlockerOvalCoinbase() public {
address created = factory.create(ticker, lockWindow);
address created = factory.create(ticker, lockWindow, maxAge);

assertTrue(created != address(0)); // Check if the address is set, non-zero.

Expand All @@ -38,7 +39,7 @@ contract StandardCoinbaseFactoryTest is CommonTest {
}

function testOwnerCanChangeUnlockers() public {
address created = factory.create(ticker, lockWindow);
address created = factory.create(ticker, lockWindow, maxAge);
OvalCoinbase instance = OvalCoinbase(created);

address newUnlocker = address(0x789);
Expand Down
5 changes: 3 additions & 2 deletions test/unit/StandardPythFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ contract StandardPythFactoryTest is CommonTest {
address[] unlockers;
uint256 lockWindow = 300;
uint256 maxTraversal = 15;
uint256 maxAge = 86400;

function setUp() public {
mockSource = IPyth(address(0x456));
Expand All @@ -20,7 +21,7 @@ contract StandardPythFactoryTest is CommonTest {
}

function testCreateMutableUnlockerOvalPyth() public {
address created = factory.create(bytes32(uint256(0x789)), lockWindow);
address created = factory.create(bytes32(uint256(0x789)), lockWindow, maxAge);

assertTrue(created != address(0)); // Check if the address is set, non-zero.

Expand All @@ -36,7 +37,7 @@ contract StandardPythFactoryTest is CommonTest {
}

function testOwnerCanChangeUnlockers() public {
address created = factory.create(bytes32(uint256(0x789)), lockWindow);
address created = factory.create(bytes32(uint256(0x789)), lockWindow, maxAge);
OvalPyth instance = OvalPyth(created);

address newUnlocker = address(0x789);
Expand Down

0 comments on commit 8af05b6

Please sign in to comment.