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

76
node_modules/viem/utils/formatters/block.ts generated vendored Normal file
View File

@@ -0,0 +1,76 @@
import type { ErrorType } from '../../errors/utils.js'
import type { Block, BlockTag } from '../../types/block.js'
import type {
Chain,
ExtractChainFormatterExclude,
ExtractChainFormatterReturnType,
} from '../../types/chain.js'
import type { Hash } from '../../types/misc.js'
import type { RpcBlock } from '../../types/rpc.js'
import type { ExactPartial, Prettify } from '../../types/utils.js'
import { type DefineFormatterErrorType, defineFormatter } from './formatter.js'
import { type FormattedTransaction, formatTransaction } from './transaction.js'
type BlockPendingDependencies = 'hash' | 'logsBloom' | 'nonce' | 'number'
export type FormattedBlock<
chain extends Chain | undefined = undefined,
includeTransactions extends boolean = boolean,
blockTag extends BlockTag = BlockTag,
_FormatterReturnType = ExtractChainFormatterReturnType<
chain,
'block',
Block<bigint, includeTransactions>
>,
_ExcludedPendingDependencies extends string = BlockPendingDependencies &
ExtractChainFormatterExclude<chain, 'block'>,
_Formatted = Omit<_FormatterReturnType, BlockPendingDependencies> & {
[_key in _ExcludedPendingDependencies]: never
} & Pick<
Block<bigint, includeTransactions, blockTag>,
BlockPendingDependencies
>,
_Transactions = includeTransactions extends true
? Prettify<FormattedTransaction<chain, blockTag>>[]
: Hash[],
> = Omit<_Formatted, 'transactions'> & {
transactions: _Transactions
}
export type FormatBlockErrorType = ErrorType
export function formatBlock(
block: ExactPartial<RpcBlock>,
_?: string | undefined,
) {
const transactions = (block.transactions ?? []).map((transaction) => {
if (typeof transaction === 'string') return transaction
return formatTransaction(transaction)
})
return {
...block,
baseFeePerGas: block.baseFeePerGas ? BigInt(block.baseFeePerGas) : null,
blobGasUsed: block.blobGasUsed ? BigInt(block.blobGasUsed) : undefined,
difficulty: block.difficulty ? BigInt(block.difficulty) : undefined,
excessBlobGas: block.excessBlobGas
? BigInt(block.excessBlobGas)
: undefined,
gasLimit: block.gasLimit ? BigInt(block.gasLimit) : undefined,
gasUsed: block.gasUsed ? BigInt(block.gasUsed) : undefined,
hash: block.hash ? block.hash : null,
logsBloom: block.logsBloom ? block.logsBloom : null,
nonce: block.nonce ? block.nonce : null,
number: block.number ? BigInt(block.number) : null,
size: block.size ? BigInt(block.size) : undefined,
timestamp: block.timestamp ? BigInt(block.timestamp) : undefined,
transactions,
totalDifficulty: block.totalDifficulty
? BigInt(block.totalDifficulty)
: null,
} as Block
}
export type DefineBlockErrorType = DefineFormatterErrorType | ErrorType
export const defineBlock = /*#__PURE__*/ defineFormatter('block', formatBlock)

33
node_modules/viem/utils/formatters/extract.ts generated vendored Normal file
View File

@@ -0,0 +1,33 @@
import type { ErrorType } from '../../errors/utils.js'
import type { ChainFormatter } from '../../types/chain.js'
export type ExtractErrorType = ErrorType
/**
* @description Picks out the keys from `value` that exist in the formatter..
*/
export function extract(
value_: Record<string, unknown>,
{ format }: { format?: ChainFormatter['format'] | undefined },
) {
if (!format) return {}
const value: Record<string, unknown> = {}
function extract_(formatted: Record<string, any>) {
const keys = Object.keys(formatted)
for (const key of keys) {
if (key in value_) value[key] = value_[key]
if (
formatted[key] &&
typeof formatted[key] === 'object' &&
!Array.isArray(formatted[key])
)
extract_(formatted[key])
}
}
const formatted = format(value_ || {})
extract_(formatted)
return value
}

