import { estimateGas } from "viem/linea";
import { DEFAULT_SIMULATED_RELAYER_ADDRESS as account } from "../../constants";
import { fixedPointAdjustment } from "../../utils";
/**
 * @notice The Linea viem provider calls the linea_estimateGas RPC endpoint to estimate gas. Linea is unique
 * in that the recommended fee per gas is hardcoded to 7 wei while the priority fee is dynamic based on the
 * compressed transaction size, layer 1 verification costs and capacity, gas price ratio between layer 1 and layer 2,
 * the transaction's gas usage, the minimum gas price on layer 2,
 * and a minimum margin (for error) for gas price estimation.
 * Source: https://docs.linea.build/get-started/how-to/gas-fees#how-gas-works-on-linea
 * @dev Because the Linea priority fee is more volatile than the base fee, the base fee multiplier will be applied
 * to the priority fee.
 * @param provider Viem PublicClient
 * @param opts Relevant options for Linea are baseFeeMultiplier and unsignedTx.
 * @param baseFeeMultiplier Unused since Linea's base fee is hardcoded while its priority fee is dynamic.
 * @param priorityFeeMultiplier Amount to multiply priority fee.
 * @param unsignedTx Should contain any params passed to linea_estimateGas, which are listed
 * here: https://docs.linea.build/api/reference/linea-estimategas#parameters
 * @returns
 */
export async function eip1559(provider, opts) {
    const { unsignedTx: _unsignedTx, priorityFeeMultiplier } = opts;
    const unsignedTx = _unsignedTx; // Cast the opaque unsignedTx type to an ethers PopulatedTransaction.
    const { baseFeePerGas, priorityFeePerGas: _priorityFeePerGas } = await estimateGas(provider, {
        account: unsignedTx?.from ?? account,
        to: unsignedTx?.to ?? account,
        value: BigInt(unsignedTx?.value?.toString() ?? "0"),
        data: unsignedTx?.data ?? "0x",
    });
    const priorityFeePerGas = (_priorityFeePerGas * BigInt(priorityFeeMultiplier.toString())) / BigInt(fixedPointAdjustment.toString());
    return {
        maxFeePerGas: baseFeePerGas + priorityFeePerGas,
        maxPriorityFeePerGas: priorityFeePerGas,
    };
}
//# sourceMappingURL=linea-viem.js.map