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

185
node_modules/viem/actions/ens/getEnsAddress.ts generated vendored Normal file
View File

@@ -0,0 +1,185 @@
import type { Address } from 'abitype'
import type { Client } from '../../clients/createClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import {
addressResolverAbi,
universalResolverResolveAbi,
} from '../../constants/abis.js'
import type { ErrorType } from '../../errors/utils.js'
import type { Chain } from '../../types/chain.js'
import type { Prettify } from '../../types/utils.js'
import {
type DecodeFunctionResultErrorType,
decodeFunctionResult,
} from '../../utils/abi/decodeFunctionResult.js'
import {
type EncodeFunctionDataErrorType,
encodeFunctionData,
} from '../../utils/abi/encodeFunctionData.js'
import {
type GetChainContractAddressErrorType,
getChainContractAddress,
} from '../../utils/chain/getChainContractAddress.js'
import { type TrimErrorType, trim } from '../../utils/data/trim.js'
import { type ToHexErrorType, toHex } from '../../utils/encoding/toHex.js'
import { isNullUniversalResolverError } from '../../utils/ens/errors.js'
import { localBatchGatewayUrl } from '../../utils/ens/localBatchGatewayRequest.js'
import { type NamehashErrorType, namehash } from '../../utils/ens/namehash.js'
import {
type PacketToBytesErrorType,
packetToBytes,
} from '../../utils/ens/packetToBytes.js'
import { getAction } from '../../utils/getAction.js'
import {
type ReadContractParameters,
readContract,
} from '../public/readContract.js'
export type GetEnsAddressParameters = Prettify<
Pick<ReadContractParameters, 'blockNumber' | 'blockTag'> & {
/**
* ENSIP-9 compliant coinType (chain) to get ENS address for.
*
* To get the `coinType` for a chain id, use the `toCoinType` function:
* ```ts
* import { toCoinType } from 'viem'
* import { base } from 'viem/chains'
*
* const coinType = toCoinType(base.id)
* ```
*
* @default 60n
*/
coinType?: bigint | undefined
/**
* Universal Resolver gateway URLs to use for resolving CCIP-read requests.
*/
gatewayUrls?: string[] | undefined
/**
* Name to get the address for.
*/
name: string
/**
* Whether or not to throw errors propagated from the ENS Universal Resolver Contract.
*/
strict?: boolean | undefined
/**
* Address of ENS Universal Resolver Contract.
*/
universalResolverAddress?: Address | undefined
}
>
export type GetEnsAddressReturnType = Address | null
export type GetEnsAddressErrorType =
| GetChainContractAddressErrorType
| EncodeFunctionDataErrorType
| NamehashErrorType
| ToHexErrorType
| PacketToBytesErrorType
| DecodeFunctionResultErrorType
| TrimErrorType
| ErrorType
/**
* Gets address for ENS name.
*
* - Docs: https://viem.sh/docs/ens/actions/getEnsAddress
* - Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/ens
*
* Calls `resolve(bytes, bytes)` on ENS Universal Resolver Contract.
*
* Since ENS names prohibit certain forbidden characters (e.g. underscore) and have other validation rules, you likely want to [normalize ENS names](https://docs.ens.domains/contract-api-reference/name-processing#normalising-names) with [UTS-46 normalization](https://unicode.org/reports/tr46) before passing them to `getEnsAddress`. You can use the built-in [`normalize`](https://viem.sh/docs/ens/utilities/normalize) function for this.
*
* @param client - Client to use
* @param parameters - {@link GetEnsAddressParameters}
* @returns Address for ENS name or `null` if not found. {@link GetEnsAddressReturnType}
*
* @example
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { getEnsAddress, normalize } from 'viem/ens'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const ensAddress = await getEnsAddress(client, {
* name: normalize('wevm.eth'),
* })
* // '0xd2135CfB216b74109775236E36d4b433F1DF507B'
*/
export async function getEnsAddress<chain extends Chain | undefined>(
client: Client<Transport, chain>,
parameters: GetEnsAddressParameters,
): Promise<GetEnsAddressReturnType> {
const { blockNumber, blockTag, coinType, name, gatewayUrls, strict } =
parameters
const { chain } = client
const universalResolverAddress = (() => {
if (parameters.universalResolverAddress)
return parameters.universalResolverAddress
if (!chain)
throw new Error(
'client chain not configured. universalResolverAddress is required.',
)
return getChainContractAddress({
blockNumber,
chain,
contract: 'ensUniversalResolver',
})
})()
const tlds = chain?.ensTlds
if (tlds && !tlds.some((tld) => name.endsWith(tld))) return null
const args = (() => {
if (coinType != null) return [namehash(name), BigInt(coinType)] as const
return [namehash(name)] as const
})()
try {
const functionData = encodeFunctionData({
abi: addressResolverAbi,
functionName: 'addr',
args,
})
const readContractParameters = {
address: universalResolverAddress,
abi: universalResolverResolveAbi,
functionName: 'resolveWithGateways',
args: [
toHex(packetToBytes(name)),
functionData,
gatewayUrls ?? [localBatchGatewayUrl],
],
blockNumber,
blockTag,
} as const
const readContractAction = getAction(client, readContract, 'readContract')
const res = await readContractAction(readContractParameters)
if (res[0] === '0x') return null
const address = decodeFunctionResult({
abi: addressResolverAbi,
args,
functionName: 'addr',
data: res[0],
})
if (address === '0x') return null
if (trim(address) === '0x00') return null
return address
} catch (err) {
if (strict) throw err
if (isNullUniversalResolverError(err)) return null
throw err
}
}

