Skip to content

Commit

Permalink
feat: add support for thirdweb
Browse files Browse the repository at this point in the history
  • Loading branch information
adnpark committed Sep 23, 2024
1 parent 6795a9e commit 7d05abb
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 19 deletions.
35 changes: 27 additions & 8 deletions packages/core/actions/account-client/getUserOperationGasPrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,34 @@ export const getUserOperationGasPrice = async <
TChain extends Chain | undefined = Chain | undefined,
TAccount extends Account | undefined = Account | undefined
>(
client: Client<TTransport, TChain, TAccount, ZeroDevAccountClientRpcSchema>
client: Client<TTransport, TChain, TAccount, ZeroDevAccountClientRpcSchema>,
provider: string
): Promise<Prettify<GetUserOperationGasPriceReturnType>> => {
const gasPrice = await client.request({
method: "zd_getUserOperationGasPrice",
params: []
})
if (provider === "PIMLICO") {
const gasPrice = await client.request({
method: "zd_getPimlicoUserOperationGasPrice",
params: []
})

return {
maxFeePerGas: BigInt(gasPrice.standard.maxFeePerGas),
maxPriorityFeePerGas: BigInt(gasPrice.standard.maxPriorityFeePerGas)
return {
maxFeePerGas: BigInt(gasPrice.standard.maxFeePerGas),
maxPriorityFeePerGas: BigInt(gasPrice.standard.maxPriorityFeePerGas)
}
}

if (provider === "THIRDWEB") {
const gasPrice = await client.request({
method: "zd_getThirdwebUserOperationGasPrice",
params: []
})

return {
maxFeePerGas: BigInt(gasPrice.fast.maxFeePerGas),
maxPriorityFeePerGas: BigInt(gasPrice.fast.maxPriorityFeePerGas)
}
}

throw new Error(
`Unsupported provider: ${provider}, please use "PIMLICO" or "THIRDWEB"`
)
}
25 changes: 15 additions & 10 deletions packages/core/clients/kernelAccountClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,21 @@ export const createKernelAccountClient = <
})

let middleware = parameters.middleware
if (
(!middleware ||
(typeof middleware !== "function" && !middleware.gasPrice)) &&
client.transport?.url &&
isProviderSet(client.transport.url, "PIMLICO")
) {
const gasPrice = () => getUserOperationGasPrice(client)
middleware = {
...middleware,
gasPrice
const providers = ["PIMLICO", "THIRDWEB"]

for (const provider of providers) {
if (
(!middleware ||
(typeof middleware !== "function" && !middleware.gasPrice)) &&
client.transport?.url &&
isProviderSet(client.transport.url, provider)
) {
const gasPrice = () => getUserOperationGasPrice(client, provider)
middleware = {
...middleware,
gasPrice
}
break
}
}
return client.extend(
Expand Down
7 changes: 6 additions & 1 deletion packages/core/types/kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,12 @@ export type ZeroDevUserOperationGasPriceWithBigIntAsHex = {

export type ZeroDevAccountClientRpcSchema = [
{
Method: "zd_getUserOperationGasPrice"
Method: "zd_getPimlicoUserOperationGasPrice"
Parameters: []
ReturnType: ZeroDevUserOperationGasPriceWithBigIntAsHex
},
{
Method: "zd_getThirdwebUserOperationGasPrice"
Parameters: []
ReturnType: ZeroDevUserOperationGasPriceWithBigIntAsHex
}
Expand Down

0 comments on commit 7d05abb

Please sign in to comment.