Skip to content

Commit f90f949

Browse files
committed
feat: stake set
this code was not pushed to the repo
1 parent e79d475 commit f90f949

File tree

8 files changed

+3044
-511
lines changed

8 files changed

+3044
-511
lines changed

contracts/kleros.json

+736-309
Large diffs are not rendered by default.

generated/Kleros/Kleros.ts

+2,128-196
Large diffs are not rendered by default.

generated/schema.ts

+131
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,137 @@ export class TokenAndETHShift extends Entity {
518518
}
519519
}
520520

521+
export class StakeSet extends Entity {
522+
constructor(id: string) {
523+
super();
524+
this.set("id", Value.fromString(id));
525+
}
526+
527+
save(): void {
528+
let id = this.get("id");
529+
assert(id != null, "Cannot save StakeSet entity without an ID");
530+
if (id) {
531+
assert(
532+
id.kind == ValueKind.STRING,
533+
`Entities of type StakeSet must have an ID of type String but the id '${id.displayData()}' is of type ${id.displayKind()}`
534+
);
535+
store.set("StakeSet", id.toString(), this);
536+
}
537+
}
538+
539+
static loadInBlock(id: string): StakeSet | null {
540+
return changetype<StakeSet | null>(store.get_in_block("StakeSet", id));
541+
}
542+
543+
static load(id: string): StakeSet | null {
544+
return changetype<StakeSet | null>(store.get("StakeSet", id));
545+
}
546+
547+
get id(): string {
548+
let value = this.get("id");
549+
if (!value || value.kind == ValueKind.NULL) {
550+
throw new Error("Cannot return null for a required field.");
551+
} else {
552+
return value.toString();
553+
}
554+
}
555+
556+
set id(value: string) {
557+
this.set("id", Value.fromString(value));
558+
}
559+
560+
get address(): Bytes {
561+
let value = this.get("address");
562+
if (!value || value.kind == ValueKind.NULL) {
563+
throw new Error("Cannot return null for a required field.");
564+
} else {
565+
return value.toBytes();
566+
}
567+
}
568+
569+
set address(value: Bytes) {
570+
this.set("address", Value.fromBytes(value));
571+
}
572+
573+
get subcourtID(): BigInt {
574+
let value = this.get("subcourtID");
575+
if (!value || value.kind == ValueKind.NULL) {
576+
throw new Error("Cannot return null for a required field.");
577+
} else {
578+
return value.toBigInt();
579+
}
580+
}
581+
582+
set subcourtID(value: BigInt) {
583+
this.set("subcourtID", Value.fromBigInt(value));
584+
}
585+
586+
get stake(): BigInt {
587+
let value = this.get("stake");
588+
if (!value || value.kind == ValueKind.NULL) {
589+
throw new Error("Cannot return null for a required field.");
590+
} else {
591+
return value.toBigInt();
592+
}
593+
}
594+
595+
set stake(value: BigInt) {
596+
this.set("stake", Value.fromBigInt(value));
597+
}
598+
599+
get newTotalStake(): BigInt {
600+
let value = this.get("newTotalStake");
601+
if (!value || value.kind == ValueKind.NULL) {
602+
throw new Error("Cannot return null for a required field.");
603+
} else {
604+
return value.toBigInt();
605+
}
606+
}
607+
608+
set newTotalStake(value: BigInt) {
609+
this.set("newTotalStake", Value.fromBigInt(value));
610+
}
611+
612+
get timestamp(): BigInt {
613+
let value = this.get("timestamp");
614+
if (!value || value.kind == ValueKind.NULL) {
615+
throw new Error("Cannot return null for a required field.");
616+
} else {
617+
return value.toBigInt();
618+
}
619+
}
620+
621+
set timestamp(value: BigInt) {
622+
this.set("timestamp", Value.fromBigInt(value));
623+
}
624+
625+
get blocknumber(): BigInt {
626+
let value = this.get("blocknumber");
627+
if (!value || value.kind == ValueKind.NULL) {
628+
throw new Error("Cannot return null for a required field.");
629+
} else {
630+
return value.toBigInt();
631+
}
632+
}
633+
634+
set blocknumber(value: BigInt) {
635+
this.set("blocknumber", Value.fromBigInt(value));
636+
}
637+
638+
get logIndex(): BigInt {
639+
let value = this.get("logIndex");
640+
if (!value || value.kind == ValueKind.NULL) {
641+
throw new Error("Cannot return null for a required field.");
642+
} else {
643+
return value.toBigInt();
644+
}
645+
}
646+
647+
set logIndex(value: BigInt) {
648+
this.set("logIndex", Value.fromBigInt(value));
649+
}
650+
}
651+
521652
export class EvidenceGroup extends Entity {
522653
constructor(id: Bytes) {
523654
super();

mappings/index.ts

+27
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
NewPeriod as NewPeriodEv,
66
Draw as DrawEv,
77
TokenAndETHShift as TokenAndETHShiftEv,
8+
StakeSet as StakeSetEv,
89
Kleros,
910
} from "../generated/Kleros/Kleros";
1011
import {
@@ -21,6 +22,7 @@ import {
2122
Evidence,
2223
EvidenceGroup,
2324
Round,
25+
StakeSet,
2426
TokenAndETHShift,
2527
} from "../generated/schema";
2628
import { ADDRESS, ONE, ZERO, ZERO_B } from "./const";
@@ -164,6 +166,31 @@ export function handleTokenAndETHShift(ev: TokenAndETHShiftEv): void {
164166
shift.save();
165167
}
166168

169+
export function handleStakeSet(ev: StakeSetEv): void {
170+
// Keep rolling until we find a free ID
171+
let i = 0;
172+
while (true) {
173+
const stakeSet = StakeSet.load(
174+
`${ev.params._address.toHexString()}-${ev.params._subcourtID}-${i}`
175+
);
176+
if (stakeSet == null) break;
177+
i++;
178+
}
179+
180+
const stakeSet = new StakeSet(
181+
`${ev.params._address.toHexString()}-${ev.params._subcourtID}-${i}`
182+
);
183+
184+
stakeSet.address = ev.params._address;
185+
stakeSet.subcourtID = ev.params._subcourtID;
186+
stakeSet.stake = ev.params._stake;
187+
stakeSet.newTotalStake = ev.params._newTotalStake;
188+
stakeSet.timestamp = ev.block.timestamp;
189+
stakeSet.blocknumber = ev.block.number;
190+
stakeSet.logIndex = ev.logIndex;
191+
stakeSet.save();
192+
}
193+
167194
export function handleMetaEvidence(ev: MetaEvidenceEv): void {
168195
const arbitrableHistory = new ArbitrableHistory(
169196
Bytes.fromByteArray(

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"scripts": {
88
"build": "graph build",
99
"gen": "graph codegen --output-dir generated",
10-
"deploy-xdai": "mustache config/xdai.json subgraph.template.yaml > subgraph.yaml && mustache config/xdai.json mappings/const.template.ts > mappings/const.ts && yarn gen && graph deploy --product hosted-service andreimvp/kleros-display",
11-
"deploy-mainnet": "mustache config/mainnet.json subgraph.template.yaml > subgraph.yaml && mustache config/mainnet.json mappings/const.template.ts > mappings/const.ts && yarn gen && graph deploy --product hosted-service andreimvp/kleros-display-mainnet"
10+
"deploy-xdai": "mustache config/xdai.json subgraph.template.yaml > subgraph.yaml && mustache config/xdai.json mappings/const.template.ts > mappings/const.ts && yarn gen && graph deploy --product hosted-service greenlucid/kleros-display",
11+
"deploy-mainnet": "mustache config/mainnet.json subgraph.template.yaml > subgraph.yaml && mustache config/mainnet.json mappings/const.template.ts > mappings/const.ts && yarn gen && graph deploy --product hosted-service greenlucid/kleros-display-mainnet"
1212
}
1313
}

schema.graphql

+12
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ type TokenAndETHShift @entity {
5656
tokenAmount: BigInt!
5757
}
5858

59+
type StakeSet @entity {
60+
"address-subcourtId-(discriminator)"
61+
id: ID!
62+
address: Bytes!
63+
subcourtID: BigInt!
64+
stake: BigInt!
65+
newTotalStake: BigInt!
66+
timestamp: BigInt!
67+
blocknumber: BigInt!
68+
logIndex: BigInt!
69+
}
70+
5971
type EvidenceGroup @entity {
6072
id: Bytes!
6173
dispute: Dispute

subgraph.template.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ dataSources:
3333
handler: handleDraw
3434
- event: TokenAndETHShift(indexed address,indexed uint256,int256,int256)
3535
handler: handleTokenAndETHShift
36+
- event: StakeSet(indexed address,uint256,uint128,uint256)
37+
handler: handleStakeSet
3638
templates:
3739
- name: Arbitrable
3840
kind: ethereum/contract

subgraph.yaml

+6-4
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ schema:
55
dataSources:
66
- name: Kleros
77
kind: ethereum
8-
network: xdai
8+
network: mainnet
99
source:
10-
address: "0x9c1da9a04925bdfdedf0f6421bc7eea8305f9002"
10+
address: "0x988b3a538b618c7a603e1c11ab82cd16dbe28069"
1111
abi: Kleros
12-
startBlock: 16895601
12+
startBlock: 7303699
1313
mapping:
1414
kind: ethereum/events
1515
apiVersion: 0.0.7
@@ -33,10 +33,12 @@ dataSources:
3333
handler: handleDraw
3434
- event: TokenAndETHShift(indexed address,indexed uint256,int256,int256)
3535
handler: handleTokenAndETHShift
36+
- event: StakeSet(indexed address,uint256,uint128,uint256)
37+
handler: handleStakeSet
3638
templates:
3739
- name: Arbitrable
3840
kind: ethereum/contract
39-
network: xdai
41+
network: mainnet
4042
source:
4143
abi: Arbitrable
4244
mapping:

0 commit comments

Comments
 (0)