From ab12f7169d42ba214b2d3a35ae10aee8c45861dc Mon Sep 17 00:00:00 2001 From: Thijs van Hoof Date: Mon, 15 Jan 2024 16:58:02 +0100 Subject: [PATCH] Remove actor codes and update to ethers v6 (#311) --- .../filecoin-actor-utils/package-lock.json | 359 ++++++++++++------ packages/filecoin-actor-utils/package.json | 5 +- packages/filecoin-actor-utils/src/data.ts | 28 +- .../src/data/actor-codes.json | 38 -- packages/filecoin-actor-utils/src/index.ts | 1 - packages/filecoin-actor-utils/src/types.ts | 17 - .../filecoin-actor-utils/src/utils/abi.ts | 8 +- .../filecoin-actor-utils/src/utils/code.ts | 53 --- .../filecoin-actor-utils/src/utils/generic.ts | 9 +- .../filecoin-actor-utils/src/utils/logs.ts | 9 +- .../filecoin-actor-utils/src/utils/method.ts | 8 +- .../filecoin-actor-utils/src/utils/params.ts | 7 +- .../filecoin-actor-utils/src/utils/return.ts | 7 +- .../filecoin-actor-utils/src/utils/state.ts | 34 +- .../filecoin-actor-utils/test/index.spec.ts | 43 --- 15 files changed, 280 insertions(+), 346 deletions(-) delete mode 100644 packages/filecoin-actor-utils/src/data/actor-codes.json delete mode 100644 packages/filecoin-actor-utils/src/utils/code.ts diff --git a/packages/filecoin-actor-utils/package-lock.json b/packages/filecoin-actor-utils/package-lock.json index c696ca09..5dc485af 100644 --- a/packages/filecoin-actor-utils/package-lock.json +++ b/packages/filecoin-actor-utils/package-lock.json @@ -11,13 +11,12 @@ "dependencies": { "@glif/filecoin-address": "^2.0.43", "@ipld/dag-cbor": "^7.0.3", - "base32-decode": "^1.0.0", - "ethers": "^5.7.2", + "ethers": "^6.10.0", "lodash.clonedeep": "^4.5.0", "uint8arrays": "^3.1.0" }, "devDependencies": { - "@types/lodash.clonedeep": "^4.5.7", + "@types/lodash.clonedeep": "^4.5.9", "@typescript-eslint/eslint-plugin": "^5.35.1", "@typescript-eslint/parser": "^5.35.1", "eslint": "^8.22.0", @@ -26,6 +25,11 @@ "prettier": "^2.7.1" } }, + "node_modules/@adraffy/ens-normalize": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/@adraffy/ens-normalize/-/ens-normalize-1.10.0.tgz", + "integrity": "sha512-nA9XHtlAkYfJxY7bce8DcN7eKxWWCWkU+1GR9d+U6MbNpfwQp8TI7vqOsBsMcHoT4mBu2kypKoSKnghEzOOq5Q==" + }, "node_modules/@eslint/eslintrc": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.3.0.tgz", @@ -345,6 +349,11 @@ "scrypt-js": "3.0.1" } }, + "node_modules/@ethersproject/json-wallets/node_modules/aes-js": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/aes-js/-/aes-js-3.0.0.tgz", + "integrity": "sha512-H7wUZRn8WpTq9jocdxQ2c8x2sKo9ZVmzfRE13GiNJXfp7NcKYEdvl3vspKjXox6RIG2VtaRe4JFvxG4rqp2Zuw==" + }, "node_modules/@ethersproject/keccak256": { "version": "5.7.0", "resolved": "https://registry.npmjs.org/@ethersproject/keccak256/-/keccak256-5.7.0.tgz", @@ -471,6 +480,26 @@ "ws": "7.4.6" } }, + "node_modules/@ethersproject/providers/node_modules/ws": { + "version": "7.4.6", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.6.tgz", + "integrity": "sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A==", + "engines": { + "node": ">=8.3.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": "^5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + }, "node_modules/@ethersproject/random": { "version": "5.7.0", "resolved": "https://registry.npmjs.org/@ethersproject/random/-/random-5.7.0.tgz", @@ -729,6 +758,53 @@ "uint8arrays": "3.0.0" } }, + "node_modules/@glif/filecoin-address/node_modules/ethers": { + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/ethers/-/ethers-5.7.2.tgz", + "integrity": "sha512-wswUsmWo1aOK8rR7DIKiWSw9DbLWe6x98Jrn8wcTflTVvaXhAMaB5zGAXy0GYQEQp9iO1iSHWVyARQm11zUtyg==", + "funding": [ + { + "type": "individual", + "url": "https://gitcoin.co/grants/13/ethersjs-complete-simple-and-tiny-2" + }, + { + "type": "individual", + "url": "https://www.buymeacoffee.com/ricmoo" + } + ], + "dependencies": { + "@ethersproject/abi": "5.7.0", + "@ethersproject/abstract-provider": "5.7.0", + "@ethersproject/abstract-signer": "5.7.0", + "@ethersproject/address": "5.7.0", + "@ethersproject/base64": "5.7.0", + "@ethersproject/basex": "5.7.0", + "@ethersproject/bignumber": "5.7.0", + "@ethersproject/bytes": "5.7.0", + "@ethersproject/constants": "5.7.0", + "@ethersproject/contracts": "5.7.0", + "@ethersproject/hash": "5.7.0", + "@ethersproject/hdnode": "5.7.0", + "@ethersproject/json-wallets": "5.7.0", + "@ethersproject/keccak256": "5.7.0", + "@ethersproject/logger": "5.7.0", + "@ethersproject/networks": "5.7.1", + "@ethersproject/pbkdf2": "5.7.0", + "@ethersproject/properties": "5.7.0", + "@ethersproject/providers": "5.7.2", + "@ethersproject/random": "5.7.0", + "@ethersproject/rlp": "5.7.0", + "@ethersproject/sha2": "5.7.0", + "@ethersproject/signing-key": "5.7.0", + "@ethersproject/solidity": "5.7.0", + "@ethersproject/strings": "5.7.0", + "@ethersproject/transactions": "5.7.0", + "@ethersproject/units": "5.7.0", + "@ethersproject/wallet": "5.7.0", + "@ethersproject/web": "5.7.1", + "@ethersproject/wordlists": "5.7.0" + } + }, "node_modules/@glif/filecoin-address/node_modules/uint8arrays": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/uint8arrays/-/uint8arrays-3.0.0.tgz", @@ -776,6 +852,28 @@ "multiformats": "^9.5.4" } }, + "node_modules/@noble/curves": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.2.0.tgz", + "integrity": "sha512-oYclrNgRaM9SsBUBVbb8M6DTV7ZHRTKugureoYEncY5c65HOmRzvSiTE3y5CYaPYJA/GVkrhXEoF0M3Ya9PMnw==", + "dependencies": { + "@noble/hashes": "1.3.2" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/@noble/hashes": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.2.tgz", + "integrity": "sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ==", + "engines": { + "node": ">= 16" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -832,14 +930,19 @@ "dev": true }, "node_modules/@types/lodash.clonedeep": { - "version": "4.5.7", - "resolved": "https://registry.npmjs.org/@types/lodash.clonedeep/-/lodash.clonedeep-4.5.7.tgz", - "integrity": "sha512-ccNqkPptFIXrpVqUECi60/DFxjNKsfoQxSQsgcBJCX/fuX1wgyQieojkcWH/KpE3xzLoWN/2k+ZeGqIN3paSvw==", + "version": "4.5.9", + "resolved": "https://registry.npmjs.org/@types/lodash.clonedeep/-/lodash.clonedeep-4.5.9.tgz", + "integrity": "sha512-19429mWC+FyaAhOLzsS8kZUsI+/GmBAQ0HFiCPsKGU+7pBXOQWhyrY6xNNDwUSX8SMZMJvuFVMF9O5dQOlQK9Q==", "dev": true, "dependencies": { "@types/lodash": "*" } }, + "node_modules/@types/node": { + "version": "18.15.13", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.15.13.tgz", + "integrity": "sha512-N+0kuo9KgrUQ1Sn/ifDXsvg0TTleP7rIy4zOBGECxAljqvqfqpTfzx0Q1NUedOixRMBfe2Whhb056a42cWs26Q==" + }, "node_modules/@typescript-eslint/eslint-plugin": { "version": "5.35.1", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.35.1.tgz", @@ -1068,9 +1171,9 @@ } }, "node_modules/aes-js": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/aes-js/-/aes-js-3.0.0.tgz", - "integrity": "sha512-H7wUZRn8WpTq9jocdxQ2c8x2sKo9ZVmzfRE13GiNJXfp7NcKYEdvl3vspKjXox6RIG2VtaRe4JFvxG4rqp2Zuw==" + "version": "4.0.0-beta.5", + "resolved": "https://registry.npmjs.org/aes-js/-/aes-js-4.0.0-beta.5.tgz", + "integrity": "sha512-G965FqalsNyrPqgEGON7nIx1e/OVENSgiEIzyC63haUMuvNnwIgIjMs52hlTCKhkBny7A2ORNlfY9Zu+jmGk1Q==" }, "node_modules/ajv": { "version": "6.12.6", @@ -1133,11 +1236,6 @@ "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", "dev": true }, - "node_modules/base32-decode": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/base32-decode/-/base32-decode-1.0.0.tgz", - "integrity": "sha512-KNWUX/R7wKenwE/G/qFMzGScOgVntOmbE27vvc6GrniDGYb6a5+qWcuoXl8WIOQL7q0TpK7nZDm1Y04Yi3Yn5g==" - }, "node_modules/base64-js": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", @@ -1271,9 +1369,9 @@ } }, "node_modules/cborg": { - "version": "1.9.5", - "resolved": "https://registry.npmjs.org/cborg/-/cborg-1.9.5.tgz", - "integrity": "sha512-fLBv8wmqtlXqy1Yu+pHzevAIkW6k2K0ZtMujNzWphLsA34vzzg9BHn+5GmZqOJkSA9V7EMKsWrf6K976c1QMjQ==", + "version": "1.10.2", + "resolved": "https://registry.npmjs.org/cborg/-/cborg-1.10.2.tgz", + "integrity": "sha512-b3tFPA9pUr2zCUiCfRd2+wok2/LBSNUMKOuRRok+WlvvAgEt/PlbgPTsZUcwCOs53IJvLgTp0eotwtosE6njug==", "bin": { "cborg": "cli.js" } @@ -1613,13 +1711,13 @@ } }, "node_modules/ethers": { - "version": "5.7.2", - "resolved": "https://registry.npmjs.org/ethers/-/ethers-5.7.2.tgz", - "integrity": "sha512-wswUsmWo1aOK8rR7DIKiWSw9DbLWe6x98Jrn8wcTflTVvaXhAMaB5zGAXy0GYQEQp9iO1iSHWVyARQm11zUtyg==", + "version": "6.10.0", + "resolved": "https://registry.npmjs.org/ethers/-/ethers-6.10.0.tgz", + "integrity": "sha512-nMNwYHzs6V1FR3Y4cdfxSQmNgZsRj1RiTU25JwvnJLmyzw9z3SKxNc2XKDuiXXo/v9ds5Mp9m6HBabgYQQ26tA==", "funding": [ { "type": "individual", - "url": "https://gitcoin.co/grants/13/ethersjs-complete-simple-and-tiny-2" + "url": "https://github.com/sponsors/ethers-io/" }, { "type": "individual", @@ -1627,38 +1725,23 @@ } ], "dependencies": { - "@ethersproject/abi": "5.7.0", - "@ethersproject/abstract-provider": "5.7.0", - "@ethersproject/abstract-signer": "5.7.0", - "@ethersproject/address": "5.7.0", - "@ethersproject/base64": "5.7.0", - "@ethersproject/basex": "5.7.0", - "@ethersproject/bignumber": "5.7.0", - "@ethersproject/bytes": "5.7.0", - "@ethersproject/constants": "5.7.0", - "@ethersproject/contracts": "5.7.0", - "@ethersproject/hash": "5.7.0", - "@ethersproject/hdnode": "5.7.0", - "@ethersproject/json-wallets": "5.7.0", - "@ethersproject/keccak256": "5.7.0", - "@ethersproject/logger": "5.7.0", - "@ethersproject/networks": "5.7.1", - "@ethersproject/pbkdf2": "5.7.0", - "@ethersproject/properties": "5.7.0", - "@ethersproject/providers": "5.7.2", - "@ethersproject/random": "5.7.0", - "@ethersproject/rlp": "5.7.0", - "@ethersproject/sha2": "5.7.0", - "@ethersproject/signing-key": "5.7.0", - "@ethersproject/solidity": "5.7.0", - "@ethersproject/strings": "5.7.0", - "@ethersproject/transactions": "5.7.0", - "@ethersproject/units": "5.7.0", - "@ethersproject/wallet": "5.7.0", - "@ethersproject/web": "5.7.1", - "@ethersproject/wordlists": "5.7.0" + "@adraffy/ens-normalize": "1.10.0", + "@noble/curves": "1.2.0", + "@noble/hashes": "1.3.2", + "@types/node": "18.15.13", + "aes-js": "4.0.0-beta.5", + "tslib": "2.4.0", + "ws": "8.5.0" + }, + "engines": { + "node": ">=14.0.0" } }, + "node_modules/ethers/node_modules/tslib": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz", + "integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==" + }, "node_modules/fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", @@ -2619,9 +2702,9 @@ } }, "node_modules/uint8arrays": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/uint8arrays/-/uint8arrays-3.1.0.tgz", - "integrity": "sha512-ei5rfKtoRO8OyOIor2Rz5fhzjThwIHJZ3uyDPnDHTXbP0aMQ1RN/6AI5B5d9dBxJOU+BvOAk7ZQ1xphsX8Lrog==", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/uint8arrays/-/uint8arrays-3.1.1.tgz", + "integrity": "sha512-+QJa8QRnbdXVpHYjLoTpJIdCTiw9Ir62nocClWuXIq2JIh4Uta0cQsTSpFL678p2CN8B+XSApwcU+pQEqVpKWg==", "dependencies": { "multiformats": "^9.4.2" } @@ -2677,11 +2760,11 @@ "dev": true }, "node_modules/ws": { - "version": "7.4.6", - "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.6.tgz", - "integrity": "sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A==", + "version": "8.5.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.5.0.tgz", + "integrity": "sha512-BWX0SWVgLPzYwF8lTzEy1egjhS4S4OEAHfsO8o65WOVsrnSRGaSiUaa9e0ggGlkMTtBlmOpEXiie9RUcBO86qg==", "engines": { - "node": ">=8.3.0" + "node": ">=10.0.0" }, "peerDependencies": { "bufferutil": "^4.0.1", @@ -2716,6 +2799,11 @@ } }, "dependencies": { + "@adraffy/ens-normalize": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/@adraffy/ens-normalize/-/ens-normalize-1.10.0.tgz", + "integrity": "sha512-nA9XHtlAkYfJxY7bce8DcN7eKxWWCWkU+1GR9d+U6MbNpfwQp8TI7vqOsBsMcHoT4mBu2kypKoSKnghEzOOq5Q==" + }, "@eslint/eslintrc": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.3.0.tgz", @@ -2900,6 +2988,13 @@ "@ethersproject/transactions": "^5.7.0", "aes-js": "3.0.0", "scrypt-js": "3.0.1" + }, + "dependencies": { + "aes-js": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/aes-js/-/aes-js-3.0.0.tgz", + "integrity": "sha512-H7wUZRn8WpTq9jocdxQ2c8x2sKo9ZVmzfRE13GiNJXfp7NcKYEdvl3vspKjXox6RIG2VtaRe4JFvxG4rqp2Zuw==" + } } }, "@ethersproject/keccak256": { @@ -2966,6 +3061,14 @@ "@ethersproject/web": "^5.7.0", "bech32": "1.1.4", "ws": "7.4.6" + }, + "dependencies": { + "ws": { + "version": "7.4.6", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.6.tgz", + "integrity": "sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A==", + "requires": {} + } } }, "@ethersproject/random": { @@ -3116,6 +3219,43 @@ "uint8arrays": "3.0.0" }, "dependencies": { + "ethers": { + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/ethers/-/ethers-5.7.2.tgz", + "integrity": "sha512-wswUsmWo1aOK8rR7DIKiWSw9DbLWe6x98Jrn8wcTflTVvaXhAMaB5zGAXy0GYQEQp9iO1iSHWVyARQm11zUtyg==", + "requires": { + "@ethersproject/abi": "5.7.0", + "@ethersproject/abstract-provider": "5.7.0", + "@ethersproject/abstract-signer": "5.7.0", + "@ethersproject/address": "5.7.0", + "@ethersproject/base64": "5.7.0", + "@ethersproject/basex": "5.7.0", + "@ethersproject/bignumber": "5.7.0", + "@ethersproject/bytes": "5.7.0", + "@ethersproject/constants": "5.7.0", + "@ethersproject/contracts": "5.7.0", + "@ethersproject/hash": "5.7.0", + "@ethersproject/hdnode": "5.7.0", + "@ethersproject/json-wallets": "5.7.0", + "@ethersproject/keccak256": "5.7.0", + "@ethersproject/logger": "5.7.0", + "@ethersproject/networks": "5.7.1", + "@ethersproject/pbkdf2": "5.7.0", + "@ethersproject/properties": "5.7.0", + "@ethersproject/providers": "5.7.2", + "@ethersproject/random": "5.7.0", + "@ethersproject/rlp": "5.7.0", + "@ethersproject/sha2": "5.7.0", + "@ethersproject/signing-key": "5.7.0", + "@ethersproject/solidity": "5.7.0", + "@ethersproject/strings": "5.7.0", + "@ethersproject/transactions": "5.7.0", + "@ethersproject/units": "5.7.0", + "@ethersproject/wallet": "5.7.0", + "@ethersproject/web": "5.7.1", + "@ethersproject/wordlists": "5.7.0" + } + }, "uint8arrays": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/uint8arrays/-/uint8arrays-3.0.0.tgz", @@ -3158,6 +3298,19 @@ "multiformats": "^9.5.4" } }, + "@noble/curves": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.2.0.tgz", + "integrity": "sha512-oYclrNgRaM9SsBUBVbb8M6DTV7ZHRTKugureoYEncY5c65HOmRzvSiTE3y5CYaPYJA/GVkrhXEoF0M3Ya9PMnw==", + "requires": { + "@noble/hashes": "1.3.2" + } + }, + "@noble/hashes": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.2.tgz", + "integrity": "sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ==" + }, "@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -3202,14 +3355,19 @@ "dev": true }, "@types/lodash.clonedeep": { - "version": "4.5.7", - "resolved": "https://registry.npmjs.org/@types/lodash.clonedeep/-/lodash.clonedeep-4.5.7.tgz", - "integrity": "sha512-ccNqkPptFIXrpVqUECi60/DFxjNKsfoQxSQsgcBJCX/fuX1wgyQieojkcWH/KpE3xzLoWN/2k+ZeGqIN3paSvw==", + "version": "4.5.9", + "resolved": "https://registry.npmjs.org/@types/lodash.clonedeep/-/lodash.clonedeep-4.5.9.tgz", + "integrity": "sha512-19429mWC+FyaAhOLzsS8kZUsI+/GmBAQ0HFiCPsKGU+7pBXOQWhyrY6xNNDwUSX8SMZMJvuFVMF9O5dQOlQK9Q==", "dev": true, "requires": { "@types/lodash": "*" } }, + "@types/node": { + "version": "18.15.13", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.15.13.tgz", + "integrity": "sha512-N+0kuo9KgrUQ1Sn/ifDXsvg0TTleP7rIy4zOBGECxAljqvqfqpTfzx0Q1NUedOixRMBfe2Whhb056a42cWs26Q==" + }, "@typescript-eslint/eslint-plugin": { "version": "5.35.1", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.35.1.tgz", @@ -3337,9 +3495,9 @@ "requires": {} }, "aes-js": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/aes-js/-/aes-js-3.0.0.tgz", - "integrity": "sha512-H7wUZRn8WpTq9jocdxQ2c8x2sKo9ZVmzfRE13GiNJXfp7NcKYEdvl3vspKjXox6RIG2VtaRe4JFvxG4rqp2Zuw==" + "version": "4.0.0-beta.5", + "resolved": "https://registry.npmjs.org/aes-js/-/aes-js-4.0.0-beta.5.tgz", + "integrity": "sha512-G965FqalsNyrPqgEGON7nIx1e/OVENSgiEIzyC63haUMuvNnwIgIjMs52hlTCKhkBny7A2ORNlfY9Zu+jmGk1Q==" }, "ajv": { "version": "6.12.6", @@ -3386,11 +3544,6 @@ "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", "dev": true }, - "base32-decode": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/base32-decode/-/base32-decode-1.0.0.tgz", - "integrity": "sha512-KNWUX/R7wKenwE/G/qFMzGScOgVntOmbE27vvc6GrniDGYb6a5+qWcuoXl8WIOQL7q0TpK7nZDm1Y04Yi3Yn5g==" - }, "base64-js": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", @@ -3478,9 +3631,9 @@ "dev": true }, "cborg": { - "version": "1.9.5", - "resolved": "https://registry.npmjs.org/cborg/-/cborg-1.9.5.tgz", - "integrity": "sha512-fLBv8wmqtlXqy1Yu+pHzevAIkW6k2K0ZtMujNzWphLsA34vzzg9BHn+5GmZqOJkSA9V7EMKsWrf6K976c1QMjQ==" + "version": "1.10.2", + "resolved": "https://registry.npmjs.org/cborg/-/cborg-1.10.2.tgz", + "integrity": "sha512-b3tFPA9pUr2zCUiCfRd2+wok2/LBSNUMKOuRRok+WlvvAgEt/PlbgPTsZUcwCOs53IJvLgTp0eotwtosE6njug==" }, "chalk": { "version": "4.1.2", @@ -3727,40 +3880,24 @@ "dev": true }, "ethers": { - "version": "5.7.2", - "resolved": "https://registry.npmjs.org/ethers/-/ethers-5.7.2.tgz", - "integrity": "sha512-wswUsmWo1aOK8rR7DIKiWSw9DbLWe6x98Jrn8wcTflTVvaXhAMaB5zGAXy0GYQEQp9iO1iSHWVyARQm11zUtyg==", + "version": "6.10.0", + "resolved": "https://registry.npmjs.org/ethers/-/ethers-6.10.0.tgz", + "integrity": "sha512-nMNwYHzs6V1FR3Y4cdfxSQmNgZsRj1RiTU25JwvnJLmyzw9z3SKxNc2XKDuiXXo/v9ds5Mp9m6HBabgYQQ26tA==", "requires": { - "@ethersproject/abi": "5.7.0", - "@ethersproject/abstract-provider": "5.7.0", - "@ethersproject/abstract-signer": "5.7.0", - "@ethersproject/address": "5.7.0", - "@ethersproject/base64": "5.7.0", - "@ethersproject/basex": "5.7.0", - "@ethersproject/bignumber": "5.7.0", - "@ethersproject/bytes": "5.7.0", - "@ethersproject/constants": "5.7.0", - "@ethersproject/contracts": "5.7.0", - "@ethersproject/hash": "5.7.0", - "@ethersproject/hdnode": "5.7.0", - "@ethersproject/json-wallets": "5.7.0", - "@ethersproject/keccak256": "5.7.0", - "@ethersproject/logger": "5.7.0", - "@ethersproject/networks": "5.7.1", - "@ethersproject/pbkdf2": "5.7.0", - "@ethersproject/properties": "5.7.0", - "@ethersproject/providers": "5.7.2", - "@ethersproject/random": "5.7.0", - "@ethersproject/rlp": "5.7.0", - "@ethersproject/sha2": "5.7.0", - "@ethersproject/signing-key": "5.7.0", - "@ethersproject/solidity": "5.7.0", - "@ethersproject/strings": "5.7.0", - "@ethersproject/transactions": "5.7.0", - "@ethersproject/units": "5.7.0", - "@ethersproject/wallet": "5.7.0", - "@ethersproject/web": "5.7.1", - "@ethersproject/wordlists": "5.7.0" + "@adraffy/ens-normalize": "1.10.0", + "@noble/curves": "1.2.0", + "@noble/hashes": "1.3.2", + "@types/node": "18.15.13", + "aes-js": "4.0.0-beta.5", + "tslib": "2.4.0", + "ws": "8.5.0" + }, + "dependencies": { + "tslib": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz", + "integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==" + } } }, "fast-deep-equal": { @@ -4445,9 +4582,9 @@ "peer": true }, "uint8arrays": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/uint8arrays/-/uint8arrays-3.1.0.tgz", - "integrity": "sha512-ei5rfKtoRO8OyOIor2Rz5fhzjThwIHJZ3uyDPnDHTXbP0aMQ1RN/6AI5B5d9dBxJOU+BvOAk7ZQ1xphsX8Lrog==", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/uint8arrays/-/uint8arrays-3.1.1.tgz", + "integrity": "sha512-+QJa8QRnbdXVpHYjLoTpJIdCTiw9Ir62nocClWuXIq2JIh4Uta0cQsTSpFL678p2CN8B+XSApwcU+pQEqVpKWg==", "requires": { "multiformats": "^9.4.2" } @@ -4494,9 +4631,9 @@ "dev": true }, "ws": { - "version": "7.4.6", - "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.6.tgz", - "integrity": "sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A==", + "version": "8.5.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.5.0.tgz", + "integrity": "sha512-BWX0SWVgLPzYwF8lTzEy1egjhS4S4OEAHfsO8o65WOVsrnSRGaSiUaa9e0ggGlkMTtBlmOpEXiie9RUcBO86qg==", "requires": {} }, "yallist": { diff --git a/packages/filecoin-actor-utils/package.json b/packages/filecoin-actor-utils/package.json index 87b09668..4703d4dd 100644 --- a/packages/filecoin-actor-utils/package.json +++ b/packages/filecoin-actor-utils/package.json @@ -28,13 +28,12 @@ "dependencies": { "@glif/filecoin-address": "^2.0.43", "@ipld/dag-cbor": "^7.0.3", - "base32-decode": "^1.0.0", - "ethers": "^5.7.2", + "ethers": "^6.10.0", "lodash.clonedeep": "^4.5.0", "uint8arrays": "^3.1.0" }, "devDependencies": { - "@types/lodash.clonedeep": "^4.5.7", + "@types/lodash.clonedeep": "^4.5.9", "@typescript-eslint/eslint-plugin": "^5.35.1", "@typescript-eslint/parser": "^5.35.1", "eslint": "^8.22.0", diff --git a/packages/filecoin-actor-utils/src/data.ts b/packages/filecoin-actor-utils/src/data.ts index 96eaeb2c..e097c1a5 100644 --- a/packages/filecoin-actor-utils/src/data.ts +++ b/packages/filecoin-actor-utils/src/data.ts @@ -1,31 +1,5 @@ -import networkActorCodeMapJSON from './data/actor-codes.json' import actorDescriptorMapJSON from './data/actor-descriptors.json' -import { - NetworkActorCodeMap, - ActorDescriptorMap, - NetworkActorCodeMapInv -} from './types' - -/** - * Returns the actor code using networkActorCodeMap[networkName][actorName] - */ -export const networkActorCodeMap: NetworkActorCodeMap = networkActorCodeMapJSON - -/** - * Returns the actor name using networkActorCodeMapInv[networkName][actorCode] - */ -export const networkActorCodeMapInv: NetworkActorCodeMapInv = - Object.fromEntries( - Object.entries(networkActorCodeMap).map(([networkName, actorCodeMap]) => [ - networkName, - Object.fromEntries( - Object.entries(actorCodeMap).map(([actorName, actorCode]) => [ - actorCode, - actorName - ]) - ) - ]) - ) +import { ActorDescriptorMap } from './types' /** * Returns the actor descriptors with MethodNum converted to number from string. diff --git a/packages/filecoin-actor-utils/src/data/actor-codes.json b/packages/filecoin-actor-utils/src/data/actor-codes.json deleted file mode 100644 index fe37edf7..00000000 --- a/packages/filecoin-actor-utils/src/data/actor-codes.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "calibrationnet": { - "account": "bafk2bzacechwwxdqvggkdylm37zldjsra2ivkdzwp7fee56bzxbzs544wv6u6", - "cron": "bafk2bzacec4gdxxkqwxqqodsv6ug5dmdbqdfqwyqfek3yhxc2wweh5psxaeq6", - "datacap": "bafk2bzacecq5ppfskxgv3iea3jarsix6jdduuhwsn4fbvngtbmzelzmlygorm", - "eam": "bafk2bzacecb6cnwftvavpph4p34zs4psuy5xvbrhf7vszkva4npw6mw3c42xe", - "ethaccount": "bafk2bzaceajmc3y3sedsqymfla3dzzqzmbu5kmr2iskm26ga2u34ll5fpztfw", - "evm": "bafk2bzaced4sozr7m6rzcgpobzeiupghthfw6afumysu3oz6bxxirv74uo3vw", - "init": "bafk2bzaceaewh7b6zl2egclm7fqzx2lsqr57i75lb6cj43ndoa4mal3k5ld3m", - "multisig": "bafk2bzacednkwcpw5yzxjceoaliajgupzj6iqxe7ks2ll3unspbprbo5f2now", - "paymentchannel": "bafk2bzacebaxhk4itfiuvbftg7kz5zxugqnvdgerobitjq4vl6q4orcwk6wqg", - "placeholder": "bafk2bzacedfvut2myeleyq67fljcrw4kkmn5pb5dpyozovj7jpoez5irnc3ro", - "reward": "bafk2bzacedra77pcglf7vdca2itcaa4vd6xrxynxmgfgdjdxqxfwqyhtoxehy", - "storagemarket": "bafk2bzacea7g46y7xxu2zjq2h75x6mmx3utz2uxnlvnwi6tzpsvulna3bmiva", - "storageminer": "bafk2bzaceb7qzqsi5uyxe4o5iuasi47l2hnznvmqr2eu4pl3qscvarjqlnuxo", - "storagepower": "bafk2bzacedd3ka44k7d46ckbinjhv3diyuu2epgbyvhqqyjkc64qlrg3wlgzi", - "system": "bafk2bzacecioupndtcnyw6iq2hbrxag3aufvczlv5nobnfbkbywqzcyfaa376", - "verifiedregistry": "bafk2bzaceavldupmf7bimeeacs67z5xdfdlfca6p7sn6bev3mt5ggepfqvhqo" - }, - "mainnet": { - "account": "bafk2bzaceboftg75mdiba7xbo2i3uvgtca4brhnr3u5ptihonixgpnrvhpxoa", - "cron": "bafk2bzacechxjkfe2cehx4s7skj3wzfpzf7zolds64khrrrs66bhazsemktls", - "datacap": "bafk2bzacebpiwb2ml4qbnnaayxumtk43ryhc63exdgnhivy3hwgmzemawsmpq", - "eam": "bafk2bzaceb3elj4hfbbjp7g5bptc7su7mptszl4nlqfedilxvstjo5ungm6oe", - "ethaccount": "bafk2bzaceb4gkau2vgsijcxpfuq33bd7w3efr2rrhxrwiacjmns2ntdiamswq", - "evm": "bafk2bzacecmnyfiwb52tkbwmm2dsd7ysi3nvuxl3lmspy7pl26wxj4zj7w4wi", - "init": "bafk2bzacebllyegx5r6lggf6ymyetbp7amacwpuxakhtjvjtvoy2bfkzk3vms", - "multisig": "bafk2bzacecw5lyp3n3t67xdwrmo36h4z7afc3lobmmr6wg55w6yjzg5jhmh42", - "paymentchannel": "bafk2bzacectv4cm47bnhga5febf3lo3fq47g72kmmp2xd5s6tcxz7hiqdywa4", - "placeholder": "bafk2bzacedfvut2myeleyq67fljcrw4kkmn5pb5dpyozovj7jpoez5irnc3ro", - "reward": "bafk2bzacealqnxn5lwzwexd6reav4dppypquklx2ujlnvaxiqk2tzstyvkp5u", - "storagemarket": "bafk2bzacedylkg5am446lcuih4voyzdn4yjeqfsxfzh5b6mcuhx4mok5ph5c4", - "storageminer": "bafk2bzacedo75pabe4i2l3hvhtsjmijrcytd2y76xwe573uku25fi7sugqld6", - "storagepower": "bafk2bzacecsij5tpfzjpfuckxvccv2p3bdqjklkrfyyoei6lx5dyj5j4fvjm6", - "system": "bafk2bzacebfqrja2hip7esf4eafxjmu6xcogoqu5xxtgdg7xa5szgvvdguchu", - "verifiedregistry": "bafk2bzacedudgflxc75c77c6zkmfyq4u2xuk7k6xw6dfdccarjrvxx453b77q" - } -} \ No newline at end of file diff --git a/packages/filecoin-actor-utils/src/index.ts b/packages/filecoin-actor-utils/src/index.ts index c764ef30..0c7b3ac5 100644 --- a/packages/filecoin-actor-utils/src/index.ts +++ b/packages/filecoin-actor-utils/src/index.ts @@ -1,6 +1,5 @@ export * from './types' export * from './utils/abi' -export * from './utils/code' export * from './utils/logs' export * from './utils/method' export * from './utils/params' diff --git a/packages/filecoin-actor-utils/src/types.ts b/packages/filecoin-actor-utils/src/types.ts index fd6001d5..37c88ea4 100644 --- a/packages/filecoin-actor-utils/src/types.ts +++ b/packages/filecoin-actor-utils/src/types.ts @@ -1,25 +1,8 @@ export type ActorName = string -export type ActorCode = string export type MethodNum = number export type NetworkName = string export type PropName = string -export type ActorCodeMap = { - [actorName: ActorName]: ActorCode -} - -export type ActorCodeMapInv = { - [actorCode: ActorCode]: ActorName -} - -export type NetworkActorCodeMap = { - [networkName: NetworkName]: ActorCodeMap -} - -export type NetworkActorCodeMapInv = { - [networkName: NetworkName]: ActorCodeMapInv -} - export enum Type { Bool = 'boolean', Number = 'number', diff --git a/packages/filecoin-actor-utils/src/utils/abi.ts b/packages/filecoin-actor-utils/src/utils/abi.ts index 518b1cc7..36ce15d7 100644 --- a/packages/filecoin-actor-utils/src/utils/abi.ts +++ b/packages/filecoin-actor-utils/src/utils/abi.ts @@ -1,4 +1,4 @@ -import { Fragment, JsonFragment, ParamType } from '@ethersproject/abi' +import { Fragment, JsonFragment, ParamType } from 'ethers' import { fromString, toString } from 'uint8arrays' import { decode } from '@ipld/dag-cbor' import { DataType, Type } from '../types' @@ -24,7 +24,7 @@ export const cborToHex = (base64: string): string => { */ export const abiParamsToDataType = ( name: string, - params: ParamType[] + params: ReadonlyArray ): DataType => ({ Type: Type.Object, Name: name, @@ -41,12 +41,16 @@ export const abiParamsToDataType = ( export const abiParamToDataType = (param: ParamType): DataType => { switch (param.baseType) { case 'array': + if (!param.arrayChildren) + throw new Error('ParamType array is missing arrayChildren') return { Type: Type.Array, Name: param.type, Contains: abiParamToDataType(param.arrayChildren) } case 'tuple': + if (!param.components) + throw new Error('ParamType tuple is missing components') return { Type: Type.Object, Name: param.type, diff --git a/packages/filecoin-actor-utils/src/utils/code.ts b/packages/filecoin-actor-utils/src/utils/code.ts deleted file mode 100644 index 7930d7a0..00000000 --- a/packages/filecoin-actor-utils/src/utils/code.ts +++ /dev/null @@ -1,53 +0,0 @@ -import base32Decode from 'base32-decode' -import { networkActorCodeMap, networkActorCodeMapInv } from '../data' -import { ActorCode, ActorName, LotusCID, NetworkName } from '../types' - -/** - * Resolves the actor name by providing the actor code and the network name. - * @param actorCode the actor code which is used to resolve the actor name - * @param networkName the network in which to search for the actor name - * @returns the actor name when found or null when not found - */ -export const getActorName = ( - actorCode: ActorCode | LotusCID, - networkName: NetworkName -): ActorName | null => { - const code = typeof actorCode === 'object' ? actorCode?.['/'] : actorCode - - // Attempt the actor code lookup - const name = networkActorCodeMapInv[networkName]?.[code] ?? null - if (name) return name - - // Attempt to decode as v1-7 actor - const legacyName = getLegacyActorName(code) - if (legacyName) return legacyName - - // Return null when not found - return null -} - -/** - * Attempts to resolve the actor name by decoding as v1-7 actor - * @param actorCode the actor code to decode as v1-7 actor - * @returns the actor if successful or null when not - */ -const getLegacyActorName = (actorCode: ActorCode): ActorName | null => { - try { - const buffer = base32Decode(actorCode.slice(1).toUpperCase(), 'RFC4648') - const decoded = new TextDecoder('utf-8').decode(buffer.slice(4)) - return decoded.startsWith('fil/') ? decoded.split('/')[2] : null - } catch { - return null - } -} - -/** - * Resolves the actor code by providing the actor name and the network name. - * @param actorName the actor name which is used to resolve the actor code - * @param networkName the network in which to search for the actor code - * @returns the actor code when found or null when not found - */ -export const getActorCode = ( - actorName: ActorName, - networkName: NetworkName -): ActorCode | null => networkActorCodeMap[networkName]?.[actorName] ?? null diff --git a/packages/filecoin-actor-utils/src/utils/generic.ts b/packages/filecoin-actor-utils/src/utils/generic.ts index ac765f14..1d0298f1 100644 --- a/packages/filecoin-actor-utils/src/utils/generic.ts +++ b/packages/filecoin-actor-utils/src/utils/generic.ts @@ -1,6 +1,5 @@ import cloneDeep from 'lodash.clonedeep' import { Address } from '@glif/filecoin-address' -import { BigNumber } from 'ethers' import { toString as BytesToString } from 'uint8arrays' import { DataType, Type } from '../types' @@ -26,8 +25,8 @@ export const describeDataType = (dataType: DataType, value: any) => { return case Type.Number: - BigNumber.isBigNumber(value) - ? describeBigNumber(dataType, value) + typeof value === 'bigint' + ? describeBigInt(dataType, value) : describeBaseValue(dataType, value) return @@ -68,11 +67,11 @@ export const describeBaseValue = ( } /** - * Adds a BigNumber value to a descriptor as a string + * Adds a BigInt value to a descriptor as a string * @param dataType the descriptor to add the value to * @param value the value to add to the descriptor */ -export const describeBigNumber = (dataType: DataType, value: BigNumber) => { +export const describeBigInt = (dataType: DataType, value: bigint) => { dataType.Value = value.toString() } diff --git a/packages/filecoin-actor-utils/src/utils/logs.ts b/packages/filecoin-actor-utils/src/utils/logs.ts index 51e04540..c8e115db 100644 --- a/packages/filecoin-actor-utils/src/utils/logs.ts +++ b/packages/filecoin-actor-utils/src/utils/logs.ts @@ -1,4 +1,4 @@ -import { ethers } from 'ethers' +import { Interface } from 'ethers' import { DataType, Type } from '../types' import { ABI, abiParamsToDataType } from './abi' import { describeDataType } from './generic' @@ -34,14 +34,15 @@ export const describeFEVMLogs = ( // Sort logs by logIndex const sorted = logs.sort((a, b) => Number(a.logIndex) - Number(b.logIndex)) - // Parse logs to array of decribed DataTypes - const iface = new ethers.utils.Interface(abi) + // Parse logs to array of described DataTypes + const iface = new Interface(abi) const parsed = sorted.map(({ data, topics, logIndex }) => { const log = iface.parseLog({ data, topics }) + if (!log) throw new Error('Failed to parse log') // Convert ABI inputs to descriptor const name = `${Number(logIndex)}: ${log.name}` - const dataType = abiParamsToDataType(name, log.eventFragment.inputs) + const dataType = abiParamsToDataType(name, log.fragment.inputs) // Supplement the descriptor with log data describeDataType(dataType, log.args) diff --git a/packages/filecoin-actor-utils/src/utils/method.ts b/packages/filecoin-actor-utils/src/utils/method.ts index 3541ccfe..02d11fa5 100644 --- a/packages/filecoin-actor-utils/src/utils/method.ts +++ b/packages/filecoin-actor-utils/src/utils/method.ts @@ -1,4 +1,4 @@ -import { ethers } from 'ethers' +import { Interface } from 'ethers' import { actorDescriptorMap } from '../data' import { ABI, cborToHex } from './abi' @@ -23,9 +23,11 @@ export const getMethodName = ( export const getFEVMMethodName = (params: string, abi: ABI): string | null => { if (!params || !abi) return null try { - const iface = new ethers.utils.Interface(abi) + const iface = new Interface(abi) const data = cborToHex(params) - return iface.parseTransaction({ data }).name + const tx = iface.parseTransaction({ data }) + if (!tx) throw new Error('Failed to parse transaction') + return tx.name } catch { return null } diff --git a/packages/filecoin-actor-utils/src/utils/params.ts b/packages/filecoin-actor-utils/src/utils/params.ts index 3e10720d..4f561b77 100644 --- a/packages/filecoin-actor-utils/src/utils/params.ts +++ b/packages/filecoin-actor-utils/src/utils/params.ts @@ -1,5 +1,5 @@ import cloneDeep from 'lodash.clonedeep' -import { ethers } from 'ethers' +import { Interface } from 'ethers' import { actorDescriptorMap } from '../data' import { ActorName, DataType, MethodNum } from '../types' import { ABI, cborToHex, abiParamsToDataType } from './abi' @@ -65,12 +65,13 @@ export const describeFEVMTxParams = ( if (!params) return null // Parse transaction from params - const iface = new ethers.utils.Interface(abi) + const iface = new Interface(abi) const data = cborToHex(params) const tx = iface.parseTransaction({ data }) - const { inputs } = tx.functionFragment + if (!tx) throw new Error('Failed to parse transaction') // Return null for empty ABI inputs + const { inputs } = tx.fragment if (!inputs.length) return null // Convert ABI inputs to descriptor diff --git a/packages/filecoin-actor-utils/src/utils/return.ts b/packages/filecoin-actor-utils/src/utils/return.ts index 82229464..62f76e43 100644 --- a/packages/filecoin-actor-utils/src/utils/return.ts +++ b/packages/filecoin-actor-utils/src/utils/return.ts @@ -1,4 +1,4 @@ -import { ethers } from 'ethers' +import { Interface } from 'ethers' import cloneDeep from 'lodash.clonedeep' import { actorDescriptorMap } from '../data' import { ActorName, DataType, MethodNum } from '../types' @@ -67,12 +67,13 @@ export const describeFEVMTxReturn = ( if (!params || !returnVal) return null // Parse transaction from params - const iface = new ethers.utils.Interface(abi) + const iface = new Interface(abi) const data = cborToHex(params) const tx = iface.parseTransaction({ data }) - const { outputs } = tx.functionFragment + if (!tx) throw new Error('Failed to parse transaction') // Return null for empty ABI outputs + const { outputs } = tx.fragment if (!outputs?.length) return null // Decode return value diff --git a/packages/filecoin-actor-utils/src/utils/state.ts b/packages/filecoin-actor-utils/src/utils/state.ts index 878328ec..ed34ae3d 100644 --- a/packages/filecoin-actor-utils/src/utils/state.ts +++ b/packages/filecoin-actor-utils/src/utils/state.ts @@ -1,40 +1,8 @@ import cloneDeep from 'lodash.clonedeep' import { actorDescriptorMap } from '../data' -import { - ActorName, - DataTypeMap, - LotusActorState, - NetworkName, - Type -} from '../types' -import { getActorName } from './code' +import { ActorName, DataTypeMap, Type } from '../types' import { describeObject } from './generic' -/** - * Returns a descriptor with values for the provided Lotus actor state and network name - * @param lotusActorState the Lotus actor state as returned from StateReadState - * @param networkName the network in which to search for the actor name - * @returns the described actor state or null when the state is null - */ -export const describeLotusActorState = ( - lotusActorState: LotusActorState, - networkName: NetworkName -): DataTypeMap | null => { - // Return null for falsy actor state - if (!lotusActorState?.State) return null - - // Retrieve the actor name from the code - const actorCode = lotusActorState.Code['/'] - const actorName = getActorName(actorCode, networkName) - if (!actorName) - throw new Error( - `Failed to resolve actor name for code: ${actorCode}, in network: ${networkName}` - ) - - // Return the described actor state - return describeActorState(actorName, lotusActorState.State) -} - /** * Returns a descriptor with values based on the provided actor name and state * @param actorName the name of the actor diff --git a/packages/filecoin-actor-utils/test/index.spec.ts b/packages/filecoin-actor-utils/test/index.spec.ts index b9246225..8f2d8c7e 100644 --- a/packages/filecoin-actor-utils/test/index.spec.ts +++ b/packages/filecoin-actor-utils/test/index.spec.ts @@ -1,54 +1,11 @@ import { describeFEVMTxParams } from '../src/utils/params' import { describeFEVMTxReturn } from '../src/utils/return' import { getFEVMMethodName } from '../src/utils/method' -import { networkActorCodeMap } from '../src/data' -import { getActorName, getActorCode } from '../src/utils/code' import { abi } from './erc20ABI' import { Type } from '../src/types' import { cborToHex } from '../src/utils/abi' describe('utils', () => { - describe('getActorName', () => { - test('should find the actor name when given a code and network', () => { - const code = networkActorCodeMap['mainnet']['multisig'] - expect(getActorName(code, 'mainnet')).toBe('multisig') - }) - - test('should not find the actor name when given the wrong network', () => { - const code = networkActorCodeMap['mainnet']['multisig'] - expect(getActorName(code, 'calibrationnet')).toBe(null) - }) - - test('should not find the actor name when the code does not exist', () => { - expect(getActorName('abc123', 'mainnet')).toBe(null) - }) - - test('it decodes v7 actors', () => { - expect( - getActorName('bafkqadtgnfwc6njpnv2wy5djonuwo', 'calibrationnet') - ).toBe('multisig') - }) - }) - - describe('getActorCode', () => { - test('should find the multisig actor code on calibrationnet', () => { - const code = networkActorCodeMap['calibrationnet']['multisig'] - expect(getActorCode('multisig', 'calibrationnet')).toBe(code) - }) - - test('should find the multisig actor code on mainnet', () => { - const code = networkActorCodeMap['mainnet']['multisig'] - expect(getActorCode('multisig', 'mainnet')).toBe(code) - }) - - test('should not find the actor code when the actor name does not exist', () => { - expect(getActorCode('test', 'mainnet')).toBe(null) - }) - - test('should not find the actor code when the network name does not exist', () => { - expect(getActorCode('multisig', 'test')).toBe(null) - }) - }) describe('FEVM', () => { describe('describeFEVMMessageParams', () => { test('it decodes an ERC20 transfer', () => {