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

518
node_modules/viem/errors/abi.ts generated vendored Normal file
View File

@@ -0,0 +1,518 @@
import type { Abi, AbiEvent, AbiParameter } from 'abitype'
import type { Hex } from '../types/misc.js'
import { formatAbiItem, formatAbiParams } from '../utils/abi/formatAbiItem.js'
import { size } from '../utils/data/size.js'
import { BaseError } from './base.js'
export type AbiConstructorNotFoundErrorType = AbiConstructorNotFoundError & {
name: 'AbiConstructorNotFoundError'
}
export class AbiConstructorNotFoundError extends BaseError {
constructor({ docsPath }: { docsPath: string }) {
super(
[
'A constructor was not found on the ABI.',
'Make sure you are using the correct ABI and that the constructor exists on it.',
].join('\n'),
{
docsPath,
name: 'AbiConstructorNotFoundError',
},
)
}
}
export type AbiConstructorParamsNotFoundErrorType =
AbiConstructorParamsNotFoundError & {
name: 'AbiConstructorParamsNotFoundError'
}
export class AbiConstructorParamsNotFoundError extends BaseError {
constructor({ docsPath }: { docsPath: string }) {
super(
[
'Constructor arguments were provided (`args`), but a constructor parameters (`inputs`) were not found on the ABI.',
'Make sure you are using the correct ABI, and that the `inputs` attribute on the constructor exists.',
].join('\n'),
{
docsPath,
name: 'AbiConstructorParamsNotFoundError',
},
)
}
}
export type AbiDecodingDataSizeInvalidErrorType =
AbiDecodingDataSizeInvalidError & {
name: 'AbiDecodingDataSizeInvalidError'
}
export class AbiDecodingDataSizeInvalidError extends BaseError {
constructor({ data, size }: { data: Hex; size: number }) {
super(
[
`Data size of ${size} bytes is invalid.`,
'Size must be in increments of 32 bytes (size % 32 === 0).',
].join('\n'),
{
metaMessages: [`Data: ${data} (${size} bytes)`],
name: 'AbiDecodingDataSizeInvalidError',
},
)
}
}
export type AbiDecodingDataSizeTooSmallErrorType =
AbiDecodingDataSizeTooSmallError & {
name: 'AbiDecodingDataSizeTooSmallError'
}
export class AbiDecodingDataSizeTooSmallError extends BaseError {
data: Hex
params: readonly AbiParameter[]
size: number
constructor({
data,
params,
size,
}: { data: Hex; params: readonly AbiParameter[]; size: number }) {
super(
[`Data size of ${size} bytes is too small for given parameters.`].join(
'\n',
),
{
metaMessages: [
`Params: (${formatAbiParams(params, { includeName: true })})`,
`Data: ${data} (${size} bytes)`,
],
name: 'AbiDecodingDataSizeTooSmallError',
},
)
this.data = data
this.params = params
this.size = size
}
}
export type AbiDecodingZeroDataErrorType = AbiDecodingZeroDataError & {
name: 'AbiDecodingZeroDataError'
}
export class AbiDecodingZeroDataError extends BaseError {
constructor({ cause }: { cause?: BaseError | Error | undefined } = {}) {
super('Cannot decode zero data ("0x") with ABI parameters.', {
name: 'AbiDecodingZeroDataError',
cause,
})
}
}
export type AbiEncodingArrayLengthMismatchErrorType =
AbiEncodingArrayLengthMismatchError & {
name: 'AbiEncodingArrayLengthMismatchError'
}
export class AbiEncodingArrayLengthMismatchError extends BaseError {
constructor({
expectedLength,
givenLength,
type,
}: { expectedLength: number; givenLength: number; type: string }) {
super(
[
`ABI encoding array length mismatch for type ${type}.`,
`Expected length: ${expectedLength}`,
`Given length: ${givenLength}`,
].join('\n'),
{ name: 'AbiEncodingArrayLengthMismatchError' },
)
}
}
export type AbiEncodingBytesSizeMismatchErrorType =
AbiEncodingBytesSizeMismatchError & {
name: 'AbiEncodingBytesSizeMismatchError'
}
export class AbiEncodingBytesSizeMismatchError extends BaseError {
constructor({ expectedSize, value }: { expectedSize: number; value: Hex }) {
super(
`Size of bytes "${value}" (bytes${size(
value,
)}) does not match expected size (bytes${expectedSize}).`,
{ name: 'AbiEncodingBytesSizeMismatchError' },
)
}
}
export type AbiEncodingLengthMismatchErrorType =
AbiEncodingLengthMismatchError & {
name: 'AbiEncodingLengthMismatchError'
}
export class AbiEncodingLengthMismatchError extends BaseError {
constructor({
expectedLength,
givenLength,
}: { expectedLength: number; givenLength: number }) {
super(
[
'ABI encoding params/values length mismatch.',
`Expected length (params): ${expectedLength}`,
`Given length (values): ${givenLength}`,
].join('\n'),
{ name: 'AbiEncodingLengthMismatchError' },
)
}
}
export type AbiErrorInputsNotFoundErrorType = AbiErrorInputsNotFoundError & {
name: 'AbiErrorInputsNotFoundError'
}
export class AbiErrorInputsNotFoundError extends BaseError {
constructor(errorName: string, { docsPath }: { docsPath: string }) {
super(
[
`Arguments (\`args\`) were provided to "${errorName}", but "${errorName}" on the ABI does not contain any parameters (\`inputs\`).`,
'Cannot encode error result without knowing what the parameter types are.',
'Make sure you are using the correct ABI and that the inputs exist on it.',
].join('\n'),
{
docsPath,
name: 'AbiErrorInputsNotFoundError',
},
)
}
}
export type AbiErrorNotFoundErrorType = AbiErrorNotFoundError & {
name: 'AbiErrorNotFoundError'
}
export class AbiErrorNotFoundError extends BaseError {
constructor(
errorName?: string | undefined,
{ docsPath }: { docsPath?: string | undefined } = {},
) {
super(
[
`Error ${errorName ? `"${errorName}" ` : ''}not found on ABI.`,
'Make sure you are using the correct ABI and that the error exists on it.',
].join('\n'),
{
docsPath,
name: 'AbiErrorNotFoundError',
},
)
}
}
export type AbiErrorSignatureNotFoundErrorType =
AbiErrorSignatureNotFoundError & {
name: 'AbiErrorSignatureNotFoundError'
}
export class AbiErrorSignatureNotFoundError extends BaseError {
signature: Hex
constructor(
signature: Hex,
{
docsPath,
cause,
}: { docsPath: string; cause?: BaseError | Error | undefined },
) {
super(
[
`Encoded error signature "${signature}" not found on ABI.`,
'Make sure you are using the correct ABI and that the error exists on it.',
`You can look up the decoded signature here: https://4byte.sourcify.dev/?q=${signature}.`,
].join('\n'),
{
docsPath,
name: 'AbiErrorSignatureNotFoundError',
cause,
},
)
this.signature = signature
}
}
export type AbiEventSignatureEmptyTopicsErrorType =
AbiEventSignatureEmptyTopicsError & {
name: 'AbiEventSignatureEmptyTopicsError'
}
export class AbiEventSignatureEmptyTopicsError extends BaseError {
constructor({ docsPath }: { docsPath: string }) {
super('Cannot extract event signature from empty topics.', {
docsPath,
name: 'AbiEventSignatureEmptyTopicsError',
})
}
}
export type AbiEventSignatureNotFoundErrorType =
AbiEventSignatureNotFoundError & {
name: 'AbiEventSignatureNotFoundError'
}
export class AbiEventSignatureNotFoundError extends BaseError {
constructor(signature: Hex, { docsPath }: { docsPath: string }) {
super(
[
`Encoded event signature "${signature}" not found on ABI.`,
'Make sure you are using the correct ABI and that the event exists on it.',
`You can look up the signature here: https://4byte.sourcify.dev/?q=${signature}.`,
].join('\n'),
{
docsPath,
name: 'AbiEventSignatureNotFoundError',
},
)
}
}
export type AbiEventNotFoundErrorType = AbiEventNotFoundError & {
name: 'AbiEventNotFoundError'
}
export class AbiEventNotFoundError extends BaseError {
constructor(
eventName?: string | undefined,
{ docsPath }: { docsPath?: string | undefined } = {},
) {
super(
[
`Event ${eventName ? `"${eventName}" ` : ''}not found on ABI.`,
'Make sure you are using the correct ABI and that the event exists on it.',
].join('\n'),
{
docsPath,
name: 'AbiEventNotFoundError',
},
)
}
}
export type AbiFunctionNotFoundErrorType = AbiFunctionNotFoundError & {
name: 'AbiFunctionNotFoundError'
}
export class AbiFunctionNotFoundError extends BaseError {
constructor(
functionName?: string | undefined,
{ docsPath }: { docsPath?: string | undefined } = {},
) {
super(
[
`Function ${functionName ? `"${functionName}" ` : ''}not found on ABI.`,
'Make sure you are using the correct ABI and that the function exists on it.',
].join('\n'),
{
docsPath,
name: 'AbiFunctionNotFoundError',
},
)
}
}
export type AbiFunctionOutputsNotFoundErrorType =
AbiFunctionOutputsNotFoundError & {
name: 'AbiFunctionOutputsNotFoundError'
}
export class AbiFunctionOutputsNotFoundError extends BaseError {
constructor(functionName: string, { docsPath }: { docsPath: string }) {
super(
[
`Function "${functionName}" does not contain any \`outputs\` on ABI.`,
'Cannot decode function result without knowing what the parameter types are.',
'Make sure you are using the correct ABI and that the function exists on it.',
].join('\n'),
{
docsPath,
name: 'AbiFunctionOutputsNotFoundError',
},
)
}
}
export type AbiFunctionSignatureNotFoundErrorType =
AbiFunctionSignatureNotFoundError & {
name: 'AbiFunctionSignatureNotFoundError'
}
export class AbiFunctionSignatureNotFoundError extends BaseError {
constructor(signature: Hex, { docsPath }: { docsPath: string }) {
super(
[
`Encoded function signature "${signature}" not found on ABI.`,
'Make sure you are using the correct ABI and that the function exists on it.',
`You can look up the signature here: https://4byte.sourcify.dev/?q=${signature}.`,
].join('\n'),
{
docsPath,
name: 'AbiFunctionSignatureNotFoundError',
},
)
}
}
export type AbiItemAmbiguityErrorType = AbiItemAmbiguityError & {
name: 'AbiItemAmbiguityError'
}
export class AbiItemAmbiguityError extends BaseError {
constructor(
x: { abiItem: Abi[number]; type: string },
y: { abiItem: Abi[number]; type: string },
) {
super('Found ambiguous types in overloaded ABI items.', {
metaMessages: [
`\`${x.type}\` in \`${formatAbiItem(x.abiItem)}\`, and`,
`\`${y.type}\` in \`${formatAbiItem(y.abiItem)}\``,
'',
'These types encode differently and cannot be distinguished at runtime.',
'Remove one of the ambiguous items in the ABI.',
],
name: 'AbiItemAmbiguityError',
})
}
}
export type BytesSizeMismatchErrorType = BytesSizeMismatchError & {
name: 'BytesSizeMismatchError'
}
export class BytesSizeMismatchError extends BaseError {
constructor({
expectedSize,
givenSize,
}: { expectedSize: number; givenSize: number }) {
super(`Expected bytes${expectedSize}, got bytes${givenSize}.`, {
name: 'BytesSizeMismatchError',
})
}
}
export type DecodeLogDataMismatchErrorType = DecodeLogDataMismatch & {
name: 'DecodeLogDataMismatch'
}
export class DecodeLogDataMismatch extends BaseError {
abiItem: AbiEvent
data: Hex
params: readonly AbiParameter[]
size: number
constructor({
abiItem,
data,
params,
size,
}: {
abiItem: AbiEvent
data: Hex
params: readonly AbiParameter[]
size: number
}) {
super(
[
`Data size of ${size} bytes is too small for non-indexed event parameters.`,
].join('\n'),
{
metaMessages: [
`Params: (${formatAbiParams(params, { includeName: true })})`,
`Data: ${data} (${size} bytes)`,
],
name: 'DecodeLogDataMismatch',
},
)
this.abiItem = abiItem
this.data = data
this.params = params
this.size = size
}
}
export type DecodeLogTopicsMismatchErrorType = DecodeLogTopicsMismatch & {
name: 'DecodeLogTopicsMismatch'
}
export class DecodeLogTopicsMismatch extends BaseError {
abiItem: AbiEvent
constructor({
abiItem,
param,
}: {
abiItem: AbiEvent
param: AbiParameter & { indexed: boolean }
}) {
super(
[
`Expected a topic for indexed event parameter${
param.name ? ` "${param.name}"` : ''
} on event "${formatAbiItem(abiItem, { includeName: true })}".`,
].join('\n'),
{ name: 'DecodeLogTopicsMismatch' },
)
this.abiItem = abiItem
}
}
export type InvalidAbiEncodingTypeErrorType = InvalidAbiEncodingTypeError & {
name: 'InvalidAbiEncodingTypeError'
}
export class InvalidAbiEncodingTypeError extends BaseError {
constructor(type: string, { docsPath }: { docsPath: string }) {
super(
[
`Type "${type}" is not a valid encoding type.`,
'Please provide a valid ABI type.',
].join('\n'),
{ docsPath, name: 'InvalidAbiEncodingType' },
)
}
}
export type InvalidAbiDecodingTypeErrorType = InvalidAbiDecodingTypeError & {
name: 'InvalidAbiDecodingTypeError'
}
export class InvalidAbiDecodingTypeError extends BaseError {
constructor(type: string, { docsPath }: { docsPath: string }) {
super(
[
`Type "${type}" is not a valid decoding type.`,
'Please provide a valid ABI type.',
].join('\n'),
{ docsPath, name: 'InvalidAbiDecodingType' },
)
}
}
export type InvalidArrayErrorType = InvalidArrayError & {
name: 'InvalidArrayError'
}
export class InvalidArrayError extends BaseError {
constructor(value: unknown) {
super([`Value "${value}" is not a valid array.`].join('\n'), {
name: 'InvalidArrayError',
})
}
}
export type InvalidDefinitionTypeErrorType = InvalidDefinitionTypeError & {
name: 'InvalidDefinitionTypeError'
}
export class InvalidDefinitionTypeError extends BaseError {
constructor(type: string) {
super(
[
`"${type}" is not a valid definition type.`,
'Valid types: "function", "event", "error"',
].join('\n'),
{ name: 'InvalidDefinitionTypeError' },
)
}
}
export type UnsupportedPackedAbiTypeErrorType = UnsupportedPackedAbiType & {
name: 'UnsupportedPackedAbiType'
}
export class UnsupportedPackedAbiType extends BaseError {
constructor(type: unknown) {
super(`Type "${type}" is not supported for packed encoding.`, {
name: 'UnsupportedPackedAbiType',
})
}
}

41
node_modules/viem/errors/account.ts generated vendored Normal file
View File

@@ -0,0 +1,41 @@
import { BaseError } from './base.js'
export type AccountNotFoundErrorType = AccountNotFoundError & {
name: 'AccountNotFoundError'
}
export class AccountNotFoundError extends BaseError {
constructor({ docsPath }: { docsPath?: string | undefined } = {}) {
super(
[
'Could not find an Account to execute with this Action.',
'Please provide an Account with the `account` argument on the Action, or by supplying an `account` to the Client.',
].join('\n'),
{
docsPath,
docsSlug: 'account',
name: 'AccountNotFoundError',
},
)
}
}
export type AccountTypeNotSupportedErrorType = AccountTypeNotSupportedError & {
name: 'AccountTypeNotSupportedError'
}
export class AccountTypeNotSupportedError extends BaseError {
constructor({
docsPath,
metaMessages,
type,
}: {
docsPath?: string | undefined
metaMessages?: string[] | undefined
type: string
}) {
super(`Account type "${type}" is not supported.`, {
docsPath,
metaMessages,
name: 'AccountTypeNotSupportedError',
})
}
}

16
node_modules/viem/errors/address.ts generated vendored Normal file
View File

@@ -0,0 +1,16 @@
import { BaseError } from './base.js'
export type InvalidAddressErrorType = InvalidAddressError & {
name: 'InvalidAddressError'
}
export class InvalidAddressError extends BaseError {
constructor({ address }: { address: string }) {
super(`Address "${address}" is invalid.`, {
metaMessages: [
'- Address must be a hex value of 20 bytes (40 hex characters).',
'- Address must match its checksum counterpart.',
],
name: 'InvalidAddressError',
})
}
}

98
node_modules/viem/errors/base.ts generated vendored Normal file
View File

