Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 49 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,29 @@ $ yarn local-stack
$ yarn workspace @kleros/kleros-v2-contracts start-local
...
Started HTTP and WebSocket JSON-RPC server at http://127.0.0.1:8545/

```

⏳ Wait until deployment is complete.

##### In a new terminal run:

```bash
$ yarn workspace @kleros/kleros-v2-contracts populate:local
```

This will populate the courts local by pulling devnet courts.

> Note: Whenever contracts are redeployed or their ABIs change, you must regenerate
> the typed wagmi/viem contract bindings used by the frontend.
>
> ```bash
> yarn workspace @kleros/kleros-v2-contracts viem:generate-hardhat
> ```

#### Shell 2 - Local Graph Node

> Requires Docker desktop to be installed and running

```bash
$ yarn workspace @kleros/kleros-v2-subgraph start-local-indexer
...
Expand Down Expand Up @@ -140,16 +156,20 @@ Queries (HTTP): http://localhost:8000/subgraphs/name/kleros/kleros-v2-core-l

#### Shell 4 - Frontend Pointing to the Local Subgraph

> Note: If not already built, or on any change, build `kleros-app` first.
>
> ```bash
> yarn workspace @kleros/kleros-app build
> ```

```bash
yarn workspace @kleros/kleros-v2-web generate
$ yarn workspace @kleros/kleros-v2-web start-local
✔ Parse Configuration
✔ Generate outputs
✔ Validating plugins
✔ Resolving contracts
✔ Running plugins
✔ Writing to src/hooks/contracts/generated.ts

$ yarn workspace @kleros/kleros-v2-web start-local
Server running at http://localhost:1234
✨ Built in 2.35s
```
Expand All @@ -160,9 +180,15 @@ Server running at http://localhost:1234
# Contracts
$ yarn workspace @kleros/kleros-v2-contracts deploy-local

# If contracts were updated
$ yarn workspace @kleros/kleros-v2-contracts viem:generate-hardhat

# Subgraph
$ yarn workspace @kleros/kleros-v2-subgraph rebuild-deploy:local

# If contracts were updated, restart web server to regenerate the wagmi hooks
$ yarn workspace @kleros/kleros-v2-web start-local

```

### Simulating Arbitration Activity
Expand All @@ -186,10 +212,28 @@ Just press `Ctrl + c` in each terminal.

Every versions were saved as `subgraph.yaml.bak.<timestamp>`.

##### Based on the ArbitrumGoerli deployment artifacts
##### Based on the ArbitrumSepolia deployment artifacts

`yarn workspace @kleros/kleros-v2-subgraph update`

##### Based on the last commit

`git restore subgraph.yaml`

## Run a local Blockscout explorer to inspect transactions on hardhat (Optional)

Make sure [hardhat node](#####shell-1---local-rpc-with-contracts-deployed) is running.

#### Step 1 - Clone [blockscout](https://github.com/blockscout/blockscout/blob/master/docker-compose/README.md) repo

```bash
git clone https://github.com/blockscout/blockscout.git
```

#### Step 2: Start the Docker compose stack

```bash
docker-compose -f hardhat-network.yml up -d
```

This should run a Blockscout locally at http://localhost.
4 changes: 2 additions & 2 deletions contracts/deploy/00-home-chain-arbitration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { DeployFunction } from "hardhat-deploy/types";
import { getContractAddress } from "./utils/getContractAddress";
import { deployUpgradable } from "./utils/deployUpgradable";
import { changeCurrencyRate } from "./utils/klerosCoreHelper";
import { HomeChains, isSkipped, isDevnet, PNK, ETH, Courts } from "./utils";
import { HomeChains, isSkipped, isDevnet, PNK, ETH, Courts, isLocalhost } from "./utils";
import { getContractOrDeploy, getContractOrDeployUpgradable } from "./utils/getContractOrDeploy";
import { deployERC20AndFaucet } from "./utils/deployTokens";
import { DisputeKitClassic, KlerosCore, RNGWithFallback } from "../typechain-types";
Expand Down Expand Up @@ -47,7 +47,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
klerosCoreAddress = getContractAddress(deployer, nonce + 3); // deployed on the 4th tx (nonce+3): SortitionModule Impl tx, SortitionModule Proxy tx, KlerosCore Impl tx, KlerosCore Proxy tx
console.log("calculated future KlerosCore address for nonce %d: %s", nonce + 3, klerosCoreAddress);
}
const devnet = isDevnet(hre.network);
const devnet = isDevnet(hre.network) || isLocalhost(hre.network);
const minStakingTime = devnet ? 180 : 1800;
const maxFreezingTime = devnet ? 600 : 1800;
const rngWithFallback = await ethers.getContract<RNGWithFallback>("RNGWithFallback");
Expand Down
4 changes: 2 additions & 2 deletions contracts/deploy/00-rng-chainlink.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import { HomeChains, isSkipped } from "./utils";
import { HomeChains, isLocalhost, isSkipped } from "./utils";
import { getContractOrDeploy } from "./utils/getContractOrDeploy";
import { RNGWithFallback } from "../typechain-types";

Expand Down Expand Up @@ -76,7 +76,7 @@ const deployRng: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
log: true,
});

const fallbackTimeoutSeconds = 30 * 60; // 30 minutes
const fallbackTimeoutSeconds = isLocalhost(hre.network) ? 10 : 30 * 60; // 30 minutes
await getContractOrDeploy(hre, "RNGWithFallback", {
from: deployer,
args: [
Expand Down
10 changes: 7 additions & 3 deletions contracts/deploy/utils/deployTokens.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Contract } from "ethers";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { getContractOrDeploy } from "./getContractOrDeploy";
import { isMainnet } from ".";
import { isLocalhost, isMainnet } from ".";

export const deployERC20AndFaucet = async (
hre: HardhatRuntimeEnvironment,
Expand All @@ -21,10 +21,14 @@ export const deployERC20 = async (
deployer: string,
ticker: string
): Promise<Contract> => {
// locally the ERC20contract lacks `increaseAllowance` function,
// so we swap it with an updated contract to allow local development
const contractName = ticker === "PNK" && isLocalhost(hre.network) ? "PinakionV2Local" : "TestERC20";
const args = ticker === "PNK" && isLocalhost(hre.network) ? [] : [ticker, ticker];
return await getContractOrDeploy(hre, ticker, {
from: deployer,
contract: "TestERC20",
args: [ticker, ticker],
contract: contractName,
args: args,
log: true,
});
};
Expand Down
2 changes: 2 additions & 0 deletions contracts/deploy/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export enum Courts {

export const isMainnet = (network: Network) => network.tags.production ?? false;
export const isDevnet = (network: Network) => network.name.endsWith("Devnet");
// when deployed while starting node, the network name is "hardhat", the common factor for determining local node is chainId
export const isLocalhost = (network: Network) => network.name === "localhost" || network.config.chainId === 31337;

export const isSkipped = async (network: Network, skip: boolean) => {
if (skip) {
Expand Down
Loading