@owlprotocol/contracts-account-abstraction
Version:
ERC4337 Account Abstraction support for deploying relevant smart contracts and interacting with UserOps.
108 lines (107 loc) • 3.62 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var calcArbitrumPreVerificationGas_exports = {};
__export(calcArbitrumPreVerificationGas_exports, {
calcArbitrumPreVerificationGas: () => calcArbitrumPreVerificationGas
});
module.exports = __toCommonJS(calcArbitrumPreVerificationGas_exports);
var import_viem = require("viem");
var import_actions = require("viem/actions");
var import_utils = require("viem/utils");
var import_EntryPoint = require("../../artifacts/EntryPoint.js");
var import_PackedUserOperation = require("../../models/PackedUserOperation.js");
const getArbitrumL1FeeAbi = [
{
inputs: [
{
internalType: "address",
name: "to",
type: "address"
},
{
internalType: "bool",
name: "contractCreation",
type: "bool"
},
{
internalType: "bytes",
name: "data",
type: "bytes"
}
],
name: "gasEstimateL1Component",
outputs: [
{
internalType: "uint64",
name: "gasEstimateForL1",
type: "uint64"
},
{
internalType: "uint256",
name: "baseFee",
type: "uint256"
},
{
internalType: "uint256",
name: "l1BaseFeeEstimate",
type: "uint256"
}
],
stateMutability: "nonpayable",
type: "function"
}
];
async function calcArbitrumPreVerificationGas(client, parameters) {
const { packedUserOperation, entryPoint, staticFee } = parameters;
const chainId = client.chain?.id ?? await (0, import_utils.getAction)(client, import_actions.getChainId, "getChainId")({});
const randomDataUserOp = (0, import_PackedUserOperation.packedUserOperationToRandomDataUserOp)(packedUserOperation);
const handleOpsAbi = (0, import_viem.getAbiItem)({
abi: import_EntryPoint.abi,
name: "handleOps"
});
const selector = (0, import_viem.toFunctionSelector)(handleOpsAbi);
const paramData = (0, import_viem.encodeAbiParameters)(handleOpsAbi.inputs, [[randomDataUserOp], entryPoint]);
const data = (0, import_viem.concat)([selector, paramData]);
const precompileAddress = "0x00000000000000000000000000000000000000C8";
const serializedTx = (0, import_viem.serializeTransaction)(
{
to: entryPoint,
chainId,
nonce: 999999,
gasLimit: import_viem.maxUint64,
gasPrice: import_viem.maxUint64,
data
},
{
r: "0x123451234512345123451234512345123451234512345123451234512345",
s: "0x123451234512345123451234512345123451234512345123451234512345",
v: 28n
}
);
const { result } = await (0, import_utils.getAction)(
client,
import_actions.simulateContract,
"simulateContract"
)({
abi: getArbitrumL1FeeAbi,
address: precompileAddress,
functionName: "gasEstimateL1Component",
args: [entryPoint, false, serializedTx]
});
return result[0] + staticFee;
}