import { Effect } from "effect";
import * as CoreAddress from "../../../Address.js";
import * as CoreAssets from "../../../Assets.js";
import type * as PlutusData from "../../../Data.js";
import type * as DatumOption from "../../../DatumOption.js";
import * as CoreScript from "../../../Script.js";
import * as Transaction from "../../../Transaction.js";
import type * as TransactionInput from "../../../TransactionInput.js";
import * as TransactionWitnessSet from "../../../TransactionWitnessSet.js";
import * as TxOut from "../../../TxOut.js";
import * as CoreUTxO from "../../../UTxO.js";
import type { UnfrackOptions } from "../TransactionBuilder.js";
import { BuildOptionsTag, TransactionBuilderError, TxBuilderConfigTag, TxContext } from "../TransactionBuilder.js";
/**
 * This file contains the program creators that generate ProgramSteps.
 * ProgramSteps are deferred Effects executed during build() with fresh state.
 *
 * Architecture:
 * - Program creators return deferred Effects (ProgramSteps)
 * - Programs access TxContext (single unified Context) containing config, state, and options
 * - Programs are executed with fresh state on each build() call
 * - No state mutation between builds - complete isolation
 * - No prop drilling - everything accessible via single Context
 */
/**
 * Check if an address is a script address (payment credential is ScriptHash).
 * Works with Core Address type.
 *
 * @deprecated Use `Address.isScript` from the core module instead.
 * @since 2.0.0
 * @category helpers
 */
export declare const isScriptAddressCore: (address: CoreAddress.Address) => boolean;
/**
 * Check if an address string is a script address (payment credential is ScriptHash).
 * Parses the address to extract its structure and checks the payment credential type.
 *
 * @since 2.0.0
 * @category helpers
 */
export declare const isScriptAddress: (address: string) => Effect.Effect<boolean, TransactionBuilderError>;
/**
 * Filter UTxOs to find those locked by scripts (script-locked UTxOs).
 *
 * @since 2.0.0
 * @category helpers
 */
export declare const filterScriptUtxos: (utxos: ReadonlyArray<CoreUTxO.UTxO>) => Effect.Effect<ReadonlyArray<CoreUTxO.UTxO>, TransactionBuilderError>;
/**
 * Calculate total assets from a set of UTxOs.
 *
 * @deprecated Use `UTxO.totalAssets` from the core module instead.
 * @since 2.0.0
 * @category helpers
 */
export declare const calculateTotalAssets: (utxos: ReadonlyArray<CoreUTxO.UTxO> | Set<CoreUTxO.UTxO>) => CoreAssets.Assets;
/**
 * Calculate reference script fees using tiered pricing.
 *
 * Direct port of the Cardano ledger's `tierRefScriptFee` function.
 * Each `sizeIncrement`-byte chunk is priced at `curTierPrice` per byte,
 * then `curTierPrice *= multiplier` for the next chunk. Final result: `floor(total)`.
 *
 * @since 2.0.0
 * @category helpers
 */
export declare const tierRefScriptFee: (multiplier: number, sizeIncrement: number, baseFee: number, totalSize: number) => bigint;
/**
 * Calculate reference script fees using tiered pricing.
 *
 * Matches the Cardano node's `tierRefScriptFee` from Conway ledger:
 * - Stride: 25,600 bytes (hardcoded, becomes a protocol param post-Conway)
 * - Multiplier: 1.2× per tier (hardcoded, becomes a protocol param post-Conway)
 * - Base cost: `minFeeRefScriptCostPerByte` protocol parameter
 *
 * For each 25,600-byte chunk the price per byte increases by 1.2×.
 * The final (partial) chunk is charged proportionally. Result is `floor(total)`.
 *
 * The Cardano node sums scriptRef sizes from both spent inputs and reference
 * inputs (`txNonDistinctRefScriptsSize`), so callers must pass both.
 *
 * @param utxos - All UTxOs (spent inputs + reference inputs) to scan for scriptRefs
 * @param costPerByte - The minFeeRefScriptCostPerByte protocol parameter
 *
 * @since 2.0.0
 * @category helpers
 */
