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

Top up functionlaity for fork arbitrator #213

Closed
wants to merge 2 commits into from
Closed
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
15 changes: 15 additions & 0 deletions contracts/L2ForkArbitrator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ contract L2ForkArbitrator is IL2ForkArbitrator {
uint256 remaining
);

event LogRequestArbitrationTopUp(
bytes32 indexed question_id,
uint256 fee_paid
);

// stores data on the arbitration process
// questionId => ArbitrationRequest
mapping(bytes32 => ArbitrationRequest) public arbitrationRequests;
Expand Down Expand Up @@ -109,6 +114,16 @@ contract L2ForkArbitrator is IL2ForkArbitrator {
return true;
}

/// @inheritdoc IL2ForkArbitrator
function topUpArbitrationRequest(bytes32 questionId) external payable {
ArbitrationRequest storage request = arbitrationRequests[questionId];
if (request.status != RequestStatus.QUEUED) {
revert NotAwaitingActivation();
}
request.paid = request.paid + msg.value;
emit LogRequestArbitrationTopUp(questionId, msg.value);
}

/// @inheritdoc IL2ForkArbitrator
// @note This function requires all the information from the original question,
// to verify the address of the adjudication framework that initially asked the question
Expand Down
6 changes: 6 additions & 0 deletions contracts/interfaces/IL2ForkArbitrator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ interface IL2ForkArbitrator is IBridgeMessageReceiver {
uint256 maxPrevious
) external payable returns (bool);

/// @notice Allows a requestor to top up their arbitration fee
/// This function needs to be used, in case the arbitration fee was increased in the time period between
/// the requestArbitration call and the arbitration request being processed.
/// @param questionId The question in question
function topUpArbitrationRequest(bytes32 questionId) external payable;

/// @notice Request a fork via the bridge
/// @dev Talks to the L1 ForkingManager asynchronously, and may fail.
/// @param templateId The template id of the question during requestArbitration call
Expand Down
45 changes: 45 additions & 0 deletions test/L2ForkArbitrator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -290,4 +290,49 @@ contract L2ForkArbitratorTest is Test {
address(this)
);
}

function testTopUpArbitrationRequest() public {
bytes32 questionId = keccak256("testQuestion");
uint256 maxPrevious = 0;
uint256 arbitrationFee = arbitrator.getDisputeFee(questionId);

// Mock call to realitio and simulate arbitration request
vm.mockCall(
address(realitio),
abi.encodeWithSelector(
IRealityETH.notifyOfArbitrationRequest.selector,
questionId,
address(this),
maxPrevious
),
abi.encode()
);

vm.deal(address(this), arbitrationFee);
arbitrator.requestArbitration{value: arbitrationFee}(
questionId,
maxPrevious
);

// Top up the arbitration request
uint256 topUpAmount = 0.5 ether;
vm.deal(address(this), topUpAmount);
arbitrator.topUpArbitrationRequest{value: topUpAmount}(questionId);

// Verify the top-up was successful
(, , uint256 paid, , ) = arbitrator.arbitrationRequests(questionId);
assertEq(
paid,
arbitrationFee + topUpAmount,
"Top-up amount not added to the paid total"
);

// Test for non-existent, non-queued arbitration request
bytes32 invalidQuestionId = keccak256("invalidQuestion");
vm.expectRevert(IL2ForkArbitrator.NotAwaitingActivation.selector);
vm.deal(address(this), topUpAmount);
arbitrator.topUpArbitrationRequest{value: topUpAmount}(
invalidQuestionId
);
}
}
Loading