UNPKG

@0xfacet/sdk

Version:

A toolkit for Facet blockchain integration.

38 lines (37 loc) 1.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.decodeFacetEncodedTransaction = void 0; const viem_1 = require("viem"); /** * Decodes the encoded transaction data from an L1 transaction to the Facet Inbox * * @param encodedData - The encoded transaction data * @returns The decoded transaction parameters * @throws Error if the data cannot be decoded */ const decodeFacetEncodedTransaction = async (encodedData) => { if (!encodedData || encodedData.length < 4) { throw new Error("Invalid Facet transaction calldata"); } const strippedData = `0x${encodedData.slice(4)}`; // Remove '0x' and '46' prefix const decoded = (0, viem_1.fromRlp)(strippedData); if (!Array.isArray(decoded) || decoded.length < 6) { throw new Error("Invalid RLP structure"); } const l2ChainId = (0, viem_1.fromHex)(decoded[0], "number"); const to = decoded[1]; // Handle empty hex values by defaulting to 0n const value = decoded[2] === "0x" ? 0n : (0, viem_1.fromHex)(decoded[2], "bigint"); const gasLimit = decoded[3] === "0x" ? 0n : (0, viem_1.fromHex)(decoded[3], "bigint"); const data = decoded[4]; const fctMintAmount = decoded[5] === "0x" ? 0n : (0, viem_1.fromHex)(decoded[5], "bigint"); return { l2ChainId, to, value, data, gasLimit, fctMintAmount, }; }; exports.decodeFacetEncodedTransaction = decodeFacetEncodedTransaction;