Skip to content

Commit

Permalink
Merge branch 'dev' into postSetup
Browse files Browse the repository at this point in the history
  • Loading branch information
daopunk committed Jan 2, 2024
2 parents 1c8addb + 55a6640 commit 7448d77
Show file tree
Hide file tree
Showing 28 changed files with 3,963 additions and 174 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
name: test

on: workflow_dispatch
on: [push, workflow_dispatch]


concurrency:
group: ${{github.workflow}}-${{github.ref}}
cancel-in-progress: true

env:
FOUNDRY_PROFILE: ci
OP_MAINNET_RPC: ${{ secrets.OP_MAINNET_RPC }}
OP_GOERLI_RPC: ${{ secrets.OP_GOERLI_RPC }}
OP_MAINNET_DEPLOYER_PK: ${{ secrets.TEST_DEPLOYER_PK }}
OP_GOERLI_DEPLOYER_PK: ${{ secrets.TEST_DEPLOYER_PK }}
ARB_GOERLI_RPC: ${{ secrets.ARB_GOERLI_RPC }}
ARB_MAINNET_RPC: ${{ secrets.ARB_MAINNET_RPC }}

jobs:
check:
Expand Down
457 changes: 457 additions & 0 deletions broadcast/DeployOracles.s.sol/421614/run-1703718630.json

Large diffs are not rendered by default.

457 changes: 457 additions & 0 deletions broadcast/DeployOracles.s.sol/421614/run-1703718669.json

Large diffs are not rendered by default.

457 changes: 457 additions & 0 deletions broadcast/DeployOracles.s.sol/421614/run-latest.json

Large diffs are not rendered by default.

717 changes: 717 additions & 0 deletions broadcast/DeployPool.s.sol/421614/run-1703712392.json

Large diffs are not rendered by default.

717 changes: 717 additions & 0 deletions broadcast/DeployPool.s.sol/421614/run-1703712427.json

Large diffs are not rendered by default.

717 changes: 717 additions & 0 deletions broadcast/DeployPool.s.sol/421614/run-latest.json

Large diffs are not rendered by default.

57 changes: 52 additions & 5 deletions script/Common.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,71 @@ pragma solidity 0.7.6;

import '@script/Registry.s.sol';
import {Script} from 'forge-std/Script.sol';
import {Sqrt} from '@algebra-core/libraries/Sqrt.sol';
import {IERC20Metadata} from '@algebra-periphery/interfaces/IERC20Metadata.sol';
import {IAlgebraPool} from '@algebra-core/interfaces/IAlgebraPool.sol';
import {IAuthorizable} from '@interfaces/utils/IAuthorizable.sol';
import {RelayerFactory} from '@contracts/factories/RelayerFactory.sol';
import {CamelotRelayerFactory} from '@contracts/factories/CamelotRelayerFactory.sol';
import {ChainlinkRelayerFactory} from '@contracts/factories/ChainlinkRelayerFactory.sol';
import {DenominatedOracleFactory} from '@contracts/factories/DenominatedOracleFactory.sol';

abstract contract Common is Script {
RelayerFactory public camelotRelayerFactory = RelayerFactory(CAMELOT_RELAYER_FACTORY);
ChainlinkRelayerFactory public chainlinkRelayerFactory = ChainlinkRelayerFactory(CHAINLINK_RELAYER_FACTORY);
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(camelotRelayerFactory)), TEST_GOVERNOR, vm.envAddress('ARB_SEPOLIA_DEPLOYER_PC'));
_revoke(IAuthorizable(address(chainlinkRelayerFactory)), 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
function initialPrice(
uint256 _basePrice,
uint256 _quotePrice,
address _pool
) internal returns (uint160 _sqrtPriceX96) {
address _token0 = IAlgebraPool(_pool).token0();
bytes32 _symbol = keccak256(abi.encodePacked(IERC20Metadata(_token0).symbol()));
uint256 _price;

// price = token1 / token0
if (_token0 == SEPOLIA_SYSTEM_COIN) {
require(keccak256(abi.encodePacked('OD')) == _symbol, '!OD');
_price = ((_quotePrice * WAD) / _basePrice);
} else {
require(keccak256(abi.encodePacked('WETH')) == _symbol, '!WETH');
_price = ((_basePrice * WAD) / _quotePrice);
}

_sqrtPriceX96 = uint160(Sqrt.sqrtAbs(int256(_price)) * (2 ** 96));
}

/**
* note FOR TEST
*/
function authOnlyFactories() internal {
if (!chainlinkRelayerFactoryAuth.authorizedAccounts(admin)) {
chainlinkRelayerFactoryAuth.addAuthorization(admin);
}
if (!camelotRelayerFactoryAuth.authorizedAccounts(admin)) {
camelotRelayerFactoryAuth.addAuthorization(admin);
}
if (!denominatedOracleFactoryAuth.authorizedAccounts(admin)) {
denominatedOracleFactoryAuth.addAuthorization(admin);
}
}
}
7 changes: 5 additions & 2 deletions script/Registry.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ 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;

