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

12
node_modules/viem/celo/chainConfig.ts generated vendored Normal file
View File

@@ -0,0 +1,12 @@
import { contracts } from '../op-stack/contracts.js'
import { fees } from './fees.js'
import { formatters } from './formatters.js'
import { serializers } from './serializers.js'
export const chainConfig = {
blockTime: 1_000,
contracts,
formatters,
serializers,
fees,
} as const

95
node_modules/viem/celo/fees.ts generated vendored Normal file
View File

@@ -0,0 +1,95 @@
import type { Client } from '../clients/createClient.js'
import type {
Address,
ChainEstimateFeesPerGasFnParameters,
ChainFees,
Hex,
} from '../index.js'
import type { formatters } from './formatters.js'
export const fees: ChainFees<typeof formatters> = {
/*
* Estimates the fees per gas for a transaction.
* If the transaction is to be paid in a token (feeCurrency is present) then the fees
* are estimated in the value of the token. Otherwise falls back to the default
* estimation by returning null.
*
* @param params fee estimation function parameters
*/
estimateFeesPerGas: async (
params: ChainEstimateFeesPerGasFnParameters<typeof formatters>,
) => {
if (!params.request?.feeCurrency) return null
const [gasPrice, maxPriorityFeePerGas] = await Promise.all([
estimateFeePerGasInFeeCurrency(params.client, params.request.feeCurrency),
estimateMaxPriorityFeePerGasInFeeCurrency(
params.client,
params.request.feeCurrency,
),
])
// eth_gasPrice for cel2 returns baseFeePerGas + maxPriorityFeePerGas
const maxFeePerGas =
params.multiply(gasPrice - maxPriorityFeePerGas) + maxPriorityFeePerGas
return {
maxFeePerGas,
maxPriorityFeePerGas,
}
},
}
type RequestGasPriceInFeeCurrencyParams = {
Method: 'eth_gasPrice'
Parameters: [Address]
ReturnType: Hex
}
/*
* Estimate the fee per gas in the value of the fee token
*
* @param client - Client to use
* @param feeCurrency - Address of a whitelisted fee token
* @returns The fee per gas in wei in the value of the fee token
*
*/
async function estimateFeePerGasInFeeCurrency(
client: Client,
feeCurrency: Address,
) {
const fee = await client.request<RequestGasPriceInFeeCurrencyParams>({
method: 'eth_gasPrice',
params: [feeCurrency],
})
return BigInt(fee)
}
type RequestMaxGasPriceInFeeCurrencyParams = {
Method: 'eth_maxPriorityFeePerGas'
Parameters: [Address]
ReturnType: Hex
}
/*
* Estimate the max priority fee per gas in the value of the fee token
*
* @param client - Client to use
* @param feeCurrency - Address of a whitelisted fee token
* @returns The fee per gas in wei in the value of the fee token
*
*/
async function estimateMaxPriorityFeePerGasInFeeCurrency(
client: Client,
feeCurrency: Address,
) {
const feesPerGas =
await client.request<RequestMaxGasPriceInFeeCurrencyParams>({
method: 'eth_maxPriorityFeePerGas',
params: [feeCurrency],
})
return BigInt(feesPerGas)
}

77
node_modules/viem/celo/formatters.ts generated vendored Normal file
View File

