{"version":3,"file":"index.cjs","sources":["../../../../../../src/v3/unified/index.ts","../../../../../../src/v3/actions/unwrap.ts"],"sourcesContent":["/**\n * Exports for @lightprotocol/compressed-token/unified\n *\n * Import from `/unified` to get a single unified associated token account for SPL/T22 and light-token\n * mints.\n */\nimport {\n    PublicKey,\n    Signer,\n    ConfirmOptions,\n    Commitment,\n    ComputeBudgetProgram,\n    TransactionInstruction,\n} from '@solana/web3.js';\nimport {\n    Rpc,\n    LIGHT_TOKEN_PROGRAM_ID,\n    buildAndSignTx,\n    sendAndConfirmTx,\n} from '@lightprotocol/stateless.js';\nimport BN from 'bn.js';\n\nimport {\n    getAtaInterface as _getAtaInterface,\n    AccountInterface,\n} from '../get-account-interface';\nimport { getAssociatedTokenAddressInterface as _getAssociatedTokenAddressInterface } from '../get-associated-token-address-interface';\nimport {\n    createLoadAtaInstructions as _createLoadAtaInstructions,\n    loadAta as _loadAta,\n} from '../actions/load-ata';\nimport { createAssociatedTokenAccountInterfaceIdempotentInstruction } from '../instructions/create-ata-interface';\nimport {\n    transferInterface as _transferInterface,\n    transferToAccountInterface as _transferToAccountInterface,\n    createTransferInterfaceInstructions as _createTransferInterfaceInstructions,\n    createTransferToAccountInterfaceInstructions as _createTransferToAccountInterfaceInstructions,\n} from '../actions/transfer-interface';\nimport {\n    approveInterface as _approveInterface,\n    revokeInterface as _revokeInterface,\n} from '../actions/approve-interface';\nimport {\n    createApproveInterfaceInstructions as _createApproveInterfaceInstructions,\n    createRevokeInterfaceInstructions as _createRevokeInterfaceInstructions,\n} from '../instructions/approve-interface';\n\nimport { _getOrCreateAtaInterface } from '../actions/get-or-create-ata-interface';\nimport {\n    createUnwrapInstructions as _createUnwrapInstructions,\n    unwrap as _unwrap,\n} from '../actions/unwrap';\nimport { SplInterfaceInfo } from '../../utils/get-token-pool-infos';\nimport { getAtaProgramId } from '../ata-utils';\nimport { InterfaceOptions } from '..';\nimport { getMintInterface } from '../get-mint-interface';\n\n/**\n * Get associated token account with unified balance\n *\n * @param rpc         RPC connection\n * @param ata         Associated token address\n * @param owner       Owner public key\n * @param mint        Mint public key\n * @param commitment  Optional commitment level\n * @param programId   Optional program ID (omit for unified behavior)\n * @returns AccountInterface with aggregated balance from all sources\n */\nexport async function getAtaInterface(\n    rpc: Rpc,\n    ata: PublicKey,\n    owner: PublicKey,\n    mint: PublicKey,\n    commitment?: Commitment,\n    programId?: PublicKey,\n): Promise<AccountInterface> {\n    return _getAtaInterface(rpc, ata, owner, mint, commitment, programId, true);\n}\n\n/**\n * Derive the canonical token associated token account for SPL/T22/light-token in the unified path.\n *\n * Enforces LIGHT_TOKEN_PROGRAM_ID.\n *\n * @param mint                      Mint public key\n * @param owner                     Owner public key\n * @param allowOwnerOffCurve        Allow owner to be a PDA. Default false.\n * @param programId                 Token program ID. Default light-token.\n * @param associatedTokenProgramId  Associated token program ID. Default\n *                                  auto-detected.\n * @returns                         Associated token address.\n */\nexport function getAssociatedTokenAddressInterface(\n    mint: PublicKey,\n    owner: PublicKey,\n    allowOwnerOffCurve = false,\n    programId: PublicKey = LIGHT_TOKEN_PROGRAM_ID,\n    associatedTokenProgramId?: PublicKey,\n): PublicKey {\n    if (!programId.equals(LIGHT_TOKEN_PROGRAM_ID)) {\n        throw new Error(\n            'Please derive the unified ATA from the light-token program; balances across SPL, T22, and light-token are unified under the canonical light-token ATA.',\n        );\n    }\n\n    return _getAssociatedTokenAddressInterface(\n        mint,\n        owner,\n        allowOwnerOffCurve,\n        programId,\n        associatedTokenProgramId,\n    );\n}\n\n/**\n * Create instruction batches for loading ALL token balances into a light-token associated token account.\n *\n * @param rpc     RPC connection\n * @param ata     Associated token address\n * @param owner   Owner public key\n * @param mint    Mint public key\n * @param payer   Fee payer (defaults to owner)\n * @param options Optional interface options\n * @returns Instruction batches - each inner array is one transaction\n */\nexport async function createLoadAtaInstructions(\n    rpc: Rpc,\n    ata: PublicKey,\n    owner: PublicKey,\n    mint: PublicKey,\n    payer?: PublicKey,\n    options?: InterfaceOptions,\n): Promise<TransactionInstruction[][]> {\n    const mintInterface = await getMintInterface(rpc, mint);\n    return _createLoadAtaInstructions(\n        rpc,\n        ata,\n        owner,\n        mint,\n        mintInterface.mint.decimals,\n        payer,\n        { ...options, wrap: true },\n    );\n}\n\n/**\n * Load all token balances into the light-token associated token account.\n *\n * Wraps SPL/Token-2022 balances and decompresses compressed light-tokens\n * into the on-chain light-token associated token account. If no balances exist and the associated token account doesn't\n * exist, creates an empty ATA (idempotent).\n *\n * @param rpc               RPC connection\n * @param ata               Associated token address (light-token)\n * @param owner             Owner of the tokens (signer)\n * @param mint              Mint public key\n * @param payer             Fee payer (signer, defaults to owner)\n * @param confirmOptions    Optional confirm options\n * @param interfaceOptions  Optional interface options\n * @returns Transaction signature, or null if ATA exists and nothing to load\n */\nexport async function loadAta(\n    rpc: Rpc,\n    ata: PublicKey,\n    owner: Signer,\n    mint: PublicKey,\n    payer?: Signer,\n    confirmOptions?: ConfirmOptions,\n    interfaceOptions?: InterfaceOptions,\n    decimals?: number,\n) {\n    payer ??= owner;\n\n    const signature = await _loadAta(\n        rpc,\n        ata,\n        owner,\n        mint,\n        payer,\n        confirmOptions,\n        { ...interfaceOptions, wrap: true },\n        decimals,\n    );\n\n    // If nothing to load, ensure ATA exists (idempotent).\n    if (signature === null) {\n        const accountInfo = await rpc.getAccountInfo(ata);\n        if (!accountInfo) {\n            const ix =\n                createAssociatedTokenAccountInterfaceIdempotentInstruction(\n                    payer.publicKey,\n                    ata,\n                    owner.publicKey,\n                    mint,\n                    LIGHT_TOKEN_PROGRAM_ID,\n                );\n            const { blockhash } = await rpc.getLatestBlockhash();\n            const tx = buildAndSignTx(\n                [\n                    ComputeBudgetProgram.setComputeUnitLimit({ units: 30_000 }),\n                    ix,\n                ],\n                payer,\n                blockhash,\n                payer.publicKey.equals(owner.publicKey) ? [] : [owner],\n            );\n            return sendAndConfirmTx(rpc, tx, confirmOptions);\n        }\n    }\n\n    return signature;\n}\n\n/**\n * Transfer tokens using the unified ata interface.\n *\n * Destination ATA is derived from `recipient` and created idempotently.\n * Automatically wraps SPL/T22 to light-token associated token account.\n *\n * @param rpc             RPC connection\n * @param payer           Fee payer (signer)\n * @param source          Source light-token associated token account address\n * @param mint            Mint address\n * @param recipient       Destination owner wallet address\n * @param owner           Source account owner pubkey\n * @param authority       Signing authority (owner or approved delegate)\n * @param amount          Amount to transfer\n * @param confirmOptions  Optional confirm options\n * @param options         Optional interface options\n * @returns Transaction signature\n */\nexport async function transferInterface(\n    rpc: Rpc,\n    payer: Signer,\n    source: PublicKey,\n    mint: PublicKey,\n    recipient: PublicKey,\n    owner: PublicKey,\n    authority: Signer,\n    amount: number | bigint | BN,\n    confirmOptions?: ConfirmOptions,\n    options?: InterfaceOptions,\n    decimals?: number,\n) {\n    return _transferInterface(\n        rpc,\n        payer,\n        source,\n        mint,\n        recipient,\n        owner,\n        authority,\n        amount,\n        undefined, // programId: use default LIGHT_TOKEN_PROGRAM_ID\n        confirmOptions,\n        { ...options, wrap: true }, // unified always wraps\n        decimals,\n    );\n}\n\n/**\n * Transfer tokens to an explicit destination token account.\n *\n * Use this for advanced routing to non-ATA destinations.\n */\nexport async function transferToAccountInterface(\n    rpc: Rpc,\n    payer: Signer,\n    source: PublicKey,\n    mint: PublicKey,\n    destination: PublicKey,\n    owner: PublicKey,\n    authority: Signer,\n    amount: number | bigint | BN,\n    confirmOptions?: ConfirmOptions,\n    options?: InterfaceOptions,\n    decimals?: number,\n) {\n    return _transferToAccountInterface(\n        rpc,\n        payer,\n        source,\n        mint,\n        destination,\n        owner,\n        authority,\n        amount,\n        undefined, // programId: use default LIGHT_TOKEN_PROGRAM_ID\n        confirmOptions,\n        { ...options, wrap: true }, // unified always wraps\n        decimals,\n    );\n}\n\n/**\n * Get or create light-token ATA with unified balance detection and auto-loading.\n *\n * Enforces LIGHT_TOKEN_PROGRAM_ID. Aggregates balances from:\n * - light-token associated token account (hot balance)\n * - compressed light-token accounts (cold balance)\n * - SPL token accounts (for unified wrapping)\n * - Token-2022 accounts (for unified wrapping)\n *\n * When owner is a Signer:\n * - Creates hot ATA if it doesn't exist\n * - Loads cold (compressed) tokens into hot ATA\n * - Wraps SPL/T22 tokens into light-token associated token account\n * - Returns account with all tokens ready to use\n *\n * When owner is a PublicKey:\n * - Creates hot ATA if it doesn't exist\n * - Returns aggregated balance but does NOT auto-load (can't sign)\n *\n * @param rpc             RPC connection\n * @param payer           Fee payer\n * @param mint            Mint address\n * @param owner           Owner (Signer for auto-load, PublicKey for read-only)\n * @param allowOwnerOffCurve Allow PDA owners (default: false)\n * @param commitment      Optional commitment level\n * @param confirmOptions  Optional confirm options\n * @returns AccountInterface with unified balance and source breakdown\n */\nexport async function getOrCreateAtaInterface(\n    rpc: Rpc,\n    payer: Signer,\n    mint: PublicKey,\n    owner: PublicKey | Signer,\n    allowOwnerOffCurve = false,\n    commitment?: Commitment,\n    confirmOptions?: ConfirmOptions,\n): Promise<AccountInterface> {\n    return _getOrCreateAtaInterface(\n        rpc,\n        payer,\n        mint,\n        owner,\n        allowOwnerOffCurve,\n        commitment,\n        confirmOptions,\n        LIGHT_TOKEN_PROGRAM_ID,\n        getAtaProgramId(LIGHT_TOKEN_PROGRAM_ID),\n        true, // wrap=true for unified path\n    );\n}\n\n/**\n * Create transfer instructions for a unified token transfer.\n *\n * Unified variant: always wraps SPL/T22 to light-token associated token account.\n * Recipient must be an on-curve wallet address. For PDA/off-curve owners,\n * use createTransferToAccountInterfaceInstructions with an explicit destination ATA.\n *\n * Returns `TransactionInstruction[][]`. Send [0..n-2] in parallel, then [n-1].\n * Use `sliceLast` to separate the parallel prefix from the final transfer.\n *\n * @see createTransferInterfaceInstructions in v3/actions/transfer-interface.ts\n */\nexport async function createTransferInterfaceInstructions(\n    rpc: Rpc,\n    payer: PublicKey,\n    mint: PublicKey,\n    amount: number | bigint | BN,\n    owner: PublicKey,\n    recipient: PublicKey,\n    options?: InterfaceOptions,\n): Promise<TransactionInstruction[][]> {\n    const mintInterface = await getMintInterface(rpc, mint);\n    return _createTransferInterfaceInstructions(\n        rpc,\n        payer,\n        mint,\n        amount,\n        owner,\n        recipient,\n        mintInterface.mint.decimals,\n        {\n            ...options,\n            wrap: true,\n        },\n    );\n}\n\n/**\n * Create transfer instructions that route to an explicit destination token\n * account.\n */\nexport async function createTransferToAccountInterfaceInstructions(\n    rpc: Rpc,\n    payer: PublicKey,\n    mint: PublicKey,\n    amount: number | bigint | BN,\n    owner: PublicKey,\n    destination: PublicKey,\n    options?: InterfaceOptions,\n): Promise<TransactionInstruction[][]> {\n    const mintInterface = await getMintInterface(rpc, mint);\n    return _createTransferToAccountInterfaceInstructions(\n        rpc,\n        payer,\n        mint,\n        amount,\n        owner,\n        destination,\n        mintInterface.mint.decimals,\n        {\n            ...options,\n            wrap: true,\n        },\n    );\n}\n\n/**\n * Build instruction batches for unwrapping light-tokens to SPL/T22.\n *\n * Load batches (cold -> hot) come first if needed; unwrap is bundled into the\n * final batch.\n * SPL/T22 balances are not consolidated; only light ATA (hot + cold) is unwrapped.\n *\n * Returns `TransactionInstruction[][]`. Load-only batches (if any) come first;\n * the last batch contains unwrap.\n *\n * @param rpc               RPC connection\n * @param destination       Destination SPL/T22 token account (must exist)\n * @param owner             Owner of the light-token\n * @param mint              Mint address\n * @param amount            Amount to unwrap (defaults to full balance)\n * @param payer             Fee payer (defaults to owner)\n * @param splInterfaceInfo  Optional: SPL interface info\n * @param interfaceOptions  Optional: interface options for load\n * @returns Instruction batches - each inner array is one transaction\n */\nexport async function createUnwrapInstructions(\n    rpc: Rpc,\n    destination: PublicKey,\n    owner: PublicKey,\n    mint: PublicKey,\n    amount?: number | bigint | BN,\n    payer?: PublicKey,\n    splInterfaceInfo?: SplInterfaceInfo,\n    interfaceOptions?: InterfaceOptions,\n): Promise<TransactionInstruction[][]> {\n    const mintInterface = await getMintInterface(rpc, mint);\n    return _createUnwrapInstructions(\n        rpc,\n        destination,\n        owner,\n        mint,\n        mintInterface.mint.decimals,\n        amount,\n        payer,\n        splInterfaceInfo,\n        undefined, // maxTopUp - use default\n        interfaceOptions,\n        false, // always no wrap on unwrap.\n    );\n}\n\n/**\n * Unwrap light-tokens to SPL tokens.\n *\n * Loads cold into hot if needed, then unwraps from light ATA to destination SPL/T22.\n * SPL/T22 balances are not consolidated; only light ATA balance is unwrapped.\n *\n * @param rpc                RPC connection\n * @param payer              Fee payer\n * @param destination        Destination SPL/T22 token account\n * @param owner              Owner of the light-token (signer)\n * @param mint               Mint address\n * @param amount             Amount to unwrap (defaults to all)\n * @param splInterfaceInfo   SPL interface info\n * @param confirmOptions     Confirm options\n * @returns Transaction signature of the unwrap transaction\n */\nexport async function unwrap(\n    rpc: Rpc,\n    payer: Signer,\n    destination: PublicKey,\n    owner: Signer,\n    mint: PublicKey,\n    amount?: number | bigint | BN,\n    splInterfaceInfo?: SplInterfaceInfo,\n    confirmOptions?: ConfirmOptions,\n    decimals?: number,\n): Promise<string> {\n    return _unwrap(\n        rpc,\n        payer,\n        destination,\n        owner,\n        mint,\n        amount,\n        splInterfaceInfo,\n        undefined, // maxTopUp - use default\n        confirmOptions,\n        decimals,\n        false, // always no wrap on unwrap.\n    );\n}\n\n/**\n * Approve a delegate for an associated token account.\n *\n * Auto-detects mint type (light-token, SPL, or Token-2022) and dispatches\n * to the appropriate instruction.\n *\n * @remarks For light-token mints, all cold (compressed) balances are loaded\n * into the hot ATA, not just the delegation amount. The `amount` parameter\n * only controls the delegate's spending limit.\n *\n * @param rpc            RPC connection\n * @param payer          Fee payer (signer)\n * @param tokenAccount   ATA address\n * @param mint           Mint address\n * @param delegate       Delegate to approve\n * @param amount         Amount to delegate\n * @param owner          Owner of the token account (signer)\n * @param confirmOptions Optional confirm options\n * @returns Transaction signature\n */\nexport async function approveInterface(\n    rpc: Rpc,\n    payer: Signer,\n    tokenAccount: PublicKey,\n    mint: PublicKey,\n    delegate: PublicKey,\n    amount: number | bigint | BN,\n    owner: Signer,\n    confirmOptions?: ConfirmOptions,\n    options?: InterfaceOptions,\n    decimals?: number,\n) {\n    return _approveInterface(\n        rpc,\n        payer,\n        tokenAccount,\n        mint,\n        delegate,\n        amount,\n        owner,\n        confirmOptions,\n        undefined, // programId: use default LIGHT_TOKEN_PROGRAM_ID\n        { ...options, wrap: true }, // unified always wraps\n        decimals,\n    );\n}\n\n/**\n * Build instruction batches for approving a delegate on an ATA.\n *\n * Auto-detects mint type (light-token, SPL, or Token-2022).\n *\n * @remarks For light-token mints, all cold (compressed) balances are loaded\n * into the hot ATA before the approve instruction. The `amount` parameter\n * only controls the delegate's spending limit, not the number of accounts\n * loaded.\n */\nexport async function createApproveInterfaceInstructions(\n    rpc: Rpc,\n    payer: PublicKey,\n    mint: PublicKey,\n    tokenAccount: PublicKey,\n    delegate: PublicKey,\n    amount: number | bigint | BN,\n    owner: PublicKey,\n    decimals?: number,\n    options?: InterfaceOptions,\n): Promise<TransactionInstruction[][]> {\n    const resolvedDecimals =\n        decimals ?? (await getMintInterface(rpc, mint)).mint.decimals;\n    return _createApproveInterfaceInstructions(\n        rpc,\n        payer,\n        mint,\n        tokenAccount,\n        delegate,\n        amount,\n        owner,\n        resolvedDecimals,\n        undefined, // programId: use default LIGHT_TOKEN_PROGRAM_ID\n        { ...options, wrap: true }, // unified always wraps\n    );\n}\n\n/**\n * Revoke delegation for an associated token account.\n *\n * Auto-detects mint type (light-token, SPL, or Token-2022) and dispatches\n * to the appropriate instruction.\n *\n * @remarks For light-token mints, all cold (compressed) balances are loaded\n * into the hot ATA before the revoke instruction.\n *\n * @param rpc            RPC connection\n * @param payer          Fee payer (signer)\n * @param tokenAccount   ATA address\n * @param mint           Mint address\n * @param owner          Owner of the token account (signer)\n * @param confirmOptions Optional confirm options\n * @returns Transaction signature\n */\nexport async function revokeInterface(\n    rpc: Rpc,\n    payer: Signer,\n    tokenAccount: PublicKey,\n    mint: PublicKey,\n    owner: Signer,\n    confirmOptions?: ConfirmOptions,\n    options?: InterfaceOptions,\n    decimals?: number,\n) {\n    return _revokeInterface(\n        rpc,\n        payer,\n        tokenAccount,\n        mint,\n        owner,\n        confirmOptions,\n        undefined, // programId: use default LIGHT_TOKEN_PROGRAM_ID\n        { ...options, wrap: true }, // unified always wraps\n        decimals,\n    );\n}\n\n/**\n * Build instruction batches for revoking delegation on an ATA.\n *\n * Auto-detects mint type (light-token, SPL, or Token-2022).\n *\n * @remarks For light-token mints, all cold (compressed) balances are loaded\n * into the hot ATA before the revoke instruction.\n */\nexport async function createRevokeInterfaceInstructions(\n    rpc: Rpc,\n    payer: PublicKey,\n    mint: PublicKey,\n    tokenAccount: PublicKey,\n    owner: PublicKey,\n    decimals?: number,\n    options?: InterfaceOptions,\n): Promise<TransactionInstruction[][]> {\n    const resolvedDecimals =\n        decimals ?? (await getMintInterface(rpc, mint)).mint.decimals;\n    return _createRevokeInterfaceInstructions(\n        rpc,\n        payer,\n        mint,\n        tokenAccount,\n        owner,\n        resolvedDecimals,\n        undefined, // programId: use default LIGHT_TOKEN_PROGRAM_ID\n        { ...options, wrap: true }, // unified always wraps\n    );\n}\n\nexport {\n    getAccountInterface,\n    AccountInterface,\n    TokenAccountSource,\n    // Note: Account is already exported from @solana/spl-token via get-account-interface\n    AccountState,\n    ParsedTokenAccount,\n    parseLightTokenHot,\n    parseLightTokenCold,\n    toAccountInfo,\n    convertTokenDataToAccount,\n} from '../get-account-interface';\n\nexport { InterfaceOptions, sliceLast } from '../actions/transfer-interface';\n\nexport * from '../../actions';\nexport * from '../../utils';\nexport * from '../../constants';\nexport * from '../../idl';\nexport * from '../../layout';\nexport * from '../../program';\nexport * from '../../types';\nexport * from '../derivation';\n\nexport {\n    // Instructions\n    createMintInstruction,\n    createTokenMetadata,\n    createAssociatedLightTokenAccountInstruction,\n    createAssociatedLightTokenAccountIdempotentInstruction,\n    createAssociatedTokenAccountInterfaceInstruction,\n    createAssociatedTokenAccountInterfaceIdempotentInstruction,\n    createAtaInterfaceIdempotentInstruction,\n    createMintToInstruction,\n    createMintToCompressedInstruction,\n    createMintToInterfaceInstruction,\n    createUpdateMintAuthorityInstruction,\n    createUpdateFreezeAuthorityInstruction,\n    createUpdateMetadataFieldInstruction,\n    createUpdateMetadataAuthorityInstruction,\n    createRemoveMetadataKeyInstruction,\n    createWrapInstruction,\n    createUnwrapInstruction,\n    createLightTokenTransferInstruction,\n    createLightTokenTransferCheckedInstruction,\n    createLightTokenFreezeAccountInstruction,\n    createLightTokenThawAccountInstruction,\n    createLightTokenApproveInstruction,\n    createLightTokenRevokeInstruction,\n    // Types\n    TokenMetadataInstructionData,\n    CompressibleConfig,\n    LightTokenConfig,\n    CreateAssociatedLightTokenAccountParams,\n    // Constants for rent sponsor\n    DEFAULT_COMPRESSIBLE_CONFIG,\n    // Actions\n    createMintInterface,\n    createAtaInterface,\n    createAtaInterfaceIdempotent,\n    // getOrCreateAtaInterface is defined locally with unified behavior\n    wrap,\n    // unwrap and createUnwrapInstructions are defined locally with unified behavior\n    mintTo as mintToLightToken,\n    mintToCompressed,\n    mintToInterface,\n    updateMintAuthority,\n    updateFreezeAuthority,\n    updateMetadataField,\n    updateMetadataAuthority,\n    removeMetadataKey,\n    // Helpers\n    getMintInterface,\n    unpackMintInterface,\n    unpackMintData,\n    MintInterface,\n    // Serde\n    BaseMint,\n    MintContext,\n    MintExtension,\n    TokenMetadata,\n    CompressedMint,\n    deserializeMint,\n    serializeMint,\n    decodeTokenMetadata,\n    encodeTokenMetadata,\n    extractTokenMetadata,\n    ExtensionType,\n    // Metadata formatting\n    toOffChainMetadataJson,\n    OffChainTokenMetadata,\n    OffChainTokenMetadataJson,\n} from '..';\n","import {\n    ConfirmOptions,\n    PublicKey,\n    Signer,\n    TransactionInstruction,\n    TransactionSignature,\n} from '@solana/web3.js';\nimport {\n    Rpc,\n    buildAndSignTx,\n    sendAndConfirmTx,\n    dedupeSigner,\n    assertV2Enabled,\n} from '@lightprotocol/stateless.js';\nimport { sliceLast } from './transfer-interface';\nimport BN from 'bn.js';\nimport { createUnwrapInstructions } from '../instructions/unwrap';\nimport { getMintInterface } from '../get-mint-interface';\nimport { type SplInterfaceInfo } from '../../utils/get-token-pool-infos';\n\nexport { createUnwrapInstructions } from '../instructions/unwrap';\n\nexport async function unwrap(\n    rpc: Rpc,\n    payer: Signer,\n    destination: PublicKey,\n    owner: Signer,\n    mint: PublicKey,\n    amount?: number | bigint | BN,\n    splInterfaceInfo?: SplInterfaceInfo,\n    maxTopUp?: number,\n    confirmOptions?: ConfirmOptions,\n    decimals?: number,\n    wrap = false,\n): Promise<TransactionSignature> {\n    assertV2Enabled();\n\n    const resolvedDecimals =\n        decimals ?? (await getMintInterface(rpc, mint)).mint.decimals;\n    const batches = await createUnwrapInstructions(\n        rpc,\n        destination,\n        owner.publicKey,\n        mint,\n        resolvedDecimals,\n        amount,\n        payer.publicKey,\n        splInterfaceInfo,\n        maxTopUp,\n        undefined,\n        wrap,\n    );\n\n    const additionalSigners = dedupeSigner(payer, [owner]);\n    const { rest: loads, last: unwrapIxs } = sliceLast(batches);\n\n    await Promise.all(\n        loads.map(async (ixs: TransactionInstruction[]) => {\n            const { blockhash } = await rpc.getLatestBlockhash();\n            const tx = buildAndSignTx(ixs, payer, blockhash, additionalSigners);\n            return sendAndConfirmTx(rpc, tx, confirmOptions);\n        }),\n    );\n\n    const { blockhash } = await rpc.getLatestBlockhash();\n    const tx = buildAndSignTx(unwrapIxs, payer, blockhash, additionalSigners);\n    return sendAndConfirmTx(rpc, tx, confirmOptions);\n}\n"],"names":["async","rpc","payer","tokenAccount","mint","delegate","amount","owner","confirmOptions","options","decimals","_approveInterface","approveInterface","undefined","Object","assign","wrap","resolvedDecimals","getMintInterface","_createApproveInterfaceInstructions","createApproveInterfaceInstructions","ata","mintInterface","_createLoadAtaInstructions","createLoadAtaInstructions","_createRevokeInterfaceInstructions","createRevokeInterfaceInstructions","recipient","_createTransferInterfaceInstructions","createTransferInterfaceInstructions","destination","_createTransferToAccountInterfaceInstructions","createTransferToAccountInterfaceInstructions","splInterfaceInfo","interfaceOptions","_createUnwrapInstructions","allowOwnerOffCurve","programId","LIGHT_TOKEN_PROGRAM_ID","associatedTokenProgramId","equals","Error","_getAssociatedTokenAddressInterface","commitment","_getAtaInterface","getAtaInterface","_getOrCreateAtaInterface","getAtaProgramId","signature","_loadAta","loadAta","getAccountInfo","ix","createAssociatedTokenAccountInterfaceIdempotentInstruction","publicKey","blockhash","getLatestBlockhash","tx","buildAndSignTx","ComputeBudgetProgram","setComputeUnitLimit","units","sendAndConfirmTx","_revokeInterface","source","authority","_transferInterface","transferInterface","_transferToAccountInterface","transferToAccountInterface","maxTopUp","assertV2Enabled","batches","createUnwrapInstructions","additionalSigners","dedupeSigner","rest","loads","last","unwrapIxs","sliceLast","Promise","all","map","ixs","_unwrap"],"mappings":"8pUAugBOA,eACHC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,GAEA,OAAOC,EAAiBC,iBACpBX,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,OACAK,EAASC,OAAAC,OAAAD,OAAAC,OAAA,CAAA,EACJN,GAAO,CAAEO,MAAM,IACpBN,EAER,6CAYOV,eACHC,EACAC,EACAE,EACAD,EACAE,EACAC,EACAC,EACAG,EACAD,GAEA,MAAMQ,EACFP,QAAAA,SAAmBQ,EAAgBA,iBAACjB,EAAKG,IAAOA,KAAKM,SACzD,OAAOS,EAAmCC,mCACtCnB,EACAC,EACAE,EACAD,EACAE,EACAC,EACAC,EACAU,OACAJ,EAASC,OAAAC,OAAAD,OAAAC,OAAA,CAAA,EACJN,GAAO,CAAEO,MAAM,IAE5B,oCAxcOhB,eACHC,EACAoB,EACAd,EACAH,EACAF,EACAO,GAEA,MAAMa,QAAsBJ,EAAAA,iBAAiBjB,EAAKG,GAClD,OAAOmB,EAA0BC,0BAC7BvB,EACAoB,EACAd,EACAH,EACAkB,EAAclB,KAAKM,SACnBR,EACKY,OAAAC,OAAAD,OAAAC,OAAA,GAAAN,IAASO,MAAM,IAE5B,4CAweOhB,eACHC,EACAC,EACAE,EACAD,EACAI,EACAG,EACAD,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