From 3124f000984c2952e8bb176e1b7966531b68f6b7 Mon Sep 17 00:00:00 2001 From: Kostiantyn Smyrnov Date: Mon, 15 May 2023 13:39:17 +0200 Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20Ethers=20removed=20f?= =?UTF-8?q?rom=20exports;=20Types=20for=20ethers-v6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintignore | 2 ++ .gitignore | 1 + .lintstagedrc | 2 +- .prettierignore | 1 + deploy/001.ts | 2 +- deploy/002.ts | 2 +- package.json | 3 ++- src/constants.ts | 27 ++++--------------------- test/contracts/EntitiesRegistry.test.ts | 2 +- test/contracts/Market.test.ts | 4 ++-- test/contracts/setup.ts | 2 +- test/contracts/utils.ts | 2 +- utils/constants.ts | 18 +++++++++++++++++ src/utils.ts => utils/index.ts | 2 +- {src => utils}/types.ts | 0 yarn.lock | 8 ++++++++ 16 files changed, 45 insertions(+), 33 deletions(-) create mode 100644 utils/constants.ts rename src/utils.ts => utils/index.ts (99%) rename {src => utils}/types.ts (100%) diff --git a/.eslintignore b/.eslintignore index ca85851..438afea 100644 --- a/.eslintignore +++ b/.eslintignore @@ -11,3 +11,5 @@ cache-zk artifacts cache ./**/*.sol +typechain +typechainV6 diff --git a/.gitignore b/.gitignore index 4ce679a..89ef88e 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,5 @@ cache-zk artifacts cache typechain +typechainV6 network/volumes diff --git a/.lintstagedrc b/.lintstagedrc index 6281268..4f7169e 100644 --- a/.lintstagedrc +++ b/.lintstagedrc @@ -1,4 +1,4 @@ { - "*.{ts,js}": ["prettier --write", "eslint --cache --fix"], + "*.{ts,js}": ["prettier --write", "eslint --config ./.eslintrc --ignore-path ./.eslintignore --cache --fix"], "*.md": ["prettier --write"] } diff --git a/.prettierignore b/.prettierignore index 238b8d5..07ad045 100644 --- a/.prettierignore +++ b/.prettierignore @@ -13,3 +13,4 @@ artifacts cache network typechain +typechainV6 diff --git a/deploy/001.ts b/deploy/001.ts index 67dec8b..a85ebd2 100644 --- a/deploy/001.ts +++ b/deploy/001.ts @@ -9,7 +9,7 @@ import { protocolFee, retailerFee, minDeposit, -} from '../src'; +} from '../utils/constants'; const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { const { network, deployments, getNamedAccounts } = hre; diff --git a/deploy/002.ts b/deploy/002.ts index 5173a76..2e11e2d 100644 --- a/deploy/002.ts +++ b/deploy/002.ts @@ -9,7 +9,7 @@ import { protocolFee, retailerFee, minDeposit, -} from '../src'; +} from '../utils/constants'; const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { const { network, deployments, getNamedAccounts } = hre; diff --git a/package.json b/package.json index f8cf0cf..f2745dc 100644 --- a/package.json +++ b/package.json @@ -89,6 +89,7 @@ "typechain": "^8.1.1", "@typechain/hardhat": "^6.1.6", "@typechain/ethers-v5": "^10.2.1", + "@typechain/ethers-v6": "^0.3.2", "dotenv": "^16.0.3" }, "dependencies": { @@ -96,7 +97,7 @@ }, "scripts": { "build:contracts": "hardhat compile", - "build:src": "rm -rf ./lib && tsc -p ./tsconfig.build.json", + "build:src": "rm -rf ./lib && typechain --target=ethers-v6 --out-dir typechainV6 artifacts/**/Config.json artifacts/**/EntitiesRegistry.json artifacts/**/Market.json && tsc -p ./tsconfig.build.json", "test:contracts": "hardhat test", "test:src": "mocha -t 60000 --extension spec.ts test/src", "lint": "solhint . && eslint --ext .ts", diff --git a/src/constants.ts b/src/constants.ts index 3d25db2..842e56f 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,20 +1,18 @@ -import { utils, BigNumber } from 'ethers'; - -// utils.solidityKeccak256( +// ethers.solidityPackedKeccak256( // ['string'], // ['PaymentOption(bytes32 id,uint256 price,address asset)'], // ); export const PAYMENT_OPTION_TYPE_HASH = '0x2f8fc0b3ad3f58f6deb367673d38e4112a3c8c64de033c5b780b84ef8f67cde6'; -// utils.solidityKeccak256( +// ethers.solidityPackedKeccak256( // ['string'], // ['CancelOption(uint256 time,uint256 penalty)'], // ); export const CANCEL_OPTION_TYPE_HASH = '0x8ea27057ea8a0239f02c8b75748218a035a5a2a2a0785b53aaa99af91ff538c5'; -// utils.solidityKeccak256( +// ethers.solidityPackedKeccak256( // ['string'], // [ // 'Offer(bytes32 id,uint256 expire,bytes32 supplierId,uint256 chainId,bytes32 requestHash,bytes32 optionsHash,bytes32 paymentHash,bytes32 cancelHash,bool transferable,uint256 checkIn)', @@ -23,7 +21,7 @@ export const CANCEL_OPTION_TYPE_HASH = export const OFFER_TYPE_HASH = '0xcf2addd2f89a78825d3f130a17e47b4e9963adfd09837fa9c454569faa073354'; -// utils.solidityKeccak256( +// ethers.solidityPackedKeccak256( // ['string'], // [ // 'Voucher(bytes32 id,address signer)', @@ -31,20 +29,3 @@ export const OFFER_TYPE_HASH = // ); export const CHECK_IN_TYPE_HASH = '0xf811d7f3ddb148410001929e2cbfb7fea8779b9349b7c2f650fa91840528d69c'; - -// Protocol entities types (kinds) as object -export const kinds = { - supplier: utils.formatBytes32String('supplier'), - retailer: utils.formatBytes32String('retailer'), -}; - -// Protocol entities types (kinds) as values array -export const kindsArr = Object.values(kinds); - -// Protocol defaults -export const eip712name = 'Market'; -export const eip712version = '1'; -export const minDeposit = BigNumber.from('1000000000000000000000'); -export const claimPeriod = BigNumber.from('60'); -export const protocolFee = BigNumber.from('1'); -export const retailerFee = BigNumber.from('1'); diff --git a/test/contracts/EntitiesRegistry.test.ts b/test/contracts/EntitiesRegistry.test.ts index f8c5c1c..8bf0793 100644 --- a/test/contracts/EntitiesRegistry.test.ts +++ b/test/contracts/EntitiesRegistry.test.ts @@ -1,6 +1,6 @@ import { expect } from 'chai'; import { BigNumber, constants } from 'ethers'; -import { minDeposit, kinds } from '../../src'; +import { minDeposit, kinds } from '../../utils/constants'; import { randomId, createSupplierId, createPermitSignature } from './utils'; import { User, setup, registerEntity } from './setup'; diff --git a/test/contracts/Market.test.ts b/test/contracts/Market.test.ts index d10f06e..efa16c1 100644 --- a/test/contracts/Market.test.ts +++ b/test/contracts/Market.test.ts @@ -2,8 +2,8 @@ import { expect } from 'chai'; import { BigNumber, constants } from 'ethers'; import { ethers } from 'hardhat'; import { TransferEventObject } from '../../typechain/contracts/Market'; -import { kinds } from '../../src'; -import { Offer } from '../../src/types'; +import { kinds } from '../../utils/constants'; +import { Offer } from '../../utils/types'; import { structEqual, buildRandomOffer, diff --git a/test/contracts/setup.ts b/test/contracts/setup.ts index 7042aac..6ae00b8 100644 --- a/test/contracts/setup.ts +++ b/test/contracts/setup.ts @@ -8,7 +8,7 @@ import { } from '../../typechain'; import { ethers, deployments, getNamedAccounts } from 'hardhat'; import { BigNumber, Contract, VoidSigner } from 'ethers'; -import { protocolFee, retailerFee, minDeposit } from '../../src'; +import { protocolFee, retailerFee, minDeposit } from '../../utils/constants'; import { structEqual, createSupplierId } from './utils'; export interface Contracts { diff --git a/test/contracts/utils.ts b/test/contracts/utils.ts index 96627a9..92956e8 100644 --- a/test/contracts/utils.ts +++ b/test/contracts/utils.ts @@ -19,7 +19,7 @@ import { OfferPayload, Offer, Request, -} from '../../src/types'; +} from '../../utils/types'; export const nonces: Record = { request: 1, diff --git a/utils/constants.ts b/utils/constants.ts new file mode 100644 index 0000000..0dec761 --- /dev/null +++ b/utils/constants.ts @@ -0,0 +1,18 @@ +import { utils, BigNumber } from 'ethers'; + +// Protocol entities types (kinds) as object +export const kinds = { + supplier: utils.formatBytes32String('supplier'), + retailer: utils.formatBytes32String('retailer'), +}; + +// Protocol entities types (kinds) as values array +export const kindsArr = Object.values(kinds); + +// Protocol defaults +export const eip712name = 'Market'; +export const eip712version = '1'; +export const minDeposit = BigNumber.from('1000000000000000000000'); +export const claimPeriod = BigNumber.from('60'); +export const protocolFee = BigNumber.from('1'); +export const retailerFee = BigNumber.from('1'); diff --git a/src/utils.ts b/utils/index.ts similarity index 99% rename from src/utils.ts rename to utils/index.ts index 465605c..ad897ae 100644 --- a/src/utils.ts +++ b/utils/index.ts @@ -4,7 +4,7 @@ import { PAYMENT_OPTION_TYPE_HASH, CANCEL_OPTION_TYPE_HASH, OFFER_TYPE_HASH, -} from './constants'; +} from '../src/constants'; import { MockERC20Dec18Permit } from '../typechain'; import { PaymentOption, CancelOption, OfferPayload, Offer, Request } from './types'; diff --git a/src/types.ts b/utils/types.ts similarity index 100% rename from src/types.ts rename to utils/types.ts diff --git a/yarn.lock b/yarn.lock index b62f921..87bd845 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1536,6 +1536,14 @@ lodash "^4.17.15" ts-essentials "^7.0.1" +"@typechain/ethers-v6@^0.3.2": + version "0.3.2" + resolved "https://registry.yarnpkg.com/@typechain/ethers-v6/-/ethers-v6-0.3.2.tgz#c7c9ed2cbe6869a131e55646ce775e3673f0c123" + integrity sha512-LUxAVAHICc6lROLf16JIl/j0FVuCQ93qLkGxlVFM1QCN5V4QRUE2scNwhKLIh8urik1c0FcvFujOPtBV4erqYg== + dependencies: + lodash "^4.17.15" + ts-essentials "^7.0.1" + "@typechain/hardhat@^6.1.6": version "6.1.6" resolved "https://registry.yarnpkg.com/@typechain/hardhat/-/hardhat-6.1.6.tgz#1a749eb35e5054c80df531cf440819cb347c62ea"