@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
62 lines • 2.64 kB
JavaScript
import { concat } from "viem";
import { bigIntClamp, bigIntMultiply } from "./bigint.js";
import { allEqual, isBigNumberish } from "./index.js";
export function isValidRequest(request) {
return (BigInt(request.callGasLimit || 0n) > 0n &&
BigInt(request.maxFeePerGas || 0n) > 0n &&
BigInt(request.preVerificationGas || 0n) > 0n &&
BigInt(request.verificationGasLimit || 0n) > 0n &&
request.maxPriorityFeePerGas != null &&
isValidPaymasterAndData(request) &&
isValidFactoryAndData(request));
}
export function isValidPaymasterAndData(request) {
if ("paymasterAndData" in request) {
return request.paymasterAndData != null;
}
return allEqual(request.paymaster == null, request.paymasterData == null, request.paymasterPostOpGasLimit == null, request.paymasterVerificationGasLimit == null);
}
export function isValidFactoryAndData(request) {
if ("initCode" in request) {
const { initCode } = request;
return initCode != null;
}
return allEqual(request.factory == null, request.factoryData == null);
}
export function applyUserOpOverride(value, override) {
if (override == null) {
return value;
}
if (isBigNumberish(override)) {
return override;
}
else {
return value != null ? bigIntMultiply(value, override.multiplier) : value;
}
}
export function applyUserOpFeeOption(value, feeOption) {
if (feeOption == null) {
return value;
}
return value != null
? bigIntClamp(feeOption.multiplier
? bigIntMultiply(value, feeOption.multiplier)
: value, feeOption.min, feeOption.max)
: feeOption.min ?? 0n;
}
export function applyUserOpOverrideOrFeeOption(value, override, feeOption) {
return value != null && override != null
? applyUserOpOverride(value, override)
: applyUserOpFeeOption(value, feeOption);
}
export const bypassPaymasterAndData = (overrides) => !!overrides &&
("paymasterAndData" in overrides || "paymasterData" in overrides);
export const bypassPaymasterAndDataEmptyHex = (overrides) => overrides !== undefined &&
(("paymasterAndData" in overrides && overrides.paymasterAndData === "0x") ||
("paymasterData" in overrides && overrides.paymasterData === "0x"));
export const parsePaymasterAndData = (paymasterAndData) => ({
paymaster: paymasterAndData.substring(0, 42),
paymasterData: `0x${paymasterAndData.substring(42)}`,
});
export const concatPaymasterAndData = ({ paymaster = "0x", paymasterData = "0x", }) => concat([paymaster, paymasterData]);
//# sourceMappingURL=userop.js.map