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

81
node_modules/viem/utils/address/getAddress.ts generated vendored Normal file
View File

@@ -0,0 +1,81 @@
import type { Address } from 'abitype'
import { InvalidAddressError } from '../../errors/address.js'
import type { ErrorType } from '../../errors/utils.js'
import {
type StringToBytesErrorType,
stringToBytes,
} from '../encoding/toBytes.js'
import { type Keccak256ErrorType, keccak256 } from '../hash/keccak256.js'
import { LruMap } from '../lru.js'
import { type IsAddressErrorType, isAddress } from './isAddress.js'
const checksumAddressCache = /*#__PURE__*/ new LruMap<Address>(8192)
export type ChecksumAddressErrorType =
| Keccak256ErrorType
| StringToBytesErrorType
| ErrorType
export function checksumAddress(
address_: Address,
/**
* Warning: EIP-1191 checksum addresses are generally not backwards compatible with the
* wider Ethereum ecosystem, meaning it will break when validated against an application/tool
* that relies on EIP-55 checksum encoding (checksum without chainId).
*
* It is highly recommended to not use this feature unless you
* know what you are doing.
*
* See more: https://github.com/ethereum/EIPs/issues/1121
*/
chainId?: number | undefined,
): Address {
if (checksumAddressCache.has(`${address_}.${chainId}`))
return checksumAddressCache.get(`${address_}.${chainId}`)!
const hexAddress = chainId
? `${chainId}${address_.toLowerCase()}`
: address_.substring(2).toLowerCase()
const hash = keccak256(stringToBytes(hexAddress), 'bytes')
const address = (
chainId ? hexAddress.substring(`${chainId}0x`.length) : hexAddress
).split('')
for (let i = 0; i < 40; i += 2) {
if (hash[i >> 1] >> 4 >= 8 && address[i]) {
address[i] = address[i].toUpperCase()
}
if ((hash[i >> 1] & 0x0f) >= 8 && address[i + 1]) {
address[i + 1] = address[i + 1].toUpperCase()
}
}
const result = `0x${address.join('')}` as const
checksumAddressCache.set(`${address_}.${chainId}`, result)
return result
}
export type GetAddressErrorType =
| ChecksumAddressErrorType
| IsAddressErrorType
| ErrorType
export function getAddress(
address: string,
/**
* Warning: EIP-1191 checksum addresses are generally not backwards compatible with the
* wider Ethereum ecosystem, meaning it will break when validated against an application/tool
* that relies on EIP-55 checksum encoding (checksum without chainId).
*
* It is highly recommended to not use this feature unless you
* know what you are doing.
*
* See more: https://github.com/ethereum/EIPs/issues/1121
*/
chainId?: number,
): Address {
if (!isAddress(address, { strict: false }))
throw new InvalidAddressError({ address })
return checksumAddress(address, chainId)
}

87
node_modules/viem/utils/address/getContractAddress.ts generated vendored Normal file
View File

