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

129
node_modules/viem/zksync/utils/abi/encodeDeployData.ts generated vendored Normal file
View File

@@ -0,0 +1,129 @@
import type { Abi } from 'abitype'
import { zeroHash } from '../../../constants/bytes.js'
import {
AbiConstructorNotFoundError,
AbiConstructorParamsNotFoundError,
} from '../../../errors/abi.js'
import type { ErrorType } from '../../../errors/utils.js'
import type { ContractConstructorArgs } from '../../../types/contract.js'
import type { Hash, Hex } from '../../../types/misc.js'
import { encodeAbiParameters } from '../../../utils/abi/encodeAbiParameters.js'
import type {
EncodeDeployDataParameters as EncodeDeployDataParameters_,
EncodeDeployDataReturnType,
} from '../../../utils/abi/encodeDeployData.js'
import {
type EncodeFunctionDataErrorType,
encodeFunctionData,
} from '../../../utils/abi/encodeFunctionData.js'
import { toHex } from '../../../utils/encoding/toHex.js'
import { contractDeployerAbi } from '../../constants/abis.js'
import { accountAbstractionVersion1 } from '../../constants/contract.js'
import type { ContractDeploymentType } from '../../types/contract.js'
import { type HashBytecodeErrorType, hashBytecode } from '../hashBytecode.js'
const docsPath = '/docs/contract/encodeDeployData'
/** @internal */
export type EncodeDeployDataParameters<
abi extends Abi | readonly unknown[] = Abi,
hasConstructor = abi extends Abi
? Abi extends abi
? true
: [Extract<abi[number], { type: 'constructor' }>] extends [never]
? false
: true
: true,
allArgs = ContractConstructorArgs<abi>,
> = EncodeDeployDataParameters_<abi, hasConstructor, allArgs> & {
deploymentType?: ContractDeploymentType | undefined
salt?: Hash | undefined
}
export type EncodeDeployDataErrorType =
| EncodeFunctionDataErrorType
| HashBytecodeErrorType
| ErrorType
export function encodeDeployData<const abi extends Abi | readonly unknown[]>(
parameters: EncodeDeployDataParameters<abi>,
): EncodeDeployDataReturnType {
const { abi, args, bytecode, deploymentType, salt } =
parameters as EncodeDeployDataParameters
if (!args || args.length === 0) {
const { functionName, argsContractDeployer } = getDeploymentDetails(
deploymentType,
salt ?? zeroHash,
toHex(hashBytecode(bytecode)),
'0x',
)
return encodeFunctionData({
abi: contractDeployerAbi,
functionName,
args: argsContractDeployer,
})
}
const description = abi.find((x) => 'type' in x && x.type === 'constructor')
if (!description) throw new AbiConstructorNotFoundError({ docsPath })
if (!('inputs' in description))
throw new AbiConstructorParamsNotFoundError({ docsPath })
if (!description.inputs || description.inputs.length === 0)
throw new AbiConstructorParamsNotFoundError({ docsPath })
const data = encodeAbiParameters(description.inputs, args)
const { functionName, argsContractDeployer } = getDeploymentDetails(
deploymentType,
salt ?? zeroHash,
toHex(hashBytecode(bytecode)),
data,
)
return encodeFunctionData({
abi: contractDeployerAbi,
functionName,
args: argsContractDeployer,
})
}
function getDeploymentDetails(
deploymentType: ContractDeploymentType,
salt: Hash,
bytecodeHash: Hex,
data: Hex,
): {
functionName: string
argsContractDeployer: readonly unknown[]
} {
const contractDeploymentArgs = [salt, bytecodeHash, data]
const deploymentOptions = {
create: {
functionName: 'create',
argsContractDeployer: contractDeploymentArgs,
},
create2: {
functionName: 'create2',
argsContractDeployer: contractDeploymentArgs,
},
createAccount: {
functionName: 'createAccount',
argsContractDeployer: [
...contractDeploymentArgs,
accountAbstractionVersion1,
],
},
create2Account: {
functionName: 'create2Account',
argsContractDeployer: [
...contractDeploymentArgs,
accountAbstractionVersion1,
],
},
}
const deploymentKey = deploymentType || 'create'
return deploymentOptions[deploymentKey]
}

29
node_modules/viem/zksync/utils/assertEip712Request.ts generated vendored Normal file
View File

