Skip to content

Commit 61da2b8

Browse files
authored
Merge branch 'dev' into feat/dispute-period-quick-pass
2 parents 481bd7d + e1b8ce2 commit 61da2b8

File tree

13 files changed

+45
-63
lines changed

13 files changed

+45
-63
lines changed

contracts/src/arbitration/KlerosCoreBase.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,7 @@ abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable
11011101
if (_result == StakingResult.StakingTransferFailed) revert StakingTransferFailed();
11021102
if (_result == StakingResult.UnstakingTransferFailed) revert UnstakingTransferFailed();
11031103
if (_result == StakingResult.CannotStakeInMoreCourts) revert StakingInTooManyCourts();
1104-
if (_result == StakingResult.CannotStakeInThisCourt) revert StakingNotPossibeInThisCourt();
1104+
if (_result == StakingResult.CannotStakeInThisCourt) revert StakingNotPossibleInThisCourt();
11051105
if (_result == StakingResult.CannotStakeLessThanMinStake) revert StakingLessThanCourtMinStake();
11061106
if (_result == StakingResult.CannotStakeZeroWhenNoStake) revert StakingZeroWhenNoStake();
11071107
}
@@ -1155,7 +1155,7 @@ abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable
11551155
error WrongDisputeKitIndex();
11561156
error CannotDisableClassicDK();
11571157
error StakingInTooManyCourts();
1158-
error StakingNotPossibeInThisCourt();
1158+
error StakingNotPossibleInThisCourt();
11591159
error StakingLessThanCourtMinStake();
11601160
error StakingTransferFailed();
11611161
error UnstakingTransferFailed();

contracts/src/arbitration/university/KlerosCoreUniversity.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,7 @@ contract KlerosCoreUniversity is IArbitratorV2, UUPSProxiable, Initializable {
10911091
if (_result == StakingResult.StakingTransferFailed) revert StakingTransferFailed();
10921092
if (_result == StakingResult.UnstakingTransferFailed) revert UnstakingTransferFailed();
10931093
if (_result == StakingResult.CannotStakeInMoreCourts) revert StakingInTooManyCourts();
1094-
if (_result == StakingResult.CannotStakeInThisCourt) revert StakingNotPossibeInThisCourt();
1094+
if (_result == StakingResult.CannotStakeInThisCourt) revert StakingNotPossibleInThisCourt();
10951095
if (_result == StakingResult.CannotStakeLessThanMinStake) revert StakingLessThanCourtMinStake();
10961096
}
10971097