@@ -0,0 +1,87 @@
import type { Address } from 'abitype'
import type { ErrorType } from '../../errors/utils.js'
import type { ByteArray, Hex } from '../../types/misc.js'
import { type ConcatErrorType, concat } from '../data/concat.js'
import { type IsBytesErrorType, isBytes } from '../data/isBytes.js'
import { type PadErrorType, pad } from '../data/pad.js'
import { type SliceErrorType, slice } from '../data/slice.js'
import { type ToBytesErrorType, toBytes } from '../encoding/toBytes.js'
import { type ToRlpErrorType, toRlp } from '../encoding/toRlp.js'
import { type Keccak256ErrorType, keccak256 } from '../hash/keccak256.js'
import { type GetAddressErrorType, getAddress } from './getAddress.js'
export type GetCreateAddressOptions = {
from: Address
nonce: bigint
}
export type GetCreate2AddressOptions =
| {
bytecode: ByteArray | Hex
from: Address
salt: ByteArray | Hex
}
| {
bytecodeHash: ByteArray | Hex
from: Address
salt: ByteArray | Hex
}
export type GetContractAddressOptions =
| ({
opcode?: 'CREATE' | undefined
} & GetCreateAddressOptions)
| ({ opcode: 'CREATE2' } & GetCreate2AddressOptions)
export function getContractAddress(opts: GetContractAddressOptions) {
if (opts.opcode === 'CREATE2') return getCreate2Address(opts)
return getCreateAddress(opts)
}
export type GetCreateAddressErrorType =
| Keccak256ErrorType
| GetAddressErrorType
| ToBytesErrorType
| ToRlpErrorType
| ErrorType
export function getCreateAddress(opts: GetCreateAddressOptions) {
const from = toBytes(getAddress(opts.from))
let nonce = toBytes(opts.nonce)
if (nonce[0] === 0) nonce = new Uint8Array([])
return getAddress(
`0x${keccak256(toRlp([from, nonce], 'bytes')).slice(26)}` as Address,
)
}
export type GetCreate2AddressErrorType =
| ConcatErrorType
| Keccak256ErrorType
| GetAddressErrorType
| IsBytesErrorType
| PadErrorType
| SliceErrorType
| ToBytesErrorType
| ToRlpErrorType
| ErrorType
export function getCreate2Address(opts: GetCreate2AddressOptions) {
const from = toBytes(getAddress(opts.from))
const salt = pad(isBytes(opts.salt) ? opts.salt : toBytes(opts.salt), {
size: 32,
})
const bytecodeHash = (() => {
if ('bytecodeHash' in opts) {
if (isBytes(opts.bytecodeHash)) return opts.bytecodeHash
return toBytes(opts.bytecodeHash)
}
return keccak256(opts.bytecode, 'bytes')
})()
return getAddress(
slice(keccak256(concat([toBytes('0xff'), from, salt, bytecodeHash])), 12),
)
}

39
node_modules/viem/utils/address/isAddress.ts generated vendored Normal file
View File

@@ -0,0 +1,39 @@
import type { Address } from 'abitype'
import type { ErrorType } from '../../errors/utils.js'
import { LruMap } from '../lru.js'
import { checksumAddress } from './getAddress.js'
const addressRegex = /^0x[a-fA-F0-9]{40}$/
/** @internal */
export const isAddressCache = /*#__PURE__*/ new LruMap<boolean>(8192)
export type IsAddressOptions = {
/**
* Enables strict mode. Whether or not to compare the address against its checksum.
*
* @default true
*/
strict?: boolean | undefined
}
export type IsAddressErrorType = ErrorType
export function isAddress(
address: string,
options?: IsAddressOptions | undefined,
): address is Address {
const { strict = true } = options ?? {}
const cacheKey = `${address}.${strict}`
if (isAddressCache.has(cacheKey)) return isAddressCache.get(cacheKey)!
const result = (() => {
if (!addressRegex.test(address)) return false
if (address.toLowerCase() === address) return true
if (strict) return checksumAddress(address as Address) === address
return true
})()
isAddressCache.set(cacheKey, result)
return result
}

19
node_modules/viem/utils/address/isAddressEqual.ts generated vendored Normal file
View File

@@ -0,0 +1,19 @@
import type { Address } from 'abitype'
import {
InvalidAddressError,
type InvalidAddressErrorType,
} from '../../errors/address.js'
import type { ErrorType } from '../../errors/utils.js'
import { isAddress } from './isAddress.js'
export type IsAddressEqualReturnType = boolean
export type IsAddressEqualErrorType = InvalidAddressErrorType | ErrorType
export function isAddressEqual(a: Address, b: Address) {
if (!isAddress(a, { strict: false }))
throw new InvalidAddressError({ address: a })
if (!isAddress(b, { strict: false }))
throw new InvalidAddressError({ address: b })
return a.toLowerCase() === b.toLowerCase()
}