Skip to content

Commit

Permalink
Merge pull request #1 from open-dollar/add-gmx-oracle
Browse files Browse the repository at this point in the history
Add gmx oracle
  • Loading branch information
MrDeadCe11 authored Jul 23, 2024
2 parents 250811c + 940cfa2 commit 12a237f
Show file tree
Hide file tree
Showing 84 changed files with 1,525 additions and 1,417 deletions.
14 changes: 7 additions & 7 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "lib/AlgebraV1.9"]
path = lib/AlgebraV1.9
url = https://github.com/cryptoalgebra/AlgebraV1.9
path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "lib/gmx-synthetics"]
path = lib/gmx-synthetics
url = https://github.com/gmx-io/gmx-synthetics.git
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"solidity.compileUsingRemoteVersion": "v0.8.26+commit.8a97fa7a"
}
1 change: 0 additions & 1 deletion lib/AlgebraV1.9
Submodule AlgebraV1.9 deleted from 779b56
1 change: 1 addition & 0 deletions lib/gmx-synthetics
Submodule gmx-synthetics added at 5173cb
2 changes: 1 addition & 1 deletion lib/openzeppelin-contracts
6 changes: 1 addition & 5 deletions remappings.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
@openzeppelin/=lib/openzeppelin-contracts/
@isolmate/=lib/isolmate/src/
@cryptoalgebra/v1.9-core/contracts/=lib/AlgebraV1.9/src/core/contracts/

@algebra-core/=lib/AlgebraV1.9/src/core/contracts/
@algebra-periphery/=lib/AlgebraV1.9/src/periphery/contracts/
@algebra-tokenomics/=lib/AlgebraV1.9/src/tokenomics/contracts/
@gmx/=lib/gmx-synthetics/

@script/=script/
@contracts/=src/contracts/
Expand Down
50 changes: 19 additions & 31 deletions script/Common.s.sol
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.7.6;
pragma solidity 0.8.26;

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 {CamelotRelayerFactory} from '@contracts/factories/CamelotRelayerFactory.sol';
import {ChainlinkRelayerFactory} from '@contracts/factories/ChainlinkRelayerFactory.sol';
import {DenominatedOracleFactory} from '@contracts/factories/DenominatedOracleFactory.sol';
import {PendleRelayerFactory} from '@contracts/factories/pendle/PendleRelayerFactory.sol';
import {IDelayedOracleFactory} from '@interfaces/factories/IDelayedOracleFactory.sol';

