Skip to content

Commit

Permalink
sync with main
Browse files Browse the repository at this point in the history
  • Loading branch information
mouseless0x committed Feb 15, 2025
2 parents 22feeda + 0a77ef0 commit da02a65
Show file tree
Hide file tree
Showing 23 changed files with 399 additions and 109 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"author": "Pimlico",
"license": "GPL-3.0-or-later",
"bin": {
"alto": "./src/lib/cli/alto.js"
"alto": "./src/esm/cli/alto.js"
},
"scripts": {
"prepare": "pnpm run build",
Expand Down
6 changes: 6 additions & 0 deletions src/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @pimlico/alto

## 0.0.13

### Patch Changes

- 2d8116a08da748cbe3e32763680300cd86e34325: Added alto binary to the package release

## 0.0.12

### Patch Changes
Expand Down
1 change: 1 addition & 0 deletions src/cli/alto.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env node
import * as sentry from "@sentry/node"
import dotenv from "dotenv"
import yargs from "yargs"
Expand Down
7 changes: 6 additions & 1 deletion src/cli/config/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export const compatibilityArgsSchema = z.object({
.transform((val) => val as ApiVersion),
"balance-override": z.boolean(),
"flush-stuck-transactions-during-startup": z.boolean(),
"is-gas-free-chain": z.boolean(),
"fixed-gas-limit-for-estimation": z
.string()
.transform((val) => BigInt(val))
Expand Down Expand Up @@ -206,6 +207,9 @@ export const gasEstimationArgsSchema = z.object({
.transform((val) => BigInt(val))
.default("1000000"),
"v6-call-gas-limit-multiplier": z.string().transform((val) => BigInt(val)),
"v6-verification-gas-limit-multiplier": z
.string()
.transform((val) => BigInt(val)),
"v7-call-gas-limit-multiplier": z.string().transform((val) => BigInt(val)),
"v7-verification-gas-limit-multiplier": z
.string()
Expand All @@ -226,7 +230,8 @@ export const gasEstimationArgsSchema = z.object({
"paymaster-gas-limit-multiplier": z
.string()
.transform((val) => BigInt(val)),
"eth-call-sender-address": addressSchema.optional()
"eth-call-sender-address": addressSchema.optional(),
"split-simulation-calls": z.boolean()
})

export const mempoolArgsSchema = z.object({
Expand Down
19 changes: 19 additions & 0 deletions src/cli/config/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,13 @@ export const gasEstimationOptions: CliCommandOptions<IGasEstimationArgsInput> =
require: true,
default: "100"
},
"v6-verification-gas-limit-multiplier": {
description:
"Amount to multiply the verificationGasLimit fetched from simulations for v6 userOperations",
type: "string",
require: true,
default: "100"
},
"v7-call-gas-limit-multiplier": {
description:
"Amount to multiply the callGasLimit fetched from simulations for v7 userOperations",
Expand Down Expand Up @@ -262,6 +269,12 @@ export const gasEstimationOptions: CliCommandOptions<IGasEstimationArgsInput> =
description:
"For permissioned chains, eth_call simulations require a whitelisted address as the sender",
type: "string"
},
"split-simulation-calls": {
description:
"Should the bundler split estimation simulations into smaller calls.",
type: "boolean",
default: false
}
}

Expand Down Expand Up @@ -392,6 +405,12 @@ export const compatibilityOptions: CliCommandOptions<ICompatibilityArgsInput> =
require: true,
default: "v1,v2"
},
"is-gas-free-chain": {
description:
"Indicates if the chain uses 0 for maxFee/maxPriorityFee",
type: "boolean",
default: false
},
"default-api-version": {
description: "Default API version",
type: "string",
Expand Down
6 changes: 3 additions & 3 deletions src/executor/executorManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ export class ExecutorManager {
}

// Debug endpoint
async sendBundleNow(): Promise<Hash> {
async sendBundleNow(): Promise<Hash | undefined> {
const bundles = await this.mempool.getBundles(1)
const bundle = bundles[0]

if (bundle.userOps.length === 0) {
throw new Error("no ops to bundle")
if (bundles.length === 0 || bundle.userOps.length === 0) {
return
}

const txHash = await this.sendBundleToExecutor(bundle)
Expand Down
2 changes: 1 addition & 1 deletion src/executor/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const getAuthorizationList = (
): SignedAuthorizationList | undefined => {
const authList = userOpInfos
.map(({ userOp }) => userOp)
.map(({ eip7702Auth }) => eip7702Auth)
.map(({ eip7702auth }) => eip7702auth)
.filter(Boolean) as SignedAuthorizationList

return authList.length ? authList : undefined
Expand Down
7 changes: 7 additions & 0 deletions src/handlers/gasPriceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,13 @@ export class GasPriceManager {
}

public async getGasPrice(): Promise<GasPriceParameters> {
if (this.config.isGasFreeChain) {
return {
maxFeePerGas: 0n,
maxPriorityFeePerGas: 0n
}
}

if (this.config.gasPriceRefreshInterval === 0) {
try {
return await this.tryUpdateGasPrice()
Expand Down
67 changes: 47 additions & 20 deletions src/mempool/mempool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
type UserOperation,
ValidationErrors,
type ValidationResult,
UserOperationBundle,
UserOpInfo
type UserOperationBundle,
type UserOpInfo
} from "@alto/types"
import type { Logger } from "@alto/utils"
import {
Expand Down Expand Up @@ -274,7 +274,6 @@ export class Mempool {
]
}

this.reputationManager.updateUserOperationSeenStatus(userOp, entryPoint)
const oldUserOpInfo = [
...outstandingOps,
...processedOrSubmittedOps
Expand Down Expand Up @@ -347,15 +346,24 @@ export class Mempool {
newOp.maxFeePerGas >=
scaleBigIntByPercent(oldOp.maxFeePerGas, 110n)

const hasHigherFees = hasHigherPriorityFee || hasHigherMaxFee
const hasHigherFees = hasHigherPriorityFee && hasHigherMaxFee

if (!hasHigherFees) {
return [false, reason]
}

await this.store.removeOutstanding(oldUserOpInfo.userOpHash)
this.reputationManager.replaceUserOperationSeenStatus(
oldOp,
entryPoint
)
}

this.reputationManager.increaseUserOperationSeenStatus(
userOp,
entryPoint
)

// Check if mempool already includes max amount of parallel user operations
const parallelUserOperationsCount = outstandingOps.filter(
(userOpInfo) => {
Expand Down Expand Up @@ -571,6 +579,11 @@ export class Mempool {
"2nd Validation error"
)
this.store.removeOutstanding(userOpHash)
this.reputationManager.decreaseUserOperationSeenStatus(
userOp,
entryPoint,
e instanceof RpcError ? e.message : JSON.stringify(e)
)
return {
skip: true,
paymasterDeposit,
Expand Down Expand Up @@ -833,10 +846,10 @@ export class Mempool {

const [nonceKey, nonceSequence] = getNonceKeyAndSequence(userOp.nonce)

let currentNonceValue: bigint = BigInt(0)
let currentNonceSequence: bigint = BigInt(0)

if (_currentNonceValue) {
currentNonceValue = _currentNonceValue
currentNonceSequence = _currentNonceValue
} else {
const getNonceResult = await entryPointContract.read.getNonce(
[userOp.sender, nonceKey],
Expand All @@ -845,7 +858,7 @@ export class Mempool {
}
)

currentNonceValue = getNonceKeyAndSequence(getNonceResult)[1]
currentNonceSequence = getNonceKeyAndSequence(getNonceResult)[1]
}

const outstandingOps = await this.store.dumpOutstanding()
Expand All @@ -855,25 +868,39 @@ export class Mempool {
const [mempoolNonceKey, mempoolNonceSequence] =
getNonceKeyAndSequence(mempoolUserOp.nonce)

let isPaymasterSame = false

if (isVersion07(userOp) && isVersion07(mempoolUserOp)) {
isPaymasterSame =
mempoolUserOp.paymaster === userOp.paymaster &&
!(
mempoolUserOp.sender === userOp.sender &&
mempoolNonceKey === nonceKey &&
mempoolNonceSequence === nonceSequence
) &&
userOp.paymaster !== null
}

return (
mempoolUserOp.sender === userOp.sender &&
mempoolNonceKey === nonceKey &&
mempoolNonceSequence >= currentNonceValue &&
mempoolNonceSequence < nonceSequence
(mempoolUserOp.sender === userOp.sender &&
mempoolNonceKey === nonceKey &&
mempoolNonceSequence >= currentNonceSequence &&
mempoolNonceSequence < nonceSequence) ||
isPaymasterSame
)
})

outstanding.sort((a, b) => {
const aUserOp = a.userOp
const bUserOp = b.userOp
return outstanding
.sort((a, b) => {
const aUserOp = a.userOp
const bUserOp = b.userOp

const [, aNonceValue] = getNonceKeyAndSequence(aUserOp.nonce)
const [, bNonceValue] = getNonceKeyAndSequence(bUserOp.nonce)
const [, aNonceValue] = getNonceKeyAndSequence(aUserOp.nonce)
const [, bNonceValue] = getNonceKeyAndSequence(bUserOp.nonce)

return Number(aNonceValue - bNonceValue)
})

return outstanding.map((userOpInfo) => userOpInfo.userOp)
return Number(aNonceValue - bNonceValue)
})
.map((userOpInfo) => userOpInfo.userOp)
}

clear(): void {
Expand Down
Loading

0 comments on commit da02a65

Please sign in to comment.