Skip to content

Commit

Permalink
chore: use constants file
Browse files Browse the repository at this point in the history
  • Loading branch information
xenide committed Sep 20, 2024
1 parent ffae6c5 commit 03aef63
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"ci": "forge build --force && npm run lint:check && npm run test:unit && npm run gas:check && npm run slither:check",
"clean": "forge clean",
"coverage": "export FOUNDRY_PROFILE=coverage && forge coverage --report lcov",
"deploy:testnet": "forge script script/Deploy.s.sol --target-contract Deploy --sig \"run()\" --fork-url \"https://1rpc.io/sepolia\" --broadcast -vvvv",
"deploy:testnet": "forge script script/01_Deploy.s.sol --target-contract Deploy --sig \"run()\" --fork-url \"https://1rpc.io/sepolia\" --sender 0x85073D34FB2e76c838D23CcEe105be5e66E26303 --interactives 1 --broadcast -vvvv",
"eslint": "npm run eslint:check",
"eslint:check": "eslint scripts",
"eslint:fix": "eslint scripts --fix",
Expand Down
2 changes: 1 addition & 1 deletion script/01_Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.0;

import { Script } from "forge-std/Script.sol";
import { ReservoirPriceOracle, PriceType } from "src/ReservoirPriceOracle.sol";
import { ReservoirPriceOracle, PriceType, Constants } from "src/ReservoirPriceOracle.sol";