95
node_modules/viem/actions/ens/getEnsAvatar.ts generated vendored Normal file
View File

@@ -0,0 +1,95 @@
import type { Client } from '../../clients/createClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import type { ErrorType } from '../../errors/utils.js'
import type { Chain } from '../../types/chain.js'
import type { AssetGatewayUrls } from '../../types/ens.js'
import type { Prettify } from '../../types/utils.js'
import {
type ParseAvatarRecordErrorType,
parseAvatarRecord,
} from '../../utils/ens/avatar/parseAvatarRecord.js'
import { getAction } from '../../utils/getAction.js'
import {
type GetEnsTextErrorType,
type GetEnsTextParameters,
getEnsText,
} from './getEnsText.js'
export type GetEnsAvatarParameters = Prettify<
Omit<GetEnsTextParameters, 'key'> & {
/** Gateway urls to resolve IPFS and/or Arweave assets. */
assetGatewayUrls?: AssetGatewayUrls | undefined
}
>
export type GetEnsAvatarReturnType = string | null
export type GetEnsAvatarErrorType =
| GetEnsTextErrorType
| ParseAvatarRecordErrorType
| ErrorType
/**
* Gets the avatar of an ENS name.
*
* - Docs: https://viem.sh/docs/ens/actions/getEnsAvatar
* - Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/ens
*
* Calls [`getEnsText`](https://viem.sh/docs/ens/actions/getEnsText) with `key` set to `'avatar'`.
*
* Since ENS names prohibit certain forbidden characters (e.g. underscore) and have other validation rules, you likely want to [normalize ENS names](https://docs.ens.domains/contract-api-reference/name-processing#normalising-names) with [UTS-46 normalization](https://unicode.org/reports/tr46) before passing them to `getEnsAddress`. You can use the built-in [`normalize`](https://viem.sh/docs/ens/utilities/normalize) function for this.
*
* @param client - Client to use
* @param parameters - {@link GetEnsAvatarParameters}
* @returns Avatar URI or `null` if not found. {@link GetEnsAvatarReturnType}
*
* @example
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { getEnsAvatar, normalize } from 'viem/ens'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const ensAvatar = await getEnsAvatar(client, {
* name: normalize('wevm.eth'),
* })
* // 'https://ipfs.io/ipfs/Qma8mnp6xV3J2cRNf3mTth5C8nV11CAnceVinc3y8jSbio'
*/
export async function getEnsAvatar<chain extends Chain | undefined>(
client: Client<Transport, chain>,
{
blockNumber,
blockTag,
assetGatewayUrls,
name,
gatewayUrls,
strict,
universalResolverAddress,
}: GetEnsAvatarParameters,
): Promise<GetEnsAvatarReturnType> {
const record = await getAction(
client,
getEnsText,
'getEnsText',
)({
blockNumber,
blockTag,
key: 'avatar',
name,
universalResolverAddress,
gatewayUrls,
strict,
})
if (!record) return null
try {
return await parseAvatarRecord(client, {
record,
gatewayUrls: assetGatewayUrls,
})
} catch {
return null
}
}

