-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow users to specify custom action to sponsor user operation
- Loading branch information
1 parent
13c0ce6
commit 9ff308f
Showing
6 changed files
with
161 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { deployContract } from "./smartAccount/deployContract.js" | ||
|
||
import { getChainId } from "./smartAccount/getChainId.js" | ||
|
||
import { | ||
type PrepareUserOperationRequestParameters, | ||
type PrepareUserOperationRequestReturnType, | ||
prepareUserOperationRequest | ||
} from "./smartAccount/prepareUserOperationRequest.js" | ||
|
||
import { sendTransaction } from "./smartAccount/sendTransaction.js" | ||
|
||
import { | ||
type SendUserOperationParameters, | ||
type SendUserOperationReturnType, | ||
sendUserOperation | ||
} from "./smartAccount/sendUserOperation.js" | ||
|
||
import { signMessage } from "./smartAccount/signMessage.js" | ||
|
||
import { signTypedData } from "./smartAccount/signTypedData.js" | ||
|
||
import { | ||
type SponsorUserOperationParameters, | ||
type SponsorUserOperationReturnType, | ||
sponsorUserOperation | ||
} from "./smartAccount/sponsorUserOperation.js" | ||
|
||
export { | ||
deployContract, | ||
getChainId, | ||
prepareUserOperationRequest, | ||
type PrepareUserOperationRequestParameters, | ||
type PrepareUserOperationRequestReturnType, | ||
sendTransaction, | ||
sendUserOperation, | ||
type SendUserOperationParameters, | ||
type SendUserOperationReturnType, | ||
signMessage, | ||
signTypedData, | ||
sponsorUserOperation, | ||
type SponsorUserOperationParameters, | ||
type SponsorUserOperationReturnType | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import type { Chain, Client, Hex, Transport } from "viem" | ||
import { type SmartAccount } from "../../accounts/types.js" | ||
import type { GetAccountParameter } from "../../types/index.js" | ||
import type { UserOperation } from "../../types/userOperation.js" | ||
import { getAction } from "../../utils/getAction.js" | ||
import { parseAccount } from "../../utils/index.js" | ||
import { AccountOrClientNotFoundError } from "../../utils/signUserOperationHashWithECDSA.js" | ||
import { estimateUserOperationGas } from "../bundler/estimateUserOperationGas.js" | ||
|
||
export type SponsorUserOperationParameters<TAccount extends SmartAccount | undefined = SmartAccount | undefined,> = { | ||
userOperation: UserOperation | ||
} & GetAccountParameter<TAccount> | ||
|
||
export type SponsorUserOperationReturnType = { | ||
paymasterAndData: Hex | ||
preVerificationGas: bigint | ||
verificationGasLimit: bigint | ||
callGasLimit: bigint | ||
} | ||
|
||
export async function sponsorUserOperation<TChain extends Chain | undefined, TAccount extends SmartAccount | undefined>( | ||
client: Client<Transport, TChain, TAccount>, | ||
args: SponsorUserOperationParameters<TAccount> | ||
): Promise<SponsorUserOperationReturnType> { | ||
const { account: account_ = client.account, userOperation } = args | ||
if (!account_) throw new AccountOrClientNotFoundError() | ||
|
||
const account = parseAccount(account_) as SmartAccount | ||
|
||
let callGasLimit = userOperation.callGasLimit | ||
let verificationGasLimit = userOperation.verificationGasLimit | ||
let preVerificationGas = userOperation.preVerificationGas | ||
|
||
if (!userOperation.callGasLimit || !userOperation.verificationGasLimit || !userOperation.preVerificationGas) { | ||
const gasParameters = await getAction( | ||
client, | ||
estimateUserOperationGas | ||
)({ | ||
userOperation, | ||
entryPoint: account.entryPoint | ||
}) | ||
|
||
callGasLimit = callGasLimit || gasParameters.callGasLimit | ||
verificationGasLimit = verificationGasLimit || gasParameters.verificationGasLimit | ||
preVerificationGas = preVerificationGas || gasParameters.preVerificationGas | ||
} | ||
|
||
return { | ||
paymasterAndData: "0x", | ||
callGasLimit, | ||
verificationGasLimit, | ||
preVerificationGas | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters