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

Commit

Permalink
chore: map governance functions in subgraph
Browse files Browse the repository at this point in the history
  • Loading branch information
epiqueras committed Jan 23, 2021
1 parent 9810923 commit 360d007
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 7 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## (2021-01-22)
## (2021-01-23)

- chore: build subgraph schema ([9810923](https://github.com/kleros/governor-web/commit/9810923))
- 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))
8 changes: 8 additions & 0 deletions subgraph/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ type Contract @entity {
"""
id: ID!
"""
Arbitrator.
"""
arbitrator: Bytes!
"""
Arbitrator extra data.
"""
arbitratorExtraData: Bytes!
"""
Deployer.
"""
deployer: Bytes!
Expand Down
102 changes: 96 additions & 6 deletions subgraph/src/mapping.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import { ByteArray } from "@graphprotocol/graph-ts";
import { Address, ByteArray } from "@graphprotocol/graph-ts";

import { Governor, SetMetaEvidenceCall } from "../generated/Governor/Governor";
import {
ChangeArbitratorCall,
ChangeExecutionTimeoutCall,
ChangeLoserMultiplierCall,
ChangeMetaEvidenceCall,
ChangeSharedMultiplierCall,
ChangeSubmissionDepositCall,
ChangeSubmissionTimeoutCall,
ChangeWinnerMultiplierCall,
ChangeWithdrawTimeoutCall,
Governor,
SetMetaEvidenceCall,
} from "../generated/Governor/Governor";
import { Contract, MetaEvidence } from "../generated/schema";

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

export function setMetaEvidence(call: SetMetaEvidenceCall): void {
let governor = Governor.bind(call.to);
function initializeContract(address: Address, deployer: Address): Contract {
let contract = Contract.load("0");
if (contract != null) return contract as Contract;
let governor = Governor.bind(address);

let contract = new Contract("0");
contract.deployer = call.from;
contract = new Contract("0");
contract.arbitrator = governor.arbitrator();
contract.arbitratorExtraData = governor.arbitratorExtraData();
contract.deployer = contract.deployer || deployer;
contract.reservedETH = governor.reservedETH();
contract.submissionBaseDeposit = governor.submissionBaseDeposit();
contract.submissionTimeout = governor.submissionTimeout();
Expand All @@ -32,6 +48,80 @@ export function setMetaEvidence(call: SetMetaEvidenceCall): void {
contract.loserMultiplier = governor.loserMultiplier();
contract.lastApprovalTime = governor.lastApprovalTime();
contract.metaEvidenceUpdates = governor.metaEvidenceUpdates();
contract.metaEvidence = contract.metaEvidenceUpdates.toHexString();
contract.save();

return contract as Contract;
}

export function setMetaEvidence(call: SetMetaEvidenceCall): void {
let contract = initializeContract(call.to, call.from);

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

contract.metaEvidence = metaEvidence.id;
contract.save();
}

export function changeSubmissionDeposit(
call: ChangeSubmissionDepositCall
): void {
let contract = initializeContract(call.to, call.from);
contract.submissionBaseDeposit = call.inputs._submissionBaseDeposit;
contract.save();
}

export function changeSubmissionTimeout(
call: ChangeSubmissionTimeoutCall
): void {
let contract = initializeContract(call.to, call.from);
contract.submissionTimeout = call.inputs._submissionTimeout;
contract.save();
}

export function changeExecutionTimeout(call: ChangeExecutionTimeoutCall): void {
let contract = initializeContract(call.to, call.from);
contract.executionTimeout = call.inputs._executionTimeout;
contract.save();
}

export function changeWithdrawTimeout(call: ChangeWithdrawTimeoutCall): void {
let contract = initializeContract(call.to, call.from);
contract.withdrawTimeout = call.inputs._withdrawTimeout;
contract.save();
}

export function changeSharedMultiplier(call: ChangeSharedMultiplierCall): void {
let contract = initializeContract(call.to, call.from);
contract.sharedMultiplier = call.inputs._sharedMultiplier;
contract.save();
}

export function changeWinnerMultiplier(call: ChangeWinnerMultiplierCall): void {
let contract = initializeContract(call.to, call.from);
contract.winnerMultiplier = call.inputs._winnerMultiplier;
contract.save();
}

export function changeLoserMultiplier(call: ChangeLoserMultiplierCall): void {
let contract = initializeContract(call.to, call.from);
contract.loserMultiplier = call.inputs._loserMultiplier;
contract.save();
}

export function changeArbitrator(call: ChangeArbitratorCall): void {
let contract = initializeContract(call.to, call.from);
contract.arbitrator = call.inputs._arbitrator;
contract.arbitratorExtraData = call.inputs._arbitratorExtraData;
contract.save();
}

export function changeMetaEvidence(call: ChangeMetaEvidenceCall): void {
let contract = initializeContract(call.to, call.from);

let metaEvidence = new MetaEvidence(
contract.metaEvidenceUpdates.toHexString()
Expand Down
18 changes: 18 additions & 0 deletions subgraph/subgraph.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,22 @@ dataSources:
callHandlers:
- function: setMetaEvidence(string)
handler: setMetaEvidence
- function: changeSubmissionDeposit(uint256)
handler: changeSubmissionDeposit
- function: changeSubmissionTimeout(uint256)
handler: changeSubmissionTimeout
- function: changeExecutionTimeout(uint256)
handler: changeExecutionTimeout
- function: changeWithdrawTimeout(uint256)
handler: changeWithdrawTimeout
- function: changeSharedMultiplier(uint256)
handler: changeSharedMultiplier
- function: changeWinnerMultiplier(uint256)
handler: changeWinnerMultiplier
- function: changeLoserMultiplier(uint256)
handler: changeLoserMultiplier
- function: changeArbitrator(address,bytes)
handler: changeArbitrator
- function: changeMetaEvidence(string)
handler: changeMetaEvidence
file: ./src/mapping.ts

0 comments on commit 360d007

Please sign in to comment.