diff --git a/CHANGELOG.md b/CHANGELOG.md index 65b23b8b..ba618a4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## [1.3.9] - 2023-10-28 ### Bug Fixes - Upgraded Apollo package dependencies +- Updated Error messages with optional possibleSolution parameter for common errors from bundler or Validation Errors on sdk ## [1.3.8] - 2023-10-25 ### Bug Fixes diff --git a/package-lock.json b/package-lock.json index 99962889..6e76f3ff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,6 @@ "dependencies": { "@apollo/client": "3.8.6", "@lifi/sdk": "2.2.3", - "@nerdwallet/apollo-cache-policies": "3.2.0", "@thehubbleproject/bls": "0.5.1", "@walletconnect/universal-provider": "2.10.0", "apollo-link-ws": "1.0.20", @@ -21,7 +20,7 @@ "commander": "10.0.1", "cross-fetch": "3.1.5", "ethers": "5.7.0", - "graphql-ws": "5.14.0", + "graphql-ws": "5.14.2", "prettier": "2.8.8" }, "devDependencies": { @@ -36,8 +35,8 @@ "npm": "9.6.4", "reflect-metadata": "0.1.13", "rxjs": "6.6.7", - "ts-node": "8.10.2", - "typescript": "4.5.2" + "ts-node": "10.9.1", + "typescript": "4.9.5" } }, "node_modules/@apollo/client": { @@ -121,6 +120,18 @@ "node": ">=6.9.0" } }, + "node_modules/@cspotcode/source-map-support": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", + "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", + "dev": true, + "dependencies": { + "@jridgewell/trace-mapping": "0.3.9" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/@ethersproject/abi": { "version": "5.7.0", "resolved": "https://registry.npmjs.org/@ethersproject/abi/-/abi-5.7.0.tgz", @@ -800,6 +811,31 @@ "graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" } }, + "node_modules/@jridgewell/resolve-uri": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.1.tgz", + "integrity": "sha512-dSYZh7HhCDtCKm4QakX0xFpsRDqjjtZf/kjI/v3T3Nwt5r8/qz/M19F9ySyOqU94SXBmeG9ttTul+YnR4LOxFA==", + "dev": true, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.4.15", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz", + "integrity": "sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==", + "dev": true + }, + "node_modules/@jridgewell/trace-mapping": { + "version": "0.3.9", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", + "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", + "dev": true, + "dependencies": { + "@jridgewell/resolve-uri": "^3.0.3", + "@jridgewell/sourcemap-codec": "^1.4.10" + } + }, "node_modules/@lifi/sdk": { "version": "2.2.3", "resolved": "https://registry.npmjs.org/@lifi/sdk/-/sdk-2.2.3.tgz", @@ -989,20 +1025,6 @@ "@ethersproject/wordlists": "5.7.0" } }, - "node_modules/@nerdwallet/apollo-cache-policies": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/@nerdwallet/apollo-cache-policies/-/apollo-cache-policies-3.2.0.tgz", - "integrity": "sha512-gX4aCNotuto5woBlOpxD7sEM1DofhxDbWfwaXl/uhomHB4KfRY0r+jOTG5PLlIiXCwRsqIrboMoVwzBEn3+CzQ==", - "dependencies": { - "graphql": "^15.5.0", - "lodash": "^4.17.21", - "uuid": "^7.0.3" - }, - "peerDependencies": { - "@apollo/client": "^3.8.1", - "react": "^16.8.0 || ^17.0.0 || ^18.0.0" - } - }, "node_modules/@stablelib/aead": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/@stablelib/aead/-/aead-1.0.1.tgz", @@ -1158,6 +1180,30 @@ "mcl-wasm": "^1.0.0" } }, + "node_modules/@tsconfig/node10": { + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz", + "integrity": "sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==", + "dev": true + }, + "node_modules/@tsconfig/node12": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz", + "integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==", + "dev": true + }, + "node_modules/@tsconfig/node14": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz", + "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==", + "dev": true + }, + "node_modules/@tsconfig/node16": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.4.tgz", + "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==", + "dev": true + }, "node_modules/@types/eslint-visitor-keys": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz", @@ -1633,6 +1679,15 @@ "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" } }, + "node_modules/acorn-walk": { + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.0.tgz", + "integrity": "sha512-FS7hV565M5l1R08MXqo8odwMTB02C2UqzB17RVgu9EyuYFBqJZ3/ZY97sQD5FewVu1UyDFc1yztUDrAwT0EypA==", + "dev": true, + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/aes-js": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/aes-js/-/aes-js-3.0.0.tgz", @@ -1982,12 +2037,6 @@ "ieee754": "^1.2.1" } }, - "node_modules/buffer-from": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", - "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==", - "dev": true - }, "node_modules/call-bind": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", @@ -2104,6 +2153,12 @@ "node": ">=0.10.0" } }, + "node_modules/create-require": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", + "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", + "dev": true + }, "node_modules/cross-fetch": { "version": "3.1.5", "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.5.tgz", @@ -3101,6 +3156,7 @@ "version": "15.8.0", "resolved": "https://registry.npmjs.org/graphql/-/graphql-15.8.0.tgz", "integrity": "sha512-5gghUc24tP9HRznNpV2+FIoq3xKkj5dTQqf4v0CpdPbFVwFkWoxOM+o+2OC9ZSvjEMTjfmG9QT+gcvggTwW1zw==", + "peer": true, "engines": { "node": ">= 10.x" } @@ -3125,9 +3181,9 @@ "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==" }, "node_modules/graphql-ws": { - "version": "5.14.0", - "resolved": "https://registry.npmjs.org/graphql-ws/-/graphql-ws-5.14.0.tgz", - "integrity": "sha512-itrUTQZP/TgswR4GSSYuwWUzrE/w5GhbwM2GX3ic2U7aw33jgEsayfIlvaj7/GcIvZgNMzsPTrE5hqPuFUiE5g==", + "version": "5.14.2", + "resolved": "https://registry.npmjs.org/graphql-ws/-/graphql-ws-5.14.2.tgz", + "integrity": "sha512-LycmCwhZ+Op2GlHz4BZDsUYHKRiiUz+3r9wbhBATMETNlORQJAaFlAgTFoeRh6xQoQegwYwIylVD1Qns9/DA3w==", "engines": { "node": ">=10" }, @@ -3794,7 +3850,8 @@ "node_modules/lodash": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", - "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", + "dev": true }, "node_modules/lodash.isequal": { "version": "4.5.0", @@ -7280,6 +7337,7 @@ "version": "18.2.0", "resolved": "https://registry.npmjs.org/react/-/react-18.2.0.tgz", "integrity": "sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==", + "optional": true, "peer": true, "dependencies": { "loose-envify": "^1.1.0" @@ -7618,25 +7676,6 @@ "atomic-sleep": "^1.0.0" } }, - "node_modules/source-map": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/source-map-support": { - "version": "0.5.21", - "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz", - "integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==", - "dev": true, - "dependencies": { - "buffer-from": "^1.0.0", - "source-map": "^0.6.0" - } - }, "node_modules/spdx-correct": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.2.0.tgz", @@ -7990,28 +8029,58 @@ "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==" }, "node_modules/ts-node": { - "version": "8.10.2", - "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-8.10.2.tgz", - "integrity": "sha512-ISJJGgkIpDdBhWVu3jufsWpK3Rzo7bdiIXJjQc0ynKxVOVcg2oIrf2H2cejminGrptVc6q6/uynAHNCuWGbpVA==", - "dev": true, - "dependencies": { + "version": "10.9.1", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.1.tgz", + "integrity": "sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==", + "dev": true, + "dependencies": { + "@cspotcode/source-map-support": "^0.8.0", + "@tsconfig/node10": "^1.0.7", + "@tsconfig/node12": "^1.0.7", + "@tsconfig/node14": "^1.0.0", + "@tsconfig/node16": "^1.0.2", + "acorn": "^8.4.1", + "acorn-walk": "^8.1.1", "arg": "^4.1.0", + "create-require": "^1.1.0", "diff": "^4.0.1", "make-error": "^1.1.1", - "source-map-support": "^0.5.17", + "v8-compile-cache-lib": "^3.0.1", "yn": "3.1.1" }, "bin": { "ts-node": "dist/bin.js", + "ts-node-cwd": "dist/bin-cwd.js", + "ts-node-esm": "dist/bin-esm.js", "ts-node-script": "dist/bin-script.js", "ts-node-transpile-only": "dist/bin-transpile.js", "ts-script": "dist/bin-script-deprecated.js" }, - "engines": { - "node": ">=6.0.0" - }, "peerDependencies": { + "@swc/core": ">=1.2.50", + "@swc/wasm": ">=1.2.50", + "@types/node": "*", "typescript": ">=2.7" + }, + "peerDependenciesMeta": { + "@swc/core": { + "optional": true + }, + "@swc/wasm": { + "optional": true + } + } + }, + "node_modules/ts-node/node_modules/acorn": { + "version": "8.11.2", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.2.tgz", + "integrity": "sha512-nc0Axzp/0FILLEVsm4fNwLCwMttvhEI263QtVPQcbpfZZ3ts0hLsZGOpE6czNlid7CJ9MlyH8reXkpsf3YUY4w==", + "dev": true, + "bin": { + "acorn": "bin/acorn" + }, + "engines": { + "node": ">=0.4.0" } }, "node_modules/tslib": { @@ -8121,9 +8190,9 @@ } }, "node_modules/typescript": { - "version": "4.5.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.2.tgz", - "integrity": "sha512-5BlMof9H1yGt0P8/WF+wPNw6GfctgGjXp5hkblpyT+8rkASSmkUKMXrxR0Xg8ThVCi/JnHQiKXeBaEwCeQwMFw==", + "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", @@ -8170,20 +8239,18 @@ "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==" }, - "node_modules/uuid": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-7.0.3.tgz", - "integrity": "sha512-DPSke0pXhTZgoF/d+WSt2QaKMCFSfx7QegxEWT+JOuHF5aWrKEn0G+ztjuJg/gG8/ItK+rbPCD/yNv8yyih6Cg==", - "bin": { - "uuid": "dist/bin/uuid" - } - }, "node_modules/v8-compile-cache": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz", "integrity": "sha512-l8lCEmLcLYZh4nbunNZvQCJc5pv7+RCwa8q/LdUx8u7lsWvPDKmpodJAJNwkAhJC//dFY48KuIEmjtd4RViDrA==", "dev": true }, + "node_modules/v8-compile-cache-lib": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", + "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", + "dev": true + }, "node_modules/validate-npm-package-license": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz", diff --git a/package.json b/package.json index afac0fd5..c58d8126 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,6 @@ "dependencies": { "@apollo/client": "3.8.6", "@lifi/sdk": "2.2.3", - "@nerdwallet/apollo-cache-policies": "3.2.0", "@thehubbleproject/bls": "0.5.1", "@walletconnect/universal-provider": "2.10.0", "apollo-link-ws": "1.0.20", @@ -67,7 +66,7 @@ "commander": "10.0.1", "cross-fetch": "3.1.5", "ethers": "5.7.0", - "graphql-ws": "5.14.0", + "graphql-ws": "5.14.2", "prettier": "2.8.8" }, "devDependencies": { @@ -82,7 +81,7 @@ "npm": "9.6.4", "reflect-metadata": "0.1.13", "rxjs": "6.6.7", - "ts-node": "8.10.2", - "typescript": "4.5.2" + "ts-node": "10.9.1", + "typescript": "4.9.5" } } diff --git a/src/sdk/api/api.service.ts b/src/sdk/api/api.service.ts index 26be0915..ac85ce82 100644 --- a/src/sdk/api/api.service.ts +++ b/src/sdk/api/api.service.ts @@ -1,12 +1,10 @@ -import { ApolloClient, DocumentNode, HttpLink, NormalizedCacheObject, Observable, split } from '@apollo/client/core'; +import { ApolloClient, DocumentNode, InMemoryCache, HttpLink, NormalizedCacheObject, Observable, split } from '@apollo/client/core'; import { setContext } from '@apollo/client/link/context'; import { WebSocketLink } from '@apollo/client/link/ws'; import { getMainDefinition } from '@apollo/client/utilities'; -import { InvalidationPolicyCache } from '@nerdwallet/apollo-cache-policies'; import fetch from 'cross-fetch'; import { BigNumber } from 'ethers'; import { isBigNumber, Service } from '../common'; -import { ŅacheSettings } from './constants'; import { HttpException, HttpExceptionCodes } from './exceptions'; import { ApiOptions, ApiRequestOptions, ApiRequestQueryOptions } from './interfaces'; import { buildApiUri, catchApiError, mapApiResult } from './utils'; @@ -15,13 +13,6 @@ export class ApiService extends Service { private readonly options: ApiOptions; private apolloClient: ApolloClient; - private cache = new InvalidationPolicyCache({ - resultCaching: true, - addTypename: false, - invalidationPolicies: { - types: ŅacheSettings, - }, - }); constructor(options: ApiOptions) { super(); @@ -139,7 +130,7 @@ export class ApiService extends Service { this.apolloClient = new ApolloClient({ link, - cache: this.cache, + cache: new InMemoryCache(), }); } @@ -153,9 +144,6 @@ export class ApiService extends Service { let result: T; try { - // checks and removes outdated cache entries - this.cache.expire(); - const { data } = await call(); result = mapApiResult(data, models); } catch (err) { diff --git a/src/sdk/base/HttpRpcClient.ts b/src/sdk/base/HttpRpcClient.ts index f771f951..46d9df47 100644 --- a/src/sdk/base/HttpRpcClient.ts +++ b/src/sdk/base/HttpRpcClient.ts @@ -5,6 +5,7 @@ import { UserOperationStruct } from '../contracts/account-abstraction/contracts/ import Debug from 'debug'; import { deepHexlify } from '../common/ERC4337Utils'; import { Gas } from '../common'; +import { ErrorHandler } from '../errorHandler/errorHandler.service'; const debug = Debug('aa.rpc'); @@ -34,8 +35,16 @@ export class HttpRpcClient { async getVerificationGasInfo(tx: UserOperationStruct): Promise { const hexifiedUserOp = deepHexlify(await resolveProperties(tx)); - const response = await this.userOpJsonRpcProvider.send('eth_estimateUserOperationGas', [hexifiedUserOp, this.entryPointAddress]); - return response; + try { + const response = await this.userOpJsonRpcProvider.send('eth_estimateUserOperationGas', [hexifiedUserOp, this.entryPointAddress]); + return response; + } catch (err) { + const body = JSON.parse(err.body); + if (body?.error?.code) { + throw new ErrorHandler(body.error.message, body.error.code) + } + throw new Error(err.message); + } } /** @@ -44,19 +53,35 @@ export class HttpRpcClient { * @return userOpHash the id of this operation, for getUserOperationTransaction */ async sendUserOpToBundler(userOp1: UserOperationStruct): Promise { - await this.initializing; - const hexifiedUserOp = deepHexlify(await resolveProperties(userOp1)); - const jsonRequestData: [UserOperationStruct, string] = [hexifiedUserOp, this.entryPointAddress]; - await this.printUserOperation('eth_sendUserOperation', jsonRequestData); - return await this.userOpJsonRpcProvider.send('eth_sendUserOperation', [hexifiedUserOp, this.entryPointAddress]); + try { + await this.initializing; + const hexifiedUserOp = deepHexlify(await resolveProperties(userOp1)); + const jsonRequestData: [UserOperationStruct, string] = [hexifiedUserOp, this.entryPointAddress]; + await this.printUserOperation('eth_sendUserOperation', jsonRequestData); + return await this.userOpJsonRpcProvider.send('eth_sendUserOperation', [hexifiedUserOp, this.entryPointAddress]); + } catch (err) { + const body = JSON.parse(err.body); + if (body?.error?.code) { + throw new ErrorHandler(body.error.message, body.error.code) + } + throw new Error(err); + } } async sendAggregatedOpsToBundler(userOps1: UserOperationStruct[]): Promise { - const hexifiedUserOps = await Promise.all(userOps1.map(async (userOp1) => await resolveProperties(userOp1))); - return await this.userOpJsonRpcProvider.send('eth_sendAggregatedUserOperation', [ - hexifiedUserOps, - this.entryPointAddress, - ]); + try { + const hexifiedUserOps = await Promise.all(userOps1.map(async (userOp1) => await resolveProperties(userOp1))); + return await this.userOpJsonRpcProvider.send('eth_sendAggregatedUserOperation', [ + hexifiedUserOps, + this.entryPointAddress, + ]); + } catch (err) { + const body = JSON.parse(err.body); + if (body?.error?.code) { + throw new ErrorHandler(body.error.message, body.error.code) + } + throw new Error(err); + } } async getSkandhaGasPrice(): Promise { diff --git a/src/sdk/errorHandler/constants.ts b/src/sdk/errorHandler/constants.ts new file mode 100644 index 00000000..be63c14a --- /dev/null +++ b/src/sdk/errorHandler/constants.ts @@ -0,0 +1,12 @@ +export const errorMsg = { + '-32521': 'Check for balance in your Smart wallet', // execution reverted + '-32500': `Please make sure you have enough funds for wallet creation.`, // transaction rejected by entryPoint's simulateValidation, during wallet creation or validation + '-32501': `Check paymaster data`, // transaction rejected by paymaster's validatePaymasterUserOp + '-32502': 'Try with another bundler', //transaction rejected because of opcode validation + '-32503': 'validUntil and validAfter cannot be past timestamps', // UserOperation out of time-range + '-32504': 'Try changing the bundler which accepts this paymaster', // transaction rejected because paymaster (or signature aggregator) is throttled/banned + '-32505': 'Paymaster not staked or unstake-delay is too low. Try with another paymaster', // transaction rejected because paymaster (or signature aggregator) stake or unstake-delay is too low + '-32506': null, // transaction rejected because wallet specified unsupported signature aggregator + '-32507': null, // transaction rejected because of wallet signature check failed (or paymaster signature, if the paymaster uses its data as signature) + '1': 'Make sure the sdk fn called has valid parameters', // sdk Validation errors +} \ No newline at end of file diff --git a/src/sdk/errorHandler/errorHandler.service.ts b/src/sdk/errorHandler/errorHandler.service.ts new file mode 100644 index 00000000..cc06d64f --- /dev/null +++ b/src/sdk/errorHandler/errorHandler.service.ts @@ -0,0 +1,16 @@ +import { errorMsg } from "./constants"; + +export class ErrorHandler extends Error { + public possibleSolution: string = null; + constructor(public error: string, public code?: number) { + super(error); + this.error = error; + this.code = code; + if (code) { + this.possibleSolution = errorMsg[code.toString()]; + if (error.includes('AA33 reverted')) { + this.possibleSolution += ' If using a token, make sure that approval transaction is done for the requested operation and have enough tokens to spend for this transaction.' + } + } + } +} \ No newline at end of file diff --git a/src/sdk/sdk.ts b/src/sdk/sdk.ts index 5ae22588..028ff20f 100644 --- a/src/sdk/sdk.ts +++ b/src/sdk/sdk.ts @@ -19,6 +19,7 @@ import { CreateSessionDto, OnRamperDto, GetAccountBalancesDto, GetAdvanceRoutesL import { AccountBalances, AdvanceRoutesLiFi, BridgingQuotes, ExchangeOffer, NftList, StepTransactions, Transaction, Session, RateData, TokenListToken, TokenList } from './'; import { ZeroDevWalletAPI } from './base/ZeroDevWalletAPI'; import { SimpleAccountAPI } from './base/SimpleAccountWalletAPI'; +import { ErrorHandler } from './errorHandler/errorHandler.service'; /** * Prime-Sdk @@ -156,7 +157,7 @@ export class PrimeSdk { async estimate(paymasterDetails?: PaymasterApi, gasDetails?: TransactionGasInfoForUserOp) { if (this.userOpsBatch.to.length < 1) { - throw new Error("cannot sign empty transaction batch"); + throw new ErrorHandler('cannot sign empty transaction batch', 1); } if (paymasterDetails?.url) { @@ -242,8 +243,8 @@ export class PrimeSdk { async addUserOpsToBatch( tx: UserOpsRequest, ): Promise { - if (!tx.data && !tx.value) throw new Error('Data and Value both cannot be empty'); - if (tx.value && this.factoryUsed === Factory.SIMPLE_ACCOUNT && tx.value.toString() !== '0' && this.userOpsBatch.value.length > 0) throw new Error('SimpleAccount: native transfers cant be part of batch'); + if (!tx.data && !tx.value) throw new ErrorHandler('Data and Value both cannot be empty', 1); + if (tx.value && this.factoryUsed === Factory.SIMPLE_ACCOUNT && tx.value.toString() !== '0' && this.userOpsBatch.value.length > 0) throw new ErrorHandler('SimpleAccount: native transfers cant be part of batch', 1); this.userOpsBatch.to.push(tx.to); this.userOpsBatch.value.push(tx.value ?? BigNumber.from(0)); this.userOpsBatch.data.push(tx.data ?? '0x'); @@ -272,7 +273,7 @@ export class PrimeSdk { else { const networks = params.onlyCryptoNetworks.split(','); for (const network in networks) { - if (!onRamperAllNetworks.includes(network)) throw new Error('Included Networks which are not supported. Please Check'); + if (!onRamperAllNetworks.includes(network)) throw new ErrorHandler('Included Networks which are not supported. Please Check', 1); } }