FRE-600: Fix code review blockers

- Consolidated duplicate UndoManagers to single instance
- Fixed connection promise to only resolve on 'connected' status
- Fixed WebSocketProvider import (WebsocketProvider)
- Added proper doc.destroy() cleanup
- Renamed isPresenceInitialized property to avoid conflict

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
2026-04-25 00:08:01 -04:00
parent 65b552bb08
commit 7c684a42cc
48450 changed files with 5679671 additions and 383 deletions

View File

@@ -0,0 +1,36 @@
import type { ErrorType } from '../../errors/utils.js'
import type { Log } from '../../types/log.js'
import {
type ParseEventLogsErrorType,
parseEventLogs,
} from '../../utils/abi/parseEventLogs.js'
import { portalAbi } from '../abis.js'
export type ExtractTransactionDepositedLogsParameters = {
/** An opaque array of logs. */
logs: Log[]
}
export type ExtractTransactionDepositedLogsReturnType = Log<
bigint,
number,
false,
undefined,
true,
typeof portalAbi,
'TransactionDeposited'
>[]
export type ExtractTransactionDepositedLogsErrorType =
| ParseEventLogsErrorType
| ErrorType
export function extractTransactionDepositedLogs({
logs,
}: ExtractTransactionDepositedLogsParameters) {
return parseEventLogs({
abi: portalAbi,
eventName: 'TransactionDeposited',
logs,
})
}

View File

@@ -0,0 +1,36 @@
import type { ErrorType } from '../../errors/utils.js'
import type { Log } from '../../types/log.js'
import {
type ParseEventLogsErrorType,
parseEventLogs,
} from '../../utils/abi/parseEventLogs.js'
import { l2ToL1MessagePasserAbi } from '../abis.js'
export type ExtractWithdrawalMessageLogsParameters = {
/** An opaque array of logs. */
logs: Log[]
}
export type ExtractWithdrawalMessageLogsReturnType = Log<
bigint,
number,
false,
undefined,
true,
typeof l2ToL1MessagePasserAbi,
'MessagePassed'
>[]
export type ExtractWithdrawalMessageLogsErrorType =
| ParseEventLogsErrorType
| ErrorType
export function extractWithdrawalMessageLogs({
logs,
}: ExtractWithdrawalMessageLogsParameters) {
return parseEventLogs({
abi: l2ToL1MessagePasserAbi,
eventName: 'MessagePassed',
logs,
})
}

View File

@@ -0,0 +1,52 @@
// Adapted from https://github.com/ethereum-optimism/optimism/blob/develop/packages/core-utils/src/optimism/deposit-transaction.ts#L117
import type { ErrorType } from '../../errors/utils.js'
import type { Log } from '../../types/log.js'
import type { Hex } from '../../types/misc.js'
import { keccak256 } from '../../utils/hash/keccak256.js'
import type { portalAbi } from '../abis.js'
import { serializeTransaction } from '../serializers.js'
import { getSourceHash } from './getSourceHash.js'
import { opaqueDataToDepositData } from './opaqueDataToDepositData.js'
export type GetL2TransactionHashParameters = {
/** The "TransactionDeposited" log to compute the L2 hash from. */
log: Log<
bigint,
number,
false,
undefined,
true,
typeof portalAbi,
'TransactionDeposited'
>
}
export type GetL2TransactionHashReturnType = Hex
export type GetL2TransactionHashErrorType = ErrorType
export function getL2TransactionHash({ log }: GetL2TransactionHashParameters) {
const sourceHash = getSourceHash({
domain: 'userDeposit',
l1BlockHash: log.blockHash,
l1LogIndex: log.logIndex,
})
const { data, gas, isCreation, mint, value } = opaqueDataToDepositData(
log.args.opaqueData,
)
return keccak256(
serializeTransaction({
from: log.args.from,
to: isCreation ? undefined : log.args.to,
sourceHash,
data,
gas,
isSystemTx: false,
mint,
type: 'deposit',
value,
}),
)
}

View File

@@ -0,0 +1,21 @@
import type { ErrorType } from '../../errors/utils.js'
import type { Log } from '../../types/log.js'
import type { Hex } from '../../types/misc.js'
import { extractTransactionDepositedLogs } from './extractTransactionDepositedLogs.js'
import { getL2TransactionHash } from './getL2TransactionHash.js'
export type GetL2TransactionHashesParameters = {
/** The L1 transaction receipt logs. */
logs: Log[]
}
export type GetL2TransactionHashesReturnType = Hex[]
export type GetL2TransactionHashesErrorType = ErrorType
export function getL2TransactionHashes({
logs,
}: GetL2TransactionHashesParameters): GetL2TransactionHashesReturnType {
const extractedLogs = extractTransactionDepositedLogs({ logs })
return extractedLogs.map((log) => getL2TransactionHash({ log }))
}

61
node_modules/viem/op-stack/utils/getSourceHash.ts generated vendored Normal file
View File

