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: relative timestamps #47

Merged
merged 22 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"package.json": "sort-package-json"
},
"dependencies": {
"@defi-wonderland/prophet-core": "0.0.0-0954a47f",
"@defi-wonderland/prophet-modules": "0.0.0-6986feea"
"@defi-wonderland/prophet-core": "0.0.0-96d1084b",
"@defi-wonderland/prophet-modules": "0.0.0-b3fa5d2c"
},
"devDependencies": {
"@commitlint/cli": "19.3.0",
Expand Down
6 changes: 3 additions & 3 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ contract Deploy is Script {
// Set response module params
// TODO: Review production params (responseBondSize == disputeBondSize)
responseBondSize = 0.5 ether;
responseDeadline = block.timestamp + 5 days;
responseDisputeWindow = block.timestamp + 1 weeks;
responseDeadline = 5 days;
responseDisputeWindow = 1 weeks;

// Set dispute module params
// TODO: Review production params (disputeBondSize == responseBondSize)
disputeBondSize = 0.3 ether;
maxNumberOfEscalations = 2;
disputeDeadline = block.timestamp + 10 days;
disputeDeadline = 10 days;
tyingBuffer = 3 days;
disputeDisputeWindow = 1 weeks;
}
Expand Down
34 changes: 8 additions & 26 deletions test/integration/arbitrum/ArbitrateDispute.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ contract IntegrationArbitrateDispute is IntegrationBase {
_pledgeAgainstDispute(_requestId, _disputeId);

// Pass the dispute deadline
vm.warp(disputeDeadline + 1);
vm.warp(oracle.disputeCreatedAt(_disputeId) + disputeDeadline + 1);

// Escalate the dispute
_escalateDispute(_requestId, _responseId, _disputeId);
Expand All @@ -57,13 +57,6 @@ contract IntegrationArbitrateDispute is IntegrationBase {
vm.expectRevert(ICouncilArbitrator.CouncilArbitrator_InvalidAward.selector);
_arbitrateDispute(_disputeId, IOracle.DisputeStatus.Escalated);

// Revert if the request is finalized before the response deadline
vm.expectRevert(IBondedResponseModule.BondedResponseModule_TooEarlyToFinalize.selector);
_arbitrateDispute(_disputeId, IOracle.DisputeStatus.Won);

// Pass the response deadline
vm.roll(block.number + responseDeadline);
Comment on lines -60 to -65
Copy link
Member

Choose a reason for hiding this comment

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

This could still be tested in case that disputeDeadline were less than what's left of responseDeadline at that moment.


// Arbitrate and resolve the dispute, and finalize the request without response
_arbitrateDispute(_disputeId, IOracle.DisputeStatus.Won);

Expand Down Expand Up @@ -103,7 +96,7 @@ contract IntegrationArbitrateDispute is IntegrationBase {
assertEq(horizonAccountingExtension.bondedForRequest(_disputer, _requestId), 0);
assertEq(horizonAccountingExtension.totalBonded(_disputer), 0);
// Assert Oracle::finalize
assertEq(oracle.finalizedAt(_requestId), block.number);
assertEq(oracle.finalizedAt(_requestId), block.timestamp);
assertEq(oracle.finalizedResponseId(_requestId), 0);

// Revert if the dispute has already been arbitrated
Expand Down Expand Up @@ -135,7 +128,7 @@ contract IntegrationArbitrateDispute is IntegrationBase {
_pledgeAgainstDispute(_requestId, _disputeId);

// Pass the dispute deadline
vm.warp(disputeDeadline + 1);
vm.warp(oracle.disputeCreatedAt(_disputeId) + disputeDeadline + 1);

// Escalate the dispute
_escalateDispute(_requestId, _responseId, _disputeId);
Expand All @@ -148,19 +141,15 @@ contract IntegrationArbitrateDispute is IntegrationBase {
vm.expectRevert(ICouncilArbitrator.CouncilArbitrator_InvalidAward.selector);
_arbitrateDispute(_disputeId, IOracle.DisputeStatus.Escalated);

// Revert if the request is finalized before the response deadline
vm.expectRevert(IBondedResponseModule.BondedResponseModule_TooEarlyToFinalize.selector);
_arbitrateDispute(_disputeId, IOracle.DisputeStatus.Lost);

// Pass the response deadline
vm.roll(block.number + responseDeadline);
vm.warp(oracle.responseCreatedAt(_responseId) + responseDeadline);
Comment on lines 144 to +145
Copy link
Member

Choose a reason for hiding this comment

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

// Pass the response deadline, but not the dispute deadline

Also, shouldn't it add the responseDeadline to requestCreatedAt?

Copy link
Member Author

Choose a reason for hiding this comment

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

100%


// Revert if the request is finalized with response before the dispute window
vm.expectRevert(IBondedResponseModule.BondedResponseModule_TooEarlyToFinalize.selector);
_arbitrateDispute(_disputeId, IOracle.DisputeStatus.Lost);

// Pass the dispute window
vm.roll(block.number + responseDisputeWindow - responseDeadline);
vm.warp(oracle.disputeCreatedAt(_disputeId) + disputeDeadline + 1);
Comment on lines 151 to +152
Copy link
Member

Choose a reason for hiding this comment

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

Pass the dispute window or pass the dispute deadline?

Also, bear in mind whether they should be computed from the response creation timestamp or the dispute creation timestamp.


// Arbitrate and resolve the dispute, and finalize the request with response
_arbitrateDispute(_disputeId, IOracle.DisputeStatus.Lost);
Expand Down Expand Up @@ -198,7 +187,7 @@ contract IntegrationArbitrateDispute is IntegrationBase {
assertEq(graphToken.balanceOf(_proposer), disputeBondSize);
assertEq(graphToken.balanceOf(_disputer), 0);
// Assert Oracle::finalize
assertEq(oracle.finalizedAt(_requestId), block.number);
assertEq(oracle.finalizedAt(_requestId), block.timestamp);
assertEq(oracle.finalizedResponseId(_requestId), _responseId);
// Assert HorizonAccountingExtension::release
assertEq(horizonAccountingExtension.bondedForRequest(_proposer, _requestId), 0);
Expand Down Expand Up @@ -233,7 +222,7 @@ contract IntegrationArbitrateDispute is IntegrationBase {
_pledgeAgainstDispute(_requestId, _disputeId);

// Pass the dispute deadline
vm.warp(disputeDeadline + 1);
vm.warp(oracle.disputeCreatedAt(_disputeId) + disputeDeadline + 1);

// Escalate the dispute
_escalateDispute(_requestId, _responseId, _disputeId);
Expand All @@ -246,13 +235,6 @@ contract IntegrationArbitrateDispute is IntegrationBase {
vm.expectRevert(ICouncilArbitrator.CouncilArbitrator_InvalidAward.selector);
_arbitrateDispute(_disputeId, IOracle.DisputeStatus.Escalated);

// Revert if the request is finalized before the response deadline
vm.expectRevert(IBondedResponseModule.BondedResponseModule_TooEarlyToFinalize.selector);
_arbitrateDispute(_disputeId, IOracle.DisputeStatus.NoResolution);

// Pass the response deadline
vm.roll(block.number + responseDeadline);

// Arbitrate and resolve the dispute, and finalize the request without response
_arbitrateDispute(_disputeId, IOracle.DisputeStatus.NoResolution);

Expand Down Expand Up @@ -281,7 +263,7 @@ contract IntegrationArbitrateDispute is IntegrationBase {
assertEq(horizonAccountingExtension.bondedForRequest(_proposer, _requestId), responseBondSize);
assertEq(horizonAccountingExtension.totalBonded(_proposer), responseBondSize);
// Assert Oracle::finalize
assertEq(oracle.finalizedAt(_requestId), block.number);
assertEq(oracle.finalizedAt(_requestId), block.timestamp);
assertEq(oracle.finalizedResponseId(_requestId), 0);

// Revert if the dispute has already been arbitrated
Expand Down
33 changes: 18 additions & 15 deletions test/integration/arbitrum/BondEscalation.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ contract IntegrationBondEscalation is IntegrationBase {
bytes32 internal _requestId;
bytes32 internal _responseId;
bytes32 internal _disputeId;
uint256 internal _disputeCreatedAt;

function setUp() public override {
super.setUp();
Expand All @@ -33,25 +34,27 @@ contract IntegrationBondEscalation is IntegrationBase {
_responseId = _proposeResponse(_requestId);
// Dispute the response
_disputeId = _disputeResponse(_requestId, _responseId);

_disputeCreatedAt = oracle.disputeCreatedAt(_disputeId);
}

function test_PledgeForDispute() public {
// Pass the dispute deadline, but not the tying buffer
vm.warp(disputeDeadline + 1);
vm.warp(_disputeCreatedAt + disputeDeadline + 1);

// Revert if breaking a tie during the tying buffer
vm.expectRevert(IBondEscalationModule.BondEscalationModule_CannotBreakTieDuringTyingBuffer.selector);
_pledgeForDispute(_requestId, _disputeId);

// Pass the dispute deadline and the tying buffer
vm.warp(disputeDeadline + tyingBuffer + 1);
vm.warp(_disputeCreatedAt + disputeDeadline + tyingBuffer + 1);

// Revert if the bond escalation deadline and the tying buffer have passed
vm.expectRevert(IBondEscalationModule.BondEscalationModule_BondEscalationOver.selector);
_pledgeForDispute(_requestId, _disputeId);

// Do not pass the dispute deadline nor the tying buffer
vm.warp(disputeDeadline);
vm.warp(_disputeCreatedAt + disputeDeadline);

// Pledge for the dispute
_pledgeForDispute(_requestId, _disputeId);
Expand All @@ -72,21 +75,21 @@ contract IntegrationBondEscalation is IntegrationBase {

function test_PledgeAgainstDispute() public {
// Pass the dispute deadline, but not the tying buffer
vm.warp(disputeDeadline + 1);
vm.warp(_disputeCreatedAt + disputeDeadline + 1);

// Revert if breaking a tie during the tying buffer
vm.expectRevert(IBondEscalationModule.BondEscalationModule_CannotBreakTieDuringTyingBuffer.selector);
_pledgeAgainstDispute(_requestId, _disputeId);

// Pass the dispute deadline and the tying buffer
vm.warp(disputeDeadline + tyingBuffer + 1);
vm.warp(_disputeCreatedAt + disputeDeadline + tyingBuffer + 1);

// Revert if the bond escalation deadline and the tying buffer have passed
vm.expectRevert(IBondEscalationModule.BondEscalationModule_BondEscalationOver.selector);
_pledgeAgainstDispute(_requestId, _disputeId);

// Do not pass the dispute deadline nor the tying buffer
vm.warp(disputeDeadline);
vm.warp(_disputeCreatedAt + disputeDeadline);

// Pledge against the dispute
_pledgeAgainstDispute(_requestId, _disputeId);
Expand Down Expand Up @@ -114,7 +117,7 @@ contract IntegrationBondEscalation is IntegrationBase {
_pledgeAgainstDispute(_requestId, _disputeId);

// Pass the dispute deadline, but not the tying buffer
vm.warp(disputeDeadline + 1);
vm.warp(_disputeCreatedAt + disputeDeadline + 1);

// Pledge for the dispute, again
_pledgeForDispute(_requestId, _disputeId);
Expand Down Expand Up @@ -144,14 +147,14 @@ contract IntegrationBondEscalation is IntegrationBase {
_settleBondEscalation(_requestId, _responseId, _disputeId);

// Pass the dispute deadline and the tying buffer
vm.warp(disputeDeadline + tyingBuffer + 1);
vm.warp(_disputeCreatedAt + disputeDeadline + tyingBuffer + 1);

// Revert if the bond escalation has tied
vm.expectRevert(IBondEscalationModule.BondEscalationModule_ShouldBeEscalated.selector);
_settleBondEscalation(_requestId, _responseId, _disputeId);

// Do not pass the dispute deadline nor the tying buffer
vm.warp(disputeDeadline);
vm.warp(_disputeCreatedAt + disputeDeadline);

// Pledge against the dispute
_pledgeAgainstDispute(_requestId, _disputeId);
Expand All @@ -161,7 +164,7 @@ contract IntegrationBondEscalation is IntegrationBase {
_pledgeForDispute(_requestId, _disputeId);

// Pass the dispute deadline and the tying buffer
vm.warp(disputeDeadline + tyingBuffer + 1);
vm.warp(_disputeCreatedAt + disputeDeadline + tyingBuffer + 1);

// Settle the bond escalation
_settleBondEscalation(_requestId, _responseId, _disputeId);
Expand Down Expand Up @@ -211,14 +214,14 @@ contract IntegrationBondEscalation is IntegrationBase {
_settleBondEscalation(_requestId, _responseId, _disputeId);

// Pass the dispute deadline and the tying buffer
vm.warp(disputeDeadline + tyingBuffer + 1);
vm.warp(_disputeCreatedAt + disputeDeadline + tyingBuffer + 1);

// Revert if the bond escalation has tied
vm.expectRevert(IBondEscalationModule.BondEscalationModule_ShouldBeEscalated.selector);
_settleBondEscalation(_requestId, _responseId, _disputeId);

// Do not pass the dispute deadline nor the tying buffer
vm.warp(disputeDeadline);
vm.warp(_disputeCreatedAt + disputeDeadline);

// Pledge for the dispute
_pledgeForDispute(_requestId, _disputeId);
Expand All @@ -228,7 +231,7 @@ contract IntegrationBondEscalation is IntegrationBase {
_pledgeAgainstDispute(_requestId, _disputeId);

// Pass the dispute deadline and the tying buffer
vm.warp(disputeDeadline + tyingBuffer + 1);
vm.warp(_disputeCreatedAt + disputeDeadline + tyingBuffer + 1);

// Settle the bond escalation
_settleBondEscalation(_requestId, _responseId, _disputeId);
Expand Down Expand Up @@ -284,7 +287,7 @@ contract IntegrationBondEscalation is IntegrationBase {
_pledgeForDispute(_requestId, _disputeId);

// Pass the dispute deadline and the tying buffer
vm.warp(disputeDeadline + tyingBuffer + 1);
vm.warp(_disputeCreatedAt + disputeDeadline + tyingBuffer + 1);

// Settle the bond escalation
_settleBondEscalation(_requestId, _responseId, _disputeId);
Expand Down Expand Up @@ -328,7 +331,7 @@ contract IntegrationBondEscalation is IntegrationBase {
_pledgeAgainstDispute(_requestId, _disputeId);

// Pass the dispute deadline and the tying buffer
vm.warp(disputeDeadline + tyingBuffer + 1);
vm.warp(_disputeCreatedAt + disputeDeadline + tyingBuffer + 1);

// Settle the bond escalation
_settleBondEscalation(_requestId, _responseId, _disputeId);
Expand Down
2 changes: 1 addition & 1 deletion test/integration/arbitrum/CreateRequest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ contract IntegrationCreateRequest is IntegrationBase {
bytes32 _requestId = eboRequestCreator.requestIdPerChainAndEpoch(_chainId, _currentEpoch);

// Check that the request ID is stored correctly
assertEq(oracle.requestCreatedAt(_requestId), block.number);
assertEq(oracle.requestCreatedAt(_requestId), block.timestamp);

// Expect revert if the request is already created
vm.prank(_requester);
Expand Down
18 changes: 10 additions & 8 deletions test/integration/arbitrum/DisputeResponse.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,35 @@
// Propose the response
bytes32 _responseId = _proposeResponse(_requestId);

uint256 _responseCreation = oracle.responseCreatedAt(_responseId);

// Pass the dispute window
vm.roll(block.number + disputeDisputeWindow + 1);
vm.warp(_responseCreation + disputeDisputeWindow + 1);

// Revert if the dispute window has passed
vm.expectRevert(IBondEscalationModule.BondEscalationModule_DisputeWindowOver.selector);
_disputeResponse(_requestId, _responseId);

// Do not pass the dispute window
vm.roll(block.number - disputeDisputeWindow - 1);
// TODO: Commented out because of a bug in prophet core dispute module
// Fix after this task is done https://linear.app/defi-wonderland/issue/OPO-669/incorrect-validation-in-bondescalationmodule

Check warning on line 43 in test/integration/arbitrum/DisputeResponse.t.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Line length must be no more than 120 but current length is 128

// Pass the dispute deadline
vm.warp(disputeDeadline + 1);
// vm.warp(_responseCreation + disputeDeadline + 1);

// Revert if the bond escalation deadline has passed
vm.expectRevert(IBondEscalationModule.BondEscalationModule_BondEscalationOver.selector);
_disputeResponse(_requestId, _responseId);
// vm.expectRevert(IBondEscalationModule.BondEscalationModule_BondEscalationOver.selector);
// _disputeResponse(_requestId, _responseId);

// Do not pass the dispute deadline
vm.warp(disputeDeadline);
vm.warp(_responseCreation + disputeDisputeWindow - 1);
Comment on lines 52 to +53
Copy link
Member

Choose a reason for hiding this comment

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

Do not pass the dispute deadline or do not pass the dispute window?


// Dispute the response
bytes32 _disputeId = _disputeResponse(_requestId, _responseId);

// Assert Oracle::disputeResponse
assertEq(uint8(oracle.disputeStatus(_disputeId)), uint8(IOracle.DisputeStatus.Active));
assertEq(oracle.disputeOf(_responseId), _disputeId);
assertEq(oracle.disputeCreatedAt(_disputeId), block.number);
assertEq(oracle.disputeCreatedAt(_disputeId), block.timestamp);
// Assert BondEscalationModule::disputeResponse
IBondEscalationModule.BondEscalation memory _escalation = bondEscalationModule.getEscalation(_requestId);
assertEq(_escalation.disputeId, _disputeId);
Expand Down
8 changes: 4 additions & 4 deletions test/integration/arbitrum/EscalateDispute.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@ contract IntegrationEscalateDispute is IntegrationBase {
_pledgeForDispute(_requestId, _disputeId);

// Pass the dispute deadline
vm.warp(disputeDeadline + 1);
vm.warp(oracle.disputeCreatedAt(_disputeId) + disputeDeadline + 1);

// Revert if the bond escalation has not tied
vm.expectRevert(IBondEscalationModule.BondEscalationModule_NotEscalatable.selector);
_escalateDispute(_requestId, _responseId, _disputeId);

// Do not pass the dispute deadline
vm.warp(disputeDeadline);
vm.warp(oracle.disputeCreatedAt(_disputeId) + disputeDeadline);

// Pledge against the dispute
_pledgeAgainstDispute(_requestId, _disputeId);

// Pass the dispute deadline
vm.warp(disputeDeadline + 1);
vm.warp(oracle.disputeCreatedAt(_disputeId) + disputeDeadline + 1);

// Escalate the dispute
_escalateDispute(_requestId, _responseId, _disputeId);
Expand Down Expand Up @@ -86,7 +86,7 @@ contract IntegrationEscalateDispute is IntegrationBase {
_settleBondEscalation(_requestId, _responseId, _disputeId);

// Pass the dispute deadline and the tying buffer
vm.warp(disputeDeadline + tyingBuffer + 1);
vm.warp(oracle.disputeCreatedAt(_disputeId) + disputeDeadline + tyingBuffer + 1);

// Revert if the dispute has been escalated
vm.expectRevert(IBondEscalationModule.BondEscalationModule_BondEscalationOver.selector);
Expand Down
10 changes: 6 additions & 4 deletions test/integration/arbitrum/ProposeResponse.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,29 @@ contract IntegrationProposeResponse is IntegrationBase {
// Create the request
bytes32 _requestId = _createRequest();

uint256 _requestCreatedAt = oracle.requestCreatedAt(_requestId);

// Pass the response deadline
vm.warp(responseDeadline);
vm.warp(_requestCreatedAt + responseDeadline);

// Revert if the response is proposed after the response deadline
vm.expectRevert(IBondedResponseModule.BondedResponseModule_TooLateToPropose.selector);
_proposeResponse(_requestId);

// Do not pass the response deadline
vm.warp(responseDeadline - 1);
vm.warp(_requestCreatedAt + responseDeadline - 1);

// Propose the response
bytes32 _responseId = _proposeResponse(_requestId);

// Assert Oracle::proposeResponse
assertEq(oracle.responseCreatedAt(_responseId), block.number);
assertEq(oracle.responseCreatedAt(_responseId), block.timestamp);
// Assert HorizonAccountingExtension::bond
assertEq(horizonAccountingExtension.bondedForRequest(_proposer, _requestId), responseBondSize);
assertEq(horizonAccountingExtension.totalBonded(_proposer), responseBondSize);

// Revert if the response has already been proposed
vm.expectRevert(IOracle.Oracle_InvalidResponseBody.selector);
vm.expectRevert(IOracle.Oracle_ResponseAlreadyProposed.selector);
_proposeResponse(_requestId);
}
}
Loading
Loading