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

88 lines 3.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.unpackAccountGasLimits = exports.packPaymasterData = exports.packAccountGasLimits = void 0; const viem_1 = require("viem"); const EntryPointAbi_v7_js_1 = require("../abis/EntryPointAbi_v7.js"); const packUserOperation = (request) => { const initCode = request.factory && request.factoryData ? (0, viem_1.concat)([request.factory, request.factoryData]) : "0x"; const accountGasLimits = packAccountGasLimits((({ verificationGasLimit, callGasLimit }) => ({ verificationGasLimit, callGasLimit, }))(request)); const gasFees = packAccountGasLimits((({ maxPriorityFeePerGas, maxFeePerGas }) => ({ maxPriorityFeePerGas, maxFeePerGas, }))(request)); const paymasterAndData = request.paymaster && (0, viem_1.isAddress)(request.paymaster) ? packPaymasterData((({ paymaster, paymasterVerificationGasLimit, paymasterPostOpGasLimit, paymasterData, }) => ({ paymaster, paymasterVerificationGasLimit, paymasterPostOpGasLimit, paymasterData, }))(request)) : "0x"; return (0, viem_1.encodeAbiParameters)([ { type: "address" }, { type: "uint256" }, { type: "bytes32" }, { type: "bytes32" }, { type: "bytes32" }, { type: "uint256" }, { type: "bytes32" }, { type: "bytes32" }, ], [ request.sender, (0, viem_1.hexToBigInt)(request.nonce), (0, viem_1.keccak256)(initCode), (0, viem_1.keccak256)(request.callData), accountGasLimits, (0, viem_1.hexToBigInt)(request.preVerificationGas), gasFees, (0, viem_1.keccak256)(paymasterAndData), ]); }; exports.default = { version: "0.7.0", address: { default: "0x0000000071727De22E5E9d8BAf0edAc6f37da032", }, abi: EntryPointAbi_v7_js_1.EntryPointAbi_v7, getUserOperationHash: (request, entryPointAddress, chainId) => { const encoded = (0, viem_1.encodeAbiParameters)([{ type: "bytes32" }, { type: "address" }, { type: "uint256" }], [ (0, viem_1.keccak256)(packUserOperation(request)), entryPointAddress, BigInt(chainId), ]); return (0, viem_1.keccak256)(encoded); }, packUserOperation, }; function packAccountGasLimits(data) { return (0, viem_1.concat)(Object.values(data).map((v) => (0, viem_1.pad)(v, { size: 16 }))); } exports.packAccountGasLimits = packAccountGasLimits; function packPaymasterData({ paymaster, paymasterVerificationGasLimit, paymasterPostOpGasLimit, paymasterData, }) { if (!paymaster || !paymasterVerificationGasLimit || !paymasterPostOpGasLimit || !paymasterData) { return "0x"; } return (0, viem_1.concat)([ paymaster, (0, viem_1.pad)(paymasterVerificationGasLimit, { size: 16 }), (0, viem_1.pad)(paymasterPostOpGasLimit, { size: 16 }), paymasterData, ]); } exports.packPaymasterData = packPaymasterData; function unpackAccountGasLimits(accountGasLimits) { return { verificationGasLimit: parseInt(accountGasLimits.slice(2, 34), 16), callGasLimit: parseInt(accountGasLimits.slice(34), 16), }; } exports.unpackAccountGasLimits = unpackAccountGasLimits; //# sourceMappingURL=0.7.js.map