Ethers v5 -> v6 migration

Updated dependencies and removed unused ones.
This commit is contained in:
hueso 2025-08-02 21:09:40 -03:00
parent 811d5344a3
commit f924593ee2
18 changed files with 3669 additions and 7066 deletions

View File

@ -1,2 +0,0 @@
extends:
- "@commitlint/config-conventional"

3
.czrc
View File

@ -1,3 +0,0 @@
{
"path": "cz-conventional-changelog"
}

1
.husky/.gitignore vendored
View File

@ -1 +0,0 @@
_

View File

@ -1,4 +0,0 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
yarn dlx commitlint --edit $1

View File

@ -1,4 +0,0 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
yarn dlx lint-staged

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

942
.yarn/releases/yarn-4.9.2.cjs vendored Executable file

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,7 @@
compressionLevel: mixed
enableGlobalCache: false
nodeLinker: node-modules nodeLinker: node-modules
plugins: yarnPath: .yarn/releases/yarn-4.9.2.cjs
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
spec: "@yarnpkg/plugin-interactive-tools"
yarnPath: .yarn/releases/yarn-3.2.1.cjs

View File

@ -92,6 +92,7 @@ const config: HardhatUserConfig = {
process.env.REPORT_GAS && process.env.REPORT_GAS &&
process.env.REPORT_GAS != "false" process.env.REPORT_GAS != "false"
), ),
offline: true,
showTimeSpent: true, showTimeSpent: true,
showMethodSig: true, showMethodSig: true,
token: "ETH", token: "ETH",
@ -147,7 +148,7 @@ const config: HardhatUserConfig = {
}, },
typechain: { typechain: {
outDir: "src/types", outDir: "src/types",
target: "ethers-v5", target: "ethers-v6",
}, },
docgen: { docgen: {
pages: "files", pages: "files",

View File

@ -9,10 +9,9 @@
"url": "https://github.com/doiim/p2pix-smart-contracts/issues" "url": "https://github.com/doiim/p2pix-smart-contracts/issues"
}, },
"scripts": { "scripts": {
"clean": "shx rm -rf ./artifacts ./cache ./coverage ./src/types ./coverage.json && yarn typechain", "clean": "hardhat clean",
"commit": "git-cz", "compile": "hardhat compile",
"compile": "cross-env TS_NODE_TRANSPILE_ONLY=true hardhat compile", "typechain": "hardhat typechain",
"typechain": "cross-env TS_NODE_TRANSPILE_ONLY=true hardhat typechain",
"test": "hardhat test", "test": "hardhat test",
"deploy1:localhost": "hardhat run scripts/1-deploy-mockToken.ts --network localhost", "deploy1:localhost": "hardhat run scripts/1-deploy-mockToken.ts --network localhost",
"deploy2:localhost": "hardhat run scripts/2-deploy-p2pix.ts --network localhost", "deploy2:localhost": "hardhat run scripts/2-deploy-p2pix.ts --network localhost",
@ -24,71 +23,49 @@
"lint": "yarn lint:sol && yarn lint:ts && yarn prettier:check", "lint": "yarn lint:sol && yarn lint:ts && yarn prettier:check",
"lint:sol": "solhint --config ./.solhint.json --max-warnings 0 \"contracts/**/*.sol\"", "lint:sol": "solhint --config ./.solhint.json --max-warnings 0 \"contracts/**/*.sol\"",
"lint:ts": "eslint --config ./.eslintrc.yaml --ignore-path ./.eslintignore --ext .js,.ts .", "lint:ts": "eslint --config ./.eslintrc.yaml --ignore-path ./.eslintignore --ext .js,.ts .",
"_postinstall": "husky install",
"postpublish": "pinst --enable",
"prepublishOnly": "pinst --disable",
"prettier": "prettier --config ./.prettierrc.yaml --write \"**/*.{js,json,md,sol,ts,yaml,yml}\"", "prettier": "prettier --config ./.prettierrc.yaml --write \"**/*.{js,json,md,sol,ts,yaml,yml}\"",
"prettier:check": "prettier --check --config ./.prettierrc.yaml \"**/*.{js,json,md,sol,ts,yaml,yml}\"" "prettier:check": "prettier --check --config ./.prettierrc.yaml \"**/*.{js,json,md,sol,ts,yaml,yml}\""
}, },
"devDependencies": { "devDependencies": {
"@commitlint/cli": "^17.2.0", "@ethersproject/abi": "^5.8.0",
"@commitlint/config-conventional": "^17.2.0", "@ethersproject/providers": "^5.8.0",
"@ethersproject/abi": "^5.7.0", "@nomicfoundation/hardhat-chai-matchers": "^2.1.0",
"@ethersproject/abstract-signer": "^5.7.0", "@nomicfoundation/hardhat-ethers": "^3.1.0",
"@ethersproject/bignumber": "^5.7.0", "@nomicfoundation/hardhat-ignition": "^0.15.13",
"@ethersproject/bytes": "^5.7.0", "@nomicfoundation/hardhat-ignition-ethers": "^0.15.14",
"@ethersproject/providers": "^5.7.2", "@nomicfoundation/hardhat-network-helpers": "^1.1.0",
"@nomicfoundation/hardhat-chai-matchers": "^1.0.4", "@nomicfoundation/hardhat-toolbox": "^6.1.0",
"@nomicfoundation/hardhat-network-helpers": "1.0.6", "@nomicfoundation/hardhat-verify": "^2.1.0",
"@nomicfoundation/hardhat-toolbox": "^2.0.0", "@nomicfoundation/hardhat-viem": "^2.1.0",
"@nomicfoundation/hardhat-viem": "^2.0.6", "@nomicfoundation/ignition-core": "^0.15.13",
"@nomiclabs/hardhat-ethers": "^2.2.3", "@typechain/ethers-v6": "^0.5.1",
"@nomiclabs/hardhat-etherscan": "^3.1.2", "@typechain/hardhat": "^9.1.0",
"@trivago/prettier-plugin-sort-imports": "^3.4.0", "@types/chai": "^4.3.20",
"@typechain/ethers-v5": "^10.1.1", "@types/mocha": "^10.0.10",
"@typechain/hardhat": "^6.1.4", "@types/node": "^24.1.0",
"@types/chai": "^4.3.3", "chai": "4.5.0",
"@types/fs-extra": "^9.0.13", "dotenv": "^16.6.1",
"@types/mocha": "^9.1.1", "eslint": "^9.32.0",
"@types/node": "^18.11.9", "eslint-config-prettier": "^10.1.8",
"@typescript-eslint/eslint-plugin": "^5.42.0", "ethers": "^6.15.0",
"@typescript-eslint/parser": "^5.42.0", "hardhat": "^2.26.1",
"chai": "^4.3.6", "hardhat-contract-sizer": "^2.10.0",
"chalk": "4.x", "hardhat-gas-reporter": "^2.3.0",
"commitizen": "^4.2.5",
"cross-env": "^7.0.3",
"cz-conventional-changelog": "^3.3.0",
"dotenv": "^16.0.3",
"eslint": "^8.26.0",
"eslint-config-prettier": "^8.5.0",
"ethers": "^5.7.2",
"fs-extra": "^10.1.0",
"hardhat": "^2.12.2",
"hardhat-contract-sizer": "^2.8.0",
"hardhat-gas-reporter": "^1.0.9",
"husky": "^8.0.1",
"keccak256": "^1.0.6", "keccak256": "^1.0.6",
"lint-staged": "^13.0.3",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"merkletreejs": "^0.2.32", "merkletreejs": "^0.5.2",
"mocha": "^10.1.0", "mocha": "^10.8.2",
"prettier": "^2.7.1", "solidity-coverage": "^0.8.16",
"prettier-plugin-solidity": "^1.0.0-rc.1",
"shx": "^0.3.4",
"solhint": "^3.3.7",
"solhint-plugin-prettier": "^0.0.5",
"solidity-coverage": "^0.8.2",
"solidity-docgen": "^0.6.0-beta.36", "solidity-docgen": "^0.6.0-beta.36",
"ts-generator": "^0.1.1", "ts-node": "^10.9.2",
"ts-node": "^10.9.1", "typechain": "^8.3.2",
"typechain": "^8.1.1", "typescript": "^5.8.3",
"typescript": "^5", "viem": "^2.33.1"
"viem": "^2.23.14"
}, },
"files": [ "files": [
"/contracts" "/contracts"
], ],
"packageManager": "yarn@3.2.1", "packageManager": "yarn@4.9.2",
"publishConfig": { "publishConfig": {
"access": "public" "access": "public"
} }

