diff --git a/package.json b/package.json index d296299..9c7797d 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/script/01_Deploy.s.sol b/script/01_Deploy.s.sol index 80b66f5..6c61da2 100644 --- a/script/01_Deploy.s.sol +++ b/script/01_Deploy.s.sol @@ -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 { diff --git a/src/libraries/Constants.sol b/src/libraries/Constants.sol index 4e61c15..064ce5a 100644 --- a/src/libraries/Constants.sol +++ b/src/libraries/Constants.sol @@ -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% } diff --git a/test/unit/ReservoirPriceOracle.t.sol b/test/unit/ReservoirPriceOracle.t.sol index 0ab90b9..ffe7d2b 100644 --- a/test/unit/ReservoirPriceOracle.t.sol +++ b/test/unit/ReservoirPriceOracle.t.sol @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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), @@ -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; @@ -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; @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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; @@ -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; @@ -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);