Skip to content

Commit

Permalink
Merge branch 'dev' into fix(web)/styling-feedback-plinio
Browse files Browse the repository at this point in the history
  • Loading branch information
kemuru committed Oct 10, 2023
2 parents 1cdb391 + 788a48b commit 5d2d3a9
Show file tree
Hide file tree
Showing 74 changed files with 2,479 additions and 1,062 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:

steps:
- name: Harden Runner
uses: step-security/harden-runner@128a63446a954579617e875aaab7d2978154e969 # v2.4.0
uses: step-security/harden-runner@1b05615854632b887b69ae1be8cbefe72d3ae423 # v2.6.0
with:
egress-policy: audit

Expand All @@ -47,7 +47,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@29b1f65c5e92e24fe6b6647da1eaabe529cec70f # v2.3.3
uses: github/codeql-action/init@2cb752a87e96af96708ab57187ab6372ee1973ab # v2.22.0
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -61,7 +61,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@29b1f65c5e92e24fe6b6647da1eaabe529cec70f # v2.3.3
uses: github/codeql-action/autobuild@2cb752a87e96af96708ab57187ab6372ee1973ab # v2.22.0

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
Expand All @@ -74,6 +74,6 @@ jobs:
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@29b1f65c5e92e24fe6b6647da1eaabe529cec70f # v2.3.3
uses: github/codeql-action/analyze@2cb752a87e96af96708ab57187ab6372ee1973ab # v2.22.0
with:
category: "/language:${{matrix.language}}"
4 changes: 2 additions & 2 deletions .github/workflows/contracts-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@8ca2b8b2ece13480cda6dacd3511b49857a23c09 # v2.5.0
uses: step-security/harden-runner@1b05615854632b887b69ae1be8cbefe72d3ae423 # v2.5.0
with:
disable-sudo: true
egress-policy: block
Expand All @@ -47,7 +47,7 @@ jobs:
- uses: actions/checkout@7739b9ba2efcda9dde65ad1e3c2dbe65b41dfba7

- name: Cache node modules
uses: actions/cache@f7ebb81a3f195b4fb88dab7c14e2f7aff52045aa
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84
env:
cache-name: cache-node-modules
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dependabot-automerge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