@@ -0,0 +1,77 @@
import type { ChainFormatters } from '../types/chain.js'
import type { RpcTransaction } from '../types/rpc.js'
import { hexToBigInt } from '../utils/encoding/fromHex.js'
import { defineBlock } from '../utils/formatters/block.js'
import {
defineTransaction,
formatTransaction,
} from '../utils/formatters/transaction.js'
import { defineTransactionRequest } from '../utils/formatters/transactionRequest.js'
import type {
CeloBlock,
CeloRpcBlock,
CeloRpcTransaction,
CeloRpcTransactionRequest,
CeloTransaction,
CeloTransactionRequest,
} from './types.js'
import { isCIP64 } from './utils.js'
export const formatters = {
block: /*#__PURE__*/ defineBlock({
format(args: CeloRpcBlock): CeloBlock {
const transactions = args.transactions?.map((transaction) => {
if (typeof transaction === 'string') return transaction
const formatted = formatTransaction(transaction as RpcTransaction)
return {
...formatted,
...(transaction.gatewayFee
? {
gatewayFee: hexToBigInt(transaction.gatewayFee),
gatewayFeeRecipient: transaction.gatewayFeeRecipient,
}
: {}),
feeCurrency: transaction.feeCurrency,
}
})
return {
transactions,
} as CeloBlock
},
}),
transaction: /*#__PURE__*/ defineTransaction({
format(args: CeloRpcTransaction): CeloTransaction {
if (args.type === '0x7e')
return {
isSystemTx: args.isSystemTx,
mint: args.mint ? hexToBigInt(args.mint) : undefined,
sourceHash: args.sourceHash,
type: 'deposit',
} as CeloTransaction
const transaction = { feeCurrency: args.feeCurrency } as CeloTransaction
if (args.type === '0x7b') transaction.type = 'cip64'
else {
if (args.type === '0x7c') transaction.type = 'cip42'
transaction.gatewayFee = args.gatewayFee
? hexToBigInt(args.gatewayFee)
: null
transaction.gatewayFeeRecipient = args.gatewayFeeRecipient
}
return transaction
},
}),
transactionRequest: /*#__PURE__*/ defineTransactionRequest({
format(args: CeloTransactionRequest): CeloRpcTransactionRequest {
const request = {} as CeloRpcTransactionRequest
if (args.feeCurrency) request.feeCurrency = args.feeCurrency
if (isCIP64(args)) request.type = '0x7b'
return request
},
}),
} as const satisfies ChainFormatters

31
node_modules/viem/celo/index.ts generated vendored Normal file
View File

@@ -0,0 +1,31 @@
// biome-ignore lint/performance/noBarrelFile: entrypoint module
export { chainConfig } from './chainConfig.js'
export { type ParseTransactionReturnType, parseTransaction } from './parsers.js'
export {
type SerializeTransactionCIP64ReturnType,
serializeTransaction,
} from './serializers.js'
export type {
CeloBlock,
CeloRpcBlock,
CeloRpcTransaction,
CeloRpcTransactionRequest,
CeloTransaction,
CeloTransactionRequest,
CeloTransactionSerializable,
CeloTransactionSerialized,
CeloTransactionType,
RpcTransactionCIP42,
RpcTransactionCIP64,
RpcTransactionRequestCIP64,
TransactionCIP42,
TransactionCIP64,
TransactionRequestCIP64,
TransactionSerializableCIP42,
TransactionSerializableCIP64,
TransactionSerializedCIP42,
TransactionSerializedCIP64,
} from './types.js'

6
node_modules/viem/celo/package.json generated vendored Normal file
View File

@@ -0,0 +1,6 @@
{
"type": "module",
"types": "../_types/celo/index.d.ts",
"module": "../_esm/celo/index.js",
"main": "../_cjs/celo/index.js"
}

204
node_modules/viem/celo/parsers.ts generated vendored Normal file
View File

