-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
214 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
contracts/src/arbitration/devtools/DisputeResolverRuler.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters