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

View File

@@ -0,0 +1,171 @@
import type { Address, Narrow } from 'abitype'
import {
type SendTransactionErrorType,
sendTransaction,
} from '../../../actions/wallet/sendTransaction.js'
import type { Client } from '../../../clients/createClient.js'
import type { Transport } from '../../../clients/transports/createTransport.js'
import type { BaseError } from '../../../errors/base.js'
import type { ErrorType } from '../../../errors/utils.js'
import type { Account, GetAccountParameter } from '../../../types/account.js'
import type { Calls } from '../../../types/calls.js'
import type {
Chain,
DeriveChain,
GetChainParameter,
} from '../../../types/chain.js'
import type { Hex } from '../../../types/misc.js'
import type { UnionEvaluate, UnionPick } from '../../../types/utils.js'
import type { FormattedTransactionRequest } from '../../../utils/formatters/transactionRequest.js'
import { withCache } from '../../../utils/promise/withCache.js'
import { executionMode } from '../constants.js'
import { ExecuteUnsupportedError } from '../errors.js'
import {
type EncodeExecuteDataErrorType,
encodeExecuteData,
} from '../utils/encodeExecuteData.js'
import {
type GetExecuteErrorReturnType,
getExecuteError,
} from '../utils/getExecuteError.js'
import { supportsExecutionMode } from './supportsExecutionMode.js'
export type ExecuteParameters<
calls extends readonly unknown[] = readonly unknown[],
chain extends Chain | undefined = Chain | undefined,
account extends Account | undefined = Account | undefined,
chainOverride extends Chain | undefined = Chain | undefined,
_derivedChain extends Chain | undefined = DeriveChain<chain, chainOverride>,
> = UnionEvaluate<
UnionPick<
FormattedTransactionRequest<_derivedChain>,
| 'authorizationList'
| 'gas'
| 'gasPrice'
| 'maxFeePerGas'
| 'maxPriorityFeePerGas'
>
> &
GetAccountParameter<account, Account | Address, true, true> &
GetChainParameter<chain, chainOverride> & {
/** Address that will execute the calls. */
address: Address
/** Calls to execute. */
calls: Calls<Narrow<calls>>
/** Additional data to include for execution. */
opData?: Hex | undefined
}
export type ExecuteReturnType = Hex
export type ExecuteErrorType =
| GetExecuteErrorReturnType
| EncodeExecuteDataErrorType
| SendTransactionErrorType
| ErrorType
/**
* Executes call(s) using the `execute` function on an [ERC-7821-compatible contract](https://eips.ethereum.org/EIPS/eip-7821).
*
* @example
* ```ts
* import { createClient, http } from 'viem'
* import { privateKeyToAccount } from 'viem/accounts'
* import { mainnet } from 'viem/chains'
* import { execute } from 'viem/experimental/erc7821'
*
* const account = privateKeyToAccount('0x...')
*
* const client = createClient({
* chain: mainnet,
* transport: http(),
* })
*
* const hash = await execute(client, {
* account,
* calls: [{
* {
* data: '0xdeadbeef',
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
* },
* {
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
* value: 69420n,
* },
* }],
* to: account.address,
* })
* ```
*
* @example
* ```ts
* // Account Hoisting
* import { createClient, http } from 'viem'
* import { privateKeyToAccount } from 'viem/accounts'
* import { mainnet } from 'viem/chains'
* import { execute } from 'viem/experimental/erc7821'
*
* const account = privateKeyToAccount('0x...')
*
* const client = createClient({
* account,
* chain: mainnet,
* transport: http(),
* })
*
* const hash = await execute(client, {
* calls: [{
* {
* data: '0xdeadbeef',
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
* },
* {
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
* value: 69420n,
* },
* }],
* to: account.address,
* })
* ```
*
* @param client - Client to use.
* @param parameters - {@link ExecuteParameters}
* @returns Transaction hash. {@link ExecuteReturnType}
*/
export async function execute<
const calls extends readonly unknown[],
chain extends Chain | undefined,
account extends Account | undefined,
chainOverride extends Chain | undefined = undefined,
>(
client: Client<Transport, chain, account>,
parameters: ExecuteParameters<calls, chain, account, chainOverride>,
): Promise<ExecuteReturnType> {
const { authorizationList, calls, opData } = parameters
const address = authorizationList?.[0]?.address ?? parameters.address
const mode = opData ? executionMode.opData : executionMode.default
const supported = await withCache(
() =>
supportsExecutionMode(client, {
address,
mode,
}),
{
cacheKey: `supportsExecutionMode.${client.uid}.${address}.${mode}`,
},
)
if (!supported) throw new ExecuteUnsupportedError()
try {
return await sendTransaction(client, {
...parameters,
to: parameters.address,
data: encodeExecuteData({ calls, opData }),
} as any)
} catch (e) {
throw getExecuteError(e as BaseError, { calls })
}
}