@@ -0,0 +1,204 @@
import type { OpStackTransactionSerialized } from '../chains/index.js'
import { InvalidSerializedTransactionError } from '../errors/transaction.js'
import { parseTransaction as parseTransaction_op } from '../op-stack/parsers.js'
import type { Hex } from '../types/misc.js'
import type { ExactPartial } from '../types/utils.js'
import { isHex } from '../utils/data/isHex.js'
import { sliceHex } from '../utils/data/slice.js'
import { hexToBigInt, hexToNumber } from '../utils/encoding/fromHex.js'
import type { RecursiveArray } from '../utils/encoding/toRlp.js'
import type { GetSerializedTransactionType } from '../utils/transaction/getSerializedTransactionType.js'
import {
type ParseTransactionReturnType as ParseTransactionReturnType_,
parseAccessList,
toTransactionArray,
} from '../utils/transaction/parseTransaction.js'
import {
assertTransactionCIP42,
assertTransactionCIP64,
} from './serializers.js'
import type {
CeloTransactionSerialized,
CeloTransactionType,
TransactionSerializableCIP42,
TransactionSerializableCIP64,
TransactionSerializedCIP42,
TransactionSerializedCIP64,
} from './types.js'
export type ParseTransactionReturnType<
serialized extends CeloTransactionSerialized = CeloTransactionSerialized,
type extends CeloTransactionType = GetSerializedTransactionType<serialized>,
> = serialized extends TransactionSerializedCIP42
? TransactionSerializableCIP42
: ParseTransactionReturnType_<serialized, type>
export function parseTransaction<serialized extends CeloTransactionSerialized>(
serializedTransaction: serialized,
): ParseTransactionReturnType<serialized> {
const serializedType = sliceHex(serializedTransaction, 0, 1)
if (serializedType === '0x7c')
return parseTransactionCIP42(
serializedTransaction as TransactionSerializedCIP42,
) as ParseTransactionReturnType<serialized>
if (serializedType === '0x7b')
return parseTransactionCIP64(
serializedTransaction as TransactionSerializedCIP64,
) as ParseTransactionReturnType<serialized>
return parseTransaction_op(
serializedTransaction as OpStackTransactionSerialized,
) as ParseTransactionReturnType<serialized>
}
function parseTransactionCIP42(
serializedTransaction: TransactionSerializedCIP42,
): TransactionSerializableCIP42 {
const transactionArray = toTransactionArray(serializedTransaction)
const [
chainId,
nonce,
maxPriorityFeePerGas,
maxFeePerGas,
gas,
feeCurrency,
gatewayFeeRecipient,
gatewayFee,
to,
value,
data,
accessList,
v,
r,
s,
] = transactionArray
if (transactionArray.length !== 15 && transactionArray.length !== 12) {
throw new InvalidSerializedTransactionError({
attributes: {
chainId,
nonce,
maxPriorityFeePerGas,
maxFeePerGas,
gas,
feeCurrency,
to,
gatewayFeeRecipient,
gatewayFee,
value,
data,
accessList,
...(transactionArray.length > 12
? {
v,
r,
s,
}
: {}),
},
serializedTransaction,
type: 'cip42',
})
}
const transaction: ExactPartial<TransactionSerializableCIP42> = {
chainId: hexToNumber(chainId as Hex),
type: 'cip42',
}
if (isHex(to) && to !== '0x') transaction.to = to
if (isHex(gas) && gas !== '0x') transaction.gas = hexToBigInt(gas)
if (isHex(data) && data !== '0x') transaction.data = data
if (isHex(nonce) && nonce !== '0x') transaction.nonce = hexToNumber(nonce)
if (isHex(value) && value !== '0x') transaction.value = hexToBigInt(value)
if (isHex(feeCurrency) && feeCurrency !== '0x')
transaction.feeCurrency = feeCurrency
if (isHex(gatewayFeeRecipient) && gatewayFeeRecipient !== '0x')
transaction.gatewayFeeRecipient = gatewayFeeRecipient
if (isHex(gatewayFee) && gatewayFee !== '0x')
transaction.gatewayFee = hexToBigInt(gatewayFee)
if (isHex(maxFeePerGas) && maxFeePerGas !== '0x')
transaction.maxFeePerGas = hexToBigInt(maxFeePerGas)
if (isHex(maxPriorityFeePerGas) && maxPriorityFeePerGas !== '0x')
transaction.maxPriorityFeePerGas = hexToBigInt(maxPriorityFeePerGas)
if (accessList.length !== 0 && accessList !== '0x')
transaction.accessList = parseAccessList(accessList as RecursiveArray<Hex>)
assertTransactionCIP42(transaction as TransactionSerializableCIP42)
return transaction as TransactionSerializableCIP42
}
function parseTransactionCIP64(
serializedTransaction: TransactionSerializedCIP64,
): TransactionSerializableCIP64 {
const transactionArray = toTransactionArray(serializedTransaction)
const [
chainId,
nonce,
maxPriorityFeePerGas,
maxFeePerGas,
gas,
to,
value,
data,
accessList,
feeCurrency,
v,
r,
s,
] = transactionArray
if (transactionArray.length !== 13 && transactionArray.length !== 10) {
throw new InvalidSerializedTransactionError({
attributes: {
chainId,
nonce,
maxPriorityFeePerGas,
maxFeePerGas,
gas,
to,
value,
data,
accessList,
feeCurrency,
...(transactionArray.length > 10
? {
v,
r,
s,
}
: {}),
},
serializedTransaction,
type: 'cip64',
})
}
const transaction: ExactPartial<TransactionSerializableCIP64> = {
chainId: hexToNumber(chainId as Hex),
type: 'cip64',
}
if (isHex(to) && to !== '0x') transaction.to = to
if (isHex(gas) && gas !== '0x') transaction.gas = hexToBigInt(gas)
if (isHex(data) && data !== '0x') transaction.data = data
if (isHex(nonce) && nonce !== '0x') transaction.nonce = hexToNumber(nonce)
if (isHex(value) && value !== '0x') transaction.value = hexToBigInt(value)
if (isHex(feeCurrency) && feeCurrency !== '0x')
transaction.feeCurrency = feeCurrency
if (isHex(maxFeePerGas) && maxFeePerGas !== '0x')
transaction.maxFeePerGas = hexToBigInt(maxFeePerGas)
if (isHex(maxPriorityFeePerGas) && maxPriorityFeePerGas !== '0x')
transaction.maxPriorityFeePerGas = hexToBigInt(maxPriorityFeePerGas)
if (accessList.length !== 0 && accessList !== '0x')
transaction.accessList = parseAccessList(accessList as RecursiveArray<Hex>)
assertTransactionCIP64(transaction as TransactionSerializableCIP64)
return transaction as TransactionSerializableCIP64
}