@@ -0,0 +1,98 @@
import { version } from './version.js'
type ErrorConfig = {
getDocsUrl?: ((args: BaseErrorParameters) => string | undefined) | undefined
version?: string | undefined
}
let errorConfig: ErrorConfig = {
getDocsUrl: ({
docsBaseUrl,
docsPath = '',
docsSlug,
}: BaseErrorParameters) =>
docsPath
? `${docsBaseUrl ?? 'https://viem.sh'}${docsPath}${
docsSlug ? `#${docsSlug}` : ''
}`
: undefined,
version: `viem@${version}`,
}
export function setErrorConfig(config: ErrorConfig) {
errorConfig = config
}
type BaseErrorParameters = {
cause?: BaseError | Error | undefined
details?: string | undefined
docsBaseUrl?: string | undefined
docsPath?: string | undefined
docsSlug?: string | undefined
metaMessages?: string[] | undefined
name?: string | undefined
}
export type BaseErrorType = BaseError & { name: 'BaseError' }
export class BaseError extends Error {
details: string
docsPath?: string | undefined
metaMessages?: string[] | undefined
shortMessage: string
version: string
override name = 'BaseError'
constructor(shortMessage: string, args: BaseErrorParameters = {}) {
const details = (() => {
if (args.cause instanceof BaseError) return args.cause.details
if (args.cause?.message) return args.cause.message
return args.details!
})()
const docsPath = (() => {
if (args.cause instanceof BaseError)
return args.cause.docsPath || args.docsPath
return args.docsPath
})()
const docsUrl = errorConfig.getDocsUrl?.({ ...args, docsPath })
const message = [
shortMessage || 'An error occurred.',
'',
...(args.metaMessages ? [...args.metaMessages, ''] : []),
...(docsUrl ? [`Docs: ${docsUrl}`] : []),
...(details ? [`Details: ${details}`] : []),
...(errorConfig.version ? [`Version: ${errorConfig.version}`] : []),
].join('\n')
super(message, args.cause ? { cause: args.cause } : undefined)
this.details = details
this.docsPath = docsPath
this.metaMessages = args.metaMessages
this.name = args.name ?? this.name
this.shortMessage = shortMessage
this.version = version
}
walk(): Error
walk(fn: (err: unknown) => boolean): Error | null
walk(fn?: any): any {
return walk(this, fn)
}
}
function walk(
err: unknown,
fn?: ((err: unknown) => boolean) | undefined,
): unknown {
if (fn?.(err)) return err
if (
err &&
typeof err === 'object' &&
'cause' in err &&
err.cause !== undefined
)
return walk(err.cause, fn)
return fn ? null : err
}

66
node_modules/viem/errors/blob.ts generated vendored Normal file
View File

@@ -0,0 +1,66 @@
import { versionedHashVersionKzg } from '../constants/kzg.js'
import type { Hash } from '../types/misc.js'
import { BaseError } from './base.js'
export type BlobSizeTooLargeErrorType = BlobSizeTooLargeError & {
name: 'BlobSizeTooLargeError'
}
export class BlobSizeTooLargeError extends BaseError {
constructor({ maxSize, size }: { maxSize: number; size: number }) {
super('Blob size is too large.', {
metaMessages: [`Max: ${maxSize} bytes`, `Given: ${size} bytes`],
name: 'BlobSizeTooLargeError',
})
}
}
export type EmptyBlobErrorType = EmptyBlobError & {
name: 'EmptyBlobError'
}
export class EmptyBlobError extends BaseError {
constructor() {
super('Blob data must not be empty.', { name: 'EmptyBlobError' })
}
}
export type InvalidVersionedHashSizeErrorType =
InvalidVersionedHashSizeError & {
name: 'InvalidVersionedHashSizeError'
}
export class InvalidVersionedHashSizeError extends BaseError {
constructor({
hash,
size,
}: {
hash: Hash
size: number
}) {
super(`Versioned hash "${hash}" size is invalid.`, {
metaMessages: ['Expected: 32', `Received: ${size}`],
name: 'InvalidVersionedHashSizeError',
})
}
}
export type InvalidVersionedHashVersionErrorType =
InvalidVersionedHashVersionError & {
name: 'InvalidVersionedHashVersionError'
}
export class InvalidVersionedHashVersionError extends BaseError {
constructor({
hash,
version,
}: {
hash: Hash
version: number
}) {
super(`Versioned hash "${hash}" version is invalid.`, {
metaMessages: [
`Expected: ${versionedHashVersionKzg}`,
`Received: ${version}`,
],
name: 'InvalidVersionedHashVersionError',
})
}
}

21
node_modules/viem/errors/block.ts generated vendored Normal file
View File

@@ -0,0 +1,21 @@
import type { Hash } from '../types/misc.js'
import { BaseError } from './base.js'
export type BlockNotFoundErrorType = BlockNotFoundError & {
name: 'BlockNotFoundError'
}
export class BlockNotFoundError extends BaseError {
constructor({
blockHash,
blockNumber,
}: {
blockHash?: Hash | undefined
blockNumber?: bigint | undefined
}) {
let identifier = 'Block'
if (blockHash) identifier = `Block at hash "${blockHash}"`
if (blockNumber) identifier = `Block at number "${blockNumber}"`
super(`${identifier} could not be found.`, { name: 'BlockNotFoundError' })
}
}

17
node_modules/viem/errors/calls.ts generated vendored Normal file
View File

@@ -0,0 +1,17 @@
import type { GetCallsStatusReturnType } from '../actions/wallet/getCallsStatus.js'
import { BaseError } from './base.js'
export type BundleFailedErrorType = BundleFailedError & {
name: 'BundleFailedError'
}
export class BundleFailedError extends BaseError {
result: GetCallsStatusReturnType
constructor(result: GetCallsStatusReturnType) {
super(`Call bundle failed with status: ${result.statusCode}`, {
name: 'BundleFailedError',
})
this.result = result
}
}

89
node_modules/viem/errors/ccip.ts generated vendored Normal file
View File

@@ -0,0 +1,89 @@
import type { Address } from 'abitype'
import type { Hex } from '../types/misc.js'
import { stringify } from '../utils/stringify.js'
import { BaseError } from './base.js'
import { getUrl } from './utils.js'
export type OffchainLookupErrorType = OffchainLookupError & {
name: 'OffchainLookupError'
}
export class OffchainLookupError extends BaseError {
constructor({
callbackSelector,
cause,
data,
extraData,
sender,
urls,
}: {
callbackSelector: Hex
cause: BaseError
data: Hex
extraData: Hex
sender: Address
urls: readonly string[]
}) {
super(
cause.shortMessage ||
'An error occurred while fetching for an offchain result.',
{
cause,
metaMessages: [
...(cause.metaMessages || []),
cause.metaMessages?.length ? '' : [],
'Offchain Gateway Call:',
urls && [
' Gateway URL(s):',
...urls.map((url) => ` ${getUrl(url)}`),
],
` Sender: ${sender}`,
` Data: ${data}`,
` Callback selector: ${callbackSelector}`,
` Extra data: ${extraData}`,
].flat(),
name: 'OffchainLookupError',
},
)
}
}
export type OffchainLookupResponseMalformedErrorType =
OffchainLookupResponseMalformedError & {
name: 'OffchainLookupResponseMalformedError'
}
export class OffchainLookupResponseMalformedError extends BaseError {
constructor({ result, url }: { result: any; url: string }) {
super(
'Offchain gateway response is malformed. Response data must be a hex value.',
{
metaMessages: [
`Gateway URL: ${getUrl(url)}`,
`Response: ${stringify(result)}`,
],
name: 'OffchainLookupResponseMalformedError',
},
)
}
}
/** @internal */
export type OffchainLookupSenderMismatchErrorType =
OffchainLookupSenderMismatchError & {
name: 'OffchainLookupSenderMismatchError'
}
export class OffchainLookupSenderMismatchError extends BaseError {
constructor({ sender, to }: { sender: Address; to: Address }) {
super(
'Reverted sender address does not match target contract address (`to`).',
{
metaMessages: [
`Contract address: ${to}`,
`OffchainLookup sender address: ${sender}`,
],
name: 'OffchainLookupSenderMismatchError',
},
)
}
}

105
node_modules/viem/errors/chain.ts generated vendored Normal file
View File

@@ -0,0 +1,105 @@
import type { Chain } from '../types/chain.js'
import { BaseError } from './base.js'
export type ChainDoesNotSupportContractErrorType =
ChainDoesNotSupportContract & {
name: 'ChainDoesNotSupportContract'
}
export class ChainDoesNotSupportContract extends BaseError {
constructor({
blockNumber,
chain,
contract,
}: {
blockNumber?: bigint | undefined
chain: Chain
contract: { name: string; blockCreated?: number | undefined }
}) {
super(
`Chain "${chain.name}" does not support contract "${contract.name}".`,
{
metaMessages: [
'This could be due to any of the following:',
...(blockNumber &&
contract.blockCreated &&
contract.blockCreated > blockNumber
? [
`- The contract "${contract.name}" was not deployed until block ${contract.blockCreated} (current block ${blockNumber}).`,
]
: [
`- The chain does not have the contract "${contract.name}" configured.`,
]),
],
name: 'ChainDoesNotSupportContract',
},
)
}
}
export type ChainMismatchErrorType = ChainMismatchError & {
name: 'ChainMismatchError'
}
export class ChainMismatchError extends BaseError {
constructor({
chain,
currentChainId,
}: {
chain: Chain
currentChainId: number
}) {
super(
`The current chain of the wallet (id: ${currentChainId}) does not match the target chain for the transaction (id: ${chain.id} ${chain.name}).`,
{
metaMessages: [
`Current Chain ID: ${currentChainId}`,
`Expected Chain ID: ${chain.id} ${chain.name}`,
],
name: 'ChainMismatchError',
},
)
}
}
export type ChainNotFoundErrorType = ChainNotFoundError & {
name: 'ChainNotFoundError'
}
export class ChainNotFoundError extends BaseError {
constructor() {
super(
[
'No chain was provided to the request.',
'Please provide a chain with the `chain` argument on the Action, or by supplying a `chain` to WalletClient.',
].join('\n'),
{
name: 'ChainNotFoundError',
},
)
}
}
export type ClientChainNotConfiguredErrorType =
ClientChainNotConfiguredError & {
name: 'ClientChainNotConfiguredError'
}
export class ClientChainNotConfiguredError extends BaseError {
constructor() {
super('No chain was provided to the Client.', {
name: 'ClientChainNotConfiguredError',
})
}
}
export type InvalidChainIdErrorType = InvalidChainIdError & {
name: 'InvalidChainIdError'
}
export class InvalidChainIdError extends BaseError {
constructor({ chainId }: { chainId?: number | undefined }) {
super(
typeof chainId === 'number'
? `Chain ID "${chainId}" is invalid.`
: 'Chain ID is invalid.',
{ name: 'InvalidChainIdError' },
)
}
}

329
node_modules/viem/errors/contract.ts generated vendored Normal file
View File

@@ -0,0 +1,329 @@
import type { Abi, Address } from 'abitype'
import { parseAccount } from '../accounts/utils/parseAccount.js'
import type { CallParameters } from '../actions/public/call.js'
import { panicReasons } from '../constants/solidity.js'
import type { Chain } from '../types/chain.js'
import type { Hex } from '../types/misc.js'
import {
type DecodeErrorResultReturnType,
decodeErrorResult,
} from '../utils/abi/decodeErrorResult.js'
import { formatAbiItem } from '../utils/abi/formatAbiItem.js'
import { formatAbiItemWithArgs } from '../utils/abi/formatAbiItemWithArgs.js'
import { getAbiItem } from '../utils/abi/getAbiItem.js'
import { formatEther } from '../utils/unit/formatEther.js'
import { formatGwei } from '../utils/unit/formatGwei.js'
import { AbiErrorSignatureNotFoundError } from './abi.js'
import { BaseError } from './base.js'
import { prettyStateOverride } from './stateOverride.js'
import { prettyPrint } from './transaction.js'
import { getContractAddress } from './utils.js'
export type CallExecutionErrorType = CallExecutionError & {
name: 'CallExecutionError'
}
export class CallExecutionError extends BaseError {
override cause: BaseError
constructor(
cause: BaseError,
{
account: account_,
docsPath,
chain,
data,
gas,
gasPrice,
maxFeePerGas,
maxPriorityFeePerGas,
nonce,
to,
value,
stateOverride,
}: CallParameters & {
chain?: Chain | undefined
docsPath?: string | undefined
},
) {
const account = account_ ? parseAccount(account_) : undefined
let prettyArgs = prettyPrint({
from: account?.address,
to,
value:
typeof value !== 'undefined' &&
`${formatEther(value)} ${chain?.nativeCurrency?.symbol || 'ETH'}`,
data,
gas,
gasPrice:
typeof gasPrice !== 'undefined' && `${formatGwei(gasPrice)} gwei`,
maxFeePerGas:
typeof maxFeePerGas !== 'undefined' &&
`${formatGwei(maxFeePerGas)} gwei`,
maxPriorityFeePerGas:
typeof maxPriorityFeePerGas !== 'undefined' &&
`${formatGwei(maxPriorityFeePerGas)} gwei`,
nonce,
})
if (stateOverride) {
prettyArgs += `\n${prettyStateOverride(stateOverride)}`
}
super(cause.shortMessage, {
cause,
docsPath,
metaMessages: [
...(cause.metaMessages ? [...cause.metaMessages, ' '] : []),
'Raw Call Arguments:',
prettyArgs,
].filter(Boolean) as string[],
name: 'CallExecutionError',
})
this.cause = cause
}
}
export type ContractFunctionExecutionErrorType =
ContractFunctionExecutionError & {
name: 'ContractFunctionExecutionError'
}
export class ContractFunctionExecutionError extends BaseError {
abi: Abi
args?: unknown[] | undefined
override cause: BaseError
contractAddress?: Address | undefined
formattedArgs?: string | undefined
functionName: string
sender?: Address | undefined
constructor(
cause: BaseError,
{
abi,
args,
contractAddress,
docsPath,
functionName,
sender,
}: {
abi: Abi
args?: any | undefined
contractAddress?: Address | undefined
docsPath?: string | undefined
functionName: string
sender?: Address | undefined
},
) {
const abiItem = getAbiItem({ abi, args, name: functionName })
const formattedArgs = abiItem
? formatAbiItemWithArgs({
abiItem,
args,
includeFunctionName: false,
includeName: false,
})
: undefined
const functionWithParams = abiItem
? formatAbiItem(abiItem, { includeName: true })
: undefined
const prettyArgs = prettyPrint({
address: contractAddress && getContractAddress(contractAddress),
function: functionWithParams,
args:
formattedArgs &&
formattedArgs !== '()' &&
`${[...Array(functionName?.length ?? 0).keys()]
.map(() => ' ')
.join('')}${formattedArgs}`,
sender,
})
super(
cause.shortMessage ||
`An unknown error occurred while executing the contract function "${functionName}".`,
{
cause,
docsPath,
metaMessages: [
...(cause.metaMessages ? [...cause.metaMessages, ' '] : []),
prettyArgs && 'Contract Call:',
prettyArgs,
].filter(Boolean) as string[],
name: 'ContractFunctionExecutionError',
},
)
this.abi = abi
this.args = args
this.cause = cause
this.contractAddress = contractAddress
this.functionName = functionName
this.sender = sender
}
}
export type ContractFunctionRevertedErrorType =
ContractFunctionRevertedError & {
name: 'ContractFunctionRevertedError'
}
export class ContractFunctionRevertedError extends BaseError {
data?: DecodeErrorResultReturnType | undefined
raw?: Hex | undefined
reason?: string | undefined
signature?: Hex | undefined
constructor({
abi,
data,
functionName,
message,
cause: error,
}: {
abi: Abi
data?: Hex | undefined
functionName: string
message?: string | undefined
cause?: BaseError | Error | undefined
}) {
let cause: Error | undefined
let decodedData: DecodeErrorResultReturnType | undefined
let metaMessages: string[] | undefined
let reason: string | undefined
if (data && data !== '0x') {
try {
decodedData = decodeErrorResult({ abi, data, cause: error })
const { abiItem, errorName, args: errorArgs } = decodedData
if (errorName === 'Error') {
reason = (errorArgs as [string])[0]
} else if (errorName === 'Panic') {
const [firstArg] = errorArgs as [number]
reason = panicReasons[firstArg as keyof typeof panicReasons]
} else {
const errorWithParams = abiItem
? formatAbiItem(abiItem, { includeName: true })
: undefined
const formattedArgs =
abiItem && errorArgs
? formatAbiItemWithArgs({
abiItem,
args: errorArgs,
includeFunctionName: false,
includeName: false,
})
: undefined
metaMessages = [
errorWithParams ? `Error: ${errorWithParams}` : '',
formattedArgs && formattedArgs !== '()'
? ` ${[...Array(errorName?.length ?? 0).keys()]
.map(() => ' ')
.join('')}${formattedArgs}`
: '',
]
}
} catch (err) {
cause = err as Error
}
} else if (message) reason = message
let signature: Hex | undefined
if (cause instanceof AbiErrorSignatureNotFoundError) {
signature = cause.signature
metaMessages = [
`Unable to decode signature "${signature}" as it was not found on the provided ABI.`,
'Make sure you are using the correct ABI and that the error exists on it.',
`You can look up the decoded signature here: https://4byte.sourcify.dev/?q=${signature}.`,
]
}
super(
(reason && reason !== 'execution reverted') || signature
? [
`The contract function "${functionName}" reverted with the following ${
signature ? 'signature' : 'reason'
}:`,
reason || signature,
].join('\n')
: `The contract function "${functionName}" reverted.`,
{
cause: cause ?? error,
metaMessages,
name: 'ContractFunctionRevertedError',
},
)
this.data = decodedData
this.raw = data
this.reason = reason
this.signature = signature
}
}
export type ContractFunctionZeroDataErrorType =
ContractFunctionZeroDataError & {
name: 'ContractFunctionZeroDataError'
}
export class ContractFunctionZeroDataError extends BaseError {
constructor({
functionName,
cause,
}: {
functionName: string
cause?: BaseError | Error | undefined
}) {
super(`The contract function "${functionName}" returned no data ("0x").`, {
metaMessages: [
'This could be due to any of the following:',
` - The contract does not have the function "${functionName}",`,
' - The parameters passed to the contract function may be invalid, or',
' - The address is not a contract.',
],
name: 'ContractFunctionZeroDataError',
cause,
})
}
}
export type CounterfactualDeploymentFailedErrorType =
CounterfactualDeploymentFailedError & {
name: 'CounterfactualDeploymentFailedError'
}
export class CounterfactualDeploymentFailedError extends BaseError {
constructor({ factory }: { factory?: Address | undefined }) {
super(
`Deployment for counterfactual contract call failed${
factory ? ` for factory "${factory}".` : ''
}`,
{
metaMessages: [
'Please ensure:',
'- The `factory` is a valid contract deployment factory (ie. Create2 Factory, ERC-4337 Factory, etc).',
'- The `factoryData` is a valid encoded function call for contract deployment function on the factory.',
],
name: 'CounterfactualDeploymentFailedError',
},
)
}
}
export type RawContractErrorType = RawContractError & {
name: 'RawContractError'
}
export class RawContractError extends BaseError {
code = 3
data?: Hex | { data?: Hex | undefined } | undefined
constructor({
data,
message,
}: {
data?: Hex | { data?: Hex | undefined } | undefined
message?: string | undefined
}) {
super(message || '', { name: 'RawContractError' })
this.data = data
}
}

