From 02748911561d13c69cb80f9b4762b2319028c39a Mon Sep 17 00:00:00 2001 From: Gas One Cent <86567384+gas1cent@users.noreply.github.com> Date: Tue, 7 Nov 2023 23:02:08 +0400 Subject: [PATCH] feat: uncomment helpers --- .../extensions/IAccountingExtension.sol | 380 +++++++------- .../extensions/IBondEscalationAccounting.sol | 480 ++++++++--------- .../modules/dispute/IBondEscalationModule.sol | 491 +++++++++--------- solidity/test/utils/Helpers.sol | 124 +++-- 4 files changed, 738 insertions(+), 737 deletions(-) diff --git a/solidity/interfaces/extensions/IAccountingExtension.sol b/solidity/interfaces/extensions/IAccountingExtension.sol index 5a42243e..74c9c9cd 100644 --- a/solidity/interfaces/extensions/IAccountingExtension.sol +++ b/solidity/interfaces/extensions/IAccountingExtension.sol @@ -1,190 +1,190 @@ -// // SPDX-License-Identifier: MIT -// pragma solidity ^0.8.19; - -// import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol'; -// import {IOracle} from '@defi-wonderland/prophet-core-contracts/solidity/interfaces/IOracle.sol'; - -// /* -// * @title AccountingExtension -// * @notice Extension allowing users to deposit and bond funds -// * to be used for payments and disputes. -// */ -// interface IAccountingExtension { -// /*/////////////////////////////////////////////////////////////// -// EVENTS -// //////////////////////////////////////////////////////////////*/ - -// /** -// * @notice A user deposited tokens into the accounting extension -// * @param _depositor The user who deposited the tokens -// * @param _token The address of the token deposited by the user -// * @param _amount The amount of `_token` deposited -// */ -// event Deposited(address indexed _depositor, IERC20 indexed _token, uint256 _amount); - -// /** -// * @notice A user withdrew tokens from the accounting extension -// * @param _withdrawer The user who withdrew the tokens -// * @param _token The address of the token withdrawn by the user -// * @param _amount The amount of `_token` withdrawn -// */ -// event Withdrew(address indexed _withdrawer, IERC20 indexed _token, uint256 _amount); - -// /** -// * @notice A payment between users has been made -// * @param _beneficiary The user receiving the tokens -// * @param _payer The user who is getting its tokens transferred -// * @param _token The address of the token being transferred -// * @param _amount The amount of `_token` transferred -// */ -// event Paid( -// bytes32 indexed _requestId, address indexed _beneficiary, address indexed _payer, IERC20 _token, uint256 _amount -// ); - -// /** -// * @notice User's funds have been bonded -// * @param _bonder The user who is getting its tokens bonded -// * @param _token The address of the token being bonded -// * @param _amount The amount of `_token` bonded -// */ -// event Bonded(bytes32 indexed _requestId, address indexed _bonder, IERC20 indexed _token, uint256 _amount); - -// /** -// * @notice User's funds have been released -// * @param _beneficiary The user who is getting its tokens released -// * @param _token The address of the token being released -// * @param _amount The amount of `_token` released -// */ -// event Released(bytes32 indexed _requestId, address indexed _beneficiary, IERC20 indexed _token, uint256 _amount); - -// /*/////////////////////////////////////////////////////////////// -// ERRORS -// //////////////////////////////////////////////////////////////*/ - -// /** -// * @notice Thrown when the account doesn't have enough balance to bond/withdraw -// * or not enough bonded to release/pay -// */ -// error AccountingExtension_InsufficientFunds(); - -// /** -// * @notice Thrown when the module bonding user tokens hasn't been approved by the user. -// */ -// error AccountingExtension_InsufficientAllowance(); - -// /** -// * @notice Thrown when an `onlyAllowedModule` function is called by something -// * else than a module being used in the corresponding request -// */ -// error AccountingExtension_UnauthorizedModule(); - -// /** -// * @notice Thrown when an `onlyParticipant` function is called with an address -// * that is not part of the request. -// */ -// error AccountingExtension_UnauthorizedUser(); - -// /*/////////////////////////////////////////////////////////////// -// VARIABLES -// //////////////////////////////////////////////////////////////*/ - -// /** -// * @notice Returns the interface for the Oracle contract -// */ -// function ORACLE() external view returns (IOracle _oracle); - -// /** -// * @notice Returns the amount of a token a user has bonded -// * @param _user The address of the user with bonded tokens -// * @param _bondToken The token bonded -// * @param _requestId The id of the request the user bonded for -// * @return _amount The amount of `_bondToken` bonded -// */ -// function bondedAmountOf(address _user, IERC20 _bondToken, bytes32 _requestId) external returns (uint256 _amount); - -// /** -// * @notice Returns the amount of a token a user has deposited -// * @param _user The address of the user with deposited tokens -// * @param _token The token deposited -// * @return _amount The amount of `_token` deposited -// */ -// function balanceOf(address _user, IERC20 _token) external view returns (uint256 _amount); - -// /*/////////////////////////////////////////////////////////////// -// LOGIC -// //////////////////////////////////////////////////////////////*/ - -// /** -// * @notice Transfers tokens from a user and updates his virtual balance -// * @dev The user must have approved the accounting extension to transfer the tokens. -// * @param _token The address of the token being deposited -// * @param _amount The amount of `_token` to deposit -// */ -// function deposit(IERC20 _token, uint256 _amount) external; - -// /** -// * @notice Allows an user to withdraw deposited tokens -// * @param _token The address of the token being withdrawn -// * @param _amount The amount of `_token` to withdraw -// */ -// function withdraw(IERC20 _token, uint256 _amount) external; - -// /** -// * @notice Allows a allowed module to transfer bonded tokens from one user to another -// * @dev Only the virtual balances in the accounting extension are modified. The token contract -// * is not called nor its balances modified. -// * @param _requestId The id of the request handling the user's tokens -// * @param _payer The address of the user paying the tokens -// * @param _receiver The address of the user receiving the tokens -// * @param _token The address of the token being transferred -// * @param _amount The amount of `_token` being transferred -// */ -// function pay(bytes32 _requestId, address _payer, address _receiver, IERC20 _token, 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 _token The address of the token being bonded -// * @param _amount The amount of `_token` to bond -// */ -// function bond(address _bonder, bytes32 _requestId, IERC20 _token, uint256 _amount) external; - -// /** -// * @notice Allows a valid 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 _token The address of the token being bonded -// * @param _amount The amount of `_token` to bond -// * @param _sender The address starting the propose call on the Oracle -// */ -// function bond(address _bonder, bytes32 _requestId, IERC20 _token, 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 _token The address of the token being released -// * @param _amount The amount of `_token` to release -// */ -// function release(address _bonder, bytes32 _requestId, IERC20 _token, uint256 _amount) external; - -// /** -// * @notice Allows a user to approve a module for bonding tokens -// * @param _module The address of the module to be approved -// */ -// function approveModule(address _module) external; - -// /** -// * @notice Allows a user to revoke a module's approval for bonding tokens -// * @param _module The address of the module to be revoked -// */ -// function revokeModule(address _module) external; - -// /** -// * @notice Returns a list of all modules a user has approved -// * @param _user The address of the user -// * @return _approvedModules The array of all modules approved by the user -// */ -// function approvedModules(address _user) external view returns (address[] memory _approvedModules); -// } +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.19; + +import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol'; +import {IOracle} from '@defi-wonderland/prophet-core-contracts/solidity/interfaces/IOracle.sol'; + +/* + * @title AccountingExtension + * @notice Extension allowing users to deposit and bond funds + * to be used for payments and disputes. + */ +interface IAccountingExtension { + /*/////////////////////////////////////////////////////////////// + EVENTS + //////////////////////////////////////////////////////////////*/ + + /** + * @notice A user deposited tokens into the accounting extension + * @param _depositor The user who deposited the tokens + * @param _token The address of the token deposited by the user + * @param _amount The amount of `_token` deposited + */ + event Deposited(address indexed _depositor, IERC20 indexed _token, uint256 _amount); + + /** + * @notice A user withdrew tokens from the accounting extension + * @param _withdrawer The user who withdrew the tokens + * @param _token The address of the token withdrawn by the user + * @param _amount The amount of `_token` withdrawn + */ + event Withdrew(address indexed _withdrawer, IERC20 indexed _token, uint256 _amount); + + /** + * @notice A payment between users has been made + * @param _beneficiary The user receiving the tokens + * @param _payer The user who is getting its tokens transferred + * @param _token The address of the token being transferred + * @param _amount The amount of `_token` transferred + */ + event Paid( + bytes32 indexed _requestId, address indexed _beneficiary, address indexed _payer, IERC20 _token, uint256 _amount + ); + + /** + * @notice User's funds have been bonded + * @param _bonder The user who is getting its tokens bonded + * @param _token The address of the token being bonded + * @param _amount The amount of `_token` bonded + */ + event Bonded(bytes32 indexed _requestId, address indexed _bonder, IERC20 indexed _token, uint256 _amount); + + /** + * @notice User's funds have been released + * @param _beneficiary The user who is getting its tokens released + * @param _token The address of the token being released + * @param _amount The amount of `_token` released + */ + event Released(bytes32 indexed _requestId, address indexed _beneficiary, IERC20 indexed _token, uint256 _amount); + + /*/////////////////////////////////////////////////////////////// + ERRORS + //////////////////////////////////////////////////////////////*/ + + /** + * @notice Thrown when the account doesn't have enough balance to bond/withdraw + * or not enough bonded to release/pay + */ + error AccountingExtension_InsufficientFunds(); + + /** + * @notice Thrown when the module bonding user tokens hasn't been approved by the user. + */ + error AccountingExtension_InsufficientAllowance(); + + /** + * @notice Thrown when an `onlyAllowedModule` function is called by something + * else than a module being used in the corresponding request + */ + error AccountingExtension_UnauthorizedModule(); + + /** + * @notice Thrown when an `onlyParticipant` function is called with an address + * that is not part of the request. + */ + error AccountingExtension_UnauthorizedUser(); + + /*/////////////////////////////////////////////////////////////// + VARIABLES + //////////////////////////////////////////////////////////////*/ + + /** + * @notice Returns the interface for the Oracle contract + */ + function ORACLE() external view returns (IOracle _oracle); + + /** + * @notice Returns the amount of a token a user has bonded + * @param _user The address of the user with bonded tokens + * @param _bondToken The token bonded + * @param _requestId The id of the request the user bonded for + * @return _amount The amount of `_bondToken` bonded + */ + function bondedAmountOf(address _user, IERC20 _bondToken, bytes32 _requestId) external returns (uint256 _amount); + + /** + * @notice Returns the amount of a token a user has deposited + * @param _user The address of the user with deposited tokens + * @param _token The token deposited + * @return _amount The amount of `_token` deposited + */ + function balanceOf(address _user, IERC20 _token) external view returns (uint256 _amount); + + /*/////////////////////////////////////////////////////////////// + LOGIC + //////////////////////////////////////////////////////////////*/ + + /** + * @notice Transfers tokens from a user and updates his virtual balance + * @dev The user must have approved the accounting extension to transfer the tokens. + * @param _token The address of the token being deposited + * @param _amount The amount of `_token` to deposit + */ + function deposit(IERC20 _token, uint256 _amount) external; + + /** + * @notice Allows an user to withdraw deposited tokens + * @param _token The address of the token being withdrawn + * @param _amount The amount of `_token` to withdraw + */ + function withdraw(IERC20 _token, uint256 _amount) external; + + /** + * @notice Allows a allowed module to transfer bonded tokens from one user to another + * @dev Only the virtual balances in the accounting extension are modified. The token contract + * is not called nor its balances modified. + * @param _requestId The id of the request handling the user's tokens + * @param _payer The address of the user paying the tokens + * @param _receiver The address of the user receiving the tokens + * @param _token The address of the token being transferred + * @param _amount The amount of `_token` being transferred + */ + function pay(bytes32 _requestId, address _payer, address _receiver, IERC20 _token, 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 _token The address of the token being bonded + * @param _amount The amount of `_token` to bond + */ + function bond(address _bonder, bytes32 _requestId, IERC20 _token, uint256 _amount) external; + + /** + * @notice Allows a valid 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 _token The address of the token being bonded + * @param _amount The amount of `_token` to bond + * @param _sender The address starting the propose call on the Oracle + */ + function bond(address _bonder, bytes32 _requestId, IERC20 _token, 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 _token The address of the token being released + * @param _amount The amount of `_token` to release + */ + function release(address _bonder, bytes32 _requestId, IERC20 _token, uint256 _amount) external; + + /** + * @notice Allows a user to approve a module for bonding tokens + * @param _module The address of the module to be approved + */ + function approveModule(address _module) external; + + /** + * @notice Allows a user to revoke a module's approval for bonding tokens + * @param _module The address of the module to be revoked + */ + function revokeModule(address _module) external; + + /** + * @notice Returns a list of all modules a user has approved + * @param _user The address of the user + * @return _approvedModules The array of all modules approved by the user + */ + function approvedModules(address _user) external view returns (address[] memory _approvedModules); +} diff --git a/solidity/interfaces/extensions/IBondEscalationAccounting.sol b/solidity/interfaces/extensions/IBondEscalationAccounting.sol index 6dbec948..ce7728c9 100644 --- a/solidity/interfaces/extensions/IBondEscalationAccounting.sol +++ b/solidity/interfaces/extensions/IBondEscalationAccounting.sol @@ -1,240 +1,240 @@ -// // SPDX-License-Identifier: AGPL-3.0-only -// pragma solidity ^0.8.19; - -// import {IAccountingExtension} from './IAccountingExtension.sol'; -// import {IBondEscalationModule} from '../modules/dispute/IBondEscalationModule.sol'; -// import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol'; - -// /** -// * @title BondEscalationAccounting -// * @notice Extension allowing users to deposit and pledge funds to be used for bond escalation -// */ -// interface IBondEscalationAccounting is IAccountingExtension { -// /*/////////////////////////////////////////////////////////////// -// EVENTS -// //////////////////////////////////////////////////////////////*/ - -// /** -// * @notice A user pledged tokens for one of the sides of a dispute -// * -// * @param _pledger The user who pledged the tokens -// * @param _requestId The ID of the bond-escalated request -// * @param _disputeId The ID of the bond-escalated dispute -// * @param _token The address of the token being pledged -// * @param _amount The amount of `_token` pledged by the user -// */ -// event Pledged( -// address indexed _pledger, bytes32 indexed _requestId, bytes32 indexed _disputeId, IERC20 _token, uint256 _amount -// ); - -// /** -// * @notice The pledgers of the winning side of a dispute have been paid -// * -// * @param _requestId The ID of the bond-escalated request -// * @param _disputeId The ID of the bond-escalated dispute -// * @param _winningPledgers The users who got paid for pledging for the winning side -// * @param _token The address of the token being paid out -// * @param _amountPerPledger The amount of `_token` paid to each of the winning pledgers -// */ -// event WinningPledgersPaid( -// bytes32 indexed _requestId, -// bytes32 indexed _disputeId, -// address[] indexed _winningPledgers, -// IERC20 _token, -// uint256 _amountPerPledger -// ); - -// /** -// * @notice A bond escalation has been settled -// * -// * @param _requestId The ID of the bond-escalated request -// * @param _disputeId The ID of the bond-escalated dispute -// * @param _forVotesWon True if the winning side were the for votes -// * @param _token The address of the token being paid out -// * @param _amountPerPledger The amount of `_token` to be paid for each winning pledgers -// * @param _winningPledgersLength The number of winning pledgers -// */ -// event BondEscalationSettled( -// bytes32 _requestId, -// bytes32 _disputeId, -// bool _forVotesWon, -// IERC20 _token, -// uint256 _amountPerPledger, -// uint256 _winningPledgersLength -// ); - -// /** -// * @notice A pledge has been released back to the user -// * -// * @param _requestId The ID of the bond-escalated request -// * @param _disputeId The ID of the bond-escalated dispute -// * @param _pledger The user who is getting their tokens released -// * @param _token The address of the token being released -// * @param _amount The amount of `_token` released -// */ -// event PledgeReleased( -// bytes32 indexed _requestId, bytes32 indexed _disputeId, address indexed _pledger, IERC20 _token, uint256 _amount -// ); - -// /** -// * @notice A user claimed their reward for pledging for the winning side of a dispute -// * -// * @param _requestId The ID of the bond-escalated request -// * @param _disputeId The ID of the bond-escalated dispute -// * @param _pledger The user who claimed their reward -// * @param _token The address of the token being paid out -// * @param _amount The amount of `_token` paid to the pledger -// */ -// event EscalationRewardClaimed( -// bytes32 indexed _requestId, bytes32 indexed _disputeId, address indexed _pledger, IERC20 _token, uint256 _amount -// ); - -// /*/////////////////////////////////////////////////////////////// -// STRUCTS -// //////////////////////////////////////////////////////////////*/ - -// /** -// * @notice Contains the data of the result of an escalation. Is used by users to claim their pledges -// * @param requestId The ID of the bond-escalated request -// * @param forVotesWon Whether the for votes won the dispute -// * @param token The address of the token being paid out -// * @param amountPerPledger The amount of token paid to each of the winning pledgers -// * @param bondEscalationModule The address of the bond escalation module that was used -// */ -// struct EscalationResult { -// bytes32 requestId; -// bool forVotesWon; -// IERC20 token; -// uint256 amountPerPledger; -// IBondEscalationModule bondEscalationModule; -// } - -// /*/////////////////////////////////////////////////////////////// -// ERRORS -// //////////////////////////////////////////////////////////////*/ - -// /** -// * @notice Thrown when the user tries to claim their pledge for an escalation that was already claimed -// */ -// error BondEscalationAccounting_AlreadyClaimed(); - -// /** -// * @notice Thrown when the user tries to claim their pledge for an escalation that wasn't finished yet -// */ -// error BondEscalationAccounting_NoEscalationResult(); - -// /** -// * @notice Thrown when the user doesn't have enough funds to pledge -// */ -// error BondEscalationAccounting_InsufficientFunds(); - -// /** -// * @notice Thrown when trying to settle an already settled escalation -// */ -// error BondEscalationAccounting_AlreadySettled(); - -// /*/////////////////////////////////////////////////////////////// -// VARIABLES -// //////////////////////////////////////////////////////////////*/ - -// /** -// * @notice The amount pledged by the given pledger in the given dispute of the given request -// * -// * @param _disputeId The ID of the bond-escalated dispute -// * @param _token Address of the token being pledged -// * @return _amountPledged The amount of pledged tokens -// */ -// function pledges(bytes32 _disputeId, IERC20 _token) external returns (uint256 _amountPledged); - -// /** -// * @notice The result of the given dispute -// * -// * @param _disputeId The ID of the bond-escalated dispute -// * @return _requestId The ID of the bond-escalated request -// * @return _forVotesWon True if the for votes won the dispute -// * @return _token Address of the token being paid as a reward for winning the bond escalation -// * @return _amountPerPledger Amount of `_token` to be rewarded to each of the winning pledgers -// * @return _bondEscalationModule The address of the bond escalation module that was used -// */ -// function escalationResults(bytes32 _disputeId) -// external -// returns ( -// bytes32 _requestId, -// bool _forVotesWon, -// IERC20 _token, -// uint256 _amountPerPledger, -// IBondEscalationModule _bondEscalationModule -// ); - -// /** -// * @notice True if the given pledger has claimed their reward for the given dispute -// * -// * @param _requestId The ID of the bond-escalated request -// * @param _pledger Address of the pledger -// * @return _claimed True if the pledger has claimed their reward -// */ -// function pledgerClaimed(bytes32 _requestId, address _pledger) external returns (bool _claimed); - -// /*/////////////////////////////////////////////////////////////// -// LOGIC -// //////////////////////////////////////////////////////////////*/ - -// /** -// * @notice Pledges the given amount of token to the provided dispute id of the provided request id -// * -// * @dev This function must be called by an allowed module -// * -// * @param _pledger Address of the pledger -// * @param _requestId The ID of the bond-escalated request -// * @param _disputeId The ID of the bond-escalated dispute -// * @param _token Address of the token being paid as a reward for winning the bond escalation -// * @param _amount Amount of token to pledge -// */ -// function pledge(address _pledger, bytes32 _requestId, bytes32 _disputeId, IERC20 _token, uint256 _amount) external; - -// /** -// * @notice Updates the accounting of the given dispute to reflect the result of the bond escalation -// * @dev This function must be called by an allowed module -// * -// * @param _requestId The ID of the bond-escalated request -// * @param _disputeId The ID of the bond-escalated dispute -// * @param _forVotesWon True if the for votes won the dispute -// * @param _token Address of the token being paid as a reward for winning the bond escalation -// * @param _amountPerPledger Amount of `_token` to be rewarded to each of the winning pledgers -// * @param _winningPledgersLength Amount of pledges that won the dispute -// */ -// function onSettleBondEscalation( -// bytes32 _requestId, -// bytes32 _disputeId, -// bool _forVotesWon, -// IERC20 _token, -// uint256 _amountPerPledger, -// uint256 _winningPledgersLength -// ) external; - -// /** -// * @notice Releases a given amount of funds to the pledger -// * -// * @dev This function must be called by an allowed module -// * -// * @param _requestId The ID of the bond-escalated request -// * @param _disputeId The ID of the bond-escalated dispute -// * @param _pledger Address of the pledger -// * @param _token Address of the token to be released -// * @param _amount Amount of `_token` to be released to the pledger -// */ -// function releasePledge( -// bytes32 _requestId, -// bytes32 _disputeId, -// address _pledger, -// IERC20 _token, -// uint256 _amount -// ) external; - -// /** -// * @notice Claims the reward for the pledger the given dispute -// * @param _disputeId The ID of the bond-escalated dispute -// * @param _pledger Address of the pledger to claim the rewards -// */ -// function claimEscalationReward(bytes32 _disputeId, address _pledger) external; -// } +// SPDX-License-Identifier: AGPL-3.0-only +pragma solidity ^0.8.19; + +import {IAccountingExtension} from './IAccountingExtension.sol'; +import {IBondEscalationModule} from '../modules/dispute/IBondEscalationModule.sol'; +import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol'; + +/** + * @title BondEscalationAccounting + * @notice Extension allowing users to deposit and pledge funds to be used for bond escalation + */ +interface IBondEscalationAccounting is IAccountingExtension { + /*/////////////////////////////////////////////////////////////// + EVENTS + //////////////////////////////////////////////////////////////*/ + + /** + * @notice A user pledged tokens for one of the sides of a dispute + * + * @param _pledger The user who pledged the tokens + * @param _requestId The ID of the bond-escalated request + * @param _disputeId The ID of the bond-escalated dispute + * @param _token The address of the token being pledged + * @param _amount The amount of `_token` pledged by the user + */ + event Pledged( + address indexed _pledger, bytes32 indexed _requestId, bytes32 indexed _disputeId, IERC20 _token, uint256 _amount + ); + + /** + * @notice The pledgers of the winning side of a dispute have been paid + * + * @param _requestId The ID of the bond-escalated request + * @param _disputeId The ID of the bond-escalated dispute + * @param _winningPledgers The users who got paid for pledging for the winning side + * @param _token The address of the token being paid out + * @param _amountPerPledger The amount of `_token` paid to each of the winning pledgers + */ + event WinningPledgersPaid( + bytes32 indexed _requestId, + bytes32 indexed _disputeId, + address[] indexed _winningPledgers, + IERC20 _token, + uint256 _amountPerPledger + ); + + /** + * @notice A bond escalation has been settled + * + * @param _requestId The ID of the bond-escalated request + * @param _disputeId The ID of the bond-escalated dispute + * @param _forVotesWon True if the winning side were the for votes + * @param _token The address of the token being paid out + * @param _amountPerPledger The amount of `_token` to be paid for each winning pledgers + * @param _winningPledgersLength The number of winning pledgers + */ + event BondEscalationSettled( + bytes32 _requestId, + bytes32 _disputeId, + bool _forVotesWon, + IERC20 _token, + uint256 _amountPerPledger, + uint256 _winningPledgersLength + ); + + /** + * @notice A pledge has been released back to the user + * + * @param _requestId The ID of the bond-escalated request + * @param _disputeId The ID of the bond-escalated dispute + * @param _pledger The user who is getting their tokens released + * @param _token The address of the token being released + * @param _amount The amount of `_token` released + */ + event PledgeReleased( + bytes32 indexed _requestId, bytes32 indexed _disputeId, address indexed _pledger, IERC20 _token, uint256 _amount + ); + + /** + * @notice A user claimed their reward for pledging for the winning side of a dispute + * + * @param _requestId The ID of the bond-escalated request + * @param _disputeId The ID of the bond-escalated dispute + * @param _pledger The user who claimed their reward + * @param _token The address of the token being paid out + * @param _amount The amount of `_token` paid to the pledger + */ + event EscalationRewardClaimed( + bytes32 indexed _requestId, bytes32 indexed _disputeId, address indexed _pledger, IERC20 _token, uint256 _amount + ); + + /*/////////////////////////////////////////////////////////////// + STRUCTS + //////////////////////////////////////////////////////////////*/ + + /** + * @notice Contains the data of the result of an escalation. Is used by users to claim their pledges + * @param requestId The ID of the bond-escalated request + * @param forVotesWon Whether the for votes won the dispute + * @param token The address of the token being paid out + * @param amountPerPledger The amount of token paid to each of the winning pledgers + * @param bondEscalationModule The address of the bond escalation module that was used + */ + struct EscalationResult { + bytes32 requestId; + bool forVotesWon; + IERC20 token; + uint256 amountPerPledger; + IBondEscalationModule bondEscalationModule; + } + + /*/////////////////////////////////////////////////////////////// + ERRORS + //////////////////////////////////////////////////////////////*/ + + /** + * @notice Thrown when the user tries to claim their pledge for an escalation that was already claimed + */ + error BondEscalationAccounting_AlreadyClaimed(); + + /** + * @notice Thrown when the user tries to claim their pledge for an escalation that wasn't finished yet + */ + error BondEscalationAccounting_NoEscalationResult(); + + /** + * @notice Thrown when the user doesn't have enough funds to pledge + */ + error BondEscalationAccounting_InsufficientFunds(); + + /** + * @notice Thrown when trying to settle an already settled escalation + */ + error BondEscalationAccounting_AlreadySettled(); + + /*/////////////////////////////////////////////////////////////// + VARIABLES + //////////////////////////////////////////////////////////////*/ + + /** + * @notice The amount pledged by the given pledger in the given dispute of the given request + * + * @param _disputeId The ID of the bond-escalated dispute + * @param _token Address of the token being pledged + * @return _amountPledged The amount of pledged tokens + */ + function pledges(bytes32 _disputeId, IERC20 _token) external returns (uint256 _amountPledged); + + /** + * @notice The result of the given dispute + * + * @param _disputeId The ID of the bond-escalated dispute + * @return _requestId The ID of the bond-escalated request + * @return _forVotesWon True if the for votes won the dispute + * @return _token Address of the token being paid as a reward for winning the bond escalation + * @return _amountPerPledger Amount of `_token` to be rewarded to each of the winning pledgers + * @return _bondEscalationModule The address of the bond escalation module that was used + */ + function escalationResults(bytes32 _disputeId) + external + returns ( + bytes32 _requestId, + bool _forVotesWon, + IERC20 _token, + uint256 _amountPerPledger, + IBondEscalationModule _bondEscalationModule + ); + + /** + * @notice True if the given pledger has claimed their reward for the given dispute + * + * @param _requestId The ID of the bond-escalated request + * @param _pledger Address of the pledger + * @return _claimed True if the pledger has claimed their reward + */ + function pledgerClaimed(bytes32 _requestId, address _pledger) external returns (bool _claimed); + + /*/////////////////////////////////////////////////////////////// + LOGIC + //////////////////////////////////////////////////////////////*/ + + /** + * @notice Pledges the given amount of token to the provided dispute id of the provided request id + * + * @dev This function must be called by an allowed module + * + * @param _pledger Address of the pledger + * @param _requestId The ID of the bond-escalated request + * @param _disputeId The ID of the bond-escalated dispute + * @param _token Address of the token being paid as a reward for winning the bond escalation + * @param _amount Amount of token to pledge + */ + function pledge(address _pledger, bytes32 _requestId, bytes32 _disputeId, IERC20 _token, uint256 _amount) external; + + /** + * @notice Updates the accounting of the given dispute to reflect the result of the bond escalation + * @dev This function must be called by an allowed module + * + * @param _requestId The ID of the bond-escalated request + * @param _disputeId The ID of the bond-escalated dispute + * @param _forVotesWon True if the for votes won the dispute + * @param _token Address of the token being paid as a reward for winning the bond escalation + * @param _amountPerPledger Amount of `_token` to be rewarded to each of the winning pledgers + * @param _winningPledgersLength Amount of pledges that won the dispute + */ + function onSettleBondEscalation( + bytes32 _requestId, + bytes32 _disputeId, + bool _forVotesWon, + IERC20 _token, + uint256 _amountPerPledger, + uint256 _winningPledgersLength + ) external; + + /** + * @notice Releases a given amount of funds to the pledger + * + * @dev This function must be called by an allowed module + * + * @param _requestId The ID of the bond-escalated request + * @param _disputeId The ID of the bond-escalated dispute + * @param _pledger Address of the pledger + * @param _token Address of the token to be released + * @param _amount Amount of `_token` to be released to the pledger + */ + function releasePledge( + bytes32 _requestId, + bytes32 _disputeId, + address _pledger, + IERC20 _token, + uint256 _amount + ) external; + + /** + * @notice Claims the reward for the pledger the given dispute + * @param _disputeId The ID of the bond-escalated dispute + * @param _pledger Address of the pledger to claim the rewards + */ + function claimEscalationReward(bytes32 _disputeId, address _pledger) external; +} diff --git a/solidity/interfaces/modules/dispute/IBondEscalationModule.sol b/solidity/interfaces/modules/dispute/IBondEscalationModule.sol index 4b511fc8..20463e01 100644 --- a/solidity/interfaces/modules/dispute/IBondEscalationModule.sol +++ b/solidity/interfaces/modules/dispute/IBondEscalationModule.sol @@ -1,275 +1,264 @@ -// // SPDX-License-Identifier: AGPL-3.0-only -// pragma solidity ^0.8.19; +// SPDX-License-Identifier: AGPL-3.0-only +pragma solidity ^0.8.19; -// import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol'; -// import {IOracle} from '@defi-wonderland/prophet-core-contracts/solidity/interfaces/IOracle.sol'; -// import {IDisputeModule} from -// '@defi-wonderland/prophet-core-contracts/solidity/interfaces/modules/dispute/IDisputeModule.sol'; +import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol'; +import {IOracle} from '@defi-wonderland/prophet-core-contracts/solidity/interfaces/IOracle.sol'; +import {IDisputeModule} from + '@defi-wonderland/prophet-core-contracts/solidity/interfaces/modules/dispute/IDisputeModule.sol'; -// import {IBondEscalationAccounting} from '../../extensions/IBondEscalationAccounting.sol'; +import {IBondEscalationAccounting} from '../../extensions/IBondEscalationAccounting.sol'; -// /** -// * @title BondEscalationModule -// * @notice Module allowing users to have the first dispute of a request go through the bond escalation mechanism. -// */ -// interface IBondEscalationModule is IDisputeModule { -// /*/////////////////////////////////////////////////////////////// -// EVENTS -// //////////////////////////////////////////////////////////////*/ +/** + * @title BondEscalationModule + * @notice Module allowing users to have the first dispute of a request go through the bond escalation mechanism. + */ +interface IBondEscalationModule is IDisputeModule { + /*/////////////////////////////////////////////////////////////// + EVENTS + //////////////////////////////////////////////////////////////*/ -// /** -// * @notice A pledge has been made in favor of a dispute. -// * -// * @param _disputeId The id of the dispute the pledger is pledging in favor of. -// * @param _pledger The address of the pledger. -// * @param _amount The amount pledged. -// */ -// event PledgedForDispute(bytes32 indexed _disputeId, address indexed _pledger, uint256 indexed _amount); + /** + * @notice A pledge has been made in favor of a dispute. + * + * @param _disputeId The id of the dispute the pledger is pledging in favor of. + * @param _pledger The address of the pledger. + * @param _amount The amount pledged. + */ + event PledgedForDispute(bytes32 indexed _disputeId, address indexed _pledger, uint256 indexed _amount); -// /** -// * @notice A pledge has been made against a dispute. -// * -// * @param _disputeId The id of the dispute the pledger is pledging against. -// * @param _pledger The address of the pledger. -// * @param _amount The amount pledged. -// */ -// event PledgedAgainstDispute(bytes32 indexed _disputeId, address indexed _pledger, uint256 indexed _amount); + /** + * @notice A pledge has been made against a dispute. + * + * @param _disputeId The id of the dispute the pledger is pledging against. + * @param _pledger The address of the pledger. + * @param _amount The amount pledged. + */ + event PledgedAgainstDispute(bytes32 indexed _disputeId, address indexed _pledger, uint256 indexed _amount); -// /** -// * @notice The status of the bond escalation mechanism has been updated. -// * -// * @param _requestId The id of the request associated with the bond escalation mechanism. -// * @param _disputeId The id of the dispute going through the bond escalation mechanism. -// * @param _status The new status. -// */ -// event BondEscalationStatusUpdated( -// bytes32 indexed _requestId, bytes32 indexed _disputeId, BondEscalationStatus _status -// ); + /** + * @notice The status of the bond escalation mechanism has been updated. + * + * @param _requestId The id of the request associated with the bond escalation mechanism. + * @param _disputeId The id of the dispute going through the bond escalation mechanism. + * @param _status The new status. + */ + event BondEscalationStatusUpdated( + bytes32 indexed _requestId, bytes32 indexed _disputeId, BondEscalationStatus _status + ); -// /*/////////////////////////////////////////////////////////////// -// ERRORS -// //////////////////////////////////////////////////////////////*/ + /*/////////////////////////////////////////////////////////////// + ERRORS + //////////////////////////////////////////////////////////////*/ -// /** -// * @notice Thrown when trying to escalate a dispute going through the bond escalation module before its deadline. -// */ -// error BondEscalationModule_BondEscalationNotOver(); -// /** -// * @notice Thrown when trying to pledge for a dispute that is not going through the bond escalation mechanism. -// */ -// error BondEscalationModule_InvalidDispute(); -// /** -// * @notice Thrown when the number of escalation pledges of a given dispute has reached its maximum. -// */ -// error BondEscalationModule_MaxNumberOfEscalationsReached(); -// /** -// * @notice Thrown when trying to settle a dispute that went through the bond escalation when it's not active. -// */ -// error BondEscalationModule_BondEscalationCantBeSettled(); -// /** -// * @notice Thrown when trying to settle a bond escalation process that is not tied. -// */ -// error BondEscalationModule_ShouldBeEscalated(); -// /** -// * @notice Thrown when trying to break a tie after the tying buffer has started. -// */ -// error BondEscalationModule_CannotBreakTieDuringTyingBuffer(); -// /** -// * @notice Thrown when the max number of escalations or the bond size is set to 0. -// */ -// error BondEscalationModule_ZeroValue(); -// /** -// * @notice Thrown when trying to pledge after the bond escalation deadline. -// */ -// error BondEscalationModule_BondEscalationOver(); -// /** -// * @notice Thrown when trying to escalate a dispute going through the bond escalation process that is not tied -// * or that is not active. -// */ -// error BondEscalationModule_NotEscalatable(); -// /** -// * @notice Thrown when trying to pledge for a dispute that does not exist -// */ -// error BondEscalationModule_DisputeDoesNotExist(); -// /** -// * @notice Thrown when trying to surpass the number of pledges of the other side by more than 1 in the bond escalation mechanism. -// */ -// error BondEscalationModule_CanOnlySurpassByOnePledge(); -// /** -// * @notice Thrown when trying to dispute a response after the dispute period expired. -// */ -// error BondEscalationModule_DisputeWindowOver(); -// /** -// * @notice Thrown when trying to set up a request with invalid bond size or maximum amount of escalations. -// */ -// error BondEscalationModule_InvalidEscalationParameters(); + /** + * @notice Thrown when trying to escalate a dispute going through the bond escalation module before its deadline. + */ + error BondEscalationModule_BondEscalationNotOver(); + /** + * @notice Thrown when trying to pledge for a dispute that is not going through the bond escalation mechanism. + */ + error BondEscalationModule_InvalidDispute(); + /** + * @notice Thrown when the number of escalation pledges of a given dispute has reached its maximum. + */ + error BondEscalationModule_MaxNumberOfEscalationsReached(); + /** + * @notice Thrown when trying to settle a dispute that went through the bond escalation when it's not active. + */ + error BondEscalationModule_BondEscalationCantBeSettled(); + /** + * @notice Thrown when trying to settle a bond escalation process that is not tied. + */ + error BondEscalationModule_ShouldBeEscalated(); + /** + * @notice Thrown when trying to break a tie after the tying buffer has started. + */ + error BondEscalationModule_CannotBreakTieDuringTyingBuffer(); + /** + * @notice Thrown when the max number of escalations or the bond size is set to 0. + */ + error BondEscalationModule_ZeroValue(); + /** + * @notice Thrown when trying to pledge after the bond escalation deadline. + */ + error BondEscalationModule_BondEscalationOver(); + /** + * @notice Thrown when trying to escalate a dispute going through the bond escalation process that is not tied + * or that is not active. + */ + error BondEscalationModule_NotEscalatable(); + /** + * @notice Thrown when trying to pledge for a dispute that does not exist + */ + error BondEscalationModule_DisputeDoesNotExist(); + /** + * @notice Thrown when trying to surpass the number of pledges of the other side by more than 1 in the bond escalation mechanism. + */ + error BondEscalationModule_CanOnlySurpassByOnePledge(); + /** + * @notice Thrown when trying to dispute a response after the dispute period expired. + */ + error BondEscalationModule_DisputeWindowOver(); + /** + * @notice Thrown when trying to set up a request with invalid bond size or maximum amount of escalations. + */ + error BondEscalationModule_InvalidEscalationParameters(); -// /*/////////////////////////////////////////////////////////////// -// ENUMS -// //////////////////////////////////////////////////////////////*/ + /*/////////////////////////////////////////////////////////////// + ENUMS + //////////////////////////////////////////////////////////////*/ -// /** -// * @notice Enum holding all the possible statuses of a dispute going through the bond escalation mechanism. -// */ -// enum BondEscalationStatus { -// None, // Dispute is not going through the bond escalation mechanism. -// Active, // Dispute is going through the bond escalation mechanism. -// Escalated, // Dispute is going through the bond escalation mechanism and has been escalated. -// DisputerLost, // An escalated dispute has been settled and the disputer lost. -// DisputerWon // An escalated dispute has been settled and the disputer won. -// } + /** + * @notice Enum holding all the possible statuses of a dispute going through the bond escalation mechanism. + */ + enum BondEscalationStatus { + None, // Dispute is not going through the bond escalation mechanism. + Active, // Dispute is going through the bond escalation mechanism. + Escalated, // Dispute is going through the bond escalation mechanism and has been escalated. + DisputerLost, // An escalated dispute has been settled and the disputer lost. + DisputerWon // An escalated dispute has been settled and the disputer won. + } -// /*/////////////////////////////////////////////////////////////// -// STRUCTS -// //////////////////////////////////////////////////////////////*/ + /*/////////////////////////////////////////////////////////////// + STRUCTS + //////////////////////////////////////////////////////////////*/ -// /** -// * @notice Parameters of the request as stored in the module -// * -// * @param _accountingExtension Address of the accounting extension associated with the given request -// * @param _bondToken Address of the token associated with the given request -// * @param _bondSize Amount to bond to dispute or propose an answer for the given request -// * @param _numberOfEscalations Maximum allowed escalations or pledges for each side during the bond escalation process -// * @param _bondEscalationDeadline Timestamp at which bond escalation process finishes when pledges are not tied -// * @param _tyingBuffer Number of seconds to extend the bond escalation process to allow the losing -// * party to tie if at the end of the initial deadline the pledges weren't tied. -// * @param _disputeWindow Number of seconds disputers have to challenge the proposed response since its creation. -// */ -// struct RequestParameters { -// IBondEscalationAccounting accountingExtension; -// IERC20 bondToken; -// uint256 bondSize; -// uint256 maxNumberOfEscalations; -// uint256 bondEscalationDeadline; -// uint256 tyingBuffer; -// uint256 disputeWindow; -// } + /** + * @notice Parameters of the request as stored in the module + * + * @param _accountingExtension Address of the accounting extension associated with the given request + * @param _bondToken Address of the token associated with the given request + * @param _bondSize Amount to bond to dispute or propose an answer for the given request + * @param _numberOfEscalations Maximum allowed escalations or pledges for each side during the bond escalation process + * @param _bondEscalationDeadline Timestamp at which bond escalation process finishes when pledges are not tied + * @param _tyingBuffer Number of seconds to extend the bond escalation process to allow the losing + * party to tie if at the end of the initial deadline the pledges weren't tied. + * @param _disputeWindow Number of seconds disputers have to challenge the proposed response since its creation. + */ + struct RequestParameters { + IBondEscalationAccounting accountingExtension; + IERC20 bondToken; + uint256 bondSize; + uint256 maxNumberOfEscalations; + uint256 bondEscalationDeadline; + uint256 tyingBuffer; + uint256 disputeWindow; + } -// /** -// * @notice Data of a dispute going through the bond escalation. -// * -// * @param disputeId The id of the dispute being bond-escalated. -// * @param status The status of the bond escalation. -// * @param amountOfPledgesForDispute The amount of pledges made in favor of the dispute. -// * @param amountOfPledgesAgainstDispute The amount of pledges made against the dispute. -// */ -// struct BondEscalation { -// bytes32 disputeId; -// BondEscalationStatus status; -// uint256 amountOfPledgesForDispute; -// uint256 amountOfPledgesAgainstDispute; -// } + /** + * @notice Data of a dispute going through the bond escalation. + * + * @param disputeId The id of the dispute being bond-escalated. + * @param status The status of the bond escalation. + * @param amountOfPledgesForDispute The amount of pledges made in favor of the dispute. + * @param amountOfPledgesAgainstDispute The amount of pledges made against the dispute. + */ + struct BondEscalation { + bytes32 disputeId; + BondEscalationStatus status; + uint256 amountOfPledgesForDispute; + uint256 amountOfPledgesAgainstDispute; + } -// /*/////////////////////////////////////////////////////////////// -// VARIABLES -// //////////////////////////////////////////////////////////////*/ + /*/////////////////////////////////////////////////////////////// + VARIABLES + //////////////////////////////////////////////////////////////*/ -// /** -// * @notice Returns the escalation data for a request. -// * @param _requestId The id of the request to get its escalation data. -// * @return _escalation The struct containing the escalation data. -// */ -// function getEscalation(bytes32 _requestId) external view returns (BondEscalation memory _escalation); + /** + * @notice Returns the escalation data for a request. + * @param _requestId The id of the request to get its escalation data. + * @return _escalation The struct containing the escalation data. + */ + function getEscalation(bytes32 _requestId) external view returns (BondEscalation memory _escalation); -// /** -// * @notice Decodes the request data associated with a request id. -// * @param _requestId The id of the request to decode. -// * @return _params The struct containing the parameters for the request -// */ -// function decodeRequestData(bytes32 _requestId) external view returns (RequestParameters memory _params); + /** + * @notice Returns the decoded data for a request + * @param _data The encoded request parameters + * @return _params The struct containing the parameters for the request + */ + function decodeRequestData(bytes calldata _data) external view returns (RequestParameters memory _params); -// /** -// * @notice Returns the amount of pledges that a particular pledger has made for a given dispute. -// * @param _requestId The id of the request to get the pledges for. -// * @param _pledger The address of the pledger to get the pledges for. -// * @return _numPledges The number of pledges made by the pledger for the dispute. -// */ -// function pledgesForDispute(bytes32 _requestId, address _pledger) external view returns (uint256 _numPledges); + /** + * @notice Returns the amount of pledges that a particular pledger has made for a given dispute. + * @param _requestId The id of the request to get the pledges for. + * @param _pledger The address of the pledger to get the pledges for. + * @return _numPledges The number of pledges made by the pledger for the dispute. + */ + function pledgesForDispute(bytes32 _requestId, address _pledger) external view returns (uint256 _numPledges); -// /** -// * @notice Returns the amount of pledges that a particular pledger has made against a given dispute. -// * @param _requestId The id of the request to get the pledges for. -// * @param _pledger The address of the pledger to get the pledges for. -// * @return _numPledges The number of pledges made by the pledger against the dispute. -// */ -// function pledgesAgainstDispute(bytes32 _requestId, address _pledger) external view returns (uint256 _numPledges); + /** + * @notice Returns the amount of pledges that a particular pledger has made against a given dispute. + * @param _requestId The id of the request to get the pledges for. + * @param _pledger The address of the pledger to get the pledges for. + * @return _numPledges The number of pledges made by the pledger against the dispute. + */ + function pledgesAgainstDispute(bytes32 _requestId, address _pledger) external view returns (uint256 _numPledges); -// /*/////////////////////////////////////////////////////////////// -// LOGIC -// //////////////////////////////////////////////////////////////*/ + /*/////////////////////////////////////////////////////////////// + LOGIC + //////////////////////////////////////////////////////////////*/ -// /** -// * @notice Disputes a response -// * -// * @dev If this is the first dispute of the request and the bond escalation window is not over, -// * it will start the bond escalation process. This function must be called through the Oracle. -// * -// * @param _requestId The ID of the request containing the response to dispute. -// * @param _responseId The ID of the request to dispute. -// * @param _disputer The address of the disputer. -// * @param _proposer The address of the proposer of the response. -// * -// * @return _dispute The data of the created dispute. -// */ -// function disputeResponse( -// bytes32 _requestId, -// bytes32 _responseId, -// address _disputer, -// address _proposer -// ) external override returns (IOracle.Dispute memory _dispute); + /** + * @notice Disputes a response + * + * @dev If this is the first dispute of the request and the bond escalation window is not over, + * it will start the bond escalation process. This function must be called through the Oracle. + * + * @param _response The response being disputed. + */ + function disputeResponse( + IOracle.Request calldata _request, + IOracle.Response calldata _response, + IOracle.Dispute calldata _dispute + ) external; -// /** -// * @notice Updates the status of a given disputeId and pays the proposer and disputer accordingly. If this -// * dispute has gone through the bond escalation mechanism, then it will pay the winning pledgers as well. -// * -// * @param _disputeId The ID of the dispute to update the status for. -// * @param _dispute The full dispute object. -// * -// */ -// function onDisputeStatusChange(bytes32 _disputeId, IOracle.Dispute memory _dispute) external override; + /** + * @notice Updates the status of a given disputeId and pays the proposer and disputer accordingly. If this + * dispute has gone through the bond escalation mechanism, then it will pay the winning pledgers as well. + * + * @param _disputeId The ID of the dispute to update the status for. + * @param _dispute The full dispute object. + * + */ + function onDisputeStatusChange( + bytes32 _disputeId, + IOracle.Request calldata _request, + IOracle.Response calldata _response, + IOracle.Dispute calldata _dispute + ) external; -// /** -// * @notice Verifies whether the dispute going through the bond escalation mechanism has reached a tie and -// * updates its escalation status accordingly. -// * -// * @param _disputeId The ID of the dispute to escalate. -// */ -// function disputeEscalated(bytes32 _disputeId) external; + /** + * @notice Bonds funds in favor of a given dispute during the bond escalation process. + * + * @dev This function must be called directly through this contract. + * @dev If the bond escalation is not tied at the end of its deadline, a tying buffer is added + * to avoid scenarios where one of the parties breaks the tie very last second. + * During the tying buffer, the losing party can only tie, and once the escalation is tied + * no further funds can be pledged. + */ + function pledgeForDispute(IOracle.Request calldata _request, IOracle.Dispute calldata _dispute) external; -// /** -// * @notice Bonds funds in favor of a given dispute during the bond escalation process. -// * -// * @dev This function must be called directly through this contract. -// * @dev If the bond escalation is not tied at the end of its deadline, a tying buffer is added -// * to avoid scenarios where one of the parties breaks the tie very last second. -// * During the tying buffer, the losing party can only tie, and once the escalation is tied -// * no further funds can be pledged. -// * -// * @param _disputeId The ID of the dispute to pledge for. -// */ -// function pledgeForDispute(bytes32 _disputeId) external; + /** + * @notice Pledges funds against a given disputeId during its bond escalation process. + * + * @dev Must be called directly through this contract. Will revert if the disputeId is not going through + * the bond escalation process. + * @dev If the bond escalation is not tied at the end of its deadline, a tying buffer is added + * to avoid scenarios where one of the parties breaks the tie very last second. + * During the tying buffer, the losing party can only tie, and once the escalation is tied + * no further funds can be pledged. + */ + function pledgeAgainstDispute(IOracle.Request calldata _request, IOracle.Dispute calldata _dispute) external; -// /** -// * @notice Pledges funds against a given disputeId during its bond escalation process. -// * -// * @dev Must be called directly through this contract. Will revert if the disputeId is not going through -// * the bond escalation process. -// * @dev If the bond escalation is not tied at the end of its deadline, a tying buffer is added -// * to avoid scenarios where one of the parties breaks the tie very last second. -// * During the tying buffer, the losing party can only tie, and once the escalation is tied -// * no further funds can be pledged. -// * -// * @param _disputeId ID of the dispute id to pledge against. -// */ -// function pledgeAgainstDispute(bytes32 _disputeId) external; - -// /** -// * @notice Settles the bond escalation process of a given requestId. -// * -// * @dev Must be called directly through this contract. -// * @dev Can only be called if after the deadline + tyingBuffer window is over, the pledges weren't tied -// * -// * @param _requestId requestId of the request to settle the bond escalation process for. -// */ -// function settleBondEscalation(bytes32 _requestId) external; -// } + /** + * @notice Settles the bond escalation process of a given requestId. + * + * @dev Must be called directly through this contract. + * @dev Can only be called if after the deadline + tyingBuffer window is over, the pledges weren't tied + */ + function settleBondEscalation( + IOracle.Request calldata _request, + IOracle.Response calldata _response, + IOracle.Dispute calldata _dispute + ) external; +} diff --git a/solidity/test/utils/Helpers.sol b/solidity/test/utils/Helpers.sol index 46874489..5bddd4bc 100644 --- a/solidity/test/utils/Helpers.sol +++ b/solidity/test/utils/Helpers.sol @@ -1,56 +1,68 @@ -// // SPDX-License-Identifier: MIT -// pragma solidity ^0.8.19; - -// import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol'; -// import {DSTestPlus} from '@defi-wonderland/solidity-utils/solidity/test/DSTestPlus.sol'; -// import {IOracle} from '@defi-wonderland/prophet-core-contracts/solidity/interfaces/IOracle.sol'; - -// import {IAccountingExtension} from '../../interfaces/extensions/IAccountingExtension.sol'; - -// contract Helpers is DSTestPlus { -// modifier assumeFuzzable(address _address) { -// _assumeFuzzable(_address); -// _; -// } - -// function _assumeFuzzable(address _address) internal pure { -// assumeNotForgeAddress(_address); -// assumeNotZeroAddress(_address); -// assumeNotPrecompile(_address); -// } - -// function _mockAndExpect(address _receiver, bytes memory _calldata, bytes memory _returned) internal { -// vm.mockCall(_receiver, _calldata, _returned); -// vm.expectCall(_receiver, _calldata); -// } - -// function _getMockDispute( -// bytes32 _requestId, -// address _disputer, -// address _proposer -// ) internal view returns (IOracle.Dispute memory _dispute) { -// _dispute = IOracle.Dispute({ -// disputer: _disputer, -// responseId: bytes32('response'), -// proposer: _proposer, -// requestId: _requestId, -// status: IOracle.DisputeStatus.None, -// createdAt: block.timestamp -// }); -// } - -// function _forBondDepositERC20( -// IAccountingExtension _accountingExtension, -// address _depositor, -// IERC20 _token, -// uint256 _depositAmount, -// uint256 _balanceIncrease -// ) internal { -// vm.assume(_balanceIncrease >= _depositAmount); -// deal(address(_token), _depositor, _balanceIncrease); -// vm.startPrank(_depositor); -// _token.approve(address(_accountingExtension), _depositAmount); -// _accountingExtension.deposit(_token, _depositAmount); -// vm.stopPrank(); -// } -// } +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.19; + +import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol'; +import {DSTestPlus} from '@defi-wonderland/solidity-utils/solidity/test/DSTestPlus.sol'; +import {IOracle} from '@defi-wonderland/prophet-core-contracts/solidity/interfaces/IOracle.sol'; + +import {IAccountingExtension} from '../../interfaces/extensions/IAccountingExtension.sol'; + +contract Helpers is DSTestPlus { + modifier assumeFuzzable(address _address) { + _assumeFuzzable(_address); + _; + } + + function _assumeFuzzable(address _address) internal pure { + assumeNotForgeAddress(_address); + assumeNotZeroAddress(_address); + assumeNotPrecompile(_address); + } + + function _mockAndExpect(address _receiver, bytes memory _calldata, bytes memory _returned) internal { + vm.mockCall(_receiver, _calldata, _returned); + vm.expectCall(_receiver, _calldata); + } + + function _getMockDispute( + bytes32 _requestId, + address _disputer, + address _proposer + ) internal view returns (IOracle.Dispute memory _dispute) { + _dispute = IOracle.Dispute({ + disputer: _disputer, + responseId: bytes32('response'), + proposer: _proposer, + requestId: _requestId, + status: IOracle.DisputeStatus.None, + createdAt: block.timestamp + }); + } + + function _forBondDepositERC20( + IAccountingExtension _accountingExtension, + address _depositor, + IERC20 _token, + uint256 _depositAmount, + uint256 _balanceIncrease + ) internal { + vm.assume(_balanceIncrease >= _depositAmount); + deal(address(_token), _depositor, _balanceIncrease); + vm.startPrank(_depositor); + _token.approve(address(_accountingExtension), _depositAmount); + _accountingExtension.deposit(_token, _depositAmount); + vm.stopPrank(); + } + + function _getId(IOracle.Response memory _response) internal pure returns (bytes32 _id) { + _id = keccak256(abi.encode(_response)); + } + + function _getId(IOracle.Request memory _request) internal pure returns (bytes32 _id) { + _id = keccak256(abi.encode(_request)); + } + + function _getId(IOracle.Dispute memory _dispute) internal pure returns (bytes32 _id) { + _id = keccak256(abi.encode(_dispute)); + } +}