From fb623128b1e2055b5e55d297f9c660b811878542 Mon Sep 17 00:00:00 2001 From: Vignesh Date: Wed, 20 Sep 2023 16:30:11 +0530 Subject: [PATCH 1/2] removed axios package and used fetch instead --- package-lock.json | 113 +++----------------------- package.json | 13 ++- src/sdk/base/VerifyingPaymasterAPI.ts | 28 ++++--- 3 files changed, 35 insertions(+), 119 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2f51273c..31d1beec 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,27 +1,26 @@ { "name": "@etherspot/prime-sdk", - "version": "1.2.6", + "version": "1.2.7", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@etherspot/prime-sdk", - "version": "1.2.6", + "version": "1.2.7", "license": "MIT", "dependencies": { "@apollo/client": "3.4.0", - "@lifi/sdk": "^2.2.3", + "@lifi/sdk": "2.2.3", "@nerdwallet/apollo-cache-policies": "1.2.1", "@thehubbleproject/bls": "0.5.1", - "@walletconnect/universal-provider": "^2.10.0", - "apollo-link-ws": "^1.0.20", - "axios": "1.3.4", + "@walletconnect/universal-provider": "2.10.0", + "apollo-link-ws": "1.0.20", "class-transformer": "0.5.1", "class-validator": "0.14.0", - "commander": "^10.0.1", + "commander": "10.0.1", "cross-fetch": "3.1.5", "ethers": "5.7.0", - "prettier": "^2.8.8", + "prettier": "2.8.8", "reflect-metadata": "0.1.13" }, "devDependencies": { @@ -790,13 +789,13 @@ } }, "node_modules/@lifi/sdk": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/@lifi/sdk/-/sdk-2.3.0.tgz", - "integrity": "sha512-LWS2fXHduqrXFhZ3XMS4GLZwsDxDOl1xDc9+WUTKE8MUP+GJ/UGQ9jpvM2i4YQf/2KGttdPHYs77UnGk/0bYSQ==", + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/@lifi/sdk/-/sdk-2.2.3.tgz", + "integrity": "sha512-k5KFK5SRRqA1hGrQkkWPPhM0AYciAFyu6GLCJdDFUK6HM+No4qDQWT359K9mGU6FrXVhPMds58Imex/lj/XReQ==", "dependencies": { "@ethersproject/abi": "^5.7.0", "@ethersproject/contracts": "^5.7.0", - "@lifi/types": "^8.4.0", + "@lifi/types": "^8.0.4", "bignumber.js": "^9.1.1", "eth-rpc-errors": "^4.0.3", "ethers": "^5.7.2" @@ -1885,11 +1884,6 @@ "node": ">=4" } }, - "node_modules/asynckit": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" - }, "node_modules/atomic-sleep": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/atomic-sleep/-/atomic-sleep-1.0.0.tgz", @@ -1910,16 +1904,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/axios": { - "version": "1.3.4", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.3.4.tgz", - "integrity": "sha512-toYm+Bsyl6VC5wSkfkbbNB6ROv7KY93PEBBL6xyDczaIHasAiv4wPqQ/c4RjoQzipxRD2W5g21cOqQulZ7rHwQ==", - "dependencies": { - "follow-redirects": "^1.15.0", - "form-data": "^4.0.0", - "proxy-from-env": "^1.1.0" - } - }, "node_modules/backo2": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/backo2/-/backo2-1.0.2.tgz", @@ -2064,17 +2048,6 @@ "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", "dev": true }, - "node_modules/combined-stream": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", - "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "dependencies": { - "delayed-stream": "~1.0.0" - }, - "engines": { - "node": ">= 0.8" - } - }, "node_modules/commander": { "version": "10.0.1", "resolved": "https://registry.npmjs.org/commander/-/commander-10.0.1.tgz", @@ -2178,14 +2151,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/delayed-stream": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", - "engines": { - "node": ">=0.4.0" - } - }, "node_modules/detect-browser": { "version": "5.3.0", "resolved": "https://registry.npmjs.org/detect-browser/-/detect-browser-5.3.0.tgz", @@ -2925,25 +2890,6 @@ "integrity": "sha512-r5wGx7YeOwNWNlCA0wQ86zKyDLMQr+/RB8xy74M4hTphfmjlijTSSXGuH8rnvKZnfT9i+75zmd8jcKdMR4O6jA==", "dev": true }, - "node_modules/follow-redirects": { - "version": "1.15.2", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", - "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==", - "funding": [ - { - "type": "individual", - "url": "https://github.com/sponsors/RubenVerborgh" - } - ], - "engines": { - "node": ">=4.0" - }, - "peerDependenciesMeta": { - "debug": { - "optional": true - } - } - }, "node_modules/for-each": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz", @@ -2953,19 +2899,6 @@ "is-callable": "^1.1.3" } }, - "node_modules/form-data": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", - "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", - "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" - }, - "engines": { - "node": ">= 6" - } - }, "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -3842,25 +3775,6 @@ "node": ">=8.9.0" } }, - "node_modules/mime-db": { - "version": "1.52.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", - "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/mime-types": { - "version": "2.1.35", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", - "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", - "dependencies": { - "mime-db": "1.52.0" - }, - "engines": { - "node": ">= 0.6" - } - }, "node_modules/mimic-fn": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", @@ -7278,11 +7192,6 @@ "react-is": "^16.13.1" } }, - "node_modules/proxy-from-env": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", - "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" - }, "node_modules/punycode": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.0.tgz", diff --git a/package.json b/package.json index 62b62ef0..b3c1bbdc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@etherspot/prime-sdk", - "version": "1.2.6", + "version": "1.2.7", "description": "Etherspot Prime (Account Abstraction) SDK", "keywords": [ "ether", @@ -51,18 +51,17 @@ }, "dependencies": { "@apollo/client": "3.4.0", - "@lifi/sdk": "^2.2.3", + "@lifi/sdk": "2.2.3", "@nerdwallet/apollo-cache-policies": "1.2.1", "@thehubbleproject/bls": "0.5.1", - "apollo-link-ws": "^1.0.20", - "@walletconnect/universal-provider": "^2.10.0", - "axios": "1.3.4", + "apollo-link-ws": "1.0.20", + "@walletconnect/universal-provider": "2.10.0", "class-transformer": "0.5.1", "class-validator": "0.14.0", - "commander": "^10.0.1", + "commander": "10.0.1", "cross-fetch": "3.1.5", "ethers": "5.7.0", - "prettier": "^2.8.8", + "prettier": "2.8.8", "reflect-metadata": "0.1.13" }, "devDependencies": { diff --git a/src/sdk/base/VerifyingPaymasterAPI.ts b/src/sdk/base/VerifyingPaymasterAPI.ts index 400314ba..813484f5 100644 --- a/src/sdk/base/VerifyingPaymasterAPI.ts +++ b/src/sdk/base/VerifyingPaymasterAPI.ts @@ -1,5 +1,5 @@ -import axios from 'axios'; import { ethers } from 'ethers'; +import fetch from 'cross-fetch'; import { calcPreVerificationGas } from './calcPreVerificationGas'; import { PaymasterAPI } from './PaymasterAPI'; import { UserOperationStruct } from '../contracts/account-abstraction/contracts/core/BaseAccount'; @@ -39,7 +39,7 @@ export class VerifyingPaymasterAPI extends PaymasterAPI { // userOp.preVerificationGas contains a promise that will resolve to an error. await ethers.utils.resolveProperties(userOp); // eslint-disable-next-line no-empty - } catch (_) {} + } catch (_) { } const pmOp: Partial = { sender: userOp.sender, nonce: userOp.nonce, @@ -57,15 +57,23 @@ export class VerifyingPaymasterAPI extends PaymasterAPI { op.preVerificationGas = calcPreVerificationGas(op); // Ask the paymaster to sign the transaction and return a valid paymasterAndData value. - const paymasterAndData = await axios - .post(this.paymasterUrl, { - jsonrpc: '2.0', - id: 1, - method: 'pm_sponsorUserOperation', - params: [await toJSON(op), this.entryPoint, this.context, this.chainId, this.api_key], + const paymasterAndData = await fetch(this.paymasterUrl, { + method: 'POST', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ params: [await toJSON(op), this.entryPoint, this.context, this.chainId, this.api_key], jsonrpc: '2', id: 2 }), + }) + .then(async (res) => { + const response = await await res.json(); + if (response.error) { + throw new Error(response.error); + } + return response }) - .then((res) => { - return res.data + .catch((err) => { + throw new Error(err.message); }) return paymasterAndData; From bdca71659e68d0e25cb13990cc6faa1a4d35b10b Mon Sep 17 00:00:00 2001 From: Vignesh Date: Wed, 20 Sep 2023 16:31:48 +0530 Subject: [PATCH 2/2] updated changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b943b508..62537d40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ # Changelog +## [1.2.7] - 2023-09-20 +### Fixes +- Fixed the issue on usage of axios when paymaster is called via react native by replacing it to fetch. + ## [1.2.6] - 2023-09-12 ### Fixes - Fixed the issue on setting gas prices by the user if specified on estimate step