diff --git a/packages/hardhat-plugin/package.json b/packages/hardhat-plugin/package.json index 59685230b472..daaf06e08bf3 100644 --- a/packages/hardhat-plugin/package.json +++ b/packages/hardhat-plugin/package.json @@ -19,11 +19,10 @@ "lint": "eslint --resolve-plugins-relative-to ../eslint-config --ext .tsx,.ts,.js src/ test/", "test": "ts-mocha --exit --recursive 'test/**/*.ts'", "ci": "yarn build && yarn lint && yarn test", - "build": "yarn networks && tsc", + "build": "tsc", "watch": "tsc -w", "clean": "rm -rf dist test/fixture-projects/hardhat-project/.openzeppelin test/fixture-projects/hardhat-project/artifacts test/fixture-projects/hardhat-project/cache test/fixture-projects/hardhat-project/contracts", - "prepublishOnly": "yarn clean && yarn build", - "networks": "node scripts/parseNetworks.js" + "prepublishOnly": "yarn clean && yarn build" }, "files": [ "dist/src/**/*", @@ -36,8 +35,7 @@ "directory": "packages/hardhat-plugin" }, "devDependencies": { - "@types/chai": "4.3.14", - "@types/fs-extra": "11.0.4", + "@types/chai": "4.3.12", "@types/mocha": "10.0.6", "@types/node": "20.10.1", "@unlock-protocol/contracts": "workspace:^", diff --git a/packages/hardhat-plugin/scripts/parseNetworks.js b/packages/hardhat-plugin/scripts/parseNetworks.js deleted file mode 100644 index 0ae9998ef0cb..000000000000 --- a/packages/hardhat-plugin/scripts/parseNetworks.js +++ /dev/null @@ -1,18 +0,0 @@ -const { networks } = require('@unlock-protocol/networks') -const fs = require('fs-extra') - -const keysToIgnore = ['publicProvider', 'provider'] - -const filePath = './src/networks.json' -const filtered = {} - -Object.keys(networks).forEach((chainId) => { - if (chainId === 'networks') return - const net = networks[chainId] - keysToIgnore.forEach((k) => delete net[k]) - filtered[chainId] = net -}) - -fs.outputJSONSync(filePath, filtered, { spaces: 2 }) - -console.log(`networks saved to ${filePath}.`) diff --git a/packages/hardhat-plugin/src/index.ts b/packages/hardhat-plugin/src/index.ts index 164be28a012d..5fdcf9349a59 100644 --- a/packages/hardhat-plugin/src/index.ts +++ b/packages/hardhat-plugin/src/index.ts @@ -8,7 +8,7 @@ import './type-extensions' import { TASK_CREATE_LOCK } from './constants' import { deployLockTask } from './tasks' -import networks from './networks.json' +import { networks as defaultNetworks } from '@unlock-protocol/networks' // types import { UnlockNetworkConfigs } from './types' @@ -31,6 +31,15 @@ export interface HardhatUnlockPlugin { networks: UnlockNetworkConfigs } +// parse networks to remove providers +const networks = Object.keys(defaultNetworks).reduce((parsed, chainId) => { + const { publicProvider, provider, ...network } = defaultNetworks[chainId] + return { + ...parsed, + [chainId]: network, + } +}, {}) + extendEnvironment((hre) => { hre.unlock = lazyObject(() => { const { createLock } = require('./createLock') diff --git a/packages/hardhat-plugin/src/utils.ts b/packages/hardhat-plugin/src/utils.ts index c2011828f7df..55bbf1938ace 100644 --- a/packages/hardhat-plugin/src/utils.ts +++ b/packages/hardhat-plugin/src/utils.ts @@ -1,9 +1,10 @@ import { contracts } from '@unlock-protocol/contracts' import { HardhatRuntimeEnvironment } from 'hardhat/types' import type { Signer, Contract, ContractFactory } from 'ethers' - -import fs from 'fs-extra' -import path from 'path' +import { + bytecode as proxyBytecode, + abi as proxyAbi, +} from './abis/ERC1967Proxy.json' export const contractExists = (contractName: string, versionNumber: number) => { // make sure contract exists @@ -58,9 +59,6 @@ export async function deployUpgreadableContract( const data = impl.interface.encodeFunctionData(fragment, initializerArguments) // deploy proxy - const { bytecode: proxyBytecode, abi: proxyAbi } = await fs.readJSON( - path.join(__dirname, 'abis', 'ERC1967Proxy.json') - ) const ERC1967Proxy = await hre.ethers.getContractFactory( proxyAbi, proxyBytecode, diff --git a/packages/hardhat-plugin/test/fixture-projects/hardhat-project/hardhat.config.ts b/packages/hardhat-plugin/test/fixture-projects/hardhat-project/hardhat.config.ts index 703918d9c94e..989396591745 100644 --- a/packages/hardhat-plugin/test/fixture-projects/hardhat-project/hardhat.config.ts +++ b/packages/hardhat-plugin/test/fixture-projects/hardhat-project/hardhat.config.ts @@ -17,8 +17,9 @@ const config: HardhatUserConfig = { }, defaultNetwork: 'hardhat', unlock: { - 31337: { - name: 'Custom Localhost Name', + // extend an existing network + 100: { + name: 'Custom Polygon Name', subgraph: { endpoint: 'here goes a subgraph URI', }, diff --git a/packages/hardhat-plugin/test/index.test.ts b/packages/hardhat-plugin/test/index.test.ts index aaa8e9ef1a45..f72b310af4e6 100644 --- a/packages/hardhat-plugin/test/index.test.ts +++ b/packages/hardhat-plugin/test/index.test.ts @@ -41,13 +41,11 @@ describe('Unlock Hardhat plugin', function () { assert.equal(this.hre.unlock.networks['1'].unlockAddress, 'newAddress') }) it('should store additional networks info', function () { - assert.isTrue(Object.keys(this.hre.unlock.networks).includes('31337')) + assert.isTrue(Object.keys(this.hre.unlock.networks).includes('100')) + assert.isTrue(Object.keys(this.hre.unlock.networks).includes('12345')) + assert.equal(this.hre.unlock.networks['100'].name, 'Custom Polygon Name') assert.equal( - this.hre.unlock.networks['31337'].name, - 'Custom Localhost Name' - ) - assert.equal( - this.hre.unlock.networks['31337'].subgraph?.endpoint, + this.hre.unlock.networks['100'].subgraph?.endpoint, 'here goes a subgraph URI' ) }) @@ -218,12 +216,12 @@ describe('HardhatConfig unlock extension', function () { assert.isTrue(Object.keys(this.hre.config).includes('unlock')) assert.deepEqual( Object.keys(this.hre.config.unlock).sort(), - [...Object.keys(networks), '12345', '31337'].sort() + [...Object.keys(networks), '12345'].sort() ) }) it('Should allow user to configure exsiting network', function () { - assert.equal(this.hre.config.unlock['31337'].name, 'Custom Localhost Name') + assert.equal(this.hre.config.unlock['100'].name, 'Custom Polygon Name') }) it('Should allow user to pass a new network', function () {