@@ -0,0 +1,29 @@
import type { ErrorType } from '../../errors/utils.js'
import type { ExactPartial } from '../../types/utils.js'
import {
type AssertRequestErrorType,
assertRequest,
} from '../../utils/transaction/assertRequest.js'
import type { zksync } from '../../zksync/chains.js'
import type { SendTransactionParameters } from '../actions/sendTransaction.js'
import {
InvalidEip712TransactionError,
type InvalidEip712TransactionErrorType,
} from '../errors/transaction.js'
import { isEIP712Transaction } from './isEip712Transaction.js'
export type AssertEip712RequestParameters = ExactPartial<
SendTransactionParameters<typeof zksync>
>
/** @internal */
export type AssertEip712RequestErrorType =
| InvalidEip712TransactionErrorType
| AssertRequestErrorType
| ErrorType
export function assertEip712Request(args: AssertEip712RequestParameters) {
if (!isEIP712Transaction(args as any))
throw new InvalidEip712TransactionError()
assertRequest(args as any)
}

View File

@@ -0,0 +1,36 @@
import { InvalidAddressError } from '../../errors/address.js'
import { BaseError } from '../../errors/base.js'
import { InvalidChainIdError } from '../../errors/chain.js'
import type { ExactPartial } from '../../types/utils.js'
import { isAddress } from '../../utils/address/isAddress.js'
import { InvalidEip712TransactionError } from '../errors/transaction.js'
import type {
ZksyncTransactionSerializable,
ZksyncTransactionSerializableEIP712,
} from '../types/transaction.js'
import { isEIP712Transaction } from './isEip712Transaction.js'
export function assertEip712Transaction(
transaction: ExactPartial<ZksyncTransactionSerializable>,
) {
const { chainId, to, from, paymaster, paymasterInput } =
transaction as ZksyncTransactionSerializableEIP712
if (!isEIP712Transaction(transaction))
throw new InvalidEip712TransactionError()
if (!chainId || chainId <= 0) throw new InvalidChainIdError({ chainId })
if (to && !isAddress(to)) throw new InvalidAddressError({ address: to })
if (from && !isAddress(from)) throw new InvalidAddressError({ address: from })
if (paymaster && !isAddress(paymaster))
throw new InvalidAddressError({ address: paymaster })
if (paymaster && !paymasterInput) {
throw new BaseError(
'`paymasterInput` must be provided when `paymaster` is defined',
)
}
if (!paymaster && paymasterInput) {
throw new BaseError(
'`paymaster` must be provided when `paymasterInput` is defined',
)
}
}

View File

@@ -0,0 +1,29 @@
import type { Address } from '../../../accounts/index.js'
import { pad, toHex } from '../../../utils/index.js'
import { addressModulo, l1ToL2AliasOffset } from '../../constants/address.js'
/**
* Converts the address that submitted a transaction to the inbox on L1 to the `msg.sender` viewed on L2.
* Returns the `msg.sender` of the `L1->L2` transaction as the address of the contract that initiated the transaction.
*
* All available cases:
* - During a normal transaction, if contract `A` calls contract `B`, the `msg.sender` is `A`.
* - During `L1->L2` communication, if an EOA `X` calls contract `B`, the `msg.sender` is `X`.
* - During `L1->L2` communication, if a contract `A` calls contract `B`, the `msg.sender` is `applyL1ToL2Alias(A)`.
*
* @param address - The address of the contract.
* @returns address - The transformed address representing the `msg.sender` on L2.
*
* @example
* import { applyL1ToL2Alias } from 'viem/zksync'
*
* const l1ContractAddress = "0x702942B8205E5dEdCD3374E5f4419843adA76Eeb";
* const l2ContractAddress = utils.applyL1ToL2Alias(l1ContractAddress);
* // l2ContractAddress = "0x813A42B8205E5DedCd3374e5f4419843ADa77FFC"
*/
export function applyL1ToL2Alias(address: Address): Address {
return pad(
toHex((BigInt(address) + BigInt(l1ToL2AliasOffset)) % addressModulo),
{ size: 20 },
)
}

View File

