Skip to content

Commit

Permalink
fix: fixed based on feedback from @unknownunknown1, bumped hardhat-de…
Browse files Browse the repository at this point in the history
…ploy to pick up this merged PR

wighawag/hardhat-deploy#479
  • Loading branch information
jaybuidl committed Oct 13, 2023
1 parent ed9aab0 commit 03fe846
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 32 deletions.
19 changes: 12 additions & 7 deletions contracts/deploy/utils/deployUpgradable.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
import { DeployResult, DeployOptions } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";

export function deployUpgradable(
export const deployUpgradable = async (
hre: HardhatRuntimeEnvironment,
contract: string,
options: DeployOptions
): Promise<DeployResult> {
): Promise<DeployResult> => {
const { deploy } = hre.deployments;
const { args, ...otherOptions } = options;
// Rationale: https://github.com/kleros/kleros-v2/pull/1214#issue-1879116629
return deploy(contract, {
proxy: {
proxyContract: "UUPSProxy",
proxyArgs: ["{implementation}", "{data}"],
checkProxyAdmin: false,
checkABIConflict: false,
checkProxyAdmin: false, // Not relevant for UUPSProxy
checkABIConflict: false, // Not relevant for UUPSProxy
upgradeFunction: {
methodName: "upgradeToAndCall",
upgradeArgs: ["{implementation}", "{data}"],
},
execute: {
init: {
methodName: "initialize",
args: args ?? [],
},
onUpgrade: {
methodName: "governor",
args: [],
methodName: "initialize",
args: args ?? [],
},
},
},
...otherOptions,
});
}
};
2 changes: 1 addition & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"graphql-request": "^6.1.0",
"hardhat": "^2.15.0",
"hardhat-contract-sizer": "^2.10.0",
"hardhat-deploy": "^0.11.37",
"hardhat-deploy": "^0.11.42",
"hardhat-deploy-ethers": "^0.4.0-next.1",
"hardhat-deploy-tenderly": "^0.2.0",
"hardhat-docgen": "^1.3.0",
Expand Down
11 changes: 5 additions & 6 deletions contracts/src/arbitration/KlerosCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable {
uint256 private constant ALPHA_DIVISOR = 1e4; // The number to divide `Court.alpha` by.
uint256 private constant NON_PAYABLE_AMOUNT = (2 ** 256 - 2) / 2; // An amount higher than the supply of ETH.
uint256 private constant SEARCH_ITERATIONS = 10; // Number of iterations to search for suitable parent court before jumping to the top court.
IERC20 private constant NATIVE_CURRENCY = IERC20(address(0)); // The native currency, such as ETH on Arbitrum, Optimism and Ethereum L1.

address public governor; // The governor of the contract.
IERC20 public pinakion; // The Pinakion token contract.
Expand Down Expand Up @@ -516,7 +515,7 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable {
) external payable override returns (uint256 disputeID) {
if (msg.value < arbitrationCost(_extraData)) revert ArbitrationFeesNotEnough();

return _createDispute(_numberOfChoices, _extraData, NATIVE_CURRENCY, msg.value);
return _createDispute(_numberOfChoices, _extraData, Constants.NATIVE_CURRENCY, msg.value);
}

/// @inheritdoc IArbitratorV2
Expand Down Expand Up @@ -553,7 +552,7 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable {
Round storage round = dispute.rounds.push();

// Obtain the feeForJuror in the same currency as the _feeAmount
uint256 feeForJuror = (_feeToken == NATIVE_CURRENCY)
uint256 feeForJuror = (_feeToken == Constants.NATIVE_CURRENCY)
? court.feeForJuror
: convertEthToTokenAmount(_feeToken, court.feeForJuror);
round.nbVotes = _feeAmount / feeForJuror;
Expand Down Expand Up @@ -810,7 +809,7 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable {
}
if (_params.repartition == _params.numberOfVotesInRound - 1 && _params.coherentCount == 0) {
// No one was coherent, send the rewards to the governor.
if (round.feeToken == NATIVE_CURRENCY) {
if (round.feeToken == Constants.NATIVE_CURRENCY) {
// The dispute fees were paid in ETH
payable(governor).send(round.totalFeesForJurors);
} else {
Expand Down Expand Up @@ -865,7 +864,7 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable {
uint256 feeReward = ((round.totalFeesForJurors / _params.coherentCount) * degreeOfCoherence) / ALPHA_DIVISOR;
round.sumFeeRewardPaid += feeReward;
pinakion.safeTransfer(account, pnkReward);
if (round.feeToken == NATIVE_CURRENCY) {
if (round.feeToken == Constants.NATIVE_CURRENCY) {
// The dispute fees were paid in ETH
payable(account).send(feeReward);
} else {
Expand All @@ -891,7 +890,7 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable {
pinakion.safeTransfer(governor, leftoverPnkReward);
}
if (leftoverFeeReward != 0) {
if (round.feeToken == NATIVE_CURRENCY) {
if (round.feeToken == Constants.NATIVE_CURRENCY) {
// The dispute fees were paid in ETH
payable(governor).send(leftoverFeeReward);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ contract DisputeKitSybilResistant is IDisputeKit, IEvidence, Initializable, UUPS
/// @dev Initializer.
/// @param _governor The governor's address.
/// @param _core The KlerosCore arbitrator.
/// @param _poh The Proof of Humanity registry.
function initialize(address _governor, KlerosCore _core, IProofOfHumanity _poh) external reinitializer(1) {
governor = _governor;
core = _core;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

pragma solidity 0.8.18;

import "./IArbitratorV2.sol";

/// @title IDisputeTemplate
/// @notice Dispute Template interface.
interface IDisputeTemplateRegistry {
Expand Down
9 changes: 6 additions & 3 deletions contracts/src/gateway/ForeignGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pragma solidity 0.8.18;
import "./interfaces/IForeignGateway.sol";
import "../proxy/UUPSProxiable.sol";
import "../proxy/Initializable.sol";
import "../libraries/Constants.sol";

/// Foreign Gateway
/// Counterpart of `HomeGateway`
Expand All @@ -37,7 +38,6 @@ contract ForeignGateway is IForeignGateway, UUPSProxiable, Initializable {
// * Storage * //
// ************************************* //

uint256 public constant DEFAULT_NB_OF_JURORS = 3; // The default number of jurors in a dispute.
uint256 internal localDisputeID; // 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.
mapping(uint96 => uint256) public feeForJuror; // feeForJuror[v2CourtID], it mirrors the value on KlerosCore.
address public governor;
Expand Down Expand Up @@ -78,6 +78,9 @@ contract ForeignGateway is IForeignGateway, UUPSProxiable, Initializable {

/// @dev Constructs the `PolicyRegistry` contract.
/// @param _governor The governor's address.
/// @param _veaOutbox The address of the VeaOutbox.
/// @param _homeChainID The chainID of the home chain.
/// @param _homeGateway The address of the home gateway.
function initialize(
address _governor,
address _veaOutbox,
Expand Down Expand Up @@ -263,10 +266,10 @@ contract ForeignGateway is IForeignGateway, UUPSProxiable, Initializable {
minJurors := mload(add(_extraData, 0x40))
}
if (feeForJuror[courtID] == 0) courtID = 0;
if (minJurors == 0) minJurors = DEFAULT_NB_OF_JURORS;
if (minJurors == 0) minJurors = Constants.DEFAULT_NB_OF_JURORS;
} else {
courtID = 0;
minJurors = DEFAULT_NB_OF_JURORS;
minJurors = Constants.DEFAULT_NB_OF_JURORS;
}
}
}
11 changes: 8 additions & 3 deletions contracts/src/gateway/HomeGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pragma solidity 0.8.18;
import "./interfaces/IForeignGateway.sol";
import "./interfaces/IHomeGateway.sol";
import "../libraries/SafeERC20.sol";
import "../libraries/Constants.sol";
import "../proxy/UUPSProxiable.sol";
import "../proxy/Initializable.sol";

Expand All @@ -32,7 +33,6 @@ contract HomeGateway is IHomeGateway, UUPSProxiable, Initializable {
// * Storage * //
// ************************************* //

IERC20 public constant NATIVE_CURRENCY = IERC20(address(0)); // The native currency, such as ETH on Arbitrum, Optimism and Ethereum L1.
address public governor;
IArbitratorV2 public arbitrator;
IVeaInbox public veaInbox;
Expand Down Expand Up @@ -64,6 +64,11 @@ contract HomeGateway is IHomeGateway, UUPSProxiable, Initializable {

/// @dev Constructs the `PolicyRegistry` contract.
/// @param _governor The governor's address.
/// @param _arbitrator The address of the arbitrator.
/// @param _veaInbox The address of the vea inbox.
/// @param _foreignChainID The ID of the foreign chain.
/// @param _foreignGateway The address of the foreign gateway.
/// @param _feeToken The address of the fee token.
function initialize(
address _governor,
IArbitratorV2 _arbitrator,
Expand Down Expand Up @@ -128,7 +133,7 @@ contract HomeGateway is IHomeGateway, UUPSProxiable, Initializable {

/// @inheritdoc IHomeGateway
function relayCreateDispute(RelayCreateDisputeParams memory _params) external payable override {
require(feeToken == NATIVE_CURRENCY, "Fees paid in ERC20 only");
require(feeToken == Constants.NATIVE_CURRENCY, "Fees paid in ERC20 only");
require(_params.foreignChainID == foreignChainID, "Foreign chain ID not supported");

bytes32 disputeHash = keccak256(
Expand Down Expand Up @@ -166,7 +171,7 @@ contract HomeGateway is IHomeGateway, UUPSProxiable, Initializable {

/// @inheritdoc IHomeGateway
function relayCreateDispute(RelayCreateDisputeParams memory _params, uint256 _feeAmount) external {
require(feeToken != NATIVE_CURRENCY, "Fees paid in native currency only");
require(feeToken != Constants.NATIVE_CURRENCY, "Fees paid in native currency only");
require(_params.foreignChainID == foreignChainID, "Foreign chain ID not supported");

bytes32 disputeHash = keccak256(
Expand Down
3 changes: 3 additions & 0 deletions contracts/src/libraries/Constants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

pragma solidity 0.8.18;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

/// @title Constants
library Constants {
// Courts
Expand All @@ -14,4 +16,5 @@ library Constants {

// Defaults
uint256 public constant DEFAULT_NB_OF_JURORS = 3; // The default number of jurors in a dispute.
IERC20 public constant NATIVE_CURRENCY = IERC20(address(0)); // The native currency, such as ETH on Arbitrum, Optimism and Ethereum L1.
}
8 changes: 7 additions & 1 deletion contracts/src/proxy/Initializable.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol) <https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/proxy/utils/Initializable.sol>
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol) <https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.9.0/contracts/proxy/utils/Initializable.sol>

pragma solidity 0.8.18;

Expand Down Expand Up @@ -43,6 +43,12 @@ pragma solidity 0.8.18;
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
*/
abstract contract Initializable {
/**
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/proxy/UUPSProxiable.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//SPDX-License-Identifier: MIT
// Adapted from <https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/proxy/utils/UUPSUpgradeable.sol>
// Adapted from <https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.9.0/contracts/proxy/utils/UUPSUpgradeable.sol>

/**
* @authors: [@malatrax]
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/proxy/UUPSProxy.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//SPDX-License-Identifier: MIT
// Adapted from <https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/proxy/ERC1967/ERC1967Proxy.sol>
// Adapted from <https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.9.0/contracts/proxy/ERC1967/ERC1967Proxy.sol>

/**
* @authors: [@malatrax]
Expand Down
3 changes: 1 addition & 2 deletions contracts/test/proxy/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { expect } from "chai";
import { ethers, deployments, getNamedAccounts } from "hardhat";
const hre = require("hardhat");
import { ethers, deployments } from "hardhat";

let deployer;
let user1;
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5290,7 +5290,7 @@ __metadata:
graphql-request: ^6.1.0
hardhat: ^2.15.0
hardhat-contract-sizer: ^2.10.0
hardhat-deploy: ^0.11.37
hardhat-deploy: ^0.11.42
hardhat-deploy-ethers: ^0.4.0-next.1
hardhat-deploy-tenderly: ^0.2.0
hardhat-docgen: ^1.3.0
Expand Down Expand Up @@ -18011,9 +18011,9 @@ __metadata:
languageName: node
linkType: hard

"hardhat-deploy@npm:^0.11.37":
version: 0.11.37
resolution: "hardhat-deploy@npm:0.11.37"
"hardhat-deploy@npm:^0.11.42":
version: 0.11.42
resolution: "hardhat-deploy@npm:0.11.42"
dependencies:
"@ethersproject/abi": ^5.7.0
"@ethersproject/abstract-signer": ^5.7.0
Expand All @@ -18039,7 +18039,7 @@ __metadata:
murmur-128: ^0.2.1
qs: ^6.9.4
zksync-web3: ^0.14.3
checksum: c338289849f26530296be648c7bfc2d4673d0786855ed256ee9cc864f40b94125cfa36808bedfbae4f2bad7adc38def7547bbeb3b84cbfb0aeabae04de5238fd
checksum: b5ee4d9e8716a7f359be9c222942531adccb28fa5e4a8f4d9e3f33b5b2b13bd13f8aa190f8fbe50072d817b9f8731909b507cad19b692b8814c991795f5a0d73
languageName: node
linkType: hard

Expand Down

0 comments on commit 03fe846

Please sign in to comment.