Skip to content

Commit

Permalink
Merge pull request #1744 from kleros/fix/stake-simulator
Browse files Browse the repository at this point in the history
Fix/stake simulator
  • Loading branch information
jaybuidl authored Nov 19, 2024
2 parents b03eb5a + cac9194 commit 87971a6
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 16 deletions.
1 change: 0 additions & 1 deletion web/.env.devnet-neo.public
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export REACT_APP_DEPLOYMENT=devnet
export REACT_APP_CORE_SUBGRAPH=https://api.studio.thegraph.com/query/61738/kleros-v2-coreneo-devnet/version/latest
export REACT_APP_DRT_ARBSEPOLIA_SUBGRAPH=https://api.studio.thegraph.com/query/61738/kleros-v2-drt-arbisep-devnet/version/latest
export REACT_APP_STATUS_URL=https://kleros-v2-devnet.betteruptime.com/badge
export REACT_APP_GENESIS_BLOCK_ARBSEPOLIA=3084598
export REACT_APP_DEVTOOLS_URL=https://dev--kleros-v2-neo-devtools.netlify.app
export REACT_APP_ARBITRATOR_TYPE=neo
export REACT_APP_ATLAS_URI=http://localhost:3000
Expand Down
1 change: 0 additions & 1 deletion web/.env.devnet-university.public
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export REACT_APP_DEPLOYMENT=devnet
export REACT_APP_CORE_SUBGRAPH=https://api.studio.thegraph.com/query/61738/kleros-v2-coreuni-devnet/version/latest
export REACT_APP_DRT_ARBSEPOLIA_SUBGRAPH=https://api.studio.thegraph.com/query/61738/kleros-v2-drt-arbisep-devnet/version/latest
export REACT_APP_STATUS_URL=https://kleros-v2-devnet.betteruptime.com/badge
export REACT_APP_GENESIS_BLOCK_ARBSEPOLIA=3084598
export REACT_APP_ARBITRATOR_TYPE=university
export REACT_APP_ATLAS_URI=http://localhost:3000
export WALLETCONNECT_PROJECT_ID=
Expand Down
1 change: 0 additions & 1 deletion web/.env.devnet.public
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export REACT_APP_DEPLOYMENT=devnet
export REACT_APP_CORE_SUBGRAPH=https://api.studio.thegraph.com/query/61738/kleros-v2-core-devnet/version/latest
export REACT_APP_DRT_ARBSEPOLIA_SUBGRAPH=https://api.studio.thegraph.com/query/61738/kleros-v2-drt-arbisep-devnet/version/latest
export REACT_APP_STATUS_URL=https://kleros-v2-devnet.betteruptime.com/badge
export REACT_APP_GENESIS_BLOCK_ARBSEPOLIA=3084598
export REACT_APP_ATLAS_URI=http://localhost:3000
export REACT_APP_DEVTOOLS_URL=https://dev--kleros-v2-testnet-devtools.netlify.app
export NODE_OPTIONS='--max-old-space-size=7680'
Expand Down
1 change: 0 additions & 1 deletion web/.env.mainnet-neo.public
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export REACT_APP_DEPLOYMENT=mainnet
export REACT_APP_CORE_SUBGRAPH=https://api.studio.thegraph.com/query/61738/kleros-v2-coreneo/version/latest
export REACT_APP_DRT_ARBMAINNET_SUBGRAPH=https://api.studio.thegraph.com/query/61738/kleros-v2-drt/version/latest
export REACT_APP_STATUS_URL=https://kleros-v2-devnet.betteruptime.com/badge
export REACT_APP_GENESIS_BLOCK_ARBMAINNET=190274403
export REACT_APP_DEVTOOLS_URL=https://devtools.v2.kleros.builders
export REACT_APP_ARBITRATOR_TYPE=neo
export REACT_APP_ATLAS_URI=http://localhost:3000
Expand Down
1 change: 0 additions & 1 deletion web/.env.testnet.public
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export REACT_APP_CORE_SUBGRAPH=https://api.studio.thegraph.com/query/61738/klero
export REACT_APP_DRT_ARBSEPOLIA_SUBGRAPH=https://api.studio.thegraph.com/query/61738/kleros-v2-drt-arbisep-devnet/version/latest
export REACT_APP_STATUS_URL=https://kleros-v2.betteruptime.com/badge
export REACT_APP_ATLAS_URI=http://localhost:3000
export REACT_APP_GENESIS_BLOCK_ARBSEPOLIA=3842783
export REACT_APP_DEVTOOLS_URL=https://devtools.v2-testnet.kleros.builders
export WALLETCONNECT_PROJECT_ID=
export ALCHEMY_API_KEY=
Expand Down
1 change: 1 addition & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"dependencies": {
"@cyntler/react-doc-viewer": "^1.16.3",
"@kleros/kleros-sdk": "workspace:^",
"@kleros/kleros-v2-contracts": "workspace:^",
"@kleros/ui-components-library": "^2.15.0",
"@lifi/wallet-management": "^3.0.3",
"@lifi/widget": "^3.2.0",
Expand Down
5 changes: 1 addition & 4 deletions web/src/consts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const ETH_ADDRESS_REGEX = /^0x[a-fA-F0-9]{40}$/;
export const ETH_SIGNATURE_REGEX = /^0x[a-fA-F0-9]{130}$/;

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

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

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

export const GENESIS_BLOCK_ARBSEPOLIA = BigInt(import.meta.env.REACT_APP_GENESIS_BLOCK_ARBSEPOLIA ?? 0);
export const GENESIS_BLOCK_ARBMAINNET = BigInt(import.meta.env.REACT_APP_GENESIS_BLOCK_ARBMAINNET ?? 0);
export const genesisBlock = () => (isProductionDeployment() ? GENESIS_BLOCK_ARBMAINNET : GENESIS_BLOCK_ARBSEPOLIA);

export const INVALID_DISPUTE_DATA_ERROR = `The dispute data is not valid, please vote "Refuse to arbitrate"`;
export const RPC_ERROR = `RPC Error: Unable to fetch dispute data. Please avoid voting.`;

Expand Down
4 changes: 0 additions & 4 deletions web/src/consts/processEnvConsts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ export const isKlerosNeo = () => getArbitratorType() === ArbitratorTypes.neo;
export const getArbitratorType = (): ArbitratorTypes =>
_getArbitratorType(process.env.REACT_APP_ARBITRATOR_TYPE?.toLowerCase());

export const GENESIS_BLOCK_ARBSEPOLIA = BigInt(process.env.REACT_APP_GENESIS_BLOCK_ARBSEPOLIA ?? 0);
export const GENESIS_BLOCK_ARBMAINNET = BigInt(process.env.REACT_APP_GENESIS_BLOCK_ARBMAINNET ?? 0);
export const genesisBlock = () => (isProductionDeployment() ? GENESIS_BLOCK_ARBMAINNET : GENESIS_BLOCK_ARBSEPOLIA);

export const INVALID_DISPUTE_DATA_ERROR = `The dispute data is not valid, please vote "Refuse to arbitrate"`;
export const RPC_ERROR = `RPC Error: Unable to fetch dispute data. Please avoid voting.`;

Expand Down
7 changes: 5 additions & 2 deletions web/src/hooks/queries/useHomePageBlockQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { isUndefined } from "utils/index";

import { graphql } from "src/graphql";
import { HomePageBlockQuery } from "src/graphql/graphql";
import useGenesisBlock from "../useGenesisBlock";
export type { HomePageBlockQuery };

const homePageBlockQuery = graphql(`
Expand Down Expand Up @@ -58,18 +59,20 @@ export type HomePageBlockStats = {
};

export const useHomePageBlockQuery = (blockNumber: number | undefined, allTime: boolean) => {
const isEnabled = !isUndefined(blockNumber) || allTime;
const genesisBlock = useGenesisBlock();
const isEnabled = !isUndefined(blockNumber) || allTime || !isUndefined(genesisBlock);
const { graphqlBatcher } = useGraphqlBatcher();

return useQuery<HomePageBlockStats>({
queryKey: [`homePageBlockQuery${blockNumber}-${allTime}`],
enabled: isEnabled,
staleTime: Infinity,
queryFn: async () => {
const targetBlock = Math.max(blockNumber!, genesisBlock!);
const data = await graphqlBatcher.fetch({
id: crypto.randomUUID(),
document: homePageBlockQuery,
variables: { blockNumber },
variables: { blockNumber: targetBlock },
});

return processData(data, allTime);
Expand Down
32 changes: 32 additions & 0 deletions web/src/hooks/useGenesisBlock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { useEffect, useState } from "react";
import { isKlerosNeo, isKlerosUniversity, isTestnetDeployment } from "~src/consts";

/**
* @returns genesis block for kleros core contract
*/
const useGenesisBlock = () => {
const [genesisBlock, setGenesisBlock] = useState<number>();
useEffect(() => {
if (isKlerosUniversity()) {
import("@kleros/kleros-v2-contracts/deployments/arbitrumSepoliaDevnet/KlerosCoreUniversity.json").then((json) =>
setGenesisBlock(json.receipt.blockNumber)
);
} else if (isKlerosNeo()) {
import("@kleros/kleros-v2-contracts/deployments/arbitrum/KlerosCoreNeo.json").then((json) =>
setGenesisBlock(json.receipt.blockNumber)
);
} else if (isTestnetDeployment()) {
import("@kleros/kleros-v2-contracts/deployments/arbitrumSepolia/KlerosCore.json").then((json) =>
setGenesisBlock(json.receipt.blockNumber)
);
} else {
import("@kleros/kleros-v2-contracts/deployments/arbitrumSepoliaDevnet/KlerosCore.json").then((json) =>
setGenesisBlock(json.receipt.blockNumber)
);
}
}, []);

return genesisBlock;
};

export default useGenesisBlock;
3 changes: 2 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6553,7 +6553,7 @@ __metadata:
languageName: unknown
linkType: soft

"@kleros/kleros-v2-contracts@workspace:contracts":
"@kleros/kleros-v2-contracts@workspace:^, @kleros/kleros-v2-contracts@workspace:contracts":
version: 0.0.0-use.local
resolution: "@kleros/kleros-v2-contracts@workspace:contracts"
dependencies:
Expand Down Expand Up @@ -6707,6 +6707,7 @@ __metadata:
"@graphql-codegen/cli": "npm:^4.0.1"
"@graphql-codegen/client-preset": "npm:^4.2.0"
"@kleros/kleros-sdk": "workspace:^"
"@kleros/kleros-v2-contracts": "workspace:^"
"@kleros/kleros-v2-eslint-config": "workspace:^"
"@kleros/kleros-v2-prettier-config": "workspace:^"
"@kleros/kleros-v2-tsconfig": "workspace:^"
Expand Down

0 comments on commit 87971a6

Please sign in to comment.