@@ -0,0 +1,63 @@
import type { Address } from 'abitype'
import type { Hash } from '../../../types/misc.js'
import type { TransactionReceipt } from '../../../types/transaction.js'
import { decodeEventLog, isAddressEqual } from '../../../utils/index.js'
import { zksyncAbi } from '../../constants/abis.js'
import {
TxHashNotFoundInLogsError,
type TxHashNotFoundInLogsErrorType,
} from '../../errors/bridge.js'
export type GetL2HashFromPriorityOpErrorType = TxHashNotFoundInLogsErrorType
/**
* Returns the hash of the L2 priority operation from a given L1 transaction receipt.
*
* @param receipt - The L1 transaction receipt.
* @param zksync - The address of the ZKsync Era main contract.
* @returns hash - The hash of the L2 priority operation.
*
* @example
* import { createPublicClient, http } from 'viem'
* import { zksync, mainnet } from 'viem/chains'
* import { publicActionsL2, getL2HashFromPriorityOp } from 'viem/zksync'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
*
* const zksyncClient = const client = createPublicClient({
* chain: zksync,
* transport: http(),
* })
*
* const receipt = await client.waitForTransactionReceipt({hash: '0x...'})
* const l2Hash = getL2HashFromPriorityOp(
* receipt,
* await zksyncClient.getMainContractAddress()
* )
*/
export function getL2HashFromPriorityOp(
receipt: TransactionReceipt,
zksync: Address,
): Address {
let hash: Hash | null = null
for (const log of receipt.logs) {
if (!isAddressEqual(log.address, zksync)) continue
try {
const priorityQueueLog = decodeEventLog({
abi: zksyncAbi,
data: log.data,
topics: log.topics,
})
if (priorityQueueLog && (priorityQueueLog.args as any).txHash !== null)
hash = (priorityQueueLog.args as any).txHash
} catch (_e) {}
}
if (!hash) {
throw new TxHashNotFoundInLogsError()
}
return hash
}

View File

@@ -0,0 +1,47 @@
import type { Address } from 'abitype'
import type { Account } from '../../../accounts/index.js'
import { getTransactionReceipt } from '../../../actions/index.js'
import type { Client } from '../../../clients/createClient.js'
import type { Transport } from '../../../clients/transports/createTransport.js'
import type { Chain } from '../../../types/chain.js'
import type { Hash } from '../../../types/misc.js'
import { isAddressEqual } from '../../../utils/index.js'
import { l1MessengerAddress } from '../../constants/address.js'
import type { ZksyncL2ToL1Log } from '../../types/log.js'
import type { ZksyncTransactionReceipt } from '../../types/transaction.js'
export type GetWithdrawalL2ToL1LogParameters = {
/** Hash of the L2 transaction where the withdrawal was initiated. */
hash: Hash
/** In case there were multiple withdrawals in one transaction, you may pass an index of the
withdrawal you want to finalize. */
index?: number | undefined
}
export type GetWithdrawalL2ToL1LogReturnType = {
l2ToL1LogIndex: number | null
l2ToL1Log: ZksyncL2ToL1Log
}
/** @internal */
export async function getWithdrawalL2ToL1Log<
chain extends Chain | undefined,
account extends Account | undefined,
>(
client: Client<Transport, chain, account>,
parameters: GetWithdrawalL2ToL1LogParameters,
): Promise<GetWithdrawalL2ToL1LogReturnType> {
const { hash, index = 0 } = parameters
const receipt = (await getTransactionReceipt(client, {
hash,
})) as ZksyncTransactionReceipt
const messages = Array.from(receipt.l2ToL1Logs.entries()).filter(([, log]) =>
isAddressEqual(log.sender as Address, l1MessengerAddress),
)
const [l2ToL1LogIndex, l2ToL1Log] = messages[index]
return {
l2ToL1LogIndex,
l2ToL1Log,
}
}

View File

@@ -0,0 +1,47 @@
import type { Account } from '../../../accounts/types.js'
import { getTransactionReceipt } from '../../../actions/index.js'
import type { Client } from '../../../clients/createClient.js'
import type { Transport } from '../../../clients/transports/createTransport.js'
import type { Chain } from '../../../types/chain.js'
import type { Hash } from '../../../types/misc.js'
import { isAddressEqual, toFunctionHash } from '../../../utils/index.js'
import { l1MessengerAddress } from '../../constants/address.js'
import type { ZksyncLog } from '../../types/log.js'
import type { ZksyncTransactionReceipt } from '../../types/transaction.js'
export type GetWithdrawalLogParameters = {
/** Hash of the L2 transaction where the withdrawal was initiated. */
hash: Hash
/** In case there were multiple withdrawals in one transaction, you may pass an index of the
withdrawal you want to finalize. */
index?: number | undefined
}
export type GetWithdrawalLogReturnType = {
log: ZksyncLog
l1BatchTxId: bigint | null
}
/** @internal */
export async function getWithdrawalLog<
chain extends Chain | undefined,
account extends Account | undefined,
>(
client: Client<Transport, chain, account>,
parameters: GetWithdrawalLogParameters,
): Promise<GetWithdrawalLogReturnType> {
const { hash, index = 0 } = parameters
const receipt = (await getTransactionReceipt(client, {
hash,
})) as ZksyncTransactionReceipt
const log = receipt.logs.filter(
(log) =>
isAddressEqual(log.address, l1MessengerAddress) &&
log.topics[0] === toFunctionHash('L1MessageSent(address,bytes32,bytes)'),
)[index]
return {
log,
l1BatchTxId: receipt.l1BatchTxIndex,
}
}

