Skip to content

Commit e7eb5da

Browse files
Emmett Childsgitbook-bot
authored andcommitted
GITBOOK-317: change request with no subject merged in GitBook
1 parent c4ed256 commit e7eb5da

File tree

2 files changed

+166
-0
lines changed

2 files changed

+166
-0
lines changed

SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
* [Arbitration Development](developer/arbitration-development/README.md)
8484
* [ERC-792: Arbitration Standard](developer/arbitration-development/erc-792-arbitration-standard.md)
8585
* [ERC 1497: Evidence Standard](developer/arbitration-development/erc-1497-evidence-standard.md)
86+
* [Arbitrable Proxy](developer/arbitration-development/arbitrable-proxy.md)
8687
* [Arbitration by Example](developer/arbitration-by-example/README.md)
8788
* [ArbitrableDeposit.sol](developer/arbitration-by-example/arbitrabledeposit.sol.md)
8889
* [TwoPartyArbitrable.sol](developer/arbitration-by-example/twopartyarbitrable.sol.md)
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
---
2+
description: A simpler way to build arbitrable applications.
3+
---
4+
5+
# Arbitrable Proxy
6+
7+
The arbitrable proxy contract abstracts away most of the heavy lifting associated with implementing the ERC792 and ERC1497 standards from scratch in an arbitrable application.
8+
9+
## Getting Started
10+
11+
### Step 1:
12+
13+
Import the IArbitrableProxy interface into your project
14+
15+
```solidity
16+
// SPDX-License-Identifier: MIT
17+
18+
pragma solidity ^0.8.0;
19+
20+
import "@kleros/erc-792/contracts/IArbitrator.sol";
21+
22+
/**
23+
* @title IArbitrableProxy
24+
* A general purpose arbitrable contract. Supports non-binary rulings.
25+
*/
26+
interface IArbitrableProxy {
27+
function arbitrator() external view returns (IArbitrator arbitrator);
28+
29+
function createDispute(
30+
bytes calldata _arbitratorExtraData,
31+
string calldata _metaevidenceURI,
32+
uint256 _numberOfRulingOptions
33+
) external payable returns (uint256 disputeID);
34+
35+
struct DisputeStruct {
36+
bytes arbitratorExtraData;
37+
bool isRuled;
38+
uint256 ruling;
39+
uint256 disputeIDOnArbitratorSide;
40+
}
41+
42+
function externalIDtoLocalID(
43+
uint256 _externalID
44+
) external returns (uint256 localID);
45+
46+
function disputes(
47+
uint256 _localID
48+
)
49+
external
50+
returns (
51+
bytes memory extraData,
52+
bool isRuled,
53+
uint256 ruling,
54+
uint256 disputeIDOnArbitratorSide
55+
);
56+
57+
function submitEvidence(uint256 _localDisputeID, string calldata _evidenceURI) external;
58+
}
59+
60+
```
61+
62+
#### Usage
63+
64+
```solidity
65+
contract MyArbitrable {
66+
IArbitrableProxy arbitrableProxy = IArbitrableProxy(<ARBITRATOR_ADDRESS>);
67+
}
68+
```
69+
70+
### Step 2:
71+
72+
Create disputes through the proxy
73+
74+
```solidity
75+
contract MyArbitrable {
76+
IArbitrableProxy arbitrableProxy = IArbitrableProxy(<ARBITRATOR_ADDRESS>);
77+
78+
function foo(
79+
bytes calldata extraData,
80+
string memory evidenceURI,
81+
uint256 rulingOptions
82+
) {
83+
uint256 disputeID = arbitrableProxy.createDispute{value: msg.value}(
84+
extraData,
85+
evidenceURI,
86+
rulingOptions
87+
);
88+
89+
// do something with disputeID
90+
}
91+
}
92+
```
93+
94+
### Step 3:
95+
96+
Create a fetchRuling function.&#x20;
97+
98+
A key difference between using the proxy and implementing your own ERC792 arbitrable from scratch is that a rule function is not directly called in your contract by the arbitrator. The proxy stores the data of rulings locally in an array and its up to you to query the rulings relevant to your contract.
99+
100+
Let's first take a look at how rulings are stored on the arbitrable proxy then move on to how to implement a fetchRuling function in your contract.
101+
102+
```solidity
103+
/// https://github.com/kleros/arbitrable-proxy-contracts/blob/master/contracts/ArbitrableProxy.sol
104+
105+
contract ArbitrableProxy is IDisputeResolver {
106+
// ...
107+
// ...
108+
// ...
109+
struct DisputeStruct {
110+
bytes arbitratorExtraData;
111+
bool isRuled;
112+
uint256 ruling;
113+
uint256 disputeIDOnArbitratorSide;
114+
}
115+
116+
DisputeStruct[] public disputes;
117+
118+
function rule(uint256 _externalDisputeID, uint256 _ruling) external override {
119+
uint256 localDisputeID = externalIDtoLocalID[_externalDisputeID];
120+
DisputeStruct storage dispute = disputes[localDisputeID];
121+
require(msg.sender == address(arbitrator), "Only the arbitrator can execute this.");
122+
require(_ruling <= numberOfRulingOptions[localDisputeID], "Invalid ruling.");
123+
require(dispute.isRuled == false, "This dispute has been ruled already.");
124+
125+
dispute.isRuled = true;
126+
dispute.ruling = _ruling;
127+
128+
Round[] storage rounds = disputeIDtoRoundArray[localDisputeID];
129+
Round storage lastRound = disputeIDtoRoundArray[localDisputeID][rounds.length - 1];
130+
// If only one ruling option is funded, it wins by default. Note that if any other ruling had funded, an appeal would have been created.
131+
if (lastRound.fundedRulings.length == 1) {
132+
dispute.ruling = lastRound.fundedRulings[0];
133+
}
134+
135+
emit Ruling(IArbitrator(msg.sender), _externalDisputeID, dispute.ruling);
136+
}
137+
}
138+
```
139+
140+
```solidity
141+
contract MyArbitrable {
142+
IArbitrableProxy arbitrableProxy = IArbitrableProxy(<ARBITRATOR_ADDRESS>);
143+
function foo(
144+
bytes calldata extraData,
145+
string memory evidenceURI,
146+
uint256 rulingOptions
147+
) {
148+
uint256 disputeID = arbitrableProxy.createDispute{value: msg.value}(
149+
extraData,
150+
evidenceURI,
151+
rulingOptions
152+
);
153+
154+
// do something with disputeID
155+
}
156+
157+
function fetchRuling(uint256 disputeID) {
158+
(, bool isRuled, uint256 ruling) = arbitrableProxy.disputes(disputeID)
159+
160+
// do something with ruling if isRuled
161+
}
162+
}
163+
```
164+
165+
And that's it! With this, you would have a fully trustless integration with Kleros Court for less than half the work of a fully ERC792 compliant integration.

0 commit comments

Comments
 (0)