Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { changeCurrencyRate } from "./utils/klerosCoreHelper";
import { HomeChains, isSkipped, isDevnet, PNK, ETH } from "./utils";
import { getContractOrDeploy, getContractOrDeployUpgradable } from "./utils/getContractOrDeploy";
import { deployERC20AndFaucet, deployERC721 } from "./utils/deployTokens";
import { ChainlinkRNG, DisputeKitClassic, KlerosCoreNeo, RNGWithFallback } from "../typechain-types";
import { DisputeKitClassic, KlerosCore, RNGWithFallback } from "../typechain-types";

const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { ethers, deployments, getNamedAccounts, getChainId } = hre;
Expand All @@ -29,26 +29,25 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
await deployUpgradable(deployments, "EvidenceModule", { from: deployer, args: [deployer], log: true });

const classicDisputeKitID = 1; // Classic DK
const disputeKit = await deployUpgradable(deployments, "DisputeKitClassicNeo", {
const disputeKit = await deployUpgradable(deployments, "DisputeKitClassic", {
from: deployer,
contract: "DisputeKitClassic",
args: [deployer, ZeroAddress, weth.target, classicDisputeKitID],
log: true,
});

let klerosCoreAddress = await deployments.getOrNull("KlerosCoreNeo").then((deployment) => deployment?.address);
let klerosCoreAddress = await deployments.getOrNull("KlerosCore").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);
console.log("calculated future KlerosCore address for nonce %d: %s", nonce + 3, klerosCoreAddress);
}
const devnet = isDevnet(hre.network);
const minStakingTime = devnet ? 180 : 1800;
const maxFreezingTime = devnet ? 600 : 1800;
const rngWithFallback = await ethers.getContract<RNGWithFallback>("RNGWithFallback");
const maxStakePerJuror = PNK(2_000);
const maxTotalStaked = PNK(2_000_000);
const sortitionModule = await deployUpgradable(deployments, "SortitionModuleNeo", {
const sortitionModule = await deployUpgradable(deployments, "SortitionModule", {
from: deployer,
args: [
deployer,
Expand All @@ -66,7 +65,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
const alpha = 10000;
const feeForJuror = ETH(0.1);
const jurorsForCourtJump = 256;
const klerosCore = await deployUpgradable(deployments, "KlerosCoreNeo", {
const klerosCore = await deployUpgradable(deployments, "KlerosCore", {
from: deployer,
args: [
deployer,
Expand All @@ -79,14 +78,14 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
[0, 0, 0, 10], // evidencePeriod, commitPeriod, votePeriod, appealPeriod
ethers.toBeHex(5), // Extra data for sortition module will return the default value of K
sortitionModule.address,
nft.target,
weth.target,
nft.target,
],
log: true,
}); // nonce+2 (implementation), nonce+3 (proxy)

// disputeKit.changeCore() only if necessary
const disputeKitContract = await hre.ethers.getContract<DisputeKitClassic>("DisputeKitClassicNeo");
const disputeKitContract = await hre.ethers.getContract<DisputeKitClassic>("DisputeKitClassic");
const currentCore = await disputeKitContract.core();
if (currentCore !== klerosCore.address) {
console.log(`disputeKit.changeCore(${klerosCore.address})`);
Expand All @@ -100,7 +99,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
await rngWithFallback.changeConsumer(sortitionModule.address);
}

const core = await hre.ethers.getContract<KlerosCoreNeo>("KlerosCoreNeo");
const core = await hre.ethers.getContract<KlerosCore>("KlerosCore");
try {
await changeCurrencyRate(core, await weth.getAddress(), true, 1, 1);
} catch (e) {
Expand All @@ -113,12 +112,13 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
log: true,
});

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

Expand Down Expand Up @@ -155,7 +155,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
});
};

deployArbitration.tags = ["ArbitrationNeo"];
deployArbitration.tags = ["ArbitrationMainnet"];
deployArbitration.dependencies = ["ChainlinkRNG"];
deployArbitration.skip = async ({ network }) => {
return isSkipped(network, !HomeChains[network.config.chainId ?? 0]);
Expand Down
13 changes: 11 additions & 2 deletions contracts/deploy/00-home-chain-arbitration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { changeCurrencyRate } from "./utils/klerosCoreHelper";
import { HomeChains, isSkipped, isDevnet, PNK, ETH, Courts } from "./utils";
import { getContractOrDeploy, getContractOrDeployUpgradable } from "./utils/getContractOrDeploy";
import { deployERC20AndFaucet } from "./utils/deployTokens";
import { ChainlinkRNG, DisputeKitClassic, KlerosCore, RNGWithFallback } from "../typechain-types";
import { DisputeKitClassic, KlerosCore, RNGWithFallback } from "../typechain-types";

const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { ethers, deployments, getNamedAccounts, getChainId } = hre;
Expand Down Expand Up @@ -53,7 +53,15 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
const rngWithFallback = await ethers.getContract<RNGWithFallback>("RNGWithFallback");
const sortitionModule = await deployUpgradable(deployments, "SortitionModule", {
from: deployer,
args: [deployer, klerosCoreAddress, minStakingTime, maxFreezingTime, rngWithFallback.target],
args: [
deployer,
klerosCoreAddress,
minStakingTime,
maxFreezingTime,
rngWithFallback.target,
ethers.MaxUint256, // maxStakePerJuror
ethers.MaxUint256, // maxTotalStaked
],
log: true,
}); // nonce (implementation), nonce+1 (proxy)

Expand All @@ -75,6 +83,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
ethers.toBeHex(5), // Extra data for sortition module will return the default value of K
sortitionModule.address,
weth.target,
ZeroAddress, // jurorNft
],
log: true,
}); // nonce+2 (implementation), nonce+3 (proxy)
Expand Down
14 changes: 3 additions & 11 deletions contracts/deploy/change-sortition-module-rng.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import { HomeChains, isMainnet, isSkipped } from "./utils";
import { HomeChains, isSkipped } from "./utils";
import { ethers } from "hardhat";
import { ChainlinkRNG, SortitionModule, SortitionModuleNeo } from "../typechain-types";
import { ChainlinkRNG, SortitionModule } from "../typechain-types";

const task: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { getNamedAccounts, getChainId } = hre;
Expand All @@ -13,15 +13,7 @@ const task: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
console.log("deploying to %s with deployer %s", HomeChains[chainId], deployer);

const chainlinkRng = await ethers.getContract<ChainlinkRNG>("ChainlinkRNG");

let sortitionModule: SortitionModule | SortitionModuleNeo;
if (isMainnet(hre.network)) {
console.log("Using SortitionModuleNeo");
sortitionModule = await ethers.getContract<SortitionModuleNeo>("SortitionModuleNeo");
} else {
console.log("Using SortitionModule");
sortitionModule = await ethers.getContract<SortitionModule>("SortitionModule");
}
const sortitionModule = await ethers.getContract<SortitionModule>("SortitionModule");

console.log(`chainlinkRng.changeConsumer(${sortitionModule.target})`);
await chainlinkRng.changeConsumer(sortitionModule.target);
Expand Down
41 changes: 7 additions & 34 deletions contracts/deploy/upgrade-all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { DeployFunction } from "hardhat-deploy/types";
import { prompt, print } from "gluegun";
import { deployUpgradable } from "./utils/deployUpgradable";
import { HomeChains, isSkipped } from "./utils";
import { getContractNames, getContractNamesFromNetwork } from "../scripts/utils/contracts";
import { getContractNamesFromNetwork } from "../scripts/utils/contracts";

const { bold } = print.colors;

Expand Down Expand Up @@ -36,21 +36,7 @@ const deployUpgradeAll: DeployFunction = async (hre: HardhatRuntimeEnvironment)
try {
print.highlight(`🔍 Validating upgrade of ${bold(contractName)}`);

const contractNameWithoutNeo = contractName.replace(/Neo.*$/, "");
let compareStorageOptions = { contract: contractName } as any;
if (hre.network.name === "arbitrum") {
switch (contractName) {
case "KlerosCoreNeo":
case "SortitionModuleNeo":
compareStorageOptions = { deployedArtifact: `${contractName}_Implementation`, contract: contractName };
break;
default:
compareStorageOptions = {
deployedArtifact: `${contractName}_Implementation`,
contract: contractNameWithoutNeo,
};
}
}
await hre.run("compare-storage", compareStorageOptions);
print.newline();
print.highlight(`💣 Upgrading ${bold(contractName)}`);
Expand All @@ -65,25 +51,12 @@ const deployUpgradeAll: DeployFunction = async (hre: HardhatRuntimeEnvironment)
}
print.info(`Upgrading ${contractName}...`);

switch (contractName) {
case "DisputeKitClassicNeo":
case "DisputeResolverNeo":
await deployUpgradable(deployments, contractName, {
contract: contractName,
newImplementation: contractNameWithoutNeo,
initializer,
from: deployer,
args, // Warning: do not reinitialize existing state variables, only the new ones
});
break;
default:
await deployUpgradable(deployments, contractName, {
newImplementation: contractName,
initializer,
from: deployer,
args, // Warning: do not reinitialize existing state variables, only the new ones
});
}
await deployUpgradable(deployments, contractName, {
newImplementation: contractName,
initializer,
from: deployer,
args, // Warning: do not reinitialize existing state variables, only the new ones
});
print.info(`Verifying ${contractName} on Etherscan...`);
await hre.run("etherscan-verify", { contractName: `${contractName}_Implementation` });
} catch (err) {
Expand Down
4 changes: 2 additions & 2 deletions contracts/deploy/utils/klerosCoreHelper.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { KlerosCore, KlerosCoreNeo, KlerosCoreRuler, KlerosCoreUniversity } from "../../typechain-types";
import { KlerosCore, KlerosCoreRuler, KlerosCoreUniversity } from "../../typechain-types";
import { BigNumberish, toBigInt } from "ethers";

export const changeCurrencyRate = async (
core: KlerosCore | KlerosCoreNeo | KlerosCoreRuler | KlerosCoreUniversity,
core: KlerosCore | KlerosCoreRuler | KlerosCoreUniversity,
erc20: string,
accepted: boolean,
rateInEth: BigNumberish,
Expand Down
14 changes: 5 additions & 9 deletions contracts/deployments/contractsEthers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ import {
KlerosCoreUniversity__factory,
SortitionModuleUniversity,
SortitionModuleUniversity__factory,
KlerosCoreNeo,
KlerosCoreNeo__factory,
SortitionModuleNeo,
SortitionModuleNeo__factory,
} from "../typechain-types";
import { type ContractConfig, type DeploymentName, deployments, getAddress } from "./utils";

Expand Down Expand Up @@ -171,8 +167,8 @@ function getCommonFactories(

export const getContracts = async (provider: ethers.Provider, deployment: DeploymentName) => {
const { chainId } = deployments[deployment];
let klerosCore: KlerosCore | KlerosCoreNeo | KlerosCoreUniversity;
let sortition: SortitionModule | SortitionModuleNeo | SortitionModuleUniversity;
let klerosCore: KlerosCore | KlerosCoreUniversity;
let sortition: SortitionModule | SortitionModuleUniversity;
let commonFactories: CommonFactories;

switch (deployment) {
Expand Down Expand Up @@ -247,9 +243,9 @@ export const getContracts = async (provider: ethers.Provider, deployment: Deploy
chainId
);
break;
case "mainnetNeo":
klerosCore = KlerosCoreNeo__factory.connect(getAddress(mainnetCoreConfig, chainId), provider);
sortition = SortitionModuleNeo__factory.connect(getAddress(mainnetSortitionConfig, chainId), provider);
case "mainnet":
klerosCore = KlerosCore__factory.connect(getAddress(mainnetCoreConfig, chainId), provider);
sortition = SortitionModule__factory.connect(getAddress(mainnetSortitionConfig, chainId), provider);
commonFactories = getCommonFactories(
{
dkClassicConfig: mainnetDkcConfig,
Expand Down
2 changes: 1 addition & 1 deletion contracts/deployments/contractsViem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export const getConfigs = ({ deployment }: { deployment: DeploymentName }): Cont
},
});

case "mainnetNeo":
case "mainnet":
return getCommonConfigs({
chainId,
configs: {
Expand Down
2 changes: 1 addition & 1 deletion contracts/deployments/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const deployments = {
testnet: {
chainId: arbitrumSepolia.id,
},
mainnetNeo: {
mainnet: {
chainId: arbitrum.id,
},
} as const;
Expand Down
6 changes: 3 additions & 3 deletions contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@
"docbuild": "scripts/docPreprocess.sh && forge doc --build --out dist && scripts/docPostprocess.sh",
"populate:courts:devnet": "hardhat populate:courts --from v2_devnet --network arbitrumSepoliaDevnet",
"populate:courts:testnet": "hardhat populate:courts --from v2_testnet --network arbitrumSepolia",
"populate:courts:mainnetNeo": "hardhat populate:courts --core-type neo --from v2_mainnet_neo --network arbitrum",
"populate:policiesUris": "scripts/setPoliciesURIs.sh config/policies.v2.{devnet,testnet,mainnet-neo}.json",
"populate:courts:mainnet": "hardhat populate:courts --from v2_mainnet --network arbitrum",
"populate:policiesUris": "scripts/setPoliciesURIs.sh config/policies.v2.{devnet,testnet,mainnet}.json",
"populate:policies:devnet": "hardhat populate:policy-registry --from v2_devnet --network arbitrumSepoliaDevnet",
"populate:policies:testnet": "hardhat populate:policy-registry --from v2_testnet --network arbitrumSepolia",
"populate:policies:mainnetNeo": "hardhat populate:policy-registry --from v2_mainnet_neo --network arbitrum",
"populate:policies:mainnet": "hardhat populate:policy-registry --from v2_mainnet --network arbitrum",
"release:patch": "scripts/publish.sh patch",
"release:minor": "scripts/publish.sh minor",
"release:major": "scripts/publish.sh major",
Expand Down
4 changes: 2 additions & 2 deletions contracts/scripts/changeOwner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { bold } = print.colors;

task("change-owner", "Changes the owner for all the contracts")
.addPositionalParam("newOwner", "The address of the new owner")
.addOptionalParam("coreType", "The type of core to use between base, neo, university (default: base)", Cores.BASE)
.addOptionalParam("coreType", "The type of core to use between base, university (default: base)", Cores.BASE)
.setAction(async (taskArgs, hre) => {
const newOwner = taskArgs.newOwner;
if (!isAddress(newOwner)) {
Expand All @@ -27,7 +27,7 @@ task("change-owner", "Changes the owner for all the contracts")

const coreType = Cores[taskArgs.coreType.toUpperCase() as keyof typeof Cores];
if (coreType === undefined) {
console.error("Invalid core type, must be one of base, neo, university");
console.error("Invalid core type, must be one of base, university");
return;
}
console.log("Using core type %s", coreType);
Expand Down
2 changes: 1 addition & 1 deletion contracts/scripts/generateDeploymentArtifact.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

if [[ $# < 2 ]]
if [[ $# -lt 2 ]]
then
echo "usage: $(basename $0) network address"
exit 1
Expand Down
7 changes: 4 additions & 3 deletions contracts/scripts/generateDeploymentsMarkdown.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ IGNORED_ARTIFACTS=(
function generate() { #deploymentDir #explorerUrl
deploymentDir=$1
explorerUrl=$2
# shellcheck disable=SC2068
for f in $(ls -1 $deploymentDir/*.json 2>/dev/null | grep -v ${IGNORED_ARTIFACTS[@]/#/-e } | sort); do
contractName=$(basename $f .json)
address=$(cat $f | jq -r .address)
Expand All @@ -28,12 +29,12 @@ function generate() { #deploymentDir #explorerUrl
done
}

echo "### V2 Neo (prelaunch)"
echo "### V2 Mainnet"
echo "#### Arbitrum One"
echo
generate "$SCRIPT_DIR/../deployments/arbitrum" "https://arbiscan.io/address/" | grep -v 'DAI\|WETH\|PNKFaucet'
echo
echo "### Official Testnet"
echo "### V2 Testnet"
echo "#### Arbitrum Sepolia"
echo
generate "$SCRIPT_DIR/../deployments/arbitrumSepolia" "https://sepolia.arbiscan.io/address/"
Expand All @@ -47,7 +48,7 @@ echo
generate "$SCRIPT_DIR/../deployments/chiado" "https://gnosis-chiado.blockscout.com/address/"
echo

echo "### Devnet"
echo "### V2 Devnet (unstable)"
echo "#### Arbitrum Sepolia"
echo
generate "$SCRIPT_DIR/../deployments/arbitrumSepoliaDevnet" "https://sepolia.arbiscan.io/address/"
Expand Down
7 changes: 2 additions & 5 deletions contracts/scripts/keeperBot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
DisputeKitGatedShutter,
DisputeKitShutter,
SortitionModule,
SortitionModuleNeo,
} from "../typechain-types";
import env from "./utils/env";
import loggerFactory from "./utils/logger";
Expand Down Expand Up @@ -49,7 +48,7 @@ const getContracts = async () => {
throw new Error("University is not supported yet");
}
const contracts = await getContractsForCoreType(hre, coreType);
return { ...contracts, sortition: contracts.sortition as SortitionModule | SortitionModuleNeo };
return { ...contracts, sortition: contracts.sortition as SortitionModule };
};

type Contribution = {
Expand Down Expand Up @@ -277,9 +276,7 @@ const isRngReady = async () => {
return true;
}
} else if (currentRng === blockHashRNG?.target && blockHashRNG !== null) {
const requestBlock = await sortition.randomNumberRequestBlock();
const lookahead = await sortition.rngLookahead();
const n = await blockHashRNG.receiveRandomness.staticCall(requestBlock + lookahead);
const n = await blockHashRNG.receiveRandomness.staticCall();
if (Number(n) === 0) {
logger.info("BlockHashRNG is NOT ready yet");
return false;
Expand Down
Loading
Loading