37
node_modules/viem/errors/cursor.ts generated vendored Normal file
View File

@@ -0,0 +1,37 @@
import { BaseError } from './base.js'
export type NegativeOffsetErrorType = NegativeOffsetError & {
name: 'NegativeOffsetError'
}
export class NegativeOffsetError extends BaseError {
constructor({ offset }: { offset: number }) {
super(`Offset \`${offset}\` cannot be negative.`, {
name: 'NegativeOffsetError',
})
}
}
export type PositionOutOfBoundsErrorType = PositionOutOfBoundsError & {
name: 'PositionOutOfBoundsError'
}
export class PositionOutOfBoundsError extends BaseError {
constructor({ length, position }: { length: number; position: number }) {
super(
`Position \`${position}\` is out of bounds (\`0 < position < ${length}\`).`,
{ name: 'PositionOutOfBoundsError' },
)
}
}
export type RecursiveReadLimitExceededErrorType =
RecursiveReadLimitExceededError & {
name: 'RecursiveReadLimitExceededError'
}
export class RecursiveReadLimitExceededError extends BaseError {
constructor({ count, limit }: { count: number; limit: number }) {
super(
`Recursive read limit of \`${limit}\` exceeded (recursive read count: \`${count}\`).`,
{ name: 'RecursiveReadLimitExceededError' },
)
}
}

63
node_modules/viem/errors/data.ts generated vendored Normal file
View File

@@ -0,0 +1,63 @@
import { BaseError } from './base.js'
export type SliceOffsetOutOfBoundsErrorType = SliceOffsetOutOfBoundsError & {
name: 'SliceOffsetOutOfBoundsError'
}
export class SliceOffsetOutOfBoundsError extends BaseError {
constructor({
offset,
position,
size,
}: { offset: number; position: 'start' | 'end'; size: number }) {
super(
`Slice ${
position === 'start' ? 'starting' : 'ending'
} at offset "${offset}" is out-of-bounds (size: ${size}).`,
{ name: 'SliceOffsetOutOfBoundsError' },
)
}
}
export type SizeExceedsPaddingSizeErrorType = SizeExceedsPaddingSizeError & {
name: 'SizeExceedsPaddingSizeError'
}
export class SizeExceedsPaddingSizeError extends BaseError {
constructor({
size,
targetSize,
type,
}: {
size: number
targetSize: number
type: 'hex' | 'bytes'
}) {
super(
`${type.charAt(0).toUpperCase()}${type
.slice(1)
.toLowerCase()} size (${size}) exceeds padding size (${targetSize}).`,
{ name: 'SizeExceedsPaddingSizeError' },
)
}
}
export type InvalidBytesLengthErrorType = InvalidBytesLengthError & {
name: 'InvalidBytesLengthError'
}
export class InvalidBytesLengthError extends BaseError {
constructor({
size,
targetSize,
type,
}: {
size: number
targetSize: number
type: 'hex' | 'bytes'
}) {
super(
`${type.charAt(0).toUpperCase()}${type
.slice(1)
.toLowerCase()} is expected to be ${targetSize} ${type} long, but is ${size} ${type} long.`,
{ name: 'InvalidBytesLengthError' },
)
}
}

19
node_modules/viem/errors/eip712.ts generated vendored Normal file
View File

@@ -0,0 +1,19 @@
import type { Address } from 'abitype'
import { BaseError } from './base.js'
export type Eip712DomainNotFoundErrorType = Eip712DomainNotFoundError & {
name: 'Eip712DomainNotFoundError'
}
export class Eip712DomainNotFoundError extends BaseError {
constructor({ address }: { address: Address }) {
super(`No EIP-712 domain found on contract "${address}".`, {
metaMessages: [
'Ensure that:',
`- The contract is deployed at the address "${address}".`,
'- `eip712Domain()` function exists on the contract.',
'- `eip712Domain()` function matches signature to ERC-5267 specification.',
],
name: 'Eip712DomainNotFoundError',
})
}
}

79
node_modules/viem/errors/encoding.ts generated vendored Normal file
View File

@@ -0,0 +1,79 @@
import type { ByteArray, Hex } from '../types/misc.js'
import { BaseError } from './base.js'
export type IntegerOutOfRangeErrorType = IntegerOutOfRangeError & {
name: 'IntegerOutOfRangeError'
}
export class IntegerOutOfRangeError extends BaseError {
constructor({
max,
min,
signed,
size,
value,
}: {
max?: string | undefined
min: string
signed?: boolean | undefined
size?: number | undefined
value: string
}) {
super(
`Number "${value}" is not in safe ${
size ? `${size * 8}-bit ${signed ? 'signed' : 'unsigned'} ` : ''
}integer range ${max ? `(${min} to ${max})` : `(above ${min})`}`,
{ name: 'IntegerOutOfRangeError' },
)
}
}
export type InvalidBytesBooleanErrorType = InvalidBytesBooleanError & {
name: 'InvalidBytesBooleanError'
}
export class InvalidBytesBooleanError extends BaseError {
constructor(bytes: ByteArray) {
super(
`Bytes value "${bytes}" is not a valid boolean. The bytes array must contain a single byte of either a 0 or 1 value.`,
{
name: 'InvalidBytesBooleanError',
},
)
}
}
export type InvalidHexBooleanErrorType = InvalidHexBooleanError & {
name: 'InvalidHexBooleanError'
}
export class InvalidHexBooleanError extends BaseError {
constructor(hex: Hex) {
super(
`Hex value "${hex}" is not a valid boolean. The hex value must be "0x0" (false) or "0x1" (true).`,
{ name: 'InvalidHexBooleanError' },
)
}
}
export type InvalidHexValueErrorType = InvalidHexValueError & {
name: 'InvalidHexValueError'
}
export class InvalidHexValueError extends BaseError {
constructor(value: Hex) {
super(
`Hex value "${value}" is an odd length (${value.length}). It must be an even length.`,
{ name: 'InvalidHexValueError' },
)
}
}
export type SizeOverflowErrorType = SizeOverflowError & {
name: 'SizeOverflowError'
}
export class SizeOverflowError extends BaseError {
constructor({ givenSize, maxSize }: { givenSize: number; maxSize: number }) {
super(
`Size cannot exceed ${maxSize} bytes. Given size: ${givenSize} bytes.`,
{ name: 'SizeOverflowError' },
)
}
}

71
node_modules/viem/errors/ens.ts generated vendored Normal file
View File

@@ -0,0 +1,71 @@
import { BaseError } from './base.js'
export type EnsAvatarInvalidMetadataErrorType =
EnsAvatarInvalidMetadataError & {
name: 'EnsAvatarInvalidMetadataError'
}
export class EnsAvatarInvalidMetadataError extends BaseError {
constructor({ data }: { data: any }) {
super(
'Unable to extract image from metadata. The metadata may be malformed or invalid.',
{
metaMessages: [
'- Metadata must be a JSON object with at least an `image`, `image_url` or `image_data` property.',
'',
`Provided data: ${JSON.stringify(data)}`,
],
name: 'EnsAvatarInvalidMetadataError',
},
)
}
}
export type EnsAvatarInvalidNftUriErrorType = EnsAvatarInvalidNftUriError & {
name: 'EnsAvatarInvalidNftUriError'
}
export class EnsAvatarInvalidNftUriError extends BaseError {
constructor({ reason }: { reason: string }) {
super(`ENS NFT avatar URI is invalid. ${reason}`, {
name: 'EnsAvatarInvalidNftUriError',
})
}
}
export type EnsAvatarUriResolutionErrorType = EnsAvatarUriResolutionError & {
name: 'EnsAvatarUriResolutionError'
}
export class EnsAvatarUriResolutionError extends BaseError {
constructor({ uri }: { uri: string }) {
super(
`Unable to resolve ENS avatar URI "${uri}". The URI may be malformed, invalid, or does not respond with a valid image.`,
{ name: 'EnsAvatarUriResolutionError' },
)
}
}
export type EnsAvatarUnsupportedNamespaceErrorType =
EnsAvatarUnsupportedNamespaceError & {
name: 'EnsAvatarUnsupportedNamespaceError'
}
export class EnsAvatarUnsupportedNamespaceError extends BaseError {
constructor({ namespace }: { namespace: string }) {
super(
`ENS NFT avatar namespace "${namespace}" is not supported. Must be "erc721" or "erc1155".`,
{ name: 'EnsAvatarUnsupportedNamespaceError' },
)
}
}
export type EnsInvalidChainIdErrorType = EnsInvalidChainIdError & {
name: 'EnsInvalidChainIdError'
}
export class EnsInvalidChainIdError extends BaseError {
constructor({ chainId }: { chainId: number }) {
super(
`Invalid ENSIP-11 chainId: ${chainId}. Must be between 0 and 0x7fffffff, or 1.`,
{
name: 'EnsInvalidChainIdError',
},
)
}
}

67
node_modules/viem/errors/estimateGas.ts generated vendored Normal file
View File

@@ -0,0 +1,67 @@
import type { Account } from '../accounts/types.js'
import type { EstimateGasParameters } from '../actions/public/estimateGas.js'
import type { Chain } from '../types/chain.js'
import { formatEther } from '../utils/unit/formatEther.js'
import { formatGwei } from '../utils/unit/formatGwei.js'
import { BaseError } from './base.js'
import { prettyPrint } from './transaction.js'
export type EstimateGasExecutionErrorType = EstimateGasExecutionError & {
name: 'EstimateGasExecutionError'
}
export class EstimateGasExecutionError extends BaseError {
override cause: BaseError
constructor(
cause: BaseError,
{
account,
docsPath,
chain,
data,
gas,
gasPrice,
maxFeePerGas,
maxPriorityFeePerGas,
nonce,
to,
value,
}: Omit<EstimateGasParameters<any>, 'account'> & {
account?: Account | undefined
chain?: Chain | undefined
docsPath?: string | undefined
},
) {
const prettyArgs = prettyPrint({
from: account?.address,
to,
value:
typeof value !== 'undefined' &&
`${formatEther(value)} ${chain?.nativeCurrency?.symbol || 'ETH'}`,
data,
gas,
gasPrice:
typeof gasPrice !== 'undefined' && `${formatGwei(gasPrice)} gwei`,
maxFeePerGas:
typeof maxFeePerGas !== 'undefined' &&
`${formatGwei(maxFeePerGas)} gwei`,
maxPriorityFeePerGas:
typeof maxPriorityFeePerGas !== 'undefined' &&
`${formatGwei(maxPriorityFeePerGas)} gwei`,
nonce,
})
super(cause.shortMessage, {
cause,
docsPath,
metaMessages: [
...(cause.metaMessages ? [...cause.metaMessages, ' '] : []),
'Estimate Gas Arguments:',
prettyArgs,
].filter(Boolean) as string[],
name: 'EstimateGasExecutionError',
})
this.cause = cause
}
}

