From bd843b70815ee223931a8500f029a6f7ff428e84 Mon Sep 17 00:00:00 2001 From: Leszek Stachowski Date: Tue, 28 Nov 2023 13:57:01 +0100 Subject: [PATCH 01/63] revert ESM/CJS compilation, use previous directory structure --- packages/protocol/abis/README.md | 4 +- .../abis/{package.json => package.json.dist} | 7 +-- packages/protocol/abis/tsconfig-cjs.json | 8 --- packages/protocol/abis/tsconfig.json | 24 -------- packages/protocol/scripts/build.ts | 2 +- .../prepare-contracts-and-abis-publishing.ts | 58 +++++++------------ packages/protocol/wagmi.config.ts | 2 +- 7 files changed, 27 insertions(+), 78 deletions(-) rename packages/protocol/abis/{package.json => package.json.dist} (63%) delete mode 100644 packages/protocol/abis/tsconfig-cjs.json delete mode 100644 packages/protocol/abis/tsconfig.json diff --git a/packages/protocol/abis/README.md b/packages/protocol/abis/README.md index d0dd6b751bc..5b8e111e23f 100644 --- a/packages/protocol/abis/README.md +++ b/packages/protocol/abis/README.md @@ -28,8 +28,8 @@ import { Accounts } from '@celo/abis/types/ethers' // web3 import Accounts from '@celo/abis/types/web3/Accounts' -// truffle -import { AccountsContract } from '@celo/abis/types/truffle' +// wagmi +import Accounts from '@celo/abis/types/wagmi/Accounts' ``` ## License diff --git a/packages/protocol/abis/package.json b/packages/protocol/abis/package.json.dist similarity index 63% rename from packages/protocol/abis/package.json rename to packages/protocol/abis/package.json.dist index 8c7a86ca9ec..7deebd23438 100644 --- a/packages/protocol/abis/package.json +++ b/packages/protocol/abis/package.json.dist @@ -6,14 +6,11 @@ "repository": { "type": "git", "url": "https://github.com/celo-org/celo-monorepo.git", - "directory": "packages/protocol/contracts" + "directory": "packages/protocol/abis" }, "scripts": {}, "dependencies": {}, - "main": "./lib/cjs/index.js", - "module": "./lib/esm/index.js", - "types": "./lib/esm/index.d.ts", "files": [ - "lib/" + "./" ] } diff --git a/packages/protocol/abis/tsconfig-cjs.json b/packages/protocol/abis/tsconfig-cjs.json deleted file mode 100644 index 793f22f7159..00000000000 --- a/packages/protocol/abis/tsconfig-cjs.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "module": "CommonJS", - "outDir": "./lib/cjs" - }, - "references": [{ "path": "../../sdk/utils" }] -} diff --git a/packages/protocol/abis/tsconfig.json b/packages/protocol/abis/tsconfig.json deleted file mode 100644 index d58d74f1d48..00000000000 --- a/packages/protocol/abis/tsconfig.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "compileOnSave": false, - "compilerOptions": { - "allowSyntheticDefaultImports": true, - "esModuleInterop": true, - "baseUrl": ".", - "strict": true, - "moduleResolution": "node", - "noUnusedLocals": true, - "noUnusedParameters": true, - "removeComments": false, - "skipLibCheck": true, - "sourceMap": true, - "target": "ES2020", - "downlevelIteration": true, - "resolveJsonModule": true, - "declaration": true, - "module": "ES2020", - "outDir": "./lib/esm" - }, - "include": ["./src-generated"], - "exclude": ["./src-generated/ethers"], - "references": [{ "path": "../../sdk/utils" }] -} diff --git a/packages/protocol/scripts/build.ts b/packages/protocol/scripts/build.ts index ce92663e7a9..0a47ec0a5d9 100644 --- a/packages/protocol/scripts/build.ts +++ b/packages/protocol/scripts/build.ts @@ -114,7 +114,7 @@ async function generateFilesForContractKit({ coreContractsOnly, web3Types: outdi ? CoreContracts : CoreContracts.concat('Proxy').concat(Interfaces) - const globPattern = `${BUILD_DIR}/contracts/@(${contractKitContracts.join('|')}).json` + const globPattern = `${BUILD_DIR}/contracts*/@(${contractKitContracts.join('|')}).json` const cwd = process.cwd() diff --git a/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts b/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts index 2f20e8bf2d2..2b05ea2891b 100644 --- a/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts +++ b/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts @@ -7,7 +7,6 @@ import { ABIS_BUILD_DIR, ABIS_PACKAGE_SRC_DIR, BUILD_EXECUTABLE, - CONTRACTS_PACKAGE_SRC_DIR, CoreContracts, TSCONFIG_PATH, } from './consts' @@ -31,10 +30,11 @@ try { build(`--solidity ${path.join(ABIS_BUILD_DIR)}`) // Generate ethers typings - build(`--ethersTypes ${path.join(ABIS_BUILD_DIR, 'ethers')}`) + build(`--ethersTypes ${path.join(ABIS_BUILD_DIR, 'types/ethers')}`) // Generate web3 typings - build(`--web3Types ${path.join(ABIS_BUILD_DIR, 'web3')}`) + // TODO web3 is generating nested dir structure + build(`--web3Types ${path.join(ABIS_BUILD_DIR, 'types/web3')}`) // Merge contracts-0.8, contracts-mento, etc.. at the root of the build dir log('Merging files at the root of the build dir') @@ -46,6 +46,9 @@ try { const mvCommand = `mv -f ${ABIS_BUILD_DIR}/${folder}/* ${ABIS_BUILD_DIR}` log(mvCommand) child_process.execSync(mvCommand) + + // Once copied all the files, remove the folder + child_process.execSync(`rm -r ${ABIS_BUILD_DIR}/${folder}`) } // Remove Mocks, tests, extraneous files @@ -67,42 +70,23 @@ try { log('Running yarn wagmi generate') child_process.execSync(`yarn wagmi generate`, { stdio: 'inherit' }) - // Generate an index.ts to be esm friendly - log('Generate index.ts from `CoreContracts`') - fs.writeFileSync( - path.join(ABIS_BUILD_DIR, 'index.ts'), - '// This is a generated file, do not modify\n' + - [...new Set(CoreContracts)] - .map((contract) => { - return `export * as ${contract} from './${contract}';` - }) - .join('\n') - ) + const sourcePackageJson = path.join(ABIS_PACKAGE_SRC_DIR, 'package.json.dist') + const destinationPackageJson = path.join(ABIS_BUILD_DIR, 'package.json') - // Generate the js folder to be published from ts files - log('Running tsc -b ') - child_process.execSync(`yarn tsc -b ${path.join(ABIS_PACKAGE_SRC_DIR, 'tsconfig.json')}`, { - stdio: 'inherit', - }) - child_process.execSync(`yarn tsc -b ${path.join(ABIS_PACKAGE_SRC_DIR, 'tsconfig-cjs.json')}`, { - stdio: 'inherit', - }) + fs.copyFileSync( + path.join(ABIS_PACKAGE_SRC_DIR, 'README.md'), + path.join(ABIS_BUILD_DIR, 'README.md') + ) // Change the packages version to what CI is providing from environment variables - const packageJsons = [ - path.join(CONTRACTS_PACKAGE_SRC_DIR, 'package.json'), - path.join(ABIS_PACKAGE_SRC_DIR, 'package.json'), - ] - packageJsons.forEach((packageJsonPath) => { - const file = fs.readFileSync(packageJsonPath).toString() - - if (process.env.RELEASE_VERSION) { - fs.writeFileSync( - packageJsonPath, - file.replace('0.0.0-template.version', process.env.RELEASE_VERSION) - ) - } - }) + const file = fs.readFileSync(sourcePackageJson).toString() + + if (process.env.RELEASE_VERSION) { + fs.writeFileSync( + destinationPackageJson, + file.replace('0.0.0-template.version', process.env.RELEASE_VERSION) + ) + } } finally { // Cleanup log('Cleaning up folders and checking out dirty git files') @@ -126,7 +110,7 @@ function lsRecursive(dir: string): string[] { function build(cmd: string) { log(`Running build for ${cmd}`) child_process.execSync( - `BUILD_DIR=./build/abis/src ts-node ${BUILD_EXECUTABLE} --coreContractsOnly ${cmd}`, + `BUILD_DIR=./build ts-node ${BUILD_EXECUTABLE} --coreContractsOnly ${cmd}`, { stdio: 'inherit' } ) } diff --git a/packages/protocol/wagmi.config.ts b/packages/protocol/wagmi.config.ts index 8c33b65fb74..833f1d197c5 100644 --- a/packages/protocol/wagmi.config.ts +++ b/packages/protocol/wagmi.config.ts @@ -19,7 +19,7 @@ for (const contractName of new Set(CoreContracts)) { export default defineConfig( contracts.map(({ name, abi }) => ({ - out: path.join(ABIS_BUILD_DIR, `${name}.ts`), + out: path.join(ABIS_BUILD_DIR, `types/wagmi/${name}.ts`), contracts: [{ name, abi }], plugins: [], })) From 9c3288311c2455e68c5ad2bc597aafb27ec93429 Mon Sep 17 00:00:00 2001 From: Leszek Stachowski Date: Tue, 28 Nov 2023 16:36:12 +0100 Subject: [PATCH 02/63] merge web3/* folders into one as well --- packages/protocol/abis/package.json.dist | 6 ++-- .../prepare-contracts-and-abis-publishing.ts | 34 +++++++++++++------ 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/packages/protocol/abis/package.json.dist b/packages/protocol/abis/package.json.dist index 7deebd23438..8b1dcac8937 100644 --- a/packages/protocol/abis/package.json.dist +++ b/packages/protocol/abis/package.json.dist @@ -9,8 +9,6 @@ "directory": "packages/protocol/abis" }, "scripts": {}, - "dependencies": {}, - "files": [ - "./" - ] + "dependencies": {}, + "types": "./types/wagmi/index.d.ts" } diff --git a/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts b/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts index 2b05ea2891b..4ffc167839c 100644 --- a/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts +++ b/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts @@ -38,18 +38,16 @@ try { // Merge contracts-0.8, contracts-mento, etc.. at the root of the build dir log('Merging files at the root of the build dir') - for (const folder of [ - 'contracts', - `contracts-${MENTO_PACKAGE.name}`, - `contracts-${SOLIDITY_08_PACKAGE.name}`, - ]) { - const mvCommand = `mv -f ${ABIS_BUILD_DIR}/${folder}/* ${ABIS_BUILD_DIR}` - log(mvCommand) - child_process.execSync(mvCommand) + mergeFromFolder( + ['contracts', `contracts-${MENTO_PACKAGE.name}`, `contracts-${SOLIDITY_08_PACKAGE.name}`], + path.join(ABIS_BUILD_DIR) + ) - // Once copied all the files, remove the folder - child_process.execSync(`rm -r ${ABIS_BUILD_DIR}/${folder}`) - } + log('Merging files in web3 folder') + mergeFromFolder( + [`${MENTO_PACKAGE.name}`, `${SOLIDITY_08_PACKAGE.name}`], + path.join(ABIS_BUILD_DIR, 'types/web3') + ) // Remove Mocks, tests, extraneous files log('Deleting extraneous files') @@ -114,3 +112,17 @@ function build(cmd: string) { { stdio: 'inherit' } ) } + +function mergeFromFolder(folderNames: string[], rootFolderName: string) { + for (const folderName of folderNames) { + const mvCommand = `mv -f ${rootFolderName}/${folderName}/* ${rootFolderName}` + const rmCommand = `rm -r ${rootFolderName}/${folderName}` + + log(mvCommand) + child_process.execSync(mvCommand) + + // Once copied all the files, remove the folder + log(rmCommand) + child_process.execSync(rmCommand) + } +} From 5a6333db6ed60510173bedc06157b44baeef12f1 Mon Sep 17 00:00:00 2001 From: Leszek Stachowski Date: Tue, 28 Nov 2023 16:39:03 +0100 Subject: [PATCH 03/63] change working dir to packages/protocol/abis/src-generated --- .github/workflows/publish-contracts-abi-release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-contracts-abi-release.yml b/.github/workflows/publish-contracts-abi-release.yml index bfb94c03add..315931ff6d4 100644 --- a/.github/workflows/publish-contracts-abi-release.yml +++ b/.github/workflows/publish-contracts-abi-release.yml @@ -75,7 +75,7 @@ jobs: - name: Publish @celo/abis run: npm publish $RELEASE_TYPE $DRY_RUN - working-directory: packages/protocol/abis + working-directory: packages/protocol/abis/src-generated env: RELEASE_TYPE: ${{ env.RELEASE_TYPE != '' && '--tag $RELEASE_TYPE' || '' }} RELEASE_VERSION: ${{ env.RELEASE_VERSION }} From 123fffe9d667bdf013bf0c7fcb6f3759d559f561 Mon Sep 17 00:00:00 2001 From: Leszek Stachowski Date: Tue, 28 Nov 2023 17:04:00 +0100 Subject: [PATCH 04/63] include interfaces --- .../prepare-contracts-and-abis-publishing.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts b/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts index 4ffc167839c..c261dd95a4f 100644 --- a/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts +++ b/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts @@ -8,6 +8,7 @@ import { ABIS_PACKAGE_SRC_DIR, BUILD_EXECUTABLE, CoreContracts, + Interfaces, TSCONFIG_PATH, } from './consts' @@ -56,7 +57,12 @@ try { const name = path.basename(filePath) const baseName = name.replace(/.(sol|d.ts|json)$/, '') - if (baseName !== 'index' && !CoreContracts.includes(baseName)) { + if ( + baseName !== 'index' && + baseName !== 'Proxy' && + !CoreContracts.includes(baseName) && + !Interfaces.includes(baseName) + ) { rmrfSync(path.join(ABIS_BUILD_DIR, `${baseName}.json`)) rmrfSync(path.join(ABIS_BUILD_DIR, `${baseName}.ts`)) rmrfSync(path.join(ABIS_BUILD_DIR, '**', `${baseName}.d.ts`)) @@ -107,10 +113,9 @@ function lsRecursive(dir: string): string[] { function build(cmd: string) { log(`Running build for ${cmd}`) - child_process.execSync( - `BUILD_DIR=./build ts-node ${BUILD_EXECUTABLE} --coreContractsOnly ${cmd}`, - { stdio: 'inherit' } - ) + child_process.execSync(`BUILD_DIR=./build ts-node ${BUILD_EXECUTABLE} ${cmd}`, { + stdio: 'inherit', + }) } function mergeFromFolder(folderNames: string[], rootFolderName: string) { From 0bb93ba80a316b99d0cdfec6edb8cdaeffaf98dd Mon Sep 17 00:00:00 2001 From: Leszek Stachowski Date: Wed, 29 Nov 2023 11:27:27 +0100 Subject: [PATCH 05/63] prepare contracts package.json --- .../prepare-contracts-and-abis-publishing.ts | 35 ++++++++++++++----- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts b/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts index c261dd95a4f..ef974f02eb7 100644 --- a/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts +++ b/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts @@ -7,6 +7,7 @@ import { ABIS_BUILD_DIR, ABIS_PACKAGE_SRC_DIR, BUILD_EXECUTABLE, + CONTRACTS_PACKAGE_SRC_DIR, CoreContracts, Interfaces, TSCONFIG_PATH, @@ -74,22 +75,15 @@ try { log('Running yarn wagmi generate') child_process.execSync(`yarn wagmi generate`, { stdio: 'inherit' }) - const sourcePackageJson = path.join(ABIS_PACKAGE_SRC_DIR, 'package.json.dist') - const destinationPackageJson = path.join(ABIS_BUILD_DIR, 'package.json') - fs.copyFileSync( path.join(ABIS_PACKAGE_SRC_DIR, 'README.md'), path.join(ABIS_BUILD_DIR, 'README.md') ) // Change the packages version to what CI is providing from environment variables - const file = fs.readFileSync(sourcePackageJson).toString() - if (process.env.RELEASE_VERSION) { - fs.writeFileSync( - destinationPackageJson, - file.replace('0.0.0-template.version', process.env.RELEASE_VERSION) - ) + prepareAbisPackageJson() + prepareContractsPackageJson() } } finally { // Cleanup @@ -100,6 +94,29 @@ try { } // Helper functions +function prepareAbisPackageJson() { + const sourcePackageJson = path.join(ABIS_PACKAGE_SRC_DIR, 'package.json.dist') + const destinationPackageJson = path.join(ABIS_BUILD_DIR, 'package.json') + + fs.writeFileSync( + destinationPackageJson, + fs + .readFileSync(sourcePackageJson) + .toString() + .replace('0.0.0-template.version', process.env.RELEASE_VERSION) + ) +} + +function prepareContractsPackageJson() { + const contractsPackageJsonPath = path.join(CONTRACTS_PACKAGE_SRC_DIR, 'package.json') + const file = fs.readFileSync(contractsPackageJsonPath).toString() + + fs.writeFileSync( + contractsPackageJsonPath, + file.replace('0.0.0-template.version', process.env.RELEASE_VERSION) + ) +} + function lsRecursive(dir: string): string[] { const filesAndDirectories = fs.readdirSync(dir, { withFileTypes: true }) return filesAndDirectories.reduce((fileNames, fileOrDir) => { From fa8813a67bf791c5294942ae0b5072c1962547e4 Mon Sep 17 00:00:00 2001 From: Leszek Stachowski Date: Wed, 29 Nov 2023 11:50:18 +0100 Subject: [PATCH 06/63] fix package.json not exisiting for @celo/abis package --- .../prepare-contracts-and-abis-publishing.ts | 43 +++++++++++-------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts b/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts index ef974f02eb7..d0884f8ce33 100644 --- a/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts +++ b/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts @@ -81,10 +81,8 @@ try { ) // Change the packages version to what CI is providing from environment variables - if (process.env.RELEASE_VERSION) { - prepareAbisPackageJson() - prepareContractsPackageJson() - } + prepareAbisPackageJson() + prepareContractsPackageJson() } finally { // Cleanup log('Cleaning up folders and checking out dirty git files') @@ -95,26 +93,37 @@ try { // Helper functions function prepareAbisPackageJson() { + log('Preparing @celo/abis package.json') const sourcePackageJson = path.join(ABIS_PACKAGE_SRC_DIR, 'package.json.dist') const destinationPackageJson = path.join(ABIS_BUILD_DIR, 'package.json') + let contents = fs.readFileSync(sourcePackageJson).toString() - fs.writeFileSync( - destinationPackageJson, - fs - .readFileSync(sourcePackageJson) - .toString() - .replace('0.0.0-template.version', process.env.RELEASE_VERSION) - ) + if (process.env.RELEASE_VERSION) { + log('Replacing @celo/abis version with provided RELEASE_VERSION') + + contents = contents.replace('0.0.0-template.version', process.env.RELEASE_VERSION) + } else { + log('No RELEASE_VERSION provided') + } + + fs.writeFileSync(destinationPackageJson, contents) } function prepareContractsPackageJson() { - const contractsPackageJsonPath = path.join(CONTRACTS_PACKAGE_SRC_DIR, 'package.json') - const file = fs.readFileSync(contractsPackageJsonPath).toString() + if (process.env.RELEASE_VERSION) { + log('Replacing @celo/contracts version with RELEASE_VERSION)') + const contractsPackageJsonPath = path.join(CONTRACTS_PACKAGE_SRC_DIR, 'package.json') + const contents = fs.readFileSync(contractsPackageJsonPath).toString() - fs.writeFileSync( - contractsPackageJsonPath, - file.replace('0.0.0-template.version', process.env.RELEASE_VERSION) - ) + fs.writeFileSync( + contractsPackageJsonPath, + contents.replace('0.0.0-template.version', process.env.RELEASE_VERSION) + ) + + return + } + + log('Skipping @celo/contracts package.json preparation (no RELEASE_VERSION provided)') } function lsRecursive(dir: string): string[] { From 286e7fa8bc482ef3c76840d44660deee7034cd80 Mon Sep 17 00:00:00 2001 From: Aaron DeRuvo Date: Wed, 29 Nov 2023 13:39:38 +0200 Subject: [PATCH 07/63] fix npm tagging, and a spelling issue --- .github/workflows/publish-contracts-abi-release.yml | 4 ++-- packages/protocol/contractPackages.ts | 6 +++--- packages/protocol/scripts/build.ts | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/publish-contracts-abi-release.yml b/.github/workflows/publish-contracts-abi-release.yml index 315931ff6d4..9b646a43615 100644 --- a/.github/workflows/publish-contracts-abi-release.yml +++ b/.github/workflows/publish-contracts-abi-release.yml @@ -68,7 +68,7 @@ jobs: run: npm publish $RELEASE_TYPE $DRY_RUN working-directory: packages/protocol/contracts env: - RELEASE_TYPE: ${{ env.RELEASE_TYPE != '' && '--tag $RELEASE_TYPE' || '' }} + RELEASE_TYPE: ${{ env.RELEASE_TYPE != '' && '--tag' && env.RELEASE_TYPE || '' }} RELEASE_VERSION: ${{ env.RELEASE_VERSION }} NODE_AUTH_TOKEN: ${{ env.NPM_TOKEN }} DRY_RUN: ${{ env.RELEASE_VERSION == '' && '--dry-run' || '' }} @@ -77,7 +77,7 @@ jobs: run: npm publish $RELEASE_TYPE $DRY_RUN working-directory: packages/protocol/abis/src-generated env: - RELEASE_TYPE: ${{ env.RELEASE_TYPE != '' && '--tag $RELEASE_TYPE' || '' }} + RELEASE_TYPE: ${{ env.RELEASE_TYPE != '' && '--tag' && env.RELEASE_TYPE || '' }} RELEASE_VERSION: ${{ env.RELEASE_VERSION }} NODE_AUTH_TOKEN: ${{ env.NPM_TOKEN }} DRY_RUN: ${{ env.RELEASE_VERSION == '' && '--dry-run' || '' }} diff --git a/packages/protocol/contractPackages.ts b/packages/protocol/contractPackages.ts index 7c284b2d16d..577823d83d4 100644 --- a/packages/protocol/contractPackages.ts +++ b/packages/protocol/contractPackages.ts @@ -3,7 +3,7 @@ export interface ContractPackage { folderPath?: string name: string contracts: string[] - contracstFolder?: string + contractsFolder?: string proxyContracts?: string[] truffleConfig?: string solidityVersion?: string @@ -12,7 +12,7 @@ export interface ContractPackage { export const MENTO_PACKAGE: ContractPackage = { path: 'mento-core', - contracstFolder: 'contracts', + contractsFolder: 'contracts', folderPath: 'lib', name: 'mento', contracts: [ @@ -42,7 +42,7 @@ export const MENTO_PACKAGE: ContractPackage = { export const SOLIDITY_08_PACKAGE: ContractPackage = { path: 'contracts-0.8', - contracstFolder: '', + contractsFolder: '', folderPath: '', name: '0.8', proxiesPath: '/', // Proxies are still with 0.5 contracts diff --git a/packages/protocol/scripts/build.ts b/packages/protocol/scripts/build.ts index 0a47ec0a5d9..332b2c2a349 100644 --- a/packages/protocol/scripts/build.ts +++ b/packages/protocol/scripts/build.ts @@ -31,7 +31,7 @@ function compile({ coreContractsOnly, solidity: outdir }: BuildTargets) { './', contractPackage.folderPath, contractPackage.path, - contractPackage.contracstFolder + contractPackage.contractsFolder ) if (!existsSync(contractPath)) { console.log(`Contract package named ${contractPackage.name} doesn't exist`) From a660324c82133a69a3b2e36ef59b328830f47cf2 Mon Sep 17 00:00:00 2001 From: Leszek Stachowski Date: Wed, 29 Nov 2023 13:41:12 +0100 Subject: [PATCH 08/63] leave nested dirs in web3/ generated folder --- .../scripts/prepare-contracts-and-abis-publishing.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts b/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts index d0884f8ce33..0bd617fd6bb 100644 --- a/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts +++ b/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts @@ -45,12 +45,6 @@ try { path.join(ABIS_BUILD_DIR) ) - log('Merging files in web3 folder') - mergeFromFolder( - [`${MENTO_PACKAGE.name}`, `${SOLIDITY_08_PACKAGE.name}`], - path.join(ABIS_BUILD_DIR, 'types/web3') - ) - // Remove Mocks, tests, extraneous files log('Deleting extraneous files') const allFiles = lsRecursive(ABIS_BUILD_DIR) From 2a46bb04427c0fb0f6ca0dc197a743e7042a3344 Mon Sep 17 00:00:00 2001 From: Aaron DeRuvo Date: Wed, 29 Nov 2023 14:47:50 +0200 Subject: [PATCH 09/63] fix #10564 warning --- .github/workflows/publish-contracts-abi-release.yml | 1 + packages/protocol/scripts/build.ts | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish-contracts-abi-release.yml b/.github/workflows/publish-contracts-abi-release.yml index 9b646a43615..f93c78e199b 100644 --- a/.github/workflows/publish-contracts-abi-release.yml +++ b/.github/workflows/publish-contracts-abi-release.yml @@ -51,6 +51,7 @@ jobs: run: yarn build - name: Check if a release should be published + # This is what sets the RELEASE_TYPE and RELEASE_VERSION env variables run: yarn --silent is_contract_release >> "$GITHUB_ENV" working-directory: packages/protocol env: diff --git a/packages/protocol/scripts/build.ts b/packages/protocol/scripts/build.ts index 332b2c2a349..93d6df4719a 100644 --- a/packages/protocol/scripts/build.ts +++ b/packages/protocol/scripts/build.ts @@ -52,8 +52,14 @@ function compile({ coreContractsOnly, solidity: outdir }: BuildTargets) { // check that there were no errors for (const contractName of contracts) { try { + const artifactPath = `${outdir}/contracts/${contractName}.json` + const artifactPath8 = `${outdir}/contracts-0.8/${contractName}.json` + let is08 = false // This is issuing a warning: https://github.com/celo-org/celo-monorepo/issues/10564 - const fileStr = readJSONSync(`${outdir}/contracts/${contractName}.json`) + if (existsSync(artifactPath8)) { + is08 = true + } + const fileStr = readJSONSync(is08 ? artifactPath8 : artifactPath) if (hasEmptyBytecode(fileStr)) { console.error( `${contractName} has empty bytecode. Maybe you forgot to fully implement an interface?` From 6ff7f4a1e6aad3bfaa82ce7a5467a7af76cf7b65 Mon Sep 17 00:00:00 2001 From: philbow61 <80156619+philbow61@users.noreply.github.com> Date: Wed, 29 Nov 2023 13:58:27 +0100 Subject: [PATCH 10/63] fix: celocli network:contracts command post Mento upgrade 04 (#10792) * fix: add StableTokens to unversioned contracts list * feat: add celocli changeset * Update new-queens-smoke.md minor would be a new feature --------- Co-authored-by: Aaron DeRuvo --- .changeset/new-queens-smoke.md | 5 +++++ packages/cli/src/commands/network/contracts.ts | 3 +++ 2 files changed, 8 insertions(+) create mode 100644 .changeset/new-queens-smoke.md diff --git a/.changeset/new-queens-smoke.md b/.changeset/new-queens-smoke.md new file mode 100644 index 00000000000..4753a2d1649 --- /dev/null +++ b/.changeset/new-queens-smoke.md @@ -0,0 +1,5 @@ +--- +'@celo/celocli': patch +--- + +network:contracts command fix added StableTokens to unversioned contracts list diff --git a/packages/cli/src/commands/network/contracts.ts b/packages/cli/src/commands/network/contracts.ts index 843e2aefdbf..fef399927aa 100644 --- a/packages/cli/src/commands/network/contracts.ts +++ b/packages/cli/src/commands/network/contracts.ts @@ -10,6 +10,9 @@ const UNVERSIONED_CONTRACTS = [ CeloContract.Registry, CeloContract.FeeCurrencyWhitelist, CeloContract.Freezer, + CeloContract.StableToken, + CeloContract.StableTokenBRL, + CeloContract.StableTokenEUR, ] const UNPROXIED_CONTRACTS: CeloContract[] = [] From 55054ff3f6f9529d4f21bd7104c903d28121056b Mon Sep 17 00:00:00 2001 From: Aaron DeRuvo Date: Wed, 29 Nov 2023 16:15:44 +0200 Subject: [PATCH 11/63] fix #10564 warning --- .../workflows/publish-contracts-abi-release.yml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/publish-contracts-abi-release.yml b/.github/workflows/publish-contracts-abi-release.yml index f93c78e199b..cc76dc9b899 100644 --- a/.github/workflows/publish-contracts-abi-release.yml +++ b/.github/workflows/publish-contracts-abi-release.yml @@ -19,7 +19,7 @@ jobs: contents: write id-token: write pull-requests: write - repository-projects: write + repository-projects: write steps: - uses: actions/checkout@v4 - name: Akeyless Get Secrets @@ -66,19 +66,23 @@ jobs: RELEASE_VERSION: ${{ env.RELEASE_VERSION }} - name: Publish @celo/contracts - run: npm publish $RELEASE_TYPE $DRY_RUN + run: | + cat package.json + npm publish $RELEASE_TYPE $DRY_RUN working-directory: packages/protocol/contracts env: - RELEASE_TYPE: ${{ env.RELEASE_TYPE != '' && '--tag' && env.RELEASE_TYPE || '' }} + RELEASE_TYPE: --tag ${{ env.RELEASE_TYPE != '' && env.RELEASE_TYPE || 'canary' }} RELEASE_VERSION: ${{ env.RELEASE_VERSION }} NODE_AUTH_TOKEN: ${{ env.NPM_TOKEN }} DRY_RUN: ${{ env.RELEASE_VERSION == '' && '--dry-run' || '' }} - name: Publish @celo/abis - run: npm publish $RELEASE_TYPE $DRY_RUN + run: | + cat package.json + npm publish $RELEASE_TYPE $DRY_RUN working-directory: packages/protocol/abis/src-generated env: - RELEASE_TYPE: ${{ env.RELEASE_TYPE != '' && '--tag' && env.RELEASE_TYPE || '' }} + RELEASE_TYPE: --tag ${{ env.RELEASE_TYPE != '' && env.RELEASE_TYPE || 'canary' }} RELEASE_VERSION: ${{ env.RELEASE_VERSION }} NODE_AUTH_TOKEN: ${{ env.NPM_TOKEN }} DRY_RUN: ${{ env.RELEASE_VERSION == '' && '--dry-run' || '' }} From 9729338998d5bd8334514201c532ef2bbd6e9969 Mon Sep 17 00:00:00 2001 From: Leszek Stachowski Date: Wed, 29 Nov 2023 16:04:07 +0100 Subject: [PATCH 12/63] add @celo/abis usage and change imports --- packages/sdk/contractkit/package.json | 1 + packages/sdk/contractkit/src/wrappers/Accounts.ts | 2 +- packages/sdk/contractkit/src/wrappers/Attestations.ts | 2 +- packages/sdk/contractkit/src/wrappers/BaseWrapper.ts | 2 +- .../contractkit/src/wrappers/BlockChainParameters.test.ts | 2 +- .../sdk/contractkit/src/wrappers/BlockchainParameters.ts | 2 +- packages/sdk/contractkit/src/wrappers/CeloTokenWrapper.ts | 4 ++-- .../sdk/contractkit/src/wrappers/DoubleSigningSlasher.ts | 2 +- packages/sdk/contractkit/src/wrappers/DowntimeSlasher.ts | 2 +- packages/sdk/contractkit/src/wrappers/Election.ts | 2 +- packages/sdk/contractkit/src/wrappers/EpochRewards.ts | 2 +- packages/sdk/contractkit/src/wrappers/Erc20Wrapper.ts | 2 +- packages/sdk/contractkit/src/wrappers/Escrow.ts | 2 +- packages/sdk/contractkit/src/wrappers/Exchange.ts | 2 +- .../sdk/contractkit/src/wrappers/FederatedAttestations.ts | 2 +- packages/sdk/contractkit/src/wrappers/FeeHandler.ts | 2 +- packages/sdk/contractkit/src/wrappers/Freezer.ts | 2 +- packages/sdk/contractkit/src/wrappers/GasPriceMinimum.ts | 2 +- packages/sdk/contractkit/src/wrappers/GoldTokenWrapper.ts | 2 +- packages/sdk/contractkit/src/wrappers/Governance.test.ts | 2 +- packages/sdk/contractkit/src/wrappers/Governance.ts | 2 +- packages/sdk/contractkit/src/wrappers/GrandaMento.ts | 4 ++-- packages/sdk/contractkit/src/wrappers/LockedGold.ts | 2 +- .../sdk/contractkit/src/wrappers/MetaTransactionWallet.ts | 2 +- .../src/wrappers/MetaTransactionWalletDeployer.test.ts | 7 +++++-- 25 files changed, 31 insertions(+), 27 deletions(-) diff --git a/packages/sdk/contractkit/package.json b/packages/sdk/contractkit/package.json index e216315ed54..18afb321333 100644 --- a/packages/sdk/contractkit/package.json +++ b/packages/sdk/contractkit/package.json @@ -43,6 +43,7 @@ "web3-core-helpers": "1.10.0" }, "devDependencies": { + "@celo/abis": "10.0.0-beta.3", "@celo/celo-devchain": "^6.0.3-beta.1", "@celo/odis-identifiers": "^1.0.0", "@celo/dev-utils": "0.0.1", diff --git a/packages/sdk/contractkit/src/wrappers/Accounts.ts b/packages/sdk/contractkit/src/wrappers/Accounts.ts index 3a13144a922..c98656b1cc7 100644 --- a/packages/sdk/contractkit/src/wrappers/Accounts.ts +++ b/packages/sdk/contractkit/src/wrappers/Accounts.ts @@ -9,7 +9,7 @@ import { import { soliditySha3 } from '@celo/utils/lib/solidity' import { authorizeSigner as buildAuthorizeSignerTypedData } from '@celo/utils/lib/typed-data-constructors' import type BN from 'bn.js' // just the types -import { Accounts } from '../generated/Accounts' +import { Accounts } from '@celo/abis/types/web3/Accounts' import { getParsedSignatureOfAddress } from '../utils/getParsedSignatureOfAddress' import { newContractVersion } from '../versions' import { diff --git a/packages/sdk/contractkit/src/wrappers/Attestations.ts b/packages/sdk/contractkit/src/wrappers/Attestations.ts index d1b539d4653..33b75b694f2 100644 --- a/packages/sdk/contractkit/src/wrappers/Attestations.ts +++ b/packages/sdk/contractkit/src/wrappers/Attestations.ts @@ -2,7 +2,7 @@ import { StableToken } from '@celo/base' import { eqAddress } from '@celo/base/lib/address' import { Address, Connection, toTransactionObject } from '@celo/connect' import BigNumber from 'bignumber.js' -import { Attestations } from '../generated/Attestations' +import { Attestations } from '@celo/abis/types/web3/Attestations' import { AccountsWrapper } from './Accounts' import { BaseWrapper, diff --git a/packages/sdk/contractkit/src/wrappers/BaseWrapper.ts b/packages/sdk/contractkit/src/wrappers/BaseWrapper.ts index a53b10195c2..e3d428c6ada 100644 --- a/packages/sdk/contractkit/src/wrappers/BaseWrapper.ts +++ b/packages/sdk/contractkit/src/wrappers/BaseWrapper.ts @@ -11,7 +11,7 @@ import { } from '@celo/connect' import { fromFixed, toFixed } from '@celo/utils/lib/fixidity' import BigNumber from 'bignumber.js' -import { ICeloVersionedContract } from '../generated/ICeloVersionedContract' +import { ICeloVersionedContract } from '@celo/abis/types/web3/ICeloVersionedContract' import { ContractVersion } from '../versions' /** Represents web3 native contract Method */ diff --git a/packages/sdk/contractkit/src/wrappers/BlockChainParameters.test.ts b/packages/sdk/contractkit/src/wrappers/BlockChainParameters.test.ts index e36c9795e4e..fc877ae747c 100644 --- a/packages/sdk/contractkit/src/wrappers/BlockChainParameters.test.ts +++ b/packages/sdk/contractkit/src/wrappers/BlockChainParameters.test.ts @@ -3,7 +3,7 @@ import { testWithGanache } from '@celo/dev-utils/lib/ganache-test' import BigNumber from 'bignumber.js' import { AddressRegistry } from '../address-registry' import { CeloContract } from '../base' -import { newBlockchainParameters } from '../generated/BlockchainParameters' +import { newBlockchainParameters } from '@celo/abis/types/web3/BlockchainParameters' import { BlockchainParametersWrapper } from './BlockchainParameters' testWithGanache('BlockChainParametersWrapper', (web3) => { diff --git a/packages/sdk/contractkit/src/wrappers/BlockchainParameters.ts b/packages/sdk/contractkit/src/wrappers/BlockchainParameters.ts index c800ae7a3f0..983c48e637e 100644 --- a/packages/sdk/contractkit/src/wrappers/BlockchainParameters.ts +++ b/packages/sdk/contractkit/src/wrappers/BlockchainParameters.ts @@ -1,5 +1,5 @@ import { BigNumber } from 'bignumber.js' -import { BlockchainParameters } from '../generated/BlockchainParameters' +import { BlockchainParameters } from '@celo/abis/types/web3/BlockchainParameters' import { BaseWrapper, proxyCall, proxySend, valueToBigNumber, valueToInt } from './BaseWrapper' export interface BlockchainParametersConfig { diff --git a/packages/sdk/contractkit/src/wrappers/CeloTokenWrapper.ts b/packages/sdk/contractkit/src/wrappers/CeloTokenWrapper.ts index 39f0e8b3bc8..8b801fe38f4 100644 --- a/packages/sdk/contractkit/src/wrappers/CeloTokenWrapper.ts +++ b/packages/sdk/contractkit/src/wrappers/CeloTokenWrapper.ts @@ -2,8 +2,8 @@ // after the move to node 10. This allows types to be inferred without // referencing '@celo/utils/node_modules/bignumber.js' import 'bignumber.js' -import { ICeloToken } from '../generated/ICeloToken' -import { IERC20 } from '../generated/IERC20' +import { ICeloToken } from '@celo/abis/types/web3/ICeloToken' +import { IERC20 } from '@celo/abis/types/web3/IERC20' import { proxyCall, proxySend, valueToInt } from './BaseWrapper' import { Erc20Wrapper } from './Erc20Wrapper' diff --git a/packages/sdk/contractkit/src/wrappers/DoubleSigningSlasher.ts b/packages/sdk/contractkit/src/wrappers/DoubleSigningSlasher.ts index c25454a147b..99c5ccff11c 100644 --- a/packages/sdk/contractkit/src/wrappers/DoubleSigningSlasher.ts +++ b/packages/sdk/contractkit/src/wrappers/DoubleSigningSlasher.ts @@ -1,5 +1,5 @@ import { Address } from '@celo/connect' -import { DoubleSigningSlasher } from '../generated/DoubleSigningSlasher' +import { DoubleSigningSlasher } from '@celo/abis/types/web3/DoubleSigningSlasher' import { BaseSlasher } from './BaseSlasher' import { valueToInt } from './BaseWrapper' diff --git a/packages/sdk/contractkit/src/wrappers/DowntimeSlasher.ts b/packages/sdk/contractkit/src/wrappers/DowntimeSlasher.ts index c3f543f49dd..99b7b912a02 100644 --- a/packages/sdk/contractkit/src/wrappers/DowntimeSlasher.ts +++ b/packages/sdk/contractkit/src/wrappers/DowntimeSlasher.ts @@ -1,6 +1,6 @@ import { Address } from '@celo/connect' import BigNumber from 'bignumber.js' -import { DowntimeSlasher } from '../generated/DowntimeSlasher' +import { DowntimeSlasher } from '@celo/abis/types/web3/DowntimeSlasher' import { BaseSlasher } from './BaseSlasher' import { blocksToDurationString, diff --git a/packages/sdk/contractkit/src/wrappers/Election.ts b/packages/sdk/contractkit/src/wrappers/Election.ts index d5d919d93b1..7daadef1129 100644 --- a/packages/sdk/contractkit/src/wrappers/Election.ts +++ b/packages/sdk/contractkit/src/wrappers/Election.ts @@ -8,7 +8,7 @@ import { concurrentMap, concurrentValuesMap } from '@celo/base/lib/async' import { zeroRange, zip } from '@celo/base/lib/collections' import { Address, CeloTransactionObject, EventLog, toTransactionObject } from '@celo/connect' import BigNumber from 'bignumber.js' -import { Election } from '../generated/Election' +import { Election } from '@celo/abis/types/web3/Election' import { fixidityValueToBigNumber, identity, diff --git a/packages/sdk/contractkit/src/wrappers/EpochRewards.ts b/packages/sdk/contractkit/src/wrappers/EpochRewards.ts index c1e6b36ceb3..bd069b010d9 100644 --- a/packages/sdk/contractkit/src/wrappers/EpochRewards.ts +++ b/packages/sdk/contractkit/src/wrappers/EpochRewards.ts @@ -1,5 +1,5 @@ import { fromFixed } from '@celo/utils/lib/fixidity' -import { EpochRewards } from '../generated/EpochRewards' +import { EpochRewards } from '@celo/abis/types/web3/EpochRewards' import { BaseWrapper, proxyCall, valueToBigNumber } from './BaseWrapper' const parseFixidity = (v: string) => fromFixed(valueToBigNumber(v)) diff --git a/packages/sdk/contractkit/src/wrappers/Erc20Wrapper.ts b/packages/sdk/contractkit/src/wrappers/Erc20Wrapper.ts index 31269a840e4..6413e1f12b4 100644 --- a/packages/sdk/contractkit/src/wrappers/Erc20Wrapper.ts +++ b/packages/sdk/contractkit/src/wrappers/Erc20Wrapper.ts @@ -2,7 +2,7 @@ // after the move to node 10. This allows types to be inferred without // referencing '@celo/utils/node_modules/bignumber.js' import BigNumber from 'bignumber.js' -import { IERC20 } from '../generated/IERC20' +import { IERC20 } from '@celo/abis/types/web3/IERC20' import { BaseWrapper, proxyCall, proxySend, valueToBigNumber } from './BaseWrapper' /** diff --git a/packages/sdk/contractkit/src/wrappers/Escrow.ts b/packages/sdk/contractkit/src/wrappers/Escrow.ts index 4742b0c18b7..efd17b260ba 100644 --- a/packages/sdk/contractkit/src/wrappers/Escrow.ts +++ b/packages/sdk/contractkit/src/wrappers/Escrow.ts @@ -1,5 +1,5 @@ import { Address, CeloTransactionObject } from '@celo/connect' -import { Escrow } from '../generated/Escrow' +import { Escrow } from '@celo/abis/types/web3/Escrow' import { BaseWrapper, proxyCall, proxySend } from './BaseWrapper' /** diff --git a/packages/sdk/contractkit/src/wrappers/Exchange.ts b/packages/sdk/contractkit/src/wrappers/Exchange.ts index 1cc3177d229..f788ca06947 100644 --- a/packages/sdk/contractkit/src/wrappers/Exchange.ts +++ b/packages/sdk/contractkit/src/wrappers/Exchange.ts @@ -1,6 +1,6 @@ import { CeloTransactionObject } from '@celo/connect' import BigNumber from 'bignumber.js' -import { Exchange } from '../generated/mento/Exchange' +import { Exchange } from '@celo/abis/types/web3/mento/Exchange' import { BaseWrapper, fixidityValueToBigNumber, diff --git a/packages/sdk/contractkit/src/wrappers/FederatedAttestations.ts b/packages/sdk/contractkit/src/wrappers/FederatedAttestations.ts index 4323ccffa39..02ee2fec708 100644 --- a/packages/sdk/contractkit/src/wrappers/FederatedAttestations.ts +++ b/packages/sdk/contractkit/src/wrappers/FederatedAttestations.ts @@ -1,6 +1,6 @@ import { Address, CeloTransactionObject, toTransactionObject } from '@celo/connect' import { registerAttestation as buildRegisterAttestationTypedData } from '@celo/utils/lib/typed-data-constructors' -import { FederatedAttestations } from '../generated/FederatedAttestations' +import { FederatedAttestations } from '@celo/abis/types/web3/FederatedAttestations' import { BaseWrapper, proxyCall, proxySend } from './BaseWrapper' export class FederatedAttestationsWrapper extends BaseWrapper { diff --git a/packages/sdk/contractkit/src/wrappers/FeeHandler.ts b/packages/sdk/contractkit/src/wrappers/FeeHandler.ts index 207db37a68c..d4ae61a9dc1 100644 --- a/packages/sdk/contractkit/src/wrappers/FeeHandler.ts +++ b/packages/sdk/contractkit/src/wrappers/FeeHandler.ts @@ -1,7 +1,7 @@ import { Address } from '@celo/connect' import BigNumber from 'bignumber.js' import { StableTokenContract } from '../base' -import { FeeHandler } from '../generated/FeeHandler' +import { FeeHandler } from '@celo/abis/types/web3/FeeHandler' import { BaseWrapper, proxyCall, proxySend } from './BaseWrapper' export enum ExchangeProposalState { diff --git a/packages/sdk/contractkit/src/wrappers/Freezer.ts b/packages/sdk/contractkit/src/wrappers/Freezer.ts index 2dcb5ec8b58..c961af9be04 100644 --- a/packages/sdk/contractkit/src/wrappers/Freezer.ts +++ b/packages/sdk/contractkit/src/wrappers/Freezer.ts @@ -1,4 +1,4 @@ -import { Freezer } from '../generated/Freezer' +import { Freezer } from '@celo/abis/types/web3/Freezer' import { BaseWrapper, proxyCall, proxySend } from './BaseWrapper' export class FreezerWrapper extends BaseWrapper { diff --git a/packages/sdk/contractkit/src/wrappers/GasPriceMinimum.ts b/packages/sdk/contractkit/src/wrappers/GasPriceMinimum.ts index 87cfbda9bf1..747f728e0cf 100644 --- a/packages/sdk/contractkit/src/wrappers/GasPriceMinimum.ts +++ b/packages/sdk/contractkit/src/wrappers/GasPriceMinimum.ts @@ -1,5 +1,5 @@ import BigNumber from 'bignumber.js' -import { GasPriceMinimum } from '../generated/0.8/GasPriceMinimum' +import { GasPriceMinimum } from '@celo/abis/types/web3/0.8/GasPriceMinimum' import { BaseWrapper, fixidityValueToBigNumber, proxyCall, valueToBigNumber } from './BaseWrapper' export interface GasPriceMinimumConfig { diff --git a/packages/sdk/contractkit/src/wrappers/GoldTokenWrapper.ts b/packages/sdk/contractkit/src/wrappers/GoldTokenWrapper.ts index 370b98f27bf..ae9bcfe6652 100644 --- a/packages/sdk/contractkit/src/wrappers/GoldTokenWrapper.ts +++ b/packages/sdk/contractkit/src/wrappers/GoldTokenWrapper.ts @@ -3,7 +3,7 @@ // referencing '@celo/utils/node_modules/bignumber.js' import { Address } from '@celo/base' import 'bignumber.js' -import { GoldToken } from '../generated/GoldToken' +import { GoldToken } from '@celo/abis/types/web3/GoldToken' import { proxySend, stringIdentity, diff --git a/packages/sdk/contractkit/src/wrappers/Governance.test.ts b/packages/sdk/contractkit/src/wrappers/Governance.test.ts index 1505f05b1f0..1e19f91e443 100644 --- a/packages/sdk/contractkit/src/wrappers/Governance.test.ts +++ b/packages/sdk/contractkit/src/wrappers/Governance.test.ts @@ -4,7 +4,7 @@ import { NetworkConfig, testWithGanache, timeTravel } from '@celo/dev-utils/lib/ import BigNumber from 'bignumber.js' import Web3 from 'web3' import { CeloContract } from '..' -import { Registry } from '../generated/Registry' +import { Registry } from '@celo/abis/types/web3/Registry' import { newKitFromWeb3 } from '../kit' import { AccountsWrapper } from './Accounts' import { GovernanceWrapper, Proposal, ProposalTransaction, VoteValue } from './Governance' diff --git a/packages/sdk/contractkit/src/wrappers/Governance.ts b/packages/sdk/contractkit/src/wrappers/Governance.ts index 6cc2c23e58c..33a6892a095 100644 --- a/packages/sdk/contractkit/src/wrappers/Governance.ts +++ b/packages/sdk/contractkit/src/wrappers/Governance.ts @@ -10,7 +10,7 @@ import { zeroRange, zip } from '@celo/base/lib/collections' import { Address, CeloTxPending, toTransactionObject } from '@celo/connect' import { fromFixed } from '@celo/utils/lib/fixidity' import BigNumber from 'bignumber.js' -import { Governance } from '../generated/Governance' +import { Governance } from '@celo/abis/types/web3/Governance' import { bufferToSolidityBytes, identity, diff --git a/packages/sdk/contractkit/src/wrappers/GrandaMento.ts b/packages/sdk/contractkit/src/wrappers/GrandaMento.ts index 5b56775fa00..aeb91cf5fe5 100644 --- a/packages/sdk/contractkit/src/wrappers/GrandaMento.ts +++ b/packages/sdk/contractkit/src/wrappers/GrandaMento.ts @@ -1,8 +1,8 @@ import BigNumber from 'bignumber.js' import { StableTokenContract } from '../base' import { StableToken as StableTokenEnum, stableTokenInfos } from '../celo-tokens' -import { GrandaMento } from '../generated/mento/GrandaMento' -import { newStableToken } from '../generated/mento/StableToken' +import { GrandaMento } from '@celo/abis/types/web3/mento/GrandaMento' +import { newStableToken } from '@celo/abis/types/web3/mento/StableToken' import { BaseWrapper, fixidityValueToBigNumber, diff --git a/packages/sdk/contractkit/src/wrappers/LockedGold.ts b/packages/sdk/contractkit/src/wrappers/LockedGold.ts index d36721a590c..bb00c3d6653 100644 --- a/packages/sdk/contractkit/src/wrappers/LockedGold.ts +++ b/packages/sdk/contractkit/src/wrappers/LockedGold.ts @@ -6,7 +6,7 @@ import { } from '@celo/base/lib/collections' import { Address, CeloTransactionObject, EventLog } from '@celo/connect' import BigNumber from 'bignumber.js' -import { LockedGold } from '../generated/LockedGold' +import { LockedGold } from '@celo/abis/types/web3/LockedGold' import { ContractVersion } from '../versions' import { proxyCall, diff --git a/packages/sdk/contractkit/src/wrappers/MetaTransactionWallet.ts b/packages/sdk/contractkit/src/wrappers/MetaTransactionWallet.ts index b9aff8794e5..65f8340b33b 100644 --- a/packages/sdk/contractkit/src/wrappers/MetaTransactionWallet.ts +++ b/packages/sdk/contractkit/src/wrappers/MetaTransactionWallet.ts @@ -3,7 +3,7 @@ import { Signature } from '@celo/base/lib/signatureUtils' import { CeloTransactionObject, CeloTxObject, toTransactionObject } from '@celo/connect' import { EIP712TypedData } from '@celo/utils/lib/sign-typed-data-utils' import BigNumber from 'bignumber.js' -import { MetaTransactionWallet } from '../generated/MetaTransactionWallet' +import { MetaTransactionWallet } from '@celo/abis/types/web3/MetaTransactionWallet' import { BaseWrapper, proxyCall, diff --git a/packages/sdk/contractkit/src/wrappers/MetaTransactionWalletDeployer.test.ts b/packages/sdk/contractkit/src/wrappers/MetaTransactionWalletDeployer.test.ts index 335727826ff..420bfd8b03e 100644 --- a/packages/sdk/contractkit/src/wrappers/MetaTransactionWalletDeployer.test.ts +++ b/packages/sdk/contractkit/src/wrappers/MetaTransactionWalletDeployer.test.ts @@ -3,8 +3,11 @@ import MTWContractArtifacts from '@celo/celo-devchain/contracts/contracts-0.5/Me import MTWDeployerContractArtifacts from '@celo/celo-devchain/contracts/contracts-0.5/MetaTransactionWalletDeployer.json' import { CeloTxReceipt, EventLog } from '@celo/connect' import { testWithGanache } from '@celo/dev-utils/lib/ganache-test' -import { MetaTransactionWallet, newMetaTransactionWallet } from '../generated/MetaTransactionWallet' -import { newProxy } from '../generated/Proxy' +import { + MetaTransactionWallet, + newMetaTransactionWallet, +} from '@celo/abis/types/web3/MetaTransactionWallet' +import { newProxy } from '@celo/abis/types/web3/Proxy' import { newKitFromWeb3 } from '../kit' import { MetaTransactionWalletDeployerWrapper } from './MetaTransactionWalletDeployer' From 404c55f57d062d2ed27b8f7ae0a86d03f6822cec Mon Sep 17 00:00:00 2001 From: Leszek Stachowski Date: Wed, 29 Nov 2023 16:14:29 +0100 Subject: [PATCH 13/63] change @celo/abis to be a regular dependency instead of a dev one --- packages/sdk/contractkit/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sdk/contractkit/package.json b/packages/sdk/contractkit/package.json index 18afb321333..d4cc5370221 100644 --- a/packages/sdk/contractkit/package.json +++ b/packages/sdk/contractkit/package.json @@ -27,6 +27,7 @@ "lint": "tslint -c tslint.json --project ." }, "dependencies": { + "@celo/abis": "10.0.0-beta.3", "@celo/base": "^6.0.0", "@celo/connect": "^5.1.1", "@celo/utils": "^5.0.6", @@ -43,7 +44,6 @@ "web3-core-helpers": "1.10.0" }, "devDependencies": { - "@celo/abis": "10.0.0-beta.3", "@celo/celo-devchain": "^6.0.3-beta.1", "@celo/odis-identifiers": "^1.0.0", "@celo/dev-utils": "0.0.1", From d24e275ca9ad243b7908147f2d0889513281b82d Mon Sep 17 00:00:00 2001 From: Leszek Stachowski Date: Wed, 29 Nov 2023 17:37:12 +0100 Subject: [PATCH 14/63] remove extraneous fields from generated jsons --- .../prepare-contracts-and-abis-publishing.ts | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts b/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts index 0bd617fd6bb..ccc8aa0c9a2 100644 --- a/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts +++ b/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts @@ -65,6 +65,8 @@ try { } }) + removeExtraneousFieldsFromGeneratedJsons() + // Generate wagmi friendly ts files log('Running yarn wagmi generate') child_process.execSync(`yarn wagmi generate`, { stdio: 'inherit' }) @@ -86,6 +88,37 @@ try { } // Helper functions +function removeExtraneousFieldsFromGeneratedJsons() { + log('Removing extraneous fields from generated json files') + const fileNames = fs.readdirSync(ABIS_BUILD_DIR) + + fileNames.forEach((fileName) => { + const filePath = path.join(ABIS_BUILD_DIR, fileName) + const parsedPath = path.parse(filePath) + + // TODO create a single const for all contracts + if ( + Interfaces.includes(parsedPath.name) || + CoreContracts.includes(parsedPath.name) || + parsedPath.name === 'Proxy' + ) { + const json = JSON.parse(fs.readFileSync(filePath).toString()) + + fs.writeFileSync( + filePath, + JSON.stringify( + { + contractName: json.contractName, + abi: json.abi, + }, + null, + 2 + ) + ) + } + }) +} + function prepareAbisPackageJson() { log('Preparing @celo/abis package.json') const sourcePackageJson = path.join(ABIS_PACKAGE_SRC_DIR, 'package.json.dist') From bfbec5720a5bf4f62b6eb1a6051dce8d0355b4a9 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 29 Nov 2023 19:03:03 +0200 Subject: [PATCH 15/63] Version Packages (#10776) Co-authored-by: github-actions[bot] --- .changeset/gold-crabs-carry.md | 5 ----- .changeset/new-queens-smoke.md | 5 ----- .changeset/rotten-weeks-sip.md | 6 ------ .changeset/strange-eels-live.md | 5 ----- packages/cli/CHANGELOG.md | 10 ++++++++++ packages/cli/package.json | 4 ++-- packages/sdk/contractkit/CHANGELOG.md | 8 ++++++++ packages/sdk/contractkit/package.json | 2 +- 8 files changed, 21 insertions(+), 24 deletions(-) delete mode 100644 .changeset/gold-crabs-carry.md delete mode 100644 .changeset/new-queens-smoke.md delete mode 100644 .changeset/rotten-weeks-sip.md delete mode 100644 .changeset/strange-eels-live.md diff --git a/.changeset/gold-crabs-carry.md b/.changeset/gold-crabs-carry.md deleted file mode 100644 index 93c2639dad1..00000000000 --- a/.changeset/gold-crabs-carry.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@celo/contractkit': patch ---- - -add notice that LockedGold.getTotalPendingWithdrawalsCount is not yet available on all networks diff --git a/.changeset/new-queens-smoke.md b/.changeset/new-queens-smoke.md deleted file mode 100644 index 4753a2d1649..00000000000 --- a/.changeset/new-queens-smoke.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@celo/celocli': patch ---- - -network:contracts command fix added StableTokens to unversioned contracts list diff --git a/.changeset/rotten-weeks-sip.md b/.changeset/rotten-weeks-sip.md deleted file mode 100644 index e9027f5d65d..00000000000 --- a/.changeset/rotten-weeks-sip.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -'@celo/contractkit': patch ---- - -Mark MetaTransactionWallet and MetaTransactionWalletDeployer as deprecated, including functions to get them and their wrappers. see https://github.com/celo-org/celo-monorepo/issues/10766 - diff --git a/.changeset/strange-eels-live.md b/.changeset/strange-eels-live.md deleted file mode 100644 index 8b8d97cb0cd..00000000000 --- a/.changeset/strange-eels-live.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@celo/contractkit': patch ---- - -Refactor Accounts.getParsedSignatureOfAddress diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md index b34bb9d3369..0e950bedcaa 100644 --- a/packages/cli/CHANGELOG.md +++ b/packages/cli/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## 3.1.1 + +### Patch Changes + +- 6ff7f4a1e: network:contracts command fix added StableTokens to unversioned contracts list +- Updated dependencies [88e3788b8] +- Updated dependencies [70f600bb0] +- Updated dependencies [2985f9eb2] + - @celo/contractkit@5.2.1 + ## 3.1.0 ### Minor Changes diff --git a/packages/cli/package.json b/packages/cli/package.json index 569e6cae2c8..9705520caa7 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,7 +1,7 @@ { "name": "@celo/celocli", "description": "CLI Tool for transacting with the Celo protocol", - "version": "3.1.0", + "version": "3.1.1", "author": "Celo", "license": "Apache-2.0", "repository": "celo-org/celo-monorepo", @@ -33,7 +33,7 @@ "@celo/base": "^6.0.0", "@celo/celo-devchain": "^6.0.3-beta.1", "@celo/connect": "^5.1.1", - "@celo/contractkit": "^5.2.0", + "@celo/contractkit": "^5.2.1", "@celo/explorer": "^5.0.6", "@celo/governance": "^5.0.6", "@celo/identity": "^5.1.1", diff --git a/packages/sdk/contractkit/CHANGELOG.md b/packages/sdk/contractkit/CHANGELOG.md index 7fc28fcfcbd..5713f855e65 100644 --- a/packages/sdk/contractkit/CHANGELOG.md +++ b/packages/sdk/contractkit/CHANGELOG.md @@ -1,5 +1,13 @@ # @celo/contractkit +## 5.2.1 + +### Patch Changes + +- 88e3788b8: add notice that LockedGold.getTotalPendingWithdrawalsCount is not yet available on all networks +- 70f600bb0: Mark MetaTransactionWallet and MetaTransactionWalletDeployer as deprecated, including functions to get them and their wrappers. see https://github.com/celo-org/celo-monorepo/issues/10766 +- 2985f9eb2: Refactor Accounts.getParsedSignatureOfAddress + ## 5.2.0 ### Minor Changes diff --git a/packages/sdk/contractkit/package.json b/packages/sdk/contractkit/package.json index e216315ed54..eda6808236b 100644 --- a/packages/sdk/contractkit/package.json +++ b/packages/sdk/contractkit/package.json @@ -1,6 +1,6 @@ { "name": "@celo/contractkit", - "version": "5.2.0", + "version": "5.2.1", "description": "Celo's ContractKit to interact with Celo network", "main": "./lib/index.js", "types": "./lib/index.d.ts", From 550caf4e421cecb4689ac268218c68e252a15df2 Mon Sep 17 00:00:00 2001 From: Leszek Stachowski Date: Wed, 29 Nov 2023 18:05:17 +0100 Subject: [PATCH 16/63] missing yarn.lock + bump up @celo/abis --- packages/sdk/contractkit/package.json | 2 +- yarn.lock | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/sdk/contractkit/package.json b/packages/sdk/contractkit/package.json index d4cc5370221..15dc5ba3460 100644 --- a/packages/sdk/contractkit/package.json +++ b/packages/sdk/contractkit/package.json @@ -27,7 +27,7 @@ "lint": "tslint -c tslint.json --project ." }, "dependencies": { - "@celo/abis": "10.0.0-beta.3", + "@celo/abis": "10.0.0-beta.4", "@celo/base": "^6.0.0", "@celo/connect": "^5.1.1", "@celo/utils": "^5.0.6", diff --git a/yarn.lock b/yarn.lock index b7862e180fd..7e2bedc0dd1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -973,6 +973,11 @@ resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== +"@celo/abis@10.0.0-beta.4": + version "10.0.0-beta.4" + resolved "https://registry.yarnpkg.com/@celo/abis/-/abis-10.0.0-beta.4.tgz#9540c422e90f14a35032a33cd4380cfefe31ec27" + integrity sha512-qA5Iv9pjBniL9GeOclvIkTtflECZPCLtsWOx2zEiCXsqdGMRDJhkNuFpvViihyOqNLD9yxARXyklqiM1L07xpw== + "@celo/base@^5.0.5": version "5.0.5" resolved "https://registry.yarnpkg.com/@celo/base/-/base-5.0.5.tgz#b4102faba080ce536411b7987259d9ca152b6e6d" From 8d341ab49be987a0d92670deae1e6278639f9fe8 Mon Sep 17 00:00:00 2001 From: Aaron DeRuvo Date: Thu, 30 Nov 2023 10:31:38 +0200 Subject: [PATCH 17/63] no longer need build:gen as the contract interfaces come from celo/abis... so also no need to clean /generated. --- packages/sdk/contractkit/package.json | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/sdk/contractkit/package.json b/packages/sdk/contractkit/package.json index 15dc5ba3460..cf4cb3b3bb5 100644 --- a/packages/sdk/contractkit/package.json +++ b/packages/sdk/contractkit/package.json @@ -16,11 +16,8 @@ ], "scripts": { "build:ts": "tsc -b .", - "build:gen": "yarn --cwd ../../protocol ts-node ./scripts/build.ts --web3Types ../sdk/contractkit/src/generated", - "build": "yarn build:gen && yarn build:ts", - "build:releasetag": "BUILD_DIR=./build/$RELEASE_TAG yarn build", + "build": "tsc -b .", "clean": "tsc -b . --clean", - "clean:all": "yarn clean && rm -rf src/generated", "prepublishOnly": "yarn build", "docs": "typedoc", "test": "jest --runInBand --forceExit", @@ -47,7 +44,6 @@ "@celo/celo-devchain": "^6.0.3-beta.1", "@celo/odis-identifiers": "^1.0.0", "@celo/dev-utils": "0.0.1", - "@celo/protocol": "1.0.2", "@types/debug": "^4.1.5", "fetch-mock": "9.10.4", "ganache": "npm:@celo/ganache@7.8.0-unofficial.0", From 1dd2ea3be20467095d9f7339b58600bfc978a60c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Volpe?= Date: Thu, 30 Nov 2023 14:32:38 +0100 Subject: [PATCH 18/63] Added Foundry clean command (#10770) --- packages/protocol/foundry.toml | 2 +- packages/protocol/package.json | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/protocol/foundry.toml b/packages/protocol/foundry.toml index 6795b82b92b..012768da682 100644 --- a/packages/protocol/foundry.toml +++ b/packages/protocol/foundry.toml @@ -1,4 +1,4 @@ -[default] +[profile.default] src = 'contracts' out = 'out' test = 'test-sol' diff --git a/packages/protocol/package.json b/packages/protocol/package.json index 750a720e2e0..b84b1ddafeb 100644 --- a/packages/protocol/package.json +++ b/packages/protocol/package.json @@ -9,7 +9,8 @@ "lint:ts": "tslint -c tslint.json --project tsconfig.json", "lint:sol": "solhint './contracts/**/*.sol'", "lint": "yarn run lint:ts && yarn run lint:sol", - "clean": "rm -rf ./types/typechain && rm -rf build/* && rm -rf .0x-artifacts/* && rm -rf migrations/*.js* && rm -rf migrations_ts/*.js* && rm -rf test/**/*.js* && rm -f lib/*.js* && rm -f lib/**/*.js* && rm -f scripts/*.js*", + "clean": "rm -rf ./types/typechain && rm -rf build/* && rm -rf .0x-artifacts/* && rm -rf migrations/*.js* && rm -rf migrations_ts/*.js* && rm -rf test/**/*.js* && rm -f lib/*.js* && rm -f lib/**/*.js* && rm -f scripts/*.js* && yarn clean:foundry", + "clean:foundry": "rm -rf cache out", "test": "rm test/**/*.js ; node runTests.js", "quicktest": "./scripts/bash/quicktest.sh", "test:coverage": "yarn run test --coverage", From 90a16c95129ad0df757f9bd6e2eea6f4f02e51a6 Mon Sep 17 00:00:00 2001 From: Leszek Stachowski Date: Thu, 30 Nov 2023 15:33:36 +0100 Subject: [PATCH 19/63] esm/cjs compilation --- .../publish-contracts-abi-release.yml | 2 +- packages/protocol/abis/package-cjs.json | 3 + packages/protocol/abis/package-esm.json | 3 + .../abis/{package.json.dist => package.json} | 8 +- packages/protocol/abis/tsconfig-cjs.json | 8 + packages/protocol/abis/tsconfig.json | 25 ++++ packages/protocol/scripts/consts.ts | 9 +- .../prepare-contracts-and-abis-publishing.ts | 140 ++++++++++++++---- 8 files changed, 163 insertions(+), 35 deletions(-) create mode 100644 packages/protocol/abis/package-cjs.json create mode 100644 packages/protocol/abis/package-esm.json rename packages/protocol/abis/{package.json.dist => package.json} (64%) create mode 100644 packages/protocol/abis/tsconfig-cjs.json create mode 100644 packages/protocol/abis/tsconfig.json diff --git a/.github/workflows/publish-contracts-abi-release.yml b/.github/workflows/publish-contracts-abi-release.yml index cc76dc9b899..fae567d34fc 100644 --- a/.github/workflows/publish-contracts-abi-release.yml +++ b/.github/workflows/publish-contracts-abi-release.yml @@ -80,7 +80,7 @@ jobs: run: | cat package.json npm publish $RELEASE_TYPE $DRY_RUN - working-directory: packages/protocol/abis/src-generated + working-directory: packages/protocol/abis env: RELEASE_TYPE: --tag ${{ env.RELEASE_TYPE != '' && env.RELEASE_TYPE || 'canary' }} RELEASE_VERSION: ${{ env.RELEASE_VERSION }} diff --git a/packages/protocol/abis/package-cjs.json b/packages/protocol/abis/package-cjs.json new file mode 100644 index 00000000000..5bbefffbabe --- /dev/null +++ b/packages/protocol/abis/package-cjs.json @@ -0,0 +1,3 @@ +{ + "type": "commonjs" +} diff --git a/packages/protocol/abis/package-esm.json b/packages/protocol/abis/package-esm.json new file mode 100644 index 00000000000..3dbc1ca591c --- /dev/null +++ b/packages/protocol/abis/package-esm.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/packages/protocol/abis/package.json.dist b/packages/protocol/abis/package.json similarity index 64% rename from packages/protocol/abis/package.json.dist rename to packages/protocol/abis/package.json index 8b1dcac8937..b18291a0d3a 100644 --- a/packages/protocol/abis/package.json.dist +++ b/packages/protocol/abis/package.json @@ -4,11 +4,13 @@ "author": "cLabs", "license": "LGPL-3.0", "repository": { - "type": "git", - "url": "https://github.com/celo-org/celo-monorepo.git", + "url": "git+https://github.com/celo-org/celo-monorepo.git", "directory": "packages/protocol/abis" }, "scripts": {}, "dependencies": {}, - "types": "./types/wagmi/index.d.ts" + "peerDependencies": {}, + "files": [ + "./dist" + ] } diff --git a/packages/protocol/abis/tsconfig-cjs.json b/packages/protocol/abis/tsconfig-cjs.json new file mode 100644 index 00000000000..3734495e62e --- /dev/null +++ b/packages/protocol/abis/tsconfig-cjs.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "CommonJS", + "outDir": "./dist/cjs" + }, + "references": [{ "path": "../../sdk/utils" }] +} \ No newline at end of file diff --git a/packages/protocol/abis/tsconfig.json b/packages/protocol/abis/tsconfig.json new file mode 100644 index 00000000000..7c400b0f1e2 --- /dev/null +++ b/packages/protocol/abis/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compileOnSave": false, + "compilerOptions": { + "allowSyntheticDefaultImports": true, + "esModuleInterop": true, + "baseUrl": ".", + "strict": true, + "moduleResolution": "node", + "noUnusedLocals": true, + "noUnusedParameters": true, + "removeComments": false, + "skipLibCheck": true, + "sourceMap": true, + "target": "ES2020", + "downlevelIteration": true, + "resolveJsonModule": true, + "declaration": true, + "module": "ES2020", + "rootDir": "./src-generated", + "outDir": "./dist/esm" + }, + "include": ["./src-generated"], + "exclude": ["./src-generated/types/ethers"], + "references": [{ "path": "../../sdk/utils" }] +} \ No newline at end of file diff --git a/packages/protocol/scripts/consts.ts b/packages/protocol/scripts/consts.ts index f9abd216234..645fdbb98d0 100644 --- a/packages/protocol/scripts/consts.ts +++ b/packages/protocol/scripts/consts.ts @@ -5,9 +5,12 @@ export const ROOT_DIR = path.join(__dirname, '../') export const CONTRACTS_PACKAGE_SRC_DIR = path.join(__dirname, '../contracts') export const ABIS_PACKAGE_SRC_DIR = path.join(__dirname, '../abis') export const ABIS_BUILD_DIR = path.join(ABIS_PACKAGE_SRC_DIR, 'src-generated') +export const ABIS_DIST_DIR = path.join(ABIS_PACKAGE_SRC_DIR, 'dist') export const BUILD_EXECUTABLE = path.join(__dirname, 'build.ts') export const TSCONFIG_PATH = path.join(ROOT_DIR, 'tsconfig.json') +const PROXY_CONTRACT = 'Proxy' + export const ProxyContracts = [ 'AccountsProxy', 'AttestationsProxy', @@ -73,7 +76,7 @@ export const CoreContracts = [ ] export const OtherContracts = [ - 'Proxy', + PROXY_CONTRACT, 'Migrations', // abstract 'Initializable', @@ -85,3 +88,7 @@ export const contractPackages = [MENTO_PACKAGE, SOLIDITY_08_PACKAGE].filter(Bool export const Interfaces = ['ICeloToken', 'IERC20', 'ICeloVersionedContract'] export const ImplContracts = OtherContracts.concat(ProxyContracts).concat(CoreContracts) + +export const PublishContracts = CoreContracts.concat(Interfaces) + .concat(PROXY_CONTRACT) + .concat(MENTO_PACKAGE.contracts) diff --git a/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts b/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts index ccc8aa0c9a2..e24363afce7 100644 --- a/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts +++ b/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts @@ -5,11 +5,11 @@ import { sync as rmrfSync } from 'rimraf' import { MENTO_PACKAGE, SOLIDITY_08_PACKAGE } from '../contractPackages' import { ABIS_BUILD_DIR, + ABIS_DIST_DIR, ABIS_PACKAGE_SRC_DIR, BUILD_EXECUTABLE, CONTRACTS_PACKAGE_SRC_DIR, - CoreContracts, - Interfaces, + PublishContracts, TSCONFIG_PATH, } from './consts' @@ -25,8 +25,9 @@ try { fs.writeFileSync(TSCONFIG_PATH, JSON.stringify(tsconfig, null, 4)) // Start from scratch - rmrfSync([ABIS_BUILD_DIR, path.join(ABIS_PACKAGE_SRC_DIR, 'lib')]) + rmrfSync([ABIS_BUILD_DIR, ABIS_DIST_DIR]) fs.mkdirSync(ABIS_BUILD_DIR, { recursive: true }) + fs.mkdirSync(ABIS_DIST_DIR, { recursive: true }) // Generate all ABIs build(`--solidity ${path.join(ABIS_BUILD_DIR)}`) @@ -35,7 +36,6 @@ try { build(`--ethersTypes ${path.join(ABIS_BUILD_DIR, 'types/ethers')}`) // Generate web3 typings - // TODO web3 is generating nested dir structure build(`--web3Types ${path.join(ABIS_BUILD_DIR, 'types/web3')}`) // Merge contracts-0.8, contracts-mento, etc.. at the root of the build dir @@ -52,12 +52,7 @@ try { const name = path.basename(filePath) const baseName = name.replace(/.(sol|d.ts|json)$/, '') - if ( - baseName !== 'index' && - baseName !== 'Proxy' && - !CoreContracts.includes(baseName) && - !Interfaces.includes(baseName) - ) { + if (baseName !== 'index' && !PublishContracts.includes(baseName)) { rmrfSync(path.join(ABIS_BUILD_DIR, `${baseName}.json`)) rmrfSync(path.join(ABIS_BUILD_DIR, `${baseName}.ts`)) rmrfSync(path.join(ABIS_BUILD_DIR, '**', `${baseName}.d.ts`)) @@ -65,19 +60,29 @@ try { } }) - removeExtraneousFieldsFromGeneratedJsons() + let exports = processRawJsonsAndPrepareExports() // Generate wagmi friendly ts files log('Running yarn wagmi generate') child_process.execSync(`yarn wagmi generate`, { stdio: 'inherit' }) - fs.copyFileSync( - path.join(ABIS_PACKAGE_SRC_DIR, 'README.md'), - path.join(ABIS_BUILD_DIR, 'README.md') - ) + log('Compiling esm') + child_process.execSync(`yarn tsc -b ${path.join(ABIS_PACKAGE_SRC_DIR, 'tsconfig.json')}`, { + stdio: 'inherit', + }) + + log('Compiling cjs') + child_process.execSync(`yarn tsc -b ${path.join(ABIS_PACKAGE_SRC_DIR, 'tsconfig-cjs.json')}`, { + stdio: 'inherit', + }) + + exports = { + ...exports, + ...prepareTargetTypesExports(), + } // Change the packages version to what CI is providing from environment variables - prepareAbisPackageJson() + prepareAbisPackageJson(exports) prepareContractsPackageJson() } finally { // Cleanup @@ -88,7 +93,73 @@ try { } // Helper functions -function removeExtraneousFieldsFromGeneratedJsons() { +function prepareTargetTypesExports() { + const exports = {} + const targets = ['esm', 'cjs'] + + targets.forEach((target) => { + fs.copyFileSync( + path.join(ABIS_PACKAGE_SRC_DIR, `package-${target}.json`), + path.join(ABIS_DIST_DIR, target, 'package.json') + ) + + const filePaths = lsRecursive(path.join(ABIS_DIST_DIR, target)) + + filePaths.forEach((filePath) => { + const parsedPath = path.parse(filePath) + + if (PublishContracts.includes(parsedPath.name)) { + const relativePath = path.join( + path.relative(ABIS_PACKAGE_SRC_DIR, parsedPath.dir), + parsedPath.name + ) + const exportKey = `./${path.join( + path.relative(path.join(ABIS_DIST_DIR, target), parsedPath.dir), + parsedPath.name + )}` + + if (!exports.hasOwnProperty(exportKey)) { + exports[exportKey] = {} + } + + if (target == 'esm') { + const typesPath = `./${relativePath}.d.ts` + const importPath = `./${relativePath}.js` + + expectFileExists(typesPath) + expectFileExists(importPath) + + exports[exportKey] = { + ...exports[exportKey], + types: typesPath, + import: importPath, + } + } else { + const requirePath = `./${relativePath}.js` + + expectFileExists(requirePath) + + exports[exportKey] = { + ...exports[exportKey], + require: `./${relativePath}.js`, + } + } + } + }) + }) + + return exports +} + +function expectFileExists(relativePath: string) { + if (!fs.existsSync(path.join(ABIS_PACKAGE_SRC_DIR, relativePath))) { + throw new Error(`Expected file ${relativePath} to exist`) + } +} + +function processRawJsonsAndPrepareExports() { + const exports = {} + log('Removing extraneous fields from generated json files') const fileNames = fs.readdirSync(ABIS_BUILD_DIR) @@ -96,16 +167,15 @@ function removeExtraneousFieldsFromGeneratedJsons() { const filePath = path.join(ABIS_BUILD_DIR, fileName) const parsedPath = path.parse(filePath) - // TODO create a single const for all contracts - if ( - Interfaces.includes(parsedPath.name) || - CoreContracts.includes(parsedPath.name) || - parsedPath.name === 'Proxy' - ) { + if (PublishContracts.includes(parsedPath.name)) { const json = JSON.parse(fs.readFileSync(filePath).toString()) + const defaultPath = path.join( + path.relative(ABIS_PACKAGE_SRC_DIR, ABIS_DIST_DIR), + `${parsedPath.name}.json` + ) fs.writeFileSync( - filePath, + path.join(ABIS_DIST_DIR, fileName), JSON.stringify( { contractName: json.contractName, @@ -115,25 +185,35 @@ function removeExtraneousFieldsFromGeneratedJsons() { 2 ) ) + + expectFileExists(defaultPath) + + exports[`./${parsedPath.name}.json`] = { + default: `./${defaultPath}`, + } } }) + + return exports } -function prepareAbisPackageJson() { +function prepareAbisPackageJson(exports) { log('Preparing @celo/abis package.json') - const sourcePackageJson = path.join(ABIS_PACKAGE_SRC_DIR, 'package.json.dist') - const destinationPackageJson = path.join(ABIS_BUILD_DIR, 'package.json') - let contents = fs.readFileSync(sourcePackageJson).toString() + const packageJsonPath = path.join(ABIS_PACKAGE_SRC_DIR, 'package.json') + let json = JSON.parse(fs.readFileSync(packageJsonPath).toString()) if (process.env.RELEASE_VERSION) { log('Replacing @celo/abis version with provided RELEASE_VERSION') - contents = contents.replace('0.0.0-template.version', process.env.RELEASE_VERSION) + json.version = process.env.RELEASE_VERSION } else { log('No RELEASE_VERSION provided') } - fs.writeFileSync(destinationPackageJson, contents) + log('Setting @celo/abis exports') + json.exports = exports + + fs.writeFileSync(packageJsonPath, JSON.stringify(json, null, 2)) } function prepareContractsPackageJson() { From 3df7eb4cddca8f894ff501bd3a5904e242829ab3 Mon Sep 17 00:00:00 2001 From: Leszek Stachowski Date: Thu, 30 Nov 2023 15:57:54 +0100 Subject: [PATCH 20/63] missed changed imports --- .../contractkit/src/wrappers/MetaTransactionWalletDeployer.ts | 2 +- packages/sdk/contractkit/src/wrappers/MultiSig.ts | 2 +- packages/sdk/contractkit/src/wrappers/OdisPayments.ts | 2 +- packages/sdk/contractkit/src/wrappers/ReleaseGold.ts | 2 +- packages/sdk/contractkit/src/wrappers/Reserve.ts | 2 +- packages/sdk/contractkit/src/wrappers/SortedOracles.ts | 2 +- packages/sdk/contractkit/src/wrappers/StableTokenWrapper.ts | 2 +- packages/sdk/contractkit/src/wrappers/Validators.ts | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/sdk/contractkit/src/wrappers/MetaTransactionWalletDeployer.ts b/packages/sdk/contractkit/src/wrappers/MetaTransactionWalletDeployer.ts index 25fc0318777..f6be41356cf 100644 --- a/packages/sdk/contractkit/src/wrappers/MetaTransactionWalletDeployer.ts +++ b/packages/sdk/contractkit/src/wrappers/MetaTransactionWalletDeployer.ts @@ -1,4 +1,4 @@ -import { MetaTransactionWalletDeployer } from '../generated/MetaTransactionWalletDeployer' +import { MetaTransactionWalletDeployer } from '@celo/abis/types/web3/MetaTransactionWalletDeployer' import { BaseWrapper, proxySend } from './BaseWrapper' /* diff --git a/packages/sdk/contractkit/src/wrappers/MultiSig.ts b/packages/sdk/contractkit/src/wrappers/MultiSig.ts index e360529645f..5fa0355f9a9 100644 --- a/packages/sdk/contractkit/src/wrappers/MultiSig.ts +++ b/packages/sdk/contractkit/src/wrappers/MultiSig.ts @@ -1,6 +1,6 @@ import { Address, CeloTransactionObject, CeloTxObject, toTransactionObject } from '@celo/connect' import BigNumber from 'bignumber.js' -import { MultiSig } from '../generated/MultiSig' +import { MultiSig } from '@celo/abis/types/web3/MultiSig' import { BaseWrapper, proxyCall, diff --git a/packages/sdk/contractkit/src/wrappers/OdisPayments.ts b/packages/sdk/contractkit/src/wrappers/OdisPayments.ts index 3b4998a0a74..20dbe93f04d 100644 --- a/packages/sdk/contractkit/src/wrappers/OdisPayments.ts +++ b/packages/sdk/contractkit/src/wrappers/OdisPayments.ts @@ -1,6 +1,6 @@ import { Address, CeloTransactionObject } from '@celo/connect' import { BigNumber } from 'bignumber.js' -import { OdisPayments } from '../generated/OdisPayments' +import { OdisPayments } from '@celo/abis/types/web3/OdisPayments' import { BaseWrapper, proxyCall, proxySend, valueToBigNumber } from './BaseWrapper' export class OdisPaymentsWrapper extends BaseWrapper { diff --git a/packages/sdk/contractkit/src/wrappers/ReleaseGold.ts b/packages/sdk/contractkit/src/wrappers/ReleaseGold.ts index 5896cf1989d..181677d7e91 100644 --- a/packages/sdk/contractkit/src/wrappers/ReleaseGold.ts +++ b/packages/sdk/contractkit/src/wrappers/ReleaseGold.ts @@ -5,7 +5,7 @@ import { Address, CeloTransactionObject, toTransactionObject } from '@celo/conne import { hashMessageWithPrefix, signedMessageToPublicKey } from '@celo/utils/lib/signatureUtils' import BigNumber from 'bignumber.js' import { flatten } from 'fp-ts/lib/Array' -import { ReleaseGold } from '../generated/ReleaseGold' +import { ReleaseGold } from '@celo/abis/types/web3/ReleaseGold' import { proxyCall, proxySend, diff --git a/packages/sdk/contractkit/src/wrappers/Reserve.ts b/packages/sdk/contractkit/src/wrappers/Reserve.ts index b0bfe464889..1c894719e6c 100644 --- a/packages/sdk/contractkit/src/wrappers/Reserve.ts +++ b/packages/sdk/contractkit/src/wrappers/Reserve.ts @@ -1,6 +1,6 @@ import { Address, EventLog } from '@celo/connect' import BigNumber from 'bignumber.js' -import { Reserve } from '../generated/mento/Reserve' +import { Reserve } from '@celo/abis/types/web3/mento/Reserve' import { BaseWrapper, fixidityValueToBigNumber, diff --git a/packages/sdk/contractkit/src/wrappers/SortedOracles.ts b/packages/sdk/contractkit/src/wrappers/SortedOracles.ts index 2bc56e81161..5a447654d92 100644 --- a/packages/sdk/contractkit/src/wrappers/SortedOracles.ts +++ b/packages/sdk/contractkit/src/wrappers/SortedOracles.ts @@ -6,7 +6,7 @@ import BigNumber from 'bignumber.js' import { AddressRegistry } from '../address-registry' import { CeloContract, StableTokenContract } from '../base' import { isStableTokenContract, StableToken, stableTokenInfos } from '../celo-tokens' -import { SortedOracles } from '../generated/SortedOracles' +import { SortedOracles } from '@celo/abis/types/web3/SortedOracles' import { BaseWrapper, proxyCall, diff --git a/packages/sdk/contractkit/src/wrappers/StableTokenWrapper.ts b/packages/sdk/contractkit/src/wrappers/StableTokenWrapper.ts index d606f44321b..35169c72ad6 100644 --- a/packages/sdk/contractkit/src/wrappers/StableTokenWrapper.ts +++ b/packages/sdk/contractkit/src/wrappers/StableTokenWrapper.ts @@ -1,6 +1,6 @@ +import { StableToken } from '@celo/abis/types/web3/mento/StableToken' import { fromFixed } from '@celo/utils/lib/fixidity' import BigNumber from 'bignumber.js' -import { StableToken } from '../generated/mento/StableToken' import { proxyCall, proxySend, diff --git a/packages/sdk/contractkit/src/wrappers/Validators.ts b/packages/sdk/contractkit/src/wrappers/Validators.ts index 77a1db96c89..cbba7e560b5 100644 --- a/packages/sdk/contractkit/src/wrappers/Validators.ts +++ b/packages/sdk/contractkit/src/wrappers/Validators.ts @@ -4,7 +4,7 @@ import { zeroRange, zip } from '@celo/base/lib/collections' import { Address, CeloTransactionObject, EventLog, toTransactionObject } from '@celo/connect' import { fromFixed, toFixed } from '@celo/utils/lib/fixidity' import BigNumber from 'bignumber.js' -import { Validators } from '../generated/Validators' +import { Validators } from '@celo/abis/types/web3/Validators' import { blocksToDurationString, proxyCall, From e6dbff10a0761139560c2d3927a31f43ec14f2ed Mon Sep 17 00:00:00 2001 From: Leszek Stachowski Date: Thu, 30 Nov 2023 15:59:31 +0100 Subject: [PATCH 21/63] contract cache: use @celo/abis package --- .../contractkit/src/web3-contract-cache.ts | 68 +++++++++---------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/packages/sdk/contractkit/src/web3-contract-cache.ts b/packages/sdk/contractkit/src/web3-contract-cache.ts index 1fd60ba80c4..3e1396a1958 100644 --- a/packages/sdk/contractkit/src/web3-contract-cache.ts +++ b/packages/sdk/contractkit/src/web3-contract-cache.ts @@ -3,41 +3,41 @@ import debugFactory from 'debug' import { AddressRegistry } from './address-registry' import { CeloContract, ProxyContracts } from './base' import { StableToken } from './celo-tokens' -import { newGasPriceMinimum } from './generated/0.8/GasPriceMinimum' -import { newAccounts } from './generated/Accounts' -import { newAttestations } from './generated/Attestations' -import { newBlockchainParameters } from './generated/BlockchainParameters' -import { newDoubleSigningSlasher } from './generated/DoubleSigningSlasher' -import { newDowntimeSlasher } from './generated/DowntimeSlasher' -import { newElection } from './generated/Election' -import { newEpochRewards } from './generated/EpochRewards' -import { newEscrow } from './generated/Escrow' -import { newFederatedAttestations } from './generated/FederatedAttestations' -import { newFeeCurrencyWhitelist } from './generated/FeeCurrencyWhitelist' -import { newFeeHandler } from './generated/FeeHandler' -import { newFreezer } from './generated/Freezer' -import { newGoldToken } from './generated/GoldToken' -import { newGovernance } from './generated/Governance' -import { newIERC20 } from './generated/IERC20' -import { newLockedGold } from './generated/LockedGold' -import { newMetaTransactionWallet } from './generated/MetaTransactionWallet' -import { newMetaTransactionWalletDeployer } from './generated/MetaTransactionWalletDeployer' -import { newMultiSig } from './generated/MultiSig' -import { newOdisPayments } from './generated/OdisPayments' -import { newProxy } from './generated/Proxy' -import { newRandom } from './generated/Random' -import { newRegistry } from './generated/Registry' -import { newSortedOracles } from './generated/SortedOracles' -import { newValidators } from './generated/Validators' -import { newExchange } from './generated/mento/Exchange' -import { newExchangeBRL } from './generated/mento/ExchangeBRL' -import { newExchangeEUR } from './generated/mento/ExchangeEUR' -import { newGrandaMento } from './generated/mento/GrandaMento' -import { newReserve } from './generated/mento/Reserve' -import { newStableToken } from './generated/mento/StableToken' +import { newGasPriceMinimum } from '@celo/abis/types/web3/0.8/GasPriceMinimum' +import { newAccounts } from '@celo/abis/types/web3/Accounts' +import { newAttestations } from '@celo/abis/types/web3/Attestations' +import { newBlockchainParameters } from '@celo/abis/types/web3/BlockchainParameters' +import { newDoubleSigningSlasher } from '@celo/abis/types/web3/DoubleSigningSlasher' +import { newDowntimeSlasher } from '@celo/abis/types/web3/DowntimeSlasher' +import { newElection } from '@celo/abis/types/web3/Election' +import { newEpochRewards } from '@celo/abis/types/web3/EpochRewards' +import { newEscrow } from '@celo/abis/types/web3/Escrow' +import { newFederatedAttestations } from '@celo/abis/types/web3/FederatedAttestations' +import { newFeeCurrencyWhitelist } from '@celo/abis/types/web3/FeeCurrencyWhitelist' +import { newFeeHandler } from '@celo/abis/types/web3/FeeHandler' +import { newFreezer } from '@celo/abis/types/web3/Freezer' +import { newGoldToken } from '@celo/abis/types/web3/GoldToken' +import { newGovernance } from '@celo/abis/types/web3/Governance' +import { newIERC20 } from '@celo/abis/types/web3/IERC20' +import { newLockedGold } from '@celo/abis/types/web3/LockedGold' +import { newMetaTransactionWallet } from '@celo/abis/types/web3/MetaTransactionWallet' +import { newMetaTransactionWalletDeployer } from '@celo/abis/types/web3/MetaTransactionWalletDeployer' +import { newMultiSig } from '@celo/abis/types/web3/MultiSig' +import { newOdisPayments } from '@celo/abis/types/web3/OdisPayments' +import { newProxy } from '@celo/abis/types/web3/Proxy' +import { newRandom } from '@celo/abis/types/web3/Random' +import { newRegistry } from '@celo/abis/types/web3/Registry' +import { newSortedOracles } from '@celo/abis/types/web3/SortedOracles' +import { newValidators } from '@celo/abis/types/web3/Validators' +import { newExchange } from '@celo/abis/types/web3/mento/Exchange' +import { newExchangeBRL } from '@celo/abis/types/web3/mento/ExchangeBRL' +import { newExchangeEUR } from '@celo/abis/types/web3/mento/ExchangeEUR' +import { newGrandaMento } from '@celo/abis/types/web3/mento/GrandaMento' +import { newReserve } from '@celo/abis/types/web3/mento/Reserve' +import { newStableToken } from '@celo/abis/types/web3/mento/StableToken' -import { newMentoFeeHandlerSeller } from './generated/MentoFeeHandlerSeller' -import { newUniswapFeeHandlerSeller } from './generated/UniswapFeeHandlerSeller' +import { newMentoFeeHandlerSeller } from '@celo/abis/types/web3/MentoFeeHandlerSeller' +import { newUniswapFeeHandlerSeller } from '@celo/abis/types/web3/UniswapFeeHandlerSeller' const debug = debugFactory('kit:web3-contract-cache') From 8a6311f5584960526e4292a6cf73983d250e24a2 Mon Sep 17 00:00:00 2001 From: Leszek Stachowski Date: Thu, 30 Nov 2023 16:01:43 +0100 Subject: [PATCH 22/63] proxy: use @celo/abis package --- packages/sdk/contractkit/src/proxy.ts | 62 +++++++++++++-------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/packages/sdk/contractkit/src/proxy.ts b/packages/sdk/contractkit/src/proxy.ts index 9bd8c457dcf..fce91b4fd3c 100644 --- a/packages/sdk/contractkit/src/proxy.ts +++ b/packages/sdk/contractkit/src/proxy.ts @@ -1,37 +1,37 @@ // tslint:disable: ordered-imports import { ABIDefinition, AbiItem } from '@celo/connect' import Web3 from 'web3' -import { ABI as GasPriceMinimumABI } from './generated/0.8/GasPriceMinimum' -import { ABI as AccountsABI } from './generated/Accounts' -import { ABI as AttestationsABI } from './generated/Attestations' -import { ABI as BlockchainParametersABI } from './generated/BlockchainParameters' -import { ABI as DoubleSigningSlasherABI } from './generated/DoubleSigningSlasher' -import { ABI as DowntimeSlasherABI } from './generated/DowntimeSlasher' -import { ABI as ElectionABI } from './generated/Election' -import { ABI as EpochRewardsABI } from './generated/EpochRewards' -import { ABI as EscrowABI } from './generated/Escrow' -import { ABI as FederatedAttestationsABI } from './generated/FederatedAttestations' -import { ABI as FeeCurrencyWhitelistABI } from './generated/FeeCurrencyWhitelist' -import { ABI as FeeHandlerABI } from './generated/FeeHandler' -import { ABI as FreezerABI } from './generated/Freezer' -import { ABI as GoldTokenABI } from './generated/GoldToken' -import { ABI as GovernanceABI } from './generated/Governance' -import { ABI as LockedGoldABI } from './generated/LockedGold' -import { ABI as MentoFeeHandlerSellerABI } from './generated/MentoFeeHandlerSeller' -import { ABI as MetaTransactionWalletABI } from './generated/MetaTransactionWallet' -import { ABI as MetaTransactionWalletDeployerABI } from './generated/MetaTransactionWalletDeployer' -import { ABI as MultiSigABI } from './generated/MultiSig' -import { ABI as OdisPaymentsABI } from './generated/OdisPayments' -import { ABI as ProxyABI } from './generated/Proxy' -import { ABI as RandomABI } from './generated/Random' -import { ABI as RegistryABI } from './generated/Registry' -import { ABI as SortedOraclesABI } from './generated/SortedOracles' -import { ABI as UniswapFeeHandlerSellerABI } from './generated/UniswapFeeHandlerSeller' -import { ABI as ValidatorsABI } from './generated/Validators' -import { ABI as ExchangeABI } from './generated/mento/Exchange' -import { ABI as GrandaMentoABI } from './generated/mento/GrandaMento' -import { ABI as ReserveABI } from './generated/mento/Reserve' -import { ABI as StableTokenABI } from './generated/mento/StableToken' +import { ABI as GasPriceMinimumABI } from '@celo/abis/types/web3/0.8/GasPriceMinimum' +import { ABI as AccountsABI } from '@celo/abis/types/web3/Accounts' +import { ABI as AttestationsABI } from '@celo/abis/types/web3/Attestations' +import { ABI as BlockchainParametersABI } from '@celo/abis/types/web3/BlockchainParameters' +import { ABI as DoubleSigningSlasherABI } from '@celo/abis/types/web3/DoubleSigningSlasher' +import { ABI as DowntimeSlasherABI } from '@celo/abis/types/web3/DowntimeSlasher' +import { ABI as ElectionABI } from '@celo/abis/types/web3/Election' +import { ABI as EpochRewardsABI } from '@celo/abis/types/web3/EpochRewards' +import { ABI as EscrowABI } from '@celo/abis/types/web3/Escrow' +import { ABI as FederatedAttestationsABI } from '@celo/abis/types/web3/FederatedAttestations' +import { ABI as FeeCurrencyWhitelistABI } from '@celo/abis/types/web3/FeeCurrencyWhitelist' +import { ABI as FeeHandlerABI } from '@celo/abis/types/web3/FeeHandler' +import { ABI as FreezerABI } from '@celo/abis/types/web3/Freezer' +import { ABI as GoldTokenABI } from '@celo/abis/types/web3/GoldToken' +import { ABI as GovernanceABI } from '@celo/abis/types/web3/Governance' +import { ABI as LockedGoldABI } from '@celo/abis/types/web3/LockedGold' +import { ABI as MentoFeeHandlerSellerABI } from '@celo/abis/types/web3/MentoFeeHandlerSeller' +import { ABI as MetaTransactionWalletABI } from '@celo/abis/types/web3/MetaTransactionWallet' +import { ABI as MetaTransactionWalletDeployerABI } from '@celo/abis/types/web3/MetaTransactionWalletDeployer' +import { ABI as MultiSigABI } from '@celo/abis/types/web3/MultiSig' +import { ABI as OdisPaymentsABI } from '@celo/abis/types/web3/OdisPayments' +import { ABI as ProxyABI } from '@celo/abis/types/web3/Proxy' +import { ABI as RandomABI } from '@celo/abis/types/web3/Random' +import { ABI as RegistryABI } from '@celo/abis/types/web3/Registry' +import { ABI as SortedOraclesABI } from '@celo/abis/types/web3/SortedOracles' +import { ABI as UniswapFeeHandlerSellerABI } from '@celo/abis/types/web3/UniswapFeeHandlerSeller' +import { ABI as ValidatorsABI } from '@celo/abis/types/web3/Validators' +import { ABI as ExchangeABI } from '@celo/abis/types/web3/mento/Exchange' +import { ABI as GrandaMentoABI } from '@celo/abis/types/web3/mento/GrandaMento' +import { ABI as ReserveABI } from '@celo/abis/types/web3/mento/Reserve' +import { ABI as StableTokenABI } from '@celo/abis/types/web3/mento/StableToken' export const GET_IMPLEMENTATION_ABI: ABIDefinition = { constant: true, From ed89d6538f2d02307fcbe718463252fbf46a6588 Mon Sep 17 00:00:00 2001 From: Leszek Stachowski Date: Thu, 30 Nov 2023 16:02:28 +0100 Subject: [PATCH 23/63] mini contract cache: use @celo/abis package --- .../sdk/contractkit/src/mini-contract-cache.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/sdk/contractkit/src/mini-contract-cache.ts b/packages/sdk/contractkit/src/mini-contract-cache.ts index 72a4c93115b..803b8281d82 100644 --- a/packages/sdk/contractkit/src/mini-contract-cache.ts +++ b/packages/sdk/contractkit/src/mini-contract-cache.ts @@ -4,15 +4,15 @@ import { AddressRegistry } from './address-registry' import { CeloContract } from './base' import { ContractCacheType } from './basic-contract-cache-type' import { stableTokenInfos } from './celo-tokens' -import { newGasPriceMinimum } from './generated/0.8/GasPriceMinimum' -import { newAccounts } from './generated/Accounts' -import { newGoldToken } from './generated/GoldToken' -import { newExchange } from './generated/mento/Exchange' -import { newExchangeBRL } from './generated/mento/ExchangeBRL' -import { newExchangeEUR } from './generated/mento/ExchangeEUR' -import { newStableToken } from './generated/mento/StableToken' -import { newStableTokenBRL } from './generated/mento/StableTokenBRL' -import { newStableTokenEUR } from './generated/mento/StableTokenEUR' +import { newGasPriceMinimum } from '@celo/abis/types/web3/0.8/GasPriceMinimum' +import { newAccounts } from '@celo/abis/types/web3/Accounts' +import { newGoldToken } from '@celo/abis/types/web3/GoldToken' +import { newExchange } from '@celo/abis/types/web3/mento/Exchange' +import { newExchangeBRL } from '@celo/abis/types/web3/mento/ExchangeBRL' +import { newExchangeEUR } from '@celo/abis/types/web3/mento/ExchangeEUR' +import { newStableToken } from '@celo/abis/types/web3/mento/StableToken' +import { newStableTokenBRL } from '@celo/abis/types/web3/mento/StableTokenBRL' +import { newStableTokenEUR } from '@celo/abis/types/web3/mento/StableTokenEUR' import { AccountsWrapper } from './wrappers/Accounts' import { ExchangeWrapper } from './wrappers/Exchange' import { GasPriceMinimumWrapper } from './wrappers/GasPriceMinimum' From 11a0506b6c04def0850f9be6682c841d2dac55bc Mon Sep 17 00:00:00 2001 From: Leszek Stachowski Date: Thu, 30 Nov 2023 16:03:44 +0100 Subject: [PATCH 24/63] contract cache: use @celo/abis package --- packages/sdk/contractkit/src/contract-cache.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sdk/contractkit/src/contract-cache.ts b/packages/sdk/contractkit/src/contract-cache.ts index 51bdb7b1931..ce85c934a9d 100644 --- a/packages/sdk/contractkit/src/contract-cache.ts +++ b/packages/sdk/contractkit/src/contract-cache.ts @@ -3,7 +3,7 @@ import { AddressRegistry } from './address-registry' import { CeloContract } from './base' import { ContractCacheType } from './basic-contract-cache-type' import { StableToken, stableTokenInfos } from './celo-tokens' -import { IERC20 } from './generated/IERC20' +import { IERC20 } from '@celo/abis/types/web3/IERC20' import { Web3ContractCache } from './web3-contract-cache' import { AccountsWrapper } from './wrappers/Accounts' import { AttestationsWrapper } from './wrappers/Attestations' From 8e1f35ce04815c0e4f5fbcbcb7d079ea55fe9509 Mon Sep 17 00:00:00 2001 From: Leszek Stachowski Date: Thu, 30 Nov 2023 16:06:00 +0100 Subject: [PATCH 25/63] replace all other usages of ./generated --- packages/sdk/contractkit/src/address-registry.ts | 2 +- packages/sdk/contractkit/src/wrappers/BaseWrapper.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/sdk/contractkit/src/address-registry.ts b/packages/sdk/contractkit/src/address-registry.ts index 83937637a68..3926399ec1d 100644 --- a/packages/sdk/contractkit/src/address-registry.ts +++ b/packages/sdk/contractkit/src/address-registry.ts @@ -2,7 +2,7 @@ import { Address, NULL_ADDRESS } from '@celo/base/lib/address' import { Connection } from '@celo/connect' import debugFactory from 'debug' import { CeloContract, RegisteredContracts, stripProxy } from './base' -import { newRegistry, Registry } from './generated/Registry' +import { newRegistry, Registry } from '@celo/abis/types/web3/Registry' const debug = debugFactory('kit:registry') diff --git a/packages/sdk/contractkit/src/wrappers/BaseWrapper.test.ts b/packages/sdk/contractkit/src/wrappers/BaseWrapper.test.ts index e24bc768e8a..c9b29a43033 100644 --- a/packages/sdk/contractkit/src/wrappers/BaseWrapper.test.ts +++ b/packages/sdk/contractkit/src/wrappers/BaseWrapper.test.ts @@ -5,7 +5,7 @@ import Web3 from 'web3' import { ICeloVersionedContract, newICeloVersionedContract, -} from '../generated/ICeloVersionedContract' +} from '@celo/abis/types/web3/ICeloVersionedContract' import { ContractVersion, newContractVersion } from '../versions' import { BaseWrapper, unixSecondsTimestampToDateString } from './BaseWrapper' From 698e725cefcbc65997c33e69e476ea15ec9b75de Mon Sep 17 00:00:00 2001 From: Aaron DeRuvo Date: Thu, 30 Nov 2023 17:18:07 +0200 Subject: [PATCH 26/63] fix other places import must change and add changeset --- .changeset/cool-waves-switch.md | 5 +++++ packages/sdk/contractkit/README.md | 2 +- packages/sdk/contractkit/typedoc.json | 2 +- packages/sdk/governance/src/proposals.ts | 7 +++---- 4 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 .changeset/cool-waves-switch.md diff --git a/.changeset/cool-waves-switch.md b/.changeset/cool-waves-switch.md new file mode 100644 index 00000000000..2bb7d71fc87 --- /dev/null +++ b/.changeset/cool-waves-switch.md @@ -0,0 +1,5 @@ +--- +'@celo/contractkit': major +--- + +Remove contracts from lib/generated. now available in @celo/abis package at @celo/abis/types/web3 diff --git a/packages/sdk/contractkit/README.md b/packages/sdk/contractkit/README.md index e8026404dfb..b6069188029 100644 --- a/packages/sdk/contractkit/README.md +++ b/packages/sdk/contractkit/README.md @@ -178,7 +178,7 @@ You can also initialize contracts wrappers directly. They require a `Connection` import { newKit } from "@celo/contractkit/lib/mini-kit" import { MultiSigWrapper } from '@celo/contractkit/lib/wrappers/MultiSig' -import { newMultiSig } from '@celo/contractkit/lib/generated/MultiSig' +import { newMultiSig } from '@celo/abis/types/web3/MultiSig' const miniKit = newKit("https://alfajores-forno.celo-testnet.org/") diff --git a/packages/sdk/contractkit/typedoc.json b/packages/sdk/contractkit/typedoc.json index 98ed9bc21e8..d47b699bff6 100644 --- a/packages/sdk/contractkit/typedoc.json +++ b/packages/sdk/contractkit/typedoc.json @@ -1,6 +1,6 @@ { "mode": "modules", - "exclude": ["**/generated/*.ts", "**/*+(index|.test).ts"], + "exclude": ["**/*+(index|.test).ts"], "excludeNotExported": true, "excludePrivate": true, "excludeProtected": true, diff --git a/packages/sdk/governance/src/proposals.ts b/packages/sdk/governance/src/proposals.ts index bb54d2290a6..bad02d3b43e 100644 --- a/packages/sdk/governance/src/proposals.ts +++ b/packages/sdk/governance/src/proposals.ts @@ -1,3 +1,5 @@ +import { ABI as GovernanceABI } from '@celo/abis/types/web3/Governance' +import { ABI as RegistryABI } from '@celo/abis/types/web3/Registry' import { Address, isHexString, trimLeading0x } from '@celo/base/lib/address' import { AbiCoder, @@ -18,8 +20,6 @@ import { REGISTRY_CONTRACT_ADDRESS, } from '@celo/contractkit' import { stripProxy, suffixProxy } from '@celo/contractkit/lib/base' -import { ABI as GovernanceABI } from '@celo/contractkit/lib/generated/Governance' -import { ABI as RegistryABI } from '@celo/contractkit/lib/generated/Registry' // tslint:disable: ordered-imports import { getInitializeAbiOfImplementation, @@ -462,8 +462,7 @@ export class InteractiveProposalBuilder { } const contractName = choice as CeloContract - const contractABI = require('@celo/contractkit/lib/generated/' + contractName) - .ABI as ABIDefinition[] + const contractABI = require('@celo/abis/types/web3/' + contractName).ABI as ABIDefinition[] const txMethods = contractABI.filter( (def) => def.type === 'function' && def.stateMutability !== 'view' From cb1f3836e35188314f21855e1ed1f46ded39b55c Mon Sep 17 00:00:00 2001 From: Leszek Stachowski Date: Thu, 30 Nov 2023 16:31:06 +0100 Subject: [PATCH 27/63] use @celo/abis/types/web3 instead of generated/ --- packages/cli/src/commands/network/contracts.ts | 4 ++-- packages/cli/src/commands/releasegold/admin-revoke.test.ts | 2 +- .../cli/src/commands/releasegold/refund-and-finalize.test.ts | 2 +- packages/cli/src/commands/releasegold/set-beneficiary.test.ts | 2 +- packages/cli/src/commands/releasegold/withdraw.test.ts | 2 +- packages/cli/src/commands/transfer/erc20.ts | 2 +- packages/cli/src/utils/release-gold-base.ts | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/cli/src/commands/network/contracts.ts b/packages/cli/src/commands/network/contracts.ts index 843e2aefdbf..b1fe27d9fe6 100644 --- a/packages/cli/src/commands/network/contracts.ts +++ b/packages/cli/src/commands/network/contracts.ts @@ -1,7 +1,7 @@ import { concurrentMap } from '@celo/base' import { CeloContract } from '@celo/contractkit' -import { newICeloVersionedContract } from '@celo/contractkit/lib/generated/ICeloVersionedContract' -import { newProxy } from '@celo/contractkit/lib/generated/Proxy' +import { newICeloVersionedContract } from '@celo/abis/types/web3/ICeloVersionedContract' +import { newProxy } from '@celo/abis/types/web3/Proxy' import { cli } from 'cli-ux' import { table } from 'cli-ux/lib/styled/table' import { BaseCommand } from '../../base' diff --git a/packages/cli/src/commands/releasegold/admin-revoke.test.ts b/packages/cli/src/commands/releasegold/admin-revoke.test.ts index ac55c4ee26b..6bf86924748 100644 --- a/packages/cli/src/commands/releasegold/admin-revoke.test.ts +++ b/packages/cli/src/commands/releasegold/admin-revoke.test.ts @@ -1,6 +1,6 @@ import { serializeSignature } from '@celo/base/lib/signatureUtils' import { ContractKit, newKitFromWeb3 } from '@celo/contractkit' -import { newReleaseGold } from '@celo/contractkit/lib/generated/ReleaseGold' +import { newReleaseGold } from '@celo/abis/types/web3/ReleaseGold' import { AccountsWrapper } from '@celo/contractkit/lib/wrappers/Accounts' import { GovernanceWrapper } from '@celo/contractkit/lib/wrappers/Governance' import { ReleaseGoldWrapper } from '@celo/contractkit/lib/wrappers/ReleaseGold' diff --git a/packages/cli/src/commands/releasegold/refund-and-finalize.test.ts b/packages/cli/src/commands/releasegold/refund-and-finalize.test.ts index cb0621cc4f3..9b697127b09 100644 --- a/packages/cli/src/commands/releasegold/refund-and-finalize.test.ts +++ b/packages/cli/src/commands/releasegold/refund-and-finalize.test.ts @@ -1,5 +1,5 @@ import { ContractKit, newKitFromWeb3 } from '@celo/contractkit' -import { newReleaseGold } from '@celo/contractkit/lib/generated/ReleaseGold' +import { newReleaseGold } from '@celo/abis/types/web3/ReleaseGold' import { ReleaseGoldWrapper } from '@celo/contractkit/lib/wrappers/ReleaseGold' import { getContractFromEvent, testWithGanache } from '@celo/dev-utils/lib/ganache-test' import Web3 from 'web3' diff --git a/packages/cli/src/commands/releasegold/set-beneficiary.test.ts b/packages/cli/src/commands/releasegold/set-beneficiary.test.ts index cf30769ada6..75169bf7a17 100644 --- a/packages/cli/src/commands/releasegold/set-beneficiary.test.ts +++ b/packages/cli/src/commands/releasegold/set-beneficiary.test.ts @@ -1,5 +1,5 @@ import { newKitFromWeb3 } from '@celo/contractkit' -import { newReleaseGold } from '@celo/contractkit/lib/generated/ReleaseGold' +import { newReleaseGold } from '@celo/abis/types/web3/ReleaseGold' import { ReleaseGoldWrapper } from '@celo/contractkit/lib/wrappers/ReleaseGold' import { getContractFromEvent, testWithGanache } from '@celo/dev-utils/lib/ganache-test' import Web3 from 'web3' diff --git a/packages/cli/src/commands/releasegold/withdraw.test.ts b/packages/cli/src/commands/releasegold/withdraw.test.ts index 150da5491cc..99ccea9721d 100644 --- a/packages/cli/src/commands/releasegold/withdraw.test.ts +++ b/packages/cli/src/commands/releasegold/withdraw.test.ts @@ -1,5 +1,5 @@ import { ContractKit, newKitFromWeb3 } from '@celo/contractkit' -import { newReleaseGold } from '@celo/contractkit/lib/generated/ReleaseGold' +import { newReleaseGold } from '@celo/abis/types/web3/ReleaseGold' import { ReleaseGoldWrapper } from '@celo/contractkit/lib/wrappers/ReleaseGold' import { getContractFromEvent, testWithGanache, timeTravel } from '@celo/dev-utils/lib/ganache-test' import { BigNumber } from 'bignumber.js' diff --git a/packages/cli/src/commands/transfer/erc20.ts b/packages/cli/src/commands/transfer/erc20.ts index 31dd4458924..1b5f4a5cb91 100644 --- a/packages/cli/src/commands/transfer/erc20.ts +++ b/packages/cli/src/commands/transfer/erc20.ts @@ -1,4 +1,4 @@ -import { IERC20 } from '@celo/contractkit/lib/generated/IERC20' +import { IERC20 } from '@celo/abis/types/web3/IERC20' import { Erc20Wrapper } from '@celo/contractkit/lib/wrappers/Erc20Wrapper' import { flags } from '@oclif/command' import BigNumber from 'bignumber.js' diff --git a/packages/cli/src/utils/release-gold-base.ts b/packages/cli/src/utils/release-gold-base.ts index 79ab38c2241..dc7457a6722 100644 --- a/packages/cli/src/utils/release-gold-base.ts +++ b/packages/cli/src/utils/release-gold-base.ts @@ -1,4 +1,4 @@ -import { newReleaseGold } from '@celo/contractkit/lib/generated/ReleaseGold' +import { newReleaseGold } from '@celo/abis/types/web3/ReleaseGold' import { ReleaseGoldWrapper } from '@celo/contractkit/lib/wrappers/ReleaseGold' import { ParserOutput } from '@oclif/parser/lib/parse' import { BaseCommand } from '../base' From d5f2dad984f408da1e37cc2e894c028c68556580 Mon Sep 17 00:00:00 2001 From: Leszek Stachowski Date: Thu, 30 Nov 2023 16:59:27 +0100 Subject: [PATCH 28/63] bump up @celo/abis version --- packages/sdk/contractkit/package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/sdk/contractkit/package.json b/packages/sdk/contractkit/package.json index cf4cb3b3bb5..ba015e3433a 100644 --- a/packages/sdk/contractkit/package.json +++ b/packages/sdk/contractkit/package.json @@ -24,7 +24,7 @@ "lint": "tslint -c tslint.json --project ." }, "dependencies": { - "@celo/abis": "10.0.0-beta.4", + "@celo/abis": "10.0.0-beta.5", "@celo/base": "^6.0.0", "@celo/connect": "^5.1.1", "@celo/utils": "^5.0.6", diff --git a/yarn.lock b/yarn.lock index 7e2bedc0dd1..2be4787f23f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -973,10 +973,10 @@ resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== -"@celo/abis@10.0.0-beta.4": - version "10.0.0-beta.4" - resolved "https://registry.yarnpkg.com/@celo/abis/-/abis-10.0.0-beta.4.tgz#9540c422e90f14a35032a33cd4380cfefe31ec27" - integrity sha512-qA5Iv9pjBniL9GeOclvIkTtflECZPCLtsWOx2zEiCXsqdGMRDJhkNuFpvViihyOqNLD9yxARXyklqiM1L07xpw== +"@celo/abis@10.0.0-beta.5": + version "10.0.0-beta.5" + resolved "https://registry.yarnpkg.com/@celo/abis/-/abis-10.0.0-beta.5.tgz#633e567b66ba7e1767ee5cb970d6249445d7b78d" + integrity sha512-yfRZj26Cw35G6M2xsmiZtRyN7OdHZI1uAkoBJ0ZHUlRq+GFSa60PiXcjfAPHLx/Y6MMjHVRjNtSEL/awNlmzoQ== "@celo/base@^5.0.5": version "5.0.5" From ba7ca7884adfd1c2b7e1b723c561108a7b189d47 Mon Sep 17 00:00:00 2001 From: Aaron DeRuvo Date: Thu, 30 Nov 2023 18:54:08 +0200 Subject: [PATCH 29/63] abis are imported to these packages --- packages/cli/package.json | 3 ++- packages/sdk/governance/package.json | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/cli/package.json b/packages/cli/package.json index 569e6cae2c8..87c288521a2 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -30,8 +30,8 @@ "test": "TZ=UTC jest --runInBand" }, "dependencies": { + "@celo/abis": "10.0.0-beta.5", "@celo/base": "^6.0.0", - "@celo/celo-devchain": "^6.0.3-beta.1", "@celo/connect": "^5.1.1", "@celo/contractkit": "^5.2.0", "@celo/explorer": "^5.0.6", @@ -73,6 +73,7 @@ "web3": "1.10.0" }, "devDependencies": { + "@celo/celo-devchain": "^6.0.3-beta.1", "@celo/dev-utils": "0.0.1", "@oclif/dev-cli": "^1.23.0", "@types/cli-table": "^0.3.0", diff --git a/packages/sdk/governance/package.json b/packages/sdk/governance/package.json index a68e8f07d1d..cfce4295673 100644 --- a/packages/sdk/governance/package.json +++ b/packages/sdk/governance/package.json @@ -21,6 +21,7 @@ "prepublishOnly": "yarn build" }, "dependencies": { + "@celo/abis": "10.0.0-beta.5", "@celo/base": "^6.0.0", "@celo/utils": "^5.0.6", "@celo/connect": "^5.1.1", From e5dc22062a4d725bff9a69fa4301121785ce75f7 Mon Sep 17 00:00:00 2001 From: Aaron DeRuvo Date: Fri, 1 Dec 2023 10:38:11 +0200 Subject: [PATCH 30/63] must set moduleResolution to node16, should be targeting at least es6 --- packages/sdk/contractkit/tsconfig.json | 1 + packages/typescript/tsconfig.json | 7 +++---- packages/typescript/tsconfig.library.json | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/sdk/contractkit/tsconfig.json b/packages/sdk/contractkit/tsconfig.json index c24241002b7..984b87c7e44 100644 --- a/packages/sdk/contractkit/tsconfig.json +++ b/packages/sdk/contractkit/tsconfig.json @@ -1,6 +1,7 @@ { "extends": "@celo/typescript/tsconfig.library.json", "compilerOptions": { + "moduleResolution": "node16", "rootDir": "src", "outDir": "lib", "resolveJsonModule": true diff --git a/packages/typescript/tsconfig.json b/packages/typescript/tsconfig.json index 8d662d06c44..89a1e70dcc6 100644 --- a/packages/typescript/tsconfig.json +++ b/packages/typescript/tsconfig.json @@ -4,14 +4,13 @@ "allowSyntheticDefaultImports": false, "baseUrl": ".", "importHelpers": true, - "jsx": "react", - "lib": ["es7", "esnext", "dom"], - "moduleResolution": "node", + "lib": ["es7", "esnext"], + "moduleResolution": "node16", "noImplicitAny": true, "noUnusedLocals": true, "strictNullChecks": true, "skipLibCheck": true, - "target": "es3", + "target": "es6", "strict": true }, "exclude": ["node_modules"] diff --git a/packages/typescript/tsconfig.library.json b/packages/typescript/tsconfig.library.json index 45376c841f8..7217c449de9 100644 --- a/packages/typescript/tsconfig.library.json +++ b/packages/typescript/tsconfig.library.json @@ -2,7 +2,7 @@ "compileOnSave": false, "compilerOptions": { "lib": ["dom", "es2015", "es2016"], - "target": "es5", + "target": "es6", "module": "commonjs", "moduleResolution": "node", "jsx": "preserve", From 72ccaea728c812d8b4f4bf3499135f49f99bcecc Mon Sep 17 00:00:00 2001 From: Aaron DeRuvo Date: Fri, 1 Dec 2023 12:44:53 +0200 Subject: [PATCH 31/63] keep declarations separate --- package.json | 3 +- packages/protocol/abis/package.json | 481 +++++++++++++++++- packages/protocol/abis/tsconfig-cjs.json | 2 + packages/protocol/abis/tsconfig-types.json | 8 + packages/protocol/abis/tsconfig.json | 5 +- .../prepare-contracts-and-abis-publishing.ts | 45 +- packages/sdk/contractkit/package.json | 2 +- 7 files changed, 524 insertions(+), 22 deletions(-) create mode 100644 packages/protocol/abis/tsconfig-types.json diff --git a/package.json b/package.json index 55fb70231f5..064b2f7b8f0 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,8 @@ "packages": [ "packages/*", "packages/sdk/*", - "packages/sdk/wallets/*" + "packages/sdk/wallets/*", + "packages/protocol/abis" ], "nohoist": [ "**/openzeppelin-solidity", diff --git a/packages/protocol/abis/package.json b/packages/protocol/abis/package.json index b18291a0d3a..ee3fc51c839 100644 --- a/packages/protocol/abis/package.json +++ b/packages/protocol/abis/package.json @@ -1,6 +1,6 @@ { "name": "@celo/abis", - "version": "0.0.0-template.version", + "version": "10.0.0-local", "author": "cLabs", "license": "LGPL-3.0", "repository": { @@ -12,5 +12,480 @@ "peerDependencies": {}, "files": [ "./dist" - ] -} + ], + "exports": { + "./Accounts.json": { + "default": "./dist/Accounts.json" + }, + "./Attestations.json": { + "default": "./dist/Attestations.json" + }, + "./BlockchainParameters.json": { + "default": "./dist/BlockchainParameters.json" + }, + "./DoubleSigningSlasher.json": { + "default": "./dist/DoubleSigningSlasher.json" + }, + "./DowntimeSlasher.json": { + "default": "./dist/DowntimeSlasher.json" + }, + "./Election.json": { + "default": "./dist/Election.json" + }, + "./EpochRewards.json": { + "default": "./dist/EpochRewards.json" + }, + "./Escrow.json": { + "default": "./dist/Escrow.json" + }, + "./Exchange.json": { + "default": "./dist/Exchange.json" + }, + "./ExchangeBRL.json": { + "default": "./dist/ExchangeBRL.json" + }, + "./ExchangeEUR.json": { + "default": "./dist/ExchangeEUR.json" + }, + "./FederatedAttestations.json": { + "default": "./dist/FederatedAttestations.json" + }, + "./FeeCurrencyWhitelist.json": { + "default": "./dist/FeeCurrencyWhitelist.json" + }, + "./FeeHandler.json": { + "default": "./dist/FeeHandler.json" + }, + "./Freezer.json": { + "default": "./dist/Freezer.json" + }, + "./GasPriceMinimum.json": { + "default": "./dist/GasPriceMinimum.json" + }, + "./GoldToken.json": { + "default": "./dist/GoldToken.json" + }, + "./Governance.json": { + "default": "./dist/Governance.json" + }, + "./GovernanceApproverMultiSig.json": { + "default": "./dist/GovernanceApproverMultiSig.json" + }, + "./GrandaMento.json": { + "default": "./dist/GrandaMento.json" + }, + "./ICeloToken.json": { + "default": "./dist/ICeloToken.json" + }, + "./ICeloVersionedContract.json": { + "default": "./dist/ICeloVersionedContract.json" + }, + "./IERC20.json": { + "default": "./dist/IERC20.json" + }, + "./LockedGold.json": { + "default": "./dist/LockedGold.json" + }, + "./MentoFeeHandlerSeller.json": { + "default": "./dist/MentoFeeHandlerSeller.json" + }, + "./MetaTransactionWallet.json": { + "default": "./dist/MetaTransactionWallet.json" + }, + "./MetaTransactionWalletDeployer.json": { + "default": "./dist/MetaTransactionWalletDeployer.json" + }, + "./MultiSig.json": { + "default": "./dist/MultiSig.json" + }, + "./OdisPayments.json": { + "default": "./dist/OdisPayments.json" + }, + "./Proxy.json": { + "default": "./dist/Proxy.json" + }, + "./Random.json": { + "default": "./dist/Random.json" + }, + "./Registry.json": { + "default": "./dist/Registry.json" + }, + "./ReleaseGold.json": { + "default": "./dist/ReleaseGold.json" + }, + "./Reserve.json": { + "default": "./dist/Reserve.json" + }, + "./ReserveSpenderMultiSig.json": { + "default": "./dist/ReserveSpenderMultiSig.json" + }, + "./SortedOracles.json": { + "default": "./dist/SortedOracles.json" + }, + "./StableToken.json": { + "default": "./dist/StableToken.json" + }, + "./StableTokenBRL.json": { + "default": "./dist/StableTokenBRL.json" + }, + "./StableTokenEUR.json": { + "default": "./dist/StableTokenEUR.json" + }, + "./UniswapFeeHandlerSeller.json": { + "default": "./dist/UniswapFeeHandlerSeller.json" + }, + "./Validators.json": { + "default": "./dist/Validators.json" + }, + "./types/wagmi/Accounts": { + "import": "./dist/esm/types/wagmi/Accounts.js", + "require": "./dist/cjs/types/wagmi/Accounts.js", + "types": "./dist/types/types/wagmi/Accounts.d.ts" + }, + "./types/wagmi/Attestations": { + "import": "./dist/esm/types/wagmi/Attestations.js", + "require": "./dist/cjs/types/wagmi/Attestations.js", + "types": "./dist/types/types/wagmi/Attestations.d.ts" + }, + "./types/wagmi/BlockchainParameters": { + "import": "./dist/esm/types/wagmi/BlockchainParameters.js", + "require": "./dist/cjs/types/wagmi/BlockchainParameters.js", + "types": "./dist/types/types/wagmi/BlockchainParameters.d.ts" + }, + "./types/wagmi/DoubleSigningSlasher": { + "import": "./dist/esm/types/wagmi/DoubleSigningSlasher.js", + "require": "./dist/cjs/types/wagmi/DoubleSigningSlasher.js", + "types": "./dist/types/types/wagmi/DoubleSigningSlasher.d.ts" + }, + "./types/wagmi/DowntimeSlasher": { + "import": "./dist/esm/types/wagmi/DowntimeSlasher.js", + "require": "./dist/cjs/types/wagmi/DowntimeSlasher.js", + "types": "./dist/types/types/wagmi/DowntimeSlasher.d.ts" + }, + "./types/wagmi/Election": { + "import": "./dist/esm/types/wagmi/Election.js", + "require": "./dist/cjs/types/wagmi/Election.js", + "types": "./dist/types/types/wagmi/Election.d.ts" + }, + "./types/wagmi/EpochRewards": { + "import": "./dist/esm/types/wagmi/EpochRewards.js", + "require": "./dist/cjs/types/wagmi/EpochRewards.js", + "types": "./dist/types/types/wagmi/EpochRewards.d.ts" + }, + "./types/wagmi/Escrow": { + "import": "./dist/esm/types/wagmi/Escrow.js", + "require": "./dist/cjs/types/wagmi/Escrow.js", + "types": "./dist/types/types/wagmi/Escrow.d.ts" + }, + "./types/wagmi/FederatedAttestations": { + "import": "./dist/esm/types/wagmi/FederatedAttestations.js", + "require": "./dist/cjs/types/wagmi/FederatedAttestations.js", + "types": "./dist/types/types/wagmi/FederatedAttestations.d.ts" + }, + "./types/wagmi/FeeCurrencyWhitelist": { + "import": "./dist/esm/types/wagmi/FeeCurrencyWhitelist.js", + "require": "./dist/cjs/types/wagmi/FeeCurrencyWhitelist.js", + "types": "./dist/types/types/wagmi/FeeCurrencyWhitelist.d.ts" + }, + "./types/wagmi/FeeHandler": { + "import": "./dist/esm/types/wagmi/FeeHandler.js", + "require": "./dist/cjs/types/wagmi/FeeHandler.js", + "types": "./dist/types/types/wagmi/FeeHandler.d.ts" + }, + "./types/wagmi/Freezer": { + "import": "./dist/esm/types/wagmi/Freezer.js", + "require": "./dist/cjs/types/wagmi/Freezer.js", + "types": "./dist/types/types/wagmi/Freezer.d.ts" + }, + "./types/wagmi/GasPriceMinimum": { + "import": "./dist/esm/types/wagmi/GasPriceMinimum.js", + "require": "./dist/cjs/types/wagmi/GasPriceMinimum.js", + "types": "./dist/types/types/wagmi/GasPriceMinimum.d.ts" + }, + "./types/wagmi/GoldToken": { + "import": "./dist/esm/types/wagmi/GoldToken.js", + "require": "./dist/cjs/types/wagmi/GoldToken.js", + "types": "./dist/types/types/wagmi/GoldToken.d.ts" + }, + "./types/wagmi/Governance": { + "import": "./dist/esm/types/wagmi/Governance.js", + "require": "./dist/cjs/types/wagmi/Governance.js", + "types": "./dist/types/types/wagmi/Governance.d.ts" + }, + "./types/wagmi/GovernanceApproverMultiSig": { + "import": "./dist/esm/types/wagmi/GovernanceApproverMultiSig.js", + "require": "./dist/cjs/types/wagmi/GovernanceApproverMultiSig.js", + "types": "./dist/types/types/wagmi/GovernanceApproverMultiSig.d.ts" + }, + "./types/wagmi/LockedGold": { + "import": "./dist/esm/types/wagmi/LockedGold.js", + "require": "./dist/cjs/types/wagmi/LockedGold.js", + "types": "./dist/types/types/wagmi/LockedGold.d.ts" + }, + "./types/wagmi/MentoFeeHandlerSeller": { + "import": "./dist/esm/types/wagmi/MentoFeeHandlerSeller.js", + "require": "./dist/cjs/types/wagmi/MentoFeeHandlerSeller.js", + "types": "./dist/types/types/wagmi/MentoFeeHandlerSeller.d.ts" + }, + "./types/wagmi/MetaTransactionWallet": { + "import": "./dist/esm/types/wagmi/MetaTransactionWallet.js", + "require": "./dist/cjs/types/wagmi/MetaTransactionWallet.js", + "types": "./dist/types/types/wagmi/MetaTransactionWallet.d.ts" + }, + "./types/wagmi/MetaTransactionWalletDeployer": { + "import": "./dist/esm/types/wagmi/MetaTransactionWalletDeployer.js", + "require": "./dist/cjs/types/wagmi/MetaTransactionWalletDeployer.js", + "types": "./dist/types/types/wagmi/MetaTransactionWalletDeployer.d.ts" + }, + "./types/wagmi/MultiSig": { + "import": "./dist/esm/types/wagmi/MultiSig.js", + "require": "./dist/cjs/types/wagmi/MultiSig.js", + "types": "./dist/types/types/wagmi/MultiSig.d.ts" + }, + "./types/wagmi/OdisPayments": { + "import": "./dist/esm/types/wagmi/OdisPayments.js", + "require": "./dist/cjs/types/wagmi/OdisPayments.js", + "types": "./dist/types/types/wagmi/OdisPayments.d.ts" + }, + "./types/wagmi/Random": { + "import": "./dist/esm/types/wagmi/Random.js", + "require": "./dist/cjs/types/wagmi/Random.js", + "types": "./dist/types/types/wagmi/Random.d.ts" + }, + "./types/wagmi/Registry": { + "import": "./dist/esm/types/wagmi/Registry.js", + "require": "./dist/cjs/types/wagmi/Registry.js", + "types": "./dist/types/types/wagmi/Registry.d.ts" + }, + "./types/wagmi/ReleaseGold": { + "import": "./dist/esm/types/wagmi/ReleaseGold.js", + "require": "./dist/cjs/types/wagmi/ReleaseGold.js", + "types": "./dist/types/types/wagmi/ReleaseGold.d.ts" + }, + "./types/wagmi/SortedOracles": { + "import": "./dist/esm/types/wagmi/SortedOracles.js", + "require": "./dist/cjs/types/wagmi/SortedOracles.js", + "types": "./dist/types/types/wagmi/SortedOracles.d.ts" + }, + "./types/wagmi/UniswapFeeHandlerSeller": { + "import": "./dist/esm/types/wagmi/UniswapFeeHandlerSeller.js", + "require": "./dist/cjs/types/wagmi/UniswapFeeHandlerSeller.js", + "types": "./dist/types/types/wagmi/UniswapFeeHandlerSeller.d.ts" + }, + "./types/wagmi/Validators": { + "import": "./dist/esm/types/wagmi/Validators.js", + "require": "./dist/cjs/types/wagmi/Validators.js", + "types": "./dist/types/types/wagmi/Validators.d.ts" + }, + "./types/web3/0.8/GasPriceMinimum": { + "import": "./dist/esm/types/web3/0.8/GasPriceMinimum.js", + "require": "./dist/cjs/types/web3/0.8/GasPriceMinimum.js", + "types": "./dist/types/types/web3/0.8/GasPriceMinimum.d.ts" + }, + "./types/web3/Accounts": { + "import": "./dist/esm/types/web3/Accounts.js", + "require": "./dist/cjs/types/web3/Accounts.js", + "types": "./dist/types/types/web3/Accounts.d.ts" + }, + "./types/web3/Attestations": { + "import": "./dist/esm/types/web3/Attestations.js", + "require": "./dist/cjs/types/web3/Attestations.js", + "types": "./dist/types/types/web3/Attestations.d.ts" + }, + "./types/web3/BlockchainParameters": { + "import": "./dist/esm/types/web3/BlockchainParameters.js", + "require": "./dist/cjs/types/web3/BlockchainParameters.js", + "types": "./dist/types/types/web3/BlockchainParameters.d.ts" + }, + "./types/web3/DoubleSigningSlasher": { + "import": "./dist/esm/types/web3/DoubleSigningSlasher.js", + "require": "./dist/cjs/types/web3/DoubleSigningSlasher.js", + "types": "./dist/types/types/web3/DoubleSigningSlasher.d.ts" + }, + "./types/web3/DowntimeSlasher": { + "import": "./dist/esm/types/web3/DowntimeSlasher.js", + "require": "./dist/cjs/types/web3/DowntimeSlasher.js", + "types": "./dist/types/types/web3/DowntimeSlasher.d.ts" + }, + "./types/web3/Election": { + "import": "./dist/esm/types/web3/Election.js", + "require": "./dist/cjs/types/web3/Election.js", + "types": "./dist/types/types/web3/Election.d.ts" + }, + "./types/web3/EpochRewards": { + "import": "./dist/esm/types/web3/EpochRewards.js", + "require": "./dist/cjs/types/web3/EpochRewards.js", + "types": "./dist/types/types/web3/EpochRewards.d.ts" + }, + "./types/web3/Escrow": { + "import": "./dist/esm/types/web3/Escrow.js", + "require": "./dist/cjs/types/web3/Escrow.js", + "types": "./dist/types/types/web3/Escrow.d.ts" + }, + "./types/web3/FederatedAttestations": { + "import": "./dist/esm/types/web3/FederatedAttestations.js", + "require": "./dist/cjs/types/web3/FederatedAttestations.js", + "types": "./dist/types/types/web3/FederatedAttestations.d.ts" + }, + "./types/web3/FeeCurrencyWhitelist": { + "import": "./dist/esm/types/web3/FeeCurrencyWhitelist.js", + "require": "./dist/cjs/types/web3/FeeCurrencyWhitelist.js", + "types": "./dist/types/types/web3/FeeCurrencyWhitelist.d.ts" + }, + "./types/web3/FeeHandler": { + "import": "./dist/esm/types/web3/FeeHandler.js", + "require": "./dist/cjs/types/web3/FeeHandler.js", + "types": "./dist/types/types/web3/FeeHandler.d.ts" + }, + "./types/web3/Freezer": { + "import": "./dist/esm/types/web3/Freezer.js", + "require": "./dist/cjs/types/web3/Freezer.js", + "types": "./dist/types/types/web3/Freezer.d.ts" + }, + "./types/web3/GasPriceMinimum": { + "import": "./dist/esm/types/web3/GasPriceMinimum.js", + "require": "./dist/cjs/types/web3/GasPriceMinimum.js", + "types": "./dist/types/types/web3/GasPriceMinimum.d.ts" + }, + "./types/web3/GoldToken": { + "import": "./dist/esm/types/web3/GoldToken.js", + "require": "./dist/cjs/types/web3/GoldToken.js", + "types": "./dist/types/types/web3/GoldToken.d.ts" + }, + "./types/web3/Governance": { + "import": "./dist/esm/types/web3/Governance.js", + "require": "./dist/cjs/types/web3/Governance.js", + "types": "./dist/types/types/web3/Governance.d.ts" + }, + "./types/web3/GovernanceApproverMultiSig": { + "import": "./dist/esm/types/web3/GovernanceApproverMultiSig.js", + "require": "./dist/cjs/types/web3/GovernanceApproverMultiSig.js", + "types": "./dist/types/types/web3/GovernanceApproverMultiSig.d.ts" + }, + "./types/web3/ICeloToken": { + "import": "./dist/esm/types/web3/ICeloToken.js", + "require": "./dist/cjs/types/web3/ICeloToken.js", + "types": "./dist/types/types/web3/ICeloToken.d.ts" + }, + "./types/web3/ICeloVersionedContract": { + "import": "./dist/esm/types/web3/ICeloVersionedContract.js", + "require": "./dist/cjs/types/web3/ICeloVersionedContract.js", + "types": "./dist/types/types/web3/ICeloVersionedContract.d.ts" + }, + "./types/web3/IERC20": { + "import": "./dist/esm/types/web3/IERC20.js", + "require": "./dist/cjs/types/web3/IERC20.js", + "types": "./dist/types/types/web3/IERC20.d.ts" + }, + "./types/web3/LockedGold": { + "import": "./dist/esm/types/web3/LockedGold.js", + "require": "./dist/cjs/types/web3/LockedGold.js", + "types": "./dist/types/types/web3/LockedGold.d.ts" + }, + "./types/web3/MentoFeeHandlerSeller": { + "import": "./dist/esm/types/web3/MentoFeeHandlerSeller.js", + "require": "./dist/cjs/types/web3/MentoFeeHandlerSeller.js", + "types": "./dist/types/types/web3/MentoFeeHandlerSeller.d.ts" + }, + "./types/web3/MetaTransactionWallet": { + "import": "./dist/esm/types/web3/MetaTransactionWallet.js", + "require": "./dist/cjs/types/web3/MetaTransactionWallet.js", + "types": "./dist/types/types/web3/MetaTransactionWallet.d.ts" + }, + "./types/web3/MetaTransactionWalletDeployer": { + "import": "./dist/esm/types/web3/MetaTransactionWalletDeployer.js", + "require": "./dist/cjs/types/web3/MetaTransactionWalletDeployer.js", + "types": "./dist/types/types/web3/MetaTransactionWalletDeployer.d.ts" + }, + "./types/web3/MultiSig": { + "import": "./dist/esm/types/web3/MultiSig.js", + "require": "./dist/cjs/types/web3/MultiSig.js", + "types": "./dist/types/types/web3/MultiSig.d.ts" + }, + "./types/web3/OdisPayments": { + "import": "./dist/esm/types/web3/OdisPayments.js", + "require": "./dist/cjs/types/web3/OdisPayments.js", + "types": "./dist/types/types/web3/OdisPayments.d.ts" + }, + "./types/web3/Proxy": { + "import": "./dist/esm/types/web3/Proxy.js", + "require": "./dist/cjs/types/web3/Proxy.js", + "types": "./dist/types/types/web3/Proxy.d.ts" + }, + "./types/web3/Random": { + "import": "./dist/esm/types/web3/Random.js", + "require": "./dist/cjs/types/web3/Random.js", + "types": "./dist/types/types/web3/Random.d.ts" + }, + "./types/web3/Registry": { + "import": "./dist/esm/types/web3/Registry.js", + "require": "./dist/cjs/types/web3/Registry.js", + "types": "./dist/types/types/web3/Registry.d.ts" + }, + "./types/web3/ReleaseGold": { + "import": "./dist/esm/types/web3/ReleaseGold.js", + "require": "./dist/cjs/types/web3/ReleaseGold.js", + "types": "./dist/types/types/web3/ReleaseGold.d.ts" + }, + "./types/web3/SortedOracles": { + "import": "./dist/esm/types/web3/SortedOracles.js", + "require": "./dist/cjs/types/web3/SortedOracles.js", + "types": "./dist/types/types/web3/SortedOracles.d.ts" + }, + "./types/web3/UniswapFeeHandlerSeller": { + "import": "./dist/esm/types/web3/UniswapFeeHandlerSeller.js", + "require": "./dist/cjs/types/web3/UniswapFeeHandlerSeller.js", + "types": "./dist/types/types/web3/UniswapFeeHandlerSeller.d.ts" + }, + "./types/web3/Validators": { + "import": "./dist/esm/types/web3/Validators.js", + "require": "./dist/cjs/types/web3/Validators.js", + "types": "./dist/types/types/web3/Validators.d.ts" + }, + "./types/web3/mento/Exchange": { + "import": "./dist/esm/types/web3/mento/Exchange.js", + "require": "./dist/cjs/types/web3/mento/Exchange.js", + "types": "./dist/types/types/web3/mento/Exchange.d.ts" + }, + "./types/web3/mento/ExchangeBRL": { + "import": "./dist/esm/types/web3/mento/ExchangeBRL.js", + "require": "./dist/cjs/types/web3/mento/ExchangeBRL.js", + "types": "./dist/types/types/web3/mento/ExchangeBRL.d.ts" + }, + "./types/web3/mento/ExchangeEUR": { + "import": "./dist/esm/types/web3/mento/ExchangeEUR.js", + "require": "./dist/cjs/types/web3/mento/ExchangeEUR.js", + "types": "./dist/types/types/web3/mento/ExchangeEUR.d.ts" + }, + "./types/web3/mento/GrandaMento": { + "import": "./dist/esm/types/web3/mento/GrandaMento.js", + "require": "./dist/cjs/types/web3/mento/GrandaMento.js", + "types": "./dist/types/types/web3/mento/GrandaMento.d.ts" + }, + "./types/web3/mento/Reserve": { + "import": "./dist/esm/types/web3/mento/Reserve.js", + "require": "./dist/cjs/types/web3/mento/Reserve.js", + "types": "./dist/types/types/web3/mento/Reserve.d.ts" + }, + "./types/web3/mento/ReserveSpenderMultiSig": { + "import": "./dist/esm/types/web3/mento/ReserveSpenderMultiSig.js", + "require": "./dist/cjs/types/web3/mento/ReserveSpenderMultiSig.js", + "types": "./dist/types/types/web3/mento/ReserveSpenderMultiSig.d.ts" + }, + "./types/web3/mento/StableToken": { + "import": "./dist/esm/types/web3/mento/StableToken.js", + "require": "./dist/cjs/types/web3/mento/StableToken.js", + "types": "./dist/types/types/web3/mento/StableToken.d.ts" + }, + "./types/web3/mento/StableTokenBRL": { + "import": "./dist/esm/types/web3/mento/StableTokenBRL.js", + "require": "./dist/cjs/types/web3/mento/StableTokenBRL.js", + "types": "./dist/types/types/web3/mento/StableTokenBRL.d.ts" + }, + "./types/web3/mento/StableTokenEUR": { + "import": "./dist/esm/types/web3/mento/StableTokenEUR.js", + "require": "./dist/cjs/types/web3/mento/StableTokenEUR.js", + "types": "./dist/types/types/web3/mento/StableTokenEUR.d.ts" + } + } +} \ No newline at end of file diff --git a/packages/protocol/abis/tsconfig-cjs.json b/packages/protocol/abis/tsconfig-cjs.json index 3734495e62e..86635778c22 100644 --- a/packages/protocol/abis/tsconfig-cjs.json +++ b/packages/protocol/abis/tsconfig-cjs.json @@ -1,6 +1,8 @@ { "extends": "./tsconfig.json", "compilerOptions": { + "esModuleInterop": false, + "declaration": false, "module": "CommonJS", "outDir": "./dist/cjs" }, diff --git a/packages/protocol/abis/tsconfig-types.json b/packages/protocol/abis/tsconfig-types.json new file mode 100644 index 00000000000..caf132b8e02 --- /dev/null +++ b/packages/protocol/abis/tsconfig-types.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "./dist/types", + "declaration": true, + "emitDeclarationOnly": true + } +} \ No newline at end of file diff --git a/packages/protocol/abis/tsconfig.json b/packages/protocol/abis/tsconfig.json index 7c400b0f1e2..abc7c088d7d 100644 --- a/packages/protocol/abis/tsconfig.json +++ b/packages/protocol/abis/tsconfig.json @@ -5,7 +5,7 @@ "esModuleInterop": true, "baseUrl": ".", "strict": true, - "moduleResolution": "node", + "moduleResolution": "node16", "noUnusedLocals": true, "noUnusedParameters": true, "removeComments": false, @@ -14,8 +14,7 @@ "target": "ES2020", "downlevelIteration": true, "resolveJsonModule": true, - "declaration": true, - "module": "ES2020", + "declaration": false, "rootDir": "./src-generated", "outDir": "./dist/esm" }, diff --git a/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts b/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts index e24363afce7..fb4b31226e8 100644 --- a/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts +++ b/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts @@ -76,6 +76,11 @@ try { stdio: 'inherit', }) + log('Compiling declarations') + child_process.execSync(`yarn tsc -b ${path.join(ABIS_PACKAGE_SRC_DIR, 'tsconfig-types.json')}`, { + stdio: 'inherit', + }) + exports = { ...exports, ...prepareTargetTypesExports(), @@ -95,27 +100,32 @@ try { // Helper functions function prepareTargetTypesExports() { const exports = {} - const targets = ['esm', 'cjs'] + const targets = ['esm', 'cjs', 'types'] targets.forEach((target) => { - fs.copyFileSync( - path.join(ABIS_PACKAGE_SRC_DIR, `package-${target}.json`), - path.join(ABIS_DIST_DIR, target, 'package.json') - ) + // why? + // fs.copyFileSync( + // path.join(ABIS_PACKAGE_SRC_DIR, `package-${target}.json`), + // path.join(ABIS_DIST_DIR, target, 'package.json') + // ) const filePaths = lsRecursive(path.join(ABIS_DIST_DIR, target)) - + console.log(filePaths) filePaths.forEach((filePath) => { const parsedPath = path.parse(filePath) - if (PublishContracts.includes(parsedPath.name)) { + // Remove the .d from the name -- only for types types no harm otherwise + const parsedPathName = parsedPath.name.replace('.d', '') + console.log('path name', parsedPathName) + if (PublishContracts.includes(parsedPathName)) { const relativePath = path.join( path.relative(ABIS_PACKAGE_SRC_DIR, parsedPath.dir), - parsedPath.name + parsedPathName ) + console.log(relativePath) const exportKey = `./${path.join( path.relative(path.join(ABIS_DIST_DIR, target), parsedPath.dir), - parsedPath.name + parsedPathName )}` if (!exports.hasOwnProperty(exportKey)) { @@ -123,25 +133,32 @@ function prepareTargetTypesExports() { } if (target == 'esm') { - const typesPath = `./${relativePath}.d.ts` const importPath = `./${relativePath}.js` - expectFileExists(typesPath) expectFileExists(importPath) exports[exportKey] = { ...exports[exportKey], - types: typesPath, import: importPath, } - } else { + } else if (target == 'cjs') { const requirePath = `./${relativePath}.js` expectFileExists(requirePath) exports[exportKey] = { ...exports[exportKey], - require: `./${relativePath}.js`, + require: requirePath, + } + } else { + //types + const typesPath = `./${relativePath}.d.ts` + console.log('types', typesPath) + expectFileExists(typesPath) + + exports[exportKey] = { + ...exports[exportKey], + types: typesPath, } } } diff --git a/packages/sdk/contractkit/package.json b/packages/sdk/contractkit/package.json index ba015e3433a..38a6cc88510 100644 --- a/packages/sdk/contractkit/package.json +++ b/packages/sdk/contractkit/package.json @@ -24,7 +24,7 @@ "lint": "tslint -c tslint.json --project ." }, "dependencies": { - "@celo/abis": "10.0.0-beta.5", + "@celo/abis": "10.0.0-local", "@celo/base": "^6.0.0", "@celo/connect": "^5.1.1", "@celo/utils": "^5.0.6", From 1666b0144c59067f05bbadecc22829e6af35c924 Mon Sep 17 00:00:00 2001 From: Aaron DeRuvo Date: Fri, 1 Dec 2023 13:18:16 +0200 Subject: [PATCH 32/63] yolo --- packages/cli/package.json | 2 +- packages/cli/src/base.ts | 3 ++- packages/cli/tsconfig.json | 5 +++-- packages/sdk/contractkit/src/wrappers/BaseSlasher.ts | 2 +- packages/sdk/governance/package.json | 2 +- packages/sdk/governance/tsconfig.json | 1 + yarn.lock | 5 ----- 7 files changed, 9 insertions(+), 11 deletions(-) diff --git a/packages/cli/package.json b/packages/cli/package.json index 87c288521a2..44ef0a4f73f 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -30,7 +30,7 @@ "test": "TZ=UTC jest --runInBand" }, "dependencies": { - "@celo/abis": "10.0.0-beta.5", + "@celo/abis": "10.0.0-local", "@celo/base": "^6.0.0", "@celo/connect": "^5.1.1", "@celo/contractkit": "^5.2.0", diff --git a/packages/cli/src/base.ts b/packages/cli/src/base.ts index b97492c5ffb..fa2070a94d6 100644 --- a/packages/cli/src/base.ts +++ b/packages/cli/src/base.ts @@ -97,7 +97,7 @@ export abstract class BaseCommand extends Command { // For commands that don't require the node is synced, add the following line // to its definition: // requireSynced = false - public requireSynced: boolean = true + public requireSynced = true private _web3: Web3 | null = null private _kit: ContractKit | null = null @@ -155,6 +155,7 @@ export abstract class BaseCommand extends Command { try { // Importing for ledger uses only fixes running jest tests const TransportNodeHid = (await import('@ledgerhq/hw-transport-node-hid')).default + // @ts-expect-error // TODO fix types transport = await TransportNodeHid.open('') const derivationPathIndexes = res.raw.some( (value) => (value as any).flag === 'ledgerCustomAddresses' diff --git a/packages/cli/tsconfig.json b/packages/cli/tsconfig.json index f8c11ebdc94..a70ac88f42d 100644 --- a/packages/cli/tsconfig.json +++ b/packages/cli/tsconfig.json @@ -1,10 +1,11 @@ { "extends": "@celo/typescript/tsconfig.library.json", "compilerOptions": { + "moduleResolution": "node16", "rootDir": "src", "outDir": "lib", - "esModuleInterop": true, - "target": "es6" + "esModuleInterop": false, + "target": "es2020" }, "include": ["src", "../contractkit/types"], "references": [{ "path": "../sdk/utils" }, { "path": "../sdk/contractkit" }] diff --git a/packages/sdk/contractkit/src/wrappers/BaseSlasher.ts b/packages/sdk/contractkit/src/wrappers/BaseSlasher.ts index 17a03fb5b35..122df4322a0 100644 --- a/packages/sdk/contractkit/src/wrappers/BaseSlasher.ts +++ b/packages/sdk/contractkit/src/wrappers/BaseSlasher.ts @@ -61,7 +61,7 @@ export class BaseSlasher extends BaseWrapperForGovern } protected slash = (...args: Parameters) => - toTransactionObject(this.connection, this.contract.methods.slash(...args)) + toTransactionObject(this.connection, this.contract.methods.slash(...(args as any[]))) /** * Returns slashing incentives. diff --git a/packages/sdk/governance/package.json b/packages/sdk/governance/package.json index cfce4295673..2efda07f2c5 100644 --- a/packages/sdk/governance/package.json +++ b/packages/sdk/governance/package.json @@ -21,7 +21,7 @@ "prepublishOnly": "yarn build" }, "dependencies": { - "@celo/abis": "10.0.0-beta.5", + "@celo/abis": "10.0.0-local", "@celo/base": "^6.0.0", "@celo/utils": "^5.0.6", "@celo/connect": "^5.1.1", diff --git a/packages/sdk/governance/tsconfig.json b/packages/sdk/governance/tsconfig.json index 25d848de425..0d7e3ffd850 100644 --- a/packages/sdk/governance/tsconfig.json +++ b/packages/sdk/governance/tsconfig.json @@ -1,6 +1,7 @@ { "extends": "@celo/typescript/tsconfig.library.json", "compilerOptions": { + "moduleResolution": "node16", "rootDir": "src", "outDir": "lib" }, diff --git a/yarn.lock b/yarn.lock index 2be4787f23f..b7862e180fd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -973,11 +973,6 @@ resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== -"@celo/abis@10.0.0-beta.5": - version "10.0.0-beta.5" - resolved "https://registry.yarnpkg.com/@celo/abis/-/abis-10.0.0-beta.5.tgz#633e567b66ba7e1767ee5cb970d6249445d7b78d" - integrity sha512-yfRZj26Cw35G6M2xsmiZtRyN7OdHZI1uAkoBJ0ZHUlRq+GFSa60PiXcjfAPHLx/Y6MMjHVRjNtSEL/awNlmzoQ== - "@celo/base@^5.0.5": version "5.0.5" resolved "https://registry.yarnpkg.com/@celo/base/-/base-5.0.5.tgz#b4102faba080ce536411b7987259d9ca152b6e6d" From 2737ba06f177e62f0b491e1fb8794a20a3b1442e Mon Sep 17 00:00:00 2001 From: Aaron DeRuvo Date: Fri, 1 Dec 2023 13:30:40 +0200 Subject: [PATCH 33/63] two experiments, dont build all packages before running the script as it will build what it needs always prepare --- .github/workflows/publish-contracts-abi-release.yml | 3 --- packages/protocol/package.json | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/publish-contracts-abi-release.yml b/.github/workflows/publish-contracts-abi-release.yml index fae567d34fc..ceb49eb350a 100644 --- a/.github/workflows/publish-contracts-abi-release.yml +++ b/.github/workflows/publish-contracts-abi-release.yml @@ -47,9 +47,6 @@ jobs: shell: bash run: yarn - - name: 'Build all packages' - run: yarn build - - name: Check if a release should be published # This is what sets the RELEASE_TYPE and RELEASE_VERSION env variables run: yarn --silent is_contract_release >> "$GITHUB_ENV" diff --git a/packages/protocol/package.json b/packages/protocol/package.json index 750a720e2e0..e3a337a6347 100644 --- a/packages/protocol/package.json +++ b/packages/protocol/package.json @@ -21,7 +21,7 @@ "pull-submodules": "git submodule update --init --recursive", "delete-submodules": "rm -rf $(git submodule | awk '{ print $2 }')", "build:sol": "yarn pull-submodules && mkdir -p migrations && ts-node --preferTsExts ./scripts/build.ts --solidity ${BUILD_DIR:-./build}", - "build": "yarn build:sol && yarn build:ts", + "build": "yarn build:sol && yarn build:ts && yarn prepare_contracts_and_abis_publishing", "prebuild": "rm -rf ./build", "is_contract_release": "ts-node ./scripts/is-contract-release.ts", "prepare_contracts_and_abis_publishing": "ts-node ./scripts/prepare-contracts-and-abis-publishing.ts", From 6fe6b5d2bc15645f7974386f1d7af869aaef5a2c Mon Sep 17 00:00:00 2001 From: Aaron DeRuvo Date: Fri, 1 Dec 2023 14:59:22 +0200 Subject: [PATCH 34/63] we dont need to change target as it already set. --- packages/protocol/package.json | 2 +- .../prepare-contracts-and-abis-publishing.ts | 5 -- packages/protocol/tsconfig.json | 52 ++++++++++++------- 3 files changed, 33 insertions(+), 26 deletions(-) diff --git a/packages/protocol/package.json b/packages/protocol/package.json index e3a337a6347..750a720e2e0 100644 --- a/packages/protocol/package.json +++ b/packages/protocol/package.json @@ -21,7 +21,7 @@ "pull-submodules": "git submodule update --init --recursive", "delete-submodules": "rm -rf $(git submodule | awk '{ print $2 }')", "build:sol": "yarn pull-submodules && mkdir -p migrations && ts-node --preferTsExts ./scripts/build.ts --solidity ${BUILD_DIR:-./build}", - "build": "yarn build:sol && yarn build:ts && yarn prepare_contracts_and_abis_publishing", + "build": "yarn build:sol && yarn build:ts", "prebuild": "rm -rf ./build", "is_contract_release": "ts-node ./scripts/is-contract-release.ts", "prepare_contracts_and_abis_publishing": "ts-node ./scripts/prepare-contracts-and-abis-publishing.ts", diff --git a/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts b/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts index fb4b31226e8..cd87b71818f 100644 --- a/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts +++ b/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts @@ -19,11 +19,6 @@ function log(...args: any[]) { } try { - log('Setting package.json target to ES2020') - const tsconfig = JSON.parse(fs.readFileSync(TSCONFIG_PATH, 'utf8')) - tsconfig.compilerOptions.target = 'ES2020' - fs.writeFileSync(TSCONFIG_PATH, JSON.stringify(tsconfig, null, 4)) - // Start from scratch rmrfSync([ABIS_BUILD_DIR, ABIS_DIST_DIR]) fs.mkdirSync(ABIS_BUILD_DIR, { recursive: true }) diff --git a/packages/protocol/tsconfig.json b/packages/protocol/tsconfig.json index 93e3054ed23..e26f8383d08 100644 --- a/packages/protocol/tsconfig.json +++ b/packages/protocol/tsconfig.json @@ -1,21 +1,33 @@ { - "compileOnSave": false, - "compilerOptions": { - "allowSyntheticDefaultImports": true, - "esModuleInterop": true, - "baseUrl": ".", - "lib": ["dom", "es2015", "es2016"], - "module": "commonjs", - "moduleResolution": "node", - "noUnusedLocals": true, - "noUnusedParameters": true, - "removeComments": false, - "skipLibCheck": true, - "sourceMap": true, - "target": "ES5", - "downlevelIteration": true, - "resolveJsonModule": true - }, - "exclude": ["node_modules", "wagmi.config.ts"], - "references": [{ "path": "../sdk/utils" }] -} + "compileOnSave": false, + "compilerOptions": { + "allowSyntheticDefaultImports": true, + "esModuleInterop": true, + "baseUrl": ".", + "lib": [ + "dom", + "es2015", + "es2016" + ], + "module": "commonjs", + "moduleResolution": "node", + "noUnusedLocals": true, + "noUnusedParameters": true, + "removeComments": false, + "skipLibCheck": true, + "sourceMap": true, + "target": "ES2020", + "downlevelIteration": true, + "resolveJsonModule": true + }, + "exclude": [ + "node_modules", + "wagmi.config.ts", + "abis" + ], + "references": [ + { + "path": "../sdk/utils" + } + ] +} \ No newline at end of file From 3dc0d3554e28c53f6de5e7ac5670cfd5a9d234ae Mon Sep 17 00:00:00 2001 From: pahor167 <47992132+pahor167@users.noreply.github.com> Date: Fri, 1 Dec 2023 14:05:26 +0100 Subject: [PATCH 35/63] Foundry IdentityProxy IdentityProxyHub test (#10698) * Identity Proxy Test * Identity proxy hub * gitmodules * attestations basic * celo foundry update * celo foundry update v2 * Attestions.t buildable and few tests migrated * some tests working * Attestation tests * FederatedAttestation tests * OdisPayments * attestations spelling fixes * more spelling fixes * remoal of ts tests * Federated attestations removal of warnings * ExtractFunctionSignatureTest * AddressSortedLinkedListWithMedian * PR comments 2 * revert of submodule * Split into multiple PRs * Revert of other tests --- .../protocol/contracts/common/Accounts.sol | 6 +- packages/protocol/foundry.toml | 2 + packages/protocol/test-sol/GoldToken.t.sol | 18 +- .../protocol/test-sol/IdentityProxy.t.sol | 46 ++++ .../protocol/test-sol/IdentityProxyHub.t.sol | 239 +++++++++++++++++ packages/protocol/test/common/goldtoken.ts | 243 ------------------ .../protocol/test/identity/identityproxy.ts | 47 ---- .../test/identity/identityproxyhub.ts | 216 ---------------- 8 files changed, 299 insertions(+), 518 deletions(-) create mode 100644 packages/protocol/test-sol/IdentityProxy.t.sol create mode 100644 packages/protocol/test-sol/IdentityProxyHub.t.sol delete mode 100644 packages/protocol/test/common/goldtoken.ts delete mode 100644 packages/protocol/test/identity/identityproxy.ts delete mode 100644 packages/protocol/test/identity/identityproxyhub.ts diff --git a/packages/protocol/contracts/common/Accounts.sol b/packages/protocol/contracts/common/Accounts.sol index 2dcad7d7013..ac93720967e 100644 --- a/packages/protocol/contracts/common/Accounts.sol +++ b/packages/protocol/contracts/common/Accounts.sol @@ -756,7 +756,7 @@ contract Accounts is * @notice Returns the account associated with `signer`. * @param signer The address of the account or currently authorized attestation signer. * @dev Fails if the `signer` is not an account or currently authorized attestation signer. - * @return The associated account. + * @return The associated account that the signer is authorized to attest for. */ function attestationSignerToAccount(address signer) external view returns (address) { return signerToAccountWithRole(signer, AttestationSigner); @@ -766,7 +766,7 @@ contract Accounts is * @notice Returns the account associated with `signer`. * @param signer The address of an account or currently authorized validator signer. * @dev Fails if the `signer` is not an account or currently authorized validator. - * @return The associated account. + * @return The associated account that signer is authorized to validate for. */ function validatorSignerToAccount(address signer) public view returns (address) { return signerToAccountWithRole(signer, ValidatorSigner); @@ -776,7 +776,7 @@ contract Accounts is * @notice Returns the account associated with `signer`. * @param signer The address of the account or currently authorized vote signer. * @dev Fails if the `signer` is not an account or currently authorized vote signer. - * @return The associated account. + * @return The associated account that signer is authorized to vote for. */ function voteSignerToAccount(address signer) external view returns (address) { return signerToAccountWithRole(signer, VoteSigner); diff --git a/packages/protocol/foundry.toml b/packages/protocol/foundry.toml index 012768da682..4ea48658d7e 100644 --- a/packages/protocol/foundry.toml +++ b/packages/protocol/foundry.toml @@ -15,4 +15,6 @@ remappings = [ no_match_contract = "RandomTest" no_match_path = "contracts/common/libraries/test/BLS12Passthrough.sol" # tested from celo-blockain repo +fs_permissions = [{ access = "read", path = "./out"}] + # See more config options https://github.com/foundry-rs/foundry/tree/master/config diff --git a/packages/protocol/test-sol/GoldToken.t.sol b/packages/protocol/test-sol/GoldToken.t.sol index 1b002c5e1a1..1869aa75466 100644 --- a/packages/protocol/test-sol/GoldToken.t.sol +++ b/packages/protocol/test-sol/GoldToken.t.sol @@ -131,7 +131,7 @@ contract GoldTokenTransferFrom is GoldTokenTest { goldToken.transferFrom(sender, address(0), ONE_GOLDTOKEN); } - function testTransfer_ShouldNotAllowTransferingMoreThanSenderHas() public { + function testTransfer_ShouldNotAllowTransferMoreThanSenderHas() public { uint256 value = sender.balance + ONE_GOLDTOKEN * 4; vm.prank(receiver); @@ -174,13 +174,13 @@ contract BurnGoldToken is GoldTokenTest { } contract MockGoldTokenTest is Test { - MockGoldToken mockgoldToken; + MockGoldToken mockGoldToken; uint256 ONE_GOLDTOKEN = 1000000000000000000; address burnAddress = address(0x000000000000000000000000000000000000dEaD); function setUp() public { - mockgoldToken = new MockGoldToken(); - mockgoldToken.setTotalSupply(ONE_GOLDTOKEN * 1000); + mockGoldToken = new MockGoldToken(); + mockGoldToken.setTotalSupply(ONE_GOLDTOKEN * 1000); } } @@ -189,13 +189,13 @@ contract MockGoldTokenCirculatingSupply is MockGoldTokenTest { super.setUp(); } - function test_ShouldMatchCirculationSuply_WhenNoBurn() public { - assertEq(mockgoldToken.circulatingSupply(), mockgoldToken.totalSupply()); + function test_ShouldMatchCirculationSupply_WhenNoBurn() public { + assertEq(mockGoldToken.circulatingSupply(), mockGoldToken.totalSupply()); } function test_ShouldDecreaseCirculatingSupply_WhenThereWasBurn() public { - mockgoldToken.setBalanceOf(burnAddress, ONE_GOLDTOKEN); - assertEq(mockgoldToken.circulatingSupply(), ONE_GOLDTOKEN * 999); - assertEq(mockgoldToken.circulatingSupply(), mockgoldToken.totalSupply() - ONE_GOLDTOKEN); + mockGoldToken.setBalanceOf(burnAddress, ONE_GOLDTOKEN); + assertEq(mockGoldToken.circulatingSupply(), ONE_GOLDTOKEN * 999); + assertEq(mockGoldToken.circulatingSupply(), mockGoldToken.totalSupply() - ONE_GOLDTOKEN); } } diff --git a/packages/protocol/test-sol/IdentityProxy.t.sol b/packages/protocol/test-sol/IdentityProxy.t.sol new file mode 100644 index 00000000000..57c92d322bd --- /dev/null +++ b/packages/protocol/test-sol/IdentityProxy.t.sol @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.5.13; + +import "celo-foundry/Test.sol"; +import "forge-std/console.sol"; +import "../contracts/identity/IdentityProxy.sol"; +import "../contracts/identity/test/IdentityProxyTest.sol"; + +contract IdentityProxyTestFoundry is Test { + IdentityProxy identityProxy; + IdentityProxyTest identityProxyTest; + + address randomActor = actor("randomActor"); + + function setUp() public { + identityProxy = new IdentityProxy(); + identityProxyTest = new IdentityProxyTest(); + } +} + +contract IdentityProxyTestMakeCall is IdentityProxyTestFoundry { + function setUp() public { + super.setUp(); + } + + function test_CanBeUsedToForwardCall() public { + uint256 value = 42; + identityProxy.makeCall( + address(identityProxyTest), + abi.encodeWithSignature("setX(uint256)", value) + ); + assertEq(identityProxyTest.x(), value); + } + + function test_MakesCallsFromAddressOfTheProxy() public { + identityProxy.makeCall(address(identityProxyTest), abi.encodeWithSignature("callMe()")); + assertEq(identityProxyTest.lastAddress(), address(identityProxy)); + } + + function test_CannotBeCalledByAnyoneOtherThanTheOriginalDeployer() public { + bytes memory txData = abi.encodeWithSignature("callMe()"); + vm.expectRevert("Only callable by original deployer"); + vm.prank(randomActor); + identityProxy.makeCall(address(identityProxyTest), txData); + } +} diff --git a/packages/protocol/test-sol/IdentityProxyHub.t.sol b/packages/protocol/test-sol/IdentityProxyHub.t.sol new file mode 100644 index 00000000000..ea6ce490694 --- /dev/null +++ b/packages/protocol/test-sol/IdentityProxyHub.t.sol @@ -0,0 +1,239 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.5.13; + +import "celo-foundry/Test.sol"; +import "forge-std/console.sol"; +import "../contracts/identity/IdentityProxy.sol"; +import "../contracts/identity/IdentityProxyHub.sol"; +import "../contracts/identity/test/IdentityProxyTest.sol"; +import "../contracts/identity/test/MockAttestations.sol"; +import "../contracts/common/Registry.sol"; + +contract IdentityProxyHubTest is Test { + IdentityProxy identityProxy; + IdentityProxyTest identityProxyTest; + IdentityProxyHub identityProxyHub; + MockAttestations mockAttestations; + Registry registry; + + address randomActor = actor("randomActor"); + + bytes32 identifier = keccak256( + "0x00000000000000000000000000000000000000000000000000000000babecafe" + ); + + function setUp() public { + identityProxy = new IdentityProxy(); + identityProxyTest = new IdentityProxyTest(); + identityProxyHub = new IdentityProxyHub(); + mockAttestations = new MockAttestations(); + registry = new Registry(true); + registry.initialize(); + registry.setAddressFor("Attestations", address(mockAttestations)); + identityProxyHub.setRegistry(address(registry)); + } + + function computeCreate2Address( + bytes32 salt, + address deployerAddress, + bytes memory contractBytecode + ) public pure returns (address) { + bytes32 bytecodeHash = keccak256(contractBytecode); + bytes32 hash = keccak256(abi.encodePacked(bytes1(0xff), deployerAddress, salt, bytecodeHash)); + + return + address( + uint160(uint256(hash) & 0x000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF) + ); + } + + /** + * Returns bytecode at address + * @param _addr The address to get the code from + */ + function at(address _addr) public view returns (bytes memory o_code) { + assembly { + // retrieve the size of the code + let size := extcodesize(_addr) + // allocate output byte array + // by using o_code = new bytes(size) + o_code := mload(0x40) + // new "memory end" including padding + mstore(0x40, add(o_code, and(add(add(size, 0x20), 0x1f), not(0x1f)))) + // store length in memory + mstore(o_code, size) + // actually retrieve the code, this needs assembly + extcodecopy(_addr, add(o_code, 0x20), 0, size) + } + } +} + +contract IdentityProxyTestGetIdenityProxy is IdentityProxyHubTest { + function setUp() public { + super.setUp(); + } + + function test_ReturnsTheCorrectCREATE2Address() public { + bytes memory bytecode = type(IdentityProxy).creationCode; + address expectedAddress = computeCreate2Address( + identifier, + address(identityProxyHub), + bytecode + ); + IdentityProxy identityProxyReturned = identityProxyHub.getOrDeployIdentityProxy(identifier); + assertEq(expectedAddress, address(identityProxyReturned)); + } + + function test_ReturnsTheAddressOfAnIdentityProxy() public { + IdentityProxy identityProxyReturned = identityProxyHub.getOrDeployIdentityProxy(identifier); + identityProxyHub.getOrDeployIdentityProxy(identifier); + + bytes memory deployedCode = vm.getDeployedCode("IdentityProxy.sol:IdentityProxy"); + assertEq(deployedCode, at(address(identityProxyReturned))); + } +} + +contract IdentityProxyTestMakeCall_Failures is IdentityProxyHubTest { + address identityProxyAddress; + + function setUp() public { + super.setUp(); + identityProxyAddress = address(identityProxyHub.getOrDeployIdentityProxy(identifier)); + } + + function test_FailsToCallIfSenderDoesNotHaveAtLeast3AttestationCompletions() public { + mockAttestations.complete(identifier, 0, bytes32(0), bytes32(0)); + mockAttestations.complete(identifier, 0, bytes32(0), bytes32(0)); + + bytes memory txData = abi.encodeWithSignature("callMe()"); + vm.expectRevert("does not pass identity heuristic"); + identityProxyHub.makeCall(identifier, address(identityProxyTest), txData); + } + + function test_FailsToCallIfSenderDoesNotHaveMoreThan50PercentAttestationCompletions() public { + mockAttestations.complete(identifier, 0, bytes32(0), bytes32(0)); + mockAttestations.complete(identifier, 0, bytes32(0), bytes32(0)); + mockAttestations.complete(identifier, 0, bytes32(0), bytes32(0)); + + mockAttestations.request(identifier, 0, bytes32(0), bytes32(0)); + mockAttestations.request(identifier, 0, bytes32(0), bytes32(0)); + mockAttestations.request(identifier, 0, bytes32(0), bytes32(0)); + mockAttestations.request(identifier, 0, bytes32(0), bytes32(0)); + mockAttestations.request(identifier, 0, bytes32(0), bytes32(0)); + mockAttestations.request(identifier, 0, bytes32(0), bytes32(0)); + mockAttestations.request(identifier, 0, bytes32(0), bytes32(0)); + + bytes memory txData = abi.encodeWithSignature("callMe()"); + vm.expectRevert("does not pass identity heuristic"); + identityProxyHub.makeCall(identifier, address(identityProxyTest), txData); + } + + function test_FailsToCallIfAnotherAddressHasMoreAttestationsCompleted() public { + mockAttestations.complete(identifier, 0, bytes32(0), bytes32(0)); + mockAttestations.complete(identifier, 0, bytes32(0), bytes32(0)); + mockAttestations.complete(identifier, 0, bytes32(0), bytes32(0)); + + vm.prank(randomActor); + mockAttestations.complete(identifier, 0, bytes32(0), bytes32(0)); + vm.prank(randomActor); + mockAttestations.complete(identifier, 0, bytes32(0), bytes32(0)); + vm.prank(randomActor); + mockAttestations.complete(identifier, 0, bytes32(0), bytes32(0)); + vm.prank(randomActor); + mockAttestations.complete(identifier, 0, bytes32(0), bytes32(0)); + + bytes memory txData = abi.encodeWithSignature("callMe()"); + vm.expectRevert("does not pass identity heuristic"); + identityProxyHub.makeCall(identifier, address(identityProxyTest), txData); + } +} + +contract IdentityProxyTestMakeCall_WhenCalledByContractRelatedToTheIdentifier is + IdentityProxyHubTest +{ + address identityProxyAddress; + + function setUp() public { + super.setUp(); + + identityProxyAddress = address(identityProxyHub.getOrDeployIdentityProxy(identifier)); + + mockAttestations.complete(identifier, 0, bytes32(0), bytes32(0)); + mockAttestations.complete(identifier, 0, bytes32(0), bytes32(0)); + mockAttestations.complete(identifier, 0, bytes32(0), bytes32(0)); + } + + function test_ForwardsCallToTheDestination() public { + uint256 value = 42; + identityProxyHub.makeCall( + identifier, + address(identityProxyTest), + abi.encodeWithSignature("setX(uint256)", value) + ); + + assertEq(identityProxyTest.x(), value); + } + + function test_ForwardsCallToEvenWhenCompletedRationIsCloseTo50Percent() public { + mockAttestations.request(identifier, 0, bytes32(0), bytes32(0)); + mockAttestations.request(identifier, 0, bytes32(0), bytes32(0)); + mockAttestations.request(identifier, 0, bytes32(0), bytes32(0)); + mockAttestations.request(identifier, 0, bytes32(0), bytes32(0)); + mockAttestations.request(identifier, 0, bytes32(0), bytes32(0)); + + uint256 value = 42; + identityProxyHub.makeCall( + identifier, + address(identityProxyTest), + abi.encodeWithSignature("setX(uint256)", value) + ); + + assertEq(identityProxyTest.x(), value); + } + + function test_ForwardsCallAsLongAsNoOtherAddressHasMoreCompletions() public { + vm.prank(randomActor); + mockAttestations.complete(identifier, 0, bytes32(0), bytes32(0)); + vm.prank(randomActor); + mockAttestations.complete(identifier, 0, bytes32(0), bytes32(0)); + vm.prank(randomActor); + mockAttestations.complete(identifier, 0, bytes32(0), bytes32(0)); + + uint256 value = 42; + identityProxyHub.makeCall( + identifier, + address(identityProxyTest), + abi.encodeWithSignature("setX(uint256)", value) + ); + + assertEq(identityProxyTest.x(), value); + } + + function test_ForwardsCallToProxyRelatedToIdentifier() public { + uint256 value = 42; + identityProxyHub.makeCall( + identifier, + address(identityProxyTest), + abi.encodeWithSignature("callMe()", value) + ); + + assertEq(identityProxyTest.lastAddress(), identityProxyAddress); + } + + function test_CanSendAPayment() public { + uint256 balanceBefore = address(identityProxyTest).balance; + identityProxyHub.makeCall.value(100)( + identifier, + address(identityProxyTest), + abi.encodeWithSignature("payMe()") + ); + + uint256 proxyBalance = identityProxyAddress.balance; + uint256 balanceAfter = address(identityProxyTest).balance; + + assertEq(balanceBefore, 0); + assertEq(proxyBalance, 0); + assertEq(balanceAfter, 100); + } +} + diff --git a/packages/protocol/test/common/goldtoken.ts b/packages/protocol/test/common/goldtoken.ts deleted file mode 100644 index 9845fbb15b7..00000000000 --- a/packages/protocol/test/common/goldtoken.ts +++ /dev/null @@ -1,243 +0,0 @@ -import { NULL_ADDRESS } from '@celo/base/lib/address' -import { CeloContractName } from '@celo/protocol/lib/registry-utils' -import { - assertBalance, - assertEqualBN, - assertTransactionRevertWithReason, -} from '@celo/protocol/lib/test-utils' -import { BigNumber } from 'bignumber.js' -import _ from 'lodash' -import { - FreezerContract, - FreezerInstance, - GoldTokenContract, - GoldTokenInstance, - MockGoldTokenContract, - MockGoldTokenInstance, - RegistryContract, - RegistryInstance, -} from 'types' - -const Freezer: FreezerContract = artifacts.require('Freezer') -const GoldToken: GoldTokenContract = artifacts.require('GoldToken') -const Registry: RegistryContract = artifacts.require('Registry') -const MockGoldToken: MockGoldTokenContract = artifacts.require('MockGoldToken') - -// @ts-ignore -// TODO(mcortesi): Use BN -GoldToken.numberFormat = 'BigNumber' - -contract('GoldToken', (accounts: string[]) => { - let freezer: FreezerInstance - let goldToken: GoldTokenInstance - let registry: RegistryInstance - const ONE_GOLDTOKEN = new BigNumber('1000000000000000000') - const TWO_GOLDTOKEN = new BigNumber('2000000000000000000') - const burnAddress = '0x000000000000000000000000000000000000dEaD' - - const sender = accounts[0] - const receiver = accounts[1] - - beforeEach(async () => { - freezer = await Freezer.new(true) - goldToken = await GoldToken.new(true) - registry = await Registry.new(true) - await registry.setAddressFor(CeloContractName.Freezer, freezer.address) - await goldToken.initialize(registry.address) - }) - - describe('#name()', () => { - it('should have a name', async () => { - const name: string = await goldToken.name() - assert.equal(name, 'Celo native asset') - }) - }) - - describe('#symbol()', () => { - it('should have a symbol', async () => { - const name: string = await goldToken.symbol() - assert.equal(name, 'CELO') - }) - }) - - describe('#burn()', () => { - let startBurn: BigNumber - - beforeEach(async () => { - startBurn = await goldToken.getBurnedAmount() - }) - - it('burn address starts with zero balance', async () => { - assertEqualBN(await goldToken.balanceOf(burnAddress), 0) - }) - - it('burn starts as start burn amount', async () => { - assertEqualBN(await goldToken.getBurnedAmount(), startBurn) - }) - - it('Burned amount equals the balance of the burn address', async () => { - assertEqualBN(await goldToken.getBurnedAmount(), await goldToken.balanceOf(burnAddress)) - }) - - it('returns right burned amount', async () => { - await goldToken.burn(ONE_GOLDTOKEN) - - assertEqualBN(await goldToken.getBurnedAmount(), ONE_GOLDTOKEN.plus(startBurn)) - }) - }) - - describe('#circulatingSupply()', () => { - let mockGoldToken: MockGoldTokenInstance - - beforeEach(async () => { - mockGoldToken = await MockGoldToken.new() - // set supply to 1K - await mockGoldToken.setTotalSupply(ONE_GOLDTOKEN.multipliedBy(1000)) - }) - - it('matches circulatingSupply() when there was no burn', async () => { - assertEqualBN(await mockGoldToken.circulatingSupply(), await mockGoldToken.totalSupply()) - }) - - it('decreases when there was a burn', async () => { - // mock a burn - await mockGoldToken.setBalanceOf(burnAddress, ONE_GOLDTOKEN) - - const circulatingSupply = await mockGoldToken.circulatingSupply() - // circulatingSupply got reduced to 999 after burning 1 Celo - assertEqualBN(circulatingSupply, ONE_GOLDTOKEN.multipliedBy(999)) - assertEqualBN( - circulatingSupply, - new BigNumber(await mockGoldToken.totalSupply()).plus(ONE_GOLDTOKEN.multipliedBy(-1)) - ) - }) - }) - - describe('#decimals()', () => { - it('should have decimals', async () => { - const decimals: BigNumber = await goldToken.decimals() - assert.equal(decimals.toNumber(), 18) - }) - }) - - describe('#balanceOf()', () => { - it('should match the balance returned by web3', async () => { - assertEqualBN(await goldToken.balanceOf(receiver), await web3.eth.getBalance(receiver)) - }) - }) - - describe('#approve()', () => { - it('should set "allowed"', async () => { - await goldToken.approve(receiver, ONE_GOLDTOKEN) - assert.equal((await goldToken.allowance(sender, receiver)).valueOf(), ONE_GOLDTOKEN.valueOf()) - }) - }) - - describe('#increaseAllowance()', () => { - it('should increase "allowed"', async () => { - await goldToken.increaseAllowance(receiver, ONE_GOLDTOKEN) - await goldToken.increaseAllowance(receiver, ONE_GOLDTOKEN) - assert.equal((await goldToken.allowance(sender, receiver)).valueOf(), TWO_GOLDTOKEN.valueOf()) - }) - }) - - describe('#decreaseAllowance()', () => { - it('should decrease "allowed"', async () => { - await goldToken.approve(receiver, TWO_GOLDTOKEN) - await goldToken.decreaseAllowance(receiver, ONE_GOLDTOKEN) - assert.equal((await goldToken.allowance(sender, receiver)).valueOf(), ONE_GOLDTOKEN.valueOf()) - }) - }) - - describe('#allowance()', () => { - it('should return the allowance', async () => { - await goldToken.approve(receiver, ONE_GOLDTOKEN) - assert.equal((await goldToken.allowance(sender, receiver)).valueOf(), ONE_GOLDTOKEN.valueOf()) - }) - }) - - describe('#transfer()', () => { - it('should transfer balance from one user to another', async () => { - const startBalanceFrom = await goldToken.balanceOf(sender) - const startBalanceTo = await goldToken.balanceOf(receiver) - await goldToken.transfer(receiver, ONE_GOLDTOKEN) - await assertBalance(sender, startBalanceFrom.minus(ONE_GOLDTOKEN)) - await assertBalance(receiver, startBalanceTo.plus(ONE_GOLDTOKEN)) - }) - - it('should transfer balance with a comment', async () => { - const comment = 'tacos at lunch' - const startBalanceFrom = await goldToken.balanceOf(sender) - const startBalanceTo = await goldToken.balanceOf(receiver) - const res = await goldToken.transferWithComment(receiver, ONE_GOLDTOKEN, comment) - const transferEvent = _.find(res.logs, { event: 'Transfer' }) - const transferCommentEvent = _.find(res.logs, { event: 'TransferComment' }) - assert.exists(transferEvent) - assert.equal(transferCommentEvent.args.comment, comment) - await assertBalance(sender, startBalanceFrom.minus(ONE_GOLDTOKEN)) - await assertBalance(receiver, startBalanceTo.plus(ONE_GOLDTOKEN)) - }) - - it('should not allow transferring to the null address', async () => { - await assertTransactionRevertWithReason( - goldToken.transfer(NULL_ADDRESS, ONE_GOLDTOKEN, { gasPrice: 0 }), - 'transfer attempted to reserved address 0x0' - ) - }) - - it('should not allow transferring more than the sender has', async () => { - // We try to send four more gold tokens than the sender has, in case they happen to mine the - // block with this transaction, which will reward them with 3 gold tokens. - const value = web3.utils.toBN( - (await goldToken.balanceOf(sender)).plus(ONE_GOLDTOKEN.times(4)) - ) - await assertTransactionRevertWithReason( - goldToken.transfer(receiver, value), - 'transfer value exceeded balance of sender' - ) - }) - }) - - describe('#transferFrom()', () => { - beforeEach(async () => { - await goldToken.approve(receiver, ONE_GOLDTOKEN) - }) - - it('should transfer balance from one user to another', async () => { - const startBalanceFrom = await goldToken.balanceOf(sender) - const startBalanceTo = await goldToken.balanceOf(receiver) - await goldToken.transferFrom(sender, receiver, ONE_GOLDTOKEN, { from: receiver }) - await assertBalance(sender, startBalanceFrom.minus(ONE_GOLDTOKEN)) - await assertBalance(receiver, startBalanceTo.plus(ONE_GOLDTOKEN)) - }) - - it('should not allow transferring to the null address', async () => { - await assertTransactionRevertWithReason( - goldToken.transferFrom(sender, NULL_ADDRESS, ONE_GOLDTOKEN, { from: receiver }), - 'transfer attempted to reserved address 0x0' - ) - }) - - it('should not allow transferring more than the sender has', async () => { - // We try to send four more gold tokens than the sender has, in case they happen to mine the - // block with this transaction, which will reward them with 3 gold tokens. - const value = web3.utils.toBN( - (await goldToken.balanceOf(sender)).plus(ONE_GOLDTOKEN.times(4)) - ) - await goldToken.approve(receiver, value) - await assertTransactionRevertWithReason( - goldToken.transferFrom(sender, receiver, value, { from: receiver }), - 'transfer value exceeded balance of sender' - ) - }) - - it('should not allow transferring more than the spender is allowed', async () => { - await assertTransactionRevertWithReason( - goldToken.transferFrom(sender, receiver, ONE_GOLDTOKEN.plus(1), { - from: receiver, - }), - "transfer value exceeded sender's allowance for spender" - ) - }) - }) -}) diff --git a/packages/protocol/test/identity/identityproxy.ts b/packages/protocol/test/identity/identityproxy.ts deleted file mode 100644 index 378dc74c1e9..00000000000 --- a/packages/protocol/test/identity/identityproxy.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { assertTransactionRevertWithReason } from '@celo/protocol/lib/test-utils' -import { - IdentityProxyContract, - IdentityProxyInstance, - IdentityProxyTestContract, - IdentityProxyTestInstance, -} from 'types' - -const IdentityProxy: IdentityProxyContract = artifacts.require('IdentityProxy') -const IdentityProxyTest: IdentityProxyTestContract = artifacts.require('IdentityProxyTest') - -contract('IdentityProxy', (accounts: string[]) => { - let identityProxy: IdentityProxyInstance - let identityProxyTest: IdentityProxyTestInstance - - beforeEach(async () => { - identityProxy = await IdentityProxy.new() - identityProxyTest = await IdentityProxyTest.new() - }) - - describe('makeCall', () => { - it('can be used to forward calls', async () => { - // @ts-ignore - const txData = identityProxyTest.contract.methods.setX(42).encodeABI() - await identityProxy.makeCall(identityProxyTest.address, txData) - const x = await identityProxyTest.x() - assert.equal(x.toNumber(), 42) - }) - - it('makes calls from the address of the proxy', async () => { - // @ts-ignore - const txData = identityProxyTest.contract.methods.callMe().encodeABI() - await identityProxy.makeCall(identityProxyTest.address, txData) - const address = await identityProxyTest.lastAddress() - assert.equal(address, identityProxy.address) - }) - - it('cannot be called by anyone other than the original deployer', async () => { - // @ts-ignore - const txData = identityProxyTest.contract.methods.callMe().encodeABI() - await assertTransactionRevertWithReason( - identityProxy.makeCall(identityProxyTest.address, txData, { from: accounts[1] }), - 'Only callable by original deployer' - ) - }) - }) -}) diff --git a/packages/protocol/test/identity/identityproxyhub.ts b/packages/protocol/test/identity/identityproxyhub.ts deleted file mode 100644 index a9bbccec68e..00000000000 --- a/packages/protocol/test/identity/identityproxyhub.ts +++ /dev/null @@ -1,216 +0,0 @@ -import { assertTransactionRevertWithReason } from '@celo/protocol/lib/test-utils' -import { - IdentityProxyContract, - IdentityProxyHubContract, - IdentityProxyHubInstance, - IdentityProxyTestContract, - IdentityProxyTestInstance, - MockAttestationsContract, - MockAttestationsInstance, - RegistryContract, - RegistryInstance, -} from 'types' - -const IdentityProxyHub: IdentityProxyHubContract = artifacts.require('IdentityProxyHub') -const IdentityProxy: IdentityProxyContract = artifacts.require('IdentityProxy') -const IdentityProxyTest: IdentityProxyTestContract = artifacts.require('IdentityProxyTest') -const MockAttestations: MockAttestationsContract = artifacts.require('MockAttestations') -const Registry: RegistryContract = artifacts.require('Registry') - -const concatanateHexStrings = (...strings: string[]) => { - return `0x${strings.reduce((concatanated: string, s: string) => { - return `${concatanated}${s.slice(2)}` - }, '')}` -} - -const computeCreate2Address = ( - salt: string, - deployerAddress: string, - Contract: Truffle.Contract -) => { - const hash = web3.utils.soliditySha3( - concatanateHexStrings( - '0xff', - deployerAddress, - salt, - // @ts-ignore - web3.utils.soliditySha3(Contract._json.bytecode) - ) - ) - // Skip '0x' and the first 12 bytes (so take the last 20 bytes). - return `0x${hash.slice(2 + 2 * 12)}` -} - -contract('IdentityProxyHub', (accounts: string[]) => { - let identityProxyHub: IdentityProxyHubInstance - let identityProxyTest: IdentityProxyTestInstance - let attestations: MockAttestationsInstance - let registry: RegistryInstance - const identifier: string = '0x00000000000000000000000000000000000000000000000000000000babecafe' - - beforeEach(async () => { - registry = await Registry.new(true) - await registry.initialize() - attestations = await MockAttestations.new() - await registry.setAddressFor('Attestations', attestations.address) - - identityProxyHub = await IdentityProxyHub.new() - identityProxyTest = await IdentityProxyTest.new() - await identityProxyHub.setRegistry(registry.address) - }) - - describe('getIdentityProxy', () => { - it('returns the correct CREATE2 address', async () => { - const expectedAddress = computeCreate2Address( - identifier, - identityProxyHub.address, - IdentityProxy - ) - const onchainAddress = await identityProxyHub.getIdentityProxy(identifier) - assert.equal(onchainAddress.toLowerCase(), expectedAddress.toLowerCase()) - }) - }) - - describe('getOrDeployIdentityProxy', () => { - it('returns the correct CREATE2 address', async () => { - const expectedAddress = computeCreate2Address( - identifier, - identityProxyHub.address, - IdentityProxy - ) - const onchainAddress = await identityProxyHub.getOrDeployIdentityProxy.call(identifier) - assert.equal(onchainAddress.toLowerCase(), expectedAddress.toLowerCase()) - }) - - it('returns the address of an IdentityProxy', async () => { - const address = await identityProxyHub.getOrDeployIdentityProxy.call(identifier) - await identityProxyHub.getOrDeployIdentityProxy(identifier) - const bytecode = await web3.eth.getCode(address) - // @ts-ignore _json property not declared by typechain - assert.equal(bytecode, IdentityProxy._json.deployedBytecode) - }) - }) - - describe('makeCall', () => { - let address: string - - beforeEach(async () => { - address = await identityProxyHub.getIdentityProxy(identifier) - }) - - describe('when called by a contract related to the identifier', () => { - beforeEach(async () => { - await attestations.complete(identifier, 0, '0x0', '0x0') - await attestations.complete(identifier, 0, '0x0', '0x0') - await attestations.complete(identifier, 0, '0x0', '0x0') - }) - - it('forwards calls to the destination', async () => { - // @ts-ignore - const txData = identityProxyTest.contract.methods.setX(42).encodeABI() - await identityProxyHub.makeCall(identifier, identityProxyTest.address, txData) - const x = await identityProxyTest.x() - assert.equal(x.toNumber(), 42) - }) - - it('forwards calls even when completed/requested ration is close to 50%', async () => { - await attestations.request(identifier, 0, '0x0', '0x0') - await attestations.request(identifier, 0, '0x0', '0x0') - await attestations.request(identifier, 0, '0x0', '0x0') - await attestations.request(identifier, 0, '0x0', '0x0') - await attestations.request(identifier, 0, '0x0', '0x0') - - // @ts-ignore - const txData = identityProxyTest.contract.methods.setX(42).encodeABI() - await identityProxyHub.makeCall(identifier, identityProxyTest.address, txData) - const x = await identityProxyTest.x() - assert.equal(x.toNumber(), 42) - }) - - it('forwards calls as long as no other address has more completions', async () => { - await attestations.complete(identifier, 0, '0x0', '0x0', { from: accounts[1] }) - await attestations.complete(identifier, 0, '0x0', '0x0', { from: accounts[1] }) - await attestations.complete(identifier, 0, '0x0', '0x0', { from: accounts[1] }) - - // @ts-ignore - const txData = identityProxyTest.contract.methods.setX(42).encodeABI() - await identityProxyHub.makeCall(identifier, identityProxyTest.address, txData) - const x = await identityProxyTest.x() - assert.equal(x.toNumber(), 42) - }) - - it('forwards a call through the proxy related to the identifier', async () => { - // @ts-ignore - const txData = identityProxyTest.contract.methods.callMe().encodeABI() - await identityProxyHub.makeCall(identifier, identityProxyTest.address, txData) - const addressThatCalled = await identityProxyTest.lastAddress() - assert.equal(address, addressThatCalled) - }) - - it('can send a payment', async () => { - const balanceBefore = await web3.eth.getBalance(identityProxyTest.address) - // @ts-ignore - const txData = identityProxyTest.contract.methods.payMe().encodeABI() - // @ts-ignore - await identityProxyHub.makeCall(identifier, identityProxyTest.address, txData, { - value: '100', - }) - const proxyBalance = await web3.eth.getBalance(address) - const balanceAfter = await web3.eth.getBalance(identityProxyTest.address) - assert.equal(balanceBefore, 0) - assert.equal(proxyBalance, 0) - assert.equal(balanceAfter, 100) - }) - }) - - it('fails to call if sender does not have at least 3 attestation completions', async () => { - await attestations.complete(identifier, 0, '0x0', '0x0') - await attestations.complete(identifier, 0, '0x0', '0x0') - - // @ts-ignore - const txData = identityProxyTest.contract.methods.callMe().encodeABI() - await assertTransactionRevertWithReason( - identityProxyHub.makeCall(identifier, identityProxyTest.address, txData), - 'does not pass identity heuristic' - ) - }) - - it('fails to call if sender does not have more than 50% attestation completions', async () => { - await attestations.complete(identifier, 0, '0x0', '0x0') - await attestations.complete(identifier, 0, '0x0', '0x0') - await attestations.complete(identifier, 0, '0x0', '0x0') - - await attestations.request(identifier, 0, '0x0', '0x0') - await attestations.request(identifier, 0, '0x0', '0x0') - await attestations.request(identifier, 0, '0x0', '0x0') - await attestations.request(identifier, 0, '0x0', '0x0') - await attestations.request(identifier, 0, '0x0', '0x0') - await attestations.request(identifier, 0, '0x0', '0x0') - - // @ts-ignore - const txData = identityProxyTest.contract.methods.callMe().encodeABI() - await assertTransactionRevertWithReason( - identityProxyHub.makeCall(identifier, identityProxyTest.address, txData), - 'does not pass identity heuristic' - ) - }) - - it('fails to call if another address has more attestations completed', async () => { - await attestations.complete(identifier, 0, '0x0', '0x0') - await attestations.complete(identifier, 0, '0x0', '0x0') - await attestations.complete(identifier, 0, '0x0', '0x0') - - await attestations.complete(identifier, 0, '0x0', '0x0', { from: accounts[1] }) - await attestations.complete(identifier, 0, '0x0', '0x0', { from: accounts[1] }) - await attestations.complete(identifier, 0, '0x0', '0x0', { from: accounts[1] }) - await attestations.complete(identifier, 0, '0x0', '0x0', { from: accounts[1] }) - - // @ts-ignore - const txData = identityProxyTest.contract.methods.callMe().encodeABI() - await assertTransactionRevertWithReason( - identityProxyHub.makeCall(identifier, identityProxyTest.address, txData), - 'does not pass identity heuristic' - ) - }) - }) -}) From e4fd383fab7298351ee8b36870443363b8069f5e Mon Sep 17 00:00:00 2001 From: Aaron DeRuvo Date: Fri, 1 Dec 2023 15:16:17 +0200 Subject: [PATCH 36/63] may it be so --- .github/workflows/celo-monorepo.yml | 4 +++- .github/workflows/publish-contracts-abi-release.yml | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/celo-monorepo.yml b/.github/workflows/celo-monorepo.yml index 98e43854428..2302091d75c 100644 --- a/.github/workflows/celo-monorepo.yml +++ b/.github/workflows/celo-monorepo.yml @@ -77,7 +77,9 @@ jobs: run: yarn run postinstall if: steps.cache_node.outputs.cache-hit == 'true' - name: Build packages - run: yarn build --ignore docs --include-dependencies + run: | + yarn --cwd packages/protocol run prepare_contracts_and_abis_publishing + yarn build --ignore docs --include-dependencies - name: Check licenses if: steps.cache_node.outputs.cache-hit != 'true' run: | diff --git a/.github/workflows/publish-contracts-abi-release.yml b/.github/workflows/publish-contracts-abi-release.yml index ceb49eb350a..a74f504e3ab 100644 --- a/.github/workflows/publish-contracts-abi-release.yml +++ b/.github/workflows/publish-contracts-abi-release.yml @@ -22,6 +22,8 @@ jobs: repository-projects: write steps: - uses: actions/checkout@v4 + with: + submodules: recursive - name: Akeyless Get Secrets id: get_auth_token uses: docker://us-west1-docker.pkg.dev/devopsre/akeyless-public/akeyless-action:latest @@ -54,7 +56,9 @@ jobs: env: GITHUB_TAG: ${{ github.ref_name }} INPUT_VERSION: ${{ inputs.npm_version }} - + - name: 'Build Protocol' + shell: bash + run: yarn --cwd packages/protocol build - name: Compile solidity contracts and typescript files run: yarn prepare_contracts_and_abis_publishing working-directory: packages/protocol From bf6c32bd7ff99223b6d8cd2a1e59ff4ca542c1f0 Mon Sep 17 00:00:00 2001 From: Aaron DeRuvo Date: Fri, 1 Dec 2023 16:05:35 +0200 Subject: [PATCH 37/63] must run packages protocol needs, then prepare abis, then contractkit ++ --- .github/workflows/celo-monorepo.yml | 2 ++ .github/workflows/publish-contracts-abi-release.yml | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/celo-monorepo.yml b/.github/workflows/celo-monorepo.yml index 2302091d75c..2d2c147fca9 100644 --- a/.github/workflows/celo-monorepo.yml +++ b/.github/workflows/celo-monorepo.yml @@ -77,7 +77,9 @@ jobs: run: yarn run postinstall if: steps.cache_node.outputs.cache-hit == 'true' - name: Build packages + # Just until contractkit is removed wait to build all packages the need abis to be built first run: | + yarn build --ignore @celo/contractkit --ignore @celo/explorer --ignore @celo/celocli --ignore @celo/governance --ignore @celo/metadata-crawler --ignore @celo/celotool --ignore @celo/env-tests --ignore @celo/transactions-uri --ignore @celo/wallet-rpc --include-dependencies yarn --cwd packages/protocol run prepare_contracts_and_abis_publishing yarn build --ignore docs --include-dependencies - name: Check licenses diff --git a/.github/workflows/publish-contracts-abi-release.yml b/.github/workflows/publish-contracts-abi-release.yml index a74f504e3ab..7795e9d4cc0 100644 --- a/.github/workflows/publish-contracts-abi-release.yml +++ b/.github/workflows/publish-contracts-abi-release.yml @@ -56,9 +56,9 @@ jobs: env: GITHUB_TAG: ${{ github.ref_name }} INPUT_VERSION: ${{ inputs.npm_version }} - - name: 'Build Protocol' + - name: 'Build packages which will not need abis' shell: bash - run: yarn --cwd packages/protocol build + run: yarn build --ignore @celo/contractkit --ignore @celo/explorer --ignore @celo/celocli --ignore @celo/governance --ignore @celo/metadata-crawler --ignore @celo/celotool --ignore @celo/env-tests --ignore @celo/transactions-uri --ignore @celo/wallet-rpc --include-dependencies - name: Compile solidity contracts and typescript files run: yarn prepare_contracts_and_abis_publishing working-directory: packages/protocol From a23eaa33ec3d1dcd55d4a98e6066fde20b854ab7 Mon Sep 17 00:00:00 2001 From: Aaron DeRuvo Date: Fri, 1 Dec 2023 16:29:32 +0200 Subject: [PATCH 38/63] dont need to cache these --- .github/workflows/celo-monorepo.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/celo-monorepo.yml b/.github/workflows/celo-monorepo.yml index 2d2c147fca9..1a34aaf696f 100644 --- a/.github/workflows/celo-monorepo.yml +++ b/.github/workflows/celo-monorepo.yml @@ -115,7 +115,7 @@ jobs: - name: Get the artifacts to cache id: get_artifacts_to_cache run: | - artifacts_to_cache="$(git ls-files --others --ignored --exclude-standard | grep -v node_modules)" + artifacts_to_cache="$(git ls-files --others --ignored --exclude-standard | grep -v node_modules | grep -v cjs/types/wagmi |grep -v src-generated/types/ethers | grep -v .js.map)" echo "artifacts_to_cache<> $GITHUB_OUTPUT echo "$artifacts_to_cache" >> $GITHUB_OUTPUT echo "EOF" >> $GITHUB_OUTPUT From 2359a56b4732af1aaa57c804bfcd501cd33bf059 Mon Sep 17 00:00:00 2001 From: Aaron DeRuvo Date: Fri, 1 Dec 2023 16:50:19 +0200 Subject: [PATCH 39/63] order imports, and fix esModuleInterpo issue --- packages/cli/tsconfig.json | 2 +- packages/sdk/contractkit/src/address-registry.ts | 2 +- packages/sdk/contractkit/src/contract-cache.ts | 2 +- packages/sdk/contractkit/src/mini-contract-cache.ts | 12 ++++++------ packages/sdk/contractkit/src/wrappers/Accounts.ts | 2 +- .../sdk/contractkit/src/wrappers/Attestations.ts | 2 +- packages/sdk/contractkit/src/wrappers/BaseWrapper.ts | 2 +- .../contractkit/src/wrappers/BlockchainParameters.ts | 2 +- .../sdk/contractkit/src/wrappers/CeloTokenWrapper.ts | 2 +- .../contractkit/src/wrappers/DoubleSigningSlasher.ts | 2 +- .../sdk/contractkit/src/wrappers/DowntimeSlasher.ts | 2 +- packages/sdk/contractkit/src/wrappers/Election.ts | 2 +- .../sdk/contractkit/src/wrappers/EpochRewards.ts | 2 +- .../sdk/contractkit/src/wrappers/Erc20Wrapper.ts | 2 +- packages/sdk/contractkit/src/wrappers/Escrow.ts | 2 +- packages/sdk/contractkit/src/wrappers/Exchange.ts | 2 +- .../src/wrappers/FederatedAttestations.ts | 2 +- packages/sdk/contractkit/src/wrappers/FeeHandler.ts | 2 +- .../sdk/contractkit/src/wrappers/GasPriceMinimum.ts | 2 +- .../sdk/contractkit/src/wrappers/GoldTokenWrapper.ts | 2 +- packages/sdk/contractkit/src/wrappers/Governance.ts | 2 +- packages/sdk/contractkit/src/wrappers/GrandaMento.ts | 4 ++-- packages/sdk/contractkit/src/wrappers/LockedGold.ts | 2 +- .../src/wrappers/MetaTransactionWallet.ts | 2 +- packages/sdk/contractkit/src/wrappers/MultiSig.ts | 2 +- .../sdk/contractkit/src/wrappers/OdisPayments.ts | 2 +- packages/sdk/contractkit/src/wrappers/ReleaseGold.ts | 2 +- packages/sdk/contractkit/src/wrappers/Reserve.ts | 2 +- .../sdk/contractkit/src/wrappers/SortedOracles.ts | 2 +- packages/sdk/contractkit/src/wrappers/Validators.ts | 2 +- 30 files changed, 36 insertions(+), 36 deletions(-) diff --git a/packages/cli/tsconfig.json b/packages/cli/tsconfig.json index a70ac88f42d..f1339041c5d 100644 --- a/packages/cli/tsconfig.json +++ b/packages/cli/tsconfig.json @@ -4,7 +4,7 @@ "moduleResolution": "node16", "rootDir": "src", "outDir": "lib", - "esModuleInterop": false, + "esModuleInterop": true, "target": "es2020" }, "include": ["src", "../contractkit/types"], diff --git a/packages/sdk/contractkit/src/address-registry.ts b/packages/sdk/contractkit/src/address-registry.ts index 3926399ec1d..1ec6ee92967 100644 --- a/packages/sdk/contractkit/src/address-registry.ts +++ b/packages/sdk/contractkit/src/address-registry.ts @@ -1,8 +1,8 @@ +import { newRegistry, Registry } from '@celo/abis/types/web3/Registry' import { Address, NULL_ADDRESS } from '@celo/base/lib/address' import { Connection } from '@celo/connect' import debugFactory from 'debug' import { CeloContract, RegisteredContracts, stripProxy } from './base' -import { newRegistry, Registry } from '@celo/abis/types/web3/Registry' const debug = debugFactory('kit:registry') diff --git a/packages/sdk/contractkit/src/contract-cache.ts b/packages/sdk/contractkit/src/contract-cache.ts index ce85c934a9d..be1379bd62f 100644 --- a/packages/sdk/contractkit/src/contract-cache.ts +++ b/packages/sdk/contractkit/src/contract-cache.ts @@ -1,9 +1,9 @@ +import { IERC20 } from '@celo/abis/types/web3/IERC20' import { Connection } from '@celo/connect' import { AddressRegistry } from './address-registry' import { CeloContract } from './base' import { ContractCacheType } from './basic-contract-cache-type' import { StableToken, stableTokenInfos } from './celo-tokens' -import { IERC20 } from '@celo/abis/types/web3/IERC20' import { Web3ContractCache } from './web3-contract-cache' import { AccountsWrapper } from './wrappers/Accounts' import { AttestationsWrapper } from './wrappers/Attestations' diff --git a/packages/sdk/contractkit/src/mini-contract-cache.ts b/packages/sdk/contractkit/src/mini-contract-cache.ts index 803b8281d82..4ded4693d4f 100644 --- a/packages/sdk/contractkit/src/mini-contract-cache.ts +++ b/packages/sdk/contractkit/src/mini-contract-cache.ts @@ -1,9 +1,3 @@ -import { StableToken } from '@celo/base' -import { Connection } from '@celo/connect' -import { AddressRegistry } from './address-registry' -import { CeloContract } from './base' -import { ContractCacheType } from './basic-contract-cache-type' -import { stableTokenInfos } from './celo-tokens' import { newGasPriceMinimum } from '@celo/abis/types/web3/0.8/GasPriceMinimum' import { newAccounts } from '@celo/abis/types/web3/Accounts' import { newGoldToken } from '@celo/abis/types/web3/GoldToken' @@ -13,6 +7,12 @@ import { newExchangeEUR } from '@celo/abis/types/web3/mento/ExchangeEUR' import { newStableToken } from '@celo/abis/types/web3/mento/StableToken' import { newStableTokenBRL } from '@celo/abis/types/web3/mento/StableTokenBRL' import { newStableTokenEUR } from '@celo/abis/types/web3/mento/StableTokenEUR' +import { StableToken } from '@celo/base' +import { Connection } from '@celo/connect' +import { AddressRegistry } from './address-registry' +import { CeloContract } from './base' +import { ContractCacheType } from './basic-contract-cache-type' +import { stableTokenInfos } from './celo-tokens' import { AccountsWrapper } from './wrappers/Accounts' import { ExchangeWrapper } from './wrappers/Exchange' import { GasPriceMinimumWrapper } from './wrappers/GasPriceMinimum' diff --git a/packages/sdk/contractkit/src/wrappers/Accounts.ts b/packages/sdk/contractkit/src/wrappers/Accounts.ts index c98656b1cc7..20dbefd75a7 100644 --- a/packages/sdk/contractkit/src/wrappers/Accounts.ts +++ b/packages/sdk/contractkit/src/wrappers/Accounts.ts @@ -1,3 +1,4 @@ +import { Accounts } from '@celo/abis/types/web3/Accounts' import { NativeSigner, Signature, Signer } from '@celo/base/lib/signatureUtils' import { Address, CeloTransactionObject, toTransactionObject } from '@celo/connect' import { @@ -9,7 +10,6 @@ import { import { soliditySha3 } from '@celo/utils/lib/solidity' import { authorizeSigner as buildAuthorizeSignerTypedData } from '@celo/utils/lib/typed-data-constructors' import type BN from 'bn.js' // just the types -import { Accounts } from '@celo/abis/types/web3/Accounts' import { getParsedSignatureOfAddress } from '../utils/getParsedSignatureOfAddress' import { newContractVersion } from '../versions' import { diff --git a/packages/sdk/contractkit/src/wrappers/Attestations.ts b/packages/sdk/contractkit/src/wrappers/Attestations.ts index 33b75b694f2..67d45a8be9b 100644 --- a/packages/sdk/contractkit/src/wrappers/Attestations.ts +++ b/packages/sdk/contractkit/src/wrappers/Attestations.ts @@ -1,8 +1,8 @@ +import { Attestations } from '@celo/abis/types/web3/Attestations' import { StableToken } from '@celo/base' import { eqAddress } from '@celo/base/lib/address' import { Address, Connection, toTransactionObject } from '@celo/connect' import BigNumber from 'bignumber.js' -import { Attestations } from '@celo/abis/types/web3/Attestations' import { AccountsWrapper } from './Accounts' import { BaseWrapper, diff --git a/packages/sdk/contractkit/src/wrappers/BaseWrapper.ts b/packages/sdk/contractkit/src/wrappers/BaseWrapper.ts index e3d428c6ada..b65871b9f07 100644 --- a/packages/sdk/contractkit/src/wrappers/BaseWrapper.ts +++ b/packages/sdk/contractkit/src/wrappers/BaseWrapper.ts @@ -1,3 +1,4 @@ +import { ICeloVersionedContract } from '@celo/abis/types/web3/ICeloVersionedContract' import { bufferToHex, ensureLeading0x } from '@celo/base/lib/address' import { zip } from '@celo/base/lib/collections' import { @@ -11,7 +12,6 @@ import { } from '@celo/connect' import { fromFixed, toFixed } from '@celo/utils/lib/fixidity' import BigNumber from 'bignumber.js' -import { ICeloVersionedContract } from '@celo/abis/types/web3/ICeloVersionedContract' import { ContractVersion } from '../versions' /** Represents web3 native contract Method */ diff --git a/packages/sdk/contractkit/src/wrappers/BlockchainParameters.ts b/packages/sdk/contractkit/src/wrappers/BlockchainParameters.ts index 983c48e637e..29869d44031 100644 --- a/packages/sdk/contractkit/src/wrappers/BlockchainParameters.ts +++ b/packages/sdk/contractkit/src/wrappers/BlockchainParameters.ts @@ -1,5 +1,5 @@ -import { BigNumber } from 'bignumber.js' import { BlockchainParameters } from '@celo/abis/types/web3/BlockchainParameters' +import { BigNumber } from 'bignumber.js' import { BaseWrapper, proxyCall, proxySend, valueToBigNumber, valueToInt } from './BaseWrapper' export interface BlockchainParametersConfig { diff --git a/packages/sdk/contractkit/src/wrappers/CeloTokenWrapper.ts b/packages/sdk/contractkit/src/wrappers/CeloTokenWrapper.ts index 8b801fe38f4..908b1bdf838 100644 --- a/packages/sdk/contractkit/src/wrappers/CeloTokenWrapper.ts +++ b/packages/sdk/contractkit/src/wrappers/CeloTokenWrapper.ts @@ -1,9 +1,9 @@ // NOTE: removing this import results in `yarn build` failures in Dockerfiles // after the move to node 10. This allows types to be inferred without // referencing '@celo/utils/node_modules/bignumber.js' -import 'bignumber.js' import { ICeloToken } from '@celo/abis/types/web3/ICeloToken' import { IERC20 } from '@celo/abis/types/web3/IERC20' +import 'bignumber.js' import { proxyCall, proxySend, valueToInt } from './BaseWrapper' import { Erc20Wrapper } from './Erc20Wrapper' diff --git a/packages/sdk/contractkit/src/wrappers/DoubleSigningSlasher.ts b/packages/sdk/contractkit/src/wrappers/DoubleSigningSlasher.ts index 99c5ccff11c..40cb2596646 100644 --- a/packages/sdk/contractkit/src/wrappers/DoubleSigningSlasher.ts +++ b/packages/sdk/contractkit/src/wrappers/DoubleSigningSlasher.ts @@ -1,5 +1,5 @@ -import { Address } from '@celo/connect' import { DoubleSigningSlasher } from '@celo/abis/types/web3/DoubleSigningSlasher' +import { Address } from '@celo/connect' import { BaseSlasher } from './BaseSlasher' import { valueToInt } from './BaseWrapper' diff --git a/packages/sdk/contractkit/src/wrappers/DowntimeSlasher.ts b/packages/sdk/contractkit/src/wrappers/DowntimeSlasher.ts index 99b7b912a02..0efca96857e 100644 --- a/packages/sdk/contractkit/src/wrappers/DowntimeSlasher.ts +++ b/packages/sdk/contractkit/src/wrappers/DowntimeSlasher.ts @@ -1,6 +1,6 @@ +import { DowntimeSlasher } from '@celo/abis/types/web3/DowntimeSlasher' import { Address } from '@celo/connect' import BigNumber from 'bignumber.js' -import { DowntimeSlasher } from '@celo/abis/types/web3/DowntimeSlasher' import { BaseSlasher } from './BaseSlasher' import { blocksToDurationString, diff --git a/packages/sdk/contractkit/src/wrappers/Election.ts b/packages/sdk/contractkit/src/wrappers/Election.ts index 7daadef1129..e8b07206c5c 100644 --- a/packages/sdk/contractkit/src/wrappers/Election.ts +++ b/packages/sdk/contractkit/src/wrappers/Election.ts @@ -1,3 +1,4 @@ +import { Election } from '@celo/abis/types/web3/Election' import { eqAddress, findAddressIndex, @@ -8,7 +9,6 @@ import { concurrentMap, concurrentValuesMap } from '@celo/base/lib/async' import { zeroRange, zip } from '@celo/base/lib/collections' import { Address, CeloTransactionObject, EventLog, toTransactionObject } from '@celo/connect' import BigNumber from 'bignumber.js' -import { Election } from '@celo/abis/types/web3/Election' import { fixidityValueToBigNumber, identity, diff --git a/packages/sdk/contractkit/src/wrappers/EpochRewards.ts b/packages/sdk/contractkit/src/wrappers/EpochRewards.ts index bd069b010d9..6fc1a1179dd 100644 --- a/packages/sdk/contractkit/src/wrappers/EpochRewards.ts +++ b/packages/sdk/contractkit/src/wrappers/EpochRewards.ts @@ -1,5 +1,5 @@ -import { fromFixed } from '@celo/utils/lib/fixidity' import { EpochRewards } from '@celo/abis/types/web3/EpochRewards' +import { fromFixed } from '@celo/utils/lib/fixidity' import { BaseWrapper, proxyCall, valueToBigNumber } from './BaseWrapper' const parseFixidity = (v: string) => fromFixed(valueToBigNumber(v)) diff --git a/packages/sdk/contractkit/src/wrappers/Erc20Wrapper.ts b/packages/sdk/contractkit/src/wrappers/Erc20Wrapper.ts index 6413e1f12b4..5b28b8b143d 100644 --- a/packages/sdk/contractkit/src/wrappers/Erc20Wrapper.ts +++ b/packages/sdk/contractkit/src/wrappers/Erc20Wrapper.ts @@ -1,8 +1,8 @@ // NOTE: removing this import results in `yarn build` failures in Dockerfiles // after the move to node 10. This allows types to be inferred without // referencing '@celo/utils/node_modules/bignumber.js' -import BigNumber from 'bignumber.js' import { IERC20 } from '@celo/abis/types/web3/IERC20' +import BigNumber from 'bignumber.js' import { BaseWrapper, proxyCall, proxySend, valueToBigNumber } from './BaseWrapper' /** diff --git a/packages/sdk/contractkit/src/wrappers/Escrow.ts b/packages/sdk/contractkit/src/wrappers/Escrow.ts index efd17b260ba..f2ef70a62b2 100644 --- a/packages/sdk/contractkit/src/wrappers/Escrow.ts +++ b/packages/sdk/contractkit/src/wrappers/Escrow.ts @@ -1,5 +1,5 @@ -import { Address, CeloTransactionObject } from '@celo/connect' import { Escrow } from '@celo/abis/types/web3/Escrow' +import { Address, CeloTransactionObject } from '@celo/connect' import { BaseWrapper, proxyCall, proxySend } from './BaseWrapper' /** diff --git a/packages/sdk/contractkit/src/wrappers/Exchange.ts b/packages/sdk/contractkit/src/wrappers/Exchange.ts index f788ca06947..5661cde2c62 100644 --- a/packages/sdk/contractkit/src/wrappers/Exchange.ts +++ b/packages/sdk/contractkit/src/wrappers/Exchange.ts @@ -1,6 +1,6 @@ +import { Exchange } from '@celo/abis/types/web3/mento/Exchange' import { CeloTransactionObject } from '@celo/connect' import BigNumber from 'bignumber.js' -import { Exchange } from '@celo/abis/types/web3/mento/Exchange' import { BaseWrapper, fixidityValueToBigNumber, diff --git a/packages/sdk/contractkit/src/wrappers/FederatedAttestations.ts b/packages/sdk/contractkit/src/wrappers/FederatedAttestations.ts index 02ee2fec708..a8e5f660c6a 100644 --- a/packages/sdk/contractkit/src/wrappers/FederatedAttestations.ts +++ b/packages/sdk/contractkit/src/wrappers/FederatedAttestations.ts @@ -1,6 +1,6 @@ +import { FederatedAttestations } from '@celo/abis/types/web3/FederatedAttestations' import { Address, CeloTransactionObject, toTransactionObject } from '@celo/connect' import { registerAttestation as buildRegisterAttestationTypedData } from '@celo/utils/lib/typed-data-constructors' -import { FederatedAttestations } from '@celo/abis/types/web3/FederatedAttestations' import { BaseWrapper, proxyCall, proxySend } from './BaseWrapper' export class FederatedAttestationsWrapper extends BaseWrapper { diff --git a/packages/sdk/contractkit/src/wrappers/FeeHandler.ts b/packages/sdk/contractkit/src/wrappers/FeeHandler.ts index d4ae61a9dc1..1990e3ce60a 100644 --- a/packages/sdk/contractkit/src/wrappers/FeeHandler.ts +++ b/packages/sdk/contractkit/src/wrappers/FeeHandler.ts @@ -1,7 +1,7 @@ +import { FeeHandler } from '@celo/abis/types/web3/FeeHandler' import { Address } from '@celo/connect' import BigNumber from 'bignumber.js' import { StableTokenContract } from '../base' -import { FeeHandler } from '@celo/abis/types/web3/FeeHandler' import { BaseWrapper, proxyCall, proxySend } from './BaseWrapper' export enum ExchangeProposalState { diff --git a/packages/sdk/contractkit/src/wrappers/GasPriceMinimum.ts b/packages/sdk/contractkit/src/wrappers/GasPriceMinimum.ts index 747f728e0cf..c425943c73d 100644 --- a/packages/sdk/contractkit/src/wrappers/GasPriceMinimum.ts +++ b/packages/sdk/contractkit/src/wrappers/GasPriceMinimum.ts @@ -1,5 +1,5 @@ -import BigNumber from 'bignumber.js' import { GasPriceMinimum } from '@celo/abis/types/web3/0.8/GasPriceMinimum' +import BigNumber from 'bignumber.js' import { BaseWrapper, fixidityValueToBigNumber, proxyCall, valueToBigNumber } from './BaseWrapper' export interface GasPriceMinimumConfig { diff --git a/packages/sdk/contractkit/src/wrappers/GoldTokenWrapper.ts b/packages/sdk/contractkit/src/wrappers/GoldTokenWrapper.ts index ae9bcfe6652..df3dc1f573a 100644 --- a/packages/sdk/contractkit/src/wrappers/GoldTokenWrapper.ts +++ b/packages/sdk/contractkit/src/wrappers/GoldTokenWrapper.ts @@ -1,9 +1,9 @@ // NOTE: removing this import results in `yarn build` failures in Dockerfiles // after the move to node 10. This allows types to be inferred without // referencing '@celo/utils/node_modules/bignumber.js' +import { GoldToken } from '@celo/abis/types/web3/GoldToken' import { Address } from '@celo/base' import 'bignumber.js' -import { GoldToken } from '@celo/abis/types/web3/GoldToken' import { proxySend, stringIdentity, diff --git a/packages/sdk/contractkit/src/wrappers/Governance.ts b/packages/sdk/contractkit/src/wrappers/Governance.ts index 33a6892a095..80a60f0bd4b 100644 --- a/packages/sdk/contractkit/src/wrappers/Governance.ts +++ b/packages/sdk/contractkit/src/wrappers/Governance.ts @@ -1,3 +1,4 @@ +import { Governance } from '@celo/abis/types/web3/Governance' import { bufferToHex, ensureLeading0x, @@ -10,7 +11,6 @@ import { zeroRange, zip } from '@celo/base/lib/collections' import { Address, CeloTxPending, toTransactionObject } from '@celo/connect' import { fromFixed } from '@celo/utils/lib/fixidity' import BigNumber from 'bignumber.js' -import { Governance } from '@celo/abis/types/web3/Governance' import { bufferToSolidityBytes, identity, diff --git a/packages/sdk/contractkit/src/wrappers/GrandaMento.ts b/packages/sdk/contractkit/src/wrappers/GrandaMento.ts index aeb91cf5fe5..18792c773e8 100644 --- a/packages/sdk/contractkit/src/wrappers/GrandaMento.ts +++ b/packages/sdk/contractkit/src/wrappers/GrandaMento.ts @@ -1,8 +1,8 @@ +import { GrandaMento } from '@celo/abis/types/web3/mento/GrandaMento' +import { newStableToken } from '@celo/abis/types/web3/mento/StableToken' import BigNumber from 'bignumber.js' import { StableTokenContract } from '../base' import { StableToken as StableTokenEnum, stableTokenInfos } from '../celo-tokens' -import { GrandaMento } from '@celo/abis/types/web3/mento/GrandaMento' -import { newStableToken } from '@celo/abis/types/web3/mento/StableToken' import { BaseWrapper, fixidityValueToBigNumber, diff --git a/packages/sdk/contractkit/src/wrappers/LockedGold.ts b/packages/sdk/contractkit/src/wrappers/LockedGold.ts index bb00c3d6653..3f140f8f127 100644 --- a/packages/sdk/contractkit/src/wrappers/LockedGold.ts +++ b/packages/sdk/contractkit/src/wrappers/LockedGold.ts @@ -1,3 +1,4 @@ +import { LockedGold } from '@celo/abis/types/web3/LockedGold' import { AddressListItem as ALI, Comparator, @@ -6,7 +7,6 @@ import { } from '@celo/base/lib/collections' import { Address, CeloTransactionObject, EventLog } from '@celo/connect' import BigNumber from 'bignumber.js' -import { LockedGold } from '@celo/abis/types/web3/LockedGold' import { ContractVersion } from '../versions' import { proxyCall, diff --git a/packages/sdk/contractkit/src/wrappers/MetaTransactionWallet.ts b/packages/sdk/contractkit/src/wrappers/MetaTransactionWallet.ts index 65f8340b33b..eb561a95f70 100644 --- a/packages/sdk/contractkit/src/wrappers/MetaTransactionWallet.ts +++ b/packages/sdk/contractkit/src/wrappers/MetaTransactionWallet.ts @@ -1,9 +1,9 @@ +import { MetaTransactionWallet } from '@celo/abis/types/web3/MetaTransactionWallet' import { Address, ensureLeading0x, trimLeading0x } from '@celo/base/lib/address' import { Signature } from '@celo/base/lib/signatureUtils' import { CeloTransactionObject, CeloTxObject, toTransactionObject } from '@celo/connect' import { EIP712TypedData } from '@celo/utils/lib/sign-typed-data-utils' import BigNumber from 'bignumber.js' -import { MetaTransactionWallet } from '@celo/abis/types/web3/MetaTransactionWallet' import { BaseWrapper, proxyCall, diff --git a/packages/sdk/contractkit/src/wrappers/MultiSig.ts b/packages/sdk/contractkit/src/wrappers/MultiSig.ts index 5fa0355f9a9..f570f9b0572 100644 --- a/packages/sdk/contractkit/src/wrappers/MultiSig.ts +++ b/packages/sdk/contractkit/src/wrappers/MultiSig.ts @@ -1,6 +1,6 @@ +import { MultiSig } from '@celo/abis/types/web3/MultiSig' import { Address, CeloTransactionObject, CeloTxObject, toTransactionObject } from '@celo/connect' import BigNumber from 'bignumber.js' -import { MultiSig } from '@celo/abis/types/web3/MultiSig' import { BaseWrapper, proxyCall, diff --git a/packages/sdk/contractkit/src/wrappers/OdisPayments.ts b/packages/sdk/contractkit/src/wrappers/OdisPayments.ts index 20dbe93f04d..66cdca972e5 100644 --- a/packages/sdk/contractkit/src/wrappers/OdisPayments.ts +++ b/packages/sdk/contractkit/src/wrappers/OdisPayments.ts @@ -1,6 +1,6 @@ +import { OdisPayments } from '@celo/abis/types/web3/OdisPayments' import { Address, CeloTransactionObject } from '@celo/connect' import { BigNumber } from 'bignumber.js' -import { OdisPayments } from '@celo/abis/types/web3/OdisPayments' import { BaseWrapper, proxyCall, proxySend, valueToBigNumber } from './BaseWrapper' export class OdisPaymentsWrapper extends BaseWrapper { diff --git a/packages/sdk/contractkit/src/wrappers/ReleaseGold.ts b/packages/sdk/contractkit/src/wrappers/ReleaseGold.ts index 181677d7e91..5479d0f530f 100644 --- a/packages/sdk/contractkit/src/wrappers/ReleaseGold.ts +++ b/packages/sdk/contractkit/src/wrappers/ReleaseGold.ts @@ -1,3 +1,4 @@ +import { ReleaseGold } from '@celo/abis/types/web3/ReleaseGold' import { concurrentMap } from '@celo/base' import { findAddressIndex } from '@celo/base/lib/address' import { Signature } from '@celo/base/lib/signatureUtils' @@ -5,7 +6,6 @@ import { Address, CeloTransactionObject, toTransactionObject } from '@celo/conne import { hashMessageWithPrefix, signedMessageToPublicKey } from '@celo/utils/lib/signatureUtils' import BigNumber from 'bignumber.js' import { flatten } from 'fp-ts/lib/Array' -import { ReleaseGold } from '@celo/abis/types/web3/ReleaseGold' import { proxyCall, proxySend, diff --git a/packages/sdk/contractkit/src/wrappers/Reserve.ts b/packages/sdk/contractkit/src/wrappers/Reserve.ts index 1c894719e6c..394ed9fdc9e 100644 --- a/packages/sdk/contractkit/src/wrappers/Reserve.ts +++ b/packages/sdk/contractkit/src/wrappers/Reserve.ts @@ -1,6 +1,6 @@ +import { Reserve } from '@celo/abis/types/web3/mento/Reserve' import { Address, EventLog } from '@celo/connect' import BigNumber from 'bignumber.js' -import { Reserve } from '@celo/abis/types/web3/mento/Reserve' import { BaseWrapper, fixidityValueToBigNumber, diff --git a/packages/sdk/contractkit/src/wrappers/SortedOracles.ts b/packages/sdk/contractkit/src/wrappers/SortedOracles.ts index 5a447654d92..8414a7e0d3e 100644 --- a/packages/sdk/contractkit/src/wrappers/SortedOracles.ts +++ b/packages/sdk/contractkit/src/wrappers/SortedOracles.ts @@ -1,3 +1,4 @@ +import { SortedOracles } from '@celo/abis/types/web3/SortedOracles' import { eqAddress, NULL_ADDRESS } from '@celo/base/lib/address' import { Address, CeloTransactionObject, Connection, toTransactionObject } from '@celo/connect' import { isValidAddress } from '@celo/utils/lib/address' @@ -6,7 +7,6 @@ import BigNumber from 'bignumber.js' import { AddressRegistry } from '../address-registry' import { CeloContract, StableTokenContract } from '../base' import { isStableTokenContract, StableToken, stableTokenInfos } from '../celo-tokens' -import { SortedOracles } from '@celo/abis/types/web3/SortedOracles' import { BaseWrapper, proxyCall, diff --git a/packages/sdk/contractkit/src/wrappers/Validators.ts b/packages/sdk/contractkit/src/wrappers/Validators.ts index cbba7e560b5..4f00ac8b14c 100644 --- a/packages/sdk/contractkit/src/wrappers/Validators.ts +++ b/packages/sdk/contractkit/src/wrappers/Validators.ts @@ -1,10 +1,10 @@ +import { Validators } from '@celo/abis/types/web3/Validators' import { eqAddress, findAddressIndex, NULL_ADDRESS } from '@celo/base/lib/address' import { concurrentMap } from '@celo/base/lib/async' import { zeroRange, zip } from '@celo/base/lib/collections' import { Address, CeloTransactionObject, EventLog, toTransactionObject } from '@celo/connect' import { fromFixed, toFixed } from '@celo/utils/lib/fixidity' import BigNumber from 'bignumber.js' -import { Validators } from '@celo/abis/types/web3/Validators' import { blocksToDurationString, proxyCall, From f48a93326d58638f5f457d7ba4e80a5d33ab7bf7 Mon Sep 17 00:00:00 2001 From: Leszek Stachowski Date: Fri, 1 Dec 2023 16:04:29 +0100 Subject: [PATCH 40/63] fix linting errors --- .../prepare-contracts-and-abis-publishing.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts b/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts index cd87b71818f..338dbc3b28d 100644 --- a/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts +++ b/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts @@ -105,19 +105,16 @@ function prepareTargetTypesExports() { // ) const filePaths = lsRecursive(path.join(ABIS_DIST_DIR, target)) - console.log(filePaths) filePaths.forEach((filePath) => { const parsedPath = path.parse(filePath) // Remove the .d from the name -- only for types types no harm otherwise const parsedPathName = parsedPath.name.replace('.d', '') - console.log('path name', parsedPathName) if (PublishContracts.includes(parsedPathName)) { const relativePath = path.join( path.relative(ABIS_PACKAGE_SRC_DIR, parsedPath.dir), parsedPathName ) - console.log(relativePath) const exportKey = `./${path.join( path.relative(path.join(ABIS_DIST_DIR, target), parsedPath.dir), parsedPathName @@ -127,7 +124,7 @@ function prepareTargetTypesExports() { exports[exportKey] = {} } - if (target == 'esm') { + if (target === 'esm') { const importPath = `./${relativePath}.js` expectFileExists(importPath) @@ -136,7 +133,7 @@ function prepareTargetTypesExports() { ...exports[exportKey], import: importPath, } - } else if (target == 'cjs') { + } else if (target === 'cjs') { const requirePath = `./${relativePath}.js` expectFileExists(requirePath) @@ -146,9 +143,9 @@ function prepareTargetTypesExports() { require: requirePath, } } else { - //types + // types const typesPath = `./${relativePath}.d.ts` - console.log('types', typesPath) + expectFileExists(typesPath) exports[exportKey] = { @@ -212,7 +209,7 @@ function processRawJsonsAndPrepareExports() { function prepareAbisPackageJson(exports) { log('Preparing @celo/abis package.json') const packageJsonPath = path.join(ABIS_PACKAGE_SRC_DIR, 'package.json') - let json = JSON.parse(fs.readFileSync(packageJsonPath).toString()) + const json = JSON.parse(fs.readFileSync(packageJsonPath).toString()) if (process.env.RELEASE_VERSION) { log('Replacing @celo/abis version with provided RELEASE_VERSION') From 26f8fab59f87ed6304626a1027c77345283d907b Mon Sep 17 00:00:00 2001 From: Aaron DeRuvo Date: Fri, 1 Dec 2023 17:14:58 +0200 Subject: [PATCH 41/63] fix failure made noticable by test --- packages/sdk/contractkit/src/wrappers/SortedOracles.test.ts | 2 +- packages/sdk/contractkit/src/wrappers/SortedOracles.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/sdk/contractkit/src/wrappers/SortedOracles.test.ts b/packages/sdk/contractkit/src/wrappers/SortedOracles.test.ts index 2befdbb9f9a..4e4ce689d76 100644 --- a/packages/sdk/contractkit/src/wrappers/SortedOracles.test.ts +++ b/packages/sdk/contractkit/src/wrappers/SortedOracles.test.ts @@ -1,7 +1,7 @@ +import SortedOraclesArtifacts from '@celo/celo-devchain/contracts/contracts-0.5/SortedOracles.json' import { Address } from '@celo/connect' import { describeEach } from '@celo/dev-utils/lib/describeEach' import { NetworkConfig, testWithGanache, timeTravel } from '@celo/dev-utils/lib/ganache-test' -import SortedOraclesArtifacts from '@celo/celo-devchain/contracts/contracts-0.5/SortedOracles.json' import { CeloContract } from '../base' import { StableToken } from '../celo-tokens' import { newKitFromWeb3 } from '../kit' diff --git a/packages/sdk/contractkit/src/wrappers/SortedOracles.ts b/packages/sdk/contractkit/src/wrappers/SortedOracles.ts index 8414a7e0d3e..1b48c194538 100644 --- a/packages/sdk/contractkit/src/wrappers/SortedOracles.ts +++ b/packages/sdk/contractkit/src/wrappers/SortedOracles.ts @@ -136,7 +136,8 @@ export class SortedOraclesWrapper extends BaseWrapper { async isOldestReportExpired(target: ReportTarget): Promise<[boolean, Address]> { const identifier = await this.toCurrencyPairIdentifier(target) const response = await this.contract.methods.isOldestReportExpired(identifier).call() - return response as [boolean, Address] + // response is NOT an array, but a js object with two keys 0 and 1 + return [response[0], response[1]] } /** From cf5334609294082ad260acc8efb47afc186a8f81 Mon Sep 17 00:00:00 2001 From: Aaron DeRuvo Date: Fri, 1 Dec 2023 17:33:06 +0200 Subject: [PATCH 42/63] lint cli --- packages/cli/src/commands/network/contracts.ts | 4 ++-- packages/cli/src/commands/releasegold/admin-revoke.test.ts | 2 +- .../cli/src/commands/releasegold/refund-and-finalize.test.ts | 2 +- packages/cli/src/commands/releasegold/set-beneficiary.test.ts | 2 +- packages/cli/src/commands/releasegold/withdraw.test.ts | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/cli/src/commands/network/contracts.ts b/packages/cli/src/commands/network/contracts.ts index b1fe27d9fe6..48abff95e38 100644 --- a/packages/cli/src/commands/network/contracts.ts +++ b/packages/cli/src/commands/network/contracts.ts @@ -1,7 +1,7 @@ -import { concurrentMap } from '@celo/base' -import { CeloContract } from '@celo/contractkit' import { newICeloVersionedContract } from '@celo/abis/types/web3/ICeloVersionedContract' import { newProxy } from '@celo/abis/types/web3/Proxy' +import { concurrentMap } from '@celo/base' +import { CeloContract } from '@celo/contractkit' import { cli } from 'cli-ux' import { table } from 'cli-ux/lib/styled/table' import { BaseCommand } from '../../base' diff --git a/packages/cli/src/commands/releasegold/admin-revoke.test.ts b/packages/cli/src/commands/releasegold/admin-revoke.test.ts index 6bf86924748..da2e21abb33 100644 --- a/packages/cli/src/commands/releasegold/admin-revoke.test.ts +++ b/packages/cli/src/commands/releasegold/admin-revoke.test.ts @@ -1,6 +1,6 @@ +import { newReleaseGold } from '@celo/abis/types/web3/ReleaseGold' import { serializeSignature } from '@celo/base/lib/signatureUtils' import { ContractKit, newKitFromWeb3 } from '@celo/contractkit' -import { newReleaseGold } from '@celo/abis/types/web3/ReleaseGold' import { AccountsWrapper } from '@celo/contractkit/lib/wrappers/Accounts' import { GovernanceWrapper } from '@celo/contractkit/lib/wrappers/Governance' import { ReleaseGoldWrapper } from '@celo/contractkit/lib/wrappers/ReleaseGold' diff --git a/packages/cli/src/commands/releasegold/refund-and-finalize.test.ts b/packages/cli/src/commands/releasegold/refund-and-finalize.test.ts index 9b697127b09..bb91136dcf4 100644 --- a/packages/cli/src/commands/releasegold/refund-and-finalize.test.ts +++ b/packages/cli/src/commands/releasegold/refund-and-finalize.test.ts @@ -1,5 +1,5 @@ -import { ContractKit, newKitFromWeb3 } from '@celo/contractkit' import { newReleaseGold } from '@celo/abis/types/web3/ReleaseGold' +import { ContractKit, newKitFromWeb3 } from '@celo/contractkit' import { ReleaseGoldWrapper } from '@celo/contractkit/lib/wrappers/ReleaseGold' import { getContractFromEvent, testWithGanache } from '@celo/dev-utils/lib/ganache-test' import Web3 from 'web3' diff --git a/packages/cli/src/commands/releasegold/set-beneficiary.test.ts b/packages/cli/src/commands/releasegold/set-beneficiary.test.ts index 75169bf7a17..ce83c112d12 100644 --- a/packages/cli/src/commands/releasegold/set-beneficiary.test.ts +++ b/packages/cli/src/commands/releasegold/set-beneficiary.test.ts @@ -1,5 +1,5 @@ -import { newKitFromWeb3 } from '@celo/contractkit' import { newReleaseGold } from '@celo/abis/types/web3/ReleaseGold' +import { newKitFromWeb3 } from '@celo/contractkit' import { ReleaseGoldWrapper } from '@celo/contractkit/lib/wrappers/ReleaseGold' import { getContractFromEvent, testWithGanache } from '@celo/dev-utils/lib/ganache-test' import Web3 from 'web3' diff --git a/packages/cli/src/commands/releasegold/withdraw.test.ts b/packages/cli/src/commands/releasegold/withdraw.test.ts index 99ccea9721d..faae7bed97b 100644 --- a/packages/cli/src/commands/releasegold/withdraw.test.ts +++ b/packages/cli/src/commands/releasegold/withdraw.test.ts @@ -1,5 +1,5 @@ -import { ContractKit, newKitFromWeb3 } from '@celo/contractkit' import { newReleaseGold } from '@celo/abis/types/web3/ReleaseGold' +import { ContractKit, newKitFromWeb3 } from '@celo/contractkit' import { ReleaseGoldWrapper } from '@celo/contractkit/lib/wrappers/ReleaseGold' import { getContractFromEvent, testWithGanache, timeTravel } from '@celo/dev-utils/lib/ganache-test' import { BigNumber } from 'bignumber.js' From df708f806aca439b11c8464ebf2f8b8dd5023b91 Mon Sep 17 00:00:00 2001 From: soloseng <102702451+soloseng@users.noreply.github.com> Date: Fri, 1 Dec 2023 11:21:49 -0500 Subject: [PATCH 43/63] Adding MultiSig Foundry Test (#10675) --- .../protocol/test-sol/common/Multisig.t.sol | 426 ++++++++++++++++ packages/protocol/test/common/multisig.ts | 457 ------------------ 2 files changed, 426 insertions(+), 457 deletions(-) create mode 100644 packages/protocol/test-sol/common/Multisig.t.sol delete mode 100644 packages/protocol/test/common/multisig.ts diff --git a/packages/protocol/test-sol/common/Multisig.t.sol b/packages/protocol/test-sol/common/Multisig.t.sol new file mode 100644 index 00000000000..89ef6d9f092 --- /dev/null +++ b/packages/protocol/test-sol/common/Multisig.t.sol @@ -0,0 +1,426 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.5.13; + +import "celo-foundry/Test.sol"; +import "../../contracts/common/MultiSig.sol"; + +contract MultiSigTest is Test { + function() external payable {} + + MultiSig public multiSig; + address owner0; + address owner1; + address newOwner; + address nonOwner; + address sender; + uint256 requiredSignatures = 2; + uint256 internalRequiredSignatures = 2; + address[] public owners; + bytes addOwnerTxData; + + event Confirmation(address indexed sender, uint256 indexed transactionId); + event Revocation(address indexed sender, uint256 indexed transactionId); + event Submission(uint256 indexed transactionId); + event Execution(uint256 indexed transactionId, bytes returnData); + event Deposit(address indexed sender, uint256 value); + event OwnerAddition(address indexed owner); + event OwnerRemoval(address indexed owner); + event RequirementChange(uint256 required); + event InternalRequirementChange(uint256 internalRequired); + + function setUp() public { + multiSig = new MultiSig(true); + owner0 = actor("owner0"); + owner1 = actor("owner1"); + sender = actor("sender"); + newOwner = actor("newOwner"); + nonOwner = actor("nonOwner"); + vm.deal(sender, 10 ether); + owners = [owner0, owner1]; + + addOwnerTxData = abi.encodeWithSignature("addOwner(address)", newOwner); + + multiSig.initialize(owners, requiredSignatures, internalRequiredSignatures); + } +} + +contract MultiSigInitialize is MultiSigTest { + function setUp() public { + super.setUp(); + } + + function test_shouldHaveSetTheOwners() public { + assertEq(multiSig.getOwners(), owners); + } + + function test_shouldHaveSetTheNumberOfRequiredSignaturesForExternalTransactions() public { + assertEq(uint256(multiSig.required()), 2); + } + + function test_shouldHaveSetTheNumberOfRequiredSignaturesForInternalTransactions() public { + assertEq(uint256(multiSig.internalRequired()), 2); + } + + function test_revertsWhenCalledTwice() public { + vm.expectRevert("contract already initialized"); + multiSig.initialize(owners, requiredSignatures, internalRequiredSignatures); + } +} + +contract MultiSigFallbackFunction is MultiSigTest { + uint256 amount = 100; + + function setUp() public { + super.setUp(); + } + + function uncheckedSendViaCall(address payable _to, uint256 _amount) public payable { + _to.call.value(_amount)(""); + } + + function test_emitsDepositEventWithCorrectParameters_whenReceivingCelo() public payable { + vm.prank(sender); + vm.expectEmit(true, false, false, false); + emit Deposit(sender, amount); + uncheckedSendViaCall(address(multiSig), amount); + } + + // TODO: Implement after pragma ^0.8 + function SKIP_test_doesNotEmitEvent_whenReceivingZeroValue() public { + vm.prank(sender); + vm.recordLogs(); + uncheckedSendViaCall(address(multiSig), 0); + // Vm.Log[] memory entries = vm.getRecordedLogs(); + // assertEq(entries.length, 0); + } +} + +contract MultiSigSubmitTransaction is MultiSigTest { + uint256 txId = 0; + + function setUp() public { + super.setUp(); + } + + function test_shouldAllowAnOwnerToSubmitATransaction() public { + vm.prank(owner0); + vm.expectEmit(true, true, true, true); + emit Confirmation(owner0, txId); + multiSig.submitTransaction(address(multiSig), 0, addOwnerTxData); + + (address dest, uint256 val, bytes memory data, bool exec) = multiSig.transactions(txId); + + assertEq(dest, address(multiSig)); + assertEq(val, 0); + assertEq(data, addOwnerTxData); + assertEq(exec, false); + assertEq(multiSig.confirmations(txId, owner0), true); + assertEq(multiSig.transactionCount(), 1); + } + + function test_shouldNotAllowAnOwnerToSubmitATransactionToANullAddress() public { + vm.expectRevert("address was null"); + multiSig.submitTransaction(address(0), 0, addOwnerTxData); + } + + function test_shouldNotAllowANonOwnerToSubmitATransaction() public { + vm.expectRevert("owner does not exist"); + multiSig.submitTransaction(address(multiSig), 0, addOwnerTxData); + } +} + +contract MultiSigConfirmTransaction is MultiSigTest { + uint256 txId = 0; + + function setUp() public { + super.setUp(); + vm.prank(owner0); + multiSig.submitTransaction(address(multiSig), 0, addOwnerTxData); + } + + function test_shouldAllowAnOwnerToConfirmTransaction() public { + vm.prank(owner1); + multiSig.confirmTransaction(txId); + + assertEq(multiSig.confirmations(txId, owner1), true); + + (, , , bool exec) = multiSig.transactions(txId); + assertEq(exec, true); + } + + function test_shouldNotAllowAnOwnerToConfirmATransactionTwice() public { + vm.prank(owner0); + vm.expectRevert("transaction was already confirmed for owner"); + multiSig.confirmTransaction(txId); + } + + function test_shouldNotAllowANonOwnerToConfirmATransaction() public { + vm.prank(nonOwner); + vm.expectRevert("owner does not exist"); + multiSig.confirmTransaction(txId); + } +} + +contract MultiSigRevokeConfirmation is MultiSigTest { + uint256 txId = 0; + + function setUp() public { + super.setUp(); + vm.prank(owner0); + multiSig.submitTransaction(address(multiSig), 0, addOwnerTxData); + } + + function test_shouldAllowAnOwnerToRevokeConfirmation() public { + vm.prank(owner0); + multiSig.revokeConfirmation(txId); + assertEq(multiSig.confirmations(txId, owner0), false); + } + + function test_shouldNotAllowANonOwnerToRevokeConfirmation() public { + vm.prank(nonOwner); + vm.expectRevert("owner does not exist"); + multiSig.revokeConfirmation(txId); + } + + function test_shouldNotAllowAnOwnerToRevokeBeforeConfirming() public { + vm.prank(owner1); + vm.expectRevert("transaction was not confirmed for owner"); + multiSig.revokeConfirmation(txId); + } +} + +contract MultiSigAddOwner is MultiSigTest { + uint256 txId = 0; + address[] public updatedOwners; + + function setUp() public { + super.setUp(); + updatedOwners = [owner0, owner1, newOwner]; + } + + function test_shouldAllowNewOwnerToBeAddedViaMultiSig() public { + vm.prank(owner0); + multiSig.submitTransaction(address(multiSig), 0, addOwnerTxData); + vm.prank(owner1); + multiSig.confirmTransaction(txId); + assertEq(multiSig.isOwner(newOwner), true); + + assertEq(multiSig.getOwners(), updatedOwners); + } + + function test_shouldNotAllowAnExternalAccountToAddAnOwner() public { + vm.prank(nonOwner); + vm.expectRevert("msg.sender was not multisig wallet"); + multiSig.addOwner(newOwner); + } + + function test_shouldNotAllowAddingTheNullAddress() public { + bytes memory txData_null = abi.encodeWithSignature("addOwner(address)", address(0)); + vm.prank(owner0); + multiSig.submitTransaction(address(multiSig), 0, txData_null); + + vm.prank(owner1); + vm.expectRevert("Transaction execution failed."); + multiSig.confirmTransaction(txId); + } +} + +contract MultiSigRemoveOwner is MultiSigTest { + uint256 txId = 0; + address[] public updatedOwners; + + function setUp() public { + super.setUp(); + updatedOwners = [owner0]; + } + + function test_shouldAllowOwnerToBeRemovedViaMultiSig() public { + bytes memory txData_remove = abi.encodeWithSignature("removeOwner(address)", owner1); + vm.prank(owner0); + multiSig.submitTransaction(address(multiSig), 0, txData_remove); + + vm.prank(owner1); + multiSig.confirmTransaction(txId); + + assertEq(multiSig.isOwner(owner1), false); + assertEq(multiSig.required(), 1); + assertEq(multiSig.internalRequired(), 1); + assertEq(multiSig.getOwners(), updatedOwners); + } + + function test_shouldNotAllowAnExternalAccountToRemoveAnOwner() public { + vm.prank(nonOwner); + vm.expectRevert("msg.sender was not multisig wallet"); + multiSig.removeOwner(newOwner); + } +} + +contract MultiSigReplaceOwner is MultiSigTest { + uint256 txId = 0; + address[] public updatedOwners; + + function setUp() public { + super.setUp(); + updatedOwners = [owner0, newOwner]; + } + + function test_shouldAllowAnExistingOwnerToBeReplacedViaMultiSig() public { + bytes memory txData_replace = abi.encodeWithSignature( + "replaceOwner(address,address)", + owner1, + newOwner + ); + vm.prank(owner0); + multiSig.submitTransaction(address(multiSig), 0, txData_replace); + + vm.prank(owner1); + multiSig.confirmTransaction(txId); + + assertEq(multiSig.isOwner(owner1), false); + assertEq(multiSig.isOwner(newOwner), true); + assertEq(multiSig.getOwners(), updatedOwners); + } + + function test_shouldNotAllowAnExternalAccountToReplaceAnOwner() public { + vm.prank(nonOwner); + vm.expectRevert("msg.sender was not multisig wallet"); + multiSig.replaceOwner(owner1, newOwner); + } + + function test_shouldNotAllowAnOwnerToBeReplacedByNullAddress() public { + bytes memory txData_replace = abi.encodeWithSignature( + "replaceOwner(address,address)", + owner1, + address(0) + ); + vm.prank(owner0); + multiSig.submitTransaction(address(multiSig), 0, txData_replace); + + vm.prank(owner1); + vm.expectRevert("Transaction execution failed."); + multiSig.confirmTransaction(txId); + } +} + +contract MultiSigChangeRequirements is MultiSigTest { + uint256 txId = 0; + + function setUp() public { + super.setUp(); + } + + function test_shouldAllowTheRequirementToBeChangedViaMultiSig() public { + bytes memory txData_change_req = abi.encodeWithSignature("changeRequirement(uint256)", 1); + + vm.prank(owner0); + multiSig.submitTransaction(address(multiSig), 0, txData_change_req); + + vm.prank(owner1); + multiSig.confirmTransaction(txId); + assertEq(multiSig.required(), 1); + } + + function test_shouldNotAllowAnExternalAccountToChangeTheRequirement() public { + vm.prank(nonOwner); + vm.expectRevert("msg.sender was not multisig wallet"); + multiSig.changeRequirement(3); + } +} + +contract MultiSigChangeInternalRequirements is MultiSigTest { + uint256 txId = 0; + + function setUp() public { + super.setUp(); + } + + function test_shouldAllowTheInternalRequirementToBeChangedViaMultiSig() public { + bytes memory txData_change_req = abi.encodeWithSignature( + "changeInternalRequirement(uint256)", + 1 + ); + + vm.prank(owner0); + multiSig.submitTransaction(address(multiSig), 0, txData_change_req); + + vm.prank(owner1); + multiSig.confirmTransaction(txId); + assertEq(multiSig.internalRequired(), 1); + } + + function test_shouldNotAllowAnExternalAccountToChangeTheInternalRequirement() public { + vm.prank(nonOwner); + vm.expectRevert("msg.sender was not multisig wallet"); + multiSig.changeInternalRequirement(3); + } +} + +contract MultiSigGetConfirmationCount is MultiSigTest { + uint256 txId = 0; + + function setUp() public { + super.setUp(); + vm.prank(owner0); + multiSig.submitTransaction(address(multiSig), 0, addOwnerTxData); + } + + function test_shouldReturnTheConfirmationCount() public { + assertEq(multiSig.getConfirmationCount(txId), 1); + } +} + +contract MultiSigGetTransactionCount is MultiSigTest { + uint256 txId = 0; + + function setUp() public { + super.setUp(); + vm.prank(owner0); + multiSig.submitTransaction(address(multiSig), 0, addOwnerTxData); + } + + function test_shouldReturnTheTransactionCount() public { + assertEq(multiSig.getTransactionCount(true, true), 1); + } +} + +contract MultiSigGetOwners is MultiSigTest { + function setUp() public { + super.setUp(); + } + + function test_shouldReturnTheOwners() public { + assertEq(multiSig.getOwners(), owners); + } +} + +contract MultiSigGetConfirmations is MultiSigTest { + uint256 txId = 0; + + function setUp() public { + super.setUp(); + vm.prank(owner0); + multiSig.submitTransaction(address(multiSig), 0, addOwnerTxData); + } + + function test_shouldReturnTheConfirmations() public { + address[] memory expectedConfirmations = new address[](1); + expectedConfirmations[0] = owner0; + assertEq(multiSig.getConfirmations(txId), expectedConfirmations); + } +} + +contract MultiSigGetTransactionIds is MultiSigTest { + uint256 txId = 0; + + function setUp() public { + super.setUp(); + vm.prank(owner0); + multiSig.submitTransaction(address(multiSig), 0, addOwnerTxData); + } + + function test_shouldReturnTheTransactionIds() public { + uint256[] memory expectedTransactionIds = new uint256[](1); + expectedTransactionIds[0] = txId; + assertEq(multiSig.getTransactionIds(0, 1, true, true), expectedTransactionIds); + } +} diff --git a/packages/protocol/test/common/multisig.ts b/packages/protocol/test/common/multisig.ts deleted file mode 100644 index a0e4c070a2f..00000000000 --- a/packages/protocol/test/common/multisig.ts +++ /dev/null @@ -1,457 +0,0 @@ -import { NULL_ADDRESS } from '@celo/base/lib/address' -import { - assertEqualBN, - assertLogMatches2, - assertTransactionRevertWithReason, -} from '@celo/protocol/lib/test-utils' -import { parseMultiSigTransaction } from '@celo/protocol/lib/web3-utils' -import _ from 'lodash' -import { MultiSigContract, MultiSigInstance } from 'types' - -const MultiSig: MultiSigContract = artifacts.require('MultiSig') - -// TODO(asa): Test more governance configurations, calling functions on external contracts. -contract('MultiSig', (accounts: any) => { - let multiSig: MultiSigInstance - - const owners = [accounts[0], accounts[1]] - const requiredSignatures = 2 - const internalRequiredSignatures = 2 - - beforeEach(async () => { - multiSig = await MultiSig.new(true) - await multiSig.initialize(owners, requiredSignatures, internalRequiredSignatures) - }) - - describe('#initialize()', () => { - it('should have set the owners', async () => { - assert.deepEqual(await multiSig.getOwners(), owners) - }) - - it('should have set the number of required signatures for external transactions', async () => { - const required: number = (await multiSig.required()).toNumber() - assert.equal(required, requiredSignatures) - }) - - it('should have set the number of required signatures for internal transactions', async () => { - const required: number = (await multiSig.internalRequired()).toNumber() - assert.equal(required, internalRequiredSignatures) - }) - - it('should not be callable again', async () => { - await assertTransactionRevertWithReason( - multiSig.initialize(owners, requiredSignatures, internalRequiredSignatures), - 'contract already initialized' - ) - }) - }) - - describe('fallback function', () => { - describe('when receiving celo', () => { - it('emits Deposit event with correct parameters', async () => { - const value = 100 - // @ts-ignore - const res = await multiSig.send(value) - assertLogMatches2(res.logs[0], { - event: 'Deposit', - args: { - sender: accounts[0], - value, - }, - }) - }) - }) - - describe('when receiving 0 value', () => { - it('does not emit an event', async () => { - // @ts-ignore - const res = await multiSig.send(0) - assert.equal(res.logs, 0) - }) - }) - }) - - describe('#submitTransaction()', () => { - let txData: string - beforeEach(async () => { - // @ts-ignore - txData = multiSig.contract.methods.addOwner(accounts[2]).encodeABI() - }) - - it('should allow an owner to submit a transaction', async () => { - // @ts-ignore: TODO(mcortesi): fix typings - const tx = await multiSig.submitTransaction(multiSig.address, 0, txData, { - from: accounts[0], - }) - - const txEvent = _.find(tx.logs, { - event: 'Confirmation', - }) - const txId = txEvent.args.transactionId - - // @ts-ignore: TODO(mcortesi): fix typings - const parsedTxData = parseMultiSigTransaction(await multiSig.transactions(txId)) - assert.equal(parsedTxData.destination, multiSig.address) - assert.equal(parsedTxData.value, 0) - assert.equal(parsedTxData.data, txData) - assert.isFalse(parsedTxData.executed) - assert.isTrue(await multiSig.confirmations(txId, accounts[0])) - assert.equal((await multiSig.transactionCount()).toNumber(), 1) - }) - - it('should not allow an owner to submit a transaction to a null address', async () => { - // @ts-ignore: TODO(mcortesi): fix typings - await assertTransactionRevertWithReason( - multiSig.submitTransaction(NULL_ADDRESS, 0, txData), - 'address was null' - ) - }) - - it('should not allow a non-owner to submit a transaction', async () => { - await assertTransactionRevertWithReason( - // @ts-ignore: TODO(mcortesi): fix typings - multiSig.submitTransaction(multiSig.address, 0, txData, { from: accounts[2] }), - 'owner does not exist' - ) - }) - }) - - describe('#confirmTransaction()', () => { - let txId: number - let tx: string - beforeEach(async () => { - // @ts-ignore - const txData = multiSig.contract.methods.addOwner(accounts[2]).encodeABI() - // @ts-ignore: TODO(mcortesi): fix typings - tx = await multiSig.submitTransaction(multiSig.address, 0, txData, { - from: accounts[0], - }) - - // @ts-ignore: TODO(mcortesi): fix typings - const txEvent = _.find(tx.logs, { - event: 'Confirmation', - }) - txId = txEvent.args.transactionId - }) - - it('should allow an owner to confirm a transaction', async () => { - await multiSig.confirmTransaction(txId, { from: accounts[1] }) - assert.isTrue(await multiSig.confirmations(txId, accounts[1])) - - // @ts-ignore: TODO(mcortesi): fix typings - const parsedTxData = parseMultiSigTransaction(await multiSig.transactions(txId)) - assert.isTrue(parsedTxData.executed) - }) - - it('should not allow an owner to confirm a transaction twice', async () => { - await assertTransactionRevertWithReason( - multiSig.confirmTransaction(txId, { from: accounts[0] }), - 'transaction was already confirmed for owner' - ) - }) - - it('should not allow a non-owner to confirm a transaction', async () => { - await assertTransactionRevertWithReason( - multiSig.confirmTransaction(txId, { from: accounts[2] }), - 'owner does not exist' - ) - }) - }) - - describe('#revokeConfirmation()', () => { - let txId: number - let tx: string - beforeEach(async () => { - // @ts-ignore - const txData = multiSig.contract.methods.addOwner(accounts[2]).encodeABI() - // @ts-ignore: TODO(mcortesi): fix typings - tx = await multiSig.submitTransaction(multiSig.address, 0, txData, { - from: accounts[0], - }) - - // @ts-ignore: TODO(mcortesi): fix typings - const txEvent = _.find(tx.logs, { - event: 'Confirmation', - }) - txId = txEvent.args.transactionId - }) - - it('should allow an owner to revoke a confirmation', async () => { - await multiSig.revokeConfirmation(txId) - assert.isFalse(await multiSig.confirmations(txId, accounts[0])) - }) - - it('should not allow a non-owner to revoke a confirmation', async () => { - await assertTransactionRevertWithReason( - multiSig.revokeConfirmation(txId, { from: accounts[2] }), - 'owner does not exist' - ) - }) - - it('should not allow an owner to revoke before confirming', async () => { - await assertTransactionRevertWithReason( - multiSig.revokeConfirmation(txId, { from: accounts[1] }), - 'transaction was not confirmed for owner' - ) - }) - }) - - describe('#addOwner()', () => { - it('should allow a new owner to be added via the MultiSig', async () => { - // @ts-ignore - const txData = multiSig.contract.methods.addOwner(accounts[2]).encodeABI() - // @ts-ignore: TODO(mcortesi): fix typings - const tx = await multiSig.submitTransaction(multiSig.address, 0, txData, { - from: accounts[0], - }) - - // @ts-ignore: TODO(mcortesi): fix typings - const txEvent = _.find(tx.logs, { - event: 'Confirmation', - }) - const txId = txEvent.args.transactionId - // @ts-ignore: TODO(mcortesi): fix typings - await multiSig.confirmTransaction(txId, { from: accounts[1] }) - assert.isTrue(await multiSig.isOwner(accounts[2])) - assert.sameMembers([accounts[0], accounts[1], accounts[2]], await multiSig.getOwners()) - }) - - it('should not allow an external account to add an owner', async () => { - // @ts-ignore - await assertTransactionRevertWithReason( - multiSig.addOwner(accounts[2], { from: accounts[3] }), - 'msg.sender was not multisig wallet' - ) - }) - - it('should not allow adding the null address', async () => { - // @ts-ignore - const txData = multiSig.contract.methods.addOwner(NULL_ADDRESS).encodeABI() - const tx = await multiSig.submitTransaction(multiSig.address, 0, txData, { - from: accounts[0], - }) - // @ts-ignore: TODO(mcortesi): fix typings - const txEvent = _.find(tx.logs, { - event: 'Confirmation', - }) - const txId = txEvent.args.transactionId - await assertTransactionRevertWithReason( - multiSig.confirmTransaction(txId, { from: accounts[1] }), - 'Transaction execution failed.' - ) - }) - }) - - describe('#removeOwner()', () => { - it('should allow an owner to be removed via the MultiSig', async () => { - // @ts-ignore - const txData = multiSig.contract.methods.removeOwner(accounts[1]).encodeABI() - - const tx = await multiSig.submitTransaction(multiSig.address, 0, txData, { - from: accounts[0], - }) - - // @ts-ignore: TODO(mcortesi): fix typings - const txEvent = _.find(tx.logs, { - event: 'Confirmation', - }) - // @ts-ignore: TODO(mcortesi): fix typings - const txId = txEvent.args.transactionId - - // @ts-ignore: TODO(mcortesi): fix typings - await multiSig.confirmTransaction(txId, { from: accounts[1] }) - - assert.isFalse(await multiSig.isOwner(accounts[1])) - assertEqualBN(await multiSig.required(), 1) - assertEqualBN(await multiSig.internalRequired(), 1) - assert.sameMembers([accounts[0]], await multiSig.getOwners()) - }) - - it('should not allow an external account to remove an owner', async () => { - // @ts-ignore - await assertTransactionRevertWithReason( - multiSig.removeOwner(accounts[1], { from: accounts[3] }), - 'msg.sender was not multisig wallet' - ) - }) - }) - - describe('#replaceOwner()', () => { - it('should allow an existing owner to be replaced by a new one via the MultiSig', async () => { - // @ts-ignore: TODO(mcortesi): fix typings - const txData = multiSig.contract.methods.replaceOwner(accounts[1], accounts[2]).encodeABI() - const tx = await multiSig.submitTransaction(multiSig.address, 0, txData, { - from: accounts[0], - }) - // @ts-ignore: TODO(mcortesi): fix typings - const txEvent = _.find(tx.logs, { - event: 'Confirmation', - }) - // @ts-ignore: TODO(mcortesi): fix typings - const txId = txEvent.args.transactionId - // @ts-ignore: TODO(mcortesi): fix typings - await multiSig.confirmTransaction(txId, { from: accounts[1] }) - assert.isTrue(await multiSig.isOwner(accounts[2])) - assert.isFalse(await multiSig.isOwner(accounts[1])) - assert.sameMembers([accounts[0], accounts[2]], await multiSig.getOwners()) - }) - - it('should not allow an external account to replace an owner', async () => { - // @ts-ignore - await assertTransactionRevertWithReason( - multiSig.replaceOwner(accounts[1], accounts[2], { from: accounts[3] }), - 'msg.sender was not multisig wallet' - ) - }) - - it('should not allow an owner to be replaced by the null address', async () => { - // @ts-ignore - const txData = multiSig.contract.methods.replaceOwner(accounts[1], NULL_ADDRESS).encodeABI() - const tx = await multiSig.submitTransaction(multiSig.address, 0, txData, { - from: accounts[0], - }) - // @ts-ignore: TODO(mcortesi): fix typings - const txEvent = _.find(tx.logs, { - event: 'Confirmation', - }) - const txId = txEvent.args.transactionId - await assertTransactionRevertWithReason( - multiSig.confirmTransaction(txId, { from: accounts[1] }), - 'Transaction execution failed.' - ) - }) - }) - - describe('#changeRequirement()', () => { - it('should allow the requirement to be changed via the MultiSig', async () => { - // @ts-ignore: TODO(mcortesi): fix typings - const txData = multiSig.contract.methods.changeRequirement(1).encodeABI() - const tx = await multiSig.submitTransaction(multiSig.address, 0, txData, { - from: accounts[0], - }) - // @ts-ignore: TODO(mcortesi): fix typings - const txEvent = _.find(tx.logs, { - event: 'Confirmation', - }) - // @ts-ignore: TODO(mcortesi): fix typings - const txId = txEvent.args.transactionId - - // @ts-ignore: TODO(mcortesi): fix typings - await multiSig.confirmTransaction(txId, { from: accounts[1] }) - assertEqualBN(await multiSig.required(), 1) - }) - - it('should not allow an external account to change the requirement', async () => { - // @ts-ignore - await assertTransactionRevertWithReason( - multiSig.changeRequirement(3, { from: accounts[3] }), - 'msg.sender was not multisig wallet' - ) - }) - }) - - describe('#changeInternalRequirement()', () => { - it('should allow the internal requirement to be changed via the MultiSig', async () => { - // @ts-ignore: TODO(mcortesi): fix typings - const txData = multiSig.contract.methods.changeInternalRequirement(1).encodeABI() - const tx = await multiSig.submitTransaction(multiSig.address, 0, txData, { - from: accounts[0], - }) - // @ts-ignore: TODO(mcortesi): fix typings - const txEvent = _.find(tx.logs, { - event: 'Confirmation', - }) - // @ts-ignore: TODO(mcortesi): fix typings - const txId = txEvent.args.transactionId - - // @ts-ignore: TODO(mcortesi): fix typings - await multiSig.confirmTransaction(txId, { from: accounts[1] }) - assertEqualBN(await multiSig.internalRequired(), 1) - }) - - it('should not allow an external account to change the internal requirement', async () => { - // @ts-ignore - await assertTransactionRevertWithReason( - multiSig.changeInternalRequirement(3, { from: accounts[3] }), - 'msg.sender was not multisig wallet' - ) - }) - }) - - describe('#getConfirmationCount()', () => { - let txId: number - beforeEach(async () => { - // @ts-ignore: TODO(mcortesi): fix typings - const txData = multiSig.contract.methods.addOwner(accounts[2]).encodeABI() - const tx = await multiSig.submitTransaction(multiSig.address, 0, txData, { - from: accounts[0], - }) - // @ts-ignore: TODO(mcortesi): fix typings - const txEvent = _.find(tx.logs, { - event: 'Confirmation', - }) - // @ts-ignore: TODO(mcortesi): fix typings - txId = txEvent.args.transactionId - }) - - it('should return the confirmation count', async () => { - assertEqualBN(await multiSig.getConfirmationCount(txId), 1) - }) - }) - - describe('#getTransactionCount()', () => { - beforeEach(async () => { - // @ts-ignore: TODO(mcortesi): fix typings - const txData = multiSig.contract.methods.addOwner(accounts[2]).encodeABI() - await multiSig.submitTransaction(multiSig.address, 0, txData, { - from: accounts[0], - }) - }) - - it('should return the transaction count', async () => { - assertEqualBN(await multiSig.getTransactionCount(true, true), 1) - }) - }) - - describe('#getOwners()', () => { - it('should return the owners', async () => { - assert.deepEqual(await multiSig.getOwners(), owners) - }) - }) - - describe('#getConfirmations()', () => { - let txId: number - beforeEach(async () => { - // @ts-ignore: TODO(mcortesi): fix typings - const txData = multiSig.contract.methods.addOwner(accounts[2]).encodeABI() - const tx = await multiSig.submitTransaction(multiSig.address, 0, txData, { - from: accounts[0], - }) - // @ts-ignore: TODO(mcortesi): fix typings - const txEvent = _.find(tx.logs, { - event: 'Confirmation', - }) - // @ts-ignore: TODO(mcortesi): fix typings - txId = txEvent.args.transactionId - }) - - it('should return the confirmations', async () => { - assert.deepEqual(await multiSig.getConfirmations(txId), [accounts[0]]) - }) - }) - - describe('#getTransactionIds()', () => { - beforeEach(async () => { - // @ts-ignore: TODO(mcortesi): fix typings - const txData = multiSig.contract.methods.addOwner(accounts[2]).encodeABI() - await multiSig.submitTransaction(multiSig.address, 0, txData, { - from: accounts[0], - }) - }) - - it('should return the confirmations', async () => { - const txIds = (await multiSig.getTransactionIds(0, 1, true, true)).map((x) => x.toNumber()) - assert.deepEqual(txIds, [0]) - }) - }) -}) From b24408b145010f0ad1c77102af640cdb92f36044 Mon Sep 17 00:00:00 2001 From: pahor167 <47992132+pahor167@users.noreply.github.com> Date: Fri, 1 Dec 2023 19:09:08 +0100 Subject: [PATCH 44/63] Accounts foundry test (#10774) * Accounts foundry test * rest of the tests * Removal of accounts.ts * Update packages/protocol/test-sol/Accounts.t.sol Co-authored-by: soloseng <102702451+soloseng@users.noreply.github.com> * Update packages/protocol/test-sol/Accounts.t.sol Co-authored-by: soloseng <102702451+soloseng@users.noreply.github.com> * Update packages/protocol/test-sol/Accounts.t.sol Co-authored-by: soloseng <102702451+soloseng@users.noreply.github.com> * Update packages/protocol/test-sol/Accounts.t.sol Co-authored-by: soloseng <102702451+soloseng@users.noreply.github.com> * PR comments * PR comments 2 * PR comments 3 * Move of tests into different folder structure --------- Co-authored-by: soloseng <102702451+soloseng@users.noreply.github.com> --- .github/workflows/celo-monorepo.yml | 3 - packages/protocol/test-sol/Accounts.t.sol | 1535 +++++++++++++++++ .../test-sol/{ => common}/GoldToken.t.sol | 4 +- .../{ => identity}/IdentityProxy.t.sol | 4 +- .../{ => identity}/IdentityProxyHub.t.sol | 10 +- packages/protocol/test/common/accounts.ts | 1049 ----------- 6 files changed, 1544 insertions(+), 1061 deletions(-) create mode 100644 packages/protocol/test-sol/Accounts.t.sol rename packages/protocol/test-sol/{ => common}/GoldToken.t.sol (98%) rename packages/protocol/test-sol/{ => identity}/IdentityProxy.t.sol (91%) rename packages/protocol/test-sol/{ => identity}/IdentityProxyHub.t.sol (96%) delete mode 100644 packages/protocol/test/common/accounts.ts diff --git a/.github/workflows/celo-monorepo.yml b/.github/workflows/celo-monorepo.yml index 98e43854428..b7f3f6d5d1b 100644 --- a/.github/workflows/celo-monorepo.yml +++ b/.github/workflows/celo-monorepo.yml @@ -279,9 +279,6 @@ jobs: - name: Protocol Governance Voting command: | yarn --cwd packages/protocol test governance/voting/ - - name: Protocol Identity - command: | - yarn --cwd packages/protocol test identity/ - name: Protocol Stability command: | yarn --cwd packages/protocol test stability/ diff --git a/packages/protocol/test-sol/Accounts.t.sol b/packages/protocol/test-sol/Accounts.t.sol new file mode 100644 index 00000000000..fbfe6201db6 --- /dev/null +++ b/packages/protocol/test-sol/Accounts.t.sol @@ -0,0 +1,1535 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.5.13; +pragma experimental ABIEncoderV2; + +import "celo-foundry/Test.sol"; +import "../contracts/identity/Escrow.sol"; +import "../contracts/identity/FederatedAttestations.sol"; +import "../contracts/identity/test/MockAttestations.sol"; +import "../contracts/identity/test/MockERC20Token.sol"; +import "../contracts/common/FixidityLib.sol"; +import "../contracts/common/Registry.sol"; +import "../contracts/common/Accounts.sol"; +import "../contracts/governance/test/MockValidators.sol"; + +contract AccountsTest is Test { + using FixidityLib for FixidityLib.Fraction; + + Registry registry; + Accounts accounts; + MockValidators validators; + + string constant name = "Account"; + string constant metadataURL = "https://www.celo.org"; + string constant otherMetadataURL = "https://clabs.co"; + + bytes storageRoot = abi.encodePacked(metadataURL); + bytes otherStorageRoot = abi.encodePacked(otherMetadataURL); + + bytes constant dataEncryptionKey = hex"02f2f48ee19680706196e2e339e5da3491186e0c4c5030670656b0e01611111111"; + bytes constant longDataEncryptionKey = hex"04f2f48ee19680706196e2e339e5da3491186e0c4c5030670656b0e0161111111102f2f48ee19680706196e2e339e5da3491186e0c4c5030670656b0e01611111111"; + + address caller; + uint256 callerPK; + + address caller2; + uint256 caller2PK; + + bytes32 constant EIP712DOMAIN_TYPEHASH = keccak256( + "EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)" + ); + + bytes32 public constant EIP712_AUTHORIZE_SIGNER_TYPEHASH = keccak256( + "AuthorizeSigner(address account,address signer,bytes32 role)" + ); + + struct Domain { + string name; + string version; + uint256 chainId; + address verifyingContract; + } + + struct AuthorizeSigner { + address account; + address signer; + bytes32 role; + } + + event AttestationSignerAuthorized(address indexed account, address signer); + event VoteSignerAuthorized(address indexed account, address signer); + event ValidatorSignerAuthorized(address indexed account, address signer); + event SignerAuthorized(address indexed account, address signer, bytes32 indexed role); + event SignerAuthorizationStarted(address indexed account, address signer, bytes32 indexed role); + event SignerAuthorizationCompleted(address indexed account, address signer, bytes32 indexed role); + event AttestationSignerRemoved(address indexed account, address oldSigner); + event VoteSignerRemoved(address indexed account, address oldSigner); + event ValidatorSignerRemoved(address indexed account, address oldSigner); + event IndexedSignerSet(address indexed account, address signer, bytes32 role); + event IndexedSignerRemoved(address indexed account, address oldSigner, bytes32 role); + event DefaultSignerSet(address indexed account, address signer, bytes32 role); + event DefaultSignerRemoved(address indexed account, address oldSigner, bytes32 role); + event LegacySignerSet(address indexed account, address signer, bytes32 role); + event LegacySignerRemoved(address indexed account, address oldSigner, bytes32 role); + event SignerRemoved(address indexed account, address oldSigner, bytes32 indexed role); + event AccountDataEncryptionKeySet(address indexed account, bytes dataEncryptionKey); + event AccountNameSet(address indexed account, string name); + event AccountMetadataURLSet(address indexed account, string metadataURL); + event AccountWalletAddressSet(address indexed account, address walletAddress); + event AccountCreated(address indexed account); + event OffchainStorageRootAdded(address indexed account, bytes url); + event OffchainStorageRootRemoved(address indexed account, bytes url, uint256 index); + event PaymentDelegationSet(address indexed beneficiary, uint256 fraction); + + function setUp() public { + address registryAddress = 0x000000000000000000000000000000000000ce10; + + deployCodeTo("Registry.sol", abi.encode(false), registryAddress); + + accounts = new Accounts(true); + validators = new MockValidators(); + + registry = Registry(registryAddress); + + registry.setAddressFor("Validators", address(validators)); + registry.setAddressFor("Accounts", address(accounts)); + + accounts.initialize(address(registry)); + accounts.setEip712DomainSeparator(); + + (caller, callerPK) = actorWithPK("caller"); + (caller2, caller2PK) = actorWithPK("caller2"); + } + + function getParsedSignatureOfAddress(address _address, uint256 privateKey) + public + pure + returns (uint8, bytes32, bytes32) + { + bytes32 addressHash = keccak256(abi.encodePacked(_address)); + bytes32 prefixedHash = ECDSA.toEthSignedMessageHash(addressHash); + return vm.sign(privateKey, prefixedHash); + } + + function assertStorageRoots( + string memory rootsHex, + uint256[] memory lengths, + string[] memory expectedRoots + ) public { + assertEq(lengths.length, expectedRoots.length); + + bytes memory roots = bytes(abi.encodePacked(rootsHex)); + uint256 currentIndex = 0; + + for (uint256 i = 0; i < expectedRoots.length; i++) { + bytes memory root = slice(roots, currentIndex, currentIndex + lengths[i]); + currentIndex += lengths[i]; + assertEq(string(root), expectedRoots[i]); + } + + assertEq(roots.length, currentIndex); + } + + function slice(bytes memory data, uint256 start, uint256 end) + internal + pure + returns (bytes memory) + { + bytes memory part = new bytes(end - start); + for (uint256 i = 0; i < part.length; i++) { + part[i] = data[i + start]; + } + return part; + } + + function getAddressFromPrivateKey(uint256 privateKey) public pure returns (address) { + return vm.addr(privateKey); + } + + function getSignatureForAuthorization( + address account, + bytes32 _role, + uint256 privateKeySigner, // This is used to simulate signing in the test environment + uint256 _chainId, + address verifyingContract + ) public pure returns (uint8 v, bytes32 r, bytes32 s) { + bytes32 dataHash = generateTypedDataHash( + Domain("Celo Core Contracts", "1.0", _chainId, verifyingContract), + AuthorizeSigner(account, getAddressFromPrivateKey(privateKeySigner), _role) + ); + + // Simulate the signing of the digest with the provided private key using the EVM function + (v, r, s) = vm.sign(privateKeySigner, dataHash); + + // Return the signature components + return (v, r, s); + } + + function generateTypedDataHash(Domain memory domain, AuthorizeSigner memory authorizeSigner) + public + pure + returns (bytes32) + { + bytes32 domainSeparator = structHashEIP712Domain(domain); + bytes32 authorizeSignerHash = getAuthorizeSigner(authorizeSigner); + return keccak256(abi.encodePacked("\x19\x01", domainSeparator, authorizeSignerHash)); + } + + function getAuthorizeSigner(AuthorizeSigner memory authorizeSigner) + public + pure + returns (bytes32) + { + return + keccak256( + abi.encode( + EIP712_AUTHORIZE_SIGNER_TYPEHASH, + authorizeSigner.account, + authorizeSigner.signer, + authorizeSigner.role + ) + ); + } + + function structHashEIP712Domain(Domain memory domain) private pure returns (bytes32) { + return + keccak256( + abi.encode( + EIP712DOMAIN_TYPEHASH, + keccak256(bytes(domain.name)), + keccak256(bytes(domain.version)), + domain.chainId, + domain.verifyingContract + ) + ); + } +} + +contract CreateAccount is AccountsTest { + function setUp() public { + super.setUp(); + } + + function test_ShouldCreateTheAccount() public { + assertEq(accounts.isAccount(address(this)), false); + accounts.createAccount(); + assertEq(accounts.isAccount(address(this)), true); + } + + function test_ShouldEmitAccountCreatedEvent() public { + vm.expectEmit(true, true, true, true); + emit AccountCreated(address(this)); + accounts.createAccount(); + } +} + +contract SetAccountDataEncryptionKey is AccountsTest { + function setUp() public { + super.setUp(); + } + + function test_ShouldSetDataEncryptionKey() public { + accounts.setAccountDataEncryptionKey(dataEncryptionKey); + assertEq(accounts.getDataEncryptionKey(address(this)), dataEncryptionKey); + } + + function test_ShouldAllowSettingAKeyWithLEadingZeros() public { + bytes memory keyWithLeadingZeros = hex"00000000000000000000000000000000000000000000000f2f48ee19680706191111"; + accounts.setAccountDataEncryptionKey(keyWithLeadingZeros); + assertEq(accounts.getDataEncryptionKey(address(this)), keyWithLeadingZeros); + } + + function test_ShouldRevertWhenKeyIsInvalid() public { + bytes memory invalidKey = hex"321329312493"; + vm.expectRevert(bytes("data encryption key length <= 32")); + accounts.setAccountDataEncryptionKey(invalidKey); + } + + function test_ShouldAllowKeyLongerThan33Bytes() public { + accounts.setAccountDataEncryptionKey(longDataEncryptionKey); + assertEq(accounts.getDataEncryptionKey(address(this)), longDataEncryptionKey); + } + + function test_ShouldEmitAccountDataEncryptionKeySet() public { + vm.expectEmit(true, true, true, true); + emit AccountDataEncryptionKeySet(address(this), dataEncryptionKey); + accounts.setAccountDataEncryptionKey(dataEncryptionKey); + } +} + +contract SetAccount is AccountsTest { + function setUp() public { + super.setUp(); + } + + function test_ShouldSetTheNameDataEncryptionKeyAndWalletAddress_WhenTheAccountHasBeenCreated() + public + { + accounts.createAccount(); + accounts.setAccount(name, dataEncryptionKey, address(this), 0, 0x0, 0x0); + assertEq(accounts.getName(address(this)), name); + assertEq(accounts.getDataEncryptionKey(address(this)), dataEncryptionKey); + assertEq(accounts.getWalletAddress(address(this)), address(this)); + } + + function test_ShouldEmitAccountNameSetEvent_WhenTheAccountHasBeenCreated() public { + accounts.createAccount(); + vm.expectEmit(true, true, true, true); + emit AccountNameSet(address(this), name); + accounts.setAccount(name, dataEncryptionKey, address(this), 0, 0x0, 0x0); + } + + function test_ShouldEmitAccountDataEncryptionKeySetEvent_WhenTheAccountHasBeenCreated() public { + accounts.createAccount(); + vm.expectEmit(true, true, true, true); + emit AccountDataEncryptionKeySet(address(this), dataEncryptionKey); + accounts.setAccount(name, dataEncryptionKey, address(this), 0, 0x0, 0x0); + } + + function test_ShouldEmitAccountWalletAddressSetEvent_WhenTheAccountHasBeenCreated() public { + accounts.createAccount(); + vm.expectEmit(true, true, true, true); + emit AccountWalletAddressSet(address(this), address(this)); + accounts.setAccount(name, dataEncryptionKey, address(this), 0, 0x0, 0x0); + } + + function test_ShouldSetADifferentAddressWithAppropriateSignature_WhenTheAccountHasBeenCreated() + public + { + (uint8 v, bytes32 r, bytes32 s) = getParsedSignatureOfAddress(address(this), caller2PK); + accounts.setAccount(name, dataEncryptionKey, caller2, v, r, s); + assertEq(accounts.getWalletAddress(address(this)), caller2); + } + + function test_ShouldSetTheNameDataEncryptionKeyAndWalletAddress_WhenTheAccountHasNotBeenCreated() + public + { + accounts.setAccount(name, dataEncryptionKey, address(this), 0, 0x0, 0x0); + assertEq(accounts.getName(address(this)), name); + assertEq(accounts.getDataEncryptionKey(address(this)), dataEncryptionKey); + assertEq(accounts.getWalletAddress(address(this)), address(this)); + assertEq(accounts.isAccount(address(this)), true); + } + + function test_ShouldEmitAccountCreated_WhenTheAccountHasNotBeenCreated() public { + vm.expectEmit(true, true, true, true); + emit AccountCreated(address(this)); + accounts.setAccount(name, dataEncryptionKey, address(this), 0, 0x0, 0x0); + } + + function test_ShouldEmitAccountNameSetEvent_WhenTheAccountHasNotBeenCreated() public { + vm.expectEmit(true, true, true, true); + emit AccountNameSet(address(this), name); + accounts.setAccount(name, dataEncryptionKey, address(this), 0, 0x0, 0x0); + } + + function test_ShouldEmitAccountDataEncryptionKeySetEvent_WhenTheAccountHasNotBeenCreated() + public + { + vm.expectEmit(true, true, true, true); + emit AccountDataEncryptionKeySet(address(this), dataEncryptionKey); + accounts.setAccount(name, dataEncryptionKey, address(this), 0, 0x0, 0x0); + } + + function test_ShouldEmitAccountWalletAddressSetEvent_WhenTheAccountHasNotBeenCreated() public { + vm.expectEmit(true, true, true, true); + emit AccountWalletAddressSet(address(this), address(this)); + accounts.setAccount(name, dataEncryptionKey, address(this), 0, 0x0, 0x0); + } + + function test_ShouldRevertWhenIncorrectSignature() public { + (uint8 v, bytes32 r, bytes32 s) = getParsedSignatureOfAddress(address(caller), caller2PK); + vm.prank(caller); + vm.expectRevert("Invalid signature"); + accounts.setAccount(name, dataEncryptionKey, address(this), v, r, s); + } +} + +contract SetWalletAddress is AccountsTest { + function setUp() public { + super.setUp(); + } + + function test_ShouldRevert_WhenAccountHasNotBeenCreated() public { + vm.expectRevert("Unknown account"); + accounts.setWalletAddress(address(this), 0, 0x0, 0x0); + } + + function test_ShouldSetWalletAddress_WhenAccountHasBeenCreated() public { + accounts.createAccount(); + accounts.setWalletAddress(address(this), 0, 0x0, 0x0); + assertEq(accounts.getWalletAddress(address(this)), address(this)); + } + + function test_ShouldSetDifferentAddressWithTheAppropriateSignature_WhenAccountHasBeenCreated() + public + { + vm.startPrank(caller); + accounts.createAccount(); + (uint8 v, bytes32 r, bytes32 s) = getParsedSignatureOfAddress(address(caller), caller2PK); + accounts.setWalletAddress(caller2, v, r, s); + assertEq(accounts.getWalletAddress(address(caller)), caller2); + } + + function test_ShouldSetTheNULLAddress_WhenAccountHasBeenCreated() public { + accounts.createAccount(); + accounts.setWalletAddress(address(0), 0, 0x0, 0x0); + assertEq(accounts.getWalletAddress(address(this)), address(0)); + } + + function test_ShouldEmitTheAccountWalletAddressSetEvent_WhenAccountHasBeenCreated() public { + accounts.createAccount(); + vm.expectEmit(true, true, true, true); + emit AccountWalletAddressSet(address(this), address(this)); + accounts.setWalletAddress(address(this), 0, 0x0, 0x0); + } + + function test_ShouldRevertWithWrongSignatureForADifferentAddress_WhenAccountHasBEenCreated() + public + { + vm.startPrank(caller); + accounts.createAccount(); + (uint8 v, bytes32 r, bytes32 s) = getParsedSignatureOfAddress(address(caller), caller2PK); + vm.expectRevert("Invalid signature"); + accounts.setWalletAddress(address(this), v, r, s); + } +} + +contract SetMetadataURL is AccountsTest { + function setUp() public { + super.setUp(); + } + + function test_ShouldRevert_WhenAccountHasNotBeenCreated() public { + vm.expectRevert("Unknown account"); + accounts.setMetadataURL(metadataURL); + } + + function test_ShouldSetMetadatURL_WhenAccountHasBeenCreated() public { + accounts.createAccount(); + accounts.setMetadataURL(metadataURL); + assertEq(accounts.getMetadataURL(address(this)), metadataURL); + } + + function test_ShouldEmitTheAccountMetadataURLSetEvent() public { + accounts.createAccount(); + vm.expectEmit(true, true, true, true); + emit AccountMetadataURLSet(address(this), metadataURL); + accounts.setMetadataURL(metadataURL); + } +} + +contract BatchGetMetadataURL is AccountsTest { + function setUp() public { + super.setUp(); + } + + function parseSolidityStringArray(uint256[] memory stringLengths, bytes memory data) + private + pure + returns (string[] memory) + { + string[] memory strings = new string[](stringLengths.length); + uint256 offset = 0; + + for (uint256 i = 0; i < stringLengths.length; i++) { + bytes memory stringBytes = new bytes(stringLengths[i]); + for (uint256 j = 0; j < stringLengths[i]; j++) { + stringBytes[j] = data[offset + j]; + } + strings[i] = string(stringBytes); + offset += stringLengths[i]; + } + + return strings; + } + + function test_ShouldReturnTheMetadataURLs() public { + accounts.createAccount(); + accounts.setMetadataURL(metadataURL); + vm.prank(caller2); + accounts.createAccount(); + vm.prank(caller2); + accounts.setMetadataURL(otherMetadataURL); + + address[] memory addresses = new address[](2); + addresses[0] = address(this); + addresses[1] = address(caller2); + + string[] memory urlStrings = new string[](2); + urlStrings[0] = metadataURL; + urlStrings[1] = otherMetadataURL; + + (uint256[] memory sizes, bytes memory data) = accounts.batchGetMetadataURL(addresses); + + string[] memory returnedStrings = parseSolidityStringArray(sizes, data); + + for (uint256 i = 0; i < returnedStrings.length; i++) { + assertEq(returnedStrings[i], urlStrings[i]); + } + } +} + +contract AddStorageRoot is AccountsTest { + function setUp() public { + super.setUp(); + } + + function test_ShouldRevert_WhenAccountHasNotBeenCreated() public { + vm.expectRevert("Unknown account"); + accounts.addStorageRoot(storageRoot); + } + + function test_ShouldAddANewStorageRoot_WhenAccountHasBeenCreated() public { + accounts.createAccount(); + accounts.addStorageRoot(bytes(storageRoot)); + (bytes memory concatenated, uint256[] memory length) = accounts.getOffchainStorageRoots( + address(this) + ); + + string[] memory urls = new string[](1); + urls[0] = metadataURL; + + assertStorageRoots(string(concatenated), length, urls); + } + + function test_ShouldEmitTheOffchainStorageRootAddedEvent_WhenAccountHasBeenCreated() public { + accounts.createAccount(); + vm.expectEmit(true, true, true, true); + emit OffchainStorageRootAdded(address(this), bytes(metadataURL)); + accounts.addStorageRoot(bytes(metadataURL)); + } + + function test_ShouldAddMultipleStorageRoots_WhenAccountHasBeenCreated() public { + accounts.createAccount(); + accounts.addStorageRoot(bytes(metadataURL)); + accounts.addStorageRoot(bytes(otherMetadataURL)); + (bytes memory concatenated, uint256[] memory length) = accounts.getOffchainStorageRoots( + address(this) + ); + + string[] memory urls = new string[](2); + urls[0] = metadataURL; + urls[1] = otherMetadataURL; + + assertStorageRoots(string(concatenated), length, urls); + } +} + +contract RemoveStorageRoot is AccountsTest { + function setUp() public { + super.setUp(); + } + + function test_ShouldRevert_WhenAccountHasNotBeenCreated() public { + vm.expectRevert("Unknown account"); + accounts.removeStorageRoot(0); + } + + function test_ShouldRevertWithMessage_WhenThereAreNoStorageRootsAndAccountHasBeenCreated() + public + { + accounts.createAccount(); + vm.expectRevert("Invalid storage root index"); + accounts.removeStorageRoot(0); + } + + function test_ShouldRemoveOneOfTheRoots_WhenThereAreStorageRootsAndAccountHasBeenCreated() + public + { + accounts.createAccount(); + accounts.addStorageRoot(storageRoot); + accounts.addStorageRoot(otherStorageRoot); + accounts.removeStorageRoot(0); + + (bytes memory concatenated, uint256[] memory length) = accounts.getOffchainStorageRoots( + address(this) + ); + + string[] memory urls = new string[](1); + urls[0] = otherMetadataURL; + + assertStorageRoots(string(concatenated), length, urls); + } + + function test_ShouldRemoveDifferentRoot_WhenThereAreStorageRootsAndAccountHasBeenCreated() + public + { + accounts.createAccount(); + accounts.addStorageRoot(storageRoot); + accounts.addStorageRoot(otherStorageRoot); + accounts.removeStorageRoot(1); + + (bytes memory concatenated, uint256[] memory length) = accounts.getOffchainStorageRoots( + address(this) + ); + + string[] memory urls = new string[](1); + urls[0] = metadataURL; + + assertStorageRoots(string(concatenated), length, urls); + } + + function test_ShouldEmitOffchainStorageRootRemovedEvent_WhenThereAreStorageRootsAndAccountHasBeenCreated() + public + { + accounts.createAccount(); + accounts.addStorageRoot(storageRoot); + accounts.addStorageRoot(otherStorageRoot); + + vm.expectEmit(true, true, true, true); + emit OffchainStorageRootRemoved(address(this), bytes(otherMetadataURL), 1); + accounts.removeStorageRoot(1); + + (bytes memory concatenated, uint256[] memory length) = accounts.getOffchainStorageRoots( + address(this) + ); + + string[] memory urls = new string[](1); + urls[0] = metadataURL; + + assertStorageRoots(string(concatenated), length, urls); + } +} + +contract SetPaymentDelegation is AccountsTest { + address beneficiary = actor("beneficiary"); + uint256 fraction = FixidityLib.newFixedFraction(2, 10).unwrap(); + uint256 badFraction = FixidityLib.newFixedFraction(12, 10).unwrap(); + + function setUp() public { + super.setUp(); + } + + function test_ShouldNotBeCallableByNonAccount() public { + vm.expectRevert("Must first register address with Account.createAccount"); + accounts.setPaymentDelegation((beneficiary), fraction); + } + + function test_ShouldSetAnAddressAndAFraction() public { + accounts.createAccount(); + accounts.setPaymentDelegation(beneficiary, fraction); + (address realBeneficiary, uint256 realFraction) = accounts.getPaymentDelegation(address(this)); + assertEq(realBeneficiary, beneficiary); + assertEq(realFraction, fraction); + } + + function test_ShouldNotAllowFractionGreaterThan1() public { + accounts.createAccount(); + vm.expectRevert("Fraction must not be greater than 1"); + accounts.setPaymentDelegation(beneficiary, badFraction); + } + + function test_ShouldNotAllowABeneficiaryWithNullAddress() public { + accounts.createAccount(); + vm.expectRevert("Beneficiary cannot be address 0x0"); + accounts.setPaymentDelegation(address(0), badFraction); + } + + function test_ShouldEmitAPaymentDelegationSetEvent() public { + accounts.createAccount(); + vm.expectEmit(true, true, true, true); + emit PaymentDelegationSet(beneficiary, fraction); + accounts.setPaymentDelegation(beneficiary, fraction); + } +} + +contract DeletePaymentDelegation is AccountsTest { + address beneficiary = actor("beneficiary"); + uint256 fraction = FixidityLib.newFixedFraction(2, 10).unwrap(); + + function setUp() public { + super.setUp(); + accounts.createAccount(); + accounts.setPaymentDelegation(beneficiary, fraction); + } + + function test_ShouldNotBeCallableByNonAccount() public { + vm.prank(caller); + vm.expectRevert("Must first register address with Account.createAccount"); + accounts.deletePaymentDelegation(); + } + + function test_ShouldSetTheAddressAndBeneficiaryTo0() public { + accounts.deletePaymentDelegation(); + (address realBeneficiary, uint256 realFraction) = accounts.getPaymentDelegation(address(this)); + assertEq(realBeneficiary, address(0)); + assertEq(realFraction, 0); + } + + function test_ShouldEmitAPaymentDelegationSetEvent() public { + vm.expectEmit(true, true, true, true); + emit PaymentDelegationSet(address(0), 0); + accounts.deletePaymentDelegation(); + } +} + +contract SetName is AccountsTest { + function setUp() public { + super.setUp(); + } + + function test_ShouldNotBeCallableByNonAccount() public { + vm.expectRevert("Register with createAccount to set account name"); + accounts.setName(name); + } + + function test_ShouldSetTheName() public { + accounts.createAccount(); + accounts.setName(name); + assertEq(accounts.getName(address(this)), name); + } + + function test_ShouldEmitAccountNameSetEvent() public { + accounts.createAccount(); + vm.expectEmit(true, true, true, true); + emit AccountNameSet(address(this), name); + accounts.setName(name); + } +} + +contract GenericAuthorization is AccountsTest { + address account2 = actor("account2"); + address signer; + uint256 signerPK; + address signer2; + uint256 signer2PK; + bytes32 role = keccak256("Test Role"); + bytes32 role2 = keccak256("Test Role 2"); + + uint8 v; + bytes32 r; + bytes32 s; + + function setUp() public { + super.setUp(); + (signer, signerPK) = actorWithPK("signer"); + (signer2, signer2PK) = actorWithPK("signer2"); + (v, r, s) = getSignatureForAuthorization( + address(this), + role, + signerPK, + 31337, + address(accounts) + ); + accounts.createAccount(); + vm.prank(account2); + accounts.createAccount(); + } + + function test_ShouldRecoverTheCorrectSignerFromEIP712Signature() public { + address recoveredSigner = accounts.getRoleAuthorizationSigner( + address(this), + signer, + role, + v, + r, + s + ); + assertEq(recoveredSigner, signer); + } + + function test_ShouldNotCompleteAnAuthorizationThatHasntBeenStarted_WhenSmartContractSigner() + public + { + vm.expectRevert("Signer authorization not started"); + vm.prank(signer); + accounts.completeSignerAuthorization(address(this), role); + } + + function test_ShouldNotCompleteAuthorizationThatWasOnlyStarted_WhenSmartContractSigner() public { + accounts.authorizeSigner(signer, role); + assertEq(accounts.isSigner(address(this), signer, role), false); + } + + function test_ShouldSetAuthorizedSignerInTwoSteps_WhenSmartContractSigner() public { + accounts.authorizeSigner(signer, role); + vm.prank(signer); + accounts.completeSignerAuthorization(address(this), role); + assertEq(accounts.isSigner(address(this), signer, role), true); + assertEq(accounts.authorizedBy(signer), address(this)); + assertEq(accounts.isAuthorizedSigner(signer), true); + } + + function test_ShouldEmitTheRightEvents_WhenSmartContractSigner() public { + vm.expectEmit(true, true, true, true); + emit SignerAuthorizationStarted(address(this), signer, role); + accounts.authorizeSigner(signer, role); + vm.expectEmit(true, true, true, true); + emit SignerAuthorizationCompleted(address(this), signer, role); + vm.prank(signer); + accounts.completeSignerAuthorization(address(this), role); + } + + function test_ShouldSetAuthorizedSignerInOneStep_WhenEOASigner() public { + assertEq(accounts.isSigner(address(this), signer, role), false); + accounts.authorizeSignerWithSignature(signer, role, v, r, s); + + assertEq(accounts.isSigner(address(this), signer, role), true); + assertEq(accounts.authorizedBy(signer), address(this)); + assertEq(accounts.isAuthorizedSigner(signer), true); + } + + function test_ShouldEmitTheRightEvents_WhenEOASigner() public { + vm.expectEmit(true, true, true, true); + emit SignerAuthorized(address(this), signer, role); + accounts.authorizeSignerWithSignature(signer, role, v, r, s); + } + + function test_ShouldRemoveTheAuthorizedSigner() public { + accounts.authorizeSignerWithSignature(signer, role, v, r, s); + accounts.removeSigner(signer, role); + assertEq(accounts.isSigner(address(this), signer, role), false); + } + + function test_ShouldAuthorizeMultipleSignersForARole() public { + assertEq(accounts.isSigner(address(this), signer, role), false); + assertEq(accounts.isSigner(address(this), signer2, role), false); + + accounts.authorizeSignerWithSignature(signer, role, v, r, s); + + (uint8 v2, bytes32 r2, bytes32 s2) = getSignatureForAuthorization( + address(this), + role, + signer2PK, + 31337, + address(accounts) + ); + + accounts.authorizeSignerWithSignature(signer2, role, v2, r2, s2); + + assertEq(accounts.isSigner(address(this), signer, role), true); + assertEq(accounts.isSigner(address(this), signer2, role), true); + assertEq(accounts.authorizedBy(signer), address(this)); + assertEq(accounts.authorizedBy(signer2), address(this)); + assertEq(accounts.isAuthorizedSigner(signer), true); + assertEq(accounts.isAuthorizedSigner(signer2), true); + } + + function test_ShouldAuthorizeMultipleSignersForMultipleRoles() public { + assertEq(accounts.isSigner(address(this), signer, role), false); + assertEq(accounts.isSigner(address(this), signer2, role2), false); + + accounts.authorizeSignerWithSignature(signer, role, v, r, s); + + (uint8 v2, bytes32 r2, bytes32 s2) = getSignatureForAuthorization( + address(this), + role2, + signer2PK, + 31337, + address(accounts) + ); + + accounts.authorizeSignerWithSignature(signer2, role2, v2, r2, s2); + + assertEq(accounts.isSigner(address(this), signer, role), true); + assertEq(accounts.isSigner(address(this), signer2, role2), true); + assertEq(accounts.authorizedBy(signer), address(this)); + assertEq(accounts.authorizedBy(signer2), address(this)); + assertEq(accounts.isAuthorizedSigner(signer), true); + assertEq(accounts.isAuthorizedSigner(signer2), true); + } + + function test_ShouldNotAllowToAuthorizeSignerForTwoAccounts() public { + accounts.authorizeSignerWithSignature(signer, role, v, r, s); + + (uint8 v2, bytes32 r2, bytes32 s2) = getSignatureForAuthorization( + account2, + role, + signerPK, + 31337, + address(accounts) + ); + + vm.expectRevert("Invalid signature"); + accounts.authorizeSignerWithSignature(signer, role, v2, r2, s2); + } + + function test_ShouldSetDefaultSignerForTheRole() public { + assertEq(accounts.isSigner(address(this), signer, role), false); + assertEq(accounts.hasDefaultSigner(address(this), role), false); + assertEq(accounts.getDefaultSigner(address(this), role), address(this)); + + vm.expectRevert("Must authorize signer before setting as default"); + accounts.setIndexedSigner(signer, role); + + accounts.authorizeSignerWithSignature(signer, role, v, r, s); + accounts.setIndexedSigner(signer, role); + + assertEq(accounts.isSigner(address(this), signer, role), true); + assertEq(accounts.hasDefaultSigner(address(this), role), true); + assertEq(accounts.getDefaultSigner(address(this), role), signer); + } + + function test_ShouldRemoveTheDefaultSignerForARole() public { + accounts.authorizeSignerWithSignature(signer, role, v, r, s); + accounts.setIndexedSigner(signer, role); + accounts.removeDefaultSigner(role); + + assertEq(accounts.isSigner(address(this), signer, role), true); + assertEq(accounts.hasDefaultSigner(address(this), role), false); + assertEq(accounts.getDefaultSigner(address(this), role), address(this)); + } +} + +contract BackwardCompatibility is AccountsTest { + address account = address(this); + address otherAccount = actor("otherAccount"); + + address signer; + uint256 signerPK; + address signer2; + uint256 signer2PK; + + enum Role { Attestation, Vote, Validator } + + function setUp() public { + super.setUp(); + + (signer, signerPK) = actorWithPK("signer"); + (signer2, signer2PK) = actorWithPK("signer2"); + + accounts.createAccount(); + } + + function authorizeSignerFactory( + address _signer, + bytes32 _role, + uint8 _v, + bytes32 _r, + bytes32 _s, + bool expectRevert + ) public { + accounts.authorizeSignerWithSignature(_signer, _role, _v, _r, _s); + if (!expectRevert) { + accounts.setIndexedSigner(_signer, _role); + } + } + + function getSignature(address _account, bytes32 role, uint256 _signerPK, bool genericWrite) + public + view + returns (uint8, bytes32, bytes32) + { + if (genericWrite) { + return getSignatureForAuthorization(_account, role, _signerPK, 31337, address(accounts)); + } + + return getParsedSignatureOfAddress(_account, _signerPK); + } + + function getRole(Role role) public pure returns (bytes32 _role) { + if (role == Role.Attestation) { + _role = keccak256(abi.encodePacked("celo.org/core/attestation")); + } else if (role == Role.Vote) { + _role = keccak256(abi.encodePacked("celo.org/core/vote")); + } else if (role == Role.Validator) { + _role = keccak256(abi.encodePacked("celo.org/core/validator")); + } + } + + function hasAuthorizedSigner(Role role, address _signer, bool genericRead) + public + view + returns (bool) + { + bytes32 _role = getRole(role); + if (genericRead) { + return accounts.hasIndexedSigner(_signer, _role); + } else { + if (role == Role.Attestation) { + return accounts.hasAuthorizedAttestationSigner(_signer); + } else if (role == Role.Vote) { + return accounts.hasAuthorizedVoteSigner(_signer); + } else if (role == Role.Validator) { + return accounts.hasAuthorizedValidatorSigner(_signer); + } + } + } + + function authorize( + Role role, + bool genericWrite, + address _account, + address _signer, + uint256 _signerPK + ) public { + bytes32 _role = getRole(role); + (uint8 _v, bytes32 _r, bytes32 _s) = getSignature(_account, _role, _signerPK, genericWrite); + vm.startPrank(_account); + if (genericWrite) { + authorizeSignerFactory(_signer, _role, _v, _r, _s, false); + } else { + if (role == Role.Attestation) { + accounts.authorizeAttestationSigner(_signer, _v, _r, _s); + } else if (role == Role.Vote) { + accounts.authorizeVoteSigner(_signer, _v, _r, _s); + } else if (role == Role.Validator) { + accounts.authorizeValidatorSigner(_signer, _v, _r, _s); + } + } + vm.stopPrank(); + } + + function removeSigner(bool genericWrite, Role role, address _account) public { + vm.startPrank(_account); + bytes32 _role = getRole(role); + if (genericWrite) { + address defaultSigner = accounts.getIndexedSigner(_account, _role); + accounts.removeSigner(defaultSigner, _role); + } else { + if (role == Role.Attestation) { + accounts.removeAttestationSigner(); + } else if (role == Role.Vote) { + accounts.removeVoteSigner(); + } else if (role == Role.Validator) { + accounts.removeValidatorSigner(); + } + } + vm.stopPrank(); + } + + function getAuthorizedFromAccount(Role role, bool genericRead, address _account) + public + view + returns (address) + { + bytes32 _role = getRole(role); + if (genericRead) { + return accounts.getIndexedSigner(_account, _role); + } else { + if (role == Role.Attestation) { + return accounts.getAttestationSigner(_account); + } else if (role == Role.Vote) { + return accounts.getVoteSigner(_account); + } else if (role == Role.Validator) { + return accounts.getValidatorSigner(_account); + } + } + } + + function authorizedSignerToAccount(Role role, bool genericRead, address _signer) + public + view + returns (address) + { + if (genericRead) { + return accounts.signerToAccount(_signer); + } else { + if (role == Role.Attestation) { + return accounts.attestationSignerToAccount(_signer); + } else if (role == Role.Vote) { + return accounts.voteSignerToAccount(_signer); + } else if (role == Role.Validator) { + return accounts.validatorSignerToAccount(_signer); + } + } + } + + function helperShouldSetAuthorizedKey(bool genericRead, bool genericWrite, Role role) public { + assertEq(hasAuthorizedSigner(role, account, genericRead), false); + authorize(role, genericWrite, account, signer, signerPK); + assertEq(accounts.authorizedBy(signer), account); + assertEq(getAuthorizedFromAccount(role, genericRead, account), signer); + assertEq(authorizedSignerToAccount(role, genericRead, signer), account); + assertEq(hasAuthorizedSigner(role, account, genericRead), true); + } + + function test_ShouldAuthorizeVoteSigningKey_GenericReadFalse_GenericWriteFalse() public { + helperShouldSetAuthorizedKey(false, false, Role.Vote); + } + + function test_ShouldAuthorizeVoteSigningKey_GenericReadFalse_GenericWriteTrue() public { + helperShouldSetAuthorizedKey(false, true, Role.Vote); + } + + function test_ShouldAuthorizeVoteSigningKey_GenericReadTrue_GenericWriteFalse() public { + helperShouldSetAuthorizedKey(true, false, Role.Vote); + } + + function test_ShouldAuthorizeVoteSigningKey_GenericReadTrue_GenericWriteTrue() public { + helperShouldSetAuthorizedKey(true, true, Role.Vote); + } + + function test_ShouldAuthorizeAttestationSigningKey_GenericReadFalse_GenericWriteFalse() public { + helperShouldSetAuthorizedKey(false, false, Role.Attestation); + } + + function test_ShouldAuthorizeAttestationSigningKey_GenericReadFalse_GenericWriteTrue() public { + helperShouldSetAuthorizedKey(false, true, Role.Attestation); + } + + function test_ShouldAuthorizeAttestationSigningKey_GenericReadTrue_GenericWriteFalse() public { + helperShouldSetAuthorizedKey(true, false, Role.Attestation); + } + + function test_ShouldAuthorizeAttestationSigningKey_GenericReadTrue_GenericWriteTrue() public { + helperShouldSetAuthorizedKey(true, true, Role.Attestation); + } + + function test_ShouldAuthorizeValidatorSigningKey_GenericReadFalse_GenericWriteFalse() public { + helperShouldSetAuthorizedKey(false, false, Role.Validator); + } + + function test_ShouldAuthorizeValidatorSigningKey_GenericReadFalse_GenericWriteTrue() public { + helperShouldSetAuthorizedKey(false, true, Role.Validator); + } + + function test_ShouldAuthorizeValidatorSigningKey_GenericReadTrue_GenericWriteFalse() public { + helperShouldSetAuthorizedKey(true, false, Role.Validator); + } + + function test_ShouldAuthorizeValidatorSigningKey_GenericReadTrue_GenericWriteTrue() public { + helperShouldSetAuthorizedKey(true, true, Role.Validator); + } + + function test_ShouldEmitRightEventVote_GenericWriteTrue() public { + vm.expectEmit(true, true, true, true); + emit SignerAuthorized(account, signer, getRole(Role.Vote)); + authorize(Role.Vote, true, account, signer, signerPK); + } + + function test_ShouldEmitRightEventVote_GenericWriteFalse() public { + vm.expectEmit(true, true, true, true); + emit VoteSignerAuthorized(account, signer); + authorize(Role.Vote, false, account, signer, signerPK); + } + + function test_ShouldEmitRightEventAttestation_GenericWriteTrue() public { + vm.expectEmit(true, true, true, true); + emit SignerAuthorized(account, signer, getRole(Role.Attestation)); + authorize(Role.Attestation, true, account, signer, signerPK); + } + + function test_ShouldEmitRightEventAttestation_GenericWriteFalse() public { + vm.expectEmit(true, true, true, true); + emit AttestationSignerAuthorized(account, signer); + authorize(Role.Attestation, false, account, signer, signerPK); + } + + function test_ShouldEmitRightEventValidator_GenericWriteTrue() public { + vm.expectEmit(true, true, true, true); + emit SignerAuthorized(account, signer, getRole(Role.Validator)); + authorize(Role.Validator, true, account, signer, signerPK); + } + + function test_ShouldEmitRightEventValidator_GenericWriteFalse() public { + vm.expectEmit(true, true, true, true); + emit ValidatorSignerAuthorized(account, signer); + authorize(Role.Validator, false, account, signer, signerPK); + } + + function test_ShouldRevertIfVoteIsAnAccount_GenericWriteTrue() public { + vm.prank(signer); + accounts.createAccount(); + vm.expectRevert("Cannot re-authorize address or locked gold account for another account"); + bytes32 _role = getRole(Role.Vote); + (uint8 _v, bytes32 _r, bytes32 _s) = getSignature(account, _role, signerPK, true); + authorizeSignerFactory(signer, _role, _v, _r, _s, true); + } + + function test_ShouldRevertIfVoteIsAnAccount_GenericWriteFalse() public { + vm.prank(signer); + accounts.createAccount(); + vm.expectRevert("Cannot re-authorize address or locked gold account for another account"); + authorize(Role.Vote, false, account, signer, signerPK); + } + + function test_ShouldRevertIfValidatorIsAnAccount_GenericWriteTrue() public { + vm.prank(signer); + accounts.createAccount(); + vm.expectRevert("Cannot re-authorize address or locked gold account for another account"); + bytes32 _role = getRole(Role.Validator); + (uint8 _v, bytes32 _r, bytes32 _s) = getSignature(account, _role, signerPK, true); + authorizeSignerFactory(signer, _role, _v, _r, _s, true); + } + + function test_ShouldRevertIfValidatorIsAnAccount_GenericWriteFalse() public { + vm.prank(signer); + accounts.createAccount(); + vm.expectRevert("Cannot re-authorize address or locked gold account for another account"); + authorize(Role.Validator, false, account, signer, signerPK); + } + + function test_ShouldRevertIfAttestationIsAnAccount_GenericWriteTrue() public { + vm.prank(signer); + accounts.createAccount(); + vm.expectRevert("Cannot re-authorize address or locked gold account for another account"); + bytes32 _role = getRole(Role.Attestation); + (uint8 _v, bytes32 _r, bytes32 _s) = getSignature(account, _role, signerPK, true); + authorizeSignerFactory(signer, _role, _v, _r, _s, true); + } + + function test_ShouldRevertIfAttestationIsAnAccount_GenericWriteFalse() public { + vm.prank(signer); + accounts.createAccount(); + vm.expectRevert("Cannot re-authorize address or locked gold account for another account"); + authorize(Role.Attestation, false, account, signer, signerPK); + } + + function test_ShouldRevertIfVoteIsAlreadyAuthorized_GenericWriteFalse() public { + vm.prank(otherAccount); + accounts.createAccount(); + authorize(Role.Vote, true, otherAccount, signer, signerPK); + vm.expectRevert("Cannot re-authorize address or locked gold account for another account"); + + authorize(Role.Vote, false, account, signer, signerPK); + } + + function test_ShouldRevertIfVoteIsAlreadyAuthorized_GenericWriteTrue() public { + vm.prank(otherAccount); + accounts.createAccount(); + authorize(Role.Vote, true, otherAccount, signer, signerPK); + vm.expectRevert("Cannot re-authorize address or locked gold account for another account"); + bytes32 _role = getRole(Role.Vote); + (uint8 _v, bytes32 _r, bytes32 _s) = getSignature(account, _role, signerPK, true); + authorizeSignerFactory(signer, _role, _v, _r, _s, true); + } + + function test_ShouldRevertIfValidatorIsAlreadyAuthorized_GenericWriteFalse() public { + vm.prank(otherAccount); + accounts.createAccount(); + authorize(Role.Validator, true, otherAccount, signer, signerPK); + vm.expectRevert("Cannot re-authorize address or locked gold account for another account"); + + authorize(Role.Validator, false, account, signer, signerPK); + } + + function test_ShouldRevertIfValidatorIsAlreadyAuthorized_GenericWriteTrue() public { + vm.prank(otherAccount); + accounts.createAccount(); + authorize(Role.Validator, true, otherAccount, signer, signerPK); + vm.expectRevert("Cannot re-authorize address or locked gold account for another account"); + bytes32 _role = getRole(Role.Validator); + (uint8 _v, bytes32 _r, bytes32 _s) = getSignature(account, _role, signerPK, true); + authorizeSignerFactory(signer, _role, _v, _r, _s, true); + } + + function test_ShouldRevertIfAttestationIsAlreadyAuthorized_GenericWriteFalse() public { + vm.prank(otherAccount); + accounts.createAccount(); + authorize(Role.Attestation, true, otherAccount, signer, signerPK); + vm.expectRevert("Cannot re-authorize address or locked gold account for another account"); + + authorize(Role.Attestation, false, account, signer, signerPK); + } + + function test_ShouldRevertIfAttestationIsAlreadyAuthorized_GenericWriteTrue() public { + vm.prank(otherAccount); + accounts.createAccount(); + authorize(Role.Attestation, true, otherAccount, signer, signerPK); + vm.expectRevert("Cannot re-authorize address or locked gold account for another account"); + bytes32 _role = getRole(Role.Attestation); + (uint8 _v, bytes32 _r, bytes32 _s) = getSignature(account, _role, signerPK, true); + authorizeSignerFactory(signer, _role, _v, _r, _s, true); + } + + function helperShouldRevertIfSignatureIsIncorrect(Role role, bool genericWrite) public { + (, uint256 otherSignerPK) = actorWithPK("otherSigner"); + bytes32 _role = getRole(role); + (uint8 v, bytes32 r, bytes32 s) = getSignature(account, _role, otherSignerPK, genericWrite); + vm.expectRevert("Invalid signature"); + authorizeSignerFactory(signer, _role, v, r, s, true); + } + + function test_ShouldRevertIfSignatureIsIncorrect_Attestations_GenericWriteTrue() public { + helperShouldRevertIfSignatureIsIncorrect(Role.Attestation, true); + } + + function test_ShouldRevertIfSignatureIsIncorrect_Attestations_GenericWriteFalse() public { + helperShouldRevertIfSignatureIsIncorrect(Role.Attestation, false); + } + + function test_ShouldRevertIfSignatureIsIncorrect_Vote_GenericWriteTrue() public { + helperShouldRevertIfSignatureIsIncorrect(Role.Vote, true); + } + + function test_ShouldRevertIfSignatureIsIncorrect_Vote_GenericWriteFalse() public { + helperShouldRevertIfSignatureIsIncorrect(Role.Vote, false); + } + + function test_ShouldRevertIfSignatureIsIncorrect_Validator_GenericWriteTrue() public { + helperShouldRevertIfSignatureIsIncorrect(Role.Validator, true); + } + + function test_ShouldRevertIfSignatureIsIncorrect_Validator_GenericWriteFalse() public { + helperShouldRevertIfSignatureIsIncorrect(Role.Validator, false); + } + + function helperShouldSetTheNewAuthorized(Role role, bool genericWrite, bool genericRead) public { + authorize(role, genericWrite, account, signer, signerPK); + (address newAuthorized, uint256 newAuthorizedPK) = actorWithPK("otherSigner"); + authorize(role, genericWrite, account, newAuthorized, newAuthorizedPK); + + assertEq(accounts.authorizedBy(newAuthorized), account); + assertEq(getAuthorizedFromAccount(role, genericRead, account), newAuthorized); + assertEq(authorizedSignerToAccount(role, genericRead, newAuthorized), account); + assertEq(accounts.authorizedBy(signer), account); + } + + function test_ShouldSetTheNewAuthorized_WhenPreviousAuthorizationHasBeenMade_Attestations_GenericWriteTrue_GenericReadTrue() + public + { + helperShouldSetTheNewAuthorized(Role.Attestation, true, true); + } + + function test_ShouldSetTheNewAuthorized_WhenPreviousAuthorizationHasBeenMade_Attestations_GenericWriteTrue_GenericReadFalse() + public + { + helperShouldSetTheNewAuthorized(Role.Attestation, true, false); + } + + function test_ShouldSetTheNewAuthorized_WhenPreviousAuthorizationHasBeenMade_Attestations_GenericWriteFalse_GenericReadTrue() + public + { + helperShouldSetTheNewAuthorized(Role.Attestation, false, true); + } + + function test_ShouldSetTheNewAuthorized_WhenPreviousAuthorizationHasBeenMade_Attestations_GenericWriteFalse_GenericReadFalse() + public + { + helperShouldSetTheNewAuthorized(Role.Attestation, false, false); + } + + function test_ShouldSetTheNewAuthorized_WhenPreviousAuthorizationHasBeenMade_Vote_GenericWriteTrue_GenericReadTrue() + public + { + helperShouldSetTheNewAuthorized(Role.Vote, true, true); + } + + function test_ShouldSetTheNewAuthorized_WhenPreviousAuthorizationHasBeenMade_Vote_GenericWriteTrue_GenericReadFalse() + public + { + helperShouldSetTheNewAuthorized(Role.Vote, true, false); + } + + function test_ShouldSetTheNewAuthorized_WhenPreviousAuthorizationHasBeenMade_Vote_GenericWriteFalse_GenericReadTrue() + public + { + helperShouldSetTheNewAuthorized(Role.Vote, false, true); + } + + function test_ShouldSetTheNewAuthorized_WhenPreviousAuthorizationHasBeenMade_Vote_GenericWriteFalse_GenericReadFalse() + public + { + helperShouldSetTheNewAuthorized(Role.Vote, false, false); + } + + function test_ShouldSetTheNewAuthorized_WhenPreviousAuthorizationHasBeenMade_Validator_GenericWriteTrue_GenericReadTrue() + public + { + helperShouldSetTheNewAuthorized(Role.Validator, true, true); + } + + function test_ShouldSetTheNewAuthorized_WhenPreviousAuthorizationHasBeenMade_Validator_GenericWriteTrue_GenericReadFalse() + public + { + helperShouldSetTheNewAuthorized(Role.Validator, true, false); + } + + function test_ShouldSetTheNewAuthorized_WhenPreviousAuthorizationHasBeenMade_Validator_GenericWriteFalse_GenericReadTrue() + public + { + helperShouldSetTheNewAuthorized(Role.Validator, false, true); + } + + function test_ShouldSetTheNewAuthorized_WhenPreviousAuthorizationHasBeenMade_Validator_GenericWriteFalse_GenericReadFalse() + public + { + helperShouldSetTheNewAuthorized(Role.Validator, false, false); + } + + function helperShouldReturnCorrectValues_WhenAccountHasNotAuthorized(Role role, bool genericRead) + public + { + assertEq(authorizedSignerToAccount(role, genericRead, account), account); + + vm.expectRevert("Must first register address with Account.createAccount"); + authorizedSignerToAccount(role, genericRead, otherAccount); + + assertEq(getAuthorizedFromAccount(role, genericRead, account), account); + } + + function test_ShouldReturnCorrectValues_WhenAccountHasNotAuthorized_Attestation_GenericReadTrue() + public + { + helperShouldReturnCorrectValues_WhenAccountHasNotAuthorized(Role.Attestation, true); + } + + function test_ShouldReturnCorrectValues_WhenAccountHasNotAuthorized_Attestation_GenericReadFalse() + public + { + helperShouldReturnCorrectValues_WhenAccountHasNotAuthorized(Role.Attestation, false); + } + + function test_ShouldReturnCorrectValues_WhenAccountHasNotAuthorized_Vote_GenericReadTrue() + public + { + helperShouldReturnCorrectValues_WhenAccountHasNotAuthorized(Role.Vote, true); + } + + function test_ShouldReturnCorrectValues_WhenAccountHasNotAuthorized_Vote_GenericReadFalse() + public + { + helperShouldReturnCorrectValues_WhenAccountHasNotAuthorized(Role.Vote, false); + } + + function test_ShouldReturnCorrectValues_WhenAccountHasNotAuthorized_Validator_GenericReadTrue() + public + { + helperShouldReturnCorrectValues_WhenAccountHasNotAuthorized(Role.Validator, true); + } + + function test_ShouldReturnCorrectValues_WhenAccountHasNotAuthorized_Validator_GenericReadFalse() + public + { + helperShouldReturnCorrectValues_WhenAccountHasNotAuthorized(Role.Validator, false); + } + + function helperShouldReturnCorrectValues_WhenAccountHasAuthorized( + Role role, + bool genericRead, + bool genericWrite + ) public { + assertEq(authorizedSignerToAccount(role, genericRead, account), account); + + authorize(role, genericWrite, account, signer, signerPK); + assertEq(authorizedSignerToAccount(role, genericRead, signer), account); + assertEq(getAuthorizedFromAccount(role, genericRead, account), signer); + } + + function test_ShouldReturnCorrectValues_WhenAccountHasAuthorized_Attestation_GenericReadTrue_GenericWriteTrue() + public + { + helperShouldReturnCorrectValues_WhenAccountHasAuthorized(Role.Attestation, true, true); + } + + function test_ShouldReturnCorrectValues_WhenAccountHasAuthorized_Attestation_GenericReadFalse_GenericWriteTrue() + public + { + helperShouldReturnCorrectValues_WhenAccountHasAuthorized(Role.Attestation, false, true); + } + + function test_ShouldReturnCorrectValues_WhenAccountHasAuthorized_Attestation_GenericReadTrue_GenericWriteFalse() + public + { + helperShouldReturnCorrectValues_WhenAccountHasAuthorized(Role.Attestation, true, false); + } + + function test_ShouldReturnCorrectValues_WhenAccountHasAuthorized_Attestation_GenericReadFalse_GenericWriteFalse() + public + { + helperShouldReturnCorrectValues_WhenAccountHasAuthorized(Role.Attestation, false, false); + } + + function test_ShouldReturnCorrectValues_WhenAccountHasAuthorized_Vote_GenericReadTrue_GenericWriteTrue() + public + { + helperShouldReturnCorrectValues_WhenAccountHasAuthorized(Role.Vote, true, true); + } + + function test_ShouldReturnCorrectValues_WhenAccountHasAuthorized_Vote_GenericReadFalse_GenericWriteTrue() + public + { + helperShouldReturnCorrectValues_WhenAccountHasAuthorized(Role.Vote, false, true); + } + + function test_ShouldReturnCorrectValues_WhenAccountHasAuthorized_Vote_GenericReadTrue_GenericWriteFalse() + public + { + helperShouldReturnCorrectValues_WhenAccountHasAuthorized(Role.Vote, true, false); + } + + function test_ShouldReturnCorrectValues_WhenAccountHasAuthorized_Vote_GenericReadFalse_GenericWriteFalse() + public + { + helperShouldReturnCorrectValues_WhenAccountHasAuthorized(Role.Vote, false, false); + } + + function test_ShouldReturnCorrectValues_WhenAccountHasAuthorized_Validator_GenericReadTrue_GenericWriteTrue() + public + { + helperShouldReturnCorrectValues_WhenAccountHasAuthorized(Role.Validator, true, true); + } + + function test_ShouldReturnCorrectValues_WhenAccountHasAuthorized_Validator_GenericReadFalse_GenericWriteTrue() + public + { + helperShouldReturnCorrectValues_WhenAccountHasAuthorized(Role.Validator, false, true); + } + + function test_ShouldReturnCorrectValues_WhenAccountHasAuthorized_Validator_GenericReadTrue_GenericWriteFalse() + public + { + helperShouldReturnCorrectValues_WhenAccountHasAuthorized(Role.Validator, true, false); + } + + function test_ShouldReturnCorrectValues_WhenAccountHasAuthorized_Validator_GenericReadFalse_GenericWriteFalse() + public + { + helperShouldReturnCorrectValues_WhenAccountHasAuthorized(Role.Validator, false, false); + } + + function helper_ShouldRemoveSigner(Role role, bool genericRead, bool genericWrite) public { + authorize(role, genericWrite, account, signer, signerPK); + assertEq(hasAuthorizedSigner(role, account, genericRead), true, "No authorized signer"); + assertEq( + getAuthorizedFromAccount(role, genericRead, account), + signer, + "authorized from account" + ); + + removeSigner(genericWrite, role, account); + + assertEq(hasAuthorizedSigner(role, account, genericRead), false, "Authorized signer"); + assertEq(getAuthorizedFromAccount(role, genericRead, account), account); + } + + function test_ShouldRemoveSigner_Attestations_GenericReadTrue_GenericWriteTrue() public { + helper_ShouldRemoveSigner(Role.Attestation, true, true); + } + + function test_ShouldRemoveSigner_Attestations_GenericReadFalse_GenericWriteTrue() public { + helper_ShouldRemoveSigner(Role.Attestation, false, true); + } + + function test_ShouldRemoveSigner_Attestations_GenericReadTrue_GenericWriteFalse() public { + helper_ShouldRemoveSigner(Role.Attestation, true, false); + } + + function test_ShouldRemoveSigner_Attestations_GenericReadFalse_GenericWriteFalse() public { + helper_ShouldRemoveSigner(Role.Attestation, false, true); + } + + function test_ShouldRemoveSigner_Vote_GenericReadTrue_GenericWriteTrue() public { + helper_ShouldRemoveSigner(Role.Vote, true, true); + } + + function test_ShouldRemoveSigner_Vote_GenericReadFalse_GenericWriteTrue() public { + helper_ShouldRemoveSigner(Role.Vote, false, true); + } + + function test_ShouldRemoveSigner_Vote_GenericReadTrue_GenericWriteFalse() public { + helper_ShouldRemoveSigner(Role.Vote, true, false); + } + + function test_ShouldRemoveSigner_Vote_GenericReadFalse_GenericWriteFalse() public { + helper_ShouldRemoveSigner(Role.Vote, false, true); + } + + function test_ShouldRemoveSigner_Validator_GenericReadTrue_GenericWriteTrue() public { + helper_ShouldRemoveSigner(Role.Validator, true, true); + } + + function test_ShouldRemoveSigner_Validator_GenericReadFalse_GenericWriteTrue() public { + helper_ShouldRemoveSigner(Role.Validator, false, true); + } + + function test_ShouldRemoveSigner_Validator_GenericReadTrue_GenericWriteFalse() public { + helper_ShouldRemoveSigner(Role.Validator, true, false); + } + + function test_ShouldRemoveSigner_Validator_GenericReadFalse_GenericWriteFalse() public { + helper_ShouldRemoveSigner(Role.Validator, false, true); + } +} diff --git a/packages/protocol/test-sol/GoldToken.t.sol b/packages/protocol/test-sol/common/GoldToken.t.sol similarity index 98% rename from packages/protocol/test-sol/GoldToken.t.sol rename to packages/protocol/test-sol/common/GoldToken.t.sol index 1869aa75466..7c8967ff986 100644 --- a/packages/protocol/test-sol/GoldToken.t.sol +++ b/packages/protocol/test-sol/common/GoldToken.t.sol @@ -3,8 +3,8 @@ pragma solidity ^0.5.13; import "celo-foundry/Test.sol"; import "forge-std/console.sol"; -import "../contracts/common/GoldToken.sol"; -import "../contracts/common/test/MockGoldToken.sol"; +import "../../contracts/common/GoldToken.sol"; +import "../../contracts/common/test/MockGoldToken.sol"; contract GoldTokenTest is Test { GoldToken goldToken; diff --git a/packages/protocol/test-sol/IdentityProxy.t.sol b/packages/protocol/test-sol/identity/IdentityProxy.t.sol similarity index 91% rename from packages/protocol/test-sol/IdentityProxy.t.sol rename to packages/protocol/test-sol/identity/IdentityProxy.t.sol index 57c92d322bd..683293352e4 100644 --- a/packages/protocol/test-sol/IdentityProxy.t.sol +++ b/packages/protocol/test-sol/identity/IdentityProxy.t.sol @@ -3,8 +3,8 @@ pragma solidity ^0.5.13; import "celo-foundry/Test.sol"; import "forge-std/console.sol"; -import "../contracts/identity/IdentityProxy.sol"; -import "../contracts/identity/test/IdentityProxyTest.sol"; +import "../../contracts/identity/IdentityProxy.sol"; +import "../../contracts/identity/test/IdentityProxyTest.sol"; contract IdentityProxyTestFoundry is Test { IdentityProxy identityProxy; diff --git a/packages/protocol/test-sol/IdentityProxyHub.t.sol b/packages/protocol/test-sol/identity/IdentityProxyHub.t.sol similarity index 96% rename from packages/protocol/test-sol/IdentityProxyHub.t.sol rename to packages/protocol/test-sol/identity/IdentityProxyHub.t.sol index ea6ce490694..de2aff9b2df 100644 --- a/packages/protocol/test-sol/IdentityProxyHub.t.sol +++ b/packages/protocol/test-sol/identity/IdentityProxyHub.t.sol @@ -3,11 +3,11 @@ pragma solidity ^0.5.13; import "celo-foundry/Test.sol"; import "forge-std/console.sol"; -import "../contracts/identity/IdentityProxy.sol"; -import "../contracts/identity/IdentityProxyHub.sol"; -import "../contracts/identity/test/IdentityProxyTest.sol"; -import "../contracts/identity/test/MockAttestations.sol"; -import "../contracts/common/Registry.sol"; +import "../../contracts/identity/IdentityProxy.sol"; +import "../../contracts/identity/IdentityProxyHub.sol"; +import "../../contracts/identity/test/IdentityProxyTest.sol"; +import "../../contracts/identity/test/MockAttestations.sol"; +import "../../contracts/common/Registry.sol"; contract IdentityProxyHubTest is Test { IdentityProxy identityProxy; diff --git a/packages/protocol/test/common/accounts.ts b/packages/protocol/test/common/accounts.ts deleted file mode 100644 index b697d27f9b0..00000000000 --- a/packages/protocol/test/common/accounts.ts +++ /dev/null @@ -1,1049 +0,0 @@ -import { Address, NULL_ADDRESS } from '@celo/base/lib/address' -import { CeloContractName } from '@celo/protocol/lib/registry-utils' -import { getParsedSignatureOfAddress } from '@celo/protocol/lib/signing-utils' -import { - assertEqualBN, - assertLogMatches, - assertLogMatches2, - assertRevert, - assertTransactionRevertWithReason, -} from '@celo/protocol/lib/test-utils' -import { toFixed } from '@celo/utils/lib/fixidity' -import { parseSolidityStringArray } from '@celo/utils/lib/parsing' -import { authorizeSigner as buildAuthorizeSignerTypedData } from '@celo/utils/lib/typed-data-constructors' -import { generateTypedDataHash } from '@celo/utils/src/sign-typed-data-utils' -import { parseSignatureWithoutPrefix } from '@celo/utils/src/signatureUtils' -import { bufferToHex } from '@ethereumjs/util' -import BigNumber from 'bignumber.js' -import { - AccountsContract, - AccountsInstance, - MockValidatorsContract, - MockValidatorsInstance, - RegistryContract, -} from 'types' -import { keccak256 } from 'web3-utils' - -const Accounts: AccountsContract = artifacts.require('Accounts') -const Registry: RegistryContract = artifacts.require('Registry') -const MockValidators: MockValidatorsContract = artifacts.require('MockValidators') - -const assertStorageRoots = (rootsHex: string, lengths: BigNumber[], expectedRoots: string[]) => { - assert.equal(lengths.length, expectedRoots.length) - const roots = web3.utils.hexToUtf8(rootsHex) - let currentIndex = 0 - expectedRoots.forEach((expectedRoot: string, i: number) => { - const root = roots.slice(currentIndex, currentIndex + lengths[i].toNumber()) - currentIndex += lengths[i].toNumber() - assert.equal(root, expectedRoot) - }) - assert.equal(roots.length, currentIndex) -} - -contract('Accounts', (accounts: string[]) => { - let accountsInstance: AccountsInstance - let mockValidators: MockValidatorsInstance - const account = accounts[0] - const caller = accounts[0] - - const name = 'Account' - const metadataURL = 'https://www.celo.org' - const otherMetadataURL = 'https://clabs.co' - const storageRoot = web3.utils.utf8ToHex(metadataURL) - const otherStorageRoot = web3.utils.utf8ToHex(otherMetadataURL) - const dataEncryptionKey = '0x02f2f48ee19680706196e2e339e5da3491186e0c4c5030670656b0e01611111111' - const longDataEncryptionKey = - '0x04f2f48ee19680706196e2e339e5da3491186e0c4c5030670656b0e01611111111' + - '02f2f48ee19680706196e2e339e5da3491186e0c4c5030670656b0e01611111111' - - beforeEach(async () => { - accountsInstance = await Accounts.new(true, { from: account }) - mockValidators = await MockValidators.new() - const registry = await Registry.new(true) - await registry.setAddressFor(CeloContractName.Validators, mockValidators.address) - await registry.setAddressFor(CeloContractName.Accounts, accountsInstance.address) - await accountsInstance.initialize(registry.address) - await accountsInstance.setEip712DomainSeparator() - }) - - describe('#createAccount', () => { - it('creates the account', async () => { - let isAccount = await accountsInstance.isAccount(account) - assert.isFalse(isAccount) - await accountsInstance.createAccount() - isAccount = await accountsInstance.isAccount(account) - assert.isTrue(isAccount) - }) - - it('emits an AccountCreated event', async () => { - const resp = await accountsInstance.createAccount() - assertLogMatches2(resp.logs[0], { - event: 'AccountCreated', - args: { account }, - }) - }) - }) - - describe('#setAccountDataEncryptionKey()', () => { - it('should set dataEncryptionKey', async () => { - await accountsInstance.setAccountDataEncryptionKey(dataEncryptionKey) - const fetchedKey: string = await accountsInstance.getDataEncryptionKey(caller) - assert.equal(fetchedKey, dataEncryptionKey) - }) - - it('should allow setting a key with leading zeros', async () => { - const keyWithZeros = '0x00000000000000000000000000000000000000000000000f2f48ee19680706191111' - await accountsInstance.setAccountDataEncryptionKey(keyWithZeros) - const fetchedKey: string = await accountsInstance.getDataEncryptionKey(caller) - assert.equal(fetchedKey, keyWithZeros) - }) - - it('should revert when the key is invalid', async () => { - await assertTransactionRevertWithReason( - accountsInstance.setAccountDataEncryptionKey('0x32132931293'), - 'data encryption key length <= 32' - ) - }) - - it('should allow a key that is longer than 33 bytes', async () => { - await accountsInstance.setAccountDataEncryptionKey(longDataEncryptionKey) - const fetchedKey: string = await accountsInstance.getDataEncryptionKey(caller) - assert.equal(fetchedKey, longDataEncryptionKey) - }) - - it('should emit the AccountDataEncryptionKeySet event', async () => { - const response = await accountsInstance.setAccountDataEncryptionKey(dataEncryptionKey) - assert.lengthOf(response.logs, 1) - const event = response.logs[0] - assertLogMatches2(event, { - event: 'AccountDataEncryptionKeySet', - args: { account: caller, dataEncryptionKey }, - }) - }) - }) - - describe('#setAccount', () => { - describe('when the account has been created', () => { - beforeEach(async () => { - await accountsInstance.createAccount() - }) - - it('should set the name, dataEncryptionKey and walletAddress', async () => { - await accountsInstance.setAccount(name, dataEncryptionKey, caller, '0x0', '0x0', '0x0') - const expectedWalletAddress = await accountsInstance.getWalletAddress(caller) - assert.equal(expectedWalletAddress, caller) - const expectedKey = await accountsInstance.getDataEncryptionKey(caller) - assert.equal(expectedKey, dataEncryptionKey) - const expectedName = await accountsInstance.getName(caller) - assert.equal(expectedName, name) - }) - - it('emits the AccountNameSet event', async () => { - const resp = await accountsInstance.setAccount( - name, - dataEncryptionKey, - caller, - '0x0', - '0x0', - '0x0' - ) - assertLogMatches2(resp.logs[0], { - event: 'AccountNameSet', - args: { account: caller, name }, - }) - }) - - it('emits the AccountDataEncryptionKeySet event', async () => { - const resp = await accountsInstance.setAccount( - name, - dataEncryptionKey, - caller, - '0x0', - '0x0', - '0x0' - ) - assertLogMatches2(resp.logs[1], { - event: 'AccountDataEncryptionKeySet', - args: { account: caller, dataEncryptionKey }, - }) - }) - - it('emits the AccountWalletAddressSet event', async () => { - const resp = await accountsInstance.setAccount( - name, - dataEncryptionKey, - caller, - '0x0', - '0x0', - '0x0' - ) - assertLogMatches2(resp.logs[2], { - event: 'AccountWalletAddressSet', - args: { account: caller, walletAddress: caller }, - }) - }) - }) - - describe('when the account has not yet been created', () => { - it('should set the name, dataEncryptionKey and walletAddress', async () => { - await accountsInstance.setAccount(name, dataEncryptionKey, caller, '0x0', '0x0', '0x0') - const expectedWalletAddress = await accountsInstance.getWalletAddress(caller) - assert.equal(expectedWalletAddress, caller) - const expectedKey = await accountsInstance.getDataEncryptionKey(caller) - assert.equal(expectedKey, dataEncryptionKey) - const expectedName = await accountsInstance.getName(caller) - assert.equal(expectedName, name) - const isAccount = await accountsInstance.isAccount(caller) - assert.isTrue(isAccount) - }) - - it('should set a different address with the appropriate signature', async () => { - const sig = await getParsedSignatureOfAddress(web3, account, accounts[1]) - await accountsInstance.setAccount(name, dataEncryptionKey, accounts[1], sig.v, sig.r, sig.s) - const result = await accountsInstance.getWalletAddress(caller) - assert.equal(result, accounts[1]) - }) - - it('emits the AccountCreated event', async () => { - const resp = await accountsInstance.setAccount( - name, - dataEncryptionKey, - caller, - '0x0', - '0x0', - '0x0' - ) - assertLogMatches2(resp.logs[0], { - event: 'AccountCreated', - args: { account: caller }, - }) - }) - - it('emits the AccountNameSet event', async () => { - const resp = await accountsInstance.setAccount( - name, - dataEncryptionKey, - caller, - '0x0', - '0x0', - '0x0' - ) - assertLogMatches2(resp.logs[1], { - event: 'AccountNameSet', - args: { account: caller, name }, - }) - }) - - it('emits the AccountDataEncryptionKeySet event', async () => { - const resp = await accountsInstance.setAccount( - name, - dataEncryptionKey, - caller, - '0x0', - '0x0', - '0x0' - ) - assertLogMatches2(resp.logs[2], { - event: 'AccountDataEncryptionKeySet', - args: { account: caller, dataEncryptionKey }, - }) - }) - - it('emits the AccountWalletAddressSet event', async () => { - const resp = await accountsInstance.setAccount( - name, - dataEncryptionKey, - caller, - '0x0', - '0x0', - '0x0' - ) - assertLogMatches2(resp.logs[3], { - event: 'AccountWalletAddressSet', - args: { account: caller, walletAddress: caller }, - }) - }) - - it('should set a revert with the wrong signature for a different address', async () => { - const sig = await getParsedSignatureOfAddress(web3, account, accounts[1]) - await assertTransactionRevertWithReason( - accountsInstance.setAccount(name, dataEncryptionKey, accounts[2], sig.v, sig.r, sig.s), - 'Invalid signature' - ) - }) - }) - }) - - describe('#setWalletAddress', () => { - describe('when the account has not been created', () => { - it('should revert', async () => { - await assertTransactionRevertWithReason( - accountsInstance.setWalletAddress(caller, '0x0', '0x0', '0x0'), - 'Unknown account' - ) - }) - }) - - describe('when the account has been created', () => { - beforeEach(async () => { - await accountsInstance.createAccount() - }) - - it('should set the walletAddress', async () => { - await accountsInstance.setWalletAddress(caller, '0x0', '0x0', '0x0') - const result = await accountsInstance.getWalletAddress(caller) - assert.equal(result, caller) - }) - - it('should set a different address with the appropriate signature', async () => { - const sig = await getParsedSignatureOfAddress(web3, account, accounts[1]) - await accountsInstance.setWalletAddress(accounts[1], sig.v, sig.r, sig.s) - const result = await accountsInstance.getWalletAddress(caller) - assert.equal(result, accounts[1]) - }) - - it('should set the NULL_ADDRESS', async () => { - await accountsInstance.setWalletAddress(NULL_ADDRESS, '0x0', '0x0', '0x0') - const result = await accountsInstance.getWalletAddress(caller) - assert.equal(result, NULL_ADDRESS) - }) - - it('should emit the AccountWalletAddressSet event', async () => { - const response = await accountsInstance.setWalletAddress(caller, '0x0', '0x0', '0x0') - assert.lengthOf(response.logs, 1) - const event = response.logs[0] - assertLogMatches2(event, { - event: 'AccountWalletAddressSet', - args: { account: caller, walletAddress: caller }, - }) - }) - - it('should set a revert with the wrong signature for a different address', async () => { - const sig = await getParsedSignatureOfAddress(web3, account, accounts[1]) - await assertTransactionRevertWithReason( - accountsInstance.setWalletAddress(accounts[2], sig.v, sig.r, sig.s), - 'Invalid signature' - ) - }) - }) - }) - - describe('#setMetadataURL', () => { - describe('when the account has not been created', () => { - it('should revert', async () => { - await assertTransactionRevertWithReason( - accountsInstance.setMetadataURL(caller), - 'Unknown account' - ) - }) - }) - - describe('when the account has been created', () => { - beforeEach(async () => { - await accountsInstance.createAccount() - }) - - it('should set the metadataURL', async () => { - await accountsInstance.setMetadataURL(metadataURL) - const result = await accountsInstance.getMetadataURL(caller) - assert.equal(result, metadataURL) - }) - - it('should emit the AccountMetadataURLSet event', async () => { - const response = await accountsInstance.setMetadataURL(metadataURL) - assert.lengthOf(response.logs, 1) - const event = response.logs[0] - assertLogMatches2(event, { - event: 'AccountMetadataURLSet', - args: { account: caller, metadataURL }, - }) - }) - }) - }) - - describe('#batchGetMetadataURL', () => { - it('returns multiple metadata URLs', async () => { - const randomStrings = accounts.map((_) => web3.utils.randomHex(20).slice(2)) - - for (let i = 0; i < accounts.length; i++) { - await accountsInstance.createAccount({ from: accounts[i] }) - await accountsInstance.setMetadataURL(randomStrings[i], { from: accounts[i] }) - } - - const [stringLengths, data] = await accountsInstance.batchGetMetadataURL(accounts) - const strings = parseSolidityStringArray( - stringLengths.map((x) => x.toNumber()), - data as unknown as string - ) - for (let i = 0; i < accounts.length; i++) { - assert.equal(strings[i], randomStrings[i]) - } - }) - }) - - describe('#addStorageRoot', () => { - describe('when the account has not been created', () => { - it('should revert', async () => { - await assertTransactionRevertWithReason( - accountsInstance.addStorageRoot(storageRoot), - 'Unknown account' - ) - }) - }) - - describe('when the account has been created', () => { - beforeEach(async () => { - await accountsInstance.createAccount() - }) - - it('adds a new storage root', async () => { - await accountsInstance.addStorageRoot(storageRoot) - const [rootsHex, lengths] = await accountsInstance.getOffchainStorageRoots(accounts[0]) - assertStorageRoots(rootsHex, lengths, [metadataURL]) - }) - - it('should emit the OffchainStorageRootAdded event', async () => { - const response = await accountsInstance.addStorageRoot(storageRoot) - assert.lengthOf(response.logs, 1) - const event = response.logs[0] - assertLogMatches2(event, { - event: 'OffchainStorageRootAdded', - args: { account: caller, url: storageRoot }, - }) - }) - - it('can add multiple storage roots', async () => { - await accountsInstance.addStorageRoot(storageRoot) - await accountsInstance.addStorageRoot(otherStorageRoot) - const [rootsHex, lengths] = await accountsInstance.getOffchainStorageRoots(accounts[0]) - assertStorageRoots(rootsHex, lengths, [metadataURL, otherMetadataURL]) - }) - }) - }) - - describe('#removeStorageRoot', () => { - describe('when the account has not been created', () => { - it('should revert', async () => { - await assertTransactionRevertWithReason( - accountsInstance.removeStorageRoot(0), - 'Unknown account' - ) - }) - }) - - describe('when the account has been created', () => { - beforeEach(async () => { - await accountsInstance.createAccount() - }) - - describe('when there are no storage roots', async () => { - it('should revert with message', async () => { - await assertTransactionRevertWithReason( - accountsInstance.removeStorageRoot(0), - 'Invalid storage root index' - ) - }) - }) - - describe('when there are storage roots', async () => { - beforeEach(async () => { - await accountsInstance.addStorageRoot(storageRoot) - await accountsInstance.addStorageRoot(otherStorageRoot) - }) - - it('should remove one of the storage roots', async () => { - await accountsInstance.removeStorageRoot(0) - const [rootsHex, lengths] = await accountsInstance.getOffchainStorageRoots(accounts[0]) - assertStorageRoots(rootsHex, lengths, [otherMetadataURL]) - }) - - it('should remove a different storage root', async () => { - await accountsInstance.removeStorageRoot(1) - const [rootsHex, lengths] = await accountsInstance.getOffchainStorageRoots(accounts[0]) - assertStorageRoots(rootsHex, lengths, [metadataURL]) - }) - - it('should emit the OffchainStorageRootRemoved event', async () => { - const response = await accountsInstance.removeStorageRoot(0) - assert.lengthOf(response.logs, 1) - const event = response.logs[0] - assertLogMatches2(event, { - event: 'OffchainStorageRootRemoved', - args: { account: caller, url: storageRoot, index: 0 }, - }) - }) - }) - }) - }) - - describe('#setPaymentDelegation', () => { - const beneficiary = accounts[1] - const fraction = toFixed(0.2) - const badFraction = toFixed(1.2) - - it('should not be callable by a non-account', async () => { - await assertTransactionRevertWithReason( - accountsInstance.setPaymentDelegation(beneficiary, fraction), - 'Must first register address with Account.createAccount' - ) - }) - - describe('when an account has been created', () => { - beforeEach(async () => { - await accountsInstance.createAccount() - }) - - it('should set an address and a fraction', async () => { - await accountsInstance.setPaymentDelegation(beneficiary, fraction) - const [realBeneficiary, realFraction] = await accountsInstance.getPaymentDelegation.call( - accounts[0] - ) - assert.equal(realBeneficiary, beneficiary) - assertEqualBN(realFraction, fraction) - }) - - it('should not allow a fraction greater than 1', async () => { - await assertTransactionRevertWithReason( - accountsInstance.setPaymentDelegation(beneficiary, badFraction), - 'Fraction must not be greater than 1' - ) - }) - - it('should not allow a beneficiary with address 0x0', async () => { - await assertTransactionRevertWithReason( - accountsInstance.setPaymentDelegation(NULL_ADDRESS, fraction), - 'Beneficiary cannot be address 0x0' - ) - }) - - it('emits a PaymentDelegationSet event', async () => { - const resp = await accountsInstance.setPaymentDelegation(beneficiary, fraction) - assertLogMatches2(resp.logs[0], { - event: 'PaymentDelegationSet', - args: { beneficiary, fraction }, - }) - }) - }) - }) - - describe('#deletePaymentDelegation', () => { - const beneficiary = accounts[1] - const fraction = toFixed(0.2) - - beforeEach(async () => { - await accountsInstance.createAccount() - await accountsInstance.setPaymentDelegation(beneficiary, fraction) - }) - - it('should not be callable by a non-account', async () => { - await assertTransactionRevertWithReason( - accountsInstance.setPaymentDelegation(beneficiary, fraction, { from: accounts[2] }), - 'Must first register address with Account.createAccount' - ) - }) - - it('should set the address and beneficiary to 0', async () => { - await accountsInstance.deletePaymentDelegation() - const [realBeneficiary, realFraction] = await accountsInstance.getPaymentDelegation.call( - accounts[0] - ) - assert.equal(realBeneficiary, NULL_ADDRESS) - assertEqualBN(realFraction, new BigNumber(0)) - }) - - it('emits a PaymentDelegationSet event', async () => { - const resp = await accountsInstance.deletePaymentDelegation() - assertLogMatches2(resp.logs[0], { - event: 'PaymentDelegationSet', - args: { beneficiary: NULL_ADDRESS, fraction: new BigNumber(0) }, - }) - }) - }) - - describe('#setName', () => { - describe('when the account has not been created', () => { - it('should revert', async () => { - await assertTransactionRevertWithReason( - accountsInstance.setWalletAddress(caller, '0x0', '0x0', '0x0'), - 'Unknown account' - ) - }) - }) - - describe('when the account has been created', () => { - beforeEach(async () => { - await accountsInstance.createAccount() - }) - - it('should set the name', async () => { - await accountsInstance.setName(name) - const result = await accountsInstance.getName(caller) - assert.equal(result, name) - }) - - it('should emit the AccountNameSet event', async () => { - const response = await accountsInstance.setName(name) - assert.lengthOf(response.logs, 1) - const event = response.logs[0] - assertLogMatches2(event, { - event: 'AccountNameSet', - args: { account: caller, name }, - }) - }) - }) - }) - - const getSignatureForAuthorization = async ( - _account: Address, - signer: Address, - role: string, - accountsContractAddress: string - ) => { - const chainID = await web3.eth.getChainId() - const typedData = buildAuthorizeSignerTypedData({ - account: _account, - signer, - chainId: chainID, - role, - accountsContractAddress, - }) - - const signature = await web3.currentProvider.request({ - method: 'eth_signTypedData', - params: [signer, typedData], - }) - - const messageHash = bufferToHex(generateTypedDataHash(typedData)) - const parsedSignature = parseSignatureWithoutPrefix(messageHash, signature, signer) - return parsedSignature - } - - describe('generic authorization', () => { - const account2 = accounts[1] - const signer = accounts[2] - const signer2 = accounts[3] - const role = keccak256('Test Role') - const role2 = keccak256('Test Role 2') - let sig - - beforeEach(async () => { - sig = await getSignatureForAuthorization(account, signer, role, accountsInstance.address) - await accountsInstance.createAccount() - await accountsInstance.createAccount({ from: account2 }) - }) - - it('should recover the correct signer from EIP712 signature', async () => { - const recoveredSigner = await accountsInstance.getRoleAuthorizationSigner( - account, - signer, - role, - sig.v, - sig.r, - sig.s - ) - expect(signer).to.be.equal(recoveredSigner) - }) - - describe('smart contract signers', async () => { - it("can't complete an authorization that hasn't been started", async () => { - await assertTransactionRevertWithReason( - accountsInstance.completeSignerAuthorization(account, role, { from: signer }), - 'Signer authorization not started' - ) - }) - - it('starting the authorization does not complete it', async () => { - await accountsInstance.authorizeSigner(signer, role) - assert.isFalse(await accountsInstance.isSigner(account, signer, role)) - }) - - it('should set the authorized signer in two steps', async () => { - await accountsInstance.authorizeSigner(signer, role) - await accountsInstance.completeSignerAuthorization(account, role, { from: signer }) - - assert.isTrue(await accountsInstance.isSigner(account, signer, role)) - assert.equal(await accountsInstance.authorizedBy(signer), account) - assert.isTrue(await accountsInstance.isAuthorizedSigner(signer)) - }) - - it(`should emit the right event`, async () => { - const { logs: startLogs } = await accountsInstance.authorizeSigner(signer, role) - const { logs: completeLogs } = await accountsInstance.completeSignerAuthorization( - account, - role, - { - from: signer, - } - ) - - assert.equal(startLogs.length, 1) - assertLogMatches(startLogs[0], 'SignerAuthorizationStarted', { account, signer, role }) - - assert.equal(completeLogs.length, 1) - assertLogMatches(completeLogs[0], 'SignerAuthorizationCompleted', { account, signer, role }) - }) - }) - - describe('EOA signers', async () => { - it('should set the authorized signer in one step with signature', async () => { - assert.isFalse(await accountsInstance.isSigner(account, signer, role)) - await accountsInstance.authorizeSignerWithSignature(signer, role, sig.v, sig.r, sig.s) - - assert.isTrue(await accountsInstance.isSigner(account, signer, role)) - assert.equal(await accountsInstance.authorizedBy(signer), account) - assert.isTrue(await accountsInstance.isAuthorizedSigner(signer)) - }) - - it(`should emit the right event`, async () => { - const resp = await accountsInstance.authorizeSignerWithSignature( - signer, - role, - sig.v, - sig.r, - sig.s - ) - assert.equal(resp.logs.length, 1) - const log = resp.logs[0] - const expected = { account, signer, role } - assertLogMatches(log, 'SignerAuthorized', expected) - }) - }) - - it('should remove the authorized signer', async () => { - await accountsInstance.authorizeSignerWithSignature(signer, role, sig.v, sig.r, sig.s) - await accountsInstance.removeSigner(signer, role) - assert.isFalse(await accountsInstance.isSigner(account, signer, role)) - }) - - it('can authorize multiple signers for a role', async () => { - assert.isFalse(await accountsInstance.isSigner(account, signer, role)) - assert.isFalse(await accountsInstance.isSigner(account, signer2, role)) - - const sigTwo = await getSignatureForAuthorization( - account, - signer2, - role, - accountsInstance.address - ) - - await accountsInstance.authorizeSignerWithSignature(signer, role, sig.v, sig.r, sig.s) - await accountsInstance.authorizeSignerWithSignature( - signer2, - role, - sigTwo.v, - sigTwo.r, - sigTwo.s - ) - - assert.isTrue(await accountsInstance.isSigner(account, signer, role)) - assert.isTrue(await accountsInstance.isSigner(account, signer2, role)) - assert.equal(await accountsInstance.authorizedBy(signer), account) - assert.equal(await accountsInstance.authorizedBy(signer2), account) - assert.isTrue(await accountsInstance.isAuthorizedSigner(signer)) - assert.isTrue(await accountsInstance.isAuthorizedSigner(signer2)) - }) - - it('can authorize a signer for multiple roles', async () => { - assert.isFalse(await accountsInstance.isSigner(account, signer, role)) - assert.isFalse(await accountsInstance.isSigner(account, signer, role2)) - - const sigTwo = await getSignatureForAuthorization( - account, - signer, - role2, - accountsInstance.address - ) - await accountsInstance.authorizeSignerWithSignature(signer, role, sig.v, sig.r, sig.s) - await accountsInstance.authorizeSignerWithSignature( - signer, - role2, - sigTwo.v, - sigTwo.r, - sigTwo.s - ) - - assert.isTrue(await accountsInstance.isSigner(account, signer, role)) - assert.isTrue(await accountsInstance.isSigner(account, signer, role2)) - assert.equal(await accountsInstance.authorizedBy(signer), account) - assert.isTrue(await accountsInstance.isAuthorizedSigner(signer)) - }) - - it('signer cannot be authorized by two accounts', async () => { - const sigTwo = await getSignatureForAuthorization( - account2, - signer, - role, - accountsInstance.address - ) - await accountsInstance.authorizeSignerWithSignature(signer, role, sig.v, sig.r, sig.s) - await assertTransactionRevertWithReason( - accountsInstance.authorizeSignerWithSignature(signer, role, sigTwo.v, sigTwo.r, sigTwo.s), - 'Invalid signature' - ) - }) - - it('can set the default signer for a role', async () => { - assert.isFalse(await accountsInstance.isSigner(account, signer, role)) - assert.isFalse(await accountsInstance.hasDefaultSigner(account, role)) - assert.equal(await accountsInstance.getDefaultSigner(account, role), account) - - await assertTransactionRevertWithReason( - accountsInstance.setIndexedSigner(signer, role), - 'Must authorize signer before setting as default' - ) - await accountsInstance.authorizeSignerWithSignature(signer, role, sig.v, sig.r, sig.s) - await accountsInstance.setIndexedSigner(signer, role) - - assert.isTrue(await accountsInstance.isSigner(account, signer, role)) - assert.isTrue(await accountsInstance.hasDefaultSigner(account, role)) - assert.equal(await accountsInstance.getDefaultSigner(account, role), signer) - }) - - it('can remove the default signer for a role', async () => { - await accountsInstance.authorizeSignerWithSignature(signer, role, sig.v, sig.r, sig.s) - await accountsInstance.setIndexedSigner(signer, role) - await accountsInstance.removeDefaultSigner(role) - - assert.isTrue(await accountsInstance.isSigner(account, signer, role)) - assert.isFalse(await accountsInstance.hasDefaultSigner(account, role)) - assert.equal(await accountsInstance.getDefaultSigner(account, role), account) - }) - }) - - // backwards compatibility matrix for authorizeSigner instead - // of authorizeXXXSigner - const backwardsCompatibilityMatrix = [ - [false, false], - [false, true], - [true, false], - [true, true], - ] - backwardsCompatibilityMatrix.forEach(([genericRead, genericWrite]) => { - const scenarios = [ - { - keyName: 'Vote', - key: keccak256('celo.org/core/vote'), - description: 'vote signing key', - }, - { - keyName: 'Validator', - key: keccak256('celo.org/core/validator'), - description: 'validator signing key', - }, - { - keyName: 'Attestation', - key: keccak256('celo.org/core/attestation'), - description: 'attestation signing key', - }, - ] - - scenarios.forEach(({ keyName, key, description }) => { - describe(`${description} authorization tests (generic writes ${genericWrite} and generic reads ${genericRead})`, () => { - let testInstance: any - let getSignature - - beforeEach(async () => { - const authorizeSignerFactory = - (role: string) => - async (signer, v, r, s, ...rest) => { - const result1 = await accountsInstance.authorizeSignerWithSignature( - signer, - role, - v, - r, - s, - ...rest - ) - const result2 = await accountsInstance.setIndexedSigner(signer, role, ...rest) - return { - logs: [...result1.logs, ...result2.logs], - } - } - - getSignature = (_account, signer) => { - if (genericWrite) { - return getSignatureForAuthorization(_account, signer, key, accountsInstance.address) - } - return getParsedSignatureOfAddress(web3, _account, signer) - } - - testInstance = { - fn: genericWrite - ? authorizeSignerFactory(key) - : accountsInstance[`authorize${keyName}Signer`], - eventName: genericWrite ? 'SignerAuthorized' : `${keyName}SignerAuthorized`, - getAuthorizedFromAccount: genericRead - ? (...args) => accountsInstance.getIndexedSigner(args[0], key, ...args.slice(1)) - : accountsInstance[`get${keyName}Signer`], - authorizedSignerToAccount: genericRead - ? (signer) => accountsInstance.signerToAccount(signer) - : accountsInstance[`${keyName.toLowerCase()}SignerToAccount`], - hasAuthorizedSigner: genericRead - ? (signer) => accountsInstance.hasIndexedSigner(signer, key) - : accountsInstance[`hasAuthorized${keyName}Signer`], - removeSigner: genericWrite - ? async () => { - const defaultSigner = await accountsInstance[`get${keyName}Signer`](account) - await accountsInstance.removeSigner(defaultSigner, key) - } - : accountsInstance[`remove${keyName}Signer`], - } - await accountsInstance.createAccount() - }) - - describe(`#authorize${keyName}Signer()`, () => { - const authorized = accounts[1] - let sig - - beforeEach(async () => { - sig = await getSignature(account, authorized) - }) - - it(`should set the authorized key (${description})`, async () => { - assert.isFalse(await testInstance.hasAuthorizedSigner(account)) - await testInstance.fn(authorized, sig.v, sig.r, sig.s) - assert.equal(await accountsInstance.authorizedBy(authorized), account) - assert.equal(await testInstance.getAuthorizedFromAccount(account), authorized) - assert.equal(await testInstance.authorizedSignerToAccount(authorized), account) - assert.isTrue(await testInstance.hasAuthorizedSigner(account)) - }) - - it(`should emit the right event`, async () => { - const resp = await testInstance.fn(authorized, sig.v, sig.r, sig.s) - - assert.equal(resp.logs.length, genericWrite ? 3 : 4) - const log = resp.logs[genericWrite ? 0 : 3] - assertLogMatches( - log, - testInstance.eventName, - genericWrite - ? { - account, - role: key, - signer: authorized, - } - : { - account, - signer: authorized, - } - ) - }) - - it(`should revert if the ${description} is an account`, async () => { - await accountsInstance.createAccount({ from: authorized }) - await assertTransactionRevertWithReason( - testInstance.fn(authorized, sig.v, sig.r, sig.s), - 'Cannot re-authorize address or locked gold account for another account' - ) - }) - - it(`should revert if the ${description} is already authorized`, async () => { - const otherAccount = accounts[2] - const otherSig = await getSignature(otherAccount, authorized) - await accountsInstance.createAccount({ from: otherAccount }) - await testInstance.fn(authorized, otherSig.v, otherSig.r, otherSig.s, { - from: otherAccount, - }) - await assertTransactionRevertWithReason( - testInstance.fn(authorized, sig.v, sig.r, sig.s), - 'Cannot re-authorize address or locked gold account for another account' - ) - }) - - it('should revert if the signature is incorrect', async () => { - const nonVoter = accounts[3] - const incorrectSig = await getSignature(account, nonVoter) - await assertTransactionRevertWithReason( - testInstance.fn(authorized, incorrectSig.v, incorrectSig.r, incorrectSig.s), - 'Invalid signature' - ) - }) - - describe('when a previous authorization has been made', () => { - const newAuthorized = accounts[2] - let newSig - beforeEach(async () => { - await testInstance.fn(authorized, sig.v, sig.r, sig.s) - newSig = await getSignature(account, newAuthorized) - await testInstance.fn(newAuthorized, newSig.v, newSig.r, newSig.s) - }) - - it(`should set the new authorized ${description}`, async () => { - assert.equal(await accountsInstance.authorizedBy(newAuthorized), account) - assert.equal(await testInstance.getAuthorizedFromAccount(account), newAuthorized) - assert.equal(await testInstance.authorizedSignerToAccount(newAuthorized), account) - }) - - it('should preserve the previous authorization', async () => { - assert.equal(await accountsInstance.authorizedBy(authorized), account) - }) - }) - }) - - describe(`#getAccountFrom${keyName}Signer()`, () => { - describe(`when the account has not authorized a ${description}`, () => { - it('should return the account when passed the account', async () => { - assert.equal(await testInstance.authorizedSignerToAccount(account), account) - }) - - it('should revert when passed an address that is not an account', async () => { - await assertRevert(testInstance.authorizedSignerToAccount(accounts[1])) - }) - }) - - describe(`when the account has authorized a ${description}`, () => { - const authorized = accounts[1] - beforeEach(async () => { - const sig = await getSignature(account, authorized) - await testInstance.fn(authorized, sig.v, sig.r, sig.s) - }) - - it('should return the account when passed the account', async () => { - assert.equal(await testInstance.authorizedSignerToAccount(account), account) - }) - - it(`should return the account when passed the ${description}`, async () => { - assert.equal(await testInstance.authorizedSignerToAccount(authorized), account) - }) - }) - }) - - describe(`#get${keyName}SignerFromAccount()`, () => { - describe(`when the account has not authorized a ${description}`, () => { - it('should return the account when passed the account', async () => { - assert.equal(await testInstance.getAuthorizedFromAccount(account), account) - }) - }) - - describe(`when the account has authorized a ${description}`, () => { - const authorized = accounts[1] - - beforeEach(async () => { - const sig = await getSignature(account, authorized) - await testInstance.fn(authorized, sig.v, sig.r, sig.s) - }) - - it(`should return the ${description} when passed the account`, async () => { - assert.equal(await testInstance.getAuthorizedFromAccount(account), authorized) - }) - }) - }) - - describe(`#remove${keyName}Signer()`, () => { - it(`should be able to remove the ${description} signer after authorizing`, async () => { - const authorized = accounts[1] - const sig = await getSignature(account, authorized) - - await testInstance.fn(authorized, sig.v, sig.r, sig.s) - assert.isTrue(await testInstance.hasAuthorizedSigner(account)) - assert.equal(await testInstance.getAuthorizedFromAccount(account), authorized) - - await testInstance.removeSigner() - assert.isFalse(await testInstance.hasAuthorizedSigner(account)) - assert.equal(await testInstance.getAuthorizedFromAccount(account), account) - }) - }) - }) - }) - }) -}) From ba46338d8b867d38677e361b06d6121165011085 Mon Sep 17 00:00:00 2001 From: Aaron DeRuvo Date: Mon, 4 Dec 2023 10:33:33 +0200 Subject: [PATCH 45/63] fix ledger connection --- packages/cli/src/base.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/base.ts b/packages/cli/src/base.ts index fa2070a94d6..65035b16df3 100644 --- a/packages/cli/src/base.ts +++ b/packages/cli/src/base.ts @@ -154,8 +154,10 @@ export abstract class BaseCommand extends Command { let transport try { // Importing for ledger uses only fixes running jest tests - const TransportNodeHid = (await import('@ledgerhq/hw-transport-node-hid')).default - // @ts-expect-error // TODO fix types + const _TransportNodeHid = (await import('@ledgerhq/hw-transport-node-hid')).default + // types seem to be suggesting 2 defaults but js is otherwise for TransportNodeHid + const TransportNodeHid: typeof _TransportNodeHid.default = + _TransportNodeHid.default || _TransportNodeHid transport = await TransportNodeHid.open('') const derivationPathIndexes = res.raw.some( (value) => (value as any).flag === 'ledgerCustomAddresses' From 36952d89065f25fb15b700e802a8e50350584e42 Mon Sep 17 00:00:00 2001 From: Aaron DeRuvo Date: Mon, 4 Dec 2023 10:53:12 +0200 Subject: [PATCH 46/63] clean up ts configs --- packages/celotool/tsconfig.json | 7 +++---- packages/protocol/abis/tsconfig.json | 3 +-- packages/protocol/tsconfig.json | 6 ------ packages/typescript/tsconfig.library.json | 3 +-- 4 files changed, 5 insertions(+), 14 deletions(-) diff --git a/packages/celotool/tsconfig.json b/packages/celotool/tsconfig.json index 4a888b76f7d..747699ef2ee 100644 --- a/packages/celotool/tsconfig.json +++ b/packages/celotool/tsconfig.json @@ -4,15 +4,14 @@ "outDir": "lib", "rootDir": "src", "baseUrl": ".", - "lib": ["es7", "es2017"], - "target": "es6", + "lib": ["es7", "es2017", "es2020"], + "target": "es2020", "resolveJsonModule": true, "esModuleInterop": true, "paths": { "@google-cloud/monitoring": ["types/monitoring"] } }, - "include": ["src", "../contractkit/types"], + "include": ["src"], "exclude": ["node_modules/"], - "references": [{ "path": "../sdk/utils" }, { "path": "../sdk/contractkit" }] } diff --git a/packages/protocol/abis/tsconfig.json b/packages/protocol/abis/tsconfig.json index abc7c088d7d..d224a3681e1 100644 --- a/packages/protocol/abis/tsconfig.json +++ b/packages/protocol/abis/tsconfig.json @@ -19,6 +19,5 @@ "outDir": "./dist/esm" }, "include": ["./src-generated"], - "exclude": ["./src-generated/types/ethers"], - "references": [{ "path": "../../sdk/utils" }] + "exclude": ["./src-generated/types/ethers"] } \ No newline at end of file diff --git a/packages/protocol/tsconfig.json b/packages/protocol/tsconfig.json index e26f8383d08..46acf8d3b36 100644 --- a/packages/protocol/tsconfig.json +++ b/packages/protocol/tsconfig.json @@ -5,7 +5,6 @@ "esModuleInterop": true, "baseUrl": ".", "lib": [ - "dom", "es2015", "es2016" ], @@ -24,10 +23,5 @@ "node_modules", "wagmi.config.ts", "abis" - ], - "references": [ - { - "path": "../sdk/utils" - } ] } \ No newline at end of file diff --git a/packages/typescript/tsconfig.library.json b/packages/typescript/tsconfig.library.json index 7217c449de9..713cd7ebf01 100644 --- a/packages/typescript/tsconfig.library.json +++ b/packages/typescript/tsconfig.library.json @@ -1,11 +1,10 @@ { "compileOnSave": false, "compilerOptions": { - "lib": ["dom", "es2015", "es2016"], + "lib": ["es2015", "es2016"], "target": "es6", "module": "commonjs", "moduleResolution": "node", - "jsx": "preserve", "composite": true, "allowSyntheticDefaultImports": true, "esModuleInterop": true, From 540a0332fd50c19309eea09ea2a18830945c8c7a Mon Sep 17 00:00:00 2001 From: Aaron DeRuvo Date: Mon, 4 Dec 2023 11:59:23 +0200 Subject: [PATCH 47/63] target must be es5 for tests but es2020 for export --- packages/protocol/abis/tsconfig-cjs.json | 1 - packages/protocol/abis/tsconfig.json | 2 +- .../scripts/prepare-contracts-and-abis-publishing.ts | 5 +++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/protocol/abis/tsconfig-cjs.json b/packages/protocol/abis/tsconfig-cjs.json index 86635778c22..50bbdbe9f10 100644 --- a/packages/protocol/abis/tsconfig-cjs.json +++ b/packages/protocol/abis/tsconfig-cjs.json @@ -6,5 +6,4 @@ "module": "CommonJS", "outDir": "./dist/cjs" }, - "references": [{ "path": "../../sdk/utils" }] } \ No newline at end of file diff --git a/packages/protocol/abis/tsconfig.json b/packages/protocol/abis/tsconfig.json index d224a3681e1..5cc35282b28 100644 --- a/packages/protocol/abis/tsconfig.json +++ b/packages/protocol/abis/tsconfig.json @@ -11,7 +11,7 @@ "removeComments": false, "skipLibCheck": true, "sourceMap": true, - "target": "ES2020", + "target": "ES5", "downlevelIteration": true, "resolveJsonModule": true, "declaration": false, diff --git a/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts b/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts index 338dbc3b28d..c012fcdfe76 100644 --- a/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts +++ b/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts @@ -19,6 +19,11 @@ function log(...args: any[]) { } try { + log('Setting package.json target to ES2020') + const tsconfig = JSON.parse(fs.readFileSync(TSCONFIG_PATH, 'utf8')) + tsconfig.compilerOptions.target = 'ES2020' + fs.writeFileSync(TSCONFIG_PATH, JSON.stringify(tsconfig, null, 4)) + // Start from scratch rmrfSync([ABIS_BUILD_DIR, ABIS_DIST_DIR]) fs.mkdirSync(ABIS_BUILD_DIR, { recursive: true }) From b501100438ac9048866642e0762dc2bb67547477 Mon Sep 17 00:00:00 2001 From: Aaron DeRuvo Date: Mon, 4 Dec 2023 13:09:13 +0200 Subject: [PATCH 48/63] es5 is a must --- packages/protocol/tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol/tsconfig.json b/packages/protocol/tsconfig.json index 46acf8d3b36..86ec49d29c4 100644 --- a/packages/protocol/tsconfig.json +++ b/packages/protocol/tsconfig.json @@ -15,7 +15,7 @@ "removeComments": false, "skipLibCheck": true, "sourceMap": true, - "target": "ES2020", + "target": "es5", "downlevelIteration": true, "resolveJsonModule": true }, From bc8c20e93a0aca5ac0fde2c56f28f586e87c538e Mon Sep 17 00:00:00 2001 From: Leszek Stachowski Date: Mon, 4 Dec 2023 15:55:55 +0100 Subject: [PATCH 49/63] remove types/ prefix --- packages/protocol/abis/tsconfig.json | 2 +- .../prepare-contracts-and-abis-publishing.ts | 13 ++++++------- packages/protocol/wagmi.config.ts | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/protocol/abis/tsconfig.json b/packages/protocol/abis/tsconfig.json index 5cc35282b28..7335abbe062 100644 --- a/packages/protocol/abis/tsconfig.json +++ b/packages/protocol/abis/tsconfig.json @@ -19,5 +19,5 @@ "outDir": "./dist/esm" }, "include": ["./src-generated"], - "exclude": ["./src-generated/types/ethers"] + "exclude": ["./src-generated/ethers"] } \ No newline at end of file diff --git a/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts b/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts index c012fcdfe76..37bef4ae52f 100644 --- a/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts +++ b/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts @@ -33,10 +33,10 @@ try { build(`--solidity ${path.join(ABIS_BUILD_DIR)}`) // Generate ethers typings - build(`--ethersTypes ${path.join(ABIS_BUILD_DIR, 'types/ethers')}`) + build(`--ethersTypes ${path.join(ABIS_BUILD_DIR, 'ethers')}`) // Generate web3 typings - build(`--web3Types ${path.join(ABIS_BUILD_DIR, 'types/web3')}`) + build(`--web3Types ${path.join(ABIS_BUILD_DIR, 'web3')}`) // Merge contracts-0.8, contracts-mento, etc.. at the root of the build dir log('Merging files at the root of the build dir') @@ -103,11 +103,10 @@ function prepareTargetTypesExports() { const targets = ['esm', 'cjs', 'types'] targets.forEach((target) => { - // why? - // fs.copyFileSync( - // path.join(ABIS_PACKAGE_SRC_DIR, `package-${target}.json`), - // path.join(ABIS_DIST_DIR, target, 'package.json') - // ) + fs.copyFileSync( + path.join(ABIS_PACKAGE_SRC_DIR, `package-${target}.json`), + path.join(ABIS_DIST_DIR, target, 'package.json') + ) const filePaths = lsRecursive(path.join(ABIS_DIST_DIR, target)) filePaths.forEach((filePath) => { diff --git a/packages/protocol/wagmi.config.ts b/packages/protocol/wagmi.config.ts index 833f1d197c5..e6a2d0ad898 100644 --- a/packages/protocol/wagmi.config.ts +++ b/packages/protocol/wagmi.config.ts @@ -19,7 +19,7 @@ for (const contractName of new Set(CoreContracts)) { export default defineConfig( contracts.map(({ name, abi }) => ({ - out: path.join(ABIS_BUILD_DIR, `types/wagmi/${name}.ts`), + out: path.join(ABIS_BUILD_DIR, `wagmi/${name}.ts`), contracts: [{ name, abi }], plugins: [], })) From f53db38f62c005a311c38b9b446f2fd8372bc2ca Mon Sep 17 00:00:00 2001 From: Leszek Stachowski Date: Mon, 4 Dec 2023 16:56:50 +0100 Subject: [PATCH 50/63] change imports --- .../cli/src/commands/network/contracts.ts | 4 +- .../commands/releasegold/admin-revoke.test.ts | 2 +- .../releasegold/refund-and-finalize.test.ts | 2 +- .../releasegold/set-beneficiary.test.ts | 2 +- .../src/commands/releasegold/withdraw.test.ts | 2 +- packages/cli/src/commands/transfer/erc20.ts | 2 +- packages/cli/src/utils/release-gold-base.ts | 2 +- packages/protocol/abis/README.md | 7 +- packages/protocol/scripts/consts.ts | 6 ++ .../prepare-contracts-and-abis-publishing.ts | 18 +++-- .../sdk/contractkit/src/address-registry.ts | 2 +- .../sdk/contractkit/src/contract-cache.ts | 2 +- .../contractkit/src/mini-contract-cache.ts | 18 ++--- packages/sdk/contractkit/src/proxy.ts | 62 ++++++++--------- .../contractkit/src/web3-contract-cache.ts | 68 +++++++++---------- .../sdk/contractkit/src/wrappers/Accounts.ts | 2 +- .../contractkit/src/wrappers/Attestations.ts | 2 +- .../src/wrappers/BaseWrapper.test.ts | 2 +- .../contractkit/src/wrappers/BaseWrapper.ts | 2 +- .../src/wrappers/BlockChainParameters.test.ts | 2 +- .../src/wrappers/BlockchainParameters.ts | 2 +- .../src/wrappers/CeloTokenWrapper.ts | 4 +- .../src/wrappers/DoubleSigningSlasher.ts | 2 +- .../src/wrappers/DowntimeSlasher.ts | 2 +- .../sdk/contractkit/src/wrappers/Election.ts | 2 +- .../contractkit/src/wrappers/EpochRewards.ts | 2 +- .../contractkit/src/wrappers/Erc20Wrapper.ts | 2 +- .../sdk/contractkit/src/wrappers/Escrow.ts | 2 +- .../sdk/contractkit/src/wrappers/Exchange.ts | 2 +- .../src/wrappers/FederatedAttestations.ts | 2 +- .../contractkit/src/wrappers/FeeHandler.ts | 2 +- .../sdk/contractkit/src/wrappers/Freezer.ts | 2 +- .../src/wrappers/GasPriceMinimum.ts | 2 +- .../src/wrappers/GoldTokenWrapper.ts | 2 +- .../src/wrappers/Governance.test.ts | 2 +- .../contractkit/src/wrappers/Governance.ts | 2 +- .../contractkit/src/wrappers/GrandaMento.ts | 4 +- .../contractkit/src/wrappers/LockedGold.ts | 2 +- .../src/wrappers/MetaTransactionWallet.ts | 2 +- .../MetaTransactionWalletDeployer.test.ts | 4 +- .../wrappers/MetaTransactionWalletDeployer.ts | 2 +- .../sdk/contractkit/src/wrappers/MultiSig.ts | 2 +- .../contractkit/src/wrappers/OdisPayments.ts | 2 +- .../contractkit/src/wrappers/ReleaseGold.ts | 2 +- .../sdk/contractkit/src/wrappers/Reserve.ts | 2 +- .../contractkit/src/wrappers/SortedOracles.ts | 2 +- .../src/wrappers/StableTokenWrapper.ts | 2 +- .../contractkit/src/wrappers/Validators.ts | 2 +- packages/sdk/governance/src/proposals.ts | 6 +- 49 files changed, 142 insertions(+), 135 deletions(-) diff --git a/packages/cli/src/commands/network/contracts.ts b/packages/cli/src/commands/network/contracts.ts index 56b6f8d8ef6..93806bb00bd 100644 --- a/packages/cli/src/commands/network/contracts.ts +++ b/packages/cli/src/commands/network/contracts.ts @@ -1,5 +1,5 @@ -import { newICeloVersionedContract } from '@celo/abis/types/web3/ICeloVersionedContract' -import { newProxy } from '@celo/abis/types/web3/Proxy' +import { newICeloVersionedContract } from '@celo/abis/web3/ICeloVersionedContract' +import { newProxy } from '@celo/abis/web3/Proxy' import { concurrentMap } from '@celo/base' import { CeloContract } from '@celo/contractkit' import { cli } from 'cli-ux' diff --git a/packages/cli/src/commands/releasegold/admin-revoke.test.ts b/packages/cli/src/commands/releasegold/admin-revoke.test.ts index da2e21abb33..7711ca4a105 100644 --- a/packages/cli/src/commands/releasegold/admin-revoke.test.ts +++ b/packages/cli/src/commands/releasegold/admin-revoke.test.ts @@ -1,4 +1,4 @@ -import { newReleaseGold } from '@celo/abis/types/web3/ReleaseGold' +import { newReleaseGold } from '@celo/abis/web3/ReleaseGold' import { serializeSignature } from '@celo/base/lib/signatureUtils' import { ContractKit, newKitFromWeb3 } from '@celo/contractkit' import { AccountsWrapper } from '@celo/contractkit/lib/wrappers/Accounts' diff --git a/packages/cli/src/commands/releasegold/refund-and-finalize.test.ts b/packages/cli/src/commands/releasegold/refund-and-finalize.test.ts index bb91136dcf4..a6a30ebf3c5 100644 --- a/packages/cli/src/commands/releasegold/refund-and-finalize.test.ts +++ b/packages/cli/src/commands/releasegold/refund-and-finalize.test.ts @@ -1,4 +1,4 @@ -import { newReleaseGold } from '@celo/abis/types/web3/ReleaseGold' +import { newReleaseGold } from '@celo/abis/web3/ReleaseGold' import { ContractKit, newKitFromWeb3 } from '@celo/contractkit' import { ReleaseGoldWrapper } from '@celo/contractkit/lib/wrappers/ReleaseGold' import { getContractFromEvent, testWithGanache } from '@celo/dev-utils/lib/ganache-test' diff --git a/packages/cli/src/commands/releasegold/set-beneficiary.test.ts b/packages/cli/src/commands/releasegold/set-beneficiary.test.ts index ce83c112d12..11710dd6f20 100644 --- a/packages/cli/src/commands/releasegold/set-beneficiary.test.ts +++ b/packages/cli/src/commands/releasegold/set-beneficiary.test.ts @@ -1,4 +1,4 @@ -import { newReleaseGold } from '@celo/abis/types/web3/ReleaseGold' +import { newReleaseGold } from '@celo/abis/web3/ReleaseGold' import { newKitFromWeb3 } from '@celo/contractkit' import { ReleaseGoldWrapper } from '@celo/contractkit/lib/wrappers/ReleaseGold' import { getContractFromEvent, testWithGanache } from '@celo/dev-utils/lib/ganache-test' diff --git a/packages/cli/src/commands/releasegold/withdraw.test.ts b/packages/cli/src/commands/releasegold/withdraw.test.ts index faae7bed97b..5e3548609df 100644 --- a/packages/cli/src/commands/releasegold/withdraw.test.ts +++ b/packages/cli/src/commands/releasegold/withdraw.test.ts @@ -1,4 +1,4 @@ -import { newReleaseGold } from '@celo/abis/types/web3/ReleaseGold' +import { newReleaseGold } from '@celo/abis/web3/ReleaseGold' import { ContractKit, newKitFromWeb3 } from '@celo/contractkit' import { ReleaseGoldWrapper } from '@celo/contractkit/lib/wrappers/ReleaseGold' import { getContractFromEvent, testWithGanache, timeTravel } from '@celo/dev-utils/lib/ganache-test' diff --git a/packages/cli/src/commands/transfer/erc20.ts b/packages/cli/src/commands/transfer/erc20.ts index 1b5f4a5cb91..875f95085f0 100644 --- a/packages/cli/src/commands/transfer/erc20.ts +++ b/packages/cli/src/commands/transfer/erc20.ts @@ -1,4 +1,4 @@ -import { IERC20 } from '@celo/abis/types/web3/IERC20' +import { IERC20 } from '@celo/abis/web3/IERC20' import { Erc20Wrapper } from '@celo/contractkit/lib/wrappers/Erc20Wrapper' import { flags } from '@oclif/command' import BigNumber from 'bignumber.js' diff --git a/packages/cli/src/utils/release-gold-base.ts b/packages/cli/src/utils/release-gold-base.ts index dc7457a6722..5376ca0cf24 100644 --- a/packages/cli/src/utils/release-gold-base.ts +++ b/packages/cli/src/utils/release-gold-base.ts @@ -1,4 +1,4 @@ -import { newReleaseGold } from '@celo/abis/types/web3/ReleaseGold' +import { newReleaseGold } from '@celo/abis/web3/ReleaseGold' import { ReleaseGoldWrapper } from '@celo/contractkit/lib/wrappers/ReleaseGold' import { ParserOutput } from '@oclif/parser/lib/parse' import { BaseCommand } from '../base' diff --git a/packages/protocol/abis/README.md b/packages/protocol/abis/README.md index 5b8e111e23f..1dd0e51305f 100644 --- a/packages/protocol/abis/README.md +++ b/packages/protocol/abis/README.md @@ -22,14 +22,11 @@ yarn add @celo/abis // json abi import Accounts from '@celo/abis/Accounts.json' -// ethers -import { Accounts } from '@celo/abis/types/ethers' - // web3 -import Accounts from '@celo/abis/types/web3/Accounts' +import Accounts from '@celo/abis/web3/Accounts' // wagmi -import Accounts from '@celo/abis/types/wagmi/Accounts' +import Accounts from '@celo/abis/wagmi/Accounts' ``` ## License diff --git a/packages/protocol/scripts/consts.ts b/packages/protocol/scripts/consts.ts index 645fdbb98d0..3db464e561d 100644 --- a/packages/protocol/scripts/consts.ts +++ b/packages/protocol/scripts/consts.ts @@ -92,3 +92,9 @@ export const ImplContracts = OtherContracts.concat(ProxyContracts).concat(CoreCo export const PublishContracts = CoreContracts.concat(Interfaces) .concat(PROXY_CONTRACT) .concat(MENTO_PACKAGE.contracts) + +export enum BuildTarget { + CJS = 'cjs', + ESM = 'esm', + TYPES = 'types', +} diff --git a/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts b/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts index 37bef4ae52f..d48382a488a 100644 --- a/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts +++ b/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts @@ -8,6 +8,7 @@ import { ABIS_DIST_DIR, ABIS_PACKAGE_SRC_DIR, BUILD_EXECUTABLE, + BuildTarget, CONTRACTS_PACKAGE_SRC_DIR, PublishContracts, TSCONFIG_PATH, @@ -100,13 +101,16 @@ try { // Helper functions function prepareTargetTypesExports() { const exports = {} - const targets = ['esm', 'cjs', 'types'] + const targets = [BuildTarget.ESM, BuildTarget.CJS, BuildTarget.TYPES] targets.forEach((target) => { - fs.copyFileSync( - path.join(ABIS_PACKAGE_SRC_DIR, `package-${target}.json`), - path.join(ABIS_DIST_DIR, target, 'package.json') - ) + // We don't need package.json for type declarations + if (target != BuildTarget.TYPES) { + fs.copyFileSync( + path.join(ABIS_PACKAGE_SRC_DIR, `package-${target}.json`), + path.join(ABIS_DIST_DIR, target, 'package.json') + ) + } const filePaths = lsRecursive(path.join(ABIS_DIST_DIR, target)) filePaths.forEach((filePath) => { @@ -128,7 +132,7 @@ function prepareTargetTypesExports() { exports[exportKey] = {} } - if (target === 'esm') { + if (target === BuildTarget.ESM) { const importPath = `./${relativePath}.js` expectFileExists(importPath) @@ -137,7 +141,7 @@ function prepareTargetTypesExports() { ...exports[exportKey], import: importPath, } - } else if (target === 'cjs') { + } else if (target === BuildTarget.CJS) { const requirePath = `./${relativePath}.js` expectFileExists(requirePath) diff --git a/packages/sdk/contractkit/src/address-registry.ts b/packages/sdk/contractkit/src/address-registry.ts index 1ec6ee92967..33e5958de7f 100644 --- a/packages/sdk/contractkit/src/address-registry.ts +++ b/packages/sdk/contractkit/src/address-registry.ts @@ -1,4 +1,4 @@ -import { newRegistry, Registry } from '@celo/abis/types/web3/Registry' +import { newRegistry, Registry } from '@celo/abis/web3/Registry' import { Address, NULL_ADDRESS } from '@celo/base/lib/address' import { Connection } from '@celo/connect' import debugFactory from 'debug' diff --git a/packages/sdk/contractkit/src/contract-cache.ts b/packages/sdk/contractkit/src/contract-cache.ts index be1379bd62f..ff7e033e609 100644 --- a/packages/sdk/contractkit/src/contract-cache.ts +++ b/packages/sdk/contractkit/src/contract-cache.ts @@ -1,4 +1,4 @@ -import { IERC20 } from '@celo/abis/types/web3/IERC20' +import { IERC20 } from '@celo/abis/web3/IERC20' import { Connection } from '@celo/connect' import { AddressRegistry } from './address-registry' import { CeloContract } from './base' diff --git a/packages/sdk/contractkit/src/mini-contract-cache.ts b/packages/sdk/contractkit/src/mini-contract-cache.ts index 4ded4693d4f..c4b6e25d125 100644 --- a/packages/sdk/contractkit/src/mini-contract-cache.ts +++ b/packages/sdk/contractkit/src/mini-contract-cache.ts @@ -1,12 +1,12 @@ -import { newGasPriceMinimum } from '@celo/abis/types/web3/0.8/GasPriceMinimum' -import { newAccounts } from '@celo/abis/types/web3/Accounts' -import { newGoldToken } from '@celo/abis/types/web3/GoldToken' -import { newExchange } from '@celo/abis/types/web3/mento/Exchange' -import { newExchangeBRL } from '@celo/abis/types/web3/mento/ExchangeBRL' -import { newExchangeEUR } from '@celo/abis/types/web3/mento/ExchangeEUR' -import { newStableToken } from '@celo/abis/types/web3/mento/StableToken' -import { newStableTokenBRL } from '@celo/abis/types/web3/mento/StableTokenBRL' -import { newStableTokenEUR } from '@celo/abis/types/web3/mento/StableTokenEUR' +import { newGasPriceMinimum } from '@celo/abis/web3/0.8/GasPriceMinimum' +import { newAccounts } from '@celo/abis/web3/Accounts' +import { newGoldToken } from '@celo/abis/web3/GoldToken' +import { newExchange } from '@celo/abis/web3/mento/Exchange' +import { newExchangeBRL } from '@celo/abis/web3/mento/ExchangeBRL' +import { newExchangeEUR } from '@celo/abis/web3/mento/ExchangeEUR' +import { newStableToken } from '@celo/abis/web3/mento/StableToken' +import { newStableTokenBRL } from '@celo/abis/web3/mento/StableTokenBRL' +import { newStableTokenEUR } from '@celo/abis/web3/mento/StableTokenEUR' import { StableToken } from '@celo/base' import { Connection } from '@celo/connect' import { AddressRegistry } from './address-registry' diff --git a/packages/sdk/contractkit/src/proxy.ts b/packages/sdk/contractkit/src/proxy.ts index fce91b4fd3c..6c57ec4adea 100644 --- a/packages/sdk/contractkit/src/proxy.ts +++ b/packages/sdk/contractkit/src/proxy.ts @@ -1,37 +1,37 @@ // tslint:disable: ordered-imports import { ABIDefinition, AbiItem } from '@celo/connect' import Web3 from 'web3' -import { ABI as GasPriceMinimumABI } from '@celo/abis/types/web3/0.8/GasPriceMinimum' -import { ABI as AccountsABI } from '@celo/abis/types/web3/Accounts' -import { ABI as AttestationsABI } from '@celo/abis/types/web3/Attestations' -import { ABI as BlockchainParametersABI } from '@celo/abis/types/web3/BlockchainParameters' -import { ABI as DoubleSigningSlasherABI } from '@celo/abis/types/web3/DoubleSigningSlasher' -import { ABI as DowntimeSlasherABI } from '@celo/abis/types/web3/DowntimeSlasher' -import { ABI as ElectionABI } from '@celo/abis/types/web3/Election' -import { ABI as EpochRewardsABI } from '@celo/abis/types/web3/EpochRewards' -import { ABI as EscrowABI } from '@celo/abis/types/web3/Escrow' -import { ABI as FederatedAttestationsABI } from '@celo/abis/types/web3/FederatedAttestations' -import { ABI as FeeCurrencyWhitelistABI } from '@celo/abis/types/web3/FeeCurrencyWhitelist' -import { ABI as FeeHandlerABI } from '@celo/abis/types/web3/FeeHandler' -import { ABI as FreezerABI } from '@celo/abis/types/web3/Freezer' -import { ABI as GoldTokenABI } from '@celo/abis/types/web3/GoldToken' -import { ABI as GovernanceABI } from '@celo/abis/types/web3/Governance' -import { ABI as LockedGoldABI } from '@celo/abis/types/web3/LockedGold' -import { ABI as MentoFeeHandlerSellerABI } from '@celo/abis/types/web3/MentoFeeHandlerSeller' -import { ABI as MetaTransactionWalletABI } from '@celo/abis/types/web3/MetaTransactionWallet' -import { ABI as MetaTransactionWalletDeployerABI } from '@celo/abis/types/web3/MetaTransactionWalletDeployer' -import { ABI as MultiSigABI } from '@celo/abis/types/web3/MultiSig' -import { ABI as OdisPaymentsABI } from '@celo/abis/types/web3/OdisPayments' -import { ABI as ProxyABI } from '@celo/abis/types/web3/Proxy' -import { ABI as RandomABI } from '@celo/abis/types/web3/Random' -import { ABI as RegistryABI } from '@celo/abis/types/web3/Registry' -import { ABI as SortedOraclesABI } from '@celo/abis/types/web3/SortedOracles' -import { ABI as UniswapFeeHandlerSellerABI } from '@celo/abis/types/web3/UniswapFeeHandlerSeller' -import { ABI as ValidatorsABI } from '@celo/abis/types/web3/Validators' -import { ABI as ExchangeABI } from '@celo/abis/types/web3/mento/Exchange' -import { ABI as GrandaMentoABI } from '@celo/abis/types/web3/mento/GrandaMento' -import { ABI as ReserveABI } from '@celo/abis/types/web3/mento/Reserve' -import { ABI as StableTokenABI } from '@celo/abis/types/web3/mento/StableToken' +import { ABI as GasPriceMinimumABI } from '@celo/abis/web3/0.8/GasPriceMinimum' +import { ABI as AccountsABI } from '@celo/abis/web3/Accounts' +import { ABI as AttestationsABI } from '@celo/abis/web3/Attestations' +import { ABI as BlockchainParametersABI } from '@celo/abis/web3/BlockchainParameters' +import { ABI as DoubleSigningSlasherABI } from '@celo/abis/web3/DoubleSigningSlasher' +import { ABI as DowntimeSlasherABI } from '@celo/abis/web3/DowntimeSlasher' +import { ABI as ElectionABI } from '@celo/abis/web3/Election' +import { ABI as EpochRewardsABI } from '@celo/abis/web3/EpochRewards' +import { ABI as EscrowABI } from '@celo/abis/web3/Escrow' +import { ABI as FederatedAttestationsABI } from '@celo/abis/web3/FederatedAttestations' +import { ABI as FeeCurrencyWhitelistABI } from '@celo/abis/web3/FeeCurrencyWhitelist' +import { ABI as FeeHandlerABI } from '@celo/abis/web3/FeeHandler' +import { ABI as FreezerABI } from '@celo/abis/web3/Freezer' +import { ABI as GoldTokenABI } from '@celo/abis/web3/GoldToken' +import { ABI as GovernanceABI } from '@celo/abis/web3/Governance' +import { ABI as LockedGoldABI } from '@celo/abis/web3/LockedGold' +import { ABI as MentoFeeHandlerSellerABI } from '@celo/abis/web3/MentoFeeHandlerSeller' +import { ABI as MetaTransactionWalletABI } from '@celo/abis/web3/MetaTransactionWallet' +import { ABI as MetaTransactionWalletDeployerABI } from '@celo/abis/web3/MetaTransactionWalletDeployer' +import { ABI as MultiSigABI } from '@celo/abis/web3/MultiSig' +import { ABI as OdisPaymentsABI } from '@celo/abis/web3/OdisPayments' +import { ABI as ProxyABI } from '@celo/abis/web3/Proxy' +import { ABI as RandomABI } from '@celo/abis/web3/Random' +import { ABI as RegistryABI } from '@celo/abis/web3/Registry' +import { ABI as SortedOraclesABI } from '@celo/abis/web3/SortedOracles' +import { ABI as UniswapFeeHandlerSellerABI } from '@celo/abis/web3/UniswapFeeHandlerSeller' +import { ABI as ValidatorsABI } from '@celo/abis/web3/Validators' +import { ABI as ExchangeABI } from '@celo/abis/web3/mento/Exchange' +import { ABI as GrandaMentoABI } from '@celo/abis/web3/mento/GrandaMento' +import { ABI as ReserveABI } from '@celo/abis/web3/mento/Reserve' +import { ABI as StableTokenABI } from '@celo/abis/web3/mento/StableToken' export const GET_IMPLEMENTATION_ABI: ABIDefinition = { constant: true, diff --git a/packages/sdk/contractkit/src/web3-contract-cache.ts b/packages/sdk/contractkit/src/web3-contract-cache.ts index 3e1396a1958..c3e31b36549 100644 --- a/packages/sdk/contractkit/src/web3-contract-cache.ts +++ b/packages/sdk/contractkit/src/web3-contract-cache.ts @@ -3,41 +3,41 @@ import debugFactory from 'debug' import { AddressRegistry } from './address-registry' import { CeloContract, ProxyContracts } from './base' import { StableToken } from './celo-tokens' -import { newGasPriceMinimum } from '@celo/abis/types/web3/0.8/GasPriceMinimum' -import { newAccounts } from '@celo/abis/types/web3/Accounts' -import { newAttestations } from '@celo/abis/types/web3/Attestations' -import { newBlockchainParameters } from '@celo/abis/types/web3/BlockchainParameters' -import { newDoubleSigningSlasher } from '@celo/abis/types/web3/DoubleSigningSlasher' -import { newDowntimeSlasher } from '@celo/abis/types/web3/DowntimeSlasher' -import { newElection } from '@celo/abis/types/web3/Election' -import { newEpochRewards } from '@celo/abis/types/web3/EpochRewards' -import { newEscrow } from '@celo/abis/types/web3/Escrow' -import { newFederatedAttestations } from '@celo/abis/types/web3/FederatedAttestations' -import { newFeeCurrencyWhitelist } from '@celo/abis/types/web3/FeeCurrencyWhitelist' -import { newFeeHandler } from '@celo/abis/types/web3/FeeHandler' -import { newFreezer } from '@celo/abis/types/web3/Freezer' -import { newGoldToken } from '@celo/abis/types/web3/GoldToken' -import { newGovernance } from '@celo/abis/types/web3/Governance' -import { newIERC20 } from '@celo/abis/types/web3/IERC20' -import { newLockedGold } from '@celo/abis/types/web3/LockedGold' -import { newMetaTransactionWallet } from '@celo/abis/types/web3/MetaTransactionWallet' -import { newMetaTransactionWalletDeployer } from '@celo/abis/types/web3/MetaTransactionWalletDeployer' -import { newMultiSig } from '@celo/abis/types/web3/MultiSig' -import { newOdisPayments } from '@celo/abis/types/web3/OdisPayments' -import { newProxy } from '@celo/abis/types/web3/Proxy' -import { newRandom } from '@celo/abis/types/web3/Random' -import { newRegistry } from '@celo/abis/types/web3/Registry' -import { newSortedOracles } from '@celo/abis/types/web3/SortedOracles' -import { newValidators } from '@celo/abis/types/web3/Validators' -import { newExchange } from '@celo/abis/types/web3/mento/Exchange' -import { newExchangeBRL } from '@celo/abis/types/web3/mento/ExchangeBRL' -import { newExchangeEUR } from '@celo/abis/types/web3/mento/ExchangeEUR' -import { newGrandaMento } from '@celo/abis/types/web3/mento/GrandaMento' -import { newReserve } from '@celo/abis/types/web3/mento/Reserve' -import { newStableToken } from '@celo/abis/types/web3/mento/StableToken' +import { newGasPriceMinimum } from '@celo/abis/web3/0.8/GasPriceMinimum' +import { newAccounts } from '@celo/abis/web3/Accounts' +import { newAttestations } from '@celo/abis/web3/Attestations' +import { newBlockchainParameters } from '@celo/abis/web3/BlockchainParameters' +import { newDoubleSigningSlasher } from '@celo/abis/web3/DoubleSigningSlasher' +import { newDowntimeSlasher } from '@celo/abis/web3/DowntimeSlasher' +import { newElection } from '@celo/abis/web3/Election' +import { newEpochRewards } from '@celo/abis/web3/EpochRewards' +import { newEscrow } from '@celo/abis/web3/Escrow' +import { newFederatedAttestations } from '@celo/abis/web3/FederatedAttestations' +import { newFeeCurrencyWhitelist } from '@celo/abis/web3/FeeCurrencyWhitelist' +import { newFeeHandler } from '@celo/abis/web3/FeeHandler' +import { newFreezer } from '@celo/abis/web3/Freezer' +import { newGoldToken } from '@celo/abis/web3/GoldToken' +import { newGovernance } from '@celo/abis/web3/Governance' +import { newIERC20 } from '@celo/abis/web3/IERC20' +import { newLockedGold } from '@celo/abis/web3/LockedGold' +import { newMetaTransactionWallet } from '@celo/abis/web3/MetaTransactionWallet' +import { newMetaTransactionWalletDeployer } from '@celo/abis/web3/MetaTransactionWalletDeployer' +import { newMultiSig } from '@celo/abis/web3/MultiSig' +import { newOdisPayments } from '@celo/abis/web3/OdisPayments' +import { newProxy } from '@celo/abis/web3/Proxy' +import { newRandom } from '@celo/abis/web3/Random' +import { newRegistry } from '@celo/abis/web3/Registry' +import { newSortedOracles } from '@celo/abis/web3/SortedOracles' +import { newValidators } from '@celo/abis/web3/Validators' +import { newExchange } from '@celo/abis/web3/mento/Exchange' +import { newExchangeBRL } from '@celo/abis/web3/mento/ExchangeBRL' +import { newExchangeEUR } from '@celo/abis/web3/mento/ExchangeEUR' +import { newGrandaMento } from '@celo/abis/web3/mento/GrandaMento' +import { newReserve } from '@celo/abis/web3/mento/Reserve' +import { newStableToken } from '@celo/abis/web3/mento/StableToken' -import { newMentoFeeHandlerSeller } from '@celo/abis/types/web3/MentoFeeHandlerSeller' -import { newUniswapFeeHandlerSeller } from '@celo/abis/types/web3/UniswapFeeHandlerSeller' +import { newMentoFeeHandlerSeller } from '@celo/abis/web3/MentoFeeHandlerSeller' +import { newUniswapFeeHandlerSeller } from '@celo/abis/web3/UniswapFeeHandlerSeller' const debug = debugFactory('kit:web3-contract-cache') diff --git a/packages/sdk/contractkit/src/wrappers/Accounts.ts b/packages/sdk/contractkit/src/wrappers/Accounts.ts index 20dbefd75a7..a9d2935f18e 100644 --- a/packages/sdk/contractkit/src/wrappers/Accounts.ts +++ b/packages/sdk/contractkit/src/wrappers/Accounts.ts @@ -1,4 +1,4 @@ -import { Accounts } from '@celo/abis/types/web3/Accounts' +import { Accounts } from '@celo/abis/web3/Accounts' import { NativeSigner, Signature, Signer } from '@celo/base/lib/signatureUtils' import { Address, CeloTransactionObject, toTransactionObject } from '@celo/connect' import { diff --git a/packages/sdk/contractkit/src/wrappers/Attestations.ts b/packages/sdk/contractkit/src/wrappers/Attestations.ts index 67d45a8be9b..5787d06d4bb 100644 --- a/packages/sdk/contractkit/src/wrappers/Attestations.ts +++ b/packages/sdk/contractkit/src/wrappers/Attestations.ts @@ -1,4 +1,4 @@ -import { Attestations } from '@celo/abis/types/web3/Attestations' +import { Attestations } from '@celo/abis/web3/Attestations' import { StableToken } from '@celo/base' import { eqAddress } from '@celo/base/lib/address' import { Address, Connection, toTransactionObject } from '@celo/connect' diff --git a/packages/sdk/contractkit/src/wrappers/BaseWrapper.test.ts b/packages/sdk/contractkit/src/wrappers/BaseWrapper.test.ts index c9b29a43033..fa52d068888 100644 --- a/packages/sdk/contractkit/src/wrappers/BaseWrapper.test.ts +++ b/packages/sdk/contractkit/src/wrappers/BaseWrapper.test.ts @@ -5,7 +5,7 @@ import Web3 from 'web3' import { ICeloVersionedContract, newICeloVersionedContract, -} from '@celo/abis/types/web3/ICeloVersionedContract' +} from '@celo/abis/web3/ICeloVersionedContract' import { ContractVersion, newContractVersion } from '../versions' import { BaseWrapper, unixSecondsTimestampToDateString } from './BaseWrapper' diff --git a/packages/sdk/contractkit/src/wrappers/BaseWrapper.ts b/packages/sdk/contractkit/src/wrappers/BaseWrapper.ts index b65871b9f07..efce69af554 100644 --- a/packages/sdk/contractkit/src/wrappers/BaseWrapper.ts +++ b/packages/sdk/contractkit/src/wrappers/BaseWrapper.ts @@ -1,4 +1,4 @@ -import { ICeloVersionedContract } from '@celo/abis/types/web3/ICeloVersionedContract' +import { ICeloVersionedContract } from '@celo/abis/web3/ICeloVersionedContract' import { bufferToHex, ensureLeading0x } from '@celo/base/lib/address' import { zip } from '@celo/base/lib/collections' import { diff --git a/packages/sdk/contractkit/src/wrappers/BlockChainParameters.test.ts b/packages/sdk/contractkit/src/wrappers/BlockChainParameters.test.ts index fc877ae747c..c677dba2d55 100644 --- a/packages/sdk/contractkit/src/wrappers/BlockChainParameters.test.ts +++ b/packages/sdk/contractkit/src/wrappers/BlockChainParameters.test.ts @@ -3,7 +3,7 @@ import { testWithGanache } from '@celo/dev-utils/lib/ganache-test' import BigNumber from 'bignumber.js' import { AddressRegistry } from '../address-registry' import { CeloContract } from '../base' -import { newBlockchainParameters } from '@celo/abis/types/web3/BlockchainParameters' +import { newBlockchainParameters } from '@celo/abis/web3/BlockchainParameters' import { BlockchainParametersWrapper } from './BlockchainParameters' testWithGanache('BlockChainParametersWrapper', (web3) => { diff --git a/packages/sdk/contractkit/src/wrappers/BlockchainParameters.ts b/packages/sdk/contractkit/src/wrappers/BlockchainParameters.ts index 29869d44031..30e04f7c051 100644 --- a/packages/sdk/contractkit/src/wrappers/BlockchainParameters.ts +++ b/packages/sdk/contractkit/src/wrappers/BlockchainParameters.ts @@ -1,4 +1,4 @@ -import { BlockchainParameters } from '@celo/abis/types/web3/BlockchainParameters' +import { BlockchainParameters } from '@celo/abis/web3/BlockchainParameters' import { BigNumber } from 'bignumber.js' import { BaseWrapper, proxyCall, proxySend, valueToBigNumber, valueToInt } from './BaseWrapper' diff --git a/packages/sdk/contractkit/src/wrappers/CeloTokenWrapper.ts b/packages/sdk/contractkit/src/wrappers/CeloTokenWrapper.ts index 908b1bdf838..255f2c44cca 100644 --- a/packages/sdk/contractkit/src/wrappers/CeloTokenWrapper.ts +++ b/packages/sdk/contractkit/src/wrappers/CeloTokenWrapper.ts @@ -1,8 +1,8 @@ // NOTE: removing this import results in `yarn build` failures in Dockerfiles // after the move to node 10. This allows types to be inferred without // referencing '@celo/utils/node_modules/bignumber.js' -import { ICeloToken } from '@celo/abis/types/web3/ICeloToken' -import { IERC20 } from '@celo/abis/types/web3/IERC20' +import { ICeloToken } from '@celo/abis/web3/ICeloToken' +import { IERC20 } from '@celo/abis/web3/IERC20' import 'bignumber.js' import { proxyCall, proxySend, valueToInt } from './BaseWrapper' import { Erc20Wrapper } from './Erc20Wrapper' diff --git a/packages/sdk/contractkit/src/wrappers/DoubleSigningSlasher.ts b/packages/sdk/contractkit/src/wrappers/DoubleSigningSlasher.ts index 40cb2596646..6958b59b815 100644 --- a/packages/sdk/contractkit/src/wrappers/DoubleSigningSlasher.ts +++ b/packages/sdk/contractkit/src/wrappers/DoubleSigningSlasher.ts @@ -1,4 +1,4 @@ -import { DoubleSigningSlasher } from '@celo/abis/types/web3/DoubleSigningSlasher' +import { DoubleSigningSlasher } from '@celo/abis/web3/DoubleSigningSlasher' import { Address } from '@celo/connect' import { BaseSlasher } from './BaseSlasher' import { valueToInt } from './BaseWrapper' diff --git a/packages/sdk/contractkit/src/wrappers/DowntimeSlasher.ts b/packages/sdk/contractkit/src/wrappers/DowntimeSlasher.ts index 0efca96857e..d3ad94bafe5 100644 --- a/packages/sdk/contractkit/src/wrappers/DowntimeSlasher.ts +++ b/packages/sdk/contractkit/src/wrappers/DowntimeSlasher.ts @@ -1,4 +1,4 @@ -import { DowntimeSlasher } from '@celo/abis/types/web3/DowntimeSlasher' +import { DowntimeSlasher } from '@celo/abis/web3/DowntimeSlasher' import { Address } from '@celo/connect' import BigNumber from 'bignumber.js' import { BaseSlasher } from './BaseSlasher' diff --git a/packages/sdk/contractkit/src/wrappers/Election.ts b/packages/sdk/contractkit/src/wrappers/Election.ts index e8b07206c5c..61e8e164fb6 100644 --- a/packages/sdk/contractkit/src/wrappers/Election.ts +++ b/packages/sdk/contractkit/src/wrappers/Election.ts @@ -1,4 +1,4 @@ -import { Election } from '@celo/abis/types/web3/Election' +import { Election } from '@celo/abis/web3/Election' import { eqAddress, findAddressIndex, diff --git a/packages/sdk/contractkit/src/wrappers/EpochRewards.ts b/packages/sdk/contractkit/src/wrappers/EpochRewards.ts index 6fc1a1179dd..c69d6b9244c 100644 --- a/packages/sdk/contractkit/src/wrappers/EpochRewards.ts +++ b/packages/sdk/contractkit/src/wrappers/EpochRewards.ts @@ -1,4 +1,4 @@ -import { EpochRewards } from '@celo/abis/types/web3/EpochRewards' +import { EpochRewards } from '@celo/abis/web3/EpochRewards' import { fromFixed } from '@celo/utils/lib/fixidity' import { BaseWrapper, proxyCall, valueToBigNumber } from './BaseWrapper' diff --git a/packages/sdk/contractkit/src/wrappers/Erc20Wrapper.ts b/packages/sdk/contractkit/src/wrappers/Erc20Wrapper.ts index 5b28b8b143d..b9228cd455f 100644 --- a/packages/sdk/contractkit/src/wrappers/Erc20Wrapper.ts +++ b/packages/sdk/contractkit/src/wrappers/Erc20Wrapper.ts @@ -1,7 +1,7 @@ // NOTE: removing this import results in `yarn build` failures in Dockerfiles // after the move to node 10. This allows types to be inferred without // referencing '@celo/utils/node_modules/bignumber.js' -import { IERC20 } from '@celo/abis/types/web3/IERC20' +import { IERC20 } from '@celo/abis/web3/IERC20' import BigNumber from 'bignumber.js' import { BaseWrapper, proxyCall, proxySend, valueToBigNumber } from './BaseWrapper' diff --git a/packages/sdk/contractkit/src/wrappers/Escrow.ts b/packages/sdk/contractkit/src/wrappers/Escrow.ts index f2ef70a62b2..142022303f9 100644 --- a/packages/sdk/contractkit/src/wrappers/Escrow.ts +++ b/packages/sdk/contractkit/src/wrappers/Escrow.ts @@ -1,4 +1,4 @@ -import { Escrow } from '@celo/abis/types/web3/Escrow' +import { Escrow } from '@celo/abis/web3/Escrow' import { Address, CeloTransactionObject } from '@celo/connect' import { BaseWrapper, proxyCall, proxySend } from './BaseWrapper' diff --git a/packages/sdk/contractkit/src/wrappers/Exchange.ts b/packages/sdk/contractkit/src/wrappers/Exchange.ts index 5661cde2c62..8ebb1482edb 100644 --- a/packages/sdk/contractkit/src/wrappers/Exchange.ts +++ b/packages/sdk/contractkit/src/wrappers/Exchange.ts @@ -1,4 +1,4 @@ -import { Exchange } from '@celo/abis/types/web3/mento/Exchange' +import { Exchange } from '@celo/abis/web3/mento/Exchange' import { CeloTransactionObject } from '@celo/connect' import BigNumber from 'bignumber.js' import { diff --git a/packages/sdk/contractkit/src/wrappers/FederatedAttestations.ts b/packages/sdk/contractkit/src/wrappers/FederatedAttestations.ts index a8e5f660c6a..86e65e5c34e 100644 --- a/packages/sdk/contractkit/src/wrappers/FederatedAttestations.ts +++ b/packages/sdk/contractkit/src/wrappers/FederatedAttestations.ts @@ -1,4 +1,4 @@ -import { FederatedAttestations } from '@celo/abis/types/web3/FederatedAttestations' +import { FederatedAttestations } from '@celo/abis/web3/FederatedAttestations' import { Address, CeloTransactionObject, toTransactionObject } from '@celo/connect' import { registerAttestation as buildRegisterAttestationTypedData } from '@celo/utils/lib/typed-data-constructors' import { BaseWrapper, proxyCall, proxySend } from './BaseWrapper' diff --git a/packages/sdk/contractkit/src/wrappers/FeeHandler.ts b/packages/sdk/contractkit/src/wrappers/FeeHandler.ts index 1990e3ce60a..1d90fad4272 100644 --- a/packages/sdk/contractkit/src/wrappers/FeeHandler.ts +++ b/packages/sdk/contractkit/src/wrappers/FeeHandler.ts @@ -1,4 +1,4 @@ -import { FeeHandler } from '@celo/abis/types/web3/FeeHandler' +import { FeeHandler } from '@celo/abis/web3/FeeHandler' import { Address } from '@celo/connect' import BigNumber from 'bignumber.js' import { StableTokenContract } from '../base' diff --git a/packages/sdk/contractkit/src/wrappers/Freezer.ts b/packages/sdk/contractkit/src/wrappers/Freezer.ts index c961af9be04..26200c9020a 100644 --- a/packages/sdk/contractkit/src/wrappers/Freezer.ts +++ b/packages/sdk/contractkit/src/wrappers/Freezer.ts @@ -1,4 +1,4 @@ -import { Freezer } from '@celo/abis/types/web3/Freezer' +import { Freezer } from '@celo/abis/web3/Freezer' import { BaseWrapper, proxyCall, proxySend } from './BaseWrapper' export class FreezerWrapper extends BaseWrapper { diff --git a/packages/sdk/contractkit/src/wrappers/GasPriceMinimum.ts b/packages/sdk/contractkit/src/wrappers/GasPriceMinimum.ts index c425943c73d..821820f35a7 100644 --- a/packages/sdk/contractkit/src/wrappers/GasPriceMinimum.ts +++ b/packages/sdk/contractkit/src/wrappers/GasPriceMinimum.ts @@ -1,4 +1,4 @@ -import { GasPriceMinimum } from '@celo/abis/types/web3/0.8/GasPriceMinimum' +import { GasPriceMinimum } from '@celo/abis/web3/0.8/GasPriceMinimum' import BigNumber from 'bignumber.js' import { BaseWrapper, fixidityValueToBigNumber, proxyCall, valueToBigNumber } from './BaseWrapper' diff --git a/packages/sdk/contractkit/src/wrappers/GoldTokenWrapper.ts b/packages/sdk/contractkit/src/wrappers/GoldTokenWrapper.ts index df3dc1f573a..3943441b8c8 100644 --- a/packages/sdk/contractkit/src/wrappers/GoldTokenWrapper.ts +++ b/packages/sdk/contractkit/src/wrappers/GoldTokenWrapper.ts @@ -1,7 +1,7 @@ // NOTE: removing this import results in `yarn build` failures in Dockerfiles // after the move to node 10. This allows types to be inferred without // referencing '@celo/utils/node_modules/bignumber.js' -import { GoldToken } from '@celo/abis/types/web3/GoldToken' +import { GoldToken } from '@celo/abis/web3/GoldToken' import { Address } from '@celo/base' import 'bignumber.js' import { diff --git a/packages/sdk/contractkit/src/wrappers/Governance.test.ts b/packages/sdk/contractkit/src/wrappers/Governance.test.ts index 1e19f91e443..fc45bcbd03f 100644 --- a/packages/sdk/contractkit/src/wrappers/Governance.test.ts +++ b/packages/sdk/contractkit/src/wrappers/Governance.test.ts @@ -4,7 +4,7 @@ import { NetworkConfig, testWithGanache, timeTravel } from '@celo/dev-utils/lib/ import BigNumber from 'bignumber.js' import Web3 from 'web3' import { CeloContract } from '..' -import { Registry } from '@celo/abis/types/web3/Registry' +import { Registry } from '@celo/abis/web3/Registry' import { newKitFromWeb3 } from '../kit' import { AccountsWrapper } from './Accounts' import { GovernanceWrapper, Proposal, ProposalTransaction, VoteValue } from './Governance' diff --git a/packages/sdk/contractkit/src/wrappers/Governance.ts b/packages/sdk/contractkit/src/wrappers/Governance.ts index 80a60f0bd4b..21ca62316bd 100644 --- a/packages/sdk/contractkit/src/wrappers/Governance.ts +++ b/packages/sdk/contractkit/src/wrappers/Governance.ts @@ -1,4 +1,4 @@ -import { Governance } from '@celo/abis/types/web3/Governance' +import { Governance } from '@celo/abis/web3/Governance' import { bufferToHex, ensureLeading0x, diff --git a/packages/sdk/contractkit/src/wrappers/GrandaMento.ts b/packages/sdk/contractkit/src/wrappers/GrandaMento.ts index 18792c773e8..591ef31ae7a 100644 --- a/packages/sdk/contractkit/src/wrappers/GrandaMento.ts +++ b/packages/sdk/contractkit/src/wrappers/GrandaMento.ts @@ -1,5 +1,5 @@ -import { GrandaMento } from '@celo/abis/types/web3/mento/GrandaMento' -import { newStableToken } from '@celo/abis/types/web3/mento/StableToken' +import { GrandaMento } from '@celo/abis/web3/mento/GrandaMento' +import { newStableToken } from '@celo/abis/web3/mento/StableToken' import BigNumber from 'bignumber.js' import { StableTokenContract } from '../base' import { StableToken as StableTokenEnum, stableTokenInfos } from '../celo-tokens' diff --git a/packages/sdk/contractkit/src/wrappers/LockedGold.ts b/packages/sdk/contractkit/src/wrappers/LockedGold.ts index 3f140f8f127..2101df4cc84 100644 --- a/packages/sdk/contractkit/src/wrappers/LockedGold.ts +++ b/packages/sdk/contractkit/src/wrappers/LockedGold.ts @@ -1,4 +1,4 @@ -import { LockedGold } from '@celo/abis/types/web3/LockedGold' +import { LockedGold } from '@celo/abis/web3/LockedGold' import { AddressListItem as ALI, Comparator, diff --git a/packages/sdk/contractkit/src/wrappers/MetaTransactionWallet.ts b/packages/sdk/contractkit/src/wrappers/MetaTransactionWallet.ts index eb561a95f70..fa38d5d229c 100644 --- a/packages/sdk/contractkit/src/wrappers/MetaTransactionWallet.ts +++ b/packages/sdk/contractkit/src/wrappers/MetaTransactionWallet.ts @@ -1,4 +1,4 @@ -import { MetaTransactionWallet } from '@celo/abis/types/web3/MetaTransactionWallet' +import { MetaTransactionWallet } from '@celo/abis/web3/MetaTransactionWallet' import { Address, ensureLeading0x, trimLeading0x } from '@celo/base/lib/address' import { Signature } from '@celo/base/lib/signatureUtils' import { CeloTransactionObject, CeloTxObject, toTransactionObject } from '@celo/connect' diff --git a/packages/sdk/contractkit/src/wrappers/MetaTransactionWalletDeployer.test.ts b/packages/sdk/contractkit/src/wrappers/MetaTransactionWalletDeployer.test.ts index 420bfd8b03e..e23271ea481 100644 --- a/packages/sdk/contractkit/src/wrappers/MetaTransactionWalletDeployer.test.ts +++ b/packages/sdk/contractkit/src/wrappers/MetaTransactionWalletDeployer.test.ts @@ -6,8 +6,8 @@ import { testWithGanache } from '@celo/dev-utils/lib/ganache-test' import { MetaTransactionWallet, newMetaTransactionWallet, -} from '@celo/abis/types/web3/MetaTransactionWallet' -import { newProxy } from '@celo/abis/types/web3/Proxy' +} from '@celo/abis/web3/MetaTransactionWallet' +import { newProxy } from '@celo/abis/web3/Proxy' import { newKitFromWeb3 } from '../kit' import { MetaTransactionWalletDeployerWrapper } from './MetaTransactionWalletDeployer' diff --git a/packages/sdk/contractkit/src/wrappers/MetaTransactionWalletDeployer.ts b/packages/sdk/contractkit/src/wrappers/MetaTransactionWalletDeployer.ts index f6be41356cf..4cbc46da035 100644 --- a/packages/sdk/contractkit/src/wrappers/MetaTransactionWalletDeployer.ts +++ b/packages/sdk/contractkit/src/wrappers/MetaTransactionWalletDeployer.ts @@ -1,4 +1,4 @@ -import { MetaTransactionWalletDeployer } from '@celo/abis/types/web3/MetaTransactionWalletDeployer' +import { MetaTransactionWalletDeployer } from '@celo/abis/web3/MetaTransactionWalletDeployer' import { BaseWrapper, proxySend } from './BaseWrapper' /* diff --git a/packages/sdk/contractkit/src/wrappers/MultiSig.ts b/packages/sdk/contractkit/src/wrappers/MultiSig.ts index f570f9b0572..d009a91bb19 100644 --- a/packages/sdk/contractkit/src/wrappers/MultiSig.ts +++ b/packages/sdk/contractkit/src/wrappers/MultiSig.ts @@ -1,4 +1,4 @@ -import { MultiSig } from '@celo/abis/types/web3/MultiSig' +import { MultiSig } from '@celo/abis/web3/MultiSig' import { Address, CeloTransactionObject, CeloTxObject, toTransactionObject } from '@celo/connect' import BigNumber from 'bignumber.js' import { diff --git a/packages/sdk/contractkit/src/wrappers/OdisPayments.ts b/packages/sdk/contractkit/src/wrappers/OdisPayments.ts index 66cdca972e5..5777c5e670b 100644 --- a/packages/sdk/contractkit/src/wrappers/OdisPayments.ts +++ b/packages/sdk/contractkit/src/wrappers/OdisPayments.ts @@ -1,4 +1,4 @@ -import { OdisPayments } from '@celo/abis/types/web3/OdisPayments' +import { OdisPayments } from '@celo/abis/web3/OdisPayments' import { Address, CeloTransactionObject } from '@celo/connect' import { BigNumber } from 'bignumber.js' import { BaseWrapper, proxyCall, proxySend, valueToBigNumber } from './BaseWrapper' diff --git a/packages/sdk/contractkit/src/wrappers/ReleaseGold.ts b/packages/sdk/contractkit/src/wrappers/ReleaseGold.ts index 5479d0f530f..186e0c728ac 100644 --- a/packages/sdk/contractkit/src/wrappers/ReleaseGold.ts +++ b/packages/sdk/contractkit/src/wrappers/ReleaseGold.ts @@ -1,4 +1,4 @@ -import { ReleaseGold } from '@celo/abis/types/web3/ReleaseGold' +import { ReleaseGold } from '@celo/abis/web3/ReleaseGold' import { concurrentMap } from '@celo/base' import { findAddressIndex } from '@celo/base/lib/address' import { Signature } from '@celo/base/lib/signatureUtils' diff --git a/packages/sdk/contractkit/src/wrappers/Reserve.ts b/packages/sdk/contractkit/src/wrappers/Reserve.ts index 394ed9fdc9e..05b7f3a8e99 100644 --- a/packages/sdk/contractkit/src/wrappers/Reserve.ts +++ b/packages/sdk/contractkit/src/wrappers/Reserve.ts @@ -1,4 +1,4 @@ -import { Reserve } from '@celo/abis/types/web3/mento/Reserve' +import { Reserve } from '@celo/abis/web3/mento/Reserve' import { Address, EventLog } from '@celo/connect' import BigNumber from 'bignumber.js' import { diff --git a/packages/sdk/contractkit/src/wrappers/SortedOracles.ts b/packages/sdk/contractkit/src/wrappers/SortedOracles.ts index 1b48c194538..af14060b301 100644 --- a/packages/sdk/contractkit/src/wrappers/SortedOracles.ts +++ b/packages/sdk/contractkit/src/wrappers/SortedOracles.ts @@ -1,4 +1,4 @@ -import { SortedOracles } from '@celo/abis/types/web3/SortedOracles' +import { SortedOracles } from '@celo/abis/web3/SortedOracles' import { eqAddress, NULL_ADDRESS } from '@celo/base/lib/address' import { Address, CeloTransactionObject, Connection, toTransactionObject } from '@celo/connect' import { isValidAddress } from '@celo/utils/lib/address' diff --git a/packages/sdk/contractkit/src/wrappers/StableTokenWrapper.ts b/packages/sdk/contractkit/src/wrappers/StableTokenWrapper.ts index 35169c72ad6..bb0a0f76d01 100644 --- a/packages/sdk/contractkit/src/wrappers/StableTokenWrapper.ts +++ b/packages/sdk/contractkit/src/wrappers/StableTokenWrapper.ts @@ -1,4 +1,4 @@ -import { StableToken } from '@celo/abis/types/web3/mento/StableToken' +import { StableToken } from '@celo/abis/web3/mento/StableToken' import { fromFixed } from '@celo/utils/lib/fixidity' import BigNumber from 'bignumber.js' import { diff --git a/packages/sdk/contractkit/src/wrappers/Validators.ts b/packages/sdk/contractkit/src/wrappers/Validators.ts index 4f00ac8b14c..255d06b5bc7 100644 --- a/packages/sdk/contractkit/src/wrappers/Validators.ts +++ b/packages/sdk/contractkit/src/wrappers/Validators.ts @@ -1,4 +1,4 @@ -import { Validators } from '@celo/abis/types/web3/Validators' +import { Validators } from '@celo/abis/web3/Validators' import { eqAddress, findAddressIndex, NULL_ADDRESS } from '@celo/base/lib/address' import { concurrentMap } from '@celo/base/lib/async' import { zeroRange, zip } from '@celo/base/lib/collections' diff --git a/packages/sdk/governance/src/proposals.ts b/packages/sdk/governance/src/proposals.ts index bad02d3b43e..29d9ba664b7 100644 --- a/packages/sdk/governance/src/proposals.ts +++ b/packages/sdk/governance/src/proposals.ts @@ -1,5 +1,5 @@ -import { ABI as GovernanceABI } from '@celo/abis/types/web3/Governance' -import { ABI as RegistryABI } from '@celo/abis/types/web3/Registry' +import { ABI as GovernanceABI } from '@celo/abis/web3/Governance' +import { ABI as RegistryABI } from '@celo/abis/web3/Registry' import { Address, isHexString, trimLeading0x } from '@celo/base/lib/address' import { AbiCoder, @@ -462,7 +462,7 @@ export class InteractiveProposalBuilder { } const contractName = choice as CeloContract - const contractABI = require('@celo/abis/types/web3/' + contractName).ABI as ABIDefinition[] + const contractABI = require('@celo/abis/web3/' + contractName).ABI as ABIDefinition[] const txMethods = contractABI.filter( (def) => def.type === 'function' && def.stateMutability !== 'view' From 53c9529166c489803aad80dd314d0e40078123b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Volpe?= Date: Mon, 4 Dec 2023 17:01:36 +0100 Subject: [PATCH 51/63] Foundry Compile contracts job (#10807) --- .github/workflows/protocol_tests.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/protocol_tests.yml b/.github/workflows/protocol_tests.yml index b28f036eb56..443f2c75d49 100644 --- a/.github/workflows/protocol_tests.yml +++ b/.github/workflows/protocol_tests.yml @@ -33,5 +33,10 @@ jobs: - name: Install forge dependencies run: forge install + # "Run tests" already tries to compile the contracts + # Making it explicit here to have easier to read errors + - name: Compile Contracts + run: forge compile + - name: Run tests - run: forge test -vvv \ No newline at end of file + run: forge test -vvv From bb9eabfe934dab7eeb4abaf3a5ef14992677ed7a Mon Sep 17 00:00:00 2001 From: Leszek Stachowski Date: Mon, 4 Dec 2023 17:29:02 +0100 Subject: [PATCH 52/63] comment out temporarily --- .../scripts/prepare-contracts-and-abis-publishing.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts b/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts index d48382a488a..3e38fa522ca 100644 --- a/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts +++ b/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts @@ -106,10 +106,10 @@ function prepareTargetTypesExports() { targets.forEach((target) => { // We don't need package.json for type declarations if (target != BuildTarget.TYPES) { - fs.copyFileSync( - path.join(ABIS_PACKAGE_SRC_DIR, `package-${target}.json`), - path.join(ABIS_DIST_DIR, target, 'package.json') - ) + // fs.copyFileSync( + // path.join(ABIS_PACKAGE_SRC_DIR, `package-${target}.json`), + // path.join(ABIS_DIST_DIR, target, 'package.json') + // ) } const filePaths = lsRecursive(path.join(ABIS_DIST_DIR, target)) From b3478337f8fb4e51f6f07ce73dd9668fbc72b7e6 Mon Sep 17 00:00:00 2001 From: Leszek Stachowski Date: Mon, 4 Dec 2023 17:47:52 +0100 Subject: [PATCH 53/63] is this the changed file? + uncomment --- packages/protocol/abis/package.json | 698 +++++++++--------- .../prepare-contracts-and-abis-publishing.ts | 8 +- 2 files changed, 353 insertions(+), 353 deletions(-) diff --git a/packages/protocol/abis/package.json b/packages/protocol/abis/package.json index ee3fc51c839..6ce2f55bf61 100644 --- a/packages/protocol/abis/package.json +++ b/packages/protocol/abis/package.json @@ -137,355 +137,355 @@ "./Validators.json": { "default": "./dist/Validators.json" }, - "./types/wagmi/Accounts": { - "import": "./dist/esm/types/wagmi/Accounts.js", - "require": "./dist/cjs/types/wagmi/Accounts.js", - "types": "./dist/types/types/wagmi/Accounts.d.ts" - }, - "./types/wagmi/Attestations": { - "import": "./dist/esm/types/wagmi/Attestations.js", - "require": "./dist/cjs/types/wagmi/Attestations.js", - "types": "./dist/types/types/wagmi/Attestations.d.ts" - }, - "./types/wagmi/BlockchainParameters": { - "import": "./dist/esm/types/wagmi/BlockchainParameters.js", - "require": "./dist/cjs/types/wagmi/BlockchainParameters.js", - "types": "./dist/types/types/wagmi/BlockchainParameters.d.ts" - }, - "./types/wagmi/DoubleSigningSlasher": { - "import": "./dist/esm/types/wagmi/DoubleSigningSlasher.js", - "require": "./dist/cjs/types/wagmi/DoubleSigningSlasher.js", - "types": "./dist/types/types/wagmi/DoubleSigningSlasher.d.ts" - }, - "./types/wagmi/DowntimeSlasher": { - "import": "./dist/esm/types/wagmi/DowntimeSlasher.js", - "require": "./dist/cjs/types/wagmi/DowntimeSlasher.js", - "types": "./dist/types/types/wagmi/DowntimeSlasher.d.ts" - }, - "./types/wagmi/Election": { - "import": "./dist/esm/types/wagmi/Election.js", - "require": "./dist/cjs/types/wagmi/Election.js", - "types": "./dist/types/types/wagmi/Election.d.ts" - }, - "./types/wagmi/EpochRewards": { - "import": "./dist/esm/types/wagmi/EpochRewards.js", - "require": "./dist/cjs/types/wagmi/EpochRewards.js", - "types": "./dist/types/types/wagmi/EpochRewards.d.ts" - }, - "./types/wagmi/Escrow": { - "import": "./dist/esm/types/wagmi/Escrow.js", - "require": "./dist/cjs/types/wagmi/Escrow.js", - "types": "./dist/types/types/wagmi/Escrow.d.ts" - }, - "./types/wagmi/FederatedAttestations": { - "import": "./dist/esm/types/wagmi/FederatedAttestations.js", - "require": "./dist/cjs/types/wagmi/FederatedAttestations.js", - "types": "./dist/types/types/wagmi/FederatedAttestations.d.ts" - }, - "./types/wagmi/FeeCurrencyWhitelist": { - "import": "./dist/esm/types/wagmi/FeeCurrencyWhitelist.js", - "require": "./dist/cjs/types/wagmi/FeeCurrencyWhitelist.js", - "types": "./dist/types/types/wagmi/FeeCurrencyWhitelist.d.ts" - }, - "./types/wagmi/FeeHandler": { - "import": "./dist/esm/types/wagmi/FeeHandler.js", - "require": "./dist/cjs/types/wagmi/FeeHandler.js", - "types": "./dist/types/types/wagmi/FeeHandler.d.ts" - }, - "./types/wagmi/Freezer": { - "import": "./dist/esm/types/wagmi/Freezer.js", - "require": "./dist/cjs/types/wagmi/Freezer.js", - "types": "./dist/types/types/wagmi/Freezer.d.ts" - }, - "./types/wagmi/GasPriceMinimum": { - "import": "./dist/esm/types/wagmi/GasPriceMinimum.js", - "require": "./dist/cjs/types/wagmi/GasPriceMinimum.js", - "types": "./dist/types/types/wagmi/GasPriceMinimum.d.ts" - }, - "./types/wagmi/GoldToken": { - "import": "./dist/esm/types/wagmi/GoldToken.js", - "require": "./dist/cjs/types/wagmi/GoldToken.js", - "types": "./dist/types/types/wagmi/GoldToken.d.ts" - }, - "./types/wagmi/Governance": { - "import": "./dist/esm/types/wagmi/Governance.js", - "require": "./dist/cjs/types/wagmi/Governance.js", - "types": "./dist/types/types/wagmi/Governance.d.ts" - }, - "./types/wagmi/GovernanceApproverMultiSig": { - "import": "./dist/esm/types/wagmi/GovernanceApproverMultiSig.js", - "require": "./dist/cjs/types/wagmi/GovernanceApproverMultiSig.js", - "types": "./dist/types/types/wagmi/GovernanceApproverMultiSig.d.ts" - }, - "./types/wagmi/LockedGold": { - "import": "./dist/esm/types/wagmi/LockedGold.js", - "require": "./dist/cjs/types/wagmi/LockedGold.js", - "types": "./dist/types/types/wagmi/LockedGold.d.ts" - }, - "./types/wagmi/MentoFeeHandlerSeller": { - "import": "./dist/esm/types/wagmi/MentoFeeHandlerSeller.js", - "require": "./dist/cjs/types/wagmi/MentoFeeHandlerSeller.js", - "types": "./dist/types/types/wagmi/MentoFeeHandlerSeller.d.ts" - }, - "./types/wagmi/MetaTransactionWallet": { - "import": "./dist/esm/types/wagmi/MetaTransactionWallet.js", - "require": "./dist/cjs/types/wagmi/MetaTransactionWallet.js", - "types": "./dist/types/types/wagmi/MetaTransactionWallet.d.ts" - }, - "./types/wagmi/MetaTransactionWalletDeployer": { - "import": "./dist/esm/types/wagmi/MetaTransactionWalletDeployer.js", - "require": "./dist/cjs/types/wagmi/MetaTransactionWalletDeployer.js", - "types": "./dist/types/types/wagmi/MetaTransactionWalletDeployer.d.ts" - }, - "./types/wagmi/MultiSig": { - "import": "./dist/esm/types/wagmi/MultiSig.js", - "require": "./dist/cjs/types/wagmi/MultiSig.js", - "types": "./dist/types/types/wagmi/MultiSig.d.ts" - }, - "./types/wagmi/OdisPayments": { - "import": "./dist/esm/types/wagmi/OdisPayments.js", - "require": "./dist/cjs/types/wagmi/OdisPayments.js", - "types": "./dist/types/types/wagmi/OdisPayments.d.ts" - }, - "./types/wagmi/Random": { - "import": "./dist/esm/types/wagmi/Random.js", - "require": "./dist/cjs/types/wagmi/Random.js", - "types": "./dist/types/types/wagmi/Random.d.ts" - }, - "./types/wagmi/Registry": { - "import": "./dist/esm/types/wagmi/Registry.js", - "require": "./dist/cjs/types/wagmi/Registry.js", - "types": "./dist/types/types/wagmi/Registry.d.ts" - }, - "./types/wagmi/ReleaseGold": { - "import": "./dist/esm/types/wagmi/ReleaseGold.js", - "require": "./dist/cjs/types/wagmi/ReleaseGold.js", - "types": "./dist/types/types/wagmi/ReleaseGold.d.ts" - }, - "./types/wagmi/SortedOracles": { - "import": "./dist/esm/types/wagmi/SortedOracles.js", - "require": "./dist/cjs/types/wagmi/SortedOracles.js", - "types": "./dist/types/types/wagmi/SortedOracles.d.ts" - }, - "./types/wagmi/UniswapFeeHandlerSeller": { - "import": "./dist/esm/types/wagmi/UniswapFeeHandlerSeller.js", - "require": "./dist/cjs/types/wagmi/UniswapFeeHandlerSeller.js", - "types": "./dist/types/types/wagmi/UniswapFeeHandlerSeller.d.ts" - }, - "./types/wagmi/Validators": { - "import": "./dist/esm/types/wagmi/Validators.js", - "require": "./dist/cjs/types/wagmi/Validators.js", - "types": "./dist/types/types/wagmi/Validators.d.ts" - }, - "./types/web3/0.8/GasPriceMinimum": { - "import": "./dist/esm/types/web3/0.8/GasPriceMinimum.js", - "require": "./dist/cjs/types/web3/0.8/GasPriceMinimum.js", - "types": "./dist/types/types/web3/0.8/GasPriceMinimum.d.ts" - }, - "./types/web3/Accounts": { - "import": "./dist/esm/types/web3/Accounts.js", - "require": "./dist/cjs/types/web3/Accounts.js", - "types": "./dist/types/types/web3/Accounts.d.ts" - }, - "./types/web3/Attestations": { - "import": "./dist/esm/types/web3/Attestations.js", - "require": "./dist/cjs/types/web3/Attestations.js", - "types": "./dist/types/types/web3/Attestations.d.ts" - }, - "./types/web3/BlockchainParameters": { - "import": "./dist/esm/types/web3/BlockchainParameters.js", - "require": "./dist/cjs/types/web3/BlockchainParameters.js", - "types": "./dist/types/types/web3/BlockchainParameters.d.ts" - }, - "./types/web3/DoubleSigningSlasher": { - "import": "./dist/esm/types/web3/DoubleSigningSlasher.js", - "require": "./dist/cjs/types/web3/DoubleSigningSlasher.js", - "types": "./dist/types/types/web3/DoubleSigningSlasher.d.ts" - }, - "./types/web3/DowntimeSlasher": { - "import": "./dist/esm/types/web3/DowntimeSlasher.js", - "require": "./dist/cjs/types/web3/DowntimeSlasher.js", - "types": "./dist/types/types/web3/DowntimeSlasher.d.ts" - }, - "./types/web3/Election": { - "import": "./dist/esm/types/web3/Election.js", - "require": "./dist/cjs/types/web3/Election.js", - "types": "./dist/types/types/web3/Election.d.ts" - }, - "./types/web3/EpochRewards": { - "import": "./dist/esm/types/web3/EpochRewards.js", - "require": "./dist/cjs/types/web3/EpochRewards.js", - "types": "./dist/types/types/web3/EpochRewards.d.ts" - }, - "./types/web3/Escrow": { - "import": "./dist/esm/types/web3/Escrow.js", - "require": "./dist/cjs/types/web3/Escrow.js", - "types": "./dist/types/types/web3/Escrow.d.ts" - }, - "./types/web3/FederatedAttestations": { - "import": "./dist/esm/types/web3/FederatedAttestations.js", - "require": "./dist/cjs/types/web3/FederatedAttestations.js", - "types": "./dist/types/types/web3/FederatedAttestations.d.ts" - }, - "./types/web3/FeeCurrencyWhitelist": { - "import": "./dist/esm/types/web3/FeeCurrencyWhitelist.js", - "require": "./dist/cjs/types/web3/FeeCurrencyWhitelist.js", - "types": "./dist/types/types/web3/FeeCurrencyWhitelist.d.ts" - }, - "./types/web3/FeeHandler": { - "import": "./dist/esm/types/web3/FeeHandler.js", - "require": "./dist/cjs/types/web3/FeeHandler.js", - "types": "./dist/types/types/web3/FeeHandler.d.ts" - }, - "./types/web3/Freezer": { - "import": "./dist/esm/types/web3/Freezer.js", - "require": "./dist/cjs/types/web3/Freezer.js", - "types": "./dist/types/types/web3/Freezer.d.ts" - }, - "./types/web3/GasPriceMinimum": { - "import": "./dist/esm/types/web3/GasPriceMinimum.js", - "require": "./dist/cjs/types/web3/GasPriceMinimum.js", - "types": "./dist/types/types/web3/GasPriceMinimum.d.ts" - }, - "./types/web3/GoldToken": { - "import": "./dist/esm/types/web3/GoldToken.js", - "require": "./dist/cjs/types/web3/GoldToken.js", - "types": "./dist/types/types/web3/GoldToken.d.ts" - }, - "./types/web3/Governance": { - "import": "./dist/esm/types/web3/Governance.js", - "require": "./dist/cjs/types/web3/Governance.js", - "types": "./dist/types/types/web3/Governance.d.ts" - }, - "./types/web3/GovernanceApproverMultiSig": { - "import": "./dist/esm/types/web3/GovernanceApproverMultiSig.js", - "require": "./dist/cjs/types/web3/GovernanceApproverMultiSig.js", - "types": "./dist/types/types/web3/GovernanceApproverMultiSig.d.ts" - }, - "./types/web3/ICeloToken": { - "import": "./dist/esm/types/web3/ICeloToken.js", - "require": "./dist/cjs/types/web3/ICeloToken.js", - "types": "./dist/types/types/web3/ICeloToken.d.ts" - }, - "./types/web3/ICeloVersionedContract": { - "import": "./dist/esm/types/web3/ICeloVersionedContract.js", - "require": "./dist/cjs/types/web3/ICeloVersionedContract.js", - "types": "./dist/types/types/web3/ICeloVersionedContract.d.ts" - }, - "./types/web3/IERC20": { - "import": "./dist/esm/types/web3/IERC20.js", - "require": "./dist/cjs/types/web3/IERC20.js", - "types": "./dist/types/types/web3/IERC20.d.ts" - }, - "./types/web3/LockedGold": { - "import": "./dist/esm/types/web3/LockedGold.js", - "require": "./dist/cjs/types/web3/LockedGold.js", - "types": "./dist/types/types/web3/LockedGold.d.ts" - }, - "./types/web3/MentoFeeHandlerSeller": { - "import": "./dist/esm/types/web3/MentoFeeHandlerSeller.js", - "require": "./dist/cjs/types/web3/MentoFeeHandlerSeller.js", - "types": "./dist/types/types/web3/MentoFeeHandlerSeller.d.ts" - }, - "./types/web3/MetaTransactionWallet": { - "import": "./dist/esm/types/web3/MetaTransactionWallet.js", - "require": "./dist/cjs/types/web3/MetaTransactionWallet.js", - "types": "./dist/types/types/web3/MetaTransactionWallet.d.ts" - }, - "./types/web3/MetaTransactionWalletDeployer": { - "import": "./dist/esm/types/web3/MetaTransactionWalletDeployer.js", - "require": "./dist/cjs/types/web3/MetaTransactionWalletDeployer.js", - "types": "./dist/types/types/web3/MetaTransactionWalletDeployer.d.ts" - }, - "./types/web3/MultiSig": { - "import": "./dist/esm/types/web3/MultiSig.js", - "require": "./dist/cjs/types/web3/MultiSig.js", - "types": "./dist/types/types/web3/MultiSig.d.ts" - }, - "./types/web3/OdisPayments": { - "import": "./dist/esm/types/web3/OdisPayments.js", - "require": "./dist/cjs/types/web3/OdisPayments.js", - "types": "./dist/types/types/web3/OdisPayments.d.ts" - }, - "./types/web3/Proxy": { - "import": "./dist/esm/types/web3/Proxy.js", - "require": "./dist/cjs/types/web3/Proxy.js", - "types": "./dist/types/types/web3/Proxy.d.ts" - }, - "./types/web3/Random": { - "import": "./dist/esm/types/web3/Random.js", - "require": "./dist/cjs/types/web3/Random.js", - "types": "./dist/types/types/web3/Random.d.ts" - }, - "./types/web3/Registry": { - "import": "./dist/esm/types/web3/Registry.js", - "require": "./dist/cjs/types/web3/Registry.js", - "types": "./dist/types/types/web3/Registry.d.ts" - }, - "./types/web3/ReleaseGold": { - "import": "./dist/esm/types/web3/ReleaseGold.js", - "require": "./dist/cjs/types/web3/ReleaseGold.js", - "types": "./dist/types/types/web3/ReleaseGold.d.ts" - }, - "./types/web3/SortedOracles": { - "import": "./dist/esm/types/web3/SortedOracles.js", - "require": "./dist/cjs/types/web3/SortedOracles.js", - "types": "./dist/types/types/web3/SortedOracles.d.ts" - }, - "./types/web3/UniswapFeeHandlerSeller": { - "import": "./dist/esm/types/web3/UniswapFeeHandlerSeller.js", - "require": "./dist/cjs/types/web3/UniswapFeeHandlerSeller.js", - "types": "./dist/types/types/web3/UniswapFeeHandlerSeller.d.ts" - }, - "./types/web3/Validators": { - "import": "./dist/esm/types/web3/Validators.js", - "require": "./dist/cjs/types/web3/Validators.js", - "types": "./dist/types/types/web3/Validators.d.ts" - }, - "./types/web3/mento/Exchange": { - "import": "./dist/esm/types/web3/mento/Exchange.js", - "require": "./dist/cjs/types/web3/mento/Exchange.js", - "types": "./dist/types/types/web3/mento/Exchange.d.ts" - }, - "./types/web3/mento/ExchangeBRL": { - "import": "./dist/esm/types/web3/mento/ExchangeBRL.js", - "require": "./dist/cjs/types/web3/mento/ExchangeBRL.js", - "types": "./dist/types/types/web3/mento/ExchangeBRL.d.ts" - }, - "./types/web3/mento/ExchangeEUR": { - "import": "./dist/esm/types/web3/mento/ExchangeEUR.js", - "require": "./dist/cjs/types/web3/mento/ExchangeEUR.js", - "types": "./dist/types/types/web3/mento/ExchangeEUR.d.ts" - }, - "./types/web3/mento/GrandaMento": { - "import": "./dist/esm/types/web3/mento/GrandaMento.js", - "require": "./dist/cjs/types/web3/mento/GrandaMento.js", - "types": "./dist/types/types/web3/mento/GrandaMento.d.ts" - }, - "./types/web3/mento/Reserve": { - "import": "./dist/esm/types/web3/mento/Reserve.js", - "require": "./dist/cjs/types/web3/mento/Reserve.js", - "types": "./dist/types/types/web3/mento/Reserve.d.ts" - }, - "./types/web3/mento/ReserveSpenderMultiSig": { - "import": "./dist/esm/types/web3/mento/ReserveSpenderMultiSig.js", - "require": "./dist/cjs/types/web3/mento/ReserveSpenderMultiSig.js", - "types": "./dist/types/types/web3/mento/ReserveSpenderMultiSig.d.ts" - }, - "./types/web3/mento/StableToken": { - "import": "./dist/esm/types/web3/mento/StableToken.js", - "require": "./dist/cjs/types/web3/mento/StableToken.js", - "types": "./dist/types/types/web3/mento/StableToken.d.ts" - }, - "./types/web3/mento/StableTokenBRL": { - "import": "./dist/esm/types/web3/mento/StableTokenBRL.js", - "require": "./dist/cjs/types/web3/mento/StableTokenBRL.js", - "types": "./dist/types/types/web3/mento/StableTokenBRL.d.ts" - }, - "./types/web3/mento/StableTokenEUR": { - "import": "./dist/esm/types/web3/mento/StableTokenEUR.js", - "require": "./dist/cjs/types/web3/mento/StableTokenEUR.js", - "types": "./dist/types/types/web3/mento/StableTokenEUR.d.ts" + "./wagmi/Accounts": { + "import": "./dist/esm/wagmi/Accounts.js", + "require": "./dist/cjs/wagmi/Accounts.js", + "types": "./dist/types/wagmi/Accounts.d.ts" + }, + "./wagmi/Attestations": { + "import": "./dist/esm/wagmi/Attestations.js", + "require": "./dist/cjs/wagmi/Attestations.js", + "types": "./dist/types/wagmi/Attestations.d.ts" + }, + "./wagmi/BlockchainParameters": { + "import": "./dist/esm/wagmi/BlockchainParameters.js", + "require": "./dist/cjs/wagmi/BlockchainParameters.js", + "types": "./dist/types/wagmi/BlockchainParameters.d.ts" + }, + "./wagmi/DoubleSigningSlasher": { + "import": "./dist/esm/wagmi/DoubleSigningSlasher.js", + "require": "./dist/cjs/wagmi/DoubleSigningSlasher.js", + "types": "./dist/types/wagmi/DoubleSigningSlasher.d.ts" + }, + "./wagmi/DowntimeSlasher": { + "import": "./dist/esm/wagmi/DowntimeSlasher.js", + "require": "./dist/cjs/wagmi/DowntimeSlasher.js", + "types": "./dist/types/wagmi/DowntimeSlasher.d.ts" + }, + "./wagmi/Election": { + "import": "./dist/esm/wagmi/Election.js", + "require": "./dist/cjs/wagmi/Election.js", + "types": "./dist/types/wagmi/Election.d.ts" + }, + "./wagmi/EpochRewards": { + "import": "./dist/esm/wagmi/EpochRewards.js", + "require": "./dist/cjs/wagmi/EpochRewards.js", + "types": "./dist/types/wagmi/EpochRewards.d.ts" + }, + "./wagmi/Escrow": { + "import": "./dist/esm/wagmi/Escrow.js", + "require": "./dist/cjs/wagmi/Escrow.js", + "types": "./dist/types/wagmi/Escrow.d.ts" + }, + "./wagmi/FederatedAttestations": { + "import": "./dist/esm/wagmi/FederatedAttestations.js", + "require": "./dist/cjs/wagmi/FederatedAttestations.js", + "types": "./dist/types/wagmi/FederatedAttestations.d.ts" + }, + "./wagmi/FeeCurrencyWhitelist": { + "import": "./dist/esm/wagmi/FeeCurrencyWhitelist.js", + "require": "./dist/cjs/wagmi/FeeCurrencyWhitelist.js", + "types": "./dist/types/wagmi/FeeCurrencyWhitelist.d.ts" + }, + "./wagmi/FeeHandler": { + "import": "./dist/esm/wagmi/FeeHandler.js", + "require": "./dist/cjs/wagmi/FeeHandler.js", + "types": "./dist/types/wagmi/FeeHandler.d.ts" + }, + "./wagmi/Freezer": { + "import": "./dist/esm/wagmi/Freezer.js", + "require": "./dist/cjs/wagmi/Freezer.js", + "types": "./dist/types/wagmi/Freezer.d.ts" + }, + "./wagmi/GasPriceMinimum": { + "import": "./dist/esm/wagmi/GasPriceMinimum.js", + "require": "./dist/cjs/wagmi/GasPriceMinimum.js", + "types": "./dist/types/wagmi/GasPriceMinimum.d.ts" + }, + "./wagmi/GoldToken": { + "import": "./dist/esm/wagmi/GoldToken.js", + "require": "./dist/cjs/wagmi/GoldToken.js", + "types": "./dist/types/wagmi/GoldToken.d.ts" + }, + "./wagmi/Governance": { + "import": "./dist/esm/wagmi/Governance.js", + "require": "./dist/cjs/wagmi/Governance.js", + "types": "./dist/types/wagmi/Governance.d.ts" + }, + "./wagmi/GovernanceApproverMultiSig": { + "import": "./dist/esm/wagmi/GovernanceApproverMultiSig.js", + "require": "./dist/cjs/wagmi/GovernanceApproverMultiSig.js", + "types": "./dist/types/wagmi/GovernanceApproverMultiSig.d.ts" + }, + "./wagmi/LockedGold": { + "import": "./dist/esm/wagmi/LockedGold.js", + "require": "./dist/cjs/wagmi/LockedGold.js", + "types": "./dist/types/wagmi/LockedGold.d.ts" + }, + "./wagmi/MentoFeeHandlerSeller": { + "import": "./dist/esm/wagmi/MentoFeeHandlerSeller.js", + "require": "./dist/cjs/wagmi/MentoFeeHandlerSeller.js", + "types": "./dist/types/wagmi/MentoFeeHandlerSeller.d.ts" + }, + "./wagmi/MetaTransactionWallet": { + "import": "./dist/esm/wagmi/MetaTransactionWallet.js", + "require": "./dist/cjs/wagmi/MetaTransactionWallet.js", + "types": "./dist/types/wagmi/MetaTransactionWallet.d.ts" + }, + "./wagmi/MetaTransactionWalletDeployer": { + "import": "./dist/esm/wagmi/MetaTransactionWalletDeployer.js", + "require": "./dist/cjs/wagmi/MetaTransactionWalletDeployer.js", + "types": "./dist/types/wagmi/MetaTransactionWalletDeployer.d.ts" + }, + "./wagmi/MultiSig": { + "import": "./dist/esm/wagmi/MultiSig.js", + "require": "./dist/cjs/wagmi/MultiSig.js", + "types": "./dist/types/wagmi/MultiSig.d.ts" + }, + "./wagmi/OdisPayments": { + "import": "./dist/esm/wagmi/OdisPayments.js", + "require": "./dist/cjs/wagmi/OdisPayments.js", + "types": "./dist/types/wagmi/OdisPayments.d.ts" + }, + "./wagmi/Random": { + "import": "./dist/esm/wagmi/Random.js", + "require": "./dist/cjs/wagmi/Random.js", + "types": "./dist/types/wagmi/Random.d.ts" + }, + "./wagmi/Registry": { + "import": "./dist/esm/wagmi/Registry.js", + "require": "./dist/cjs/wagmi/Registry.js", + "types": "./dist/types/wagmi/Registry.d.ts" + }, + "./wagmi/ReleaseGold": { + "import": "./dist/esm/wagmi/ReleaseGold.js", + "require": "./dist/cjs/wagmi/ReleaseGold.js", + "types": "./dist/types/wagmi/ReleaseGold.d.ts" + }, + "./wagmi/SortedOracles": { + "import": "./dist/esm/wagmi/SortedOracles.js", + "require": "./dist/cjs/wagmi/SortedOracles.js", + "types": "./dist/types/wagmi/SortedOracles.d.ts" + }, + "./wagmi/UniswapFeeHandlerSeller": { + "import": "./dist/esm/wagmi/UniswapFeeHandlerSeller.js", + "require": "./dist/cjs/wagmi/UniswapFeeHandlerSeller.js", + "types": "./dist/types/wagmi/UniswapFeeHandlerSeller.d.ts" + }, + "./wagmi/Validators": { + "import": "./dist/esm/wagmi/Validators.js", + "require": "./dist/cjs/wagmi/Validators.js", + "types": "./dist/types/wagmi/Validators.d.ts" + }, + "./web3/0.8/GasPriceMinimum": { + "import": "./dist/esm/web3/0.8/GasPriceMinimum.js", + "require": "./dist/cjs/web3/0.8/GasPriceMinimum.js", + "types": "./dist/types/web3/0.8/GasPriceMinimum.d.ts" + }, + "./web3/Accounts": { + "import": "./dist/esm/web3/Accounts.js", + "require": "./dist/cjs/web3/Accounts.js", + "types": "./dist/types/web3/Accounts.d.ts" + }, + "./web3/Attestations": { + "import": "./dist/esm/web3/Attestations.js", + "require": "./dist/cjs/web3/Attestations.js", + "types": "./dist/types/web3/Attestations.d.ts" + }, + "./web3/BlockchainParameters": { + "import": "./dist/esm/web3/BlockchainParameters.js", + "require": "./dist/cjs/web3/BlockchainParameters.js", + "types": "./dist/types/web3/BlockchainParameters.d.ts" + }, + "./web3/DoubleSigningSlasher": { + "import": "./dist/esm/web3/DoubleSigningSlasher.js", + "require": "./dist/cjs/web3/DoubleSigningSlasher.js", + "types": "./dist/types/web3/DoubleSigningSlasher.d.ts" + }, + "./web3/DowntimeSlasher": { + "import": "./dist/esm/web3/DowntimeSlasher.js", + "require": "./dist/cjs/web3/DowntimeSlasher.js", + "types": "./dist/types/web3/DowntimeSlasher.d.ts" + }, + "./web3/Election": { + "import": "./dist/esm/web3/Election.js", + "require": "./dist/cjs/web3/Election.js", + "types": "./dist/types/web3/Election.d.ts" + }, + "./web3/EpochRewards": { + "import": "./dist/esm/web3/EpochRewards.js", + "require": "./dist/cjs/web3/EpochRewards.js", + "types": "./dist/types/web3/EpochRewards.d.ts" + }, + "./web3/Escrow": { + "import": "./dist/esm/web3/Escrow.js", + "require": "./dist/cjs/web3/Escrow.js", + "types": "./dist/types/web3/Escrow.d.ts" + }, + "./web3/FederatedAttestations": { + "import": "./dist/esm/web3/FederatedAttestations.js", + "require": "./dist/cjs/web3/FederatedAttestations.js", + "types": "./dist/types/web3/FederatedAttestations.d.ts" + }, + "./web3/FeeCurrencyWhitelist": { + "import": "./dist/esm/web3/FeeCurrencyWhitelist.js", + "require": "./dist/cjs/web3/FeeCurrencyWhitelist.js", + "types": "./dist/types/web3/FeeCurrencyWhitelist.d.ts" + }, + "./web3/FeeHandler": { + "import": "./dist/esm/web3/FeeHandler.js", + "require": "./dist/cjs/web3/FeeHandler.js", + "types": "./dist/types/web3/FeeHandler.d.ts" + }, + "./web3/Freezer": { + "import": "./dist/esm/web3/Freezer.js", + "require": "./dist/cjs/web3/Freezer.js", + "types": "./dist/types/web3/Freezer.d.ts" + }, + "./web3/GasPriceMinimum": { + "import": "./dist/esm/web3/GasPriceMinimum.js", + "require": "./dist/cjs/web3/GasPriceMinimum.js", + "types": "./dist/types/web3/GasPriceMinimum.d.ts" + }, + "./web3/GoldToken": { + "import": "./dist/esm/web3/GoldToken.js", + "require": "./dist/cjs/web3/GoldToken.js", + "types": "./dist/types/web3/GoldToken.d.ts" + }, + "./web3/Governance": { + "import": "./dist/esm/web3/Governance.js", + "require": "./dist/cjs/web3/Governance.js", + "types": "./dist/types/web3/Governance.d.ts" + }, + "./web3/GovernanceApproverMultiSig": { + "import": "./dist/esm/web3/GovernanceApproverMultiSig.js", + "require": "./dist/cjs/web3/GovernanceApproverMultiSig.js", + "types": "./dist/types/web3/GovernanceApproverMultiSig.d.ts" + }, + "./web3/ICeloToken": { + "import": "./dist/esm/web3/ICeloToken.js", + "require": "./dist/cjs/web3/ICeloToken.js", + "types": "./dist/types/web3/ICeloToken.d.ts" + }, + "./web3/ICeloVersionedContract": { + "import": "./dist/esm/web3/ICeloVersionedContract.js", + "require": "./dist/cjs/web3/ICeloVersionedContract.js", + "types": "./dist/types/web3/ICeloVersionedContract.d.ts" + }, + "./web3/IERC20": { + "import": "./dist/esm/web3/IERC20.js", + "require": "./dist/cjs/web3/IERC20.js", + "types": "./dist/types/web3/IERC20.d.ts" + }, + "./web3/LockedGold": { + "import": "./dist/esm/web3/LockedGold.js", + "require": "./dist/cjs/web3/LockedGold.js", + "types": "./dist/types/web3/LockedGold.d.ts" + }, + "./web3/MentoFeeHandlerSeller": { + "import": "./dist/esm/web3/MentoFeeHandlerSeller.js", + "require": "./dist/cjs/web3/MentoFeeHandlerSeller.js", + "types": "./dist/types/web3/MentoFeeHandlerSeller.d.ts" + }, + "./web3/MetaTransactionWallet": { + "import": "./dist/esm/web3/MetaTransactionWallet.js", + "require": "./dist/cjs/web3/MetaTransactionWallet.js", + "types": "./dist/types/web3/MetaTransactionWallet.d.ts" + }, + "./web3/MetaTransactionWalletDeployer": { + "import": "./dist/esm/web3/MetaTransactionWalletDeployer.js", + "require": "./dist/cjs/web3/MetaTransactionWalletDeployer.js", + "types": "./dist/types/web3/MetaTransactionWalletDeployer.d.ts" + }, + "./web3/MultiSig": { + "import": "./dist/esm/web3/MultiSig.js", + "require": "./dist/cjs/web3/MultiSig.js", + "types": "./dist/types/web3/MultiSig.d.ts" + }, + "./web3/OdisPayments": { + "import": "./dist/esm/web3/OdisPayments.js", + "require": "./dist/cjs/web3/OdisPayments.js", + "types": "./dist/types/web3/OdisPayments.d.ts" + }, + "./web3/Proxy": { + "import": "./dist/esm/web3/Proxy.js", + "require": "./dist/cjs/web3/Proxy.js", + "types": "./dist/types/web3/Proxy.d.ts" + }, + "./web3/Random": { + "import": "./dist/esm/web3/Random.js", + "require": "./dist/cjs/web3/Random.js", + "types": "./dist/types/web3/Random.d.ts" + }, + "./web3/Registry": { + "import": "./dist/esm/web3/Registry.js", + "require": "./dist/cjs/web3/Registry.js", + "types": "./dist/types/web3/Registry.d.ts" + }, + "./web3/ReleaseGold": { + "import": "./dist/esm/web3/ReleaseGold.js", + "require": "./dist/cjs/web3/ReleaseGold.js", + "types": "./dist/types/web3/ReleaseGold.d.ts" + }, + "./web3/SortedOracles": { + "import": "./dist/esm/web3/SortedOracles.js", + "require": "./dist/cjs/web3/SortedOracles.js", + "types": "./dist/types/web3/SortedOracles.d.ts" + }, + "./web3/UniswapFeeHandlerSeller": { + "import": "./dist/esm/web3/UniswapFeeHandlerSeller.js", + "require": "./dist/cjs/web3/UniswapFeeHandlerSeller.js", + "types": "./dist/types/web3/UniswapFeeHandlerSeller.d.ts" + }, + "./web3/Validators": { + "import": "./dist/esm/web3/Validators.js", + "require": "./dist/cjs/web3/Validators.js", + "types": "./dist/types/web3/Validators.d.ts" + }, + "./web3/mento/Exchange": { + "import": "./dist/esm/web3/mento/Exchange.js", + "require": "./dist/cjs/web3/mento/Exchange.js", + "types": "./dist/types/web3/mento/Exchange.d.ts" + }, + "./web3/mento/ExchangeBRL": { + "import": "./dist/esm/web3/mento/ExchangeBRL.js", + "require": "./dist/cjs/web3/mento/ExchangeBRL.js", + "types": "./dist/types/web3/mento/ExchangeBRL.d.ts" + }, + "./web3/mento/ExchangeEUR": { + "import": "./dist/esm/web3/mento/ExchangeEUR.js", + "require": "./dist/cjs/web3/mento/ExchangeEUR.js", + "types": "./dist/types/web3/mento/ExchangeEUR.d.ts" + }, + "./web3/mento/GrandaMento": { + "import": "./dist/esm/web3/mento/GrandaMento.js", + "require": "./dist/cjs/web3/mento/GrandaMento.js", + "types": "./dist/types/web3/mento/GrandaMento.d.ts" + }, + "./web3/mento/Reserve": { + "import": "./dist/esm/web3/mento/Reserve.js", + "require": "./dist/cjs/web3/mento/Reserve.js", + "types": "./dist/types/web3/mento/Reserve.d.ts" + }, + "./web3/mento/ReserveSpenderMultiSig": { + "import": "./dist/esm/web3/mento/ReserveSpenderMultiSig.js", + "require": "./dist/cjs/web3/mento/ReserveSpenderMultiSig.js", + "types": "./dist/types/web3/mento/ReserveSpenderMultiSig.d.ts" + }, + "./web3/mento/StableToken": { + "import": "./dist/esm/web3/mento/StableToken.js", + "require": "./dist/cjs/web3/mento/StableToken.js", + "types": "./dist/types/web3/mento/StableToken.d.ts" + }, + "./web3/mento/StableTokenBRL": { + "import": "./dist/esm/web3/mento/StableTokenBRL.js", + "require": "./dist/cjs/web3/mento/StableTokenBRL.js", + "types": "./dist/types/web3/mento/StableTokenBRL.d.ts" + }, + "./web3/mento/StableTokenEUR": { + "import": "./dist/esm/web3/mento/StableTokenEUR.js", + "require": "./dist/cjs/web3/mento/StableTokenEUR.js", + "types": "./dist/types/web3/mento/StableTokenEUR.d.ts" } } } \ No newline at end of file diff --git a/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts b/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts index 3e38fa522ca..d48382a488a 100644 --- a/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts +++ b/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts @@ -106,10 +106,10 @@ function prepareTargetTypesExports() { targets.forEach((target) => { // We don't need package.json for type declarations if (target != BuildTarget.TYPES) { - // fs.copyFileSync( - // path.join(ABIS_PACKAGE_SRC_DIR, `package-${target}.json`), - // path.join(ABIS_DIST_DIR, target, 'package.json') - // ) + fs.copyFileSync( + path.join(ABIS_PACKAGE_SRC_DIR, `package-${target}.json`), + path.join(ABIS_DIST_DIR, target, 'package.json') + ) } const filePaths = lsRecursive(path.join(ABIS_DIST_DIR, target)) From c94f5143e138723332aa3878b59b9c740fe461b1 Mon Sep 17 00:00:00 2001 From: Leszek Stachowski Date: Mon, 4 Dec 2023 18:07:49 +0100 Subject: [PATCH 54/63] add packages/protocol/abis/src-generated/ to .prettierignore --- .prettierignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.prettierignore b/.prettierignore index b62c11d9dce..269beb0221b 100644 --- a/.prettierignore +++ b/.prettierignore @@ -20,7 +20,7 @@ packages/protocol/scripts/**/*.js packages/protocol/migrations/**/*.js packages/protocol/test/**/*.js packages/protocol/contractPackages.js - +packages/protocol/abis/src-generated/ # prettier eats Latex underscore escapting and doesn't seem to have an option to disable packages/docs/celo-codebase/protocol/proof-of-stake/epoch-rewards.md From 8d046fdaf2f7422a957183b8c2e1494c8fc596c0 Mon Sep 17 00:00:00 2001 From: Leszek Stachowski Date: Mon, 4 Dec 2023 18:17:17 +0100 Subject: [PATCH 55/63] lint fix --- .../protocol/scripts/prepare-contracts-and-abis-publishing.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts b/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts index d48382a488a..e1e1d9eee49 100644 --- a/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts +++ b/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts @@ -105,7 +105,7 @@ function prepareTargetTypesExports() { targets.forEach((target) => { // We don't need package.json for type declarations - if (target != BuildTarget.TYPES) { + if (target !== BuildTarget.TYPES) { fs.copyFileSync( path.join(ABIS_PACKAGE_SRC_DIR, `package-${target}.json`), path.join(ABIS_DIST_DIR, target, 'package.json') From 818d0c6ffd0dc7e4560828a622ba9dd103c901ec Mon Sep 17 00:00:00 2001 From: Leszek Stachowski Date: Tue, 5 Dec 2023 14:16:36 +0100 Subject: [PATCH 56/63] remove ethers specific files generation --- packages/protocol/abis/tsconfig.json | 1 - .../protocol/scripts/prepare-contracts-and-abis-publishing.ts | 3 --- 2 files changed, 4 deletions(-) diff --git a/packages/protocol/abis/tsconfig.json b/packages/protocol/abis/tsconfig.json index 7335abbe062..f1dda77be5d 100644 --- a/packages/protocol/abis/tsconfig.json +++ b/packages/protocol/abis/tsconfig.json @@ -19,5 +19,4 @@ "outDir": "./dist/esm" }, "include": ["./src-generated"], - "exclude": ["./src-generated/ethers"] } \ No newline at end of file diff --git a/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts b/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts index e1e1d9eee49..aafc5b2f0c4 100644 --- a/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts +++ b/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts @@ -33,9 +33,6 @@ try { // Generate all ABIs build(`--solidity ${path.join(ABIS_BUILD_DIR)}`) - // Generate ethers typings - build(`--ethersTypes ${path.join(ABIS_BUILD_DIR, 'ethers')}`) - // Generate web3 typings build(`--web3Types ${path.join(ABIS_BUILD_DIR, 'web3')}`) From 93c2c1d01ce1bb00080f782cca4958890a691fee Mon Sep 17 00:00:00 2001 From: Aaron DeRuvo Date: Tue, 5 Dec 2023 18:18:34 +0200 Subject: [PATCH 57/63] esm should be esm --- packages/protocol/abis/tsconfig-esm.json | 9 +++++++++ packages/protocol/abis/tsconfig.json | 1 - .../scripts/prepare-contracts-and-abis-publishing.ts | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 packages/protocol/abis/tsconfig-esm.json diff --git a/packages/protocol/abis/tsconfig-esm.json b/packages/protocol/abis/tsconfig-esm.json new file mode 100644 index 00000000000..36251a4ed7b --- /dev/null +++ b/packages/protocol/abis/tsconfig-esm.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "target": "ES2020", + "declaration": false, + "module": "ES2020", + "outDir": "./dist/esm" + }, +} \ No newline at end of file diff --git a/packages/protocol/abis/tsconfig.json b/packages/protocol/abis/tsconfig.json index f1dda77be5d..08ce54a4f0e 100644 --- a/packages/protocol/abis/tsconfig.json +++ b/packages/protocol/abis/tsconfig.json @@ -16,7 +16,6 @@ "resolveJsonModule": true, "declaration": false, "rootDir": "./src-generated", - "outDir": "./dist/esm" }, "include": ["./src-generated"], } \ No newline at end of file diff --git a/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts b/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts index aafc5b2f0c4..d8c52194d99 100644 --- a/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts +++ b/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts @@ -65,7 +65,7 @@ try { child_process.execSync(`yarn wagmi generate`, { stdio: 'inherit' }) log('Compiling esm') - child_process.execSync(`yarn tsc -b ${path.join(ABIS_PACKAGE_SRC_DIR, 'tsconfig.json')}`, { + child_process.execSync(`yarn tsc -b ${path.join(ABIS_PACKAGE_SRC_DIR, 'tsconfig-esm.json')}`, { stdio: 'inherit', }) From a7977eabd58ce22b68adc578c15440331d095fdc Mon Sep 17 00:00:00 2001 From: Aaron DeRuvo Date: Tue, 5 Dec 2023 18:37:57 +0200 Subject: [PATCH 58/63] better changeset --- .changeset/cool-waves-switch.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.changeset/cool-waves-switch.md b/.changeset/cool-waves-switch.md index 2bb7d71fc87..ccffa8a8aaa 100644 --- a/.changeset/cool-waves-switch.md +++ b/.changeset/cool-waves-switch.md @@ -2,4 +2,9 @@ '@celo/contractkit': major --- -Remove contracts from lib/generated. now available in @celo/abis package at @celo/abis/types/web3 +Remove contracts from lib/generated. now available in @celo/abis package at @celo/abis/web3 + +If you were directly importing contracts from `@celo/contractkit/lib/generated/*` eg `@celo/lib/generated/Accounts` do a find replace + +find: `@celo/contractkit/lib/generated/` +replace: `@celo/abis/web3/` From 1ed40419c1a6cd7e273899a728d4130fb2e6464e Mon Sep 17 00:00:00 2001 From: Aaron DeRuvo Date: Tue, 5 Dec 2023 19:22:33 +0200 Subject: [PATCH 59/63] use rc of abi --- packages/cli/package.json | 2 +- packages/sdk/contractkit/package.json | 2 +- packages/sdk/governance/package.json | 2 +- yarn.lock | 5 +++++ 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/cli/package.json b/packages/cli/package.json index 53b89030713..459b0f8852a 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -30,7 +30,7 @@ "test": "TZ=UTC jest --runInBand" }, "dependencies": { - "@celo/abis": "10.0.0-local", + "@celo/abis": "10.0.0-rc.2", "@celo/base": "^6.0.0", "@celo/connect": "^5.1.1", "@celo/contractkit": "^5.2.1", diff --git a/packages/sdk/contractkit/package.json b/packages/sdk/contractkit/package.json index 0fdaa69968b..b761c7f0321 100644 --- a/packages/sdk/contractkit/package.json +++ b/packages/sdk/contractkit/package.json @@ -24,7 +24,7 @@ "lint": "tslint -c tslint.json --project ." }, "dependencies": { - "@celo/abis": "10.0.0-local", + "@celo/abis": "10.0.0-rc.2", "@celo/base": "^6.0.0", "@celo/connect": "^5.1.1", "@celo/utils": "^5.0.6", diff --git a/packages/sdk/governance/package.json b/packages/sdk/governance/package.json index 2efda07f2c5..d77f8274c14 100644 --- a/packages/sdk/governance/package.json +++ b/packages/sdk/governance/package.json @@ -21,7 +21,7 @@ "prepublishOnly": "yarn build" }, "dependencies": { - "@celo/abis": "10.0.0-local", + "@celo/abis": "10.0.0-rc.2", "@celo/base": "^6.0.0", "@celo/utils": "^5.0.6", "@celo/connect": "^5.1.1", diff --git a/yarn.lock b/yarn.lock index b7862e180fd..2efbf7452d7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -973,6 +973,11 @@ resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== +"@celo/abis@10.0.0-rc.2": + version "10.0.0-rc.2" + resolved "https://registry.yarnpkg.com/@celo/abis/-/abis-10.0.0-rc.2.tgz#c0c45692dffc7647d70c8d6bea260b18214ca16b" + integrity sha512-okTthgUOGcLM8PeMnVdUBDsblvwpXTttoFJmOr9t3nF9PJBe1philf0IfhnCrpMdNsk/4Z+VXsammHccG6eYog== + "@celo/base@^5.0.5": version "5.0.5" resolved "https://registry.yarnpkg.com/@celo/base/-/base-5.0.5.tgz#b4102faba080ce536411b7987259d9ca152b6e6d" From 1f36681a4dac972efc759ba20b1890d9f6dbd5d4 Mon Sep 17 00:00:00 2001 From: Aaron DeRuvo Date: Tue, 5 Dec 2023 19:56:55 +0200 Subject: [PATCH 60/63] shhhh - we are already not expecting this to be working on current version so no worries --- packages/sdk/contractkit/src/wrappers/LockedGold.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/sdk/contractkit/src/wrappers/LockedGold.ts b/packages/sdk/contractkit/src/wrappers/LockedGold.ts index 2101df4cc84..fcc305d9556 100644 --- a/packages/sdk/contractkit/src/wrappers/LockedGold.ts +++ b/packages/sdk/contractkit/src/wrappers/LockedGold.ts @@ -417,6 +417,7 @@ export class LockedGoldWrapper extends BaseWrapperForGoverning { } _getTotalPendingWithdrawalsCount = proxyCall( + // @ts-expect-error this.contract.methods.getTotalPendingWithdrawalsCount, undefined, valueToBigNumber From c01197dcff9e36f513b364683a10b19efb1b09ad Mon Sep 17 00:00:00 2001 From: Aaron DeRuvo Date: Wed, 6 Dec 2023 10:29:16 +0200 Subject: [PATCH 61/63] exclude source maps --- packages/protocol/abis/package.json | 3 ++- packages/protocol/abis/tsconfig.json | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/protocol/abis/package.json b/packages/protocol/abis/package.json index 6ce2f55bf61..7e0c77de0f0 100644 --- a/packages/protocol/abis/package.json +++ b/packages/protocol/abis/package.json @@ -11,7 +11,8 @@ "dependencies": {}, "peerDependencies": {}, "files": [ - "./dist" + "./dist", + "!**/*.js.map" ], "exports": { "./Accounts.json": { diff --git a/packages/protocol/abis/tsconfig.json b/packages/protocol/abis/tsconfig.json index 08ce54a4f0e..0ee28e1c551 100644 --- a/packages/protocol/abis/tsconfig.json +++ b/packages/protocol/abis/tsconfig.json @@ -8,9 +8,9 @@ "moduleResolution": "node16", "noUnusedLocals": true, "noUnusedParameters": true, - "removeComments": false, + "removeComments": true, "skipLibCheck": true, - "sourceMap": true, + "sourceMap": false, "target": "ES5", "downlevelIteration": true, "resolveJsonModule": true, From a50a543f6b66981b8fd36e2895312bb42364198f Mon Sep 17 00:00:00 2001 From: Aaron DeRuvo Date: Wed, 6 Dec 2023 13:42:22 +0200 Subject: [PATCH 62/63] generate ts files at top level --- .../protocol/scripts/prepare-contracts-and-abis-publishing.ts | 2 +- packages/protocol/wagmi.config.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts b/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts index d8c52194d99..38c06295745 100644 --- a/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts +++ b/packages/protocol/scripts/prepare-contracts-and-abis-publishing.ts @@ -60,7 +60,7 @@ try { let exports = processRawJsonsAndPrepareExports() - // Generate wagmi friendly ts files + // Generate ts abi files log('Running yarn wagmi generate') child_process.execSync(`yarn wagmi generate`, { stdio: 'inherit' }) diff --git a/packages/protocol/wagmi.config.ts b/packages/protocol/wagmi.config.ts index e6a2d0ad898..8c33b65fb74 100644 --- a/packages/protocol/wagmi.config.ts +++ b/packages/protocol/wagmi.config.ts @@ -19,7 +19,7 @@ for (const contractName of new Set(CoreContracts)) { export default defineConfig( contracts.map(({ name, abi }) => ({ - out: path.join(ABIS_BUILD_DIR, `wagmi/${name}.ts`), + out: path.join(ABIS_BUILD_DIR, `${name}.ts`), contracts: [{ name, abi }], plugins: [], })) From 3ab415abfbadd52e9d1c8557d92c3bf83b8e5ee3 Mon Sep 17 00:00:00 2001 From: Aaron DeRuvo Date: Wed, 6 Dec 2023 16:31:37 +0200 Subject: [PATCH 63/63] fix the readme and undo some temp stuff --- .github/workflows/celo-monorepo.yml | 8 ++------ package.json | 3 +-- packages/protocol/abis/README.md | 15 ++++++++++----- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/celo-monorepo.yml b/.github/workflows/celo-monorepo.yml index 72eb4bef0e8..17b33989d02 100644 --- a/.github/workflows/celo-monorepo.yml +++ b/.github/workflows/celo-monorepo.yml @@ -77,11 +77,7 @@ jobs: run: yarn run postinstall if: steps.cache_node.outputs.cache-hit == 'true' - name: Build packages - # Just until contractkit is removed wait to build all packages the need abis to be built first - run: | - yarn build --ignore @celo/contractkit --ignore @celo/explorer --ignore @celo/celocli --ignore @celo/governance --ignore @celo/metadata-crawler --ignore @celo/celotool --ignore @celo/env-tests --ignore @celo/transactions-uri --ignore @celo/wallet-rpc --include-dependencies - yarn --cwd packages/protocol run prepare_contracts_and_abis_publishing - yarn build --ignore docs --include-dependencies + run: yarn build --ignore docs --include-dependencies - name: Check licenses if: steps.cache_node.outputs.cache-hit != 'true' run: | @@ -115,7 +111,7 @@ jobs: - name: Get the artifacts to cache id: get_artifacts_to_cache run: | - artifacts_to_cache="$(git ls-files --others --ignored --exclude-standard | grep -v node_modules | grep -v cjs/types/wagmi |grep -v src-generated/types/ethers | grep -v .js.map)" + artifacts_to_cache="$(git ls-files --others --ignored --exclude-standard | grep -v node_modules | grep -v .js.map)" echo "artifacts_to_cache<> $GITHUB_OUTPUT echo "$artifacts_to_cache" >> $GITHUB_OUTPUT echo "EOF" >> $GITHUB_OUTPUT diff --git a/package.json b/package.json index 064b2f7b8f0..55fb70231f5 100644 --- a/package.json +++ b/package.json @@ -42,8 +42,7 @@ "packages": [ "packages/*", "packages/sdk/*", - "packages/sdk/wallets/*", - "packages/protocol/abis" + "packages/sdk/wallets/*" ], "nohoist": [ "**/openzeppelin-solidity", diff --git a/packages/protocol/abis/README.md b/packages/protocol/abis/README.md index 1dd0e51305f..7fd7a12bf66 100644 --- a/packages/protocol/abis/README.md +++ b/packages/protocol/abis/README.md @@ -16,17 +16,22 @@ or yarn add @celo/abis ``` +**There is no index so the following do not work** +`import abis from '@celo/abis'` or ` import web3AbiTypes from '@celo/abis/web3'` + ### In your javascript or ts ```ts -// json abi +// abi in json import Accounts from '@celo/abis/Accounts.json' -// web3 -import Accounts from '@celo/abis/web3/Accounts' +// abi in js/ts +import { accountsABI } from '@celo/abis/Accounts' + +// abi in js/ts for use with contractkit +import { type Accounts, newAccounts, ABI } from '@celo/abis/web3/Accounts' + -// wagmi -import Accounts from '@celo/abis/wagmi/Accounts' ``` ## License