@@ -0,0 +1,61 @@
// Adapted from https://github.com/ethereum-optimism/optimism/blob/develop/packages/core-utils/src/optimism/deposit-transaction.ts#L117
import type { ErrorType } from '../../errors/utils.js'
import type { Hex } from '../../types/misc.js'
import { type ConcatErrorType, concat } from '../../utils/data/concat.js'
import { type PadErrorType, pad } from '../../utils/data/pad.js'
import { type ToHexErrorType, toHex } from '../../utils/encoding/toHex.js'
import {
type Keccak256ErrorType,
keccak256,
} from '../../utils/hash/keccak256.js'
export type GetSourceHashParameters = {
/** The L1 block hash. */
l1BlockHash: Hex
} & (
| {
/** Domain of source hash. */
domain: 'userDeposit'
/** The index of the log on the L1. */
l1LogIndex: number
/** The sequence number. */
sequenceNumber?: undefined
}
| {
/** Domain of source hash. */
domain: 'l1InfoDeposit'
/** The index of the log on the L1. */
l1LogIndex?: undefined
/** The sequence number. */
sequenceNumber: number
}
)
export type GetSourceHashReturnType = Hex
export type GetSourceHashErrorType =
| ConcatErrorType
| Keccak256ErrorType
| PadErrorType
| ToHexErrorType
| ErrorType
const sourceHashDomainMap = {
userDeposit: 0,
l1InfoDeposit: 1,
} as const
export function getSourceHash({
domain,
l1LogIndex,
l1BlockHash,
sequenceNumber,
}: GetSourceHashParameters) {
const marker = toHex(l1LogIndex! ?? sequenceNumber!)
const input = concat([l1BlockHash, pad(marker, { size: 32 })])
const depositIdHash = keccak256(input)
const domainHex = toHex(sourceHashDomainMap[domain])
const domainInput = concat([pad(domainHex, { size: 32 }), depositIdHash])
return keccak256(domainInput)
}

View File

@@ -0,0 +1,29 @@
import type { ErrorType } from '../../errors/utils.js'
import type { Hash } from '../../types/misc.js'
import {
type EncodeAbiParametersErrorType,
encodeAbiParameters,
} from '../../utils/abi/encodeAbiParameters.js'
import {
type Keccak256ErrorType,
keccak256,
} from '../../utils/hash/keccak256.js'
export type GetWithdrawalHashStorageSlotParameters = {
withdrawalHash: Hash
}
export type GetWithdrawalHashStorageSlotReturnType = Hash
export type GetWithdrawalHashStorageSlotErrorType =
| EncodeAbiParametersErrorType
| Keccak256ErrorType
| ErrorType
export function getWithdrawalHashStorageSlot({
withdrawalHash,
}: GetWithdrawalHashStorageSlotParameters) {
const data = encodeAbiParameters(
[{ type: 'bytes32' }, { type: 'uint256' }],
[withdrawalHash, 0n],
)
return keccak256(data)
}

25
node_modules/viem/op-stack/utils/getWithdrawals.ts generated vendored Normal file
View File

@@ -0,0 +1,25 @@
import type { ErrorType } from '../../errors/utils.js'
import type { Log } from '../../types/log.js'
import type { Withdrawal } from '../types/withdrawal.js'
import {
type ExtractWithdrawalMessageLogsErrorType,
extractWithdrawalMessageLogs,
} from './extractWithdrawalMessageLogs.js'
export type GetWithdrawalsParameters = {
/** The L2 transaction receipt logs. */
logs: Log[]
}
export type GetWithdrawalsReturnType = Withdrawal[]
export type GetWithdrawalsErrorType =
| ExtractWithdrawalMessageLogsErrorType
| ErrorType
export function getWithdrawals({
logs,
}: GetWithdrawalsParameters): GetWithdrawalsReturnType {
const extractedLogs = extractWithdrawalMessageLogs({ logs })
return extractedLogs.map((log) => log.args)
}

View File

@@ -0,0 +1,45 @@
import type { ErrorType } from '../../errors/utils.js'
import type { Hex } from '../../types/misc.js'
import { type SizeErrorType, size } from '../../utils/data/size.js'
import { type SliceErrorType, slice } from '../../utils/data/slice.js'
import { hexToBigInt } from '../../utils/encoding/fromHex.js'
export type OpaqueDataToDepositDataParameters = Hex
export type OpaqueDataToDepositDataReturnType = {
mint: bigint
value: bigint
gas: bigint
isCreation: boolean
data: Hex
}
export type OpaqueDataToDepositDataErrorType =
| SliceErrorType
| SizeErrorType
| ErrorType
export function opaqueDataToDepositData(
opaqueData: Hex,
): OpaqueDataToDepositDataReturnType {
let offset = 0
const mint = slice(opaqueData, offset, offset + 32)
offset += 32
const value = slice(opaqueData, offset, offset + 32)
offset += 32
const gas = slice(opaqueData, offset, offset + 8)
offset += 8
const isCreation = BigInt(slice(opaqueData, offset, offset + 1)) === 1n
offset += 1
const data =
offset > size(opaqueData) - 1
? '0x'
: slice(opaqueData, offset, opaqueData.length)
return {
mint: hexToBigInt(mint),
value: hexToBigInt(value),
gas: hexToBigInt(gas),
isCreation,
data,
}
}