38
node_modules/viem/errors/fee.ts generated vendored Normal file
View File

@@ -0,0 +1,38 @@
import { formatGwei } from '../utils/unit/formatGwei.js'
import { BaseError } from './base.js'
export type BaseFeeScalarErrorType = BaseFeeScalarError & {
name: 'BaseFeeScalarError'
}
export class BaseFeeScalarError extends BaseError {
constructor() {
super('`baseFeeMultiplier` must be greater than 1.', {
name: 'BaseFeeScalarError',
})
}
}
export type Eip1559FeesNotSupportedErrorType = Eip1559FeesNotSupportedError & {
name: 'Eip1559FeesNotSupportedError'
}
export class Eip1559FeesNotSupportedError extends BaseError {
constructor() {
super('Chain does not support EIP-1559 fees.', {
name: 'Eip1559FeesNotSupportedError',
})
}
}
export type MaxFeePerGasTooLowErrorType = MaxFeePerGasTooLowError & {
name: 'MaxFeePerGasTooLowError'
}
export class MaxFeePerGasTooLowError extends BaseError {
constructor({ maxPriorityFeePerGas }: { maxPriorityFeePerGas: bigint }) {
super(
`\`maxFeePerGas\` cannot be less than the \`maxPriorityFeePerGas\` (${formatGwei(
maxPriorityFeePerGas,
)} gwei).`,
{ name: 'MaxFeePerGasTooLowError' },
)
}
}

12
node_modules/viem/errors/log.ts generated vendored Normal file
View File

@@ -0,0 +1,12 @@
import { BaseError } from './base.js'
export type FilterTypeNotSupportedErrorType = FilterTypeNotSupportedError & {
name: 'FilterTypeNotSupportedError'
}
export class FilterTypeNotSupportedError extends BaseError {
constructor(type: string) {
super(`Filter type "${type}" is not supported.`, {
name: 'FilterTypeNotSupportedError',
})
}
}

277
node_modules/viem/errors/node.ts generated vendored Normal file
View File

@@ -0,0 +1,277 @@
import { formatGwei } from '../utils/unit/formatGwei.js'
import { BaseError } from './base.js'
/**
* geth: https://github.com/ethereum/go-ethereum/blob/master/core/error.go
* https://github.com/ethereum/go-ethereum/blob/master/core/types/transaction.go#L34-L41
*
* erigon: https://github.com/ledgerwatch/erigon/blob/master/core/error.go
* https://github.com/ledgerwatch/erigon/blob/master/core/types/transaction.go#L41-L46
*
* anvil: https://github.com/foundry-rs/foundry/blob/master/anvil/src/eth/error.rs#L108
*/
export type ExecutionRevertedErrorType = ExecutionRevertedError & {
code: 3
name: 'ExecutionRevertedError'
}
export class ExecutionRevertedError extends BaseError {
static code = 3
static nodeMessage = /execution reverted|gas required exceeds allowance/
constructor({
cause,
message,
}: { cause?: BaseError | undefined; message?: string | undefined } = {}) {
const reason = message
?.replace('execution reverted: ', '')
?.replace('execution reverted', '')
super(
`Execution reverted ${
reason ? `with reason: ${reason}` : 'for an unknown reason'
}.`,
{
cause,
name: 'ExecutionRevertedError',
},
)
}
}
export type FeeCapTooHighErrorType = FeeCapTooHighError & {
name: 'FeeCapTooHighError'
}
export class FeeCapTooHighError extends BaseError {
static nodeMessage =
/max fee per gas higher than 2\^256-1|fee cap higher than 2\^256-1/
constructor({
cause,
maxFeePerGas,
}: {
cause?: BaseError | undefined
maxFeePerGas?: bigint | undefined
} = {}) {
super(
`The fee cap (\`maxFeePerGas\`${
maxFeePerGas ? ` = ${formatGwei(maxFeePerGas)} gwei` : ''
}) cannot be higher than the maximum allowed value (2^256-1).`,
{
cause,
name: 'FeeCapTooHighError',
},
)
}
}
export type FeeCapTooLowErrorType = FeeCapTooLowError & {
name: 'FeeCapTooLowError'
}
export class FeeCapTooLowError extends BaseError {
static nodeMessage =
/max fee per gas less than block base fee|fee cap less than block base fee|transaction is outdated/
constructor({
cause,
maxFeePerGas,
}: {
cause?: BaseError | undefined
maxFeePerGas?: bigint | undefined
} = {}) {
super(
`The fee cap (\`maxFeePerGas\`${
maxFeePerGas ? ` = ${formatGwei(maxFeePerGas)}` : ''
} gwei) cannot be lower than the block base fee.`,
{
cause,
name: 'FeeCapTooLowError',
},
)
}
}
export type NonceTooHighErrorType = NonceTooHighError & {
name: 'NonceTooHighError'
}
export class NonceTooHighError extends BaseError {
static nodeMessage = /nonce too high/
constructor({
cause,
nonce,
}: { cause?: BaseError | undefined; nonce?: number | undefined } = {}) {
super(
`Nonce provided for the transaction ${
nonce ? `(${nonce}) ` : ''
}is higher than the next one expected.`,
{ cause, name: 'NonceTooHighError' },
)
}
}
export type NonceTooLowErrorType = NonceTooLowError & {
name: 'NonceTooLowError'
}
export class NonceTooLowError extends BaseError {
static nodeMessage =
/nonce too low|transaction already imported|already known/
constructor({
cause,
nonce,
}: { cause?: BaseError | undefined; nonce?: number | undefined } = {}) {
super(
[
`Nonce provided for the transaction ${
nonce ? `(${nonce}) ` : ''
}is lower than the current nonce of the account.`,
'Try increasing the nonce or find the latest nonce with `getTransactionCount`.',
].join('\n'),
{ cause, name: 'NonceTooLowError' },
)
}
}
export type NonceMaxValueErrorType = NonceMaxValueError & {
name: 'NonceMaxValueError'
}
export class NonceMaxValueError extends BaseError {
static nodeMessage = /nonce has max value/
constructor({
cause,
nonce,
}: { cause?: BaseError | undefined; nonce?: number | undefined } = {}) {
super(
`Nonce provided for the transaction ${
nonce ? `(${nonce}) ` : ''
}exceeds the maximum allowed nonce.`,
{ cause, name: 'NonceMaxValueError' },
)
}
}
export type InsufficientFundsErrorType = InsufficientFundsError & {
name: 'InsufficientFundsError'
}
export class InsufficientFundsError extends BaseError {
static nodeMessage =
/insufficient funds|exceeds transaction sender account balance/
constructor({ cause }: { cause?: BaseError | undefined } = {}) {
super(
[
'The total cost (gas * gas fee + value) of executing this transaction exceeds the balance of the account.',
].join('\n'),
{
cause,
metaMessages: [
'This error could arise when the account does not have enough funds to:',
' - pay for the total gas fee,',
' - pay for the value to send.',
' ',
'The cost of the transaction is calculated as `gas * gas fee + value`, where:',
' - `gas` is the amount of gas needed for transaction to execute,',
' - `gas fee` is the gas fee,',
' - `value` is the amount of ether to send to the recipient.',
],
name: 'InsufficientFundsError',
},
)
}
}
export type IntrinsicGasTooHighErrorType = IntrinsicGasTooHighError & {
name: 'IntrinsicGasTooHighError'
}
export class IntrinsicGasTooHighError extends BaseError {
static nodeMessage = /intrinsic gas too high|gas limit reached/
constructor({
cause,
gas,
}: { cause?: BaseError | undefined; gas?: bigint | undefined } = {}) {
super(
`The amount of gas ${
gas ? `(${gas}) ` : ''
}provided for the transaction exceeds the limit allowed for the block.`,
{
cause,
name: 'IntrinsicGasTooHighError',
},
)
}
}
export type IntrinsicGasTooLowErrorType = IntrinsicGasTooLowError & {
name: 'IntrinsicGasTooLowError'
}
export class IntrinsicGasTooLowError extends BaseError {
static nodeMessage = /intrinsic gas too low/
constructor({
cause,
gas,
}: { cause?: BaseError | undefined; gas?: bigint | undefined } = {}) {
super(
`The amount of gas ${
gas ? `(${gas}) ` : ''
}provided for the transaction is too low.`,
{
cause,
name: 'IntrinsicGasTooLowError',
},
)
}
}
export type TransactionTypeNotSupportedErrorType =
TransactionTypeNotSupportedError & {
name: 'TransactionTypeNotSupportedError'
}
export class TransactionTypeNotSupportedError extends BaseError {
static nodeMessage = /transaction type not valid/
constructor({ cause }: { cause?: BaseError | undefined }) {
super('The transaction type is not supported for this chain.', {
cause,
name: 'TransactionTypeNotSupportedError',
})
}
}
export type TipAboveFeeCapErrorType = TipAboveFeeCapError & {
name: 'TipAboveFeeCapError'
}
export class TipAboveFeeCapError extends BaseError {
static nodeMessage =
/max priority fee per gas higher than max fee per gas|tip higher than fee cap/
constructor({
cause,
maxPriorityFeePerGas,
maxFeePerGas,
}: {
cause?: BaseError | undefined
maxPriorityFeePerGas?: bigint | undefined
maxFeePerGas?: bigint | undefined
} = {}) {
super(
[
`The provided tip (\`maxPriorityFeePerGas\`${
maxPriorityFeePerGas
? ` = ${formatGwei(maxPriorityFeePerGas)} gwei`
: ''
}) cannot be higher than the fee cap (\`maxFeePerGas\`${
maxFeePerGas ? ` = ${formatGwei(maxFeePerGas)} gwei` : ''
}).`,
].join('\n'),
{
cause,
name: 'TipAboveFeeCapError',
},
)
}
}
export type UnknownNodeErrorType = UnknownNodeError & {
name: 'UnknownNodeError'
}
export class UnknownNodeError extends BaseError {
constructor({ cause }: { cause?: BaseError | undefined }) {
super(`An error occurred while executing: ${cause?.shortMessage}`, {
cause,
name: 'UnknownNodeError',
})
}
}

141
node_modules/viem/errors/request.ts generated vendored Normal file
View File

