Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: epoch #5

Merged
merged 25 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
MAINNET_RPC=
MAINNET_DEPLOYER_PK=
ARBITRUM_RPC=
ARBITRUM_DEPLOYER_PK=

SEPOLIA_RPC=
SEPOLIA_DEPLOYER_PK=

ETHERSCAN_API_KEY=
ARBISCAN_API_KEY=
3 changes: 1 addition & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ concurrency:
cancel-in-progress: true

env:
MAINNET_RPC: ${{ secrets.MAINNET_RPC }}
SEPOLIA_RPC: ${{ secrets.SEPOLIA_RPC }}
ARBITRUM_RPC: ${{ secrets.ARBITRUM_RPC }}

jobs:
unit-tests:
Expand Down
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,10 @@ yarn coverage

Configure the `.env` variables.

### Sepolia
### Arbitrum

```bash
yarn deploy:sepolia
```

### Mainnet

```bash
yarn deploy:mainnet
yarn deploy:arbitrum
```

The deployments are stored in ./broadcast
Expand Down
6 changes: 2 additions & 4 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ src = 'src/interfaces/'
runs = 1000

[rpc_endpoints]
mainnet = "${MAINNET_RPC}"
sepolia = "${SEPOLIA_RPC}"
arbitrum = "${ARBITRUM_RPC}"

[etherscan]
mainnet = { key = "${ETHERSCAN_API_KEY}", chain = "mainnet" }
sepolia = { key = "${ETHERSCAN_API_KEY}", chain = "sepolia" }
arbitrum = { key = "${ARBISCAN_API_KEY}", chain = "arbitrum" }
0xShaito marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
"build": "forge build",
"build:optimized": "FOUNDRY_PROFILE=optimized forge build",
"coverage": "forge coverage --report summary --report lcov --match-path 'test/unit/*'",
"deploy:mainnet": "bash -c 'source .env && forge script Deploy -vvvvv --rpc-url $MAINNET_RPC --broadcast --chain mainnet --private-key $MAINNET_DEPLOYER_PK'",
"deploy:sepolia": "bash -c 'source .env && forge script Deploy -vvvvv --rpc-url $SEPOLIA_RPC --broadcast --chain sepolia --private-key $SEPOLIA_DEPLOYER_PK'",
"deploy:arbitrum": "bash -c 'source .env && forge script Deploy -vvvvv --rpc-url $ARBITRUM_RPC --broadcast --chain arbitrum --private-key $ARBITRUM_DEPLOYER_PK'",
"lint:check": "yarn lint:sol-tests && yarn lint:sol-logic && forge fmt --check",
"lint:fix": "sort-package-json && forge fmt && yarn lint:sol-tests --fix && yarn lint:sol-logic --fix",
"lint:natspec": "npx @defi-wonderland/natspec-smells --config natspec-smells.config.js",
Expand Down
4 changes: 2 additions & 2 deletions src/contracts/Arbitrable.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.26;

import {IArbitrable} from 'interfaces/IArbitrable.sol';

Expand Down Expand Up @@ -62,7 +62,7 @@
}

/// @inheritdoc IArbitrable
function setArbitrator(address __arbitrator) external onlyCouncil {

Check warning on line 65 in src/contracts/Arbitrable.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Function order is incorrect, external function can not go after public view function (line 60)

Check warning on line 65 in src/contracts/Arbitrable.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Function order is incorrect, external function can not go after public view function (line 60)
_setArbitrator(__arbitrator);
}

Expand Down
38 changes: 33 additions & 5 deletions src/contracts/EBORequestCreator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@
import {EnumerableSet} from '@openzeppelin/contracts/utils/structs/EnumerableSet.sol';

import {Arbitrable} from 'contracts/Arbitrable.sol';
import {IEBORequestCreator, IOracle} from 'interfaces/IEBORequestCreator.sol';
import {IEBORequestCreator, IEpochManager, IOracle} from 'interfaces/IEBORequestCreator.sol';