178
node_modules/viem/celo/serializers.ts generated vendored Normal file
View File

@@ -0,0 +1,178 @@
import { maxUint256 } from '../constants/number.js'
import { InvalidAddressError } from '../errors/address.js'
import { BaseError } from '../errors/base.js'
import { InvalidChainIdError } from '../errors/chain.js'
import { FeeCapTooHighError, TipAboveFeeCapError } from '../errors/node.js'
import { serializeTransaction as serializeTransaction_op } from '../op-stack/serializers.js'
import type { ChainSerializers } from '../types/chain.js'
import type { Signature } from '../types/misc.js'
import { isAddress } from '../utils/address/isAddress.js'
import { concatHex } from '../utils/data/concat.js'
import { toHex } from '../utils/encoding/toHex.js'
import { toRlp } from '../utils/encoding/toRlp.js'
import { serializeAccessList } from '../utils/transaction/serializeAccessList.js'
import { toYParitySignatureArray } from '../utils/transaction/serializeTransaction.js'
import type {
CeloTransactionSerializable,
TransactionSerializableCIP42,
TransactionSerializableCIP64,
TransactionSerializedCIP64,
} from './types.js'
import { isCIP64, isEmpty, isPresent } from './utils.js'
export function serializeTransaction(
transaction: CeloTransactionSerializable,
signature?: Signature | undefined,
) {
if (isCIP64(transaction))
return serializeTransactionCIP64(transaction, signature)
return serializeTransaction_op(transaction, signature)
}
export const serializers = {
transaction: serializeTransaction,
} as const satisfies ChainSerializers
//////////////////////////////////////////////////////////////////////////////
// Serializers
export type SerializeTransactionCIP64ReturnType = TransactionSerializedCIP64
function serializeTransactionCIP64(
transaction: TransactionSerializableCIP64,
signature?: Signature | undefined,
): SerializeTransactionCIP64ReturnType {
assertTransactionCIP64(transaction)
const {
chainId,
gas,
nonce,
to,
value,
maxFeePerGas,
maxPriorityFeePerGas,
accessList,
feeCurrency,
data,
} = transaction
const serializedTransaction = [
toHex(chainId),
nonce ? toHex(nonce) : '0x',
maxPriorityFeePerGas ? toHex(maxPriorityFeePerGas) : '0x',
maxFeePerGas ? toHex(maxFeePerGas) : '0x',
gas ? toHex(gas) : '0x',
to ?? '0x',
value ? toHex(value) : '0x',
data ?? '0x',
serializeAccessList(accessList),
feeCurrency!,
...toYParitySignatureArray(transaction, signature),
]
return concatHex([
'0x7b',
toRlp(serializedTransaction),
]) as SerializeTransactionCIP64ReturnType
}
// maxFeePerGas must be less than maxUint256
const MAX_MAX_FEE_PER_GAS = maxUint256
export function assertTransactionCIP42(
transaction: TransactionSerializableCIP42,
) {
const {
chainId,
maxPriorityFeePerGas,
gasPrice,
maxFeePerGas,
to,
feeCurrency,
gatewayFee,
gatewayFeeRecipient,
} = transaction
if (chainId <= 0) throw new InvalidChainIdError({ chainId })
if (to && !isAddress(to)) throw new InvalidAddressError({ address: to })
if (gasPrice)
throw new BaseError(
'`gasPrice` is not a valid CIP-42 Transaction attribute.',
)
if (isPresent(maxFeePerGas) && maxFeePerGas > MAX_MAX_FEE_PER_GAS)
throw new FeeCapTooHighError({ maxFeePerGas })
if (
isPresent(maxPriorityFeePerGas) &&
isPresent(maxFeePerGas) &&
maxPriorityFeePerGas > maxFeePerGas
)
throw new TipAboveFeeCapError({ maxFeePerGas, maxPriorityFeePerGas })
if (
(isPresent(gatewayFee) && isEmpty(gatewayFeeRecipient)) ||
(isPresent(gatewayFeeRecipient) && isEmpty(gatewayFee))
) {
throw new BaseError(
'`gatewayFee` and `gatewayFeeRecipient` must be provided together.',
)
}
if (isPresent(feeCurrency) && !isAddress(feeCurrency)) {
throw new BaseError(
'`feeCurrency` MUST be a token address for CIP-42 transactions.',
)
}
if (isPresent(gatewayFeeRecipient) && !isAddress(gatewayFeeRecipient)) {
throw new InvalidAddressError(gatewayFeeRecipient)
}
if (isEmpty(feeCurrency) && isEmpty(gatewayFeeRecipient)) {
throw new BaseError(
'Either `feeCurrency` or `gatewayFeeRecipient` must be provided for CIP-42 transactions.',
)
}
}
export function assertTransactionCIP64(
transaction: TransactionSerializableCIP64,
) {
const {
chainId,
maxPriorityFeePerGas,
gasPrice,
maxFeePerGas,
to,
feeCurrency,
} = transaction
if (chainId <= 0) throw new InvalidChainIdError({ chainId })
if (to && !isAddress(to)) throw new InvalidAddressError({ address: to })
if (gasPrice)
throw new BaseError(
'`gasPrice` is not a valid CIP-64 Transaction attribute.',
)
if (isPresent(maxFeePerGas) && maxFeePerGas > MAX_MAX_FEE_PER_GAS)
throw new FeeCapTooHighError({ maxFeePerGas })
if (
isPresent(maxPriorityFeePerGas) &&
isPresent(maxFeePerGas) &&
maxPriorityFeePerGas > maxFeePerGas
)
throw new TipAboveFeeCapError({ maxFeePerGas, maxPriorityFeePerGas })
if (isPresent(feeCurrency) && !isAddress(feeCurrency)) {
throw new BaseError(
'`feeCurrency` MUST be a token address for CIP-64 transactions.',
)
}
if (isEmpty(feeCurrency)) {
throw new BaseError(
'`feeCurrency` must be provided for CIP-64 transactions.',
)
}
}

