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 15 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
7 changes: 2 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
MAINNET_RPC=
MAINNET_DEPLOYER_PK=

SEPOLIA_RPC=
SEPOLIA_DEPLOYER_PK=
ARBITRUM_RPC=
ARBITRUM_DEPLOYER_PK=

ETHERSCAN_API_KEY=
23 changes: 7 additions & 16 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 All @@ -26,7 +25,7 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: 'yarn'
cache: "yarn"

- name: Install dependencies
run: yarn --frozen-lockfile --network-concurrency 1
Expand All @@ -53,7 +52,7 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: 'yarn'
cache: "yarn"

- name: Install dependencies
run: yarn --frozen-lockfile --network-concurrency 1
Expand Down Expand Up @@ -83,7 +82,7 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: 'yarn'
cache: "yarn"

- name: Install dependencies
run: yarn --frozen-lockfile --network-concurrency 1
Expand All @@ -92,14 +91,6 @@ jobs:
run: |
forge build --build-info

- name: Run Echidna
uses: crytic/echidna-action@v2
with:
files: .
contract: InvariantGreeter
test-mode: assertion
crytic-args: --ignore-compile

halmos-tests:
name: Run symbolic execution tests
runs-on: ubuntu-latest
Expand All @@ -115,7 +106,7 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: 'yarn'
cache: "yarn"

- name: Install dependencies
run: yarn --frozen-lockfile --network-concurrency 1
Expand Down Expand Up @@ -146,9 +137,9 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: 'yarn'
cache: "yarn"

- name: Install dependencies
run: yarn --frozen-lockfile --network-concurrency 1

- run: yarn lint:check
- run: yarn lint:check
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
8 changes: 3 additions & 5 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ multiline_func_header = 'params_first'
sort_imports = true

[profile.default]
solc_version = '0.8.23'
solc_version = '0.8.26'
libs = ['node_modules', 'lib']
optimizer_runs = 10_000

Expand All @@ -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 = "${ARBITRUM_API_KEY}", chain = "arbitrum" }
0xJabberwock marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 3 additions & 4 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 All @@ -35,8 +34,8 @@
"package.json": "sort-package-json"
},
"dependencies": {
"@defi-wonderland/prophet-core-contracts": "0.0.0-438de1c5",
"@defi-wonderland/prophet-modules-contracts": "0.0.0-1197c328"
"@defi-wonderland/prophet-core": "0.0.0-2e39539b",
"@defi-wonderland/prophet-modules": "0.0.0-e52f8cce"
},
"devDependencies": {
"@commitlint/cli": "19.3.0",
Expand Down
2 changes: 1 addition & 1 deletion remappings.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
forge-std/=node_modules/forge-std/src
halmos-cheatcodes=node_modules/halmos-cheatcodes
@defi-wonderland/prophet-core-contracts/=node_modules/@defi-wonderland/prophet-core-contracts
@defi-wonderland/prophet-core/=node_modules/@defi-wonderland/prophet-core
@defi-wonderland/prophet-modules-contracts/=node_modules/@defi-wonderland/prophet-modules-contracts

contracts/=src/contracts
Expand Down
33 changes: 0 additions & 33 deletions script/Deploy.sol

This file was deleted.

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)
_setArbitrator(__arbitrator);
}

Expand Down
148 changes: 148 additions & 0 deletions src/contracts/EBORequestCreator.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.26;

import {EnumerableSet} from '@openzeppelin/contracts/utils/structs/EnumerableSet.sol';

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

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

/// @inheritdoc IEBORequestCreator
IOracle public oracle;

/// @inheritdoc IEBORequestCreator
IEpochManager public epochManager;

/// @inheritdoc IEBORequestCreator
IOracle.Request public requestData;

/// @inheritdoc IEBORequestCreator
uint256 public startEpoch;
0xShaito marked this conversation as resolved.
Show resolved Hide resolved

