Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
daopunk committed Jan 3, 2024
1 parent 174c06b commit b1b539d
Show file tree
Hide file tree
Showing 19 changed files with 4,242 additions and 582 deletions.
277 changes: 277 additions & 0 deletions broadcast/DeployFactories.s.sol/421614/run-1704309785.json

Large diffs are not rendered by default.

277 changes: 277 additions & 0 deletions broadcast/DeployFactories.s.sol/421614/run-1704309787.json

Large diffs are not rendered by default.

433 changes: 433 additions & 0 deletions broadcast/DeployFactories.s.sol/421614/run-1704310254.json

Large diffs are not rendered by default.

433 changes: 433 additions & 0 deletions broadcast/DeployFactories.s.sol/421614/run-1704310255.json

Large diffs are not rendered by default.

379 changes: 326 additions & 53 deletions broadcast/DeployFactories.s.sol/421614/run-latest.json

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

380 changes: 114 additions & 266 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-1704309671.json

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion script/Registry.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ uint256 constant INIT_OD_AMOUNT = 2230 ether;
address constant H = 0x37c5B029f9c3691B3d47cb024f84E5E257aEb0BB;

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

// Camelot Relayer
Expand Down
34 changes: 14 additions & 20 deletions script/dexrelayer/DeployOracles.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ 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 {ICamelotRelayerFactory} from '@interfaces/factories/ICamelotRelayerFactory.sol';
import {IChainlinkRelayerFactory} from '@interfaces/factories/IChainlinkRelayerFactory.sol';
import {IDenominatedOracleFactory} from '@interfaces/factories/IDenominatedOracleFactory.sol';
import {IChainlinkRelayer} from '@interfaces/oracles/IChainlinkRelayer.sol';
import {ICamelotRelayer} from '@interfaces/oracles/ICamelotRelayer.sol';
import {IDenominatedOracle} from '@interfaces/oracles/IDenominatedOracle.sol';
import {IBaseOracle} from '@interfaces/oracles/IBaseOracle.sol';
import {MintableERC20} from '@contracts/for-test/MintableERC20.sol';
import {Data} from '@contracts/for-test/Data.sol';
Expand All @@ -24,41 +26,33 @@ contract DeployOracles is Script {
IBaseOracle public camelotRelayer;
IBaseOracle public denominatedOracle;

ChainlinkRelayerFactory public chainlinkRelayerFactory;
CamelotRelayerFactory public camelotRelayerFactory;
DenominatedOracleFactory public denominatedOracleFactory;
IChainlinkRelayerFactory public chainlinkRelayerFactory;
ICamelotRelayerFactory public camelotRelayerFactory;
IDenominatedOracleFactory public denominatedOracleFactory;

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

// deploy oracle factories
deployFactories();
chainlinkRelayerFactory = data.chainlinkRelayerFactory();
camelotRelayerFactory = data.camelotRelayerFactory();
denominatedOracleFactory = data.denominatedOracleFactory();

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

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

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

vm.stopBroadcast();
}

/**
* @dev setup functions
*/
function deployFactories() public {
chainlinkRelayerFactory = new ChainlinkRelayerFactory();
camelotRelayerFactory = new CamelotRelayerFactory();
denominatedOracleFactory = new DenominatedOracleFactory();
}
}
35 changes: 35 additions & 0 deletions script/predeployment/DeployFactories.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ 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';
import {Data} from '@contracts/for-test/Data.sol';

// BROADCAST
// source .env && forge script DeployFactories --with-gas-price 2000000000 -vvvvv --rpc-url $ARB_SEPOLIA_RPC --broadcast --verify --etherscan-api-key $ARB_ETHERSCAN_API_KEY
Expand All @@ -29,3 +31,36 @@ contract DeployFactories is Script {
vm.stopBroadcast();
}
}

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

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

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

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

/**
* @dev CamelotRelayerFactory must be deployed by deployer of protocol
*/
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_PC'));
IAuthorizable(address(camelotRelayerFactory)).addAuthorization(vm.envAddress('ARB_SEPOLIA_PC'));
IAuthorizable(address(denominatedOracleFactory)).addAuthorization(vm.envAddress('ARB_SEPOLIA_PC'));

