diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..4632c43 --- /dev/null +++ b/.env.example @@ -0,0 +1,16 @@ +ARB_ETHERSCAN_API_KEY= + +# SEPOLIA +ARB_SEPOLIA_RPC= + +ARB_SEPOLIA_DEPLOYER_ADDR=0x +ARB_SEPOLIA_DEPLOYER_PK=0x + +ARB_SEPOLIA_ADDR=0x +ARB_SEPOLIA_PK=0x + +# MAINNET +ARB_MAINNET_RPC= + +ARB_MAINNET_DEPLOYER_PK=0x +ARB_MAINNET_ADMIN_PK=0x diff --git a/script/Common.s.sol b/script/Common.s.sol index c86339b..d4cb815 100644 --- a/script/Common.s.sol +++ b/script/Common.s.sol @@ -28,8 +28,8 @@ abstract contract CommonSepolia is Script { IAuthorizable public camelotRelayerFactoryAuth = IAuthorizable(SEPOLIA_CAMELOT_RELAYER_FACTORY); IAuthorizable public denominatedOracleFactoryAuth = IAuthorizable(SEPOLIA_DENOMINATED_ORACLE_FACTORY); - address public deployer = vm.envAddress('ARB_SEPOLIA_DEPLOYER_PC'); - address public admin = vm.envAddress('ARB_SEPOLIA_PC'); + address public deployer = vm.envAddress('ARB_SEPOLIA_DEPLOYER_ADDR'); + address public admin = vm.envAddress('ARB_SEPOLIA_ADDR'); function _revoke(IAuthorizable _contract, address _authorize, address _deauthorize) internal { _contract.addAuthorization(_authorize); diff --git a/script/dexrelayer/DeployOracleFactories.s.sol b/script/dexrelayer/DeployOracleFactories.s.sol index 610a19b..df647eb 100644 --- a/script/dexrelayer/DeployOracleFactories.s.sol +++ b/script/dexrelayer/DeployOracleFactories.s.sol @@ -31,9 +31,9 @@ contract MockDeployFactories is Script { camelotRelayerFactory = new CamelotRelayerFactory(); denominatedOracleFactory = new DenominatedOracleFactory(); - IAuthorizable(address(chainlinkRelayerFactory)).addAuthorization(vm.envAddress('ARB_SEPOLIA_PC')); - IAuthorizable(address(camelotRelayerFactory)).addAuthorization(vm.envAddress('ARB_SEPOLIA_PC')); - IAuthorizable(address(denominatedOracleFactory)).addAuthorization(vm.envAddress('ARB_SEPOLIA_PC')); + IAuthorizable(address(chainlinkRelayerFactory)).addAuthorization(vm.envAddress('ARB_SEPOLIA_ADDR')); + IAuthorizable(address(camelotRelayerFactory)).addAuthorization(vm.envAddress('ARB_SEPOLIA_ADDR')); + IAuthorizable(address(denominatedOracleFactory)).addAuthorization(vm.envAddress('ARB_SEPOLIA_ADDR')); data.modifyFactory(bytes32('chainlinkRelayerFactory'), address(chainlinkRelayerFactory)); data.modifyFactory(bytes32('camelotRelayerFactory'), address(camelotRelayerFactory)); diff --git a/script/postdeployment/MockSetupPostEnv.s.sol b/script/postdeployment/MockSetupPostEnv.s.sol new file mode 100644 index 0000000..f8cb988 --- /dev/null +++ b/script/postdeployment/MockSetupPostEnv.s.sol @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity 0.7.6; + +import 'forge-std/console2.sol'; +import '@script/Registry.s.sol'; +import {CommonSepolia} from '@script/Common.s.sol'; +import {IAlgebraFactory} from '@algebra-core/interfaces/IAlgebraFactory.sol'; +import {IAlgebraPool} from '@algebra-core/interfaces/IAlgebraPool.sol'; +import {IBaseOracle} from '@interfaces/oracles/IBaseOracle.sol'; +import {MintableERC20} from '@contracts/for-test/MintableERC20.sol'; + +// BROADCAST +// source .env && forge script MockSetupPostEnvironment --with-gas-price 2000000000 -vvvvv --rpc-url $ARB_SEPOLIA_RPC --broadcast --verify --etherscan-api-key $ARB_ETHERSCAN_API_KEY + +// SIMULATE +// source .env && forge script MockSetupPostEnvironment --with-gas-price 2000000000 -vvvvv --rpc-url $ARB_SEPOLIA_RPC + +// ToDo: add liquidity + +contract MockSetupPostEnvironment is CommonSepolia { + IAlgebraFactory public algebraFactory = IAlgebraFactory(SEPOLIA_ALGEBRA_FACTORY); + + function run() public { + vm.startBroadcast(vm.envUint('ARB_SEPOLIA_DEPLOYER_PK')); + MintableERC20 mockWeth = new MintableERC20('Wrapped ETH', 'WETH', 18); + + algebraFactory.createPool(SEPOLIA_SYSTEM_COIN, address(mockWeth)); + address _pool = algebraFactory.poolByPair(SEPOLIA_SYSTEM_COIN, address(mockWeth)); + + uint160 _sqrtPriceX96 = initialPrice(INIT_OD_AMOUNT, INIT_WETH_AMOUNT, _pool); + IAlgebraPool(_pool).initialize(_sqrtPriceX96); + + IBaseOracle _odWethOracle = camelotRelayerFactory.deployAlgebraRelayer( + SEPOLIA_ALGEBRA_FACTORY, SEPOLIA_SYSTEM_COIN, address(mockWeth), uint32(ORACLE_INTERVAL_TEST) + ); + + IBaseOracle chainlinkEthUSDPriceFeed = + chainlinkRelayerFactory.deployChainlinkRelayer(SEPOLIA_CHAINLINK_ETH_USD_FEED, ORACLE_INTERVAL_TEST); + + // deploy systemOracle + denominatedOracleFactory.deployDenominatedOracle(_odWethOracle, chainlinkEthUSDPriceFeed, false); + + authOnlyFactories(); + + vm.stopBroadcast(); + } +} diff --git a/script/postdeployment/SetupPostEnvironment.s.sol b/script/postdeployment/SetupPostEnvironment.s.sol index dd07aeb..b83d2ec 100644 --- a/script/postdeployment/SetupPostEnvironment.s.sol +++ b/script/postdeployment/SetupPostEnvironment.s.sol @@ -47,40 +47,3 @@ contract SetupPostEnvironment is CommonSepolia { vm.stopBroadcast(); } } - -// BROADCAST -// source .env && forge script MockSetupPostEnvironment --with-gas-price 2000000000 -vvvvv --rpc-url $ARB_SEPOLIA_RPC --broadcast --verify --etherscan-api-key $ARB_ETHERSCAN_API_KEY - -// SIMULATE -// source .env && forge script MockSetupPostEnvironment --with-gas-price 2000000000 -vvvvv --rpc-url $ARB_SEPOLIA_RPC - -// ToDo: add liquidity - -contract MockSetupPostEnvironment is CommonSepolia { - IAlgebraFactory public algebraFactory = IAlgebraFactory(SEPOLIA_ALGEBRA_FACTORY); - - function run() public { - vm.startBroadcast(vm.envUint('ARB_SEPOLIA_DEPLOYER_PK')); - MintableERC20 mockWeth = new MintableERC20('Wrapped ETH', 'WETH', 18); - - algebraFactory.createPool(SEPOLIA_SYSTEM_COIN, address(mockWeth)); - address _pool = algebraFactory.poolByPair(SEPOLIA_SYSTEM_COIN, address(mockWeth)); - - uint160 _sqrtPriceX96 = initialPrice(INIT_OD_AMOUNT, INIT_WETH_AMOUNT, _pool); - IAlgebraPool(_pool).initialize(_sqrtPriceX96); - - IBaseOracle _odWethOracle = camelotRelayerFactory.deployAlgebraRelayer( - SEPOLIA_ALGEBRA_FACTORY, SEPOLIA_SYSTEM_COIN, address(mockWeth), uint32(ORACLE_INTERVAL_TEST) - ); - - IBaseOracle chainlinkEthUSDPriceFeed = - chainlinkRelayerFactory.deployChainlinkRelayer(SEPOLIA_CHAINLINK_ETH_USD_FEED, ORACLE_INTERVAL_TEST); - - // deploy systemOracle - denominatedOracleFactory.deployDenominatedOracle(_odWethOracle, chainlinkEthUSDPriceFeed, false); - - authOnlyFactories(); - - vm.stopBroadcast(); - } -} diff --git a/test/QMath.t.sol b/test/QMath.t.sol index b0e7354..f2f954b 100644 --- a/test/QMath.t.sol +++ b/test/QMath.t.sol @@ -97,13 +97,16 @@ contract QMath is Test { assertApproxEqAbs(INIT_OD_AMOUNT / 1e18, _result / 1e18, 500); // $500 flux } - // needs to be predeployed function testCamelotRelayerPrice() public { + vm.warp(block.timestamp + 1 minutes + 1 seconds); uint256 _result = camelotOdWethOracle.read(); - emit log_named_uint('Camelot OD/WETH', _result); // / 1e18 = + emit log_named_uint('Camelot OD/WETH', _result); - assertApproxEqAbs(initPrice, _result, 100_000_000); // 0.000000000100000000 variability + assertEq(INIT_OD_AMOUNT / 1e18, _result); } - // function testDenominatedOraclePrice() public {} + function testOldCamelotRelayerPrice() public { + vm.expectRevert(bytes('OLD')); + camelotOdWethOracle.read(); + } }