16
node_modules/viem/utils/formatters/feeHistory.ts generated vendored Normal file
View File

@@ -0,0 +1,16 @@
import type { ErrorType } from '../../errors/utils.js'
import type { FeeHistory } from '../../types/fee.js'
import type { RpcFeeHistory } from '../../types/rpc.js'
export type FormatFeeHistoryErrorType = ErrorType
export function formatFeeHistory(feeHistory: RpcFeeHistory): FeeHistory {
return {
baseFeePerGas: feeHistory.baseFeePerGas.map((value) => BigInt(value)),
gasUsedRatio: feeHistory.gasUsedRatio,
oldestBlock: BigInt(feeHistory.oldestBlock),
reward: feeHistory.reward?.map((reward) =>
reward.map((value) => BigInt(value)),
),
}
}

43
node_modules/viem/utils/formatters/formatter.ts generated vendored Normal file
View File

@@ -0,0 +1,43 @@
import type { ErrorType } from '../../errors/utils.js'
import type { Prettify } from '../../types/utils.js'
export type DefineFormatterErrorType = ErrorType
export function defineFormatter<type extends string, parameters, returnType>(
type: type,
format: (args: parameters, action?: string | undefined) => returnType,
) {
return <
parametersOverride,
returnTypeOverride,
exclude extends (keyof parameters | keyof parametersOverride)[] = [],
>({
exclude,
format: overrides,
}: {
exclude?: exclude | undefined
format: (
args: parametersOverride,
action?: string | undefined,
) => returnTypeOverride
}) => {
return {
exclude,
format: (args: parametersOverride, action?: string | undefined) => {
const formatted = format(args as any, action)
if (exclude) {
for (const key of exclude) {
delete (formatted as any)[key]
}
}
return {
...formatted,
...overrides(args, action),
} as Prettify<returnTypeOverride> & {
[_key in exclude[number]]: never
}
},
type,
}
}
}

31
node_modules/viem/utils/formatters/log.ts generated vendored Normal file
View File

@@ -0,0 +1,31 @@
import type { ErrorType } from '../../errors/utils.js'
import type { Log } from '../../types/log.js'
import type { RpcLog } from '../../types/rpc.js'
import type { ExactPartial } from '../../types/utils.js'
export type FormatLogErrorType = ErrorType
export function formatLog(
log: ExactPartial<RpcLog>,
{
args,
eventName,
}: { args?: unknown | undefined; eventName?: string | undefined } = {},
) {
return {
...log,
blockHash: log.blockHash ? log.blockHash : null,
blockNumber: log.blockNumber ? BigInt(log.blockNumber) : null,
blockTimestamp: log.blockTimestamp
? BigInt(log.blockTimestamp)
: log.blockTimestamp === null
? null
: undefined,
logIndex: log.logIndex ? Number(log.logIndex) : null,
transactionHash: log.transactionHash ? log.transactionHash : null,
transactionIndex: log.transactionIndex
? Number(log.transactionIndex)
: null,
...(eventName ? { args, eventName } : {}),
} as Log
}

25
node_modules/viem/utils/formatters/proof.ts generated vendored Normal file
View File

@@ -0,0 +1,25 @@
import type { ErrorType } from '../../errors/utils.js'
import type { Proof } from '../../types/proof.js'
import type { RpcProof } from '../../types/rpc.js'
import type { ExactPartial } from '../../types/utils.js'
import { hexToNumber } from '../index.js'
export type FormatProofErrorType = ErrorType
function formatStorageProof(storageProof: RpcProof['storageProof']) {
return storageProof.map((proof) => ({
...proof,
value: BigInt(proof.value),
}))
}
export function formatProof(proof: ExactPartial<RpcProof>) {
return {
...proof,
balance: proof.balance ? BigInt(proof.balance) : undefined,
nonce: proof.nonce ? hexToNumber(proof.nonce) : undefined,
storageProof: proof.storageProof
? formatStorageProof(proof.storageProof)
: undefined,
} as Proof
}

139
node_modules/viem/utils/formatters/transaction.ts generated vendored Normal file
View File