data.modifyFactory(bytes32('chainlinkRelayerFactory'), address(chainlinkRelayerFactory));
data.modifyFactory(bytes32('camelotRelayerFactory'), address(camelotRelayerFactory));
data.modifyFactory(bytes32('denominatedOracleFactory'), address(denominatedOracleFactory));
vm.stopBroadcast();
}
}
26 changes: 18 additions & 8 deletions src/contracts/for-test/Data.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ pragma solidity 0.7.6;

import {IAlgebraPool} from '@algebra-core/interfaces/IAlgebraPool.sol';
import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import {IChainlinkRelayerFactory} from '@interfaces/factories/IChainlinkRelayerFactory.sol';
import {ICamelotRelayerFactory} from '@interfaces/factories/ICamelotRelayerFactory.sol';
import {IDenominatedOracleFactory} from '@interfaces/factories/IDenominatedOracleFactory.sol';
import {IChainlinkRelayer} from '@interfaces/oracles/IChainlinkRelayer.sol';
import {ICamelotRelayer} from '@interfaces/oracles/ICamelotRelayer.sol';
import {IDenominatedOracle} from '@interfaces/oracles/IDenominatedOracle.sol';
Expand All @@ -15,6 +18,11 @@ contract Data {
// Pool
IAlgebraPool public pool;

// Factories
IChainlinkRelayerFactory public chainlinkRelayerFactory;
ICamelotRelayerFactory public camelotRelayerFactory;
IDenominatedOracleFactory public denominatedOracleFactory;

// Relayers
IChainlinkRelayer public chainlinkRelayer;
ICamelotRelayer public camelotRelayer;
Expand Down Expand Up @@ -46,15 +54,17 @@ contract Data {
pool = _pool;
}

function setChainlinkRelayer(address _relayer) public {
chainlinkRelayer = IChainlinkRelayer(_relayer);
}

function setCamelotRelayer(address _relayer) public {
camelotRelayer = ICamelotRelayer(_relayer);
function modifyFactory(bytes32 _param, address _factory) public {
if (_param == 'chainlinkRelayerFactory') chainlinkRelayerFactory = IChainlinkRelayerFactory(_factory);
else if (_param == 'camelotRelayerFactory') camelotRelayerFactory = ICamelotRelayerFactory(_factory);
else if (_param == 'denominatedOracleFactory') denominatedOracleFactory = IDenominatedOracleFactory(_factory);
else revert('Factory not set');
}

function setDenominatedOracle(address _relayer) public {
denominatedOracle = IDenominatedOracle(_relayer);
function modifyOracle(bytes32 _param, address _oracle) public {
if (_param == 'chainlinkRelayer') chainlinkRelayer = IChainlinkRelayer(_oracle);
else if (_param == 'camelotRelayer') camelotRelayer = ICamelotRelayer(_oracle);
else if (_param == 'denominatedOracle') denominatedOracle = IDenominatedOracle(_oracle);
else revert('Oracle not set');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity 0.7.6;

import {IBaseOracle} from '@interfaces/oracles/IBaseOracle.sol';

interface IRelayerFactory {
interface ICamelotRelayerFactory {
// --- Events ---
event NewAlgebraRelayer(address indexed _relayer, address _baseToken, address _quoteToken, uint32 _quotePeriod);

Expand Down
11 changes: 11 additions & 0 deletions src/interfaces/factories/IChainlinkRelayerFactory.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.7.6;

import {IBaseOracle} from '@interfaces/oracles/IBaseOracle.sol';

interface IChainlinkRelayerFactory {
// --- Events ---
event NewChainlinkRelayer(address indexed _chainlinkRelayer, address _aggregator, uint256 _staleThreshold);

function deployChainlinkRelayer(address _aggregator, uint256 _staleThreshold) external returns (IBaseOracle _relayer);
}
17 changes: 17 additions & 0 deletions src/interfaces/factories/IDenominatedOracleFactory.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.7.6;

import {IBaseOracle} from '@interfaces/oracles/IBaseOracle.sol';

interface IDenominatedOracleFactory {
// --- Events ---
event NewDenominatedOracle(
address indexed _denominatedOracle, address _priceSource, address _denominationPriceSource, bool _inverted
);

function deployDenominatedOracle(
IBaseOracle _priceSource,
IBaseOracle _denominationPriceSource,
bool _inverted
) external returns (IBaseOracle _denominatedOracle);
}
22 changes: 15 additions & 7 deletions test/unit/RelayerFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {IERC20Metadata} from '@algebra-periphery/interfaces/IERC20Metadata.sol';
import {IAlgebraFactory} from '@algebra-core/interfaces/IAlgebraFactory.sol';
import {IAlgebraPool} from '@algebra-core/interfaces/IAlgebraPool.sol';
import {CamelotRelayerFactory} from '@contracts/factories/CamelotRelayerFactory.sol';
import {IRelayerFactory} from '@interfaces/factories/IRelayerFactory.sol';
import {CamelotRelayerChild} from '@contracts/factories/CamelotRelayerChild.sol';
import {IAuthorizable} from '@interfaces/utils/IAuthorizable.sol';

Expand All @@ -23,8 +22,9 @@ abstract contract Base is DSTestPlus {
IERC20Metadata mockQuoteToken = IERC20Metadata(mockContract('QuoteToken'));

CamelotRelayerFactory relayerFactory;
CamelotRelayerChild relayerChild =
CamelotRelayerChild(label(address(0x0000000000000000000000007f85e9e000597158aed9320b5a5e11ab8cc7329a), 'CamelotRelayerChild'));
CamelotRelayerChild relayerChild = CamelotRelayerChild(
label(address(0x0000000000000000000000007f85e9e000597158aed9320b5a5e11ab8cc7329a), 'CamelotRelayerChild')
);

function setUp() public virtual {
vm.startPrank(deployer);
Expand Down Expand Up @@ -106,15 +106,19 @@ contract Unit_RelayerFactory_DeployRelayer is Base {
function test_Revert_Unauthorized(uint32 _quotePeriod) public {
vm.expectRevert('Unauthorized');

relayerFactory.deployAlgebraRelayer(SEPOLIA_ALGEBRA_FACTORY, address(mockBaseToken), address(mockQuoteToken), _quotePeriod);
relayerFactory.deployAlgebraRelayer(
SEPOLIA_ALGEBRA_FACTORY, address(mockBaseToken), address(mockQuoteToken), _quotePeriod
);
}

function test_Deploy_RelayerChild(
uint32 _quotePeriod,
string memory _symbol,
uint8 _decimals
) public happyPath(_symbol, _decimals) {
relayerFactory.deployAlgebraRelayer(SEPOLIA_ALGEBRA_FACTORY, address(mockBaseToken), address(mockQuoteToken), _quotePeriod);
relayerFactory.deployAlgebraRelayer(
SEPOLIA_ALGEBRA_FACTORY, address(mockBaseToken), address(mockQuoteToken), _quotePeriod
);

// assertEq(address(relayerChild).code, type(CamelotRelayerChild).runtimeCode);

Expand All @@ -129,7 +133,9 @@ contract Unit_RelayerFactory_DeployRelayer is Base {
string memory _symbol,
uint8 _decimals
) public happyPath(_symbol, _decimals) {
relayerFactory.deployAlgebraRelayer(SEPOLIA_ALGEBRA_FACTORY, address(mockBaseToken), address(mockQuoteToken), _quotePeriod);
relayerFactory.deployAlgebraRelayer(
SEPOLIA_ALGEBRA_FACTORY, address(mockBaseToken), address(mockQuoteToken), _quotePeriod
);

assertEq(relayerFactory.relayerById(1), address(relayerChild));
}
Expand All @@ -142,7 +148,9 @@ contract Unit_RelayerFactory_DeployRelayer is Base {
vm.expectEmit();
emit NewAlgebraRelayer(address(relayerChild), address(mockBaseToken), address(mockQuoteToken), _quotePeriod);

relayerFactory.deployAlgebraRelayer(SEPOLIA_ALGEBRA_FACTORY, address(mockBaseToken), address(mockQuoteToken), _quotePeriod);
relayerFactory.deployAlgebraRelayer(
SEPOLIA_ALGEBRA_FACTORY, address(mockBaseToken), address(mockQuoteToken), _quotePeriod
);
}

function test_Return_Relayer(
Expand Down

0 comments on commit b1b539d

Please sign in to comment.