View File

@@ -0,0 +1,22 @@
import type { Address } from '../../../accounts/index.js'
import { pad, toHex } from '../../../utils/index.js'
import { addressModulo, l1ToL2AliasOffset } from '../../constants/address.js'
/**
* Converts and returns the `msg.sender` viewed on L2 to the address that submitted a transaction to the inbox on L1.
*
* @param address - The sender address viewed on L2.
* @returns address - The hash of the L2 priority operation.
*
* @example
* import { undoL1ToL2Alias } from 'viem/zksync'
*
* const l2ContractAddress = "0x813A42B8205E5DedCd3374e5f4419843ADa77FFC";
* const l1ContractAddress = utils.undoL1ToL2Alias(l2ContractAddress);
* // const l1ContractAddress = "0x702942B8205E5dEdCD3374E5f4419843adA76Eeb"
*/
export function undoL1ToL2Alias(address: Address): Address {
let result = BigInt(address) - BigInt(l1ToL2AliasOffset)
if (result < 0n) result += addressModulo
return pad(toHex(result), { size: 20 })
}

11
node_modules/viem/zksync/utils/camelCaseKeys.ts generated vendored Normal file
View File

@@ -0,0 +1,11 @@
export function camelCaseKeys(response: object): object {
if (!response) return response
if (typeof response !== 'object') return response
if (Array.isArray(response)) return response.map(camelCaseKeys)
return Object.fromEntries(
Object.entries(response).map(([key, value]) => [
key.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase()),
camelCaseKeys(value),
]),
)
}

86
node_modules/viem/zksync/utils/getEip712Domain.ts generated vendored Normal file
View File

@@ -0,0 +1,86 @@
import { toHex } from '../../utils/encoding/toHex.js'
import { gasPerPubdataDefault } from '../constants/number.js'
import type { EIP712DomainFn } from '../types/eip712.js'
import type {
ZksyncEIP712TransactionSignable,
ZksyncTransactionSerializable,
ZksyncTransactionSerializableEIP712,
} from '../types/transaction.js'
import { assertEip712Transaction } from './assertEip712Transaction.js'
import { hashBytecode } from './hashBytecode.js'
export const getEip712Domain: EIP712DomainFn<
ZksyncTransactionSerializable,
ZksyncEIP712TransactionSignable
> = (transaction) => {
assertEip712Transaction(transaction)
const message = transactionToMessage(
transaction as ZksyncTransactionSerializableEIP712,
)
return {
domain: {
name: 'zkSync',
version: '2',
chainId: transaction.chainId,
},
types: {
Transaction: [
{ name: 'txType', type: 'uint256' },
{ name: 'from', type: 'uint256' },
{ name: 'to', type: 'uint256' },
{ name: 'gasLimit', type: 'uint256' },
{ name: 'gasPerPubdataByteLimit', type: 'uint256' },
{ name: 'maxFeePerGas', type: 'uint256' },
{ name: 'maxPriorityFeePerGas', type: 'uint256' },
{ name: 'paymaster', type: 'uint256' },
{ name: 'nonce', type: 'uint256' },
{ name: 'value', type: 'uint256' },
{ name: 'data', type: 'bytes' },
{ name: 'factoryDeps', type: 'bytes32[]' },
{ name: 'paymasterInput', type: 'bytes' },
],
},
primaryType: 'Transaction',
message: message,
}
}
//////////////////////////////////////////////////////////////////////////////
// Utilities
function transactionToMessage(
transaction: ZksyncTransactionSerializableEIP712,
): ZksyncEIP712TransactionSignable {
const {
gas,
nonce,
to,
from,
value,
maxFeePerGas,
maxPriorityFeePerGas,
factoryDeps,
paymaster,
paymasterInput,
gasPerPubdata,
data,
} = transaction
return {
txType: 113n,
from: BigInt(from),
to: to ? BigInt(to) : 0n,
gasLimit: gas ?? 0n,
gasPerPubdataByteLimit: gasPerPubdata ?? gasPerPubdataDefault,
maxFeePerGas: maxFeePerGas ?? 0n,
maxPriorityFeePerGas: maxPriorityFeePerGas ?? 0n,
paymaster: paymaster ? BigInt(paymaster) : 0n,
nonce: nonce ? BigInt(nonce) : 0n,
value: value ?? 0n,
data: data ?? '0x',
factoryDeps: factoryDeps?.map((dep) => toHex(hashBytecode(dep))) ?? [],
paymasterInput: paymasterInput ? paymasterInput : '0x',
}
}

