Skip to content
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

Feat(contracts)/upgradability #1214

Merged
merged 16 commits into from
Sep 26, 2023
Merged
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
19 changes: 9 additions & 10 deletions contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Refresh the list of deployed contracts by running `./scripts/generateDeployments
- [ArbitrableExample](https://gnosis-chiado.blockscout.com/address/0xB56A23b396E0eae85414Ce5815da448ba529Cb4A)
- [DisputeResolver](https://gnosis-chiado.blockscout.com/address/0x16f20604a51Ac1e68c9aAd1C0E53e951B62CC1Cb)
- [DisputeTemplateRegistry](https://gnosis-chiado.blockscout.com/address/0x96E49552669ea81B8E9cE8694F7E4A55D8bFb957)
- [ForeignGatewayOnGnosis](https://gnosis-chiado.blockscout.com/address/0x83F393F2aE68FA6A6701D7c65CBbFf3225f3fDf9)
- [ForeignGatewayOnGnosis: proxy](https://gnosis-chiado.blockscout.com/address/0x078dAd05373d19d7fd6829735b765F12242a4300), [implementation](https://gnosis-chiado.blockscout.com/address/0xA4096fDA5291D5bbDD5Ed0D6CF2AF98229168Ace)
- [WETH](https://gnosis-chiado.blockscout.com/address/0x2DFC9c3141268e6eac04a7D6d98Fbf64BDe836a8)
- [WETHFaucet](https://gnosis-chiado.blockscout.com/address/0x22CB016c4b57413ca4DF5F1AC44a0E0d3c69811F)
- [WPNKFaucet](https://gnosis-chiado.blockscout.com/address/0x5898aeE045A25B276369914c3448B72a41758B2c)
Expand All @@ -66,19 +66,18 @@ Refresh the list of deployed contracts by running `./scripts/generateDeployments
#### Arbitrum Goerli

