Skip to content

Commit

Permalink
Extract function
Browse files Browse the repository at this point in the history
  • Loading branch information
forshtat committed Dec 22, 2024
1 parent 9a5bc12 commit 8ab1c22
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions packages/bundler/src/modules/BundleManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,20 +410,11 @@ export class BundleManager implements IBundleManager {
}
mergeStorageMap(storageMap, validationResult.storageMap)

for (const eip7702Authorization of entry.userOp.authorizationList ?? []) {
const existingAuthorization = sharedAuthorizationList
.find(it => {
return getEip7702AuthorizationSigner(it) === getEip7702AuthorizationSigner(eip7702Authorization)
})
if (existingAuthorization != null && existingAuthorization.address.toLowerCase() !== eip7702Authorization.address.toLowerCase()) {
const mergeOk = this.mergeEip7702Authorizations(entry, sharedAuthorizationList)
if (!mergeOk) {
debug('unable to add bundle as it relies on an EIP-7702 tuple that conflicts with other UserOperations')
// eslint-disable-next-line no-labels
continue mainLoop
}
if (existingAuthorization == null && entry.userOp.authorizationList != null) {
sharedAuthorizationList.push(...entry.userOp.authorizationList)
continue
}
}

bundleGas = bundleGas.add(entry.userOpMaxGas)
senders.add(entry.userOp.sender)
Expand All @@ -433,6 +424,29 @@ export class BundleManager implements IBundleManager {
return [bundle, sharedAuthorizationList, storageMap]
}

/**
* Merges the EIP-7702 authorizations from the given mempool entry into the provided authorization list.
*
* @param {MempoolEntry} entry - The mempool entry containing a list of UserOperation authorizations to be checked.
* @param {EIP7702Authorization[]} authList - The list of existing EIP-7702 authorizations to update.
* @return {boolean} - Returns `true` if the authorizations were successfully merged, otherwise `false`.
*/
mergeEip7702Authorizations (entry: MempoolEntry, authList: EIP7702Authorization[]): boolean {
for (const eip7702Authorization of entry.userOp.authorizationList ?? []) {
const existingAuthorization = authList
.find(it => {
return getEip7702AuthorizationSigner(it) === getEip7702AuthorizationSigner(eip7702Authorization)
})
if (existingAuthorization != null && existingAuthorization.address.toLowerCase() !== eip7702Authorization.address.toLowerCase()) {
return false
}
if (existingAuthorization == null && entry.userOp.authorizationList != null) {
authList.push(...entry.userOp.authorizationList)
}
}
return true
}

_handleSecondValidationException (e: any, paymaster: string | undefined, entry: MempoolEntry): void {
debug('failed 2nd validation:', e.message)
// EREP-015: special case: if it is account/factory failure, then decreases paymaster's opsSeen
Expand Down

0 comments on commit 8ab1c22

Please sign in to comment.