@kleros/kleros-v2-contracts
Smart contracts for Kleros v2
Deployed Addresses
Refresh the list of deployed contracts by running ./scripts/generateDeploymentsMarkdown.sh
.
v2-alpha-1
Chiado
- ArbitrableExample
- ForeignGatewayOnGnosis
- SortitionSumTreeFactory
- TokenBridge
- WETH
- WETHFaucet
- WPNKFaucet
- WrappedPinakionV2
- xKlerosLiquidV2
Goerli
Arbitrum Goerli
- PNK
- ArbitrableExampleEthFee
- BlockHashRNG
- DisputeKitClassic
- DisputeResolver
- HomeGatewayToGnosis
- KlerosCore
- PolicyRegistry
- RandomizerRNG
- SortitionModule
Getting Started
Install the Dependencies
yarn install
Run Tests
yarn test
Compile the Contracts
yarn build
Run Linter on Files
yarn lint
Fix Linter Issues on Files
yarn fix
Deploy Instructions
NOTICE: the commands below work only if you are inside the contracts/
directory.
0. Set the Environment Variables
Copy .env.example
file as .env
and edit it accordingly.
cp .env.example .env
The following env vars are required:
PRIVATE_KEY
: the private key of the deployer account used for the testnets.MAINNET_PRIVATE_KEY
: the private key of the deployer account used for Mainnet.INFURA_API_KEY
: the API key for infura.
The ones below are optional:
ETHERSCAN_API_KEY
: to verify the source of the newly deployed contracts on Etherscan.ARBISCAN_API_KEY
: to verify the source of the newly deployed contracts on Arbitrum.GNOSISSCAN_API_KEY
: to verify the source of the newly deployed contracts on Gnosis chain.
1. Update the Constructor Parameters (optional)
If some of the constructor parameters (such as the Meta Evidence) needs to change, you need to update the files in the deploy/
directory.
2. Deploy to a Local Network
The complete deployment is multi-chain, so a deployment to the local network can only simulate either the Home chain or the Foreign chain.
Shell 1: the node
yarn hardhat node --tags nothing
Shell 2: the deploy script
yarn deploy --network localhost --tags <Arbitration|VeaMock|ForeignGatewayOnEthereum|HomeGateway>
3. Deploy to Public Testnets
# ArbitrumGoerli to Chiado
yarn deploy --network arbitrumGoerli --tags Arbitration
yarn deploy --network chiado --tags ForeignGatewayOnGnosis
yarn deploy --network chiado --tags KlerosLiquidOnGnosis
yarn deploy --network arbitrumGoerli --tags HomeGatewayToGnosis
# Goerli
yarn deploy --network arbitrumGoerli --tags Arbitration
yarn deploy --network goerli --tags ForeignGatewayOnEthereum
yarn deploy --network arbitrumGoerli --tags HomeGatewayToEthereum
The deployed addresses should be displayed to the screen after the deployment is complete. If you missed them, you can always go to the deployments/<network>
directory and look for the respective file.
Running Test Fixtures
Shell 1: the node
yarn hardhat node --tags Arbitration,VeaMock
Shell 2: the test scripts
yarn test --network localhost
4. Verify the Source Code
This must be done for each network separately.
# explorer
yarn etherscan-verify --network <arbitrumGoerli|arbitrum|chiado|gnosischain|goerli|mainnet>
# sourcify
yarn sourcify --network <arbitrumGoerli|arbitrum|chiado|gnosischain|goerli|mainnet>
Ad-hoc procedures
Populating the policy registry and courts
1/ Export the registry data from V1
for network in mainnet gnosischain
do
yarn hardhat run scripts/getPoliciesV1.ts --network $network | tee config/policies.v1.$network.json
yarn hardhat run scripts/getCourtsV1.ts --network $network | tee config/courts.v1.$network.json
done
2/ Import the data to V2 - Local Network
:warning: By default this script populates from *.mainnet.json
. To populate from *.gnosischain.json
, set the variable USE_GNOSIS
to true inside scripts/populateCourts.ts.
:warning: It is possible to switch to testnet-friendly court parameters by setting the variable TESTING_PARAMETERS
to true inside scripts/populateCourts.ts.
Shell 1:
yarn hardhat node --tags Arbitration
Shell 2:
yarn hardhat run scripts/populatePolicyRegistry.ts --network localhost
yarn hardhat run scripts/populateCourts.ts --network localhost
3/ Import the data to V2 - Public Testnet
yarn hardhat run scripts/populatePolicyRegistry.ts --network arbitrumGoerli
yarn hardhat run scripts/populateCourts.ts --network arbitrumGoerli
Generate deployment artifacts for existing contracts
Usage
scripts/generateDeploymentArtifact.sh <network> <address>
Example: WETH on Gnosis chain
scripts/generateDeploymentArtifact.sh gnosischain 0xf8d1677c8a0c961938bf2f9adc3f3cfda759a9d9 > deployments/gnosischain/WETH.json
Push the contracts to a Tenderly project
Ensure that your $TENDERLY_PROJECT
and $TENDERLY_USERNAME
is set correctly in .env
.
yarn hardhat --network goerli tenderly:push
yarn hardhat --network arbitrumGoerli tenderly:push
Contents
- arbitrables
- dispute-kits
- CentralizedArbitrator
- IArbitrable
- IArbitrator
- IDisputeKit
- ISortitionModule
- KlerosCore
- KlerosGovernor
- PolicyRegistry
- SortitionModule
Contents
ArbitrableExample
Inherits: IArbitrable, IMetaEvidence
State Variables
governor
address public immutable governor;
arbitrator
IArbitrator public arbitrator;
weth
ERC20 public immutable weth;
externalIDtoLocalID
mapping(uint256 => uint256) public externalIDtoLocalID;
disputes
DisputeStruct[] public disputes;
Functions
constructor
Constructor
constructor(IArbitrator _arbitrator, uint256 _metaEvidenceID, string memory _metaEvidence, ERC20 _weth);
Parameters
Name | Type | Description |
---|---|---|
_arbitrator | IArbitrator | The arbitrator to rule on created disputes. |
_metaEvidenceID | uint256 | Unique identifier of meta-evidence. |
_metaEvidence | string | The URI of the meta evidence object for evidence submissions requests. |
_weth | ERC20 |
createDispute
TRUSTED. Calls createDispute function of the specified arbitrator to create a dispute. Note that we don’t need to check that msg.value is enough to pay arbitration fees as it’s the responsibility of the arbitrator contract.
function createDispute(
uint256 _numberOfRulingOptions,
bytes calldata _arbitratorExtraData,
uint256 _metaEvidenceID,
uint256 _evidenceGroupID,
uint256 _feeInWeth
) external payable returns (uint256 disputeID);
Parameters
Name | Type | Description |
---|---|---|
_numberOfRulingOptions | uint256 | Number of ruling options. Must be greater than 1, otherwise there is nothing to choose from. |
_arbitratorExtraData | bytes | Extra data for the arbitrator. |
_metaEvidenceID | uint256 | Unique identifier of meta-evidence. |
_evidenceGroupID | uint256 | Unique identifier of the evidence group that is linked to this dispute. |
_feeInWeth | uint256 | Amount of fees in WETH for the arbitrator. |
Returns
Name | Type | Description |
---|---|---|
disputeID | uint256 | Dispute id (on arbitrator side) of the dispute created. |
rule
To be called by the arbitrator of the dispute, to declare the winning ruling.
function rule(uint256 _externalDisputeID, uint256 _ruling) external override;
Parameters
Name | Type | Description |
---|---|---|
_externalDisputeID | uint256 | ID of the dispute in arbitrator contract. |
_ruling | uint256 | The ruling choice of the arbitration. |
changeMetaEvidence
function changeMetaEvidence(uint256 _metaEvidenceID, string memory _metaEvidence) external;
changeArbitrator
function changeArbitrator(IArbitrator _arbitrator) external;
Structs
DisputeStruct
struct DisputeStruct {
bool isRuled;
uint256 ruling;
uint256 numberOfRulingOptions;
}
ArbitrableExampleEthFee
Inherits: IArbitrable, IMetaEvidence
State Variables
META_EVIDENCE_ID
uint256 META_EVIDENCE_ID = 0;
governor
address public governor;
arbitrator
IArbitrator public immutable arbitrator;
externalIDtoLocalID
mapping(uint256 => uint256) public externalIDtoLocalID;
disputes
DisputeStruct[] public disputes;
Functions
constructor
Constructor
constructor(IArbitrator _arbitrator, string memory _metaEvidence);
Parameters
Name | Type | Description |
---|---|---|
_arbitrator | IArbitrator | The arbitrator to rule on created disputes. |
_metaEvidence | string | The URI of the meta evidence object for evidence submissions requests. |
createDispute
TRUSTED. Calls createDispute function of the specified arbitrator to create a dispute. Note that we don’t need to check that msg.value is enough to pay arbitration fees as it’s the responsibility of the arbitrator contract.
function createDispute(uint256 _numberOfRulingOptions, bytes calldata _arbitratorExtraData, uint256 _evidenceGroupID)
external
payable
returns (uint256 disputeID);
Parameters
Name | Type | Description |
---|---|---|
_numberOfRulingOptions | uint256 | Number of ruling options. Must be greater than 1, otherwise there is nothing to choose from. |
_arbitratorExtraData | bytes | Extra data for the arbitrator. |
_evidenceGroupID | uint256 | Unique identifier of the evidence group that is linked to this dispute. |
Returns
Name | Type | Description |
---|---|---|
disputeID | uint256 | Dispute id (on arbitrator side) of the dispute created. |
rule
To be called by the arbitrator of the dispute, to declare the winning ruling.
function rule(uint256 _externalDisputeID, uint256 _ruling) external override;
Parameters
Name | Type | Description |
---|---|---|
_externalDisputeID | uint256 | ID of the dispute in arbitrator contract. |
_ruling | uint256 | The ruling choice of the arbitration. |
changeMetaEvidence
function changeMetaEvidence(string memory _metaEvidence) external;
Structs
DisputeStruct
struct DisputeStruct {
bool isRuled;
uint256 ruling;
uint256 numberOfRulingOptions;
}
DisputeResolver
Inherits: IArbitrable, IMetaEvidence
State Variables
arbitrator
IArbitrator public immutable arbitrator;
disputes
DisputeStruct[] public disputes;
externalIDtoLocalID
mapping(uint256 => uint256) public externalIDtoLocalID;
Functions
constructor
Constructor
constructor(IArbitrator _arbitrator);
Parameters
Name | Type | Description |
---|---|---|
_arbitrator | IArbitrator | Target global arbitrator for any disputes. |
createDispute
TRUSTED. Calls createDispute function of the specified arbitrator to create a dispute. Note that we don’t need to check that msg.value is enough to pay arbitration fees as it’s the responsibility of the arbitrator contract.
function createDispute(
bytes calldata _arbitratorExtraData,
string calldata _metaevidenceURI,
uint256 _numberOfRulingOptions
) external payable returns (uint256 disputeID);
Parameters
Name | Type | Description |
---|---|---|
_arbitratorExtraData | bytes | Extra data for the arbitrator of the dispute. |
_metaevidenceURI | string | Link to metaevidence of the dispute. |
_numberOfRulingOptions | uint256 | Number of ruling options. |
Returns
Name | Type | Description |
---|---|---|
disputeID | uint256 | Dispute id (on arbitrator side) of the created dispute. |
rule
To be called by the arbitrator of the dispute, to declare the winning ruling.
function rule(uint256 _externalDisputeID, uint256 _ruling) external override;
Parameters
Name | Type | Description |
---|---|---|
_externalDisputeID | uint256 | ID of the dispute in arbitrator contract. |
_ruling | uint256 | The ruling choice of the arbitration. |
Structs
DisputeStruct
struct DisputeStruct {
bytes arbitratorExtraData;
bool isRuled;
uint256 ruling;
uint256 numberOfRulingOptions;
}
Contents
BaseDisputeKit
Inherits: IDisputeKit
State Variables
governor
address public governor;
core
KlerosCore public core;
Functions
onlyByGovernor
modifier onlyByGovernor();
onlyByCore
modifier onlyByCore();
constructor
Constructor.
constructor(address _governor, KlerosCore _core);
Parameters
Name | Type | Description |
---|---|---|
_governor | address | The governor's address. |
_core | KlerosCore | The KlerosCore arbitrator. |
executeGovernorProposal
Allows the governor to call anything on behalf of the contract.
function executeGovernorProposal(address _destination, uint256 _amount, bytes memory _data) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_destination | address | The destination of the call. |
_amount | uint256 | The value sent with the call. |
_data | bytes | The data sent with the call. |
_postDrawCheck
Checks that the chosen address satisfies certain conditions for being drawn.
function _postDrawCheck(uint256 _coreDisputeID, address _juror) internal virtual returns (bool);
Parameters
Name | Type | Description |
---|---|---|
_coreDisputeID | uint256 | ID of the dispute in the core contract. |
_juror | address | Chosen address. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | Whether the address can be drawn or not. |
DisputeKitClassic
Inherits: BaseDisputeKit, IEvidence
State Variables
WINNER_STAKE_MULTIPLIER
uint256 public constant WINNER_STAKE_MULTIPLIER = 10000;
LOSER_STAKE_MULTIPLIER
uint256 public constant LOSER_STAKE_MULTIPLIER = 20000;
LOSER_APPEAL_PERIOD_MULTIPLIER
uint256 public constant LOSER_APPEAL_PERIOD_MULTIPLIER = 5000;
ONE_BASIS_POINT
uint256 public constant ONE_BASIS_POINT = 10000;
disputes
Dispute[] public disputes;
coreDisputeIDToLocal
mapping(uint256 => uint256) public coreDisputeIDToLocal;
Functions
notJumped
modifier notJumped(uint256 _coreDisputeID);
constructor
Constructor.
constructor(address _governor, KlerosCore _core) BaseDisputeKit(_governor, _core);
Parameters
Name | Type | Description |
---|---|---|
_governor | address | The governor's address. |
_core | KlerosCore | The KlerosCore arbitrator. |
changeGovernor
Changes the governor
storage variable.
function changeGovernor(address payable _governor) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_governor | address payable | The new value for the governor storage variable. |
changeCore
Changes the core
storage variable.
function changeCore(address _core) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_core | address | The new value for the core storage variable. |
createDispute
Creates a local dispute and maps it to the dispute ID in the Core contract. Note: Access restricted to Kleros Core only.
function createDispute(uint256 _coreDisputeID, uint256 _numberOfChoices, bytes calldata _extraData, uint256 _nbVotes)
external
override
onlyByCore;
Parameters
Name | Type | Description |
---|---|---|
_coreDisputeID | uint256 | The ID of the dispute in Kleros Core. |
_numberOfChoices | uint256 | Number of choices of the dispute |
_extraData | bytes | Additional info about the dispute, for possible use in future dispute kits. |
_nbVotes | uint256 | Number of votes for this dispute. |
draw
Draws the juror from the sortition tree. The drawn address is picked up by Kleros Core. Note: Access restricted to Kleros Core only.
function draw(uint256 _coreDisputeID)
external
override
onlyByCore
notJumped(_coreDisputeID)
returns (address drawnAddress);
Parameters
Name | Type | Description |
---|---|---|
_coreDisputeID | uint256 | The ID of the dispute in Kleros Core. |
Returns
Name | Type | Description |
---|---|---|
drawnAddress | address | The drawn address. |
castCommit
Sets the caller's commit for the specified votes. It can be called multiple times during the
commit period, each call overrides the commits of the previous one.
O(n)
where
n
is the number of votes.
function castCommit(uint256 _coreDisputeID, uint256[] calldata _voteIDs, bytes32 _commit)
external
notJumped(_coreDisputeID);
Parameters
Name | Type | Description |
---|---|---|
_coreDisputeID | uint256 | The ID of the dispute in Kleros Core. |
_voteIDs | uint256[] | The IDs of the votes. |
_commit | bytes32 | The commit. Note that justification string is a part of the commit. |
castVote
Sets the caller's choices for the specified votes.
O(n)
where
n
is the number of votes.
function castVote(
uint256 _coreDisputeID,
uint256[] calldata _voteIDs,
uint256 _choice,
uint256 _salt,
string memory _justification
) external notJumped(_coreDisputeID);
Parameters
Name | Type | Description |
---|---|---|
_coreDisputeID | uint256 | The ID of the dispute in Kleros Core. |
_voteIDs | uint256[] | The IDs of the votes. |
_choice | uint256 | The choice. |
_salt | uint256 | The salt for the commit if the votes were hidden. |
_justification | string | Justification of the choice. |
fundAppeal
Manages contributions, and appeals a dispute if at least two choices are fully funded. Note that the surplus deposit will be reimbursed.
function fundAppeal(uint256 _coreDisputeID, uint256 _choice) external payable notJumped(_coreDisputeID);
Parameters
Name | Type | Description |
---|---|---|
_coreDisputeID | uint256 | Index of the dispute in Kleros Core. |
_choice | uint256 | A choice that receives funding. |
withdrawFeesAndRewards
Allows those contributors who attempted to fund an appeal round to withdraw any reimbursable fees or rewards after the dispute gets resolved.
function withdrawFeesAndRewards(
uint256 _coreDisputeID,
address payable _beneficiary,
uint256 _coreRoundID,
uint256 _choice
) external returns (uint256 amount);
Parameters
Name | Type | Description |
---|---|---|
_coreDisputeID | uint256 | Index of the dispute in Kleros Core contract. |
_beneficiary | address payable | The address whose rewards to withdraw. |
_coreRoundID | uint256 | The round in the Kleros Core contract the caller wants to withdraw from. |
_choice | uint256 | The ruling option that the caller wants to withdraw from. |
Returns
Name | Type | Description |
---|---|---|
amount | uint256 | The withdrawn amount. |
submitEvidence
Submits evidence.
function submitEvidence(uint256 _evidenceGroupID, string calldata _evidence) external;
Parameters
Name | Type | Description |
---|---|---|
_evidenceGroupID | uint256 | Unique identifier of the evidence group the evidence belongs to. It's the submitter responsability to submit the right evidence group ID. |
_evidence | string | IPFS path to evidence, example: '/ipfs/Qmarwkf7C9RuzDEJNnarT3WZ7kem5bk8DZAzx78acJjMFH/evidence.json'. |
getFundedChoices
function getFundedChoices(uint256 _coreDisputeID) public view returns (uint256[] memory fundedChoices);
currentRuling
Gets the current ruling of a specified dispute.
function currentRuling(uint256 _coreDisputeID)
external
view
override
returns (uint256 ruling, bool tied, bool overridden);
Parameters
Name | Type | Description |
---|---|---|
_coreDisputeID | uint256 | The ID of the dispute in Kleros Core. |
Returns
Name | Type | Description |
---|---|---|
ruling | uint256 | The current ruling. |
tied | bool | Whether it's a tie or not. |
overridden | bool | Whether the ruling was overridden by appeal funding or not. |
getDegreeOfCoherence
Gets the degree of coherence of a particular voter. This function is called by Kleros Core in order to determine the amount of the reward.
function getDegreeOfCoherence(uint256 _coreDisputeID, uint256 _coreRoundID, uint256 _voteID)
external
view
override
returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
_coreDisputeID | uint256 | The ID of the dispute in Kleros Core, not in the Dispute Kit. |
_coreRoundID | uint256 | The ID of the round in Kleros Core, not in the Dispute Kit. |
_voteID | uint256 | The ID of the vote. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The degree of coherence in basis points. |
getCoherentCount
Gets the number of jurors who are eligible to a reward in this round.
function getCoherentCount(uint256 _coreDisputeID, uint256 _coreRoundID) external view override returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
_coreDisputeID | uint256 | The ID of the dispute in Kleros Core, not in the Dispute Kit. |
_coreRoundID | uint256 | The ID of the round in Kleros Core, not in the Dispute Kit. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The number of coherent jurors. |
areCommitsAllCast
Returns true if all of the jurors have cast their commits for the last round.
function areCommitsAllCast(uint256 _coreDisputeID) external view override returns (bool);
Parameters
Name | Type | Description |
---|---|---|
_coreDisputeID | uint256 | The ID of the dispute in Kleros Core. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | Whether all of the jurors have cast their commits for the last round. |
areVotesAllCast
Returns true if all of the jurors have cast their votes for the last round.
function areVotesAllCast(uint256 _coreDisputeID) external view override returns (bool);
Parameters
Name | Type | Description |
---|---|---|
_coreDisputeID | uint256 | The ID of the dispute in Kleros Core. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | Whether all of the jurors have cast their votes for the last round. |
isVoteActive
Returns true if the specified voter was active in this round.
function isVoteActive(uint256 _coreDisputeID, uint256 _coreRoundID, uint256 _voteID)
external
view
override
returns (bool);
Parameters
Name | Type | Description |
---|---|---|
_coreDisputeID | uint256 | The ID of the dispute in Kleros Core, not in the Dispute Kit. |
_coreRoundID | uint256 | The ID of the round in Kleros Core, not in the Dispute Kit. |
_voteID | uint256 | The ID of the voter. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | Whether the voter was active or not. |
getRoundInfo
function getRoundInfo(uint256 _coreDisputeID, uint256 _coreRoundID, uint256 _choice)
external
view
override
returns (
uint256 winningChoice,
bool tied,
uint256 totalVoted,
uint256 totalCommited,
uint256 nbVoters,
uint256 choiceCount
);
getVoteInfo
function getVoteInfo(uint256 _coreDisputeID, uint256 _coreRoundID, uint256 _voteID)
external
view
override
returns (address account, bytes32 commit, uint256 choice, bool voted);
_postDrawCheck
Checks that the chosen address satisfies certain conditions for being drawn.
function _postDrawCheck(uint256 _coreDisputeID, address _juror) internal view override returns (bool);
Parameters
Name | Type | Description |
---|---|---|
_coreDisputeID | uint256 | ID of the dispute in the core contract. |
_juror | address | Chosen address. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | Whether the address can be drawn or not. |
Events
DisputeCreation
event DisputeCreation(uint256 indexed _coreDisputeID, uint256 _numberOfChoices, bytes _extraData);
CommitCast
event CommitCast(uint256 indexed _coreDisputeID, uint256[] _voteIDs, bytes32 _commit);
Contribution
event Contribution(
uint256 indexed _coreDisputeID,
uint256 indexed _coreRoundID,
uint256 _choice,
address indexed _contributor,
uint256 _amount
);
Withdrawal
event Withdrawal(
uint256 indexed _coreDisputeID,
uint256 indexed _coreRoundID,
uint256 _choice,
address indexed _contributor,
uint256 _amount
);
ChoiceFunded
event ChoiceFunded(uint256 indexed _coreDisputeID, uint256 indexed _coreRoundID, uint256 indexed _choice);
Structs
Dispute
struct Dispute {
Round[] rounds;
uint256 numberOfChoices;
bool jumped;
mapping(uint256 => uint256) coreRoundIDToLocal;
bytes extraData;
}
Round
struct Round {
Vote[] votes;
uint256 winningChoice;
mapping(uint256 => uint256) counts;
bool tied;
uint256 totalVoted;
uint256 totalCommitted;
mapping(uint256 => uint256) paidFees;
mapping(uint256 => bool) hasPaid;
mapping(address => mapping(uint256 => uint256)) contributions;
uint256 feeRewards;
uint256[] fundedChoices;
uint256 nbVotes;
}
Vote
struct Vote {
address account;
bytes32 commit;
uint256 choice;
bool voted;
}
IProofOfHumanity
Functions
isRegistered
Return true if the submission is registered and not expired.
function isRegistered(address _submissionID) external view returns (bool);
Parameters
Name | Type | Description |
---|---|---|
_submissionID | address | The address of the submission. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | Whether the submission is registered or not. |
DisputeKitSybilResistant
Inherits: BaseDisputeKit, IEvidence
State Variables
WINNER_STAKE_MULTIPLIER
uint256 public constant WINNER_STAKE_MULTIPLIER = 10000;
LOSER_STAKE_MULTIPLIER
uint256 public constant LOSER_STAKE_MULTIPLIER = 20000;
LOSER_APPEAL_PERIOD_MULTIPLIER
uint256 public constant LOSER_APPEAL_PERIOD_MULTIPLIER = 5000;
ONE_BASIS_POINT
uint256 public constant ONE_BASIS_POINT = 10000;
poh
IProofOfHumanity public poh;
disputes
Dispute[] public disputes;
coreDisputeIDToLocal
mapping(uint256 => uint256) public coreDisputeIDToLocal;
Functions
notJumped
modifier notJumped(uint256 _coreDisputeID);
constructor
Constructor.
constructor(address _governor, KlerosCore _core, IProofOfHumanity _poh) BaseDisputeKit(_governor, _core);
Parameters
Name | Type | Description |
---|---|---|
_governor | address | The governor's address. |
_core | KlerosCore | The KlerosCore arbitrator. |
_poh | IProofOfHumanity | ProofOfHumanity contract. |
changeGovernor
Changes the governor
storage variable.
function changeGovernor(address payable _governor) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_governor | address payable | The new value for the governor storage variable. |
changeCore
Changes the core
storage variable.
function changeCore(address _core) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_core | address | The new value for the core storage variable. |
changePoh
Changes the poh
storage variable.
function changePoh(address _poh) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_poh | address | The new value for the poh storage variable. |
createDispute
Creates a local dispute and maps it to the dispute ID in the Core contract. Note: Access restricted to Kleros Core only.
function createDispute(uint256 _coreDisputeID, uint256 _numberOfChoices, bytes calldata _extraData, uint256 _nbVotes)
external
override
onlyByCore;
Parameters
Name | Type | Description |
---|---|---|
_coreDisputeID | uint256 | The ID of the dispute in Kleros Core. |
_numberOfChoices | uint256 | Number of choices of the dispute |
_extraData | bytes | Additional info about the dispute, for possible use in future dispute kits. |
_nbVotes | uint256 | Number of votes for this dispute. |
draw
Draws the juror from the sortition tree. The drawn address is picked up by Kleros Core. Note: Access restricted to Kleros Core only.
function draw(uint256 _coreDisputeID)
external
override
onlyByCore
notJumped(_coreDisputeID)
returns (address drawnAddress);
Parameters
Name | Type | Description |
---|---|---|
_coreDisputeID | uint256 | The ID of the dispute in Kleros Core. |
Returns
Name | Type | Description |
---|---|---|
drawnAddress | address | The drawn address. |
castCommit
Sets the caller's commit for the specified votes. It can be called multiple times during the
commit period, each call overrides the commits of the previous one.
O(n)
where
n
is the number of votes.
function castCommit(uint256 _coreDisputeID, uint256[] calldata _voteIDs, bytes32 _commit)
external
notJumped(_coreDisputeID);
Parameters
Name | Type | Description |
---|---|---|
_coreDisputeID | uint256 | The ID of the dispute in Kleros Core. |
_voteIDs | uint256[] | The IDs of the votes. |
_commit | bytes32 | The commit. Note that justification string is a part of the commit. |
castVote
Sets the caller's choices for the specified votes.
O(n)
where
n
is the number of votes.
function castVote(
uint256 _coreDisputeID,
uint256[] calldata _voteIDs,
uint256 _choice,
uint256 _salt,
string memory _justification
) external notJumped(_coreDisputeID);
Parameters
Name | Type | Description |
---|---|---|
_coreDisputeID | uint256 | The ID of the dispute in Kleros Core. |
_voteIDs | uint256[] | The IDs of the votes. |
_choice | uint256 | The choice. |
_salt | uint256 | The salt for the commit if the votes were hidden. |
_justification | string | Justification of the choice. |
fundAppeal
Manages contributions, and appeals a dispute if at least two choices are fully funded. Note that the surplus deposit will be reimbursed.
function fundAppeal(uint256 _coreDisputeID, uint256 _choice) external payable notJumped(_coreDisputeID);
Parameters
Name | Type | Description |
---|---|---|
_coreDisputeID | uint256 | Index of the dispute in Kleros Core. |
_choice | uint256 | A choice that receives funding. |
withdrawFeesAndRewards
Allows those contributors who attempted to fund an appeal round to withdraw any reimbursable fees or rewards after the dispute gets resolved.
function withdrawFeesAndRewards(
uint256 _coreDisputeID,
address payable _beneficiary,
uint256 _coreRoundID,
uint256 _choice
) external returns (uint256 amount);
Parameters
Name | Type | Description |
---|---|---|
_coreDisputeID | uint256 | Index of the dispute in Kleros Core contract. |
_beneficiary | address payable | The address whose rewards to withdraw. |
_coreRoundID | uint256 | The round in the Kleros Core contract the caller wants to withdraw from. |
_choice | uint256 | The ruling option that the caller wants to withdraw from. |
Returns
Name | Type | Description |
---|---|---|
amount | uint256 | The withdrawn amount. |
submitEvidence
Submits evidence.
function submitEvidence(uint256 _evidenceGroupID, string calldata _evidence) external;
Parameters
Name | Type | Description |
---|---|---|
_evidenceGroupID | uint256 | Unique identifier of the evidence group the evidence belongs to. It's the submitter responsability to submit the right evidence group ID. |
_evidence | string | IPFS path to evidence, example: '/ipfs/Qmarwkf7C9RuzDEJNnarT3WZ7kem5bk8DZAzx78acJjMFH/evidence.json'. |
getFundedChoices
function getFundedChoices(uint256 _coreDisputeID) public view returns (uint256[] memory fundedChoices);
currentRuling
Gets the current ruling of a specified dispute.
function currentRuling(uint256 _coreDisputeID)
external
view
override
returns (uint256 ruling, bool tied, bool overridden);
Parameters
Name | Type | Description |
---|---|---|
_coreDisputeID | uint256 | The ID of the dispute in Kleros Core. |
Returns
Name | Type | Description |
---|---|---|
ruling | uint256 | The current ruling. |
tied | bool | Whether it's a tie or not. |
overridden | bool | Whether the ruling was overridden by appeal funding or not. |
getDegreeOfCoherence
Gets the degree of coherence of a particular voter. This function is called by Kleros Core in order to determine the amount of the reward.
function getDegreeOfCoherence(uint256 _coreDisputeID, uint256 _coreRoundID, uint256 _voteID)
external
view
override
returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
_coreDisputeID | uint256 | The ID of the dispute in Kleros Core, not in the Dispute Kit. |
_coreRoundID | uint256 | The ID of the round in Kleros Core, not in the Dispute Kit. |
_voteID | uint256 | The ID of the vote. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The degree of coherence in basis points. |
getCoherentCount
Gets the number of jurors who are eligible to a reward in this round.
function getCoherentCount(uint256 _coreDisputeID, uint256 _coreRoundID) external view override returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
_coreDisputeID | uint256 | The ID of the dispute in Kleros Core, not in the Dispute Kit. |
_coreRoundID | uint256 | The ID of the round in Kleros Core, not in the Dispute Kit. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The number of coherent jurors. |
areCommitsAllCast
Returns true if all of the jurors have cast their commits for the last round.
function areCommitsAllCast(uint256 _coreDisputeID) external view override returns (bool);
Parameters
Name | Type | Description |
---|---|---|
_coreDisputeID | uint256 | The ID of the dispute in Kleros Core. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | Whether all of the jurors have cast their commits for the last round. |
areVotesAllCast
Returns true if all of the jurors have cast their votes for the last round.
function areVotesAllCast(uint256 _coreDisputeID) external view override returns (bool);
Parameters
Name | Type | Description |
---|---|---|
_coreDisputeID | uint256 | The ID of the dispute in Kleros Core. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | Whether all of the jurors have cast their votes for the last round. |
isVoteActive
Returns true if the specified voter was active in this round.
function isVoteActive(uint256 _coreDisputeID, uint256 _coreRoundID, uint256 _voteID)
external
view
override
returns (bool);
Parameters
Name | Type | Description |
---|---|---|
_coreDisputeID | uint256 | The ID of the dispute in Kleros Core, not in the Dispute Kit. |
_coreRoundID | uint256 | The ID of the round in Kleros Core, not in the Dispute Kit. |
_voteID | uint256 | The ID of the voter. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | Whether the voter was active or not. |
getRoundInfo
function getRoundInfo(uint256 _coreDisputeID, uint256 _coreRoundID, uint256 _choice)
external
view
override
returns (
uint256 winningChoice,
bool tied,
uint256 totalVoted,
uint256 totalCommited,
uint256 nbVoters,
uint256 choiceCount
);
getVoteInfo
function getVoteInfo(uint256 _coreDisputeID, uint256 _coreRoundID, uint256 _voteID)
external
view
override
returns (address account, bytes32 commit, uint256 choice, bool voted);
_postDrawCheck
Checks that the chosen address satisfies certain conditions for being drawn.
function _postDrawCheck(uint256 _coreDisputeID, address _juror) internal view override returns (bool);
Parameters
Name | Type | Description |
---|---|---|
_coreDisputeID | uint256 | ID of the dispute in the core contract. |
_juror | address | Chosen address. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | Whether the address can be drawn or not. |
_proofOfHumanity
Checks if an address belongs to the Proof of Humanity registry.
function _proofOfHumanity(address _address) internal view returns (bool);
Parameters
Name | Type | Description |
---|---|---|
_address | address | The address to check. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | registered True if registered. |
Events
DisputeCreation
event DisputeCreation(uint256 indexed _coreDisputeID, uint256 _numberOfChoices, bytes _extraData);
CommitCast
event CommitCast(uint256 indexed _coreDisputeID, uint256[] _voteIDs, bytes32 _commit);
Contribution
event Contribution(
uint256 indexed _coreDisputeID,
uint256 indexed _coreRoundID,
uint256 _choice,
address indexed _contributor,
uint256 _amount
);
Withdrawal
event Withdrawal(
uint256 indexed _coreDisputeID,
uint256 indexed _coreRoundID,
uint256 _choice,
address indexed _contributor,
uint256 _amount
);
ChoiceFunded
event ChoiceFunded(uint256 indexed _coreDisputeID, uint256 indexed _coreRoundID, uint256 indexed _choice);
Structs
Dispute
struct Dispute {
Round[] rounds;
uint256 numberOfChoices;
bool jumped;
mapping(uint256 => uint256) coreRoundIDToLocal;
bytes extraData;
}
Round
struct Round {
Vote[] votes;
uint256 winningChoice;
mapping(uint256 => uint256) counts;
bool tied;
uint256 totalVoted;
uint256 totalCommitted;
mapping(uint256 => uint256) paidFees;
mapping(uint256 => bool) hasPaid;
mapping(address => mapping(uint256 => uint256)) contributions;
uint256 feeRewards;
uint256[] fundedChoices;
uint256 nbVotes;
mapping(address => bool) alreadyDrawn;
}
Vote
struct Vote {
address account;
bytes32 commit;
uint256 choice;
bool voted;
}
CentralizedArbitrator
Inherits: IArbitrator
This is a centralized arbitrator deciding alone on the result of disputes. It illustrates how IArbitrator interface can be implemented. Note that this contract supports appeals. The ruling given by the arbitrator can be appealed by crowdfunding a desired choice.
State Variables
WINNER_STAKE_MULTIPLIER
uint256 public constant WINNER_STAKE_MULTIPLIER = 10000;
LOSER_STAKE_MULTIPLIER
uint256 public constant LOSER_STAKE_MULTIPLIER = 20000;
LOSER_APPEAL_PERIOD_MULTIPLIER
uint256 public constant LOSER_APPEAL_PERIOD_MULTIPLIER = 5000;
MULTIPLIER_DIVISOR
uint256 public constant MULTIPLIER_DIVISOR = 10000;
owner
address public owner = msg.sender;
appealDuration
uint256 public appealDuration;
arbitrationFee
uint256 private arbitrationFee;
appealFee
uint256 public appealFee;
disputes
DisputeStruct[] public disputes;
disputeIDtoRoundArray
mapping(uint256 => Round[]) public disputeIDtoRoundArray;
Functions
onlyOwner
modifier onlyOwner();
constructor
Constructor.
constructor(uint256 _arbitrationFee, uint256 _appealDuration, uint256 _appealFee);
Parameters
Name | Type | Description |
---|---|---|
_arbitrationFee | uint256 | Amount to be paid for arbitration. |
_appealDuration | uint256 | Duration of the appeal period. |
_appealFee | uint256 | Amount to be paid to fund one of the appeal choices, not counting the additional fee stake amount. |
setArbitrationFee
Set the arbitration fee. Only callable by the owner.
function setArbitrationFee(uint256 _arbitrationFee) external onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
_arbitrationFee | uint256 | Amount to be paid for arbitration. |
setAppealDuration
Set the duration of the appeal period. Only callable by the owner.
function setAppealDuration(uint256 _appealDuration) external onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
_appealDuration | uint256 | New duration of the appeal period. |
setAppealFee
Set the appeal fee. Only callable by the owner.
function setAppealFee(uint256 _appealFee) external onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
_appealFee | uint256 | Amount to be paid for appeal. |
createDispute
Create a dispute. Must be called by the arbitrable contract. Must be paid at least arbitrationCost().
function createDispute(uint256 _choices, bytes calldata _extraData)
external
payable
override
returns (uint256 disputeID);
Parameters
Name | Type | Description |
---|---|---|
_choices | uint256 | Amount of choices the arbitrator can make in this dispute. |
_extraData | bytes | Can be used to give additional info on the dispute to be created. |
Returns
Name | Type | Description |
---|---|---|
disputeID | uint256 | ID of the dispute created. |
fundAppeal
TRUSTED. Manages contributions, and appeals a dispute if at least two choices are fully funded. This function allows the appeals to be crowdfunded. Note that the surplus deposit will be reimbursed.
function fundAppeal(uint256 _disputeID, uint256 _choice) external payable;
Parameters
Name | Type | Description |
---|---|---|
_disputeID | uint256 | Index of the dispute to appeal. |
_choice | uint256 | A choice that receives funding. |
giveRuling
Give a ruling to a dispute. Once it's given the dispute can be appealed, and after the appeal period has passed this function should be called again to finalize the ruling. Accounts for the situation where the winner loses a case due to paying less appeal fees than expected.
function giveRuling(uint256 _disputeID, uint256 _ruling) external onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
_disputeID | uint256 | ID of the dispute to rule. |
_ruling | uint256 | Ruling given by the arbitrator. Note that 0 means that arbitrator chose "Refused to rule". |
withdrawFeesAndRewards
Allows to withdraw any reimbursable fees or rewards after the dispute gets resolved.
function withdrawFeesAndRewards(uint256 _disputeID, address payable _beneficiary, uint256 _round, uint256 _choice)
external
returns (uint256 amount);
Parameters
Name | Type | Description |
---|---|---|
_disputeID | uint256 | Index of the dispute in disputes array. |
_beneficiary | address payable | The address which rewards to withdraw. |
_round | uint256 | The round the caller wants to withdraw from. |
_choice | uint256 | The ruling option that the caller wants to withdraw from. |
Returns
Name | Type | Description |
---|---|---|
amount | uint256 | The withdrawn amount. |
arbitrationCost
Cost of arbitration.
function arbitrationCost(bytes calldata) public view override returns (uint256 fee);
Returns
Name | Type | Description |
---|---|---|
fee | uint256 | The required amount. |
fundingStatus
Return the funded amount and funding goal for one of the choices.
function fundingStatus(uint256 _disputeID, uint256 _choice) external view returns (uint256 funded, uint256 goal);
Parameters
Name | Type | Description |
---|---|---|
_disputeID | uint256 | The ID of the dispute to appeal. |
_choice | uint256 | The choice to check the funding status of. |
Returns
Name | Type | Description |
---|---|---|
funded | uint256 | The amount funded so far for this choice in wei. |
goal | uint256 | The amount to fully fund this choice in wei. |
appealPeriod
Compute the start and end of the dispute's appeal period, if possible. If the dispute is not appealble return (0, 0).
function appealPeriod(uint256 _disputeID) public view returns (uint256 start, uint256 end);
Parameters
Name | Type | Description |
---|---|---|
_disputeID | uint256 | ID of the dispute. |
Returns
Name | Type | Description |
---|---|---|
start | uint256 | The start of the period. |
end | uint256 | The end of the period. |
Events
AppealPossible
To be emitted when a dispute can be appealed.
event AppealPossible(uint256 indexed _disputeID, IArbitrable indexed _arbitrable);
AppealDecision
To be emitted when the current ruling is appealed.
event AppealDecision(uint256 indexed _disputeID, IArbitrable indexed _arbitrable);
Contribution
Raised when a contribution is made, inside fundAppeal function.
event Contribution(
uint256 indexed _disputeID, uint256 indexed _round, uint256 _choice, address indexed _contributor, uint256 _amount
);
Withdrawal
Raised when a contributor withdraws a non-zero value.
event Withdrawal(
uint256 indexed _disputeID, uint256 indexed _round, uint256 _choice, address indexed _contributor, uint256 _amount
);
ChoiceFunded
To be raised when a choice is fully funded for appeal.
event ChoiceFunded(uint256 indexed _disputeID, uint256 indexed _round, uint256 indexed _choice);
Structs
DisputeStruct
struct DisputeStruct {
IArbitrable arbitrated;
bytes arbitratorExtraData;
uint256 choices;
uint256 appealPeriodStart;
uint256 arbitrationFee;
uint256 ruling;
DisputeStatus status;
}
Round
struct Round {
mapping(uint256 => uint256) paidFees;
mapping(uint256 => bool) hasPaid;
mapping(address => mapping(uint256 => uint256)) contributions;
uint256 feeRewards;
uint256[] fundedChoices;
}
Enums
DisputeStatus
enum DisputeStatus {
Waiting,
Appealable,
Solved
}
IArbitrable
Functions
rule
Give a ruling for a dispute. Must be called by the arbitrator. The purpose of this function is to ensure that the address calling it has the right to rule on the contract.
function rule(uint256 _disputeID, uint256 _ruling) external;
Parameters
Name | Type | Description |
---|---|---|
_disputeID | uint256 | ID of the dispute in the Arbitrator contract. |
_ruling | uint256 | Ruling given by the arbitrator. Note that 0 is reserved for "Not able/wanting to make a decision". |
Events
Ruling
To be raised when a ruling is given.
event Ruling(IArbitrator indexed _arbitrator, uint256 indexed _disputeID, uint256 _ruling);
IArbitrator
Functions
createDispute
Create a dispute. Must be called by the arbitrable contract. Must pay at least arbitrationCost(_extraData).
function createDispute(uint256 _choices, bytes calldata _extraData) external payable returns (uint256 disputeID);
Parameters
Name | Type | Description |
---|---|---|
_choices | uint256 | Amount of choices the arbitrator can make in this dispute. |
_extraData | bytes | Can be used to give additional info on the dispute to be created. |
Returns
Name | Type | Description |
---|---|---|
disputeID | uint256 | ID of the dispute created. |
arbitrationCost
Compute the cost of arbitration. It is recommended not to increase it often, as it can be highly time and gas consuming for the arbitrated contracts to cope with fee augmentation.
function arbitrationCost(bytes calldata _extraData) external view returns (uint256 cost);
Parameters
Name | Type | Description |
---|---|---|
_extraData | bytes | Can be used to give additional info on the dispute to be created. |
Returns
Name | Type | Description |
---|---|---|
cost | uint256 | Required cost of arbitration. |
Events
DisputeCreation
To be emitted when a dispute is created.
event DisputeCreation(uint256 indexed _disputeID, IArbitrable indexed _arbitrable);
Ruling
To be raised when a ruling is given.
event Ruling(IArbitrable indexed _arbitrable, uint256 indexed _disputeID, uint256 _ruling);
IDisputeKit
Functions
createDispute
Creates a local dispute and maps it to the dispute ID in the Core contract. Note: Access restricted to Kleros Core only.
function createDispute(uint256 _coreDisputeID, uint256 _numberOfChoices, bytes calldata _extraData, uint256 _nbVotes)
external;
Parameters
Name | Type | Description |
---|---|---|
_coreDisputeID | uint256 | The ID of the dispute in Kleros Core, not in the Dispute Kit. |
_numberOfChoices | uint256 | Number of choices of the dispute |
_extraData | bytes | Additional info about the dispute, for possible use in future dispute kits. |
_nbVotes | uint256 |
draw
Draws the juror from the sortition tree. The drawn address is picked up by Kleros Core. Note: Access restricted to Kleros Core only.
function draw(uint256 _coreDisputeID) external returns (address drawnAddress);
Parameters
Name | Type | Description |
---|---|---|
_coreDisputeID | uint256 | The ID of the dispute in Kleros Core, not in the Dispute Kit. |
Returns
Name | Type | Description |
---|---|---|
drawnAddress | address | The drawn address. |
currentRuling
Gets the current ruling of a specified dispute.
function currentRuling(uint256 _coreDisputeID) external view returns (uint256 ruling, bool tied, bool overridden);
Parameters
Name | Type | Description |
---|---|---|
_coreDisputeID | uint256 | The ID of the dispute in Kleros Core, not in the Dispute Kit. |
Returns
Name | Type | Description |
---|---|---|
ruling | uint256 | The current ruling. |
tied | bool | Whether it's a tie or not. |
overridden | bool | Whether the ruling was overridden by appeal funding or not. |
getDegreeOfCoherence
Gets the degree of coherence of a particular voter. This function is called by Kleros Core in order to determine the amount of the reward.
function getDegreeOfCoherence(uint256 _coreDisputeID, uint256 _coreRoundID, uint256 _voteID)
external
view
returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
_coreDisputeID | uint256 | The ID of the dispute in Kleros Core, not in the Dispute Kit. |
_coreRoundID | uint256 | The ID of the round in Kleros Core, not in the Dispute Kit. |
_voteID | uint256 | The ID of the vote. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The degree of coherence in basis points. |
getCoherentCount
Gets the number of jurors who are eligible to a reward in this round.
function getCoherentCount(uint256 _coreDisputeID, uint256 _coreRoundID) external view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
_coreDisputeID | uint256 | The ID of the dispute in Kleros Core, not in the Dispute Kit. |
_coreRoundID | uint256 | The ID of the round in Kleros Core, not in the Dispute Kit. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The number of coherent jurors. |
areCommitsAllCast
Returns true if all of the jurors have cast their commits for the last round.
function areCommitsAllCast(uint256 _coreDisputeID) external view returns (bool);
Parameters
Name | Type | Description |
---|---|---|
_coreDisputeID | uint256 | The ID of the dispute in Kleros Core, not in the Dispute Kit. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | Whether all of the jurors have cast their commits for the last round. |
areVotesAllCast
Returns true if all of the jurors have cast their votes for the last round.
function areVotesAllCast(uint256 _coreDisputeID) external view returns (bool);
Parameters
Name | Type | Description |
---|---|---|
_coreDisputeID | uint256 | The ID of the dispute in Kleros Core, not in the Dispute Kit. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | Whether all of the jurors have cast their votes for the last round. |
isVoteActive
Returns true if the specified voter was active in this round.
function isVoteActive(uint256 _coreDisputeID, uint256 _coreRoundID, uint256 _voteID) external view returns (bool);
Parameters
Name | Type | Description |
---|---|---|
_coreDisputeID | uint256 | The ID of the dispute in Kleros Core, not in the Dispute Kit. |
_coreRoundID | uint256 | The ID of the round in Kleros Core, not in the Dispute Kit. |
_voteID | uint256 | The ID of the voter. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | Whether the voter was active or not. |
getRoundInfo
function getRoundInfo(uint256 _coreDisputeID, uint256 _coreRoundID, uint256 _choice)
external
view
returns (
uint256 winningChoice,
bool tied,
uint256 totalVoted,
uint256 totalCommited,
uint256 nbVoters,
uint256 choiceCount
);
getVoteInfo
function getVoteInfo(uint256 _coreDisputeID, uint256 _coreRoundID, uint256 _voteID)
external
view
returns (address account, bytes32 commit, uint256 choice, bool voted);
Events
Justification
Emitted when casting a vote to provide the justification of juror's choice.
event Justification(
uint256 indexed _coreDisputeID, address indexed _juror, uint256 indexed _choice, string _justification
);
ISortitionModule
Functions
createTree
function createTree(bytes32 _key, bytes memory _extraData) external;
setStake
function setStake(address _account, uint96 _courtID, uint256 _value) external;
setJurorInactive
function setJurorInactive(address _account) external;
notifyRandomNumber
function notifyRandomNumber(uint256 _drawnNumber) external;
draw
function draw(bytes32 _court, uint256 _coreDisputeID, uint256 _voteID) external view returns (address);
preStakeHook
function preStakeHook(address _account, uint96 _courtID, uint256 _stake, uint256 _penalty)
external
returns (preStakeHookResult);
createDisputeHook
function createDisputeHook(uint256 _disputeID, uint256 _roundID) external;
postDrawHook
function postDrawHook(uint256 _disputeID, uint256 _roundID) external;
Events
NewPhase
event NewPhase(Phase _phase);
Enums
Phase
enum Phase {
staking,
generating,
drawing
}
preStakeHookResult
enum preStakeHookResult {
ok,
delayed,
failed
}
KlerosCore
Inherits: IArbitrator
State Variables
FORKING_COURT
uint96 public constant FORKING_COURT = 0;
GENERAL_COURT
uint96 public constant GENERAL_COURT = 1;
NULL_DISPUTE_KIT
uint256 public constant NULL_DISPUTE_KIT = 0;
DISPUTE_KIT_CLASSIC
uint256 public constant DISPUTE_KIT_CLASSIC = 1;
DEFAULT_NB_OF_JURORS
uint256 public constant DEFAULT_NB_OF_JURORS = 3;
ALPHA_DIVISOR
uint256 public constant ALPHA_DIVISOR = 1e4;
NON_PAYABLE_AMOUNT
uint256 public constant NON_PAYABLE_AMOUNT = (2 ** 256 - 2) / 2;
SEARCH_ITERATIONS
uint256 public constant SEARCH_ITERATIONS = 10;
governor
address public governor;
pinakion
IERC20 public pinakion;
jurorProsecutionModule
address public jurorProsecutionModule;
sortitionModule
ISortitionModule public sortitionModule;
courts
Court[] public courts;
disputeKitNodes
DisputeKitNode[] public disputeKitNodes;
disputes
Dispute[] public disputes;
jurors
mapping(address => Juror) internal jurors;
Functions
onlyByGovernor
modifier onlyByGovernor();
constructor
Constructor.
constructor(
address _governor,
IERC20 _pinakion,
address _jurorProsecutionModule,
IDisputeKit _disputeKit,
bool _hiddenVotes,
uint256[4] memory _courtParameters,
uint256[4] memory _timesPerPeriod,
bytes memory _sortitionExtraData,
ISortitionModule _sortitionModuleAddress
);
Parameters
Name | Type | Description |
---|---|---|
_governor | address | The governor's address. |
_pinakion | IERC20 | The address of the token contract. |
_jurorProsecutionModule | address | The address of the juror prosecution module. |
_disputeKit | IDisputeKit | The address of the default dispute kit. |
_hiddenVotes | bool | The hiddenVotes property value of the general court. |
_courtParameters | uint256[4] | Numeric parameters of General court (minStake, alpha, feeForJuror and jurorsForCourtJump respectively). |
_timesPerPeriod | uint256[4] | The timesPerPeriod property value of the general court. |
_sortitionExtraData | bytes | The extra data for sortition module. |
_sortitionModuleAddress | ISortitionModule | The sortition module responsible for sortition of the jurors. |
executeGovernorProposal
Allows the governor to call anything on behalf of the contract.
function executeGovernorProposal(address _destination, uint256 _amount, bytes memory _data) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_destination | address | The destination of the call. |
_amount | uint256 | The value sent with the call. |
_data | bytes | The data sent with the call. |
changeGovernor
Changes the governor
storage variable.
function changeGovernor(address payable _governor) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_governor | address payable | The new value for the governor storage variable. |
changePinakion
Changes the pinakion
storage variable.
function changePinakion(IERC20 _pinakion) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_pinakion | IERC20 | The new value for the pinakion storage variable. |
changeJurorProsecutionModule
Changes the jurorProsecutionModule
storage variable.
function changeJurorProsecutionModule(address _jurorProsecutionModule) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_jurorProsecutionModule | address | The new value for the jurorProsecutionModule storage variable. |
changeSortitionModule
Changes the _sortitionModule
storage variable.
Note that the new module should be initialized for all courts.
function changeSortitionModule(ISortitionModule _sortitionModule) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_sortitionModule | ISortitionModule | The new value for the sortitionModule storage variable. |
addNewDisputeKit
Add a new supported dispute kit module to the court.
function addNewDisputeKit(IDisputeKit _disputeKitAddress, uint256 _parent) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_disputeKitAddress | IDisputeKit | The address of the dispute kit contract. |
_parent | uint256 | The ID of the parent dispute kit. It is left empty when root DK is created. Note that the root DK must be supported by the general court. |
createCourt
Creates a court under a specified parent court.
function createCourt(
uint96 _parent,
bool _hiddenVotes,
uint256 _minStake,
uint256 _alpha,
uint256 _feeForJuror,
uint256 _jurorsForCourtJump,
uint256[4] memory _timesPerPeriod,
bytes memory _sortitionExtraData,
uint256[] memory _supportedDisputeKits
) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_parent | uint96 | The parent property value of the court. |
_hiddenVotes | bool | The hiddenVotes property value of the court. |
_minStake | uint256 | The minStake property value of the court. |
_alpha | uint256 | The alpha property value of the court. |
_feeForJuror | uint256 | The feeForJuror property value of the court. |
_jurorsForCourtJump | uint256 | The jurorsForCourtJump property value of the court. |
_timesPerPeriod | uint256[4] | The timesPerPeriod property value of the court. |
_sortitionExtraData | bytes | Extra data for sortition module. |
_supportedDisputeKits | uint256[] | Indexes of dispute kits that this court will support. |
changeCourtMinStake
Changes the minStake
property value of a specified court. Don't set to a value lower than its parent's minStake
property value.
function changeCourtMinStake(uint96 _courtID, uint256 _minStake) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_courtID | uint96 | The ID of the court. |
_minStake | uint256 | The new value for the minStake property value. |
changeCourtAlpha
Changes the alpha
property value of a specified court.
function changeCourtAlpha(uint96 _courtID, uint256 _alpha) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_courtID | uint96 | The ID of the court. |
_alpha | uint256 | The new value for the alpha property value. |
changeCourtJurorFee
Changes the feeForJuror
property value of a specified court.
function changeCourtJurorFee(uint96 _courtID, uint256 _feeForJuror) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_courtID | uint96 | The ID of the court. |
_feeForJuror | uint256 | The new value for the feeForJuror property value. |
changeCourtJurorsForJump
Changes the jurorsForCourtJump
property value of a specified court.
function changeCourtJurorsForJump(uint96 _courtID, uint256 _jurorsForCourtJump) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_courtID | uint96 | The ID of the court. |
_jurorsForCourtJump | uint256 | The new value for the jurorsForCourtJump property value. |
changeCourtHiddenVotes
Changes the hiddenVotes
property value of a specified court.
function changeCourtHiddenVotes(uint96 _courtID, bool _hiddenVotes) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_courtID | uint96 | The ID of the court. |
_hiddenVotes | bool | The new value for the hiddenVotes property value. |
changeCourtTimesPerPeriod
Changes the timesPerPeriod
property value of a specified court.
function changeCourtTimesPerPeriod(uint96 _courtID, uint256[4] memory _timesPerPeriod) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_courtID | uint96 | The ID of the court. |
_timesPerPeriod | uint256[4] | The new value for the timesPerPeriod property value. |
enableDisputeKits
Adds/removes court's support for specified dispute kits.
function enableDisputeKits(uint96 _courtID, uint256[] memory _disputeKitIDs, bool _enable) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_courtID | uint96 | The ID of the court. |
_disputeKitIDs | uint256[] | The IDs of dispute kits which support should be added/removed. |
_enable | bool | Whether add or remove the dispute kits from the court. |
setStake
Sets the caller's stake in a court.
function setStake(uint96 _courtID, uint256 _stake) external;
Parameters
Name | Type | Description |
---|---|---|
_courtID | uint96 | The ID of the court. |
_stake | uint256 | The new stake. |
setStakeBySortitionModule
function setStakeBySortitionModule(address _account, uint96 _courtID, uint256 _stake, uint256 _penalty) external;
createDispute
Creates a dispute. Must be called by the arbitrable contract.
function createDispute(uint256 _numberOfChoices, bytes memory _extraData)
external
payable
override
returns (uint256 disputeID);
Parameters
Name | Type | Description |
---|---|---|
_numberOfChoices | uint256 | Number of choices for the jurors to choose from. |
_extraData | bytes | Additional info about the dispute. We use it to pass the ID of the dispute's court (first 32 bytes), the minimum number of jurors required (next 32 bytes) and the ID of the specific dispute kit (last 32 bytes). |
Returns
Name | Type | Description |
---|---|---|
disputeID | uint256 | The ID of the created dispute. |
passPeriod
Passes the period of a specified dispute.
function passPeriod(uint256 _disputeID) external;
Parameters
Name | Type | Description |
---|---|---|
_disputeID | uint256 | The ID of the dispute. |
draw
Draws jurors for the dispute. Can be called in parts.
function draw(uint256 _disputeID, uint256 _iterations) external;
Parameters
Name | Type | Description |
---|---|---|
_disputeID | uint256 | The ID of the dispute. |
_iterations | uint256 | The number of iterations to run. |
appeal
Appeals the ruling of a specified dispute.
Note: Access restricted to the Dispute Kit for this disputeID
.
function appeal(uint256 _disputeID, uint256 _numberOfChoices, bytes memory _extraData) external payable;
Parameters
Name | Type | Description |
---|---|---|
_disputeID | uint256 | The ID of the dispute. |
_numberOfChoices | uint256 | Number of choices for the dispute. Can be required during court jump. |
_extraData | bytes | Extradata for the dispute. Can be required during court jump. |
execute
Distribute tokens and ETH for the specific round of the dispute. Can be called in parts.
function execute(uint256 _disputeID, uint256 _round, uint256 _iterations) external;
Parameters
Name | Type | Description |
---|---|---|
_disputeID | uint256 | The ID of the dispute. |
_round | uint256 | The appeal round. |
_iterations | uint256 | The number of iterations to run. |
_executePenalties
Distribute the tokens and ETH for the specific round of the dispute, penalties only.
function _executePenalties(ExecuteParams memory _params) internal returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
_params | ExecuteParams | The parameters for the execution, see ExecuteParams . |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | penaltiesInRoundCache The updated penalties in round cache. |
_executeRewards
Distribute the tokens and ETH for the specific round of the dispute, rewards only.
function _executeRewards(ExecuteParams memory _params) internal;
Parameters
Name | Type | Description |
---|---|---|
_params | ExecuteParams | The parameters for the execution, see ExecuteParams . |
executeRuling
Executes a specified dispute's ruling. UNTRUSTED.
function executeRuling(uint256 _disputeID) external;
Parameters
Name | Type | Description |
---|---|---|
_disputeID | uint256 | The ID of the dispute. |
arbitrationCost
Gets the cost of arbitration in a specified court.
function arbitrationCost(bytes memory _extraData) public view override returns (uint256 cost);
Parameters
Name | Type | Description |
---|---|---|
_extraData | bytes | Additional info about the dispute. We use it to pass the ID of the court to create the dispute in (first 32 bytes) and the minimum number of jurors required (next 32 bytes). |
Returns
Name | Type | Description |
---|---|---|
cost | uint256 | The arbitration cost. |
appealCost
Gets the cost of appealing a specified dispute.
function appealCost(uint256 _disputeID) public view returns (uint256 cost);
Parameters
Name | Type | Description |
---|---|---|
_disputeID | uint256 | The ID of the dispute. |
Returns
Name | Type | Description |
---|---|---|
cost | uint256 | The appeal cost. |
appealPeriod
Gets the start and the end of a specified dispute's current appeal period.
function appealPeriod(uint256 _disputeID) public view returns (uint256 start, uint256 end);
Parameters
Name | Type | Description |
---|---|---|
_disputeID | uint256 | The ID of the dispute. |
Returns
Name | Type | Description |
---|---|---|
start | uint256 | The start of the appeal period. |
end | uint256 | The end of the appeal period. |
currentRuling
Gets the current ruling of a specified dispute.
function currentRuling(uint256 _disputeID) public view returns (uint256 ruling, bool tied, bool overridden);
Parameters
Name | Type | Description |
---|---|---|
_disputeID | uint256 | The ID of the dispute. |
Returns
Name | Type | Description |
---|---|---|
ruling | uint256 | The current ruling. |
tied | bool | Whether it's a tie or not. |
overridden | bool | Whether the ruling was overridden by appeal funding or not. |
getRoundInfo
function getRoundInfo(uint256 _disputeID, uint256 _round)
external
view
returns (
uint256 tokensAtStakePerJuror,
uint256 totalFeesForJurors,
uint256 repartitions,
uint256 penalties,
address[] memory drawnJurors,
uint256 disputeKitID,
uint256 sumRewardPaid,
uint256 sumTokenRewardPaid
);
getNumberOfRounds
function getNumberOfRounds(uint256 _disputeID) external view returns (uint256);
getJurorBalance
function getJurorBalance(address _juror, uint96 _courtID)
external
view
returns (uint256 staked, uint256 locked, uint256 nbCourts);
isSupported
function isSupported(uint96 _courtID, uint256 _disputeKitID) external view returns (bool);
getDisputeKitChildren
Gets non-primitive properties of a specified dispute kit node.
function getDisputeKitChildren(uint256 _disputeKitID) external view returns (uint256[] memory);
Parameters
Name | Type | Description |
---|---|---|
_disputeKitID | uint256 | The ID of the dispute kit. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256[] | children Indexes of children of this DK. |
getTimesPerPeriod
Gets the timesPerPeriod array for a given court.
function getTimesPerPeriod(uint96 _courtID) external view returns (uint256[4] memory timesPerPeriod);
Parameters
Name | Type | Description |
---|---|---|
_courtID | uint96 | The ID of the court to get the times from. |
Returns
Name | Type | Description |
---|---|---|
timesPerPeriod | uint256[4] | The timesPerPeriod array for the given court. |
getNumberOfVotes
Gets the number of votes permitted for the specified dispute in the latest round.
function getNumberOfVotes(uint256 _disputeID) external view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
_disputeID | uint256 | The ID of the dispute. |
isDisputeKitJumping
Returns true if the dispute kit will be switched to a parent DK.
function isDisputeKitJumping(uint256 _disputeID) external view returns (bool);
Parameters
Name | Type | Description |
---|---|---|
_disputeID | uint256 | The ID of the dispute. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | Whether DK will be switched or not. |
getDisputeKitNodesLength
function getDisputeKitNodesLength() external view returns (uint256);
getDisputeKit
Gets the dispute kit for a specific _disputeKitID
.
function getDisputeKit(uint256 _disputeKitID) external view returns (IDisputeKit);
Parameters
Name | Type | Description |
---|---|---|
_disputeKitID | uint256 | The ID of the dispute kit. |
getJurorCourtIDs
Gets the court identifiers where a specific _juror
has staked.
function getJurorCourtIDs(address _juror) public view returns (uint96[] memory);
Parameters
Name | Type | Description |
---|---|---|
_juror | address | The address of the juror. |
_enableDisputeKit
Toggles the dispute kit support for a given court.
function _enableDisputeKit(uint96 _courtID, uint256 _disputeKitID, bool _enable) internal;
Parameters
Name | Type | Description |
---|---|---|
_courtID | uint96 | The ID of the court to toggle the support for. |
_disputeKitID | uint256 | The ID of the dispute kit to toggle the support for. |
_enable | bool | Whether to enable or disable the support. |
_setStakeForAccount
Sets the specified juror's stake in a court.
O(n + p * log_k(j))
where
n
is the number of courts the juror has staked in,
p
is the depth of the court tree,
k
is the minimum number of children per node of one of these courts' sortition sum tree,
and j
is the maximum number of jurors that ever staked in one of these courts simultaneously.
function _setStakeForAccount(address _account, uint96 _courtID, uint256 _stake, uint256 _penalty)
internal
returns (bool succeeded);
Parameters
Name | Type | Description |
---|---|---|
_account | address | The address of the juror. |
_courtID | uint96 | The ID of the court. |
_stake | uint256 | The new stake. |
_penalty | uint256 | Penalized amount won't be transferred back to juror when the stake is lowered. |
Returns
Name | Type | Description |
---|---|---|
succeeded | bool | True if the call succeeded, false otherwise. |
_extraDataToCourtIDMinJurorsDisputeKit
Gets a court ID, the minimum number of jurors and an ID of a dispute kit from a specified extra data bytes array. Note that if extradata contains an incorrect value then this value will be switched to default.
function _extraDataToCourtIDMinJurorsDisputeKit(bytes memory _extraData)
internal
view
returns (uint96 courtID, uint256 minJurors, uint256 disputeKitID);
Parameters
Name | Type | Description |
---|---|---|
_extraData | bytes | The extra data bytes array. The first 32 bytes are the court ID, the next are the minimum number of jurors and the last are the dispute kit ID. |
Returns
Name | Type | Description |
---|---|---|
courtID | uint96 | The court ID. |
minJurors | uint256 | The minimum number of jurors required. |
disputeKitID | uint256 | The ID of the dispute kit. |
_safeTransfer
Calls transfer() without reverting.
function _safeTransfer(address _to, uint256 _value) internal returns (bool);
Parameters
Name | Type | Description |
---|---|---|
_to | address | Recepient address. |
_value | uint256 | Amount transferred. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | Whether transfer succeeded or not. |
_safeTransferFrom
Calls transferFrom() without reverting.
function _safeTransferFrom(address _from, address _to, uint256 _value) internal returns (bool);
Parameters
Name | Type | Description |
---|---|---|
_from | address | Sender address. |
_to | address | Recepient address. |
_value | uint256 | Amount transferred. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | Whether transfer succeeded or not. |
Events
StakeSet
event StakeSet(address indexed _address, uint256 _courtID, uint256 _amount);
StakeDelayed
event StakeDelayed(address indexed _address, uint256 _courtID, uint256 _amount, uint256 _penalty);
NewPeriod
event NewPeriod(uint256 indexed _disputeID, Period _period);
AppealPossible
event AppealPossible(uint256 indexed _disputeID, IArbitrable indexed _arbitrable);
AppealDecision
event AppealDecision(uint256 indexed _disputeID, IArbitrable indexed _arbitrable);
Draw
event Draw(address indexed _address, uint256 indexed _disputeID, uint256 _roundID, uint256 _voteID);
CourtCreated
event CourtCreated(
uint256 indexed _courtID,
uint96 indexed _parent,
bool _hiddenVotes,
uint256 _minStake,
uint256 _alpha,
uint256 _feeForJuror,
uint256 _jurorsForCourtJump,
uint256[4] _timesPerPeriod,
uint256[] _supportedDisputeKits
);
CourtModified
event CourtModified(uint96 indexed _courtID, string _param);
DisputeKitCreated
event DisputeKitCreated(uint256 indexed _disputeKitID, IDisputeKit indexed _disputeKitAddress, uint256 indexed _parent);
DisputeKitEnabled
event DisputeKitEnabled(uint96 indexed _courtID, uint256 indexed _disputeKitID, bool indexed _enable);
CourtJump
event CourtJump(uint256 indexed _disputeID, uint256 indexed _roundID, uint96 indexed _fromCourtID, uint96 _toCourtID);
DisputeKitJump
event DisputeKitJump(
uint256 indexed _disputeID, uint256 indexed _roundID, uint256 indexed _fromDisputeKitID, uint256 _toDisputeKitID
);
TokenAndETHShift
event TokenAndETHShift(
address indexed _account,
uint256 indexed _disputeID,
uint256 indexed _roundID,
uint256 _degreeOfCoherency,
int256 _tokenAmount,
int256 _ethAmount
);
LeftoverRewardSent
event LeftoverRewardSent(
uint256 indexed _disputeID, uint256 indexed _roundID, uint256 _tokenAmount, uint256 _ethAmount
);
Structs
Court
struct Court {
uint96 parent;
bool hiddenVotes;
uint256[] children;
uint256 minStake;
uint256 alpha;
uint256 feeForJuror;
uint256 jurorsForCourtJump;
uint256[4] timesPerPeriod;
mapping(uint256 => bool) supportedDisputeKits;
bool disabled;
}
Dispute
struct Dispute {
uint96 courtID;
IArbitrable arbitrated;
Period period;
bool ruled;
uint256 lastPeriodChange;
Round[] rounds;
}
Round
struct Round {
uint256 disputeKitID;
uint256 tokensAtStakePerJuror;
uint256 totalFeesForJurors;
uint256 nbVotes;
uint256 repartitions;
uint256 penalties;
address[] drawnJurors;
uint256 sumRewardPaid;
uint256 sumTokenRewardPaid;
}
Juror
struct Juror {
uint96[] courtIDs;
mapping(uint96 => uint256) stakedTokens;
mapping(uint96 => uint256) lockedTokens;
}
DisputeKitNode
struct DisputeKitNode {
uint256 parent;
uint256[] children;
IDisputeKit disputeKit;
uint256 depthLevel;
bool disabled;
}
ExecuteParams
struct ExecuteParams {
uint256 disputeID;
uint256 round;
uint256 coherentCount;
uint256 numberOfVotesInRound;
uint256 penaltiesInRound;
uint256 repartition;
}
Enums
Period
enum Period {
evidence,
commit,
vote,
appeal,
execution
}
KlerosGovernor
Inherits: IArbitrable, IMetaEvidence
State Variables
arbitrator
IArbitrator public arbitrator;
arbitratorExtraData
bytes public arbitratorExtraData;
metaEvidenceUpdates
uint256 public metaEvidenceUpdates;
submissionBaseDeposit
uint256 public submissionBaseDeposit;
submissionTimeout
uint256 public submissionTimeout;
executionTimeout
uint256 public executionTimeout;
withdrawTimeout
uint256 public withdrawTimeout;
lastApprovalTime
uint256 public lastApprovalTime;
reservedETH
uint256 public reservedETH;
submissions
Submission[] public submissions;
sessions
Session[] public sessions;
Functions
duringSubmissionPeriod
modifier duringSubmissionPeriod();
duringApprovalPeriod
modifier duringApprovalPeriod();
onlyByGovernor
modifier onlyByGovernor();
constructor
Constructor.
constructor(
IArbitrator _arbitrator,
bytes memory _arbitratorExtraData,
string memory _metaEvidence,
uint256 _submissionBaseDeposit,
uint256 _submissionTimeout,
uint256 _executionTimeout,
uint256 _withdrawTimeout
);
Parameters
Name | Type | Description |
---|---|---|
_arbitrator | IArbitrator | The arbitrator of the contract. |
_arbitratorExtraData | bytes | Extra data for the arbitrator. |
_metaEvidence | string | The URI of the meta evidence file. |
_submissionBaseDeposit | uint256 | The base deposit required for submission. |
_submissionTimeout | uint256 | Time in seconds allocated for submitting transaction list. |
_executionTimeout | uint256 | Time in seconds after approval that allows to execute transactions of the approved list. |
_withdrawTimeout | uint256 | Time in seconds after submission that allows to withdraw submitted list. |
changeSubmissionDeposit
Changes the value of the base deposit required for submitting a list.
function changeSubmissionDeposit(uint256 _submissionBaseDeposit) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_submissionBaseDeposit | uint256 | The new value of the base deposit, in wei. |
changeSubmissionTimeout
Changes the time allocated for submission. Note that it can't be changed during approval period because there can be an active dispute in the old arbitrator contract and prolonging submission timeout might switch it back to submission period.
function changeSubmissionTimeout(uint256 _submissionTimeout) external onlyByGovernor duringSubmissionPeriod;
Parameters
Name | Type | Description |
---|---|---|
_submissionTimeout | uint256 | The new duration of the submission period, in seconds. |
changeExecutionTimeout
Changes the time allocated for list's execution.
function changeExecutionTimeout(uint256 _executionTimeout) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_executionTimeout | uint256 | The new duration of the execution timeout, in seconds. |
changeWithdrawTimeout
Changes list withdrawal timeout. Note that withdrawals are only possible in the first half of the submission period.
function changeWithdrawTimeout(uint256 _withdrawTimeout) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_withdrawTimeout | uint256 | The new duration of withdraw period, in seconds. |
changeArbitrator
Changes the arbitrator of the contract. Note that it can't be changed during approval period because there can be an active dispute in the old arbitrator contract.
function changeArbitrator(IArbitrator _arbitrator, bytes memory _arbitratorExtraData)
external
onlyByGovernor
duringSubmissionPeriod;
Parameters
Name | Type | Description |
---|---|---|
_arbitrator | IArbitrator | The new trusted arbitrator. |
_arbitratorExtraData | bytes | The extra data used by the new arbitrator. |
changeMetaEvidence
Update the meta evidence used for disputes.
function changeMetaEvidence(string memory _metaEvidence) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_metaEvidence | string | URI to the new meta evidence file. |
submitList
Creates transaction list based on input parameters and submits it for potential approval and execution. Transactions must be ordered by their hash.
function submitList(
address[] memory _target,
uint256[] memory _value,
bytes memory _data,
uint256[] memory _dataSize,
string memory _description
) external payable duringSubmissionPeriod;
Parameters
Name | Type | Description |
---|---|---|
_target | address[] | List of addresses to call. |
_value | uint256[] | List of values required for respective addresses. |
_data | bytes | Concatenated calldata of all transactions of this list. |
_dataSize | uint256[] | List of lengths in bytes required to split calldata for its respective targets. |
_description | string | String in CSV format that describes list's transactions. |
withdrawTransactionList
Withdraws submitted transaction list. Reimburses submission deposit. Withdrawal is only possible during the first half of the submission period and during withdrawTimeout after the submission is made.
function withdrawTransactionList(uint256 _submissionID, bytes32 _listHash) external;
Parameters
Name | Type | Description |
---|---|---|
_submissionID | uint256 | Submission's index in the array of submitted lists of the current sesssion. |
_listHash | bytes32 | Hash of a withdrawing list. |
executeSubmissions
Approves a transaction list or creates a dispute if more than one list was submitted. TRUSTED. If nothing was submitted changes session.
function executeSubmissions() external duringApprovalPeriod;
rule
Gives a ruling for a dispute. Must be called by the arbitrator.
function rule(uint256 _disputeID, uint256 _ruling) external override;
Parameters
Name | Type | Description |
---|---|---|
_disputeID | uint256 | ID of the dispute in the Arbitrator contract. |
_ruling | uint256 | Ruling given by the arbitrator. Note that 0 is reserved for "Refuse to arbitrate". Note If the final ruling is "0" nothing is approved and deposits will stay locked in the contract. |
executeTransactionList
Executes selected transactions of the list. UNTRUSTED.
function executeTransactionList(uint256 _listID, uint256 _cursor, uint256 _count) external;
Parameters
Name | Type | Description |
---|---|---|
_listID | uint256 | The index of the transaction list in the array of lists. |
_cursor | uint256 | Index of the transaction from which to start executing. |
_count | uint256 | Number of transactions to execute. Executes until the end if set to "0" or number higher than number of transactions in the list. |
receive
Receive function to receive funds for the execution of transactions.
receive() external payable;
getExpendableFunds
Gets the sum of contract funds that are used for the execution of transactions.
function getExpendableFunds() public view returns (uint256);
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | Contract balance without reserved ETH. |
getTransactionInfo
Gets the info of the specific transaction in the specific list.
function getTransactionInfo(uint256 _listID, uint256 _transactionIndex)
external
view
returns (address target, uint256 value, bytes memory data, bool executed);
Parameters
Name | Type | Description |
---|---|---|
_listID | uint256 | The index of the transaction list in the array of lists. |
_transactionIndex | uint256 | The index of the transaction. |
Returns
Name | Type | Description |
---|---|---|
target | address | The target of the transaction. |
value | uint256 | The value of the transaction. |
data | bytes | The data of the transaction. |
executed | bool | Whether the transaction was executed or not. |
getSubmittedLists
Gets the array of submitted lists in the session. Note that this function is O(n), where n is the number of submissions in the session. This could exceed the gas limit, therefore this function should only be used for interface display and not by other contracts.
function getSubmittedLists(uint256 _session) external view returns (uint256[] memory submittedLists);
Parameters
Name | Type | Description |
---|---|---|
_session | uint256 | The ID of the session. |
Returns
Name | Type | Description |
---|---|---|
submittedLists | uint256[] | Indexes of lists that were submitted during the session. |
getNumberOfTransactions
Gets the number of transactions in the list.
function getNumberOfTransactions(uint256 _listID) external view returns (uint256 txCount);
Parameters
Name | Type | Description |
---|---|---|
_listID | uint256 | The index of the transaction list in the array of lists. |
Returns
Name | Type | Description |
---|---|---|
txCount | uint256 | The number of transactions in the list. |
getNumberOfCreatedLists
Gets the number of lists created in contract's lifetime.
function getNumberOfCreatedLists() external view returns (uint256);
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The number of created lists. |
getCurrentSessionNumber
Gets the number of the ongoing session.
function getCurrentSessionNumber() external view returns (uint256);
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The number of the ongoing session. |
Events
ListSubmitted
Emitted when a new list is submitted.
event ListSubmitted(uint256 indexed _listID, address indexed _submitter, uint256 indexed _session, string _description);
Structs
Session
struct Session {
uint256 ruling;
uint256 disputeID;
uint256[] submittedLists;
uint256 sumDeposit;
Status status;
mapping(bytes32 => bool) alreadySubmitted;
uint256 durationOffset;
}
Transaction
struct Transaction {
address target;
uint256 value;
bytes data;
bool executed;
}
Submission
struct Submission {
address payable submitter;
uint256 deposit;
Transaction[] txs;
bytes32 listHash;
uint256 submissionTime;
bool approved;
uint256 approvalTime;
}
Enums
Status
enum Status {
NoDispute,
DisputeCreated,
Resolved
}
PolicyRegistry
Author: Enrique Piqueras - epiquerass@gmail.com
A contract to maintain a policy for each court.
State Variables
governor
address public governor;
policies
mapping(uint256 => string) public policies;
Functions
onlyByGovernor
Requires that the sender is the governor.
modifier onlyByGovernor();
constructor
Constructs the PolicyRegistry
contract.
constructor(address _governor);
Parameters
Name | Type | Description |
---|---|---|
_governor | address | The governor's address. |
changeGovernor
Changes the governor
storage variable.
function changeGovernor(address _governor) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_governor | address | The new value for the governor storage variable. |
setPolicy
Sets the policy for the specified court.
function setPolicy(uint256 _courtID, string calldata _courtName, string calldata _policy) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_courtID | uint256 | The ID of the specified court. |
_courtName | string | The name of the specified court. |
_policy | string | The URI of the policy JSON. |
Events
PolicyUpdate
Emitted when a policy is updated.
event PolicyUpdate(uint256 indexed _courtID, string _courtName, string _policy);
SortitionModule
Inherits: ISortitionModule
A factory of trees that keeps track of staked values for sortition.
State Variables
MAX_STAKE_PATHS
uint256 public constant MAX_STAKE_PATHS = 4;
DEFAULT_K
uint256 public constant DEFAULT_K = 6;
governor
address public governor;
core
KlerosCore public core;
phase
Phase public phase;
minStakingTime
uint256 public minStakingTime;
maxDrawingTime
uint256 public maxDrawingTime;
lastPhaseChange
uint256 public lastPhaseChange;
randomNumberRequestBlock
uint256 public randomNumberRequestBlock;
disputesWithoutJurors
uint256 public disputesWithoutJurors;
rng
RNG public rng;
randomNumber
uint256 public randomNumber;
rngLookahead
uint256 public rngLookahead;
delayedStakeWriteIndex
uint256 public delayedStakeWriteIndex;
delayedStakeReadIndex
uint256 public delayedStakeReadIndex = 1;
sortitionSumTrees
mapping(bytes32 => SortitionSumTree) sortitionSumTrees;
delayedStakes
mapping(uint256 => DelayedStake) public delayedStakes;
Functions
onlyByGovernor
modifier onlyByGovernor();
onlyByCore
modifier onlyByCore();
constructor
Constructor.
constructor(
address _governor,
KlerosCore _core,
uint256 _minStakingTime,
uint256 _maxDrawingTime,
RNG _rng,
uint256 _rngLookahead
);
Parameters
Name | Type | Description |
---|---|---|
_governor | address | |
_core | KlerosCore | The KlerosCore. |
_minStakingTime | uint256 | Minimal time to stake |
_maxDrawingTime | uint256 | Time after which the drawing phase can be switched |
_rng | RNG | The random number generator. |
_rngLookahead | uint256 | Lookahead value for rng. |
changeMinStakingTime
Changes the minStakingTime
storage variable.
function changeMinStakingTime(uint256 _minStakingTime) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_minStakingTime | uint256 | The new value for the minStakingTime storage variable. |
changeMaxDrawingTime
Changes the maxDrawingTime
storage variable.
function changeMaxDrawingTime(uint256 _maxDrawingTime) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_maxDrawingTime | uint256 | The new value for the maxDrawingTime storage variable. |
changeRandomNumberGenerator
Changes the _rng
and _rngLookahead
storage variables.
function changeRandomNumberGenerator(RNG _rng, uint256 _rngLookahead) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_rng | RNG | The new value for the RNGenerator storage variable. |
_rngLookahead | uint256 | The new value for the rngLookahead storage variable. |
passPhase
function passPhase() external;
createTree
Create a sortition sum tree at the specified key.
function createTree(bytes32 _key, bytes memory _extraData) external override onlyByCore;
Parameters
Name | Type | Description |
---|---|---|
_key | bytes32 | The key of the new tree. |
_extraData | bytes | Extra data that contains the number of children each node in the tree should have. |
executeDelayedStakes
Executes the next delayed stakes.
function executeDelayedStakes(uint256 _iterations) external;
Parameters
Name | Type | Description |
---|---|---|
_iterations | uint256 | The number of delayed stakes to execute. |
preStakeHook
function preStakeHook(address _account, uint96 _courtID, uint256 _stake, uint256 _penalty)
external
override
onlyByCore
returns (preStakeHookResult);
createDisputeHook
function createDisputeHook(uint256, uint256) external override onlyByCore;
postDrawHook
function postDrawHook(uint256, uint256) external override onlyByCore;
notifyRandomNumber
Saves the random number to use it in sortition. Not used by this contract because the storing of the number is inlined in passPhase().
function notifyRandomNumber(uint256 _randomNumber) public override;
Parameters
Name | Type | Description |
---|---|---|
_randomNumber | uint256 | Random number returned by RNG contract. |
setStake
Sets the value for a particular court and its parent courts.
function setStake(address _account, uint96 _courtID, uint256 _value) external override onlyByCore;
Parameters
Name | Type | Description |
---|---|---|
_account | address | Address of the juror. O(log_k(n)) where k is the maximum number of children per node in the tree, and n is the maximum number of nodes ever appended. |
_courtID | uint96 | ID of the court. |
_value | uint256 | The new value. |
setJurorInactive
Unstakes the inactive juror from all courts.
O(n * (p * log_k(j)) )
where
n
is the number of courts the juror has staked in,
p
is the depth of the court tree,
k
is the minimum number of children per node of one of these courts' sortition sum tree,
and j
is the maximum number of jurors that ever staked in one of these courts simultaneously.
function setJurorInactive(address _account) external override onlyByCore;
Parameters
Name | Type | Description |
---|---|---|
_account | address | The juror to unstake. |
draw
Draw an ID from a tree using a number. Note that this function reverts if the sum of all values in the tree is 0.
function draw(bytes32 _key, uint256 _coreDisputeID, uint256 _voteID)
public
view
override
returns (address drawnAddress);
Parameters
Name | Type | Description |
---|---|---|
_key | bytes32 | The key of the tree. |
_coreDisputeID | uint256 | Index of the dispute in Kleros Core. |
_voteID | uint256 | ID of the voter. |
Returns
Name | Type | Description |
---|---|---|
drawnAddress | address | The drawn address. O(k * log_k(n)) where k is the maximum number of children per node in the tree, and n is the maximum number of nodes ever appended. |
_updateParents
Update all the parents of a node.
function _updateParents(bytes32 _key, uint256 _treeIndex, bool _plusOrMinus, uint256 _value) private;
Parameters
Name | Type | Description |
---|---|---|
_key | bytes32 | The key of the tree to update. |
_treeIndex | uint256 | The index of the node to start from. |
_plusOrMinus | bool | Whether to add (true) or substract (false). |
_value | uint256 | The value to add or substract. O(log_k(n)) where k is the maximum number of children per node in the tree, and n is the maximum number of nodes ever appended. |
_stakePathIDToAccount
Retrieves a juror's address from the stake path ID.
function _stakePathIDToAccount(bytes32 _stakePathID) internal pure returns (address account);
Parameters
Name | Type | Description |
---|---|---|
_stakePathID | bytes32 | The stake path ID to unpack. |
Returns
Name | Type | Description |
---|---|---|
account | address | The account. |
_extraDataToTreeK
function _extraDataToTreeK(bytes memory _extraData) internal pure returns (uint256 K);
_set
Set a value in a tree.
function _set(bytes32 _key, uint256 _value, bytes32 _ID) internal;
Parameters
Name | Type | Description |
---|---|---|
_key | bytes32 | The key of the tree. |
_value | uint256 | The new value. |
_ID | bytes32 | The ID of the value. O(log_k(n)) where k is the maximum number of children per node in the tree, and n is the maximum number of nodes ever appended. |
_accountAndCourtIDToStakePathID
Packs an account and a court ID into a stake path ID.
function _accountAndCourtIDToStakePathID(address _account, uint96 _courtID)
internal
pure
returns (bytes32 stakePathID);
Parameters
Name | Type | Description |
---|---|---|
_account | address | The address of the juror to pack. |
_courtID | uint96 | The court ID to pack. |
Returns
Name | Type | Description |
---|---|---|
stakePathID | bytes32 | The stake path ID. |
Structs
SortitionSumTree
struct SortitionSumTree {
uint256 K;
uint256[] stack;
uint256[] nodes;
mapping(bytes32 => uint256) IDsToNodeIndexes;
mapping(uint256 => bytes32) nodeIndexesToIDs;
}
DelayedStake
struct DelayedStake {
address account;
uint96 courtID;
uint256 stake;
uint256 penalty;
}
Contents
EvidenceModule
State Variables
arbitrator
IArbitrator public arbitrator;
Functions
constructor
constructor(IArbitrator _arbitrator);
submitEvidence
Submits evidence.
function submitEvidence(uint256 _evidenceGroupID, string calldata _evidence) external;
Parameters
Name | Type | Description |
---|---|---|
_evidenceGroupID | uint256 | Unique identifier of the evidence group the evidence belongs to. It's the submitter responsability to submit the right evidence group ID. |
_evidence | string | IPFS path to evidence, example: '/ipfs/Qmarwkf7C9RuzDEJNnarT3WZ7kem5bk8DZAzx78acJjMFH/evidence.json'. |
Events
Evidence
event Evidence(
IArbitrator indexed _arbitrator, uint256 indexed _evidenceGroupID, address indexed _party, string _evidence
);
IEvidence
Events
Evidence
To be raised when evidence is submitted. Should point to the resource (evidences are not to be stored on chain due to gas considerations).
event Evidence(uint256 indexed _evidenceGroupID, address indexed _party, string _evidence);
IMetaEvidence
Events
MetaEvidence
To be emitted when meta-evidence is submitted.
event MetaEvidence(uint256 indexed _metaEvidenceID, string _evidence);
Dispute
To be emitted when a dispute is created to link the correct meta-evidence to the disputeID.
event Dispute(
IArbitrator indexed _arbitrator, uint256 indexed _disputeID, uint256 _metaEvidenceID, uint256 _evidenceGroupID
);
ModeratedEvidenceModule
Inherits: IArbitrable, IMetaEvidence
State Variables
AMOUNT_OF_CHOICES
uint256 public constant AMOUNT_OF_CHOICES = 2;
MULTIPLIER_DIVISOR
uint256 public constant MULTIPLIER_DIVISOR = 10000;
evidences
mapping(bytes32 => EvidenceData) evidences;
disputeIDtoEvidenceID
mapping(uint256 => bytes32) public disputeIDtoEvidenceID;
arbitratorDataList
ArbitratorData[] public arbitratorDataList;
arbitrator
IArbitrator public immutable arbitrator;
governor
address public governor;
bondTimeout
uint256 public bondTimeout;
totalCostMultiplier
uint256 public totalCostMultiplier;
initialDepositMultiplier
uint256 public initialDepositMultiplier;
Functions
onlyGovernor
modifier onlyGovernor();
constructor
Constructor.
constructor(
IArbitrator _arbitrator,
address _governor,
uint256 _totalCostMultiplier,
uint256 _initialDepositMultiplier,
uint256 _bondTimeout,
bytes memory _arbitratorExtraData,
string memory _metaEvidence
);
Parameters
Name | Type | Description |
---|---|---|
_arbitrator | IArbitrator | The trusted arbitrator to resolve potential disputes. |
_governor | address | The trusted governor of the contract. |
_totalCostMultiplier | uint256 | Multiplier of arbitration fees that must be ultimately paid as fee stake. In basis points. |
_initialDepositMultiplier | uint256 | Multiplier of arbitration fees that must be paid as initial stake for submitting evidence. In basis points. |
_bondTimeout | uint256 | The time in seconds during which the last moderation status can be challenged. |
_arbitratorExtraData | bytes | Extra data for the trusted arbitrator contract. |
_metaEvidence | string | The URI of the meta evidence object for evidence submissions requests. |
changeGovernor
Change the governor of the contract.
function changeGovernor(address _governor) external onlyGovernor;
Parameters
Name | Type | Description |
---|---|---|
_governor | address | The address of the new governor. |
changeInitialDepositMultiplier
Change the proportion of arbitration fees that must be paid as fee stake by parties when there is no winner or loser (e.g. when the arbitrator refused to rule).
function changeInitialDepositMultiplier(uint256 _initialDepositMultiplier) external onlyGovernor;
Parameters
Name | Type | Description |
---|---|---|
_initialDepositMultiplier | uint256 | Multiplier of arbitration fees that must be paid as fee stake. In basis points. |
changeTotalCostMultiplier
Change the proportion of arbitration fees that must be paid as fee stake by the winner of the previous round.
function changeTotalCostMultiplier(uint256 _totalCostMultiplier) external onlyGovernor;
Parameters
Name | Type | Description |
---|---|---|
_totalCostMultiplier | uint256 | Multiplier of arbitration fees that must be paid as fee stake. In basis points. |
changeBondTimeout
Change the the time window within which evidence submissions and removals can be contested. Ongoing moderations will start using the latest bondTimeout available after calling moderate() again.
function changeBondTimeout(uint256 _bondTimeout) external onlyGovernor;
Parameters
Name | Type | Description |
---|---|---|
_bondTimeout | uint256 | Multiplier of arbitration fees that must be paid as fee stake. In basis points. |
changeMetaEvidence
Update the meta evidence used for disputes.
function changeMetaEvidence(string calldata _newMetaEvidence) external onlyGovernor;
Parameters
Name | Type | Description |
---|---|---|
_newMetaEvidence | string | The meta evidence to be used for future registration request disputes. |
changeArbitratorExtraData
Change the arbitrator to be used for disputes that may be raised in the next requests. The arbitrator is trusted to support appeal period and not reenter.
function changeArbitratorExtraData(bytes calldata _arbitratorExtraData) external onlyGovernor;
Parameters
Name | Type | Description |
---|---|---|
_arbitratorExtraData | bytes | The extra data used by the new arbitrator. |
submitEvidence
Submits evidence.
function submitEvidence(uint256 _evidenceGroupID, string calldata _evidence) external payable;
Parameters
Name | Type | Description |
---|---|---|
_evidenceGroupID | uint256 | Unique identifier of the evidence group the evidence belongs to. It's the submitter responsability to submit the right evidence group ID. |
_evidence | string | IPFS path to evidence, example: '/ipfs/Qmarwkf7C9RuzDEJNnarT3WZ7kem5bk8DZAzx78acJjMFH/evidence.json'. |
moderate
Moderates an evidence submission. Requires the contester to at least double the accumulated stake of the oposing party.
Optimization opportunity: use bytes calldata args
and compress _evidenceID and _side (only for optimistic rollups).
function moderate(bytes32 _evidenceID, Party _side) external payable;
Parameters
Name | Type | Description |
---|---|---|
_evidenceID | bytes32 | Unique identifier of the evidence submission. |
_side | Party | The side to contribute to. |
resolveModerationMarket
Resolves a moderation event once the timeout has passed.
function resolveModerationMarket(bytes32 _evidenceID) external;
Parameters
Name | Type | Description |
---|---|---|
_evidenceID | bytes32 | Unique identifier of the evidence submission. |
contribute
Make a fee contribution.
function contribute(
Moderation storage _moderation,
Party _side,
address payable _contributor,
uint256 _amount,
uint256 _totalRequired
) internal returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
_moderation | Moderation | The moderation to contribute to. |
_side | Party | The side to contribute to. |
_contributor | address payable | The contributor. |
_amount | uint256 | The amount contributed. |
_totalRequired | uint256 | The total amount required for this side. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The amount of fees contributed. |
calculateContribution
Returns the contribution value and remainder from available ETH and required amount.
function calculateContribution(uint256 _available, uint256 _requiredAmount)
internal
pure
returns (uint256 taken, uint256 remainder);
Parameters
Name | Type | Description |
---|---|---|
_available | uint256 | The amount of ETH available for the contribution. |
_requiredAmount | uint256 | The amount of ETH required for the contribution. |
Returns
Name | Type | Description |
---|---|---|
taken | uint256 | The amount of ETH taken. |
remainder | uint256 | The amount of ETH left from the contribution. |
withdrawFeesAndRewards
Withdraws contributions of moderations. Reimburses contributions if the appeal was not fully funded.
If the appeal was fully funded, sends the fee stake rewards and reimbursements proportional to the contributions made to the winner of a dispute.
Optimization opportunity: use bytes calldata args
and compress _evidenceID and _moderationID (only for optimistic rollups).
function withdrawFeesAndRewards(address payable _beneficiary, bytes32 _evidenceID, uint256 _moderationID)
external
returns (uint256 reward);
Parameters
Name | Type | Description |
---|---|---|
_beneficiary | address payable | The address that made contributions. |
_evidenceID | bytes32 | The ID of the associated evidence submission. |
_moderationID | uint256 | The ID of the moderatino occurence. |
rule
Give a ruling for a dispute. Must be called by the arbitrator to enforce the final ruling. The purpose of this function is to ensure that the address calling it has the right to rule on the contract.
function rule(uint256 _disputeID, uint256 _ruling) public override;
Parameters
Name | Type | Description |
---|---|---|
_disputeID | uint256 | ID of the dispute in the Arbitrator contract. |
_ruling | uint256 | Ruling given by the arbitrator. Note that 0 is reserved for "Not able/wanting to make a decision". |
getNumberOfModerations
Gets the number of moderation events of the specific evidence submission.
function getNumberOfModerations(bytes32 _evidenceID) external view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
_evidenceID | bytes32 | The ID of the evidence submission. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The number of moderations. |
getContributions
Gets the contributions made by a party for a given moderation.
function getContributions(bytes32 _evidenceID, uint256 _moderationID, address _contributor)
external
view
returns (uint256[3] memory contributions);
Parameters
Name | Type | Description |
---|---|---|
_evidenceID | bytes32 | The ID of the evidence submission. |
_moderationID | uint256 | The ID of the moderation occurence. |
_contributor | address | The address of the contributor. |
Returns
Name | Type | Description |
---|---|---|
contributions | uint256[3] | The contributions. |
getModerationInfo
Gets the information of a moderation event.
function getModerationInfo(bytes32 _evidenceID, uint256 _moderationID)
external
view
returns (uint256[3] memory paidFees, Party currentWinner, uint256 feeRewards);
Parameters
Name | Type | Description |
---|---|---|
_evidenceID | bytes32 | The ID of the evidence submission. |
_moderationID | uint256 | The ID of the moderation occurence. |
Returns
Name | Type | Description |
---|---|---|
paidFees | uint256[3] | currentWinner feeRewards The moderation information. |
currentWinner | Party | |
feeRewards | uint256 |
getCurrentArbitratorIndex
Gets the last arbitrator data index, which is used for current new submissions.
function getCurrentArbitratorIndex() external view returns (uint256);
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The last arbitrator data index. |
Events
Evidence
To be raised when evidence is submitted. Should point to the resource (evidences are not to be stored on chain due to gas considerations).
event Evidence(
IArbitrator indexed _arbitrator, uint256 indexed _evidenceGroupID, address indexed _party, string _evidence
);
ModerationStatusChanged
Indicate that a party has to pay a fee or would otherwise be considered as losing.
event ModerationStatusChanged(bytes32 indexed _evidenceID, Party _currentWinner);
Structs
EvidenceData
struct EvidenceData {
address payable submitter;
bool disputed;
Party ruling;
uint256 disputeID;
Moderation[] moderations;
}
Moderation
struct Moderation {
uint256[3] paidFees;
uint256 feeRewards;
mapping(address => uint256[3]) contributions;
bool closed;
Party currentWinner;
uint256 bondDeadline;
uint256 arbitratorDataID;
}
ArbitratorData
struct ArbitratorData {
uint256 metaEvidenceUpdates;
bytes arbitratorExtraData;
}
Enums
Party
enum Party {
None,
Submitter,
Moderator
}
Contents
Contents
IForeignGateway
Inherits: IArbitrator, IReceiverGateway
Functions
relayRule
Relay the rule call from the home gateway to the arbitrable.
function relayRule(address _messageSender, bytes32 _disputeHash, uint256 _ruling, address _forwarder) external;
withdrawFees
function withdrawFees(bytes32 _disputeHash) external;
disputeHashToForeignID
function disputeHashToForeignID(bytes32 _disputeHash) external view returns (uint256);
createDisputeERC20
function createDisputeERC20(uint256 _choices, bytes calldata _extraData, uint256 _amount)
external
returns (uint256 disputeID);
IHomeGateway
Inherits: IArbitrable, IMetaEvidence, ISenderGateway
Functions
relayCreateDispute
Provide the same parameters as on the foreignChain while creating a dispute. Providing incorrect parameters will create a different hash than on the foreignChain and will not affect the actual dispute/arbitrable's ruling.
function relayCreateDispute(
uint256 _foreignChainID,
bytes32 _foreignBlockHash,
uint256 _foreignDisputeID,
uint256 _choices,
bytes calldata _extraData,
address _arbitrable
) external payable;
Parameters
Name | Type | Description |
---|---|---|
_foreignChainID | uint256 | foreignChainId |
_foreignBlockHash | bytes32 | foreignBlockHash |
_foreignDisputeID | uint256 | foreignDisputeID |
_choices | uint256 | number of ruling choices |
_extraData | bytes | extraData |
_arbitrable | address | arbitrable |
disputeHashToHomeID
Looks up the local home disputeID for a disputeHash. For cross-chain Evidence standard.
function disputeHashToHomeID(bytes32 _disputeHash) external view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
_disputeHash | bytes32 | dispute hash |
Contents
VeaMock
Inherits: IVeaOutboxOnL1, IVeaInbox
Functions
sendMessage
Sends an arbitrary message to receiving chain. Note: Calls authenticated by receiving gateway checking the sender argument.
function sendMessage(address _to, bytes4 _fnSelector, bytes memory _data) external returns (uint64 msgId);
Parameters
Name | Type | Description |
---|---|---|
_to | address | The cross-domain contract address which receives the calldata. |
_fnSelector | bytes4 | The function selector of the receiving contract. |
_data | bytes | The message calldata, abi.encode(...) |
Returns
Name | Type | Description |
---|---|---|
msgId | uint64 | The index of the message in the inbox, as a message Id, needed to relay the message. |
saveSnapshot
Snapshots can be saved a maximum of once per epoch.
Saves snapshot of state root.
O(log(count))
where count number of messages in the inbox.
function saveSnapshot() external;
sendMessage
Verifies and relays the message. Note: Gateways expect first argument of message call to be the arbitrum message sender, used for authentication.
function sendMessage(bytes32[] calldata _proof, uint64 _msgId, address _to, bytes calldata _message) external;
Parameters
Name | Type | Description |
---|---|---|
_proof | bytes32[] | The merkle proof to prove the message. |
_msgId | uint64 | The zero based index of the message in the inbox. |
_to | address | The address to send the message to. |
_message | bytes | The message to relay. |
resolveDisputedClaim
Resolves any challenge of the optimistic claim for 'epoch' using the canonical bridge. Note: Access restricted to canonical bridge.
function resolveDisputedClaim(uint256 _epoch, bytes32 _stateRoot, Claim memory _claim) external;
Parameters
Name | Type | Description |
---|---|---|
_epoch | uint256 | The epoch to verify. |
_stateRoot | bytes32 | The true state root for the epoch. |
_claim | Claim | The claim associated with the epoch. |
ForeignGateway
Inherits: IForeignGateway
State Variables
DEFAULT_NB_OF_JURORS
uint256 public constant DEFAULT_NB_OF_JURORS = 3;
localDisputeID
uint256 internal localDisputeID = 1;
feeForJuror
mapping(uint96 => uint256) public feeForJuror;
governor
address public governor;
veaOutbox
address public veaOutbox;
senderChainID
uint256 public immutable senderChainID;
senderGateway
address public override senderGateway;
deprecatedVeaOutbox
address public deprecatedVeaOutbox;
deprecatedVeaOutboxExpiration
uint256 public deprecatedVeaOutboxExpiration;
disputeHashtoDisputeData
mapping(bytes32 => DisputeData) public disputeHashtoDisputeData;
Functions
onlyFromVea
modifier onlyFromVea(address _messageSender);
onlyByGovernor
modifier onlyByGovernor();
constructor
constructor(address _governor, address _veaOutbox, address _senderGateway, uint256 _senderChainID);
changeGovernor
Changes the governor.
function changeGovernor(address _governor) external;
Parameters
Name | Type | Description |
---|---|---|
_governor | address | The address of the new governor. |
changeVea
Changes the outbox.
function changeVea(address _veaOutbox, uint256 _gracePeriod) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_veaOutbox | address | The address of the new outbox. |
_gracePeriod | uint256 | The duration to accept messages from the deprecated bridge (if at all). |
changeReceiverGateway
Changes the sender gateway.
function changeReceiverGateway(address _senderGateway) external;
Parameters
Name | Type | Description |
---|---|---|
_senderGateway | address | The address of the new sender gateway. |
changeCourtJurorFee
Changes the feeForJuror
property value of a specified court.
function changeCourtJurorFee(uint96 _courtID, uint256 _feeForJuror) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_courtID | uint96 | The ID of the court. |
_feeForJuror | uint256 | The new value for the feeForJuror property value. |
createDispute
function createDispute(uint256 _choices, bytes calldata _extraData)
external
payable
override
returns (uint256 disputeID);
createDisputeERC20
function createDisputeERC20(uint256, bytes calldata, uint256) external override returns (uint256);
arbitrationCost
function arbitrationCost(bytes calldata _extraData) public view override returns (uint256 cost);
relayRule
Relay the rule call from the home gateway to the arbitrable.
function relayRule(address _messageSender, bytes32 _disputeHash, uint256 _ruling, address _relayer)
external
override
onlyFromVea(_messageSender);
withdrawFees
function withdrawFees(bytes32 _disputeHash) external override;
disputeHashToForeignID
function disputeHashToForeignID(bytes32 _disputeHash) external view override returns (uint256);
extraDataToCourtIDMinJurors
function extraDataToCourtIDMinJurors(bytes memory _extraData)
internal
view
returns (uint96 courtID, uint256 minJurors);
Events
OutgoingDispute
event OutgoingDispute(
bytes32 disputeHash,
bytes32 blockhash,
uint256 localDisputeID,
uint256 _choices,
bytes _extraData,
address arbitrable
);
ArbitrationCostModified
event ArbitrationCostModified(uint96 indexed _courtID, uint256 _feeForJuror);
Structs
DisputeData
struct DisputeData {
uint248 id;
bool ruled;
address arbitrable;
uint256 paid;
address relayer;
}
ForeignGatewayOnGnosis
Inherits: IForeignGateway
State Variables
DEFAULT_NB_OF_JURORS
uint256 public constant DEFAULT_NB_OF_JURORS = 3;
weth
IERC20 public immutable weth;
localDisputeID
uint256 internal localDisputeID = 1;
feeForJuror
mapping(uint96 => uint256) public feeForJuror;
governor
address public governor;
veaOutbox
address public veaOutbox;
senderChainID
uint256 public immutable senderChainID;
senderGateway
address public override senderGateway;
deprecatedVeaOutbox
address public deprecatedVeaOutbox;
deprecatedVeaOutboxExpiration
uint256 public deprecatedVeaOutboxExpiration;
disputeHashtoDisputeData
mapping(bytes32 => DisputeData) public disputeHashtoDisputeData;
Functions
onlyFromVea
modifier onlyFromVea(address _messageSender);
onlyByGovernor
modifier onlyByGovernor();
constructor
constructor(address _governor, address _veaOutbox, address _senderGateway, uint256 _senderChainID, IERC20 _weth);
changeGovernor
Changes the governor.
function changeGovernor(address _governor) external;
Parameters
Name | Type | Description |
---|---|---|
_governor | address | The address of the new governor. |
changeVea
Changes the outbox.
function changeVea(address _veaOutbox, uint256 _gracePeriod) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_veaOutbox | address | The address of the new outbox. |
_gracePeriod | uint256 | The duration to accept messages from the deprecated bridge (if at all). |
changeReceiverGateway
Changes the sender gateway.
function changeReceiverGateway(address _senderGateway) external;
Parameters
Name | Type | Description |
---|---|---|
_senderGateway | address | The address of the new sender gateway. |
changeCourtJurorFee
Changes the feeForJuror
property value of a specified court.
function changeCourtJurorFee(uint96 _courtID, uint256 _feeForJuror) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_courtID | uint96 | The ID of the court. |
_feeForJuror | uint256 | The new value for the feeForJuror property value. |
createDispute
function createDispute(uint256, bytes calldata) external payable override returns (uint256 disputeID);
createDisputeERC20
function createDisputeERC20(uint256 _choices, bytes calldata _extraData, uint256 _amount)
external
override
returns (uint256 disputeID);
arbitrationCost
function arbitrationCost(bytes calldata _extraData) public view override returns (uint256 cost);
relayRule
Relay the rule call from the home gateway to the arbitrable.
function relayRule(address _messageSender, bytes32 _disputeHash, uint256 _ruling, address _relayer)
external
override
onlyFromVea(_messageSender);
withdrawFees
function withdrawFees(bytes32 _disputeHash) external override;
disputeHashToForeignID
function disputeHashToForeignID(bytes32 _disputeHash) external view override returns (uint256);
extraDataToCourtIDMinJurors
function extraDataToCourtIDMinJurors(bytes memory _extraData)
internal
view
returns (uint96 courtID, uint256 minJurors);
Events
OutgoingDispute
event OutgoingDispute(
bytes32 disputeHash,
bytes32 blockhash,
uint256 localDisputeID,
uint256 _choices,
bytes _extraData,
address arbitrable
);
ArbitrationCostModified
event ArbitrationCostModified(uint96 indexed _courtID, uint256 _feeForJuror);
Structs
DisputeData
struct DisputeData {
uint248 id;
bool ruled;
address arbitrable;
uint256 paid;
address relayer;
}
HomeGateway
Inherits: IHomeGateway
State Variables
governor
address public governor;
arbitrator
IArbitrator public arbitrator;
veaInbox
IVeaInbox public veaInbox;
receiverGateway
address public override receiverGateway;
receiverChainID
uint256 public immutable receiverChainID;
disputeIDtoHash
mapping(uint256 => bytes32) public disputeIDtoHash;
disputeHashtoID
mapping(bytes32 => uint256) public disputeHashtoID;
disputeHashtoRelayedData
mapping(bytes32 => RelayedData) public disputeHashtoRelayedData;
Functions
constructor
constructor(
address _governor,
IArbitrator _arbitrator,
IVeaInbox _veaInbox,
address _receiverGateway,
uint256 _receiverChainID
);
changeGovernor
Changes the governor.
function changeGovernor(address _governor) external;
Parameters
Name | Type | Description |
---|---|---|
_governor | address | The address of the new governor. |
changeArbitrator
Changes the arbitrator.
function changeArbitrator(IArbitrator _arbitrator) external;
Parameters
Name | Type | Description |
---|---|---|
_arbitrator | IArbitrator | The address of the new arbitrator. |
changeVea
Changes the vea inbox, useful to increase the claim deposit.
function changeVea(IVeaInbox _veaInbox) external;
Parameters
Name | Type | Description |
---|---|---|
_veaInbox | IVeaInbox | The address of the new vea inbox. |
changeReceiverGateway
Changes the receiver gateway.
function changeReceiverGateway(address _receiverGateway) external;
Parameters
Name | Type | Description |
---|---|---|
_receiverGateway | address | The address of the new receiver gateway. |
relayCreateDispute
Provide the same parameters as on the foreignChain while creating a dispute. Providing incorrect parameters will create a different hash than on the foreignChain and will not affect the actual dispute/arbitrable's ruling.
function relayCreateDispute(
uint256 _foreignChainID,
bytes32 _foreignBlockHash,
uint256 _foreignDisputeID,
uint256 _choices,
bytes calldata _extraData,
address _arbitrable
) external payable override;
Parameters
Name | Type | Description |
---|---|---|
_foreignChainID | uint256 | foreignChainId |
_foreignBlockHash | bytes32 | foreignBlockHash |
_foreignDisputeID | uint256 | foreignDisputeID |
_choices | uint256 | number of ruling choices |
_extraData | bytes | extraData |
_arbitrable | address | arbitrable |
rule
Give a ruling for a dispute. Must be called by the arbitrator. The purpose of this function is to ensure that the address calling it has the right to rule on the contract.
function rule(uint256 _disputeID, uint256 _ruling) external override;
Parameters
Name | Type | Description |
---|---|---|
_disputeID | uint256 | ID of the dispute in the Arbitrator contract. |
_ruling | uint256 | Ruling given by the arbitrator. Note that 0 is reserved for "Not able/wanting to make a decision". |
disputeHashToHomeID
Looks up the local home disputeID for a disputeHash. For cross-chain Evidence standard.
function disputeHashToHomeID(bytes32 _disputeHash) external view override returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
_disputeHash | bytes32 | dispute hash |
Structs
RelayedData
struct RelayedData {
uint256 arbitrationCost;
address relayer;
}
Contents
Contents
IArbitrableV1
Functions
rule
Give a ruling for a dispute. Must be called by the arbitrator. The purpose of this function is to ensure that the address calling it has the right to rule on the contract.
function rule(uint256 _disputeID, uint256 _ruling) external;
Parameters
Name | Type | Description |
---|---|---|
_disputeID | uint256 | ID of the dispute in the Arbitrator contract. |
_ruling | uint256 | Ruling given by the arbitrator. Note that 0 is reserved for "Not able/wanting to make a decision". |
Events
Ruling
To be raised when a ruling is given.
event Ruling(IArbitratorV1 indexed _arbitrator, uint256 indexed _disputeID, uint256 _ruling);
IArbitratorV1
Functions
createDispute
Create a dispute. Must be called by the arbitrable contract. Must be paid at least arbitrationCost(_extraData).
function createDispute(uint256 _choices, bytes calldata _extraData) external payable returns (uint256 disputeID);
Parameters
Name | Type | Description |
---|---|---|
_choices | uint256 | Amount of choices the arbitrator can make in this dispute. |
_extraData | bytes | Can be used to give additional info on the dispute to be created. |
Returns
Name | Type | Description |
---|---|---|
disputeID | uint256 | ID of the dispute created. |
arbitrationCost
Compute the cost of arbitration. It is recommended not to increase it often, as it can be highly time and gas consuming for the arbitrated contracts to cope with fee augmentation.
function arbitrationCost(bytes calldata _extraData) external view returns (uint256 cost);
Parameters
Name | Type | Description |
---|---|---|
_extraData | bytes | Can be used to give additional info on the dispute to be created. |
Returns
Name | Type | Description |
---|---|---|
cost | uint256 | Amount to be paid. |
appeal
Appeal a ruling. Note that it has to be called before the arbitrator contract calls rule.
function appeal(uint256 _disputeID, bytes calldata _extraData) external payable;
Parameters
Name | Type | Description |
---|---|---|
_disputeID | uint256 | ID of the dispute to be appealed. |
_extraData | bytes | Can be used to give extra info on the appeal. |
appealCost
Compute the cost of appeal. It is recommended not to increase it often, as it can be higly time and gas consuming for the arbitrated contracts to cope with fee augmentation.
function appealCost(uint256 _disputeID, bytes calldata _extraData) external view returns (uint256 cost);
Parameters
Name | Type | Description |
---|---|---|
_disputeID | uint256 | ID of the dispute to be appealed. |
_extraData | bytes | Can be used to give additional info on the dispute to be created. |
Returns
Name | Type | Description |
---|---|---|
cost | uint256 | Amount to be paid. |
appealPeriod
Compute the start and end of the dispute's current or next appeal period, if possible. If not known or appeal is impossible: should return (0, 0).
function appealPeriod(uint256 _disputeID) external view returns (uint256 start, uint256 end);
Parameters
Name | Type | Description |
---|---|---|
_disputeID | uint256 | ID of the dispute. |
Returns
Name | Type | Description |
---|---|---|
start | uint256 | The start of the period. |
end | uint256 | The end of the period. |
disputeStatus
Return the status of a dispute.
function disputeStatus(uint256 _disputeID) external view returns (DisputeStatus status);
Parameters
Name | Type | Description |
---|---|---|
_disputeID | uint256 | ID of the dispute to rule. |
Returns
Name | Type | Description |
---|---|---|
status | DisputeStatus | The status of the dispute. |
currentRuling
Return the current ruling of a dispute. This is useful for parties to know if they should appeal.
function currentRuling(uint256 _disputeID) external view returns (uint256 ruling);
Parameters
Name | Type | Description |
---|---|---|
_disputeID | uint256 | ID of the dispute. |
Returns
Name | Type | Description |
---|---|---|
ruling | uint256 | The ruling which has been given or the one which will be given if there is no appeal. |
Events
DisputeCreation
To be emitted when a dispute is created.
event DisputeCreation(uint256 indexed _disputeID, IArbitrableV1 indexed _arbitrable);
AppealPossible
To be emitted when a dispute can be appealed.
event AppealPossible(uint256 indexed _disputeID, IArbitrableV1 indexed _arbitrable);
AppealDecision
To be emitted when the current ruling is appealed.
event AppealDecision(uint256 indexed _disputeID, IArbitrableV1 indexed _arbitrable);
Enums
DisputeStatus
enum DisputeStatus {
Waiting,
Appealable,
Solved
}
IKlerosLiquid
Inherits: IArbitratorV1
Functions
courts
function courts(uint256 _index)
external
view
returns (
uint96 parent,
bool hiddenVotes,
uint256 minStake,
uint256 alpha,
uint256 feeForJuror,
uint256 jurorsForCourtJump
);
phase
function phase() external view returns (Phase);
lockInsolventTransfers
function lockInsolventTransfers() external view returns (bool);
minStakingTime
function minStakingTime() external view returns (uint256);
pinakion
function pinakion() external view returns (address);
disputes
function disputes(uint256 _index) external view returns (Dispute memory);
jurors
function jurors(address _account) external view returns (Juror memory);
changeSubcourtTimesPerPeriod
function changeSubcourtTimesPerPeriod(uint96 _subcourtID, uint256[4] calldata _timesPerPeriod) external;
executeGovernorProposal
function executeGovernorProposal(address _destination, uint256 _amount, bytes calldata _data) external;
getVote
function getVote(uint256 _disputeID, uint256 _appeal, uint256 _voteID)
external
view
returns (address account, bytes32 commit, uint256 choice, bool voted);
getDispute
function getDispute(uint256 _disputeID)
external
view
returns (
uint256[] memory votesLengths,
uint256[] memory tokensAtStakePerJuror,
uint256[] memory totalFeesForJurors,
uint256[] memory votesInEachRound,
uint256[] memory repartitionsInEachRound,
uint256[] memory penaltiesInEachRound
);
getSubcourt
function getSubcourt(uint96 _subcourtID)
external
view
returns (uint256[] memory children, uint256[4] memory timesPerPeriod);
Structs
Court
struct Court {
uint96 parent;
uint256[] children;
bool hiddenVotes;
uint256 minStake;
uint256 alpha;
uint256 feeForJuror;
uint256 jurorsForCourtJump;
uint256[4] timesPerPeriod;
}
Dispute
struct Dispute {
uint96 subcourtID;
address arbitrated;
uint256 numberOfChoices;
Period period;
uint256 lastPeriodChange;
uint256 drawsInRound;
uint256 commitsInRound;
bool ruled;
}
Juror
struct Juror {
uint256 stakedTokens;
uint256 lockedTokens;
}
Enums
Period
enum Period {
evidence,
commit,
vote,
appeal,
execution
}
Phase
enum Phase {
staking,
generating,
drawing
}
ITokenController
The token controller contract must implement these functions. See https://github.com/Giveth/minime/blob/master/contracts/TokenController.sol
Functions
proxyPayment
Called when _owner
sends ether to the MiniMe Token contract
function proxyPayment(address _owner) external payable returns (bool);
Parameters
Name | Type | Description |
---|---|---|
_owner | address | The address that sent the ether to create tokens |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | True if the ether is accepted, false if it throws |
onTransfer
Notifies the controller about a token transfer allowing the controller to react if desired
function onTransfer(address _from, address _to, uint256 _amount) external returns (bool);
Parameters
Name | Type | Description |
---|---|---|
_from | address | The origin of the transfer |
_to | address | The destination of the transfer |
_amount | uint256 | The amount of the transfer |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | False if the controller does not authorize the transfer |
onApprove
Notifies the controller about an approval allowing the controller to react if desired
function onApprove(address _owner, address _spender, uint256 _amount) external returns (bool);
Parameters
Name | Type | Description |
---|---|---|
_owner | address | The address that calls approve() |
_spender | address | The spender in the approve() call |
_amount | uint256 | The amount in the approve() call |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | False if the controller does not authorize the approval |
Contents
IPinakion
Functions
balanceOf
function balanceOf(address who) external view returns (uint256);
KlerosLiquidToV2Governor
Inherits: IArbitrable, ITokenController
State Variables
foreignGateway
IArbitrator public immutable foreignGateway;
klerosLiquid
IKlerosLiquid public immutable klerosLiquid;
governor
address public governor;
klerosLiquidDisputeIDtoGatewayDisputeID
mapping(uint256 => uint256) public klerosLiquidDisputeIDtoGatewayDisputeID;
disputes
mapping(uint256 => DisputeData) public disputes;
frozenTokens
mapping(address => uint256) public frozenTokens;
isDisputeNotified
mapping(uint256 => mapping(uint256 => bool)) public isDisputeNotified;
Functions
onlyByGovernor
modifier onlyByGovernor();
constructor
Constructor. Before this contract is made the new governor of KlerosLiquid, the evidence period of all subcourts has to be set to uint(-1).
constructor(IKlerosLiquid _klerosLiquid, address _governor, IArbitrator _foreignGateway);
Parameters
Name | Type | Description |
---|---|---|
_klerosLiquid | IKlerosLiquid | The trusted arbitrator to resolve potential disputes. |
_governor | address | The trusted governor of the contract. |
_foreignGateway | IArbitrator | The trusted gateway that acts as an arbitrator, relaying disputes to v2. |
executeGovernorProposal
Lets the governor call anything on behalf of the contract.
function executeGovernorProposal(address _destination, uint256 _amount, bytes calldata _data) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_destination | address | The destination of the call. |
_amount | uint256 | The value sent with the call. |
_data | bytes | The data sent with the call. |
changeGovernor
Changes the governor
storage variable.
function changeGovernor(address _governor) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_governor | address | The new value for the governor storage variable. |
relayDispute
Relays disputes from KlerosLiquid to Kleros v2. Only disputes in the evidence period of the initial round can be realyed.
function relayDispute(uint256 _disputeID) external;
Parameters
Name | Type | Description |
---|---|---|
_disputeID | uint256 | The ID of the dispute as defined in KlerosLiquid. |
rule
Give a ruling for a dispute. Can only be called by the arbitrator. TRUSTED. Triggers rule() from KlerosLiquid to the arbitrable contract which created the dispute.
function rule(uint256 _disputeID, uint256 _ruling) public;
Parameters
Name | Type | Description |
---|---|---|
_disputeID | uint256 | ID of the dispute in the arbitrator contract. |
_ruling | uint256 | Ruling given by the arbitrator. Note that 0 is reserved for "Refused to arbitrate". |
notifyFrozenTokens
Registers jurors' tokens which where locked due to relaying a given dispute. These tokens don't count as locked.
function notifyFrozenTokens(uint256 _disputeID) external;
Parameters
Name | Type | Description |
---|---|---|
_disputeID | uint256 | The ID of the dispute as defined in KlerosLiquid. |
proxyPayment
Called when _owner
sends ether to the MiniMe Token contract.
function proxyPayment(address _owner) external payable returns (bool allowed);
Parameters
Name | Type | Description |
---|---|---|
_owner | address | The address that sent the ether to create tokens. |
Returns
Name | Type | Description |
---|---|---|
allowed | bool | Whether the operation should be allowed or not. |
onTransfer
Notifies the controller about a token transfer allowing the controller to react if desired.
function onTransfer(address _from, address _to, uint256 _amount) external returns (bool allowed);
Parameters
Name | Type | Description |
---|---|---|
_from | address | The origin of the transfer. |
_to | address | The destination of the transfer. |
_amount | uint256 | The amount of the transfer. |
Returns
Name | Type | Description |
---|---|---|
allowed | bool | Whether the operation should be allowed or not. |
onApprove
Notifies the controller about an approval allowing the controller to react if desired.
function onApprove(address _owner, address _spender, uint256 _amount) external returns (bool allowed);
Parameters
Name | Type | Description |
---|---|---|
_owner | address | The address that calls approve() . |
_spender | address | The spender in the approve() call. |
_amount | uint256 | The amount in the approve() call. |
Returns
Name | Type | Description |
---|---|---|
allowed | bool | Whether the operation should be allowed or not. |
receive
This contract should be able to receive arbitration fees from KlerosLiquid.
receive() external payable;
Structs
DisputeData
struct DisputeData {
uint256 klerosLiquidDisputeID;
bool ruled;
}
Contents
Contents
IERC677
Functions
transfer
function transfer(address _to, uint256 _value) external returns (bool);
transferFrom
function transferFrom(address _from, address _to, uint256 _value) external returns (bool);
approve
function approve(address _spender, uint256 _value) external returns (bool);
IRandomAuRa
Functions
currentSeed
function currentSeed() external view returns (uint256);
isCommitPhase
function isCommitPhase() external view returns (bool);
nextCommitPhaseStartBlock
function nextCommitPhaseStartBlock() external view returns (uint256);
collectRoundLength
function collectRoundLength() external view returns (uint256);
ITokenBridge
Functions
relayTokens
function relayTokens(IERC677 token, address _receiver, uint256 _value) external;
WrappedPinakion
Inherits: Initializable
State Variables
balances
mapping(address => uint256) private balances;
allowance
mapping(address => mapping(address => uint256)) public allowance;
totalSupply
Total supply of the token. Equals the total xPinakion deposit into the contract.
uint256 public totalSupply;
name
Name of the token.
string public name;
symbol
Symbol of the token.
string public symbol;
decimals
Number of decimals of the token.
uint8 public decimals;
controller
The token's controller.
address public controller;
xPinakion
Bridged PNK on xDai to be wrapped. This token is upgradeable.
IERC677 public xPinakion;
tokenBridge
xDai Token Bridge. The Token Bridge is upgradeable.
ITokenBridge public tokenBridge;
Functions
onlyController
Verifies that the sender has ability to modify controlled parameters.
modifier onlyController();
initialize
Initializer.
function initialize(string memory _name, string memory _symbol, IERC677 _xPinakion, ITokenBridge _tokenBridge)
public
initializer;
Parameters
Name | Type | Description |
---|---|---|
_name | string | for the wrapped PNK on the home chain. |
_symbol | string | for wrapped PNK ticker on the home chain. |
_xPinakion | IERC677 | the home PNK contract which is already bridged to the foreign PNK contract. |
_tokenBridge | ITokenBridge | the TokenBridge contract. |
changeController
function changeController(address _controller) external onlyController;
Parameters
Name | Type | Description |
---|---|---|
_controller | address | The new controller of the contract |
deposit
Converts bridged PNK (xPinakion) into wrapped PNK which can be staked in KlerosLiquid.
function deposit(uint256 _amount) external;
Parameters
Name | Type | Description |
---|---|---|
_amount | uint256 | The amount of wrapped pinakions to mint. |
onTokenBridged
IERC20 Receiver functionality.
Converts bridged PNK (xPinakion) into wrapped PNK which can be staked in KlerosLiquid.
If the tokenBridge is calling this function, then this contract has already received
the xPinakion tokens. Notice that the Home bridge calls onTokenBridge as a result of
someone invoking relayTokensAndCall()
on the Foreign bridge contract.
function onTokenBridged(address _token, uint256 _amount, bytes calldata _data) external;
Parameters
Name | Type | Description |
---|---|---|
_token | address | The token address the _amount belongs to. |
_amount | uint256 | The amount of wrapped PNK to mint. |
_data | bytes | Calldata containing the address of the recipient. Notice that the address has to be padded to the right 32 bytes. |
withdraw
Converts wrapped PNK back into bridged PNK (xPinakion).
function withdraw(uint256 _amount) external;
Parameters
Name | Type | Description |
---|---|---|
_amount | uint256 | The amount of bridged PNK to withdraw. |
withdrawAndConvertToPNK
Converts wrapped PNK back into PNK using the Token Bridge.
This function is not strictly needed, but it provides a good UX to users who want to get their Mainnet's PNK back. What normally takes 3 transactions, here is done in one go. Notice that the PNK have to be claimed on Mainnet's TokenBridge by the receiver.
function withdrawAndConvertToPNK(uint256 _amount, address _receiver) external;
Parameters
Name | Type | Description |
---|---|---|
_amount | uint256 | The amount of PNK to withdraw. |
_receiver | address | The address which will receive the PNK back in the foreign chain. |
transfer
Moves _amount
tokens from the caller's account to _recipient
.
function transfer(address _recipient, uint256 _amount) public returns (bool);
Parameters
Name | Type | Description |
---|---|---|
_recipient | address | The entity receiving the funds. |
_amount | uint256 | The amount to tranfer in base units. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | True on success. |
transferFrom
Moves _amount
tokens from _sender
to _recipient
using the
allowance mechanism. _amount
is then deducted from the caller's allowance.
function transferFrom(address _sender, address _recipient, uint256 _amount) public returns (bool);
Parameters
Name | Type | Description |
---|---|---|
_sender | address | The entity to take the funds from. |
_recipient | address | The entity receiving the funds. |
_amount | uint256 | The amount to tranfer in base units. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | True on success. |
approve
Approves _spender
to spend _amount
.
function approve(address _spender, uint256 _amount) public returns (bool);
Parameters
Name | Type | Description |
---|---|---|
_spender | address | The entity allowed to spend funds. |
_amount | uint256 | The amount of base units the entity will be allowed to spend. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | True on success. |
increaseAllowance
Increases the _spender
allowance by _addedValue
.
function increaseAllowance(address _spender, uint256 _addedValue) public returns (bool);
Parameters
Name | Type | Description |
---|---|---|
_spender | address | The entity allowed to spend funds. |
_addedValue | uint256 | The amount of extra base units the entity will be allowed to spend. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | True on success. |
decreaseAllowance
Decreases the _spender
allowance by _subtractedValue
.
function decreaseAllowance(address _spender, uint256 _subtractedValue) public returns (bool);
Parameters
Name | Type | Description |
---|---|---|
_spender | address | The entity whose spending allocation will be reduced. |
_subtractedValue | uint256 | The reduction of spending allocation in base units. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | True on success. |
_mint
Internal function that mints an amount of the token and assigns it to an account. This encapsulates the modification of balances such that the proper events are emitted.
function _mint(address _recipient, uint256 _amount) internal;
Parameters
Name | Type | Description |
---|---|---|
_recipient | address | The address which will receive the minted tokens. |
_amount | uint256 | The amount that will be created. |
_burn
Destroys _amount
tokens from the caller. Cannot burn locked tokens.
function _burn(uint256 _amount) internal;
Parameters
Name | Type | Description |
---|---|---|
_amount | uint256 | The quantity of tokens to burn in base units. |
isContract
Internal function to determine if an address is a contract.
function isContract(address _addr) internal view returns (bool);
Parameters
Name | Type | Description |
---|---|---|
_addr | address | The address being queried. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | True if _addr is a contract. |
balanceOf
Gets the balance of the specified address.
function balanceOf(address _owner) public view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
_owner | address | The address to query the balance of. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | uint256 value representing the amount owned by the passed address. |
Events
Transfer
Emitted when value
tokens are moved from one account (from
) to another (to
).
Notice that value
may be zero.
event Transfer(address indexed from, address indexed to, uint256 value);
Approval
Emitted when the allowance of a spender
for an owner
is set by
a call to {approve}. value
is the new allowance.
event Approval(address indexed owner, address indexed spender, uint256 value);
xKlerosLiquidV2
Inherits: Initializable, ITokenController, IArbitrator
This contract is an adaption of Mainnet's KlerosLiquid (https://github.com/kleros/kleros/blob/69cfbfb2128c29f1625b3a99a3183540772fda08/contracts/kleros/KlerosLiquid.sol) for xDai chain. Notice that variables referring to ETH values in this contract, will hold the native token values of the chain on which xKlerosLiquid is deployed. When this contract gets deployed on xDai chain, ETH variables will hold xDai values.
State Variables
MAX_STAKE_PATHS
uint256 public constant MAX_STAKE_PATHS = 4;
DEFAULT_NB_OF_JURORS
uint256 public constant DEFAULT_NB_OF_JURORS = 3;
NON_PAYABLE_AMOUNT
uint256 public constant NON_PAYABLE_AMOUNT = (2 ** 256 - 2) / 2;
ALPHA_DIVISOR
uint256 public constant ALPHA_DIVISOR = 1e4;
governor
address public governor;
pinakion
WrappedPinakion public pinakion;
RNGenerator
IRandomAuRa public RNGenerator;
phase
Phase public phase;
lastPhaseChange
uint256 public lastPhaseChange;
disputesWithoutJurors
uint256 public disputesWithoutJurors;
RNBlock
uint256 public RNBlock;
RN
uint256 public RN;
minStakingTime
uint256 public minStakingTime;
maxDrawingTime
uint256 public maxDrawingTime;
lockInsolventTransfers
bool public lockInsolventTransfers;
courts
Court[] public courts;
sortitionSumTrees
SortitionSumTreeFactory.SortitionSumTrees internal sortitionSumTrees;
delayedSetStakes
mapping(uint256 => DelayedSetStake) public delayedSetStakes;
nextDelayedSetStake
uint256 public nextDelayedSetStake;
lastDelayedSetStake
uint256 public lastDelayedSetStake;
disputes
mapping(uint256 => Dispute) public disputes;
totalDisputes
uint256 public totalDisputes;
jurors
mapping(address => Juror) public jurors;
foreignGateway
IForeignGateway public foreignGateway;
weth
IERC20 public weth;
disputesRuling
mapping(uint256 => uint256) public disputesRuling;
Functions
onlyDuringPhase
Requires a specific phase.
modifier onlyDuringPhase(Phase _phase);
Parameters
Name | Type | Description |
---|---|---|
_phase | Phase | The required phase. |
onlyDuringPeriod
Requires a specific period in a dispute.
modifier onlyDuringPeriod(uint256 _disputeID, Period _period);
Parameters
Name | Type | Description |
---|---|---|
_disputeID | uint256 | The ID of the dispute. |
_period | Period | The required period. |
onlyByGovernor
Requires that the sender is the governor. Note that the governor is expected to not be malicious.
modifier onlyByGovernor();
initialize
Constructs the KlerosLiquid contract.
function initialize(
address _governor,
WrappedPinakion _pinakion,
IRandomAuRa _RNGenerator,
uint256 _minStakingTime,
uint256 _maxDrawingTime,
bool _hiddenVotes,
uint256[4] memory _courtParameters,
uint256[4] memory _timesPerPeriod,
uint256 _sortitionSumTreeK,
IForeignGateway _foreignGateway,
IERC20 _weth
) public initializer;
Parameters
Name | Type | Description |
---|---|---|
_governor | address | The governor's address. |
_pinakion | WrappedPinakion | The address of the token contract. |
_RNGenerator | IRandomAuRa | The address of the random number generator contract. |
_minStakingTime | uint256 | The minimum time that the staking phase should last. |
_maxDrawingTime | uint256 | The maximum time that the drawing phase should last. |
_hiddenVotes | bool | The hiddenVotes property value of the general court. |
_courtParameters | uint256[4] | MinStake, alpha, feeForJuror and jurorsForCourtJump respectively. |
_timesPerPeriod | uint256[4] | The timesPerPeriod property value of the general court. |
_sortitionSumTreeK | uint256 | The number of children per node of the general court's sortition sum tree. |
_foreignGateway | IForeignGateway | Foreign gateway on xDai. |
_weth | IERC20 | Weth contract. |
executeGovernorProposal
Lets the governor call anything on behalf of the contract.
function executeGovernorProposal(address _destination, uint256 _amount, bytes memory _data) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_destination | address | The destination of the call. |
_amount | uint256 | The value sent with the call. |
_data | bytes | The data sent with the call. |
changeGovernor
Changes the governor
storage variable.
function changeGovernor(address _governor) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_governor | address | The new value for the governor storage variable. |
changePinakion
Changes the pinakion
storage variable.
function changePinakion(WrappedPinakion _pinakion) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_pinakion | WrappedPinakion | The new value for the pinakion storage variable. |
changeRNGenerator
Changes the RNGenerator
storage variable.
function changeRNGenerator(IRandomAuRa _RNGenerator) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_RNGenerator | IRandomAuRa | The new value for the RNGenerator storage variable. |
changeMinStakingTime
Changes the minStakingTime
storage variable.
function changeMinStakingTime(uint256 _minStakingTime) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_minStakingTime | uint256 | The new value for the minStakingTime storage variable. |
changeMaxDrawingTime
Changes the maxDrawingTime
storage variable.
function changeMaxDrawingTime(uint256 _maxDrawingTime) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_maxDrawingTime | uint256 | The new value for the maxDrawingTime storage variable. |
changeForeignGateway
Changes the foreignGateway
storage variable.
function changeForeignGateway(IForeignGateway _foreignGateway) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_foreignGateway | IForeignGateway | The new value for the foreignGateway storage variable. |
changeWethAddress
Changes the weth
storage variable.
function changeWethAddress(IERC20 _weth) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_weth | IERC20 | The new value for the weth storage variable. |
createSubcourt
Creates a subcourt under a specified parent court.
function createSubcourt(
uint96 _parent,
bool _hiddenVotes,
uint256 _minStake,
uint256 _alpha,
uint256 _feeForJuror,
uint256 _jurorsForCourtJump,
uint256[4] memory _timesPerPeriod,
uint256 _sortitionSumTreeK
) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_parent | uint96 | The parent property value of the subcourt. |
_hiddenVotes | bool | The hiddenVotes property value of the subcourt. |
_minStake | uint256 | The minStake property value of the subcourt. |
_alpha | uint256 | The alpha property value of the subcourt. |
_feeForJuror | uint256 | The feeForJuror property value of the subcourt. |
_jurorsForCourtJump | uint256 | The jurorsForCourtJump property value of the subcourt. |
_timesPerPeriod | uint256[4] | The timesPerPeriod property value of the subcourt. |
_sortitionSumTreeK | uint256 | The number of children per node of the subcourt's sortition sum tree. |
changeSubcourtMinStake
Changes the minStake
property value of a specified subcourt. Don't set to a value lower than its parent's minStake
property value.
function changeSubcourtMinStake(uint96 _subcourtID, uint256 _minStake) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_subcourtID | uint96 | The ID of the subcourt. |
_minStake | uint256 | The new value for the minStake property value. |
changeSubcourtAlpha
Changes the alpha
property value of a specified subcourt.
function changeSubcourtAlpha(uint96 _subcourtID, uint256 _alpha) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_subcourtID | uint96 | The ID of the subcourt. |
_alpha | uint256 | The new value for the alpha property value. |
changeSubcourtJurorFee
Changes the feeForJuror
property value of a specified subcourt.
function changeSubcourtJurorFee(uint96 _subcourtID, uint256 _feeForJuror) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_subcourtID | uint96 | The ID of the subcourt. |
_feeForJuror | uint256 | The new value for the feeForJuror property value. |
changeSubcourtJurorsForJump
Changes the jurorsForCourtJump
property value of a specified subcourt.
function changeSubcourtJurorsForJump(uint96 _subcourtID, uint256 _jurorsForCourtJump) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_subcourtID | uint96 | The ID of the subcourt. |
_jurorsForCourtJump | uint256 | The new value for the jurorsForCourtJump property value. |
changeSubcourtTimesPerPeriod
Changes the timesPerPeriod
property value of a specified subcourt.
function changeSubcourtTimesPerPeriod(uint96 _subcourtID, uint256[4] memory _timesPerPeriod) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_subcourtID | uint96 | The ID of the subcourt. |
_timesPerPeriod | uint256[4] | The new value for the timesPerPeriod property value. |
setStake
Sets the caller's stake in a subcourt.
function setStake(uint96 _subcourtID, uint128 _stake) external;
Parameters
Name | Type | Description |
---|---|---|
_subcourtID | uint96 | The ID of the subcourt. |
_stake | uint128 | The new stake. |
executeDelayedSetStakes
Executes the next delayed set stakes.
O(n)
where n
is the number of iterations to run.
function executeDelayedSetStakes(uint256 _iterations) external onlyDuringPhase(Phase.staking);
Parameters
Name | Type | Description |
---|---|---|
_iterations | uint256 | The number of delayed set stakes to execute. |
rule
Receive the ruling from foreign gateway which technically is an arbitrator of this contract.
function rule(uint256 _disputeID, uint256 _ruling) external;
Parameters
Name | Type | Description |
---|---|---|
_disputeID | uint256 | ID of the dispute. |
_ruling | uint256 | Ruling given by V2 court and relayed by foreign gateway. |
createDispute
Public
Creates a dispute. Must be called by the arbitrable contract.
function createDispute(uint256 _numberOfChoices, bytes memory _extraData)
public
payable
override
returns (uint256 disputeID);
Parameters
Name | Type | Description |
---|---|---|
_numberOfChoices | uint256 | Number of choices to choose from in the dispute to be created. |
_extraData | bytes | Additional info about the dispute to be created. We use it to pass the ID of the subcourt to create the dispute in (first 32 bytes) and the minimum number of jurors required (next 32 bytes). |
Returns
Name | Type | Description |
---|---|---|
disputeID | uint256 | The ID of the created dispute. |
proxyPayment
DEPRECATED. Called when _owner
sends ETH to the Wrapped Token contract.
function proxyPayment(address _owner) public payable override returns (bool allowed);
Parameters
Name | Type | Description |
---|---|---|
_owner | address | The address that sent the ETH to create tokens. |
Returns
Name | Type | Description |
---|---|---|
allowed | bool | Whether the operation should be allowed or not. |
onTransfer
Notifies the controller about a token transfer allowing the controller to react if desired.
function onTransfer(address _from, address _to, uint256 _amount) public override returns (bool allowed);
Parameters
Name | Type | Description |
---|---|---|
_from | address | The origin of the transfer. |
_to | address | The destination of the transfer. |
_amount | uint256 | The amount of the transfer. |
Returns
Name | Type | Description |
---|---|---|
allowed | bool | Whether the operation should be allowed or not. |
onApprove
Notifies the controller about an approval allowing the controller to react if desired.
function onApprove(address _owner, address _spender, uint256 _amount) public override returns (bool allowed);
Parameters
Name | Type | Description |
---|---|---|
_owner | address | The address that calls approve() . |
_spender | address | The spender in the approve() call. |
_amount | uint256 | The amount in the approve() call. |
Returns
Name | Type | Description |
---|---|---|
allowed | bool | Whether the operation should be allowed or not. |
_setStake
Sets the specified juror's stake in a subcourt.
O(n + p * log_k(j))
where
n
is the number of subcourts the juror has staked in,
p
is the depth of the subcourt tree,
k
is the minimum number of children per node of one of these subcourts' sortition sum tree,
and j
is the maximum number of jurors that ever staked in one of these subcourts simultaneously.
function _setStake(address _account, uint96 _subcourtID, uint128 _stake) internal returns (bool succeeded);
Parameters
Name | Type | Description |
---|---|---|
_account | address | The address of the juror. |
_subcourtID | uint96 | The ID of the subcourt. |
_stake | uint128 | The new stake. |
Returns
Name | Type | Description |
---|---|---|
succeeded | bool | True if the call succeeded, false otherwise. |
extraDataToSubcourtIDAndMinJurors
Gets a subcourt ID and the minimum number of jurors required from a specified extra data bytes array.
function extraDataToSubcourtIDAndMinJurors(bytes memory _extraData)
internal
view
returns (uint96 subcourtID, uint256 minJurors);
Parameters
Name | Type | Description |
---|---|---|
_extraData | bytes | The extra data bytes array. The first 32 bytes are the subcourt ID and the next 32 bytes are the minimum number of jurors. |
Returns
Name | Type | Description |
---|---|---|
subcourtID | uint96 | The subcourt ID. |
minJurors | uint256 | The minimum number of jurors required. |
accountAndSubcourtIDToStakePathID
Packs an account and a subcourt ID into a stake path ID.
function accountAndSubcourtIDToStakePathID(address _account, uint96 _subcourtID)
internal
pure
returns (bytes32 stakePathID);
Parameters
Name | Type | Description |
---|---|---|
_account | address | The account to pack. |
_subcourtID | uint96 | The subcourt ID to pack. |
Returns
Name | Type | Description |
---|---|---|
stakePathID | bytes32 | The stake path ID. |
arbitrationCost
Gets the cost of arbitration in a specified subcourt.
function arbitrationCost(bytes memory _extraData) public view override returns (uint256 cost);
Parameters
Name | Type | Description |
---|---|---|
_extraData | bytes | Additional info about the dispute. We use it to pass the ID of the subcourt to create the dispute in (first 32 bytes) and the minimum number of jurors required (next 32 bytes). |
Returns
Name | Type | Description |
---|---|---|
cost | uint256 | The cost. |
currentRuling
Gets the current ruling of a specified dispute.
function currentRuling(uint256 _disputeID) public view returns (uint256 ruling);
Parameters
Name | Type | Description |
---|---|---|
_disputeID | uint256 | The ID of the dispute. |
Returns
Name | Type | Description |
---|---|---|
ruling | uint256 | The current ruling. |
getSubcourt
Gets a specified subcourt's non primitive properties.
function getSubcourt(uint96 _subcourtID)
external
view
returns (uint256[] memory children, uint256[4] memory timesPerPeriod);
Parameters
Name | Type | Description |
---|---|---|
_subcourtID | uint96 | The ID of the subcourt. |
Returns
Name | Type | Description |
---|---|---|
children | uint256[] | The subcourt's child court list. |
timesPerPeriod | uint256[4] | The subcourt's time per period. |
getVote
Gets a specified vote for a specified appeal in a specified dispute.
function getVote(uint256 _disputeID, uint256 _appeal, uint256 _voteID)
external
view
returns (address account, bytes32 commit, uint256 choice, bool voted);
Parameters
Name | Type | Description |
---|---|---|
_disputeID | uint256 | The ID of the dispute. |
_appeal | uint256 | The appeal. |
_voteID | uint256 | The ID of the vote. |
Returns
Name | Type | Description |
---|---|---|
account | address | The account for vote. |
commit | bytes32 | The commit for vote. |
choice | uint256 | The choice for vote. |
voted | bool | True if the account voted, False otherwise. |
getVoteCounter
Gets the vote counter for a specified appeal in a specified dispute. Note: This function is only to be used by the interface and it won't work if the number of choices is too high.
function getVoteCounter(uint256 _disputeID, uint256 _appeal)
external
view
returns (uint256 winningChoice, uint256[] memory counts, bool tied);
Parameters
Name | Type | Description |
---|---|---|
_disputeID | uint256 | The ID of the dispute. |
_appeal | uint256 | The appeal. |
Returns
Name | Type | Description |
---|---|---|
winningChoice | uint256 | The winning choice. |
counts | uint256[] | The count. |
tied | bool | Whether the vote tied. O(n) where n is the number of choices of the dispute. |
getDispute
Gets a specified dispute's non primitive properties.
function getDispute(uint256 _disputeID)
external
view
returns (
uint256[] memory votesLengths,
uint256[] memory tokensAtStakePerJuror,
uint256[] memory totalFeesForJurors,
uint256[] memory votesInEachRound,
uint256[] memory repartitionsInEachRound,
uint256[] memory penaltiesInEachRound
);
Parameters
Name | Type | Description |
---|---|---|
_disputeID | uint256 | The ID of the dispute. |
Returns
Name | Type | Description |
---|---|---|
votesLengths | uint256[] | The dispute's vote length. |
tokensAtStakePerJuror | uint256[] | The dispute's required tokens at stake per Juror. |
totalFeesForJurors | uint256[] | The dispute's total fees for Jurors. |
votesInEachRound | uint256[] | The dispute's counter of votes made in each round. |
repartitionsInEachRound | uint256[] | The dispute's counter of vote reward repartitions made in each round. |
penaltiesInEachRound | uint256[] | The dispute's amount of tokens collected from penalties in each round. O(a) where a is the number of appeals of the dispute. |
getJuror
Gets a specified juror's non primitive properties.
function getJuror(address _account) external view returns (uint96[] memory subcourtIDs);
Parameters
Name | Type | Description |
---|---|---|
_account | address | The address of the juror. |
Returns
Name | Type | Description |
---|---|---|
subcourtIDs | uint96[] | The juror's IDs of subcourts where the juror has stake path. |
stakeOf
Gets the stake of a specified juror in a specified subcourt.
function stakeOf(address _account, uint96 _subcourtID) external view returns (uint256 stake);
Parameters
Name | Type | Description |
---|---|---|
_account | address | The address of the juror. |
_subcourtID | uint96 | The ID of the subcourt. |
Returns
Name | Type | Description |
---|---|---|
stake | uint256 | The stake. |
Events
NewPhase
Emitted when we pass to a new phase.
event NewPhase(Phase _phase);
NewPeriod
Emitted when a dispute passes to a new period.
event NewPeriod(uint256 indexed _disputeID, Period _period);
StakeSet
Emitted when a juror's stake is set.
event StakeSet(address indexed _address, uint256 _subcourtID, uint128 _stake, uint256 _newTotalStake);
Draw
Emitted when a juror is drawn.
event Draw(address indexed _address, uint256 indexed _disputeID, uint256 _appeal, uint256 _voteID);
TokenAndETHShift
Emitted when a juror wins or loses tokens and ETH from a dispute.
event TokenAndETHShift(address indexed _address, uint256 indexed _disputeID, int256 _tokenAmount, int256 _ETHAmount);
Structs
Court
struct Court {
uint96 parent;
uint256[] children;
bool hiddenVotes;
uint256 minStake;
uint256 alpha;
uint256 feeForJuror;
uint256 jurorsForCourtJump;
uint256[4] timesPerPeriod;
}
DelayedSetStake
struct DelayedSetStake {
address account;
uint96 subcourtID;
uint128 stake;
}
Vote
struct Vote {
address account;
bytes32 commit;
uint256 choice;
bool voted;
}
VoteCounter
struct VoteCounter {
uint256 winningChoice;
mapping(uint256 => uint256) counts;
bool tied;
}
Dispute
struct Dispute {
uint96 subcourtID;
IArbitrable arbitrated;
uint256 numberOfChoices;
Period period;
uint256 lastPeriodChange;
Vote[][] votes;
VoteCounter[] voteCounters;
uint256[] tokensAtStakePerJuror;
uint256[] totalFeesForJurors;
uint256 drawsInRound;
uint256 commitsInRound;
uint256[] votesInEachRound;
uint256[] repartitionsInEachRound;
uint256[] penaltiesInEachRound;
bool ruled;
}
Juror
struct Juror {
uint96[] subcourtIDs;
uint256 stakedTokens;
uint256 lockedTokens;
}
Enums
Phase
enum Phase {
staking,
generating,
drawing
}
Period
enum Period {
evidence,
commit,
vote,
appeal,
execution
}
Contents
CappedMath
Math operations with caps for under and overflow.
State Variables
UINT_MAX
uint256 private constant UINT_MAX = type(uint256).max;
Functions
addCap
Adds two unsigned integers, returns 2^256 - 1 on overflow.
function addCap(uint256 _a, uint256 _b) internal pure returns (uint256);
subCap
Subtracts two integers, returns 0 on underflow.
function subCap(uint256 _a, uint256 _b) internal pure returns (uint256);
mulCap
Multiplies two unsigned integers, returns 2^256 - 1 on overflow.
function mulCap(uint256 _a, uint256 _b) internal pure returns (uint256);
SortitionSumTreeFactory
Author: Enrique Piqueras - epiquerass@gmail.com
A factory of trees that keep track of staked values for sortition.
Functions
createTree
Public
Create a sortition sum tree at the specified key.
function createTree(SortitionSumTrees storage self, bytes32 _key, uint256 _K) public;
Parameters
Name | Type | Description |
---|---|---|
self | SortitionSumTrees | |
_key | bytes32 | The key of the new tree. |
_K | uint256 | The number of children each node in the tree should have. |
set
Set a value of a tree.
function set(SortitionSumTrees storage self, bytes32 _key, uint256 _value, bytes32 _ID) public;
Parameters
Name | Type | Description |
---|---|---|
self | SortitionSumTrees | |
_key | bytes32 | The key of the tree. |
_value | uint256 | The new value. |
_ID | bytes32 | The ID of the value. O(log_k(n)) where k is the maximum number of childs per node in the tree, and n is the maximum number of nodes ever appended. |
queryLeafs
Public Views
Query the leaves of a tree. Note that if startIndex == 0
, the tree is empty and the root node will be returned.
function queryLeafs(SortitionSumTrees storage self, bytes32 _key, uint256 _cursor, uint256 _count)
public
view
returns (uint256 startIndex, uint256[] memory values, bool hasMore);
Parameters
Name | Type | Description |
---|---|---|
self | SortitionSumTrees | |
_key | bytes32 | The key of the tree to get the leaves from. |
_cursor | uint256 | The pagination cursor. |
_count | uint256 | The number of items to return. |
Returns
Name | Type | Description |
---|---|---|
startIndex | uint256 | The index at which leaves start. |
values | uint256[] | The values of the returned leaves. |
hasMore | bool | Whether there are more for pagination. O(n) where n is the maximum number of nodes ever appended. |
draw
Draw an ID from a tree using a number. Note that this function reverts if the sum of all values in the tree is 0.
function draw(SortitionSumTrees storage self, bytes32 _key, uint256 _drawnNumber) public view returns (bytes32 ID);
Parameters
Name | Type | Description |
---|---|---|
self | SortitionSumTrees | |
_key | bytes32 | The key of the tree. |
_drawnNumber | uint256 | The drawn number. |
Returns
Name | Type | Description |
---|---|---|
ID | bytes32 | The drawn ID. O(k * log_k(n)) where k is the maximum number of childs per node in the tree, and n is the maximum number of nodes ever appended. |
stakeOf
Gets a specified ID's associated value.
function stakeOf(SortitionSumTrees storage self, bytes32 _key, bytes32 _ID) public view returns (uint256 value);
Parameters
Name | Type | Description |
---|---|---|
self | SortitionSumTrees | |
_key | bytes32 | The key of the tree. |
_ID | bytes32 | The ID of the value. |
Returns
Name | Type | Description |
---|---|---|
value | uint256 | The associated value. |
updateParents
Private
Update all the parents of a node.
function updateParents(
SortitionSumTrees storage self,
bytes32 _key,
uint256 _treeIndex,
bool _plusOrMinus,
uint256 _value
) private;
Parameters
Name | Type | Description |
---|---|---|
self | SortitionSumTrees | |
_key | bytes32 | The key of the tree to update. |
_treeIndex | uint256 | The index of the node to start from. |
_plusOrMinus | bool | Wether to add (true) or substract (false). |
_value | uint256 | The value to add or substract. O(log_k(n)) where k is the maximum number of childs per node in the tree, and n is the maximum number of nodes ever appended. |
Structs
SortitionSumTree
Structs
struct SortitionSumTree {
uint256 K;
uint256[] stack;
uint256[] nodes;
mapping(bytes32 => uint256) IDsToNodeIndexes;
mapping(uint256 => bytes32) nodeIndexesToIDs;
}
SortitionSumTrees
Storage
struct SortitionSumTrees {
mapping(bytes32 => SortitionSumTree) sortitionSumTrees;
}
Contents
Contents
RandomizerMock
Inherits: IRandomizer
State Variables
id
uint256 private id;
Functions
request
function request(uint256 callbackGasLimit) external override returns (uint256);
clientWithdrawTo
function clientWithdrawTo(address _to, uint256 _amount) external override;
relay
function relay(RandomizerRNG _rng, uint256 _id, bytes32 _value) external;
BlockHashRNG
Inherits: RNG
Author: Clément Lesaege - clement@lesaege.com
Random Number Generator returning the blockhash with a fallback behaviour. In case no one called it within the 256 blocks, it returns the previous blockhash. This contract must be used when returning 0 is a worse failure mode than returning another blockhash. Allows saving the random number for use in the future. It allows the contract to still access the blockhash even after 256 blocks.*
State Variables
randomNumbers
mapping(uint256 => uint256) public randomNumbers;
Functions
requestRandomness
Request a random number.
function requestRandomness(uint256 _block) external override;
Parameters
Name | Type | Description |
---|---|---|
_block | uint256 | Block the random number is linked to. |
receiveRandomness
Return the random number. If it has not been saved and is still computable compute it.
function receiveRandomness(uint256 _block) external override returns (uint256 randomNumber);
Parameters
Name | Type | Description |
---|---|---|
_block | uint256 | Block the random number is linked to. |
Returns
Name | Type | Description |
---|---|---|
randomNumber | uint256 | The random number or 0 if it is not ready or has not been requested. |
IRandomizer
Functions
request
function request(uint256 callbackGasLimit) external returns (uint256);
clientWithdrawTo
function clientWithdrawTo(address _to, uint256 _amount) external;
IncrementalNG
Inherits: RNG
Author: JayBuidl jb@kleros.io
A Random Number Generator which returns a number incremented by 1 each time. Useful as a fallback method.
State Variables
number
uint256 public number;
Functions
constructor
constructor(uint256 _start);
requestRandomness
Request a random number.
function requestRandomness(uint256 _block) external override;
Parameters
Name | Type | Description |
---|---|---|
_block | uint256 | Block the random number is linked to. |
receiveRandomness
Get the "random number" (which is always the same).
function receiveRandomness(uint256 _block) external override returns (uint256 randomNumber);
Parameters
Name | Type | Description |
---|---|---|
_block | uint256 | Block the random number is linked to. |
Returns
Name | Type | Description |
---|---|---|
randomNumber | uint256 | The random number or 0 if it is not ready or has not been requested. |
RNG
Functions
requestRandomness
Request a random number.
function requestRandomness(uint256 _block) external;
Parameters
Name | Type | Description |
---|---|---|
_block | uint256 | Block linked to the request. |
receiveRandomness
Receive the random number.
function receiveRandomness(uint256 _block) external returns (uint256 randomNumber);
Parameters
Name | Type | Description |
---|---|---|
_block | uint256 | Block the random number is linked to. |
Returns
Name | Type | Description |
---|---|---|
randomNumber | uint256 | Random Number. If the number is not ready or has not been required 0 instead. |
RandomizerRNG
Inherits: RNG
State Variables
governor
address public governor;
callbackGasLimit
uint256 public callbackGasLimit = 50000;
randomizer
IRandomizer public randomizer;
randomNumbers
mapping(uint256 => uint256) public randomNumbers;
requesterToID
mapping(address => uint256) public requesterToID;
Functions
onlyByGovernor
modifier onlyByGovernor();
constructor
Constructor.
constructor(IRandomizer _randomizer, address _governor);
Parameters
Name | Type | Description |
---|---|---|
_randomizer | IRandomizer | Randomizer contract. |
_governor | address | Governor of the contract. |
changeGovernor
Changes the governor of the contract.
function changeGovernor(address _governor) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_governor | address | The new governor. |
setCallbackGasLimit
Change the Randomizer callback gas limit.
function setCallbackGasLimit(uint256 _callbackGasLimit) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_callbackGasLimit | uint256 | the new limit. |
setRandomizer
Change the Randomizer address.
function setRandomizer(address _randomizer) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_randomizer | address | the new Randomizer address. |
randomizerWithdraw
Allows the governor to withdraw randomizer funds.
function randomizerWithdraw(uint256 _amount) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_amount | uint256 | Amount to withdraw in wei. |
requestRandomness
Request a random number. The id of the request is tied to the sender.
function requestRandomness(uint256) external override;
randomizerCallback
Callback function called by the randomizer contract when the random value is generated.
function randomizerCallback(uint256 _id, bytes32 _value) external;
receiveRandomness
Return the random number.
function receiveRandomness(uint256) external view override returns (uint256 randomNumber);
Returns
Name | Type | Description |
---|---|---|
randomNumber | uint256 | The random number or 0 if it is not ready or has not been requested. |
Contents
Faucet
State Variables
token
IERC20 public token;
withdrewAlready
mapping(address => bool) public withdrewAlready;
Functions
constructor
constructor(IERC20 _token);
balance
function balance() public view returns (uint256);
request
function request() public;
PNK
Inherits: ERC20
Functions
constructor
constructor() ERC20("Pinakion", "PNK");
WETH
Inherits: ERC20
Functions
constructor
constructor() ERC20("Wrapped ETH", "WETH");
WrappedPinakionV2
Inherits: ERC20
Functions
constructor
constructor() ERC20("Staking PNK on xDai", "stPNK");