View File

@@ -0,0 +1,194 @@
import type { Address, Narrow } from 'abitype'
import {
type SendTransactionErrorType,
sendTransaction,
} from '../../../actions/wallet/sendTransaction.js'
import type { Client } from '../../../clients/createClient.js'
import type { Transport } from '../../../clients/transports/createTransport.js'
import type { BaseError } from '../../../errors/base.js'
import type { ErrorType } from '../../../errors/utils.js'
import type { Account, GetAccountParameter } from '../../../types/account.js'
import type { Batches, Calls } from '../../../types/calls.js'
import type {
Chain,
DeriveChain,
GetChainParameter,
} from '../../../types/chain.js'
import type { Hex } from '../../../types/misc.js'
import type { UnionEvaluate, UnionPick } from '../../../types/utils.js'
import type { FormattedTransactionRequest } from '../../../utils/formatters/transactionRequest.js'
import { withCache } from '../../../utils/promise/withCache.js'
import { ExecuteUnsupportedError } from '../errors.js'
import {
type EncodeExecuteBatchesDataErrorType,
encodeExecuteBatchesData,
} from '../utils/encodeExecuteBatchesData.js'
import {
type GetExecuteErrorReturnType,
getExecuteError,
} from '../utils/getExecuteError.js'
import { supportsExecutionMode } from './supportsExecutionMode.js'
/** @internal */
export type Batch = { calls: readonly unknown[]; opData?: Hex | undefined }
export type ExecuteBatchesParameters<
batches extends readonly Batch[] = readonly Batch[],
chain extends Chain | undefined = Chain | undefined,
account extends Account | undefined = Account | undefined,
chainOverride extends Chain | undefined = Chain | undefined,
_derivedChain extends Chain | undefined = DeriveChain<chain, chainOverride>,
> = UnionEvaluate<
UnionPick<
FormattedTransactionRequest<_derivedChain>,
| 'authorizationList'
| 'gas'
| 'gasPrice'
| 'maxFeePerGas'
| 'maxPriorityFeePerGas'
>
> &
GetAccountParameter<account, Account | Address, true, true> &
GetChainParameter<chain, chainOverride> & {
/** Address that will execute the calls. */
address: Address
/** Batches to execute. */
batches: Batches<Narrow<batches>, { opData?: Hex | undefined }>
}
export type ExecuteBatchesReturnType = Hex
export type ExecuteBatchesErrorType =
| GetExecuteErrorReturnType
| EncodeExecuteBatchesDataErrorType
| SendTransactionErrorType
| ErrorType
/**
* Executes batches of call(s) using "batch of batches" mode on an [ERC-7821-compatible contract](https://eips.ethereum.org/EIPS/eip-7821).
*
* @example
* ```ts
* import { createClient, http, parseEther } from 'viem'
* import { privateKeyToAccount } from 'viem/accounts'
* import { mainnet } from 'viem/chains'
* import { executeBatches } from 'viem/experimental/erc7821'
*
* const account = privateKeyToAccount('0x...')
*
* const client = createClient({
* chain: mainnet,
* transport: http(),
* })
*
* const hash = await executeBatches(client, {
* account,
* batches: [
* {
* calls: [
* {
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
* value: parseEther('1'),
* },
* ],
* },
* {
* calls: [
* {
* to: '0xcb98643b8786950F0461f3B0edf99D88F274574D',
* value: parseEther('2'),
* },
* {
* data: '0xdeadbeef',
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
* },
* ],
* },
* ],
* to: account.address,
* })
* ```
*
* @example
* ```ts
* // Account Hoisting
* import { createClient, http, parseEther } from 'viem'
* import { privateKeyToAccount } from 'viem/accounts'
* import { mainnet } from 'viem/chains'
* import { executeBatches } from 'viem/experimental/erc7821'
*
* const account = privateKeyToAccount('0x...')
*
* const client = createClient({
* chain: mainnet,
* transport: http(),
* })
*
* const hash = await executeBatches(client, {
* batches: [
* {
* calls: [
* {
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
* value: parseEther('1'),
* },
* ],
* },
* {
* calls: [
* {
* to: '0xcb98643b8786950F0461f3B0edf99D88F274574D',
* value: parseEther('2'),
* },
* {
* data: '0xdeadbeef',
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
* },
* ],
* },
* ],
* to: account.address,
* })
* ```
*
* @param client - Client to use.
* @param parameters - {@link ExecuteBatchesParameters}
* @returns Transaction hash. {@link ExecuteBatchesReturnType}
*/
export async function executeBatches<
batches extends readonly Batch[],
chain extends Chain | undefined,
account extends Account | undefined,
chainOverride extends Chain | undefined = undefined,
>(
client: Client<Transport, chain, account>,
parameters: ExecuteBatchesParameters<batches, chain, account, chainOverride>,
): Promise<ExecuteBatchesReturnType> {
const { authorizationList, batches } = parameters
const address = authorizationList?.[0]?.address ?? parameters.address
const supported = await withCache(
() =>
supportsExecutionMode(client, {
address,
mode: 'batchOfBatches',
}),
{
cacheKey: `supportsExecutionMode.${client.uid}.${address}.batchOfBatches`,
},
)
if (!supported) throw new ExecuteUnsupportedError()
try {
return await sendTransaction(client, {
...parameters,
to: parameters.address,
data: encodeExecuteBatchesData({ batches }),
} as any)
} catch (e) {
const calls = batches.flatMap((b) => b.calls) as Calls<Narrow<batches>>
throw getExecuteError(e as BaseError, { calls })
}
}