@@ -0,0 +1,141 @@
import { stringify } from '../utils/stringify.js'
import { BaseError } from './base.js'
import { getUrl } from './utils.js'
export type HttpRequestErrorType = HttpRequestError & {
name: 'HttpRequestError'
}
export class HttpRequestError extends BaseError {
body?: { [x: string]: unknown } | { [y: string]: unknown }[] | undefined
headers?: Headers | undefined
status?: number | undefined
url: string
constructor({
body,
cause,
details,
headers,
status,
url,
}: {
body?: { [x: string]: unknown } | { [y: string]: unknown }[] | undefined
cause?: Error | undefined
details?: string | undefined
headers?: Headers | undefined
status?: number | undefined
url: string
}) {
super('HTTP request failed.', {
cause,
details,
metaMessages: [
status && `Status: ${status}`,
`URL: ${getUrl(url)}`,
body && `Request body: ${stringify(body)}`,
].filter(Boolean) as string[],
name: 'HttpRequestError',
})
this.body = body
this.headers = headers
this.status = status
this.url = url
}
}
export type WebSocketRequestErrorType = WebSocketRequestError & {
name: 'WebSocketRequestError'
}
export class WebSocketRequestError extends BaseError {
url: string
constructor({
body,
cause,
details,
url,
}: {
body?: { [key: string]: unknown } | undefined
cause?: Error | undefined
details?: string | undefined
url: string
}) {
super('WebSocket request failed.', {
cause,
details,
metaMessages: [
`URL: ${getUrl(url)}`,
body && `Request body: ${stringify(body)}`,
].filter(Boolean) as string[],
name: 'WebSocketRequestError',
})
this.url = url
}
}
export type RpcRequestErrorType = RpcRequestError & {
name: 'RpcRequestError'
}
export class RpcRequestError extends BaseError {
code: number
data?: unknown
url: string
constructor({
body,
error,
url,
}: {
body: { [x: string]: unknown } | { [y: string]: unknown }[]
error: { code: number; data?: unknown; message: string }
url: string
}) {
super('RPC Request failed.', {
cause: error as any,
details: error.message,
metaMessages: [`URL: ${getUrl(url)}`, `Request body: ${stringify(body)}`],
name: 'RpcRequestError',
})
this.code = error.code
this.data = error.data
this.url = url
}
}
export type SocketClosedErrorType = SocketClosedError & {
name: 'SocketClosedError'
}
export class SocketClosedError extends BaseError {
url: string | undefined
constructor({
url,
}: {
url?: string | undefined
} = {}) {
super('The socket has been closed.', {
metaMessages: [url && `URL: ${getUrl(url)}`].filter(Boolean) as string[],
name: 'SocketClosedError',
})
this.url = url
}
}
export type TimeoutErrorType = TimeoutError & {
name: 'TimeoutError'
}
export class TimeoutError extends BaseError {
url: string
constructor({
body,
url,
}: {
body: { [x: string]: unknown } | { [y: string]: unknown }[]
url: string
}) {
super('The request took too long to respond.', {
details: 'The request timed out.',
metaMessages: [`URL: ${getUrl(url)}`, `Request body: ${stringify(body)}`],
name: 'TimeoutError',
})
this.url = url
}
}

683
node_modules/viem/errors/rpc.ts generated vendored Normal file
View File

@@ -0,0 +1,683 @@
import type { Prettify } from '../types/utils.js'
import { BaseError } from './base.js'
import { RpcRequestError } from './request.js'
const unknownErrorCode = -1
export type RpcErrorCode =
| -1
| -32700 // Parse error
| -32600 // Invalid request
| -32601 // Method not found
| -32602 // Invalid params
| -32603 // Internal error
| -32000 // Invalid input
| -32001 // Resource not found
| -32002 // Resource unavailable
| -32003 // Transaction rejected
| -32004 // Method not supported
| -32005 // Limit exceeded
| -32006 // JSON-RPC version not supported
| -32042 // Method not found
type RpcErrorOptions<code extends number = RpcErrorCode> = {
code?: code | (number & {}) | undefined
docsPath?: string | undefined
metaMessages?: string[] | undefined
name?: string | undefined
shortMessage: string
}
/**
* Error subclass implementing JSON RPC 2.0 errors and Ethereum RPC errors per EIP-1474.
*
* - EIP https://eips.ethereum.org/EIPS/eip-1474
*/
export type RpcErrorType = RpcError & { name: 'RpcError' }
export class RpcError<code_ extends number = RpcErrorCode> extends BaseError {
code: code_ | (number & {})
constructor(
cause: Error,
{
code,
docsPath,
metaMessages,
name,
shortMessage,
}: RpcErrorOptions<code_>,
) {
super(shortMessage, {
cause,
docsPath,
metaMessages:
metaMessages || (cause as { metaMessages?: string[] })?.metaMessages,
name: name || 'RpcError',
})
this.name = name || cause.name
this.code = (
cause instanceof RpcRequestError ? cause.code : (code ?? unknownErrorCode)
) as code_
}
}
export type ProviderRpcErrorCode =
| 4001 // User Rejected Request
| 4100 // Unauthorized
| 4200 // Unsupported Method
| 4900 // Disconnected
| 4901 // Chain Disconnected
| 4902 // Chain Not Recognized
| 5700 // Unsupported non-optional capability
| 5710 // Unsupported chain id
| 5720 // Duplicate ID
| 5730 // Unknown bundle id
| 5740 // Bundle too large
| 5750 // Atomic-ready wallet rejected upgrade
| 5760 // Atomicity not supported
| 7000 // WalletConnect Session Settlement Failed
/**
* Error subclass implementing Ethereum Provider errors per EIP-1193.
*
* - EIP https://eips.ethereum.org/EIPS/eip-1193
*/
export type ProviderRpcErrorType = ProviderRpcError & {
name: 'ProviderRpcError'
}
export class ProviderRpcError<
T = undefined,
> extends RpcError<ProviderRpcErrorCode> {
data?: T | undefined
constructor(
cause: Error,
options: Prettify<
RpcErrorOptions<ProviderRpcErrorCode> & {
data?: T | undefined
}
>,
) {
super(cause, options)
this.data = options.data
}
}
/**
* Subclass for a "Parse error" EIP-1474 error.
*
* EIP https://eips.ethereum.org/EIPS/eip-1474#error-codes
*/
export type ParseRpcErrorType = ParseRpcError & {
code: -32700
name: 'ParseRpcError'
}
export class ParseRpcError extends RpcError {
static code = -32700 as const
constructor(cause: Error) {
super(cause, {
code: ParseRpcError.code,
name: 'ParseRpcError',
shortMessage:
'Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text.',
})
}
}
/**
* Subclass for a "Invalid request" EIP-1474 error.
*
* EIP https://eips.ethereum.org/EIPS/eip-1474#error-codes
*/
export type InvalidRequestRpcErrorType = InvalidRequestRpcError & {
code: -32600
name: 'InvalidRequestRpcError'
}
export class InvalidRequestRpcError extends RpcError {
static code = -32600 as const
constructor(cause: Error) {
super(cause, {
code: InvalidRequestRpcError.code,
name: 'InvalidRequestRpcError',
shortMessage: 'JSON is not a valid request object.',
})
}
}
/**
* Subclass for a "Method not found" EIP-1474 error.
*
* EIP https://eips.ethereum.org/EIPS/eip-1474#error-codes
*/
export type MethodNotFoundRpcErrorType = MethodNotFoundRpcError & {
code: -32601
name: 'MethodNotFoundRpcError'
}
export class MethodNotFoundRpcError extends RpcError {
static code = -32601 as const
constructor(cause: Error, { method }: { method?: string } = {}) {
super(cause, {
code: MethodNotFoundRpcError.code,
name: 'MethodNotFoundRpcError',
shortMessage: `The method${method ? ` "${method}"` : ''} does not exist / is not available.`,
})
}
}
/**
* Subclass for an "Invalid params" EIP-1474 error.
*
* EIP https://eips.ethereum.org/EIPS/eip-1474#error-codes
*/
export type InvalidParamsRpcErrorType = InvalidParamsRpcError & {
code: -32602
name: 'InvalidParamsRpcError'
}
export class InvalidParamsRpcError extends RpcError {
static code = -32602 as const
constructor(cause: Error) {
super(cause, {
code: InvalidParamsRpcError.code,
name: 'InvalidParamsRpcError',
shortMessage: [
'Invalid parameters were provided to the RPC method.',
'Double check you have provided the correct parameters.',
].join('\n'),
})
}
}
/**
* Subclass for an "Internal error" EIP-1474 error.
*
* EIP https://eips.ethereum.org/EIPS/eip-1474#error-codes
*/
export type InternalRpcErrorType = InternalRpcError & {
code: -32603
name: 'InternalRpcError'
}
export class InternalRpcError extends RpcError {
static code = -32603 as const
constructor(cause: Error) {
super(cause, {
code: InternalRpcError.code,
name: 'InternalRpcError',
shortMessage: 'An internal error was received.',
})
}
}
/**
* Subclass for an "Invalid input" EIP-1474 error.
*
* EIP https://eips.ethereum.org/EIPS/eip-1474#error-codes
*/
export type InvalidInputRpcErrorType = InvalidInputRpcError & {
code: -32000
name: 'InvalidInputRpcError'
}
export class InvalidInputRpcError extends RpcError {
static code = -32000 as const
constructor(cause: Error) {
super(cause, {
code: InvalidInputRpcError.code,
name: 'InvalidInputRpcError',
shortMessage: [
'Missing or invalid parameters.',
'Double check you have provided the correct parameters.',
].join('\n'),
})
}
}
/**
* Subclass for a "Resource not found" EIP-1474 error.
*
* EIP https://eips.ethereum.org/EIPS/eip-1474#error-codes
*/
export type ResourceNotFoundRpcErrorType = ResourceNotFoundRpcError & {
code: -32001
name: 'ResourceNotFoundRpcError'
}
export class ResourceNotFoundRpcError extends RpcError {
override name = 'ResourceNotFoundRpcError'
static code = -32001 as const
constructor(cause: Error) {
super(cause, {
code: ResourceNotFoundRpcError.code,
name: 'ResourceNotFoundRpcError',
shortMessage: 'Requested resource not found.',
})
}
}
/**
* Subclass for a "Resource unavailable" EIP-1474 error.
*
* EIP https://eips.ethereum.org/EIPS/eip-1474#error-codes
*/
export type ResourceUnavailableRpcErrorType = ResourceUnavailableRpcError & {
code: -32002
name: 'ResourceUnavailableRpcError'
}
export class ResourceUnavailableRpcError extends RpcError {
static code = -32002 as const
constructor(cause: Error) {
super(cause, {
code: ResourceUnavailableRpcError.code,
name: 'ResourceUnavailableRpcError',
shortMessage: 'Requested resource not available.',
})
}
}
/**
* Subclass for a "Transaction rejected" EIP-1474 error.
*
* EIP https://eips.ethereum.org/EIPS/eip-1474#error-codes
*/
export type TransactionRejectedRpcErrorType = TransactionRejectedRpcError & {
code: -32003
name: 'TransactionRejectedRpcError'
}
export class TransactionRejectedRpcError extends RpcError {
static code = -32003 as const
constructor(cause: Error) {
super(cause, {
code: TransactionRejectedRpcError.code,
name: 'TransactionRejectedRpcError',
shortMessage: 'Transaction creation failed.',
})
}
}
/**
* Subclass for a "Method not supported" EIP-1474 error.
*
* EIP https://eips.ethereum.org/EIPS/eip-1474#error-codes
*/
export type MethodNotSupportedRpcErrorType = MethodNotSupportedRpcError & {
code: -32004
name: 'MethodNotSupportedRpcError'
}
export class MethodNotSupportedRpcError extends RpcError {
static code = -32004 as const
constructor(cause: Error, { method }: { method?: string } = {}) {
super(cause, {
code: MethodNotSupportedRpcError.code,
name: 'MethodNotSupportedRpcError',
shortMessage: `Method${method ? ` "${method}"` : ''} is not supported.`,
})
}
}
/**
* Subclass for a "Limit exceeded" EIP-1474 error.
*
* EIP https://eips.ethereum.org/EIPS/eip-1474#error-codes
*/
export type LimitExceededRpcErrorType = LimitExceededRpcError & {
code: -32005
name: 'LimitExceededRpcError'
}
export class LimitExceededRpcError extends RpcError {
static code = -32005 as const
constructor(cause: Error) {
super(cause, {
code: LimitExceededRpcError.code,
name: 'LimitExceededRpcError',
shortMessage: 'Request exceeds defined limit.',
})
}
}
/**
* Subclass for a "JSON-RPC version not supported" EIP-1474 error.
*
* EIP https://eips.ethereum.org/EIPS/eip-1474#error-codes
*/
export type JsonRpcVersionUnsupportedErrorType =
JsonRpcVersionUnsupportedError & {
code: -32006
name: 'JsonRpcVersionUnsupportedError'
}
export class JsonRpcVersionUnsupportedError extends RpcError {
static code = -32006 as const
constructor(cause: Error) {
super(cause, {
code: JsonRpcVersionUnsupportedError.code,
name: 'JsonRpcVersionUnsupportedError',
shortMessage: 'Version of JSON-RPC protocol is not supported.',
})
}
}
/**
* Subclass for a "User Rejected Request" EIP-1193 error.
*
* EIP https://eips.ethereum.org/EIPS/eip-1193#provider-errors
*/
export type UserRejectedRequestErrorType = UserRejectedRequestError & {
code: 4001
name: 'UserRejectedRequestError'
}
export class UserRejectedRequestError extends ProviderRpcError {
static code = 4001 as const
constructor(cause: Error) {
super(cause, {
code: UserRejectedRequestError.code,
name: 'UserRejectedRequestError',
shortMessage: 'User rejected the request.',
})
}
}
/**
* Subclass for an "Unauthorized" EIP-1193 error.
*
* EIP https://eips.ethereum.org/EIPS/eip-1193#provider-errors
*/
export type UnauthorizedProviderErrorType = UnauthorizedProviderError & {
code: 4100
name: 'UnauthorizedProviderError'
}
export class UnauthorizedProviderError extends ProviderRpcError {
static code = 4100 as const
constructor(cause: Error) {
super(cause, {
code: UnauthorizedProviderError.code,
name: 'UnauthorizedProviderError',
shortMessage:
'The requested method and/or account has not been authorized by the user.',
})
}
}
/**
* Subclass for an "Unsupported Method" EIP-1193 error.
*
* EIP https://eips.ethereum.org/EIPS/eip-1193#provider-errors
*/
export type UnsupportedProviderMethodErrorType =
UnsupportedProviderMethodError & {
code: 4200
name: 'UnsupportedProviderMethodError'
}
export class UnsupportedProviderMethodError extends ProviderRpcError {
static code = 4200 as const
constructor(cause: Error, { method }: { method?: string } = {}) {
super(cause, {
code: UnsupportedProviderMethodError.code,
name: 'UnsupportedProviderMethodError',
shortMessage: `The Provider does not support the requested method${method ? ` " ${method}"` : ''}.`,
})
}
}
/**
* Subclass for an "Disconnected" EIP-1193 error.
*
* EIP https://eips.ethereum.org/EIPS/eip-1193#provider-errors
*/
export type ProviderDisconnectedErrorType = ProviderDisconnectedError & {
code: 4900
name: 'ProviderDisconnectedError'
}
export class ProviderDisconnectedError extends ProviderRpcError {
static code = 4900 as const
constructor(cause: Error) {
super(cause, {
code: ProviderDisconnectedError.code,
name: 'ProviderDisconnectedError',
shortMessage: 'The Provider is disconnected from all chains.',
})
}
}
/**
* Subclass for an "Chain Disconnected" EIP-1193 error.
*
* EIP https://eips.ethereum.org/EIPS/eip-1193#provider-errors
*/
export type ChainDisconnectedErrorType = ChainDisconnectedError & {
code: 4901
name: 'ChainDisconnectedError'
}
export class ChainDisconnectedError extends ProviderRpcError {
static code = 4901 as const
constructor(cause: Error) {
super(cause, {
code: ChainDisconnectedError.code,
name: 'ChainDisconnectedError',
shortMessage: 'The Provider is not connected to the requested chain.',
})
}
}
/**
* Subclass for an "Switch Chain" EIP-1193 error.
*
* EIP https://eips.ethereum.org/EIPS/eip-1193#provider-errors
*/
export type SwitchChainErrorType = SwitchChainError & {
code: 4902
name: 'SwitchChainError'
}
export class SwitchChainError extends ProviderRpcError {
static code = 4902 as const
constructor(cause: Error) {
super(cause, {
code: SwitchChainError.code,
name: 'SwitchChainError',
shortMessage: 'An error occurred when attempting to switch chain.',
})
}
}
/**
* Subclass for an "Unsupported non-optional capability" EIP-5792 error.
*
* EIP https://eips.ethereum.org/EIPS/eip-5792#error-codes
*/
export type UnsupportedNonOptionalCapabilityErrorType =
UnsupportedNonOptionalCapabilityError & {
code: 5700
name: 'UnsupportedNonOptionalCapabilityError'
}
export class UnsupportedNonOptionalCapabilityError extends ProviderRpcError {
static code = 5700 as const
constructor(cause: Error) {
super(cause, {
code: UnsupportedNonOptionalCapabilityError.code,
name: 'UnsupportedNonOptionalCapabilityError',
shortMessage:
'This Wallet does not support a capability that was not marked as optional.',
})
}
}
/**
* Subclass for an "Unsupported chain id" EIP-5792 error.
*
* EIP https://eips.ethereum.org/EIPS/eip-5792#error-codes
*/
export type UnsupportedChainIdErrorType = UnsupportedChainIdError & {
code: 5710
name: 'UnsupportedChainIdError'
}
export class UnsupportedChainIdError extends ProviderRpcError {
static code = 5710 as const
constructor(cause: Error) {
super(cause, {
code: UnsupportedChainIdError.code,
name: 'UnsupportedChainIdError',
shortMessage: 'This Wallet does not support the requested chain ID.',
})
}
}
/**
* Subclass for an "Duplicate ID" EIP-5792 error.
*
* EIP https://eips.ethereum.org/EIPS/eip-5792#error-codes
*/
export type DuplicateIdErrorType = DuplicateIdError & {
code: 5720
name: 'DuplicateIdError'
}
export class DuplicateIdError extends ProviderRpcError {
static code = 5720 as const
constructor(cause: Error) {
super(cause, {
code: DuplicateIdError.code,
name: 'DuplicateIdError',
shortMessage: 'There is already a bundle submitted with this ID.',
})
}
}
/**
* Subclass for an "Unknown bundle ID" EIP-5792 error.
*
* EIP https://eips.ethereum.org/EIPS/eip-5792#error-codes
*/
export type UnknownBundleIdErrorType = UnknownBundleIdError & {
code: 5730
name: 'UnknownBundleIdError'
}
export class UnknownBundleIdError extends ProviderRpcError {
static code = 5730 as const
constructor(cause: Error) {
super(cause, {
code: UnknownBundleIdError.code,
name: 'UnknownBundleIdError',
shortMessage: 'This bundle id is unknown / has not been submitted',
})
}
}
/**
* Subclass for an "Bundle too large" EIP-5792 error.
*
* EIP https://eips.ethereum.org/EIPS/eip-5792#error-codes
*/
export type BundleTooLargeErrorType = BundleTooLargeError & {
code: 5740
name: 'BundleTooLargeError'
}
export class BundleTooLargeError extends ProviderRpcError {
static code = 5740 as const
constructor(cause: Error) {
super(cause, {
code: BundleTooLargeError.code,
name: 'BundleTooLargeError',
shortMessage: 'The call bundle is too large for the Wallet to process.',
})
}
}
/**
* Subclass for an "Atomic-ready wallet rejected upgrade" EIP-5792 error.
*
* EIP https://eips.ethereum.org/EIPS/eip-5792#error-codes
*/
export type AtomicReadyWalletRejectedUpgradeErrorType =
AtomicReadyWalletRejectedUpgradeError & {
code: 5750
name: 'AtomicReadyWalletRejectedUpgradeError'
}
export class AtomicReadyWalletRejectedUpgradeError extends ProviderRpcError {
static code = 5750 as const
constructor(cause: Error) {
super(cause, {
code: AtomicReadyWalletRejectedUpgradeError.code,
name: 'AtomicReadyWalletRejectedUpgradeError',
shortMessage:
'The Wallet can support atomicity after an upgrade, but the user rejected the upgrade.',
})
}
}
/**
* Subclass for an "Atomicity not supported" EIP-5792 error.
*
* EIP https://eips.ethereum.org/EIPS/eip-5792#error-codes
*/
export type AtomicityNotSupportedErrorType = AtomicityNotSupportedError & {
code: 5760
name: 'AtomicityNotSupportedError'
}
export class AtomicityNotSupportedError extends ProviderRpcError {
static code = 5760 as const
constructor(cause: Error) {
super(cause, {
code: AtomicityNotSupportedError.code,
name: 'AtomicityNotSupportedError',
shortMessage:
'The wallet does not support atomic execution but the request requires it.',
})
}
}
/**
* Subclass for a "Session Settlement Failed" WalletConnect error.
*
* WalletConnect https://docs.walletconnect.com/2.0/specs/clients/sign/error-codes
*/
export type WalletConnectSessionSettlementErrorType =
WalletConnectSessionSettlementError & {
code: 7000
name: 'WalletConnectSessionSettlementError'
}
export class WalletConnectSessionSettlementError extends ProviderRpcError {
static code = 7000 as const
constructor(cause: Error) {
super(cause, {
code: WalletConnectSessionSettlementError.code,
name: 'WalletConnectSessionSettlementError',
shortMessage: 'WalletConnect session settlement failed.',
})
}
}
/**
* Subclass for an unknown RPC error.
*/
export type UnknownRpcErrorType = UnknownRpcError & {
name: 'UnknownRpcError'
}
export class UnknownRpcError extends RpcError {
constructor(cause: Error) {
super(cause, {
name: 'UnknownRpcError',
shortMessage: 'An unknown RPC error occurred.',
})
}
}

