Skip to content

Commit 87971a6

Browse files
authored
Merge pull request #1744 from kleros/fix/stake-simulator
Fix/stake simulator
2 parents b03eb5a + cac9194 commit 87971a6

11 files changed

+41
-16
lines changed

web/.env.devnet-neo.public

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ export REACT_APP_DEPLOYMENT=devnet
33
export REACT_APP_CORE_SUBGRAPH=https://api.studio.thegraph.com/query/61738/kleros-v2-coreneo-devnet/version/latest
44
export REACT_APP_DRT_ARBSEPOLIA_SUBGRAPH=https://api.studio.thegraph.com/query/61738/kleros-v2-drt-arbisep-devnet/version/latest
55
export REACT_APP_STATUS_URL=https://kleros-v2-devnet.betteruptime.com/badge
6-
export REACT_APP_GENESIS_BLOCK_ARBSEPOLIA=3084598
76
export REACT_APP_DEVTOOLS_URL=https://dev--kleros-v2-neo-devtools.netlify.app
87
export REACT_APP_ARBITRATOR_TYPE=neo
98
export REACT_APP_ATLAS_URI=http://localhost:3000

web/.env.devnet-university.public

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ export REACT_APP_DEPLOYMENT=devnet
33
export REACT_APP_CORE_SUBGRAPH=https://api.studio.thegraph.com/query/61738/kleros-v2-coreuni-devnet/version/latest
44
export REACT_APP_DRT_ARBSEPOLIA_SUBGRAPH=https://api.studio.thegraph.com/query/61738/kleros-v2-drt-arbisep-devnet/version/latest
55
export REACT_APP_STATUS_URL=https://kleros-v2-devnet.betteruptime.com/badge
6-
export REACT_APP_GENESIS_BLOCK_ARBSEPOLIA=3084598
76
export REACT_APP_ARBITRATOR_TYPE=university
87
export REACT_APP_ATLAS_URI=http://localhost:3000
98
export WALLETCONNECT_PROJECT_ID=

web/.env.devnet.public

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ export REACT_APP_DEPLOYMENT=devnet
33
export REACT_APP_CORE_SUBGRAPH=https://api.studio.thegraph.com/query/61738/kleros-v2-core-devnet/version/latest
44
export REACT_APP_DRT_ARBSEPOLIA_SUBGRAPH=https://api.studio.thegraph.com/query/61738/kleros-v2-drt-arbisep-devnet/version/latest
55
export REACT_APP_STATUS_URL=https://kleros-v2-devnet.betteruptime.com/badge
6-
export REACT_APP_GENESIS_BLOCK_ARBSEPOLIA=3084598
76
export REACT_APP_ATLAS_URI=http://localhost:3000
87
export REACT_APP_DEVTOOLS_URL=https://dev--kleros-v2-testnet-devtools.netlify.app
98
export NODE_OPTIONS='--max-old-space-size=7680'

web/.env.mainnet-neo.public

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ export REACT_APP_DEPLOYMENT=mainnet
33
export REACT_APP_CORE_SUBGRAPH=https://api.studio.thegraph.com/query/61738/kleros-v2-coreneo/version/latest
44
export REACT_APP_DRT_ARBMAINNET_SUBGRAPH=https://api.studio.thegraph.com/query/61738/kleros-v2-drt/version/latest
55
export REACT_APP_STATUS_URL=https://kleros-v2-devnet.betteruptime.com/badge
6-
export REACT_APP_GENESIS_BLOCK_ARBMAINNET=190274403
76
export REACT_APP_DEVTOOLS_URL=https://devtools.v2.kleros.builders
87
export REACT_APP_ARBITRATOR_TYPE=neo
98
export REACT_APP_ATLAS_URI=http://localhost:3000

