Skip to content

Dispute fees payable in ERC20 on the home chain #943

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 39 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
00b01f2
refactor: new function on IArbitrator, ForeignGatewayOnGnosis removed…
jaybuidl Jun 15, 2023
5cbb2d0
feat: dispute fees payable in erc20
jaybuidl Jun 15, 2023
ad9f77c
chore: shrank KlerosCore by consolidating some governance functions a…
jaybuidl Jun 20, 2023
5c21d38
fix: missing test contract
jaybuidl Jun 20, 2023
cfaf9f5
fix: added missing token transfers and other small improvements
jaybuidl Jun 22, 2023
78e4a3c
refactor: moved the safe transfer and allowance increase functions to…
jaybuidl Jun 22, 2023
97bafdd
feat: interfaces for the arbitrator, arbitrables and evidence v2
jaybuidl Jan 27, 2023
bdc43e4
docs: examples of metaevidence and dispute templates
jaybuidl Apr 17, 2023
1530844
docs: wip specs
jaybuidl Apr 18, 2023
cff4a41
docs: interfaces docs update
jaybuidl Apr 18, 2023
aca496d
docs: added curate, improved the schema
jaybuidl Apr 18, 2023
4a6ca5d
docs: added poh, removed type to rely on default
jaybuidl Apr 18, 2023
75b2e61
docs: new dispute template schema improvement
jaybuidl Apr 18, 2023
f07a99e
docs: added the datetime type
jaybuidl Apr 19, 2023
76eabb7
feat: interfaces wip
jaybuidl Jun 13, 2023
8072a95
docs: CrossChainDisputeRequest event
jaybuidl Jun 13, 2023
6a18a7a
refactor: example folder
jaybuidl Jun 13, 2023
6089177
fix: natspec
jaybuidl Jun 13, 2023
3f13fec
feat: migrated DisputeResolver
jaybuidl Jun 13, 2023
15b69ee
docs: removed comments
jaybuidl Jun 13, 2023
95a4e9e
feat: deploy scripts improvements
jaybuidl Jun 13, 2023
1eae9fe
feat: resolver migrated and deployed to chiado, interfaces natspec im…
jaybuidl Jun 14, 2023
65c3e0f
fix: forge doc assumes the top-level folder when linking to the githu…
jaybuidl Jun 14, 2023
02a7df5
fix: bsd vs gnu compatibility
jaybuidl Jun 14, 2023
f954c20
docs: minor parameter rename
jaybuidl Jun 14, 2023
b6b563c
refactor: moved crosschain event to the gateway interface
jaybuidl Jun 15, 2023
5bc1ed7
feat: migrated all the interfaces to the new v2 ones)
jaybuidl Jun 19, 2023
c6b7470
feat: added a simple dispute template, moved IMetaEvidence to the v1 …
jaybuidl Jun 19, 2023
73eec68
fix: adding missing files for the dispute resolver
jaybuidl Jun 20, 2023
dede020
fix: manual fixes after rebasing onto feat/erc20-fees-on-arbitrator
jaybuidl Jun 20, 2023
fae3c88
refactor: folder structure
jaybuidl Jun 20, 2023
7a08a37
fix: manual fixes after rebase
jaybuidl Jun 23, 2023
4e81aa6
fix: minor fixes
jaybuidl Jun 23, 2023
e46bffc
Merge branch 'feat/erc20-fees-on-arbitrator' into feat/interfaces-v2-…
jaybuidl Jun 23, 2023
28d492b
Merge branch 'dev' into feat/erc20-fees-on-arbitrator
jaybuidl Jun 23, 2023
1764e67
Merge branch 'feat/erc20-fees-on-arbitrator' into feat/interfaces-v2-…
jaybuidl Jun 23, 2023
5153508
fix: variable in DisputeDetails.simple.jsonc
jaybuidl Jun 23, 2023
ac47dd5
fix: added the arbitrator disputeID to the CrossChainDisputeIncoming …
jaybuidl Jun 23, 2023
eb703cb
chore: redeployed the contracts
jaybuidl Jun 23, 2023
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
20 changes: 10 additions & 10 deletions contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ Smart contracts for Kleros v2

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

### v2-alpha-1

#### Chiado