191
node_modules/viem/celo/types.ts generated vendored Normal file
View File

@@ -0,0 +1,191 @@
import type { Address } from 'abitype'
import type {
OpStackDepositTransaction,
OpStackRpcTransaction,
TransactionSerializableDeposit,
TransactionSerializedDeposit,
} from '../op-stack/types/transaction.js'
import type { Block, BlockTag } from '../types/block.js'
import type { FeeValuesEIP1559 } from '../types/fee.js'
import type { Hex } from '../types/misc.js'
import type {
RpcTransaction as core_RpcTransaction,
RpcTransactionRequest as core_RpcTransactionRequest,
Index,
Quantity,
RpcBlock,
TransactionType,
} from '../types/rpc.js'
import type {
AccessList,
Transaction as core_Transaction,
TransactionRequest as core_TransactionRequest,
TransactionBase,
TransactionRequestBase,
TransactionSerializable,
TransactionSerializableBase,
TransactionSerialized,
} from '../types/transaction.js'
import type { ExactPartial, OneOf } from '../types/utils.js'
export type CeloBlock<
includeTransactions extends boolean = boolean,
blockTag extends BlockTag = BlockTag,
> = Block<
bigint,
includeTransactions,
blockTag,
CeloTransaction<blockTag extends 'pending' ? true : false>
>
export type CeloRpcBlock<
blockTag extends BlockTag = BlockTag,
includeTransactions extends boolean = boolean,
> = RpcBlock<
blockTag,
includeTransactions,
RpcTransaction<blockTag extends 'pending' ? true : false>
>
export type CeloRpcTransaction<isPending extends boolean = boolean> = OneOf<
| RpcTransaction<isPending>
| RpcTransactionCIP42<isPending>
| RpcTransactionCIP64<isPending>
| OpStackRpcTransaction<isPending>
>
export type CeloRpcTransactionRequest = OneOf<
RpcTransactionRequest | RpcTransactionRequestCIP64
>
export type CeloTransaction<isPending extends boolean = boolean> = OneOf<
| Transaction<isPending>
| TransactionCIP42<isPending>
| TransactionCIP64<isPending>
| OpStackDepositTransaction<isPending>
>
export type CeloTransactionRequest = OneOf<
TransactionRequest | TransactionRequestCIP64
>
export type CeloTransactionSerializable = OneOf<
| TransactionSerializable
| TransactionSerializableCIP64
| TransactionSerializableDeposit
>
export type CeloTransactionSerialized<
type extends CeloTransactionType = CeloTransactionType,
> =
| TransactionSerialized<type>
| TransactionSerializedCIP42
| TransactionSerializedCIP64
| TransactionSerializedDeposit
export type CeloTransactionType = TransactionType | 'cip42' | 'cip64'
type RpcTransaction<isPending extends boolean = boolean> =
core_RpcTransaction<isPending> & {
feeCurrency: Address | null
gatewayFee: Hex | null
gatewayFeeRecipient: Address | null
}
type RpcTransactionRequest = core_RpcTransactionRequest & {
feeCurrency?: Address | undefined
}
export type RpcTransactionCIP42<isPending extends boolean = boolean> = Omit<
TransactionBase<Quantity, Index, isPending>,
'typeHex'
> & {
accessList: AccessList
chainId: Index
feeCurrency: Address | null
gatewayFee: Hex | null
gatewayFeeRecipient: Address | null
type: '0x7c'
} & FeeValuesEIP1559<Quantity>
export type RpcTransactionCIP64<isPending extends boolean = boolean> = Omit<
TransactionBase<Quantity, Index, isPending>,
'typeHex'
> & {
accessList: AccessList
chainId: Index
feeCurrency: Address | null
type: '0x7b'
} & FeeValuesEIP1559<Quantity>
export type RpcTransactionRequestCIP64 = TransactionRequestBase<
Quantity,
Index
> & {
accessList?: AccessList | undefined
feeCurrency?: Address | undefined
type?: '0x7b' | undefined
} & ExactPartial<FeeValuesEIP1559<Quantity>>
type Transaction<isPending extends boolean = boolean> = core_Transaction<
bigint,
number,
isPending
> & {
feeCurrency: Address | null
}
export type TransactionCIP42<isPending extends boolean = boolean> =
TransactionBase<bigint, number, isPending> &
FeeValuesEIP1559 & {
accessList: AccessList
chainId: number
feeCurrency: Address | null
gatewayFee: bigint | null
gatewayFeeRecipient: Address | null
type: 'cip42'
}
export type TransactionCIP64<isPending extends boolean = boolean> =
TransactionBase<bigint, number, isPending> &
FeeValuesEIP1559 & {
accessList: AccessList
chainId: number
feeCurrency: Address | null
type: 'cip64'
}
type TransactionRequest = core_TransactionRequest & {
feeCurrency?: Address | undefined
}
export type TransactionRequestCIP64 = TransactionRequestBase & {
accessList?: AccessList | undefined
feeCurrency?: Address | undefined
type?: 'cip64' | undefined
} & ExactPartial<FeeValuesEIP1559>
export type TransactionSerializableCIP42<
quantity = bigint,
index = number,
> = TransactionSerializableBase<quantity, index> & {
accessList?: AccessList | undefined
feeCurrency?: Address | undefined
gatewayFeeRecipient?: Address | undefined
gatewayFee?: quantity | undefined
chainId: number
type?: 'cip42' | undefined
} & ExactPartial<FeeValuesEIP1559<quantity>>
export type TransactionSerializableCIP64<
quantity = bigint,
index = number,
> = TransactionSerializableBase<quantity, index> & {
accessList?: AccessList | undefined
feeCurrency?: Address | undefined
chainId: number
type?: 'cip64' | undefined
} & ExactPartial<FeeValuesEIP1559<quantity>>
export type TransactionSerializedCIP42 = `0x7c${string}`
export type TransactionSerializedCIP64 = `0x7b${string}`

