Skip to content

Commit 9c01a4c

Browse files
committed
fix: mostly minor
1 parent 205a708 commit 9c01a4c

File tree

17 files changed

+670
-760
lines changed

17 files changed

+670
-760
lines changed

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

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { HardhatRuntimeEnvironment } from "hardhat/types";
22
import { DeployFunction } from "hardhat-deploy/types";
3-
import { BigNumberish, toBigInt } from "ethers";
43
import { deployUpgradable } from "./utils/deployUpgradable";
54
import { HomeChains, isSkipped } from "./utils";
65
import { deployERC20AndFaucet } from "./utils/deployTokens";

contracts/deploy/upgrade-kleros-core.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { HardhatRuntimeEnvironment } from "hardhat/types";
22
import { DeployFunction } from "hardhat-deploy/types";
3-
import { toBigInt } from "ethers";
43
import { deployUpgradable } from "./utils/deployUpgradable";
54
import { HomeChains, isSkipped } from "./utils";
65

@@ -16,9 +15,9 @@ const deployUpgradeKlerosCore: DeployFunction = async (hre: HardhatRuntimeEnviro
1615
try {
1716
const pnk = await deployments.get("PNK");
1817
const disputeKit = await deployments.get("DisputeKitClassic");
19-
const minStake = toBigInt(10) ** toBigInt(20) * toBigInt(2);
18+
const minStake = 2n * 10n ** 20n;
2019
const alpha = 10000;
21-
const feeForJuror = toBigInt(10) * toBigInt(17);
20+
const feeForJuror = 10n * 17n;
2221
const sortitionModule = await deployments.get("SortitionModule");
2322

2423
console.log("upgrading the KlerosCore...");

contracts/deploy/utils/deployTokens.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Contract } from "ethers";
22
import { HardhatRuntimeEnvironment } from "hardhat/types";
3-
import { toBigInt } from "ethers";
43
import { getContractOrDeploy } from "./getContractOrDeploy";
54
import { isMainnet } from ".";
65

@@ -46,7 +45,7 @@ export const deployFaucet = async (
4645

4746
const faucetBalance = await erc20.balanceOf(faucet.target);
4847
const deployerBalance = await erc20.balanceOf(deployer);
49-
if (deployerBalance >= faucetFundingAmount && faucetBalance < faucetFundingAmount / toBigInt(5)) {
48+
if (deployerBalance >= faucetFundingAmount && faucetBalance < faucetFundingAmount / 5n) {
5049
// Fund the faucet if deployer has enough tokens and if the faucet has less than 20% of the faucetFundingAmount
5150
console.log(`funding ${ticker}Faucet with ${faucetFundingAmount}`);
5251
await erc20.transfer(faucet.target, faucetFundingAmount);

contracts/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"@logtail/pino": "^0.4.22",
6868
"@nomicfoundation/hardhat-chai-matchers": "^2.0.8",
6969
"@nomicfoundation/hardhat-ethers": "^3.0.8",
70-
"@nomiclabs/hardhat-solhint": "^3.1.0",
70+
"@nomiclabs/hardhat-solhint": "^4.0.1",
7171
"@openzeppelin/contracts": "^5.1.0",
7272
"@typechain/ethers-v6": "^0.5.1",
7373
"@typechain/hardhat": "^9.1.0",
@@ -88,15 +88,15 @@
8888
"hardhat-deploy-ethers": "^0.4.2",
8989
"hardhat-deploy-tenderly": "^0.2.0",
9090
"hardhat-docgen": "^1.3.0",
91-
"hardhat-gas-reporter": "^1.0.10",
91+
"hardhat-gas-reporter": "^2.2.1",
9292
"hardhat-tracer": "^3.1.0",
9393
"hardhat-watcher": "^2.5.0",
9494
"node-fetch": "^3.3.2",
9595
"pino": "^8.21.0",
9696
"pino-pretty": "^10.3.1",
9797
"shelljs": "^0.8.5",
9898
"solhint-plugin-prettier": "^0.1.0",
99-
"solidity-coverage": "^0.8.12",
99+
"solidity-coverage": "^0.8.13",
100100
"ts-node": "^10.9.2",
101101
"typechain": "^8.3.2",
102102
"typescript": "^5.3.3"

contracts/scripts/populateCourts.ts

+12-13
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ type Court = {
3838
supportedDisputeKits?: BigNumberish[];
3939
};
4040

41-
const ETH_USD = toBigInt(4000);
42-
const DISPUTE_KIT_CLASSIC = toBigInt(1);
43-
const TEN_THOUSAND_GWEI = toBigInt(10) ** toBigInt(13);
41+
const ETH_USD = 4000n;
42+
const DISPUTE_KIT_CLASSIC = 1n;
43+
const TEN_THOUSAND_GWEI = 10n ** 13n;
4444

4545
task("populate:courts", "Populates the courts and their parameters")
4646
.addOptionalParam(
@@ -94,17 +94,17 @@ task("populate:courts", "Populates the courts and their parameters")
9494
}
9595
console.log("Using core type %s", Cores[coreType]);
9696

97-
const truncateWei = (x: bigint) => (x / toBigInt(TEN_THOUSAND_GWEI)) * toBigInt(TEN_THOUSAND_GWEI);
97+
const truncateWei = (x: bigint) => (x / TEN_THOUSAND_GWEI) * TEN_THOUSAND_GWEI;
9898

9999
const parametersUsdToEth = (court: Court): Court => ({
100100
...court,
101-
minStake: truncateWei(toBigInt(court.minStake) / toBigInt(ETH_USD)),
102-
feeForJuror: truncateWei(toBigInt(court.feeForJuror) / toBigInt(ETH_USD)),
101+
minStake: truncateWei(toBigInt(court.minStake) / ETH_USD),
102+
feeForJuror: truncateWei(toBigInt(court.feeForJuror) / ETH_USD),
103103
});
104104

105105
const parametersProductionToDev = (court: Court): Court => ({
106106
...court,
107-
minStake: truncateWei(toBigInt(court.minStake) / toBigInt(10000)),
107+
minStake: truncateWei(toBigInt(court.minStake) / 10000n),
108108
feeForJuror: truncateWei(ethers.parseEther("0.00001")),
109109
timesPerPeriod: [120, 120, 120, 240],
110110
});
@@ -183,17 +183,17 @@ task("populate:courts", "Populates the courts and their parameters")
183183
);
184184
}
185185

186-
if (!courtPresent.minStake === court.minStake) {
186+
if (courtPresent.minStake !== court.minStake) {
187187
change = true;
188188
console.log("Court %d: changing minStake from %d to %d", court.id, courtPresent.minStake, court.minStake);
189189
}
190190

191-
if (!courtPresent.alpha === court.alpha) {
191+
if (courtPresent.alpha !== court.alpha) {
192192
change = true;
193193
console.log("Court %d: changing alpha from %d to %d", court.id, courtPresent.alpha, court.alpha);
194194
}
195195

196-
if (!courtPresent.feeForJuror === court.feeForJuror) {
196+
if (courtPresent.feeForJuror !== court.feeForJuror) {
197197
change = true;
198198
console.log(
199199
"Court %d: changing feeForJuror from %d to %d",
@@ -203,7 +203,7 @@ task("populate:courts", "Populates the courts and their parameters")
203203
);
204204
}
205205

206-
if (!courtPresent.jurorsForCourtJump === court.jurorsForCourtJump) {
206+
if (courtPresent.jurorsForCourtJump !== court.jurorsForCourtJump) {
207207
change = true;
208208
console.log(
209209
"Court %d: changing jurorsForCourtJump from %d to %d",
@@ -228,15 +228,14 @@ task("populate:courts", "Populates the courts and their parameters")
228228
console.log("Court %d: no parameter change", court.id);
229229
continue;
230230
}
231-
232231
await core.changeCourtParameters(
233232
court.id,
234233
court.hiddenVotes,
235234
court.minStake,
236235
court.alpha,
237236
court.feeForJuror,
238237
court.jurorsForCourtJump,
239-
court.timesPerPeriod
238+
[court.timesPerPeriod[0], court.timesPerPeriod[1], court.timesPerPeriod[2], court.timesPerPeriod[3]]
240239
);
241240
} else {
242241
console.log("Court %d not found, creating it with", court.id, court);

contracts/scripts/simulations/tasks.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ task("simulate:create-court", "callable by Governor only. Create a new Court")
7777

7878
const { wallet } = await getWallet(hre, walletindex);
7979

80-
const parent = toBigInt(1);
81-
const minStake = toBigInt(10) ** toBigInt(20) * toBigInt(2);
82-
const alpha = toBigInt(10000);
83-
const feeForJuror = toBigInt(10) ** toBigInt(17);
84-
const jurorsForCourtJump = toBigInt(3);
80+
const parent = 1n;
81+
const minStake = 2n * 10n ** 20n;
82+
const alpha = 10000n;
83+
const feeForJuror = 10n * 17n;
84+
const jurorsForCourtJump = 3n;
8585
const hiddenVotes = false as boolean;
8686
const timesPerPeriod = [300, 300, 300, 300] as [BigNumberish, BigNumberish, BigNumberish, BigNumberish];
8787
const sortitionSumTreeK = ethers.toBeHex(3);
@@ -338,7 +338,7 @@ task("simulate:execute-ruling", "Executes the ruling for a dispute on KlerosCore
338338
console.log("txID execute: %s", executeTx?.hash);
339339

340340
executeRulingTx = await (await connectedKlerosCore.executeRuling(disputeid)).wait(); // rule
341-
console.log("txID executeRuling: %s", executeRulingTx?.transactionHash);
341+
console.log("txID executeRuling: %s", executeRulingTx?.hash);
342342
} catch (e) {
343343
handleError(e);
344344
} finally {

contracts/scripts/simulations/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export const waitForPeriod = async (disputeId: number, period: Period, hre) => {
151151
const { lastPeriodChange, courtID } = await core.disputes(disputeId);
152152
const periodDuration = (await core.getTimesPerPeriod(courtID))[period];
153153
const now = await latest(hre.network);
154-
const remainingDuration = ethers.getNumber(lastPeriodChange + toBigInt(periodDuration) - toBigInt(now));
154+
const remainingDuration = ethers.getNumber(lastPeriodChange + periodDuration - toBigInt(now));
155155
if (remainingDuration > 0) {
156156
await waitFor(remainingDuration, hre);
157157
}

contracts/test/arbitration/draw.ts

+32-32
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import { Courts } from "../../deploy/utils";
1717
/* eslint-disable no-unused-expressions */ // https://github.com/standard/standard/issues/690#issuecomment-278533482
1818

1919
describe("Draw Benchmark", async () => {
20-
const ONE_TENTH_ETH = toBigInt(10) ** toBigInt(17);
21-
const ONE_THOUSAND_PNK = toBigInt(10) ** toBigInt(21);
20+
const ONE_TENTH_ETH = 10n ** 17n;
21+
const ONE_THOUSAND_PNK = 10n ** 21n;
2222

2323
const enum Period {
2424
evidence, // Evidence can be submitted. This is also when drawing has to take place.
@@ -39,8 +39,8 @@ describe("Draw Benchmark", async () => {
3939
drawing, // Jurors can be drawn.
4040
}
4141

42-
let deployer;
43-
let relayer;
42+
let deployer: string;
43+
let relayer: string;
4444
let disputeKit: DisputeKitClassic;
4545
let pnk: PNK;
4646
let core: KlerosCore;
@@ -50,7 +50,7 @@ describe("Draw Benchmark", async () => {
5050
let rng: IncrementalNG;
5151
let parentCourtMinStake: bigint;
5252
let childCourtMinStake: bigint;
53-
const RANDOM = toBigInt("61688911660239508166491237672720926005752254046266901728404745669596507231249");
53+
const RANDOM = 61688911660239508166491237672720926005752254046266901728404745669596507231249n;
5454
const PARENT_COURT = 1;
5555
const CHILD_COURT = 2;
5656
const abiCoder = ethers.AbiCoder.defaultAbiCoder();
@@ -71,7 +71,7 @@ describe("Draw Benchmark", async () => {
7171

7272
parentCourtMinStake = await core.courts(Courts.GENERAL).then((court) => court.minStake);
7373

74-
childCourtMinStake = toBigInt(10) ** toBigInt(20) * toBigInt(3); // 300 PNK
74+
childCourtMinStake = 3n * 10n ** 20n; // 300 PNK
7575

7676
// Make the tests more deterministic with this dummy RNG
7777
await deployments.deploy("IncrementalNG", {
@@ -84,9 +84,9 @@ describe("Draw Benchmark", async () => {
8484
await sortitionModule.changeRandomNumberGenerator(rng.target, 20);
8585

8686
// CourtId 2 = CHILD_COURT
87-
const minStake = toBigInt(10) ** toBigInt(20) * toBigInt(3); // 300 PNK
88-
const alpha = 10000;
89-
const feeForJuror = toBigInt(10) ** toBigInt(17);
87+
const minStake = 3n * 10n ** 20n; // 300 PNK
88+
const alpha = 10000n;
89+
const feeForJuror = 10n * 17n;
9090
await core.createCourt(
9191
1,
9292
false,
@@ -110,7 +110,7 @@ describe("Draw Benchmark", async () => {
110110
expectFromDraw: ExpectFromDraw,
111111
unstake: SetStake
112112
) => {
113-
const arbitrationCost = ONE_TENTH_ETH * toBigInt(3);
113+
const arbitrationCost = ONE_TENTH_ETH * 3n;
114114
const [bridger] = await ethers.getSigners();
115115
const wallets: HDNodeWallet[] = [];
116116

@@ -125,10 +125,10 @@ describe("Draw Benchmark", async () => {
125125
});
126126
expect(await ethers.provider.getBalance(wallet)).to.equal(ethers.parseEther("10"));
127127

128-
await pnk.transfer(wallet.address, ONE_THOUSAND_PNK * toBigInt(10));
129-
expect(await pnk.balanceOf(wallet.address)).to.equal(ONE_THOUSAND_PNK * toBigInt(10));
128+
await pnk.transfer(wallet.address, ONE_THOUSAND_PNK * 10n);
129+
expect(await pnk.balanceOf(wallet.address)).to.equal(ONE_THOUSAND_PNK * 10n);
130130

131-
await pnk.connect(wallet).approve(core.target, ONE_THOUSAND_PNK * toBigInt(10), { gasLimit: 300000 });
131+
await pnk.connect(wallet).approve(core.target, ONE_THOUSAND_PNK * 10n, { gasLimit: 300000 });
132132

133133
await stake(wallet);
134134
}
@@ -147,7 +147,7 @@ describe("Draw Benchmark", async () => {
147147
.connect(await ethers.getSigner(relayer))
148148
["relayCreateDispute((bytes32,uint256,address,uint256,uint256,uint256,string,uint256,bytes))"](
149149
{
150-
foreignBlockHash: ethers.toBeHex(lastBlock?.hash),
150+
foreignBlockHash: lastBlock?.hash,
151151
foreignChainID: 31337,
152152
foreignArbitrable: arbitrable.target,
153153
foreignDisputeID: disputeId,
@@ -193,12 +193,12 @@ describe("Draw Benchmark", async () => {
193193

194194
it("Stakes in parent court and should draw jurors in parent court", async () => {
195195
const stake = async (wallet: HDNodeWallet) => {
196-
await core.connect(wallet).setStake(PARENT_COURT, ONE_THOUSAND_PNK * toBigInt(5), { gasLimit: 5000000 });
196+
await core.connect(wallet).setStake(PARENT_COURT, ONE_THOUSAND_PNK * 5n, { gasLimit: 5000000 });
197197

198198
expect(await sortitionModule.getJurorBalance(wallet.address, 1)).to.deep.equal([
199-
ONE_THOUSAND_PNK * toBigInt(5), // totalStaked
200-
0, // totalLocked
201-
ONE_THOUSAND_PNK * toBigInt(5), // stakedInCourt
199+
ONE_THOUSAND_PNK * 5n, // totalStaked
200+
0n, // totalLocked
201+
ONE_THOUSAND_PNK * 5n, // stakedInCourt
202202
PARENT_COURT, // nbOfCourts
203203
]);
204204
};
@@ -219,15 +219,15 @@ describe("Draw Benchmark", async () => {
219219
countedDraws = await countDraws(tx.blockNumber);
220220
for (const [address, draws] of Object.entries(countedDraws)) {
221221
expect(await sortitionModule.getJurorBalance(address, PARENT_COURT)).to.deep.equal([
222-
ONE_THOUSAND_PNK * toBigInt(5), // totalStaked
222+
ONE_THOUSAND_PNK * 5n, // totalStaked
223223
parentCourtMinStake * toBigInt(draws), // totalLocked
224-
ONE_THOUSAND_PNK * toBigInt(5), // stakedInCourt
224+
ONE_THOUSAND_PNK * 5n, // stakedInCourt
225225
1, // nbOfCourts
226226
]);
227227
expect(await sortitionModule.getJurorBalance(address, CHILD_COURT)).to.deep.equal([
228-
ONE_THOUSAND_PNK * toBigInt(5), // totalStaked
228+
ONE_THOUSAND_PNK * 5n, // totalStaked
229229
parentCourtMinStake * toBigInt(draws), // totalLocked
230-
0, // stakedInCourt
230+
0n, // stakedInCourt
231231
1, // nbOfCourts
232232
]);
233233
}
@@ -262,7 +262,7 @@ describe("Draw Benchmark", async () => {
262262
// Warning: we are skipping this during `hardhat coverage` because it fails, although it passes with `hardhat test`
263263
it("Stakes in parent court and should draw nobody in subcourt [ @skip-on-coverage ]", async () => {
264264
const stake = async (wallet: HDNodeWallet) => {
265-
await core.connect(wallet).setStake(PARENT_COURT, ONE_THOUSAND_PNK * toBigInt(5), { gasLimit: 5000000 });
265+
await core.connect(wallet).setStake(PARENT_COURT, ONE_THOUSAND_PNK * 5n, { gasLimit: 5000000 });
266266
};
267267

268268
const expectFromDraw = async (drawTx: Promise<ContractTransactionResponse>) => {
@@ -298,7 +298,7 @@ describe("Draw Benchmark", async () => {
298298

299299
it("Stakes in subcourt and should draw jurors in parent court", async () => {
300300
const stake = async (wallet: HDNodeWallet) => {
301-
await core.connect(wallet).setStake(CHILD_COURT, ONE_THOUSAND_PNK * toBigInt(5), { gasLimit: 5000000 });
301+
await core.connect(wallet).setStake(CHILD_COURT, ONE_THOUSAND_PNK * 5n, { gasLimit: 5000000 });
302302
};
303303
let countedDraws: CountedDraws;
304304
const expectFromDraw = async (drawTx: Promise<ContractTransactionResponse>) => {
@@ -318,15 +318,15 @@ describe("Draw Benchmark", async () => {
318318
countedDraws = await countDraws(tx.blockNumber);
319319
for (const [address, draws] of Object.entries(countedDraws)) {
320320
expect(await sortitionModule.getJurorBalance(address, PARENT_COURT)).to.deep.equal([
321-
ONE_THOUSAND_PNK * toBigInt(5), // totalStaked
321+
ONE_THOUSAND_PNK * 5n, // totalStaked
322322
parentCourtMinStake * toBigInt(draws), // totalLocked
323323
0, // stakedInCourt
324324
1, // nbOfCourts
325325
]);
326326
expect(await sortitionModule.getJurorBalance(address, CHILD_COURT)).to.deep.equal([
327-
ONE_THOUSAND_PNK * toBigInt(5), // totalStaked
327+
ONE_THOUSAND_PNK * 5n, // totalStaked
328328
parentCourtMinStake * toBigInt(draws), // totalLocked
329-
ONE_THOUSAND_PNK * toBigInt(5), // stakedInCourt
329+
ONE_THOUSAND_PNK * 5n, // stakedInCourt
330330
1, // nbOfCourts
331331
]);
332332
}
@@ -360,7 +360,7 @@ describe("Draw Benchmark", async () => {
360360

361361
it("Stakes in subcourt and should draw jurors in subcourt", async () => {
362362
const stake = async (wallet: HDNodeWallet) => {
363-
await core.connect(wallet).setStake(CHILD_COURT, ONE_THOUSAND_PNK * toBigInt(5), { gasLimit: 5000000 });
363+
await core.connect(wallet).setStake(CHILD_COURT, ONE_THOUSAND_PNK * 5n, { gasLimit: 5000000 });
364364
};
365365
let countedDraws: CountedDraws;
366366
const expectFromDraw = async (drawTx: Promise<ContractTransactionResponse>) => {
@@ -380,15 +380,15 @@ describe("Draw Benchmark", async () => {
380380
countedDraws = await countDraws(tx.blockNumber);
381381
for (const [address, draws] of Object.entries(countedDraws)) {
382382
expect(await sortitionModule.getJurorBalance(address, PARENT_COURT)).to.deep.equal([
383-
ONE_THOUSAND_PNK * toBigInt(5), // totalStaked
383+
ONE_THOUSAND_PNK * 5n, // totalStaked
384384
childCourtMinStake * toBigInt(draws), // totalLocked
385-
0, // stakedInCourt
385+
0n, // stakedInCourt
386386
1, // nbOfCourts
387387
]);
388388
expect(await sortitionModule.getJurorBalance(address, CHILD_COURT)).to.deep.equal([
389-
ONE_THOUSAND_PNK * toBigInt(5), // totalStaked
389+
ONE_THOUSAND_PNK * 5n, // totalStaked
390390
childCourtMinStake * toBigInt(draws), // totalLocked
391-
ONE_THOUSAND_PNK * toBigInt(5), // stakedInCourt
391+
ONE_THOUSAND_PNK * 5n, // stakedInCourt
392392
1, // nbOfCourts
393393
]);
394394
}

0 commit comments

Comments
 (0)