Skip to content

Commit

Permalink
Add from field to the simulation (#286)
Browse files Browse the repository at this point in the history
* Add `from` field

* Use utility wallet address as a default "from"
  • Loading branch information
pavlovdog authored Aug 25, 2024
1 parent 4a22f49 commit decf0ea
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 8 deletions.
13 changes: 10 additions & 3 deletions src/cli/setupServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,19 @@ const getValidator = ({
logger,
senderManager,
metrics,
gasPriceManager
gasPriceManager,
walletClient
}: {
client: PublicClient<Transport, Chain>
parsedArgs: IOptions
logger: Logger
senderManager: SenderManager
metrics: Metrics
gasPriceManager: GasPriceManager
gasPriceManager: GasPriceManager,
walletClient: WalletClient<Transport, Chain>
}): InterfaceValidator => {
const utilityWalletAddress = parsedArgs["utility-private-key"]?.address || "0x4337000c2828F5260d8921fD25829F606b9E8680"

if (parsedArgs["safe-mode"]) {
return new SafeValidator(
client,
Expand All @@ -83,6 +87,7 @@ const getValidator = ({
gasPriceManager,
parsedArgs["chain-type"],
parsedArgs["block-tag-support"],
utilityWalletAddress,
parsedArgs["entrypoint-simulation-contract"],
parsedArgs["fixed-gas-limit-for-estimation"],
parsedArgs.tenderly,
Expand All @@ -99,6 +104,7 @@ const getValidator = ({
gasPriceManager,
parsedArgs["chain-type"],
parsedArgs["block-tag-support"],
utilityWalletAddress,
parsedArgs["entrypoint-simulation-contract"],
parsedArgs["fixed-gas-limit-for-estimation"],
parsedArgs.tenderly,
Expand Down Expand Up @@ -429,7 +435,8 @@ export const setupServer = async ({
parsedArgs,
senderManager,
metrics,
gasPriceManager
gasPriceManager,
walletClient
})
const reputationManager = getReputationManager({
client,
Expand Down
10 changes: 8 additions & 2 deletions src/rpc/EntryPointSimulationsV07.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ async function callPimlicoEntryPointSimulations(
entryPointSimulationsCallData: Hex[],
entryPointSimulationsAddress: Address,
blockTagSupport: boolean,
utilityWalletAddress: Address,
stateOverride?: StateOverrides
) {
const callData = encodeFunctionData({
Expand All @@ -260,6 +261,7 @@ async function callPimlicoEntryPointSimulations(
params: [
{
to: entryPointSimulationsAddress,
from: utilityWalletAddress,
data: callData
},
blockTagSupport
Expand Down Expand Up @@ -287,6 +289,7 @@ export async function simulateHandleOp(
targetCallData: Hex,
entryPointSimulationsAddress: Address,
blockTagSupport: boolean,
utilityWalletAddress: Address,
stateOverride: StateOverrides = {}
) {
const finalParam = getStateOverrides({
Expand Down Expand Up @@ -319,6 +322,7 @@ export async function simulateHandleOp(
],
entryPointSimulationsAddress,
blockTagSupport,
utilityWalletAddress,
finalParam
)

Expand Down Expand Up @@ -519,7 +523,8 @@ export async function simulateValidation(
entryPoint: Address,
publicClient: PublicClient,
entryPointSimulationsAddress: Address,
blockTagSupport: boolean
blockTagSupport: boolean,
utilityWalletAddress: Address
) {
const userOperations = [...queuedUserOperations, userOperation]
const packedUserOperations = userOperations.map((uo) =>
Expand All @@ -537,7 +542,8 @@ export async function simulateValidation(
entryPoint,
[entryPointSimulationsCallData],
entryPointSimulationsAddress,
blockTagSupport
blockTagSupport,
utilityWalletAddress
)

return {
Expand Down
9 changes: 9 additions & 0 deletions src/rpc/gasEstimation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export async function simulateHandleOpV06(
targetAddress: Address,
targetCallData: Hex,
blockTagSupport: boolean,
utilityWalletAddress: Address,
finalParam: StateOverrides | undefined = undefined,
fixedGasLimitForEstimation?: bigint
): Promise<SimulateHandleOpResult> {
Expand All @@ -92,6 +93,7 @@ export async function simulateHandleOpV06(
params: [
{
to: entryPoint,
from: utilityWalletAddress,
data: encodeFunctionData({
abi: EntryPointV06Abi,
functionName: "simulateHandleOp",
Expand Down Expand Up @@ -210,6 +212,7 @@ async function callPimlicoEntryPointSimulations(
entryPointSimulationsCallData: Hex[],
entryPointSimulationsAddress: Address,
blockTagSupport: boolean,
utilityWalletAddress: Address,
stateOverride?: StateOverrides,
fixedGasLimitForEstimation?: bigint
) {
Expand All @@ -224,6 +227,7 @@ async function callPimlicoEntryPointSimulations(
params: [
{
to: entryPointSimulationsAddress,
from: utilityWalletAddress,
data: callData,
...(fixedGasLimitForEstimation !== undefined && {
gas: `0x${fixedGasLimitForEstimation.toString(16)}`
Expand Down Expand Up @@ -402,6 +406,7 @@ export async function simulateHandleOpV07(
chainId: number,
blockTagSupport: boolean,
finalParam: StateOverrides | undefined = undefined,
utilityWalletAddress: Address,
fixedGasLimitForEstimation?: bigint
): Promise<SimulateHandleOpResult> {
const userOperations = [...queuedUserOperations, userOperation]
Expand Down Expand Up @@ -537,6 +542,7 @@ export async function simulateHandleOpV07(
],
entryPointSimulationsAddress,
blockTagSupport,
utilityWalletAddress,
finalParam,
fixedGasLimitForEstimation
)
Expand Down Expand Up @@ -598,6 +604,7 @@ export function simulateHandleOp(
balanceOverrideEnabled: boolean,
chainId: number,
blockTagSupport: boolean,
utilityWalletAddress: Address,
stateOverride: StateOverrides = {},
entryPointSimulationsAddress?: Address,
fixedGasLimitForEstimation?: bigint
Expand All @@ -621,6 +628,7 @@ export function simulateHandleOp(
targetAddress,
targetCallData,
blockTagSupport,
utilityWalletAddress,
finalStateOverride,
fixedGasLimitForEstimation
)
Expand All @@ -642,6 +650,7 @@ export function simulateHandleOp(
chainId,
blockTagSupport,
finalStateOverride,
utilityWalletAddress,
fixedGasLimitForEstimation
)
}
2 changes: 2 additions & 0 deletions src/rpc/validation/SafeValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export class SafeValidator
gasPriceManager: GasPriceManager,
chainType: ChainType,
blockTagSupport: boolean,
utilityWalletAddress: Address,
entryPointSimulationsAddress?: Address,
fixedGasLimitForEstimation?: bigint,
usingTenderly = false,
Expand All @@ -82,6 +83,7 @@ export class SafeValidator
gasPriceManager,
chainType,
blockTagSupport,
utilityWalletAddress,
entryPointSimulationsAddress,
fixedGasLimitForEstimation,
usingTenderly,
Expand Down
12 changes: 9 additions & 3 deletions src/rpc/validation/UnsafeValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export class UnsafeValidator implements InterfaceValidator {
fixedGasLimitForEstimation?: bigint
chainType: ChainType
blockTagSupport: boolean
utilityWalletAddress: Address

constructor(
publicClient: PublicClient<Transport, Chain>,
Expand All @@ -76,11 +77,12 @@ export class UnsafeValidator implements InterfaceValidator {
gasPriceManager: GasPriceManager,
chainType: ChainType,
blockTagSupport: boolean,
utilityWalletAddress: Address,
entryPointSimulationsAddress?: Address,
fixedGasLimitForEstimation?: bigint,
usingTenderly = false,
balanceOverrideEnabled = false,
expirationCheck = true
expirationCheck = true,
) {
this.publicClient = publicClient
this.logger = logger
Expand All @@ -94,6 +96,7 @@ export class UnsafeValidator implements InterfaceValidator {
this.fixedGasLimitForEstimation = fixedGasLimitForEstimation
this.chainType = chainType
this.blockTagSupport = blockTagSupport
this.utilityWalletAddress = utilityWalletAddress
}

async getSimulationResult(
Expand Down Expand Up @@ -192,6 +195,7 @@ export class UnsafeValidator implements InterfaceValidator {
this.balanceOverrideEnabled,
this.chainId,
this.blockTagSupport,
this.utilityWalletAddress,
stateOverrides,
this.entryPointSimulationsAddress,
this.fixedGasLimitForEstimation
Expand Down Expand Up @@ -240,7 +244,8 @@ export class UnsafeValidator implements InterfaceValidator {
this.publicClient,
zeroAddress,
"0x",
this.blockTagSupport
this.blockTagSupport,
this.utilityWalletAddress,
)

const [simulateValidationResult, runtimeValidation] = await Promise.all(
Expand Down Expand Up @@ -395,7 +400,8 @@ export class UnsafeValidator implements InterfaceValidator {
entryPoint,
this.publicClient,
this.entryPointSimulationsAddress,
this.blockTagSupport
this.blockTagSupport,
this.utilityWalletAddress
)

if (simulateValidationResult.status === "failed") {
Expand Down

0 comments on commit decf0ea

Please sign in to comment.