contract Deploy is Script {
function run() external {
Expand Down
6 changes: 3 additions & 3 deletions src/libraries/Constants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ library Constants {
uint16 public constant BP_SCALE = 1e4;

// Defaults
uint256 public constant DEFAULT_TWAP_PERIOD = 15 minutes;
uint256 public constant DEFAULT_DEVIATION_THRESHOLD_VOLATILE = 200; // 2%
uint256 public constant DEFAULT_DEVIATION_THRESHOLD_STABLE = 2; // 0.02%
uint64 public constant DEFAULT_TWAP_PERIOD = 15 minutes;
uint16 public constant DEFAULT_DEVIATION_THRESHOLD_VOLATILE = 200; // 2%
uint16 public constant DEFAULT_DEVIATION_THRESHOLD_STABLE = 2; // 0.02%
}
32 changes: 16 additions & 16 deletions test/unit/ReservoirPriceOracle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ contract ReservoirPriceOracleTest is BaseTest {
uint16[] memory lRewardThreshold = new uint16[](1);
lRoute[0] = address(_tokenA);
lRoute[1] = address(_tokenB);
lRewardThreshold[0] = 200; // 2%
lRewardThreshold[0] = Constants.DEFAULT_DEVIATION_THRESHOLD_VOLATILE;

_oracle.designatePair(address(_tokenB), address(_tokenA), _pair);
_oracle.setRoute(address(_tokenA), address(_tokenB), lRoute, lRewardThreshold);
Expand Down Expand Up @@ -151,7 +151,7 @@ contract ReservoirPriceOracleTest is BaseTest {

address[] memory lRoute = new address[](4);
uint16[] memory lRewardThreshold = new uint16[](3);
lRewardThreshold[0] = lRewardThreshold[1] = lRewardThreshold[2] = Constants.BP_SCALE;
lRewardThreshold[0] = lRewardThreshold[1] = lRewardThreshold[2] = Constants.DEFAULT_DEVIATION_THRESHOLD_VOLATILE;

lRoute[0] = address(_tokenA);
lRoute[1] = address(_tokenB);
Expand Down Expand Up @@ -181,7 +181,7 @@ contract ReservoirPriceOracleTest is BaseTest {

address[] memory lRoute = new address[](4);
uint16[] memory lRewardThreshold = new uint16[](3);
lRewardThreshold[0] = lRewardThreshold[1] = lRewardThreshold[2] = Constants.BP_SCALE;
lRewardThreshold[0] = lRewardThreshold[1] = lRewardThreshold[2] = Constants.DEFAULT_DEVIATION_THRESHOLD_VOLATILE;
lRoute[0] = address(_tokenA);
lRoute[1] = address(_tokenB);
lRoute[2] = address(_tokenC);
Expand Down Expand Up @@ -224,7 +224,7 @@ contract ReservoirPriceOracleTest is BaseTest {

{
uint16[] memory lRewardThreshold = new uint16[](2);
lRewardThreshold[0] = lRewardThreshold[1] = Constants.BP_SCALE;
lRewardThreshold[0] = lRewardThreshold[1] = Constants.DEFAULT_DEVIATION_THRESHOLD_VOLATILE;
_oracle.setRoute(address(lTokenA), address(lTokenC), lRoute, lRewardThreshold);
_writePriceCache(address(lTokenA), address(lTokenB), 1e18);
_writePriceCache(address(lTokenC), address(lTokenB), 1e18);
Expand Down Expand Up @@ -268,7 +268,7 @@ contract ReservoirPriceOracleTest is BaseTest {

address[] memory lRoute = new address[](2);
uint16[] memory lRewardThreshold = new uint16[](1);
lRewardThreshold[0] = Constants.BP_SCALE;
lRewardThreshold[0] = Constants.DEFAULT_DEVIATION_THRESHOLD_VOLATILE;
(lRoute[0], lRoute[1]) =
lTokenA < lTokenB ? (address(lTokenA), address(lTokenB)) : (address(lTokenB), address(lTokenA));
_oracle.setRoute(lRoute[0], lRoute[1], lRoute, lRewardThreshold);
Expand Down Expand Up @@ -330,7 +330,7 @@ contract ReservoirPriceOracleTest is BaseTest {
lRoute[1] = address(lTokenB);

uint16[] memory lRewardThreshold = new uint16[](2);
lRewardThreshold[0] = lRewardThreshold[1] = Constants.BP_SCALE;
lRewardThreshold[0] = lRewardThreshold[1] = Constants.DEFAULT_DEVIATION_THRESHOLD_VOLATILE;
_oracle.setRoute(lRoute[0], lRoute[2], lRoute, lRewardThreshold);
_writePriceCache(
address(lTokenA) < address(lTokenB) ? address(lTokenA) : address(lTokenB),
Expand Down Expand Up @@ -640,7 +640,7 @@ contract ReservoirPriceOracleTest is BaseTest {
address lEnd = address(_tokenB);
address[] memory lRoute = new address[](4);
uint16[] memory lRewardThreshold = new uint16[](3);
lRewardThreshold[0] = lRewardThreshold[1] = lRewardThreshold[2] = 3; // 3bp
lRewardThreshold[0] = lRewardThreshold[1] = lRewardThreshold[2] = Constants.DEFAULT_DEVIATION_THRESHOLD_STABLE;
lRoute[0] = lStart;
lRoute[1] = lIntermediate1;
lRoute[2] = lIntermediate2;
Expand Down Expand Up @@ -714,7 +714,7 @@ contract ReservoirPriceOracleTest is BaseTest {
address lToken1 = address(_tokenC);
address[] memory lRoute = new address[](2);
uint16[] memory lRewardThreshold = new uint16[](1);
lRewardThreshold[0] = Constants.BP_SCALE;
lRewardThreshold[0] = Constants.DEFAULT_DEVIATION_THRESHOLD_VOLATILE;
lRoute[0] = lToken0;
lRoute[1] = lToken1;

Expand All @@ -738,7 +738,7 @@ contract ReservoirPriceOracleTest is BaseTest {
address lToken1 = address(_tokenC);
address[] memory lRoute = new address[](4);
uint16[] memory lRewardThreshold = new uint16[](3);
lRewardThreshold[0] = lRewardThreshold[1] = lRewardThreshold[2] = Constants.BP_SCALE;
lRewardThreshold[0] = lRewardThreshold[1] = lRewardThreshold[2] = Constants.DEFAULT_DEVIATION_THRESHOLD_VOLATILE;
lRoute[0] = lToken0;
lRoute[1] = address(_tokenA);
lRoute[2] = address(_tokenD);
Expand Down Expand Up @@ -779,7 +779,7 @@ contract ReservoirPriceOracleTest is BaseTest {
lIntermediateRoute3[1] = lEnd;

uint16[] memory lRewardThreshold = new uint16[](3);
lRewardThreshold[0] = lRewardThreshold[1] = lRewardThreshold[2] = Constants.BP_SCALE;
lRewardThreshold[0] = lRewardThreshold[1] = lRewardThreshold[2] = Constants.DEFAULT_DEVIATION_THRESHOLD_VOLATILE;

// act
vm.expectEmit(false, false, false, true);
Expand Down Expand Up @@ -807,7 +807,7 @@ contract ReservoirPriceOracleTest is BaseTest {
address lToken1 = address(_tokenC);
address[] memory lRoute = new address[](2);
uint16[] memory lRewardThreshold = new uint16[](1);
lRewardThreshold[0] = Constants.BP_SCALE;
lRewardThreshold[0] = Constants.DEFAULT_DEVIATION_THRESHOLD_VOLATILE;
lRoute[0] = lToken0;
lRoute[1] = lToken1;
_oracle.setRoute(lToken0, lToken1, lRoute, lRewardThreshold);
Expand All @@ -831,7 +831,7 @@ contract ReservoirPriceOracleTest is BaseTest {
// arrange
address[] memory lRoute = new address[](4);
uint16[] memory lRewardThreshold = new uint16[](3);
lRewardThreshold[0] = lRewardThreshold[1] = lRewardThreshold[2] = Constants.BP_SCALE;
lRewardThreshold[0] = lRewardThreshold[1] = lRewardThreshold[2] = Constants.DEFAULT_DEVIATION_THRESHOLD_VOLATILE;
lRoute[0] = address(_tokenA);
lRoute[1] = address(_tokenC);
lRoute[2] = address(_tokenB);
Expand Down Expand Up @@ -958,7 +958,7 @@ contract ReservoirPriceOracleTest is BaseTest {

address[] memory lRoute = new address[](2);
uint16[] memory lRewardThreshold = new uint16[](1);
lRewardThreshold[0] = Constants.BP_SCALE;
lRewardThreshold[0] = Constants.DEFAULT_DEVIATION_THRESHOLD_VOLATILE;
lRoute[0] = address(_tokenB);
lRoute[1] = address(_tokenC);

Expand All @@ -981,7 +981,7 @@ contract ReservoirPriceOracleTest is BaseTest {
address lToken1 = address(0x1);
address[] memory lRoute = new address[](2);
uint16[] memory lRewardThreshold = new uint16[](1);
lRewardThreshold[0] = Constants.BP_SCALE;
lRewardThreshold[0] = Constants.DEFAULT_DEVIATION_THRESHOLD_VOLATILE;
lRoute[0] = lToken0;
lRoute[1] = lToken1;

Expand All @@ -996,7 +996,7 @@ contract ReservoirPriceOracleTest is BaseTest {
address lToken1 = address(0x2);
address[] memory lRoute = new address[](2);
uint16[] memory lRewardThreshold = new uint16[](1);
lRewardThreshold[0] = Constants.BP_SCALE;
lRewardThreshold[0] = Constants.DEFAULT_DEVIATION_THRESHOLD_VOLATILE;
lRoute[0] = lToken0;
lRoute[1] = lToken1;

Expand Down Expand Up @@ -1044,7 +1044,7 @@ contract ReservoirPriceOracleTest is BaseTest {
lInvalidRoute2[2] = lToken1;

uint16[] memory lRewardThreshold = new uint16[](2);
lRewardThreshold[0] = lRewardThreshold[1] = Constants.BP_SCALE;
lRewardThreshold[0] = lRewardThreshold[1] = Constants.DEFAULT_DEVIATION_THRESHOLD_VOLATILE;

// act & assert
vm.expectRevert(OracleErrors.InvalidRoute.selector);
Expand Down

0 comments on commit 03aef63

Please sign in to comment.