Skip to content

Commit 1d84991

Browse files
committed
disputes: make the dispute manager upgradeable
1 parent 4b66b3f commit 1d84991

File tree

6 files changed

+67
-48
lines changed

6 files changed

+67
-48
lines changed

contracts/disputes/DisputeManager.sol

Lines changed: 21 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import "@openzeppelin/contracts/math/SafeMath.sol";
77
import "@openzeppelin/contracts/cryptography/ECDSA.sol";
88

99
import "../governance/Managed.sol";
10+
import "../upgrades/GraphUpgradeable.sol";
1011

12+
import "./DisputeManagerStorage.sol";
1113
import "./IDisputeManager.sol";
1214

1315
/*
@@ -33,21 +35,9 @@ import "./IDisputeManager.sol";
3335
* Disputes can only be accepted, rejected or drawn by the arbitrator role that can be delegated
3436
* to a EOA or DAO.
3537
*/
36-
contract DisputeManager is Managed, IDisputeManager {
38+
contract DisputeManager is DisputeManagerV1Storage, GraphUpgradeable, IDisputeManager {
3739
using SafeMath for uint256;
3840

39-
uint256 private constant ATTESTATION_SIZE_BYTES = 161;
40-
uint256 private constant RECEIPT_SIZE_BYTES = 96;
41-
42-
uint256 private constant SIG_R_LENGTH = 32;
43-
uint256 private constant SIG_S_LENGTH = 32;
44-
uint256 private constant SIG_R_OFFSET = RECEIPT_SIZE_BYTES;
45-
uint256 private constant SIG_S_OFFSET = RECEIPT_SIZE_BYTES + SIG_R_LENGTH;
46-
uint256 private constant SIG_V_OFFSET = RECEIPT_SIZE_BYTES + SIG_R_LENGTH + SIG_S_LENGTH;
47-
48-
uint256 private constant UINT8_BYTE_LENGTH = 1;
49-
uint256 private constant BYTES32_BYTE_LENGTH = 32;
50-
5141
// -- EIP-712 --
5242

5343
bytes32 private constant DOMAIN_TYPE_HASH = keccak256(
@@ -63,30 +53,19 @@ contract DisputeManager is Managed, IDisputeManager {
6353

6454
// -- Constants --
6555

66-
// 100% in parts per million
67-
uint256 private constant MAX_PPM = 1000000;
68-
69-
// -- State --
70-
71-
bytes32 private DOMAIN_SEPARATOR;
72-
73-
// The arbitrator is solely in control of arbitrating disputes
74-
address public arbitrator;
75-
76-
// Minimum deposit required to create a Dispute
77-
uint256 public minimumDeposit;
56+
uint256 private constant ATTESTATION_SIZE_BYTES = 161;
57+
uint256 private constant RECEIPT_SIZE_BYTES = 96;
7858

79-
// Percentage of indexer slashed funds to assign as a reward to fisherman in successful dispute
80-
// Parts per million. (Allows for 4 decimal points, 999,999 = 99.9999%)
81-
uint32 public fishermanRewardPercentage;
59+
uint256 private constant SIG_R_LENGTH = 32;
60+
uint256 private constant SIG_S_LENGTH = 32;
61+
uint256 private constant SIG_R_OFFSET = RECEIPT_SIZE_BYTES;
62+
uint256 private constant SIG_S_OFFSET = RECEIPT_SIZE_BYTES + SIG_R_LENGTH;
63+
uint256 private constant SIG_V_OFFSET = RECEIPT_SIZE_BYTES + SIG_R_LENGTH + SIG_S_LENGTH;
8264

83-
// Percentage of indexer stake to slash on disputes
84-
// Parts per million. (Allows for 4 decimal points, 999,999 = 99.9999%)
85-
uint32 public slashingPercentage;
65+
uint256 private constant UINT8_BYTE_LENGTH = 1;
66+
uint256 private constant BYTES32_BYTE_LENGTH = 32;
8667

87-
// Disputes created : disputeID => Dispute
88-
// disputeID - check creation functions to see how disputeID is built
89-
mapping(bytes32 => Dispute) public disputes;
68+
uint256 private constant MAX_PPM = 1000000; // 100% in parts per million
9069

9170
// -- Events --
9271

@@ -166,19 +145,19 @@ contract DisputeManager is Managed, IDisputeManager {
166145
}
167146

168147
/**
169-
* @dev Contract Constructor
148+
* @dev Initialize this contract.
170149
* @param _arbitrator Arbitrator role
171150
* @param _minimumDeposit Minimum deposit required to create a Dispute
172-
* @param _fishermanRewardPercentage Percent of slashed funds for fisherman (basis points)
173-
* @param _slashingPercentage Percentage of indexer stake slashed (basis points)
151+
* @param _fishermanRewardPercentage Percent of slashed funds for fisherman (ppm)
152+
* @param _slashingPercentage Percentage of indexer stake slashed (ppm)
174153
*/
175-
constructor(
154+
function initialize(
176155
address _controller,
177156
address _arbitrator,
178157
uint256 _minimumDeposit,
179158
uint32 _fishermanRewardPercentage,
180159
uint32 _slashingPercentage
181-
) {
160+
) external onlyImpl {
182161
Managed._initialize(_controller);
183162

184163
// Settings
@@ -575,7 +554,7 @@ contract DisputeManager is Managed, IDisputeManager {
575554
* @param _disputeID ID of the dispute to be accepted
576555
*/
577556
function acceptDispute(bytes32 _disputeID) external override onlyArbitrator {
578-
Dispute memory dispute =_resolveDispute(_disputeID);
557+
Dispute memory dispute = _resolveDispute(_disputeID);
579558

580559
// Slash
581560
uint256 tokensToReward = _slashIndexer(dispute.indexer, dispute.fisherman);
@@ -605,7 +584,7 @@ contract DisputeManager is Managed, IDisputeManager {
605584
* @param _disputeID ID of the dispute to be rejected
606585
*/
607586
function rejectDispute(bytes32 _disputeID) external override onlyArbitrator {
608-
Dispute memory dispute =_resolveDispute(_disputeID);
587+
Dispute memory dispute = _resolveDispute(_disputeID);
609588

610589
// Handle conflicting dispute if any
611590
require(
@@ -627,7 +606,7 @@ contract DisputeManager is Managed, IDisputeManager {
627606
* @param _disputeID ID of the dispute to be disregarded
628607
*/
629608
function drawDispute(bytes32 _disputeID) external override onlyArbitrator {
630-
Dispute memory dispute =_resolveDispute(_disputeID);
609+
Dispute memory dispute = _resolveDispute(_disputeID);
631610

632611
// Return deposit to the fisherman
633612
if (dispute.deposit > 0) {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
3+
pragma solidity ^0.7.3;
4+
5+
import "../governance/Managed.sol";
6+
7+
import "./IDisputeManager.sol";
8+
9+
contract DisputeManagerV1Storage is Managed {
10+
// -- State --
11+
12+
bytes32 internal DOMAIN_SEPARATOR;
13+
14+
// The arbitrator is solely in control of arbitrating disputes
15+
address public arbitrator;
16+
17+
// Minimum deposit required to create a Dispute
18+
uint256 public minimumDeposit;
19+
20+
// Percentage of indexer slashed funds to assign as a reward to fisherman in successful dispute
21+
// Parts per million. (Allows for 4 decimal points, 999,999 = 99.9999%)
22+
uint32 public fishermanRewardPercentage;
23+
24+
// Percentage of indexer stake to slash on disputes
25+
// Parts per million. (Allows for 4 decimal points, 999,999 = 99.9999%)
26+
uint32 public slashingPercentage;
27+
28+
// Disputes created : disputeID => Dispute
29+
// disputeID - check creation functions to see how disputeID is built
30+
mapping(bytes32 => IDisputeManager.Dispute) public disputes;
31+
}

contracts/upgrades/GraphProxyAdmin.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
13
pragma solidity ^0.7.3;
24

35
import "../governance/Governed.sol";

graph.config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ contracts:
4949
curationTaxPercentage: 50000 # 5% (parts per million)
5050
minimumCurationDeposit: "1000000000000000000" # 1 GRT
5151
DisputeManager:
52+
proxy: true
5253
init:
5354
controller: "${{Controller.address}}"
5455
arbitrator: *arbitrator

test/lib/deployment.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,21 @@ export async function deployDisputeManager(
138138
deployer: Signer,
139139
controller: string,
140140
arbitrator: string,
141+
proxyAdmin: GraphProxyAdmin,
141142
): Promise<DisputeManager> {
142143
// Deploy
143-
return deployContract(
144+
return network.deployContractWithProxy(
145+
proxyAdmin,
144146
'DisputeManager',
147+
[
148+
controller,
149+
arbitrator,
150+
defaults.dispute.minimumDeposit.toString(),
151+
defaults.dispute.fishermanRewardPercentage.toString(),
152+
defaults.dispute.slashingPercentage.toString(),
153+
],
145154
deployer,
146-
controller,
147-
arbitrator,
148-
defaults.dispute.minimumDeposit.toString(),
149-
defaults.dispute.fishermanRewardPercentage.toString(),
150-
defaults.dispute.slashingPercentage.toString(),
155+
false,
151156
) as Promise<DisputeManager>
152157
}
153158

test/lib/fixtures.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export class NetworkFixture {
3535
deployer,
3636
controller.address,
3737
arbitratorAddress,
38+
proxyAdmin,
3839
)
3940
const rewardsManager = await deployment.deployRewardsManager(
4041
deployer,

0 commit comments

Comments
 (0)