/// @inheritdoc IEBORequestCreator
mapping(string _chainId => mapping(uint256 _epoch => bytes32 _requestId)) public requestIdPerChainAndEpoch;

/**
* @notice The set of chain ids allowed
*/
EnumerableSet.Bytes32Set internal _chainIdsAllowed;

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
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
) Arbitrable(_arbitrator, _council) {
oracle = _oracle;
epochManager = _epochManager;

startEpoch = epochManager.currentEpoch();
}

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

bytes32 _encodedChainId;

IOracle.Request memory _requestData = requestData;

_requestData.nonce = uint96(0);
_requestData.requester = address(this);

for (uint256 _i; _i < _chainIds.length; _i++) {
_encodedChainId = _encodeChainId(_chainIds[_i]);
if (!_chainIdsAllowed.contains(_encodedChainId)) revert EBORequestCreator_ChainNotAdded();

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

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

emit RequestCreated(_requestId, _epoch, _chainIds[_i]);
}
}
}

/// @inheritdoc IEBORequestCreator
function addChain(string calldata _chainId) external onlyArbitrator {
bytes32 _encodedChainId = _encodeChainId(_chainId);
if (!_chainIdsAllowed.add(_encodedChainId)) {
revert EBORequestCreator_ChainAlreadyAdded();
}

emit ChainAdded(_chainId);
}

/// @inheritdoc IEBORequestCreator
function removeChain(string calldata _chainId) external onlyArbitrator {
bytes32 _encodedChainId = _encodeChainId(_chainId);
if (!_chainIdsAllowed.remove(_encodedChainId)) {
revert EBORequestCreator_ChainNotAdded();
}

emit ChainRemoved(_chainId);
}

/// @inheritdoc IEBORequestCreator
function setRequestModuleData(address _requestModule, bytes calldata _requestModuleData) external onlyArbitrator {
requestData.requestModule = _requestModule;
requestData.requestModuleData = _requestModuleData;

emit RequestModuleDataSet(_requestModule, _requestModuleData);
}

/// @inheritdoc IEBORequestCreator
function setResponseModuleData(address _responseModule, bytes calldata _responseModuleData) external onlyArbitrator {
requestData.responseModule = _responseModule;
requestData.responseModuleData = _responseModuleData;

emit ResponseModuleDataSet(_responseModule, _responseModuleData);
}

/// TODO: Change module data to the specific interface when we have
/// @inheritdoc IEBORequestCreator
function setDisputeModuleData(address _disputeModule, bytes calldata _disputeModuleData) external onlyArbitrator {
requestData.disputeModule = _disputeModule;
requestData.disputeModuleData = _disputeModuleData;

emit DisputeModuleDataSet(_disputeModule, _disputeModuleData);
}

/// @inheritdoc IEBORequestCreator
function setResolutionModuleData(
address _resolutionModule,
bytes calldata _resolutionModuleData
) external onlyArbitrator {
requestData.resolutionModule = _resolutionModule;
requestData.resolutionModuleData = _resolutionModuleData;

emit ResolutionModuleDataSet(_resolutionModule, _resolutionModuleData);
}

/// @inheritdoc IEBORequestCreator
function setFinalityModuleData(address _finalityModule, bytes calldata _finalityModuleData) external onlyArbitrator {
requestData.finalityModule = _finalityModule;
requestData.finalityModuleData = _finalityModuleData;

emit FinalityModuleDataSet(_finalityModule, _finalityModuleData);
}

/// @inheritdoc IEBORequestCreator
function setEpochManager(IEpochManager _epochManager) external onlyArbitrator {
epochManager = _epochManager;

emit EpochManagerSet(_epochManager);
0xJabberwock marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* @notice Encodes the chain id
* @dev The chain id is hashed to have a enumerable set to avoid duplicates
*/
function _encodeChainId(string calldata _chainId) internal pure returns (bytes32 _encodedChainId) {
_encodedChainId = keccak256(abi.encodePacked(_chainId));
}
}
Loading
Loading