diff --git a/docker/development/eth-node/package.json b/docker/development/eth-node/package.json index 378784aab02..0c9121542ff 100644 --- a/docker/development/eth-node/package.json +++ b/docker/development/eth-node/package.json @@ -10,9 +10,8 @@ }, "dependencies": { "@nomiclabs/hardhat-ethers": "2.2.3", - "@unlock-protocol/hardhat-plugin": "0.1.3", - "@unlock-protocol/contracts": "0.0.22", - "@unlock-protocol/contracts": "0.0.22", + "@unlock-protocol/hardhat-plugin": "latest", + "@unlock-protocol/contracts": "latest", "eslint": "8.54.0", "ethers": "5.7.2", "hardhat": "2.20.1", diff --git a/packages/contracts/.gitignore b/packages/contracts/.gitignore index 0493baba79e..53fe443e558 100644 --- a/packages/contracts/.gitignore +++ b/packages/contracts/.gitignore @@ -3,4 +3,5 @@ test/contracts artifacts cache docs-reorg -docs \ No newline at end of file +docs +src/index.ts \ No newline at end of file diff --git a/packages/contracts/CHANGELOG.md b/packages/contracts/CHANGELOG.md index 0ad60d5fe1b..eab934f2a32 100644 --- a/packages/contracts/CHANGELOG.md +++ b/packages/contracts/CHANGELOG.md @@ -1,5 +1,11 @@ # CHANGELOG +## 0.0.22 + +- add `contracts` alias for all versions +- add `PublicLock` and `Unlock` alias for all versions +- add version numbers as constant + ## 0.0.21 - release fix post-attack on Fri Apr 21st 2023 #11690 diff --git a/packages/contracts/README.md b/packages/contracts/README.md index dc9b4e9a027..bba411ecf67 100644 --- a/packages/contracts/README.md +++ b/packages/contracts/README.md @@ -3,12 +3,22 @@ ### Javascript usage ```js -// get latest -import unlock from '@unlock-protocol/contracts/Unlock' - -// get previous versions -import unlock from '@unlock-protocol/contracts/UnlockV0' -import { UnlockV0 } from '@unlock-protocol/contracts' +// get latest version +import { Unlock } from '@unlock-protocol/contracts' +import { PublicLock } from '@unlock-protocol/contracts' + +// a previous version +import UnlockV12 from '@unlock-protocol/contracts/UnlockV12' +import { UnlockV12 } from '@unlock-protocol/contracts' + +// all contracts +import { contracts } from '@unlock-protocol/contracts' + +// the number of latest versions available +import { + PUBLICLOCK_LATEST_VERSION, + UNLOCK_LATEST_VERSION, +} from '@unlock-protocol/contracts' ``` ### Solidity usage diff --git a/packages/contracts/package.json b/packages/contracts/package.json index 1318793f049..3aac5ca197e 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -1,14 +1,14 @@ { "name": "@unlock-protocol/contracts", - "version": "0.0.21", + "version": "0.0.24", "main": "dist/index.js", "scripts": { - "clean": "rm -rf dist docs", + "clean": "rm -rf dist docs src/index.ts", "test": "hardhat test", "abi:cleanup": "yarn clean && tsc && node dist/utils/cleanup.js", - "build": "yarn build:index && yarn build:dist", - "build:dist": "yarn clean && tsc && yarn contracts:copy && yarn docs && yarn docs:copy", - "build:index": "yarn clean && tsc && node dist/utils/parser.js > src/index.ts", + "build": "yarn clean && yarn build:index && yarn build:dist", + "build:dist": "yarn contracts:copy && yarn docs && yarn docs:copy", + "build:index": "tsc && node dist/parser.js > src/index.ts && tsc", "ci": "yarn test", "lint": "eslint --resolve-plugins-relative-to ../eslint-config --ext .ts,.js src/", "contracts:copy": "copyfiles --verbose -u 2 src/**/*.sol dist", diff --git a/packages/contracts/src/index.ts b/packages/contracts/src/index.ts deleted file mode 100644 index 078391ede36..00000000000 --- a/packages/contracts/src/index.ts +++ /dev/null @@ -1,85 +0,0 @@ -// This file is generated, please don't edit directly -// Refer to 'utils/parser.ts' and 'yarn build:index' for more - -import PublicLockV0 from './abis/PublicLock/PublicLockV0.json' -import PublicLockV1 from './abis/PublicLock/PublicLockV1.json' -import PublicLockV10 from './abis/PublicLock/PublicLockV10.json' -import PublicLockV11 from './abis/PublicLock/PublicLockV11.json' -import PublicLockV12 from './abis/PublicLock/PublicLockV12.json' -import PublicLockV13 from './abis/PublicLock/PublicLockV13.json' -import PublicLockV14 from './abis/PublicLock/PublicLockV14.json' -import PublicLockV2 from './abis/PublicLock/PublicLockV2.json' -import PublicLockV3 from './abis/PublicLock/PublicLockV3.json' -import PublicLockV4 from './abis/PublicLock/PublicLockV4.json' -import PublicLockV5 from './abis/PublicLock/PublicLockV5.json' -import PublicLockV6 from './abis/PublicLock/PublicLockV6.json' -import PublicLockV7 from './abis/PublicLock/PublicLockV7.json' -import PublicLockV8 from './abis/PublicLock/PublicLockV8.json' -import PublicLockV9 from './abis/PublicLock/PublicLockV9.json' -import UnlockV0 from './abis/Unlock/UnlockV0.json' -import UnlockV1 from './abis/Unlock/UnlockV1.json' -import UnlockV10 from './abis/Unlock/UnlockV10.json' -import UnlockV11 from './abis/Unlock/UnlockV11.json' -import UnlockV12 from './abis/Unlock/UnlockV12.json' -import UnlockV13 from './abis/Unlock/UnlockV13.json' -import UnlockV2 from './abis/Unlock/UnlockV2.json' -import UnlockV3 from './abis/Unlock/UnlockV3.json' -import UnlockV4 from './abis/Unlock/UnlockV4.json' -import UnlockV5 from './abis/Unlock/UnlockV5.json' -import UnlockV6 from './abis/Unlock/UnlockV6.json' -import UnlockV7 from './abis/Unlock/UnlockV7.json' -import UnlockV8 from './abis/Unlock/UnlockV8.json' -import UnlockV9 from './abis/Unlock/UnlockV9.json' -import UnlockDiscountTokenV0 from './abis/UnlockDiscountToken/UnlockDiscountTokenV0.json' -import UnlockDiscountTokenV1 from './abis/UnlockDiscountToken/UnlockDiscountTokenV1.json' -import UnlockDiscountTokenV2 from './abis/UnlockDiscountToken/UnlockDiscountTokenV2.json' -import UnlockDiscountTokenV3 from './abis/UnlockDiscountToken/UnlockDiscountTokenV3.json' -import GovernorUnlockProtocol from './abis/Governor/UnlockProtocolGovernor.json' -import GovernorUnlockProtocolTimelock from './abis/Governor/UnlockProtocolTimelock.json' -import LockSerializer from './abis/utils/LockSerializer.json' -import UnlockSwapPurchaser from './abis/utils/UnlockSwapPurchaser.json' -import UnlockSwapBurner from './abis/utils/UnlockSwapBurner.json' -import UniswapOracleV3 from './abis/utils/UniswapOracleV3.json' - -// exports -export { PublicLockV0 } -export { PublicLockV1 } -export { PublicLockV10 } -export { PublicLockV11 } -export { PublicLockV12 } -export { PublicLockV13 } -export { PublicLockV14 } -export { PublicLockV2 } -export { PublicLockV3 } -export { PublicLockV4 } -export { PublicLockV5 } -export { PublicLockV6 } -export { PublicLockV7 } -export { PublicLockV8 } -export { PublicLockV9 } -export { UnlockV0 } -export { UnlockV1 } -export { UnlockV10 } -export { UnlockV11 } -export { UnlockV12 } -export { UnlockV13 } -export { UnlockV2 } -export { UnlockV3 } -export { UnlockV4 } -export { UnlockV5 } -export { UnlockV6 } -export { UnlockV7 } -export { UnlockV8 } -export { UnlockV9 } -export { UnlockDiscountTokenV0 } -export { UnlockDiscountTokenV1 } -export { UnlockDiscountTokenV2 } -export { UnlockDiscountTokenV3 } -export { GovernorUnlockProtocol } -export { GovernorUnlockProtocolTimelock } -export { - LockSerializer, - UnlockSwapPurchaser, - UnlockSwapBurner, - UniswapOracleV3, -} diff --git a/packages/contracts/src/utils/files.ts b/packages/contracts/src/utils/files.ts index b91188e479f..843a3424e37 100644 --- a/packages/contracts/src/utils/files.ts +++ b/packages/contracts/src/utils/files.ts @@ -36,6 +36,7 @@ export const getAbiPaths = async () => { 'abis/Unlock', 'abis/UnlockDiscountToken', 'abis/Governor', + 'abis/utils', ] const paths = await Promise.all(folders.map((f) => parseExports(f))) diff --git a/packages/contracts/src/utils/parser.ts b/packages/contracts/src/utils/parser.ts index a162f821b3a..1ad5fe6fd7d 100644 --- a/packages/contracts/src/utils/parser.ts +++ b/packages/contracts/src/utils/parser.ts @@ -1,11 +1,39 @@ import { getAbiPaths } from './files' +type contractVersion = { + contractName: string + versionNumber: string + abiPath: string +} + +const findLatest = (exports: contractVersion[], contract: string) => { + const [latest] = exports + .filter(({ contractName }) => contractName === contract) + .sort( + ({ versionNumber: a }, { versionNumber: b }) => + parseInt(b.replace('V', '')) - parseInt(a.replace('V', '')) + ) + const { contractName, versionNumber } = latest + const varName = `${contract.toLocaleUpperCase()}_LATEST_VERSION` + const versionInt = versionNumber.replace('V', '') + + console.log(`export { ${contractName}${versionNumber} as ${contract} }`) + console.log(`const ${varName} = ${versionInt}`) + console.log(`export { ${varName} }`) + return latest +} + async function main() { const paths = await getAbiPaths() - const exports = paths.flat().map((abiPath) => { - const s = abiPath.split('/') - const contractName = s[2] - const versionNumber = s[3].replace(contractName, '').replace('.json', '') + const exports: contractVersion[] = paths.flat().map((abiPath) => { + let contractName, fileName, versionNumber + if (abiPath.includes('/utils/')) { + ;[, , , fileName] = abiPath.split('/') + contractName = fileName.replace('.json', '') + } else { + ;[, , contractName, fileName] = abiPath.split('/') + versionNumber = fileName.replace(contractName, '').replace('.json', '') + } return { contractName, versionNumber, @@ -16,28 +44,31 @@ async function main() { console.log("// This file is generated, please don't edit directly") console.log("// Refer to 'utils/parser.ts' and 'yarn build:index' for more\n") - exports.forEach(({ contractName, versionNumber, abiPath }) => + exports.forEach(({ contractName, versionNumber = '', abiPath }) => console.log(`import ${contractName}${versionNumber} from '${abiPath}'`) ) - const utils = [ - 'LockSerializer', - 'UnlockSwapPurchaser', - 'UnlockSwapBurner', - 'UniswapOracleV3', - ] - - utils.forEach((util) => { - console.log(`import ${util} from './abis/utils/${util}.json'`) - }) - console.log('\n// exports') - exports.forEach(({ contractName, versionNumber }) => + exports.forEach(({ contractName, versionNumber = '' }) => console.log(`export { ${contractName}${versionNumber} }`) ) - console.log(`export { ${utils.toString()} }`) + // alias for all contracts + console.log( + `const contracts = { ${exports + .map( + ({ contractName, versionNumber = '' }) => + `${contractName}${versionNumber}` + ) + .toString()} } + export { contracts }` + ) + + // alias for the newest versions + console.log('\n// latest') + findLatest(exports, 'PublicLock') + findLatest(exports, 'Unlock') } main() diff --git a/packages/hardhat-plugin/CHANGELOG.md b/packages/hardhat-plugin/CHANGELOG.md index a951e9cddf3..d7a7985fffb 100644 --- a/packages/hardhat-plugin/CHANGELOG.md +++ b/packages/hardhat-plugin/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +### 0.1.5 + +- Use version number directly fromn contracts packages + ### 0.1.2 - Changing the lock deployed version to the latest diff --git a/packages/hardhat-plugin/package.json b/packages/hardhat-plugin/package.json index a3d8081caa7..720ed395181 100644 --- a/packages/hardhat-plugin/package.json +++ b/packages/hardhat-plugin/package.json @@ -1,6 +1,6 @@ { "name": "@unlock-protocol/hardhat-plugin", - "version": "0.1.2", + "version": "0.1.5", "description": "Hardhat Plugin for Unlock Protocol", "author": "Unlock Protocol", "license": "MIT", diff --git a/packages/hardhat-plugin/src/constants.ts b/packages/hardhat-plugin/src/constants.ts index 0cf0b18e0d4..60868bc77fe 100644 --- a/packages/hardhat-plugin/src/constants.ts +++ b/packages/hardhat-plugin/src/constants.ts @@ -1,5 +1,11 @@ -export const UNLOCK_LATEST_VERSION = 11 -export const PUBLIC_LOCK_LATEST_VERSION = 13 +import { + UNLOCK_LATEST_VERSION, + PUBLICLOCK_LATEST_VERSION, +} from '@unlock-protocol/contracts' +export { + UNLOCK_LATEST_VERSION, + PUBLICLOCK_LATEST_VERSION as PUBLIC_LOCK_LATEST_VERSION, +} // task names export const TASK_CREATE_LOCK = 'unlock:create-lock' diff --git a/packages/hardhat-plugin/src/utils.ts b/packages/hardhat-plugin/src/utils.ts index 9754846e511..c2011828f7d 100644 --- a/packages/hardhat-plugin/src/utils.ts +++ b/packages/hardhat-plugin/src/utils.ts @@ -1,4 +1,4 @@ -import * as contracts from '@unlock-protocol/contracts' +import { contracts } from '@unlock-protocol/contracts' import { HardhatRuntimeEnvironment } from 'hardhat/types' import type { Signer, Contract, ContractFactory } from 'ethers'