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

Ruler (aka the centralized arbitrator) - Contract only #1517

Merged
merged 2 commits into from
Aug 7, 2024
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
81 changes: 81 additions & 0 deletions contracts/deploy/00-home-chain-arbitration-ruler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import { BigNumber, BigNumberish } from "ethers";
import { deployUpgradable } from "./utils/deployUpgradable";
import { HomeChains, isSkipped } from "./utils";
import { deployERC20AndFaucet } from "./utils/deployERC20AndFaucet";
import { KlerosCore } from "../typechain-types";
import { getContractOrDeployUpgradable } from "./utils/getContractOrDeploy";

const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { ethers, deployments, getNamedAccounts, getChainId } = 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 pnk = await deployERC20AndFaucet(hre, deployer, "PNK");
const dai = await deployERC20AndFaucet(hre, deployer, "DAI");
const weth = await deployERC20AndFaucet(hre, deployer, "WETH");

const minStake = 0;
const alpha = 10000;
const feeForJuror = BigNumber.from(10).pow(17);
const jurorsForCourtJump = 16;
const klerosCore = await deployUpgradable(deployments, "KlerosCoreRuler", {
from: deployer,
args: [
deployer, // governor
pnk.address,
[minStake, alpha, feeForJuror, jurorsForCourtJump],
],
log: true,
});

const changeCurrencyRate = async (
erc20: string,
accepted: boolean,
rateInEth: BigNumberish,
rateDecimals: BigNumberish
) => {
const core = (await ethers.getContract("KlerosCoreRuler")) 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);
}
};

try {
await changeCurrencyRate(pnk.address, true, 12225583, 12);
await changeCurrencyRate(dai.address, true, 60327783, 11);
await changeCurrencyRate(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,
});

await deploy("DisputeResolverRuler", {
from: deployer,
args: [klerosCore.address, disputeTemplateRegistry.address],
log: true,
});
};

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

export default deployArbitration;
6 changes: 3 additions & 3 deletions contracts/src/arbitration/arbitrables/DisputeResolver.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

/// @custom:authors: [@ferittuncer, @unknownunknown1, @jaybuidl]
/// @custom:authors: [@unknownunknown1, @jaybuidl]
/// @custom:reviewers: []
/// @custom:auditors: []
/// @custom:bounties: []
Expand Down Expand Up @@ -134,7 +134,7 @@ contract DisputeResolver is IArbitrableV2 {
string memory _disputeTemplateDataMappings,
string memory _disputeTemplateUri,
uint256 _numberOfRulingOptions
) internal returns (uint256 disputeID) {
) internal virtual returns (uint256 disputeID) {
require(_numberOfRulingOptions > 1, "Should be at least 2 ruling options.");

disputeID = arbitrator.createDispute{value: msg.value}(_numberOfRulingOptions, _arbitratorExtraData);
Expand All @@ -149,6 +149,6 @@ contract DisputeResolver is IArbitrableV2 {
);
arbitratorDisputeIDToLocalID[disputeID] = localDisputeID;
uint256 templateId = templateRegistry.setDisputeTemplate("", _disputeTemplate, _disputeTemplateDataMappings);
emit DisputeRequest(arbitrator, disputeID, localDisputeID, templateId, _disputeTemplateUri);
emit DisputeRequest(arbitrator, localDisputeID, localDisputeID, templateId, _disputeTemplateUri);
}
}
57 changes: 57 additions & 0 deletions contracts/src/arbitration/devtools/DisputeResolverRuler.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// SPDX-License-Identifier: MIT

/// @custom:authors: [@unknownunknown1, @jaybuidl]
/// @custom:reviewers: []
/// @custom:auditors: []
/// @custom:bounties: []

import {DisputeResolver, IArbitratorV2, IDisputeTemplateRegistry} from "../arbitrables/DisputeResolver.sol";

pragma solidity 0.8.18;

interface IKlerosCoreRulerFragment {
function getNextDisputeID() external view returns (uint256);
}

/// @title DisputeResolver
/// DisputeResolver contract adapted for V2 from https://github.com/kleros/arbitrable-proxy-contracts/blob/master/contracts/ArbitrableProxy.sol.
contract DisputeResolverRuler is DisputeResolver {
// ************************************* //
// * Constructor * //
// ************************************* //

/// @dev Constructor
/// @param _arbitrator Target global arbitrator for any disputes.
constructor(
IArbitratorV2 _arbitrator,
IDisputeTemplateRegistry _templateRegistry
) DisputeResolver(_arbitrator, _templateRegistry) {
governor = msg.sender;
}

// ************************************* //
// * State Modifiers * //
// ************************************* //

function _createDispute(
bytes calldata _arbitratorExtraData,
string memory _disputeTemplate,
string memory _disputeTemplateDataMappings,
string memory _disputeTemplateUri,
uint256 _numberOfRulingOptions
) internal override returns (uint256 disputeID) {
require(_numberOfRulingOptions > 1, "Should be at least 2 ruling options.");

uint256 localDisputeID = disputes.length;
DisputeStruct storage dispute = disputes.push();
dispute.arbitratorExtraData = _arbitratorExtraData;
dispute.numberOfRulingOptions = _numberOfRulingOptions;

disputeID = IKlerosCoreRulerFragment(address(arbitrator)).getNextDisputeID();
arbitratorDisputeIDToLocalID[disputeID] = localDisputeID;
uint256 templateId = templateRegistry.setDisputeTemplate("", _disputeTemplate, _disputeTemplateDataMappings);
emit DisputeRequest(arbitrator, localDisputeID, localDisputeID, templateId, _disputeTemplateUri);

arbitrator.createDispute{value: msg.value}(_numberOfRulingOptions, _arbitratorExtraData);
}
}
Loading
Loading