140
node_modules/viem/actions/ens/getEnsName.ts generated vendored Normal file
View File

@@ -0,0 +1,140 @@
import type { Address } from 'abitype'
import type { Client } from '../../clients/createClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import { universalResolverReverseAbi } from '../../constants/abis.js'
import type { ErrorType } from '../../errors/utils.js'
import type { Chain } from '../../types/chain.js'
import type { Prettify } from '../../types/utils.js'
import {
type GetChainContractAddressErrorType,
getChainContractAddress,
} from '../../utils/chain/getChainContractAddress.js'
import { isNullUniversalResolverError } from '../../utils/ens/errors.js'
import { localBatchGatewayUrl } from '../../utils/ens/localBatchGatewayRequest.js'
import type { PacketToBytesErrorType } from '../../utils/ens/packetToBytes.js'
import { getAction } from '../../utils/getAction.js'
import {
type ReadContractErrorType,
type ReadContractParameters,
readContract,
} from '../public/readContract.js'
export type GetEnsNameParameters = Prettify<
Pick<ReadContractParameters, 'blockNumber' | 'blockTag'> & {
/**
* Address to get ENS name for.
*/
address: Address
/**
* ENSIP-9 compliant coinType (chain) to get ENS name for.
*
* To get the `coinType` for a chain id, use the `toCoinType` function:
* ```ts
* import { toCoinType } from 'viem'
* import { base } from 'viem/chains'
*
* const coinType = toCoinType(base.id)
* ```
*
* @default 60n
*/
coinType?: bigint | undefined
/**
* Universal Resolver gateway URLs to use for resolving CCIP-read requests.
*/
gatewayUrls?: string[] | undefined
/**
* Whether or not to throw errors propagated from the ENS Universal Resolver Contract.
*/
strict?: boolean | undefined
/**
* Address of ENS Universal Resolver Contract.
*/
universalResolverAddress?: Address | undefined
}
>
export type GetEnsNameReturnType = string | null
export type GetEnsNameErrorType =
| GetChainContractAddressErrorType
| ReadContractErrorType
| PacketToBytesErrorType
| ErrorType
/**
* Gets primary name for specified address.
*
* - Docs: https://viem.sh/docs/ens/actions/getEnsName
* - Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/ens
*
* Calls `reverse(bytes)` on ENS Universal Resolver Contract to "reverse resolve" the address to the primary ENS name.
*
* @param client - Client to use
* @param parameters - {@link GetEnsNameParameters}
* @returns Name or `null` if not found. {@link GetEnsNameReturnType}
*
* @example
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { getEnsName } from 'viem/ens'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const ensName = await getEnsName(client, {
* address: '0xd2135CfB216b74109775236E36d4b433F1DF507B',
* })
* // 'wevm.eth'
*/
export async function getEnsName<chain extends Chain | undefined>(
client: Client<Transport, chain>,
parameters: GetEnsNameParameters,
): Promise<GetEnsNameReturnType> {
const {
address,
blockNumber,
blockTag,
coinType = 60n,
gatewayUrls,
strict,
} = parameters
const { chain } = client
const universalResolverAddress = (() => {
if (parameters.universalResolverAddress)
return parameters.universalResolverAddress
if (!chain)
throw new Error(
'client chain not configured. universalResolverAddress is required.',
)
return getChainContractAddress({
blockNumber,
chain,
contract: 'ensUniversalResolver',
})
})()
try {
const readContractParameters = {
address: universalResolverAddress,
abi: universalResolverReverseAbi,
args: [address, coinType, gatewayUrls ?? [localBatchGatewayUrl]],
functionName: 'reverseWithGateways',
blockNumber,
blockTag,
} as const
const readContractAction = getAction(client, readContract, 'readContract')
const [name] = await readContractAction(readContractParameters)
return name || null
} catch (err) {
if (strict) throw err
if (isNullUniversalResolverError(err)) return null
throw err
}
}

120
node_modules/viem/actions/ens/getEnsResolver.ts generated vendored Normal file
View File

