Skip to content

Commit

Permalink
feat: implement the pull function in ERC20ResolutionModule
Browse files Browse the repository at this point in the history
  • Loading branch information
gas1cent committed Nov 26, 2023
1 parent ef77ae3 commit 770ba18
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions solidity/contracts/modules/resolution/ERC20ResolutionModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,43 +83,45 @@ contract ERC20ResolutionModule is Module, IERC20ResolutionModule {
IOracle.Response calldata _response,
IOracle.Dispute calldata _dispute
) external onlyOracle {
// 0. Check disputeId actually exists and that it isn't resolved already
// Check disputeId actually exists and that it isn't resolved already
if (ORACLE.disputeStatus(_disputeId) != IOracle.DisputeStatus.Escalated) {
revert ERC20ResolutionModule_AlreadyResolved();
}

// 1. Check that the dispute is actually escalated
// Check that the dispute is actually escalated
Escalation memory _escalation = escalations[_disputeId];
if (_escalation.startTime == 0) revert ERC20ResolutionModule_DisputeNotEscalated();

// 2. Check that voting deadline is over
// Check that voting deadline is over
RequestParameters memory _params = decodeRequestData(_request.resolutionModuleData);
uint256 _deadline = _escalation.startTime + _params.timeUntilDeadline;
if (block.timestamp < _deadline) revert ERC20ResolutionModule_OnGoingVotingPhase();

uint256 _quorumReached = _escalation.totalVotes >= _params.minVotesForQuorum ? 1 : 0;

address[] memory __voters = _voters[_disputeId].values();

// 5. Update status
// Update status
if (_quorumReached == 1) {
ORACLE.updateDisputeStatus(_request, _response, _dispute, IOracle.DisputeStatus.Won);
emit DisputeResolved(_dispute.requestId, _disputeId, IOracle.DisputeStatus.Won);
} else {
ORACLE.updateDisputeStatus(_request, _response, _dispute, IOracle.DisputeStatus.Lost);
emit DisputeResolved(_dispute.requestId, _disputeId, IOracle.DisputeStatus.Lost);
}
}

uint256 _votersLength = __voters.length;
/// @inheritdoc IERC20ResolutionModule
function claimVote(IOracle.Request calldata _request, IOracle.Dispute calldata _dispute) external {
// Check that voting deadline is over
RequestParameters memory _params = decodeRequestData(_request.resolutionModuleData);
uint256 _deadline = _escalation.startTime + _params.timeUntilDeadline;
if (block.timestamp < _deadline) revert ERC20ResolutionModule_OnGoingVotingPhase();

// 6. Return tokens
for (uint256 _i; _i < _votersLength;) {
address _voter = __voters[_i];
_params.votingToken.safeTransfer(_voter, votes[_disputeId][_voter]);
unchecked {
++_i;
}
}
// Transfer the tokens back to the voter
bytes32 _disputeId = _getId(_dispute);
uint256 _amount = votes[_disputeId][msg.sender];
_params.votingToken.safeTransfer(msg.sender, _amount);

emit VoteClaimed(msg.sender, _disputeId, _amount);
}

/// @inheritdoc IERC20ResolutionModule
Expand Down

0 comments on commit 770ba18

Please sign in to comment.