From 099d0be795d170c0bc7610a18bc9a714d471ff40 Mon Sep 17 00:00:00 2001 From: vignesha22 <82584664+vignesha22@users.noreply.github.com> Date: Mon, 11 Sep 2023 21:57:23 +0530 Subject: [PATCH] Paymaster Updates PRO-1803 (#31) * updated paymaster response * updated package version * updated changelog --- CHANGELOG.md | 5 +++++ package-lock.json | 4 ++-- package.json | 2 +- src/sdk/base/BaseAccountAPI.ts | 13 ++++++++----- src/sdk/base/PaymasterAPI.ts | 2 +- src/sdk/base/VerifyingPaymasterAPI.ts | 25 ++++++++++++++++--------- src/sdk/interfaces.ts | 3 ++- src/sdk/sdk.ts | 2 +- 8 files changed, 36 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5768aef3..46a2442a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ # Changelog +## [1.2.4] - 2023-09-11 +### Breaking Changes +- Changed the paymasterApi to include api_key for ARKA +- Changed paymaster response object to return paymasterAndData, VerificationGasLimit, PreVerificationGas, callGasLimit to set to the userOp before sending to the bundler + ## [1.2.2] - 2023-08-31 ### Breaking Changes - Changed the wallet factory address so the smart wallet address will generate a new address. Whoever wishes to access the old wallet should use version 1.2.0 to connect to the old smart wallet diff --git a/package-lock.json b/package-lock.json index a9a8d7a1..97b0aaa0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@etherspot/prime-sdk", - "version": "1.2.3", + "version": "1.2.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@etherspot/prime-sdk", - "version": "1.2.3", + "version": "1.2.4", "license": "MIT", "dependencies": { "@apollo/client": "3.4.0", diff --git a/package.json b/package.json index 9f34919c..f5f403ed 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@etherspot/prime-sdk", - "version": "1.2.3", + "version": "1.2.4", "description": "Etherspot Prime (Account Abstraction) SDK", "keywords": [ "ether", diff --git a/src/sdk/base/BaseAccountAPI.ts b/src/sdk/base/BaseAccountAPI.ts index 25880654..46df2a5f 100644 --- a/src/sdk/base/BaseAccountAPI.ts +++ b/src/sdk/base/BaseAccountAPI.ts @@ -491,9 +491,11 @@ export abstract class BaseAccountAPI { preVerificationGas: this.getPreVerificationGas(partialUserOp), }; paymasterAndData = (await this.paymasterAPI.getPaymasterAndData(userOpForPm)); - partialUserOp.verificationGasLimit = BigNumber.from(paymasterAndData.verificationGasLimit); + partialUserOp.verificationGasLimit = paymasterAndData.result.verificationGasLimit; + partialUserOp.preVerificationGas = paymasterAndData.result.preVerificationGas; + partialUserOp.callGasLimit = paymasterAndData.result.callGasLimit; } - partialUserOp.paymasterAndData = paymasterAndData ? paymasterAndData.paymasterAndData : '0x'; + partialUserOp.paymasterAndData = paymasterAndData ? paymasterAndData.result.paymasterAndData : '0x'; return { ...partialUserOp, preVerificationGas: this.getPreVerificationGas(partialUserOp), @@ -508,9 +510,10 @@ export abstract class BaseAccountAPI { async signUserOp(userOp: UserOperationStruct): Promise { if (this.paymasterAPI != null) { const paymasterAndData = await this.paymasterAPI.getPaymasterAndData(userOp); - userOp.paymasterAndData = paymasterAndData.paymasterAndData; - userOp.verificationGasLimit = BigNumber.from(paymasterAndData.verificationGasLimit); - userOp.preVerificationGas = paymasterAndData.preVerificationGas; + userOp.paymasterAndData = paymasterAndData.result.paymasterAndData; + userOp.verificationGasLimit = paymasterAndData.result.verificationGasLimit; + userOp.preVerificationGas = paymasterAndData.result.preVerificationGas; + userOp.callGasLimit = paymasterAndData.result.callGasLimit; } const userOpHash = await this.getUserOpHash(userOp); const signature = await this.signUserOpHash(userOpHash); diff --git a/src/sdk/base/PaymasterAPI.ts b/src/sdk/base/PaymasterAPI.ts index 2e669f22..c329298c 100644 --- a/src/sdk/base/PaymasterAPI.ts +++ b/src/sdk/base/PaymasterAPI.ts @@ -13,6 +13,6 @@ export class PaymasterAPI { */ // eslint-disable-next-line @typescript-eslint/no-unused-vars async getPaymasterAndData(userOp: Partial): Promise { - return { paymasterAndData: '0x', verificationGasLimit: '0x' }; + return { result: {paymasterAndData: '0x', verificationGasLimit: '0x', preVerificationGas: '0x', callGasLimit: '0x' }}; } } diff --git a/src/sdk/base/VerifyingPaymasterAPI.ts b/src/sdk/base/VerifyingPaymasterAPI.ts index 21a06ab2..400314ba 100644 --- a/src/sdk/base/VerifyingPaymasterAPI.ts +++ b/src/sdk/base/VerifyingPaymasterAPI.ts @@ -10,20 +10,27 @@ const DUMMY_PAYMASTER_AND_DATA = '0x0101010101010101010101010101010101010101000000000000000000000000000000000000000000000000000001010101010100000000000000000000000000000000000000000000000000000000000000000101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101'; export interface PaymasterResponse { - paymasterAndData: string; - verificationGasLimit: string; - preVerificationGas?: string; + result: { + paymasterAndData: string; + verificationGasLimit: string; + preVerificationGas: string; + callGasLimit: string; + } } export class VerifyingPaymasterAPI extends PaymasterAPI { private paymasterUrl: string; private entryPoint: string; private context: any; - constructor(paymasterUrl: string, entryPoint: string, context: any) { + private api_key: string; + private chainId: number; + constructor(paymasterUrl: string, entryPoint: string, context: any, api_key: string, chainId: number) { super(); this.paymasterUrl = paymasterUrl; this.entryPoint = entryPoint; this.context = context; + this.api_key = api_key; + this.chainId = chainId; } async getPaymasterAndData(userOp: Partial): Promise { @@ -55,15 +62,15 @@ export class VerifyingPaymasterAPI extends PaymasterAPI { jsonrpc: '2.0', id: 1, method: 'pm_sponsorUserOperation', - params: [await toJSON(op), this.entryPoint, this.context], + params: [await toJSON(op), this.entryPoint, this.context, this.chainId, this.api_key], }) .then((res) => { return res.data - }); + }) - return {paymasterAndData: paymasterAndData.paymasterAndData, verificationGasLimit: paymasterAndData.verificationGasLimit, preVerificationGas: op.preVerificationGas.toString()}; + return paymasterAndData; } } -export const getVerifyingPaymaster = (paymasterUrl: string, entryPoint: string, context: any) => - new VerifyingPaymasterAPI(paymasterUrl, entryPoint, context); +export const getVerifyingPaymaster = (paymasterUrl: string, entryPoint: string, context: any, api_key: string, chainId: number) => + new VerifyingPaymasterAPI(paymasterUrl, entryPoint, context, api_key, chainId); diff --git a/src/sdk/interfaces.ts b/src/sdk/interfaces.ts index 27f4ec63..185e050b 100644 --- a/src/sdk/interfaces.ts +++ b/src/sdk/interfaces.ts @@ -3,7 +3,8 @@ import { SessionStorage } from './session'; export interface PaymasterApi { url: string; - context: any; + api_key: string; + context?: any; } export interface SdkOptions { diff --git a/src/sdk/sdk.ts b/src/sdk/sdk.ts index 37375507..331d0a7b 100644 --- a/src/sdk/sdk.ts +++ b/src/sdk/sdk.ts @@ -63,7 +63,7 @@ export class PrimeSdk { let paymasterAPI = null; if (optionsLike.paymasterApi && optionsLike.paymasterApi.url) { - paymasterAPI = new VerifyingPaymasterAPI(optionsLike.paymasterApi.url, Networks[chainId].contracts.entryPoint, optionsLike.paymasterApi.context ?? {}) + paymasterAPI = new VerifyingPaymasterAPI(optionsLike.paymasterApi.url, Networks[chainId].contracts.entryPoint, optionsLike.paymasterApi.context ?? {}, optionsLike.paymasterApi.api_key, chainId) } this.etherspotWallet = new EtherspotWalletAPI({