Skip to content

Commit d53f5ff

Browse files
authored
Merge pull request #1323 from kleros/dev
Release
2 parents 928d23b + 0795fbc commit d53f5ff

File tree

114 files changed

+4074
-669
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+4074
-669
lines changed

.github/workflows/deploy-subgraph.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
default: 'arbitrum-goerli'
1010
type: choice
1111
options:
12+
- arbitrum-goerli-devnet
1213
- arbitrum-goerli
1314
- arbitrum
1415
update:

contracts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
"pino-pretty": "^10.0.0",
7676
"shelljs": "^0.8.5",
7777
"solhint-plugin-prettier": "^0.0.5",
78-
"solidity-coverage": "0.8.2",
78+
"solidity-coverage": "0.8.5",
7979
"ts-node": "^10.9.1",
8080
"typechain": "^8.3.1",
8181
"typescript": "^4.9.5"

subgraph/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"update:local": "./scripts/update.sh localhost mainnet",
99
"codegen": "graph codegen",
1010
"build": "graph build",
11+
"test": "graph test",
1112
"clean": "graph clean && rm subgraph.yaml.bak.*",
1213
"deploy:arbitrum-goerli": "graph deploy --product hosted-service kleros/kleros-v2-core-testnet-2",
1314
"deploy:arbitrum-goerli-devnet": "graph deploy --product hosted-service kleros/kleros-v2-core-devnet",
@@ -30,7 +31,8 @@
3031
"@graphprotocol/graph-cli": "0.52.0",
3132
"@kleros/kleros-v2-eslint-config": "workspace:^",
3233
"@kleros/kleros-v2-prettier-config": "workspace:^",
33-
"gluegun": "^5.1.2"
34+
"gluegun": "^5.1.2",
35+
"matchstick-as": "0.6.0-beta.2"
3436
},
3537
"dependenciesComments": {
3638
"@graphprotocol/graph-cli": "pinned because of this issue: https://github.com/graphprotocol/graph-tooling/issues/1399#issuecomment-1676104540"

subgraph/schema.graphql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ interface DisputeKitDispute {
1919
coreDispute: Dispute!
2020
localRounds: [DisputeKitRound!]! @derivedFrom(field: "localDispute")
2121
currentLocalRoundIndex: BigInt!
22+
timestamp: BigInt!
2223
}
2324

2425
interface DisputeKitRound {
@@ -72,6 +73,7 @@ type User @entity {
7273
totalResolvedDisputes: BigInt!
7374
totalDisputes: BigInt!
7475
totalCoherent: BigInt!
76+
coherenceScore: BigInt!
7577
totalAppealingDisputes: BigInt!
7678
votes: [Vote!]! @derivedFrom(field: "juror")
7779
contributions: [Contribution!]! @derivedFrom(field: "contributor")
@@ -236,6 +238,7 @@ type ClassicDispute implements DisputeKitDispute @entity {
236238
coreDispute: Dispute!
237239
localRounds: [DisputeKitRound!]! @derivedFrom(field: "localDispute")
238240
currentLocalRoundIndex: BigInt!
241+
timestamp: BigInt!
239242

240243
numberOfChoices: BigInt!
241244
extraData: Bytes!

subgraph/src/entities/ClassicDispute.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ export function createClassicDisputeFromEvent(event: DisputeCreation): void {
99
classicDispute.currentLocalRoundIndex = ZERO;
1010
classicDispute.numberOfChoices = event.params._numberOfChoices;
1111
classicDispute.extraData = event.params._extraData;
12+
classicDispute.timestamp = event.block.timestamp;
1213
classicDispute.save();
1314
}

subgraph/src/entities/JurorTokensPerCourt.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function updateJurorStake(jurorAddress: string, courtID: string, contract
3838
const jurorBalance = contract.getJurorBalance(Address.fromString(jurorAddress), BigInt.fromString(courtID));
3939
const previousStake = jurorTokens.staked;
4040
const previousTotalStake = juror.totalStake;
41-
jurorTokens.staked = jurorBalance.value0;
41+
jurorTokens.staked = jurorBalance.value2;
4242
jurorTokens.locked = jurorBalance.value1;
4343
jurorTokens.save();
4444
const stakeDelta = getDelta(previousStake, jurorTokens.staked);
@@ -47,7 +47,7 @@ export function updateJurorStake(jurorAddress: string, courtID: string, contract
4747
court.stake = court.stake.plus(stakeDelta);
4848
updateStakedPNK(stakeDelta, timestamp);
4949
const activeJurorsDelta = getActivityDelta(previousTotalStake, newTotalStake);
50-
const stakedJurorsDelta = getActivityDelta(previousStake, jurorBalance.value0);
50+
const stakedJurorsDelta = getActivityDelta(previousStake, jurorBalance.value2);
5151
court.numberStakedJurors = court.numberStakedJurors.plus(stakedJurorsDelta);
5252
updateActiveJurors(activeJurorsDelta, timestamp);
5353
juror.save();

subgraph/src/entities/User.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
1-
import { BigInt } from "@graphprotocol/graph-ts";
1+
import { BigInt, BigDecimal } from "@graphprotocol/graph-ts";
22
import { User } from "../../generated/schema";
33
import { ONE, ZERO } from "../utils";
44

5+
export function computeCoherenceScore(totalCoherent: BigInt, totalResolvedDisputes: BigInt): BigInt {
6+
const smoothingFactor = BigDecimal.fromString("10");
7+
8+
let denominator = totalResolvedDisputes.toBigDecimal().plus(smoothingFactor);
9+
let coherencyRatio = totalCoherent.toBigDecimal().div(denominator);
10+
11+
const coherencyScore = coherencyRatio.times(BigDecimal.fromString("100"));
12+
13+
const roundedScore = coherencyScore.plus(BigDecimal.fromString("0.5"));
14+
15+
return BigInt.fromString(roundedScore.toString().split(".")[0]);
16+
}
17+
518
export function ensureUser(id: string): User {
619
const user = User.load(id);
720

@@ -24,6 +37,7 @@ export function createUserFromAddress(id: string): User {
2437
user.totalAppealingDisputes = ZERO;
2538
user.totalDisputes = ZERO;
2639
user.totalCoherent = ZERO;
40+
user.coherenceScore = ZERO;
2741
user.save();
2842

2943
return user;
@@ -52,6 +66,7 @@ export function resolveUserDispute(id: string, previousFeeAmount: BigInt, feeAmo
5266
user.totalCoherent = user.totalCoherent.plus(ONE);
5367
}
5468
}
69+
user.coherenceScore = computeCoherenceScore(user.totalCoherent, user.totalResolvedDisputes);
5570
user.save();
5671
return;
5772
}
@@ -61,5 +76,6 @@ export function resolveUserDispute(id: string, previousFeeAmount: BigInt, feeAmo
6176
user.totalCoherent = user.totalCoherent.plus(ONE);
6277
}
6378
user.activeDisputes = user.activeDisputes.minus(ONE);
79+
user.coherenceScore = computeCoherenceScore(user.totalCoherent, user.totalResolvedDisputes);
6480
user.save();
6581
}

subgraph/tests/user.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { assert, test, describe } from "matchstick-as/assembly/index";
2+
import { BigInt } from "@graphprotocol/graph-ts";
3+
import { computeCoherenceScore } from "../src/entities/User";
4+
5+
describe("Compute coherence score", () => {
6+
test("Slam BigInts together", () => {
7+
assert.bigIntEquals(BigInt.fromI32(8), computeCoherenceScore(BigInt.fromI32(1), BigInt.fromI32(2)));
8+
});
9+
});
-46.4 KB
Loading
-48.5 KB
Loading

0 commit comments

Comments
 (0)