- Notifications
You must be signed in to change notification settings - Fork 50
New dispute kit gated for Argentinian consumer protection lawyers #2189
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
Merged
+687 −21
Merged
Changes from 1 commit
Commits
Show all changes
4 commits Select commit Hold shift + click to select a range
b6ca2ad feat: new dispute kit with specialized gating logic
jaybuidl f5f3079 test: added coverage for the Argentina CP DK
jaybuidl 7f64aba refactor: moved more logic to _postDrawHook() to avoid extra push/pop
jaybuidl 32fe70a refactor: renamed token accreditedLawyerToken into accreditedProfessi…
jaybuidl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions 143 contracts/src/arbitration/dispute-kits/DisputeKitGatedArgentinaConsumerProtection.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| | ||
| pragma solidity ^0.8.24; | ||
| | ||
| import {DisputeKitClassicBase} from "./DisputeKitClassicBase.sol"; | ||
| import {KlerosCore} from "../KlerosCore.sol"; | ||
| | ||
| interface IBalanceHolder { | ||
| /// @notice Returns the number of tokens in `owner` account. | ||
| /// @dev Compatible with ERC-20 and ERC-721. | ||
| /// @param owner The address of the owner. | ||
| /// @return balance The number of tokens in `owner` account. | ||
| function balanceOf(address owner) external view returns (uint256 balance); | ||
| } | ||
| | ||
| /// @title DisputeKitGatedArgentinaConsumerProtection | ||
| /// @notice Dispute kit implementation adapted from DisputeKitClassic | ||
| /// - a drawing system: proportional to staked PNK among the jurors holding a `accreditedLawyerToken` or a `accreditedConsumerProtectionLawyerToken` | ||
| /// and at least one of the drawn jurors is holding a `accreditedConsumerProtectionLawyerToken`, | ||
| /// - a vote aggregation system: plurality, | ||
| /// - an incentive system: equal split between coherent votes, | ||
| /// - an appeal system: fund 2 choices only, vote on any choice. | ||
| contract DisputeKitGatedArgentinaConsumerProtection is DisputeKitClassicBase { | ||
| string public constant override version = "2.0.0"; | ||
| | ||
| // ************************************* // | ||
| // * Storage * // | ||
| // ************************************* // | ||
| | ||
| address public accreditedLawyerToken; // The address of the accredited lawyer token. | ||
| address public accreditedConsumerProtectionLawyerToken; // The address of the accredited consumer protection lawyer token. | ||
| mapping(uint256 localDisputeID => mapping(uint256 localRoundID => bool)) public drawnConsumerProtectionLawyer; // Maps the local dispute and round ID to the boolean indicating if the consumer protection lawyer was drawn. | ||
| | ||
| // ************************************* // | ||
| // * Constructor * // | ||
| // ************************************* // | ||
| | ||
| /// @custom:oz-upgrades-unsafe-allow constructor | ||
| constructor() { | ||
| _disableInitializers(); | ||
| } | ||
| | ||
| /// @notice Initializer. | ||
| /// @param _owner The owner's address. | ||
| /// @param _core The KlerosCore arbitrator. | ||
| /// @param _wNative The wrapped native token address, typically wETH. | ||
| /// @param _accreditedLawyerToken The address of the accredited lawyer token. | ||
| /// @param _accreditedConsumerProtectionLawyerToken The address of the accredited consumer protection lawyer token. | ||
| function initialize( | ||
| address _owner, | ||
| KlerosCore _core, | ||
| address _wNative, | ||
| address _accreditedLawyerToken, | ||
| address _accreditedConsumerProtectionLawyerToken | ||
| ) external initializer { | ||
| __DisputeKitClassicBase_initialize(_owner, _core, _wNative); | ||
| accreditedLawyerToken = _accreditedLawyerToken; | ||
| accreditedConsumerProtectionLawyerToken = _accreditedConsumerProtectionLawyerToken; | ||
| } | ||
jaybuidl marked this conversation as resolved. Show resolved Hide resolved | ||
| | ||
| // ************************ // | ||
| // * Governance * // | ||
| // ************************ // | ||
| | ||
| /// @dev Access Control to perform implementation upgrades (UUPS Proxiable) | ||
| /// Only the owner can perform upgrades (`onlyByOwner`) | ||
| function _authorizeUpgrade(address) internal view override onlyByOwner { | ||
| // NOP | ||
| } | ||
| | ||
| /// @notice Changes the accredited lawyer token. | ||
| /// @param _accreditedLawyerToken The address of the accredited lawyer token. | ||
| function changeAccreditedLawyerToken(address _accreditedLawyerToken) external onlyByOwner { | ||
| accreditedLawyerToken = _accreditedLawyerToken; | ||
| } | ||
| | ||
| /// @notice Changes the accredited consumer protection lawyer token. | ||
| /// @param _accreditedConsumerProtectionLawyerToken The address of the accredited consumer protection lawyer token. | ||
| function changeAccreditedConsumerProtectionLawyerToken( | ||
| address _accreditedConsumerProtectionLawyerToken | ||
| ) external onlyByOwner { | ||
| accreditedConsumerProtectionLawyerToken = _accreditedConsumerProtectionLawyerToken; | ||
| } | ||
jaybuidl marked this conversation as resolved. Outdated Show resolved Hide resolved | ||
| | ||
| // ************************************* // | ||
| // * State Modifiers * // | ||
| // ************************************* // | ||
| | ||
| /// @inheritdoc DisputeKitClassicBase | ||
| function draw( | ||
| uint256 _coreDisputeID, | ||
| uint256 _nonce, | ||
| uint256 _roundNbVotes | ||
| ) public override onlyByCore isActive(_coreDisputeID) returns (address drawnAddress, uint96 fromSubcourtID) { | ||
| (drawnAddress, fromSubcourtID) = super.draw(_coreDisputeID, _nonce, _roundNbVotes); | ||
| | ||
| if (drawnAddress == address(0)) return (drawnAddress, fromSubcourtID); | ||
| | ||
| uint256 localDisputeID = coreDisputeIDToLocal[_coreDisputeID]; | ||
| Dispute storage dispute = disputes[localDisputeID]; | ||
| uint256 localRoundID = dispute.rounds.length - 1; | ||
| if (IBalanceHolder(accreditedConsumerProtectionLawyerToken).balanceOf(drawnAddress) > 0) { | ||
| // The drawnAddress is a consumer protection lawyer. | ||
| drawnConsumerProtectionLawyer[localDisputeID][localRoundID] = true; | ||
| } else { | ||
| // The drawnAddress is not a consumer protection lawyer. | ||
| if ( | ||
| dispute.rounds[localRoundID].votes.length == _roundNbVotes && | ||
| !drawnConsumerProtectionLawyer[localDisputeID][localRoundID] | ||
| ) { | ||
| // This is the last draw iteration and we still have not drawn a consumer protection lawyer. | ||
| // Drop the last round.votes pushed by super.draw(), so that another iteration can try again. | ||
| drawnAddress = address(0); | ||
| dispute.rounds[localRoundID].votes.pop(); | ||
| // Note that round.alreadyDrawn[drawnAddress] is not cleared because we don't know if it has been drawn more than once. | ||
| // It's fine because this DisputeKit does not enable singleDrawPerJuror. | ||
| } | ||
| } | ||
| return (drawnAddress, fromSubcourtID); | ||
| } | ||
jaybuidl marked this conversation as resolved. Show resolved Hide resolved | ||
| | ||
| // ************************************* // | ||
| // * Internal * // | ||
| // ************************************* // | ||
| | ||
| /// @inheritdoc DisputeKitClassicBase | ||
| function _postDrawCheck( | ||
| Round storage _round, | ||
| uint256 _coreDisputeID, | ||
| address _juror | ||
| ) internal view override returns (bool) { | ||
| if (!super._postDrawCheck(_round, _coreDisputeID, _juror)) return false; | ||
| return | ||
| (IBalanceHolder(accreditedLawyerToken).balanceOf(_juror) > 0) || | ||
| (IBalanceHolder(accreditedConsumerProtectionLawyerToken).balanceOf(_juror) > 0); | ||
| } | ||
jaybuidl marked this conversation as resolved. Show resolved Hide resolved | ||
| | ||
| // ************************************* // | ||
| // * Errors * // | ||
| // ************************************* // | ||
| | ||
| error TokenNotSupported(address tokenGate); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.