Skip to content
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
18 changes: 10 additions & 8 deletions contracts/deploy/01-foreign-gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ enum ForeignChains {

const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { ethers, deployments, getNamedAccounts, getChainId, config } = hre;
const { deploy } = deployments;
const { deploy, execute } = deployments;
const { hexZeroPad, hexlify } = ethers.utils;

// fallback to hardhat node signers on local network
Expand Down Expand Up @@ -38,17 +38,19 @@ const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironme
const foreignGateway = await deploy("ForeignGatewayOnEthereum", {
from: deployer,
contract: "ForeignGateway",
args: [
deployer,
veaReceiver.address,
[ethers.BigNumber.from(10).pow(17)],
homeGatewayAddress,
homeChainIdAsBytes32,
],
args: [deployer, veaReceiver.address, homeGatewayAddress, homeChainIdAsBytes32],
gasLimit: 4000000,
log: true,
});

await execute(
"ForeignGatewayOnEthereum",
{ from: deployer, log: true },
"changeSubcourtJurorFee",
0,
ethers.BigNumber.from(10).pow(17)
);

const metaEvidenceUri = `https://raw.githubusercontent.com/kleros/kleros-v2/master/contracts/deployments/${hre.network.name}/MetaEvidence_ArbitrableExample.json`;

await deploy("ArbitrableExample", {
Expand Down
12 changes: 10 additions & 2 deletions contracts/deploy/03-vea-mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const HARDHAT_NETWORK = 31337;

const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { ethers, deployments, getNamedAccounts } = hre;
const { deploy } = deployments;
const { deploy, execute } = deployments;
const { hexZeroPad, hexlify } = ethers.utils;

// fallback to hardhat node signers on local network
Expand All @@ -31,7 +31,7 @@ const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment)
const foreignGateway = await deploy("ForeignGatewayOnEthereum", {
from: deployer,
contract: "ForeignGateway",
args: [deployer, vea.address, [ethers.BigNumber.from(10).pow(17)], homeGatewayAddress, homeChainIdAsBytes32],
args: [deployer, vea.address, homeGatewayAddress, homeChainIdAsBytes32],
gasLimit: 4000000,
log: true,
}); // nonce+0
Expand All @@ -44,6 +44,14 @@ const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment)
log: true,
}); // nonce+1

await execute(
"ForeignGatewayOnEthereum",
{ from: deployer, log: true },
"changeSubcourtJurorFee",
0,
ethers.BigNumber.from(10).pow(17)
);

const metaEvidenceUri = `https://raw.githubusercontent.com/kleros/kleros-v2/master/contracts/deployments/goerli/MetaEvidence_ArbitrableExample.json`;

await deploy("ArbitrableExample", {
Expand Down
36 changes: 12 additions & 24 deletions contracts/src/gateway/ForeignGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ contract ForeignGateway is IForeignGateway {
address arbitrable
);

event ArbitrationCostModified(uint96 indexed _subcourtID, uint256 _feeForJuror);

// ************************************* //
// * Storage * //
// ************************************* //
Expand All @@ -51,7 +53,7 @@ contract ForeignGateway is IForeignGateway {
uint256 public immutable override senderChainID;
address public immutable override senderGateway;
uint256 internal localDisputeID = 1; // The disputeID must start from 1 as the KlerosV1 proxy governor depends on this implementation. We now also depend on localDisputeID not ever being zero.
uint256[] internal feeForJuror; // feeForJuror[subcourtID]
mapping(uint96 => uint256) public feeForJuror; // feeForJuror[subcourtID], it mirrors the value on KlerosCore.
address public governor;
IFastBridgeReceiver public fastBridgeReceiver;
IFastBridgeReceiver public depreciatedFastbridge;
Expand Down Expand Up @@ -79,13 +81,11 @@ contract ForeignGateway is IForeignGateway {
constructor(
address _governor,
IFastBridgeReceiver _fastBridgeReceiver,
uint256[] memory _feeForJuror,
address _senderGateway,
uint256 _senderChainID
) {
governor = _governor;
fastBridgeReceiver = _fastBridgeReceiver;
feeForJuror = _feeForJuror;
senderGateway = _senderGateway;
senderChainID = _senderChainID;
}
Expand Down Expand Up @@ -113,26 +113,17 @@ contract ForeignGateway is IForeignGateway {
*/
function changeSubcourtJurorFee(uint96 _subcourtID, uint256 _feeForJuror) external onlyByGovernor {
feeForJuror[_subcourtID] = _feeForJuror;
}

/**
* @dev Creates the `feeForJuror` property value for a new subcourt.
* @param _feeForJuror The new value for the `feeForJuror` property value.
*/
function createSubcourtJurorFee(uint256 _feeForJuror) external onlyByGovernor {
feeForJuror.push(_feeForJuror);
emit ArbitrationCostModified(_subcourtID, _feeForJuror);
}

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

function createDispute(uint256 _choices, bytes calldata _extraData)
external
payable
override
returns (uint256 disputeID)
{
function createDispute(
uint256 _choices,
bytes calldata _extraData
) external payable override returns (uint256 disputeID) {
require(msg.value >= arbitrationCost(_extraData), "Not paid enough for arbitration");

disputeID = localDisputeID++;
Expand Down Expand Up @@ -166,7 +157,6 @@ contract ForeignGateway is IForeignGateway {

function arbitrationCost(bytes calldata _extraData) public view override returns (uint256 cost) {
(uint96 subcourtID, uint256 minJurors) = extraDataToSubcourtIDMinJurors(_extraData);

cost = feeForJuror[subcourtID] * minJurors;
}

Expand Down Expand Up @@ -214,19 +204,17 @@ contract ForeignGateway is IForeignGateway {
// * Internal * //
// ************************ //

function extraDataToSubcourtIDMinJurors(bytes memory _extraData)
internal
view
returns (uint96 subcourtID, uint256 minJurors)
{
function extraDataToSubcourtIDMinJurors(
bytes memory _extraData
) internal view returns (uint96 subcourtID, uint256 minJurors) {
// Note that here we ignore DisputeKitID
if (_extraData.length >= 64) {
assembly {
// solium-disable-line security/no-inline-assembly
subcourtID := mload(add(_extraData, 0x20))
minJurors := mload(add(_extraData, 0x40))
}
if (subcourtID >= feeForJuror.length) subcourtID = 0;
if (feeForJuror[subcourtID] == 0) subcourtID = 0;
if (minJurors == 0) minJurors = MIN_JURORS;
} else {
subcourtID = 0;
Expand Down