Skip to content

Commit 9a6b869

Browse files
committed
fix: fixed based on feedback from @unknownunknown1, bumped hardhat-deploy to pick up this merged PR
wighawag/hardhat-deploy#479
1 parent f8eee02 commit 9a6b869

File tree

13 files changed

+51
-32
lines changed

13 files changed

+51
-32
lines changed
Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
11
import { DeployResult, DeployOptions } from "hardhat-deploy/types";
22
import { HardhatRuntimeEnvironment } from "hardhat/types";
33

4-
export function deployUpgradable(
4+
export const deployUpgradable = async (
55
hre: HardhatRuntimeEnvironment,
66
contract: string,
77
options: DeployOptions
8-
): Promise<DeployResult> {
8+
): Promise<DeployResult> => {
99
const { deploy } = hre.deployments;
1010
const { args, ...otherOptions } = options;
11+
// Rationale: https://github.com/kleros/kleros-v2/pull/1214#issue-1879116629
1112
return deploy(contract, {
1213
proxy: {
1314
proxyContract: "UUPSProxy",
1415
proxyArgs: ["{implementation}", "{data}"],
15-
checkProxyAdmin: false,
16-
checkABIConflict: false,
16+
checkProxyAdmin: false, // Not relevant for UUPSProxy
17+
checkABIConflict: false, // Not relevant for UUPSProxy
18+
upgradeFunction: {
19+
methodName: "upgradeToAndCall",
20+
upgradeArgs: ["{implementation}", "{data}"],
21+
},
1722
execute: {
1823
init: {
1924
methodName: "initialize",
2025
args: args ?? [],
2126
},
2227
onUpgrade: {
23-
methodName: "governor",
24-
args: [],
28+
methodName: "initialize",
29+
args: args ?? [],
2530
},
2631
},
2732
},
2833
...otherOptions,
2934
});
30-
}
35+
};

contracts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"graphql-request": "^6.1.0",
6464
"hardhat": "^2.15.0",
6565
"hardhat-contract-sizer": "^2.10.0",
66-
"hardhat-deploy": "^0.11.37",
66+
"hardhat-deploy": "^0.11.42",
6767
"hardhat-deploy-ethers": "^0.4.0-next.1",
6868
"hardhat-deploy-tenderly": "^0.2.0",
6969
"hardhat-docgen": "^1.3.0",

contracts/src/arbitration/KlerosCore.sol

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable {
108108
uint256 private constant ALPHA_DIVISOR = 1e4; // The number to divide `Court.alpha` by.
109109
uint256 private constant NON_PAYABLE_AMOUNT = (2 ** 256 - 2) / 2; // An amount higher than the supply of ETH.
110110
uint256 private constant SEARCH_ITERATIONS = 10; // Number of iterations to search for suitable parent court before jumping to the top court.
111-
IERC20 private constant NATIVE_CURRENCY = IERC20(address(0)); // The native currency, such as ETH on Arbitrum, Optimism and Ethereum L1.
112111

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

519-
return _createDispute(_numberOfChoices, _extraData, NATIVE_CURRENCY, msg.value);
518+
return _createDispute(_numberOfChoices, _extraData, Constants.NATIVE_CURRENCY, msg.value);
520519
}
521520

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

