Skip to content

Commit

Permalink
fix: bond escalation flow
Browse files Browse the repository at this point in the history
  • Loading branch information
moebius committed Dec 6, 2023
1 parent bd0a826 commit 68122a5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
27 changes: 17 additions & 10 deletions solidity/contracts/modules/dispute/BondEscalationModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ contract BondEscalationModule is Module, IBondEscalationModule {
/// @inheritdoc IBondEscalationModule
function disputeResponse(
IOracle.Request calldata _request,
IOracle.Response calldata, /* _response */
IOracle.Response calldata _response,
IOracle.Dispute calldata _dispute
) external onlyOracle {
RequestParameters memory _params = decodeRequestData(_request.disputeModuleData);
Expand All @@ -50,6 +50,8 @@ contract BondEscalationModule is Module, IBondEscalationModule {
_escalation.status = BondEscalationStatus.Active;
_escalation.disputeId = _disputeId;
emit BondEscalationStatusUpdated(_dispute.requestId, _disputeId, BondEscalationStatus.Active);
} else if (_disputeId != _escalation.disputeId) {
ORACLE.escalateDispute(_request, _response, _dispute);
}

_params.accountingExtension.bond({
Expand Down Expand Up @@ -78,8 +80,9 @@ contract BondEscalationModule is Module, IBondEscalationModule {
RequestParameters memory _params = decodeRequestData(_request.disputeModuleData);

BondEscalation storage _escalation = _escalations[_dispute.requestId];
IOracle.DisputeStatus _disputeStatus = ORACLE.disputeStatus(_disputeId);

if (ORACLE.disputeStatus(_disputeId) == IOracle.DisputeStatus.Escalated) {
if (_disputeStatus == IOracle.DisputeStatus.Escalated) {
if (_disputeId == _escalation.disputeId) {
if (block.timestamp <= _params.bondEscalationDeadline) revert BondEscalationModule_BondEscalationNotOver();

Expand All @@ -93,19 +96,23 @@ contract BondEscalationModule is Module, IBondEscalationModule {
_escalation.status = BondEscalationStatus.Escalated;
emit BondEscalationStatusUpdated(_dispute.requestId, _disputeId, BondEscalationStatus.Escalated);
return;
} else {
emit DisputeStatusChanged({_disputeId: _disputeId, _dispute: _dispute, _status: IOracle.DisputeStatus.Escalated});
return;
}
}

bool _won = ORACLE.disputeStatus(_disputeId) == IOracle.DisputeStatus.Won;
bool _won = _disputeStatus == IOracle.DisputeStatus.Won;

_params.accountingExtension.pay({
_requestId: _dispute.requestId,
_payer: _won ? _dispute.proposer : _dispute.disputer,
_receiver: _won ? _dispute.disputer : _dispute.proposer,
_token: _params.bondToken,
_amount: _params.bondSize
});

if (_won) {
_params.accountingExtension.pay({
_requestId: _dispute.requestId,
_payer: _dispute.proposer,
_receiver: _dispute.disputer,
_token: _params.bondToken,
_amount: _params.bondSize
});
_params.accountingExtension.release({
_requestId: _dispute.requestId,
_bonder: _dispute.disputer,
Expand Down
8 changes: 5 additions & 3 deletions solidity/test/integration/BondEscalation.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ contract Integration_BondEscalation is IntegrationBase {
assertEq(_bondEscalationAccounting.balanceOf(disputer, usdc), 0, 'Mismatch: Disputer balance');

// Step 8: Finalize request and check balances again
vm.roll(_expectedDeadline + 1 days);
oracle.finalize(_request, _response);

// Test: The requester has no balance because he has paid the proposer
Expand All @@ -154,6 +155,7 @@ contract Integration_BondEscalation is IntegrationBase {
assertEq(_bondEscalationAccounting.balanceOf(disputer, usdc), 0, 'Mismatch: Disputer balance');
}

//asdf
function test_proposerLoses() public {
// Step 1: Proposer pledges against the dispute
_forBondDepositERC20(_bondEscalationAccounting, proposer, usdc, _pledgeSize, _pledgeSize);
Expand Down Expand Up @@ -237,9 +239,9 @@ contract Integration_BondEscalation is IntegrationBase {
vm.stopPrank();

// Step 10: The dispute goes to the resolution module
oracle.escalateDispute(_request, _secondResponse, _secondDispute);
_disputeStatus = oracle.disputeStatus(_disputeId);
assertEq(uint256(_disputeStatus), uint256(IOracle.DisputeStatus.Escalated), 'Mismatch: Dispute status');
// oracle.escalateDispute(_request, _secondResponse, _secondDispute);
// _disputeStatus = oracle.disputeStatus(_disputeId);
// assertEq(uint256(_disputeStatus), uint256(IOracle.DisputeStatus.Escalated), 'Mismatch: Dispute status');

// Step 11: Because Another proposer's answer is disputed, a third party can propose a new answer
address _thirdProposer = makeAddr('thirdProposer');
Expand Down

0 comments on commit 68122a5

Please sign in to comment.