From d1d9f2d0013e718eb316e4800e93722318dec3f8 Mon Sep 17 00:00:00 2001 From: Nitin Mittal Date: Thu, 12 Sep 2024 01:24:58 +0900 Subject: [PATCH 1/3] upd: web3-eth package --- package-lock.json | 139 ++++++++++++++++++++++++++++++++++++++++++---- package.json | 4 +- 2 files changed, 131 insertions(+), 12 deletions(-) diff --git a/package-lock.json b/package-lock.json index 69852ce..36e95cf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@maticnetwork/chain-indexer-framework", - "version": "1.3.13", + "version": "1.3.14", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@maticnetwork/chain-indexer-framework", - "version": "1.3.13", + "version": "1.3.14", "license": "MIT", "dependencies": { "axios": "^1.3.6", @@ -20,7 +20,7 @@ "web3-core-helpers": "^1.8.2", "web3-core-subscriptions": "^1.7.5", "web3-eth": "^1.8.0", - "web3-eth-abi": "^1.8.0", + "web3-eth-abi": "^4.2.3", "web3-eth-contract": "^1.8.1", "web3-utils": "^1.8.2", "winston": "^3.8.2", @@ -5820,6 +5820,20 @@ "url": "https://opencollective.com/typescript-eslint" } }, + "node_modules/abitype": { + "version": "0.7.1", + "resolved": "https://registry.npmjs.org/abitype/-/abitype-0.7.1.tgz", + "integrity": "sha512-VBkRHTDZf9Myaek/dO3yMmOzB/y2s3Zo6nVU7yaw1G+TvCHAjwaJzNGN9yo4K5D8bU/VZXKP1EJpRhFr862PlQ==", + "peerDependencies": { + "typescript": ">=4.9.4", + "zod": "^3 >=3.19.1" + }, + "peerDependenciesMeta": { + "zod": { + "optional": true + } + } + }, "node_modules/abortcontroller-polyfill": { "version": "1.7.5", "resolved": "https://registry.npmjs.org/abortcontroller-polyfill/-/abortcontroller-polyfill-1.7.5.tgz", @@ -18362,7 +18376,6 @@ "version": "4.9.5", "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", - "dev": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -18687,6 +18700,18 @@ "resolved": "https://registry.npmjs.org/@types/node/-/node-12.20.55.tgz", "integrity": "sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ==" }, + "node_modules/web3-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/web3-errors/-/web3-errors-1.3.0.tgz", + "integrity": "sha512-j5JkAKCtuVMbY3F5PYXBqg1vWrtF4jcyyMY1rlw8a4PV67AkqlepjGgpzWJZd56Mt+TvHy6DA1F/3Id8LatDSQ==", + "dependencies": { + "web3-types": "^1.7.0" + }, + "engines": { + "node": ">=14", + "npm": ">=6.12.0" + } + }, "node_modules/web3-eth": { "version": "1.10.2", "resolved": "https://registry.npmjs.org/web3-eth/-/web3-eth-1.10.2.tgz", @@ -18710,15 +18735,40 @@ } }, "node_modules/web3-eth-abi": { - "version": "1.10.2", - "resolved": "https://registry.npmjs.org/web3-eth-abi/-/web3-eth-abi-1.10.2.tgz", - "integrity": "sha512-pY4fQUio7W7ZRSLf+vsYkaxJqaT/jHcALZjIxy+uBQaYAJ3t6zpQqMZkJB3Dw7HUODRJ1yI0NPEFGTnkYf/17A==", + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/web3-eth-abi/-/web3-eth-abi-4.2.3.tgz", + "integrity": "sha512-rPVwTn0O1CzbtfXwEfIjUP0W5Y7u1OFjugwKpSqJzPQE6+REBg6OELjomTGZBu+GThxHnv0rp15SOxvqp+tyXA==", "dependencies": { - "@ethersproject/abi": "^5.6.3", - "web3-utils": "1.10.2" + "abitype": "0.7.1", + "web3-errors": "^1.2.0", + "web3-types": "^1.7.0", + "web3-utils": "^4.3.1", + "web3-validator": "^2.0.6" }, "engines": { - "node": ">=8.0.0" + "node": ">=14", + "npm": ">=6.12.0" + } + }, + "node_modules/web3-eth-abi/node_modules/eventemitter3": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.1.tgz", + "integrity": "sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==" + }, + "node_modules/web3-eth-abi/node_modules/web3-utils": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/web3-utils/-/web3-utils-4.3.1.tgz", + "integrity": "sha512-kGwOk8FxOLJ9DQC68yqNQc7AzN+k9YDLaW+ZjlAXs3qORhf8zXk5SxWAAGLbLykMs3vTeB0FTb1Exut4JEYfFA==", + "dependencies": { + "ethereum-cryptography": "^2.0.0", + "eventemitter3": "^5.0.1", + "web3-errors": "^1.2.0", + "web3-types": "^1.7.0", + "web3-validator": "^2.0.6" + }, + "engines": { + "node": ">=14", + "npm": ">=6.12.0" } }, "node_modules/web3-eth-accounts": { @@ -18771,6 +18821,18 @@ "node": ">=8.0.0" } }, + "node_modules/web3-eth-contract/node_modules/web3-eth-abi": { + "version": "1.10.2", + "resolved": "https://registry.npmjs.org/web3-eth-abi/-/web3-eth-abi-1.10.2.tgz", + "integrity": "sha512-pY4fQUio7W7ZRSLf+vsYkaxJqaT/jHcALZjIxy+uBQaYAJ3t6zpQqMZkJB3Dw7HUODRJ1yI0NPEFGTnkYf/17A==", + "dependencies": { + "@ethersproject/abi": "^5.6.3", + "web3-utils": "1.10.2" + }, + "engines": { + "node": ">=8.0.0" + } + }, "node_modules/web3-eth-ens": { "version": "1.10.2", "resolved": "https://registry.npmjs.org/web3-eth-ens/-/web3-eth-ens-1.10.2.tgz", @@ -18789,6 +18851,18 @@ "node": ">=8.0.0" } }, + "node_modules/web3-eth-ens/node_modules/web3-eth-abi": { + "version": "1.10.2", + "resolved": "https://registry.npmjs.org/web3-eth-abi/-/web3-eth-abi-1.10.2.tgz", + "integrity": "sha512-pY4fQUio7W7ZRSLf+vsYkaxJqaT/jHcALZjIxy+uBQaYAJ3t6zpQqMZkJB3Dw7HUODRJ1yI0NPEFGTnkYf/17A==", + "dependencies": { + "@ethersproject/abi": "^5.6.3", + "web3-utils": "1.10.2" + }, + "engines": { + "node": ">=8.0.0" + } + }, "node_modules/web3-eth-iban": { "version": "1.10.2", "resolved": "https://registry.npmjs.org/web3-eth-iban/-/web3-eth-iban-1.10.2.tgz", @@ -18822,6 +18896,18 @@ "resolved": "https://registry.npmjs.org/@types/node/-/node-12.20.55.tgz", "integrity": "sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ==" }, + "node_modules/web3-eth/node_modules/web3-eth-abi": { + "version": "1.10.2", + "resolved": "https://registry.npmjs.org/web3-eth-abi/-/web3-eth-abi-1.10.2.tgz", + "integrity": "sha512-pY4fQUio7W7ZRSLf+vsYkaxJqaT/jHcALZjIxy+uBQaYAJ3t6zpQqMZkJB3Dw7HUODRJ1yI0NPEFGTnkYf/17A==", + "dependencies": { + "@ethersproject/abi": "^5.6.3", + "web3-utils": "1.10.2" + }, + "engines": { + "node": ">=8.0.0" + } + }, "node_modules/web3-net": { "version": "1.10.2", "resolved": "https://registry.npmjs.org/web3-net/-/web3-net-1.10.2.tgz", @@ -18874,6 +18960,15 @@ "node": ">=8.0.0" } }, + "node_modules/web3-types": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/web3-types/-/web3-types-1.7.0.tgz", + "integrity": "sha512-nhXxDJ7a5FesRw9UG5SZdP/C/3Q2EzHGnB39hkAV+YGXDMgwxBXFWebQLfEzZzuArfHnvC0sQqkIHNwSKcVjdA==", + "engines": { + "node": ">=14", + "npm": ">=6.12.0" + } + }, "node_modules/web3-utils": { "version": "1.10.2", "resolved": "https://registry.npmjs.org/web3-utils/-/web3-utils-1.10.2.tgz", @@ -18892,6 +18987,22 @@ "node": ">=8.0.0" } }, + "node_modules/web3-validator": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/web3-validator/-/web3-validator-2.0.6.tgz", + "integrity": "sha512-qn9id0/l1bWmvH4XfnG/JtGKKwut2Vokl6YXP5Kfg424npysmtRLe9DgiNBM9Op7QL/aSiaA0TVXibuIuWcizg==", + "dependencies": { + "ethereum-cryptography": "^2.0.0", + "util": "^0.12.5", + "web3-errors": "^1.2.0", + "web3-types": "^1.6.0", + "zod": "^3.21.4" + }, + "engines": { + "node": ">=14", + "npm": ">=6.12.0" + } + }, "node_modules/webidl-conversions": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", @@ -19243,6 +19354,14 @@ "funding": { "url": "https://github.com/sponsors/sindresorhus" } + }, + "node_modules/zod": { + "version": "3.23.8", + "resolved": "https://registry.npmjs.org/zod/-/zod-3.23.8.tgz", + "integrity": "sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } } } } diff --git a/package.json b/package.json index d397e85..cb2734b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@maticnetwork/chain-indexer-framework", - "version": "1.3.14", + "version": "1.3.15-beta.0", "description": "blockchain data indexer", "type": "module", "exports": { @@ -55,7 +55,7 @@ "web3-core-helpers": "^1.8.2", "web3-core-subscriptions": "^1.7.5", "web3-eth": "^1.8.0", - "web3-eth-abi": "^1.8.0", + "web3-eth-abi": "^4.2.3", "web3-eth-contract": "^1.8.1", "web3-utils": "^1.8.2", "winston": "^3.8.2", From fc59a65a07dc5770b69e4f012c78d39ca9629ef1 Mon Sep 17 00:00:00 2001 From: Nitin Mittal Date: Thu, 12 Sep 2024 01:50:53 +0900 Subject: [PATCH 2/3] fix: tests --- internal/coder/abi_coder.ts | 17 +++++++++++------ package-lock.json | 4 ++-- tests/coder/abi_coder.test.ts | 22 +++++++++++----------- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/internal/coder/abi_coder.ts b/internal/coder/abi_coder.ts index f6deab5..556776b 100644 --- a/internal/coder/abi_coder.ts +++ b/internal/coder/abi_coder.ts @@ -1,4 +1,9 @@ -import AbiCoder from "web3-eth-abi"; +import { + decodeParameter as decodeSingleParam, + decodeParameters as decodeMultipleParams, + decodeLog as decodeSingleLog, + encodeParameters as encodeMultipleParams +} from "web3-eth-abi"; /** * web3 helper class to access any web3 js related functionalities, use this to define any web3 helper functions @@ -11,7 +16,7 @@ export class ABICoder { * @returns {any} - Can return arrays, numbers, objects, etc. depends on the RLP type */ public static decodeParameter(type: any, hex: string): any { - return (AbiCoder as any).decodeParameter(type, hex); + return decodeSingleParam(type, hex); } /** @@ -21,7 +26,7 @@ export class ABICoder { * @returns {any} - Can return an object of arrays, numbers, objects, etc. depends on the RLP type */ public static decodeParameters(types: any[], hex: string): { [key: string]: any } { - return (AbiCoder as any).decodeParameters(types, hex); + return decodeMultipleParams(types, hex); } /** @@ -31,7 +36,7 @@ export class ABICoder { * @returns {any} - return hex string */ public static encodeParameters(types: any[], values: string[]): string { - return (AbiCoder as any).encodeParameters(types, values); + return encodeMultipleParams(types, values); } /** @@ -44,7 +49,7 @@ export class ABICoder { * @returns */ public static decodeLog(inputs: any[], hex: string, topics: string[]): { [key: string]: string } { - return (AbiCoder as any).decodeLog(inputs, hex, topics); + return decodeSingleLog(inputs, hex, topics) as unknown as { [key: string]: string }; } /** @@ -56,6 +61,6 @@ export class ABICoder { * @returns {{ [key: string]: any }} */ public static decodeMethod(types: any[], data: string): { [key: string]: any } { - return ABICoder.decodeParameters(types, "0x" + data.slice(10)); + return decodeMultipleParams(types, "0x" + data.slice(10)); } } diff --git a/package-lock.json b/package-lock.json index 36e95cf..c069438 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@maticnetwork/chain-indexer-framework", - "version": "1.3.14", + "version": "1.3.15-beta.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@maticnetwork/chain-indexer-framework", - "version": "1.3.14", + "version": "1.3.15-beta.0", "license": "MIT", "dependencies": { "axios": "^1.3.6", diff --git a/tests/coder/abi_coder.test.ts b/tests/coder/abi_coder.test.ts index aa6fe03..8670a22 100644 --- a/tests/coder/abi_coder.test.ts +++ b/tests/coder/abi_coder.test.ts @@ -1,19 +1,19 @@ import { ABICoder } from "../../dist/internal/coder/abi_coder"; -import AbiCoder from "web3-eth-abi"; +import { + decodeParameter as decodeSingleParam, + decodeParameters as decodeMultipleParams, + decodeLog as decodeSingleLog, + encodeParameters as encodeMultipleParams +} from "web3-eth-abi"; jest.mock("web3-eth-abi"); describe("abi_coder", () => { - let abiCoderObject: jest.MockedObject - - beforeEach(() => { - abiCoderObject = AbiCoder as jest.MockedObject; - }); describe("ABICoder", () => { test("decodeParameter", () => { //@ts-ignore - abiCoderObject.decodeParameter.mockReturnValueOnce("mocked_result") + decodeSingleParam.mockReturnValueOnce("mocked_result") expect( ABICoder.decodeParameter( "mocked_type", @@ -24,7 +24,7 @@ describe("abi_coder", () => { test("decodeParameters", () => { //@ts-ignore - abiCoderObject.decodeParameters.mockReturnValueOnce(["mocked_result"]) + decodeMultipleParams.mockReturnValueOnce(["mocked_result"]) expect( ABICoder.decodeParameters( ["mocked_type"], @@ -35,7 +35,7 @@ describe("abi_coder", () => { test("encodeParameters", () => { //@ts-ignore - abiCoderObject.encodeParameters.mockReturnValueOnce("mocked_result") + encodeMultipleParams.mockReturnValueOnce("mocked_result") expect( ABICoder.encodeParameters( ["mocked_type"], @@ -46,7 +46,7 @@ describe("abi_coder", () => { test("decodeLog", () => { //@ts-ignore - abiCoderObject.decodeLog.mockReturnValueOnce(["mocked_result"]) + decodeSingleLog.mockReturnValueOnce(["mocked_result"]) expect( ABICoder.decodeLog( ["mocked_input"], @@ -58,7 +58,7 @@ describe("abi_coder", () => { test("decodeMethod", () => { //@ts-ignore - abiCoderObject.decodeParameters.mockReturnValueOnce(["mocked_result"]) + decodeMultipleParams.mockReturnValueOnce(["mocked_result"]) expect( ABICoder.decodeMethod( ['bytes'], From 71bccf5440c328ffe59129f759d369ff43284d88 Mon Sep 17 00:00:00 2001 From: Nitin Mittal Date: Thu, 12 Sep 2024 01:59:38 +0900 Subject: [PATCH 3/3] fix: aliases --- internal/coder/abi_coder.ts | 18 +++++++++--------- tests/coder/abi_coder.test.ts | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/internal/coder/abi_coder.ts b/internal/coder/abi_coder.ts index 556776b..261cdfa 100644 --- a/internal/coder/abi_coder.ts +++ b/internal/coder/abi_coder.ts @@ -1,8 +1,8 @@ import { - decodeParameter as decodeSingleParam, - decodeParameters as decodeMultipleParams, - decodeLog as decodeSingleLog, - encodeParameters as encodeMultipleParams + decodeParameter, + decodeParameters, + decodeLog, + encodeParameters } from "web3-eth-abi"; /** @@ -16,7 +16,7 @@ export class ABICoder { * @returns {any} - Can return arrays, numbers, objects, etc. depends on the RLP type */ public static decodeParameter(type: any, hex: string): any { - return decodeSingleParam(type, hex); + return decodeParameter(type, hex); } /** @@ -26,7 +26,7 @@ export class ABICoder { * @returns {any} - Can return an object of arrays, numbers, objects, etc. depends on the RLP type */ public static decodeParameters(types: any[], hex: string): { [key: string]: any } { - return decodeMultipleParams(types, hex); + return decodeParameters(types, hex); } /** @@ -36,7 +36,7 @@ export class ABICoder { * @returns {any} - return hex string */ public static encodeParameters(types: any[], values: string[]): string { - return encodeMultipleParams(types, values); + return encodeParameters(types, values); } /** @@ -49,7 +49,7 @@ export class ABICoder { * @returns */ public static decodeLog(inputs: any[], hex: string, topics: string[]): { [key: string]: string } { - return decodeSingleLog(inputs, hex, topics) as unknown as { [key: string]: string }; + return decodeLog(inputs, hex, topics) as unknown as { [key: string]: string }; } /** @@ -61,6 +61,6 @@ export class ABICoder { * @returns {{ [key: string]: any }} */ public static decodeMethod(types: any[], data: string): { [key: string]: any } { - return decodeMultipleParams(types, "0x" + data.slice(10)); + return decodeParameters(types, "0x" + data.slice(10)); } } diff --git a/tests/coder/abi_coder.test.ts b/tests/coder/abi_coder.test.ts index 8670a22..f5deaa5 100644 --- a/tests/coder/abi_coder.test.ts +++ b/tests/coder/abi_coder.test.ts @@ -1,9 +1,9 @@ import { ABICoder } from "../../dist/internal/coder/abi_coder"; import { - decodeParameter as decodeSingleParam, - decodeParameters as decodeMultipleParams, - decodeLog as decodeSingleLog, - encodeParameters as encodeMultipleParams + decodeParameter, + decodeParameters, + decodeLog, + encodeParameters } from "web3-eth-abi"; jest.mock("web3-eth-abi"); @@ -13,7 +13,7 @@ describe("abi_coder", () => { describe("ABICoder", () => { test("decodeParameter", () => { //@ts-ignore - decodeSingleParam.mockReturnValueOnce("mocked_result") + decodeParameter.mockReturnValueOnce("mocked_result") expect( ABICoder.decodeParameter( "mocked_type", @@ -24,7 +24,7 @@ describe("abi_coder", () => { test("decodeParameters", () => { //@ts-ignore - decodeMultipleParams.mockReturnValueOnce(["mocked_result"]) + decodeParameters.mockReturnValueOnce(["mocked_result"]) expect( ABICoder.decodeParameters( ["mocked_type"], @@ -35,7 +35,7 @@ describe("abi_coder", () => { test("encodeParameters", () => { //@ts-ignore - encodeMultipleParams.mockReturnValueOnce("mocked_result") + encodeParameters.mockReturnValueOnce("mocked_result") expect( ABICoder.encodeParameters( ["mocked_type"], @@ -46,7 +46,7 @@ describe("abi_coder", () => { test("decodeLog", () => { //@ts-ignore - decodeSingleLog.mockReturnValueOnce(["mocked_result"]) + decodeLog.mockReturnValueOnce(["mocked_result"]) expect( ABICoder.decodeLog( ["mocked_input"], @@ -58,7 +58,7 @@ describe("abi_coder", () => { test("decodeMethod", () => { //@ts-ignore - decodeMultipleParams.mockReturnValueOnce(["mocked_result"]) + decodeParameters.mockReturnValueOnce(["mocked_result"]) expect( ABICoder.decodeMethod( ['bytes'],