Skip to content
This repository has been archived by the owner on Nov 9, 2022. It is now read-only.

Commit

Permalink
chore: build subgraph schema
Browse files Browse the repository at this point in the history
  • Loading branch information
epiqueras committed Jan 22, 2021
1 parent 2e41de7 commit 9810923
Show file tree
Hide file tree
Showing 4 changed files with 307 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
## (2021-01-22)

- chore: generate first changelog ([2e41de7](https://github.com/kleros/governor-web/commit/2e41de7))
- chore: set up project and architecture ([d28fb74](https://github.com/kleros/governor-web/commit/d28fb74))
263 changes: 262 additions & 1 deletion subgraph/schema.graphql
Original file line number Diff line number Diff line change
@@ -1,6 +1,267 @@
enum Status {
"""
Session has no dispute.
"""
NoDispute
"""
Session has an active dispute.
"""
DisputeCreated
"""
Session has a resolved dispute.
"""
Resolved
}

type MetaEvidence @entity {
"""
Meta evidence ID.
"""
id: ID!
"""
URI of the meta evidence file.
"""
URI: String!
}

type Contract @entity {
"""
The singleton entity's ID, "0".
Singleton entity ID, "0".
"""
id: ID!
"""
Deployer.
"""
deployer: Bytes!
"""
Sum of reserved ETH for rewards.
"""
reservedETH: BigInt!
"""
Base deposit required for submission.
"""
submissionBaseDeposit: BigInt!
"""
Time in seconds for submission.
"""
submissionTimeout: BigInt!
"""
Time in seconds for execution.
"""
executionTimeout: BigInt!
"""
Time in seconds for withdrawal.
"""
withdrawTimeout: BigInt!
"""
Multiplier for calculating the fee stake that must be paid in a case where there is no winner or loser.
"""
sharedMultiplier: BigInt!
"""
Multiplier for calculating the fee stake paid by the party that won the previous round.
"""
winnerMultiplier: BigInt!
"""
Multiplier for calculating the fee stake paid by the party that lost the previous round.
"""
loserMultiplier: BigInt!
"""
Time of the last approval of a submission.
"""
lastApprovalTime: BigInt!
"""
Number of times the meta evidence has been updated. Used to track the latest meta evidence ID.
"""
metaEvidenceUpdates: BigInt!
"""
First submission that paid appeal fees in the last dispute.
"""
shadowWinner: Submission
"""
The current meta evidence.
"""
metaEvidence: MetaEvidence!
}

type Session @entity {
"""
Creation time.
"""
creationTime: BigInt!
"""
Session ID.
"""
id: ID!
"""
Ruling, if any.
"""
ruling: BigInt
"""
Dispute ID, if any.
"""
disputeID: BigInt
"""
Total deposits balance. This is used to calculate rewards.
"""
sumDeposit: BigInt!
"""
Status.
"""
status: Status!
"""
Cooldown period after every submission. This gives time for people to inspect and potentially challenge submissions.
"""
durationOffset: BigInt!
"""
Submissions.
"""
submissions: [Submission!]! @derivedFrom(field: "session")
"""
Number of submissions.
"""
submissionsLength: BigInt!
"""
Rounds.
"""
rounds: [Round!]! @derivedFrom(field: "session")
"""
Number of rounds.
"""
roundsLength: BigInt!
}

type Submission @entity {
"""
Creation time.
"""
creationTime: BigInt!
"""
Session the submission is for.
"""
session: Session!
"""
Submission ID.
"""
id: ID!
"""
Submitter.
"""
submitter: Bytes!
"""
Deposit.
"""
deposit: BigInt!
"""
Transactions hashed in a chain.
"""
listHash: Bytes!
"""
True, if the submission was accepted for execution.
"""
approved: Boolean!
"""
Time when the submission was approved, if any.
"""
approvalTime: BigInt
"""
Transactions.
"""
transactions: [Transaction!]! @derivedFrom(field: "submission")
"""
Number of transactions.
"""
transactionsLength: BigInt!
}

type Transaction @entity {
"""
Creation time.
"""
creationTime: BigInt!
"""
Submission the transaction is for.
"""
submission: Submission!
"""
Transaction ID, keccak256(submissionID) + submissionTransactionsLength.
"""
id: ID!
"""
Address to call.
"""
target: Bytes!
"""
Value to call with.
"""
value: BigInt!
"""
Data to call with.
"""
data: Bytes!
"""
True, if the transaction was executed.
"""
executed: Boolean!
}

type Round @entity {
"""
Creation time.
"""
creationTime: BigInt!
"""
Session the round is for.
"""
session: Session!
"""
Round ID, keccak256(sessionID, sessionRoundsLength).
"""
id: ID!
"""
Fees paid by each side in the round.
"""
paidFees: [BigInt!]!
"""
True, for sides that have fully paid their fee.
"""
hasPaid: [Boolean!]!
"""
Sum of reimbursable fees and stake rewards available to the parties that made contributions to the side that ultimately won.
"""
feeRewards: BigInt!
"""
Sum of already reimbursed fees and rewarded stakes.
"""
successfullyPaid: BigInt!
"""
Contributions for the round.
"""
contributions: [Contribution!]! @derivedFrom(field: "round")
"""
Number of contributions.
"""
contributionsLength: BigInt!
}

type Contribution @entity {
"""
Creation time.
"""
creationTime: BigInt!
"""
Round the contribution is for.
"""
round: Round!
"""
Contribution's ID, keccak256(roundID, contributor).
"""
id: ID!
"""
Address of the contributor.
"""
contributor: Bytes!
"""
Contributions for each side.
"""
values: [BigInt!]!
}
47 changes: 41 additions & 6 deletions subgraph/src/mapping.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,44 @@
import { BigInt } from "@graphprotocol/graph-ts";
import { ListSubmitted } from "../generated/Governor/Governor";
import { Contract } from "../generated/schema";
import { ByteArray } from "@graphprotocol/graph-ts";

export function listSubmitted(event: ListSubmitted): void {
let ID = new BigInt(0);
let contract = new Contract(ID.toString());
import { Governor, SetMetaEvidenceCall } from "../generated/Governor/Governor";
import { Contract, MetaEvidence } from "../generated/schema";

function getStatus(status: number): string {
if (status == 0) return "NoDispute";
if (status == 1) return "DisputeCreated";
if (status == 2) return "Resolved";
return "Error";
}

function concatByteArrays(a: ByteArray, b: ByteArray): ByteArray {
let out = new Uint8Array(a.length + b.length);
for (let i = 0; i < a.length; i++) out[i] = a[i];
for (let j = 0; j < b.length; j++) out[a.length + j] = b[j];
return out as ByteArray;
}

export function setMetaEvidence(call: SetMetaEvidenceCall): void {
let governor = Governor.bind(call.to);

let contract = new Contract("0");
contract.deployer = call.from;
contract.reservedETH = governor.reservedETH();
contract.submissionBaseDeposit = governor.submissionBaseDeposit();
contract.submissionTimeout = governor.submissionTimeout();
contract.executionTimeout = governor.executionTimeout();
contract.withdrawTimeout = governor.withdrawTimeout();
contract.sharedMultiplier = governor.sharedMultiplier();
contract.winnerMultiplier = governor.winnerMultiplier();
contract.loserMultiplier = governor.loserMultiplier();
contract.lastApprovalTime = governor.lastApprovalTime();
contract.metaEvidenceUpdates = governor.metaEvidenceUpdates();

let metaEvidence = new MetaEvidence(
contract.metaEvidenceUpdates.toHexString()
);
metaEvidence.URI = call.inputs._metaEvidence;
metaEvidence.save();

contract.metaEvidence = metaEvidence.id;
contract.save();
}
6 changes: 3 additions & 3 deletions subgraph/subgraph.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dataSources:
abis:
- name: Governor
file: ./abis/governor.json
eventHandlers:
- event: ListSubmitted(indexed uint256,indexed address,indexed uint256,string)
handler: listSubmitted
callHandlers:
- function: setMetaEvidence(string)
handler: setMetaEvidence
file: ./src/mapping.ts

0 comments on commit 9810923

Please sign in to comment.