59
node_modules/viem/celo/utils.ts generated vendored Normal file
View File

@@ -0,0 +1,59 @@
import type { Address } from 'abitype'
import { trim } from '../utils/data/trim.js'
import type {
CeloTransactionRequest,
CeloTransactionSerializable,
TransactionSerializableCIP64,
} from './types.js'
export function isEmpty(
value: string | undefined | number | BigInt,
): value is undefined {
return (
value === 0 ||
value === 0n ||
value === undefined ||
value === null ||
value === '0' ||
value === '' ||
(typeof value === 'string' &&
(trim(value as Address).toLowerCase() === '0x' ||
trim(value as Address).toLowerCase() === '0x00'))
)
}
export function isPresent(
value: string | undefined | number | BigInt,
): value is string | number | BigInt {
return !isEmpty(value)
}
/** @internal */
export function isEIP1559(
transaction: CeloTransactionSerializable | CeloTransactionRequest,
): boolean {
return (
typeof transaction.maxFeePerGas !== 'undefined' &&
typeof transaction.maxPriorityFeePerGas !== 'undefined'
)
}
export function isCIP64(
transaction: CeloTransactionSerializable | CeloTransactionRequest,
): transaction is TransactionSerializableCIP64 {
/*
* Enable end user to force the tx to be considered as a CIP-64.
*
* The preliminary type will be determined as "eip1559" by src/utils/transaction/getTransactionType.ts
* and so we need the logic below to check for the specific value instead of checking if just any
* transaction type is provided. If that's anything else than "cip64" then we need to reevaluate the
* type based on the transaction fields.
*
* Modify with caution and according to https://github.com/celo-org/celo-proposals/blob/master/CIPs/cip-0064.md
*/
if (transaction.type === 'cip64') {
return true
}
return isEIP1559(transaction) && isPresent(transaction.feeCurrency)
}