Skip to content

Commit

Permalink
support sponsorshipPolicyId context
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewwahid committed Oct 13, 2024
1 parent 84c0ae6 commit 76c753f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ PUBLIC_ADDRESS=
PRIVATE_KEY=

#get early access to Candide's Paymaster sponsor policies on our Discord
PAYMASTER_RPC=
PAYMASTER_RPC=

#Sponsorship policy ID (leave blank if you want to get sponsored by public policies if your userop is eligible)
SPONSORSHIP_POLICY_ID=
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ async function main(): Promise<void> {
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
Expand Down Expand Up @@ -73,7 +74,7 @@ async function main(): Promise<void> {
)

let [paymasterUserOperation, _sponsorMetadata] = await paymaster.createSponsorPaymasterUserOperation(
userOperation, bundlerUrl)
userOperation, bundlerUrl, sponsorshipPolicyId) // sponsorshipPolicyId will have no effect if empty
userOperation = paymasterUserOperation;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@ async function main(): Promise<void> {
let [paymasterUserOperation, _sponsorMetadata] = await paymaster.createSponsorPaymasterUserOperation(
userOperation,
bundlerUrl,
//{
// verificationGasLimitPercentageMultiplier:130
//}
)
userOperation = paymasterUserOperation;

Expand Down
17 changes: 9 additions & 8 deletions src/paymaster/CandidePaymaster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/paymaster/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { StateOverrideSet } from "../types";

export interface CandidePaymasterContext {
token?: string;
sponsorshipPolicyId?: string;
}

export interface PrependTokenPaymasterApproveAccount {
Expand Down

0 comments on commit 76c753f

Please sign in to comment.