Skip to content

Commit

Permalink
Add 'OLD' price read test (#35)
Browse files Browse the repository at this point in the history
* separate mock script

* add OLD test

* add .env.example
  • Loading branch information
daopunk authored Feb 9, 2024
1 parent fcc19dc commit 5d64891
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 46 deletions.
16 changes: 16 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions script/Common.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions script/dexrelayer/DeployOracleFactories.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
47 changes: 47 additions & 0 deletions script/postdeployment/MockSetupPostEnv.s.sol
Original file line number Diff line number Diff line change
@@ -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();
}
}
37 changes: 0 additions & 37 deletions script/postdeployment/SetupPostEnvironment.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
11 changes: 7 additions & 4 deletions test/QMath.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit 5d64891

Please sign in to comment.