- [PNK](https://goerli.arbiscan.io/token/0x3483FA1b87792cd5BE4100822C4eCEC8D3E531ee)
- [ArbitrableExample](https://goerli.arbiscan.io/address/0x6C346D9cDf0D71F71b36Fc1d7dB7c5e94696C146)
- [ArbitrableExample](https://goerli.arbiscan.io/address/0x5d96ede4D4Dd4c245d6879A4D790fF0AB1F476cC)
- [DAI](https://goerli.arbiscan.io/address/0xB755843e26F2cD1c6A46659cEBb67CcFAE0f2EeE)
- [DAIFaucet](https://goerli.arbiscan.io/address/0xCEBF1e0A5921767dd97b999ed14801A3770afAfd)
- [DisputeKitClassic](https://goerli.arbiscan.io/address/0x848DB6FBE64b06d58cD9D58820a4FB2F70537F2b)
- [DisputeResolver](https://goerli.arbiscan.io/address/0x66439ac54509892a5149efeF397DD36446281234)
- [DisputeTemplateRegistry](https://goerli.arbiscan.io/address/0xB01eC32bB0ba461ebEA9A61A6172Aba0DDE2B640)
- [HomeGatewayToGnosis](https://goerli.arbiscan.io/address/0x3DbB7993B8C2D7a1be58b8F2647ba1Cac60B6111)
- [KlerosCore](https://goerli.arbiscan.io/address/0xAbE6106f9f051af72eE2dB752061e2a0f081c10B)
- [DisputeKitClassic: proxy](https://goerli.arbiscan.io/address/0x6394A70cADD1376FdE5C38bA331761256DDd03E2), [implementation](https://goerli.arbiscan.io/address/0x9755b94c2c8AB04dDc7d102A6F8c974f538481fb)
- [DisputeResolver](https://goerli.arbiscan.io/address/0xE4af4D800Ce12149199FA6f8870cD650cD8f3164)
- [DisputeTemplateRegistry: proxy](https://goerli.arbiscan.io/address/0xBf5AF2c2938B3EE689d9A4f5324F144d9a617a2A), [implementation](https://goerli.arbiscan.io/address/0x93bf43132b6805E215d3c8305232ec3A174Ef146)
- [KlerosCore: proxy](https://goerli.arbiscan.io/address/0x813DCc76dbA91DD9f6bDD038aea0877FC95656bE), [implementation](https://goerli.arbiscan.io/address/0xEE08d6427F4f23E602C4114B8F2B7f6d6D3F4206)
- [PNKFaucet](https://goerli.arbiscan.io/address/0x05648Ee14941630a649082e0dA5cb80D29cC9002)
- [PinakionV2](https://goerli.arbiscan.io/address/0x3483FA1b87792cd5BE4100822C4eCEC8D3E531ee)
- [PolicyRegistry](https://goerli.arbiscan.io/address/0xa3556bF00c4f9ea235D6D4Bcb1B1c32121C0e935)
- [RandomizerRNG](https://goerli.arbiscan.io/address/0x0FE3869EA01Febb895Bc76DaB143858F84C67024)
- [SortitionModule](https://goerli.arbiscan.io/address/0x6f3b3c8d72Af21102088C8b3F07Ee97b166a21b2)
- [PolicyRegistry: proxy](https://goerli.arbiscan.io/address/0x0d7EeA661C1f9cB1AD389c9Df90B3beDE86a1529), [implementation](https://goerli.arbiscan.io/address/0xF9128Ae440A9d4BABc6B66f9385C5Ba6ADf11D89)
- [RandomizerRNG: proxy](https://goerli.arbiscan.io/address/0xF67D956988cb11449db7aeA80E6339b95b160593), [implementation](https://goerli.arbiscan.io/address/0xc1C85d303B4995Cb543C2b449C1b3dF490d49ebE)
- [SortitionModule: proxy](https://goerli.arbiscan.io/address/0xA7e5D4C3E6C593cF6A367C3A415BB8E4A065E62E), [implementation](https://goerli.arbiscan.io/address/0xA472Dfb104696E5CE82E46148c33Cd5FeE2C3b7d)
- [WETH](https://goerli.arbiscan.io/address/0xbB5839497dE7e6d4ddaFde093F69abA9be782E07)
- [WETHFaucet](https://goerli.arbiscan.io/address/0xD2d862B060986b25996aaeDB54813002AB791013)

Expand Down
6 changes: 3 additions & 3 deletions contracts/deploy/00-ethereum-pnk.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 disputeTemplate from "../test/fixtures/DisputeTemplate.simple.json";
import { isSkipped } from "./utils";

enum Chains {
GOERLI = 5,
Expand All @@ -24,9 +25,8 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
};

deployArbitration.tags = ["Pinakion"];
deployArbitration.skip = async ({ getChainId }) => {
const chainId = Number(await getChainId());
return !Chains[chainId];
deployArbitration.skip = async ({ network }) => {
return isSkipped(network, !Chains[network.config.chainId ?? 0]);
};

export default deployArbitration;
17 changes: 6 additions & 11 deletions contracts/deploy/00-home-chain-arbitrable.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import disputeTemplate from "../test/fixtures/DisputeTemplate.simple.json";

enum HomeChains {
ARBITRUM_ONE = 42161,
ARBITRUM_GOERLI = 421613,
HARDHAT = 31337,
}
import { HomeChains, isSkipped } from "./utils";
import { deployUpgradable } from "./utils/deployUpgradable";

const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { deployments, getNamedAccounts, getChainId } = hre;
Expand All @@ -22,9 +18,9 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
"0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000003"; // General court, 3 jurors
const weth = await deployments.get("WETH");

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

Expand All @@ -50,9 +46,8 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)

deployArbitration.tags = ["HomeArbitrable"];
deployArbitration.dependencies = ["Arbitration"];
deployArbitration.skip = async ({ getChainId }) => {
const chainId = Number(await getChainId());
return !HomeChains[chainId];
deployArbitration.skip = async ({ network }) => {
return isSkipped(network, !HomeChains[network.config.chainId ?? 0]);
};

export default deployArbitration;
56 changes: 26 additions & 30 deletions contracts/deploy/00-home-chain-arbitration.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import { BigNumber } from "ethers";
import getContractAddress from "../deploy-helpers/getContractAddress";

enum HomeChains {
ARBITRUM_ONE = 42161,
ARBITRUM_GOERLI = 421613,
HARDHAT = 31337,
}
import getContractAddress from "./utils/getContractAddress";
import { deployUpgradable } from "./utils/deployUpgradable";
import { HomeChains, isSkipped } from "./utils";

const pnkByChain = new Map<HomeChains, string>([
[HomeChains.ARBITRUM_ONE, "0x330bD769382cFc6d50175903434CCC8D206DCAE5"],
Expand Down Expand Up @@ -56,43 +52,44 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
randomizerByChain.set(HomeChains[HomeChains[chainId]], randomizerMock.address);
}

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

const randomizer = randomizerByChain.get(Number(await getChainId())) ?? AddressZero;
const rng = await deploy("RandomizerRNG", {
skipIfAlreadyDeployed: true,
from: deployer,
args: [randomizer, deployer],
log: true,
});
const rng = await deployUpgradable(hre, "RandomizerRNG", { from: deployer, args: [randomizer, deployer], log: true });

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

const nonce = await ethers.provider.getTransactionCount(deployer);
const KlerosCoreAddress = getContractAddress(deployer, nonce + 1);
console.log("calculated future KlerosCore address for nonce %d: %s", nonce, KlerosCoreAddress);
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 KlerosCore address for nonce %d: %s", nonce + 3, klerosCoreAddress);
}

const sortitionModule = await deploy("SortitionModule", {
const sortitionModule = await deployUpgradable(hre, "SortitionModule", {
from: deployer,
args: [deployer, KlerosCoreAddress, 1800, 1800, rng.address, RNG_LOOKAHEAD], // minStakingTime, maxFreezingTime
args: [
deployer,
klerosCoreAddress,
1800, // minStakingTime
1800, // maxFreezingTime
rng.address,
RNG_LOOKAHEAD,
],
log: true,
});
}); // nonce (implementation), nonce+1 (proxy)

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);
const klerosCore = await deploy("KlerosCore", {
const klerosCore = await deployUpgradable(hre, "KlerosCore", {
from: deployer,
args: [
deployer,
Expand All @@ -106,7 +103,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
sortitionModule.address,
],
log: true,
});
}); // nonce+2 (implementation), nonce+3 (proxy)

// execute DisputeKitClassic.changeCore() only if necessary
const currentCore = await hre.ethers.getContractAt("DisputeKitClassic", disputeKit.address).then((dk) => dk.core());
Expand All @@ -124,9 +121,8 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
};

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

const deployERC20AndFaucet = async (
Expand Down
12 changes: 3 additions & 9 deletions contracts/deploy/00-home-chain-pnk-faucet.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";

enum HomeChains {
ARBITRUM_ONE = 42161,
ARBITRUM_GOERLI = 421613,
HARDHAT = 31337,
}
import { HomeChains, isSkipped } from "./utils";

const pnkByChain = new Map<HomeChains, string>([
[HomeChains.ARBITRUM_ONE, "0x330bD769382cFc6d50175903434CCC8D206DCAE5"],
Expand Down Expand Up @@ -39,9 +34,8 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
};

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

export default deployArbitration;
12 changes: 3 additions & 9 deletions contracts/deploy/00-rng.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import { SortitionModule, RandomizerRNG } from "../typechain-types";

enum HomeChains {
ARBITRUM_ONE = 42161,
ARBITRUM_GOERLI = 421613,
HARDHAT = 31337,
}
import { HomeChains, isSkipped } from "./utils";

const pnkByChain = new Map<HomeChains, string>([
[HomeChains.ARBITRUM_ONE, "0x330bD769382cFc6d50175903434CCC8D206DCAE5"],
Expand Down Expand Up @@ -63,9 +58,8 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
};

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

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

enum ForeignChains {
ETHEREUM_MAINNET = 1,
ETHEREUM_GOERLI = 5,
}
import { Courts, ForeignChains, isSkipped } from "./utils";
import { deployUpgradable } from "./utils/deployUpgradable";

const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { ethers, deployments, getNamedAccounts, getChainId, config } = hre;
Expand All @@ -18,17 +15,13 @@ const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironme
const chainId = Number(await getChainId());
console.log("Deploying to chainId %s with deployer %s", chainId, deployer);

const homeNetworks = {
ETHEREUM_MAINNET: config.networks.arbitrum,
ETHEREUM_GOERLI: config.networks.arbitrumGoerli,
HARDHAT: config.networks.localhost,
};

// Hack to predict the deployment address on the home chain.
// TODO: use deterministic deployments
const homeChainProvider = new ethers.providers.JsonRpcProvider(homeNetworks[ForeignChains[chainId]].url);
const network = config.networks[hre.network.name];
const homeNetwork = config.networks[network.companionNetworks.home] as HttpNetworkConfig;
const homeChainProvider = new ethers.providers.JsonRpcProvider(homeNetwork.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.
nonce += 1; // HomeGatewayToEthereum Proxy deploy tx will be the 2nd tx after this on its home network, so we add 1 to the current nonce.
const homeGatewayAddress = getContractAddress(deployer, nonce);
console.log("Calculated future HomeGatewayToEthereum address for nonce %d: %s", nonce, homeGatewayAddress);

Expand All @@ -37,7 +30,7 @@ const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironme

const homeChainId = (await homeChainProvider.getNetwork()).chainId;
const homeChainIdAsBytes32 = hexZeroPad(hexlify(homeChainId), 32);
await deploy("ForeignGatewayOnEthereum", {
await deployUpgradable(hre, "ForeignGatewayOnEthereum", {
from: deployer,
contract: "ForeignGateway",
args: [deployer, veaOutbox.address, homeChainIdAsBytes32, homeGatewayAddress],
Expand All @@ -49,16 +42,14 @@ const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironme
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);
const fee = (await core.courts(Courts.GENERAL)).feeForJuror;
await execute("ForeignGatewayOnEthereum", { from: deployer, log: true }, "changeCourtJurorFee", Courts.GENERAL, fee);
// TODO: set up the correct fees for the lower courts
};

deployForeignGateway.tags = ["ForeignGatewayOnEthereum"];
deployForeignGateway.skip = async ({ getChainId }) => {
const chainId = Number(await getChainId());
return !ForeignChains[chainId];
deployForeignGateway.skip = async ({ network }) => {
return isSkipped(network, !ForeignChains[network.config.chainId ?? 0]);
};

export default deployForeignGateway;
41 changes: 15 additions & 26 deletions contracts/deploy/01-foreign-gateway-on-gnosis.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { parseUnits } from "ethers/lib/utils";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { HardhatRuntimeEnvironment, HttpNetworkConfig } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import getContractAddress from "../deploy-helpers/getContractAddress";
import getContractAddress from "./utils/getContractAddress";
import { KlerosCore__factory } from "../typechain-types";

enum ForeignChains {
GNOSIS_MAINNET = 100,
GNOSIS_CHIADO = 10200,
HARDHAT = 31337,
}
import { Courts, ForeignChains, isSkipped } from "./utils";
import { deployUpgradable } from "./utils/deployUpgradable";

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

Expand All @@ -22,18 +18,13 @@ const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironme
const chainId = Number(await getChainId());
console.log("Deploying to chainId %s with deployer %s", chainId, deployer);

const homeNetworks = {
GNOSIS_MAINNET: config.networks.arbitrum,
GNOSIS_CHIADO: config.networks.arbitrumGoerli,
HARDHAT: config.networks.localhost,
};

// Hack to predict the deployment address on the home chain.
// TODO: use deterministic deployments
const homeChainProvider = new ethers.providers.JsonRpcProvider(homeNetworks[ForeignChains[chainId]].url);
const nonce = await homeChainProvider.getTransactionCount(deployer);

// FIXME: this computed address is wrong for deploys to testnets, okay on Hardhat
const network = config.networks[hre.network.name];
const homeNetwork = config.networks[network.companionNetworks.home] as HttpNetworkConfig;
const homeChainProvider = new ethers.providers.JsonRpcProvider(homeNetwork.url);
let nonce = await homeChainProvider.getTransactionCount(deployer);
nonce += 1; // HomeGatewayToEthereum Proxy deploy tx will be the 2nd tx after this on its home network, so we add 1 to the current nonce.
const homeGatewayAddress = getContractAddress(deployer, nonce); // HomeGateway deploy tx will be the next tx home network
console.log("Calculated future HomeGatewayToEthereum address for nonce %d: %s", nonce, homeGatewayAddress);

Expand All @@ -42,29 +33,27 @@ const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironme

const homeChainId = (await homeChainProvider.getNetwork()).chainId;
const homeChainIdAsBytes32 = hexZeroPad(hexlify(homeChainId), 32);
await deploy("ForeignGatewayOnGnosis", {
await deployUpgradable(hre, "ForeignGatewayOnGnosis", {
from: deployer,
contract: "ForeignGateway",
args: [deployer, veaOutbox.address, homeChainIdAsBytes32, homeGatewayAddress],
log: true,
maxFeePerGas: ONE_GWEI,
maxPriorityFeePerGas: ONE_GWEI,
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);
const fee = (await core.courts(Courts.GENERAL)).feeForJuror;
await execute("ForeignGatewayOnGnosis", { from: deployer, log: true }, "changeCourtJurorFee", Courts.GENERAL, fee);
// TODO: set up the correct fees for the lower courts
};

deployForeignGateway.tags = ["ForeignGatewayOnGnosis"];
deployForeignGateway.skip = async ({ getChainId }) => {
const chainId = Number(await getChainId());
return !ForeignChains[chainId];
deployForeignGateway.skip = async ({ network }) => {
return isSkipped(network, !ForeignChains[network.config.chainId ?? 0]);
};

export default deployForeignGateway;
Loading