Skip to content

Commit

Permalink
Merge pull request #1323 from kleros/dev
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
jaybuidl authored Nov 29, 2023
2 parents 928d23b + 0795fbc commit d53f5ff
Show file tree
Hide file tree
Showing 114 changed files with 4,074 additions and 669 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deploy-subgraph.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
default: 'arbitrum-goerli'
type: choice
options:
- arbitrum-goerli-devnet
- arbitrum-goerli
- arbitrum
update:
Expand Down
2 changes: 1 addition & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"pino-pretty": "^10.0.0",
"shelljs": "^0.8.5",
"solhint-plugin-prettier": "^0.0.5",
"solidity-coverage": "0.8.2",
"solidity-coverage": "0.8.5",
"ts-node": "^10.9.1",
"typechain": "^8.3.1",
"typescript": "^4.9.5"
Expand Down
4 changes: 3 additions & 1 deletion subgraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"update:local": "./scripts/update.sh localhost mainnet",
"codegen": "graph codegen",
"build": "graph build",
"test": "graph test",
"clean": "graph clean && rm subgraph.yaml.bak.*",
"deploy:arbitrum-goerli": "graph deploy --product hosted-service kleros/kleros-v2-core-testnet-2",
"deploy:arbitrum-goerli-devnet": "graph deploy --product hosted-service kleros/kleros-v2-core-devnet",
Expand All @@ -30,7 +31,8 @@
"@graphprotocol/graph-cli": "0.52.0",
"@kleros/kleros-v2-eslint-config": "workspace:^",
"@kleros/kleros-v2-prettier-config": "workspace:^",
"gluegun": "^5.1.2"
"gluegun": "^5.1.2",
"matchstick-as": "0.6.0-beta.2"
},
"dependenciesComments": {
"@graphprotocol/graph-cli": "pinned because of this issue: https://github.com/graphprotocol/graph-tooling/issues/1399#issuecomment-1676104540"
Expand Down
3 changes: 3 additions & 0 deletions subgraph/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface DisputeKitDispute {
coreDispute: Dispute!
localRounds: [DisputeKitRound!]! @derivedFrom(field: "localDispute")
currentLocalRoundIndex: BigInt!
timestamp: BigInt!
}

interface DisputeKitRound {
Expand Down Expand Up @@ -72,6 +73,7 @@ type User @entity {
totalResolvedDisputes: BigInt!
totalDisputes: BigInt!
totalCoherent: BigInt!
coherenceScore: BigInt!
totalAppealingDisputes: BigInt!
votes: [Vote!]! @derivedFrom(field: "juror")
contributions: [Contribution!]! @derivedFrom(field: "contributor")
Expand Down Expand Up @@ -236,6 +238,7 @@ type ClassicDispute implements DisputeKitDispute @entity {
coreDispute: Dispute!
localRounds: [DisputeKitRound!]! @derivedFrom(field: "localDispute")
currentLocalRoundIndex: BigInt!
timestamp: BigInt!

numberOfChoices: BigInt!
extraData: Bytes!
Expand Down
1 change: 1 addition & 0 deletions subgraph/src/entities/ClassicDispute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ export function createClassicDisputeFromEvent(event: DisputeCreation): void {
classicDispute.currentLocalRoundIndex = ZERO;
classicDispute.numberOfChoices = event.params._numberOfChoices;
classicDispute.extraData = event.params._extraData;
classicDispute.timestamp = event.block.timestamp;
classicDispute.save();
}
4 changes: 2 additions & 2 deletions subgraph/src/entities/JurorTokensPerCourt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function updateJurorStake(jurorAddress: string, courtID: string, contract
const jurorBalance = contract.getJurorBalance(Address.fromString(jurorAddress), BigInt.fromString(courtID));
const previousStake = jurorTokens.staked;
const previousTotalStake = juror.totalStake;
jurorTokens.staked = jurorBalance.value0;
jurorTokens.staked = jurorBalance.value2;
jurorTokens.locked = jurorBalance.value1;
jurorTokens.save();
const stakeDelta = getDelta(previousStake, jurorTokens.staked);
Expand All @@ -47,7 +47,7 @@ export function updateJurorStake(jurorAddress: string, courtID: string, contract
court.stake = court.stake.plus(stakeDelta);
updateStakedPNK(stakeDelta, timestamp);
const activeJurorsDelta = getActivityDelta(previousTotalStake, newTotalStake);
const stakedJurorsDelta = getActivityDelta(previousStake, jurorBalance.value0);
const stakedJurorsDelta = getActivityDelta(previousStake, jurorBalance.value2);
court.numberStakedJurors = court.numberStakedJurors.plus(stakedJurorsDelta);
updateActiveJurors(activeJurorsDelta, timestamp);
juror.save();
Expand Down
18 changes: 17 additions & 1 deletion subgraph/src/entities/User.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import { BigInt } from "@graphprotocol/graph-ts";
import { BigInt, BigDecimal } from "@graphprotocol/graph-ts";
import { User } from "../../generated/schema";
import { ONE, ZERO } from "../utils";

export function computeCoherenceScore(totalCoherent: BigInt, totalResolvedDisputes: BigInt): BigInt {
const smoothingFactor = BigDecimal.fromString("10");

let denominator = totalResolvedDisputes.toBigDecimal().plus(smoothingFactor);
let coherencyRatio = totalCoherent.toBigDecimal().div(denominator);

const coherencyScore = coherencyRatio.times(BigDecimal.fromString("100"));

const roundedScore = coherencyScore.plus(BigDecimal.fromString("0.5"));

return BigInt.fromString(roundedScore.toString().split(".")[0]);
}

export function ensureUser(id: string): User {
const user = User.load(id);

Expand All @@ -24,6 +37,7 @@ export function createUserFromAddress(id: string): User {
user.totalAppealingDisputes = ZERO;
user.totalDisputes = ZERO;
user.totalCoherent = ZERO;
user.coherenceScore = ZERO;
user.save();

return user;
Expand Down Expand Up @@ -52,6 +66,7 @@ export function resolveUserDispute(id: string, previousFeeAmount: BigInt, feeAmo
user.totalCoherent = user.totalCoherent.plus(ONE);
}
}
user.coherenceScore = computeCoherenceScore(user.totalCoherent, user.totalResolvedDisputes);
user.save();
return;
}
Expand All @@ -61,5 +76,6 @@ export function resolveUserDispute(id: string, previousFeeAmount: BigInt, feeAmo
user.totalCoherent = user.totalCoherent.plus(ONE);
}
user.activeDisputes = user.activeDisputes.minus(ONE);
user.coherenceScore = computeCoherenceScore(user.totalCoherent, user.totalResolvedDisputes);
user.save();
}
9 changes: 9 additions & 0 deletions subgraph/tests/user.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { assert, test, describe } from "matchstick-as/assembly/index";
import { BigInt } from "@graphprotocol/graph-ts";
import { computeCoherenceScore } from "../src/entities/User";

describe("Compute coherence score", () => {
test("Slam BigInts together", () => {
assert.bigIntEquals(BigInt.fromI32(8), computeCoherenceScore(BigInt.fromI32(1), BigInt.fromI32(2)));
});
});
Binary file modified web/src/assets/pngs/dashboard/aristoteles.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified web/src/assets/pngs/dashboard/diogenes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified web/src/assets/pngs/dashboard/plato.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified web/src/assets/pngs/dashboard/pythagoras.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified web/src/assets/pngs/dashboard/socrates.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions web/src/assets/svgs/menu-icons/help.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit d53f5ff

Please sign in to comment.