UNPKG

@abstraxn/account

Version:

@abstraxn/account: Empower ERC-4337 smart accounts with seamless APIs for enhanced decentralized finance experiences.

116 lines 5.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.convertToFactor = exports.isNullOrUndefined = exports.DEFAULT_CONVERT_TO_FACTOR_PCT = exports.DefaultGasLimit = exports.calcPreVerificationGas = exports.packUserOp = exports.DefaultGasOverheads = exports.DefaultGasLimits = exports.PROXY_CREATION_CODE = exports.DEFAULT_ENTRYPOINT_ADDRESS = exports.DEFAULT_FALLBACK_HANDLER_ADDRESS = exports.DEFAULT_IMPLEMENTATION_ADDRESS = exports.ECDSA_MODULE_ADDRESS = exports.FACTORY_ADDRESS = void 0; const ethers_1 = require("ethers"); const utils_1 = require("ethers/lib/utils"); exports.FACTORY_ADDRESS = "0x0adC1F2c9c7EdE2589f7f450959181a70701a735"; exports.ECDSA_MODULE_ADDRESS = "0xbB226A6a80E81b54BBdE9888e8b8F623186b8c0B"; exports.DEFAULT_IMPLEMENTATION_ADDRESS = "0x1A778a5228c18eF8d43D9FbE90B6Bb692ad82082"; exports.DEFAULT_FALLBACK_HANDLER_ADDRESS = "0x8F0F9a3BD260Bf0EFEeDce84f037AFdc3EDe8E85"; exports.DEFAULT_ENTRYPOINT_ADDRESS = "0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789"; exports.PROXY_CREATION_CODE = "0x6080346100aa57601f61012038819003918201601f19168301916001600160401b038311848410176100af578084926020946040528339810103126100aa57516001600160a01b0381168082036100aa5715610065573055604051605a90816100c68239f35b60405162461bcd60e51b815260206004820152601e60248201527f496e76616c696420696d706c656d656e746174696f6e206164647265737300006044820152606490fd5b600080fd5b634e487b7160e01b600052604160045260246000fdfe608060405230546000808092368280378136915af43d82803e156020573d90f35b3d90fdfea2646970667358221220a643a3e437a687e6ded90abe47a4233f53666b0e4a45003271d6224f195cb56d64736f6c63430008110033"; exports.DefaultGasLimits = { validateUserOpGas: 100000, validatePaymasterUserOpGas: 100000, postOpGas: 10877, }; exports.DefaultGasOverheads = { fixed: 21000, perUserOp: 18300, perUserOpWord: 4, zeroByte: 4, nonZeroByte: 16, bundleSize: 1, sigSize: 65, }; function packUserOp(op, forSignature = true) { if (!op.initCode || !op.callData || !op.paymasterAndData) throw new Error("Missing userOp properties"); if (forSignature) { return utils_1.defaultAbiCoder.encode(["address", "uint256", "bytes32", "bytes32", "uint256", "uint256", "uint256", "uint256", "uint256", "bytes32"], [ op.sender, op.nonce, (0, utils_1.keccak256)(op.initCode), (0, utils_1.keccak256)(op.callData), op.callGasLimit, op.verificationGasLimit, op.preVerificationGas, op.maxFeePerGas, op.maxPriorityFeePerGas, (0, utils_1.keccak256)(op.paymasterAndData), ]); } else { // for the purpose of calculating gas cost encode also signature (and no keccak of bytes) return utils_1.defaultAbiCoder.encode(["address", "uint256", "bytes", "bytes", "uint256", "uint256", "uint256", "uint256", "uint256", "bytes", "bytes"], [ op.sender, op.nonce, op.initCode, op.callData, op.callGasLimit, op.verificationGasLimit, op.preVerificationGas, op.maxFeePerGas, op.maxPriorityFeePerGas, op.paymasterAndData, op.signature, ]); } } exports.packUserOp = packUserOp; function calcPreVerificationGas(userOp, overheads) { const ov = { ...exports.DefaultGasOverheads, ...(overheads !== null && overheads !== void 0 ? overheads : {}) }; /* eslint-disable @typescript-eslint/no-explicit-any */ const p = { // dummy values, in case the UserOp is incomplete. paymasterAndData: "0x", preVerificationGas: ethers_1.BigNumber.from(21000), // dummy value, just for calldata cost signature: (0, utils_1.hexlify)(Buffer.alloc(ov.sigSize, 1)), // dummy signature ...userOp, }; const packed = (0, utils_1.arrayify)(packUserOp(p, false)); const lengthInWord = (packed.length + 31) / 32; /** * general explanation * 21000 base gas * ~ 18300 gas per userOp : corresponds to _validateAccountAndPaymasterValidationData() method, * Some lines in _handlePostOp() after actualGasCost calculation and compensate() method called in handleOps() method * plus any gas overhead that can't be tracked on-chain * (if bundler needs to charge the premium one way is to increase this value for ops to sign) */ const callDataCost = packed.map((x) => (x === 0 ? ov.zeroByte : ov.nonZeroByte)).reduce((sum, x) => sum + x); const ret = Math.round(callDataCost + ov.fixed / ov.bundleSize + ov.perUserOp + ov.perUserOpWord * lengthInWord); if (ret) { return ethers_1.BigNumber.from(ret); } else { throw new Error("can't calculate preVerificationGas"); } } exports.calcPreVerificationGas = calcPreVerificationGas; exports.DefaultGasLimit = { callGasLimit: 800000, verificationGasLimit: 1000000, preVerificationGas: 100000, }; exports.DEFAULT_CONVERT_TO_FACTOR_PCT = 10; const isNullOrUndefined = (value) => { return value === null || value === undefined; }; exports.isNullOrUndefined = isNullOrUndefined; const convertToFactor = async (userOp) => { const callGasLimit = ethers_1.ethers.BigNumber.from(userOp.callGasLimit); const verificationGasLimit = ethers_1.ethers.BigNumber.from(userOp.verificationGasLimit); const preVerificationGas = ethers_1.ethers.BigNumber.from(userOp.preVerificationGas); const newPreVerificationGas = callGasLimit .add(verificationGasLimit) .add(preVerificationGas) .mul(exports.DEFAULT_CONVERT_TO_FACTOR_PCT) .div(100); userOp.preVerificationGas = newPreVerificationGas .add(preVerificationGas) .toHexString(); return userOp; }; exports.convertToFactor = convertToFactor; //# sourceMappingURL=Constants.js.map