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: remove todo #38

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
3 changes: 2 additions & 1 deletion .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"immutable-name-snakecase": "warn",
"avoid-low-level-calls": "off",
"no-console": "off",
"max-line-length": ["warn", 120]
"max-line-length": ["warn", 120],
"no-unused-vars": "off"
}
}
7 changes: 2 additions & 5 deletions src/contracts/CouncilArbitrator.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.26;

import {IOracle} from '@defi-wonderland/prophet-core/solidity/interfaces/IOracle.sol';
import {ValidatorLib} from '@defi-wonderland/prophet-core/solidity/libraries/ValidatorLib.sol';
import {IArbitrator} from '@defi-wonderland/prophet-modules/solidity/interfaces/IArbitrator.sol';
import {IArbitratorModule} from
'@defi-wonderland/prophet-modules/solidity/interfaces/modules/resolution/IArbitratorModule.sol';

import {IArbitrable, ICouncilArbitrator} from 'interfaces/ICouncilArbitrator.sol';
import {IArbitrable, IArbitratorModule, ICouncilArbitrator, IOracle} from 'interfaces/ICouncilArbitrator.sol';

/**
* @title CouncilArbitrator
Expand Down Expand Up @@ -52,7 +49,7 @@ contract CouncilArbitrator is ICouncilArbitrator {
IOracle.Request calldata _request,
IOracle.Response calldata _response,
IOracle.Dispute calldata _dispute
) external onlyArbitratorModule returns (bytes memory /* _data */ ) {
) external onlyArbitratorModule returns (bytes memory _data) {
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I support keeping solhint's no-unused-vars and commenting unused parameter names. 🤷‍♂️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

bytes32 _disputeId = _dispute._getId();

resolutions[_disputeId] = ResolutionParameters(_request, _response, _dispute);
Expand Down
27 changes: 12 additions & 15 deletions src/contracts/EBORequestCreator.sol
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.26;

import {IOracle} from '@defi-wonderland/prophet-core/solidity/interfaces/IOracle.sol';
import {IBondEscalationModule} from
'@defi-wonderland/prophet-modules/solidity/interfaces/modules/dispute/IBondEscalationModule.sol';
import {IArbitratorModule} from
'@defi-wonderland/prophet-modules/solidity/interfaces/modules/resolution/IArbitratorModule.sol';
import {IBondedResponseModule} from
'@defi-wonderland/prophet-modules/solidity/interfaces/modules/response/IBondedResponseModule.sol';
import {EnumerableSet} from '@openzeppelin/contracts/utils/structs/EnumerableSet.sol';
import {IEpochManager} from 'interfaces/external/IEpochManager.sol';

import {IArbitrable, IEBORequestCreator} from 'interfaces/IEBORequestCreator.sol';
import {IEBORequestModule} from 'interfaces/IEBORequestModule.sol';
import {
IArbitrable,
IArbitratorModule,
IBondEscalationModule,
IBondedResponseModule,
IEBORequestCreator,
IEBORequestModule,
IEpochManager,
IOracle
} from 'interfaces/IEBORequestCreator.sol';

contract EBORequestCreator is IEBORequestCreator {
using EnumerableSet for EnumerableSet.Bytes32Set;
Expand Down Expand Up @@ -161,15 +161,12 @@ contract EBORequestCreator is IEBORequestCreator {
emit ResolutionModuleDataSet(_resolutionModule, _resolutionModuleData);
}

// TODO: Why set finality module data?
// TODO: Change module data to the specific interface when we have
/// @inheritdoc IEBORequestCreator
function setFinalityModuleData(address _finalityModule, bytes calldata _finalityModuleData) external {
function setFinalityModuleData(address _finalityModule) external {
ARBITRABLE.validateArbitrator(msg.sender);
requestData.finalityModule = _finalityModule;
requestData.finalityModuleData = _finalityModuleData;

emit FinalityModuleDataSet(_finalityModule, _finalityModuleData);
emit FinalityModuleDataSet(_finalityModule, new bytes(0));
}

/// @inheritdoc IEBORequestCreator
Expand Down
24 changes: 1 addition & 23 deletions src/contracts/EBORequestModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,34 +34,12 @@
}

/// @inheritdoc IEBORequestModule
function createRequest(bytes32 _requestId, bytes calldata _data, address _requester) external onlyOracle {
function createRequest(bytes32 _requestId, bytes calldata _data, address _requester) external view onlyOracle {
if (!_eboRequestCreatorsAllowed.contains(_requester)) revert EBORequestModule_InvalidRequester();

RequestParameters memory _params = decodeRequestData(_data);

// TODO: Bond for the rewards
}

/// @inheritdoc IEBORequestModule
function finalizeRequest(
IOracle.Request calldata _request,
IOracle.Response calldata _response,
address _finalizer
) external override(Module, IEBORequestModule) onlyOracle {
if (!_eboRequestCreatorsAllowed.contains(_request.requester)) revert EBORequestModule_InvalidRequester();

// TODO: Redeclare the `Request` struct
// RequestParameters memory _params = decodeRequestData(_request.requestModuleData);

if (_response.requestId != 0) {
// TODO: Bond for the rewards
}

emit RequestFinalized(_response.requestId, _response, _finalizer);
}

/// @inheritdoc IEBORequestModule
function addEBORequestCreator(IEBORequestCreator _eboRequestCreator) external {

Check warning on line 42 in src/contracts/EBORequestModule.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 37)
ARBITRABLE.validateArbitrator(msg.sender);
_addEBORequestCreator(_eboRequestCreator);
}
Expand Down
73 changes: 53 additions & 20 deletions src/contracts/HorizonAccountingExtension.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import {EnumerableSet} from '@openzeppelin/contracts/utils/structs/EnumerableSet.sol';

import {
IArbitrable,
IBondEscalationModule,
IERC20,
IHorizonAccountingExtension,
Expand All @@ -24,17 +25,20 @@
/// @inheritdoc IHorizonAccountingExtension
IERC20 public immutable GRT;

/// @inheritdoc IHorizonAccountingExtension
IArbitrable public immutable ARBITRABLE;

/// @inheritdoc IHorizonAccountingExtension
uint256 public immutable MIN_THAWING_PERIOD;

/// @inheritdoc IHorizonAccountingExtension
uint256 public constant MAX_VERIFIER_CUT = 1_000_000;

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

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Function order is incorrect, contract constant declaration can not go after contract immutable declaration (line 32)

// TODO: Validate what the correct magic numbers should be
uint256 public constant MAX_SLASHING_USERS = 4;
/// @inheritdoc IHorizonAccountingExtension
uint256 public maxSlashingUsers;

// TODO: Validate what the correct magic numbers should be
uint256 public constant MAX_USERS_TO_CHECK = 10;
/// @inheritdoc IHorizonAccountingExtension
uint256 public maxUsersToCheck;

/// @inheritdoc IHorizonAccountingExtension
mapping(address _user => uint256 _bonded) public totalBonded;
Expand Down Expand Up @@ -67,16 +71,24 @@
* @param _oracle The address of the Oracle
* @param _grt The address of the GRT token
* @param _minThawingPeriod The minimum thawing period for the staking
* @param _maxSlashingUsers The maximum number of users to slash
* @param _maxUsersToCheck The maximum number of users to check
0xJabberwock marked this conversation as resolved.
Show resolved Hide resolved
*/
constructor(
IHorizonStaking _horizonStaking,
IOracle _oracle,
IERC20 _grt,
uint256 _minThawingPeriod
IArbitrable _arbitrable,
uint256 _minThawingPeriod,
uint256 _maxSlashingUsers,
uint256 _maxUsersToCheck
) Validator(_oracle) {
HORIZON_STAKING = _horizonStaking;
GRT = _grt;
ARBITRABLE = _arbitrable;
MIN_THAWING_PERIOD = _minThawingPeriod;
_setMaxSlashingUsers(_maxSlashingUsers);
_setMaxUsersToCheck(_maxUsersToCheck);
}

/**
Expand Down Expand Up @@ -163,10 +175,6 @@
bondEscalationModule: _bondEscalationModule
});

// TODO: The amount of money to be distributed needs to be slashed.
// The problem is that there could be multiple users to slash and we can't do it fully
// in this function.

emit BondEscalationSettled({
_requestId: _requestId,
_disputeId: _disputeId,
Expand Down Expand Up @@ -210,9 +218,9 @@
// If not enough balance, slash some users to get enough balance
uint256 _balance = GRT.balanceOf(address(this));

// TODO: How many iterations should we do?
// Claim one by one until the balance is enough
while (_balance < _claimAmount) {
_balance += _slash(_disputeId, 1, MAX_USERS_TO_CHECK, _result, _status);
_balance += _slash(_disputeId, maxSlashingUsers, maxUsersToCheck, _result, _status);
0xShaito marked this conversation as resolved.
Show resolved Hide resolved
}

_rewardAmount = _claimAmount - _pledgeAmount;
Expand Down Expand Up @@ -273,7 +281,6 @@
_unbond(_payer, _amount);

// Slash a payer to pay the receiver
// TODO: Check if will provision that amount or we will send it directly
HORIZON_STAKING.slash(_payer, _amount, _amount, _receiver);

emit Paid({_requestId: _requestId, _beneficiary: _receiver, _payer: _payer, _amount: _amount});
Expand All @@ -294,6 +301,7 @@
emit Bonded(_requestId, _bonder, _amount);
}

/// @inheritdoc IHorizonAccountingExtension
function bond(
address _bonder,
bytes32 _requestId,
Expand All @@ -320,14 +328,6 @@
bytes32 _requestId,
uint256 _amount
) external onlyAllowedModule(_requestId) onlyParticipant(_requestId, _bonder) {
// TODO: Release is used to pay the user the rewards for proposing or returning the funds to the
// creator in case the request finalized without a response. We need to finish designing the payments
// integration to do this.

// TODO: Release is also used in the bond escalation module to:
// 1) return the funds to the disputer in case there is no resolution
// 2) release the initial dispute bond if the disputer wins

// Release the bond amount for the request for the user
bondedForRequest[_bonder][_requestId] -= _amount;

Expand All @@ -336,6 +336,7 @@
emit Released(_requestId, _bonder, _amount);
}

/// @inheritdoc IHorizonAccountingExtension
function slash(bytes32 _disputeId, uint256 _usersToSlash, uint256 _maxUsersToCheck) external {
EscalationResult memory _result = escalationResults[_disputeId];

Expand All @@ -346,6 +347,38 @@
_slash(_disputeId, _usersToSlash, _maxUsersToCheck, _result, _status);
}

/// @inheritdoc IHorizonAccountingExtension
function setMaxSlashingUsers(uint256 _maxSlashingUsers) external {
ARBITRABLE.validateArbitrator(msg.sender);
_setMaxSlashingUsers(_maxSlashingUsers);
}

/// @inheritdoc IHorizonAccountingExtension
function setMaxUsersToCheck(uint256 _maxUsersToCheck) external {
ARBITRABLE.validateArbitrator(msg.sender);
_setMaxUsersToCheck(_maxUsersToCheck);
}

/**
* @notice Set the maximum number of users to slash.
* @param _maxSlashingUsers The maximum number of users to slash.
*/
function _setMaxSlashingUsers(uint256 _maxSlashingUsers) internal {
maxSlashingUsers = _maxSlashingUsers;

emit MaxSlashingUsersSetted(_maxSlashingUsers);
}

/**
* @notice Set the maximum number of users to check.
* @param _maxUsersToCheck The maximum number of users to check.
*/
function _setMaxUsersToCheck(uint256 _maxUsersToCheck) internal {
maxUsersToCheck = _maxUsersToCheck;

emit MaxUsersToCheckSetted(_maxUsersToCheck);
}

/**
* @notice Slash the users that have pledged for a dispute.
* @param _disputeId The dispute id.
Expand Down
3 changes: 1 addition & 2 deletions src/interfaces/IEBORequestCreator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,8 @@ interface IEBORequestCreator {
/**
* @notice Set the finality data module
* @param _finalityModule The finality module
* @param _finalityModuleData The finality module data
*/
function setFinalityModuleData(address _finalityModule, bytes calldata _finalityModuleData) external;
function setFinalityModuleData(address _finalityModule) external;

/**
* @notice Set the epoch manager
Expand Down
13 changes: 0 additions & 13 deletions src/interfaces/IEBORequestModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,6 @@ interface IEBORequestModule is IRequestModule {
*/
function createRequest(bytes32 _requestId, bytes calldata _data, address _requester) external;

/**
* @notice Finalizes the request by paying the proposer for the response or releasing the requester's bond if no response was submitted
* @dev Callable only by the Oracle
* @param _request The request being finalized
* @param _response The final response
* @param _finalizer The address that initiated the finalization
*/
function finalizeRequest(
IOracle.Request calldata _request,
IOracle.Response calldata _response,
address _finalizer
) external;

/**
* @notice Adds the address of the EBORequestCreator
* @dev Callable only by The Graph's Arbitrator
Expand Down
Loading
Loading