@@ -0,0 +1,120 @@
import type { Address } from 'abitype'
import type { Client } from '../../clients/createClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import type { ErrorType } from '../../errors/utils.js'
import type { Chain } from '../../types/chain.js'
import type { Prettify } from '../../types/utils.js'
import {
type GetChainContractAddressErrorType,
getChainContractAddress,
} from '../../utils/chain/getChainContractAddress.js'
import { type ToHexErrorType, toHex } from '../../utils/encoding/toHex.js'
import {
type PacketToBytesErrorType,
packetToBytes,
} from '../../utils/ens/packetToBytes.js'
import { getAction } from '../../utils/getAction.js'
import {
type ReadContractParameters,
readContract,
} from '../public/readContract.js'
export type GetEnsResolverParameters = Prettify<
Pick<ReadContractParameters, 'blockNumber' | 'blockTag'> & {
/** Name to get the address for. */
name: string
/** Address of ENS Universal Resolver Contract. */
universalResolverAddress?: Address | undefined
}
>
export type GetEnsResolverReturnType = Address
export type GetEnsResolverErrorType =
| GetChainContractAddressErrorType
| ToHexErrorType
| PacketToBytesErrorType
| ErrorType
/**
* Gets resolver for ENS name.
*
* - Docs: https://viem.sh/docs/ens/actions/getEnsResolver
* - Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/ens
*
* Calls `findResolver(bytes)` on ENS Universal Resolver Contract to retrieve the resolver of an ENS name.
*
* Since ENS names prohibit certain forbidden characters (e.g. underscore) and have other validation rules, you likely want to [normalize ENS names](https://docs.ens.domains/contract-api-reference/name-processing#normalising-names) with [UTS-46 normalization](https://unicode.org/reports/tr46) before passing them to `getEnsAddress`. You can use the built-in [`normalize`](https://viem.sh/docs/ens/utilities/normalize) function for this.
*
* @param client - Client to use
* @param parameters - {@link GetEnsResolverParameters}
* @returns Address for ENS resolver. {@link GetEnsResolverReturnType}
*
* @example
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { getEnsResolver, normalize } from 'viem/ens'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const resolverAddress = await getEnsResolver(client, {
* name: normalize('wevm.eth'),
* })
* // '0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41'
*/
export async function getEnsResolver<chain extends Chain | undefined>(
client: Client<Transport, chain>,
parameters: GetEnsResolverParameters,
): Promise<GetEnsResolverReturnType> {
const { blockNumber, blockTag, name } = parameters
const { chain } = client
const universalResolverAddress = (() => {
if (parameters.universalResolverAddress)
return parameters.universalResolverAddress
if (!chain)
throw new Error(
'client chain not configured. universalResolverAddress is required.',
)
return getChainContractAddress({
blockNumber,
chain,
contract: 'ensUniversalResolver',
})
})()
const tlds = chain?.ensTlds
if (tlds && !tlds.some((tld) => name.endsWith(tld)))
throw new Error(
`${name} is not a valid ENS TLD (${tlds?.join(', ')}) for chain "${chain.name}" (id: ${chain.id}).`,
)
const [resolverAddress] = await getAction(
client,
readContract,
'readContract',
)({
address: universalResolverAddress,
abi: [
{
inputs: [{ type: 'bytes' }],
name: 'findResolver',
outputs: [
{ type: 'address' },
{ type: 'bytes32' },
{ type: 'uint256' },
],
stateMutability: 'view',
type: 'function',
},
],
functionName: 'findResolver',
args: [toHex(packetToBytes(name))],
blockNumber,
blockTag,
})
return resolverAddress
}

153
node_modules/viem/actions/ens/getEnsText.ts generated vendored Normal file
View File

