Skip to content

Commit 7a5d08d

Browse files
committed
fix: hardhat tests, deploy scripts, unnecessary virtual keyword
1 parent 758a809 commit 7a5d08d

File tree

5 files changed

+42
-30
lines changed

5 files changed

+42
-30
lines changed

contracts/deploy/00-home-chain-arbitration-neo.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { changeCurrencyRate } from "./utils/klerosCoreHelper";
66
import { HomeChains, isSkipped, isDevnet, PNK, ETH } from "./utils";
77
import { getContractOrDeploy, getContractOrDeployUpgradable } from "./utils/getContractOrDeploy";
88
import { deployERC20AndFaucet, deployERC721 } from "./utils/deployTokens";
9-
import { ChainlinkRNG, DisputeKitClassic, KlerosCoreNeo, RNGWithFallback } from "../typechain-types";
9+
import { ChainlinkRNG, DisputeKitClassic, KlerosCore, RNGWithFallback } from "../typechain-types";
1010

1111
const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
1212
const { ethers, deployments, getNamedAccounts, getChainId } = hre;
@@ -29,26 +29,25 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
2929
await deployUpgradable(deployments, "EvidenceModule", { from: deployer, args: [deployer], log: true });
3030

3131
const classicDisputeKitID = 1; // Classic DK
32-
const disputeKit = await deployUpgradable(deployments, "DisputeKitClassicNeo", {
32+
const disputeKit = await deployUpgradable(deployments, "DisputeKitClassic", {
3333
from: deployer,
34-
contract: "DisputeKitClassic",
3534
args: [deployer, ZeroAddress, weth.target, classicDisputeKitID],
3635
log: true,
3736
});
3837

39-
let klerosCoreAddress = await deployments.getOrNull("KlerosCoreNeo").then((deployment) => deployment?.address);
38+
let klerosCoreAddress = await deployments.getOrNull("KlerosCore").then((deployment) => deployment?.address);
4039
if (!klerosCoreAddress) {
4140
const nonce = await ethers.provider.getTransactionCount(deployer);
4241
klerosCoreAddress = getContractAddress(deployer, nonce + 3); // deployed on the 4th tx (nonce+3): SortitionModule Impl tx, SortitionModule Proxy tx, KlerosCore Impl tx, KlerosCore Proxy tx
43-
console.log("calculated future KlerosCoreNeo address for nonce %d: %s", nonce + 3, klerosCoreAddress);
42+
console.log("calculated future KlerosCore address for nonce %d: %s", nonce + 3, klerosCoreAddress);
4443
}
4544
const devnet = isDevnet(hre.network);
4645
const minStakingTime = devnet ? 180 : 1800;
4746
const maxFreezingTime = devnet ? 600 : 1800;
4847
const rngWithFallback = await ethers.getContract<RNGWithFallback>("RNGWithFallback");
4948
const maxStakePerJuror = PNK(2_000);
5049
const maxTotalStaked = PNK(2_000_000);
51-
const sortitionModule = await deployUpgradable(deployments, "SortitionModuleNeo", {
50+
const sortitionModule = await deployUpgradable(deployments, "SortitionModule", {
5251
from: deployer,
5352
args: [
5453
deployer,
@@ -66,7 +65,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
6665
const alpha = 10000;
6766
const feeForJuror = ETH(0.1);
6867
const jurorsForCourtJump = 256;
69-
const klerosCore = await deployUpgradable(deployments, "KlerosCoreNeo", {
68+
const klerosCore = await deployUpgradable(deployments, "KlerosCore", {
7069
from: deployer,
7170
args: [
7271
deployer,
@@ -79,14 +78,14 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
7978
[0, 0, 0, 10], // evidencePeriod, commitPeriod, votePeriod, appealPeriod
8079
ethers.toBeHex(5), // Extra data for sortition module will return the default value of K
8180
sortitionModule.address,
82-
nft.target,
8381
weth.target,
82+
nft.target,
8483
],
8584
log: true,
8685
}); // nonce+2 (implementation), nonce+3 (proxy)
8786

8887
// disputeKit.changeCore() only if necessary
89-
const disputeKitContract = await hre.ethers.getContract<DisputeKitClassic>("DisputeKitClassicNeo");
88+
const disputeKitContract = await hre.ethers.getContract<DisputeKitClassic>("DisputeKitClassic");
9089
const currentCore = await disputeKitContract.core();
9190
if (currentCore !== klerosCore.address) {
9291
console.log(`disputeKit.changeCore(${klerosCore.address})`);
@@ -100,7 +99,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
10099
await rngWithFallback.changeConsumer(sortitionModule.address);
101100
}
102101

103-
const core = await hre.ethers.getContract<KlerosCoreNeo>("KlerosCoreNeo");
102+
const core = await hre.ethers.getContract<KlerosCore>("KlerosCore");
104103
try {
105104
await changeCurrencyRate(core, await weth.getAddress(), true, 1, 1);
106105
} catch (e) {
@@ -113,9 +112,8 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
113112
log: true,
114113
});
115114

116-
const resolver = await deploy("DisputeResolverNeo", {
115+
const resolver = await deploy("DisputeResolver", {
117116
from: deployer,
118-
contract: "DisputeResolver",
119117
args: [core.target, disputeTemplateRegistry.target],
120118
log: true,
121119
});
@@ -157,7 +155,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
157155
});
158156
};
159157

160-
deployArbitration.tags = ["ArbitrationNeo"];
158+
deployArbitration.tags = ["ArbitrationMainnet"];
161159
deployArbitration.dependencies = ["ChainlinkRNG"];
162160
deployArbitration.skip = async ({ network }) => {
163161
return isSkipped(network, !HomeChains[network.config.chainId ?? 0]);

contracts/deploy/00-home-chain-arbitration.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,15 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
5353
const rngWithFallback = await ethers.getContract<RNGWithFallback>("RNGWithFallback");
5454
const sortitionModule = await deployUpgradable(deployments, "SortitionModule", {
5555
from: deployer,
56-
args: [deployer, klerosCoreAddress, minStakingTime, maxFreezingTime, rngWithFallback.target],
56+
args: [
57+
deployer,
58+
klerosCoreAddress,
59+
minStakingTime,
60+
maxFreezingTime,
61+
rngWithFallback.target,
62+
ethers.MaxUint256, // maxStakePerJuror
63+
ethers.MaxUint256, // maxTotalStaked
64+
],
5765
log: true,
5866
}); // nonce (implementation), nonce+1 (proxy)
5967

@@ -75,6 +83,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
7583
ethers.toBeHex(5), // Extra data for sortition module will return the default value of K
7684
sortitionModule.address,
7785
weth.target,
86+
ZeroAddress, // jurorNft
7887
],
7988
log: true,
8089
}); // nonce+2 (implementation), nonce+3 (proxy)

contracts/src/arbitration/KlerosCore.sol

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,12 @@ contract KlerosCore is IArbitratorV2, Initializable, UUPSProxiable {
487487
emit NewCurrencyRate(_feeToken, _rateInEth, _rateDecimals);
488488
}
489489

490+
/// @dev Changes the `jurorNft` storage variable.
491+
/// @param _jurorNft The new value for the `jurorNft` storage variable.
492+
function changeJurorNft(IERC721 _jurorNft) external onlyByOwner {
493+
jurorNft = _jurorNft;
494+
}
495+
490496
/// @dev Adds or removes an arbitrable from whitelist.
491497
/// @param _arbitrable Arbitrable address.
492498
/// @param _allowed Whether add or remove permission.
@@ -507,7 +513,7 @@ contract KlerosCore is IArbitratorV2, Initializable, UUPSProxiable {
507513
/// @param _courtID The ID of the court.
508514
/// @param _newStake The new stake.
509515
/// Note that the existing delayed stake will be nullified as non-relevant.
510-
function setStake(uint96 _courtID, uint256 _newStake) external virtual whenNotPaused {
516+
function setStake(uint96 _courtID, uint256 _newStake) external whenNotPaused {
511517
if (address(jurorNft) != address(0) && jurorNft.balanceOf(msg.sender) == 0) revert NotEligibleForStaking();
512518
_setStake(msg.sender, _courtID, _newStake, false, OnError.Revert);
513519
}
@@ -559,7 +565,7 @@ contract KlerosCore is IArbitratorV2, Initializable, UUPSProxiable {
559565
bytes memory _extraData,
560566
IERC20 _feeToken,
561567
uint256 _feeAmount
562-
) internal virtual returns (uint256 disputeID) {
568+
) internal returns (uint256 disputeID) {
563569
if (arbitrableWhitelistEnabled && !arbitrableWhitelist[msg.sender]) revert ArbitrableNotWhitelisted();
564570
(uint96 courtID, , uint256 disputeKitID) = _extraDataToCourtIDMinJurorsDisputeKit(_extraData);
565571
if (!courts[courtID].supportedDisputeKits[disputeKitID]) revert DisputeKitNotSupportedByCourt();
@@ -1236,7 +1242,7 @@ contract KlerosCore is IArbitratorV2, Initializable, UUPSProxiable {
12361242
}
12371243

12381244
/// @dev It may revert depending on the _onError parameter.
1239-
function _stakingFailed(OnError _onError, StakingResult _result) internal pure virtual {
1245+
function _stakingFailed(OnError _onError, StakingResult _result) internal pure {
12401246
if (_onError == OnError.Return) return;
12411247
if (_result == StakingResult.StakingTransferFailed) revert StakingTransferFailed();
12421248
if (_result == StakingResult.UnstakingTransferFailed) revert UnstakingTransferFailed();

contracts/src/arbitration/SortitionModule.sol

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ contract SortitionModule is ISortitionModule, Initializable, UUPSProxiable {
278278
uint96 _courtID,
279279
uint256 _newStake,
280280
bool _noDelay
281-
) internal virtual returns (uint256 pnkDeposit, uint256 pnkWithdrawal, StakingResult stakingResult) {
281+
) internal returns (uint256 pnkDeposit, uint256 pnkWithdrawal, StakingResult stakingResult) {
282282
Juror storage juror = jurors[_account];
283283
uint256 currentStake = stakeOf(_account, _courtID);
284284
bool stakeIncrease = _newStake > currentStake;
@@ -319,13 +319,12 @@ contract SortitionModule is ISortitionModule, Initializable, UUPSProxiable {
319319
totalStaked += stakeChange;
320320
} else {
321321
pnkWithdrawal = stakeChange;
322-
totalStaked -= stakeChange;
323-
324-
// Ensure locked tokens remain in the contract. They can only be released during Execution.
325322
uint256 possibleWithdrawal = juror.stakedPnk > juror.lockedPnk ? juror.stakedPnk - juror.lockedPnk : 0;
326323
if (pnkWithdrawal > possibleWithdrawal) {
324+
// Ensure locked tokens remain in the contract. They can only be released during Execution.
327325
pnkWithdrawal = possibleWithdrawal;
328326
}
327+
totalStaked -= pnkWithdrawal;
329328
}
330329
return (pnkDeposit, pnkWithdrawal, StakingResult.Successful);
331330
}
@@ -417,7 +416,7 @@ contract SortitionModule is ISortitionModule, Initializable, UUPSProxiable {
417416
uint256 _pnkDeposit,
418417
uint256 _pnkWithdrawal,
419418
uint256 _newStake
420-
) internal virtual {
419+
) internal {
421420
Juror storage juror = jurors[_account];
422421
if (_pnkDeposit > 0) {
423422
uint256 currentStake = stakeOf(_account, _courtID);

contracts/test/arbitration/staking-neo.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import {
33
PNK,
44
RandomizerRNG,
55
RandomizerMock,
6-
SortitionModuleNeo,
7-
KlerosCoreNeo,
6+
SortitionModule,
7+
KlerosCore,
88
TestERC721,
99
DisputeResolver,
1010
ChainlinkRNG,
@@ -41,8 +41,8 @@ describe("Staking", async () => {
4141
let juror: HardhatEthersSigner;
4242
let guardian: HardhatEthersSigner;
4343
let pnk: PNK;
44-
let core: KlerosCoreNeo;
45-
let sortition: SortitionModuleNeo;
44+
let core: KlerosCore;
45+
let sortition: SortitionModule;
4646
let rng: ChainlinkRNG;
4747
let vrfCoordinator: ChainlinkVRFCoordinatorV2Mock;
4848
let nft: TestERC721;
@@ -52,16 +52,16 @@ describe("Staking", async () => {
5252
const deployUnhappy = async () => {
5353
({ deployer } = await getNamedAccounts());
5454

55-
await deployments.fixture(["ArbitrationNeo"], {
55+
await deployments.fixture(["ArbitrationMainnet"], {
5656
fallbackToGlobal: true,
5757
keepExistingDeployments: false,
5858
});
5959
pnk = await ethers.getContract<PNK>("PNK");
60-
core = await ethers.getContract<KlerosCoreNeo>("KlerosCoreNeo");
61-
sortition = await ethers.getContract<SortitionModuleNeo>("SortitionModuleNeo");
60+
core = await ethers.getContract<KlerosCore>("KlerosCore");
61+
sortition = await ethers.getContract<SortitionModule>("SortitionModule");
6262
rng = await ethers.getContract<ChainlinkRNG>("ChainlinkRNG");
6363
vrfCoordinator = await ethers.getContract<ChainlinkVRFCoordinatorV2Mock>("ChainlinkVRFCoordinator");
64-
resolver = await ethers.getContract<DisputeResolver>("DisputeResolverNeo");
64+
resolver = await ethers.getContract<DisputeResolver>("DisputeResolver");
6565
nft = await ethers.getContract<TestERC721>("KlerosV2NeoEarlyUser");
6666

6767
// Juror signer setup and funding

0 commit comments

Comments
 (0)