@@ -12,16 +12,24 @@ import "./DisputeKitClassicBase.sol";
12
12
import "../KlerosCore.sol " ;
13
13
import "../../proxy/UUPSProxiable.sol " ;
14
14
15
- interface IToken {
15
+ interface IERC20OrERC721 {
16
16
/// @dev Returns the number of tokens in `owner` account.
17
17
/// @param owner The address of the owner.
18
18
/// @return balance The number of tokens in `owner` account.
19
19
function balanceOf (address owner ) external view returns (uint256 balance );
20
20
}
21
21
22
+ interface IERC1155 {
23
+ /// @dev Returns the balance of an ERC-1155 token.
24
+ /// @param account The address of the token holder
25
+ /// @param id ID of the token
26
+ /// @return The token balance
27
+ function balanceOf (address account , uint256 id ) external view returns (uint256 );
28
+ }
29
+
22
30
/// @title DisputeKitGated
23
31
/// Dispute kit implementation adapted from DisputeKitClassic
24
- /// - a drawing system: proportional to staked PNK with a non-zero balance of `tokenGate`,
32
+ /// - a drawing system: proportional to staked PNK with a non-zero balance of `tokenGate` where `tokenGate` is an ERC20, ERC721 or ERC1155
25
33
/// - a vote aggregation system: plurality,
26
34
/// - an incentive system: equal split between coherent votes,
27
35
/// - an appeal system: fund 2 choices only, vote on any choice.
@@ -30,7 +38,9 @@ contract DisputeKitGated is DisputeKitClassicBase, UUPSProxiable {
30
38
// * Storage * //
31
39
// ************************************* //
32
40
33
- IToken public tokenGate; // The token used for gating access.
41
+ address public tokenGate; // The token used for gating access.
42
+ uint256 public tokenId; // Only used for ERC-1155
43
+ bool public isERC1155; // True if the tokenGate is an ERC-1155, false otherwise.
34
44
35
45
// ************************************* //
36
46
// * Constructor * //
@@ -45,9 +55,19 @@ contract DisputeKitGated is DisputeKitClassicBase, UUPSProxiable {
45
55
/// @param _governor The governor's address.
46
56
/// @param _core The KlerosCore arbitrator.
47
57
/// @param _tokenGate The token used for gating access.
48
- function initialize (address _governor , KlerosCore _core , IToken _tokenGate ) external reinitializer (1 ) {
58
+ /// @param _tokenId The token ID for ERC-1155 (ignored for other token types)
59
+ /// @param _isERC1155 Whether the token is an ERC-1155
60
+ function initialize (
61
+ address _governor ,
62
+ KlerosCore _core ,
63
+ address _tokenGate ,
64
+ uint256 _tokenId ,
65
+ bool _isERC1155
66
+ ) external reinitializer (1 ) {
49
67
__DisputeKitClassicBase_initialize (_governor, _core);
50
68
tokenGate = _tokenGate;
69
+ tokenId = _tokenId;
70
+ isERC1155 = _isERC1155;
51
71
}
52
72
53
73
// ************************ //
@@ -60,6 +80,22 @@ contract DisputeKitGated is DisputeKitClassicBase, UUPSProxiable {
60
80
// NOP
61
81
}
62
82
83
+ /// @dev Changes the `tokenGate` to an ERC-20 or ERC-721 token.
84
+ /// @param _tokenGate The new value for the `tokenGate` storage variable.
85
+ function changeTokenGateERC20OrERC721 (address _tokenGate ) external onlyByGovernor {
86
+ tokenGate = _tokenGate;
87
+ isERC1155 = false ;
88
+ }
89
+
90
+ /// @dev Changes the `tokenGate` to an ERC-1155 token.
91
+ /// @param _tokenGate The new value for the `tokenGate` storage variable.
92
+ /// @param _tokenId The new value for the `tokenId` storage variable.
93
+ function changeTokenGateERC1155 (address _tokenGate , uint256 _tokenId ) external onlyByGovernor {
94
+ tokenGate = _tokenGate;
95
+ tokenId = _tokenId;
96
+ isERC1155 = true ;
97
+ }
98
+
63
99
// ************************************* //
64
100
// * Internal * //
65
101
// ************************************* //
@@ -78,6 +114,12 @@ contract DisputeKitGated is DisputeKitClassicBase, UUPSProxiable {
78
114
uint256 _coreDisputeID ,
79
115
address _juror
80
116
) internal view override returns (bool ) {
81
- return super ._postDrawCheck (_round, _coreDisputeID, _juror) && tokenGate.balanceOf (_juror) > 0 ;
117
+ if (! super ._postDrawCheck (_round, _coreDisputeID, _juror)) return false ;
118
+
119
+ if (isERC1155) {
120
+ return IERC1155 (tokenGate).balanceOf (_juror, tokenId) > 0 ;
121
+ } else {
122
+ return IERC20OrERC721 (tokenGate).balanceOf (_juror) > 0 ;
123
+ }
82
124
}
83
125
}
0 commit comments