export declare const calculateReferenceScriptFee: (utxos: ReadonlyArray<CoreUTxO.UTxO>, costPerByte: number) => Effect.Effect<bigint, TransactionBuilderError>;
/**
 * Create a TransactionOutput from user-friendly parameters.
 * Uses Core types directly.
 *
 * TransactionOutput represents an output being created in a transaction.
 *
 * @since 2.0.0
 * @category helpers
 */
export declare const makeTxOutput: (params: {
    address: CoreAddress.Address;
    assets: CoreAssets.Assets;
    datum?: DatumOption.DatumOption;
    scriptRef?: CoreScript.Script;
}) => TxOut.TransactionOutput;
/**
 * Convert an array of UTxOs to an array of TransactionInputs.
 * Inputs are sorted by txHash then outputIndex for deterministic ordering.
 *
 * @deprecated Use `UTxO.toInputs` from the core module instead.
 * @since 2.0.0
 * @category assembly
 */
export declare const buildTransactionInputs: (utxos: ReadonlyArray<CoreUTxO.UTxO>) => ReadonlyArray<TransactionInput.TransactionInput>;
/**
 * Assemble a Transaction from inputs, outputs, and calculated fee.
 * Creates TransactionBody with all required fields.
 *
 * Uses Core TransactionOutput directly.
 *
 * This is minimal assembly with accurate fee:
 * - Build witness set with redeemers and signatures (Step 4 - future)
 * - Run script evaluation to fill ExUnits (Step 5 - future)
 * - Add change output (Step 6 - future)
 *
 * @since 2.0.0
 * @category assembly
 */
export declare const assembleTransaction: (inputs: ReadonlyArray<TransactionInput.TransactionInput>, outputs: ReadonlyArray<TxOut.TransactionOutput>, fee: bigint) => Effect.Effect<Transaction.Transaction, TransactionBuilderError, TxContext | TxBuilderConfigTag | BuildOptionsTag>;
/**
 * Calculate the size of a transaction in bytes for fee estimation.
 * Uses CBOR serialization to get accurate size.
 *
 * @since 2.0.0
 * @category fee-calculation
 */
export declare const calculateTransactionSize: (transaction: Transaction.Transaction) => number;
/**
 * Calculate minimum transaction fee based on protocol parameters.
 *
 * Formula: minFee = txSizeInBytes × minFeeCoefficient + minFeeConstant
 *
 * @since 2.0.0
 * @category fee-calculation
 */
export declare const calculateMinimumFee: (transactionSizeBytes: number, protocolParams: {
    minFeeCoefficient: bigint;
    minFeeConstant: bigint;
}) => bigint;
/**
 * Build a fake witness set for fee estimation from transaction inputs.
 * Extracts unique payment key hashes from input addresses and creates
 * fake witnesses to accurately estimate witness set size in CBOR.
 * Includes any attached scripts from builder state for accurate size estimation.
 *
 * @since 2.0.0
 * @category fee-calculation
 */
export declare const buildFakeWitnessSet: (inputUtxos: ReadonlyArray<CoreUTxO.UTxO>) => Effect.Effect<TransactionWitnessSet.TransactionWitnessSet, TransactionBuilderError, TxContext>;
/**
 * Calculate transaction fee iteratively until stable.
 *
 * Algorithm:
 * 1. Build fake witness set from input UTxOs for accurate size estimation
 * 2. Build transaction with fee = 0
 * 3. Calculate size and fee
 * 4. Rebuild transaction with calculated fee
 * 5. If size changed, recalculate (usually converges in 1-2 iterations)
 *
 * @since 2.0.0
 * @category fee-calculation
 */