60
node_modules/viem/zksync/utils/hashBytecode.ts generated vendored Normal file
View File

@@ -0,0 +1,60 @@
import type { ErrorType } from '../../errors/utils.js'
import type { Hex } from '../../types/misc.js'
import { pad } from '../../utils/data/pad.js'
import { type ToBytesErrorType, toBytes } from '../../utils/encoding/toBytes.js'
import { type Sha256ErrorType, sha256 } from '../../utils/hash/sha256.js'
import { maxBytecodeSize } from '../constants/number.js'
import {
BytecodeLengthExceedsMaxSizeError,
type BytecodeLengthExceedsMaxSizeErrorType,
BytecodeLengthInWordsMustBeOddError,
type BytecodeLengthInWordsMustBeOddErrorType,
BytecodeLengthMustBeDivisibleBy32Error,
type BytecodeLengthMustBeDivisibleBy32ErrorType,
} from '../errors/bytecode.js'
export type HashBytecodeErrorType =
| BytecodeLengthExceedsMaxSizeErrorType
| BytecodeLengthInWordsMustBeOddErrorType
| BytecodeLengthMustBeDivisibleBy32ErrorType
| Sha256ErrorType
| ToBytesErrorType
| ErrorType
export function hashBytecode(bytecode: Hex): Uint8Array {
const bytecodeBytes = toBytes(bytecode)
if (bytecodeBytes.length % 32 !== 0)
throw new BytecodeLengthMustBeDivisibleBy32Error({
givenLength: bytecodeBytes.length,
})
if (bytecodeBytes.length > maxBytecodeSize)
throw new BytecodeLengthExceedsMaxSizeError({
givenLength: bytecodeBytes.length,
maxBytecodeSize,
})
const hashStr = sha256(bytecodeBytes)
const hash = toBytes(hashStr)
// Note that the length of the bytecode
// should be provided in 32-byte words.
const bytecodeLengthInWords = bytecodeBytes.length / 32
if (bytecodeLengthInWords % 2 === 0) {
throw new BytecodeLengthInWordsMustBeOddError({
givenLengthInWords: bytecodeLengthInWords,
})
}
const bytecodeLength = toBytes(bytecodeLengthInWords)
// The bytecode should always take the first 2 bytes of the bytecode hash,
// so we pad it from the left in case the length is smaller than 2 bytes.
const bytecodeLengthPadded = pad(bytecodeLength, { size: 2 })
const codeHashVersion = new Uint8Array([1, 0])
hash.set(codeHashVersion, 0)
hash.set(bytecodeLengthPadded, 2)
return hash
}

23
node_modules/viem/zksync/utils/isEip712Transaction.ts generated vendored Normal file
View File

@@ -0,0 +1,23 @@
import type { ExactPartial, OneOf } from '../../types/utils.js'
import type {
ZksyncTransactionRequest,
ZksyncTransactionSerializable,
} from '../types/transaction.js'
export function isEIP712Transaction(
transaction: ExactPartial<
OneOf<ZksyncTransactionRequest | ZksyncTransactionSerializable>
>,
) {
if (transaction.type === 'eip712') return true
if (
('customSignature' in transaction && transaction.customSignature) ||
('paymaster' in transaction && transaction.paymaster) ||
('paymasterInput' in transaction && transaction.paymasterInput) ||
('gasPerPubdata' in transaction &&
typeof transaction.gasPerPubdata === 'bigint') ||
('factoryDeps' in transaction && transaction.factoryDeps)
)
return true
return false
}

20
node_modules/viem/zksync/utils/isEth.ts generated vendored Normal file
View File

