Skip to content

Commit

Permalink
Merge pull request #49 from pimlicolabs/feat/add-sponsorship-policies
Browse files Browse the repository at this point in the history
Add sponsorship policies
  • Loading branch information
kristofgazso authored Dec 11, 2023
2 parents 4707e52 + 4d6f01f commit 679a634
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 15 deletions.
6 changes: 6 additions & 0 deletions .changeset/brave-pots-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"permissionless": patch
---

Add sponsorship policies option to pimlicoPaymasterClient
Update Safe 4337 module version to 0.2.0
2 changes: 1 addition & 1 deletion src/accounts/signerToSafeSmartAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const SAFE_VERSION_TO_ADDRESSES_MAP: {
}
} = {
"1.4.1": {
ADD_MODULES_LIB_ADDRESS: "0x191EFDC03615B575922289DC339F4c70aC5C30Af",
ADD_MODULES_LIB_ADDRESS: "0x8EcD4ec46D4D2a6B64fE960B3D64e8B94B2234eb",
SAFE_4337_MODULE_ADDRESS: "0x39E54Bb2b3Aa444b4B39DEe15De3b7809c36Fc38",
SAFE_PROXY_FACTORY_ADDRESS:
"0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67",
Expand Down
4 changes: 2 additions & 2 deletions src/actions/pimlico.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
getUserOperationStatus
} from "./pimlico/getUserOperationStatus.js"
import {
type SponsorUserOperationParameters,
type PimlocoSponsorUserOperationParameters,
type SponsorUserOperationReturnType,
sponsorUserOperation
} from "./pimlico/sponsorUserOperation.js"
Expand All @@ -26,7 +26,7 @@ export type {
GetUserOperationGasPriceReturnType,
GetUserOperationStatusParameters,
GetUserOperationStatusReturnType,
SponsorUserOperationParameters,
PimlocoSponsorUserOperationParameters,
SponsorUserOperationReturnType,
PimlicoBundlerActions,
PimlicoPaymasterClientActions
Expand Down
27 changes: 20 additions & 7 deletions src/actions/pimlico/sponsorUserOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
} from "../../types/userOperation.js"
import { deepHexlify } from "../../utils/deepHexlify.js"

export type SponsorUserOperationParameters = {
export type PimlocoSponsorUserOperationParameters = {
userOperation: PartialBy<
UserOperation,
| "callGasLimit"
Expand All @@ -16,6 +16,7 @@ export type SponsorUserOperationParameters = {
| "paymasterAndData"
>
entryPoint: Address
sponsorshipPolicyId?: string
}

export type SponsorUserOperationReturnType = {
Expand All @@ -31,7 +32,7 @@ export type SponsorUserOperationReturnType = {
* - Docs: https://docs.pimlico.io/permissionless/reference/pimlico-paymaster-actions/sponsorUserOperation
*
* @param client {@link PimlicoBundlerClient} that you created using viem's createClient whose transport url is pointing to the Pimlico's bundler.
* @param args {@link sponsorUserOperationParameters} UserOperation you want to sponsor & entryPoint.
* @param args {@link PimlocoSponsorUserOperationParameters} UserOperation you want to sponsor & entryPoint.
* @returns paymasterAndData & updated gas parameters, see {@link SponsorUserOperationReturnType}
*
*
Expand All @@ -56,14 +57,26 @@ export const sponsorUserOperation = async <
TAccount extends Account | undefined = Account | undefined
>(
client: Client<TTransport, TChain, TAccount, PimlicoPaymasterRpcSchema>,
args: SponsorUserOperationParameters
args: PimlocoSponsorUserOperationParameters
): Promise<SponsorUserOperationReturnType> => {
const response = await client.request({
method: "pm_sponsorUserOperation",
params: [
deepHexlify(args.userOperation) as UserOperationWithBigIntAsHex,
args.entryPoint
]
params: args.sponsorshipPolicyId
? [
deepHexlify(
args.userOperation
) as UserOperationWithBigIntAsHex,
args.entryPoint,
{
sponsorshipPolicyId: args.sponsorshipPolicyId
}
]
: [
deepHexlify(
args.userOperation
) as UserOperationWithBigIntAsHex,
args.entryPoint
]
})

return {
Expand Down
8 changes: 4 additions & 4 deletions src/clients/decorators/pimlico.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
getUserOperationStatus
} from "../../actions/pimlico/getUserOperationStatus.js"
import {
type SponsorUserOperationParameters,
type PimlocoSponsorUserOperationParameters,
type SponsorUserOperationReturnType,
sponsorUserOperation
} from "../../actions/pimlico/sponsorUserOperation.js"
Expand Down Expand Up @@ -78,7 +78,7 @@ export type PimlicoPaymasterClientActions = {
*
* https://docs.pimlico.io/permissionless/reference/pimlico-paymaster-actions/sponsorUserOperation
*
* @param args {@link SponsorUserOperationParameters} UserOperation you want to sponsor & entryPoint.
* @param args {@link PimlocoSponsorUserOperationParameters} UserOperation you want to sponsor & entryPoint.
* @returns paymasterAndData & updated gas parameters, see {@link SponsorUserOperationReturnType}
*
* @example
Expand All @@ -97,14 +97,14 @@ export type PimlicoPaymasterClientActions = {
*
*/
sponsorUserOperation: (
args: SponsorUserOperationParameters
args: PimlocoSponsorUserOperationParameters
) => Promise<SponsorUserOperationReturnType>
}

export const pimlicoPaymasterActions = (
client: Client
): PimlicoPaymasterClientActions => ({
sponsorUserOperation: async (args: SponsorUserOperationParameters) =>
sponsorUserOperation: async (args: PimlocoSponsorUserOperationParameters) =>
sponsorUserOperation(client as PimlicoPaymasterClient, args)
})

Expand Down
5 changes: 4 additions & 1 deletion src/types/pimlico.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ export type PimlicoPaymasterRpcSchema = [
| "verificationGasLimit"
| "paymasterAndData"
>,
entryPoint: Address
entryPoint: Address,
metadata?: {
sponsorshipPolicyId?: string
}
]
ReturnType: {
paymasterAndData: Hex
Expand Down

0 comments on commit 679a634

Please sign in to comment.