Skip to content

Commit

Permalink
Merge branch 'dev' into price-read
Browse files Browse the repository at this point in the history
  • Loading branch information
daopunk authored Jan 2, 2024
2 parents 0235999 + 4410e68 commit dd7e754
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 17 deletions.
25 changes: 19 additions & 6 deletions script/Common.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,22 @@ abstract contract Common is Script {
CamelotRelayerFactory public camelotRelayerFactory = CamelotRelayerFactory(CAMELOT_RELAYER_FACTORY);
DenominatedOracleFactory public denominatedOracleFactory = DenominatedOracleFactory(DENOMINATED_ORACLE_FACTORY);

IAuthorizable public chainlinkRelayerFactoryAuth = IAuthorizable(CHAINLINK_RELAYER_FACTORY);
IAuthorizable public camelotRelayerFactoryAuth = IAuthorizable(CAMELOT_RELAYER_FACTORY);
IAuthorizable public denominatedOracleFactoryAuth = IAuthorizable(DENOMINATED_ORACLE_FACTORY);

address public deployer = vm.envAddress('ARB_SEPOLIA_DEPLOYER_PC');
address public admin = vm.envAddress('ARB_SEPOLIA_PC');

function _revoke(IAuthorizable _contract, address _authorize, address _deauthorize) internal {
_contract.addAuthorization(_authorize);
_contract.removeAuthorization(_deauthorize);
}

function revokeFactories() internal {
_revoke(IAuthorizable(address(chainlinkRelayerFactory)), TEST_GOVERNOR, vm.envAddress('ARB_SEPOLIA_DEPLOYER_PC'));
_revoke(IAuthorizable(address(camelotRelayerFactory)), TEST_GOVERNOR, vm.envAddress('ARB_SEPOLIA_DEPLOYER_PC'));
_revoke(IAuthorizable(address(denominatedOracleFactory)), TEST_GOVERNOR, vm.envAddress('ARB_SEPOLIA_DEPLOYER_PC'));
_revoke(chainlinkRelayerFactoryAuth, TEST_GOVERNOR, deployer);
_revoke(camelotRelayerFactoryAuth, TEST_GOVERNOR, deployer);
_revoke(denominatedOracleFactoryAuth, TEST_GOVERNOR, deployer);
}

// basePrice = OD, quotePrice = WETH
Expand Down Expand Up @@ -53,8 +60,14 @@ abstract contract Common is Script {
* note FOR TEST
*/
function authOnlyFactories() internal {
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'));
if (!chainlinkRelayerFactoryAuth.authorizedAccounts(admin)) {
chainlinkRelayerFactoryAuth.addAuthorization(admin);
}
if (!camelotRelayerFactoryAuth.authorizedAccounts(admin)) {
camelotRelayerFactoryAuth.addAuthorization(admin);
}
if (!denominatedOracleFactoryAuth.authorizedAccounts(admin)) {
denominatedOracleFactoryAuth.addAuthorization(admin);
}
}
}
2 changes: 2 additions & 0 deletions script/Registry.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ uint256 constant ORACLE_PERIOD = 1 seconds;
uint256 constant ORACLE_INTERVAL_TEST = 1 minutes;
uint256 constant WAD = 1e18;
uint256 constant MINT_AMOUNT = 1_000_000 ether;
uint256 constant INIT_WETH_AMOUNT = 1 ether;
uint256 constant INIT_OD_AMOUNT = 2230 ether;

// Members for governance
address constant H = 0x37c5B029f9c3691B3d47cb024f84E5E257aEb0BB;
Expand Down
50 changes: 39 additions & 11 deletions script/postdeployment/SetupPostEnvironment.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,12 @@ contract SetupPostEnvironment is Common {

function run() public {
vm.startBroadcast(vm.envUint('ARB_SEPOLIA_DEPLOYER_PK'));
MintableERC20 mockWeth = new MintableERC20('Wrapped ETH', 'WETH', 18);

// algebraFactory.createPool(SEPOLIA_SYSTEM_COIN, SEPOLIA_WETH);
// address _pool = algebraFactory.poolByPair(SEPOLIA_SYSTEM_COIN, SEPOLIA_WETH);
algebraFactory.createPool(SEPOLIA_SYSTEM_COIN, SEPOLIA_WETH);
address _pool = algebraFactory.poolByPair(SEPOLIA_SYSTEM_COIN, SEPOLIA_WETH);

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);

uint256 _initWethAmount = 1 ether;
uint256 _initODAmount = 2230 ether;

uint160 _sqrtPriceX96 = initialPrice(_initODAmount, _initWethAmount, _pool);
IAlgebraPool(_pool).initialize(uint160(_sqrtPriceX96));

// Todo: change to WETH for next deployment
Expand All @@ -45,8 +39,7 @@ contract SetupPostEnvironment is Common {
// deploy systemOracle
denominatedOracleFactory.deployDenominatedOracle(_odWethOracle, chainlinkEthUSDPriceFeed, false);

// revokeFactories(); // for mainnet
// authOnlyFactories(); // for testnet
revokeFactories();

/**
* note oracleRelayer will be set to systemOracle in odContracts post deploy script
Expand All @@ -56,3 +49,38 @@ contract SetupPostEnvironment is Common {
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

contract MockSetupPostEnvironment is Common {
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(uint160(_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();
}
}

0 comments on commit dd7e754

Please sign in to comment.