contract EBORequestCreator is IEBORequestCreator, Arbitrable {
using EnumerableSet for EnumerableSet.Bytes32Set;

/// @inheritdoc IEBORequestCreator
IOracle public oracle;
IOracle public immutable ORACLE;

/// @inheritdoc IEBORequestCreator
uint256 public immutable START_EPOCH;

/// @inheritdoc IEBORequestCreator
IEpochManager public epochManager;

/// @inheritdoc IEBORequestCreator
IOracle.Request public requestData;
Expand All @@ -25,19 +31,26 @@

constructor(
IOracle _oracle,
IEpochManager _epochManager,
address _arbitrator,

Check warning on line 35 in src/contracts/EBORequestCreator.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Variable "_arbitrator" is unused

Check warning on line 35 in src/contracts/EBORequestCreator.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Variable "_arbitrator" is unused
address _council,

Check warning on line 36 in src/contracts/EBORequestCreator.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Variable "_council" is unused

Check warning on line 36 in src/contracts/EBORequestCreator.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Variable "_council" is unused
IOracle.Request memory _requestData
) Arbitrable(_arbitrator, _council) {
oracle = _oracle;

if (_requestData.nonce != 0) revert EBORequestCreator_InvalidNonce();

ORACLE = _oracle;
_setEpochManager(_epochManager);

_requestData.requester = address(this);
requestData = _requestData;

START_EPOCH = epochManager.currentEpoch();
}

/// @inheritdoc IEBORequestCreator
function createRequests(uint256 _epoch, string[] calldata _chainIds) external {
if (_epoch > epochManager.currentEpoch() || START_EPOCH > _epoch) revert EBORequestCreator_InvalidEpoch();

bytes32 _encodedChainId;

IOracle.Request memory _requestData = requestData;
Expand All @@ -48,7 +61,7 @@

if (requestIdPerChainAndEpoch[_chainIds[_i]][_epoch] == bytes32(0)) {
// TODO: CREATE REQUEST DATA
bytes32 _requestId = oracle.createRequest(_requestData, bytes32(0));
bytes32 _requestId = ORACLE.createRequest(_requestData, bytes32(0));

requestIdPerChainAndEpoch[_chainIds[_i]][_epoch] = _requestId;

Expand Down Expand Up @@ -121,6 +134,21 @@
emit FinalityModuleDataSet(_finalityModule, _finalityModuleData);
}

/// @inheritdoc IEBORequestCreator
function setEpochManager(IEpochManager _epochManager) external onlyArbitrator {
_setEpochManager(_epochManager);
}

/**
* @notice Set the epoch manager
* @param _epochManager The epoch manager
*/
function _setEpochManager(IEpochManager _epochManager) internal {
epochManager = _epochManager;

emit EpochManagerSet(_epochManager);
}

/**
* @notice Encodes the chain id
* @dev The chain id is hashed to have a enumerable set to avoid duplicates
Expand Down
6 changes: 3 additions & 3 deletions src/interfaces/IArbitrable.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.26;
/**
* @title Arbitrable
* @notice Makes a contract subject to arbitration by The Graph
*/

interface IArbitrable {
/*///////////////////////////////////////////////////////////////
EVENTS
Expand Down Expand Up @@ -78,7 +78,7 @@
* @dev Callable only by The Graph's Council
* @param _arbitrator The address of The Graph's Arbitrator
*/
function setArbitrator(address _arbitrator) external;

Check warning on line 81 in src/interfaces/IArbitrable.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Function order is incorrect, external function can not go after external view function (line 70)

Check warning on line 81 in src/interfaces/IArbitrable.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Function order is incorrect, external function can not go after external view function (line 70)

/**
* @notice Sets the address of the pending The Graph's Council
Expand Down
34 changes: 32 additions & 2 deletions src/interfaces/IEBORequestCreator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity 0.8.26;

import {IOracle} from '@defi-wonderland/prophet-core/solidity/interfaces/IOracle.sol';
import {IEpochManager} from 'interfaces/external/IEpochManager.sol';

interface IEBORequestCreator {
/*///////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -63,6 +64,12 @@ interface IEBORequestCreator {
*/
event FinalityModuleDataSet(address indexed _finalityModule, bytes _finalityModuleData);

/**
* @notice Emitted when the epoch manager is set
* @param _epochManager The epoch manager
*/
event EpochManagerSet(IEpochManager indexed _epochManager);

/*///////////////////////////////////////////////////////////////
ERRORS
//////////////////////////////////////////////////////////////*/
Expand All @@ -81,15 +88,32 @@ interface IEBORequestCreator {
*/
error EBORequestCreator_ChainNotAdded();

/**
* @notice Thrown when the epoch is not valid
*/
error EBORequestCreator_InvalidEpoch();

/*///////////////////////////////////////////////////////////////
VARIABLES
//////////////////////////////////////////////////////////////*/

/**
* @notice The oracle contract
* @return _oracle The oracle contract
* @return _ORACLE The oracle contract
*/
function oracle() external view returns (IOracle _oracle);
function ORACLE() external view returns (IOracle _ORACLE);

/**
* @notice The first valid epoch to create requests
* @return _START_EPOCH The start epoch
*/
function START_EPOCH() external view returns (uint256 _START_EPOCH);

/**
* @notice The epoch manager contract
* @return _epochManager The epoch manager contract
*/
function epochManager() external view returns (IEpochManager _epochManager);

/**
* @notice The request data
Expand Down Expand Up @@ -192,4 +216,10 @@ interface IEBORequestCreator {
* @param _finalityModuleData The finality module data
*/
function setFinalityModuleData(address _finalityModule, bytes calldata _finalityModuleData) external;

/**
* @notice Set the epoch manager
* @param _epochManager The epoch manager
*/
function setEpochManager(IEpochManager _epochManager) external;
}
10 changes: 10 additions & 0 deletions src/interfaces/external/IEpochManager.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.26;

interface IEpochManager {
Comment on lines +1 to +4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't out there a package with The Graph's interfaces? 😕

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe yes but we need just 1 function, thats why I create the interface

/*///////////////////////////////////////////////////////////////
FUNCTIONS
//////////////////////////////////////////////////////////////*/

function currentEpoch() external view returns (uint256 _currentEpoch);
}
4 changes: 4 additions & 0 deletions test/integration/Constants.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

address constant _EPOCH_MANAGER = 0x5A843145c43d328B9bB7a4401d94918f131bB281;
Comment on lines +1 to +4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the linter complain when no initial underscore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDK to be honest, I assume that for constants should start with underscore

Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,20 @@ contract Integration_CreateRequest is IntegrationBase {
string[] memory _chainIds = new string[](1);
_chainIds[0] = 'chainId1';

// Should revert if the epoch is invalid
vm.expectRevert(IEBORequestCreator.EBORequestCreator_InvalidEpoch.selector);
vm.prank(_user);
_eboRequestCreator.createRequests(1, _chainIds);

// New epoch
vm.roll(242_000_000);
// Get the current epoch
uint256 _currentEpoch = _epochManager.currentEpoch();

// Create a request without approving the chain id
vm.expectRevert(IEBORequestCreator.EBORequestCreator_ChainNotAdded.selector);
vm.prank(_user);
_eboRequestCreator.createRequests(1, _chainIds);
_eboRequestCreator.createRequests(_currentEpoch, _chainIds);

// Create a request with an approved chain id
vm.prank(_arbitrator);
Expand All @@ -22,8 +32,8 @@ contract Integration_CreateRequest is IntegrationBase {
vm.mockCall(address(_oracle), abi.encodeWithSelector(IOracle.createRequest.selector), abi.encode(_requestId));

vm.prank(_user);
_eboRequestCreator.createRequests(1, _chainIds);
assertEq(_eboRequestCreator.requestIdPerChainAndEpoch('chainId1', 1), _requestId);
_eboRequestCreator.createRequests(_currentEpoch, _chainIds);
assertEq(_eboRequestCreator.requestIdPerChainAndEpoch('chainId1', _currentEpoch), _requestId);

// Remove the chain id
vm.prank(_arbitrator);
Expand All @@ -32,6 +42,6 @@ contract Integration_CreateRequest is IntegrationBase {
// Create a request without approving the chain id
vm.expectRevert(IEBORequestCreator.EBORequestCreator_ChainNotAdded.selector);
vm.prank(_user);
_eboRequestCreator.createRequests(1, _chainIds);
_eboRequestCreator.createRequests(_currentEpoch, _chainIds);
}
}
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

import {_EPOCH_MANAGER} from '../Constants.sol';
import {Test} from 'forge-std/Test.sol';
import {IERC20} from 'forge-std/interfaces/IERC20.sol';

import {Oracle} from '@defi-wonderland/prophet-core/solidity/contracts/Oracle.sol';
import {EBORequestCreator, IEBORequestCreator, IOracle} from 'contracts/EBORequestCreator.sol';
import {EBORequestCreator, IEBORequestCreator, IEpochManager, IOracle} from 'contracts/EBORequestCreator.sol';

contract IntegrationBase is Test {
uint256 internal constant _FORK_BLOCK = 18_920_905;
uint256 internal constant _FORK_BLOCK = 240_000_000;

address internal _arbitrator = makeAddr('arbitrator');
address internal _council = makeAddr('council');
address internal _owner = makeAddr('owner');
address internal _user = makeAddr('user');

IOracle.Request _requestData;

Check warning on line 18 in test/integration/arbitrum/IntegrationBase.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Explicitly mark visibility of state

Check warning on line 18 in test/integration/arbitrum/IntegrationBase.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Explicitly mark visibility of state

IEBORequestCreator internal _eboRequestCreator;
IOracle internal _oracle;
IEpochManager internal _epochManager;

function setUp() public {
vm.createSelectFork(vm.rpcUrl('mainnet'), _FORK_BLOCK);
vm.createSelectFork(vm.rpcUrl('arbitrum'), _FORK_BLOCK);
vm.startPrank(_owner);

_oracle = new Oracle();

_epochManager = IEpochManager(_EPOCH_MANAGER);

_requestData.nonce = 0;
// TODO: Replace with the implementation
_eboRequestCreator = new EBORequestCreator(_oracle, _arbitrator, _council, _requestData);
_eboRequestCreator = new EBORequestCreator(_oracle, _epochManager, _arbitrator, _council, _requestData);

vm.stopPrank();
}
Expand Down
Loading
Loading