@@ -0,0 +1,153 @@
import type { Address } from 'abitype'
import type { Client } from '../../clients/createClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import {
textResolverAbi,
universalResolverResolveAbi,
} from '../../constants/abis.js'
import type { Chain } from '../../types/chain.js'
import type { Prettify } from '../../types/utils.js'
import {
type DecodeFunctionResultErrorType,
decodeFunctionResult,
} from '../../utils/abi/decodeFunctionResult.js'
import {
type EncodeFunctionDataErrorType,
encodeFunctionData,
} from '../../utils/abi/encodeFunctionData.js'
import {
type GetChainContractAddressErrorType,
getChainContractAddress,
} from '../../utils/chain/getChainContractAddress.js'
import { type ToHexErrorType, toHex } from '../../utils/encoding/toHex.js'
import { isNullUniversalResolverError } from '../../utils/ens/errors.js'
import { localBatchGatewayUrl } from '../../utils/ens/localBatchGatewayRequest.js'
import { type NamehashErrorType, namehash } from '../../utils/ens/namehash.js'
import {
type PacketToBytesErrorType,
packetToBytes,
} from '../../utils/ens/packetToBytes.js'
import { getAction } from '../../utils/getAction.js'
import {
type ReadContractErrorType,
type ReadContractParameters,
readContract,
} from '../public/readContract.js'
export type GetEnsTextParameters = Prettify<
Pick<ReadContractParameters, 'blockNumber' | 'blockTag'> & {
/** ENS name to get Text for. */
name: string
/** Universal Resolver gateway URLs to use for resolving CCIP-read requests. */
gatewayUrls?: string[] | undefined
/** Text record to retrieve. */
key: string
/** Whether or not to throw errors propagated from the ENS Universal Resolver Contract. */
strict?: boolean | undefined
/** Address of ENS Universal Resolver Contract. */
universalResolverAddress?: Address | undefined
}
>
export type GetEnsTextReturnType = string | null
export type GetEnsTextErrorType =
| GetChainContractAddressErrorType
| ReadContractErrorType
| ToHexErrorType
| PacketToBytesErrorType
| EncodeFunctionDataErrorType
| NamehashErrorType
| DecodeFunctionResultErrorType
/**
* Gets a text record for specified ENS name.
*
* - Docs: https://viem.sh/docs/ens/actions/getEnsResolver
* - Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/ens
*
* Calls `resolve(bytes, bytes)` on ENS Universal Resolver Contract.
*
* Since ENS names prohibit certain forbidden characters (e.g. underscore) and have other validation rules, you likely want to [normalize ENS names](https://docs.ens.domains/contract-api-reference/name-processing#normalising-names) with [UTS-46 normalization](https://unicode.org/reports/tr46) before passing them to `getEnsAddress`. You can use the built-in [`normalize`](https://viem.sh/docs/ens/utilities/normalize) function for this.
*
* @param client - Client to use
* @param parameters - {@link GetEnsTextParameters}
* @returns Address for ENS resolver. {@link GetEnsTextReturnType}
*
* @example
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { getEnsText, normalize } from 'viem/ens'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const twitterRecord = await getEnsText(client, {
* name: normalize('wevm.eth'),
* key: 'com.twitter',
* })
* // 'wevm_dev'
*/
export async function getEnsText<chain extends Chain | undefined>(
client: Client<Transport, chain>,
parameters: GetEnsTextParameters,
): Promise<GetEnsTextReturnType> {
const { blockNumber, blockTag, key, name, gatewayUrls, strict } = parameters
const { chain } = client
const universalResolverAddress = (() => {
if (parameters.universalResolverAddress)
return parameters.universalResolverAddress
if (!chain)
throw new Error(
'client chain not configured. universalResolverAddress is required.',
)
return getChainContractAddress({
blockNumber,
chain,
contract: 'ensUniversalResolver',
})
})()
const tlds = chain?.ensTlds
if (tlds && !tlds.some((tld) => name.endsWith(tld))) return null
try {
const readContractParameters = {
address: universalResolverAddress,
abi: universalResolverResolveAbi,
args: [
toHex(packetToBytes(name)),
encodeFunctionData({
abi: textResolverAbi,
functionName: 'text',
args: [namehash(name), key],
}),
gatewayUrls ?? [localBatchGatewayUrl],
],
functionName: 'resolveWithGateways',
blockNumber,
blockTag,
} as const
const readContractAction = getAction(client, readContract, 'readContract')
const res = await readContractAction(readContractParameters)
if (res[0] === '0x') return null
const record = decodeFunctionResult({
abi: textResolverAbi,
functionName: 'text',
data: res[0],
})
return record === '' ? null : record
} catch (err) {
if (strict) throw err
if (isNullUniversalResolverError(err)) return null
throw err
}
}