From 76c753f04f89ea241efe310a135d7cd28b14d21e Mon Sep 17 00:00:00 2001 From: Andrew Wahid Date: Sun, 13 Oct 2024 20:09:36 +0300 Subject: [PATCH] support sponsorshipPolicyId context --- .../.env.example | 5 ++++- .../src/index.ts | 5 +++-- .../src/index.ts | 3 --- src/paymaster/CandidePaymaster.ts | 17 +++++++++-------- src/paymaster/types.ts | 1 + 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/examples/SafeAccountExamples/CreateAccountAndSendTransactionUsingSponsorPaymaster/.env.example b/examples/SafeAccountExamples/CreateAccountAndSendTransactionUsingSponsorPaymaster/.env.example index 1eb3c7e..1a1b35c 100644 --- a/examples/SafeAccountExamples/CreateAccountAndSendTransactionUsingSponsorPaymaster/.env.example +++ b/examples/SafeAccountExamples/CreateAccountAndSendTransactionUsingSponsorPaymaster/.env.example @@ -8,4 +8,7 @@ PUBLIC_ADDRESS= PRIVATE_KEY= #get early access to Candide's Paymaster sponsor policies on our Discord -PAYMASTER_RPC= \ No newline at end of file +PAYMASTER_RPC= + +#Sponsorship policy ID (leave blank if you want to get sponsored by public policies if your userop is eligible) +SPONSORSHIP_POLICY_ID= \ No newline at end of file diff --git a/examples/SafeAccountExamples/CreateAccountAndSendTransactionUsingSponsorPaymaster/src/index.ts b/examples/SafeAccountExamples/CreateAccountAndSendTransactionUsingSponsorPaymaster/src/index.ts index a0774d1..c1aabd3 100644 --- a/examples/SafeAccountExamples/CreateAccountAndSendTransactionUsingSponsorPaymaster/src/index.ts +++ b/examples/SafeAccountExamples/CreateAccountAndSendTransactionUsingSponsorPaymaster/src/index.ts @@ -18,7 +18,8 @@ async function main(): Promise { const ownerPublicAddress = process.env.PUBLIC_ADDRESS as string const ownerPrivateKey = process.env.PRIVATE_KEY as string const paymasterRPC = process.env.PAYMASTER_RPC as string; - + const sponsorshipPolicyId = process.env.SPONSORSHIP_POLICY_ID as string; + //initializeNewAccount only needed when the smart account //have not been deployed yet for its first useroperation. //You can store the accountAddress to use it to initialize @@ -73,7 +74,7 @@ async function main(): Promise { ) let [paymasterUserOperation, _sponsorMetadata] = await paymaster.createSponsorPaymasterUserOperation( - userOperation, bundlerUrl) + userOperation, bundlerUrl, sponsorshipPolicyId) // sponsorshipPolicyId will have no effect if empty userOperation = paymasterUserOperation; diff --git a/examples/SafeAccountExamples/WebAuthnCreateAccountAndSendTransaction/src/index.ts b/examples/SafeAccountExamples/WebAuthnCreateAccountAndSendTransaction/src/index.ts index f7ea40d..ee8fdbc 100644 --- a/examples/SafeAccountExamples/WebAuthnCreateAccountAndSendTransaction/src/index.ts +++ b/examples/SafeAccountExamples/WebAuthnCreateAccountAndSendTransaction/src/index.ts @@ -107,9 +107,6 @@ async function main(): Promise { let [paymasterUserOperation, _sponsorMetadata] = await paymaster.createSponsorPaymasterUserOperation( userOperation, bundlerUrl, - //{ - // verificationGasLimitPercentageMultiplier:130 - //} ) userOperation = paymasterUserOperation; diff --git a/src/paymaster/CandidePaymaster.ts b/src/paymaster/CandidePaymaster.ts index 007e385..512b63b 100644 --- a/src/paymaster/CandidePaymaster.ts +++ b/src/paymaster/CandidePaymaster.ts @@ -597,32 +597,33 @@ export class CandidePaymaster extends Paymaster { async createSponsorPaymasterUserOperation( userOperation: UserOperationV7, bundlerRpc: string, - overrides?: CreatePaymasterUserOperationOverrides, + sponsorshipPolicyId?: string, ): Promise<[UserOperationV7, SponsorMetadata | undefined]>; async createSponsorPaymasterUserOperation( userOperation: UserOperationV6, bundlerRpc: string, - overrides?: CreatePaymasterUserOperationOverrides, + sponsorshipPolicyId?: string, ): Promise<[UserOperationV6, SponsorMetadata | undefined]>; async createSponsorPaymasterUserOperation( userOperation: UserOperationV7 | UserOperationV6, bundlerRpc: string, - overrides: CreatePaymasterUserOperationOverrides = {}, + sponsorshipPolicyId?: string, ): Promise<[UserOperationV7 | UserOperationV6, SponsorMetadata | undefined]> { - const createPaymasterUserOperationOverrides = overrides; + const context: CandidePaymasterContext = {}; + if (sponsorshipPolicyId && sponsorshipPolicyId.trim().length > 0){ + context["sponsorshipPolicyId"] = sponsorshipPolicyId; + } if ("initCode" in userOperation) { return await this.createPaymasterUserOperation( userOperation as UserOperationV6, bundlerRpc, - {}, - createPaymasterUserOperationOverrides, + context ); } else { return await this.createPaymasterUserOperation( userOperation as UserOperationV7, bundlerRpc, - {}, - createPaymasterUserOperationOverrides, + context ); } } diff --git a/src/paymaster/types.ts b/src/paymaster/types.ts index 4d41edf..cc9716a 100644 --- a/src/paymaster/types.ts +++ b/src/paymaster/types.ts @@ -2,6 +2,7 @@ import type { StateOverrideSet } from "../types"; export interface CandidePaymasterContext { token?: string; + sponsorshipPolicyId?: string; } export interface PrependTokenPaymasterApproveAccount {