19
node_modules/viem/errors/siwe.ts generated vendored Normal file
View File

@@ -0,0 +1,19 @@
import { BaseError } from './base.js'
export type SiweInvalidMessageFieldErrorType = SiweInvalidMessageFieldError & {
name: 'SiweInvalidMessageFieldError'
}
export class SiweInvalidMessageFieldError extends BaseError {
constructor(parameters: {
docsPath?: string | undefined
field: string
metaMessages?: string[] | undefined
}) {
const { docsPath, field, metaMessages } = parameters
super(`Invalid Sign-In with Ethereum message field "${field}".`, {
docsPath,
metaMessages,
name: 'SiweInvalidMessageFieldError',
})
}
}

53
node_modules/viem/errors/stateOverride.ts generated vendored Normal file
View File

@@ -0,0 +1,53 @@
import type { StateMapping, StateOverride } from '../types/stateOverride.js'
import { BaseError } from './base.js'
export type AccountStateConflictErrorType = AccountStateConflictError & {
name: 'AccountStateConflictError'
}
export class AccountStateConflictError extends BaseError {
constructor({ address }: { address: string }) {
super(`State for account "${address}" is set multiple times.`, {
name: 'AccountStateConflictError',
})
}
}
export type StateAssignmentConflictErrorType = StateAssignmentConflictError & {
name: 'StateAssignmentConflictError'
}
export class StateAssignmentConflictError extends BaseError {
constructor() {
super('state and stateDiff are set on the same account.', {
name: 'StateAssignmentConflictError',
})
}
}
/** @internal */
export function prettyStateMapping(stateMapping: StateMapping) {
return stateMapping.reduce((pretty, { slot, value }) => {
return `${pretty} ${slot}: ${value}\n`
}, '')
}
export function prettyStateOverride(stateOverride: StateOverride) {
return stateOverride
.reduce((pretty, { address, ...state }) => {
let val = `${pretty} ${address}:\n`
if (state.nonce) val += ` nonce: ${state.nonce}\n`
if (state.balance) val += ` balance: ${state.balance}\n`
if (state.code) val += ` code: ${state.code}\n`
if (state.state) {
val += ' state:\n'
val += prettyStateMapping(state.state)
}
if (state.stateDiff) {
val += ' stateDiff:\n'
val += prettyStateMapping(state.stateDiff)
}
return val
}, ' State Override:\n')
.slice(0, -1)
}

285
node_modules/viem/errors/transaction.ts generated vendored Normal file
View File

