UNPKG

@alchemy/aa-core

Version:

viem based SDK that enables interactions with ERC-4337 Smart Accounts. ABIs are based off the definitions generated in @account-abstraction/contracts

58 lines 2.24 kB
import { fromHex } from "viem"; import { isBaseSmartAccountClient } from "../../client/isSmartAccountClient.js"; import { AccountNotFoundError } from "../../errors/account.js"; import { IncompatibleClientError } from "../../errors/client.js"; import { TransactionMissingToParamError } from "../../errors/transaction.js"; import { bigIntMax } from "../../utils/index.js"; import { buildUserOperation } from "./buildUserOperation.js"; export async function buildUserOperationFromTxs(client, args) { const { account = client.account, requests, overrides, context } = args; if (!account) { throw new AccountNotFoundError(); } if (!isBaseSmartAccountClient(client)) { throw new IncompatibleClientError("BaseSmartAccountClient", "buildUserOperationFromTxs", client); } const batch = requests.map((request) => { if (!request.to) { throw new TransactionMissingToParamError(); } return { target: request.to, data: request.data ?? "0x", value: request.value ? fromHex(request.value, "bigint") : 0n, }; }); const mfpgOverridesInTx = () => requests .filter((x) => x.maxFeePerGas != null) .map((x) => fromHex(x.maxFeePerGas, "bigint")); const maxFeePerGas = overrides?.maxFeePerGas != null ? overrides?.maxFeePerGas : mfpgOverridesInTx().length > 0 ? bigIntMax(...mfpgOverridesInTx()) : undefined; const mpfpgOverridesInTx = () => requests .filter((x) => x.maxPriorityFeePerGas != null) .map((x) => fromHex(x.maxPriorityFeePerGas, "bigint")); const maxPriorityFeePerGas = overrides?.maxPriorityFeePerGas != null ? overrides?.maxPriorityFeePerGas : mpfpgOverridesInTx().length > 0 ? bigIntMax(...mpfpgOverridesInTx()) : undefined; const _overrides = { maxFeePerGas, maxPriorityFeePerGas, }; const uoStruct = await buildUserOperation(client, { uo: batch, account, context, overrides: _overrides, }); return { uoStruct, batch, overrides: _overrides, }; } //# sourceMappingURL=buildUserOperationFromTxs.js.map