555554
// Obtain the feeForJuror in the same currency as the _feeAmount
556-
uint256 feeForJuror = (_feeToken == NATIVE_CURRENCY)
555+
uint256 feeForJuror = (_feeToken == Constants.NATIVE_CURRENCY)
557556
? court.feeForJuror
558557
: convertEthToTokenAmount(_feeToken, court.feeForJuror);
559558
round.nbVotes = _feeAmount / feeForJuror;
@@ -810,7 +809,7 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable {
810809
}
811810
if (_params.repartition == _params.numberOfVotesInRound - 1 && _params.coherentCount == 0) {
812811
// No one was coherent, send the rewards to the governor.
813-
if (round.feeToken == NATIVE_CURRENCY) {
812+
if (round.feeToken == Constants.NATIVE_CURRENCY) {
814813
// The dispute fees were paid in ETH
815814
payable(governor).send(round.totalFeesForJurors);
816815
} else {
@@ -865,7 +864,7 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable {
865864
uint256 feeReward = ((round.totalFeesForJurors / _params.coherentCount) * degreeOfCoherence) / ALPHA_DIVISOR;
866865
round.sumFeeRewardPaid += feeReward;
867866
pinakion.safeTransfer(account, pnkReward);
868-
if (round.feeToken == NATIVE_CURRENCY) {
867+
if (round.feeToken == Constants.NATIVE_CURRENCY) {
869868
// The dispute fees were paid in ETH
870869
payable(account).send(feeReward);
871870
} else {
@@ -891,7 +890,7 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable {
891890
pinakion.safeTransfer(governor, leftoverPnkReward);
892891
}
893892
if (leftoverFeeReward != 0) {
894-
if (round.feeToken == NATIVE_CURRENCY) {
893+
if (round.feeToken == Constants.NATIVE_CURRENCY) {
895894
// The dispute fees were paid in ETH
896895
payable(governor).send(leftoverFeeReward);
897896
} else {

contracts/src/arbitration/dispute-kits/DisputeKitSybilResistant.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ contract DisputeKitSybilResistant is IDisputeKit, IEvidence, Initializable, UUPS
160160
/// @dev Initializer.
161161
/// @param _governor The governor's address.
162162
/// @param _core The KlerosCore arbitrator.
163+
/// @param _poh The Proof of Humanity registry.
163164
function initialize(address _governor, KlerosCore _core, IProofOfHumanity _poh) external reinitializer(1) {
164165
governor = _governor;
165166
core = _core;

contracts/src/arbitration/interfaces/IDisputeTemplateRegistry.sol

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
pragma solidity 0.8.18;
44

5-
import "./IArbitratorV2.sol";
6-
75
/// @title IDisputeTemplate
86
/// @notice Dispute Template interface.
97
interface IDisputeTemplateRegistry {

contracts/src/gateway/ForeignGateway.sol

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pragma solidity 0.8.18;
1111
import "./interfaces/IForeignGateway.sol";
1212
import "../proxy/UUPSProxiable.sol";
1313
import "../proxy/Initializable.sol";
14+
import "../libraries/Constants.sol";
1415

1516
/// Foreign Gateway
1617
/// Counterpart of `HomeGateway`
@@ -37,7 +38,6 @@ contract ForeignGateway is IForeignGateway, UUPSProxiable, Initializable {
3738
// * Storage * //
3839
// ************************************* //
3940

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

7979
/// @dev Constructs the `PolicyRegistry` contract.
8080
/// @param _governor The governor's address.
81+
/// @param _veaOutbox The address of the VeaOutbox.
82+
/// @param _homeChainID The chainID of the home chain.
83+
/// @param _homeGateway The address of the home gateway.
8184
function initialize(
8285
address _governor,
8386
address _veaOutbox,
@@ -263,10 +266,10 @@ contract ForeignGateway is IForeignGateway, UUPSProxiable, Initializable {
263266
minJurors := mload(add(_extraData, 0x40))
264267
}
265268
if (feeForJuror[courtID] == 0) courtID = 0;
266-
if (minJurors == 0) minJurors = DEFAULT_NB_OF_JURORS;
269+
if (minJurors == 0) minJurors = Constants.DEFAULT_NB_OF_JURORS;
267270
} else {
268271
courtID = 0;
269-
minJurors = DEFAULT_NB_OF_JURORS;
272+
minJurors = Constants.DEFAULT_NB_OF_JURORS;
270273
}
271274
}
272275
}

contracts/src/gateway/HomeGateway.sol

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pragma solidity 0.8.18;
1111
import "./interfaces/IForeignGateway.sol";
1212
import "./interfaces/IHomeGateway.sol";
1313
import "../libraries/SafeERC20.sol";
14+
import "../libraries/Constants.sol";
1415
import "../proxy/UUPSProxiable.sol";
1516
import "../proxy/Initializable.sol";
1617

@@ -32,7 +33,6 @@ contract HomeGateway is IHomeGateway, UUPSProxiable, Initializable {
3233
// * Storage * //
3334
// ************************************* //
3435

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

6565
/// @dev Constructs the `PolicyRegistry` contract.
6666
/// @param _governor The governor's address.
67+
/// @param _arbitrator The address of the arbitrator.
68+
/// @param _veaInbox The address of the vea inbox.
69+
/// @param _foreignChainID The ID of the foreign chain.
70+
/// @param _foreignGateway The address of the foreign gateway.
71+
/// @param _feeToken The address of the fee token.
6772
function initialize(
6873
address _governor,
6974
IArbitratorV2 _arbitrator,
@@ -128,7 +133,7 @@ contract HomeGateway is IHomeGateway, UUPSProxiable, Initializable {
128133

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

134139
bytes32 disputeHash = keccak256(
@@ -166,7 +171,7 @@ contract HomeGateway is IHomeGateway, UUPSProxiable, Initializable {
166171

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

172177
bytes32 disputeHash = keccak256(

contracts/src/libraries/Constants.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
pragma solidity 0.8.18;
44

5+
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
6+
57
/// @title Constants
68
library Constants {
79
// Courts
@@ -14,4 +16,5 @@ library Constants {
1416

1517
// Defaults
1618
uint256 public constant DEFAULT_NB_OF_JURORS = 3; // The default number of jurors in a dispute.
19+
IERC20 public constant NATIVE_CURRENCY = IERC20(address(0)); // The native currency, such as ETH on Arbitrum, Optimism and Ethereum L1.
1720
}

contracts/src/proxy/Initializable.sol

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT
2-
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol) <https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/proxy/utils/Initializable.sol>
2+
// 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>
33

44
pragma solidity 0.8.18;
55

@@ -43,6 +43,12 @@ pragma solidity 0.8.18;
4343
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
4444
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
4545
*
46+
* ```
47+
* /// @custom:oz-upgrades-unsafe-allow constructor
48+
* constructor() {
49+
* _disableInitializers();
50+
* }
51+
* ```
4652
*/
4753
abstract contract Initializable {
4854
/**

contracts/src/proxy/UUPSProxiable.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//SPDX-License-Identifier: MIT
2-
// Adapted from <https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/proxy/utils/UUPSUpgradeable.sol>
2+
// Adapted from <https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.9.0/contracts/proxy/utils/UUPSUpgradeable.sol>
33

44
/**
55
* @authors: [@malatrax]

0 commit comments

Comments
 (0)