@@ -0,0 +1,139 @@
import type { ErrorType } from '../../errors/utils.js'
import type { SignedAuthorizationList } from '../../types/authorization.js'
import type { BlockTag } from '../../types/block.js'
import type {
Chain,
ExtractChainFormatterExclude,
ExtractChainFormatterReturnType,
} from '../../types/chain.js'
import type { Hex } from '../../types/misc.js'
import type { RpcAuthorizationList, RpcTransaction } from '../../types/rpc.js'
import type { Transaction, TransactionType } from '../../types/transaction.js'
import type { ExactPartial, UnionLooseOmit } from '../../types/utils.js'
import { hexToNumber } from '../encoding/fromHex.js'
import { type DefineFormatterErrorType, defineFormatter } from './formatter.js'
type TransactionPendingDependencies =
| 'blockHash'
| 'blockNumber'
| 'transactionIndex'
export type FormattedTransaction<
chain extends Chain | undefined = undefined,
blockTag extends BlockTag = BlockTag,
_FormatterReturnType = ExtractChainFormatterReturnType<
chain,
'transaction',
Transaction
>,
_ExcludedPendingDependencies extends string = TransactionPendingDependencies &
ExtractChainFormatterExclude<chain, 'transaction'>,
> = UnionLooseOmit<_FormatterReturnType, TransactionPendingDependencies> & {
[_K in _ExcludedPendingDependencies]: never
} & Pick<
Transaction<bigint, number, blockTag extends 'pending' ? true : false>,
TransactionPendingDependencies
>
export const transactionType = {
'0x0': 'legacy',
'0x1': 'eip2930',
'0x2': 'eip1559',
'0x3': 'eip4844',
'0x4': 'eip7702',
} as const satisfies Record<Hex, TransactionType>
export type FormatTransactionErrorType = ErrorType
export function formatTransaction(
transaction: ExactPartial<RpcTransaction>,
_?: string | undefined,
) {
const transaction_ = {
...transaction,
blockHash: transaction.blockHash ? transaction.blockHash : null,
blockNumber: transaction.blockNumber
? BigInt(transaction.blockNumber)
: null,
chainId: transaction.chainId ? hexToNumber(transaction.chainId) : undefined,
gas: transaction.gas ? BigInt(transaction.gas) : undefined,
gasPrice: transaction.gasPrice ? BigInt(transaction.gasPrice) : undefined,
maxFeePerBlobGas: transaction.maxFeePerBlobGas
? BigInt(transaction.maxFeePerBlobGas)
: undefined,
maxFeePerGas: transaction.maxFeePerGas
? BigInt(transaction.maxFeePerGas)
: undefined,
maxPriorityFeePerGas: transaction.maxPriorityFeePerGas
? BigInt(transaction.maxPriorityFeePerGas)
: undefined,
nonce: transaction.nonce ? hexToNumber(transaction.nonce) : undefined,
to: transaction.to ? transaction.to : null,
transactionIndex: transaction.transactionIndex
? Number(transaction.transactionIndex)
: null,
type: transaction.type
? (transactionType as any)[transaction.type]
: undefined,
typeHex: transaction.type ? transaction.type : undefined,
value: transaction.value ? BigInt(transaction.value) : undefined,
v: transaction.v ? BigInt(transaction.v) : undefined,
} as Transaction
if (transaction.authorizationList)
transaction_.authorizationList = formatAuthorizationList(
transaction.authorizationList,
)
transaction_.yParity = (() => {
// If `yParity` is provided, we will use it.
if (transaction.yParity) return Number(transaction.yParity)
// If no `yParity` provided, try derive from `v`.
if (typeof transaction_.v === 'bigint') {
if (transaction_.v === 0n || transaction_.v === 27n) return 0
if (transaction_.v === 1n || transaction_.v === 28n) return 1
if (transaction_.v >= 35n) return transaction_.v % 2n === 0n ? 1 : 0
}
return undefined
})()
if (transaction_.type === 'legacy') {
delete transaction_.accessList
delete transaction_.maxFeePerBlobGas
delete transaction_.maxFeePerGas
delete transaction_.maxPriorityFeePerGas
delete transaction_.yParity
}
if (transaction_.type === 'eip2930') {
delete transaction_.maxFeePerBlobGas
delete transaction_.maxFeePerGas
delete transaction_.maxPriorityFeePerGas
}
if (transaction_.type === 'eip1559') delete transaction_.maxFeePerBlobGas
return transaction_
}
export type DefineTransactionErrorType = DefineFormatterErrorType | ErrorType
export const defineTransaction = /*#__PURE__*/ defineFormatter(
'transaction',
formatTransaction,
)
//////////////////////////////////////////////////////////////////////////////
function formatAuthorizationList(
authorizationList: RpcAuthorizationList,
): SignedAuthorizationList {
return authorizationList.map((authorization) => ({
address: (authorization as any).address,
chainId: Number(authorization.chainId),
nonce: Number(authorization.nonce),
r: authorization.r,
s: authorization.s,
yParity: Number(authorization.yParity),
})) as SignedAuthorizationList
}