View File

@@ -0,0 +1,73 @@
import type { Address } from '../../../accounts/index.js'
import { readContract } from '../../../actions/public/readContract.js'
import type { Client } from '../../../clients/createClient.js'
import type { Transport } from '../../../clients/transports/createTransport.js'
import type { ErrorType } from '../../../errors/utils.js'
import type { Chain } from '../../../types/chain.js'
import type { Hex } from '../../../types/misc.js'
import { withCache } from '../../../utils/promise/withCache.js'
import { abi, executionMode } from '../constants.js'
export type SupportsExecutionModeParameters = {
address: Address
mode?: 'default' | 'opData' | 'batchOfBatches' | Hex
}
export type SupportsExecutionModeReturnType = boolean
export type SupportsExecutionModeErrorType = ErrorType
const toSerializedMode = {
default: executionMode.default,
opData: executionMode.opData,
batchOfBatches: executionMode.batchOfBatches,
} as const
/**
* Checks if the contract supports the ERC-7821 execution mode.
*
* @example
* ```ts
* import { createClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { supportsExecutionMode } from 'viem/experimental/erc7821'
*
* const client = createClient({
* chain: mainnet,
* transport: http(),
* })
*
* const supported = await supportsExecutionMode(client, {
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
* })
* ```
*
* @param client - Client to use.
* @param parameters - {@link SupportsExecutionModeParameters}
* @returns If the execution mode is supported. {@link SupportsExecutionModeReturnType}
*/
export async function supportsExecutionMode<
chain extends Chain | undefined = Chain | undefined,
>(
client: Client<Transport, chain>,
parameters: SupportsExecutionModeParameters,
): Promise<SupportsExecutionModeReturnType> {
const { address, mode: m = 'default' } = parameters
const mode = m.startsWith('0x') ? m : (toSerializedMode as any)[m]
try {
return await withCache(
() =>
readContract(client, {
abi,
address,
functionName: 'supportsExecutionMode',
args: [mode],
}),
{
cacheKey: `supportsExecutionMode.${address}.${mode}`,
},
)
} catch {
return false
}
}