View File

@ -1,14 +1,11 @@
import "@nomiclabs/hardhat-ethers"; import "@nomicfoundation/hardhat-ethers";
import "@nomiclabs/hardhat-etherscan";
import { BigNumber } from "ethers";
import * as fs from "fs"; import * as fs from "fs";
import { ethers, network } from "hardhat"; import { ethers, network } from "hardhat";
import hre from "hardhat";
import { Deploys } from "../test/utils/interfaces"; import { Deploys } from "../test/utils/interfaces";
let deploysJson: Deploys; let deploysJson: Deploys;
const supply: BigNumber = ethers.utils.parseEther("20000000"); const supply: BigInt = ethers.parseEther("20000000");
const main = async () => { const main = async () => {
try { try {
@ -25,15 +22,11 @@ const main = async () => {
const [deployer] = await ethers.getSigners(); const [deployer] = await ethers.getSigners();
console.log(`Deploying contracts with ${deployer.address}`); console.log(`Deploying contracts with ${deployer.address}`);
const ERC20Factory = await ethers.getContractFactory( let erc20 = await ethers.deployContract("MockToken", [supply]);
"MockToken", erc20 = await erc20.waitForDeployment();
);
const erc20 = await ERC20Factory.deploy(supply);
await erc20.deployed();
deploysJson.token = erc20.address; deploysJson.token = await erc20.getAddress();
console.log("🚀 Mock Token Deployed:", erc20.address); console.log("🚀 Mock Token Deployed:", await erc20.getAddress());
await erc20.deployTransaction.wait(6);
fs.writeFileSync( fs.writeFileSync(
`./deploys/${network.name}.json`, `./deploys/${network.name}.json`,

View File

@ -1,8 +1,6 @@
import "@nomiclabs/hardhat-ethers"; import "@nomicfoundation/hardhat-ethers";
import "@nomiclabs/hardhat-etherscan";
import * as fs from "fs"; import * as fs from "fs";
import { ethers, network } from "hardhat"; import { ethers, network } from "hardhat";
import hre from "hardhat";
import { Deploys } from "../test/utils/interfaces"; import { Deploys } from "../test/utils/interfaces";
@ -23,32 +21,24 @@ const main = async () => {
const [deployer] = await ethers.getSigners(); const [deployer] = await ethers.getSigners();
console.log(`Deploying contracts with ${deployer.address}`); console.log(`Deploying contracts with ${deployer.address}`);
const Reputation = await ethers.getContractFactory( let reputation = await ethers.deployContract("Reputation");
"Reputation", let multicall = await ethers.deployContract("Multicall");
); let p2pix = await ethers.deployContract("P2PIX", [
const Multicall = await ethers.getContractFactory(
"Multicall",
);
const reputation = await Reputation.deploy();
await reputation.deployed();
const mutlicall = await Multicall.deploy();
await mutlicall.deployed();
const P2PIX = await ethers.getContractFactory("P2PIX");
const p2pix = await P2PIX.deploy(
10, 10,
deploysJson.signers, deploysJson.signers,
reputation.address, reputation.target,
[deploysJson.token], [deploysJson.token],
[true], [true],
); ]);
await p2pix.deployed();
deploysJson.p2pix = p2pix.address; reputation = await reputation.waitForDeployment();
console.log("🚀 P2PIX Deployed:", p2pix.address); multicall = await multicall.waitForDeployment();
console.log("🌠 Reputation Deployed:", reputation.address); p2pix = await p2pix.waitForDeployment();
console.log("🛰 Multicall Deployed:", mutlicall.address);
await p2pix.deployTransaction.wait(6); deploysJson.p2pix = await p2pix.getAddress();
console.log("🚀 P2PIX Deployed:", await p2pix.getAddress());
console.log("🌠 Reputation Deployed:", await reputation.getAddress());
console.log("🛰 Multicall Deployed:", await multicall.getAddress());
fs.writeFileSync( fs.writeFileSync(
`./deploys/${network.name}.json`, `./deploys/${network.name}.json`,

View File

@ -1,6 +1,6 @@
import "@nomicfoundation/hardhat-chai-matchers"; import "@nomicfoundation/hardhat-chai-matchers";
import { loadFixture } from "@nomicfoundation/hardhat-network-helpers"; import { loadFixture } from "@nomicfoundation/hardhat-network-helpers";
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; import { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers";
import { expect } from "chai"; import { expect } from "chai";
import { ethers, network } from "hardhat"; import { ethers, network } from "hardhat";
@ -15,7 +15,7 @@ describe("Reputation", () => {
before("Set signers and reset network", async () => { before("Set signers and reset network", async () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
[owner] = await (ethers as any).getSigners(); [owner] = await ethers.getSigners();
await network.provider.send("hardhat_reset"); await network.provider.send("hardhat_reset");
}); });
@ -60,7 +60,7 @@ describe("Reputation", () => {
}, },
{ {
x: Number.MAX_SAFE_INTEGER, x: Number.MAX_SAFE_INTEGER,
shouldRevert: "overflow", expected: curve(Number.MAX_SAFE_INTEGER),
}, },
{ {
x: Number.POSITIVE_INFINITY, x: Number.POSITIVE_INFINITY,

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; import { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers";
import { BigNumber, Signer } from "ethers"; import { Signer } from "ethers";
import { ethers } from "hardhat"; import { ethers } from "hardhat";
import keccak256 from "keccak256"; import keccak256 from "keccak256";
import { MerkleTree } from "merkletreejs"; import { MerkleTree } from "merkletreejs";
@ -14,7 +14,6 @@ import {
import { Call, RepFixture, P2PixAndReputation, DepositArgs, LockArgs, ReleaseArgs } from "./interfaces"; import { Call, RepFixture, P2PixAndReputation, DepositArgs, LockArgs, ReleaseArgs } from "./interfaces";
// exported constants // exported constants
export const getSignerAddrs = ( export const getSignerAddrs = (
amount: number, amount: number,
@ -23,16 +22,16 @@ export const getSignerAddrs = (
return addrs.slice(0, amount).map(({ address }) => address); return addrs.slice(0, amount).map(({ address }) => address);
}; };
export const getBnFrom = (nums: number[]): BigNumber[] => { export const getBnFrom = (nums: number[]): BigInt[] => {
const bns = nums.map(num => ethers.BigNumber.from(num)); const bns = nums.map(num => BigInt(num));
return bns; return bns;
}; };
export const getLockData = ( export const getLockData = (
addr: string, addr: string,
locks: BigNumber[][], locks: BigInt[][],
): Call[] => { ): Call[] => {
const iface = new ethers.utils.Interface( const iface = new ethers.Interface(
P2PIX__factory.abi, P2PIX__factory.abi,
); );
return locks.map(lock => ({ return locks.map(lock => ({
@ -72,13 +71,8 @@ export const curve = (x: number): number => {
// exported async functions // exported async functions
export async function repFixture(): Promise<RepFixture> { export async function repFixture(): Promise<RepFixture> {
const Reputation = await ethers.getContractFactory( const reputation = await ethers.deployContract("Reputation");
"Reputation", return { reputation: await reputation.waitForDeployment() };
);
const reputation =
(await Reputation.deploy()) as Reputation;
return { reputation };
} }
export async function p2pixFixture(): Promise<P2PixAndReputation> { export async function p2pixFixture(): Promise<P2PixAndReputation> {
@ -87,30 +81,21 @@ export async function p2pixFixture(): Promise<P2PixAndReputation> {
await ethers.getSigners(), await ethers.getSigners(),
); );
const Reputation = await ethers.getContractFactory( const reputation = await ethers.deployContract("Reputation");
"Reputation",
);
const reputation =
(await Reputation.deploy()) as Reputation;
const ERC20 = await ethers.getContractFactory("MockToken"); const erc20 = await ethers.deployContract("MockToken", [
const erc20 = (await ERC20.deploy( ethers.parseEther("20000000") // 20M
ethers.utils.parseEther("20000000"), // 20M ]) as MockToken;
)) as MockToken;
const P2PIX = await ethers.getContractFactory("P2PIX"); const p2pix = await ethers.deployContract("P2PIX", [
const p2pix = (await P2PIX.deploy(
10, 10,
validSigners, validSigners,
reputation.address, reputation.target,
[erc20.address], [erc20.target],
[true], [true],
)) as P2PIX; ]);
const Multicall = await ethers.getContractFactory( const multicall = await ethers.deployContract("Multicall");
"Multicall",
);
const multicall = (await Multicall.deploy()) as Multicall;
const signers = await ethers.getSigners(); const signers = await ethers.getSigners();
const whitelisted = signers.slice(0, 2); const whitelisted = signers.slice(0, 2);
@ -126,10 +111,10 @@ export async function p2pixFixture(): Promise<P2PixAndReputation> {
); );
return { return {
multicall, multicall: await multicall.waitForDeployment(),
reputation, reputation: await reputation.waitForDeployment(),
erc20, erc20: await erc20.waitForDeployment(),
p2pix, p2pix: await p2pix.waitForDeployment(),
merkleRoot, merkleRoot,
proof, proof,
}; };

View File

@ -1,5 +1,3 @@
import { BigNumber } from "ethers";
import { import {
MockToken, MockToken,
Multicall, Multicall,
@ -19,29 +17,29 @@ export interface DepositArgs {
pixTarget: string; pixTarget: string;
allowlistRoot: string; allowlistRoot: string;
token: string; token: string;
amount: BigNumber; amount: BigInt;
valid: boolean; valid: boolean;
} }
export interface LockArgs { export interface LockArgs {
seller: string; seller: string;
token: string; token: string;
amount: BigNumber; amount: BigInt;
merkleProof: string[]; merkleProof: string[];
expiredLocks: BigNumber[]; expiredLocks: BigInt[];
} }
export interface ReleaseArgs { export interface ReleaseArgs {
lockID: BigNumber; lockID: BigInt;
pixTimestamp: string; pixTimestamp: string;
signature: string; signature: string;
} }
export interface Lock { export interface Lock {
counter: BigNumber; counter: BigInt;
expirationBlock: BigNumber; expirationBlock: BigInt;
pixTarget: string; pixTarget: string;
amount: BigNumber; amount: BigInt;
token: string; token: string;
buyerAddress: string; buyerAddress: string;
seller: string; seller: string;

7454
yarn.lock

File diff suppressed because it is too large Load Diff