-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add fork detector contract * forkability improvements This PR introduces a new core utility contract, `ForkDetector`, which provides a way for developer forks (such as Tenderly, Anvil) to distinguish themselves from the canonical chain safely. This can be useful as there are some functionalities which are difficult to operate on a fork (ex. offchain prices or precompiled contracts), and the behavior in those places can be selectively mocked to prevent interruption of testing. Design Considerations: * The idea of these changes is to provide a one-line way for integrators or anyone trying to fork the synthetix system a way to make Synthetix fork-friendly setup. In the future, who knows, this functionality could be enabled by default. * Original functionality of the chain can be restored by removing or modifying the code at `0x1234123412341234123412341234123412341234`, in case your tests require it Specific changes: * add `ForkDetector` library * in op gas price oracle, replace calls to the OP precompiled contract with mock values or skip * in arb gas price oracle, replace calls to the arbitrum precompiled contract with mock values or skip * in pyth ERC7412 adapter proxy, use whatever the latest price available on-chain is regardless of its staleness. Additionally, prices can be overridden by calling the contract (note: it was previously possible to simply switch out the oracle node on the oracle manager as well, but sometimes this lever is much more convenient to pull) Tests to be written tomorrow * add tests * set reasonable mock values reccomendation from audit * misc audit fixes * add events for fork-only write operations * misc lint/solidity style warnings * move definition of contractCode variable * fix abstract proxy is not effectively used by the pyth wrapper audit note * add flag * undo storage changes * fix yarn lock
- Loading branch information
Showing
14 changed files
with
275 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[profile.default] | ||
allow_paths = ["../../"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@synthetixio/core-contracts=../../utils/core-contracts | ||
@synthetixio/oracle-manager=../../protocol/oracle-manager |
27 changes: 27 additions & 0 deletions
27
auxiliary/ArbitrumGasPriceOracle/test/ArbGasPriceOracle.test.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.11 <0.9.0; | ||
|
||
import "../contracts/ArbGasPriceOracle.sol"; | ||
|
||
import {Test} from "forge-std/Test.sol"; | ||
|
||
contract ArbGasPriceOracleTest is Test { | ||
ArbGasPriceOracle private oracle; | ||
|
||
function setUp() external { | ||
vm.etch(0x1234123412341234123412341234123412341234, "FORK"); | ||
oracle = new ArbGasPriceOracle(address(0)); | ||
} | ||
|
||
function testIsValidVerifies() external view { | ||
bytes memory fakeParams = abi.encode(address(0), 0, 0, 0, 0, 0, 0); | ||
oracle.isValid( | ||
NodeDefinition.Data(NodeDefinition.NodeType.EXTERNAL, fakeParams, new bytes32[](0)) | ||
); | ||
} | ||
|
||
function testProcessProcesses() external view { | ||
bytes memory fakeParams = abi.encode(address(0), 0, 0, 0, 0, 0, 0); | ||
oracle.process(new NodeOutput.Data[](0), fakeParams, new bytes32[](0), new bytes32[](0)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[profile.default] | ||
allow_paths = ["../../"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@synthetixio/core-contracts=../../utils/core-contracts | ||
@synthetixio/oracle-manager=../../protocol/oracle-manager |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.11 <0.9.0; | ||
|
||
import "../contracts/OpGasPriceOracle.sol"; | ||
|
||
import {Test} from "forge-std/Test.sol"; | ||
|
||
contract OpGasPriceOracleTest is Test { | ||
OpGasPriceOracle private oracle; | ||
|
||
function setUp() external { | ||
vm.etch(0x1234123412341234123412341234123412341234, "FORK"); | ||
oracle = new OpGasPriceOracle(address(0)); | ||
} | ||
|
||
function testIsValidVerifies() external view { | ||
bytes memory fakeParams = abi.encode(address(0), 0, 0, 0, 0, 0, 0, 0, 0, 0); | ||
oracle.isValid( | ||
NodeDefinition.Data(NodeDefinition.NodeType.EXTERNAL, fakeParams, new bytes32[](0)) | ||
); | ||
} | ||
|
||
function testProcessProcesses() external view { | ||
bytes memory fakeParams = abi.encode(address(0), 0, 0, 0, 0, 0, 0, 0, 0, 0); | ||
oracle.process(new NodeOutput.Data[](0), fakeParams, new bytes32[](0), new bytes32[](0)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[profile.default] | ||
allow_paths = ["../../"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@synthetixio/core-contracts=../../utils/core-contracts | ||
@synthetixio/oracle-manager=../../protocol/oracle-manager |
71 changes: 71 additions & 0 deletions
71
auxiliary/PythERC7412Wrapper/test/PythERC7412Wrapper.test.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.11 <0.9.0; | ||
|
||
import "../contracts/PythERC7412Wrapper.sol"; | ||
|
||
import {Test} from "forge-std/Test.sol"; | ||
|
||
contract MockPythApi { | ||
function getPriceUnsafe(bytes32) external pure returns (PythStructs.Price memory price) { | ||
return PythStructs.Price(100, 0, -17, 0); | ||
} | ||
} | ||
|
||
contract PythERC7412WrapperTest is Test { | ||
MockPythApi mockPyth; | ||
PythERC7412Wrapper wrapper; | ||
bytes32 testFeedId = keccak256("test"); | ||
|
||
function setUp() external { | ||
vm.etch(0x1234123412341234123412341234123412341234, "FORK"); | ||
mockPyth = new MockPythApi(); | ||
wrapper = new PythERC7412Wrapper(address(mockPyth)); | ||
} | ||
|
||
function testSetLatestPriceOutsideOfForkFails() external { | ||
vm.etch(0x1234123412341234123412341234123412341234, "notf"); | ||
|
||
vm.expectRevert(ForkDetector.OnlyOnDevFork.selector); | ||
wrapper.setLatestPrice(testFeedId, 500); | ||
} | ||
|
||
function testSetLatestPrice() external { | ||
wrapper.setLatestPrice(testFeedId, 500); | ||
|
||
assertEq(wrapper.getLatestPrice(testFeedId, 0), 500); | ||
} | ||
|
||
function testGetLatestPrice() external view { | ||
assertEq(wrapper.getLatestPrice(testFeedId, 0), 1000); | ||
} | ||
|
||
function testSetBenchmarkPriceOutsideOfForkFails() external { | ||
vm.etch(0x1234123412341234123412341234123412341234, "notf"); | ||
|
||
vm.expectRevert(ForkDetector.OnlyOnDevFork.selector); | ||
wrapper.setLatestPrice(testFeedId, 500); | ||
} | ||
|
||
function testSetBenchmarkPrice() external { | ||
wrapper.setBenchmarkPrice(testFeedId, 100, 1234, -18); | ||
|
||
assertEq(wrapper.getBenchmarkPrice(testFeedId, 100), 1234); | ||
} | ||
|
||
function testGetBenchmarkPriceWithSkip() external { | ||
wrapper.setBenchmarkPrice(testFeedId, 100, -1, -18); | ||
|
||
vm.expectRevert( | ||
abi.encodeWithSelector( | ||
IERC7412.OracleDataRequired.selector, | ||
address(wrapper), | ||
hex"000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000649c22ff5f21f0b81b113e63f7db6da94fedef11b2119b4088b89664fb9a3cb658" | ||
) | ||
); | ||
wrapper.getBenchmarkPrice(testFeedId, 100); | ||
} | ||
|
||
function testGetBenchmarkPrice() external view { | ||
assertEq(wrapper.getBenchmarkPrice(testFeedId, 100), 1000); | ||
} | ||
} |
Oops, something went wrong.