@lightprotocol/compressed-token 0.22.1-alpha.7 → 0.22.1-alpha.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/browser/index.cjs +1 -1
- package/dist/cjs/browser/types-DiKZshjI.cjs +2 -0
- package/dist/cjs/browser/types-DiKZshjI.cjs.map +1 -0
- package/dist/cjs/browser/unified/index.cjs +1 -1
- package/dist/cjs/browser/unified/index.cjs.map +1 -1
- package/dist/cjs/node/index.cjs +1 -1
- package/dist/cjs/node/types-DaJDA3il.cjs +2 -0
- package/dist/cjs/node/types-DaJDA3il.cjs.map +1 -0
- package/dist/cjs/node/unified/index.cjs +1 -1
- package/dist/cjs/node/unified/index.cjs.map +1 -1
- package/dist/es/browser/index.js +1 -1
- package/dist/es/browser/types-f0sdegvS.js +2 -0
- package/dist/es/browser/types-f0sdegvS.js.map +1 -0
- package/dist/es/browser/unified/index.js +1 -1
- package/dist/es/browser/unified/index.js.map +1 -1
- package/dist/types/index.d.ts +61 -3
- package/dist/types/unified/index.d.ts +63 -4
- package/package.json +2 -2
- package/dist/cjs/browser/types-PKSRBuNb.cjs +0 -2
- package/dist/cjs/browser/types-PKSRBuNb.cjs.map +0 -1
- package/dist/cjs/node/types-BG4VYREN.cjs +0 -2
- package/dist/cjs/node/types-BG4VYREN.cjs.map +0 -1
- package/dist/es/browser/types-CEJ8PsnP.js +0 -2
- package/dist/es/browser/types-CEJ8PsnP.js.map +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{TransactionInstruction as c,ComputeBudgetProgram as l}from"@solana/web3.js";import{CTOKEN_PROGRAM_ID as k,dedupeSigner as C,buildAndSignTx as D,sendAndConfirmTx as g}from"@lightprotocol/stateless.js";import{br as E,bs as ea,bt as ta,bo as sa,am as oa,C as na,l as ra,g as ca,c as ia,k as ua,E as pa,bu as da,bv as Ia}from"../types-
|
|
1
|
+
import{TransactionInstruction as c,ComputeBudgetProgram as l}from"@solana/web3.js";import{CTOKEN_PROGRAM_ID as k,dedupeSigner as C,buildAndSignTx as D,sendAndConfirmTx as g}from"@lightprotocol/stateless.js";import{br as E,bs as ea,bt as ta,bo as sa,am as oa,C as na,l as ra,g as ca,c as ia,k as ua,E as pa,bu as da,bv as Ia}from"../types-f0sdegvS.js";export{aP as ADD_TOKEN_POOL_DISCRIMINATOR,aN as APPROVE_DISCRIMINATOR,an as Action,aK as BATCH_COMPRESS_DISCRIMINATOR,bx as COMPRESSED_MINT_SEED,aM as COMPRESS_SPL_TOKEN_ACCOUNT_DISCRIMINATOR,aG as CPI_AUTHORITY_SEED,aI as CREATE_TOKEN_POOL_DISCRIMINATOR,bc as CompressedTokenInstructionDataApproveLayout,bd as CompressedTokenInstructionDataRevokeLayout,aU as CompressedTokenInstructionDataTransferLayout,aT as CpiContextLayout,aQ as DECOMPRESS_ACCOUNTS_IDEMPOTENT_DISCRIMINATOR,aS as DelegatedTransferLayout,av as ERROR_NO_ACCOUNTS_FOUND,a0 as ExtensionType,aR as IDL,aJ as MINT_TO_DISCRIMINATOR,aF as POOL_SEED,aO as REVOKE_DISCRIMINATOR,aH as SPL_TOKEN_MINT_RENT_EXEMPT_BALANCE,aL as TRANSFER_DISCRIMINATOR,aE as TokenDataVersion,a9 as addSplInterfaces,b5 as addTokenPoolAccountsLayout,aa as addTokenPools,a2 as approve,b8 as approveAccountsLayout,a3 as approveAndMintTo,aW as batchCompressLayout,d as calculateCompressibleLoadComputeUnits,aD as checkMint,al as checkSplInterfaceInfo,ar as checkTokenPoolInfo,a4 as compress,a5 as compressSplTokenAccount,aX as compressSplTokenAccountInstructionDataLayout,W as convertTokenDataToAccount,i as createAssociatedCTokenAccountIdempotentInstruction,h as createAssociatedCTokenAccountInstruction,j as createAssociatedTokenAccountInterfaceInstruction,A as createAtaInterface,B as createAtaInterfaceIdempotent,m as createAtaInterfaceIdempotentInstruction,y as createCTokenTransferInstruction,w as createDecompressInterfaceInstruction,bn as createDecompressOutputState,a as createLoadAccountsParams,b as createLoadAtaInstructionsFromInterface,a6 as createMint,e as createMintInstruction,z as createMintInterface,o as createMintToCompressedInstruction,n as createMintToInstruction,p as createMintToInterfaceInstruction,u as createRemoveMetadataKeyInstruction,a7 as createSplInterface,f as createTokenMetadata,a8 as createTokenPool,b4 as createTokenPoolAccountsLayout,ab as createTokenProgramLookupTable,x as createTransferInterfaceInstruction,bm as createTransferOutputState,r as createUpdateFreezeAuthorityInstruction,t as createUpdateMetadataAuthorityInstruction,s as createUpdateMetadataFieldInstruction,q as createUpdateMintAuthorityInstruction,v as createWrapInstruction,bf as decodeApproveInstructionData,a$ as decodeBatchCompressInstructionData,b1 as decodeCompressSplTokenAccountInstructionData,aZ as decodeMintToInstructionData,bh as decodeRevokeInstructionData,Z as decodeTokenMetadata,b3 as decodeTransferInstructionData,ac as decompress,ai as decompressDelegated,F as decompressInterface,bw as deriveCMintAddress,ak as deriveSplInterfaceInfo,aq as deriveTokenPoolInfo,X as deserializeMint,be as encodeApproveInstructionData,a_ as encodeBatchCompressInstructionData,b0 as encodeCompressSplTokenAccountInstructionData,aY as encodeMintToInstructionData,bg as encodeRevokeInstructionData,_ as encodeTokenMetadata,b2 as encodeTransferInstructionData,$ as extractTokenMetadata,by as findMintAddress,ba as freezeAccountsLayout,S as getAccountInterface,bA as getAssociatedCTokenAddress,bz as getAssociatedCTokenAddressAndBump,P as getMintInterface,as as getTokenPoolInfos,bp as isSingleSplInterfaceInfo,bq as isSingleTokenPoolInfo,ad as mergeTokenAccounts,ae as mintTo,b6 as mintToAccountsLayout,H as mintToCToken,I as mintToCompressed,J as mintToInterface,aV as mintToLayout,aC as packCompressedTokenAccounts,U as parseCTokenCold,T as parseCTokenHot,bl as parseMaybeDelegatedTransfer,bk as parseTokenData,O as removeMetadataKey,af as revoke,b9 as revokeAccountsLayout,ax as selectMinCompressedTokenAccountsForDecompression,ay as selectMinCompressedTokenAccountsForTransfer,az as selectMinCompressedTokenAccountsForTransferOrPartial,aA as selectSmartCompressedTokenAccountsForTransfer,aB as selectSmartCompressedTokenAccountsForTransferOrPartial,ao as selectSplInterfaceInfo,ap as selectSplInterfaceInfosForDecompression,aw as selectTokenAccountsForApprove,at as selectTokenPoolInfo,au as selectTokenPoolInfosForDecompression,Y as serializeMint,bi as sumUpTokenAmount,bb as thawAccountsLayout,V as toAccountInfo,a1 as toOffChainMetadataJson,aj as toTokenPoolInfo,ag as transfer,b7 as transferAccountsLayout,ah as transferDelegated,R as unpackMintData,Q as unpackMintInterface,L as updateFreezeAuthority,N as updateMetadataAuthority,M as updateMetadataField,K as updateMintAuthority,bj as validateSameTokenOwner,G as wrap}from"../types-f0sdegvS.js";import{getMint as la}from"@solana/spl-token";export{AccountState}from"@solana/spl-token";import"@coral-xyz/borsh";function Ta(a,e,t,s,o,n,r,i=t){const u=[E(o,0,2,1,6),ea(o,0,3,4,n.poolIndex,n.bump,r)],p=ta({withTransactionHash:0,withLamportsChangeAccountMerkleTreeIndex:0,lamportsChangeAccountMerkleTreeIndex:0,lamportsChangeAccountOwnerIndex:0,outputQueue:0,maxTopUp:0,cpiContext:null,compressions:u,proof:null,inTokenData:[],outTokenData:[],inLamports:null,outLamports:null,inTlv:null,outTlv:null}),d=[{pubkey:sa.deriveCpiAuthorityPda,isSigner:0,isWritable:0},{pubkey:i,isSigner:1,isWritable:1},{pubkey:s,isSigner:0,isWritable:0},{pubkey:t,isSigner:1,isWritable:0},{pubkey:a,isSigner:0,isWritable:1},{pubkey:e,isSigner:0,isWritable:1},{pubkey:n.splInterfacePda,isSigner:0,isWritable:1},{pubkey:n.tokenProgram,isSigner:0,isWritable:0},{pubkey:k,isSigner:0,isWritable:0}];return new c({programId:sa.programId,keys:d,data:p})}async function fa(a,e,t,s,o,n,r,c){let i=r;if(!i&&(i=(await oa(a,o)).find((a=>a.isInitialized)),!i))throw new Error(`No initialized SPL interface found for mint: ${o.toBase58()}. Please create an SPL interface via createSplInterface().`);if(!await a.getAccountInfo(t))throw new Error(`Destination account does not exist: ${t.toBase58()}. Create it first using getOrCreateAssociatedTokenAccount or createAssociatedTokenAccountIdempotentInstruction.`);const u=na(o,s.publicKey);await ra(a,u,s,o,e,c);const p=await a.getAccountInfo(u);if(!p)throw new Error("No c-token ATA found after loading");const d=p.data.readBigUInt64LE(64);if(d===BigInt(0))throw new Error("No c-token balance to unwrap");const I=n?BigInt(n.toString()):d;if(I>d)throw new Error(`Insufficient c-token balance. Requested: ${I}, Available: ${d}`);const T=await la(a,o,void 0,i.tokenProgram),f=Ta(u,t,s.publicKey,o,I,i,T.decimals,e.publicKey),{blockhash:A}=await a.getLatestBlockhash(),k=C(e,[s]),m=D([l.setComputeUnitLimit({units:2e5}),f],e,A,k);return await g(a,m,c)}async function Aa(a,e,t,s,o,n){return ca(a,e,t,s,o,n,1)}function ka(a,e,t=0,s=k,o){if(!s.equals(k))throw new Error("Please derive the unified ATA from the c-token program; balances across SPL, T22, and c-token are unified under the canonical c-token ATA.");return na(a,e,t,s,o)}async function ma(a,e,t,s,o,n){return ia(a,e,t,s,o,n,1)}async function Ca(a,e,t,s,o,n,r){o??=t;const c=await ra(a,e,t,s,o,n,r,1);if(null===c&&!await a.getAccountInfo(e)){const r=ua(o.publicKey,e,t.publicKey,s,k),{blockhash:c}=await a.getLatestBlockhash(),i=D([l.setComputeUnitLimit({units:3e4}),r],o,c,o.publicKey.equals(t.publicKey)?[]:[t]);return g(a,i,n)}return c}async function Sa(a,e,t,s,o,n,r,c=k,i,u){return pa(a,e,t,s,o,n,r,c,i,u,1)}async function ya(a,e,t,s,o=0,n,r){return da(a,e,t,s,o,n,r,k,Ia(k),1)}export{sa as CompressedTokenProgram,ua as createAssociatedTokenAccountInterfaceIdempotentInstruction,ma as createLoadAtaInstructions,Ta as createUnwrapInstruction,ka as getAssociatedTokenAddressInterface,Aa as getAtaInterface,ya as getOrCreateAtaInterface,oa as getSplInterfaceInfos,Ca as loadAta,Sa as transferInterface,fa as unwrap};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../../../src/v3/instructions/unwrap.ts","../../../../../../src/v3/actions/unwrap.ts","../../../../../../src/v3/unified/index.ts"],"sourcesContent":["import { PublicKey, TransactionInstruction } from '@solana/web3.js';\nimport { CTOKEN_PROGRAM_ID } from '@lightprotocol/stateless.js';\nimport { CompressedTokenProgram } from '../../program';\nimport { SplInterfaceInfo } from '../../utils/get-token-pool-infos';\nimport {\n encodeTransfer2InstructionData,\n createCompressCtoken,\n createDecompressSpl,\n Transfer2InstructionData,\n Compression,\n} from '../layout/layout-transfer2';\n\n/**\n * Create an unwrap instruction that moves tokens from a c-token account to an\n * SPL/T22 account.\n *\n * @param source Source c-token account\n * @param destination Destination SPL/T22 token account\n * @param owner Owner of the source account (signer)\n * @param mint Mint address\n * @param amount Amount to unwrap,\n * @param splInterfaceInfo SPL interface info for the decompression\n * @param payer Fee payer (defaults to owner if not provided)\n * @returns TransactionInstruction to unwrap tokens\n */\nexport function createUnwrapInstruction(\n source: PublicKey,\n destination: PublicKey,\n owner: PublicKey,\n mint: PublicKey,\n amount: bigint,\n splInterfaceInfo: SplInterfaceInfo,\n payer: PublicKey = owner,\n): TransactionInstruction {\n const MINT_INDEX = 0;\n const OWNER_INDEX = 1;\n const SOURCE_INDEX = 2;\n const DESTINATION_INDEX = 3;\n const POOL_INDEX = 4;\n const _SPL_TOKEN_PROGRAM_INDEX = 5;\n const CTOKEN_PROGRAM_INDEX = 6;\n\n // Unwrap flow: compress from c-token, decompress to SPL\n const compressions: Compression[] = [\n createCompressCtoken(\n amount,\n MINT_INDEX,\n SOURCE_INDEX,\n OWNER_INDEX,\n CTOKEN_PROGRAM_INDEX,\n ),\n createDecompressSpl(\n amount,\n MINT_INDEX,\n DESTINATION_INDEX,\n POOL_INDEX,\n splInterfaceInfo.poolIndex,\n splInterfaceInfo.bump,\n ),\n ];\n\n const instructionData: Transfer2InstructionData = {\n withTransactionHash: false,\n withLamportsChangeAccountMerkleTreeIndex: false,\n lamportsChangeAccountMerkleTreeIndex: 0,\n lamportsChangeAccountOwnerIndex: 0,\n outputQueue: 0,\n maxTopUp: 0,\n cpiContext: null,\n compressions,\n proof: null,\n inTokenData: [],\n outTokenData: [],\n inLamports: null,\n outLamports: null,\n inTlv: null,\n outTlv: null,\n };\n\n const data = encodeTransfer2InstructionData(instructionData);\n\n // Account order matches wrap instruction for consistency\n const keys = [\n {\n pubkey: CompressedTokenProgram.deriveCpiAuthorityPda,\n isSigner: false,\n isWritable: false,\n },\n { pubkey: payer, isSigner: true, isWritable: true },\n { pubkey: mint, isSigner: false, isWritable: false },\n { pubkey: owner, isSigner: true, isWritable: false },\n { pubkey: source, isSigner: false, isWritable: true },\n { pubkey: destination, isSigner: false, isWritable: true },\n {\n pubkey: splInterfaceInfo.splInterfacePda,\n isSigner: false,\n isWritable: true,\n },\n {\n pubkey: splInterfaceInfo.tokenProgram,\n isSigner: false,\n isWritable: false,\n },\n {\n pubkey: CTOKEN_PROGRAM_ID,\n isSigner: false,\n isWritable: false,\n },\n ];\n\n return new TransactionInstruction({\n programId: CompressedTokenProgram.programId,\n keys,\n data,\n });\n}\n","import {\n ComputeBudgetProgram,\n ConfirmOptions,\n PublicKey,\n Signer,\n TransactionSignature,\n} from '@solana/web3.js';\nimport {\n Rpc,\n buildAndSignTx,\n sendAndConfirmTx,\n dedupeSigner,\n} from '@lightprotocol/stateless.js';\nimport BN from 'bn.js';\nimport { createUnwrapInstruction } from '../instructions/unwrap';\nimport {\n getSplInterfaceInfos,\n SplInterfaceInfo,\n} from '../../utils/get-token-pool-infos';\nimport { getAssociatedTokenAddressInterface } from '../get-associated-token-address-interface';\nimport { loadAta as _loadAta } from './load-ata';\n\n/**\n * Unwrap c-tokens to SPL tokens.\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 c-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 *\n * @returns Transaction signature\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): Promise<TransactionSignature> {\n // 1. Get SPL interface info if not provided\n let resolvedSplInterfaceInfo = splInterfaceInfo;\n if (!resolvedSplInterfaceInfo) {\n const splInterfaceInfos = await getSplInterfaceInfos(rpc, mint);\n resolvedSplInterfaceInfo = splInterfaceInfos.find(\n info => info.isInitialized,\n );\n\n if (!resolvedSplInterfaceInfo) {\n throw new Error(\n `No initialized SPL interface found for mint: ${mint.toBase58()}. ` +\n `Please create an SPL interface via createSplInterface().`,\n );\n }\n }\n\n const destAtaInfo = await rpc.getAccountInfo(destination);\n if (!destAtaInfo) {\n throw new Error(\n `Destination account does not exist: ${destination.toBase58()}. ` +\n `Create it first using getOrCreateAssociatedTokenAccount or createAssociatedTokenAccountIdempotentInstruction.`,\n );\n }\n\n // Load all tokens to c-token hot ATA\n const ctokenAta = getAssociatedTokenAddressInterface(mint, owner.publicKey);\n await _loadAta(rpc, ctokenAta, owner, mint, payer, confirmOptions);\n\n // Check c-token hot balance\n const ctokenAccountInfo = await rpc.getAccountInfo(ctokenAta);\n if (!ctokenAccountInfo) {\n throw new Error('No c-token ATA found after loading');\n }\n\n // Parse c-token account balance\n const data = ctokenAccountInfo.data;\n const ctokenBalance = data.readBigUInt64LE(64);\n\n if (ctokenBalance === BigInt(0)) {\n throw new Error('No c-token balance to unwrap');\n }\n\n const unwrapAmount = amount ? BigInt(amount.toString()) : ctokenBalance;\n\n if (unwrapAmount > ctokenBalance) {\n throw new Error(\n `Insufficient c-token balance. Requested: ${unwrapAmount}, Available: ${ctokenBalance}`,\n );\n }\n\n // Build unwrap instruction\n const ix = createUnwrapInstruction(\n ctokenAta,\n destination,\n owner.publicKey,\n mint,\n unwrapAmount,\n resolvedSplInterfaceInfo,\n payer.publicKey,\n );\n\n const { blockhash } = await rpc.getLatestBlockhash();\n const additionalSigners = dedupeSigner(payer, [owner]);\n\n const tx = buildAndSignTx(\n [ComputeBudgetProgram.setComputeUnitLimit({ units: 200_000 }), ix],\n payer,\n blockhash,\n additionalSigners,\n );\n\n const txId = await sendAndConfirmTx(rpc, tx, confirmOptions);\n\n return txId;\n}\n","/**\n * Exports for @lightprotocol/compressed-token/unified\n *\n * Import from `/unified` to get a single unified ATA for SPL/T22 and c-token\n * mints.\n */\nimport {\n PublicKey,\n Signer,\n ConfirmOptions,\n Commitment,\n ComputeBudgetProgram,\n} from '@solana/web3.js';\nimport {\n Rpc,\n CTOKEN_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 { transferInterface as _transferInterface } from '../actions/transfer-interface';\nimport { _getOrCreateAtaInterface } from '../actions/get-or-create-ata-interface';\nimport { getAtaProgramId } from '../ata-utils';\nimport { InterfaceOptions } from '..';\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 ATA for SPL/T22/c-token in the unified path.\n *\n * Enforces CTOKEN_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 c-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 = CTOKEN_PROGRAM_ID,\n associatedTokenProgramId?: PublicKey,\n): PublicKey {\n if (!programId.equals(CTOKEN_PROGRAM_ID)) {\n throw new Error(\n 'Please derive the unified ATA from the c-token program; balances across SPL, T22, and c-token are unified under the canonical c-token ATA.',\n );\n }\n\n return _getAssociatedTokenAddressInterface(\n mint,\n owner,\n allowOwnerOffCurve,\n programId,\n associatedTokenProgramId,\n );\n}\n\n/**\n * Create instructions to load ALL token balances into a c-token ATA.\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 Array of instructions (empty if nothing to load)\n */\nexport async function createLoadAtaInstructions(\n rpc: Rpc,\n ata: PublicKey,\n owner: PublicKey,\n mint: PublicKey,\n payer?: PublicKey,\n options?: InterfaceOptions,\n) {\n return _createLoadAtaInstructions(\n rpc,\n ata,\n owner,\n mint,\n payer,\n options,\n true,\n );\n}\n\n/**\n * Load all token balances into the c-token ATA.\n *\n * Wraps SPL/Token-2022 balances and decompresses compressed c-tokens\n * into the on-chain c-token ATA. If no balances exist and the ATA doesn't\n * exist, creates an empty ATA (idempotent).\n *\n * @param rpc RPC connection\n * @param ata Associated token address (c-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) {\n payer ??= owner;\n\n const signature = await _loadAta(\n rpc,\n ata,\n owner,\n mint,\n payer,\n confirmOptions,\n interfaceOptions,\n true,\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 CTOKEN_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 * Matches SPL Token's transferChecked signature order. Destination must exist.\n *\n * @param rpc RPC connection\n * @param payer Fee payer (signer)\n * @param source Source c-token ATA address\n * @param mint Mint address\n * @param destination Destination c-token ATA address (must exist)\n * @param owner Source owner (signer)\n * @param amount Amount to transfer\n * @param programId Token program ID (default: CTOKEN_PROGRAM_ID)\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 destination: PublicKey,\n owner: Signer,\n amount: number | bigint | BN,\n programId: PublicKey = CTOKEN_PROGRAM_ID,\n confirmOptions?: ConfirmOptions,\n options?: InterfaceOptions,\n) {\n return _transferInterface(\n rpc,\n payer,\n source,\n mint,\n destination,\n owner,\n amount,\n programId,\n confirmOptions,\n options,\n true,\n );\n}\n\n/**\n * Get or create c-token ATA with unified balance detection and auto-loading.\n *\n * Enforces CTOKEN_PROGRAM_ID. Aggregates balances from:\n * - c-token hot (on-chain) account\n * - c-token cold (compressed) accounts\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 c-token ATA\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 CTOKEN_PROGRAM_ID,\n getAtaProgramId(CTOKEN_PROGRAM_ID),\n true, // wrap=true for unified path\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 parseCTokenHot,\n parseCTokenCold,\n toAccountInfo,\n convertTokenDataToAccount,\n} from '../get-account-interface';\n\nexport {\n createLoadAccountsParams,\n createLoadAtaInstructionsFromInterface,\n calculateCompressibleLoadComputeUnits,\n CompressibleAccountInput,\n ParsedAccountInfoInterface,\n CompressibleLoadParams,\n PackedCompressedAccount,\n LoadResult,\n} from '../actions/load-ata';\n\nexport { InterfaceOptions } 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 createAssociatedCTokenAccountInstruction,\n createAssociatedCTokenAccountIdempotentInstruction,\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 createDecompressInterfaceInstruction,\n createTransferInterfaceInstruction,\n createCTokenTransferInstruction,\n // Types\n TokenMetadataInstructionData,\n CompressibleConfig,\n CTokenConfig,\n CreateAssociatedCTokenAccountParams,\n // Actions\n createMintInterface,\n createAtaInterface,\n createAtaInterfaceIdempotent,\n // getOrCreateAtaInterface is defined locally with unified behavior\n decompressInterface,\n wrap,\n unwrap,\n mintTo as mintToCToken,\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"],"names":["createUnwrapInstruction","source","destination","owner","mint","amount","splInterfaceInfo","payer","compressions","createCompressCtoken","createDecompressSpl","poolIndex","bump","data","encodeTransfer2InstructionData","withTransactionHash","withLamportsChangeAccountMerkleTreeIndex","lamportsChangeAccountMerkleTreeIndex","lamportsChangeAccountOwnerIndex","outputQueue","maxTopUp","cpiContext","proof","inTokenData","outTokenData","inLamports","outLamports","inTlv","outTlv","keys","pubkey","CompressedTokenProgram","deriveCpiAuthorityPda","isSigner","isWritable","splInterfacePda","tokenProgram","CTOKEN_PROGRAM_ID","TransactionInstruction","programId","async","unwrap","rpc","confirmOptions","resolvedSplInterfaceInfo","getSplInterfaceInfos","find","info","isInitialized","Error","toBase58","getAccountInfo","ctokenAta","getAssociatedTokenAddressInterface","publicKey","_loadAta","ctokenAccountInfo","ctokenBalance","readBigUInt64LE","BigInt","unwrapAmount","toString","ix","blockhash","getLatestBlockhash","additionalSigners","dedupeSigner","tx","buildAndSignTx","ComputeBudgetProgram","setComputeUnitLimit","units","sendAndConfirmTx","getAtaInterface","ata","commitment","_getAtaInterface","allowOwnerOffCurve","associatedTokenProgramId","equals","_getAssociatedTokenAddressInterface","createLoadAtaInstructions","options","_createLoadAtaInstructions","loadAta","interfaceOptions","signature","createAssociatedTokenAccountInterfaceIdempotentInstruction","transferInterface","_transferInterface","getOrCreateAtaInterface","_getOrCreateAtaInterface","getAtaProgramId"],"mappings":"stJAyBgBA,GACZC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAAmBJ,GAEnB,MASMK,EAA8B,CAChCC,EACIJ,EAXW,EAEE,EADD,EAKS,GAWzBK,GACIL,EAlBW,EAGO,EACP,EAkBXC,EAAiBK,UACjBL,EAAiBM,OAsBnBC,EAAOC,GAlBqC,CAC9CC,oBAAqB,EACrBC,yCAA0C,EAC1CC,qCAAsC,EACtCC,gCAAiC,EACjCC,YAAa,EACbC,SAAU,EACVC,WAAY,KACZb,eACAc,MAAO,KACPC,YAAa,GACbC,aAAc,GACdC,WAAY,KACZC,YAAa,KACbC,MAAO,KACPC,OAAQ,OAMNC,EAAO,CACT,CACIC,OAAQC,GAAuBC,sBAC/BC,SAAU,EACVC,WAAY,GAEhB,CAAEJ,OAAQvB,EAAO0B,SAAU,EAAMC,W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ACAE,EACAkC,EAAuBF,EACvBM,EACAuC,GAEA,OAAOO,GACH/C,EACAnC,EACAN,EACAG,EACAF,EACAC,EACAE,EACAkC,EACAI,EACAuC,EACA,EAER,CA8BO1C,eAAekD,GAClBhD,EACAnC,EACAH,EACAD,EACA0E,EAAqB,EACrBF,EACAhC,GAEA,OAAOgD,GACHjD,EACAnC,EACAH,EACAD,EACA0E,EACAF,EACAhC,EACAN,EACAuD,GAAgBvD,GAChB,EAER"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../../src/v3/instructions/unwrap.ts","../../../../../../src/v3/actions/unwrap.ts","../../../../../../src/v3/unified/index.ts"],"sourcesContent":["import { PublicKey, TransactionInstruction } from '@solana/web3.js';\nimport { CTOKEN_PROGRAM_ID } from '@lightprotocol/stateless.js';\nimport { CompressedTokenProgram } from '../../program';\nimport { SplInterfaceInfo } from '../../utils/get-token-pool-infos';\nimport {\n encodeTransfer2InstructionData,\n createCompressCtoken,\n createDecompressSpl,\n Transfer2InstructionData,\n Compression,\n} from '../layout/layout-transfer2';\n\n/**\n * Create an unwrap instruction that moves tokens from a c-token account to an\n * SPL/T22 account.\n *\n * @param source Source c-token account\n * @param destination Destination SPL/T22 token account\n * @param owner Owner of the source account (signer)\n * @param mint Mint address\n * @param amount Amount to unwrap,\n * @param splInterfaceInfo SPL interface info for the decompression\n * @param decimals Mint decimals (required for transfer_checked)\n * @param payer Fee payer (defaults to owner if not provided)\n * @returns TransactionInstruction to unwrap tokens\n */\nexport function createUnwrapInstruction(\n source: PublicKey,\n destination: PublicKey,\n owner: PublicKey,\n mint: PublicKey,\n amount: bigint,\n splInterfaceInfo: SplInterfaceInfo,\n decimals: number,\n payer: PublicKey = owner,\n): TransactionInstruction {\n const MINT_INDEX = 0;\n const OWNER_INDEX = 1;\n const SOURCE_INDEX = 2;\n const DESTINATION_INDEX = 3;\n const POOL_INDEX = 4;\n const _SPL_TOKEN_PROGRAM_INDEX = 5;\n const CTOKEN_PROGRAM_INDEX = 6;\n\n // Unwrap flow: compress from c-token, decompress to SPL\n const compressions: Compression[] = [\n createCompressCtoken(\n amount,\n MINT_INDEX,\n SOURCE_INDEX,\n OWNER_INDEX,\n CTOKEN_PROGRAM_INDEX,\n ),\n createDecompressSpl(\n amount,\n MINT_INDEX,\n DESTINATION_INDEX,\n POOL_INDEX,\n splInterfaceInfo.poolIndex,\n splInterfaceInfo.bump,\n decimals,\n ),\n ];\n\n const instructionData: Transfer2InstructionData = {\n withTransactionHash: false,\n withLamportsChangeAccountMerkleTreeIndex: false,\n lamportsChangeAccountMerkleTreeIndex: 0,\n lamportsChangeAccountOwnerIndex: 0,\n outputQueue: 0,\n maxTopUp: 0,\n cpiContext: null,\n compressions,\n proof: null,\n inTokenData: [],\n outTokenData: [],\n inLamports: null,\n outLamports: null,\n inTlv: null,\n outTlv: null,\n };\n\n const data = encodeTransfer2InstructionData(instructionData);\n\n // Account order matches wrap instruction for consistency\n const keys = [\n {\n pubkey: CompressedTokenProgram.deriveCpiAuthorityPda,\n isSigner: false,\n isWritable: false,\n },\n { pubkey: payer, isSigner: true, isWritable: true },\n { pubkey: mint, isSigner: false, isWritable: false },\n { pubkey: owner, isSigner: true, isWritable: false },\n { pubkey: source, isSigner: false, isWritable: true },\n { pubkey: destination, isSigner: false, isWritable: true },\n {\n pubkey: splInterfaceInfo.splInterfacePda,\n isSigner: false,\n isWritable: true,\n },\n {\n pubkey: splInterfaceInfo.tokenProgram,\n isSigner: false,\n isWritable: false,\n },\n {\n pubkey: CTOKEN_PROGRAM_ID,\n isSigner: false,\n isWritable: false,\n },\n ];\n\n return new TransactionInstruction({\n programId: CompressedTokenProgram.programId,\n keys,\n data,\n });\n}\n","import {\n ComputeBudgetProgram,\n ConfirmOptions,\n PublicKey,\n Signer,\n TransactionSignature,\n} from '@solana/web3.js';\nimport {\n Rpc,\n buildAndSignTx,\n sendAndConfirmTx,\n dedupeSigner,\n} from '@lightprotocol/stateless.js';\nimport { getMint } from '@solana/spl-token';\nimport BN from 'bn.js';\nimport { createUnwrapInstruction } from '../instructions/unwrap';\nimport {\n getSplInterfaceInfos,\n SplInterfaceInfo,\n} from '../../utils/get-token-pool-infos';\nimport { getAssociatedTokenAddressInterface } from '../get-associated-token-address-interface';\nimport { loadAta as _loadAta } from './load-ata';\n\n/**\n * Unwrap c-tokens to SPL tokens.\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 c-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 *\n * @returns Transaction signature\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): Promise<TransactionSignature> {\n // 1. Get SPL interface info if not provided\n let resolvedSplInterfaceInfo = splInterfaceInfo;\n if (!resolvedSplInterfaceInfo) {\n const splInterfaceInfos = await getSplInterfaceInfos(rpc, mint);\n resolvedSplInterfaceInfo = splInterfaceInfos.find(\n info => info.isInitialized,\n );\n\n if (!resolvedSplInterfaceInfo) {\n throw new Error(\n `No initialized SPL interface found for mint: ${mint.toBase58()}. ` +\n `Please create an SPL interface via createSplInterface().`,\n );\n }\n }\n\n const destAtaInfo = await rpc.getAccountInfo(destination);\n if (!destAtaInfo) {\n throw new Error(\n `Destination account does not exist: ${destination.toBase58()}. ` +\n `Create it first using getOrCreateAssociatedTokenAccount or createAssociatedTokenAccountIdempotentInstruction.`,\n );\n }\n\n // Load all tokens to c-token hot ATA\n const ctokenAta = getAssociatedTokenAddressInterface(mint, owner.publicKey);\n await _loadAta(rpc, ctokenAta, owner, mint, payer, confirmOptions);\n\n // Check c-token hot balance\n const ctokenAccountInfo = await rpc.getAccountInfo(ctokenAta);\n if (!ctokenAccountInfo) {\n throw new Error('No c-token ATA found after loading');\n }\n\n // Parse c-token account balance\n const data = ctokenAccountInfo.data;\n const ctokenBalance = data.readBigUInt64LE(64);\n\n if (ctokenBalance === BigInt(0)) {\n throw new Error('No c-token balance to unwrap');\n }\n\n const unwrapAmount = amount ? BigInt(amount.toString()) : ctokenBalance;\n\n if (unwrapAmount > ctokenBalance) {\n throw new Error(\n `Insufficient c-token balance. Requested: ${unwrapAmount}, Available: ${ctokenBalance}`,\n );\n }\n\n // Get mint info to get decimals\n const mintInfo = await getMint(\n rpc,\n mint,\n undefined,\n resolvedSplInterfaceInfo.tokenProgram,\n );\n\n // Build unwrap instruction\n const ix = createUnwrapInstruction(\n ctokenAta,\n destination,\n owner.publicKey,\n mint,\n unwrapAmount,\n resolvedSplInterfaceInfo,\n mintInfo.decimals,\n payer.publicKey,\n );\n\n const { blockhash } = await rpc.getLatestBlockhash();\n const additionalSigners = dedupeSigner(payer, [owner]);\n\n const tx = buildAndSignTx(\n [ComputeBudgetProgram.setComputeUnitLimit({ units: 200_000 }), ix],\n payer,\n blockhash,\n additionalSigners,\n );\n\n const txId = await sendAndConfirmTx(rpc, tx, confirmOptions);\n\n return txId;\n}\n","/**\n * Exports for @lightprotocol/compressed-token/unified\n *\n * Import from `/unified` to get a single unified ATA for SPL/T22 and c-token\n * mints.\n */\nimport {\n PublicKey,\n Signer,\n ConfirmOptions,\n Commitment,\n ComputeBudgetProgram,\n} from '@solana/web3.js';\nimport {\n Rpc,\n CTOKEN_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 { transferInterface as _transferInterface } from '../actions/transfer-interface';\nimport { _getOrCreateAtaInterface } from '../actions/get-or-create-ata-interface';\nimport { getAtaProgramId } from '../ata-utils';\nimport { InterfaceOptions } from '..';\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 ATA for SPL/T22/c-token in the unified path.\n *\n * Enforces CTOKEN_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 c-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 = CTOKEN_PROGRAM_ID,\n associatedTokenProgramId?: PublicKey,\n): PublicKey {\n if (!programId.equals(CTOKEN_PROGRAM_ID)) {\n throw new Error(\n 'Please derive the unified ATA from the c-token program; balances across SPL, T22, and c-token are unified under the canonical c-token ATA.',\n );\n }\n\n return _getAssociatedTokenAddressInterface(\n mint,\n owner,\n allowOwnerOffCurve,\n programId,\n associatedTokenProgramId,\n );\n}\n\n/**\n * Create instructions to load ALL token balances into a c-token ATA.\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 Array of instructions (empty if nothing to load)\n */\nexport async function createLoadAtaInstructions(\n rpc: Rpc,\n ata: PublicKey,\n owner: PublicKey,\n mint: PublicKey,\n payer?: PublicKey,\n options?: InterfaceOptions,\n) {\n return _createLoadAtaInstructions(\n rpc,\n ata,\n owner,\n mint,\n payer,\n options,\n true,\n );\n}\n\n/**\n * Load all token balances into the c-token ATA.\n *\n * Wraps SPL/Token-2022 balances and decompresses compressed c-tokens\n * into the on-chain c-token ATA. If no balances exist and the ATA doesn't\n * exist, creates an empty ATA (idempotent).\n *\n * @param rpc RPC connection\n * @param ata Associated token address (c-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) {\n payer ??= owner;\n\n const signature = await _loadAta(\n rpc,\n ata,\n owner,\n mint,\n payer,\n confirmOptions,\n interfaceOptions,\n true,\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 CTOKEN_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 * Matches SPL Token's transferChecked signature order. Destination must exist.\n *\n * @param rpc RPC connection\n * @param payer Fee payer (signer)\n * @param source Source c-token ATA address\n * @param mint Mint address\n * @param destination Destination c-token ATA address (must exist)\n * @param owner Source owner (signer)\n * @param amount Amount to transfer\n * @param programId Token program ID (default: CTOKEN_PROGRAM_ID)\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 destination: PublicKey,\n owner: Signer,\n amount: number | bigint | BN,\n programId: PublicKey = CTOKEN_PROGRAM_ID,\n confirmOptions?: ConfirmOptions,\n options?: InterfaceOptions,\n) {\n return _transferInterface(\n rpc,\n payer,\n source,\n mint,\n destination,\n owner,\n amount,\n programId,\n confirmOptions,\n options,\n true,\n );\n}\n\n/**\n * Get or create c-token ATA with unified balance detection and auto-loading.\n *\n * Enforces CTOKEN_PROGRAM_ID. Aggregates balances from:\n * - c-token hot (on-chain) account\n * - c-token cold (compressed) accounts\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 c-token ATA\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 CTOKEN_PROGRAM_ID,\n getAtaProgramId(CTOKEN_PROGRAM_ID),\n true, // wrap=true for unified path\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 parseCTokenHot,\n parseCTokenCold,\n toAccountInfo,\n convertTokenDataToAccount,\n} from '../get-account-interface';\n\nexport {\n createLoadAccountsParams,\n createLoadAtaInstructionsFromInterface,\n calculateCompressibleLoadComputeUnits,\n CompressibleAccountInput,\n ParsedAccountInfoInterface,\n CompressibleLoadParams,\n PackedCompressedAccount,\n LoadResult,\n} from '../actions/load-ata';\n\nexport { InterfaceOptions } 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 createAssociatedCTokenAccountInstruction,\n createAssociatedCTokenAccountIdempotentInstruction,\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 createDecompressInterfaceInstruction,\n createTransferInterfaceInstruction,\n createCTokenTransferInstruction,\n // Types\n TokenMetadataInstructionData,\n CompressibleConfig,\n CTokenConfig,\n CreateAssociatedCTokenAccountParams,\n // Actions\n createMintInterface,\n createAtaInterface,\n createAtaInterfaceIdempotent,\n // getOrCreateAtaInterface is defined locally with unified behavior\n decompressInterface,\n wrap,\n unwrap,\n mintTo as mintToCToken,\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"],"names":["createUnwrapInstruction","source","destination","owner","mint","amount","splInterfaceInfo","decimals","payer","compressions","createCompressCtoken","createDecompressSpl","poolIndex","bump","data","encodeTransfer2InstructionData","withTransactionHash","withLamportsChangeAccountMerkleTreeIndex","lamportsChangeAccountMerkleTreeIndex","lamportsChangeAccountOwnerIndex","outputQueue","maxTopUp","cpiContext","proof","inTokenData","outTokenData","inLamports","outLamports","inTlv","outTlv","keys","pubkey","CompressedTokenProgram","deriveCpiAuthorityPda","isSigner","isWritable","splInterfacePda","tokenProgram","CTOKEN_PROGRAM_ID","TransactionInstruction","programId","async","unwrap","rpc","confirmOptions","resolvedSplInterfaceInfo","getSplInterfaceInfos","find","info","isInitialized","Error","toBase58","getAccountInfo","ctokenAta","getAssociatedTokenAddressInterface","publicKey","_loadAta","ctokenAccountInfo","ctokenBalance","readBigUInt64LE","BigInt","unwrapAmount","toString","mintInfo","getMint","undefined","ix","blockhash","getLatestBlockhash","additionalSigners","dedupeSigner","tx","buildAndSignTx","ComputeBudgetProgram","setComputeUnitLimit","units","sendAndConfirmTx","getAtaInterface","ata","commitment","_getAtaInterface","allowOwnerOffCurve","associatedTokenProgramId","equals","_getAssociatedTokenAddressInterface","createLoadAtaInstructions","options","_createLoadAtaInstructions","loadAta","interfaceOptions","signature","createAssociatedTokenAccountInterfaceIdempotentInstruction","transferInterface","_transferInterface","getOrCreateAtaInterface","_getOrCreateAtaInterface","getAtaProgramId"],"mappings":"mwJA0BgBA,GACZC,EACAC,EACAC,EACAC,EACAC,EACAC,E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EACAC,EACAI,EACAoC,EACA6C,GAEAjF,IAAUL,EAEV,MAAMuF,QAAkBlC,GACpBb,EACAmC,EACA3E,EACAC,EACAI,EACAoC,EACA6C,EACA,GAIJ,GAAkB,OAAdC,UAC0B/C,EAAIS,eAAe0B,GAC3B,CACd,MAAMZ,EACFyB,GACInF,EAAM+C,UACNuB,EACA3E,EAAMoD,UACNnD,EACAkC,IAEF6B,UAAEA,SAAoBxB,EAAIyB,qBAC1BG,EAAKC,EACP,CACIC,EAAqBC,oBAAoB,CAAEC,MAAO,MAClDT,GAEJ1D,EACA2D,EACA3D,EAAM+C,UAAU4B,OAAOhF,EAAMoD,WAAa,GAAK,CAACpD,IAEpD,OAAOyE,EAAiBjC,EAAK4B,EAAI3B,EACpC,CAGL,OAAO8C,CACX,CAmBOjD,eAAemD,GAClBjD,EACAnC,EACAP,EACAG,EACAF,EACAC,EACAE,EACAmC,EAAuBF,EACvBM,EACA0C,GAEA,OAAOO,GACHlD,EACAnC,EACAP,EACAG,EACAF,EACAC,EACAE,EACAmC,EACAI,EACA0C,EACA,EAER,CA8BO7C,eAAeqD,GAClBnD,EACAnC,EACAJ,EACAD,EACA8E,EAAqB,EACrBF,EACAnC,GAEA,OAAOmD,GACHpD,EACAnC,EACAJ,EACAD,EACA8E,EACAF,EACAnC,EACAN,EACA0D,GAAgB1D,GAChB,EAER"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -389,6 +389,10 @@ interface MintContext {
|
|
|
389
389
|
cmintDecompressed: boolean;
|
|
390
390
|
/** PDA of the associated SPL mint */
|
|
391
391
|
splMint: PublicKey;
|
|
392
|
+
/** Signer pubkey used to derive the mint PDA */
|
|
393
|
+
mintSigner: Uint8Array;
|
|
394
|
+
/** Bump seed for the mint PDA */
|
|
395
|
+
bump: number;
|
|
392
396
|
}
|
|
393
397
|
/**
|
|
394
398
|
* Raw extension data as stored on-chain
|
|
@@ -424,8 +428,54 @@ interface TokenMetadata {
|
|
|
424
428
|
interface CompressedMint {
|
|
425
429
|
base: BaseMint;
|
|
426
430
|
mintContext: MintContext;
|
|
431
|
+
/** Reserved bytes for T22 layout compatibility */
|
|
432
|
+
reserved: Uint8Array;
|
|
433
|
+
/** Account type discriminator (1 = Mint) */
|
|
434
|
+
accountType: number;
|
|
435
|
+
/** Compression info embedded in mint */
|
|
436
|
+
compression: CompressionInfo;
|
|
427
437
|
extensions: MintExtension[] | null;
|
|
428
438
|
}
|
|
439
|
+
/**
|
|
440
|
+
* Rent configuration for compressible accounts
|
|
441
|
+
*/
|
|
442
|
+
interface RentConfig {
|
|
443
|
+
/** Base rent constant per epoch */
|
|
444
|
+
baseRent: number;
|
|
445
|
+
/** Compression cost in lamports */
|
|
446
|
+
compressionCost: number;
|
|
447
|
+
/** Lamports per byte per epoch */
|
|
448
|
+
lamportsPerBytePerEpoch: number;
|
|
449
|
+
/** Maximum epochs that can be pre-funded */
|
|
450
|
+
maxFundedEpochs: number;
|
|
451
|
+
/** Maximum lamports for top-up operation */
|
|
452
|
+
maxTopUp: number;
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Compression info embedded in CompressedMint
|
|
456
|
+
*/
|
|
457
|
+
interface CompressionInfo {
|
|
458
|
+
/** Config account version (0 = uninitialized) */
|
|
459
|
+
configAccountVersion: number;
|
|
460
|
+
/** Whether to compress to pubkey instead of owner */
|
|
461
|
+
compressToPubkey: number;
|
|
462
|
+
/** Account version for hashing scheme */
|
|
463
|
+
accountVersion: number;
|
|
464
|
+
/** Lamports to top up per write */
|
|
465
|
+
lamportsPerWrite: number;
|
|
466
|
+
/** Authority that can compress the account */
|
|
467
|
+
compressionAuthority: PublicKey;
|
|
468
|
+
/** Recipient for rent on closure */
|
|
469
|
+
rentSponsor: PublicKey;
|
|
470
|
+
/** Last slot rent was claimed */
|
|
471
|
+
lastClaimedSlot: bigint;
|
|
472
|
+
/** Rent exemption lamports paid at account creation */
|
|
473
|
+
rentExemptionPaid: number;
|
|
474
|
+
/** Reserved for future use */
|
|
475
|
+
reserved: number;
|
|
476
|
+
/** Rent configuration */
|
|
477
|
+
rentConfig: RentConfig;
|
|
478
|
+
}
|
|
429
479
|
/**
|
|
430
480
|
* Deserialize a compressed mint from buffer
|
|
431
481
|
* Uses SPL's MintLayout for BaseMint and buffer-layout struct for context
|
|
@@ -487,6 +537,10 @@ interface MintInstructionData {
|
|
|
487
537
|
splMint: PublicKey;
|
|
488
538
|
cmintDecompressed: boolean;
|
|
489
539
|
version: number;
|
|
540
|
+
/** Signer pubkey used to derive the mint PDA */
|
|
541
|
+
mintSigner: Uint8Array;
|
|
542
|
+
/** Bump seed for the mint PDA */
|
|
543
|
+
bump: number;
|
|
490
544
|
metadata?: MintMetadataField;
|
|
491
545
|
}
|
|
492
546
|
|
|
@@ -497,6 +551,8 @@ interface MintInterface {
|
|
|
497
551
|
mintContext?: MintContext;
|
|
498
552
|
tokenMetadata?: TokenMetadata;
|
|
499
553
|
extensions?: MintExtension[];
|
|
554
|
+
/** Compression info for c-token mints */
|
|
555
|
+
compression?: CompressionInfo;
|
|
500
556
|
}
|
|
501
557
|
/**
|
|
502
558
|
* Get unified mint info for SPL/T22/c-token mints.
|
|
@@ -1560,7 +1616,7 @@ declare function selectTokenPoolInfosForDecompression(infos: TokenPoolInfo[], de
|
|
|
1560
1616
|
*
|
|
1561
1617
|
* Supports decompressing to both c-token accounts and SPL token accounts:
|
|
1562
1618
|
* - For c-token destinations: No splInterfaceInfo needed
|
|
1563
|
-
* - For SPL destinations: Provide splInterfaceInfo (token pool info)
|
|
1619
|
+
* - For SPL destinations: Provide splInterfaceInfo (token pool info) and decimals
|
|
1564
1620
|
*
|
|
1565
1621
|
* @param payer Fee payer public key
|
|
1566
1622
|
* @param inputCompressedTokenAccounts Input compressed token accounts
|
|
@@ -1568,9 +1624,10 @@ declare function selectTokenPoolInfosForDecompression(infos: TokenPoolInfo[], de
|
|
|
1568
1624
|
* @param amount Amount to decompress
|
|
1569
1625
|
* @param validityProof Validity proof (contains compressedProof and rootIndices)
|
|
1570
1626
|
* @param splInterfaceInfo Optional: SPL interface info for SPL destinations
|
|
1627
|
+
* @param decimals Mint decimals (required for SPL destinations)
|
|
1571
1628
|
* @returns TransactionInstruction
|
|
1572
1629
|
*/
|
|
1573
|
-
declare function createDecompressInterfaceInstruction(payer: PublicKey, inputCompressedTokenAccounts: ParsedTokenAccount[], toAddress: PublicKey, amount: bigint, validityProof: ValidityProofWithContext, splInterfaceInfo
|
|
1630
|
+
declare function createDecompressInterfaceInstruction(payer: PublicKey, inputCompressedTokenAccounts: ParsedTokenAccount[], toAddress: PublicKey, amount: bigint, validityProof: ValidityProofWithContext, splInterfaceInfo: SplInterfaceInfo | undefined, decimals: number): TransactionInstruction;
|
|
1574
1631
|
|
|
1575
1632
|
declare const TokenAccountSourceType: {
|
|
1576
1633
|
readonly Spl: "spl";
|
|
@@ -1805,10 +1862,11 @@ declare function calculateCompressibleLoadComputeUnits(compressedAccountCount: n
|
|
|
1805
1862
|
* @param mint Mint address
|
|
1806
1863
|
* @param amount Amount to wrap,
|
|
1807
1864
|
* @param splInterfaceInfo SPL interface info for the compression
|
|
1865
|
+
* @param decimals Mint decimals (required for transfer_checked)
|
|
1808
1866
|
* @param payer Fee payer (defaults to owner)
|
|
1809
1867
|
* @returns Instruction to wrap tokens
|
|
1810
1868
|
*/
|
|
1811
|
-
declare function createWrapInstruction(source: PublicKey, destination: PublicKey, owner: PublicKey, mint: PublicKey, amount: bigint, splInterfaceInfo: SplInterfaceInfo, payer?: PublicKey): TransactionInstruction;
|
|
1869
|
+
declare function createWrapInstruction(source: PublicKey, destination: PublicKey, owner: PublicKey, mint: PublicKey, amount: bigint, splInterfaceInfo: SplInterfaceInfo, decimals: number, payer?: PublicKey): TransactionInstruction;
|
|
1812
1870
|
|
|
1813
1871
|
/**
|
|
1814
1872
|
* Create and initialize a new mint for SPL/T22/c-token.
|
|
@@ -1054,6 +1054,10 @@ interface MintContext {
|
|
|
1054
1054
|
cmintDecompressed: boolean;
|
|
1055
1055
|
/** PDA of the associated SPL mint */
|
|
1056
1056
|
splMint: PublicKey;
|
|
1057
|
+
/** Signer pubkey used to derive the mint PDA */
|
|
1058
|
+
mintSigner: Uint8Array;
|
|
1059
|
+
/** Bump seed for the mint PDA */
|
|
1060
|
+
bump: number;
|
|
1057
1061
|
}
|
|
1058
1062
|
/**
|
|
1059
1063
|
* Raw extension data as stored on-chain
|
|
@@ -1089,8 +1093,54 @@ interface TokenMetadata {
|
|
|
1089
1093
|
interface CompressedMint {
|
|
1090
1094
|
base: BaseMint;
|
|
1091
1095
|
mintContext: MintContext;
|
|
1096
|
+
/** Reserved bytes for T22 layout compatibility */
|
|
1097
|
+
reserved: Uint8Array;
|
|
1098
|
+
/** Account type discriminator (1 = Mint) */
|
|
1099
|
+
accountType: number;
|
|
1100
|
+
/** Compression info embedded in mint */
|
|
1101
|
+
compression: CompressionInfo;
|
|
1092
1102
|
extensions: MintExtension[] | null;
|
|
1093
1103
|
}
|
|
1104
|
+
/**
|
|
1105
|
+
* Rent configuration for compressible accounts
|
|
1106
|
+
*/
|
|
1107
|
+
interface RentConfig {
|
|
1108
|
+
/** Base rent constant per epoch */
|
|
1109
|
+
baseRent: number;
|
|
1110
|
+
/** Compression cost in lamports */
|
|
1111
|
+
compressionCost: number;
|
|
1112
|
+
/** Lamports per byte per epoch */
|
|
1113
|
+
lamportsPerBytePerEpoch: number;
|
|
1114
|
+
/** Maximum epochs that can be pre-funded */
|
|
1115
|
+
maxFundedEpochs: number;
|
|
1116
|
+
/** Maximum lamports for top-up operation */
|
|
1117
|
+
maxTopUp: number;
|
|
1118
|
+
}
|
|
1119
|
+
/**
|
|
1120
|
+
* Compression info embedded in CompressedMint
|
|
1121
|
+
*/
|
|
1122
|
+
interface CompressionInfo {
|
|
1123
|
+
/** Config account version (0 = uninitialized) */
|
|
1124
|
+
configAccountVersion: number;
|
|
1125
|
+
/** Whether to compress to pubkey instead of owner */
|
|
1126
|
+
compressToPubkey: number;
|
|
1127
|
+
/** Account version for hashing scheme */
|
|
1128
|
+
accountVersion: number;
|
|
1129
|
+
/** Lamports to top up per write */
|
|
1130
|
+
lamportsPerWrite: number;
|
|
1131
|
+
/** Authority that can compress the account */
|
|
1132
|
+
compressionAuthority: PublicKey;
|
|
1133
|
+
/** Recipient for rent on closure */
|
|
1134
|
+
rentSponsor: PublicKey;
|
|
1135
|
+
/** Last slot rent was claimed */
|
|
1136
|
+
lastClaimedSlot: bigint;
|
|
1137
|
+
/** Rent exemption lamports paid at account creation */
|
|
1138
|
+
rentExemptionPaid: number;
|
|
1139
|
+
/** Reserved for future use */
|
|
1140
|
+
reserved: number;
|
|
1141
|
+
/** Rent configuration */
|
|
1142
|
+
rentConfig: RentConfig;
|
|
1143
|
+
}
|
|
1094
1144
|
/**
|
|
1095
1145
|
* Deserialize a compressed mint from buffer
|
|
1096
1146
|
* Uses SPL's MintLayout for BaseMint and buffer-layout struct for context
|
|
@@ -1152,6 +1202,10 @@ interface MintInstructionData {
|
|
|
1152
1202
|
splMint: PublicKey;
|
|
1153
1203
|
cmintDecompressed: boolean;
|
|
1154
1204
|
version: number;
|
|
1205
|
+
/** Signer pubkey used to derive the mint PDA */
|
|
1206
|
+
mintSigner: Uint8Array;
|
|
1207
|
+
/** Bump seed for the mint PDA */
|
|
1208
|
+
bump: number;
|
|
1155
1209
|
metadata?: MintMetadataField;
|
|
1156
1210
|
}
|
|
1157
1211
|
|
|
@@ -1162,6 +1216,8 @@ interface MintInterface {
|
|
|
1162
1216
|
mintContext?: MintContext;
|
|
1163
1217
|
tokenMetadata?: TokenMetadata;
|
|
1164
1218
|
extensions?: MintExtension[];
|
|
1219
|
+
/** Compression info for c-token mints */
|
|
1220
|
+
compression?: CompressionInfo;
|
|
1165
1221
|
}
|
|
1166
1222
|
/**
|
|
1167
1223
|
* Get unified mint info for SPL/T22/c-token mints.
|
|
@@ -1632,7 +1688,7 @@ declare function selectTokenPoolInfosForDecompression(infos: TokenPoolInfo[], de
|
|
|
1632
1688
|
*
|
|
1633
1689
|
* Supports decompressing to both c-token accounts and SPL token accounts:
|
|
1634
1690
|
* - For c-token destinations: No splInterfaceInfo needed
|
|
1635
|
-
* - For SPL destinations: Provide splInterfaceInfo (token pool info)
|
|
1691
|
+
* - For SPL destinations: Provide splInterfaceInfo (token pool info) and decimals
|
|
1636
1692
|
*
|
|
1637
1693
|
* @param payer Fee payer public key
|
|
1638
1694
|
* @param inputCompressedTokenAccounts Input compressed token accounts
|
|
@@ -1640,9 +1696,10 @@ declare function selectTokenPoolInfosForDecompression(infos: TokenPoolInfo[], de
|
|
|
1640
1696
|
* @param amount Amount to decompress
|
|
1641
1697
|
* @param validityProof Validity proof (contains compressedProof and rootIndices)
|
|
1642
1698
|
* @param splInterfaceInfo Optional: SPL interface info for SPL destinations
|
|
1699
|
+
* @param decimals Mint decimals (required for SPL destinations)
|
|
1643
1700
|
* @returns TransactionInstruction
|
|
1644
1701
|
*/
|
|
1645
|
-
declare function createDecompressInterfaceInstruction(payer: PublicKey, inputCompressedTokenAccounts: ParsedTokenAccount[], toAddress: PublicKey, amount: bigint, validityProof: ValidityProofWithContext, splInterfaceInfo
|
|
1702
|
+
declare function createDecompressInterfaceInstruction(payer: PublicKey, inputCompressedTokenAccounts: ParsedTokenAccount[], toAddress: PublicKey, amount: bigint, validityProof: ValidityProofWithContext, splInterfaceInfo: SplInterfaceInfo | undefined, decimals: number): TransactionInstruction;
|
|
1646
1703
|
|
|
1647
1704
|
/**
|
|
1648
1705
|
* Options for interface operations (load, transfer)
|
|
@@ -1787,10 +1844,11 @@ declare function calculateCompressibleLoadComputeUnits(compressedAccountCount: n
|
|
|
1787
1844
|
* @param mint Mint address
|
|
1788
1845
|
* @param amount Amount to wrap,
|
|
1789
1846
|
* @param splInterfaceInfo SPL interface info for the compression
|
|
1847
|
+
* @param decimals Mint decimals (required for transfer_checked)
|
|
1790
1848
|
* @param payer Fee payer (defaults to owner)
|
|
1791
1849
|
* @returns Instruction to wrap tokens
|
|
1792
1850
|
*/
|
|
1793
|
-
declare function createWrapInstruction(source: PublicKey, destination: PublicKey, owner: PublicKey, mint: PublicKey, amount: bigint, splInterfaceInfo: SplInterfaceInfo, payer?: PublicKey): TransactionInstruction;
|
|
1851
|
+
declare function createWrapInstruction(source: PublicKey, destination: PublicKey, owner: PublicKey, mint: PublicKey, amount: bigint, splInterfaceInfo: SplInterfaceInfo, decimals: number, payer?: PublicKey): TransactionInstruction;
|
|
1794
1852
|
|
|
1795
1853
|
/**
|
|
1796
1854
|
* Create an unwrap instruction that moves tokens from a c-token account to an
|
|
@@ -1802,10 +1860,11 @@ declare function createWrapInstruction(source: PublicKey, destination: PublicKey
|
|
|
1802
1860
|
* @param mint Mint address
|
|
1803
1861
|
* @param amount Amount to unwrap,
|
|
1804
1862
|
* @param splInterfaceInfo SPL interface info for the decompression
|
|
1863
|
+
* @param decimals Mint decimals (required for transfer_checked)
|
|
1805
1864
|
* @param payer Fee payer (defaults to owner if not provided)
|
|
1806
1865
|
* @returns TransactionInstruction to unwrap tokens
|
|
1807
1866
|
*/
|
|
1808
|
-
declare function createUnwrapInstruction(source: PublicKey, destination: PublicKey, owner: PublicKey, mint: PublicKey, amount: bigint, splInterfaceInfo: SplInterfaceInfo, payer?: PublicKey): TransactionInstruction;
|
|
1867
|
+
declare function createUnwrapInstruction(source: PublicKey, destination: PublicKey, owner: PublicKey, mint: PublicKey, amount: bigint, splInterfaceInfo: SplInterfaceInfo, decimals: number, payer?: PublicKey): TransactionInstruction;
|
|
1809
1868
|
|
|
1810
1869
|
/**
|
|
1811
1870
|
* Create and initialize a new mint for SPL/T22/c-token.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightprotocol/compressed-token",
|
|
3
|
-
"version": "0.22.1-alpha.
|
|
3
|
+
"version": "0.22.1-alpha.9",
|
|
4
4
|
"description": "JS client to interact with the compressed-token program",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "dist/cjs/node/index.cjs",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@coral-xyz/borsh": "^0.29.0",
|
|
43
43
|
"@solana/spl-token": ">=0.3.9",
|
|
44
44
|
"@solana/web3.js": ">=1.73.5",
|
|
45
|
-
"@lightprotocol/stateless.js": "0.22.1-alpha.
|
|
45
|
+
"@lightprotocol/stateless.js": "0.22.1-alpha.8"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@solana/buffer-layout": "^4.0.1",
|