Skip to content

Commit cca96fc

Browse files
committed
feat: added support for ERC1155
1 parent 3ac630f commit cca96fc

File tree

1 file changed

+47
-5
lines changed

1 file changed

+47
-5
lines changed

contracts/src/arbitration/dispute-kits/DisputeKitGated.sol

+47-5
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,24 @@ import "./DisputeKitClassicBase.sol";
1212
import "../KlerosCore.sol";
1313
import "../../proxy/UUPSProxiable.sol";
1414

15-
interface IToken {
15+
interface IERC20OrERC721 {
1616
/// @dev Returns the number of tokens in `owner` account.
1717
/// @param owner The address of the owner.
1818
/// @return balance The number of tokens in `owner` account.
1919
function balanceOf(address owner) external view returns (uint256 balance);
2020
}
2121

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+
2230
/// @title DisputeKitGated
2331
/// 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
2533
/// - a vote aggregation system: plurality,
2634
/// - an incentive system: equal split between coherent votes,
2735
/// - an appeal system: fund 2 choices only, vote on any choice.
@@ -30,7 +38,9 @@ contract DisputeKitGated is DisputeKitClassicBase, UUPSProxiable {
3038
// * Storage * //
3139
// ************************************* //
3240

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.
3444

3545
// ************************************* //
3646
// * Constructor * //
@@ -45,9 +55,19 @@ contract DisputeKitGated is DisputeKitClassicBase, UUPSProxiable {
4555
/// @param _governor The governor's address.
4656
/// @param _core The KlerosCore arbitrator.
4757
/// @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) {
4967
__DisputeKitClassicBase_initialize(_governor, _core);
5068
tokenGate = _tokenGate;
69+
tokenId = _tokenId;
70+
isERC1155 = _isERC1155;
5171
}
5272

5373
// ************************ //
@@ -60,6 +80,22 @@ contract DisputeKitGated is DisputeKitClassicBase, UUPSProxiable {
6080
// NOP
6181
}
6282

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+
6399
// ************************************* //
64100
// * Internal * //
65101
// ************************************* //
@@ -78,6 +114,12 @@ contract DisputeKitGated is DisputeKitClassicBase, UUPSProxiable {
78114
uint256 _coreDisputeID,
79115
address _juror
80116
) 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+
}
82124
}
83125
}

0 commit comments

Comments
 (0)