// Data for dexrelayer script (for test)
address constant RELAYER_DATA = 0x98A724ECA2804DE70Cae1f28E070D3973CAdcf05;
// Data for dexrelayer script (for test) and Router for AlgebraPool
address constant RELAYER_DATA = 0x91A35Ad2f71C25eB84A19eD27f12c362920b1DB2;
address constant ROUTER = 0x2a004eA6266eA1A340D1a7D78F1e0F4e9Ae2e685;

// Camelot Relayer
address constant CAMELOT_RELAYER_FACTORY = 0x9a8E0E6611EC9ebd5A2c8168A2f808e0206d85E4; // from pre-deployment
Expand Down
4 changes: 2 additions & 2 deletions script/dexrelayer/CallResult.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity 0.7.6;
import '@script/Registry.s.sol';
import {Script} from 'forge-std/Script.sol';
import {IAlgebraPool} from '@algebra-core/interfaces/IAlgebraPool.sol';
import {IRelayer} from '@interfaces/oracles/IRelayer.sol';
import {ICamelotRelayer} from '@interfaces/oracles/ICamelotRelayer.sol';
import {Data} from '@contracts/for-test/Data.sol';

// BROADCAST
Expand All @@ -16,7 +16,7 @@ import {Data} from '@contracts/for-test/Data.sol';
contract CallResult is Script {
Data public data = Data(RELAYER_DATA);

IRelayer public relayer = data.relayer();
ICamelotRelayer public relayer = data.camelotRelayer();

function run() public {
vm.startBroadcast(vm.envUint('ARB_SEPOLIA_PK'));
Expand Down
63 changes: 0 additions & 63 deletions script/dexrelayer/DeployOracle.s.sol

This file was deleted.

68 changes: 68 additions & 0 deletions script/dexrelayer/DeployOracles.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.7.6;

import '@script/Registry.s.sol';
import {Script} from 'forge-std/Script.sol';
import {ChainlinkRelayerFactory} from '@contracts/factories/ChainlinkRelayerFactory.sol';
import {CamelotRelayerFactory} from '@contracts/factories/CamelotRelayerFactory.sol';
import {DenominatedOracleFactory} from '@contracts/factories/DenominatedOracleFactory.sol';
import {ICamelotRelayer} from '@interfaces/oracles/ICamelotRelayer.sol';
import {IBaseOracle} from '@interfaces/oracles/IBaseOracle.sol';
import {MintableERC20} from '@contracts/for-test/MintableERC20.sol';
import {Data} from '@contracts/for-test/Data.sol';

// TODO test denominated oracle after relayer works
// import {DenominatedOracleFactory} from '@contracts/factories/DenominatedOracleFactory.sol';
// import {ChainlinkRelayerFactory, IChainlinkRelayerFactory} from '@contracts/factories/ChainlinkRelayerFactory.sol';

// BROADCAST
// source .env && forge script DeployOracles --with-gas-price 2000000000 -vvvvv --rpc-url $ARB_SEPOLIA_RPC --broadcast --verify --etherscan-api-key $ARB_ETHERSCAN_API_KEY

// SIMULATE
// source .env && forge script DeployOracles --with-gas-price 2000000000 -vvvvv --rpc-url $ARB_SEPOLIA_RPC

contract DeployOracles is Script {
Data public data = Data(RELAYER_DATA);

IBaseOracle public chainlinkEthUSDPriceFeed;
IBaseOracle public camelotRelayer;
IBaseOracle public denominatedOracle;

ChainlinkRelayerFactory public chainlinkRelayerFactory;
CamelotRelayerFactory public camelotRelayerFactory;
DenominatedOracleFactory public denominatedOracleFactory;

function run() public {
vm.startBroadcast(vm.envUint('ARB_SEPOLIA_PK'));

// deploy oracle factories
deployFactories();

// deploy chainlink relayer
chainlinkEthUSDPriceFeed =
chainlinkRelayerFactory.deployChainlinkRelayer(SEPOLIA_CHAINLINK_ETH_USD_FEED, ORACLE_INTERVAL_TEST);
data.setChainlinkRelayer(address(chainlinkEthUSDPriceFeed));

// deploy camelot relayer
camelotRelayer = camelotRelayerFactory.deployAlgebraRelayer(
SEPOLIA_ALGEBRA_FACTORY, data.tokenA(), data.tokenB(), uint32(ORACLE_INTERVAL_TEST)
);
data.setCamelotRelayer(address(camelotRelayer));

// deploy denominated oracle
denominatedOracle =
denominatedOracleFactory.deployDenominatedOracle(chainlinkEthUSDPriceFeed, camelotRelayer, false);
data.setDenominatedOracle(address(denominatedOracle));

vm.stopBroadcast();
}

/**
* @dev setup functions
*/
function deployFactories() public {
chainlinkRelayerFactory = new ChainlinkRelayerFactory();
camelotRelayerFactory = new CamelotRelayerFactory();
denominatedOracleFactory = new DenominatedOracleFactory();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,25 @@ pragma solidity 0.7.6;

import '@script/Registry.s.sol';
import {Script} from 'forge-std/Script.sol';
import {Sqrt} from '@algebra-core/libraries/Sqrt.sol';
import {IAlgebraFactory} from '@algebra-core/interfaces/IAlgebraFactory.sol';
import {IAlgebraPool} from '@algebra-core/interfaces/IAlgebraPool.sol';
import {RelayerFactory} from '@contracts/factories/RelayerFactory.sol';
import {IRelayer} from '@interfaces/oracles/IRelayer.sol';
import {CamelotRelayerFactory} from '@contracts/factories/CamelotRelayerFactory.sol';
import {ICamelotRelayer} from '@interfaces/oracles/ICamelotRelayer.sol';
import {IBaseOracle} from '@interfaces/oracles/IBaseOracle.sol';
import {MintableERC20} from '@contracts/for-test/MintableERC20.sol';
import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import {Router} from '@contracts/for-test/Router.sol';
import {Data} from '@contracts/for-test/Data.sol';

// BROADCAST
// source .env && forge script DeployBase --with-gas-price 2000000000 -vvvvv --rpc-url $ARB_SEPOLIA_RPC --broadcast --verify --etherscan-api-key $ARB_ETHERSCAN_API_KEY
// source .env && forge script DeployPool --with-gas-price 2000000000 -vvvvv --rpc-url $ARB_SEPOLIA_RPC --broadcast --verify --etherscan-api-key $ARB_ETHERSCAN_API_KEY

// SIMULATE
// source .env && forge script DeployBase --with-gas-price 2000000000 -vvvvv --rpc-url $ARB_SEPOLIA_RPC
// source .env && forge script DeployPool --with-gas-price 2000000000 -vvvvv --rpc-url $ARB_SEPOLIA_RPC

contract DeployBase is Script {
// Pool & Relayer Factories
contract DeployPool is Script {
// Pool Factory
IAlgebraFactory public algebraFactory = IAlgebraFactory(SEPOLIA_ALGEBRA_FACTORY);

// Router
Expand Down Expand Up @@ -68,22 +69,12 @@ contract DeployBase is Script {
function deployPool() public {
algebraFactory.createPool(data.tokenA(), data.tokenB());
data.setPool(IAlgebraPool(algebraFactory.poolByPair(data.tokenA(), data.tokenB())));
data.pool().initialize(getSqrtPrice(1 ether, 1656.62 ether));
data.pool().initialize(getSqrtPrice(1 ether, 2355 ether));
}

function getSqrtPrice(uint256 _initWethAmount, uint256 _initODAmount) public pure returns (uint160) {
uint256 price = (_initWethAmount * WAD) / _initODAmount;
uint256 sqrtPriceX96 = sqrt(price * WAD) * (2 ** 96);
uint256 sqrtPriceX96 = Sqrt.sqrtAbs(int256(price)) * (2 ** 96);
return uint160(sqrtPriceX96);
}

// TODO test against isomate sqrt function
function sqrt(uint256 x) public pure returns (uint256 y) {
uint256 z = (x + 1) / 2;
y = x;
while (z < y) {
y = z;
z = (x / z + z) / 2;
}
}
}
Loading

0 comments on commit 7448d77

Please sign in to comment.