View File

@@ -0,0 +1,83 @@
import type { ErrorType } from '../../errors/utils.js'
import type {
Chain,
ExtractChainFormatterReturnType,
} from '../../types/chain.js'
import type { RpcTransactionReceipt } from '../../types/rpc.js'
import type { TransactionReceipt } from '../../types/transaction.js'
import type { ExactPartial } from '../../types/utils.js'
import { hexToNumber } from '../encoding/fromHex.js'
import { type DefineFormatterErrorType, defineFormatter } from './formatter.js'
import { formatLog } from './log.js'
import { transactionType } from './transaction.js'
export type FormattedTransactionReceipt<
chain extends Chain | undefined = undefined,
> = ExtractChainFormatterReturnType<
chain,
'transactionReceipt',
TransactionReceipt
>
export const receiptStatuses = {
'0x0': 'reverted',
'0x1': 'success',
} as const
export type FormatTransactionReceiptErrorType = ErrorType
export function formatTransactionReceipt(
transactionReceipt: ExactPartial<RpcTransactionReceipt>,
_?: string | undefined,
) {
const receipt = {
...transactionReceipt,
blockNumber: transactionReceipt.blockNumber
? BigInt(transactionReceipt.blockNumber)
: null,
contractAddress: transactionReceipt.contractAddress
? transactionReceipt.contractAddress
: null,
cumulativeGasUsed: transactionReceipt.cumulativeGasUsed
? BigInt(transactionReceipt.cumulativeGasUsed)
: null,
effectiveGasPrice: transactionReceipt.effectiveGasPrice
? BigInt(transactionReceipt.effectiveGasPrice)
: null,
gasUsed: transactionReceipt.gasUsed
? BigInt(transactionReceipt.gasUsed)
: null,
logs: transactionReceipt.logs
? transactionReceipt.logs.map((log) => formatLog(log))
: null,
to: transactionReceipt.to ? transactionReceipt.to : null,
transactionIndex: transactionReceipt.transactionIndex
? hexToNumber(transactionReceipt.transactionIndex)
: null,
status: transactionReceipt.status
? receiptStatuses[transactionReceipt.status]
: null,
type: transactionReceipt.type
? transactionType[
transactionReceipt.type as keyof typeof transactionType
] || transactionReceipt.type
: null,
} as TransactionReceipt
if (transactionReceipt.blobGasPrice)
receipt.blobGasPrice = BigInt(transactionReceipt.blobGasPrice)
if (transactionReceipt.blobGasUsed)
receipt.blobGasUsed = BigInt(transactionReceipt.blobGasUsed)
return receipt
}
export type DefineTransactionReceiptErrorType =
| DefineFormatterErrorType
| ErrorType
export const defineTransactionReceipt = /*#__PURE__*/ defineFormatter(
'transactionReceipt',
formatTransactionReceipt,
)

View File