steps:
- name: Harden Runner
uses: step-security/harden-runner@8ca2b8b2ece13480cda6dacd3511b49857a23c09 # v2.5.0
uses: step-security/harden-runner@1b05615854632b887b69ae1be8cbefe72d3ae423 # v2.5.0
with:
disable-sudo: true
egress-policy: block
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@8ca2b8b2ece13480cda6dacd3511b49857a23c09 # v2.5.1
uses: step-security/harden-runner@1b05615854632b887b69ae1be8cbefe72d3ae423 # v2.6.0
with:
disable-sudo: true
egress-policy: block
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/deploy-bots.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@8ca2b8b2ece13480cda6dacd3511b49857a23c09
uses: step-security/harden-runner@1b05615854632b887b69ae1be8cbefe72d3ae423
with:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- uses: actions/checkout@7739b9ba2efcda9dde65ad1e3c2dbe65b41dfba7
- uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1
- uses: actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236
- uses: aws-actions/setup-sam@12a6719db503425e98edcc798b6779590a450e8f
- uses: aws-actions/configure-aws-credentials@131c7b6fd10c0d7f36e1e49650b241d91ee327b9
- uses: aws-actions/configure-aws-credentials@010d0da01d0b5a38af31e9c3470dbfdabdecca3a
with:
aws-access-key-id: ${{ secrets.STAGING_AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.STAGING_AWS_SECRET_KEY }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deploy-subgraph.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ jobs:
environment: kleros-org-subgraph
steps:
- name: Harden Runner
uses: step-security/harden-runner@8ca2b8b2ece13480cda6dacd3511b49857a23c09 # v2.5.0
uses: step-security/harden-runner@1b05615854632b887b69ae1be8cbefe72d3ae423 # v2.5.0
with:
egress-policy: audit

- name: Checkout code
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3

- name: Set up Node.js
uses: actions/setup-node@7c12f8017d5436eb855f1ed4399f037a36fbd9e8 # v2.5.2
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
with:
node-version: 16

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/scorecards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:

steps:
- name: Harden Runner
uses: step-security/harden-runner@8ca2b8b2ece13480cda6dacd3511b49857a23c09 # v2.5.0
uses: step-security/harden-runner@1b05615854632b887b69ae1be8cbefe72d3ae423 # v2.5.0
with:
disable-sudo: true
egress-policy: block
Expand All @@ -56,7 +56,7 @@ jobs:
persist-credentials: false

- name: "Run analysis"
uses: ossf/scorecard-action@08b4669551908b1024bb425080c797723083c031 # v2.2.0
uses: ossf/scorecard-action@483ef80eb98fb506c348f7d62e28055e49fe2398 # v2.3.0
with:
results_file: results.sarif
results_format: sarif
Expand Down Expand Up @@ -86,6 +86,6 @@ jobs:

# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@a09933a12a80f87b87005513f0abb1494c27a716 # v2.21.4
uses: github/codeql-action/upload-sarif@2cb752a87e96af96708ab57187ab6372ee1973ab # v2.22.0
with:
sarif_file: results.sarif
4 changes: 2 additions & 2 deletions .github/workflows/sentry-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
version: ${{ steps.set-version.outputs.version }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@8ca2b8b2ece13480cda6dacd3511b49857a23c09 # v2.5.0
uses: step-security/harden-runner@1b05615854632b887b69ae1be8cbefe72d3ae423 # v2.5.0
with:
disable-sudo: true
egress-policy: block
Expand All @@ -32,7 +32,7 @@ jobs:
- uses: actions/checkout@7739b9ba2efcda9dde65ad1e3c2dbe65b41dfba7

- name: Cache node modules
uses: actions/cache@f7ebb81a3f195b4fb88dab7c14e2f7aff52045aa
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84
env:
cache-name: cache-node-modules
with:
Expand Down
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@
"typescript.tsdk": "node_modules/typescript/lib",
"eslint.packageManager": "yarn",
"prettier.useEditorConfig": true,
"prettier.configPath": "prettier-config/.prettierrc.js"
"prettier.configPath": "prettier-config/.prettierrc.js",
"sonarlint.connectedMode.project": {
"connectionId": "kleros",
"projectKey": "kleros_kleros-v2"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"yarn": "3.3.1"
},
"devDependencies": {
"@commitlint/cli": "^17.6.5",
"@commitlint/cli": "^17.7.2",
"@commitlint/config-conventional": "^17.6.7",
"buffer": "^5.5.0",
"conventional-changelog-cli": "^2.2.2",
Expand Down
11 changes: 10 additions & 1 deletion subgraph/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type User @entity {
totalResolvedDisputes: BigInt!
totalDisputes: BigInt!
totalCoherent: BigInt!
totalAppealingDisputes: BigInt!
votes: [Vote!]! @derivedFrom(field: "juror")
contributions: [Contribution!]! @derivedFrom(field: "contributor")
evidences: [Evidence!]! @derivedFrom(field: "sender")
Expand Down Expand Up @@ -128,6 +129,9 @@ type Court @entity {
supportedDisputeKits: [DisputeKit!]!
disputes: [Dispute!]! @derivedFrom(field: "court")
numberDisputes: BigInt!
numberClosedDisputes: BigInt!
numberVotingDisputes: BigInt!
numberAppealingDisputes: BigInt!
stakedJurors: [JurorTokensPerCourt!]! @derivedFrom(field: "court")
numberStakedJurors: BigInt!
stake: BigInt!
Expand All @@ -146,9 +150,12 @@ type Dispute @entity {
tied: Boolean!
overridden: Boolean!
lastPeriodChange: BigInt!
lastPeriodChangeBlockNumber: BigInt!
periodDeadline: BigInt!
rounds: [Round!]! @derivedFrom(field: "dispute")
currentRound: Round!
currentRoundIndex: BigInt!
jurors: [User!]! @derivedFrom(field: "disputes")
shifts: [TokenAndETHShift!]! @derivedFrom(field: "dispute")
disputeKitDispute: DisputeKitDispute @derivedFrom(field: "coreDispute")
}
Expand All @@ -166,8 +173,9 @@ type Round @entity {
feeToken: FeeToken
}

type Draw @entity {
type Draw @entity(immutable: true) {
id: ID! # dispute.id-currentRound-voteID
blockNumber: BigInt!
dispute: Dispute!
round: Round!
juror: User!
Expand Down Expand Up @@ -195,6 +203,7 @@ type Counter @entity {
cases: BigInt!
casesVoting: BigInt!
casesRuled: BigInt!
casesAppealing: BigInt!
}

type FeeToken @entity {
Expand Down
57 changes: 46 additions & 11 deletions subgraph/src/KlerosCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ import {
AcceptedFeeToken,
} from "../generated/KlerosCore/KlerosCore";
import { ZERO, ONE } from "./utils";
import { createCourtFromEvent, getFeeForJuror } from "./entities/Court";
import { createCourtFromEvent } from "./entities/Court";
import { createDisputeKitFromEvent, filterSupportedDisputeKits } from "./entities/DisputeKit";
import { createDisputeFromEvent } from "./entities/Dispute";
import { createRoundFromRoundInfo } from "./entities/Round";
import { updateCases, updateCasesRuled, updateCasesVoting } from "./datapoint";
import { updateCases, updateCasesAppealing, updateCasesRuled, updateCasesVoting } from "./datapoint";
import { addUserActiveDispute, ensureUser } from "./entities/User";
import { updateJurorDelayedStake, updateJurorStake } from "./entities/JurorTokensPerCourt";
import { createDrawFromEvent } from "./entities/Draw";
import { updateTokenAndEthShiftFromEvent } from "./entities/TokenAndEthShift";
import { updateArbitrableCases } from "./entities/Arbitrable";
import { Court, Dispute, FeeToken } from "../generated/schema";
import { Court, Dispute, User } from "../generated/schema";
import { BigInt } from "@graphprotocol/graph-ts";
import { updatePenalty } from "./entities/Penalty";
import { ensureFeeToken } from "./entities/FeeToken";
Expand Down Expand Up @@ -87,31 +87,67 @@ export function handleNewPeriod(event: NewPeriod): void {
const disputeID = event.params._disputeID;
const dispute = Dispute.load(disputeID.toString());
if (!dispute) return;
const newPeriod = getPeriodName(event.params._period);
if (dispute.period === "vote") {
const court = Court.load(dispute.court);
if (!court) return;

if (dispute.period.includes("vote")) {
court.numberVotingDisputes = court.numberVotingDisputes.minus(ONE);
updateCasesVoting(BigInt.fromI32(-1), event.block.timestamp);
} else if (newPeriod === "vote") {
} else if (dispute.period.includes("appeal")) {
let juror: User;
for (let i = 0; i < dispute.jurors.entries.length; i++) {
juror = ensureUser(dispute.jurors.entries[i].value.toString());
juror.totalAppealingDisputes = juror.totalAppealingDisputes.minus(ONE);
juror.save();
}
court.numberAppealingDisputes = court.numberAppealingDisputes.minus(ONE);
updateCasesAppealing(BigInt.fromI32(-1), event.block.timestamp);
}

const newPeriod = getPeriodName(event.params._period);
if (newPeriod === "vote") {
court.numberVotingDisputes = court.numberVotingDisputes.plus(ONE);
updateCasesVoting(ONE, event.block.timestamp);
} else if (newPeriod === "appeal") {
let juror: User;
for (let i = 0; i < dispute.jurors.entries.length; i++) {
juror = ensureUser(dispute.jurors.entries[i].value.toString());
juror.totalAppealingDisputes = juror.totalAppealingDisputes.plus(ONE);
juror.save();
}
court.numberAppealingDisputes = court.numberAppealingDisputes.plus(ONE);
updateCasesAppealing(ONE, event.block.timestamp);
} else if (newPeriod === "execution") {
const contract = KlerosCore.bind(event.address);
const currentRulingInfo = contract.currentRuling(disputeID);
dispute.currentRuling = currentRulingInfo.getRuling();
dispute.overridden = currentRulingInfo.getOverridden();
dispute.tied = currentRulingInfo.getTied();
dispute.save();
}

dispute.period = newPeriod;
dispute.lastPeriodChange = event.block.timestamp;
dispute.lastPeriodChangeBlockNumber = event.block.number;
if (newPeriod !== "execution") {
dispute.periodDeadline = event.block.timestamp.plus(court.timesPerPeriod[event.params._period]);
} else {
dispute.periodDeadline = BigInt.fromU64(U64.MAX_VALUE);
}
dispute.save();
court.save();
}

export function handleRuling(event: Ruling): void {
const disputeID = event.params._disputeID.toString();
const dispute = Dispute.load(disputeID);
updateCasesRuled(ONE, event.block.timestamp);
const disputeID = event.params._disputeID;
const dispute = Dispute.load(disputeID.toString());
if (!dispute) return;
dispute.ruled = true;
dispute.save();
updateCasesRuled(ONE, event.block.timestamp);
const court = Court.load(dispute.court);
if (!court) return;
court.numberClosedDisputes = court.numberClosedDisputes.plus(ONE);
court.save();
}

export function handleAppealDecision(event: AppealDecision): void {
Expand All @@ -124,7 +160,6 @@ export function handleAppealDecision(event: AppealDecision): void {
dispute.currentRoundIndex = newRoundIndex;
dispute.currentRound = roundID;
dispute.save();
const feeForJuror = getFeeForJuror(dispute.court);
const roundInfo = contract.getRoundInfo(disputeID, newRoundIndex);
createRoundFromRoundInfo(disputeID, newRoundIndex, roundInfo);
}
Expand Down
16 changes: 15 additions & 1 deletion subgraph/src/datapoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ export function getDelta(previousValue: BigInt, newValue: BigInt): BigInt {
return newValue.minus(previousValue);
}

const VARIABLES = ["stakedPNK", "redistributedPNK", "paidETH", "activeJurors", "cases", "casesVoting", "casesRuled"];
const VARIABLES = [
"stakedPNK",
"redistributedPNK",
"paidETH",
"activeJurors",
"cases",
"casesVoting",
"casesRuled",
"casesAppealing",
];

function updateDataPoint(delta: BigInt, timestamp: BigInt, variable: string): void {
checkFirstDayActivity();
Expand All @@ -33,6 +42,7 @@ function checkFirstDayActivity(): void {
counter.cases = ZERO;
counter.casesVoting = ZERO;
counter.casesRuled = ZERO;
counter.casesAppealing = ZERO;
counter.save();
}
}
Expand Down Expand Up @@ -72,3 +82,7 @@ export function updateCasesVoting(delta: BigInt, timestamp: BigInt): void {
export function updateCasesRuled(delta: BigInt, timestamp: BigInt): void {
updateDataPoint(delta, timestamp, "casesRuled");
}

export function updateCasesAppealing(delta: BigInt, timestamp: BigInt): void {
updateDataPoint(delta, timestamp, "casesAppealing");
}
3 changes: 3 additions & 0 deletions subgraph/src/entities/Court.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export function createCourtFromEvent(event: CourtCreated): void {
court.timesPerPeriod = event.params._timesPerPeriod;
court.supportedDisputeKits = event.params._supportedDisputeKits.map<string>((value) => value.toString());
court.numberDisputes = ZERO;
court.numberClosedDisputes = ZERO;
court.numberVotingDisputes = ZERO;
court.numberAppealingDisputes = ZERO;
court.numberStakedJurors = ZERO;
court.stake = ZERO;
court.delayedStake = ZERO;
Expand Down
9 changes: 7 additions & 2 deletions subgraph/src/entities/Dispute.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
import { KlerosCore, DisputeCreation } from "../../generated/KlerosCore/KlerosCore";
import { Dispute } from "../../generated/schema";
import { Court, Dispute } from "../../generated/schema";
import { ZERO } from "../utils";

export function createDisputeFromEvent(event: DisputeCreation): void {
const contract = KlerosCore.bind(event.address);
const disputeID = event.params._disputeID;
const disputeContractState = contract.disputes(disputeID);
const dispute = new Dispute(disputeID.toString());
dispute.court = disputeContractState.value0.toString();
const courtID = disputeContractState.value0.toString();
dispute.court = courtID;
dispute.arbitrated = event.params._arbitrable.toHexString();
dispute.period = "evidence";
dispute.ruled = false;
dispute.currentRuling = ZERO;
dispute.tied = true;
dispute.overridden = false;
dispute.lastPeriodChange = event.block.timestamp;
dispute.lastPeriodChangeBlockNumber = event.block.number;
const court = Court.load(courtID);
if (!court) return;
dispute.periodDeadline = event.block.timestamp.plus(court.timesPerPeriod[0]);
dispute.currentRoundIndex = ZERO;
const roundID = `${disputeID.toString()}-${ZERO.toString()}`;
dispute.currentRound = roundID;
Expand Down
Loading

0 comments on commit 5d2d3a9

Please sign in to comment.