MCPcopy
hub / github.com/eth-infinitism/account-abstraction / simulateValidation

Function simulateValidation

test/UserOp.ts:472–501  ·  view source on GitHub ↗
(
  userOp: PackedUserOperation,
  entryPointAddress: string,
  txOverrides?: any)

Source from the content-addressed store, hash-verified

470 * @param txOverrides
471 */
472export async function simulateValidation (
473 userOp: PackedUserOperation,
474 entryPointAddress: string,
475 txOverrides?: any): Promise<IEntryPointSimulations.ValidationResultStructOutput> {
476 const entryPointSimulations = EntryPointSimulations__factory.createInterface()
477 const data = entryPointSimulations.encodeFunctionData('simulateValidation', [userOp])
478 const tx: TransactionRequest = {
479 to: entryPointAddress,
480 data,
481 ...txOverrides
482 }
483 const stateOverride = {
484 [entryPointAddress]: {
485 code: EntryPointSimulationsJson.deployedBytecode
486 }
487 }
488 try {
489 const simulationResult = await ethers.provider.send('eth_call', [tx, 'latest', stateOverride])
490 const res = entryPointSimulations.decodeFunctionResult('simulateValidation', simulationResult)
491 // note: here collapsing the returned "tuple of one" into a single value - will break for returning actual tuples
492 return res[0]
493 } catch (error: any) {
494 const revertData = error?.data
495 if (revertData != null) {
496 // note: this line throws the revert reason instead of returning it
497 entryPointSimulations.decodeFunctionResult('simulateValidation', revertData)
498 }
499 throw error
500 }
501}
502
503// TODO: this code is very much duplicated but "encodeFunctionData" is based on 20 overloads
504// TypeScript is not able to resolve overloads with variables: https://github.com/microsoft/TypeScript/issues/14107

Calls

no outgoing calls

Tested by

no test coverage detected