- [ArbitrableExample](https://blockscout.com/gnosis/chiado/address/0xc0fcc96BFd78e36550FCaB434A9EE1210B57225b)
- [ForeignGatewayOnGnosis](https://blockscout.com/gnosis/chiado/address/0x573bcD6ee4aEe152eCC9Cafd2c0820Dc548AF6cC)
- [ArbitrableExample](https://blockscout.com/gnosis/chiado/address/0x6BC234359c2Bc212B81A5cF2dfE504940e98d4cC)
- [DisputeResolver](https://blockscout.com/gnosis/chiado/address/0x433eD78895df1df7668C40b3e82d54410331F942)
- [ForeignGatewayOnGnosis](https://blockscout.com/gnosis/chiado/address/0x2357ef115E98d171b083105E9b398231206989A3)
- [SortitionSumTreeFactory](https://blockscout.com/gnosis/chiado/address/0xc7e3BF90299f6BD9FA7c3703837A9CAbB5743636)
- [TokenBridge](https://blockscout.com/gnosis/chiado/address/0xbb3c86f9918C3C1d83668fA84e79E876d147fFf2)
- [WETH](https://blockscout.com/gnosis/chiado/address/0x2DFC9c3141268e6eac04a7D6d98Fbf64BDe836a8)
Expand All @@ -23,20 +22,20 @@ Refresh the list of deployed contracts by running `./scripts/generateDeployments
#### Goerli

- [PNK](https://goerli.etherscan.io/token/0xA3B02bA6E10F55fb177637917B1b472da0110CcC)
- [ArbitrableExample](https://goerli.etherscan.io/address/0xd78dcdde2c5a2bd4bb246bc7db6994b95f7c442c)

#### Arbitrum Goerli

- [PNK](https://goerli.arbiscan.io/token/0x4DEeeFD054434bf6721eF39Aa18EfB3fd0D12610/token-transfers)
- [ArbitrableExampleEthFee](https://goerli.arbiscan.io/address/0x1fF31be1924f55804350ADe4945f3B3a6a2e15d2)
- [BlockHashRNG](https://goerli.arbiscan.io/address/0x68eE49dfD9d76f3386257a3D0e0A85c0A5519bBD)
- [DisputeKitClassic](https://goerli.arbiscan.io/address/0xcBE3aD699919Cf59efDF715e4B41AF30A0E4c92d)
- [DisputeResolver](https://goerli.arbiscan.io/address/0x3B4edEFd12a467D1C71506ae2eE88828145202b1)
- [DAI](https://goerli.arbiscan.io/address/0x70A704Dce4cCC00568Cc142C86D07Ec71C944a39)
- [DisputeKitClassic](https://goerli.arbiscan.io/address/0x0245A93ABd9c5b2d767B2D98cE6d5e612208E474)
- [DisputeResolver](https://goerli.arbiscan.io/address/0xcDC05c8d2EEEe384359Bd22E8631528B6b0564e9)
- [HomeGatewayToGnosis](https://goerli.arbiscan.io/address/0xD60CD2151e118Dd796efcb1ceFFcF892226F9b3a)
- [KlerosCore](https://goerli.arbiscan.io/address/0xA429667Abb1A6c530BAd1083df4C69FBce86D696)
- [KlerosCore](https://goerli.arbiscan.io/address/0x8Af82E2F8890acb4AB84cbaB3c4C4Eb3E965CF24)
- [PolicyRegistry](https://goerli.arbiscan.io/address/0xED503aBA65B28D81444294D1eAa5d84CeFdC2C58)
- [RandomizerRNG](https://goerli.arbiscan.io/address/0xa90f7D2e35718FDE9AD96c8B6667AFcAa4BEfd4d)
- [SortitionModule](https://goerli.arbiscan.io/address/0xa65D3ED6494ec5fcAa115A39D625B2F01786F094)
- [SortitionModule](https://goerli.arbiscan.io/address/0x5Ae75Db8B66B574b2c5C29eE4D32cc9Fe62bfdEE)
- [WETH](https://goerli.arbiscan.io/address/0xddE1b84E43505432Fdf5F810ebB9373dD37e9230)

## Getting Started

Expand Down Expand Up @@ -121,6 +120,7 @@ yarn deploy --network localhost --tags <Arbitration|VeaMock|ForeignGatewayOnEthe
yarn deploy --network arbitrumGoerli --tags Arbitration
yarn deploy --network chiado --tags ForeignGatewayOnGnosis
yarn deploy --network chiado --tags KlerosLiquidOnGnosis
yarn deploy --network chiado --tags ForeignArbitrable
yarn deploy --network arbitrumGoerli --tags HomeGatewayToGnosis

# Goerli
Expand Down
17 changes: 12 additions & 5 deletions contracts/deploy/00-home-chain-arbitrable.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import disputeTemplate from "../../kleros-sdk/config/v2-disputetemplate/simple/NewDisputeTemplate.simple.json";

enum HomeChains {
ARBITRUM_ONE = 42161,
Expand All @@ -17,13 +18,19 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
console.log("Deploying to %s with deployer %s", HomeChains[chainId], deployer);

const klerosCore = await deployments.get("KlerosCore");
const extraData =
"0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000003"; // General court, 3 jurors
const weth = await deployments.get("WETH");

await deploy("ArbitrableExampleEthFee", {
await deploy("ArbitrableExample", {
from: deployer,
args: [
klerosCore.address,
"https://cloudflare-ipfs.com/ipfs/bafkreifteme6tusnjwyzajk75fyvzdmtyycxctf7yhfijb6rfigz3n4lvq",
],
args: [klerosCore.address, disputeTemplate, extraData, weth.address],
log: true,
});

await deploy("DisputeResolver", {
from: deployer,
args: [klerosCore.address],
log: true,
});
};
Expand Down
65 changes: 45 additions & 20 deletions contracts/deploy/00-home-chain-arbitration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ const randomizerByChain = new Map<HomeChains, string>([
[HomeChains.ARBITRUM_GOERLI, "0x923096Da90a3b60eb7E12723fA2E1547BA9236Bc"],
]);

const daiByChain = new Map<HomeChains, string>([[HomeChains.ARBITRUM_ONE, "??"]]);
const wethByChain = new Map<HomeChains, string>([[HomeChains.ARBITRUM_ONE, "??"]]);

const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { ethers, deployments, getNamedAccounts, getChainId } = hre;
const { deploy, execute } = deployments;
Expand All @@ -31,26 +34,26 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
const chainId = Number(await getChainId());
console.log("Deploying to %s with deployer %s", HomeChains[chainId], deployer);

if (chainId === HomeChains.HARDHAT) {
pnkByChain.set(
HomeChains.HARDHAT,
(
await deploy("PNK", {
from: deployer,
log: true,
})
).address
);
randomizerByChain.set(
HomeChains.HARDHAT,
(
await deploy("RandomizerMock", {
from: deployer,
args: [],
log: true,
})
).address
);
if (!pnkByChain.get(chainId)) {
const erc20Address = await deployERC20(hre, deployer, "PNK");
pnkByChain.set(HomeChains[HomeChains[chainId]], erc20Address);
}
if (!daiByChain.get(chainId)) {
const erc20Address = await deployERC20(hre, deployer, "DAI");
daiByChain.set(HomeChains[HomeChains[chainId]], erc20Address);
}
if (!wethByChain.get(chainId)) {
const erc20Address = await deployERC20(hre, deployer, "WETH");
wethByChain.set(HomeChains[HomeChains[chainId]], erc20Address);
}

if (!randomizerByChain.get(chainId)) {
const randomizerMock = await deploy("RandomizerMock", {
from: deployer,
args: [],
log: true,
});
randomizerByChain.set(HomeChains[HomeChains[chainId]], randomizerMock.address);
}

await deploy("PolicyRegistry", {
Expand Down Expand Up @@ -83,6 +86,8 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
});

const pnk = pnkByChain.get(chainId) ?? AddressZero;
const dai = daiByChain.get(chainId) ?? AddressZero;
const weth = wethByChain.get(chainId) ?? AddressZero;
const minStake = BigNumber.from(10).pow(20).mul(2);
const alpha = 10000;
const feeForJuror = BigNumber.from(10).pow(17);
Expand All @@ -108,6 +113,14 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
await execute("DisputeKitClassic", { from: deployer, log: true }, "changeCore", klerosCore.address);
}

await execute("KlerosCore", { from: deployer, log: true }, "changeAcceptedFeeTokens", pnk, true);
await execute("KlerosCore", { from: deployer, log: true }, "changeAcceptedFeeTokens", dai, true);
await execute("KlerosCore", { from: deployer, log: true }, "changeAcceptedFeeTokens", weth, true);

await execute("KlerosCore", { from: deployer, log: true }, "changeCurrencyRates", pnk, 12225583, 12);
await execute("KlerosCore", { from: deployer, log: true }, "changeCurrencyRates", dai, 60327783, 11);
await execute("KlerosCore", { from: deployer, log: true }, "changeCurrencyRates", weth, 1, 1);

await deploy("DisputeResolver", {
from: deployer,
args: [klerosCore.address],
Expand All @@ -121,4 +134,16 @@ deployArbitration.skip = async ({ getChainId }) => {
return !HomeChains[chainId];
};

const deployERC20 = async (hre: HardhatRuntimeEnvironment, deployer: string, ticker: string) => {
const { deploy } = hre.deployments;
const erc20 = await deploy(ticker, {
from: deployer,
contract: "TestERC20",
args: [ticker, ticker],
log: true,
});
console.log("Deployed %s at %s", ticker, erc20.address);
return erc20.address;
};

export default deployArbitration;
30 changes: 12 additions & 18 deletions contracts/deploy/01-foreign-gateway-on-ethereum.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import getContractAddress from "../deploy-helpers/getContractAddress";
import { KlerosCore__factory } from "../typechain-types";

enum ForeignChains {
ETHEREUM_MAINNET = 1,
Expand Down Expand Up @@ -28,37 +29,30 @@ const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironme
const homeChainProvider = new ethers.providers.JsonRpcProvider(homeNetworks[ForeignChains[chainId]].url);
let nonce = await homeChainProvider.getTransactionCount(deployer);
nonce += 2; // HomeGatewayToEthereum deploy tx will the third tx after this on its home network, so we add two to the current nonce.
const homeChainId = (await homeChainProvider.getNetwork()).chainId;
const homeChainIdAsBytes32 = hexZeroPad(hexlify(homeChainId), 32);
const homeGatewayAddress = getContractAddress(deployer, nonce);
console.log("Calculated future HomeGatewayToEthereum address for nonce %d: %s", nonce, homeGatewayAddress);

const veaOutbox = await deployments.get("VeaOutboxArbToEthDevnet");
console.log("Using VeaOutboxArbToEthDevnet at %s", veaOutbox.address);

const foreignGateway = await deploy("ForeignGatewayOnEthereum", {
const homeChainId = (await homeChainProvider.getNetwork()).chainId;
const homeChainIdAsBytes32 = hexZeroPad(hexlify(homeChainId), 32);
await deploy("ForeignGatewayOnEthereum", {
from: deployer,
contract: "ForeignGateway",
args: [deployer, veaOutbox.address, homeChainIdAsBytes32, homeGatewayAddress],
gasLimit: 4000000,
log: true,
});

await execute(
"ForeignGatewayOnEthereum",
{ from: deployer, log: true },
"changeCourtJurorFee",
0,
ethers.BigNumber.from(10).pow(17)
);

const metaEvidenceUri = `https://raw.githubusercontent.com/kleros/kleros-v2/master/contracts/deployments/${hre.network.name}/MetaEvidence_ArbitrableExample.json`;

await deploy("ArbitrableExample", {
from: deployer,
args: [foreignGateway.address, metaEvidenceUri],
log: true,
});
// TODO: disable the gateway until fully initialized with the correct fees OR allow disputeCreators to add funds again if necessary.
const coreDeployment = await hre.companionNetworks.home.deployments.get("KlerosCore");
const core = await KlerosCore__factory.connect(coreDeployment.address, homeChainProvider);
// TODO: set up the correct fees for the FORKING_COURT
const courtId = await core.GENERAL_COURT();
const fee = (await core.courts(courtId)).feeForJuror;
await execute("ForeignGatewayOnGnosis", { from: deployer, log: true }, "changeCourtJurorFee", courtId, fee);
// TODO: set up the correct fees for the lower courts
};

deployForeignGateway.tags = ["ForeignGatewayOnEthereum"];
Expand Down
45 changes: 10 additions & 35 deletions contracts/deploy/01-foreign-gateway-on-gnosis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@ import { parseUnits } from "ethers/lib/utils";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import getContractAddress from "../deploy-helpers/getContractAddress";
import { KlerosCore__factory } from "../typechain-types";

enum ForeignChains {
GNOSIS_MAINNET = 100,
GNOSIS_CHIADO = 10200,
HARDHAT = 31337,
}

const wethByChain = new Map<ForeignChains, string>([
[ForeignChains.GNOSIS_MAINNET, "0x6A023CCd1ff6F2045C3309768eAd9E68F978f6e1"],
]);

const ONE_GWEI = parseUnits("1", "gwei");

const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
Expand Down Expand Up @@ -41,47 +38,25 @@ const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironme
const veaOutbox = await deployments.get("VeaOutboxArbToGnosisDevnet");
console.log("Using VeaOutboxArbToGnosisDevnet at %s", veaOutbox.address);

if (!wethByChain.get(chainId)) {
const weth = await deploy("WETH", {
from: deployer,
log: true,
maxFeePerGas: ONE_GWEI,
maxPriorityFeePerGas: ONE_GWEI,
});

wethByChain.set(ForeignChains[ForeignChains[chainId]], weth.address);

await deploy("WETHFaucet", {
from: deployer,
contract: "Faucet",
args: [weth.address],
log: true,
maxFeePerGas: ONE_GWEI,
maxPriorityFeePerGas: ONE_GWEI,
});
}

const wethAddress = wethByChain.get(ForeignChains[ForeignChains[chainId]]);
const homeChainId = (await homeChainProvider.getNetwork()).chainId;
const homeChainIdAsBytes32 = hexZeroPad(hexlify(homeChainId), 32);

await deploy("ForeignGatewayOnGnosis", {
from: deployer,
contract: "ForeignGatewayOnGnosis",
args: [deployer, veaOutbox.address, homeChainIdAsBytes32, homeGatewayAddress, wethAddress],
contract: "ForeignGateway",
args: [deployer, veaOutbox.address, homeChainIdAsBytes32, homeGatewayAddress],
log: true,
maxFeePerGas: ONE_GWEI,
maxPriorityFeePerGas: ONE_GWEI,
});

// TODO: disable the gateway until fully initialized with the correct fees OR allow disputeCreators to add funds again if necessary.
await execute(
"ForeignGatewayOnGnosis",
{ from: deployer, log: true },
"changeCourtJurorFee",
0,
ethers.utils.parseEther("0.00001")
);
const coreDeployment = await hre.companionNetworks.home.deployments.get("KlerosCore");
const core = await KlerosCore__factory.connect(coreDeployment.address, homeChainProvider);
// TODO: set up the correct fees for the FORKING_COURT
const courtId = await core.GENERAL_COURT();
const fee = (await core.courts(courtId)).feeForJuror;
await execute("ForeignGatewayOnGnosis", { from: deployer, log: true }, "changeCourtJurorFee", courtId, fee);
// TODO: set up the correct fees for the lower courts
};

deployForeignGateway.tags = ["ForeignGatewayOnGnosis"];
Expand Down
37 changes: 24 additions & 13 deletions contracts/deploy/03-vea-mock.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import { ethers } from "hardhat";
import getContractAddress from "../deploy-helpers/getContractAddress";
import { KlerosCore__factory } from "../typechain-types";
import disputeTemplate from "../../kleros-sdk/config/v2-disputetemplate/simple/NewDisputeTemplate.simple.json";

const HARDHAT_NETWORK = 31337;

Expand Down Expand Up @@ -39,24 +40,34 @@ const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment)
await deploy("HomeGatewayToEthereum", {
from: deployer,
contract: "HomeGateway",
args: [deployer, klerosCore.address, vea.address, HARDHAT_NETWORK, foreignGateway.address],
args: [
deployer,
klerosCore.address,
vea.address,
HARDHAT_NETWORK,
foreignGateway.address,
ethers.constants.AddressZero, // feeToken
],
gasLimit: 4000000,
log: true,
}); // nonce+1

await execute(
"ForeignGatewayOnEthereum",
{ from: deployer, log: true },
"changeCourtJurorFee",
0,
ethers.BigNumber.from(10).pow(17)
);
// TODO: disable the gateway until fully initialized with the correct fees OR allow disputeCreators to add funds again if necessary.
const signer = (await hre.ethers.getSigners())[0];
const core = await KlerosCore__factory.connect(klerosCore.address, signer);
// TODO: set up the correct fees for the FORKING_COURT
const courtId = await core.GENERAL_COURT();
const fee = (await core.courts(courtId)).feeForJuror;
await execute("ForeignGatewayOnEthereum", { from: deployer, log: true }, "changeCourtJurorFee", courtId, fee);
// TODO: set up the correct fees for the lower courts

const metaEvidenceUri = `https://raw.githubusercontent.com/kleros/kleros-v2/master/contracts/deployments/goerli/MetaEvidence_ArbitrableExample.json`;

await deploy("ArbitrableExampleEthFee", {
// TODO: debug why this extraData fails but "0x00" works
// const extraData =
// "0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000003"; // General court, 3 jurors
const extraData = "0x00";
await deploy("ArbitrableExample", {
from: deployer,
args: [foreignGateway.address, metaEvidenceUri],
args: [foreignGateway.address, disputeTemplate, extraData, ethers.constants.AddressZero],
log: true,
});
};
Expand Down
Loading