@@ -1147,7 +1147,7 @@ contract KlerosCoreUniversity is IArbitratorV2, UUPSProxiable, Initializable {
11471147
error CannotDisableClassicDK();
11481148
error ArraysLengthMismatch();
11491149
error StakingInTooManyCourts();
1150-
error StakingNotPossibeInThisCourt();
1150+
error StakingNotPossibleInThisCourt();
11511151
error StakingLessThanCourtMinStake();
11521152
error StakingTransferFailed();
11531153
error UnstakingTransferFailed();

contracts/test/foundry/KlerosCore.t.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -842,12 +842,12 @@ contract KlerosCoreTest is Test {
842842
vm.prank(governor);
843843
core.unpause();
844844

845-
vm.expectRevert(KlerosCoreBase.StakingNotPossibeInThisCourt.selector);
845+
vm.expectRevert(KlerosCoreBase.StakingNotPossibleInThisCourt.selector);
846846
vm.prank(staker1);
847847
core.setStake(FORKING_COURT, 1000);
848848

849849
uint96 badCourtID = 2;
850-
vm.expectRevert(KlerosCoreBase.StakingNotPossibeInThisCourt.selector);
850+
vm.expectRevert(KlerosCoreBase.StakingNotPossibleInThisCourt.selector);
851851
vm.prank(staker1);
852852
core.setStake(badCourtID, 1000);
853853

subgraph/core/abi-migrations/KlerosCore.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@
152152
},
153153
{
154154
"inputs": [],
155-
"name": "StakingNotPossibeInThisCourt",
155+
"name": "StakingNotPossibleInThisCourt",
156156
"type": "error"
157157
},
158158
{

subgraph/core/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ type Court @entity {
150150
numberVotes: BigInt!
151151
stakedJurors: [JurorTokensPerCourt!]! @derivedFrom(field: "court")
152152
numberStakedJurors: BigInt!
153+
effectiveNumberStakedJurors: BigInt!
153154
stake: BigInt!
154155
effectiveStake: BigInt!
155156
delayedStake: BigInt!

subgraph/core/src/entities/Court.ts

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,15 @@ import { ZERO } from "../utils";
55

66
// This function calculates the "effective" stake, which is the specific stake
77
// of the current court + the specific stake of all of its children courts
8-
export function updateEffectiveStake(courtID: string): void {
8+
export function updateEffectiveStake(courtID: string, delta: BigInt): void {
99
let court = Court.load(courtID);
1010
if (!court) return;
1111

12-
while (court) {
13-
let totalStake = court.stake;
14-
15-
const childrenCourts = court.children.load();
16-
17-
for (let i = 0; i < childrenCourts.length; i++) {
18-
const childCourt = Court.load(childrenCourts[i].id);
19-
if (childCourt) {
20-
totalStake = totalStake.plus(childCourt.effectiveStake);
21-
}
22-
}
23-
24-
court.effectiveStake = totalStake;
25-
court.save();
12+
court.effectiveStake = court.effectiveStake.plus(delta);
13+
court.save();
2614

27-
if (court.parent && court.parent !== null) {
28-
court = Court.load(court.parent as string);
29-
} else {
30-
break;
31-
}
15+
if (court.parent) {
16+
updateEffectiveStake(court.parent as string, delta);
3217
}
3318
}
3419

@@ -48,6 +33,7 @@ export function createCourtFromEvent(event: CourtCreated): void {
4833
court.numberAppealingDisputes = ZERO;
4934
court.numberVotes = ZERO;
5035
court.numberStakedJurors = ZERO;
36+
court.effectiveNumberStakedJurors = ZERO;
5137
court.stake = ZERO;
5238
court.effectiveStake = ZERO;
5339
court.delayedStake = ZERO;

subgraph/core/src/entities/JurorTokensPerCourt.ts

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,34 +32,26 @@ export function createJurorTokensPerCourt(jurorAddress: string, courtID: string)
3232
return jurorTokens;
3333
}
3434

35-
export function updateJurorEffectiveStake(jurorAddress: string, courtID: string): void {
35+
export function updateJurorEffectiveStake(jurorAddress: string, courtID: string, delta: BigInt): void {
3636
let court = Court.load(courtID);
37-
if (!court) {
38-
return;
37+
if (!court) return;
38+
39+
const jurorTokensPerCourt = ensureJurorTokensPerCourt(jurorAddress, court.id);
40+
const previousEffectiveStake = jurorTokensPerCourt.effectiveStake;
41+
const newEffectiveStake = previousEffectiveStake.plus(delta);
42+
43+
if (previousEffectiveStake.equals(ZERO) && newEffectiveStake.gt(ZERO)) {
44+
court.effectiveNumberStakedJurors = court.effectiveNumberStakedJurors.plus(ONE);
45+
} else if (previousEffectiveStake.gt(ZERO) && newEffectiveStake.equals(ZERO)) {
46+
court.effectiveNumberStakedJurors = court.effectiveNumberStakedJurors.minus(ONE);
3947
}
4048

41-
while (court) {
42-
const jurorTokensPerCourt = ensureJurorTokensPerCourt(jurorAddress, court.id);
43-
let totalStake = jurorTokensPerCourt.staked;
44-
const childrenCourts = court.children.load();
45-
46-
for (let i = 0; i < childrenCourts.length; i++) {
47-
const childCourtID = childrenCourts[i].id;
48-
const childCourt = Court.load(childCourtID);
49-
if (childCourt) {
50-
const childJurorTokensPerCourt = ensureJurorTokensPerCourt(jurorAddress, childCourt.id);
51-
totalStake = totalStake.plus(childJurorTokensPerCourt.effectiveStake);
52-
}
53-
}
54-
55-
jurorTokensPerCourt.effectiveStake = totalStake;
56-
jurorTokensPerCourt.save();
57-
58-
if (court.parent && court.parent !== null) {
59-
court = Court.load(court.parent as string);
60-
} else {
61-
break;
62-
}
49+
jurorTokensPerCourt.effectiveStake = newEffectiveStake;
50+
jurorTokensPerCourt.save();
51+
court.save();
52+
53+
if (court.parent) {
54+
updateJurorEffectiveStake(jurorAddress, court.parent as string, delta);
6355
}
6456
}
6557

@@ -92,8 +84,8 @@ export function updateJurorStake(
9284
updateActiveJurors(activeJurorsDelta, timestamp);
9385
juror.save();
9486
court.save();
95-
updateEffectiveStake(courtID);
96-
updateJurorEffectiveStake(jurorAddress, courtID);
87+
updateEffectiveStake(courtID, stakeDelta);
88+
updateJurorEffectiveStake(jurorAddress, courtID, stakeDelta);
9789
updateCourtStateVariable(courtID, court.effectiveStake, timestamp, "effectiveStake");
9890
}
9991

subgraph/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kleros/kleros-v2-subgraph",
3-
"version": "0.15.0",
3+
"version": "0.15.2",
44
"drtVersion": "0.12.0",
55
"license": "MIT",
66
"scripts": {

web/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
### Pre-Requisites
2525

26-
If you haven't already, you need to follow all the previous steps of the **Contributing** section of the repo's [Contribution Guidelines](../CONTRIBUTING.md)
26+
If you haven't already, you need to follow all the previous steps of the **Contributing** section of the repo's [Contribution Guidelines](../CONTRIBUTING.md).
2727

2828
### Getting Started
2929

web/src/hooks/queries/useCourtDetails.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ const courtDetailsQuery = graphql(`
1717
numberClosedDisputes
1818
numberAppealingDisputes
1919
numberStakedJurors
20+
effectiveNumberStakedJurors
2021
numberVotes
2122
stake
23+
effectiveStake
2224
paidETH
2325
paidPNK
2426
timesPerPeriod

0 commit comments

Comments
 (0)