Skip to content

Commit a168713

Browse files
committed
Merge branch 'dev' into feat/web/dashboard/dynamic-total-pages
2 parents 9679d2a + 7016cc7 commit a168713

File tree

27 files changed

+770
-278
lines changed

27 files changed

+770
-278
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/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+
});

web/src/components/ConnectWallet/AccountDisplay.tsx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,15 @@ const StyledAvatar = styled.img<{ size: `${number}` }>`
9696
height: ${({ size }) => size + "px"};
9797
`;
9898

99-
export const IdenticonOrAvatar: React.FC<{ size: `${number}` }> = ({ size } = { size: "16" }) => {
100-
const { address } = useAccount();
99+
interface IIdenticonOrAvatar {
100+
size?: `${number}`;
101+
address?: `0x${string}`;
102+
}
103+
104+
export const IdenticonOrAvatar: React.FC<IIdenticonOrAvatar> = ({ size = "16", address: propAddress }) => {
105+
const { address: defaultAddress } = useAccount();
106+
const address = propAddress || defaultAddress;
107+
101108
const { data: name } = useEnsName({
102109
address,
103110
chainId: 1,
@@ -106,19 +113,27 @@ export const IdenticonOrAvatar: React.FC<{ size: `${number}` }> = ({ size } = {
106113
name,
107114
chainId: 1,
108115
});
116+
109117
return avatar ? (
110118
<StyledAvatar src={avatar} alt="avatar" size={size} />
111119
) : (
112120
<StyledIdenticon size={size} string={address} />
113121
);
114122
};
115123

116-
export const AddressOrName: React.FC = () => {
117-
const { address } = useAccount();
124+
interface IAddressOrName {
125+
address?: `0x${string}`;
126+
}
127+
128+
export const AddressOrName: React.FC<IAddressOrName> = ({ address: propAddress }) => {
129+
const { address: defaultAddress } = useAccount();
130+
const address = propAddress || defaultAddress;
131+
118132
const { data } = useEnsName({
119133
address,
120134
chainId: 1,
121135
});
136+
122137
return <label>{data ?? (address && shortenAddress(address))}</label>;
123138
};
124139

web/src/components/Popup/Description/StakeWithdraw.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from "react";
22
import styled from "styled-components";
3-
import { isUndefined } from "utils/index";
3+
import { formatUnits } from "viem";
44
import { useAccount } from "wagmi";
5+
import { isUndefined } from "utils/index";
56
import { useKlerosCoreGetJurorBalance } from "hooks/contracts/generated";
6-
import { format } from "src/pages/Dashboard/Courts/CourtCard";
77
import KlerosLogo from "tsx:svgs/icons/kleros.svg";
88

99
const Container = styled.div`
@@ -88,7 +88,7 @@ const StakeWithdraw: React.FC<IStakeWithdraw> = ({ pnkStaked, courtName, isStake
8888

8989
<TotalStakeContainer>
9090
<StyledKlerosLogo /> <MyStakeContainer>My Stake:</MyStakeContainer>{" "}
91-
<AmountContainer>{`${format(jurorBalance?.[0])} PNK`} </AmountContainer>
91+
<AmountContainer>{`${formatUnits(jurorBalance?.[0] ?? BigInt(0), 18)} PNK`} </AmountContainer>
9292
</TotalStakeContainer>
9393
</Container>
9494
);

web/src/hooks/queries/useClassicAppealQuery.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { graphqlQueryFnHelper } from "utils/graphqlQueryFnHelper";
55
export type { ClassicAppealQuery };
66

77
const classicAppealQuery = graphql(`
8-
query ClassicAppeal($disputeID: ID!) {
8+
query ClassicAppeal($disputeID: ID!, $orderBy: DisputeKitDispute_orderBy, $orderDirection: OrderDirection) {
99
dispute(id: $disputeID) {
1010
period
1111
court {
@@ -16,7 +16,7 @@ const classicAppealQuery = graphql(`
1616
id
1717
}
1818
lastPeriodChange
19-
disputeKitDispute {
19+
disputeKitDispute(orderBy: $orderBy, orderDirection: $orderDirection) {
2020
id
2121
currentLocalRoundIndex
2222
localRounds {
@@ -37,6 +37,13 @@ export const useClassicAppealQuery = (id?: string | number) => {
3737
return useQuery<ClassicAppealQuery>({
3838
queryKey: ["refetchOnBlock", `classicAppealQuery${id}`],
3939
enabled: isEnabled,
40-
queryFn: async () => await graphqlQueryFnHelper(classicAppealQuery, { disputeID: id?.toString() }),
40+
queryFn: async () =>
41+
isEnabled
42+
? await graphqlQueryFnHelper(classicAppealQuery, {
43+
disputeID: id?.toString(),
44+
orderBy: "timestamp",
45+
orderDirection: "asc",
46+
})
47+
: undefined,
4148
});
4249
};

0 commit comments

Comments
 (0)