abstract contract CommonMainnet is Script {
ChainlinkRelayerFactory public chainlinkRelayerFactory = ChainlinkRelayerFactory(MAINNET_CHAINLINK_RELAYER_FACTORY);
CamelotRelayerFactory public camelotRelayerFactory = CamelotRelayerFactory(MAINNET_CAMELOT_RELAYER_FACTORY);
DenominatedOracleFactory public denominatedOracleFactory =
DenominatedOracleFactory(MAINNET_DENOMINATED_ORACLE_FACTORY);
PendleRelayerFactory public pendleRelayerFactory = PendleRelayerFactory(MAINNET_PENDLE_RELAYER_FACTORY);
Expand All @@ -24,12 +19,10 @@ abstract contract CommonMainnet is Script {

abstract contract CommonSepolia is Script {
ChainlinkRelayerFactory public chainlinkRelayerFactory = ChainlinkRelayerFactory(SEPOLIA_CHAINLINK_RELAYER_FACTORY);
CamelotRelayerFactory public camelotRelayerFactory = CamelotRelayerFactory(SEPOLIA_CAMELOT_RELAYER_FACTORY);
DenominatedOracleFactory public denominatedOracleFactory =
DenominatedOracleFactory(SEPOLIA_DENOMINATED_ORACLE_FACTORY);

IAuthorizable public chainlinkRelayerFactoryAuth = IAuthorizable(SEPOLIA_CHAINLINK_RELAYER_FACTORY);
IAuthorizable public camelotRelayerFactoryAuth = IAuthorizable(SEPOLIA_CAMELOT_RELAYER_FACTORY);
IAuthorizable public denominatedOracleFactoryAuth = IAuthorizable(SEPOLIA_DENOMINATED_ORACLE_FACTORY);

address public deployer = vm.envAddress('ARB_SEPOLIA_DEPLOYER_ADDR');
Expand All @@ -42,32 +35,30 @@ abstract contract CommonSepolia is Script {

function revokeFactories() internal {
_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 view returns (uint160 _sqrtPriceX96) {
address _token0 = IAlgebraPool(_pool).token0();
bytes32 _symbol = keccak256(abi.encodePacked(IERC20Metadata(_token0).symbol()));
uint256 _price;
// function initialPrice(
// uint256 _basePrice,
// uint256 _quotePrice,
// address _pool
// ) internal view returns (uint160 _sqrtPriceX96) {
// 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);
}
// // 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);
// }

// check math @ https://uniswap-v3-calculator.netlify.app/
_sqrtPriceX96 = uint160(Sqrt.sqrtAbs(int256(_price)) * (2 ** 96)) / 1e9;
}
// // check math @ https://uniswap-v3-calculator.netlify.app/
// _sqrtPriceX96 = uint160(Sqrt.sqrtAbs(int256(_price)) * (2 ** 96)) / 1e9;
// }

/**
* note FOR TEST
Expand All @@ -76,9 +67,6 @@ abstract contract CommonSepolia is Script {
if (!chainlinkRelayerFactoryAuth.authorizedAccounts(admin)) {
chainlinkRelayerFactoryAuth.addAuthorization(admin);
}
if (!camelotRelayerFactoryAuth.authorizedAccounts(admin)) {
camelotRelayerFactoryAuth.addAuthorization(admin);
}
if (!denominatedOracleFactoryAuth.authorizedAccounts(admin)) {
denominatedOracleFactoryAuth.addAuthorization(admin);
}
Expand Down
12 changes: 5 additions & 7 deletions script/DeployOracle.s.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.7.6;
pragma solidity 0.8.26;

import '@script/Registry.s.sol';
import {Script} from 'forge-std/Script.sol';
import {CommonMainnet} from '@script/Common.s.sol';
import 'forge-std/console2.sol';

import {CamelotRelayerFactory} from '@contracts/factories/CamelotRelayerFactory.sol';
import {ChainlinkRelayerFactory} from '@contracts/factories/ChainlinkRelayerFactory.sol';
import {DenominatedOracleFactory} from '@contracts/factories/DenominatedOracleFactory.sol';
import {IBaseOracle} from '@interfaces/oracles/IBaseOracle.sol';
Expand Down Expand Up @@ -88,10 +86,10 @@ contract DeployRethPtToSyPendleRelayerMainnet is CommonMainnet {
_pendleRethPtToSyFeed, IBaseOracle(MAINNET_DENOMINATED_RETH_USD_ORACLE), false
);

IBaseOracle __rethToUSDOracleDelayedOracle =
delayedOracleFactory.deployDelayedOracle(_wstethyToUSDOracle, MAINNET_ORACLE_DELAY);
IBaseOracle _rethToUSDOracleDelayedOracle =
delayedOracleFactory.deployDelayedOracle(_rethToUSDOracle, MAINNET_ORACLE_DELAY);

__rethToUSDOracleDelayedOracle.symbol();
_rethToUSDOracleDelayedOracle.symbol();
vm.stopBroadcast();
}
}
Expand All @@ -110,7 +108,7 @@ contract DeployWstethPtToSyPendleRelayerMainnet is CommonMainnet {
);

IBaseOracle _wstethToUSDOracle = denominatedOracleFactory.deployDenominatedOracle(
_pendleRethPtToSyFeed, IBaseOracle(MAINNET_DENOMINATED_WSTETH_USD_ORACLE), false
_pendleWstethPtToSyFeed, IBaseOracle(MAINNET_DENOMINATED_WSTETH_USD_ORACLE), false
);

IBaseOracle _wstethToUSDDelayedOracle =
Expand Down
28 changes: 12 additions & 16 deletions script/Registry.s.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.7.6;
pragma solidity 0.8.26;

uint256 constant WAD = 1e18;

Expand Down Expand Up @@ -44,27 +44,12 @@ address constant SEPOLIA_SYSTEM_ORACLE = address(0); // post setup
address constant SEPOLIA_CHAINLINK_ETH_USD_FEED = 0xd30e2101a97dcbAeBCBC04F14C3f624E67A35165;
address constant SEPOLIA_CHAINLINK_ARB_USD_FEED = 0xD1092a65338d049DB68D7Be6bD89d17a0929945e;

// Algebra protocol (deployed by daopunk - not official camelot contracts)
address constant SEPOLIA_ALGEBRA_FACTORY = 0x21852176141b8D139EC5D3A1041cdC31F0F20b94;
address constant SEPOLIA_ALGEBRA_POOL_DEPLOYER = 0xca5C849a6ce036cdF83e8F87dCa71Dc2B309E59b;
address constant SEPOLIA_ALGEBRA_QUOTER = 0xf7E25be14E5F5e36d5c2FE7a7822A601d18CD120;
address constant SEPOLIA_ALGEBRA_SWAPROUTER = 0xD18583a01837c9Dc4dC02E2202955E9d71C08771;
address constant SEPOLIA_ALGEBRA_NFT_DESCRIPTOR = 0x88Fa9f46645C7c638fFA9675b36DfdeF2cbae296;
address constant SEPOLIA_ALGEBRA_PROXY = 0xDAed3376f8112570a9E319A1D425C9B37CA901B3;
address constant SEPOLIA_ALGEBRA_NFT_MANAGER = 0xAf588D87BaDE8654F26686D5502be8ceDbE8FFe0;
address constant SEPOLIA_ALGEBRA_INTERFACE_MULTICALL = 0xf94b8a5D6dBd8F4026Ae467fdDB96028F74b9B96;
address constant SEPOLIA_ALGEBRA_V3_MIGRATOR = 0x766682889b8A6070be210C2a821Ad671E3388ab3;
address constant SEPOLIA_ALGEBRA_LIMIT_FARMING = 0x62B46a9565C7ECEc4FE7Dd309174ac3B03AF44E2;
address constant SEPOLIA_ALGEBRA_ETERNAL_FARMING = 0xD8474356C6976E18275735531b22f3Aa872a8b3B;
address constant SEPOLIA_ALGEBRA_FARM_CENTER = 0x04e4A5A4E4D2A5a0fb48ECde0bbD5554652D254b;

// -- Mainnet --

////////// FACTORIES //////////
address constant MAINNET_CAMELOT_RELAYER_FACTORY = 0x36645830479170265A154Acb726780fdaE41A28F;
address constant MAINNET_CHAINLINK_RELAYER_FACTORY = 0x06C32500489C28Bd57c551afd8311Fef20bFaBB5;
address constant MAINNET_DENOMINATED_ORACLE_FACTORY = 0xBF760b23d2ef3615cec549F22b95a34DB0F8f5CD;
address constant MAINNET_ALGEBRA_FACTORY = 0x1a3c9B1d2F0529D97f2afC5136Cc23e58f1FD35B;
address constant MAINNET_DELAYED_ORACLE_FACTORY = 0x9Dd63fA54dEfd8820BCAb3e3cC39aeEc1aE88098;

////////// RELAYERS //////////
Expand All @@ -90,6 +75,7 @@ address constant MAINNET_DELAYED_ETH_USD_ORACLE = 0x562CCE2F4dc383862dC6A926AF10
// Price feeds to USD
address constant MAINNET_CHAINLINK_ETH_USD_FEED = 0x639Fe6ab55C921f74e7fac1ee960C0B6293ba612;
address constant MAINNET_CHAINLINK_ARB_USD_FEED = 0xb2A824043730FE05F3DA2efaFa1CBbe83fa548D6;
address constant MAINNET_CHAINLINK_USDC_USD_FEED = 0x50834F3163758fcC1Df9973b6e91f0F0F0434aD3;
// Price feeds to ETH
address constant MAINNET_CHAINLINK_RETH_ETH_FEED = 0xD6aB2298946840262FcC278fF31516D39fF611eF;
address constant MAINNET_CHAINLINK_WSTETH_ETH_FEED = 0xb523AE262D20A936BC152e6023996e46FDC2A95D;
Expand Down Expand Up @@ -118,4 +104,14 @@ uint32 constant MAINNET_PENDLE_TWAP_DURATION = 900;
address constant MAINNET_PENDLE_ORACLE = 0x9a9Fa8338dd5E5B2188006f1Cd2Ef26d921650C2;
address constant MAINNET_PENDLE_RETH_MARKET = 0x14FbC760eFaF36781cB0eb3Cb255aD976117B9Bd;
address constant MAINNET_PENDLE_WSTETH_MARKET = 0x08a152834de126d2ef83D612ff36e4523FD0017F;
address constant MAINNET_PENDLE_RELAYER_FACTORY = 0x0000000000000000000000000000000000000000;

//GMX
address constant MAINNET_GMX_DATA_STORE = 0xFD70de6b91282D8017aA4E741e9Ae325CAb992d8;
address constant MAINNET_GMX_READER = 0x5Ca84c34a381434786738735265b9f3FD814b824;

// GM WETH PERP MARKET
address constant MAINNET_GMX_WETH_PERP_MARKET_TOKEN = 0x70d95587d40A2caf56bd97485aB3Eec10Bee6336;
address constant MAINNET_GMX_WETH_PERP_INDEX_TOKEN = 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1; //WETH
address constant MAINNET_GMX_WETH_PERP_LONG_TOKEN = 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1; //WETH
address constant MAINNET_GMX_WETH_PERP_shortToken = 0xaf88d065e77c8cC2239327C5EDb3A432268e5831; //usdc
65 changes: 0 additions & 65 deletions script/dexrelayer/CallResult.s.sol

This file was deleted.

2 changes: 1 addition & 1 deletion script/dexrelayer/DeployDataLog.s.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.7.6;
pragma solidity 0.8.26;
pragma abicoder v2;

import '@script/Registry.s.sol';
Expand Down
10 changes: 1 addition & 9 deletions script/dexrelayer/DeployOracleFactories.s.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.7.6;
pragma solidity 0.8.26;

import '@script/Registry.s.sol';
import {Script} from 'forge-std/Script.sol';
import {CamelotRelayerFactory} from '@contracts/factories/CamelotRelayerFactory.sol';
import {ChainlinkRelayerFactory} from '@contracts/factories/ChainlinkRelayerFactory.sol';
import {DenominatedOracleFactory} from '@contracts/factories/DenominatedOracleFactory.sol';
import {IAuthorizable} from '@interfaces/utils/IAuthorizable.sol';
Expand All @@ -19,7 +18,6 @@ contract MockDeployFactories is Script {
Data public data = Data(RELAYER_DATA);

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

/**
Expand All @@ -28,15 +26,9 @@ contract MockDeployFactories is Script {
function run() public {
vm.startBroadcast(vm.envUint('ARB_SEPOLIA_DEPLOYER_PK'));
chainlinkRelayerFactory = new ChainlinkRelayerFactory();
camelotRelayerFactory = new CamelotRelayerFactory();
denominatedOracleFactory = new DenominatedOracleFactory();

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));
data.modifyFactory(bytes32('denominatedOracleFactory'), address(denominatedOracleFactory));
vm.stopBroadcast();
}
Expand Down
Loading

0 comments on commit 12a237f

Please sign in to comment.