Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions contracts/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export PRIVATE_KEY=""
export MAINNET_PRIVATE_KEY=""
export INFURA_API_KEY=""
export ETHERSCAN_API_KEY_FIX=""
export ETHERSCAN_API_KEY=""
1 change: 1 addition & 0 deletions contracts/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ tags
# End of https://www.toptal.com/developers/gitignore/api/vim,node,visualstudiocode,yarn

.env*
!.env.example
.flaskenv*
!.env.project
.env.vault
Expand Down
177 changes: 177 additions & 0 deletions contracts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
# @kleros/governor-v2-contracts

Smart contracts for GovernorV2

## Deployments

Refresh the list of deployed contracts by running `./scripts/generateDeploymentsMarkdown.sh` or `./scripts/populateReadme.sh`.

### Official Testnet

#### Arbitrum Sepolia

#### Sepolia

### Devnet

#### Arbitrum Sepolia

- [GovernorFactory](https://sepolia.arbiscan.io/address/0xb98AEdAa01D0e821278d68f2A2A13FbdB2d81A33)
- [KlerosGovernor](https://sepolia.arbiscan.io/address/0x52e6766e6C4fB05Caec92e5318668b3E366D649a)
- [WETH](https://sepolia.arbiscan.io/address/0x3829A2486d53ee984a0ca2D76552715726b77138)

#### Sepolia

## Getting Started

### Install the Dependencies

```bash
yarn install
```

### Run Tests

```bash
yarn test
```

### Compile the Contracts

```bash
yarn build
```

### Run Linter on Files

```bash
yarn lint
```

### Fix Linter Issues on Files

```bash
yarn fix
```

### Deploy Instructions

**NOTICE:** the commands below work only if you are inside the `contracts/` directory.

#### 0. Set the Environment Variables

Copy `.env.example` file as `.env` and edit it accordingly.

```bash
cp .env.example .env
```

The following env vars are required:

- `PRIVATE_KEY`: the private key of the deployer account used for the testnets.
- `MAINNET_PRIVATE_KEY`: the private key of the deployer account used for Mainnet.
- `INFURA_API_KEY`: the API key for infura.

The ones below are optional:

- `ETHERSCAN_API_KEY`: to verify the source of the newly deployed contracts on **Etherscan**.
- `ETHERSCAN_API_KEY_FIX`: to verify the source of the newly deployed contracts on **Etherscan**.

#### 1. Deploy to a Local Network

:warning: There is no mocks deployed for the kleros-v2 contracts currently so this would fail. For now consider deploying to a testnet fork (next section).

**Shell 1: the node**

```bash
yarn hardhat node --tags nothing
```

**Shell 2: the deploy script**

```bash
yarn deploy --network localhost --tags KlerosGovernor
```

#### 2. Deploy to a Public Network Fork

**Shell 1: the node**

```bash
yarn start-devnet-fork
# or
yarn start-testnet-fork
```

**Shell 2: the deploy script**

```bash
yarn deploy-devnet-fork
# or
yarn deploy-testnet-fork
```

#### 3. Deploy to Public Testnets

```bash
yarn deploy --network arbitrumSepolia --tags KlerosGovernor
```

The deployed addresses should be displayed to the screen after the deployment is complete. If you missed them, you can always go to the `deployments/<network>` directory and look for the respective file.

#### 4. Deploy a Devnet on Public Testnets

Same steps as above but append `Devnet` to the `--network` parameter.

#### Running Test Fixtures

**Shell 1: the node**

```bash
yarn hardhat node --tags KlerosGovernor
```

**Shell 2: the test scripts**

```bash
yarn test --network localhost
```

#### 4. Verify the Source Code

This must be done for each network separately.

```bash
# explorer
yarn etherscan-verify --network arbitrumSepolia
yarn etherscan-verify-proxies

# sourcify
yarn sourcify --network arbitrumSepolia

```

## Ad-hoc procedures

### Generate deployment artifacts for existing contracts

#### Usage

```bash
scripts/generateDeploymentArtifact.sh <network> <address>
```

#### Example: WETH on Gnosis chain

```bash
scripts/generateDeploymentArtifact.sh gnosischain 0xf8d1677c8a0c961938bf2f9adc3f3cfda759a9d9 > deployments/gnosischain/WETH.json
```

### Push the contracts to a Tenderly project

Ensure that your `$TENDERLY_PROJECT` and `$TENDERLY_USERNAME` is set correctly in `.env`.

```bash
yarn tenderly-verify --network sepolia
yarn tenderly-verify --network arbitrumSepolia
```
10 changes: 5 additions & 5 deletions contracts/README.md.template
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ The following env vars are required:
The ones below are optional:

- `ETHERSCAN_API_KEY`: to verify the source of the newly deployed contracts on **Etherscan**.
- `ARBISCAN_API_KEY`: to verify the source of the newly deployed contracts on **Arbitrum**.
- `GNOSISSCAN_API_KEY`: to verify the source of the newly deployed contracts on **Gnosis chain**.
- `ETHERSCAN_API_KEY_FIX`: to verify the source of the newly deployed contracts on **Etherscan**.


#### 1. Deploy to a Local Network

Expand All @@ -77,7 +77,7 @@ yarn hardhat node --tags nothing
**Shell 2: the deploy script**

```bash
yarn deploy --network localhost --tags GovernorV2
yarn deploy --network localhost --tags KlerosGovernor
```

#### 2. Deploy to a Public Network Fork
Expand All @@ -101,7 +101,7 @@ yarn deploy-testnet-fork
#### 3. Deploy to Public Testnets

```bash
yarn deploy --network arbitrumSepolia --tags GovernorV2
yarn deploy --network arbitrumSepolia --tags KlerosGovernor
```

The deployed addresses should be displayed to the screen after the deployment is complete. If you missed them, you can always go to the `deployments/<network>` directory and look for the respective file.
Expand All @@ -115,7 +115,7 @@ Same steps as above but append `Devnet` to the `--network` parameter.
**Shell 1: the node**

```bash
yarn hardhat node --tags GovernorV2
yarn hardhat node --tags KlerosGovernor
```

**Shell 2: the test scripts**
Expand Down
36 changes: 22 additions & 14 deletions contracts/deploy/00-governor-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ const extraData =
"0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000003";

const deploy: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { deployments, getNamedAccounts, getChainId, ethers } = hre;
const { deployments, getNamedAccounts, getChainId, ethers, network } = hre;
const { deploy } = deployments;

// fallback to hardhat node signers on local network
const deployer = (await getNamedAccounts()).deployer ?? (await hre.ethers.getSigners())[0].address;
const chainId = Number(await getChainId());
console.log("deploying to %s with deployer %s", HomeChains[chainId], deployer);

const wNative = await ethers.getContract("WETH");

const { disputeTemplateRegistry, klerosCore } = await getArbitratorContracts(hre);
const disputeTemplate = templateFn(klerosCore.target.toString(), chainId);

Expand All @@ -26,7 +28,21 @@ const deploy: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
log: true,
});

const governorFactory = (await ethers.getContract("GovernorFactory")) as GovernorFactory;
const governorFactory = await ethers.getContract<GovernorFactory>("GovernorFactory");

const gfArgs = [
klerosCore.target,
extraData,
disputeTemplateRegistry.target,
disputeTemplate,
dataMappings,
0,
600,
600,
600, // feeTimeout: 10 minutes
wNative.target,
];

await governorFactory.deploy(
klerosCore.target,
extraData,
Expand All @@ -36,22 +52,14 @@ const deploy: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
0,
600,
600,
600 // feeTimeout: 10 minutes
600, // feeTimeout: 10 minutes,
wNative.target
);

const kgArgs = gfArgs;
await deploy("KlerosGovernor", {
from: deployer,
args: [
klerosCore.target,
extraData,
disputeTemplateRegistry.target,
disputeTemplate,
dataMappings,
0,
600,
600,
600, // feeTimeout: 10 minutes
],
args: kgArgs,
log: true,
});
};
Expand Down
19 changes: 17 additions & 2 deletions contracts/deploy/utils/disputeTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
export const templateFn = (arbitratorAddress: string, arbitrableChainID: number) => `{
"$schema": "../NewDisputeTemplate.schema.json",
"title": "Execute a transaction list in Kleros Governor",
"description": "Multiple transaction lists were submitted in Kleros Governor session {{externalDisputeID}}, please vote for which list transaction list should be executed.",
"description": "Multiple transaction lists were submitted in Kleros Governor session {{sessionIndex}}, please vote for which list transaction list should be executed.\\n\\nBelow are the available lists:\\n\\n{{#listIds}}- **List {{.}}** → [View Transactions](https://governor-v2.kleros.builders/governor/{{arbitrableAddress}}?listId={{.}})\\n{{/listIds}}",
"question": "Which transaction list should be executed?",
"answers": [
{{#listIds}}
Expand Down Expand Up @@ -31,13 +31,28 @@ export const templateFn = (arbitratorAddress: string, arbitrableChainID: number)

export const dataMappings = `
[
{
"type": "abi/call",
"abi": "function arbitratorDisputeIDToSessionIndex(uint256) view returns (uint256)",
"address": "{{{arbitrableAddress}}}",
"functionName": "arbitratorDisputeIDToSessionIndex",
"args": [
"{{{arbitratorDisputeID}}}"
],
"seek": [
"value"
],
"populate": [
"sessionIndex"
]
},
{
"type": "abi/call",
"abi": "function getSession(uint256) view returns ((uint256 , uint256 , uint256[] , uint256 , uint8 , uint256 ))",
"address": "{{{arbitrableAddress}}}",
"functionName": "getSession",
"args": [
"{{{externalDisputeID}}}"
"{{{sessionIndex}}}"
],
"seek": [
"2"
Expand Down
2 changes: 1 addition & 1 deletion contracts/deploy/utils/getContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { KlerosGovernor } from "../../typechain-types";
const NETWORK_TO_DEPLOYMENT: Record<string, DeploymentName> = {
arbitrumSepoliaDevnet: "devnet",
arbitrumSepolia: "testnet",
arbitrum: "mainnetNeo",
arbitrum: "mainnet",
} as const;

export const getArbitratorContracts = async (hre: HardhatRuntimeEnvironment) => {
Expand Down
1 change: 1 addition & 0 deletions contracts/deployments/arbitrum/.chainId
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
42161
Loading