Skip to content

Commit

Permalink
Paymaster Updates PRO-1803 (#31)
Browse files Browse the repository at this point in the history
* updated paymaster response

* updated package version

* updated changelog
  • Loading branch information
vignesha22 authored Sep 11, 2023
1 parent 3c9bcfb commit 099d0be
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 20 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@etherspot/prime-sdk",
"version": "1.2.3",
"version": "1.2.4",
"description": "Etherspot Prime (Account Abstraction) SDK",
"keywords": [
"ether",
Expand Down
13 changes: 8 additions & 5 deletions src/sdk/base/BaseAccountAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -508,9 +510,10 @@ export abstract class BaseAccountAPI {
async signUserOp(userOp: UserOperationStruct): Promise<UserOperationStruct> {
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);
Expand Down
2 changes: 1 addition & 1 deletion src/sdk/base/PaymasterAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ export class PaymasterAPI {
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async getPaymasterAndData(userOp: Partial<UserOperationStruct>): Promise<PaymasterResponse | undefined> {
return { paymasterAndData: '0x', verificationGasLimit: '0x' };
return { result: {paymasterAndData: '0x', verificationGasLimit: '0x', preVerificationGas: '0x', callGasLimit: '0x' }};
}
}
25 changes: 16 additions & 9 deletions src/sdk/base/VerifyingPaymasterAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<UserOperationStruct>): Promise<PaymasterResponse> {
Expand Down Expand Up @@ -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);
3 changes: 2 additions & 1 deletion src/sdk/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { SessionStorage } from './session';

export interface PaymasterApi {
url: string;
context: any;
api_key: string;
context?: any;
}

export interface SdkOptions {
Expand Down
2 changes: 1 addition & 1 deletion src/sdk/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 099d0be

Please sign in to comment.