-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathpimlico.ts
More file actions
189 lines (187 loc) · 7.02 KB
/
Copy pathpimlico.ts
File metadata and controls
189 lines (187 loc) · 7.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import type { Address, Chain, Client, Hash, Prettify, Transport } from "viem"
import type { EntryPointVersion } from "viem/account-abstraction"
import {
type GetTokenQuotesParameters,
type GetTokenQuotesReturnType,
type SendCompressedUserOperationParameters,
type ValidateSponsorshipPolicies,
type ValidateSponsorshipPoliciesParameters,
getTokenQuotes,
sendCompressedUserOperation,
validateSponsorshipPolicies
} from "../../actions/pimlico.js"
import {
type EstimateErc20PaymasterCostParameters,
type EstimateErc20PaymasterCostReturnType,
estimateErc20PaymasterCost
} from "../../actions/pimlico/estimateErc20PaymasterCost.js"
import {
type GetUserOperationGasPriceReturnType,
getUserOperationGasPrice
} from "../../actions/pimlico/getUserOperationGasPrice.js"
import {
type GetUserOperationStatusParameters,
type GetUserOperationStatusReturnType,
getUserOperationStatus
} from "../../actions/pimlico/getUserOperationStatus.js"
import {
type PimlicoSponsorUserOperationParameters,
type SponsorUserOperationReturnType,
sponsorUserOperation
} from "../../actions/pimlico/sponsorUserOperation.js"
export type PimlicoActions<
TChain extends Chain | undefined,
entryPointVersion extends EntryPointVersion = EntryPointVersion
> = {
/**
* Returns the live gas prices that you can use to send a user operation.
*
* - Docs: https://docs.pimlico.io/permissionless/reference/pimlico-bundler-actions/getUserOperationGasPrice
*
* @returns slow, standard & fast values for maxFeePerGas & maxPriorityFeePerGas {@link GetUserOperationGasPriceReturnType}
*
* @example
*
* import { createClient } from "viem"
* import { pimlicoBundlerActions } from "permissionless/actions/pimlico"
*
* const bundlerClient = createClient({
* chain: goerli,
* transport: http("https://api.pimlico.io/v2/goerli/rpc?apikey=YOUR_API_KEY_HERE")
* }).extend(pimlicoBundlerActions)
*
* await bundlerClient.getUserOperationGasPrice()
*/
getUserOperationGasPrice: () => Promise<
Prettify<GetUserOperationGasPriceReturnType>
>
/**
* Returns the status of the userOperation that is pending in the mempool.
*
* - Docs: https://docs.pimlico.io/permissionless/reference/pimlico-bundler-actions/getUserOperationStatus
*
* @param hash {@link Hash} UserOpHash that you must have received from sendUserOperation.
* @returns status & transaction hash if included {@link GetUserOperationStatusReturnType}
*
* @example
* import { createClient } from "viem"
* import { pimlicoBundlerActions } from "permissionless/actions/pimlico"
*
* const bundlerClient = createClient({
* chain: goerli,
* transport: http("https://api.pimlico.io/v2/goerli/rpc?apikey=YOUR_API_KEY_HERE")
* }).extend(pimlicoBundlerActions)
*
* await bundlerClient.getUserOperationStatus({ hash: userOpHash })
*/
getUserOperationStatus: (
args: Prettify<GetUserOperationStatusParameters>
) => Promise<Prettify<GetUserOperationStatusReturnType>>
/**
* @deprecated pimlico_sendCompressedUserOperation has been deprecated due to EIP-4844 blobs. Please use sendUserOperation instead.
* Sends a compressed user operation to the bundler
*
* - Docs: https://docs.pimlico.io/permissionless/reference/pimlico-bundler-actions/sendCompressedUserOperation
*
* @param args {@link SendCompressedUserOperationParameters}.
* @returns UserOpHash that you can use to track user operation as {@link Hash}.
*
* @example
* import { createClient } from "viem"
* import { pimlicoBundlerActions } from "permissionless/actions/pimlico"
*
* const bundlerClient = createClient({
* chain: goerli,
* transport: http("https://api.pimlico.io/v1/goerli/rpc?apikey=YOUR_API_KEY_HERE")
* }).extend(pimlicoBundlerActions)
*
* const userOpHash = await bundlerClient.sendCompressedUserOperation({
* compressedUserOperation,
* inflatorAddress,
* entryPoint
* })
* // Return '0xe9fad2cd67f9ca1d0b7a6513b2a42066784c8df938518da2b51bb8cc9a89ea34'
*/
sendCompressedUserOperation: (
args: Prettify<
Omit<SendCompressedUserOperationParameters, "entryPointAddress">
>
) => Promise<Hash>
sponsorUserOperation: (
args: Omit<
PimlicoSponsorUserOperationParameters<entryPointVersion>,
"entryPoint"
>
) => Promise<Prettify<SponsorUserOperationReturnType<entryPointVersion>>>
validateSponsorshipPolicies: (
args: Prettify<
Omit<ValidateSponsorshipPoliciesParameters, "entryPointAddress">
>
) => Promise<Prettify<ValidateSponsorshipPolicies>[]>
getTokenQuotes: <
TChainOverride extends Chain | undefined = Chain | undefined
>(
args: Prettify<
Omit<
GetTokenQuotesParameters<TChain, TChainOverride>,
"entryPointAddress"
>
>
) => Promise<Prettify<GetTokenQuotesReturnType>>
estimateErc20PaymasterCost: <
TChainOverride extends Chain | undefined = Chain | undefined
>(
args: Omit<
EstimateErc20PaymasterCostParameters<
entryPointVersion,
TChain,
TChainOverride
>,
"entryPoint"
>
) => Promise<Prettify<EstimateErc20PaymasterCostReturnType>>
}
export const pimlicoActions =
<entryPointVersion extends EntryPointVersion>({
entryPoint
}: {
entryPoint: { address: Address; version: entryPointVersion }
}) =>
<
TTransport extends Transport,
TChain extends Chain | undefined = Chain | undefined
>(
client: Client<TTransport, TChain>
): PimlicoActions<TChain, entryPointVersion> => ({
getUserOperationGasPrice: async () => getUserOperationGasPrice(client),
getUserOperationStatus: async (
args: GetUserOperationStatusParameters
) => getUserOperationStatus(client, args),
sendCompressedUserOperation: async (args) =>
sendCompressedUserOperation(client, {
...args,
entryPointAddress: entryPoint.address
}),
sponsorUserOperation: async (args) =>
sponsorUserOperation(client, {
...args,
entryPoint
}),
validateSponsorshipPolicies: async (args) =>
validateSponsorshipPolicies(client, {
...args,
entryPointAddress: entryPoint.address
}),
getTokenQuotes: async (args) =>
getTokenQuotes(client, {
...args,
chain: args.chain,
entryPointAddress: entryPoint.address
}),
estimateErc20PaymasterCost: async (args) =>
estimateErc20PaymasterCost(client, {
...args,
entryPoint,
chain: args.chain
})
})