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 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
5 changes: 1 addition & 4 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
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
28 changes: 5 additions & 23 deletions src/contracts/EBORequestModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,12 @@ contract EBORequestModule is Module, IEBORequestModule {
}

/// @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
Expand Down
52 changes: 32 additions & 20 deletions src/contracts/HorizonAccountingExtension.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {SafeERC20} from '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol
import {EnumerableSet} from '@openzeppelin/contracts/utils/structs/EnumerableSet.sol';

import {
IArbitrable,
IBondEscalationModule,
IERC20,
IHorizonAccountingExtension,
Expand All @@ -24,17 +25,17 @@ contract HorizonAccountingExtension is Validator, IHorizonAccountingExtension {
/// @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;

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

// 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 @@ -70,17 +71,23 @@ contract HorizonAccountingExtension is Validator, IHorizonAccountingExtension {
* @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 _maxUsersToCheck The maximum number of users to check
* @param _authorizedCallers The addresses of the authorized callers
*/
constructor(
IHorizonStaking _horizonStaking,
IOracle _oracle,
IERC20 _grt,
IArbitrable _arbitrable,
uint256 _minThawingPeriod,
uint256 _maxUsersToCheck,
address[] memory _authorizedCallers
) Validator(_oracle) {
HORIZON_STAKING = _horizonStaking;
GRT = _grt;
ARBITRABLE = _arbitrable;
MIN_THAWING_PERIOD = _minThawingPeriod;
_setMaxUsersToCheck(_maxUsersToCheck);

// Set the authorized callers
for (uint256 _i; _i < _authorizedCallers.length; ++_i) {
Expand Down Expand Up @@ -180,10 +187,6 @@ contract HorizonAccountingExtension is Validator, IHorizonAccountingExtension {
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 @@ -227,9 +230,9 @@ contract HorizonAccountingExtension is Validator, IHorizonAccountingExtension {
// 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, 1, maxUsersToCheck, _result, _status);
Comment on lines -232 to +235
Copy link
Member

Choose a reason for hiding this comment

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

I'd pass a constant (MAX_USERS_TO_SLASH) as argument instead of the magic number.

Copy link
Member

Choose a reason for hiding this comment

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

I'm good to have it as a constant too (1)

}

_rewardAmount = _claimAmount - _pledgeAmount;
Expand Down Expand Up @@ -290,7 +293,6 @@ contract HorizonAccountingExtension is Validator, IHorizonAccountingExtension {
_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 @@ -311,6 +313,7 @@ contract HorizonAccountingExtension is Validator, IHorizonAccountingExtension {
emit Bonded(_requestId, _bonder, _amount);
}

/// @inheritdoc IHorizonAccountingExtension
function bond(
address _bonder,
bytes32 _requestId,
Expand All @@ -337,14 +340,6 @@ contract HorizonAccountingExtension is Validator, IHorizonAccountingExtension {
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 @@ -353,6 +348,7 @@ contract HorizonAccountingExtension is Validator, IHorizonAccountingExtension {
emit Released(_requestId, _bonder, _amount);
}

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

Expand All @@ -363,6 +359,22 @@ contract HorizonAccountingExtension is Validator, IHorizonAccountingExtension {
_slash(_disputeId, _usersToSlash, _maxUsersToCheck, _result, _status);
}

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

/**
* @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 MaxUsersToCheckSet(_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
44 changes: 44 additions & 0 deletions src/interfaces/IHorizonAccountingExtension.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {IBondEscalationModule} from
'@defi-wonderland/prophet-modules/solidity/interfaces/modules/dispute/IBondEscalationModule.sol';
import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';

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

interface IHorizonAccountingExtension {
/*///////////////////////////////////////////////////////////////
EVENTS
Expand Down Expand Up @@ -100,6 +102,13 @@ interface IHorizonAccountingExtension {
bytes32 indexed _requestId, bytes32 indexed _disputeId, address indexed _pledger, uint256 _reward, uint256 _released
);

/**
* @notice Emitted when max users to check is set
*
* @param _maxUsersToCheck The new value of max users to check
*/
event MaxUsersToCheckSet(uint256 _maxUsersToCheck);

/*///////////////////////////////////////////////////////////////
ERRORS
//////////////////////////////////////////////////////////////*/
Expand Down Expand Up @@ -205,6 +214,12 @@ interface IHorizonAccountingExtension {
*/
function GRT() external view returns (IERC20 _GRT);

/**
* @notice The Arbitrable contract
* @return _arbitrable The Arbitrable contract
*/
function ARBITRABLE() external view returns (IArbitrable _arbitrable);

/**
* @notice The minimum thawing period
* @return _MIN_THAWING_PERIOD The minimum thawing period
Expand All @@ -217,6 +232,12 @@ interface IHorizonAccountingExtension {
*/
function MAX_VERIFIER_CUT() external view returns (uint256 _MAX_VERIFIER_CUT);

/**
* @notice The maximum users to check
* @return _maxUsersToCheck The maximum users to check
*/
function maxUsersToCheck() external view returns (uint256 _maxUsersToCheck);

/**
* @notice The total bonded tokens for a user
* @param _user The user address
Expand Down Expand Up @@ -363,11 +384,34 @@ interface IHorizonAccountingExtension {
*/
function bond(address _bonder, bytes32 _requestId, uint256 _amount) external;

/**
* @notice Allows a allowed module to bond a user's tokens for a request
* @param _bonder The address of the user to bond tokens for
* @param _requestId The id of the request the user is bonding for
* @param _amount The amount of GRT to bond
* @param _sender The address of the user who is bonding the tokens
*/
function bond(address _bonder, bytes32 _requestId, uint256 _amount, address _sender) external;

/**
* @notice Allows a valid module to release a user's tokens
* @param _bonder The address of the user to release tokens for
* @param _requestId The id of the request where the tokens were bonded
* @param _amount The amount of GRT to release
*/
function release(address _bonder, bytes32 _requestId, uint256 _amount) external;

/**
* @notice Slashes the users that lost the dispute
* @param _disputeId The ID of the dispute
* @param _usersToSlash The number of users to slash
* @param _maxUsersToCheck The number of users to check
*/
function slash(bytes32 _disputeId, uint256 _usersToSlash, uint256 _maxUsersToCheck) external;

/**
* @notice Sets the maximum users to check
* @param _maxUsersToCheck The new value of max users to check
*/
function setMaxUsersToCheck(uint256 _maxUsersToCheck) external;
}
18 changes: 9 additions & 9 deletions test/unit/CouncilArbitrator.t.sol
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.26;

import {IOracle} from '@defi-wonderland/prophet-core/solidity/interfaces/IOracle.sol';
import {IValidator} from '@defi-wonderland/prophet-core/solidity/interfaces/IValidator.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 {Helpers} from 'test/utils/Helpers.sol';

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

import {CouncilArbitrator} from 'contracts/CouncilArbitrator.sol';
import {
CouncilArbitrator,
IArbitrable,
IArbitrator,
IArbitratorModule,
ICouncilArbitrator,
IOracle,
ValidatorLib
} from 'contracts/CouncilArbitrator.sol';

import 'forge-std/Test.sol';

Expand Down
2 changes: 1 addition & 1 deletion test/unit/EBOFinalityModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
pragma solidity 0.8.26;

import {ValidatorLib} from '@defi-wonderland/prophet-core/solidity/libraries/ValidatorLib.sol';
import {EnumerableSet} from '@openzeppelin/contracts/utils/structs/EnumerableSet.sol';

import {IAccountingExtension} from
'@defi-wonderland/prophet-modules/solidity/interfaces/extensions/IAccountingExtension.sol';

import {
EBOFinalityModule,
EnumerableSet,
IArbitrable,
IEBOFinalityModule,
IEBORequestCreator,
Expand Down Expand Up @@ -218,7 +218,7 @@
AmendEpochParams calldata _params,
string[] calldata _chainIds,
uint256[] calldata _blockNumbers,
address _arbitrator

Check warning on line 221 in test/unit/EBOFinalityModule.t.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Variable "_arbitrator" is unused
) public happyPath(_arbitrator) {
vm.assume(_chainIds.length != _blockNumbers.length);

Expand Down
Loading
Loading