web/.env.testnet.public

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ export REACT_APP_CORE_SUBGRAPH=https://api.studio.thegraph.com/query/61738/klero
44
export REACT_APP_DRT_ARBSEPOLIA_SUBGRAPH=https://api.studio.thegraph.com/query/61738/kleros-v2-drt-arbisep-devnet/version/latest
55
export REACT_APP_STATUS_URL=https://kleros-v2.betteruptime.com/badge
66
export REACT_APP_ATLAS_URI=http://localhost:3000
7-
export REACT_APP_GENESIS_BLOCK_ARBSEPOLIA=3842783
87
export REACT_APP_DEVTOOLS_URL=https://devtools.v2-testnet.kleros.builders
98
export WALLETCONNECT_PROJECT_ID=
109
export ALCHEMY_API_KEY=

web/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
"dependencies": {
7676
"@cyntler/react-doc-viewer": "^1.16.3",
7777
"@kleros/kleros-sdk": "workspace:^",
78+
"@kleros/kleros-v2-contracts": "workspace:^",
7879
"@kleros/ui-components-library": "^2.15.0",
7980
"@lifi/wallet-management": "^3.0.3",
8081
"@lifi/widget": "^3.2.0",

web/src/consts/index.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export const ETH_ADDRESS_REGEX = /^0x[a-fA-F0-9]{40}$/;
2828
export const ETH_SIGNATURE_REGEX = /^0x[a-fA-F0-9]{130}$/;
2929

3030
export const isProductionDeployment = () => import.meta.env.REACT_APP_DEPLOYMENT === "mainnet";
31+
export const isTestnetDeployment = () => import.meta.env.REACT_APP_DEPLOYMENT === "testnet";
3132

3233
export const isKlerosUniversity = () => getArbitratorType() === ArbitratorTypes.university;
3334
export const isKlerosNeo = () => getArbitratorType() === ArbitratorTypes.neo;
@@ -36,10 +37,6 @@ export const getArbitratorType = (): ArbitratorTypes =>
3637

3738
export const getDevToolsUrl = () => import.meta.env.REACT_APP_DEVTOOLS_URL || "https://devtools.v2.kleros.builders";
3839

39-
export const GENESIS_BLOCK_ARBSEPOLIA = BigInt(import.meta.env.REACT_APP_GENESIS_BLOCK_ARBSEPOLIA ?? 0);
40-
export const GENESIS_BLOCK_ARBMAINNET = BigInt(import.meta.env.REACT_APP_GENESIS_BLOCK_ARBMAINNET ?? 0);
41-
export const genesisBlock = () => (isProductionDeployment() ? GENESIS_BLOCK_ARBMAINNET : GENESIS_BLOCK_ARBSEPOLIA);
42-
4340
export const INVALID_DISPUTE_DATA_ERROR = `The dispute data is not valid, please vote "Refuse to arbitrate"`;
4441
export const RPC_ERROR = `RPC Error: Unable to fetch dispute data. Please avoid voting.`;
4542

web/src/consts/processEnvConsts.ts

-4
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ export const isKlerosNeo = () => getArbitratorType() === ArbitratorTypes.neo;
2626
export const getArbitratorType = (): ArbitratorTypes =>
2727
_getArbitratorType(process.env.REACT_APP_ARBITRATOR_TYPE?.toLowerCase());
2828

29-
export const GENESIS_BLOCK_ARBSEPOLIA = BigInt(process.env.REACT_APP_GENESIS_BLOCK_ARBSEPOLIA ?? 0);
30-
export const GENESIS_BLOCK_ARBMAINNET = BigInt(process.env.REACT_APP_GENESIS_BLOCK_ARBMAINNET ?? 0);
31-
export const genesisBlock = () => (isProductionDeployment() ? GENESIS_BLOCK_ARBMAINNET : GENESIS_BLOCK_ARBSEPOLIA);
32-
3329
export const INVALID_DISPUTE_DATA_ERROR = `The dispute data is not valid, please vote "Refuse to arbitrate"`;
3430
export const RPC_ERROR = `RPC Error: Unable to fetch dispute data. Please avoid voting.`;
3531

web/src/hooks/queries/useHomePageBlockQuery.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { isUndefined } from "utils/index";
55

66
import { graphql } from "src/graphql";
77
import { HomePageBlockQuery } from "src/graphql/graphql";
8+
import useGenesisBlock from "../useGenesisBlock";
89
export type { HomePageBlockQuery };
910

1011
const homePageBlockQuery = graphql(`
@@ -58,18 +59,20 @@ export type HomePageBlockStats = {
5859
};
5960

6061
export const useHomePageBlockQuery = (blockNumber: number | undefined, allTime: boolean) => {
61-
const isEnabled = !isUndefined(blockNumber) || allTime;
62+
const genesisBlock = useGenesisBlock();
63+
const isEnabled = !isUndefined(blockNumber) || allTime || !isUndefined(genesisBlock);
6264
const { graphqlBatcher } = useGraphqlBatcher();
6365

6466
return useQuery<HomePageBlockStats>({
6567
queryKey: [`homePageBlockQuery${blockNumber}-${allTime}`],
6668
enabled: isEnabled,
6769
staleTime: Infinity,
6870
queryFn: async () => {
71+
const targetBlock = Math.max(blockNumber!, genesisBlock!);
6972
const data = await graphqlBatcher.fetch({
7073
id: crypto.randomUUID(),
7174
document: homePageBlockQuery,
72-
variables: { blockNumber },
75+
variables: { blockNumber: targetBlock },
7376
});
7477

7578
return processData(data, allTime);

web/src/hooks/useGenesisBlock.ts

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { useEffect, useState } from "react";
2+
import { isKlerosNeo, isKlerosUniversity, isTestnetDeployment } from "~src/consts";
3+
4+
/**
5+
* @returns genesis block for kleros core contract
6+
*/
7+
const useGenesisBlock = () => {
8+
const [genesisBlock, setGenesisBlock] = useState<number>();
9+
useEffect(() => {
10+
if (isKlerosUniversity()) {
11+
import("@kleros/kleros-v2-contracts/deployments/arbitrumSepoliaDevnet/KlerosCoreUniversity.json").then((json) =>
12+
setGenesisBlock(json.receipt.blockNumber)
13+
);
14+
} else if (isKlerosNeo()) {
15+
import("@kleros/kleros-v2-contracts/deployments/arbitrum/KlerosCoreNeo.json").then((json) =>
16+
setGenesisBlock(json.receipt.blockNumber)
17+
);
18+
} else if (isTestnetDeployment()) {
19+
import("@kleros/kleros-v2-contracts/deployments/arbitrumSepolia/KlerosCore.json").then((json) =>
20+
setGenesisBlock(json.receipt.blockNumber)
21+
);
22+
} else {
23+
import("@kleros/kleros-v2-contracts/deployments/arbitrumSepoliaDevnet/KlerosCore.json").then((json) =>
24+
setGenesisBlock(json.receipt.blockNumber)
25+
);
26+
}
27+
}, []);
28+
29+
return genesisBlock;
30+
};
31+
32+
export default useGenesisBlock;

yarn.lock

+2-1
Original file line numberDiff line numberDiff line change
@@ -6553,7 +6553,7 @@ __metadata:
65536553
languageName: unknown
65546554
linkType: soft
65556555

6556-
"@kleros/kleros-v2-contracts@workspace:contracts":
6556+
"@kleros/kleros-v2-contracts@workspace:^, @kleros/kleros-v2-contracts@workspace:contracts":
65576557
version: 0.0.0-use.local
65586558
resolution: "@kleros/kleros-v2-contracts@workspace:contracts"
65596559
dependencies:
@@ -6707,6 +6707,7 @@ __metadata:
67076707
"@graphql-codegen/cli": "npm:^4.0.1"
67086708
"@graphql-codegen/client-preset": "npm:^4.2.0"
67096709
"@kleros/kleros-sdk": "workspace:^"
6710+
"@kleros/kleros-v2-contracts": "workspace:^"
67106711
"@kleros/kleros-v2-eslint-config": "workspace:^"
67116712
"@kleros/kleros-v2-prettier-config": "workspace:^"
67126713
"@kleros/kleros-v2-tsconfig": "workspace:^"

0 commit comments

Comments
 (0)