export declare const calculateFeeIteratively: (inputUtxos: ReadonlyArray<CoreUTxO.UTxO>, inputs: ReadonlyArray<TransactionInput.TransactionInput>, outputs: ReadonlyArray<TxOut.TransactionOutput>, redeemers: Map<string, {
    readonly tag: "spend" | "mint" | "cert" | "reward" | "vote";
    readonly data: PlutusData.Data;
    readonly exUnits?: {
        readonly mem: bigint;
        readonly steps: bigint;
    };
}>, protocolParams: {
    minFeeCoefficient: bigint;
    minFeeConstant: bigint;
    priceMem?: number;
    priceStep?: number;
}) => Effect.Effect<bigint, TransactionBuilderError, TxContext | BuildOptionsTag>;
/**
 * Verify if selected UTxOs can cover outputs + fee for ALL assets.
 * Used by the re-selection loop to determine if more UTxOs are needed.
 *
 * Checks both lovelace AND native assets (tokens/NFTs) to ensure complete balance.
 *
 * @since 2.0.0
 * @category fee-calculation
 */
export declare const verifyTransactionBalance: (selectedUtxos: ReadonlyArray<CoreUTxO.UTxO>, outputs: ReadonlyArray<TxOut.TransactionOutput>, fee: bigint) => {
    sufficient: boolean;
    shortfall: bigint;
    change: bigint;
};
/**
 * Validate that inputs cover outputs plus fee.
 * This is the ONLY validation for minimal build - no coin selection.
 *
 * @since 2.0.0
 * @category validation
 */
export declare const validateTransactionBalance: (params: {
    totalInputAssets: CoreAssets.Assets;
    totalOutputAssets: CoreAssets.Assets;
    fee: bigint;
}) => Effect.Effect<void, TransactionBuilderError>;
/**
 * Calculate leftover assets (will become excess fee in minimal build).
 *
 * @since 2.0.0
 * @category validation
 */
export declare const calculateLeftoverAssets: (params: {
    totalInputAssets: CoreAssets.Assets;
    totalOutputAssets: CoreAssets.Assets;
    fee: bigint;
}) => CoreAssets.Assets;
/**
 * Calculate minimum ADA required for a UTxO based on its actual CBOR size.
 * Uses the Babbage/Conway-era formula: coinsPerUtxoByte * (160 + serializedOutputSize).
 *
 * The 160-byte constant accounts for the UTxO entry overhead in the ledger state
 * (transaction hash + index). A lovelace placeholder is used during CBOR encoding
 * to ensure the coin field width matches the final result.
 *
 * This function creates a temporary TransactionOutput, encodes it to CBOR,
 * and calculates the exact size to determine the minimum lovelace required.
 *
 * @since 2.0.0
 * @category change
 */
export declare const calculateMinimumUtxoLovelace: (params: {
    address: CoreAddress.Address;
    assets: CoreAssets.Assets;
    datum?: DatumOption.DatumOption;
    scriptRef?: CoreScript.Script;
    coinsPerUtxoByte: bigint;
}) => Effect.Effect<bigint, TransactionBuilderError>;
/**
 * Create change output(s) for leftover assets.
 *
 * When unfracking is disabled (default):
 * 1. Check if leftover assets exist
 * 2. Calculate minimum ADA required for change output
 * 3. If leftover lovelace < minimum, cannot create change (warning)
 * 4. Create single output with all leftover assets to change address
 *
 * When unfracking is enabled:
 * 1. Apply Unfrack.It optimization strategies
 * 2. Bundle tokens into optimally-sized UTxOs
 * 3. Isolate fungible tokens if configured
 * 4. Group NFTs by policy if configured
 * 5. Roll up or subdivide ADA-only UTxOs
 * 6. Return multiple change outputs for optimal wallet structure
 *
 * @since 2.0.0
 * @category change
 */
export declare const createChangeOutput: (params: {
    leftoverAssets: CoreAssets.Assets;
    changeAddress: CoreAddress.Address;
    coinsPerUtxoByte: bigint;
    unfrackOptions?: UnfrackOptions;
}) => Effect.Effect<ReadonlyArray<TxOut.TransactionOutput>, TransactionBuilderError>;
//# sourceMappingURL=txBuilder.d.ts.map