@@ -0,0 +1,20 @@
import type { Address } from '../../accounts/index.js'
import {
ethAddressInContracts,
l2BaseTokenAddress,
legacyEthAddress,
} from '../constants/address.js'
export function isEth(token: Address) {
return (
token.localeCompare(legacyEthAddress, undefined, {
sensitivity: 'accent',
}) === 0 ||
token.localeCompare(l2BaseTokenAddress, undefined, {
sensitivity: 'accent',
}) === 0 ||
token.localeCompare(ethAddressInContracts, undefined, {
sensitivity: 'accent',
}) === 0
)
}

View File

@@ -0,0 +1,57 @@
import { BaseError } from '../../errors/base.js'
import type { Hex } from '../../types/misc.js'
import {
fromHex,
fromRlp,
hexToBigInt,
hexToNumber,
} from '../../utils/index.js'
import type { ZksyncTransactionSerializableEIP712 } from '../types/transaction.js'
export function parseEip712Transaction(
transaction: Hex,
): ZksyncTransactionSerializableEIP712 {
const payload = fromHex(transaction, 'bytes')
if (payload[0] !== 113) throw new BaseError('transaction type must be eip712')
function validHex(value: Hex): Hex {
if (!value || value === '0x') return '0x0'
return value
}
function parsePaymasterArray(arr: Hex[]) {
if (arr.length === 0) return undefined
if (arr.length !== 2)
throw new BaseError(
`Invalid paymaster parameters, expected to have length of 2, found ${arr.length}!`,
)
return {
paymaster: arr[0],
paymasterInput: arr[1],
}
}
const raw = fromRlp(payload.slice(1)) as Hex[]
const paymasterParams = parsePaymasterArray(raw[15] as unknown as Hex[])
return {
type: 'eip712',
nonce: hexToNumber(validHex(raw[0])),
maxPriorityFeePerGas: hexToBigInt(validHex(raw[1])),
maxFeePerGas: hexToBigInt(validHex(raw[2])),
gas: hexToBigInt(validHex(raw[3])),
to: raw[4],
value: hexToBigInt(validHex(raw[5])),
data: raw[6],
v: hexToBigInt(validHex(raw[7])),
r: raw[8],
s: raw[9],
chainId: hexToNumber(validHex(raw[10])),
from: raw[11],
gasPerPubdata: hexToBigInt(validHex(raw[12])),
factoryDeps: raw[13] as unknown as Hex[],
customSignature: raw[14],
paymaster: paymasterParams?.paymaster,
paymasterInput: paymasterParams?.paymasterInput,
}
}

View File

@@ -0,0 +1,32 @@
import type { Address } from 'abitype'
import type { ByteArray, Hex } from '../../../types/misc.js'
import {
type EncodeFunctionDataReturnType,
encodeFunctionData,
} from '../../../utils/abi/encodeFunctionData.js'
import { bytesToHex } from '../../../utils/encoding/toHex.js'
import { paymasterAbi } from '../../constants/abis.js'
export type GetApprovalBasedPaymasterInputParameters = {
innerInput: Hex | ByteArray
minAllowance: bigint
token: Address
}
export type GetApprovalBasedPaymasterInputReturnType =
EncodeFunctionDataReturnType
export function getApprovalBasedPaymasterInput(
parameters: GetApprovalBasedPaymasterInputParameters,
): GetApprovalBasedPaymasterInputReturnType {
const { innerInput, minAllowance, token } = parameters
const innerInputHex =
typeof innerInput === 'string' ? innerInput : bytesToHex(innerInput)
return encodeFunctionData({
abi: paymasterAbi,
functionName: 'approvalBased',
args: [token, minAllowance, innerInputHex],
})
}

View File

@@ -0,0 +1,28 @@
import type { ByteArray, Hex } from '../../../types/misc.js'
import {
type EncodeFunctionDataReturnType,
encodeFunctionData,
} from '../../../utils/abi/encodeFunctionData.js'
import { bytesToHex } from '../../../utils/encoding/toHex.js'
import { paymasterAbi } from '../../constants/abis.js'
export type GetGeneralPaymasterInputParameters = {
innerInput: Hex | ByteArray
}
export type GetGeneralPaymasterInputReturnType = EncodeFunctionDataReturnType
export function getGeneralPaymasterInput(
parameters: GetGeneralPaymasterInputParameters,
): GetGeneralPaymasterInputReturnType {
const { innerInput } = parameters
const innerInputHex =
typeof innerInput === 'string' ? innerInput : bytesToHex(innerInput)
return encodeFunctionData({
abi: paymasterAbi,
functionName: 'general',
args: [innerInputHex],
})
}