Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to ethers v6 #293

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 20.5.0
node-version: 22.3.0
- name: Installing dependencies
run: yarn install --frozen-lockfile
- name: Running tests
Expand Down
49 changes: 24 additions & 25 deletions benchmark/relay.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import '@nomiclabs/hardhat-ethers';
import '@nomicfoundation/hardhat-ethers';

import { parseUnits, solidityPackedKeccak256, toNumber, Wallet } from 'ethers';
import fs from 'fs';
import path from 'path';

import { ethers } from 'hardhat';
import path from 'path';

import { keccak256 } from '@ethersproject/solidity';
import { parseUnits } from '@ethersproject/units';
import { Wallet } from '@ethersproject/wallet';
import { HardhatEthersSigner } from '@nomicfoundation/hardhat-ethers/signers';
import { loadFixture } from '@nomicfoundation/hardhat-toolbox/network-helpers';

import { Bridge, TestERC20 } from '../typechain';
import { deployBridgeContracts, getAccounts, loadFixture } from '../test/lib/common';
import { deployBridgeContracts, getAccounts } from '../test/lib/common';
import { getRelayRequest } from '../test/lib/proto';
import { BigNumber } from '@ethersproject/bignumber';
import { Bridge, TestERC20 } from '../typechain';

const GAS_USAGE_DIR = 'reports/gas_usage/';
const GAS_USAGE_LOG = path.join(GAS_USAGE_DIR, 'relay.txt');
Expand All @@ -24,14 +22,15 @@ describe('Relay Gas Benchmark', function () {
fs.rmSync(GAS_USAGE_LOG, { force: true });
fs.appendFileSync(GAS_USAGE_LOG, '<validatorNum, quorumSigNum, gasCost> for cbr testErc20 relay tx\n\n');

async function fixture([admin]: Wallet[]) {
async function fixture() {
const [admin] = await ethers.getSigners();
const { bridge, token } = await deployBridgeContracts(admin);
return { admin, bridge, token };
}

let bridge: Bridge;
let token: TestERC20;
let admin: Wallet;
let admin: HardhatEthersSigner;
let accounts: Wallet[];

beforeEach(async () => {
Expand All @@ -40,10 +39,10 @@ describe('Relay Gas Benchmark', function () {
token = res.token;
admin = res.admin;
accounts = await getAccounts(admin, [token], 21);
await token.transfer(bridge.address, parseUnits('1000000'));
await bridge.setEpochVolumeCaps([token.address], [parseUnits('100')]);
await token.transfer(bridge.getAddress(), parseUnits('1000000'));
await bridge.setEpochVolumeCaps([token.getAddress()], [parseUnits('100')]);
await bridge.setEpochLength(5);
await bridge.setDelayThresholds([token.address], [parseUnits('100')])
await bridge.setDelayThresholds([token.getAddress()], [parseUnits('100')]);
});

it('benchmark relay gas cost for bridge', async function () {
Expand All @@ -62,10 +61,10 @@ describe('Relay Gas Benchmark', function () {
accounts: Wallet[],
signerNum: number,
quorumSigNum: number
): Promise<{ signers: Wallet[]; addrs: string[]; powers: BigNumber[] }> {
): Promise<{ signers: Wallet[]; addrs: string[]; powers: bigint[] }> {
const signers: Wallet[] = [];
const addrs: string[] = [];
const powers: BigNumber[] = [];
const powers: bigint[] = [];
for (let i = 0; i < signerNum; i++) {
signers.push(accounts[i]);
addrs.push(accounts[i].address);
Expand All @@ -85,9 +84,9 @@ describe('Relay Gas Benchmark', function () {
for (let i = 3; i <= maxQuorumSigNum; i += 2) {
const gasUsed = await doBenchmarkRelay(signerNum, i);
if (i == 3) {
firstCost = gasUsed.toNumber();
firstCost = toNumber(gasUsed);
}
lastCost = gasUsed.toNumber();
lastCost = toNumber(gasUsed);
}
const perSigCost = Math.ceil((lastCost - firstCost) / (maxQuorumSigNum - 3));
return perSigCost;
Expand All @@ -100,9 +99,9 @@ describe('Relay Gas Benchmark', function () {
for (let i = minSignerNum; i <= maxSignerNum; i++) {
const gasUsed = await doBenchmarkRelay(i, quorumSigNum);
if (i == minSignerNum) {
firstCost = gasUsed.toNumber();
firstCost = toNumber(gasUsed);
}
lastCost = gasUsed.toNumber();
lastCost = toNumber(gasUsed);
}
const perSignerCost = Math.ceil((lastCost - firstCost) / (maxSignerNum - minSignerNum));
return perSignerCost;
Expand All @@ -119,20 +118,20 @@ describe('Relay Gas Benchmark', function () {
const sender = accounts[0];
const receiver = accounts[1];
const amount = parseUnits('1');
const chainId = (await ethers.provider.getNetwork()).chainId;
const srcXferId = keccak256(['uint64'], [Date.now()]); // fake src xfer id
const chainId = toNumber((await ethers.provider.getNetwork()).chainId);
const srcXferId = solidityPackedKeccak256(['uint64'], [Date.now()]); // fake src xfer id
const { relayBytes, sigs } = await getRelayRequest(
sender.address,
receiver.address,
token.address,
await token.getAddress(),
amount,
chainId,
chainId,
srcXferId,
signers,
bridge.address
await bridge.getAddress()
);
const gasUsed = (await (await bridge.relay(relayBytes, sigs, addrs, powers)).wait()).gasUsed;
const gasUsed = (await (await bridge.relay(relayBytes, sigs, addrs, powers)).wait())!.gasUsed;
fs.appendFileSync(GAS_USAGE_LOG, signerNum.toString() + '\t' + quorumSigNum.toString() + '\t' + gasUsed + '\n');
return gasUsed;
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/liquidity-bridge/Signers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ contract Signers is Ownable, ISigsVerifier {
// reset can be called by the owner address for emergency recovery
uint256 public resetTime;
uint256 public noticePeriod; // advance notice period as seconds for reset
uint256 constant MAX_INT = 2**256 - 1;
uint256 constant MAX_INT = 2 ** 256 - 1;

event SignersUpdated(address[] _signers, uint256[] _powers);

Expand Down
7 changes: 5 additions & 2 deletions deploy/message/000_message_bus_init.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as dotenv from 'dotenv';
import { AbiCoder } from 'ethers/lib/utils';
import { AbiCoder } from 'ethers';
import { DeployFunction } from 'hardhat-deploy/types';
import { HardhatRuntimeEnvironment } from 'hardhat/types';

Expand Down Expand Up @@ -51,7 +51,10 @@ const deployFunc: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
// await hre.run('verify:verify', { address: proxy.address, constructorArguments: proxyArgs });
console.log(
'Encoded proxy constructor args',
new AbiCoder().encode(['address', 'address', 'bytes'], [messageBus.address, proxyAdmin.address, encodedInitData])
AbiCoder.defaultAbiCoder().encode(
['address', 'address', 'bytes'],
[messageBus.address, proxyAdmin.address, encodedInitData]
)
);
};

Expand Down
7 changes: 5 additions & 2 deletions deploy/sentinel/000_sentinel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as dotenv from 'dotenv';
import { AbiCoder } from 'ethers/lib/utils';
import { AbiCoder } from 'ethers';
import { DeployFunction } from 'hardhat-deploy/types';
import { HardhatRuntimeEnvironment } from 'hardhat/types';

Expand Down Expand Up @@ -47,7 +47,10 @@ const deployFunc: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
// await hre.run('verify:verify', { address: proxy.address, constructorArguments: proxyArgs });
console.log(
'Encoded proxy constructor args',
new AbiCoder().encode(['address', 'address', 'bytes'], [sentinel.address, proxyAdmin.address, encodedInitData])
AbiCoder.defaultAbiCoder().encode(
['address', 'address', 'bytes'],
[sentinel.address, proxyAdmin.address, encodedInitData]
)
);
};

Expand Down
32 changes: 16 additions & 16 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import '@nomiclabs/hardhat-ethers';
import '@nomicfoundation/hardhat-ethers';
import '@nomicfoundation/hardhat-toolbox';
import '@nomicfoundation/hardhat-verify';
import '@nomiclabs/hardhat-waffle';
import '@typechain/hardhat';
import 'hardhat-contract-sizer';
import 'hardhat-deploy';
import 'hardhat-gas-reporter';
import 'hardhat-signer-kms';
import '@oasisprotocol/sapphire-hardhat';
import '@rumblefishdev/hardhat-kms-signer';
import '@matterlabs/hardhat-zksync-deploy';
import '@matterlabs/hardhat-zksync-solc';
// Imports the verify plugin before the upgradable plugin
Expand Down Expand Up @@ -459,7 +459,7 @@ const config: HardhatUserConfig = {
},
typechain: {
outDir: 'typechain',
target: 'ethers-v5'
target: 'ethers-v6'
},
etherscan: {
apiKey: {
Expand Down Expand Up @@ -532,15 +532,15 @@ const config: HardhatUserConfig = {
}
};

if (config.networks?.polygon) {
config.networks.polygon.minMaxPriorityFeePerGas = 30000000000;
}
if (config.networks?.fantom) {
config.networks.fantom.minMaxPriorityFeePerGas = 30000000000;
}
if (config.networks?.bsc) {
config.networks.bsc.minMaxPriorityFeePerGas = 3000000000;
config.networks.bsc.minMaxFeePerGas = 3000000000;
}

export default config;
// if (config.networks?.polygon) {
// config.networks.polygon.minMaxPriorityFeePerGas = 30000000000;
// }
// if (config.networks?.fantom) {
// config.networks.fantom.minMaxPriorityFeePerGas = 30000000000;
// }
// if (config.networks?.bsc) {
// config.networks.bsc.minMaxPriorityFeePerGas = 3000000000;
// config.networks.bsc.minMaxFeePerGas = 3000000000;
// }

export default config;
81 changes: 44 additions & 37 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,48 +21,55 @@
},
"homepage": "https://github.com/celer-network/sgn-v2-contracts#readme",
"devDependencies": {
"@nomiclabs/hardhat-ethers": "npm:hardhat-deploy-ethers",
"@nomiclabs/hardhat-waffle": "^2.0.6",
"@oasisprotocol/sapphire-hardhat": "^2.16.1",
"@aws-sdk/client-kms": "^3.606.0",
"@nomicfoundation/hardhat-chai-matchers": "^2.0.7",
"@nomicfoundation/hardhat-ignition": "^0.15.5",
"@nomicfoundation/hardhat-ignition-ethers": "^0.15.0",
"@nomicfoundation/hardhat-network-helpers": "^1.0.11",
"@nomicfoundation/hardhat-toolbox": "^5.0.0",
"@nomicfoundation/ignition-core": "^0.15.5",
"@oasisprotocol/sapphire-hardhat": "^2.19.4",
"@openzeppelin/contracts": "4.5.0",
"@openzeppelin/contracts-upgradeable": "4.5.0",
"@openzeppelin/hardhat-upgrades": "^2.1.1",
"@openzeppelin/upgrades-core": "1.27.3",
"@typechain/ethers-v5": "^11.1.0",
"@typechain/hardhat": "^8.0.2",
"@types/chai": "^4.3.5",
"@types/mocha": "^10.0.1",
"@types/node": "^20.4.2",
"@types/sinon-chai": "^3.2.9",
"@typescript-eslint/eslint-plugin": "^6.1.0",
"@typescript-eslint/parser": "^6.1.0",
"chai": "^4.3.7",
"eslint": "^8.45.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-import": "^2.27.5",
"ethereum-waffle": "^4.0.10",
"ethers": "^5.7.2",
"fs-extra": "^11.1.1",
"hardhat": "^2.17.0",
"@openzeppelin/hardhat-upgrades": "^3.2.0",
"@openzeppelin/upgrades-core": "^1.34.1",
"@typechain/ethers-v5": "^11.1.2",
"@typechain/ethers-v6": "^0.5.1",
"@typechain/hardhat": "^9.1.0",
"@types/chai": "^4.3.16",
"@types/mocha": "^10.0.7",
"@types/node": "^20.14.9",
"@types/sinon-chai": "^3.2.12",
"@typescript-eslint/eslint-plugin": "^7.14.1",
"@typescript-eslint/parser": "^7.14.1",
"chai": "^4.4.1",
"eslint": "^9.6.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"ethers": "^6.13.1",
"fs-extra": "^11.2.0",
"hardhat": "^2.22.5",
"hardhat-contract-sizer": "^2.10.0",
"hardhat-deploy": "^0.11.34",
"hardhat-gas-reporter": "^1.0.9",
"husky": "^8.0.3",
"prettier": "^3.0.0",
"prettier-plugin-solidity": "^1.1.3",
"protobufjs": "^7.2.4",
"hardhat-deploy": "^0.12.4",
"hardhat-deploy-ethers": "^0.4.2",
"hardhat-gas-reporter": "^2.2.0",
"husky": "^9.0.11",
"prettier": "^3.3.2",
"prettier-plugin-solidity": "^1.3.1",
"protobufjs": "^7.3.2",
"solc": "0.8.17",
"ts-node": "^10.9.1",
"typechain": "^8.3.0",
"typescript": "^5.1.6"
"solidity-coverage": "^0.8.1",
"ts-node": "^10.9.2",
"typechain": "^8.3.2",
"typescript": "^5.5.2"
},
"dependencies": {
"@matterlabs/hardhat-zksync-solc": "^0.4.1",
"@matterlabs/hardhat-zksync-upgradable": "^0.1.2",
"@matterlabs/hardhat-zksync-verify": "^0.2.0",
"@nomicfoundation/hardhat-verify": "^1.1.1",
"@rumblefishdev/hardhat-kms-signer": "1.1.2",
"aws-sdk": "2.1419.0",
"dotenv": "^16.3.1"
"@matterlabs/hardhat-zksync-solc": "^1.2.0",
"@matterlabs/hardhat-zksync-upgradable": "^1.5.1",
"@matterlabs/hardhat-zksync-verify": "^1.5.0",
"@nomicfoundation/hardhat-ethers": "^3.0.6",
"@nomicfoundation/hardhat-verify": "^2.0.8",
"dotenv": "^16.4.5",
"hardhat-signer-kms": "^1.2.1"
}
}
Loading
Loading