Skip to content

Commit

Permalink
Merge branch 'dev' into fix(web)-linted-imports-with-new-rules
Browse files Browse the repository at this point in the history
  • Loading branch information
alcercu committed Mar 18, 2024
2 parents 5d0ff2a + 94754ab commit 8979b77
Show file tree
Hide file tree
Showing 112 changed files with 30,860 additions and 2,357 deletions.
20 changes: 20 additions & 0 deletions contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ Smart contracts for Kleros v2

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

### V2 Neo (prelaunch)

#### Arbitrum One

- [DisputeKitClassicNeo: proxy](https://arbiscan.io/address/0xb7c292cD9Fd3d20De84a71AE1caF054eEB6374A9), [implementation](https://arbiscan.io/address/0x86Ac67e5550F837a650B4B0Cd4778D4293a2bDe3)
- [DisputeResolverNeo](https://arbiscan.io/address/0x95eCE455bD817D6adB92F2383617d36eBE10D6EB)
- [DisputeTemplateRegistry: proxy](https://arbiscan.io/address/0x52c9f5634361eD3641016e5d9783310f9EFf9e25), [implementation](https://arbiscan.io/address/0x4Ce87329d40f15509D5F9bF4D9Ce1A081A80CeFb)
- [EvidenceModule: proxy](https://arbiscan.io/address/0xe62B776498F48061ef9425fCEf30F3d1370DB005), [implementation](https://arbiscan.io/address/0x827411b3e98bAe8c441efBf26842A1670f8f378F)
- [KlerosCoreNeo: proxy](https://arbiscan.io/address/0xCd415C03dfa85B02646C7e2977F22a480c4354F1), [implementation](https://arbiscan.io/address/0x4DD8B69958eF1D7d5dA9347E9d9F57ADFC3dc284)
- [KlerosV2NeoEarlyUser](https://arbiscan.io/address/0xfE34a72c55e512601E7d491A9c5b36373cE34d63)
- [Pinakion](https://arbiscan.io/address/0x330bD769382cFc6d50175903434CCC8D206DCAE5)
- [PolicyRegistry: proxy](https://arbiscan.io/address/0x26c1980120F1C82cF611D666CE81D2b54d018547), [implementation](https://arbiscan.io/address/0x2AC2EdFD336732bc6963f1AD03ED98B22dB949da)
- [RandomizerRNG: proxy](https://arbiscan.io/address/0xC3dB344755b15c8Edfd834db79af4f8860029FB4), [implementation](https://arbiscan.io/address/0xA995C172d286f8F4eE137CC662e2844E59Cf4836)
- [SortitionModuleNeo: proxy](https://arbiscan.io/address/0x614498118850184c62f82d08261109334bFB050f), [implementation](https://arbiscan.io/address/0xf327200420F21BAafce8F1C03B1EEdF926074B95)

### Official Testnet

#### Arbitrum Sepolia
Expand Down Expand Up @@ -55,18 +70,23 @@ Refresh the list of deployed contracts by running `./scripts/generateDeployments
- [DAI](https://sepolia.arbiscan.io/address/0x593e89704D285B0c3fbF157c7CF2537456CE64b5)
- [DAIFaucet](https://sepolia.arbiscan.io/address/0xB5b39A1bcD2D7097A8824B3cC18Ebd2dFb0D9B5E)
- [DisputeKitClassic: proxy](https://sepolia.arbiscan.io/address/0x9426F127116C3652A262AE1eA48391AC8F44D35b), [implementation](https://sepolia.arbiscan.io/address/0x692CC78F2570181FFB99297965FeAA8352ab12E8)
- [DisputeKitClassicNeo: proxy](https://sepolia.arbiscan.io/address/0xd40aA608801a639E292e10C235B90488D04070b1), [implementation](https://sepolia.arbiscan.io/address/0xE636AB278fBfc8712E807c589A362dc2396d2d2F)
- [DisputeKitClassicUniversity: proxy](https://sepolia.arbiscan.io/address/0xDaE66157D72Baa099cd63a833c353776206feea4), [implementation](https://sepolia.arbiscan.io/address/0xf36fa321Bb64b6E39f5DA3dbb053ccE63D077f8B)
- [DisputeResolver](https://sepolia.arbiscan.io/address/0xB8B36CC43f852f9F0484f53Eb38CaBBA28a81bF6)
- [DisputeResolverNeo](https://sepolia.arbiscan.io/address/0xaBC213522c01354DC0Db2B3E89bDe0FCF44Acac6)
- [DisputeResolverUniversity](https://sepolia.arbiscan.io/address/0x102Ba9488Df13842612e777aB16144cCACD38194)
- [DisputeTemplateRegistry: proxy](https://sepolia.arbiscan.io/address/0x596D3B09E684D62217682216e9b7a0De75933391), [implementation](https://sepolia.arbiscan.io/address/0xc53b813ed94AaEb6F5518D60bf6a8109954bE3f6)
- [EvidenceModule: proxy](https://sepolia.arbiscan.io/address/0x57fd453FB0d16f8ca174E7386102D7170E17Be09), [implementation](https://sepolia.arbiscan.io/address/0x05AD81f245209b7f91885fd96e57c9da90554824)
- [KlerosCore: proxy](https://sepolia.arbiscan.io/address/0xA54e7A16d7460e38a8F324eF46782FB520d58CE8), [implementation](https://sepolia.arbiscan.io/address/0x91a373BBdE0532F86410682F362e2Cf685e95085)
- [KlerosCoreNeo: proxy](https://sepolia.arbiscan.io/address/0x26bf077037550e437605F07e25EfcAd510715C3A), [implementation](https://sepolia.arbiscan.io/address/0x3bE96b7eAF6A3640DBa1f7CE58776D5b790B74CB)
- [KlerosCoreUniversity: proxy](https://sepolia.arbiscan.io/address/0x10BaAFDe8B4d3164CA781571e2F1513317f57980), [implementation](https://sepolia.arbiscan.io/address/0x8466ab62E7c923e8F2E61d0358C495676D6F939b)
- [KlerosV2NeoEarlyUser](https://sepolia.arbiscan.io/address/0x0d60Ff8bbCF49Bc5352328E7E28e141834d7750F)
- [PNKFaucet](https://sepolia.arbiscan.io/address/0x7EFE468003Ad6A858b5350CDE0A67bBED58739dD)
- [PinakionV2](https://sepolia.arbiscan.io/address/0x34B944D42cAcfC8266955D07A80181D2054aa225)
- [PolicyRegistry: proxy](https://sepolia.arbiscan.io/address/0x2AC2EdFD336732bc6963f1AD03ED98B22dB949da), [implementation](https://sepolia.arbiscan.io/address/0xAA637C9E2831614158d7eB193D03af4a7223C56E)
- [RandomizerRNG: proxy](https://sepolia.arbiscan.io/address/0xA995C172d286f8F4eE137CC662e2844E59Cf4836), [implementation](https://sepolia.arbiscan.io/address/0xe62B776498F48061ef9425fCEf30F3d1370DB005)
- [SortitionModule: proxy](https://sepolia.arbiscan.io/address/0x19cb28BAB40C3585955798f5EEabd71Eec14471C), [implementation](https://sepolia.arbiscan.io/address/0xBC82B29e5aE8a749D82b7919118Ab7C0D41fA3D3)
- [SortitionModuleNeo: proxy](https://sepolia.arbiscan.io/address/0x809533c303c10915BB5c0585f2d8D738e2a4fB64), [implementation](https://sepolia.arbiscan.io/address/0xD9ddceb7C399518F23b69D155a67C6AFF13f9fF0)
- [SortitionModuleUniversity: proxy](https://sepolia.arbiscan.io/address/0xBEEb15EF1DEf96c569c97A703E649B0251ceFB04), [implementation](https://sepolia.arbiscan.io/address/0xaA2833b174D4e29ae2aFc0b11dF9160EDB28BF9d)
- [WETH](https://sepolia.arbiscan.io/address/0x3829A2486d53ee984a0ca2D76552715726b77138)
- [WETHFaucet](https://sepolia.arbiscan.io/address/0x6F8C10E0030aDf5B8030a5E282F026ADdB6525fd)
Expand Down
136 changes: 136 additions & 0 deletions contracts/deploy/00-home-chain-arbitration-neo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import { BigNumber, BigNumberish } from "ethers";
import { getContractAddress } from "./utils/getContractAddress";
import { deployUpgradable } from "./utils/deployUpgradable";
import { changeCurrencyRate } from "./utils/klerosCoreHelper";
import { HomeChains, isSkipped, isDevnet, PNK, ETH, isMainnet } from "./utils";
import { getContractOrDeploy, getContractOrDeployUpgradable } from "./utils/getContractOrDeploy";
import { deployERC20AndFaucet, deployERC721 } from "./utils/deployTokens";
import { DisputeKitClassic, KlerosCoreNeo } from "../typechain-types";

const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { ethers, deployments, getNamedAccounts, getChainId } = hre;
const { deploy, execute } = deployments;
const { AddressZero } = hre.ethers.constants;
const RNG_LOOKAHEAD = 20;

// 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 pnk = await deployERC20AndFaucet(hre, deployer, "PNK");
const weth = await deployERC20AndFaucet(hre, deployer, "WETH");
const nft = await deployERC721(hre, deployer, "Kleros V2 Neo Early User", "KlerosV2NeoEarlyUser");

const randomizerOracle = await getContractOrDeploy(hre, "RandomizerOracle", {
from: deployer,
contract: "RandomizerMock",
args: [],
log: true,
});

await deployUpgradable(deployments, "PolicyRegistry", { from: deployer, args: [deployer], log: true });

await deployUpgradable(deployments, "EvidenceModule", { from: deployer, args: [deployer], log: true });

const rng = await deployUpgradable(deployments, "RandomizerRNG", {
from: deployer,
args: [randomizerOracle.address, deployer],
log: true,
});

const disputeKit = await deployUpgradable(deployments, "DisputeKitClassicNeo", {
from: deployer,
contract: "DisputeKitClassic",
args: [deployer, AddressZero],
log: true,
});

let klerosCoreAddress = await deployments.getOrNull("KlerosCoreNeo").then((deployment) => deployment?.address);
if (!klerosCoreAddress) {
const nonce = await ethers.provider.getTransactionCount(deployer);
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 KlerosCoreNeo address for nonce %d: %s", nonce + 3, klerosCoreAddress);
}
const devnet = isDevnet(hre.network);
const minStakingTime = devnet ? 180 : 1800;
const maxFreezingTime = devnet ? 600 : 1800;
const maxStakePerJuror = PNK(2_000);
const maxTotalStaked = PNK(2_000_000);
const sortitionModule = await deployUpgradable(deployments, "SortitionModuleNeo", {
from: deployer,
args: [
deployer,
klerosCoreAddress,
minStakingTime,
maxFreezingTime,
rng.address,
RNG_LOOKAHEAD,
maxStakePerJuror,
maxTotalStaked,
],
log: true,
}); // nonce (implementation), nonce+1 (proxy)

const minStake = PNK(200);
const alpha = 10000;
const feeForJuror = ETH(0.1);
const jurorsForCourtJump = 256;
const klerosCore = await deployUpgradable(deployments, "KlerosCoreNeo", {
from: deployer,
args: [
deployer,
deployer,
pnk.address,
AddressZero,
disputeKit.address,
false,
[minStake, alpha, feeForJuror, jurorsForCourtJump],
[0, 0, 0, 10], // evidencePeriod, commitPeriod, votePeriod, appealPeriod
ethers.utils.hexlify(5), // Extra data for sortition module will return the default value of K
sortitionModule.address,
nft.address,
],
log: true,
}); // nonce+2 (implementation), nonce+3 (proxy)

// execute DisputeKitClassic.changeCore() only if necessary
const disputeKitContract = (await hre.ethers.getContract("DisputeKitClassicNeo")) as DisputeKitClassic;
const currentCore = await disputeKitContract.core();
if (currentCore !== klerosCore.address) {
console.log(`disputeKit.changeCore(${klerosCore.address})`);
await disputeKitContract.changeCore(klerosCore.address);
}

const core = (await hre.ethers.getContract("KlerosCoreNeo")) as KlerosCoreNeo;
try {
await changeCurrencyRate(core, weth.address, true, 1, 1);
} catch (e) {
console.error("failed to change currency rates:", e);
}

const disputeTemplateRegistry = await getContractOrDeployUpgradable(hre, "DisputeTemplateRegistry", {
from: deployer,
args: [deployer],
log: true,
});

const resolver = await deploy("DisputeResolverNeo", {
from: deployer,
contract: "DisputeResolver",
args: [core.address, disputeTemplateRegistry.address],
log: true,
});

console.log(`core.changeArbitrableWhitelist(${resolver.address}, true)`);
await core.changeArbitrableWhitelist(resolver.address, true);
};

deployArbitration.tags = ["ArbitrationNeo"];
deployArbitration.skip = async ({ network }) => {
return isSkipped(network, !HomeChains[network.config.chainId ?? 0]);
};

export default deployArbitration;
43 changes: 14 additions & 29 deletions contracts/deploy/00-home-chain-arbitration-university.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { DeployFunction } from "hardhat-deploy/types";
import { BigNumber, BigNumberish } from "ethers";
import { getContractAddress } from "./utils/getContractAddress";
import { deployUpgradable } from "./utils/deployUpgradable";
import { HomeChains, isSkipped } from "./utils";
import { deployERC20AndFaucet } from "./utils/deployERC20AndFaucet";
import { DisputeKitClassic, KlerosCore } from "../typechain-types";
import { changeCurrencyRate } from "./utils/klerosCoreHelper";
import { ETH, HomeChains, PNK, isSkipped } from "./utils";
import { deployERC20AndFaucet } from "./utils/deployTokens";
import { DisputeKitClassic, KlerosCore, KlerosCoreUniversity } from "../typechain-types";
import { getContractOrDeployUpgradable } from "./utils/getContractOrDeploy";

const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
Expand Down Expand Up @@ -41,9 +42,10 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
log: true,
}); // nonce (implementation), nonce+1 (proxy)

const minStake = BigNumber.from(10).pow(20).mul(2);
const minStake = PNK(200);
const alpha = 10000;
const feeForJuror = BigNumber.from(10).pow(17);
const feeForJuror = ETH(0.1);
const jurorsForCourtJump = 256;
const klerosCore = await deployUpgradable(deployments, "KlerosCoreUniversity", {
from: deployer,
args: [
Expand All @@ -53,7 +55,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
AddressZero,
disputeKit.address,
false,
[minStake, alpha, feeForJuror, 256], // minStake, alpha, feeForJuror, jurorsForCourtJump
[minStake, alpha, feeForJuror, jurorsForCourtJump],
[0, 0, 0, 10], // evidencePeriod, commitPeriod, votePeriod, appealPeriod
sortitionModule.address,
],
Expand All @@ -64,32 +66,15 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
const disputeKitContract = (await ethers.getContract("DisputeKitClassicUniversity")) as DisputeKitClassic;
const currentCore = await disputeKitContract.core();
if (currentCore !== klerosCore.address) {
console.log("changing DisputeKitClassicUniversity.core to %s", klerosCore.address);
console.log(`disputeKit.changeCore(${klerosCore.address})`);
await disputeKitContract.changeCore(klerosCore.address);
}

const changeCurrencyRate = async (
erc20: string,
accepted: boolean,
rateInEth: BigNumberish,
rateDecimals: BigNumberish
) => {
const core = (await ethers.getContract("KlerosCoreUniversity")) as KlerosCore;
const pnkRate = await core.currencyRates(erc20);
if (pnkRate.feePaymentAccepted !== accepted) {
console.log(`core.changeAcceptedFeeTokens(${erc20}, ${accepted})`);
await core.changeAcceptedFeeTokens(erc20, accepted);
}
if (!pnkRate.rateInEth.eq(rateInEth) || pnkRate.rateDecimals !== rateDecimals) {
console.log(`core.changeCurrencyRates(${erc20}, ${rateInEth}, ${rateDecimals})`);
await core.changeCurrencyRates(erc20, rateInEth, rateDecimals);
}
};

const core = (await hre.ethers.getContract("KlerosCoreUniversity")) as KlerosCoreUniversity;
try {
await changeCurrencyRate(pnk.address, true, 12225583, 12);
await changeCurrencyRate(dai.address, true, 60327783, 11);
await changeCurrencyRate(weth.address, true, 1, 1);
await changeCurrencyRate(core, pnk.address, true, 12225583, 12);
await changeCurrencyRate(core, dai.address, true, 60327783, 11);
await changeCurrencyRate(core, weth.address, true, 1, 1);
} catch (e) {
console.error("failed to change currency rates:", e);
}
Expand All @@ -103,7 +88,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
await deploy("DisputeResolverUniversity", {
from: deployer,
contract: "DisputeResolver",
args: [klerosCore.address, disputeTemplateRegistry.address],
args: [core.address, disputeTemplateRegistry.address],
log: true,
});
};
Expand Down
45 changes: 16 additions & 29 deletions contracts/deploy/00-home-chain-arbitration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { DeployFunction } from "hardhat-deploy/types";
import { BigNumber, BigNumberish } from "ethers";
import { getContractAddress } from "./utils/getContractAddress";
import { deployUpgradable } from "./utils/deployUpgradable";
import { HomeChains, isSkipped, isDevnet } from "./utils";
import { changeCurrencyRate } from "./utils/klerosCoreHelper";
import { HomeChains, isSkipped, isDevnet, PNK, ETH } from "./utils";
import { getContractOrDeploy } from "./utils/getContractOrDeploy";
import { deployERC20AndFaucet } from "./utils/deployERC20AndFaucet";
import { KlerosCore } from "../typechain-types";
import { deployERC20AndFaucet } from "./utils/deployTokens";
import { DisputeKitClassic, KlerosCore } from "../typechain-types";

const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { ethers, deployments, getNamedAccounts, getChainId } = hre;
const { deploy, execute } = deployments;
const { AddressZero } = hre.ethers.constants;
const RNG_LOOKAHEAD = 20;

Expand Down Expand Up @@ -61,18 +61,20 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
log: true,
}); // nonce (implementation), nonce+1 (proxy)

const minStake = BigNumber.from(10).pow(20).mul(2);
const minStake = PNK(200);
const alpha = 10000;
const feeForJuror = BigNumber.from(10).pow(17);
const feeForJuror = ETH(0.1);
const jurorsForCourtJump = 256;
const klerosCore = await deployUpgradable(deployments, "KlerosCore", {
from: deployer,
args: [
deployer,
deployer,
pnk.address,
AddressZero,
disputeKit.address,
false,
[minStake, alpha, feeForJuror, 256], // minStake, alpha, feeForJuror, jurorsForCourtJump
[minStake, alpha, feeForJuror, jurorsForCourtJump],
[0, 0, 0, 10], // evidencePeriod, commitPeriod, votePeriod, appealPeriod
ethers.utils.hexlify(5), // Extra data for sortition module will return the default value of K
sortitionModule.address,
Expand All @@ -83,31 +85,16 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
// execute DisputeKitClassic.changeCore() only if necessary
const currentCore = await hre.ethers.getContractAt("DisputeKitClassic", disputeKit.address).then((dk) => dk.core());
if (currentCore !== klerosCore.address) {
await execute("DisputeKitClassic", { from: deployer, log: true }, "changeCore", klerosCore.address);
const dk = (await hre.ethers.getContract("DisputeKitClassic")) as DisputeKitClassic;
console.log(`disputeKit.changeCore(${klerosCore.address})`);
dk.changeCore(klerosCore.address);
}

const changeCurrencyRate = async (
erc20: string,
accepted: boolean,
rateInEth: BigNumberish,
rateDecimals: BigNumberish
) => {
const core = (await ethers.getContract("KlerosCore")) as KlerosCore;
const pnkRate = await core.currencyRates(erc20);
if (pnkRate.feePaymentAccepted !== accepted) {
console.log(`core.changeAcceptedFeeTokens(${erc20}, ${accepted})`);
await core.changeAcceptedFeeTokens(erc20, accepted);
}
if (!pnkRate.rateInEth.eq(rateInEth) || pnkRate.rateDecimals !== rateDecimals) {
console.log(`core.changeCurrencyRates(${erc20}, ${rateInEth}, ${rateDecimals})`);
await core.changeCurrencyRates(erc20, rateInEth, rateDecimals);
}
};

const core = (await hre.ethers.getContract("KlerosCore")) as KlerosCore;
try {
await changeCurrencyRate(pnk.address, true, 12225583, 12);
await changeCurrencyRate(dai.address, true, 60327783, 11);
await changeCurrencyRate(weth.address, true, 1, 1);
await changeCurrencyRate(core, pnk.address, true, 12225583, 12);
await changeCurrencyRate(core, dai.address, true, 60327783, 11);
await changeCurrencyRate(core, weth.address, true, 1, 1);
} catch (e) {
console.error("failed to change currency rates:", e);
}
Expand Down
8 changes: 3 additions & 5 deletions contracts/deploy/00-rng.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import { SortitionModule, RandomizerRNG } from "../typechain-types";
import { SortitionModule } from "../typechain-types";
import { HomeChains, isSkipped } from "./utils";
import { deployUpgradable } from "./utils/deployUpgradable";
import { getContractOrDeploy } from "./utils/getContractOrDeploy";

const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { deployments, getNamedAccounts, getChainId, ethers } = hre;
const { deploy, execute } = deployments;
const { getContract } = ethers;
const { AddressZero } = ethers.constants;
const { deploy } = deployments;
const RNG_LOOKAHEAD = 20;

// fallback to hardhat node signers on local network
Expand All @@ -36,7 +34,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
log: true,
});

const sortitionModule = (await hre.ethers.getContract("SortitionModule")) as SortitionModule;
const sortitionModule = (await ethers.getContract("SortitionModuleNeo")) as SortitionModule;
await sortitionModule.changeRandomNumberGenerator(rng2.address, RNG_LOOKAHEAD);
};

Expand Down
Loading

0 comments on commit 8979b77

Please sign in to comment.