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

Commit 360d007

Browse files
committed
chore: map governance functions in subgraph
1 parent 9810923 commit 360d007

File tree

4 files changed

+124
-7
lines changed

4 files changed

+124
-7
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
## (2021-01-22)
1+
## (2021-01-23)
22

3+
- chore: build subgraph schema ([9810923](https://github.com/kleros/governor-web/commit/9810923))
34
- chore: generate first changelog ([2e41de7](https://github.com/kleros/governor-web/commit/2e41de7))
45
- chore: set up project and architecture ([d28fb74](https://github.com/kleros/governor-web/commit/d28fb74))

subgraph/schema.graphql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ type Contract @entity {
3030
"""
3131
id: ID!
3232
"""
33+
Arbitrator.
34+
"""
35+
arbitrator: Bytes!
36+
"""
37+
Arbitrator extra data.
38+
"""
39+
arbitratorExtraData: Bytes!
40+
"""
3341
Deployer.
3442
"""
3543
deployer: Bytes!

subgraph/src/mapping.ts

Lines changed: 96 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
1-
import { ByteArray } from "@graphprotocol/graph-ts";
1+
import { Address, ByteArray } from "@graphprotocol/graph-ts";
22

3-
import { Governor, SetMetaEvidenceCall } from "../generated/Governor/Governor";
3+
import {
4+
ChangeArbitratorCall,
5+
ChangeExecutionTimeoutCall,
6+
ChangeLoserMultiplierCall,
7+
ChangeMetaEvidenceCall,
8+
ChangeSharedMultiplierCall,
9+
ChangeSubmissionDepositCall,
10+
ChangeSubmissionTimeoutCall,
11+
ChangeWinnerMultiplierCall,
12+
ChangeWithdrawTimeoutCall,
13+
Governor,
14+
SetMetaEvidenceCall,
15+
} from "../generated/Governor/Governor";
416
import { Contract, MetaEvidence } from "../generated/schema";
517

618
function getStatus(status: number): string {
@@ -17,11 +29,15 @@ function concatByteArrays(a: ByteArray, b: ByteArray): ByteArray {
1729
return out as ByteArray;
1830
}
1931

20-
export function setMetaEvidence(call: SetMetaEvidenceCall): void {
21-
let governor = Governor.bind(call.to);
32+
function initializeContract(address: Address, deployer: Address): Contract {
33+
let contract = Contract.load("0");
34+
if (contract != null) return contract as Contract;
35+
let governor = Governor.bind(address);
2236

23-
let contract = new Contract("0");
24-
contract.deployer = call.from;
37+
contract = new Contract("0");
38+
contract.arbitrator = governor.arbitrator();
39+
contract.arbitratorExtraData = governor.arbitratorExtraData();
40+
contract.deployer = contract.deployer || deployer;
2541
contract.reservedETH = governor.reservedETH();
2642
contract.submissionBaseDeposit = governor.submissionBaseDeposit();
2743
contract.submissionTimeout = governor.submissionTimeout();
@@ -32,6 +48,80 @@ export function setMetaEvidence(call: SetMetaEvidenceCall): void {
3248
contract.loserMultiplier = governor.loserMultiplier();
3349
contract.lastApprovalTime = governor.lastApprovalTime();
3450
contract.metaEvidenceUpdates = governor.metaEvidenceUpdates();
51+
contract.metaEvidence = contract.metaEvidenceUpdates.toHexString();
52+
contract.save();
53+
54+
return contract as Contract;
55+
}
56+
57+
export function setMetaEvidence(call: SetMetaEvidenceCall): void {
58+
let contract = initializeContract(call.to, call.from);
59+
60+
let metaEvidence = new MetaEvidence(
61+
contract.metaEvidenceUpdates.toHexString()
62+
);
63+
metaEvidence.URI = call.inputs._metaEvidence;
64+
metaEvidence.save();
65+
66+
contract.metaEvidence = metaEvidence.id;
67+
contract.save();
68+
}
69+
70+
export function changeSubmissionDeposit(
71+
call: ChangeSubmissionDepositCall
72+
): void {
73+
let contract = initializeContract(call.to, call.from);
74+
contract.submissionBaseDeposit = call.inputs._submissionBaseDeposit;
75+
contract.save();
76+
}
77+
78+
export function changeSubmissionTimeout(
79+
call: ChangeSubmissionTimeoutCall
80+
): void {
81+
let contract = initializeContract(call.to, call.from);
82+
contract.submissionTimeout = call.inputs._submissionTimeout;
83+
contract.save();
84+
}
85+
86+
export function changeExecutionTimeout(call: ChangeExecutionTimeoutCall): void {
87+
let contract = initializeContract(call.to, call.from);
88+
contract.executionTimeout = call.inputs._executionTimeout;
89+
contract.save();
90+
}
91+
92+
export function changeWithdrawTimeout(call: ChangeWithdrawTimeoutCall): void {
93+
let contract = initializeContract(call.to, call.from);
94+
contract.withdrawTimeout = call.inputs._withdrawTimeout;
95+
contract.save();
96+
}
97+
98+
export function changeSharedMultiplier(call: ChangeSharedMultiplierCall): void {
99+
let contract = initializeContract(call.to, call.from);
100+
contract.sharedMultiplier = call.inputs._sharedMultiplier;
101+
contract.save();
102+
}
103+
104+
export function changeWinnerMultiplier(call: ChangeWinnerMultiplierCall): void {
105+
let contract = initializeContract(call.to, call.from);
106+
contract.winnerMultiplier = call.inputs._winnerMultiplier;
107+
contract.save();
108+
}
109+
110+
export function changeLoserMultiplier(call: ChangeLoserMultiplierCall): void {
111+
let contract = initializeContract(call.to, call.from);
112+
contract.loserMultiplier = call.inputs._loserMultiplier;
113+
contract.save();
114+
}
115+
116+
export function changeArbitrator(call: ChangeArbitratorCall): void {
117+
let contract = initializeContract(call.to, call.from);
118+
contract.arbitrator = call.inputs._arbitrator;
119+
contract.arbitratorExtraData = call.inputs._arbitratorExtraData;
120+
contract.save();
121+
}
122+
123+
export function changeMetaEvidence(call: ChangeMetaEvidenceCall): void {
124+
let contract = initializeContract(call.to, call.from);
35125

36126
let metaEvidence = new MetaEvidence(
37127
contract.metaEvidenceUpdates.toHexString()

subgraph/subgraph.template.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,22 @@ dataSources:
2121
callHandlers:
2222
- function: setMetaEvidence(string)
2323
handler: setMetaEvidence
24+
- function: changeSubmissionDeposit(uint256)
25+
handler: changeSubmissionDeposit
26+
- function: changeSubmissionTimeout(uint256)
27+
handler: changeSubmissionTimeout
28+
- function: changeExecutionTimeout(uint256)
29+
handler: changeExecutionTimeout
30+
- function: changeWithdrawTimeout(uint256)
31+
handler: changeWithdrawTimeout
32+
- function: changeSharedMultiplier(uint256)
33+
handler: changeSharedMultiplier
34+
- function: changeWinnerMultiplier(uint256)
35+
handler: changeWinnerMultiplier
36+
- function: changeLoserMultiplier(uint256)
37+
handler: changeLoserMultiplier
38+
- function: changeArbitrator(address,bytes)
39+
handler: changeArbitrator
40+
- function: changeMetaEvidence(string)
41+
handler: changeMetaEvidence
2442
file: ./src/mapping.ts

0 commit comments

Comments
 (0)