@@ -0,0 +1,116 @@
import type { ErrorType } from '../../errors/utils.js'
import type { Account } from '../../types/account.js'
import type { AuthorizationList } from '../../types/authorization.js'
import type {
Chain,
ExtractChainFormatterParameters,
} from '../../types/chain.js'
import type { ByteArray } from '../../types/misc.js'
import type {
RpcAuthorizationList,
RpcTransactionRequest,
} from '../../types/rpc.js'
import type { TransactionRequest } from '../../types/transaction.js'
import type { ExactPartial } from '../../types/utils.js'
import { bytesToHex, numberToHex } from '../encoding/toHex.js'
import { type DefineFormatterErrorType, defineFormatter } from './formatter.js'
export type FormattedTransactionRequest<
chain extends Chain | undefined = Chain | undefined,
> = ExtractChainFormatterParameters<
chain,
'transactionRequest',
TransactionRequest
>
export const rpcTransactionType = {
legacy: '0x0',
eip2930: '0x1',
eip1559: '0x2',
eip4844: '0x3',
eip7702: '0x4',
} as const
export type FormatTransactionRequestErrorType = ErrorType
export function formatTransactionRequest(
request: ExactPartial<TransactionRequest> & { account?: Account | undefined },
_?: string | undefined,
) {
const rpcRequest = {} as RpcTransactionRequest
if (typeof request.authorizationList !== 'undefined')
rpcRequest.authorizationList = formatAuthorizationList(
request.authorizationList,
)
if (typeof request.accessList !== 'undefined')
rpcRequest.accessList = request.accessList
if (typeof request.blobVersionedHashes !== 'undefined')
rpcRequest.blobVersionedHashes = request.blobVersionedHashes
if (typeof request.blobs !== 'undefined') {
if (typeof request.blobs[0] !== 'string')
rpcRequest.blobs = (request.blobs as ByteArray[]).map((x) =>
bytesToHex(x),
)
else rpcRequest.blobs = request.blobs
}
if (typeof request.data !== 'undefined') rpcRequest.data = request.data
if (request.account) rpcRequest.from = request.account.address
if (typeof request.from !== 'undefined') rpcRequest.from = request.from
if (typeof request.gas !== 'undefined')
rpcRequest.gas = numberToHex(request.gas)
if (typeof request.gasPrice !== 'undefined')
rpcRequest.gasPrice = numberToHex(request.gasPrice)
if (typeof request.maxFeePerBlobGas !== 'undefined')
rpcRequest.maxFeePerBlobGas = numberToHex(request.maxFeePerBlobGas)
if (typeof request.maxFeePerGas !== 'undefined')
rpcRequest.maxFeePerGas = numberToHex(request.maxFeePerGas)
if (typeof request.maxPriorityFeePerGas !== 'undefined')
rpcRequest.maxPriorityFeePerGas = numberToHex(request.maxPriorityFeePerGas)
if (typeof request.nonce !== 'undefined')
rpcRequest.nonce = numberToHex(request.nonce)
if (typeof request.to !== 'undefined') rpcRequest.to = request.to
if (typeof request.type !== 'undefined')
rpcRequest.type = rpcTransactionType[request.type]
if (typeof request.value !== 'undefined')
rpcRequest.value = numberToHex(request.value)
return rpcRequest
}
export type DefineTransactionRequestErrorType =
| DefineFormatterErrorType
| ErrorType
export const defineTransactionRequest = /*#__PURE__*/ defineFormatter(
'transactionRequest',
formatTransactionRequest,
)
//////////////////////////////////////////////////////////////////////////////
function formatAuthorizationList(
authorizationList: AuthorizationList<number, boolean>,
): RpcAuthorizationList {
return authorizationList.map(
(authorization) =>
({
address: authorization.address,
r: authorization.r
? numberToHex(BigInt(authorization.r))
: authorization.r,
s: authorization.s
? numberToHex(BigInt(authorization.s))
: authorization.s,
chainId: numberToHex(authorization.chainId),
nonce: numberToHex(authorization.nonce),
...(typeof authorization.yParity !== 'undefined'
? { yParity: numberToHex(authorization.yParity) }
: {}),
...(typeof authorization.v !== 'undefined' &&
typeof authorization.yParity === 'undefined'
? { v: numberToHex(authorization.v) }
: {}),
}) as any,
) as RpcAuthorizationList
}