@@ -0,0 +1,285 @@
import type { Account } from '../accounts/types.js'
import type { SendTransactionParameters } from '../actions/wallet/sendTransaction.js'
import type { BlockTag } from '../types/block.js'
import type { Chain } from '../types/chain.js'
import type { Hash, Hex } from '../types/misc.js'
import type {
TransactionReceipt,
TransactionType,
} from '../types/transaction.js'
import { formatEther } from '../utils/unit/formatEther.js'
import { formatGwei } from '../utils/unit/formatGwei.js'
import { BaseError } from './base.js'
export function prettyPrint(
args: Record<string, bigint | number | string | undefined | false | unknown>,
) {
const entries = Object.entries(args)
.map(([key, value]) => {
if (value === undefined || value === false) return null
return [key, value]
})
.filter(Boolean) as [string, string][]
const maxLength = entries.reduce((acc, [key]) => Math.max(acc, key.length), 0)
return entries
.map(([key, value]) => ` ${`${key}:`.padEnd(maxLength + 1)} ${value}`)
.join('\n')
}
export type FeeConflictErrorType = FeeConflictError & {
name: 'FeeConflictError'
}
export class FeeConflictError extends BaseError {
constructor() {
super(
[
'Cannot specify both a `gasPrice` and a `maxFeePerGas`/`maxPriorityFeePerGas`.',
'Use `maxFeePerGas`/`maxPriorityFeePerGas` for EIP-1559 compatible networks, and `gasPrice` for others.',
].join('\n'),
{ name: 'FeeConflictError' },
)
}
}
export type InvalidLegacyVErrorType = InvalidLegacyVError & {
name: 'InvalidLegacyVError'
}
export class InvalidLegacyVError extends BaseError {
constructor({ v }: { v: bigint }) {
super(`Invalid \`v\` value "${v}". Expected 27 or 28.`, {
name: 'InvalidLegacyVError',
})
}
}
export type InvalidSerializableTransactionErrorType =
InvalidSerializableTransactionError & {
name: 'InvalidSerializableTransactionError'
}
export class InvalidSerializableTransactionError extends BaseError {
constructor({ transaction }: { transaction: Record<string, unknown> }) {
super('Cannot infer a transaction type from provided transaction.', {
metaMessages: [
'Provided Transaction:',
'{',
prettyPrint(transaction),
'}',
'',
'To infer the type, either provide:',
'- a `type` to the Transaction, or',
'- an EIP-1559 Transaction with `maxFeePerGas`, or',
'- an EIP-2930 Transaction with `gasPrice` & `accessList`, or',
'- an EIP-4844 Transaction with `blobs`, `blobVersionedHashes`, `sidecars`, or',
'- an EIP-7702 Transaction with `authorizationList`, or',
'- a Legacy Transaction with `gasPrice`',
],
name: 'InvalidSerializableTransactionError',
})
}
}
export type InvalidSerializedTransactionTypeErrorType =
InvalidSerializedTransactionTypeError & {
name: 'InvalidSerializedTransactionTypeError'
}
export class InvalidSerializedTransactionTypeError extends BaseError {
serializedType: Hex
constructor({ serializedType }: { serializedType: Hex }) {
super(`Serialized transaction type "${serializedType}" is invalid.`, {
name: 'InvalidSerializedTransactionType',
})
this.serializedType = serializedType
}
}
export type InvalidSerializedTransactionErrorType =
InvalidSerializedTransactionError & {
name: 'InvalidSerializedTransactionError'
}
export class InvalidSerializedTransactionError extends BaseError {
serializedTransaction: Hex
type: TransactionType
constructor({
attributes,
serializedTransaction,
type,
}: {
attributes: Record<string, unknown>
serializedTransaction: Hex
type: TransactionType
}) {
const missing = Object.entries(attributes)
.map(([key, value]) => (typeof value === 'undefined' ? key : undefined))
.filter(Boolean)
super(`Invalid serialized transaction of type "${type}" was provided.`, {
metaMessages: [
`Serialized Transaction: "${serializedTransaction}"`,
missing.length > 0 ? `Missing Attributes: ${missing.join(', ')}` : '',
].filter(Boolean),
name: 'InvalidSerializedTransactionError',
})
this.serializedTransaction = serializedTransaction
this.type = type
}
}
export type InvalidStorageKeySizeErrorType = InvalidStorageKeySizeError & {
name: 'InvalidStorageKeySizeError'
}
export class InvalidStorageKeySizeError extends BaseError {
constructor({ storageKey }: { storageKey: Hex }) {
super(
`Size for storage key "${storageKey}" is invalid. Expected 32 bytes. Got ${Math.floor(
(storageKey.length - 2) / 2,
)} bytes.`,
{ name: 'InvalidStorageKeySizeError' },
)
}
}
export type TransactionExecutionErrorType = TransactionExecutionError & {
name: 'TransactionExecutionError'
}
export class TransactionExecutionError extends BaseError {
override cause: BaseError
constructor(
cause: BaseError,
{
account,
docsPath,
chain,
data,
gas,
gasPrice,
maxFeePerGas,
maxPriorityFeePerGas,
nonce,
to,
value,
}: Omit<SendTransactionParameters, 'account' | 'chain'> & {
account: Account | null
chain?: Chain | undefined
docsPath?: string | undefined
},
) {
const prettyArgs = prettyPrint({
chain: chain && `${chain?.name} (id: ${chain?.id})`,
from: account?.address,
to,
value:
typeof value !== 'undefined' &&
`${formatEther(value)} ${chain?.nativeCurrency?.symbol || 'ETH'}`,
data,
gas,
gasPrice:
typeof gasPrice !== 'undefined' && `${formatGwei(gasPrice)} gwei`,
maxFeePerGas:
typeof maxFeePerGas !== 'undefined' &&
`${formatGwei(maxFeePerGas)} gwei`,
maxPriorityFeePerGas:
typeof maxPriorityFeePerGas !== 'undefined' &&
`${formatGwei(maxPriorityFeePerGas)} gwei`,
nonce,
})
super(cause.shortMessage, {
cause,
docsPath,
metaMessages: [
...(cause.metaMessages ? [...cause.metaMessages, ' '] : []),
'Request Arguments:',
prettyArgs,
].filter(Boolean) as string[],
name: 'TransactionExecutionError',
})
this.cause = cause
}
}
export type TransactionNotFoundErrorType = TransactionNotFoundError & {
name: 'TransactionNotFoundError'
}
export class TransactionNotFoundError extends BaseError {
constructor({
blockHash,
blockNumber,
blockTag,
hash,
index,
}: {
blockHash?: Hash | undefined
blockNumber?: bigint | undefined
blockTag?: BlockTag | undefined
hash?: Hash | undefined
index?: number | undefined
}) {
let identifier = 'Transaction'
if (blockTag && index !== undefined)
identifier = `Transaction at block time "${blockTag}" at index "${index}"`
if (blockHash && index !== undefined)
identifier = `Transaction at block hash "${blockHash}" at index "${index}"`
if (blockNumber && index !== undefined)
identifier = `Transaction at block number "${blockNumber}" at index "${index}"`
if (hash) identifier = `Transaction with hash "${hash}"`
super(`${identifier} could not be found.`, {
name: 'TransactionNotFoundError',
})
}
}
export type TransactionReceiptNotFoundErrorType =
TransactionReceiptNotFoundError & {
name: 'TransactionReceiptNotFoundError'
}
export class TransactionReceiptNotFoundError extends BaseError {
constructor({ hash }: { hash: Hash }) {
super(
`Transaction receipt with hash "${hash}" could not be found. The Transaction may not be processed on a block yet.`,
{
name: 'TransactionReceiptNotFoundError',
},
)
}
}
export type TransactionReceiptRevertedErrorType =
TransactionReceiptRevertedError & {
name: 'TransactionReceiptRevertedError'
}
export class TransactionReceiptRevertedError extends BaseError {
receipt: TransactionReceipt
constructor({ receipt }: { receipt: TransactionReceipt }) {
super(`Transaction with hash "${receipt.transactionHash}" reverted.`, {
metaMessages: [
'The receipt marked the transaction as "reverted". This could mean that the function on the contract you are trying to call threw an error.',
' ',
'You can attempt to extract the revert reason by:',
'- calling the `simulateContract` or `simulateCalls` Action with the `abi` and `functionName` of the contract',
'- using the `call` Action with raw `data`',
],
name: 'TransactionReceiptRevertedError',
})
this.receipt = receipt
}
}
export type WaitForTransactionReceiptTimeoutErrorType =
WaitForTransactionReceiptTimeoutError & {
name: 'WaitForTransactionReceiptTimeoutError'
}
export class WaitForTransactionReceiptTimeoutError extends BaseError {
constructor({ hash }: { hash: Hash }) {
super(
`Timed out while waiting for transaction with hash "${hash}" to be confirmed.`,
{ name: 'WaitForTransactionReceiptTimeoutError' },
)
}
}

16
node_modules/viem/errors/transport.ts generated vendored Normal file
View File

@@ -0,0 +1,16 @@
import { BaseError } from './base.js'
export type UrlRequiredErrorType = UrlRequiredError & {
name: 'UrlRequiredError'
}
export class UrlRequiredError extends BaseError {
constructor() {
super(
'No URL was provided to the Transport. Please provide a valid RPC URL to the Transport.',
{
docsPath: '/docs/clients/intro',
name: 'UrlRequiredError',
},
)
}
}

45
node_modules/viem/errors/typedData.ts generated vendored Normal file
View File

@@ -0,0 +1,45 @@
import type { TypedData } from 'abitype'
import { stringify } from '../utils/stringify.js'
import { BaseError } from './base.js'
export type InvalidDomainErrorType = InvalidDomainError & {
name: 'InvalidDomainError'
}
export class InvalidDomainError extends BaseError {
constructor({ domain }: { domain: unknown }) {
super(`Invalid domain "${stringify(domain)}".`, {
metaMessages: ['Must be a valid EIP-712 domain.'],
})
}
}
export type InvalidPrimaryTypeErrorType = InvalidPrimaryTypeError & {
name: 'InvalidPrimaryTypeError'
}
export class InvalidPrimaryTypeError extends BaseError {
constructor({
primaryType,
types,
}: { primaryType: string; types: TypedData | Record<string, unknown> }) {
super(
`Invalid primary type \`${primaryType}\` must be one of \`${JSON.stringify(Object.keys(types))}\`.`,
{
docsPath: '/api/glossary/Errors#typeddatainvalidprimarytypeerror',
metaMessages: ['Check that the primary type is a key in `types`.'],
},
)
}
}
export type InvalidStructTypeErrorType = InvalidStructTypeError & {
name: 'InvalidStructTypeError'
}
export class InvalidStructTypeError extends BaseError {
constructor({ type }: { type: string }) {
super(`Struct type "${type}" is invalid.`, {
metaMessages: ['Struct type must not be a Solidity type.'],
name: 'InvalidStructTypeError',
})
}
}

12
node_modules/viem/errors/unit.ts generated vendored Normal file
View File

@@ -0,0 +1,12 @@
import { BaseError } from './base.js'
export type InvalidDecimalNumberErrorType = InvalidDecimalNumberError & {
name: 'InvalidDecimalNumberError'
}
export class InvalidDecimalNumberError extends BaseError {
constructor({ value }: { value: string }) {
super(`Number \`${value}\` is not a valid decimal number.`, {
name: 'InvalidDecimalNumberError',
})
}
}

6
node_modules/viem/errors/utils.ts generated vendored Normal file
View File

@@ -0,0 +1,6 @@
import type { Address } from 'abitype'
export type ErrorType<name extends string = 'Error'> = Error & { name: name }
export const getContractAddress = (address: Address) => address
export const getUrl = (url: string) => url

1
node_modules/viem/errors/version.ts generated vendored Normal file
View File

@@ -0,0 +1 @@
export const version = '2.48.4'