@lightprotocol/compressed-token 0.23.0-beta.1 → 0.23.0-beta.10
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/index.cjs.map +1 -1
- package/dist/cjs/browser/types-Csty9bc2.cjs +2 -0
- package/dist/cjs/browser/types-Csty9bc2.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/index.cjs.map +1 -1
- package/dist/cjs/node/types-DgmOPYyc.cjs +2 -0
- package/dist/cjs/node/types-DgmOPYyc.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/index.js.map +1 -1
- package/dist/es/browser/types-e_5LjLhR.js +2 -0
- package/dist/es/browser/types-e_5LjLhR.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 +498 -461
- package/dist/types/unified/index.d.ts +718 -664
- package/package.json +17 -11
- package/dist/cjs/browser/types-BYVvBJS4.cjs +0 -2
- package/dist/cjs/browser/types-BYVvBJS4.cjs.map +0 -1
- package/dist/cjs/node/types-C6bFjLLI.cjs +0 -2
- package/dist/cjs/node/types-C6bFjLLI.cjs.map +0 -1
- package/dist/es/browser/types-Z2gqWJ9V.js +0 -2
- package/dist/es/browser/types-Z2gqWJ9V.js.map +0 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var e=require("@solana/web3.js"),t=require("@lightprotocol/stateless.js"),n=require("@solana/spl-token"),r=require("buffer"),o=require("@coral-xyz/borsh");const i=new e.PublicKey("ACXg8a7VaqecBWrSbdu73W4Pg9gsqXJ3EXAqkHyhvVXg"),s=new e.PublicKey("r18WwUxfG8kQ69bQPAB2jV6zGNKy3GosFGctjQoV4ti");var a;exports.TokenDataVersion=void 0,(a=exports.TokenDataVersion||(exports.TokenDataVersion={}))[a.V1=1]="V1",a[a.V2=2]="V2",a[a.ShaFlat=3]="ShaFlat";const u=r.Buffer.from("pool"),c=r.Buffer.from("cpi_authority"),l=r.Buffer.from([23,169,27,122,147,169,209,152]),d=r.Buffer.from([241,34,48,186,37,179,123,192]),p=r.Buffer.from([65,206,101,37,147,42,221,144]),m=r.Buffer.from([163,52,200,231,140,3,69,186]),h=r.Buffer.from([112,230,105,101,145,202,157,97]),f=r.Buffer.from([69,74,217,36,115,117,97,76]),g=r.Buffer.from([170,23,31,34,133,173,93,242]),y=r.Buffer.from([114,143,210,73,96,115,1,228]),b=65535;function I(e){return 128+1*e}const w=I(272);function k(e){return{mint:e.mint,tokenPoolPda:e.splInterfacePda,splInterfacePda:e.splInterfacePda,tokenProgram:e.tokenProgram,activity:e.activity,isInitialized:e.isInitialized,balance:e.balance,poolIndex:e.poolIndex,bump:e.bump}}function A(e){var t;return{mint:e.mint,splInterfacePda:null!==(t=e.tokenPoolPda)&&void 0!==t?t:e.splInterfacePda,tokenProgram:e.tokenProgram,activity:e.activity,isInitialized:e.isInitialized,balance:e.balance,poolIndex:e.poolIndex,bump:e.bump}}function v(e,n,r=0){const[o,i]=ve.deriveSplInterfacePdaWithIndex(e,r);return{mint:e,splInterfacePda:o,tokenProgram:n,activity:void 0,balance:t.bn(0),isInitialized:1,poolIndex:r,bump:i}}function T(e,t){const n="tokenPoolPda"in e?A(e):e;if(!n.mint.equals(t))throw new Error("SplInterface mint does not match the provided mint.");if(!n.isInitialized)throw new Error(`SplInterface is not initialized. Please create an SPL interface for mint: ${t.toBase58()} via createSplInterface().`);return 1}async function M(e,r,o){const i=Array.from({length:5},((e,t)=>ve.deriveSplInterfacePdaWithIndex(r,t))),s=await e.getMultipleAccountsInfo(i.map((e=>e[0])),o);if(null===s[0])throw new Error(`SplInterface not found. Please create an SPL interface for mint: ${r.toBase58()} via createSplInterface().`);const a=i.map(((e,t)=>s[t]?n.unpackAccount(e[0],s[t],s[t].owner):null)),u=s[0].owner;return a.map(((e,n)=>e?{mint:r,splInterfacePda:e.address,tokenProgram:u,activity:void 0,balance:t.bn(e.amount.toString()),isInitialized:1,poolIndex:n,bump:i[n][1]}:{mint:r,splInterfacePda:i[n][0],tokenProgram:u,activity:void 0,balance:t.bn(0),isInitialized:0,poolIndex:n,bump:i[n][1]}))}var P;exports.Action=void 0,(P=exports.Action||(exports.Action={}))[P.Compress=1]="Compress",P[P.Decompress=2]="Decompress",P[P.Transfer=3]="Transfer";const S=e=>{for(let t=e.length-1;t>0;t--){const n=Math.floor(Math.random()*(t+1));[e[t],e[n]]=[e[n],e[t]]}return e};function x(e){const t=S(e).filter((e=>e.isInitialized));if(0===t.length)throw new Error("Please pass at least one initialized SPL interface info.");return t[0]}function C(e,n){if(0===e.length)throw new Error("Please pass at least one SPL interface info.");const r=(e=S(e)).find((e=>e.balance.gte(t.bn(n).mul(t.bn(10)))));if((e=e.filter((e=>e.isInitialized)).sort(((e,t)=>e.poolIndex-t.poolIndex))).every((e=>e.balance.isZero())))throw new Error("All provided SPL interface balances are zero. Please pass recent SPL interface infos.");return r?[r]:e}const _="Could not find accounts to select for transfer.",E="Cannot select accounts from different tree types (V1/V2) in the same batch. Filter accounts by tree type first.";function O(e,t){return t?e.filter((e=>e.compressedAccount.treeInfo.treeType===t)):e}function B(e){if(e.length<=1)return;const t=e.filter((e=>{var t,n;return void 0!==(null===(n=null===(t=e.compressedAccount)||void 0===t?void 0:t.treeInfo)||void 0===n?void 0:n.treeType)}));if(t.length<=1)return;const n=t[0].compressedAccount.treeInfo.treeType;if(t.some((e=>e.compressedAccount.treeInfo.treeType!==n)))throw new Error(E)}function L(e){const t=new Map;for(const n of e){const e=n.compressedAccount.treeInfo.treeType,r=t.get(e)||[];r.push(n),t.set(e,r)}return t}function D(e,n){const r=t.featureFlags.isV2()?t.TreeType.StateV2:t.TreeType.StateV1,o=L(e);let i=r,s=o.get(r)||[],a=s.reduce(((e,t)=>e.add(t.parsed.amount)),t.bn(0));if(n&&a.lt(n)){const e=r===t.TreeType.StateV2?t.TreeType.StateV1:t.TreeType.StateV2,u=o.get(e)||[],c=u.reduce(((e,t)=>e.add(t.parsed.amount)),t.bn(0));c.gte(n)&&(i=e,s=u,a=c)}return{accounts:s,treeType:i,totalBalance:a}}function R(e,t,n=4,r){const o=O(e,null==r?void 0:r.treeType),i=o.find((e=>e.parsed.amount.eq(t)));return i?[[i],i.parsed.amount,i.compressedAccount.lamports,i.parsed.amount]:K(o,t,n,r)}function K(e,n,r=4,o){const i=O(e,null==o?void 0:o.treeType),[s,a,u,c]=U(i,n,r);if(B(s),a.lt(t.bn(n))){const e=i.reduce(((e,t)=>e.add(t.parsed.amount)),t.bn(0));throw s.length>=r?new Error(`Account limit exceeded: max ${c.toString()} (${r} accounts) per transaction. Total balance: ${e.toString()} (${i.length} accounts). Consider multiple transfers to spend full balance.`):new Error(`Insufficient balance for transfer. Required: ${n.toString()}, available: ${e.toString()}.`)}if(0===s.length)throw new Error(_);return[s,a,u,c]}function U(e,n,r=4){if(0===e.length)throw new Error(_);let o=t.bn(0),i=t.bn(0),s=t.bn(0);const a=[];e.sort(((e,t)=>t.parsed.amount.cmp(e.parsed.amount)));for(const s of e){if(a.length>=r)break;if(o.gte(t.bn(n)))break;s.parsed.amount.isZero()&&s.compressedAccount.lamports.isZero()||(o=o.add(s.parsed.amount),i=i.add(s.compressedAccount.lamports),a.push(s))}if(s=e.slice(0,r).reduce(((e,t)=>e.add(t.parsed.amount)),t.bn(0)),o.lt(t.bn(n))&&console.log(`Insufficient balance for transfer. Requested: ${n.toString()}, Returns max available: ${s.toString()}.`),0===a.length)throw new Error(_);return[a,o,i,s]}function N(e,n,r=4){if(0===e.length)throw new Error(_);let o=t.bn(0),i=t.bn(0);const s=[],a=e.filter((e=>!e.parsed.amount.isZero()||!e.compressedAccount.lamports.isZero()));a.sort(((e,t)=>t.parsed.amount.cmp(e.parsed.amount)));for(const e of a){if(s.length>=r)break;if(o=o.add(e.parsed.amount),i=i.add(e.compressedAccount.lamports),s.push(e),o.gte(t.bn(n))){const e=a.slice(s.length);if(e.length>0){const t=e.reduce(((e,t)=>t.parsed.amount.lt(e.parsed.amount)?t:e));s.length<r&&(s.push(t),o=o.add(t.parsed.amount),i=i.add(t.compressedAccount.lamports))}break}}const u=a.slice(0,r).reduce(((e,t)=>e.add(t.parsed.amount)),t.bn(0));if(0===s.length)throw new Error(_);return[s,o,i,u]}function W(e){const{inputCompressedTokenAccounts:n,outputStateTreeInfo:r,remainingAccounts:o=[],rootIndices:i,tokenTransferOutputs:s}=e,a=o.slice();let u=null;n.length>0&&n[0].parsed.delegate&&(u=t.getIndexOrAdd(a,n[0].parsed.delegate));const c=[];let l;if(n.forEach(((e,n)=>{const r=t.getIndexOrAdd(a,e.compressedAccount.treeInfo.tree),o=t.getIndexOrAdd(a,e.compressedAccount.treeInfo.queue);c.push({amount:e.parsed.amount,delegateIndex:u,merkleContext:{merkleTreePubkeyIndex:r,queuePubkeyIndex:o,leafIndex:e.compressedAccount.leafIndex,proveByIndex:e.compressedAccount.proveByIndex},rootIndex:i[n],lamports:e.compressedAccount.lamports.eq(t.bn(0))?null:e.compressedAccount.lamports,tlv:null})})),r)l=r;else{if(!(n.length>0))throw new Error("Either input accounts or outputStateTreeInfo must be provided");l=n[0].compressedAccount.treeInfo}const d=l.nextTreeInfo||l;let p=d.tree;if(d.treeType===t.TreeType.StateV2){if(!t.featureFlags.isV2())throw new Error("V2 trees are not supported yet");p=d.queue}const m=t.padOutputStateMerkleTrees(p,s.length),h=[];m.forEach(((e,n)=>{var r;const o=t.getIndexOrAdd(a,e);h.push({owner:s[n].owner,amount:s[n].amount,lamports:(null===(r=s[n].lamports)||void 0===r?void 0:r.eq(t.bn(0)))?null:s[n].lamports,merkleTreeIndex:o,tlv:null})}));const f=a.map((e=>({pubkey:e,isWritable:1,isSigner:0})));return{inputTokenDataWithContext:c,remainingAccountMetas:f,packedOutputTokenData:h}}function G(e,t){if(!e.every((e=>e.parsed.mint.equals(t))))throw new Error("All input accounts must belong to the same mint");return 1}const q=o.struct([o.array(o.u8(),32,"a"),o.array(o.u8(),64,"b"),o.array(o.u8(),32,"c")]),F=o.struct([o.publicKey("owner"),o.u64("amount"),o.option(o.u64(),"lamports"),o.u8("merkleTreeIndex"),o.option(o.vecU8(),"tlv")]),V=o.struct([o.u64("amount"),o.option(o.u8(),"delegateIndex"),o.struct([o.u8("merkleTreePubkeyIndex"),o.u8("queuePubkeyIndex"),o.u32("leafIndex"),o.bool("proveByIndex")],"merkleContext"),o.u16("rootIndex"),o.option(o.u64(),"lamports"),o.option(o.vecU8(),"tlv")]),H=o.struct([o.publicKey("owner"),o.option(o.u8(),"delegateChangeAccountIndex")]),z=o.struct([o.bool("setContext"),o.bool("firstSetContext"),o.u8("cpiContextAccountIndex")]),j=o.struct([o.option(q,"proof"),o.publicKey("mint"),o.option(H,"delegatedTransfer"),o.vec(V,"inputTokenDataWithContext"),o.vec(F,"outputCompressedAccounts"),o.bool("isCompress"),o.option(o.u64(),"compressOrDecompressAmount"),o.option(z,"cpiContext"),o.option(o.u8(),"lamportsChangeAccountMerkleTreeIndex")]),$=o.struct([o.vec(o.publicKey(),"recipients"),o.vec(o.u64(),"amounts"),o.option(o.u64(),"lamports")]),Z=o.struct([o.vec(o.publicKey(),"pubkeys"),o.option(o.vec(o.u64(),"amounts"),"amounts"),o.option(o.u64(),"lamports"),o.option(o.u64(),"amount"),o.u8("index"),o.u8("bump")]),Q=o.struct([o.publicKey("owner"),o.option(o.u64(),"remainingAmount"),o.option(z,"cpiContext")]);function X(e){const t=r.Buffer.alloc(1e3),n=$.encode({recipients:e.recipients,amounts:e.amounts,lamports:e.lamports},t);return r.Buffer.concat([new Uint8Array(d),new Uint8Array(t.subarray(0,n))])}function Y(e){const t=r.Buffer.alloc(1e3),n=Z.encode(e,t),o=r.Buffer.alloc(4);o.writeUInt32LE(n,0);const i=t.subarray(0,n);return r.Buffer.concat([new Uint8Array(p),new Uint8Array(o),new Uint8Array(i)])}function J(e){const t=r.Buffer.alloc(1e3),n=Q.encode({owner:e.owner,remainingAmount:e.remainingAmount,cpiContext:e.cpiContext},t);return r.Buffer.concat([new Uint8Array(h),new Uint8Array(t.subarray(0,n))])}function ee(e){const t=r.Buffer.alloc(1e3),n=j.encode(e,t),o=r.Buffer.alloc(4);o.writeUInt32LE(n,0);const i=t.subarray(0,n);return r.Buffer.concat([new Uint8Array(m),new Uint8Array(o),new Uint8Array(i)])}const te=e=>{const{feePayer:t,tokenPoolPda:n,systemProgram:r,mint:o,tokenProgram:i,cpiAuthorityPda:s}=e;return[{pubkey:t,isSigner:1,isWritable:1},{pubkey:n,isSigner:0,isWritable:1},{pubkey:r,isSigner:0,isWritable:0},{pubkey:o,isSigner:0,isWritable:1},{pubkey:i,isSigner:0,isWritable:0},{pubkey:s,isSigner:0,isWritable:0}]},ne=e=>{const{feePayer:t,tokenPoolPda:n,systemProgram:r,mint:o,tokenProgram:i,cpiAuthorityPda:s,existingTokenPoolPda:a}=e;return[{pubkey:t,isSigner:1,isWritable:1},{pubkey:n,isSigner:0,isWritable:1},{pubkey:a,isSigner:0,isWritable:0},{pubkey:r,isSigner:0,isWritable:0},{pubkey:o,isSigner:0,isWritable:1},{pubkey:i,isSigner:0,isWritable:0},{pubkey:s,isSigner:0,isWritable:0}]},re=e=>{const t=ve.programId,{feePayer:n,authority:r,cpiAuthorityPda:o,mint:i,tokenPoolPda:s,tokenProgram:a,lightSystemProgram:u,registeredProgramPda:c,noopProgram:l,accountCompressionAuthority:d,accountCompressionProgram:p,merkleTree:m,selfProgram:h,systemProgram:f,solPoolPda:g}=e;return[{pubkey:n,isSigner:1,isWritable:1},{pubkey:r,isSigner:1,isWritable:0},{pubkey:o,isSigner:0,isWritable:0},{pubkey:i,isSigner:0,isWritable:1},{pubkey:s,isSigner:0,isWritable:1},{pubkey:a,isSigner:0,isWritable:0},{pubkey:u,isSigner:0,isWritable:0},{pubkey:c,isSigner:0,isWritable:0},{pubkey:l,isSigner:0,isWritable:0},{pubkey:d,isSigner:0,isWritable:0},{pubkey:p,isSigner:0,isWritable:0},{pubkey:m,isSigner:0,isWritable:1},{pubkey:h,isSigner:0,isWritable:0},{pubkey:f,isSigner:0,isWritable:0},{pubkey:null!=g?g:t,isSigner:0,isWritable:1}]},oe=e=>{const t=ve.programId,{feePayer:n,authority:r,cpiAuthorityPda:o,lightSystemProgram:i,registeredProgramPda:s,noopProgram:a,accountCompressionAuthority:u,accountCompressionProgram:c,selfProgram:l,tokenPoolPda:d,compressOrDecompressTokenAccount:p,tokenProgram:m,systemProgram:h}=e;return[{pubkey:n,isSigner:1,isWritable:1},{pubkey:r,isSigner:1,isWritable:0},{pubkey:o,isSigner:0,isWritable:0},{pubkey:i,isSigner:0,isWritable:0},{pubkey:s,isSigner:0,isWritable:0},{pubkey:a,isSigner:0,isWritable:0},{pubkey:u,isSigner:0,isWritable:0},{pubkey:c,isSigner:0,isWritable:0},{pubkey:l,isSigner:0,isWritable:0},{pubkey:null!=d?d:t,isSigner:0,isWritable:1},{pubkey:null!=p?p:t,isSigner:0,isWritable:1},{pubkey:null!=m?m:t,isSigner:0,isWritable:0},{pubkey:h,isSigner:0,isWritable:0}]},ie=e=>{const{feePayer:t,authority:n,cpiAuthorityPda:r,lightSystemProgram:o,registeredProgramPda:i,noopProgram:s,accountCompressionAuthority:a,accountCompressionProgram:u,selfProgram:c,systemProgram:l}=e;return[{pubkey:t,isSigner:1,isWritable:1},{pubkey:n,isSigner:1,isWritable:0},{pubkey:r,isSigner:0,isWritable:0},{pubkey:o,isSigner:0,isWritable:0},{pubkey:i,isSigner:0,isWritable:0},{pubkey:s,isSigner:0,isWritable:0},{pubkey:a,isSigner:0,isWritable:0},{pubkey:u,isSigner:0,isWritable:0},{pubkey:c,isSigner:0,isWritable:0},{pubkey:l,isSigner:0,isWritable:0}]},se=ie,ae=e=>{const{feePayer:t,authority:n,cpiAuthorityPda:r,lightSystemProgram:o,registeredProgramPda:i,noopProgram:s,accountCompressionAuthority:a,accountCompressionProgram:u,selfProgram:c,systemProgram:l,mint:d}=e;return[{pubkey:t,isSigner:1,isWritable:1},{pubkey:n,isSigner:1,isWritable:0},{pubkey:r,isSigner:0,isWritable:0},{pubkey:o,isSigner:0,isWritable:0},{pubkey:i,isSigner:0,isWritable:0},{pubkey:s,isSigner:0,isWritable:0},{pubkey:a,isSigner:0,isWritable:0},{pubkey:u,isSigner:0,isWritable:0},{pubkey:c,isSigner:0,isWritable:0},{pubkey:l,isSigner:0,isWritable:0},{pubkey:d,isSigner:0,isWritable:0}]},ue=ae,ce=o.struct([o.struct([o.array(o.u8(),32,"a"),o.array(o.u8(),64,"b"),o.array(o.u8(),32,"c")],"proof"),o.publicKey("mint"),o.vec(V,"inputTokenDataWithContext"),o.option(z,"cpiContext"),o.publicKey("delegate"),o.u64("delegatedAmount"),o.u8("delegateMerkleTreeIndex"),o.u8("changeAccountMerkleTreeIndex"),o.option(o.u64(),"delegateLamports")]),le=o.struct([o.struct([o.array(o.u8(),32,"a"),o.array(o.u8(),64,"b"),o.array(o.u8(),32,"c")],"proof"),o.publicKey("mint"),o.vec(V,"inputTokenDataWithContext"),o.option(z,"cpiContext"),o.u8("outputAccountMerkleTreeIndex")]),de={a:new Array(32).fill(0),b:new Array(64).fill(0),c:new Array(32).fill(0)};function pe(e){return e.a.every((e=>0===e))&&e.b.every((e=>0===e))&&e.c.every((e=>0===e))}function me(e){var t;const n=r.Buffer.alloc(1e3),o=null!==(t=e.proof)&&void 0!==t?t:de,i=ce.encode(Object.assign(Object.assign({},e),{proof:o}),n),s=r.Buffer.alloc(4);s.writeUInt32LE(i,0);const a=n.subarray(0,i);return r.Buffer.concat([new Uint8Array(f),new Uint8Array(s),new Uint8Array(a)])}function he(e){var t;const n=r.Buffer.alloc(1e3),o=null!==(t=e.proof)&&void 0!==t?t:de,i=le.encode(Object.assign(Object.assign({},e),{proof:o}),n),s=r.Buffer.alloc(4);s.writeUInt32LE(i,0);const a=n.subarray(0,i);return r.Buffer.concat([new Uint8Array(g),new Uint8Array(s),new Uint8Array(a)])}const fe={tree:new e.PublicKey(t.batchMerkleTree1),queue:new e.PublicKey(t.batchQueue1),cpiContext:new e.PublicKey(t.batchCpiContext1),treeType:t.TreeType.StateV2,nextTreeInfo:null};function ge(e){var t;return"tokenPoolPda"in e&&null!==(t=e.tokenPoolPda)&&void 0!==t?t:e.splInterfacePda}const ye=e=>e.reduce(((e,t)=>e.add(t.parsed.amount)),t.bn(0)),be=e=>{const t=e[0].parsed.owner;e.forEach((e=>{if(!e.parsed.owner.equals(t))throw new Error("Token accounts must be owned by the same owner")}))},Ie=e=>({mint:e[0].parsed.mint,currentOwner:e[0].parsed.owner,delegate:e[0].parsed.delegate}),we=(e,t)=>{if(e.length<1)throw new Error("Must supply at least one input token account.");const n=e[0].parsed.owner,r=e.findIndex((e=>e.parsed.delegate));if(-1===r)return{delegatedTransfer:null,authority:n};const o=e[r].parsed.delegate;return{delegatedTransfer:{owner:n,delegateChangeAccountIndex:t.length<=1?null:0},authority:o}};function ke(e,n,r){r=t.bn(r);const o=ye(e),i=t.sumUpLamports(e.map((e=>e.compressedAccount))),s=o.sub(r);return t.validateSufficientBalance(s),s.eq(t.bn(0))&&i.eq(t.bn(0))?[{owner:n,amount:r,lamports:i,tlv:null}]:(t.validateSameOwner(e.map((e=>e.compressedAccount))),be(e),[{owner:e[0].parsed.owner,amount:s,lamports:i,tlv:null},{owner:n,amount:r,lamports:t.bn(0),tlv:null}])}function Ae(e,n){n=t.bn(n);const r=t.sumUpLamports(e.map((e=>e.compressedAccount))),o=ye(e).sub(n);return t.validateSufficientBalance(o),o.eq(t.bn(0))&&r.eq(t.bn(0))?[]:(t.validateSameOwner(e.map((e=>e.compressedAccount))),be(e),[{owner:e[0].parsed.owner,amount:o,lamports:r,tlv:null}])}class ve{constructor(){}static setProgramId(t){this.programId="string"==typeof t?new e.PublicKey(t):t}static deriveSplInterfacePda(t){const n=[u,t.toBuffer()],[r,o]=e.PublicKey.findProgramAddressSync(n,this.programId);return r}static deriveTokenPoolPda(e){return this.deriveSplInterfacePda(e)}static findSplInterfaceIndexAndBump(e,t){for(let n=0;n<5;n++){const r=ve.deriveSplInterfacePdaWithIndex(t,n);if(r[0].equals(e))return[n,r[1]]}throw new Error("SPL interface not found")}static findTokenPoolIndexAndBump(e,t){return this.findSplInterfaceIndexAndBump(e,t)}static deriveSplInterfacePdaWithIndex(t,n){let o=[];o=0===n?[r.Buffer.from("pool"),t.toBuffer(),r.Buffer.from([])]:[r.Buffer.from("pool"),t.toBuffer(),r.Buffer.from([n])];const[i,s]=e.PublicKey.findProgramAddressSync(o,this.programId);return[i,s]}static deriveTokenPoolPdaWithIndex(e,t){return this.deriveSplInterfacePdaWithIndex(e,t)}static get deriveCpiAuthorityPda(){const[t,n]=e.PublicKey.findProgramAddressSync([c],this.programId);return t}static async createMint({feePayer:t,mint:r,authority:o,freezeAuthority:i,decimals:s,rentExemptBalance:a,tokenProgramId:u,mintSize:c}){const l=null!=u?u:n.TOKEN_PROGRAM_ID;return[e.SystemProgram.createAccount({fromPubkey:t,lamports:a,newAccountPubkey:r,programId:l,space:null!=c?c:n.MINT_SIZE}),n.createInitializeMint2Instruction(r,s,o,i,l),await this.createSplInterface({feePayer:t,mint:r,tokenProgramId:l})]}static async createSplInterface({feePayer:t,mint:r,tokenProgramId:o}){const i=null!=o?o:n.TOKEN_PROGRAM_ID,s=this.deriveSplInterfacePdaWithIndex(r,0),a=te({mint:r,feePayer:t,tokenPoolPda:s[0],tokenProgram:i,cpiAuthorityPda:this.deriveCpiAuthorityPda,systemProgram:e.SystemProgram.programId});return new e.TransactionInstruction({programId:this.programId,keys:a,data:l})}static async createTokenPool(e){return this.createSplInterface(e)}static async addTokenPool({feePayer:t,mint:o,poolIndex:i,tokenProgramId:s}){if(i<=0)throw new Error("Pool index must be greater than 0. For 0, use CreateTokenPool instead.");if(i>3)throw new Error(`Invalid poolIndex ${i}. Max 4 pools per mint.`);const a=null!=s?s:n.TOKEN_PROGRAM_ID,u=this.deriveSplInterfacePdaWithIndex(o,i-1),c=this.deriveSplInterfacePdaWithIndex(o,i),l=ne({mint:o,feePayer:t,tokenPoolPda:c[0],existingTokenPoolPda:u[0],tokenProgram:a,cpiAuthorityPda:this.deriveCpiAuthorityPda,systemProgram:e.SystemProgram.programId});return new e.TransactionInstruction({programId:this.programId,keys:l,data:r.Buffer.concat([new Uint8Array(y),new Uint8Array(r.Buffer.from([i]))])})}static async mintTo({feePayer:n,mint:r,authority:o,toPubkey:i,amount:s,outputStateTreeInfo:a,tokenPoolInfo:u}){const c=t.defaultStaticAccountsStruct(),l=u.tokenProgram;T(u,r);const d=t.toArray(s).map((e=>t.bn(e))),p=t.toArray(i);if(d.length!==p.length)throw new Error("Amount and toPubkey arrays must have the same length");const m=re({mint:r,feePayer:n,authority:o,cpiAuthorityPda:this.deriveCpiAuthorityPda,tokenProgram:l,tokenPoolPda:ge(u),lightSystemProgram:t.LightSystemProgram.programId,registeredProgramPda:c.registeredProgramPda,noopProgram:c.noopProgram,accountCompressionAuthority:c.accountCompressionAuthority,accountCompressionProgram:c.accountCompressionProgram,merkleTree:a.treeType===t.TreeType.StateV2?a.queue:a.tree,selfProgram:this.programId,systemProgram:e.SystemProgram.programId,solPoolPda:null}),h=X({recipients:p,amounts:d,lamports:null});return new e.TransactionInstruction({programId:this.programId,keys:m,data:h})}static async approveAndMintTo({feePayer:e,mint:t,authority:r,authorityTokenAccount:o,toPubkey:i,amount:s,outputStateTreeInfo:a,tokenPoolInfo:u}){const c=BigInt(s.toString());return[n.createMintToInstruction(t,o,r,c,[],u.tokenProgram),await this.compress({payer:e,owner:r,source:o,toAddress:i,mint:t,amount:s,outputStateTreeInfo:a,tokenPoolInfo:u})]}static async transfer({payer:n,inputCompressedTokenAccounts:r,toAddress:o,amount:i,recentValidityProof:s,recentInputStateRootIndices:a}){var u;const c=ke(r,o,i),l=(null===(u=r[0])||void 0===u?void 0:u.compressedAccount.treeInfo.treeType)===t.TreeType.StateV1&&t.featureFlags.isV2()?fe:void 0,{inputTokenDataWithContext:d,packedOutputTokenData:p,remainingAccountMetas:m}=W({inputCompressedTokenAccounts:r,rootIndices:a,tokenTransferOutputs:c,outputStateTreeInfo:l}),{mint:h}=Ie(r),{delegatedTransfer:f,authority:g}=we(r,c),y=ee({proof:s,mint:h,delegatedTransfer:f,inputTokenDataWithContext:d,outputCompressedAccounts:p,compressOrDecompressAmount:null,isCompress:0,cpiContext:null,lamportsChangeAccountMerkleTreeIndex:null}),{accountCompressionAuthority:b,noopProgram:I,registeredProgramPda:w,accountCompressionProgram:k}=t.defaultStaticAccountsStruct(),A=oe({feePayer:n,authority:g,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:t.LightSystemProgram.programId,registeredProgramPda:w,noopProgram:I,accountCompressionAuthority:b,accountCompressionProgram:k,selfProgram:this.programId,tokenPoolPda:void 0,compressOrDecompressTokenAccount:void 0,tokenProgram:void 0,systemProgram:e.SystemProgram.programId});return A.push(...m),new e.TransactionInstruction({programId:this.programId,keys:A,data:y})}static async createTokenProgramLookupTable({payer:r,authority:o,mints:i,recentSlot:s,remainingAccounts:a}){const[u,c]=e.AddressLookupTableProgram.createLookupTable({authority:o,payer:o,recentSlot:s});let l=[];i&&(l=[...i,...i.map((e=>this.deriveSplInterfacePda(e)))]);const d=[u,e.AddressLookupTableProgram.extendLookupTable({payer:r,authority:o,lookupTable:c,addresses:[e.SystemProgram.programId,e.ComputeBudgetProgram.programId,this.deriveCpiAuthorityPda,t.LightSystemProgram.programId,ve.programId,t.defaultStaticAccountsStruct().registeredProgramPda,t.defaultStaticAccountsStruct().noopProgram,t.defaultStaticAccountsStruct().accountCompressionAuthority,t.defaultStaticAccountsStruct().accountCompressionProgram,t.defaultTestStateTreeAccounts().merkleTree,t.defaultTestStateTreeAccounts().nullifierQueue,t.defaultTestStateTreeAccounts().addressTree,t.defaultTestStateTreeAccounts().addressQueue,this.programId,n.TOKEN_PROGRAM_ID,n.TOKEN_2022_PROGRAM_ID,o,...l]})];if(a&&a.length>0)for(let t=0;t<a.length;t+=25){const n=a.slice(t,t+25),i=e.AddressLookupTableProgram.extendLookupTable({payer:r,authority:o,lookupTable:c,addresses:n});d.push(i)}return{instructions:d,address:c}}static async compress({payer:n,owner:r,source:o,toAddress:i,amount:s,mint:a,outputStateTreeInfo:u,tokenPoolInfo:c}){let l;const d=t.toArray(s),p=t.toArray(i);if(T(c,a),d.length!==p.length)throw new Error("Amount and toAddress arrays must have the same length");if(t.featureFlags.isV2()){const[i,s]=this.findSplInterfaceIndexAndBump(ge(c),a),l=Y({pubkeys:p,amounts:d.length>1?d.map((e=>t.bn(e))):null,lamports:null,amount:1===d.length?t.bn(d[0]):null,index:i,bump:s}),m=re(Object.assign(Object.assign({mint:a,feePayer:n,authority:r,cpiAuthorityPda:this.deriveCpiAuthorityPda,tokenProgram:c.tokenProgram,tokenPoolPda:ge(c),lightSystemProgram:t.LightSystemProgram.programId},t.defaultStaticAccountsStruct()),{merkleTree:u.queue,selfProgram:this.programId,systemProgram:e.SystemProgram.programId,solPoolPda:null}));return m.push({pubkey:o,isWritable:1,isSigner:0}),new e.TransactionInstruction({programId:this.programId,keys:m,data:l})}{l=d.map(((e,n)=>{const r=t.bn(e);return{owner:p[n],amount:r,lamports:null,tlv:null}}));const{inputTokenDataWithContext:i,packedOutputTokenData:m,remainingAccountMetas:h}=W({inputCompressedTokenAccounts:[],outputStateTreeInfo:u,rootIndices:[],tokenTransferOutputs:l}),f=ee({proof:null,mint:a,delegatedTransfer:null,inputTokenDataWithContext:i,outputCompressedAccounts:m,compressOrDecompressAmount:Array.isArray(s)?s.map((e=>t.bn(e))).reduce(((e,t)=>e.add(t)),t.bn(0)):t.bn(s),isCompress:1,cpiContext:null,lamportsChangeAccountMerkleTreeIndex:null}),g=oe(Object.assign(Object.assign({},t.defaultStaticAccountsStruct()),{feePayer:n,authority:r,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:t.LightSystemProgram.programId,selfProgram:this.programId,systemProgram:e.SystemProgram.programId,tokenPoolPda:ge(c),compressOrDecompressTokenAccount:o,tokenProgram:c.tokenProgram}));return g.push(...h),new e.TransactionInstruction({programId:this.programId,keys:g,data:f})}}static async decompress({payer:n,inputCompressedTokenAccounts:r,toAddress:o,amount:i,recentValidityProof:s,recentInputStateRootIndices:a,tokenPoolInfos:u}){const c=t.bn(i),l=t.toArray(u),d=Ae(r,c),{inputTokenDataWithContext:p,packedOutputTokenData:m,remainingAccountMetas:h}=W({inputCompressedTokenAccounts:r,rootIndices:a,tokenTransferOutputs:d,remainingAccounts:l.slice(1).map((e=>ge(e)))}),{mint:f}=Ie(r),{delegatedTransfer:g,authority:y}=we(r,d),b=ee({proof:s,mint:f,delegatedTransfer:g,inputTokenDataWithContext:p,outputCompressedAccounts:m,compressOrDecompressAmount:c,isCompress:0,cpiContext:null,lamportsChangeAccountMerkleTreeIndex:null}),I=l[0].tokenProgram,{accountCompressionAuthority:w,noopProgram:k,registeredProgramPda:A,accountCompressionProgram:v}=t.defaultStaticAccountsStruct(),T=oe({feePayer:n,authority:y,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:t.LightSystemProgram.programId,registeredProgramPda:A,noopProgram:k,accountCompressionAuthority:w,accountCompressionProgram:v,selfProgram:this.programId,tokenPoolPda:ge(l[0]),compressOrDecompressTokenAccount:o,tokenProgram:I,systemProgram:e.SystemProgram.programId});return T.push(...h),new e.TransactionInstruction({programId:this.programId,keys:T,data:b})}static async mergeTokenAccounts({payer:e,owner:n,inputCompressedTokenAccounts:r,mint:o,recentValidityProof:i,recentInputStateRootIndices:s}){const a=t.featureFlags.isV2()?8:4;if(r.length>a)throw new Error(`Cannot merge more than ${a} token accounts at once`);return G(r,o),[await this.transfer({payer:e,inputCompressedTokenAccounts:r,toAddress:n,amount:r.reduce(((e,t)=>e.add(t.parsed.amount)),t.bn(0)),recentInputStateRootIndices:s,recentValidityProof:i})]}static async compressSplTokenAccount({feePayer:n,authority:r,tokenAccount:o,mint:i,remainingAmount:s,outputStateTreeInfo:a,tokenPoolInfo:u}){T(u,i);const c=[{pubkey:a.treeType===t.TreeType.StateV2?a.queue:a.tree,isSigner:0,isWritable:1}],l=J({owner:r,remainingAmount:null!=s?s:null,cpiContext:null}),{accountCompressionAuthority:d,noopProgram:p,registeredProgramPda:m,accountCompressionProgram:h}=t.defaultStaticAccountsStruct(),f=oe({feePayer:n,authority:r,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:t.LightSystemProgram.programId,registeredProgramPda:m,noopProgram:p,accountCompressionAuthority:d,accountCompressionProgram:h,selfProgram:this.programId,tokenPoolPda:ge(u),compressOrDecompressTokenAccount:o,tokenProgram:u.tokenProgram,systemProgram:e.SystemProgram.programId});return f.push(...c),new e.TransactionInstruction({programId:this.programId,keys:f,data:l})}static async getMintProgramId(e,t){var n;return null===(n=await t.getAccountInfo(e))||void 0===n?void 0:n.owner}static async approve({payer:n,inputCompressedTokenAccounts:r,toAddress:o,amount:i,recentValidityProof:s,recentInputStateRootIndices:a}){const{inputTokenDataWithContext:u,remainingAccountMetas:c}=W({inputCompressedTokenAccounts:r,rootIndices:a,tokenTransferOutputs:[]}),{mint:l,currentOwner:d}=Ie(r),p=r[0].compressedAccount.treeInfo.treeType===t.TreeType.StateV2?1:0,m=me({proof:s,mint:l,inputTokenDataWithContext:u,cpiContext:null,delegate:o,delegatedAmount:t.bn(i),delegateMerkleTreeIndex:p,changeAccountMerkleTreeIndex:p,delegateLamports:null}),{accountCompressionAuthority:h,noopProgram:f,registeredProgramPda:g,accountCompressionProgram:y}=t.defaultStaticAccountsStruct(),b=ie({feePayer:n,authority:d,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:t.LightSystemProgram.programId,registeredProgramPda:g,noopProgram:f,accountCompressionAuthority:h,accountCompressionProgram:y,selfProgram:this.programId,systemProgram:e.SystemProgram.programId});return b.push(...c),new e.TransactionInstruction({programId:this.programId,keys:b,data:m})}static async revoke({payer:n,inputCompressedTokenAccounts:r,recentValidityProof:o,recentInputStateRootIndices:i}){be(r);const{inputTokenDataWithContext:s,remainingAccountMetas:a}=W({inputCompressedTokenAccounts:r,rootIndices:i,tokenTransferOutputs:[]}),{mint:u,currentOwner:c}=Ie(r),l=he({proof:o,mint:u,inputTokenDataWithContext:s,cpiContext:null,outputAccountMerkleTreeIndex:r[0].compressedAccount.treeInfo.treeType===t.TreeType.StateV2?2:1}),{accountCompressionAuthority:d,noopProgram:p,registeredProgramPda:m,accountCompressionProgram:h}=t.defaultStaticAccountsStruct(),f=se({feePayer:n,authority:c,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:t.LightSystemProgram.programId,registeredProgramPda:m,noopProgram:p,accountCompressionAuthority:d,accountCompressionProgram:h,selfProgram:this.programId,systemProgram:e.SystemProgram.programId});return f.push(...a),new e.TransactionInstruction({programId:this.programId,keys:f,data:l})}}function Te(e,n){const r=t.deriveAddressV2(Pe(e)[0].toBytes(),n.tree,t.LIGHT_TOKEN_PROGRAM_ID);return Array.from(r.toBytes())}ve.programId=new e.PublicKey("cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m");const Me=r.Buffer.from([99,111,109,112,114,101,115,115,101,100,95,109,105,110,116]);function Pe(n){const[r,o]=e.PublicKey.findProgramAddressSync([Me,n.toBuffer()],t.LIGHT_TOKEN_PROGRAM_ID);return[r,o]}const Se=r.Buffer.from([103]),xe=o.struct([o.publicKey("recipient"),o.u64("amount")]),Ce=o.struct([o.u8("tokenAccountVersion"),o.vec(xe,"recipients")]),_e=o.struct([o.option(o.publicKey(),"newAuthority")]),Ee=o.struct([o.u8("accountIndex"),o.u64("amount")]),Oe=o.struct([o.u8("extensionIndex"),o.u8("fieldType"),o.vecU8("key"),o.vecU8("value")]),Be=o.struct([o.u8("extensionIndex"),o.publicKey("newAuthority")]),Le=o.struct([o.u8("extensionIndex"),o.vecU8("key"),o.u8("idempotent")]),De=o.struct([o.u8("rentPayment"),o.u32("writeTopUp")]),Re=o.struct([o.u8("idempotent")]),Ke=o.rustEnum([Ce.replicate("mintToCompressed"),_e.replicate("updateMintAuthority"),_e.replicate("updateFreezeAuthority"),Ee.replicate("mintToLightToken"),Oe.replicate("updateMetadataField"),Be.replicate("updateMetadataAuthority"),Le.replicate("removeMetadataKey"),De.replicate("decompressMint"),Re.replicate("compressAndCloseCMint")]),Ue=o.struct([o.array(o.u8(),32,"a"),o.array(o.u8(),64,"b"),o.array(o.u8(),32,"c")]),Ne=o.struct([o.bool("setContext"),o.bool("firstSetContext"),o.u8("inTreeIndex"),o.u8("inQueueIndex"),o.u8("outQueueIndex"),o.u8("tokenOutQueueIndex"),o.u8("assignedAccountIndex"),o.array(o.u8(),4,"readOnlyAddressTrees"),o.array(o.u8(),32,"addressTreePubkey")]),We=o.struct([o.array(o.u8(),4,"readOnlyAddressTrees"),o.array(o.u16(),4,"readOnlyAddressTreeRootIndices")]),Ge=o.struct([o.vecU8("key"),o.vecU8("value")]),qe=o.struct([o.option(o.publicKey(),"updateAuthority"),o.vecU8("name"),o.vecU8("symbol"),o.vecU8("uri"),o.option(o.vec(Ge),"additionalMetadata")]),Fe=o.struct([]),Ve=o.rustEnum([Fe.replicate("placeholder0"),Fe.replicate("placeholder1"),Fe.replicate("placeholder2"),Fe.replicate("placeholder3"),Fe.replicate("placeholder4"),Fe.replicate("placeholder5"),Fe.replicate("placeholder6"),Fe.replicate("placeholder7"),Fe.replicate("placeholder8"),Fe.replicate("placeholder9"),Fe.replicate("placeholder10"),Fe.replicate("placeholder11"),Fe.replicate("placeholder12"),Fe.replicate("placeholder13"),Fe.replicate("placeholder14"),Fe.replicate("placeholder15"),Fe.replicate("placeholder16"),Fe.replicate("placeholder17"),Fe.replicate("placeholder18"),qe.replicate("tokenMetadata")]),He=o.struct([o.u8("version"),o.bool("cmintDecompressed"),o.publicKey("mint"),o.array(o.u8(),32,"mintSigner"),o.u8("bump")]),ze=o.struct([o.u64("supply"),o.u8("decimals"),He.replicate("metadata"),o.option(o.publicKey(),"mintAuthority"),o.option(o.publicKey(),"freezeAuthority"),o.option(o.vec(Ve),"extensions")]),je=o.struct([o.u32("leafIndex"),o.bool("proveByIndex"),o.u16("rootIndex"),o.u16("maxTopUp"),o.option(We,"createMint"),o.vec(Ke,"actions"),o.option(Ue,"proof"),o.option(Ne,"cpiContext"),o.option(ze,"mint")]);function $e(e){const n=e.actions.map((e=>"mintToCompressed"in e&&e.mintToCompressed?{mintToCompressed:Object.assign(Object.assign({},e.mintToCompressed),{recipients:e.mintToCompressed.recipients.map((e=>Object.assign(Object.assign({},e),{amount:t.bn(e.amount.toString())})))})}:"mintToLightToken"in e&&e.mintToLightToken?{mintToLightToken:Object.assign(Object.assign({},e.mintToLightToken),{amount:t.bn(e.mintToLightToken.amount.toString())})}:e)),o=r.Buffer.alloc(1e4),i=Object.assign(Object.assign({},e),{actions:n,mint:e.mint?Object.assign(Object.assign({},e.mint),{supply:t.bn(e.mint.supply.toString())}):null}),s=je.encode(i,o);return r.Buffer.concat([Se,o.subarray(0,s)])}function Ze(n,o,a,u,c,l,d,p,m,h){return function(n,r,o,a,u,c){const l=t.defaultStaticAccountsStruct(),[d]=Pe(n),p=[{pubkey:t.LightSystemProgram.programId,isSigner:0,isWritable:0},{pubkey:n,isSigner:1,isWritable:0},{pubkey:r,isSigner:1,isWritable:0},{pubkey:i,isSigner:0,isWritable:0},{pubkey:d,isSigner:0,isWritable:1},{pubkey:s,isSigner:0,isWritable:1},{pubkey:o,isSigner:1,isWritable:1},{pubkey:ve.deriveCpiAuthorityPda,isSigner:0,isWritable:0},{pubkey:l.registeredProgramPda,isSigner:0,isWritable:0},{pubkey:l.accountCompressionAuthority,isSigner:0,isWritable:0},{pubkey:l.accountCompressionProgram,isSigner:0,isWritable:0},{pubkey:e.SystemProgram.programId,isSigner:0,isWritable:0},{pubkey:a.queue,isSigner:0,isWritable:1},{pubkey:u.tree,isSigner:0,isWritable:1}];return new e.TransactionInstruction({programId:t.LIGHT_TOKEN_PROGRAM_ID,keys:p,data:c})}(n,a,c,p,d,function(e){var t,n;const[o,i]=Pe(e.mintSigner);let s=null;e.metadata&&(s=[{tokenMetadata:{updateAuthority:null!==(t=e.metadata.updateAuthority)&&void 0!==t?t:null,name:r.Buffer.from(e.metadata.name),symbol:r.Buffer.from(e.metadata.symbol),uri:r.Buffer.from(e.metadata.uri),additionalMetadata:e.metadata.additionalMetadata}}]);const a=function(e){if(!e)return null;if(32!==e.a.length)throw new Error(`Invalid proof.a length: expected 32, got ${e.a.length}`);if(64!==e.b.length)throw new Error(`Invalid proof.b length: expected 64, got ${e.b.length}`);if(32!==e.c.length)throw new Error(`Invalid proof.c length: expected 32, got ${e.c.length}`);return e}(e.proof);return $e({leafIndex:0,proveByIndex:0,rootIndex:e.rootIndex,maxTopUp:null!==(n=e.maxTopUp)&&void 0!==n?n:b,createMint:{readOnlyAddressTrees:[0,0,0,0],readOnlyAddressTreeRootIndices:[0,0,0,0]},actions:[{decompressMint:{rentPayment:16,writeTopUp:766}}],proof:a,cpiContext:null,mint:{supply:BigInt(0),decimals:e.decimals,metadata:{version:exports.TokenDataVersion.ShaFlat,cmintDecompressed:0,mint:o,mintSigner:Array.from(e.mintSigner.toBytes()),bump:i},mintAuthority:e.mintAuthority,freezeAuthority:e.freezeAuthority,extensions:s}})}({mintSigner:n,mintAuthority:a,freezeAuthority:u,decimals:o,addressTree:d.tree,outputQueue:p.queue,rootIndex:l.rootIndices[0],proof:l.compressedProof,metadata:m,maxTopUp:h}))}function Qe(e){var t,n,o,i;const s="mintAuthority"===e.actionType?{updateMintAuthority:{newAuthority:e.newAuthority}}:{updateFreezeAuthority:{newAuthority:e.newAuthority}},a=null!==(n=null===(t=e.mintInterface.mintContext)||void 0===t?void 0:t.cmintDecompressed)&&void 0!==n?n:0;let u=null;return!a&&e.mintInterface.tokenMetadata&&(u=[{tokenMetadata:{updateAuthority:null!==(o=e.mintInterface.tokenMetadata.updateAuthority)&&void 0!==o?o:null,name:r.Buffer.from(e.mintInterface.tokenMetadata.name),symbol:r.Buffer.from(e.mintInterface.tokenMetadata.symbol),uri:r.Buffer.from(e.mintInterface.tokenMetadata.uri),additionalMetadata:null}}]),$e({leafIndex:e.leafIndex,proveByIndex:e.proveByIndex,rootIndex:e.rootIndex,maxTopUp:null!==(i=e.maxTopUp)&&void 0!==i?i:b,createMint:null,actions:[s],proof:e.proof,cpiContext:null,mint:a?null:{supply:e.mintInterface.mint.supply,decimals:e.mintInterface.mint.decimals,metadata:{version:e.mintInterface.mintContext.version,cmintDecompressed:e.mintInterface.mintContext.cmintDecompressed,mint:e.mintInterface.mintContext.splMint,mintSigner:Array.from(e.mintInterface.mintContext.mintSigner),bump:e.mintInterface.mintContext.bump},mintAuthority:e.mintInterface.mint.mintAuthority,freezeAuthority:e.mintInterface.mint.freezeAuthority,extensions:u}})}function Xe(n,r,o,i,s,a){var u,c,l;if(!n.merkleContext)throw new Error("MintInterface must have merkleContext for light mint operations");if(!n.mintContext)throw new Error("MintInterface must have mintContext for light mint operations");const d=n.merkleContext,p=t.getOutputQueue(d),m=null!==(u=n.mintContext.cmintDecompressed)&&void 0!==u?u:0;t.getDefaultAddressTreeInfo();const h=Qe({leafIndex:d.leafIndex,proveByIndex:1,rootIndex:null!==(c=null==s?void 0:s.rootIndices[0])&&void 0!==c?c:0,proof:m?null:null!==(l=null==s?void 0:s.compressedProof)&&void 0!==l?l:null,mintInterface:n,newAuthority:o,actionType:"mintAuthority",maxTopUp:a}),f=t.defaultStaticAccountsStruct(),g=[{pubkey:t.LightSystemProgram.programId,isSigner:0,isWritable:0},{pubkey:r,isSigner:1,isWritable:0},...m?[{pubkey:n.mint.address,isSigner:0,isWritable:1}]:[],{pubkey:i,isSigner:1,isWritable:1},{pubkey:ve.deriveCpiAuthorityPda,isSigner:0,isWritable:0},{pubkey:f.registeredProgramPda,isSigner:0,isWritable:0},{pubkey:f.accountCompressionAuthority,isSigner:0,isWritable:0},{pubkey:f.accountCompressionProgram,isSigner:0,isWritable:0},{pubkey:e.SystemProgram.programId,isSigner:0,isWritable:0},{pubkey:p,isSigner:0,isWritable:1},{pubkey:d.treeInfo.tree,isSigner:0,isWritable:1},{pubkey:d.treeInfo.queue,isSigner:0,isWritable:1}];return new e.TransactionInstruction({programId:t.LIGHT_TOKEN_PROGRAM_ID,keys:g,data:h})}function Ye(n,r,o,i,s,a){var u,c,l;if(!n.merkleContext)throw new Error("MintInterface must have merkleContext for light mint operations");if(!n.mintContext)throw new Error("MintInterface must have mintContext for light mint operations");const d=n.merkleContext,p=t.getOutputQueue(d),m=null!==(u=n.mintContext.cmintDecompressed)&&void 0!==u?u:0;t.getDefaultAddressTreeInfo();const h=Qe({leafIndex:d.leafIndex,proveByIndex:1,rootIndex:null!==(c=null==s?void 0:s.rootIndices[0])&&void 0!==c?c:0,proof:m?null:null!==(l=null==s?void 0:s.compressedProof)&&void 0!==l?l:null,mintInterface:n,newAuthority:o,actionType:"freezeAuthority",maxTopUp:a}),f=t.defaultStaticAccountsStruct(),g=[{pubkey:t.LightSystemProgram.programId,isSigner:0,isWritable:0},{pubkey:r,isSigner:1,isWritable:0},...m?[{pubkey:n.mint.address,isSigner:0,isWritable:1}]:[],{pubkey:i,isSigner:1,isWritable:1},{pubkey:ve.deriveCpiAuthorityPda,isSigner:0,isWritable:0},{pubkey:f.registeredProgramPda,isSigner:0,isWritable:0},{pubkey:f.accountCompressionAuthority,isSigner:0,isWritable:0},{pubkey:f.accountCompressionProgram,isSigner:0,isWritable:0},{pubkey:e.SystemProgram.programId,isSigner:0,isWritable:0},{pubkey:p,isSigner:0,isWritable:1},{pubkey:d.treeInfo.tree,isSigner:0,isWritable:1},{pubkey:d.treeInfo.queue,isSigner:0,isWritable:1}];return new e.TransactionInstruction({programId:t.LIGHT_TOKEN_PROGRAM_ID,keys:g,data:h})}function Je(n,o,i,s,a,u){var c,l,d;if(!n.merkleContext)throw new Error("MintInterface must have merkleContext for light mint operations");if(!n.mintContext)throw new Error("MintInterface must have mintContext for light mint operations");if(!n.tokenMetadata)throw new Error("MintInterface must have tokenMetadata for metadata operations");const p=n.merkleContext,m=t.getOutputQueue(p),h=null!==(c=n.mintContext.cmintDecompressed)&&void 0!==c?c:0;t.getDefaultAddressTreeInfo();const f=function(e){var t,n,o,i;const s=e.mintInterface;if(!s.tokenMetadata)throw new Error("MintInterface must have tokenMetadata for metadata operations");const a=null!==(n=null===(t=s.mintContext)||void 0===t?void 0:t.cmintDecompressed)&&void 0!==n?n:0;var u;return $e({leafIndex:e.leafIndex,proveByIndex:null===e.proof,rootIndex:e.rootIndex,maxTopUp:null!==(o=e.maxTopUp)&&void 0!==o?o:b,createMint:null,actions:[(u=e.action,"updateField"===u.type?{updateMetadataField:{extensionIndex:u.extensionIndex,fieldType:u.fieldType,key:r.Buffer.from(u.key),value:r.Buffer.from(u.value)}}:"updateAuthority"===u.type?{updateMetadataAuthority:{extensionIndex:u.extensionIndex,newAuthority:u.newAuthority}}:{removeMetadataKey:{extensionIndex:u.extensionIndex,key:r.Buffer.from(u.key),idempotent:u.idempotent?1:0}})],proof:e.proof,cpiContext:null,mint:a?null:{supply:s.mint.supply,decimals:s.mint.decimals,metadata:{version:s.mintContext.version,cmintDecompressed:s.mintContext.cmintDecompressed,mint:s.mintContext.splMint,mintSigner:Array.from(s.mintContext.mintSigner),bump:s.mintContext.bump},mintAuthority:s.mint.mintAuthority,freezeAuthority:s.mint.freezeAuthority,extensions:[{tokenMetadata:{updateAuthority:null!==(i=s.tokenMetadata.updateAuthority)&&void 0!==i?i:null,name:r.Buffer.from(s.tokenMetadata.name),symbol:r.Buffer.from(s.tokenMetadata.symbol),uri:r.Buffer.from(s.tokenMetadata.uri),additionalMetadata:null}}]}})}({leafIndex:p.leafIndex,rootIndex:null!==(l=null==s?void 0:s.rootIndices[0])&&void 0!==l?l:0,proof:h?null:null!==(d=null==s?void 0:s.compressedProof)&&void 0!==d?d:null,mintInterface:n,action:a,maxTopUp:u}),g=t.defaultStaticAccountsStruct(),y=[{pubkey:t.LightSystemProgram.programId,isSigner:0,isWritable:0},{pubkey:o,isSigner:1,isWritable:0},...h?[{pubkey:n.mint.address,isSigner:0,isWritable:1}]:[],{pubkey:i,isSigner:1,isWritable:1},{pubkey:ve.deriveCpiAuthorityPda,isSigner:0,isWritable:0},{pubkey:g.registeredProgramPda,isSigner:0,isWritable:0},{pubkey:g.accountCompressionAuthority,isSigner:0,isWritable:0},{pubkey:g.accountCompressionProgram,isSigner:0,isWritable:0},{pubkey:e.SystemProgram.programId,isSigner:0,isWritable:0},{pubkey:m,isSigner:0,isWritable:1},{pubkey:p.treeInfo.tree,isSigner:0,isWritable:1},{pubkey:p.treeInfo.queue,isSigner:0,isWritable:1}];return new e.TransactionInstruction({programId:t.LIGHT_TOKEN_PROGRAM_ID,keys:y,data:f})}function et(e,t,n,r,o,i,s,a=0,u){return Je(e,t,n,r,{type:"updateField",extensionIndex:a,fieldType:"name"===o?0:"symbol"===o?1:"uri"===o?2:3,key:s||"",value:i},u)}function tt(e,t,n,r,o,i=0,s){return Je(e,t,r,o,{type:"updateAuthority",extensionIndex:i,newAuthority:n},s)}function nt(e,t,n,r,o,i=0,s=0,a){return Je(e,t,n,r,{type:"removeKey",extensionIndex:s,key:o,idempotent:i},a)}const rt=r.Buffer.from([100]),ot=r.Buffer.from([102]),it=o.struct([o.u8("bump"),o.array(o.u8(),32,"programId"),o.vec(o.vec(o.u8()),"seeds")]),st=o.struct([o.u8("tokenAccountVersion"),o.u8("rentPayment"),o.u8("compressionOnly"),o.u32("writeTopUp"),o.option(it,"compressToAccountPubkey")]),at=o.struct([o.option(st,"compressibleConfig")]),ut={tokenAccountVersion:3,rentPayment:16,compressionOnly:1,writeTopUp:766,compressToAccountPubkey:null};function ct(n,r){return e.PublicKey.findProgramAddressSync([n.toBuffer(),t.LIGHT_TOKEN_PROGRAM_ID.toBuffer(),r.toBuffer()],t.LIGHT_TOKEN_PROGRAM_ID)[0]}function lt(e,t){const n=r.Buffer.alloc(2e3),o=at.encode({compressibleConfig:e.compressibleConfig||null},n),i=t?ot:rt;return r.Buffer.concat([i,n.subarray(0,o)])}function dt(n,r,o,a=ut,u=i,c=s){const l=ct(r,o),d=lt({compressibleConfig:a},0),p=[{pubkey:r,isSigner:0,isWritable:0},{pubkey:o,isSigner:0,isWritable:0},{pubkey:n,isSigner:1,isWritable:1},{pubkey:l,isSigner:0,isWritable:1},{pubkey:e.SystemProgram.programId,isSigner:0,isWritable:0}];return a&&p.push({pubkey:u,isSigner:0,isWritable:0},{pubkey:c,isSigner:0,isWritable:1}),new e.TransactionInstruction({programId:t.LIGHT_TOKEN_PROGRAM_ID,keys:p,data:d})}function pt(n,r,o,a=ut,u=i,c=s){const l=ct(r,o),d=lt({compressibleConfig:a},1),p=[{pubkey:r,isSigner:0,isWritable:0},{pubkey:o,isSigner:0,isWritable:0},{pubkey:n,isSigner:1,isWritable:1},{pubkey:l,isSigner:0,isWritable:1},{pubkey:e.SystemProgram.programId,isSigner:0,isWritable:0}];return a&&p.push({pubkey:u,isSigner:0,isWritable:0},{pubkey:c,isSigner:0,isWritable:1}),new e.TransactionInstruction({programId:t.LIGHT_TOKEN_PROGRAM_ID,keys:p,data:d})}function mt(e){return e.equals(t.LIGHT_TOKEN_PROGRAM_ID)?t.LIGHT_TOKEN_PROGRAM_ID:n.ASSOCIATED_TOKEN_PROGRAM_ID}function ht(e,r,o,i,s=0){if(i){const t=n.getAssociatedTokenAddressSync(r,o,s,i,mt(i));if(e.equals(t))return{valid:1,type:ft(i),programId:i};throw new Error(`ATA address mismatch for ${i.toBase58()}. Expected: ${t.toBase58()}, got: ${e.toBase58()}`)}let a,u,c;if(a=n.getAssociatedTokenAddressSync(r,o,s,t.LIGHT_TOKEN_PROGRAM_ID,mt(t.LIGHT_TOKEN_PROGRAM_ID)),e.equals(a))return{valid:1,type:"light-token",programId:t.LIGHT_TOKEN_PROGRAM_ID};if(u=n.getAssociatedTokenAddressSync(r,o,s,n.TOKEN_PROGRAM_ID,mt(n.TOKEN_PROGRAM_ID)),e.equals(u))return{valid:1,type:"spl",programId:n.TOKEN_PROGRAM_ID};if(c=n.getAssociatedTokenAddressSync(r,o,s,n.TOKEN_2022_PROGRAM_ID,mt(n.TOKEN_2022_PROGRAM_ID)),e.equals(c))return{valid:1,type:"token2022",programId:n.TOKEN_2022_PROGRAM_ID};throw new Error(`ATA address does not match any valid derivation from mint+owner. Got: ${e.toBase58()}, expected one of: light-token=${a.toBase58()}, SPL=${u.toBase58()}, T22=${c.toBase58()}`)}function ft(e){if(e.equals(t.LIGHT_TOKEN_PROGRAM_ID))return"light-token";if(e.equals(n.TOKEN_PROGRAM_ID))return"spl";if(e.equals(n.TOKEN_2022_PROGRAM_ID))return"token2022";throw new Error(`Unknown program ID: ${e.toBase58()}`)}function gt(e,r,o,i,s=n.TOKEN_PROGRAM_ID,a,u){const c=null!=a?a:mt(s);return s.equals(t.LIGHT_TOKEN_PROGRAM_ID)?dt(e,o,i,null==u?void 0:u.compressibleConfig,null==u?void 0:u.configAccount,null==u?void 0:u.rentPayerPda):n.createAssociatedTokenAccountInstruction(e,r,o,i,s,c)}function yt(e,r,o,i,s=n.TOKEN_PROGRAM_ID,a,u){const c=null!=a?a:mt(s);return s.equals(t.LIGHT_TOKEN_PROGRAM_ID)?pt(e,o,i,null==u?void 0:u.compressibleConfig,null==u?void 0:u.configAccount,null==u?void 0:u.rentPayerPda):n.createAssociatedTokenAccountIdempotentInstruction(e,r,o,i,s,c)}const bt=yt;var It="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function wt(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function kt(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:1}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:1,get:function(){return e[t]}})})),n}var At={exports:{}},vt=kt(Object.freeze({__proto__:null,default:{}}));!function(e,t){function n(e,t){if(!e)throw new Error(t||"Assertion failed")}function r(e,t){e.super_=t;var n=function(){};n.prototype=t.prototype,e.prototype=new n,e.prototype.constructor=e}function o(e,t,n){if(o.isBN(e))return e;this.negative=0,this.words=null,this.length=0,this.red=null,null!==e&&("le"!==t&&"be"!==t||(n=t,t=10),this._init(e||0,t||10,n||"be"))}var i;"object"==typeof At?At.exports=o:t.BN=o,o.BN=o,o.wordSize=26;try{i="undefined"!=typeof window&&void 0!==window.Buffer?window.Buffer:vt.Buffer}catch(e){}function s(e,t){var r=e.charCodeAt(t);return r>=48&&r<=57?r-48:r>=65&&r<=70?r-55:r>=97&&r<=102?r-87:void n(0,"Invalid character in "+e)}function a(e,t,n){var r=s(e,n);return n-1>=t&&(r|=s(e,n-1)<<4),r}function u(e,t,r,o){for(var i=0,s=0,a=Math.min(e.length,r),u=t;u<a;u++){var c=e.charCodeAt(u)-48;i*=o,s=c>=49?c-49+10:c>=17?c-17+10:c,n(c>=0&&s<o,"Invalid character"),i+=s}return i}function c(e,t){e.words=t.words,e.length=t.length,e.negative=t.negative,e.red=t.red}if(o.isBN=function(e){return e instanceof o?1:null!==e&&"object"==typeof e&&e.constructor.wordSize===o.wordSize&&Array.isArray(e.words)},o.max=function(e,t){return e.cmp(t)>0?e:t},o.min=function(e,t){return e.cmp(t)<0?e:t},o.prototype._init=function(e,t,r){if("number"==typeof e)return this._initNumber(e,t,r);if("object"==typeof e)return this._initArray(e,t,r);"hex"===t&&(t=16),n(t===(0|t)&&t>=2&&t<=36);var o=0;"-"===(e=e.toString().replace(/\s+/g,""))[0]&&(o++,this.negative=1),o<e.length&&(16===t?this._parseHex(e,o,r):(this._parseBase(e,t,o),"le"===r&&this._initArray(this.toArray(),t,r)))},o.prototype._initNumber=function(e,t,r){e<0&&(this.negative=1,e=-e),e<67108864?(this.words=[67108863&e],this.length=1):e<4503599627370496?(this.words=[67108863&e,e/67108864&67108863],this.length=2):(n(e<9007199254740992),this.words=[67108863&e,e/67108864&67108863,1],this.length=3),"le"===r&&this._initArray(this.toArray(),t,r)},o.prototype._initArray=function(e,t,r){if(n("number"==typeof e.length),e.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(e.length/3),this.words=new Array(this.length);for(var o=0;o<this.length;o++)this.words[o]=0;var i,s,a=0;if("be"===r)for(o=e.length-1,i=0;o>=0;o-=3)s=e[o]|e[o-1]<<8|e[o-2]<<16,this.words[i]|=s<<a&67108863,this.words[i+1]=s>>>26-a&67108863,(a+=24)>=26&&(a-=26,i++);else if("le"===r)for(o=0,i=0;o<e.length;o+=3)s=e[o]|e[o+1]<<8|e[o+2]<<16,this.words[i]|=s<<a&67108863,this.words[i+1]=s>>>26-a&67108863,(a+=24)>=26&&(a-=26,i++);return this._strip()},o.prototype._parseHex=function(e,t,n){this.length=Math.ceil((e.length-t)/6),this.words=new Array(this.length);for(var r=0;r<this.length;r++)this.words[r]=0;var o,i=0,s=0;if("be"===n)for(r=e.length-1;r>=t;r-=2)o=a(e,t,r)<<i,this.words[s]|=67108863&o,i>=18?(i-=18,s+=1,this.words[s]|=o>>>26):i+=8;else for(r=(e.length-t)%2==0?t+1:t;r<e.length;r+=2)o=a(e,t,r)<<i,this.words[s]|=67108863&o,i>=18?(i-=18,s+=1,this.words[s]|=o>>>26):i+=8;this._strip()},o.prototype._parseBase=function(e,t,n){this.words=[0],this.length=1;for(var r=0,o=1;o<=67108863;o*=t)r++;r--,o=o/t|0;for(var i=e.length-n,s=i%r,a=Math.min(i,i-s)+n,c=0,l=n;l<a;l+=r)c=u(e,l,l+r,t),this.imuln(o),this.words[0]+c<67108864?this.words[0]+=c:this._iaddn(c);if(0!==s){var d=1;for(c=u(e,l,e.length,t),l=0;l<s;l++)d*=t;this.imuln(d),this.words[0]+c<67108864?this.words[0]+=c:this._iaddn(c)}this._strip()},o.prototype.copy=function(e){e.words=new Array(this.length);for(var t=0;t<this.length;t++)e.words[t]=this.words[t];e.length=this.length,e.negative=this.negative,e.red=this.red},o.prototype._move=function(e){c(e,this)},o.prototype.clone=function(){var e=new o(null);return this.copy(e),e},o.prototype._expand=function(e){for(;this.length<e;)this.words[this.length++]=0;return this},o.prototype._strip=function(){for(;this.length>1&&0===this.words[this.length-1];)this.length--;return this._normSign()},o.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},"undefined"!=typeof Symbol&&"function"==typeof Symbol.for)try{o.prototype[Symbol.for("nodejs.util.inspect.custom")]=l}catch(e){o.prototype.inspect=l}else o.prototype.inspect=l;function l(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var d=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],p=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],m=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];function h(e,t,n){n.negative=t.negative^e.negative;var r=e.length+t.length|0;n.length=r,r=r-1|0;var o=0|e.words[0],i=0|t.words[0],s=o*i,a=67108863&s,u=s/67108864|0;n.words[0]=a;for(var c=1;c<r;c++){for(var l=u>>>26,d=67108863&u,p=Math.min(c,t.length-1),m=Math.max(0,c-e.length+1);m<=p;m++){var h=c-m|0;l+=(s=(o=0|e.words[h])*(i=0|t.words[m])+d)/67108864|0,d=67108863&s}n.words[c]=0|d,u=0|l}return 0!==u?n.words[c]=0|u:n.length--,n._strip()}o.prototype.toString=function(e,t){var r;if(t=0|t||1,16===(e=e||10)||"hex"===e){r="";for(var o=0,i=0,s=0;s<this.length;s++){var a=this.words[s],u=(16777215&(a<<o|i)).toString(16);i=a>>>24-o&16777215,(o+=2)>=26&&(o-=26,s--),r=0!==i||s!==this.length-1?d[6-u.length]+u+r:u+r}for(0!==i&&(r=i.toString(16)+r);r.length%t!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}if(e===(0|e)&&e>=2&&e<=36){var c=p[e],l=m[e];r="";var h=this.clone();for(h.negative=0;!h.isZero();){var f=h.modrn(l).toString(e);r=(h=h.idivn(l)).isZero()?f+r:d[c-f.length]+f+r}for(this.isZero()&&(r="0"+r);r.length%t!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}n(0,"Base should be between 2 and 36")},o.prototype.toNumber=function(){var e=this.words[0];return 2===this.length?e+=67108864*this.words[1]:3===this.length&&1===this.words[2]?e+=4503599627370496+67108864*this.words[1]:this.length>2&&n(0,"Number can only safely store up to 53 bits"),0!==this.negative?-e:e},o.prototype.toJSON=function(){return this.toString(16,2)},i&&(o.prototype.toBuffer=function(e,t){return this.toArrayLike(i,e,t)}),o.prototype.toArray=function(e,t){return this.toArrayLike(Array,e,t)},o.prototype.toArrayLike=function(e,t,r){this._strip();var o=this.byteLength(),i=r||Math.max(1,o);n(o<=i,"byte array longer than desired length"),n(i>0,"Requested array length <= 0");var s=function(e,t){return e.allocUnsafe?e.allocUnsafe(t):new e(t)}(e,i);return this["_toArrayLike"+("le"===t?"LE":"BE")](s,o),s},o.prototype._toArrayLikeLE=function(e){for(var t=0,n=0,r=0,o=0;r<this.length;r++){var i=this.words[r]<<o|n;e[t++]=255&i,t<e.length&&(e[t++]=i>>8&255),t<e.length&&(e[t++]=i>>16&255),6===o?(t<e.length&&(e[t++]=i>>24&255),n=0,o=0):(n=i>>>24,o+=2)}if(t<e.length)for(e[t++]=n;t<e.length;)e[t++]=0},o.prototype._toArrayLikeBE=function(e){for(var t=e.length-1,n=0,r=0,o=0;r<this.length;r++){var i=this.words[r]<<o|n;e[t--]=255&i,t>=0&&(e[t--]=i>>8&255),t>=0&&(e[t--]=i>>16&255),6===o?(t>=0&&(e[t--]=i>>24&255),n=0,o=0):(n=i>>>24,o+=2)}if(t>=0)for(e[t--]=n;t>=0;)e[t--]=0},Math.clz32?o.prototype._countBits=function(e){return 32-Math.clz32(e)}:o.prototype._countBits=function(e){var t=e,n=0;return t>=4096&&(n+=13,t>>>=13),t>=64&&(n+=7,t>>>=7),t>=8&&(n+=4,t>>>=4),t>=2&&(n+=2,t>>>=2),n+t},o.prototype._zeroBits=function(e){if(0===e)return 26;var t=e,n=0;return 0==(8191&t)&&(n+=13,t>>>=13),0==(127&t)&&(n+=7,t>>>=7),0==(15&t)&&(n+=4,t>>>=4),0==(3&t)&&(n+=2,t>>>=2),0==(1&t)&&n++,n},o.prototype.bitLength=function(){var e=this.words[this.length-1],t=this._countBits(e);return 26*(this.length-1)+t},o.prototype.zeroBits=function(){if(this.isZero())return 0;for(var e=0,t=0;t<this.length;t++){var n=this._zeroBits(this.words[t]);if(e+=n,26!==n)break}return e},o.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},o.prototype.toTwos=function(e){return 0!==this.negative?this.abs().inotn(e).iaddn(1):this.clone()},o.prototype.fromTwos=function(e){return this.testn(e-1)?this.notn(e).iaddn(1).ineg():this.clone()},o.prototype.isNeg=function(){return 0!==this.negative},o.prototype.neg=function(){return this.clone().ineg()},o.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},o.prototype.iuor=function(e){for(;this.length<e.length;)this.words[this.length++]=0;for(var t=0;t<e.length;t++)this.words[t]=this.words[t]|e.words[t];return this._strip()},o.prototype.ior=function(e){return n(0==(this.negative|e.negative)),this.iuor(e)},o.prototype.or=function(e){return this.length>e.length?this.clone().ior(e):e.clone().ior(this)},o.prototype.uor=function(e){return this.length>e.length?this.clone().iuor(e):e.clone().iuor(this)},o.prototype.iuand=function(e){var t;t=this.length>e.length?e:this;for(var n=0;n<t.length;n++)this.words[n]=this.words[n]&e.words[n];return this.length=t.length,this._strip()},o.prototype.iand=function(e){return n(0==(this.negative|e.negative)),this.iuand(e)},o.prototype.and=function(e){return this.length>e.length?this.clone().iand(e):e.clone().iand(this)},o.prototype.uand=function(e){return this.length>e.length?this.clone().iuand(e):e.clone().iuand(this)},o.prototype.iuxor=function(e){var t,n;this.length>e.length?(t=this,n=e):(t=e,n=this);for(var r=0;r<n.length;r++)this.words[r]=t.words[r]^n.words[r];if(this!==t)for(;r<t.length;r++)this.words[r]=t.words[r];return this.length=t.length,this._strip()},o.prototype.ixor=function(e){return n(0==(this.negative|e.negative)),this.iuxor(e)},o.prototype.xor=function(e){return this.length>e.length?this.clone().ixor(e):e.clone().ixor(this)},o.prototype.uxor=function(e){return this.length>e.length?this.clone().iuxor(e):e.clone().iuxor(this)},o.prototype.inotn=function(e){n("number"==typeof e&&e>=0);var t=0|Math.ceil(e/26),r=e%26;this._expand(t),r>0&&t--;for(var o=0;o<t;o++)this.words[o]=67108863&~this.words[o];return r>0&&(this.words[o]=~this.words[o]&67108863>>26-r),this._strip()},o.prototype.notn=function(e){return this.clone().inotn(e)},o.prototype.setn=function(e,t){n("number"==typeof e&&e>=0);var r=e/26|0,o=e%26;return this._expand(r+1),this.words[r]=t?this.words[r]|1<<o:this.words[r]&~(1<<o),this._strip()},o.prototype.iadd=function(e){var t,n,r;if(0!==this.negative&&0===e.negative)return this.negative=0,t=this.isub(e),this.negative^=1,this._normSign();if(0===this.negative&&0!==e.negative)return e.negative=0,t=this.isub(e),e.negative=1,t._normSign();this.length>e.length?(n=this,r=e):(n=e,r=this);for(var o=0,i=0;i<r.length;i++)t=(0|n.words[i])+(0|r.words[i])+o,this.words[i]=67108863&t,o=t>>>26;for(;0!==o&&i<n.length;i++)t=(0|n.words[i])+o,this.words[i]=67108863&t,o=t>>>26;if(this.length=n.length,0!==o)this.words[this.length]=o,this.length++;else if(n!==this)for(;i<n.length;i++)this.words[i]=n.words[i];return this},o.prototype.add=function(e){var t;return 0!==e.negative&&0===this.negative?(e.negative=0,t=this.sub(e),e.negative^=1,t):0===e.negative&&0!==this.negative?(this.negative=0,t=e.sub(this),this.negative=1,t):this.length>e.length?this.clone().iadd(e):e.clone().iadd(this)},o.prototype.isub=function(e){if(0!==e.negative){e.negative=0;var t=this.iadd(e);return e.negative=1,t._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(e),this.negative=1,this._normSign();var n,r,o=this.cmp(e);if(0===o)return this.negative=0,this.length=1,this.words[0]=0,this;o>0?(n=this,r=e):(n=e,r=this);for(var i=0,s=0;s<r.length;s++)i=(t=(0|n.words[s])-(0|r.words[s])+i)>>26,this.words[s]=67108863&t;for(;0!==i&&s<n.length;s++)i=(t=(0|n.words[s])+i)>>26,this.words[s]=67108863&t;if(0===i&&s<n.length&&n!==this)for(;s<n.length;s++)this.words[s]=n.words[s];return this.length=Math.max(this.length,s),n!==this&&(this.negative=1),this._strip()},o.prototype.sub=function(e){return this.clone().isub(e)};var f=function(e,t,n){var r,o,i,s=e.words,a=t.words,u=n.words,c=0,l=0|s[0],d=8191&l,p=l>>>13,m=0|s[1],h=8191&m,f=m>>>13,g=0|s[2],y=8191&g,b=g>>>13,I=0|s[3],w=8191&I,k=I>>>13,A=0|s[4],v=8191&A,T=A>>>13,M=0|s[5],P=8191&M,S=M>>>13,x=0|s[6],C=8191&x,_=x>>>13,E=0|s[7],O=8191&E,B=E>>>13,L=0|s[8],D=8191&L,R=L>>>13,K=0|s[9],U=8191&K,N=K>>>13,W=0|a[0],G=8191&W,q=W>>>13,F=0|a[1],V=8191&F,H=F>>>13,z=0|a[2],j=8191&z,$=z>>>13,Z=0|a[3],Q=8191&Z,X=Z>>>13,Y=0|a[4],J=8191&Y,ee=Y>>>13,te=0|a[5],ne=8191&te,re=te>>>13,oe=0|a[6],ie=8191&oe,se=oe>>>13,ae=0|a[7],ue=8191&ae,ce=ae>>>13,le=0|a[8],de=8191&le,pe=le>>>13,me=0|a[9],he=8191&me,fe=me>>>13;n.negative=e.negative^t.negative,n.length=19;var ge=(c+(r=Math.imul(d,G))|0)+((8191&(o=(o=Math.imul(d,q))+Math.imul(p,G)|0))<<13)|0;c=((i=Math.imul(p,q))+(o>>>13)|0)+(ge>>>26)|0,ge&=67108863,r=Math.imul(h,G),o=(o=Math.imul(h,q))+Math.imul(f,G)|0,i=Math.imul(f,q);var ye=(c+(r=r+Math.imul(d,V)|0)|0)+((8191&(o=(o=o+Math.imul(d,H)|0)+Math.imul(p,V)|0))<<13)|0;c=((i=i+Math.imul(p,H)|0)+(o>>>13)|0)+(ye>>>26)|0,ye&=67108863,r=Math.imul(y,G),o=(o=Math.imul(y,q))+Math.imul(b,G)|0,i=Math.imul(b,q),r=r+Math.imul(h,V)|0,o=(o=o+Math.imul(h,H)|0)+Math.imul(f,V)|0,i=i+Math.imul(f,H)|0;var be=(c+(r=r+Math.imul(d,j)|0)|0)+((8191&(o=(o=o+Math.imul(d,$)|0)+Math.imul(p,j)|0))<<13)|0;c=((i=i+Math.imul(p,$)|0)+(o>>>13)|0)+(be>>>26)|0,be&=67108863,r=Math.imul(w,G),o=(o=Math.imul(w,q))+Math.imul(k,G)|0,i=Math.imul(k,q),r=r+Math.imul(y,V)|0,o=(o=o+Math.imul(y,H)|0)+Math.imul(b,V)|0,i=i+Math.imul(b,H)|0,r=r+Math.imul(h,j)|0,o=(o=o+Math.imul(h,$)|0)+Math.imul(f,j)|0,i=i+Math.imul(f,$)|0;var Ie=(c+(r=r+Math.imul(d,Q)|0)|0)+((8191&(o=(o=o+Math.imul(d,X)|0)+Math.imul(p,Q)|0))<<13)|0;c=((i=i+Math.imul(p,X)|0)+(o>>>13)|0)+(Ie>>>26)|0,Ie&=67108863,r=Math.imul(v,G),o=(o=Math.imul(v,q))+Math.imul(T,G)|0,i=Math.imul(T,q),r=r+Math.imul(w,V)|0,o=(o=o+Math.imul(w,H)|0)+Math.imul(k,V)|0,i=i+Math.imul(k,H)|0,r=r+Math.imul(y,j)|0,o=(o=o+Math.imul(y,$)|0)+Math.imul(b,j)|0,i=i+Math.imul(b,$)|0,r=r+Math.imul(h,Q)|0,o=(o=o+Math.imul(h,X)|0)+Math.imul(f,Q)|0,i=i+Math.imul(f,X)|0;var we=(c+(r=r+Math.imul(d,J)|0)|0)+((8191&(o=(o=o+Math.imul(d,ee)|0)+Math.imul(p,J)|0))<<13)|0;c=((i=i+Math.imul(p,ee)|0)+(o>>>13)|0)+(we>>>26)|0,we&=67108863,r=Math.imul(P,G),o=(o=Math.imul(P,q))+Math.imul(S,G)|0,i=Math.imul(S,q),r=r+Math.imul(v,V)|0,o=(o=o+Math.imul(v,H)|0)+Math.imul(T,V)|0,i=i+Math.imul(T,H)|0,r=r+Math.imul(w,j)|0,o=(o=o+Math.imul(w,$)|0)+Math.imul(k,j)|0,i=i+Math.imul(k,$)|0,r=r+Math.imul(y,Q)|0,o=(o=o+Math.imul(y,X)|0)+Math.imul(b,Q)|0,i=i+Math.imul(b,X)|0,r=r+Math.imul(h,J)|0,o=(o=o+Math.imul(h,ee)|0)+Math.imul(f,J)|0,i=i+Math.imul(f,ee)|0;var ke=(c+(r=r+Math.imul(d,ne)|0)|0)+((8191&(o=(o=o+Math.imul(d,re)|0)+Math.imul(p,ne)|0))<<13)|0;c=((i=i+Math.imul(p,re)|0)+(o>>>13)|0)+(ke>>>26)|0,ke&=67108863,r=Math.imul(C,G),o=(o=Math.imul(C,q))+Math.imul(_,G)|0,i=Math.imul(_,q),r=r+Math.imul(P,V)|0,o=(o=o+Math.imul(P,H)|0)+Math.imul(S,V)|0,i=i+Math.imul(S,H)|0,r=r+Math.imul(v,j)|0,o=(o=o+Math.imul(v,$)|0)+Math.imul(T,j)|0,i=i+Math.imul(T,$)|0,r=r+Math.imul(w,Q)|0,o=(o=o+Math.imul(w,X)|0)+Math.imul(k,Q)|0,i=i+Math.imul(k,X)|0,r=r+Math.imul(y,J)|0,o=(o=o+Math.imul(y,ee)|0)+Math.imul(b,J)|0,i=i+Math.imul(b,ee)|0,r=r+Math.imul(h,ne)|0,o=(o=o+Math.imul(h,re)|0)+Math.imul(f,ne)|0,i=i+Math.imul(f,re)|0;var Ae=(c+(r=r+Math.imul(d,ie)|0)|0)+((8191&(o=(o=o+Math.imul(d,se)|0)+Math.imul(p,ie)|0))<<13)|0;c=((i=i+Math.imul(p,se)|0)+(o>>>13)|0)+(Ae>>>26)|0,Ae&=67108863,r=Math.imul(O,G),o=(o=Math.imul(O,q))+Math.imul(B,G)|0,i=Math.imul(B,q),r=r+Math.imul(C,V)|0,o=(o=o+Math.imul(C,H)|0)+Math.imul(_,V)|0,i=i+Math.imul(_,H)|0,r=r+Math.imul(P,j)|0,o=(o=o+Math.imul(P,$)|0)+Math.imul(S,j)|0,i=i+Math.imul(S,$)|0,r=r+Math.imul(v,Q)|0,o=(o=o+Math.imul(v,X)|0)+Math.imul(T,Q)|0,i=i+Math.imul(T,X)|0,r=r+Math.imul(w,J)|0,o=(o=o+Math.imul(w,ee)|0)+Math.imul(k,J)|0,i=i+Math.imul(k,ee)|0,r=r+Math.imul(y,ne)|0,o=(o=o+Math.imul(y,re)|0)+Math.imul(b,ne)|0,i=i+Math.imul(b,re)|0,r=r+Math.imul(h,ie)|0,o=(o=o+Math.imul(h,se)|0)+Math.imul(f,ie)|0,i=i+Math.imul(f,se)|0;var ve=(c+(r=r+Math.imul(d,ue)|0)|0)+((8191&(o=(o=o+Math.imul(d,ce)|0)+Math.imul(p,ue)|0))<<13)|0;c=((i=i+Math.imul(p,ce)|0)+(o>>>13)|0)+(ve>>>26)|0,ve&=67108863,r=Math.imul(D,G),o=(o=Math.imul(D,q))+Math.imul(R,G)|0,i=Math.imul(R,q),r=r+Math.imul(O,V)|0,o=(o=o+Math.imul(O,H)|0)+Math.imul(B,V)|0,i=i+Math.imul(B,H)|0,r=r+Math.imul(C,j)|0,o=(o=o+Math.imul(C,$)|0)+Math.imul(_,j)|0,i=i+Math.imul(_,$)|0,r=r+Math.imul(P,Q)|0,o=(o=o+Math.imul(P,X)|0)+Math.imul(S,Q)|0,i=i+Math.imul(S,X)|0,r=r+Math.imul(v,J)|0,o=(o=o+Math.imul(v,ee)|0)+Math.imul(T,J)|0,i=i+Math.imul(T,ee)|0,r=r+Math.imul(w,ne)|0,o=(o=o+Math.imul(w,re)|0)+Math.imul(k,ne)|0,i=i+Math.imul(k,re)|0,r=r+Math.imul(y,ie)|0,o=(o=o+Math.imul(y,se)|0)+Math.imul(b,ie)|0,i=i+Math.imul(b,se)|0,r=r+Math.imul(h,ue)|0,o=(o=o+Math.imul(h,ce)|0)+Math.imul(f,ue)|0,i=i+Math.imul(f,ce)|0;var Te=(c+(r=r+Math.imul(d,de)|0)|0)+((8191&(o=(o=o+Math.imul(d,pe)|0)+Math.imul(p,de)|0))<<13)|0;c=((i=i+Math.imul(p,pe)|0)+(o>>>13)|0)+(Te>>>26)|0,Te&=67108863,r=Math.imul(U,G),o=(o=Math.imul(U,q))+Math.imul(N,G)|0,i=Math.imul(N,q),r=r+Math.imul(D,V)|0,o=(o=o+Math.imul(D,H)|0)+Math.imul(R,V)|0,i=i+Math.imul(R,H)|0,r=r+Math.imul(O,j)|0,o=(o=o+Math.imul(O,$)|0)+Math.imul(B,j)|0,i=i+Math.imul(B,$)|0,r=r+Math.imul(C,Q)|0,o=(o=o+Math.imul(C,X)|0)+Math.imul(_,Q)|0,i=i+Math.imul(_,X)|0,r=r+Math.imul(P,J)|0,o=(o=o+Math.imul(P,ee)|0)+Math.imul(S,J)|0,i=i+Math.imul(S,ee)|0,r=r+Math.imul(v,ne)|0,o=(o=o+Math.imul(v,re)|0)+Math.imul(T,ne)|0,i=i+Math.imul(T,re)|0,r=r+Math.imul(w,ie)|0,o=(o=o+Math.imul(w,se)|0)+Math.imul(k,ie)|0,i=i+Math.imul(k,se)|0,r=r+Math.imul(y,ue)|0,o=(o=o+Math.imul(y,ce)|0)+Math.imul(b,ue)|0,i=i+Math.imul(b,ce)|0,r=r+Math.imul(h,de)|0,o=(o=o+Math.imul(h,pe)|0)+Math.imul(f,de)|0,i=i+Math.imul(f,pe)|0;var Me=(c+(r=r+Math.imul(d,he)|0)|0)+((8191&(o=(o=o+Math.imul(d,fe)|0)+Math.imul(p,he)|0))<<13)|0;c=((i=i+Math.imul(p,fe)|0)+(o>>>13)|0)+(Me>>>26)|0,Me&=67108863,r=Math.imul(U,V),o=(o=Math.imul(U,H))+Math.imul(N,V)|0,i=Math.imul(N,H),r=r+Math.imul(D,j)|0,o=(o=o+Math.imul(D,$)|0)+Math.imul(R,j)|0,i=i+Math.imul(R,$)|0,r=r+Math.imul(O,Q)|0,o=(o=o+Math.imul(O,X)|0)+Math.imul(B,Q)|0,i=i+Math.imul(B,X)|0,r=r+Math.imul(C,J)|0,o=(o=o+Math.imul(C,ee)|0)+Math.imul(_,J)|0,i=i+Math.imul(_,ee)|0,r=r+Math.imul(P,ne)|0,o=(o=o+Math.imul(P,re)|0)+Math.imul(S,ne)|0,i=i+Math.imul(S,re)|0,r=r+Math.imul(v,ie)|0,o=(o=o+Math.imul(v,se)|0)+Math.imul(T,ie)|0,i=i+Math.imul(T,se)|0,r=r+Math.imul(w,ue)|0,o=(o=o+Math.imul(w,ce)|0)+Math.imul(k,ue)|0,i=i+Math.imul(k,ce)|0,r=r+Math.imul(y,de)|0,o=(o=o+Math.imul(y,pe)|0)+Math.imul(b,de)|0,i=i+Math.imul(b,pe)|0;var Pe=(c+(r=r+Math.imul(h,he)|0)|0)+((8191&(o=(o=o+Math.imul(h,fe)|0)+Math.imul(f,he)|0))<<13)|0;c=((i=i+Math.imul(f,fe)|0)+(o>>>13)|0)+(Pe>>>26)|0,Pe&=67108863,r=Math.imul(U,j),o=(o=Math.imul(U,$))+Math.imul(N,j)|0,i=Math.imul(N,$),r=r+Math.imul(D,Q)|0,o=(o=o+Math.imul(D,X)|0)+Math.imul(R,Q)|0,i=i+Math.imul(R,X)|0,r=r+Math.imul(O,J)|0,o=(o=o+Math.imul(O,ee)|0)+Math.imul(B,J)|0,i=i+Math.imul(B,ee)|0,r=r+Math.imul(C,ne)|0,o=(o=o+Math.imul(C,re)|0)+Math.imul(_,ne)|0,i=i+Math.imul(_,re)|0,r=r+Math.imul(P,ie)|0,o=(o=o+Math.imul(P,se)|0)+Math.imul(S,ie)|0,i=i+Math.imul(S,se)|0,r=r+Math.imul(v,ue)|0,o=(o=o+Math.imul(v,ce)|0)+Math.imul(T,ue)|0,i=i+Math.imul(T,ce)|0,r=r+Math.imul(w,de)|0,o=(o=o+Math.imul(w,pe)|0)+Math.imul(k,de)|0,i=i+Math.imul(k,pe)|0;var Se=(c+(r=r+Math.imul(y,he)|0)|0)+((8191&(o=(o=o+Math.imul(y,fe)|0)+Math.imul(b,he)|0))<<13)|0;c=((i=i+Math.imul(b,fe)|0)+(o>>>13)|0)+(Se>>>26)|0,Se&=67108863,r=Math.imul(U,Q),o=(o=Math.imul(U,X))+Math.imul(N,Q)|0,i=Math.imul(N,X),r=r+Math.imul(D,J)|0,o=(o=o+Math.imul(D,ee)|0)+Math.imul(R,J)|0,i=i+Math.imul(R,ee)|0,r=r+Math.imul(O,ne)|0,o=(o=o+Math.imul(O,re)|0)+Math.imul(B,ne)|0,i=i+Math.imul(B,re)|0,r=r+Math.imul(C,ie)|0,o=(o=o+Math.imul(C,se)|0)+Math.imul(_,ie)|0,i=i+Math.imul(_,se)|0,r=r+Math.imul(P,ue)|0,o=(o=o+Math.imul(P,ce)|0)+Math.imul(S,ue)|0,i=i+Math.imul(S,ce)|0,r=r+Math.imul(v,de)|0,o=(o=o+Math.imul(v,pe)|0)+Math.imul(T,de)|0,i=i+Math.imul(T,pe)|0;var xe=(c+(r=r+Math.imul(w,he)|0)|0)+((8191&(o=(o=o+Math.imul(w,fe)|0)+Math.imul(k,he)|0))<<13)|0;c=((i=i+Math.imul(k,fe)|0)+(o>>>13)|0)+(xe>>>26)|0,xe&=67108863,r=Math.imul(U,J),o=(o=Math.imul(U,ee))+Math.imul(N,J)|0,i=Math.imul(N,ee),r=r+Math.imul(D,ne)|0,o=(o=o+Math.imul(D,re)|0)+Math.imul(R,ne)|0,i=i+Math.imul(R,re)|0,r=r+Math.imul(O,ie)|0,o=(o=o+Math.imul(O,se)|0)+Math.imul(B,ie)|0,i=i+Math.imul(B,se)|0,r=r+Math.imul(C,ue)|0,o=(o=o+Math.imul(C,ce)|0)+Math.imul(_,ue)|0,i=i+Math.imul(_,ce)|0,r=r+Math.imul(P,de)|0,o=(o=o+Math.imul(P,pe)|0)+Math.imul(S,de)|0,i=i+Math.imul(S,pe)|0;var Ce=(c+(r=r+Math.imul(v,he)|0)|0)+((8191&(o=(o=o+Math.imul(v,fe)|0)+Math.imul(T,he)|0))<<13)|0;c=((i=i+Math.imul(T,fe)|0)+(o>>>13)|0)+(Ce>>>26)|0,Ce&=67108863,r=Math.imul(U,ne),o=(o=Math.imul(U,re))+Math.imul(N,ne)|0,i=Math.imul(N,re),r=r+Math.imul(D,ie)|0,o=(o=o+Math.imul(D,se)|0)+Math.imul(R,ie)|0,i=i+Math.imul(R,se)|0,r=r+Math.imul(O,ue)|0,o=(o=o+Math.imul(O,ce)|0)+Math.imul(B,ue)|0,i=i+Math.imul(B,ce)|0,r=r+Math.imul(C,de)|0,o=(o=o+Math.imul(C,pe)|0)+Math.imul(_,de)|0,i=i+Math.imul(_,pe)|0;var _e=(c+(r=r+Math.imul(P,he)|0)|0)+((8191&(o=(o=o+Math.imul(P,fe)|0)+Math.imul(S,he)|0))<<13)|0;c=((i=i+Math.imul(S,fe)|0)+(o>>>13)|0)+(_e>>>26)|0,_e&=67108863,r=Math.imul(U,ie),o=(o=Math.imul(U,se))+Math.imul(N,ie)|0,i=Math.imul(N,se),r=r+Math.imul(D,ue)|0,o=(o=o+Math.imul(D,ce)|0)+Math.imul(R,ue)|0,i=i+Math.imul(R,ce)|0,r=r+Math.imul(O,de)|0,o=(o=o+Math.imul(O,pe)|0)+Math.imul(B,de)|0,i=i+Math.imul(B,pe)|0;var Ee=(c+(r=r+Math.imul(C,he)|0)|0)+((8191&(o=(o=o+Math.imul(C,fe)|0)+Math.imul(_,he)|0))<<13)|0;c=((i=i+Math.imul(_,fe)|0)+(o>>>13)|0)+(Ee>>>26)|0,Ee&=67108863,r=Math.imul(U,ue),o=(o=Math.imul(U,ce))+Math.imul(N,ue)|0,i=Math.imul(N,ce),r=r+Math.imul(D,de)|0,o=(o=o+Math.imul(D,pe)|0)+Math.imul(R,de)|0,i=i+Math.imul(R,pe)|0;var Oe=(c+(r=r+Math.imul(O,he)|0)|0)+((8191&(o=(o=o+Math.imul(O,fe)|0)+Math.imul(B,he)|0))<<13)|0;c=((i=i+Math.imul(B,fe)|0)+(o>>>13)|0)+(Oe>>>26)|0,Oe&=67108863,r=Math.imul(U,de),o=(o=Math.imul(U,pe))+Math.imul(N,de)|0,i=Math.imul(N,pe);var Be=(c+(r=r+Math.imul(D,he)|0)|0)+((8191&(o=(o=o+Math.imul(D,fe)|0)+Math.imul(R,he)|0))<<13)|0;c=((i=i+Math.imul(R,fe)|0)+(o>>>13)|0)+(Be>>>26)|0,Be&=67108863;var Le=(c+(r=Math.imul(U,he))|0)+((8191&(o=(o=Math.imul(U,fe))+Math.imul(N,he)|0))<<13)|0;return c=((i=Math.imul(N,fe))+(o>>>13)|0)+(Le>>>26)|0,Le&=67108863,u[0]=ge,u[1]=ye,u[2]=be,u[3]=Ie,u[4]=we,u[5]=ke,u[6]=Ae,u[7]=ve,u[8]=Te,u[9]=Me,u[10]=Pe,u[11]=Se,u[12]=xe,u[13]=Ce,u[14]=_e,u[15]=Ee,u[16]=Oe,u[17]=Be,u[18]=Le,0!==c&&(u[19]=c,n.length++),n};function g(e,t,n){n.negative=t.negative^e.negative,n.length=e.length+t.length;for(var r=0,o=0,i=0;i<n.length-1;i++){var s=o;o=0;for(var a=67108863&r,u=Math.min(i,t.length-1),c=Math.max(0,i-e.length+1);c<=u;c++){var l=i-c,d=(0|e.words[l])*(0|t.words[c]),p=67108863&d;a=67108863&(p=p+a|0),o+=(s=(s=s+(d/67108864|0)|0)+(p>>>26)|0)>>>26,s&=67108863}n.words[i]=a,r=s,s=o}return 0!==r?n.words[i]=r:n.length--,n._strip()}function y(e,t,n){return g(e,t,n)}Math.imul||(f=h),o.prototype.mulTo=function(e,t){var n=this.length+e.length;return 10===this.length&&10===e.length?f(this,e,t):n<63?h(this,e,t):n<1024?g(this,e,t):y(this,e,t)},o.prototype.mul=function(e){var t=new o(null);return t.words=new Array(this.length+e.length),this.mulTo(e,t)},o.prototype.mulf=function(e){var t=new o(null);return t.words=new Array(this.length+e.length),y(this,e,t)},o.prototype.imul=function(e){return this.clone().mulTo(e,this)},o.prototype.imuln=function(e){var t=e<0;t&&(e=-e),n("number"==typeof e),n(e<67108864);for(var r=0,o=0;o<this.length;o++){var i=(0|this.words[o])*e,s=(67108863&i)+(67108863&r);r>>=26,r+=i/67108864|0,r+=s>>>26,this.words[o]=67108863&s}return 0!==r&&(this.words[o]=r,this.length++),t?this.ineg():this},o.prototype.muln=function(e){return this.clone().imuln(e)},o.prototype.sqr=function(){return this.mul(this)},o.prototype.isqr=function(){return this.imul(this.clone())},o.prototype.pow=function(e){var t=function(e){for(var t=new Array(e.bitLength()),n=0;n<t.length;n++){var r=n/26|0,o=n%26;t[n]=e.words[r]>>>o&1}return t}(e);if(0===t.length)return new o(1);for(var n=this,r=0;r<t.length&&0===t[r];r++,n=n.sqr());if(++r<t.length)for(var i=n.sqr();r<t.length;r++,i=i.sqr())0!==t[r]&&(n=n.mul(i));return n},o.prototype.iushln=function(e){n("number"==typeof e&&e>=0);var t,r=e%26,o=(e-r)/26,i=67108863>>>26-r<<26-r;if(0!==r){var s=0;for(t=0;t<this.length;t++){var a=this.words[t]&i,u=(0|this.words[t])-a<<r;this.words[t]=u|s,s=a>>>26-r}s&&(this.words[t]=s,this.length++)}if(0!==o){for(t=this.length-1;t>=0;t--)this.words[t+o]=this.words[t];for(t=0;t<o;t++)this.words[t]=0;this.length+=o}return this._strip()},o.prototype.ishln=function(e){return n(0===this.negative),this.iushln(e)},o.prototype.iushrn=function(e,t,r){var o;n("number"==typeof e&&e>=0),o=t?(t-t%26)/26:0;var i=e%26,s=Math.min((e-i)/26,this.length),a=67108863^67108863>>>i<<i,u=r;if(o-=s,o=Math.max(0,o),u){for(var c=0;c<s;c++)u.words[c]=this.words[c];u.length=s}if(0===s);else if(this.length>s)for(this.length-=s,c=0;c<this.length;c++)this.words[c]=this.words[c+s];else this.words[0]=0,this.length=1;var l=0;for(c=this.length-1;c>=0&&(0!==l||c>=o);c--){var d=0|this.words[c];this.words[c]=l<<26-i|d>>>i,l=d&a}return u&&0!==l&&(u.words[u.length++]=l),0===this.length&&(this.words[0]=0,this.length=1),this._strip()},o.prototype.ishrn=function(e,t,r){return n(0===this.negative),this.iushrn(e,t,r)},o.prototype.shln=function(e){return this.clone().ishln(e)},o.prototype.ushln=function(e){return this.clone().iushln(e)},o.prototype.shrn=function(e){return this.clone().ishrn(e)},o.prototype.ushrn=function(e){return this.clone().iushrn(e)},o.prototype.testn=function(e){n("number"==typeof e&&e>=0);var t=e%26,r=(e-t)/26,o=1<<t;return this.length<=r?0:!!(this.words[r]&o)},o.prototype.imaskn=function(e){n("number"==typeof e&&e>=0);var t=e%26,r=(e-t)/26;if(n(0===this.negative,"imaskn works only with positive numbers"),this.length<=r)return this;if(0!==t&&r++,this.length=Math.min(r,this.length),0!==t){var o=67108863^67108863>>>t<<t;this.words[this.length-1]&=o}return this._strip()},o.prototype.maskn=function(e){return this.clone().imaskn(e)},o.prototype.iaddn=function(e){return n("number"==typeof e),n(e<67108864),e<0?this.isubn(-e):0!==this.negative?1===this.length&&(0|this.words[0])<=e?(this.words[0]=e-(0|this.words[0]),this.negative=0,this):(this.negative=0,this.isubn(e),this.negative=1,this):this._iaddn(e)},o.prototype._iaddn=function(e){this.words[0]+=e;for(var t=0;t<this.length&&this.words[t]>=67108864;t++)this.words[t]-=67108864,t===this.length-1?this.words[t+1]=1:this.words[t+1]++;return this.length=Math.max(this.length,t+1),this},o.prototype.isubn=function(e){if(n("number"==typeof e),n(e<67108864),e<0)return this.iaddn(-e);if(0!==this.negative)return this.negative=0,this.iaddn(e),this.negative=1,this;if(this.words[0]-=e,1===this.length&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var t=0;t<this.length&&this.words[t]<0;t++)this.words[t]+=67108864,this.words[t+1]-=1;return this._strip()},o.prototype.addn=function(e){return this.clone().iaddn(e)},o.prototype.subn=function(e){return this.clone().isubn(e)},o.prototype.iabs=function(){return this.negative=0,this},o.prototype.abs=function(){return this.clone().iabs()},o.prototype._ishlnsubmul=function(e,t,r){var o,i,s=e.length+r;this._expand(s);var a=0;for(o=0;o<e.length;o++){i=(0|this.words[o+r])+a;var u=(0|e.words[o])*t;a=((i-=67108863&u)>>26)-(u/67108864|0),this.words[o+r]=67108863&i}for(;o<this.length-r;o++)a=(i=(0|this.words[o+r])+a)>>26,this.words[o+r]=67108863&i;if(0===a)return this._strip();for(n(-1===a),a=0,o=0;o<this.length;o++)a=(i=-(0|this.words[o])+a)>>26,this.words[o]=67108863&i;return this.negative=1,this._strip()},o.prototype._wordDiv=function(e,t){var n=(this.length,e.length),r=this.clone(),i=e,s=0|i.words[i.length-1];0!=(n=26-this._countBits(s))&&(i=i.ushln(n),r.iushln(n),s=0|i.words[i.length-1]);var a,u=r.length-i.length;if("mod"!==t){(a=new o(null)).length=u+1,a.words=new Array(a.length);for(var c=0;c<a.length;c++)a.words[c]=0}var l=r.clone()._ishlnsubmul(i,1,u);0===l.negative&&(r=l,a&&(a.words[u]=1));for(var d=u-1;d>=0;d--){var p=67108864*(0|r.words[i.length+d])+(0|r.words[i.length+d-1]);for(p=Math.min(p/s|0,67108863),r._ishlnsubmul(i,p,d);0!==r.negative;)p--,r.negative=0,r._ishlnsubmul(i,1,d),r.isZero()||(r.negative^=1);a&&(a.words[d]=p)}return a&&a._strip(),r._strip(),"div"!==t&&0!==n&&r.iushrn(n),{div:a||null,mod:r}},o.prototype.divmod=function(e,t,r){return n(!e.isZero()),this.isZero()?{div:new o(0),mod:new o(0)}:0!==this.negative&&0===e.negative?(a=this.neg().divmod(e,t),"mod"!==t&&(i=a.div.neg()),"div"!==t&&(s=a.mod.neg(),r&&0!==s.negative&&s.iadd(e)),{div:i,mod:s}):0===this.negative&&0!==e.negative?(a=this.divmod(e.neg(),t),"mod"!==t&&(i=a.div.neg()),{div:i,mod:a.mod}):0!=(this.negative&e.negative)?(a=this.neg().divmod(e.neg(),t),"div"!==t&&(s=a.mod.neg(),r&&0!==s.negative&&s.isub(e)),{div:a.div,mod:s}):e.length>this.length||this.cmp(e)<0?{div:new o(0),mod:this}:1===e.length?"div"===t?{div:this.divn(e.words[0]),mod:null}:"mod"===t?{div:null,mod:new o(this.modrn(e.words[0]))}:{div:this.divn(e.words[0]),mod:new o(this.modrn(e.words[0]))}:this._wordDiv(e,t);var i,s,a},o.prototype.div=function(e){return this.divmod(e,"div",0).div},o.prototype.mod=function(e){return this.divmod(e,"mod",0).mod},o.prototype.umod=function(e){return this.divmod(e,"mod",1).mod},o.prototype.divRound=function(e){var t=this.divmod(e);if(t.mod.isZero())return t.div;var n=0!==t.div.negative?t.mod.isub(e):t.mod,r=e.ushrn(1),o=e.andln(1),i=n.cmp(r);return i<0||1===o&&0===i?t.div:0!==t.div.negative?t.div.isubn(1):t.div.iaddn(1)},o.prototype.modrn=function(e){var t=e<0;t&&(e=-e),n(e<=67108863);for(var r=(1<<26)%e,o=0,i=this.length-1;i>=0;i--)o=(r*o+(0|this.words[i]))%e;return t?-o:o},o.prototype.modn=function(e){return this.modrn(e)},o.prototype.idivn=function(e){var t=e<0;t&&(e=-e),n(e<=67108863);for(var r=0,o=this.length-1;o>=0;o--){var i=(0|this.words[o])+67108864*r;this.words[o]=i/e|0,r=i%e}return this._strip(),t?this.ineg():this},o.prototype.divn=function(e){return this.clone().idivn(e)},o.prototype.egcd=function(e){n(0===e.negative),n(!e.isZero());var t=this,r=e.clone();t=0!==t.negative?t.umod(e):t.clone();for(var i=new o(1),s=new o(0),a=new o(0),u=new o(1),c=0;t.isEven()&&r.isEven();)t.iushrn(1),r.iushrn(1),++c;for(var l=r.clone(),d=t.clone();!t.isZero();){for(var p=0,m=1;0==(t.words[0]&m)&&p<26;++p,m<<=1);if(p>0)for(t.iushrn(p);p-- >0;)(i.isOdd()||s.isOdd())&&(i.iadd(l),s.isub(d)),i.iushrn(1),s.iushrn(1);for(var h=0,f=1;0==(r.words[0]&f)&&h<26;++h,f<<=1);if(h>0)for(r.iushrn(h);h-- >0;)(a.isOdd()||u.isOdd())&&(a.iadd(l),u.isub(d)),a.iushrn(1),u.iushrn(1);t.cmp(r)>=0?(t.isub(r),i.isub(a),s.isub(u)):(r.isub(t),a.isub(i),u.isub(s))}return{a:a,b:u,gcd:r.iushln(c)}},o.prototype._invmp=function(e){n(0===e.negative),n(!e.isZero());var t=this,r=e.clone();t=0!==t.negative?t.umod(e):t.clone();for(var i,s=new o(1),a=new o(0),u=r.clone();t.cmpn(1)>0&&r.cmpn(1)>0;){for(var c=0,l=1;0==(t.words[0]&l)&&c<26;++c,l<<=1);if(c>0)for(t.iushrn(c);c-- >0;)s.isOdd()&&s.iadd(u),s.iushrn(1);for(var d=0,p=1;0==(r.words[0]&p)&&d<26;++d,p<<=1);if(d>0)for(r.iushrn(d);d-- >0;)a.isOdd()&&a.iadd(u),a.iushrn(1);t.cmp(r)>=0?(t.isub(r),s.isub(a)):(r.isub(t),a.isub(s))}return(i=0===t.cmpn(1)?s:a).cmpn(0)<0&&i.iadd(e),i},o.prototype.gcd=function(e){if(this.isZero())return e.abs();if(e.isZero())return this.abs();var t=this.clone(),n=e.clone();t.negative=0,n.negative=0;for(var r=0;t.isEven()&&n.isEven();r++)t.iushrn(1),n.iushrn(1);for(;;){for(;t.isEven();)t.iushrn(1);for(;n.isEven();)n.iushrn(1);var o=t.cmp(n);if(o<0){var i=t;t=n,n=i}else if(0===o||0===n.cmpn(1))break;t.isub(n)}return n.iushln(r)},o.prototype.invm=function(e){return this.egcd(e).a.umod(e)},o.prototype.isEven=function(){return 0==(1&this.words[0])},o.prototype.isOdd=function(){return 1==(1&this.words[0])},o.prototype.andln=function(e){return this.words[0]&e},o.prototype.bincn=function(e){n("number"==typeof e);var t=e%26,r=(e-t)/26,o=1<<t;if(this.length<=r)return this._expand(r+1),this.words[r]|=o,this;for(var i=o,s=r;0!==i&&s<this.length;s++){var a=0|this.words[s];i=(a+=i)>>>26,a&=67108863,this.words[s]=a}return 0!==i&&(this.words[s]=i,this.length++),this},o.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},o.prototype.cmpn=function(e){var t,r=e<0;if(0!==this.negative&&!r)return-1;if(0===this.negative&&r)return 1;if(this._strip(),this.length>1)t=1;else{r&&(e=-e),n(e<=67108863,"Number is too big");var o=0|this.words[0];t=o===e?0:o<e?-1:1}return 0!==this.negative?0|-t:t},o.prototype.cmp=function(e){if(0!==this.negative&&0===e.negative)return-1;if(0===this.negative&&0!==e.negative)return 1;var t=this.ucmp(e);return 0!==this.negative?0|-t:t},o.prototype.ucmp=function(e){if(this.length>e.length)return 1;if(this.length<e.length)return-1;for(var t=0,n=this.length-1;n>=0;n--){var r=0|this.words[n],o=0|e.words[n];if(r!==o){r<o?t=-1:r>o&&(t=1);break}}return t},o.prototype.gtn=function(e){return 1===this.cmpn(e)},o.prototype.gt=function(e){return 1===this.cmp(e)},o.prototype.gten=function(e){return this.cmpn(e)>=0},o.prototype.gte=function(e){return this.cmp(e)>=0},o.prototype.ltn=function(e){return-1===this.cmpn(e)},o.prototype.lt=function(e){return-1===this.cmp(e)},o.prototype.lten=function(e){return this.cmpn(e)<=0},o.prototype.lte=function(e){return this.cmp(e)<=0},o.prototype.eqn=function(e){return 0===this.cmpn(e)},o.prototype.eq=function(e){return 0===this.cmp(e)},o.red=function(e){return new T(e)},o.prototype.toRed=function(e){return n(!this.red,"Already a number in reduction context"),n(0===this.negative,"red works only with positives"),e.convertTo(this)._forceRed(e)},o.prototype.fromRed=function(){return n(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},o.prototype._forceRed=function(e){return this.red=e,this},o.prototype.forceRed=function(e){return n(!this.red,"Already a number in reduction context"),this._forceRed(e)},o.prototype.redAdd=function(e){return n(this.red,"redAdd works only with red numbers"),this.red.add(this,e)},o.prototype.redIAdd=function(e){return n(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,e)},o.prototype.redSub=function(e){return n(this.red,"redSub works only with red numbers"),this.red.sub(this,e)},o.prototype.redISub=function(e){return n(this.red,"redISub works only with red numbers"),this.red.isub(this,e)},o.prototype.redShl=function(e){return n(this.red,"redShl works only with red numbers"),this.red.shl(this,e)},o.prototype.redMul=function(e){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,e),this.red.mul(this,e)},o.prototype.redIMul=function(e){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,e),this.red.imul(this,e)},o.prototype.redSqr=function(){return n(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},o.prototype.redISqr=function(){return n(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},o.prototype.redSqrt=function(){return n(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},o.prototype.redInvm=function(){return n(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},o.prototype.redNeg=function(){return n(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},o.prototype.redPow=function(e){return n(this.red&&!e.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,e)};var b={k256:null,p224:null,p192:null,p25519:null};function I(e,t){this.name=e,this.p=new o(t,16),this.n=this.p.bitLength(),this.k=new o(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function w(){I.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function k(){I.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function A(){I.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function v(){I.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function T(e){if("string"==typeof e){var t=o._prime(e);this.m=t.p,this.prime=t}else n(e.gtn(1),"modulus must be greater than 1"),this.m=e,this.prime=null}function M(e){T.call(this,e),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new o(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}I.prototype._tmp=function(){var e=new o(null);return e.words=new Array(Math.ceil(this.n/13)),e},I.prototype.ireduce=function(e){var t,n=e;do{this.split(n,this.tmp),t=(n=(n=this.imulK(n)).iadd(this.tmp)).bitLength()}while(t>this.n);var r=t<this.n?-1:n.ucmp(this.p);return 0===r?(n.words[0]=0,n.length=1):r>0?n.isub(this.p):void 0!==n.strip?n.strip():n._strip(),n},I.prototype.split=function(e,t){e.iushrn(this.n,0,t)},I.prototype.imulK=function(e){return e.imul(this.k)},r(w,I),w.prototype.split=function(e,t){for(var n=4194303,r=Math.min(e.length,9),o=0;o<r;o++)t.words[o]=e.words[o];if(t.length=r,e.length<=9)return e.words[0]=0,void(e.length=1);var i=e.words[9];for(t.words[t.length++]=i&n,o=10;o<e.length;o++){var s=0|e.words[o];e.words[o-10]=(s&n)<<4|i>>>22,i=s}i>>>=22,e.words[o-10]=i,0===i&&e.length>10?e.length-=10:e.length-=9},w.prototype.imulK=function(e){e.words[e.length]=0,e.words[e.length+1]=0,e.length+=2;for(var t=0,n=0;n<e.length;n++){var r=0|e.words[n];t+=977*r,e.words[n]=67108863&t,t=64*r+(t/67108864|0)}return 0===e.words[e.length-1]&&(e.length--,0===e.words[e.length-1]&&e.length--),e},r(k,I),r(A,I),r(v,I),v.prototype.imulK=function(e){for(var t=0,n=0;n<e.length;n++){var r=19*(0|e.words[n])+t,o=67108863&r;r>>>=26,e.words[n]=o,t=r}return 0!==t&&(e.words[e.length++]=t),e},o._prime=function(e){if(b[e])return b[e];var t;if("k256"===e)t=new w;else if("p224"===e)t=new k;else if("p192"===e)t=new A;else{if("p25519"!==e)throw new Error("Unknown prime "+e);t=new v}return b[e]=t,t},T.prototype._verify1=function(e){n(0===e.negative,"red works only with positives"),n(e.red,"red works only with red numbers")},T.prototype._verify2=function(e,t){n(0==(e.negative|t.negative),"red works only with positives"),n(e.red&&e.red===t.red,"red works only with red numbers")},T.prototype.imod=function(e){return this.prime?this.prime.ireduce(e)._forceRed(this):(c(e,e.umod(this.m)._forceRed(this)),e)},T.prototype.neg=function(e){return e.isZero()?e.clone():this.m.sub(e)._forceRed(this)},T.prototype.add=function(e,t){this._verify2(e,t);var n=e.add(t);return n.cmp(this.m)>=0&&n.isub(this.m),n._forceRed(this)},T.prototype.iadd=function(e,t){this._verify2(e,t);var n=e.iadd(t);return n.cmp(this.m)>=0&&n.isub(this.m),n},T.prototype.sub=function(e,t){this._verify2(e,t);var n=e.sub(t);return n.cmpn(0)<0&&n.iadd(this.m),n._forceRed(this)},T.prototype.isub=function(e,t){this._verify2(e,t);var n=e.isub(t);return n.cmpn(0)<0&&n.iadd(this.m),n},T.prototype.shl=function(e,t){return this._verify1(e),this.imod(e.ushln(t))},T.prototype.imul=function(e,t){return this._verify2(e,t),this.imod(e.imul(t))},T.prototype.mul=function(e,t){return this._verify2(e,t),this.imod(e.mul(t))},T.prototype.isqr=function(e){return this.imul(e,e.clone())},T.prototype.sqr=function(e){return this.mul(e,e)},T.prototype.sqrt=function(e){if(e.isZero())return e.clone();var t=this.m.andln(3);if(n(t%2==1),3===t){var r=this.m.add(new o(1)).iushrn(2);return this.pow(e,r)}for(var i=this.m.subn(1),s=0;!i.isZero()&&0===i.andln(1);)s++,i.iushrn(1);n(!i.isZero());var a=new o(1).toRed(this),u=a.redNeg(),c=this.m.subn(1).iushrn(1),l=this.m.bitLength();for(l=new o(2*l*l).toRed(this);0!==this.pow(l,c).cmp(u);)l.redIAdd(u);for(var d=this.pow(l,i),p=this.pow(e,i.addn(1).iushrn(1)),m=this.pow(e,i),h=s;0!==m.cmp(a);){for(var f=m,g=0;0!==f.cmp(a);g++)f=f.redSqr();n(g<h);var y=this.pow(d,new o(1).iushln(h-g-1));p=p.redMul(y),d=y.redSqr(),m=m.redMul(d),h=g}return p},T.prototype.invm=function(e){var t=e._invmp(this.m);return 0!==t.negative?(t.negative=0,this.imod(t).redNeg()):this.imod(t)},T.prototype.pow=function(e,t){if(t.isZero())return new o(1).toRed(this);if(0===t.cmpn(1))return e.clone();var n=new Array(16);n[0]=new o(1).toRed(this),n[1]=e;for(var r=2;r<n.length;r++)n[r]=this.mul(n[r-1],e);var i=n[0],s=0,a=0,u=t.bitLength()%26;for(0===u&&(u=26),r=t.length-1;r>=0;r--){for(var c=t.words[r],l=u-1;l>=0;l--){var d=c>>l&1;i!==n[0]&&(i=this.sqr(i)),0!==d||0!==s?(s<<=1,s|=d,(4==++a||0===r&&0===l)&&(i=this.mul(i,n[s]),a=0,s=0)):a=0}u=26}return i},T.prototype.convertTo=function(e){var t=e.umod(this.m);return t===e?t.clone():t},T.prototype.convertFrom=function(e){var t=e.clone();return t.red=null,t},o.mont=function(e){return new M(e)},r(M,T),M.prototype.convertTo=function(e){return this.imod(e.ushln(this.shift))},M.prototype.convertFrom=function(e){var t=this.imod(e.mul(this.rinv));return t.red=null,t},M.prototype.imul=function(e,t){if(e.isZero()||t.isZero())return e.words[0]=0,e.length=1,e;var n=e.imul(t),r=n.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),o=n.isub(r).iushrn(this.shift),i=o;return o.cmp(this.m)>=0?i=o.isub(this.m):o.cmpn(0)<0&&(i=o.iadd(this.m)),i._forceRed(this)},M.prototype.mul=function(e,t){if(e.isZero()||t.isZero())return new o(0)._forceRed(this);var n=e.mul(t),r=n.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),i=n.isub(r).iushrn(this.shift),s=i;return i.cmp(this.m)>=0?s=i.isub(this.m):i.cmpn(0)<0&&(s=i.iadd(this.m)),s._forceRed(this)},M.prototype.invm=function(e){return this.imod(e._invmp(this.m).mul(this.r2))._forceRed(this)}}(0,It);var Tt=wt(At.exports);const Mt="fetchByOwner is required",Pt="No light-token balance to unwrap",St="Mint does not have MerkleContext",xt={Spl:"spl",Token2022:"token2022",SplCold:"spl-cold",Token2022Cold:"token2022-cold",LightTokenHot:"light-token-hot",LightTokenCold:"light-token-cold"},Ct=new Set([xt.LightTokenCold,xt.SplCold,xt.Token2022Cold]);function _t(e){return Ct.has(e)}function Et(e,t){t.length>0&&function(e,t){throw new Error(`${e}: ${function(e){return e instanceof Error?e.message:String(e)}(t)}`)}(e,t[0])}function Ot(e,t){if(e._anyFrozen)throw new Error(`Account is frozen. One or more sources (hot or cold) are frozen; ${t} is not allowed.`)}const Bt={0:0,1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0,10:0,11:0,12:0,13:0,14:0,15:0,16:0,17:0,18:0,19:void 0,20:0,21:0,22:0,23:0,24:0,25:0,26:0,27:0,28:0,29:8,30:1,31:17,32:void 0},Lt=31;function Dt(e,t){let o=BigInt(0);const i=function(e){if(!e||e.length<5)return null;try{let t=0;const n=e.readUInt32LE(t);t+=4;for(let r=0;r<n;r++){if(t>=e.length)return null;const n=e[t];if(t+=1,n===Lt)return t+8>e.length?null:BigInt(e.readUInt32LE(t))|BigInt(e.readUInt32LE(t+4))<<BigInt(32);const r=Bt[n];if(void 0===r)return null;t+=r}}catch(e){return null}return null}(t.tlv);return null!==i?o=i:t.delegate&&(o=BigInt(t.amount.toString())),{address:e,mint:t.mint,owner:t.owner,amount:BigInt(t.amount.toString()),delegate:t.delegate,delegatedAmount:o,isInitialized:t.state!==n.AccountState.Uninitialized,isFrozen:t.state===n.AccountState.Frozen,isNative:0,rentExemptReserve:null,closeAuthority:null,tlvData:t.tlv?r.Buffer.from(t.tlv):r.Buffer.alloc(0)}}function Rt(e){const t=r.Buffer.from(e.data.discriminator),n=r.Buffer.from(e.data.data),o=r.Buffer.concat([t,n]);return{executable:0,owner:e.owner,lamports:e.lamports.toNumber(),data:o,rentEpoch:void 0}}function Kt(e,r){return{accountInfo:r,loadContext:void 0,parsed:n.unpackAccount(e,r,t.LIGHT_TOKEN_PROGRAM_ID),isCold:0}}function Ut(t,n){const r=function(t){if(!t||0===t.length)return null;try{let n=0;const r=new e.PublicKey(t.slice(n,n+32));n+=32;const o=new e.PublicKey(t.slice(n,n+32));n+=32;const i=new Tt(t.slice(n,n+8),"le");n+=8;const s=t[n];n+=1;const a=s?new e.PublicKey(t.slice(n,n+32)):null;n+=32;const u=t[n];n+=1;const c=t[n];return n+=1,{mint:r,owner:o,amount:i,delegate:a,state:u,tlv:c?t.slice(n):null}}catch(e){return console.error("Token data parsing error:",e),null}}(n.data.data);if(!r)throw new Error("Invalid token data");return{accountInfo:Rt(n),loadContext:{treeInfo:n.treeInfo,hash:n.hash,leafIndex:n.leafIndex,proveByIndex:n.proveByIndex},parsed:Dt(t,r),isCold:1}}async function Nt(e,n,r,o){return t.assertBetaEnabled(),Gt(e,n,r,o,void 0)}async function Wt(e,n,r,o,i,s,a=0,u=0){t.assertBetaEnabled();const c=ht(n,o,r,s,u);if(a&&"light-token"!==c.type)throw new Error(`For wrap=true, ata must be the light-token ATA. Got ${c.type} ATA instead.`);const l=await Gt(e,n,i,s,{owner:r,mint:o},a);return l._isAta=1,l._owner=r,l._mint=o,l}async function Gt(e,r,o,i,s,a=0){if(!r&&!s)throw new Error("One of address or fetchByOwner is required");if(!i)return async function(e,r,o,i,s){const a=null!=r?r:n.getAssociatedTokenAddressSync(i.mint,i.owner,0,t.LIGHT_TOKEN_PROGRAM_ID,mt(t.LIGHT_TOKEN_PROGRAM_ID)),u=[],c=[],l=[];if(u.push(async function(e,r,o){const i=await e.getAccountInfo(r,o);if(!i)return null;if(!i.owner.equals(t.LIGHT_TOKEN_PROGRAM_ID))throw new n.TokenInvalidAccountOwnerError;return Kt(r,i)}(e,a,o)),c.push(xt.LightTokenHot),l.push(a),s){if(!i)throw new Error("fetchByOwner is required for wrap=true to derive SPL/T22 addresses");const t=n.getAssociatedTokenAddressSync(i.mint,i.owner,0,n.TOKEN_PROGRAM_ID,mt(n.TOKEN_PROGRAM_ID)),r=n.getAssociatedTokenAddressSync(i.mint,i.owner,0,n.TOKEN_2022_PROGRAM_ID,mt(n.TOKEN_2022_PROGRAM_ID));u.push(async function(e,t,r){const o=await e.getAccountInfo(t,r);if(!o)return null;if(!o.owner.equals(n.TOKEN_PROGRAM_ID))throw new n.TokenInvalidAccountOwnerError;return{accountInfo:o,parsed:n.unpackAccount(t,o,n.TOKEN_PROGRAM_ID),isCold:0,loadContext:void 0}}(e,t,o)),c.push(xt.Spl),l.push(t),u.push(async function(e,t,r){const o=await e.getAccountInfo(t,r);if(!o)return null;if(!o.owner.equals(n.TOKEN_2022_PROGRAM_ID))throw new n.TokenInvalidAccountOwnerError;return{accountInfo:o,parsed:n.unpackAccount(t,o,n.TOKEN_2022_PROGRAM_ID),isCold:0,loadContext:void 0}}(e,r,o)),c.push(xt.Token2022),l.push(r)}const d=i?e.getCompressedTokenAccountsByOwner(i.owner,{mint:i.mint}):e.getCompressedTokenAccountsByOwner(r),p=await Promise.allSettled(u),m=[],h=[];let f=null;try{f=await d}catch(e){h.push(e)}const g=[];for(let e=0;e<p.length;e++){const t=p[e];if("fulfilled"===t.status){const n=t.value;if(!n)continue;g.push({type:c[e],address:l[e],amount:n.parsed.amount,accountInfo:n.accountInfo,loadContext:n.loadContext,parsed:n.parsed})}else t.reason instanceof n.TokenInvalidAccountOwnerError?m.push(t.reason):h.push(t.reason)}if(f)for(const e of f.items){const n=e.compressedAccount;if(n&&n.data&&n.data.data.length>0&&n.owner.equals(t.LIGHT_TOKEN_PROGRAM_ID)){const e=Ut(a,n);g.push({type:xt.LightTokenCold,address:a,amount:e.parsed.amount,accountInfo:e.accountInfo,loadContext:e.loadContext,parsed:e.parsed})}}if(Et("Failed to fetch token account data from RPC",h),0===g.length){if(m.length>0)throw m[0];throw new n.TokenAccountNotFoundError}const y=[xt.LightTokenHot,xt.LightTokenCold,xt.Spl,xt.Token2022];return g.sort(((e,t)=>y.indexOf(e.type)-y.indexOf(t.type))),qt(g,a)}(e,r,o,s,a);if(i.equals(t.LIGHT_TOKEN_PROGRAM_ID))return async function(e,r,o,i){if(!r){if(!i)throw new Error(Mt);r=n.getAssociatedTokenAddressSync(i.mint,i.owner,0,t.LIGHT_TOKEN_PROGRAM_ID,mt(t.LIGHT_TOKEN_PROGRAM_ID))}const[s,a]=await Promise.allSettled([e.getAccountInfo(r,o),i?e.getCompressedTokenAccountsByOwner(i.owner,{mint:i.mint}):e.getCompressedTokenAccountsByOwner(r)]),u=[],c=[],l="fulfilled"===s.status?s.value:null;"rejected"===s.status&&u.push(s.reason);const d="fulfilled"===a.status?a.value.items.map((e=>e.compressedAccount)):[];"rejected"===a.status&&u.push(a.reason);const p=[];if(l)if(l.owner.equals(t.LIGHT_TOKEN_PROGRAM_ID)){const e=Kt(r,l);p.push({type:xt.LightTokenHot,address:r,amount:e.parsed.amount,accountInfo:l,parsed:e.parsed})}else c.push(new n.TokenInvalidAccountOwnerError);for(const e of d)if(e&&e.data&&e.data.data.length>0&&e.owner.equals(t.LIGHT_TOKEN_PROGRAM_ID)){const t=Ut(r,e);p.push({type:xt.LightTokenCold,address:r,amount:t.parsed.amount,accountInfo:t.accountInfo,loadContext:t.loadContext,parsed:t.parsed})}if(Et("Failed to fetch token account data from RPC",u),0===p.length){if(c.length>0)throw c[0];throw new n.TokenAccountNotFoundError}return p.sort(((e,t)=>"light-token-hot"===e.type&&"light-token-cold"===t.type?-1:"light-token-cold"===e.type&&"light-token-hot"===t.type?1:0)),qt(p,r)}(e,r,o,s);if(i.equals(n.TOKEN_PROGRAM_ID)||i.equals(n.TOKEN_2022_PROGRAM_ID))return async function(e,r,o,i,s){if(!r){if(!s)throw new Error(Mt);r=n.getAssociatedTokenAddressSync(s.mint,s.owner,0,i,mt(i))}const a=i.equals(n.TOKEN_PROGRAM_ID)?xt.Spl:xt.Token2022,u=i.equals(n.TOKEN_PROGRAM_ID)?xt.SplCold:xt.Token2022Cold,[c,l]=await Promise.allSettled([e.getAccountInfo(r,o),s?e.getCompressedTokenAccountsByOwner(s.owner,{mint:s.mint}):Promise.resolve({items:[]})]),d=[],p=[],m=[],h="fulfilled"===c.status?c.value:null;"rejected"===c.status&&p.push(c.reason);const f="fulfilled"===l.status?l.value:{items:[]};if("rejected"===l.status&&p.push(l.reason),h)if(h.owner.equals(i))try{const e=n.unpackAccount(r,h,i);d.push({type:a,address:r,amount:e.amount,accountInfo:h,parsed:e})}catch(e){p.push(e)}else m.push(new n.TokenInvalidAccountOwnerError);for(const e of f.items){const n=e.compressedAccount;if(n&&n.data&&n.data.data.length>0&&n.owner.equals(t.LIGHT_TOKEN_PROGRAM_ID)){const e=Ut(r,n);d.push({type:u,address:r,amount:e.parsed.amount,accountInfo:e.accountInfo,loadContext:e.loadContext,parsed:e.parsed})}}if(Et("Failed to fetch token account data from RPC",p),0===d.length){if(m.length>0)throw m[0];throw new n.TokenAccountNotFoundError}return qt(d,r)}(e,r,o,i,s);throw new Error(`Unsupported program ID: ${i.toBase58()}`)}function qt(e,t){const r=e.reduce(((e,t)=>e+t.amount),BigInt(0)),o=e[0],i=e.some((e=>null!==e.parsed.delegate)),s=e.some((e=>e.parsed.isFrozen)),a=e.some((e=>_t(e.type))),u=e.length>1,c=(t,n)=>e.reduce(((e,r)=>{if(!n(r))return e;const o=r.parsed.delegate;return o&&o.equals(t)?e+(e=>{var t;const n=null!==(t=e.parsed.delegatedAmount)&&void 0!==t?t:e.amount;return e.amount<n?e.amount:n})(r):e}),BigInt(0)),l=e.find((e=>!_t(e.type)&&null!==e.parsed.delegate)),d=e.filter((e=>_t(e.type)&&null!==e.parsed.delegate));let p=null,m=BigInt(0);(null==l?void 0:l.parsed.delegate)?(p=l.parsed.delegate,m=c(p,(()=>1))):d.length>0&&(p=d[0].parsed.delegate,m=c(p,(e=>_t(e.type))));const h=Object.assign(Object.assign(Object.assign({},o.parsed),{address:t,amount:r,isInitialized:o.parsed.isInitialized||a,delegate:p,delegatedAmount:m}),s?{state:n.AccountState.Frozen,isFrozen:1}:{});return{accountInfo:o.accountInfo,parsed:h,isCold:_t(o.type),loadContext:o.loadContext,_sources:e,_needsConsolidation:u,_hasDelegate:i,_anyFrozen:s}}function Ft(e,t){var n;const r=e._owner;if(r&&t.equals(r))return e.parsed.amount;const o=e.parsed.delegate;if(o&&t.equals(o)){const t=null!==(n=e.parsed.delegatedAmount)&&void 0!==n?n:BigInt(0);return t<e.parsed.amount?t:e.parsed.amount}return BigInt(0)}function Vt(e,t){const n=e._owner;if(n&&t.equals(n))return 1;const r=e.parsed.delegate;return null!==r&&t.equals(r)}function Ht(e,t){var n;const r=e._owner;if(r&&t.equals(r))return e;const o=Ft(e,t),i=e.parsed.delegate;if(o===BigInt(0)||null===i||!t.equals(i))return Object.assign(Object.assign({},e),{_sources:[],_needsConsolidation:0,parsed:Object.assign(Object.assign({},e.parsed),{amount:BigInt(0)})});const s=(null!==(n=e._sources)&&void 0!==n?n:[]).filter((e=>null!==e.parsed.delegate&&e.parsed.delegate.equals(i))),a=s[0];return Object.assign(Object.assign(Object.assign({},e),a?{accountInfo:a.accountInfo,isCold:_t(a.type),loadContext:a.loadContext}:{}),{_sources:s,_needsConsolidation:s.length>1,parsed:Object.assign(Object.assign({},e.parsed),{amount:o})})}function zt(e,r,o=0,i=t.LIGHT_TOKEN_PROGRAM_ID,s){const a=null!=s?s:mt(i);return n.getAssociatedTokenAddressSync(e,r,o,i,a)}const jt=r.Buffer.from([101]),$t=19,Zt=31,Qt=32,Xt=0,Yt=1,Jt=o.struct([o.u64("delegatedAmount"),o.u64("withheldTransferFee"),o.bool("isFrozen"),o.u8("compressionIndex"),o.bool("isAta"),o.u8("bump"),o.u8("ownerIndex")]),en=o.struct([o.u16("baseRent"),o.u16("compressionCost"),o.u8("lamportsPerBytePerEpoch"),o.u8("maxFundedEpochs"),o.u16("maxTopUp")]),tn=o.struct([o.u16("configAccountVersion"),o.u8("compressToPubkey"),o.u8("accountVersion"),o.u32("lamportsPerWrite"),o.array(o.u8(),32,"compressionAuthority"),o.array(o.u8(),32,"rentSponsor"),o.u64("lastClaimedSlot"),o.u32("rentExemptionPaid"),o.u32("reserved"),en.replicate("rentConfig")]);function nn(e){const n=r.Buffer.alloc(1024);let o=0;if("TokenMetadata"===e.type){n.writeUInt8($t,o),o+=1;const t={updateAuthority:e.data.updateAuthority,name:e.data.name,symbol:e.data.symbol,uri:e.data.uri,additionalMetadata:e.data.additionalMetadata?e.data.additionalMetadata.map((e=>({key:r.Buffer.from(e.key),value:r.Buffer.from(e.value)}))):null};o+=qe.encode(t,n,o)}else if("CompressedOnly"===e.type){n.writeUInt8(Zt,o),o+=1;const r={delegatedAmount:t.bn(e.data.delegatedAmount.toString()),withheldTransferFee:t.bn(e.data.withheldTransferFee.toString()),isFrozen:e.data.isFrozen,compressionIndex:e.data.compressionIndex,isAta:e.data.isAta,bump:e.data.bump,ownerIndex:e.data.ownerIndex};o+=Jt.encode(r,n,o)}else if("Compressible"===e.type){n.writeUInt8(Qt,o),o+=1;const r={configAccountVersion:e.data.configAccountVersion,compressToPubkey:e.data.compressToPubkey,accountVersion:e.data.accountVersion,lamportsPerWrite:e.data.lamportsPerWrite,compressionAuthority:Array.from(e.data.compressionAuthority.toBytes()),rentSponsor:Array.from(e.data.rentSponsor.toBytes()),lastClaimedSlot:t.bn(e.data.lastClaimedSlot.toString()),rentExemptionPaid:e.data.rentExemptionPaid,reserved:e.data.reserved,rentConfig:e.data.rentConfig};o+=tn.encode(r,n,o)}return n.subarray(0,o)}function rn(e){if(null===e)return null;const t=[],n=r.Buffer.alloc(4);n.writeUInt32LE(e.length,0),t.push(n);for(const n of e){const e=r.Buffer.alloc(4);e.writeUInt32LE(n.length,0),t.push(e);for(const e of n)t.push(nn(e))}return r.Buffer.concat(t)}const on=o.struct([o.u8("mode"),o.u64("amount"),o.u8("mint"),o.u8("sourceOrRecipient"),o.u8("authority"),o.u8("poolAccountIndex"),o.u8("poolIndex"),o.u8("bump"),o.u8("decimals")]),sn=o.struct([o.u8("merkleTreePubkeyIndex"),o.u8("queuePubkeyIndex"),o.u32("leafIndex"),o.bool("proveByIndex")]),an=o.struct([o.u8("owner"),o.u64("amount"),o.bool("hasDelegate"),o.u8("delegate"),o.u8("mint"),o.u8("version"),sn.replicate("merkleContext"),o.u16("rootIndex")]),un=o.struct([o.u8("owner"),o.u64("amount"),o.bool("hasDelegate"),o.u8("delegate"),o.u8("mint"),o.u8("version")]),cn=o.struct([o.bool("setContext"),o.bool("firstSetContext"),o.u8("cpiContextAccountIndex")]),ln=o.struct([o.bool("withTransactionHash"),o.bool("withLamportsChangeAccountMerkleTreeIndex"),o.u8("lamportsChangeAccountMerkleTreeIndex"),o.u8("lamportsChangeAccountOwnerIndex"),o.u8("outputQueue"),o.u16("maxTopUp"),o.option(cn,"cpiContext"),o.option(o.vec(on),"compressions"),o.option(Ue,"proof"),o.vec(an,"inTokenData"),o.vec(un,"outTokenData"),o.option(o.vec(o.u64()),"inLamports"),o.option(o.vec(o.u64()),"outLamports")]);function dn(e){var n,o,i,s,a,u;const c={withTransactionHash:e.withTransactionHash,withLamportsChangeAccountMerkleTreeIndex:e.withLamportsChangeAccountMerkleTreeIndex,lamportsChangeAccountMerkleTreeIndex:e.lamportsChangeAccountMerkleTreeIndex,lamportsChangeAccountOwnerIndex:e.lamportsChangeAccountOwnerIndex,outputQueue:e.outputQueue,maxTopUp:e.maxTopUp,cpiContext:e.cpiContext,compressions:null!==(o=null===(n=e.compressions)||void 0===n?void 0:n.map((e=>Object.assign(Object.assign({},e),{amount:t.bn(e.amount.toString())}))))&&void 0!==o?o:null,proof:e.proof,inTokenData:e.inTokenData.map((e=>Object.assign(Object.assign({},e),{amount:t.bn(e.amount.toString())}))),outTokenData:e.outTokenData.map((e=>Object.assign(Object.assign({},e),{amount:t.bn(e.amount.toString())}))),inLamports:null!==(s=null===(i=e.inLamports)||void 0===i?void 0:i.map((e=>t.bn(e.toString()))))&&void 0!==s?s:null,outLamports:null!==(u=null===(a=e.outLamports)||void 0===a?void 0:a.map((e=>t.bn(e.toString()))))&&void 0!==u?u:null},l=r.Buffer.alloc(4e3),d=ln.encode(c,l),p=[jt,l.subarray(0,d)];if(null===e.inTlv)p.push(r.Buffer.from([0]));else{p.push(r.Buffer.from([1]));const t=rn(e.inTlv);t&&p.push(r.Buffer.from(t))}if(null===e.outTlv)p.push(r.Buffer.from([0]));else{p.push(r.Buffer.from([1]));const t=rn(e.outTlv);t&&p.push(r.Buffer.from(t))}return r.Buffer.concat(p)}function pn(e,t,n,r,o,i,s,a){return{mode:Xt,amount:e,mint:t,sourceOrRecipient:n,authority:r,poolAccountIndex:o,poolIndex:i,bump:s,decimals:a}}function mn(e,t,n,r){return{mode:Yt,amount:e,mint:t,sourceOrRecipient:n,authority:0,poolAccountIndex:r,poolIndex:0,bump:0,decimals:0}}function hn(e,t,n,r,o){return{mode:Xt,amount:e,mint:t,sourceOrRecipient:n,authority:r,poolAccountIndex:o,poolIndex:0,bump:0,decimals:0}}function fn(e,t,n,r,o,i,s){return{mode:Yt,amount:e,mint:t,sourceOrRecipient:n,authority:0,poolAccountIndex:r,poolIndex:o,bump:i,decimals:s}}function gn(n,r,o,i,s,a,u,c=o,l){const d=[pn(s,0,2,1,4,a.poolIndex,a.bump,u),mn(s,0,3,6)],p=dn({withTransactionHash:0,withLamportsChangeAccountMerkleTreeIndex:0,lamportsChangeAccountMerkleTreeIndex:0,lamportsChangeAccountOwnerIndex:0,outputQueue:0,maxTopUp:null!=l?l:b,cpiContext:null,compressions:d,proof:null,inTokenData:[],outTokenData:[],inLamports:null,outLamports:null,inTlv:null,outTlv:null}),m=[{pubkey:ve.deriveCpiAuthorityPda,isSigner:0,isWritable:0},{pubkey:c,isSigner:1,isWritable:1},{pubkey:i,isSigner:0,isWritable:0},{pubkey:o,isSigner:1,isWritable:0},{pubkey:n,isSigner:0,isWritable:1},{pubkey:r,isSigner:0,isWritable:1},{pubkey:a.splInterfacePda,isSigner:0,isWritable:1},{pubkey:a.tokenProgram,isSigner:0,isWritable:0},{pubkey:t.LIGHT_TOKEN_PROGRAM_ID,isSigner:0,isWritable:0},{pubkey:e.SystemProgram.programId,isSigner:0,isWritable:0}];return new e.TransactionInstruction({programId:ve.programId,keys:m,data:p})}const yn=31,bn=17;function In(e){if(!e||e.length<5)return null;try{let t=0;const n=e.readUInt32LE(t);t+=4;for(let r=0;r<n;r++){if(t>=e.length)return null;const n=e[t];if(t+=1,n===yn){if(t+bn>e.length)return null;const n=BigInt(e.readUInt32LE(t))|BigInt(e.readUInt32LE(t+4))<<BigInt(32);return{delegatedAmount:n,withheldTransferFee:BigInt(e.readUInt32LE(t+8))|BigInt(e.readUInt32LE(t+12))<<BigInt(32),isAta:0!==e[t+16]}}const r={29:8,30:1,31:17}[n];if(void 0===r)throw new Error(`parseCompressedOnlyFromTlv: unknown TLV extension discriminant ${n}`);t+=r}}catch(e){return null}return null}function wn(n,r,o,i){let s=0;const a=[];for(const u of n){const n=In(u.parsed.tlv);if(!n){a.push([]);continue}s=1;let c=0;if(n.isAta){const n=[o.toBuffer(),t.LIGHT_TOKEN_PROGRAM_ID.toBuffer(),i.toBuffer()],[,r]=e.PublicKey.findProgramAddressSync(n,t.LIGHT_TOKEN_PROGRAM_ID);c=r}const l=2===u.parsed.state;a.push([{type:"CompressedOnly",data:{delegatedAmount:n.delegatedAmount,withheldTransferFee:n.withheldTransferFee,isFrozen:l,compressionIndex:0,isAta:n.isAta,bump:c,ownerIndex:r}}])}return s?a:null}function kn(e){return!e||e.length<8?exports.TokenDataVersion.ShaFlat:2===e[0]?exports.TokenDataVersion.V1:3===e[7]?exports.TokenDataVersion.V2:exports.TokenDataVersion.ShaFlat}function An(n,r,o,i,s,a,u,c,l){var d;if(0===r.length)throw new Error("No input light-token accounts provided");const p=r[0].parsed.mint,m=r[0].parsed.owner,h=new Map,f=[],g=new Set,y=new Set;for(const e of r)g.add(e.compressedAccount.treeInfo.tree.toBase58()),y.add(e.compressedAccount.treeInfo.queue.toBase58());for(const t of g)h.set(t,f.length),f.push(new e.PublicKey(t));let I=0,w=1;for(const t of y)w&&(I=f.length,w=0),h.set(t,f.length),f.push(new e.PublicKey(t));const k=f.length;h.set(p.toBase58(),k),f.push(p);const A=f.length;h.set(m.toBase58(),A),f.push(m);const v=f.length;h.set(o.toBase58(),v),f.push(o);for(const e of r)if(e.parsed.delegate){const t=e.parsed.delegate.toBase58();h.has(t)||(h.set(t,f.length),f.push(e.parsed.delegate))}let T=0,M=0,P=0,S=0;a&&(T=f.length,h.set(a.splInterfacePda.toBase58(),T),f.push(a.splInterfacePda),S=f.length,h.set(a.tokenProgram.toBase58(),S),f.push(a.tokenProgram),M=a.poolIndex,P=a.bump);const x=function(e,t,n){return e.map(((e,r)=>{var o,i;const s=e.parsed.owner.toBase58(),a=e.parsed.mint.toBase58(),u=kn(null===(o=e.compressedAccount.data)||void 0===o?void 0:o.discriminator);return{owner:n.get(s),amount:BigInt(e.parsed.amount.toString()),hasDelegate:null!==e.parsed.delegate,delegate:e.parsed.delegate&&null!==(i=n.get(e.parsed.delegate.toBase58()))&&void 0!==i?i:0,mint:n.get(a),version:u,merkleContext:{merkleTreePubkeyIndex:n.get(e.compressedAccount.treeInfo.tree.toBase58()),queuePubkeyIndex:n.get(e.compressedAccount.treeInfo.queue.toBase58()),leafIndex:e.compressedAccount.leafIndex,proveByIndex:e.compressedAccount.proveByIndex},rootIndex:t[r]}}))}(r,s.rootIndices,h),C=r.reduce(((e,t)=>e+BigInt(t.parsed.amount.toString())),BigInt(0))-i,_=[];if(C>0){const e=kn(null===(d=r[0].compressedAccount.data)||void 0===d?void 0:d.discriminator);_.push({owner:A,amount:C,hasDelegate:0,delegate:0,mint:k,version:e})}const E=dn({withTransactionHash:0,withLamportsChangeAccountMerkleTreeIndex:0,lamportsChangeAccountMerkleTreeIndex:0,lamportsChangeAccountOwnerIndex:0,outputQueue:I,maxTopUp:b,cpiContext:null,compressions:[{mode:Yt,amount:i,mint:k,sourceOrRecipient:v,authority:0,poolAccountIndex:a?T:0,poolIndex:a?M:0,bump:a?P:0,decimals:u}],proof:s.compressedProof?{a:Array.from(s.compressedProof.a),b:Array.from(s.compressedProof.b),c:Array.from(s.compressedProof.c)}:null,inTokenData:x,outTokenData:_,inLamports:null,outLamports:null,inTlv:wn(r,A,m,p),outTlv:null}),{accountCompressionAuthority:O,registeredProgramPda:B,accountCompressionProgram:L}=t.defaultStaticAccountsStruct(),D=(()=>{if(!l||l.equals(m))return A;const e=h.get(l.toBase58());if(void 0===e)throw new Error(`Authority ${l.toBase58()} is not present in packed accounts`);return e})(),R=[{pubkey:t.LightSystemProgram.programId,isSigner:0,isWritable:0},{pubkey:n,isSigner:1,isWritable:1},{pubkey:ve.deriveCpiAuthorityPda,isSigner:0,isWritable:0},{pubkey:B,isSigner:0,isWritable:0},{pubkey:O,isSigner:0,isWritable:0},{pubkey:L,isSigner:0,isWritable:0},{pubkey:e.SystemProgram.programId,isSigner:0,isWritable:0},...f.map(((e,t)=>{const n=t<g.size+y.size,r=e.equals(o),i=void 0!==a&&e.equals(a.splInterfacePda);return{pubkey:e,isSigner:t===D,isWritable:n||r||i}}))];return new e.TransactionInstruction({programId:ve.programId,keys:R,data:E})}const vn=8;function Tn(e,t){if(0===e.length||t<=BigInt(0))return[];const n=[...e].sort(((e,t)=>{const n=BigInt(e.parsed.amount.toString()),r=BigInt(t.parsed.amount.toString());return r>n?1:r<n?-1:0}));let r=BigInt(0),o=0;for(const e of n)if(o++,r+=BigInt(e.parsed.amount.toString()),r>=t)break;const i=Math.min(Math.max(o,vn),n.length);return n.slice(0,i)}async function Mn(r,o,i,s,a,u,c,l=0){var d;t.assertBetaEnabled(),null!=u||(u=i);const p=null!==(d=null==c?void 0:c.owner)&&void 0!==d?d:i;let m;try{m=await Wt(r,o,p,s,void 0,void 0,l)}catch(e){if(e instanceof n.TokenAccountNotFoundError)return[];throw e}if(!p.equals(i)){if(!Vt(m,i))throw new Error("Signer is not the owner or a delegate of the account.");m=Ht(m,i)}return(await Kn(r,u,m,c,l,o,void 0,i,a)).map((t=>[e.ComputeBudgetProgram.setComputeUnitLimit({units:Rn(t)}),...t.instructions]))}const Pn=3e4,Sn=5e4,xn=5e4,Cn=1e5,_n=1e4,En=3e4,On=1.3,Bn=5e4,Ln=14e5;function Dn(e){var t;let n=0;if(e.hasAtaCreation&&(n+=Pn),n+=e.wrapCount*Sn,e.compressedAccounts.length>0){n+=xn;const r=e.compressedAccounts.some((e=>{var t;return!(null!==(t=e.compressedAccount.proveByIndex)&&void 0!==t&&t)}));r&&(n+=Cn);for(const r of e.compressedAccounts)n+=null!==(t=r.compressedAccount.proveByIndex)&&void 0!==t&&t?_n:En}return n}function Rn(e){const t=Math.ceil(Dn(e)*On);return Math.max(Bn,Math.min(Ln,t))}async function Kn(e,r,o,i,s,a,u,c,l){var d,p,m,h;if(!o._isAta||!o._owner||!o._mint)throw new Error("AccountInterface must be from getAtaInterface (requires _isAta, _owner, _mint)");Ot(o,"load");const f=o._owner,g=o._mint,y=null!==(d=o._sources)&&void 0!==d?d:[],b=function(e){return e.filter((e=>void 0!==e.loadContext)).filter((e=>Ct.has(e.type))).map((e=>{const n=e.accountInfo.data,r=n.subarray(0,Math.min(8,n.length)),o=n.length>8?n.subarray(8):Buffer.alloc(0),i={treeInfo:e.loadContext.treeInfo,hash:e.loadContext.hash,leafIndex:e.loadContext.leafIndex,proveByIndex:e.loadContext.proveByIndex,owner:e.accountInfo.owner,lamports:t.bn(e.accountInfo.lamports),address:null,data:0===n.length?null:{discriminator:Array.from(r),data:Buffer.from(o),dataHash:new Array(32).fill(0)},readOnly:0},s=e.parsed.isInitialized?e.parsed.isFrozen?2:1:0;return{compressedAccount:i,parsed:{mint:e.parsed.mint,owner:e.parsed.owner,amount:t.bn(e.parsed.amount.toString()),delegate:e.parsed.delegate,state:s,tlv:e.parsed.tlvData.length>0?e.parsed.tlvData:null}}}))}(y),I=zt(g,f),w=n.getAssociatedTokenAddressSync(g,f,0,n.TOKEN_PROGRAM_ID,mt(n.TOKEN_PROGRAM_ID)),k=n.getAssociatedTokenAddressSync(g,f,0,n.TOKEN_2022_PROGRAM_ID,mt(n.TOKEN_2022_PROGRAM_ID));let A="light-token";if(A=ht(a,g,f).type,s&&"light-token"!==A)throw new Error(`For wrap=true, targetAta must be light-token associated token account. Got ${A} associated token account.`);const v=y.find((e=>"spl"===e.type)),T=y.find((e=>"token2022"===e.type)),P=y.find((e=>"light-token-hot"===e.type)),S=y.filter((e=>Ct.has(e.type))),x=null!==(p=null==v?void 0:v.amount)&&void 0!==p?p:BigInt(0),C=null!==(m=null==T?void 0:T.amount)&&void 0!==m?m:BigInt(0),_=S.reduce(((e,t)=>e+t.amount),BigInt(0));if(x===BigInt(0)&&C===BigInt(0)&&_===BigInt(0))return[];let E;if(s||"spl"===A||"token2022"===A||x>BigInt(0)||C>BigInt(0))try{E=(null!==(h=null==i?void 0:i.splInterfaceInfos)&&void 0!==h?h:await M(e,g)).find((e=>e.isInitialized))}catch(e){if(x>BigInt(0)||C>BigInt(0))throw e}const O=[];let B,L=0,D=0,R=I,K=0;s?(R=I,B=void 0,K=1,P||(D=1,O.push(yt(r,I,f,g,t.LIGHT_TOKEN_PROGRAM_ID))),x>BigInt(0)&&E&&(O.push(gn(w,I,f,g,x,E,l,r)),L++),C>BigInt(0)&&E&&(O.push(gn(k,I,f,g,C,E,l,r)),L++)):"light-token"===A?(R=I,B=void 0,K=1,P||(D=1,O.push(yt(r,I,f,g,t.LIGHT_TOKEN_PROGRAM_ID)))):"spl"===A&&E?(R=w,B=E,K=1,v||(D=1,O.push(n.createAssociatedTokenAccountIdempotentInstruction(r,w,f,g,n.TOKEN_PROGRAM_ID)))):"token2022"===A&&E&&(R=k,B=E,K=1,T||(D=1,O.push(n.createAssociatedTokenAccountIdempotentInstruction(r,k,f,g,n.TOKEN_2022_PROGRAM_ID))));let U=b;if(void 0!==u&&K&&b.length>0){const e=void 0!==c&&!c.equals(f),t=(()=>{var t;if(!P)return BigInt(0);if(e){const e=null!==(t=P.parsed.delegatedAmount)&&void 0!==t?t:BigInt(0);return e<P.amount?e:P.amount}return P.amount})();let n;n=s?t+x+C:"light-token"===A?t:"spl"===A?x:C;const r=u>n?u-n:BigInt(0);U=r===BigInt(0)?[]:Tn(b,r)}if(!K||0===U.length)return 0===O.length?[]:[{instructions:O,compressedAccounts:[],wrapCount:L,hasAtaCreation:D}];!function(e){const n=e.filter((e=>e.compressedAccount.treeInfo.treeType===t.TreeType.StateV1)).length;if(n>0)throw new Error(`v3 interface does not support V1 compressed accounts. Found ${n} V1 account(s). Use the main SDK actions (transfer, decompress, merge) to migrate V1 accounts to V2.`)}(U);const N=function(e,t){const n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n}(U,vn);!function(e){const t=new Set;for(const n of e)for(const e of n){const n=e.compressedAccount.hash.toString();if(t.has(n))throw new Error(`Duplicate compressed account hash across chunks: ${n}. Each compressed account must appear in exactly one chunk.`);t.add(n)}}(N);const W=await Promise.all(N.map((async t=>{const n=t.map((e=>({hash:e.compressedAccount.hash,tree:e.compressedAccount.treeInfo.tree,queue:e.compressedAccount.treeInfo.queue})));return e.getValidityProofV0(n)}))),G=s||"light-token"===A?yt(r,I,f,g,t.LIGHT_TOKEN_PROGRAM_ID):"spl"===A?n.createAssociatedTokenAccountIdempotentInstruction(r,w,f,g,n.TOKEN_PROGRAM_ID):n.createAssociatedTokenAccountIdempotentInstruction(r,k,f,g,n.TOKEN_2022_PROGRAM_ID),q=[];for(let e=0;e<N.length;e++){const t=N[e],n=W[e],o=t.reduce(((e,t)=>e+BigInt(t.parsed.amount.toString())),BigInt(0)),i=[];let s=0,a=0;0===e?(i.push(...O),s=L,a=D):(i.push(G),a=1);const u=null!=c?c:f;i.push(An(r,t,R,o,n,B,l,0,u)),q.push({instructions:i,compressedAccounts:t,wrapCount:s,hasAtaCreation:a})}return q}function Un(n){const{mint:o,destination:i,amount:s,authority:a,maxTopUp:u,feePayer:c}=n,l=[{pubkey:o,isSigner:0,isWritable:1},{pubkey:i,isSigner:0,isWritable:1},{pubkey:a,isSigner:1,isWritable:void 0!==u&&!c},{pubkey:e.SystemProgram.programId,isSigner:0,isWritable:0}];c&&l.push({pubkey:c,isSigner:1,isWritable:1});const d=BigInt(s.toString()),p=void 0!==u?11:9,m=r.Buffer.alloc(p);return m.writeUInt8(7,0),m.writeBigUInt64LE(d,1),void 0!==u&&m.writeUInt16LE(u,9),new e.TransactionInstruction({programId:t.LIGHT_TOKEN_PROGRAM_ID,keys:l,data:m})}function Nn(n,r,o,i,s,a,u,c=exports.TokenDataVersion.ShaFlat,l){var d;const p=s.cmintDecompressed;t.getDefaultAddressTreeInfo();const m=function(e){var t;if(e.mintData.metadata)throw new Error("TokenMetadata extension not supported in mintTo instruction");const n=e.mintData.cmintDecompressed;return $e({leafIndex:e.leafIndex,proveByIndex:1,rootIndex:e.rootIndex,maxTopUp:null!==(t=e.maxTopUp)&&void 0!==t?t:b,createMint:null,actions:[{mintToCompressed:{tokenAccountVersion:e.tokenAccountVersion,recipients:e.recipients.map((e=>({recipient:e.recipient,amount:BigInt(e.amount.toString())})))}}],proof:n?null:e.proof,cpiContext:null,mint:n?null:{supply:e.mintData.supply,decimals:e.mintData.decimals,metadata:{version:e.mintData.version,cmintDecompressed:e.mintData.cmintDecompressed,mint:e.mintData.splMint,mintSigner:Array.from(e.mintData.mintSigner),bump:e.mintData.bump},mintAuthority:e.mintData.mintAuthority,freezeAuthority:e.mintData.freezeAuthority,extensions:null}})}({leafIndex:i.leafIndex,rootIndex:o.rootIndices[0],proof:o.compressedProof,mintData:s,recipients:a,tokenAccountVersion:c,maxTopUp:l}),h=null!==(d=null==u?void 0:u.queue)&&void 0!==d?d:t.getOutputQueue(i),f=t.defaultStaticAccountsStruct(),g=[{pubkey:t.LightSystemProgram.programId,isSigner:0,isWritable:0},{pubkey:n,isSigner:1,isWritable:0},...p?[{pubkey:s.splMint,isSigner:0,isWritable:1}]:[],{pubkey:r,isSigner:1,isWritable:1},{pubkey:ve.deriveCpiAuthorityPda,isSigner:0,isWritable:0},{pubkey:f.registeredProgramPda,isSigner:0,isWritable:0},{pubkey:f.accountCompressionAuthority,isSigner:0,isWritable:0},{pubkey:f.accountCompressionProgram,isSigner:0,isWritable:0},{pubkey:e.SystemProgram.programId,isSigner:0,isWritable:0},{pubkey:h,isSigner:0,isWritable:1},{pubkey:i.treeInfo.tree,isSigner:0,isWritable:1},{pubkey:i.treeInfo.queue,isSigner:0,isWritable:1},{pubkey:h,isSigner:0,isWritable:1}];return new e.TransactionInstruction({programId:t.LIGHT_TOKEN_PROGRAM_ID,keys:g,data:m})}function Wn(e,t,r,o,i,s,a=[]){const u=e.mint.address,c=e.programId;if(!e.merkleContext)return n.createMintToInstruction(u,t,r,BigInt(i.toString()),a,c);if(!e.mintContext)throw new Error("mintContext required for light-token mint-to");const l=r.equals(o)?void 0:o;return Un({mint:u,destination:t,amount:i,authority:r,feePayer:l})}"function"==typeof SuppressedError&&SuppressedError;const Gn=1232;function qn(e,t,n="Batch"){const r=Vn(e,t);if(r>Gn)throw new Error(`${n} exceeds max transaction size: ${r} > ${Gn}. This indicates a bug in batch assembly.`)}function Fn(e){return e<128?1:e<16384?2:3}function Vn(e,t){const n=new Set;for(const t of e){n.add(t.programId.toBase58());for(const e of t.keys)n.add(e.pubkey.toBase58())}const r=n.size,o=Fn(t)+64*t,i=Fn(r)+32*r;let s=Fn(e.length);for(const t of e)s+=1,s+=Fn(t.keys.length),s+=t.keys.length,s+=Fn(t.data.length),s+=t.data.length;return o+1+3+i+32+s+Fn(0)}const Hn=1.3,zn=5e4,jn=14e5;function $n(e,t){const n=t?Dn(t):0,r=Math.ceil((e+n)*Hn);return Math.max(zn,Math.min(jn,r))}const Zn=12,Qn=1e4;function Xn(e){return $n(Qn,e)}function Yn(n,r,o,i,s,a,u){const c=Buffer.alloc(10);c.writeUInt8(Zn,0),c.writeBigUInt64LE(BigInt(s),1),c.writeUInt8(a,9);const l=[{pubkey:n,isSigner:0,isWritable:1},{pubkey:o,isSigner:0,isWritable:0},{pubkey:r,isSigner:0,isWritable:1},{pubkey:i,isSigner:1,isWritable:u.equals(i)},{pubkey:e.SystemProgram.programId,isSigner:0,isWritable:0},{pubkey:u,isSigner:!u.equals(i),isWritable:1}];return new e.TransactionInstruction({programId:t.LIGHT_TOKEN_PROGRAM_ID,keys:l,data:c})}async function Jn(r,o,i,s,a,u,c,l){t.assertBetaEnabled();const d=BigInt(s.toString());if(d<=BigInt(0))throw new Error("Transfer amount must be greater than zero.");const p=null!=l?l:{},{wrap:m=0,programId:h=t.LIGHT_TOKEN_PROGRAM_ID,owner:f}=p,g=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}(p,["wrap","programId","owner"]),y=null!=f?f:a,b=h.equals(n.TOKEN_PROGRAM_ID)||h.equals(n.TOKEN_2022_PROGRAM_ID),I=zt(i,y,0,h);let w;try{w=await Wt(r,I,y,i,void 0,h.equals(t.LIGHT_TOKEN_PROGRAM_ID)?void 0:h,m)}catch(e){if(e instanceof n.TokenAccountNotFoundError)throw new Error("Sender has no token accounts for this mint.");throw e}if(Ot(w,"transfer"),y.equals(a)){if(w.parsed.amount<d)throw new Error(`Insufficient balance. Required: ${d}, Available: ${w.parsed.amount}`)}else{if(!Vt(w,a))throw new Error("Signer is not the owner or a delegate of the sender account.");const e=Ft(w,a);if(d>e)throw new Error(`Insufficient delegated balance. Required: ${d}, Available (delegate): ${e}`);w=Ht(w,a)}const k=await Kn(r,o,w,g,m,I,d,a,c);let A;A=b&&!m?n.createTransferCheckedInstruction(I,i,u,a,d,c,[],h):Yn(I,u,i,a,d,c,o);const v=o.equals(a)?1:2;if(0===k.length){const t=Xn(null),n=[e.ComputeBudgetProgram.setComputeUnitLimit({units:t}),A];return qn(n,v,"Batch"),[n]}if(1===k.length){const t=k[0],n=Xn(t),r=[e.ComputeBudgetProgram.setComputeUnitLimit({units:n}),...t.instructions,A];return qn(r,v,"Batch"),[r]}const T=[];for(let t=0;t<k.length-1;t++){const n=k[t],r=Rn(n),o=[e.ComputeBudgetProgram.setComputeUnitLimit({units:r}),...n.instructions];qn(o,v,"Batch"),T.push(o)}const M=k[k.length-1],P=Xn(M),S=[e.ComputeBudgetProgram.setComputeUnitLimit({units:P}),...M.instructions,A];return qn(S,v,"Batch"),T.push(S),T}function er(e){return $n(1e4,e)}function tr(n,r,o,i,s,a,u,c=o,l){const d=[hn(s,0,2,1,6),fn(s,0,3,4,a.poolIndex,a.bump,u)],p=dn({withTransactionHash:0,withLamportsChangeAccountMerkleTreeIndex:0,lamportsChangeAccountMerkleTreeIndex:0,lamportsChangeAccountOwnerIndex:0,outputQueue:0,maxTopUp:null!=l?l:b,cpiContext:null,compressions:d,proof:null,inTokenData:[],outTokenData:[],inLamports:null,outLamports:null,inTlv:null,outTlv:null}),m=[{pubkey:ve.deriveCpiAuthorityPda,isSigner:0,isWritable:0},{pubkey:c,isSigner:1,isWritable:1},{pubkey:i,isSigner:0,isWritable:0},{pubkey:o,isSigner:1,isWritable:0},{pubkey:n,isSigner:0,isWritable:1},{pubkey:r,isSigner:0,isWritable:1},{pubkey:a.splInterfacePda,isSigner:0,isWritable:1},{pubkey:a.tokenProgram,isSigner:0,isWritable:0},{pubkey:t.LIGHT_TOKEN_PROGRAM_ID,isSigner:0,isWritable:0},{pubkey:e.SystemProgram.programId,isSigner:0,isWritable:0}];return new e.TransactionInstruction({programId:ve.programId,keys:m,data:p})}const nr=r.Buffer.from([10]),rr=r.Buffer.from([11]);async function or(r,o,i,s,a=e.Keypair.generate(),u,c,l){const d=await r.getMinimumBalanceForRentExemption(n.MINT_SIZE),p=1==c?n.TOKEN_2022_PROGRAM_ID:c||n.TOKEN_PROGRAM_ID,m=await ve.createMint({feePayer:o.publicKey,mint:a.publicKey,decimals:s,authority:"secretKey"in i?i.publicKey:i,freezeAuthority:l&&"secretKey"in l?l.publicKey:null!=l?l:null,rentExemptBalance:d,tokenProgramId:p}),{blockhash:h}=await r.getLatestBlockhash(),f=t.dedupeSigner(o,[i,null!=l?l:null].filter((e=>null!=e&&"secretKey"in e))),g=t.buildAndSignTx(m,o,h,[...f,a]),y=await t.sendAndConfirmTx(r,g,u);return{mint:a.publicKey,transactionSignature:y}}var ir={};Object.defineProperty(ir,"__esModule",{value:1}),ir.s16=ir.s8=ir.nu64be=ir.u48be=ir.u40be=ir.u32be=ir.u24be=ir.u16be=ir.nu64=ir.u48=ir.u40=ir.u32=ir.u24=ir.u16=Fr=ir.u8=ir.offset=ir.greedy=ir.Constant=ir.UTF8=ir.CString=ir.Blob=ir.Boolean=ir.BitField=ir.BitStructure=ir.VariantLayout=ir.Union=ir.UnionLayoutDiscriminator=ir.UnionDiscriminator=ir.Structure=ir.Sequence=ir.DoubleBE=ir.Double=ir.FloatBE=ir.Float=ir.NearInt64BE=ir.NearInt64=ir.NearUInt64BE=ir.NearUInt64=ir.IntBE=ir.Int=ir.UIntBE=ir.UInt=ir.OffsetLayout=ir.GreedyCount=ir.ExternalLayout=ir.bindConstructorLayout=ir.nameWithProperty=ir.Layout=ir.uint8ArrayToBuffer=ir.checkUint8Array=void 0,ir.constant=ir.utf8=ir.cstr=Hr=ir.blob=ir.unionLayoutDiscriminator=ir.union=ir.seq=ir.bits=Vr=ir.struct=ir.f64be=ir.f64=ir.f32be=ir.f32=ir.ns64be=ir.s48be=ir.s40be=ir.s32be=ir.s24be=ir.s16be=ir.ns64=ir.s48=ir.s40=ir.s32=ir.s24=void 0;const sr=r;function ar(e){if(!(e instanceof Uint8Array))throw new TypeError("b must be a Uint8Array")}function ur(e){return ar(e),sr.Buffer.from(e.buffer,e.byteOffset,e.length)}ir.checkUint8Array=ar,ir.uint8ArrayToBuffer=ur;class cr{constructor(e,t){if(!Number.isInteger(e))throw new TypeError("span must be an integer");this.span=e,this.property=t}makeDestinationObject(){return{}}getSpan(e,t){if(0>this.span)throw new RangeError("indeterminate span");return this.span}replicate(e){const t=Object.create(this.constructor.prototype);return Object.assign(t,this),t.property=e,t}fromArray(e){}}function lr(e,t){return t.property?e+"["+t.property+"]":e}ir.Layout=cr,ir.nameWithProperty=lr,ir.bindConstructorLayout=function(e,t){if("function"!=typeof e)throw new TypeError("Class must be constructor");if(Object.prototype.hasOwnProperty.call(e,"layout_"))throw new Error("Class is already bound to a layout");if(!(t&&t instanceof cr))throw new TypeError("layout must be a Layout");if(Object.prototype.hasOwnProperty.call(t,"boundConstructor_"))throw new Error("layout is already bound to a constructor");e.layout_=t,t.boundConstructor_=e,t.makeDestinationObject=()=>new e,Object.defineProperty(e.prototype,"encode",{value(e,n){return t.encode(this,e,n)},writable:1}),Object.defineProperty(e,"decode",{value:(e,n)=>t.decode(e,n),writable:1})};class dr extends cr{isCount(){throw new Error("ExternalLayout is abstract")}}ir.ExternalLayout=dr;class pr extends dr{constructor(e=1,t){if(!Number.isInteger(e)||0>=e)throw new TypeError("elementSpan must be a (positive) integer");super(-1,t),this.elementSpan=e}isCount(){return 1}decode(e,t=0){ar(e);const n=e.length-t;return Math.floor(n/this.elementSpan)}encode(e,t,n){return 0}}ir.GreedyCount=pr;class mr extends dr{constructor(e,t=0,n){if(!(e instanceof cr))throw new TypeError("layout must be a Layout");if(!Number.isInteger(t))throw new TypeError("offset must be integer or undefined");super(e.span,n||e.property),this.layout=e,this.offset=t}isCount(){return this.layout instanceof hr||this.layout instanceof fr}decode(e,t=0){return this.layout.decode(e,t+this.offset)}encode(e,t,n=0){return this.layout.encode(e,t,n+this.offset)}}ir.OffsetLayout=mr;class hr extends cr{constructor(e,t){if(super(e,t),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(e,t=0){return ur(e).readUIntLE(t,this.span)}encode(e,t,n=0){return ur(t).writeUIntLE(e,n,this.span),this.span}}ir.UInt=hr;class fr extends cr{constructor(e,t){if(super(e,t),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(e,t=0){return ur(e).readUIntBE(t,this.span)}encode(e,t,n=0){return ur(t).writeUIntBE(e,n,this.span),this.span}}ir.UIntBE=fr;class gr extends cr{constructor(e,t){if(super(e,t),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(e,t=0){return ur(e).readIntLE(t,this.span)}encode(e,t,n=0){return ur(t).writeIntLE(e,n,this.span),this.span}}ir.Int=gr;class yr extends cr{constructor(e,t){if(super(e,t),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(e,t=0){return ur(e).readIntBE(t,this.span)}encode(e,t,n=0){return ur(t).writeIntBE(e,n,this.span),this.span}}ir.IntBE=yr;const br=Math.pow(2,32);function Ir(e){const t=Math.floor(e/br);return{hi32:t,lo32:e-t*br}}function wr(e,t){return e*br+t}class kr extends cr{constructor(e){super(8,e)}decode(e,t=0){const n=ur(e),r=n.readUInt32LE(t);return wr(n.readUInt32LE(t+4),r)}encode(e,t,n=0){const r=Ir(e),o=ur(t);return o.writeUInt32LE(r.lo32,n),o.writeUInt32LE(r.hi32,n+4),8}}ir.NearUInt64=kr;class Ar extends cr{constructor(e){super(8,e)}decode(e,t=0){const n=ur(e);return wr(n.readUInt32BE(t),n.readUInt32BE(t+4))}encode(e,t,n=0){const r=Ir(e),o=ur(t);return o.writeUInt32BE(r.hi32,n),o.writeUInt32BE(r.lo32,n+4),8}}ir.NearUInt64BE=Ar;class vr extends cr{constructor(e){super(8,e)}decode(e,t=0){const n=ur(e),r=n.readUInt32LE(t);return wr(n.readInt32LE(t+4),r)}encode(e,t,n=0){const r=Ir(e),o=ur(t);return o.writeUInt32LE(r.lo32,n),o.writeInt32LE(r.hi32,n+4),8}}ir.NearInt64=vr;class Tr extends cr{constructor(e){super(8,e)}decode(e,t=0){const n=ur(e);return wr(n.readInt32BE(t),n.readUInt32BE(t+4))}encode(e,t,n=0){const r=Ir(e),o=ur(t);return o.writeInt32BE(r.hi32,n),o.writeUInt32BE(r.lo32,n+4),8}}ir.NearInt64BE=Tr;class Mr extends cr{constructor(e){super(4,e)}decode(e,t=0){return ur(e).readFloatLE(t)}encode(e,t,n=0){return ur(t).writeFloatLE(e,n),4}}ir.Float=Mr;class Pr extends cr{constructor(e){super(4,e)}decode(e,t=0){return ur(e).readFloatBE(t)}encode(e,t,n=0){return ur(t).writeFloatBE(e,n),4}}ir.FloatBE=Pr;class Sr extends cr{constructor(e){super(8,e)}decode(e,t=0){return ur(e).readDoubleLE(t)}encode(e,t,n=0){return ur(t).writeDoubleLE(e,n),8}}ir.Double=Sr;class xr extends cr{constructor(e){super(8,e)}decode(e,t=0){return ur(e).readDoubleBE(t)}encode(e,t,n=0){return ur(t).writeDoubleBE(e,n),8}}ir.DoubleBE=xr;class Cr extends cr{constructor(e,t,n){if(!(e instanceof cr))throw new TypeError("elementLayout must be a Layout");if(!(t instanceof dr&&t.isCount()||Number.isInteger(t)&&0<=t))throw new TypeError("count must be non-negative integer or an unsigned integer ExternalLayout");let r=-1;!(t instanceof dr)&&0<e.span&&(r=t*e.span),super(r,n),this.elementLayout=e,this.count=t}getSpan(e,t=0){if(0<=this.span)return this.span;let n=0,r=this.count;if(r instanceof dr&&(r=r.decode(e,t)),0<this.elementLayout.span)n=r*this.elementLayout.span;else{let o=0;for(;o<r;)n+=this.elementLayout.getSpan(e,t+n),++o}return n}decode(e,t=0){const n=[];let r=0,o=this.count;for(o instanceof dr&&(o=o.decode(e,t));r<o;)n.push(this.elementLayout.decode(e,t)),t+=this.elementLayout.getSpan(e,t),r+=1;return n}encode(e,t,n=0){const r=this.elementLayout,o=e.reduce(((e,o)=>e+r.encode(o,t,n+e)),0);return this.count instanceof dr&&this.count.encode(e.length,t,n),o}}ir.Sequence=Cr;class _r extends cr{constructor(e,t,n){if(!Array.isArray(e)||!e.reduce(((e,t)=>e&&t instanceof cr),1))throw new TypeError("fields must be array of Layout instances");"boolean"==typeof t&&void 0===n&&(n=t,t=void 0);for(const t of e)if(0>t.span&&void 0===t.property)throw new Error("fields cannot contain unnamed variable-length layout");let r=-1;try{r=e.reduce(((e,t)=>e+t.getSpan()),0)}catch(e){}super(r,t),this.fields=e,this.decodePrefixes=!!n}getSpan(e,t=0){if(0<=this.span)return this.span;let n=0;try{n=this.fields.reduce(((n,r)=>{const o=r.getSpan(e,t);return t+=o,n+o}),0)}catch(e){throw new RangeError("indeterminate span")}return n}decode(e,t=0){ar(e);const n=this.makeDestinationObject();for(const r of this.fields)if(void 0!==r.property&&(n[r.property]=r.decode(e,t)),t+=r.getSpan(e,t),this.decodePrefixes&&e.length===t)break;return n}encode(e,t,n=0){const r=n;let o=0,i=0;for(const r of this.fields){let s=r.span;if(i=0<s?s:0,void 0!==r.property){const o=e[r.property];void 0!==o&&(i=r.encode(o,t,n),0>s&&(s=r.getSpan(t,n)))}o=n,n+=s}return o+i-r}fromArray(e){const t=this.makeDestinationObject();for(const n of this.fields)void 0!==n.property&&0<e.length&&(t[n.property]=e.shift());return t}layoutFor(e){if("string"!=typeof e)throw new TypeError("property must be string");for(const t of this.fields)if(t.property===e)return t}offsetOf(e){if("string"!=typeof e)throw new TypeError("property must be string");let t=0;for(const n of this.fields){if(n.property===e)return t;0>n.span?t=-1:0<=t&&(t+=n.span)}}}ir.Structure=_r;class Er{constructor(e){this.property=e}decode(e,t){throw new Error("UnionDiscriminator is abstract")}encode(e,t,n){throw new Error("UnionDiscriminator is abstract")}}ir.UnionDiscriminator=Er;class Or extends Er{constructor(e,t){if(!(e instanceof dr&&e.isCount()))throw new TypeError("layout must be an unsigned integer ExternalLayout");super(t||e.property||"variant"),this.layout=e}decode(e,t){return this.layout.decode(e,t)}encode(e,t,n){return this.layout.encode(e,t,n)}}ir.UnionLayoutDiscriminator=Or;class Br extends cr{constructor(e,t,n){let r;if(e instanceof hr||e instanceof fr)r=new Or(new mr(e));else if(e instanceof dr&&e.isCount())r=new Or(e);else{if(!(e instanceof Er))throw new TypeError("discr must be a UnionDiscriminator or an unsigned integer layout");r=e}if(void 0===t&&(t=null),!(null===t||t instanceof cr))throw new TypeError("defaultLayout must be null or a Layout");if(null!==t){if(0>t.span)throw new Error("defaultLayout must have constant span");void 0===t.property&&(t=t.replicate("content"))}let o=-1;t&&(o=t.span,0<=o&&(e instanceof hr||e instanceof fr)&&(o+=r.layout.span)),super(o,n),this.discriminator=r,this.usesPrefixDiscriminator=e instanceof hr||e instanceof fr,this.defaultLayout=t,this.registry={};let i=this.defaultGetSourceVariant.bind(this);this.getSourceVariant=function(e){return i(e)},this.configGetSourceVariant=function(e){i=e.bind(this)}}getSpan(e,t=0){if(0<=this.span)return this.span;const n=this.getVariant(e,t);if(!n)throw new Error("unable to determine span for unrecognized variant");return n.getSpan(e,t)}defaultGetSourceVariant(e){if(Object.prototype.hasOwnProperty.call(e,this.discriminator.property)){if(this.defaultLayout&&this.defaultLayout.property&&Object.prototype.hasOwnProperty.call(e,this.defaultLayout.property))return;const t=this.registry[e[this.discriminator.property]];if(t&&(!t.layout||t.property&&Object.prototype.hasOwnProperty.call(e,t.property)))return t}else for(const t in this.registry){const n=this.registry[t];if(n.property&&Object.prototype.hasOwnProperty.call(e,n.property))return n}throw new Error("unable to infer src variant")}decode(e,t=0){let n;const r=this.discriminator,o=r.decode(e,t),i=this.registry[o];if(void 0===i){const i=this.defaultLayout;let s=0;this.usesPrefixDiscriminator&&(s=r.layout.span),n=this.makeDestinationObject(),n[r.property]=o,n[i.property]=i.decode(e,t+s)}else n=i.decode(e,t);return n}encode(e,t,n=0){const r=this.getSourceVariant(e);if(void 0===r){const r=this.discriminator,o=this.defaultLayout;let i=0;return this.usesPrefixDiscriminator&&(i=r.layout.span),r.encode(e[r.property],t,n),i+o.encode(e[o.property],t,n+i)}return r.encode(e,t,n)}addVariant(e,t,n){const r=new Lr(this,e,t,n);return this.registry[e]=r,r}getVariant(e,t=0){let n;return n=e instanceof Uint8Array?this.discriminator.decode(e,t):e,this.registry[n]}}ir.Union=Br;class Lr extends cr{constructor(e,t,n,r){if(!(e instanceof Br))throw new TypeError("union must be a Union");if(!Number.isInteger(t)||0>t)throw new TypeError("variant must be a (non-negative) integer");if("string"==typeof n&&void 0===r&&(r=n,n=null),n){if(!(n instanceof cr))throw new TypeError("layout must be a Layout");if(null!==e.defaultLayout&&0<=n.span&&n.span>e.defaultLayout.span)throw new Error("variant span exceeds span of containing union");if("string"!=typeof r)throw new TypeError("variant must have a String property")}let o=e.span;0>e.span&&(o=n?n.span:0,0<=o&&e.usesPrefixDiscriminator&&(o+=e.discriminator.layout.span)),super(o,r),this.union=e,this.variant=t,this.layout=n||null}getSpan(e,t=0){if(0<=this.span)return this.span;let n=0;this.union.usesPrefixDiscriminator&&(n=this.union.discriminator.layout.span);let r=0;return this.layout&&(r=this.layout.getSpan(e,t+n)),n+r}decode(e,t=0){const n=this.makeDestinationObject();if(this!==this.union.getVariant(e,t))throw new Error("variant mismatch");let r=0;return this.union.usesPrefixDiscriminator&&(r=this.union.discriminator.layout.span),this.layout?n[this.property]=this.layout.decode(e,t+r):this.property?n[this.property]=1:this.union.usesPrefixDiscriminator&&(n[this.union.discriminator.property]=this.variant),n}encode(e,t,n=0){let r=0;if(this.union.usesPrefixDiscriminator&&(r=this.union.discriminator.layout.span),this.layout&&!Object.prototype.hasOwnProperty.call(e,this.property))throw new TypeError("variant lacks property "+this.property);this.union.discriminator.encode(this.variant,t,n);let o=r;if(this.layout&&(this.layout.encode(e[this.property],t,n+r),o+=this.layout.getSpan(t,n+r),0<=this.union.span&&o>this.union.span))throw new Error("encoded variant overruns containing union");return o}fromArray(e){if(this.layout)return this.layout.fromArray(e)}}function Dr(e){return 0>e&&(e+=4294967296),e}ir.VariantLayout=Lr;class Rr extends cr{constructor(e,t,n){if(!(e instanceof hr||e instanceof fr))throw new TypeError("word must be a UInt or UIntBE layout");if("string"==typeof t&&void 0===n&&(n=t,t=0),4<e.span)throw new RangeError("word cannot exceed 32 bits");super(e.span,n),this.word=e,this.msb=!!t,this.fields=[];let r=0;this._packedSetValue=function(e){return r=Dr(e),this},this._packedGetValue=function(){return r}}decode(e,t=0){const n=this.makeDestinationObject(),r=this.word.decode(e,t);this._packedSetValue(r);for(const t of this.fields)void 0!==t.property&&(n[t.property]=t.decode(e));return n}encode(e,t,n=0){const r=this.word.decode(t,n);this._packedSetValue(r);for(const t of this.fields)if(void 0!==t.property){const n=e[t.property];void 0!==n&&t.encode(n)}return this.word.encode(this._packedGetValue(),t,n)}addField(e,t){const n=new Kr(this,e,t);return this.fields.push(n),n}addBoolean(e){const t=new Ur(this,e);return this.fields.push(t),t}fieldFor(e){if("string"!=typeof e)throw new TypeError("property must be string");for(const t of this.fields)if(t.property===e)return t}}ir.BitStructure=Rr;class Kr{constructor(e,t,n){if(!(e instanceof Rr))throw new TypeError("container must be a BitStructure");if(!Number.isInteger(t)||0>=t)throw new TypeError("bits must be positive integer");const r=8*e.span,o=e.fields.reduce(((e,t)=>e+t.bits),0);if(t+o>r)throw new Error("bits too long for span remainder ("+(r-o)+" of "+r+" remain)");this.container=e,this.bits=t,this.valueMask=(1<<t)-1,32===t&&(this.valueMask=4294967295),this.start=o,this.container.msb&&(this.start=r-o-t),this.wordMask=Dr(this.valueMask<<this.start),this.property=n}decode(e,t){return Dr(this.container._packedGetValue()&this.wordMask)>>>this.start}encode(e){if("number"!=typeof e||!Number.isInteger(e)||e!==Dr(e&this.valueMask))throw new TypeError(lr("BitField.encode",this)+" value must be integer not exceeding "+this.valueMask);const t=this.container._packedGetValue(),n=Dr(e<<this.start);this.container._packedSetValue(Dr(t&~this.wordMask)|n)}}ir.BitField=Kr;class Ur extends Kr{constructor(e,t){super(e,1,t)}decode(e,t){return!!super.decode(e,t)}encode(e){"boolean"==typeof e&&(e=+e),super.encode(e)}}ir.Boolean=Ur;class Nr extends cr{constructor(e,t){if(!(e instanceof dr&&e.isCount()||Number.isInteger(e)&&0<=e))throw new TypeError("length must be positive integer or an unsigned integer ExternalLayout");let n=-1;e instanceof dr||(n=e),super(n,t),this.length=e}getSpan(e,t){let n=this.span;return 0>n&&(n=this.length.decode(e,t)),n}decode(e,t=0){let n=this.span;return 0>n&&(n=this.length.decode(e,t)),ur(e).slice(t,t+n)}encode(e,t,n){let r=this.length;if(this.length instanceof dr&&(r=e.length),!(e instanceof Uint8Array&&r===e.length))throw new TypeError(lr("Blob.encode",this)+" requires (length "+r+") Uint8Array as src");if(n+r>t.length)throw new RangeError("encoding overruns Uint8Array");const o=ur(e);return ur(t).write(o.toString("hex"),n,r,"hex"),this.length instanceof dr&&this.length.encode(r,t,n),r}}ir.Blob=Nr;class Wr extends cr{constructor(e){super(-1,e)}getSpan(e,t=0){ar(e);let n=t;for(;n<e.length&&0!==e[n];)n+=1;return 1+n-t}decode(e,t=0){const n=this.getSpan(e,t);return ur(e).slice(t,t+n-1).toString("utf-8")}encode(e,t,n=0){"string"!=typeof e&&(e=String(e));const r=sr.Buffer.from(e,"utf8"),o=r.length;if(n+o>t.length)throw new RangeError("encoding overruns Buffer");const i=ur(t);return r.copy(i,n),i[n+o]=0,o+1}}ir.CString=Wr;class Gr extends cr{constructor(e,t){if("string"==typeof e&&void 0===t&&(t=e,e=void 0),void 0===e)e=-1;else if(!Number.isInteger(e))throw new TypeError("maxSpan must be an integer");super(-1,t),this.maxSpan=e}getSpan(e,t=0){return ar(e),e.length-t}decode(e,t=0){const n=this.getSpan(e,t);if(0<=this.maxSpan&&this.maxSpan<n)throw new RangeError("text length exceeds maxSpan");return ur(e).slice(t,t+n).toString("utf-8")}encode(e,t,n=0){"string"!=typeof e&&(e=String(e));const r=sr.Buffer.from(e,"utf8"),o=r.length;if(0<=this.maxSpan&&this.maxSpan<o)throw new RangeError("text length exceeds maxSpan");if(n+o>t.length)throw new RangeError("encoding overruns Buffer");return r.copy(ur(t),n),o}}ir.UTF8=Gr;class qr extends cr{constructor(e,t){super(0,t),this.value=e}decode(e,t){return this.value}encode(e,t,n){return 0}}ir.Constant=qr,ir.greedy=(e,t)=>new pr(e,t),ir.offset=(e,t,n)=>new mr(e,t,n);var Fr=ir.u8=e=>new hr(1,e);ir.u16=e=>new hr(2,e),ir.u24=e=>new hr(3,e),ir.u32=e=>new hr(4,e),ir.u40=e=>new hr(5,e),ir.u48=e=>new hr(6,e),ir.nu64=e=>new kr(e),ir.u16be=e=>new fr(2,e),ir.u24be=e=>new fr(3,e),ir.u32be=e=>new fr(4,e),ir.u40be=e=>new fr(5,e),ir.u48be=e=>new fr(6,e),ir.nu64be=e=>new Ar(e),ir.s8=e=>new gr(1,e),ir.s16=e=>new gr(2,e),ir.s24=e=>new gr(3,e),ir.s32=e=>new gr(4,e),ir.s40=e=>new gr(5,e),ir.s48=e=>new gr(6,e),ir.ns64=e=>new vr(e),ir.s16be=e=>new yr(2,e),ir.s24be=e=>new yr(3,e),ir.s32be=e=>new yr(4,e),ir.s40be=e=>new yr(5,e),ir.s48be=e=>new yr(6,e),ir.ns64be=e=>new Tr(e),ir.f32=e=>new Mr(e),ir.f32be=e=>new Pr(e),ir.f64=e=>new Sr(e),ir.f64be=e=>new xr(e);var Vr=ir.struct=(e,t,n)=>new _r(e,t,n);ir.bits=(e,t,n)=>new Rr(e,t,n),ir.seq=(e,t,n)=>new Cr(e,t,n),ir.union=(e,t,n)=>new Br(e,t,n),ir.unionLayoutDiscriminator=(e,t)=>new Or(e,t);var Hr=ir.blob=(e,t)=>new Nr(e,t);ir.cstr=e=>new Wr(e),ir.utf8=(e,t)=>new Gr(e,t),ir.constant=(e,t)=>new qr(e,t);const zr=o.struct([o.publicKey("updateAuthority"),o.publicKey("mint"),o.vecU8("name"),o.vecU8("symbol"),o.vecU8("uri"),o.vec(o.struct([o.vecU8("key"),o.vecU8("value")]),"additionalMetadata")]),jr=Vr([Fr("version"),Fr("cmintDecompressed"),(()=>{const t=Hr(32,"splMint"),{encode:n,decode:r}=(e=>({decode:e.decode.bind(e),encode:e.encode.bind(e)}))(t),o=t;return o.decode=(t,n)=>{const o=r(t,n);return new e.PublicKey(o)},o.encode=(e,t,r)=>{const o=e.toBuffer();return n(o,t,r)},o})()]),$r=jr.span,Zr=32,Qr=1,Xr=16,Yr=1;function Jr(e,t,n){return e===exports.ExtensionType.TokenMetadata?function(e,t){let n=t;n+=32,n+=32,n+=4+e.readUInt32LE(n),n+=4+e.readUInt32LE(n),n+=4+e.readUInt32LE(n);const r=e.readUInt32LE(n);n+=4;for(let t=0;t<r;t++)n+=4+e.readUInt32LE(n),n+=4+e.readUInt32LE(n);return n-t}(t,n):t.length-n}function eo(t){const o=t instanceof r.Buffer?t:r.Buffer.from(t);let i=0;const s=n.MintLayout.decode(o.slice(i,i+n.MINT_SIZE));i+=n.MINT_SIZE;const a=jr.decode(o.slice(i,i+$r));i+=$r;const u=o.slice(i,i+Zr);i+=Zr;const c=o.readUInt8(i);i+=Qr;const l=o.slice(i,i+Xr);i+=Xr;const d=o.readUInt8(i);i+=Yr;const[p,m]=function(t,n){const r=n,o=t.readUInt16LE(n);n+=2;const i=t.readUInt8(n);n+=1;const s=t.readUInt8(n);n+=1;const a=t.readUInt32LE(n);n+=4;const u=new e.PublicKey(t.slice(n,n+32));n+=32;const c=new e.PublicKey(t.slice(n,n+32));n+=32;const l=t.readBigUInt64LE(n);n+=8;const d=t.readUInt32LE(n);n+=4;const p=t.readUInt32LE(n);n+=4;const m=t.readUInt16LE(n);n+=2;const h=t.readUInt16LE(n);n+=2;const f=t.readUInt8(n);n+=1;const g=t.readUInt8(n);return n+=1,[{configAccountVersion:o,compressToPubkey:i,accountVersion:s,lamportsPerWrite:a,compressionAuthority:u,rentSponsor:c,lastClaimedSlot:l,rentExemptionPaid:d,reserved:p,rentConfig:{baseRent:m,compressionCost:h,lamportsPerBytePerEpoch:f,maxFundedEpochs:g,maxTopUp:t.readUInt16LE(n)}},(n+=2)-r]}(o,i);i+=m;const h=1===o.readUInt8(i);i+=1;let f=null;if(h){const e=o.readUInt32LE(i);i+=4,f=[];for(let t=0;t<e;t++){const e=o.readUInt8(i);i+=1;const t=Jr(e,o,i),n=o.slice(i,i+t);i+=t,f.push({extensionType:e,data:n})}}return{base:{mintAuthority:1===s.mintAuthorityOption?s.mintAuthority:null,supply:s.supply,decimals:s.decimals,isInitialized:s.isInitialized,freezeAuthority:1===s.freezeAuthorityOption?s.freezeAuthority:null},mintContext:{version:a.version,cmintDecompressed:0!==a.cmintDecompressed,splMint:a.splMint,mintSigner:u,bump:c},reserved:l,accountType:d,compression:p,extensions:f}}var to;function no(e){try{const t=r.Buffer.from(e);if(t.length<80)return null;const n=zr.decode(t),o=n.updateAuthority.toBuffer().every((e=>0===e))?void 0:n.updateAuthority,i=r.Buffer.from(n.name).toString("utf-8"),s=r.Buffer.from(n.symbol).toString("utf-8"),a=r.Buffer.from(n.uri).toString("utf-8");let u;return n.additionalMetadata&&n.additionalMetadata.length>0&&(u=n.additionalMetadata.map((e=>({key:r.Buffer.from(e.key).toString("utf-8"),value:r.Buffer.from(e.value).toString("utf-8")})))),{updateAuthority:o,mint:n.mint,name:i,symbol:s,uri:a,additionalMetadata:u}}catch(e){return console.error("Failed to decode TokenMetadata:",e),null}}exports.ExtensionType=void 0,(to=exports.ExtensionType||(exports.ExtensionType={}))[to.TokenMetadata=19]="TokenMetadata";const ro=no;function oo(e){if(!e)return null;const t=e.find((e=>e.extensionType===exports.ExtensionType.TokenMetadata));return t?ro(t.data):null}async function io(e,o,i,s){var a,u;if(t.assertBetaEnabled(),!s){const[r,s,a]=await Promise.allSettled([io(e,o,i,n.TOKEN_PROGRAM_ID),io(e,o,i,n.TOKEN_2022_PROGRAM_ID),io(e,o,i,t.LIGHT_TOKEN_PROGRAM_ID)]);if("fulfilled"===r.status)return r.value;if("fulfilled"===s.status)return s.value;if("fulfilled"===a.status)return a.value;const c=[r,s,a].filter((e=>"rejected"===e.status)).map((e=>e.reason)),l=c.find((e=>e instanceof n.TokenInvalidAccountOwnerError));if(l)throw l;const d=c.length>0&&c.every((e=>e instanceof n.TokenAccountNotFoundError));if(d)throw new n.TokenAccountNotFoundError(`Mint not found: ${o.toString()}. Tried TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID, and LIGHT_TOKEN_PROGRAM_ID.`);const p=c.find((e=>!(e instanceof n.TokenAccountNotFoundError||e instanceof n.TokenInvalidAccountOwnerError)));if(p)throw new Error(`Failed to fetch mint data from RPC: ${u=p,u instanceof Error?u.message:String(u)}`);throw new n.TokenAccountNotFoundError(`Mint not found: ${o.toString()}. Tried TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID, and LIGHT_TOKEN_PROGRAM_ID.`)}if(s.equals(t.LIGHT_TOKEN_PROGRAM_ID)){const u=t.getDefaultAddressTreeInfo().tree,c=t.deriveAddressV2(o.toBytes(),u,t.LIGHT_TOKEN_PROGRAM_ID),l=await e.getCompressedAccount(t.bn(c.toBytes()));if(!(null===(a=null==l?void 0:l.data)||void 0===a?void 0:a.data))throw new n.TokenAccountNotFoundError(`Light mint not found for ${o.toString()}`);if(!l.owner.equals(t.LIGHT_TOKEN_PROGRAM_ID))throw new n.TokenInvalidAccountOwnerError;const d=r.Buffer.from(l.data.data),p=64;let m;if(d.length<p){const s=await e.getAccountInfo(o,i);if(!(null==s?void 0:s.data))throw new n.TokenAccountNotFoundError(`Decompressed light mint account not found on-chain for ${o.toString()}`);if(!s.owner.equals(t.LIGHT_TOKEN_PROGRAM_ID))throw new n.TokenInvalidAccountOwnerError;m=eo(r.Buffer.from(s.data))}else m=eo(d);const h={address:o,mintAuthority:m.base.mintAuthority,supply:m.base.supply,decimals:m.base.decimals,isInitialized:m.base.isInitialized,freezeAuthority:m.base.freezeAuthority,tlvData:r.Buffer.alloc(0)},f={treeInfo:l.treeInfo,hash:l.hash,leafIndex:l.leafIndex,proveByIndex:l.proveByIndex},g=oo(m.extensions),y={mint:h,programId:s,merkleContext:f,mintContext:m.mintContext,tokenMetadata:g||void 0,extensions:m.extensions||void 0,compression:m.compression};if(!y.merkleContext)throw new Error("Invalid light mint: merkleContext is required for LIGHT_TOKEN_PROGRAM_ID");if(!y.mintContext)throw new Error("Invalid light mint: mintContext is required for LIGHT_TOKEN_PROGRAM_ID");return y}return{mint:await n.getMint(e,o,i,s),programId:s}}function so(e){if(!e.tokenMetadata)throw new Error("Mint does not have TokenMetadata extension");if(!e.merkleContext)throw new Error(St)}async function ao(e,n,r,o,i,s,a,u=0,c){t.assertBetaEnabled(),null!=i||(i=r);const l=null!=c?c:(await io(e,o)).mint.decimals,d=await Mn(e,n,r.publicKey,o,l,i.publicKey,a,u);if(0===d.length)return null;const p=t.dedupeSigner(i,[r]),m=d.map((async n=>{const{blockhash:r}=await e.getLatestBlockhash(),o=t.buildAndSignTx(n,i,r,p);return t.sendAndConfirmTx(e,o,s)})),h=await Promise.all(m);return h[h.length-1]}function uo(e){if(!("publicKey"in e)||!("secretKey"in e))return 0;const t=e;return t.secretKey instanceof Uint8Array&&t.secretKey.length>0}function co(e){return uo(e)?e.publicKey:e}async function lo(r,o,i,s,a,u,c,l,d,p){const m=co(s),h=n.getAssociatedTokenAddressSync(i,m,a,l,d);return l.equals(t.LIGHT_TOKEN_PROGRAM_ID)?async function(e,r,o,i,s,a,u,c=0,l=0){var d,p,m;const h=co(i);let f;uo(i);let g=0;try{f=await Wt(e,s,h,o,a,t.LIGHT_TOKEN_PROGRAM_ID,c,l),g=null!==(p=null===(d=f._sources)||void 0===d?void 0:d.some((e=>e.type===xt.LightTokenHot)))&&void 0!==p?p:0}catch(i){if(!(i instanceof n.TokenAccountNotFoundError||i instanceof n.TokenInvalidAccountOwnerError))throw i;await po(e,r,o,h,s,u),f=await Wt(e,s,h,o,a,t.LIGHT_TOKEN_PROGRAM_ID,c,l),g=1}g||await po(e,r,o,h,s,u);const y=uo(i)?i:r.publicKey.equals(h)?r:null;if(y){const n=null!==(m=f._sources)&&void 0!==m?m:[],i=n.some((e=>e.type===xt.LightTokenCold&&e.amount>BigInt(0))),d=c&&n.some((e=>(e.type===xt.Spl||e.type===xt.Token2022)&&e.amount>BigInt(0)));if(i||d){if(!(y.secretKey instanceof Uint8Array)||0===y.secretKey.length)throw new Error("Owner must be a valid Signer with secretKey to auto-load");await ao(e,s,y,o,r,u,void 0,c),f=await Wt(e,s,h,o,a,t.LIGHT_TOKEN_PROGRAM_ID,c,l)}}const b=f.parsed;if(!b.mint.equals(o))throw new n.TokenInvalidMintError;if(!b.owner.equals(h))throw new n.TokenInvalidOwnerError;return f}(r,o,i,s,h,u,c,p,a):async function(t,r,o,i,s,a,u,c,l){let d;try{d=await Nt(t,s,c,a)}catch(p){if(!(p instanceof n.TokenAccountNotFoundError||p instanceof n.TokenInvalidAccountOwnerError))throw p;try{const n=(new e.Transaction).add(gt(r.publicKey,s,i,o,a,u));await e.sendAndConfirmTransaction(t,n,[r],l)}catch(e){try{await Nt(t,s,c,a)}catch(t){throw e}}d=await Nt(t,s,c,a)}const p=d.parsed;if(!p.mint.equals(o))throw new n.TokenInvalidMintError;if(!p.owner.equals(i))throw new n.TokenInvalidOwnerError;return d}(r,o,i,m,h,l,d,u,c)}async function po(n,r,o,i,s,a){const u=yt(r.publicKey,s,i,o,t.LIGHT_TOKEN_PROGRAM_ID),{blockhash:c}=await n.getLatestBlockhash(),l=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:2e5}),u],r,c,[]);await t.sendAndConfirmTx(n,l,a)}function mo(e){if(0===e.length)throw new Error("sliceLast: array must not be empty");return{rest:e.slice(0,-1),last:e.at(-1)}}async function ho(e,n,r,o,i){i=i||await ve.getMintProgramId(r,e);const s=await ve.createSplInterface({feePayer:n.publicKey,mint:r,tokenProgramId:i}),{blockhash:a}=await e.getLatestBlockhash(),u=t.buildAndSignTx([s],n,a);return await t.sendAndConfirmTx(e,u,o)}const fo=ho;async function go(e,n,r,o,i,s){s=s||await ve.getMintProgramId(r,e);const a=[],u=(await M(e,r)).slice(0,4),c=[];for(let e=0;e<u.length;e++)u[e].isInitialized||c.push(e);for(let e=0;e<o&&!(e>=c.length);e++)a.push(await ve.addTokenPool({mint:r,feePayer:n.publicKey,tokenProgramId:s,poolIndex:c[e]}));const{blockhash:l}=await e.getLatestBlockhash(),d=t.buildAndSignTx(a,n,l);return await t.sendAndConfirmTx(e,d,i)}const yo=go;function bo(e){return!Array.isArray(e)}const Io=bo;exports.ADD_TOKEN_POOL_DISCRIMINATOR=y,exports.APPROVE_DISCRIMINATOR=f,exports.BASE_RENT_PER_EPOCH=128,exports.BATCH_COMPRESS_DISCRIMINATOR=p,exports.COMPRESSED_MINT_SEED=Me,exports.COMPRESSIBLE_LIGHT_TOKEN_ACCOUNT_SIZE=272,exports.COMPRESSIBLE_LIGHT_TOKEN_RENT_PER_EPOCH=w,exports.COMPRESSION_COST=1e4,exports.COMPRESSION_INCENTIVE=1e3,exports.COMPRESS_SPL_TOKEN_ACCOUNT_DISCRIMINATOR=h,exports.CPI_AUTHORITY_SEED=c,exports.CREATE_TOKEN_POOL_DISCRIMINATOR=l,exports.CompressedTokenInstructionDataApproveLayout=ce,exports.CompressedTokenInstructionDataRevokeLayout=le,exports.CompressedTokenInstructionDataTransferLayout=j,exports.CompressedTokenProgram=ve,exports.CpiContextLayout=z,exports.DEFAULT_COMPRESSIBLE_CONFIG=ut,exports.DEFAULT_PREPAY_EPOCHS=16,exports.DEFAULT_WRITE_TOP_UP=766,exports.DelegatedTransferLayout=H,exports.ERROR_MIXED_TREE_TYPES=E,exports.ERROR_NO_ACCOUNTS_FOUND=_,exports.IDL={version:"1.2.0",name:"light_compressed_token",instructions:[{name:"createTokenPool",docs:["This instruction creates a token pool for a given mint. Every spl mint","can have one token pool. When a token is compressed the tokens are","transferrred to the token pool, and their compressed equivalent is","minted into a Merkle tree."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"tokenPoolPda",isMut:1,isSigner:0},{name:"systemProgram",isMut:0,isSigner:0},{name:"mint",isMut:1,isSigner:0},{name:"tokenProgram",isMut:0,isSigner:0},{name:"cpiAuthorityPda",isMut:0,isSigner:0}],args:[]},{name:"addTokenPool",docs:["This instruction creates an additional token pool for a given mint.","The maximum number of token pools per mint is 5."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"tokenPoolPda",isMut:1,isSigner:0},{name:"existingTokenPoolPda",isMut:0,isSigner:0},{name:"systemProgram",isMut:0,isSigner:0},{name:"mint",isMut:1,isSigner:0},{name:"tokenProgram",isMut:0,isSigner:0},{name:"cpiAuthorityPda",isMut:0,isSigner:0}],args:[{name:"tokenPoolIndex",type:"u8"}]},{name:"mintTo",docs:["Mints tokens from an spl token mint to a list of compressed accounts.","Minted tokens are transferred to a pool account owned by the compressed","token program. The instruction creates one compressed output account for","every amount and pubkey input pair. A constant amount of lamports can be","transferred to each output account to enable. A use case to add lamports","to a compressed token account is to prevent spam. This is the only way","to add lamports to a compressed token account."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"authority",isMut:0,isSigner:1},{name:"cpiAuthorityPda",isMut:0,isSigner:0},{name:"mint",isMut:1,isSigner:0},{name:"tokenPoolPda",isMut:1,isSigner:0},{name:"tokenProgram",isMut:0,isSigner:0},{name:"lightSystemProgram",isMut:0,isSigner:0},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0,docs:["programs"]},{name:"accountCompressionAuthority",isMut:0,isSigner:0},{name:"accountCompressionProgram",isMut:0,isSigner:0},{name:"merkleTree",isMut:1,isSigner:0},{name:"selfProgram",isMut:0,isSigner:0},{name:"systemProgram",isMut:0,isSigner:0},{name:"solPoolPda",isMut:1,isSigner:0,isOptional:1}],args:[{name:"publicKeys",type:{vec:"publicKey"}},{name:"amounts",type:{vec:"u64"}},{name:"lamports",type:{option:"u64"}}]},{name:"compressSplTokenAccount",docs:["Compresses the balance of an spl token account sub an optional remaining","amount. This instruction does not close the spl token account. To close","the account bundle a close spl account instruction in your transaction."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"authority",isMut:0,isSigner:1,docs:["Authority is verified through proof since both owner and delegate","are included in the token data hash, which is a public input to the","validity proof."]},{name:"cpiAuthorityPda",isMut:0,isSigner:0},{name:"lightSystemProgram",isMut:0,isSigner:0},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0},{name:"accountCompressionProgram",isMut:0,isSigner:0},{name:"selfProgram",isMut:0,isSigner:0,docs:["this program is the signer of the cpi."]},{name:"tokenPoolPda",isMut:1,isSigner:0,isOptional:1},{name:"compressOrDecompressTokenAccount",isMut:1,isSigner:0,isOptional:1},{name:"tokenProgram",isMut:0,isSigner:0,isOptional:1},{name:"systemProgram",isMut:0,isSigner:0}],args:[{name:"owner",type:"publicKey"},{name:"remainingAmount",type:{option:"u64"}},{name:"cpiContext",type:{option:{defined:"CompressedCpiContext"}}}]},{name:"transfer",docs:["Transfers compressed tokens from one account to another. All accounts","must be of the same mint. Additional spl tokens can be compressed or","decompressed. In one transaction only compression or decompression is","possible. Lamports can be transferred alongside tokens. If output token","accounts specify less lamports than inputs the remaining lamports are","transferred to an output compressed account. Signer must be owner or","delegate. If a delegated token account is transferred the delegate is","not preserved."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"authority",isMut:0,isSigner:1,docs:["Authority is verified through proof since both owner and delegate","are included in the token data hash, which is a public input to the","validity proof."]},{name:"cpiAuthorityPda",isMut:0,isSigner:0},{name:"lightSystemProgram",isMut:0,isSigner:0},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0},{name:"accountCompressionProgram",isMut:0,isSigner:0},{name:"selfProgram",isMut:0,isSigner:0,docs:["this program is the signer of the cpi."]},{name:"tokenPoolPda",isMut:1,isSigner:0,isOptional:1},{name:"compressOrDecompressTokenAccount",isMut:1,isSigner:0,isOptional:1},{name:"tokenProgram",isMut:0,isSigner:0,isOptional:1},{name:"systemProgram",isMut:0,isSigner:0}],args:[{name:"inputs",type:"bytes"}]},{name:"approve",docs:["Delegates an amount to a delegate. A compressed token account is either","completely delegated or not. Prior delegates are not preserved. Cannot","be called by a delegate.","The instruction creates two output accounts:","1. one account with delegated amount","2. one account with remaining(change) amount"],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"authority",isMut:0,isSigner:1,docs:["Authority is verified through proof since both owner and delegate","are included in the token data hash, which is a public input to the","validity proof."]},{name:"cpiAuthorityPda",isMut:0,isSigner:0},{name:"lightSystemProgram",isMut:0,isSigner:0},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0},{name:"accountCompressionProgram",isMut:0,isSigner:0},{name:"selfProgram",isMut:0,isSigner:0,docs:["this program is the signer of the cpi."]},{name:"systemProgram",isMut:0,isSigner:0}],args:[{name:"inputs",type:"bytes"}]},{name:"revoke",docs:["Revokes a delegation. The instruction merges all inputs into one output","account. Cannot be called by a delegate. Delegates are not preserved."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"authority",isMut:0,isSigner:1,docs:["Authority is verified through proof since both owner and delegate","are included in the token data hash, which is a public input to the","validity proof."]},{name:"cpiAuthorityPda",isMut:0,isSigner:0},{name:"lightSystemProgram",isMut:0,isSigner:0},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0},{name:"accountCompressionProgram",isMut:0,isSigner:0},{name:"selfProgram",isMut:0,isSigner:0,docs:["this program is the signer of the cpi."]},{name:"systemProgram",isMut:0,isSigner:0}],args:[{name:"inputs",type:"bytes"}]},{name:"freeze",docs:["Freezes compressed token accounts. Inputs must not be frozen. Creates as","many outputs as inputs. Balances and delegates are preserved."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"authority",isMut:0,isSigner:1},{name:"cpiAuthorityPda",isMut:0,isSigner:0},{name:"lightSystemProgram",isMut:0,isSigner:0},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0},{name:"accountCompressionProgram",isMut:0,isSigner:0},{name:"selfProgram",isMut:0,isSigner:0,docs:["that this program is the signer of the cpi."]},{name:"systemProgram",isMut:0,isSigner:0},{name:"mint",isMut:0,isSigner:0}],args:[{name:"inputs",type:"bytes"}]},{name:"thaw",docs:["Thaws frozen compressed token accounts. Inputs must be frozen. Creates","as many outputs as inputs. Balances and delegates are preserved."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"authority",isMut:0,isSigner:1},{name:"cpiAuthorityPda",isMut:0,isSigner:0},{name:"lightSystemProgram",isMut:0,isSigner:0},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0},{name:"accountCompressionProgram",isMut:0,isSigner:0},{name:"selfProgram",isMut:0,isSigner:0,docs:["that this program is the signer of the cpi."]},{name:"systemProgram",isMut:0,isSigner:0},{name:"mint",isMut:0,isSigner:0}],args:[{name:"inputs",type:"bytes"}]},{name:"burn",docs:["Burns compressed tokens and spl tokens from the pool account. Delegates","can burn tokens. The output compressed token account remains delegated.","Creates one output compressed token account."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"authority",isMut:0,isSigner:1,docs:["Authority is verified through proof since both owner and delegate","are included in the token data hash, which is a public input to the","validity proof."]},{name:"cpiAuthorityPda",isMut:0,isSigner:0},{name:"mint",isMut:1,isSigner:0},{name:"tokenPoolPda",isMut:1,isSigner:0},{name:"tokenProgram",isMut:0,isSigner:0},{name:"lightSystemProgram",isMut:0,isSigner:0},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0},{name:"accountCompressionProgram",isMut:0,isSigner:0},{name:"selfProgram",isMut:0,isSigner:0},{name:"systemProgram",isMut:0,isSigner:0}],args:[{name:"inputs",type:"bytes"}]},{name:"stubIdlBuild",docs:["This function is a stub to allow Anchor to include the input types in","the IDL. It should not be included in production builds nor be called in","practice."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"authority",isMut:0,isSigner:1,docs:["Authority is verified through proof since both owner and delegate","are included in the token data hash, which is a public input to the","validity proof."]},{name:"cpiAuthorityPda",isMut:0,isSigner:0},{name:"lightSystemProgram",isMut:0,isSigner:0},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0},{name:"accountCompressionProgram",isMut:0,isSigner:0},{name:"selfProgram",isMut:0,isSigner:0,docs:["this program is the signer of the cpi."]},{name:"tokenPoolPda",isMut:1,isSigner:0,isOptional:1},{name:"compressOrDecompressTokenAccount",isMut:1,isSigner:0,isOptional:1},{name:"tokenProgram",isMut:0,isSigner:0,isOptional:1},{name:"systemProgram",isMut:0,isSigner:0}],args:[{name:"inputs1",type:{defined:"CompressedTokenInstructionDataTransfer"}},{name:"inputs2",type:{defined:"TokenData"}}]}],types:[{name:"AccountState",type:{kind:"enum",variants:[{name:"Initialized"},{name:"Frozen"}]}},{name:"CompressedAccount",type:{kind:"struct",fields:[{name:"owner",type:"publicKey"},{name:"lamports",type:"u64"},{name:"address",type:{option:{array:["u8",32]}}},{name:"data",type:{option:{defined:"CompressedAccountData"}}}]}},{name:"CompressedAccountData",type:{kind:"struct",fields:[{name:"discriminator",type:{array:["u8",8]}},{name:"data",type:"bytes"},{name:"dataHash",type:{array:["u8",32]}}]}},{name:"CompressedCpiContext",type:{kind:"struct",fields:[{name:"setContext",docs:["Is set by the program that is invoking the CPI to signal that is should","set the cpi context."],type:"bool"},{name:"firstSetContext",docs:["Is set to wipe the cpi context since someone could have set it before","with unrelated data."],type:"bool"},{name:"cpiContextAccountIndex",docs:["Index of cpi context account in remaining accounts."],type:"u8"}]}},{name:"CompressedProof",type:{kind:"struct",fields:[{name:"a",type:{array:["u8",32]}},{name:"b",type:{array:["u8",64]}},{name:"c",type:{array:["u8",32]}}]}},{name:"CompressedTokenInstructionDataTransfer",type:{kind:"struct",fields:[{name:"proof",type:{option:{defined:"CompressedProof"}}},{name:"mint",type:"publicKey"},{name:"delegatedTransfer",docs:["Is required if the signer is delegate,","-> delegate is authority account,","owner = Some(owner) is the owner of the token account."],type:{option:{defined:"DelegatedTransfer"}}},{name:"inputTokenDataWithContext",type:{vec:{defined:"InputTokenDataWithContext"}}},{name:"outputCompressedAccounts",type:{vec:{defined:"PackedTokenTransferOutputData"}}},{name:"isCompress",type:"bool"},{name:"compressOrDecompressAmount",type:{option:"u64"}},{name:"cpiContext",type:{option:{defined:"CompressedCpiContext"}}},{name:"lamportsChangeAccountMerkleTreeIndex",type:{option:"u8"}}]}},{name:"CompressedTokenInstructionDataRevoke",type:{kind:"struct",fields:[{name:"proof",type:{option:{defined:"CompressedProof"}}},{name:"mint",type:"publicKey"},{name:"inputTokenDataWithContext",type:{vec:{defined:"InputTokenDataWithContext"}}},{name:"cpiContext",type:{option:{defined:"CompressedCpiContext"}}},{name:"outputAccountMerkleTreeIndex",type:"u8"}]}},{name:"CompressedTokenInstructionDataApprove",type:{kind:"struct",fields:[{name:"proof",type:{option:{defined:"CompressedProof"}}},{name:"mint",type:"publicKey"},{name:"inputTokenDataWithContext",type:{vec:{defined:"InputTokenDataWithContext"}}},{name:"cpiContext",type:{option:{defined:"CompressedCpiContext"}}},{name:"delegate",type:"publicKey"},{name:"delegatedAmount",type:"u64"},{name:"delegateMerkleTreeIndex",type:"u8"},{name:"changeAccountMerkleTreeIndex",type:"u8"},{name:"delegateLamports",type:{option:"u64"}}]}},{name:"DelegatedTransfer",docs:["Struct to provide the owner when the delegate is signer of the transaction."],type:{kind:"struct",fields:[{name:"owner",type:"publicKey"},{name:"delegateChangeAccountIndex",docs:["Index of change compressed account in output compressed accounts. In","case that the delegate didn't spend the complete delegated compressed","account balance the change compressed account will be delegated to her","as well."],type:{option:"u8"}}]}},{name:"InputTokenDataWithContext",type:{kind:"struct",fields:[{name:"amount",type:"u64"},{name:"delegateIndex",type:{option:"u8"}},{name:"merkleContext",type:{defined:"PackedMerkleContext"}},{name:"rootIndex",type:"u16"},{name:"lamports",type:{option:"u64"}},{name:"tlv",docs:["Placeholder for TokenExtension tlv data (unimplemented)"],type:{option:"bytes"}}]}},{name:"InstructionDataInvoke",type:{kind:"struct",fields:[{name:"proof",type:{option:{defined:"CompressedProof"}}},{name:"inputCompressedAccountsWithMerkleContext",type:{vec:{defined:"PackedCompressedAccountWithMerkleContext"}}},{name:"outputCompressedAccounts",type:{vec:{defined:"OutputCompressedAccountWithPackedContext"}}},{name:"relayFee",type:{option:"u64"}},{name:"newAddressParams",type:{vec:{defined:"NewAddressParamsPacked"}}},{name:"compressOrDecompressLamports",type:{option:"u64"}},{name:"isCompress",type:"bool"}]}},{name:"InstructionDataInvokeCpi",type:{kind:"struct",fields:[{name:"proof",type:{option:{defined:"CompressedProof"}}},{name:"newAddressParams",type:{vec:{defined:"NewAddressParamsPacked"}}},{name:"inputCompressedAccountsWithMerkleContext",type:{vec:{defined:"PackedCompressedAccountWithMerkleContext"}}},{name:"outputCompressedAccounts",type:{vec:{defined:"OutputCompressedAccountWithPackedContext"}}},{name:"relayFee",type:{option:"u64"}},{name:"compressOrDecompressLamports",type:{option:"u64"}},{name:"isCompress",type:"bool"},{name:"cpiContext",type:{option:{defined:"CompressedCpiContext"}}}]}},{name:"MerkleTreeSequenceNumber",type:{kind:"struct",fields:[{name:"pubkey",type:"publicKey"},{name:"seq",type:"u64"}]}},{name:"NewAddressParamsPacked",type:{kind:"struct",fields:[{name:"seed",type:{array:["u8",32]}},{name:"addressQueueAccountIndex",type:"u8"},{name:"addressMerkleTreeAccountIndex",type:"u8"},{name:"addressMerkleTreeRootIndex",type:"u16"}]}},{name:"OutputCompressedAccountWithPackedContext",type:{kind:"struct",fields:[{name:"compressedAccount",type:{defined:"CompressedAccount"}},{name:"merkleTreeIndex",type:"u8"}]}},{name:"PackedCompressedAccountWithMerkleContext",type:{kind:"struct",fields:[{name:"compressedAccount",type:{defined:"CompressedAccount"}},{name:"merkleContext",type:{defined:"PackedMerkleContext"}},{name:"rootIndex",docs:["Index of root used in inclusion validity proof."],type:"u16"},{name:"readOnly",docs:["Placeholder to mark accounts read-only unimplemented set to false."],type:"bool"}]}},{name:"PackedMerkleContext",type:{kind:"struct",fields:[{name:"merkleTreePubkeyIndex",type:"u8"},{name:"queuePubkeyIndex",type:"u8"},{name:"leafIndex",type:"u32"},{name:"proveByIndex",type:"bool"}]}},{name:"PackedTokenTransferOutputData",type:{kind:"struct",fields:[{name:"owner",type:"publicKey"},{name:"amount",type:"u64"},{name:"lamports",type:{option:"u64"}},{name:"merkleTreeIndex",type:"u8"},{name:"tlv",docs:["Placeholder for TokenExtension tlv data (unimplemented)"],type:{option:"bytes"}}]}},{name:"PublicTransactionEvent",type:{kind:"struct",fields:[{name:"inputCompressedAccountHashes",type:{vec:{array:["u8",32]}}},{name:"outputCompressedAccountHashes",type:{vec:{array:["u8",32]}}},{name:"outputCompressedAccounts",type:{vec:{defined:"OutputCompressedAccountWithPackedContext"}}},{name:"outputLeafIndices",type:{vec:"u32"}},{name:"sequenceNumbers",type:{vec:{defined:"MerkleTreeSequenceNumber"}}},{name:"relayFee",type:{option:"u64"}},{name:"isCompress",type:"bool"},{name:"compressOrDecompressLamports",type:{option:"u64"}},{name:"pubkeyArray",type:{vec:"publicKey"}},{name:"message",type:{option:"bytes"}}]}},{name:"QueueIndex",type:{kind:"struct",fields:[{name:"queueId",docs:["Id of queue in queue account."],type:"u8"},{name:"index",docs:["Index of compressed account hash in queue."],type:"u16"}]}},{name:"TokenData",type:{kind:"struct",fields:[{name:"mint",docs:["The mint associated with this account"],type:"publicKey"},{name:"owner",docs:["The owner of this account."],type:"publicKey"},{name:"amount",docs:["The amount of tokens this account holds."],type:"u64"},{name:"delegate",docs:["If `delegate` is `Some` then `delegated_amount` represents","the amount authorized by the delegate"],type:{option:"publicKey"}},{name:"state",docs:["The account's state"],type:{defined:"AccountState"}},{name:"tlv",docs:["Placeholder for TokenExtension tlv data (unimplemented)"],type:{option:"bytes"}}]}}],errors:[{code:6e3,name:"PublicKeyAmountMissmatch",msg:"public keys and amounts must be of same length"},{code:6001,name:"ComputeInputSumFailed",msg:"ComputeInputSumFailed"},{code:6002,name:"ComputeOutputSumFailed",msg:"ComputeOutputSumFailed"},{code:6003,name:"ComputeCompressSumFailed",msg:"ComputeCompressSumFailed"},{code:6004,name:"ComputeDecompressSumFailed",msg:"ComputeDecompressSumFailed"},{code:6005,name:"SumCheckFailed",msg:"SumCheckFailed"},{code:6006,name:"DecompressRecipientUndefinedForDecompress",msg:"DecompressRecipientUndefinedForDecompress"},{code:6007,name:"CompressedPdaUndefinedForDecompress",msg:"CompressedPdaUndefinedForDecompress"},{code:6008,name:"DeCompressAmountUndefinedForDecompress",msg:"DeCompressAmountUndefinedForDecompress"},{code:6009,name:"CompressedPdaUndefinedForCompress",msg:"CompressedPdaUndefinedForCompress"},{code:6010,name:"DeCompressAmountUndefinedForCompress",msg:"DeCompressAmountUndefinedForCompress"},{code:6011,name:"DelegateSignerCheckFailed",msg:"DelegateSignerCheckFailed"},{code:6012,name:"MintTooLarge",msg:"Minted amount greater than u64::MAX"},{code:6013,name:"SplTokenSupplyMismatch",msg:"SplTokenSupplyMismatch"},{code:6014,name:"HeapMemoryCheckFailed",msg:"HeapMemoryCheckFailed"},{code:6015,name:"InstructionNotCallable",msg:"The instruction is not callable"},{code:6016,name:"ArithmeticUnderflow",msg:"ArithmeticUnderflow"},{code:6017,name:"HashToFieldError",msg:"HashToFieldError"},{code:6018,name:"InvalidAuthorityMint",msg:"Expected the authority to be also a mint authority"},{code:6019,name:"InvalidFreezeAuthority",msg:"Provided authority is not the freeze authority"},{code:6020,name:"InvalidDelegateIndex"},{code:6021,name:"TokenPoolPdaUndefined"},{code:6022,name:"IsTokenPoolPda",msg:"Compress or decompress recipient is the same account as the token pool pda."},{code:6023,name:"InvalidTokenPoolPda"},{code:6024,name:"NoInputTokenAccountsProvided"},{code:6025,name:"NoInputsProvided"},{code:6026,name:"MintHasNoFreezeAuthority"},{code:6027,name:"MintWithInvalidExtension"},{code:6028,name:"InsufficientTokenAccountBalance",msg:"The token account balance is less than the remaining amount."},{code:6029,name:"InvalidTokenPoolBump",msg:"Max number of token pools reached."},{code:6030,name:"FailedToDecompress"},{code:6031,name:"FailedToBurnSplTokensFromTokenPool"},{code:6032,name:"NoMatchingBumpFound"}]},exports.LIGHT_TOKEN_CONFIG=i,exports.LIGHT_TOKEN_RENT_SPONSOR=s,exports.MAX_COMBINED_BATCH_BYTES=900,exports.MAX_LOAD_ONLY_BATCH_BYTES=1e3,exports.MAX_TOP_UP=b,exports.MAX_TRANSACTION_SIZE=Gn,exports.MINT_TO_DISCRIMINATOR=d,exports.POOL_SEED=u,exports.RENT_PER_BYTE_PER_EPOCH=1,exports.REVOKE_DISCRIMINATOR=g,exports.SLOTS_PER_RENT_EPOCH=13500,exports.SPL_TOKEN_MINT_RENT_EXEMPT_BALANCE=1461600,exports.TOTAL_COMPRESSION_COST=11e3,exports.TRANSFER_DISCRIMINATOR=m,exports._getOrCreateAtaInterface=lo,exports.addSplInterfaces=go,exports.addTokenPoolAccountsLayout=ne,exports.addTokenPools=yo,exports.approve=async function(n,r,o,i,s,a,u){i=t.bn(i);const c=await n.getCompressedTokenAccountsByOwner(s.publicKey,{mint:o}),{accounts:l}=D(c.items,i),[d]=R(l,i),p=await n.getValidityProofV0(d.map((e=>({hash:e.compressedAccount.hash,tree:e.compressedAccount.treeInfo.tree,queue:e.compressedAccount.treeInfo.queue})))),m=await ve.approve({payer:r.publicKey,inputCompressedTokenAccounts:d,toAddress:a,amount:i,recentInputStateRootIndices:p.rootIndices,recentValidityProof:p.compressedProof}),{blockhash:h}=await n.getLatestBlockhash(),f=t.dedupeSigner(r,[s]),g=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:35e4}),m],r,h,f);return t.sendAndConfirmTx(n,g,u)},exports.approveAccountsLayout=ie,exports.approveAndMintTo=async function(r,o,i,s,a,u,c,l,d){c=null!=c?c:t.selectStateTreeInfo(await r.getStateTreeInfos()),l=null!=l?l:x(await M(r,i));const p=await n.getOrCreateAssociatedTokenAccount(r,o,i,a.publicKey,void 0,void 0,d,l.tokenProgram),m=await ve.approveAndMintTo({feePayer:o.publicKey,mint:i,authority:a.publicKey,authorityTokenAccount:p.address,amount:u,toPubkey:s,outputStateTreeInfo:c,tokenPoolInfo:l}),{blockhash:h}=await r.getLatestBlockhash(),f=t.dedupeSigner(o,[a]),g=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:15e4+2e4*t.toArray(u).length}),...m],o,h,f);return await t.sendAndConfirmTx(r,g,d)},exports.batchCompressLayout=Z,exports.calculateFeePayerCostAtCreation=function(e=16,t=272){return 11e3+e*I(t)},exports.checkMint=G,exports.checkSplInterfaceInfo=T,exports.checkTokenPoolInfo=function(e,t){return T(A(e),t)},exports.compress=async function(n,r,o,i,s,a,u,c,l,d){c=null!=c?c:t.selectStateTreeInfo(await n.getStateTreeInfos()),l=null!=l?l:x(await M(n,o));const p=await ve.compress({payer:r.publicKey,owner:s.publicKey,source:a,toAddress:u,amount:i,mint:o,outputStateTreeInfo:c,tokenPoolInfo:l}),m=await n.getLatestBlockhash(),h=t.dedupeSigner(r,[s]),f=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:13e4+2e4*t.toArray(i).length}),p],r,m.blockhash,h);return await t.sendAndConfirmTx(n,f,d,m)},exports.compressSplTokenAccount=async function(n,r,o,i,s,a,u,c,l){u=null!=u?u:t.selectStateTreeInfo(await n.getStateTreeInfos()),c=null!=c?c:x(await M(n,o));const d=await ve.compressSplTokenAccount({feePayer:r.publicKey,authority:i.publicKey,tokenAccount:s,mint:o,remainingAmount:a,outputStateTreeInfo:u,tokenPoolInfo:c}),p=await n.getLatestBlockhash(),m=t.dedupeSigner(r,[i]),h=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:15e4}),d],r,p.blockhash,m);return await t.sendAndConfirmTx(n,h,l,p)},exports.compressSplTokenAccountInstructionDataLayout=Q,exports.convertTokenDataToAccount=Dt,exports.createAssociatedLightTokenAccountIdempotentInstruction=pt,exports.createAssociatedLightTokenAccountInstruction=dt,exports.createAssociatedTokenAccountInterfaceIdempotentInstruction=yt,exports.createAssociatedTokenAccountInterfaceInstruction=gt,exports.createAtaInterface=async function(n,r,o,i,s=0,a,u=t.LIGHT_TOKEN_PROGRAM_ID,c,l){t.assertBetaEnabled();const d=null!=c?c:mt(u),p=zt(o,i,s,u,d),m=gt(r.publicKey,p,i,o,u,d,l);if(u.equals(t.LIGHT_TOKEN_PROGRAM_ID)){const{blockhash:o}=await n.getLatestBlockhash(),i=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:3e4}),m],r,o,[]);await t.sendAndConfirmTx(n,i,a)}else{const t=(new e.Transaction).add(m);await e.sendAndConfirmTransaction(n,t,[r],a)}return p},exports.createAtaInterfaceIdempotent=async function(n,r,o,i,s=0,a,u=t.LIGHT_TOKEN_PROGRAM_ID,c,l){t.assertBetaEnabled();const d=null!=c?c:mt(u),p=zt(o,i,s,u,d),m=yt(r.publicKey,p,i,o,u,d,l);if(u.equals(t.LIGHT_TOKEN_PROGRAM_ID)){const{blockhash:o}=await n.getLatestBlockhash(),i=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:3e4}),m],r,o,[]);await t.sendAndConfirmTx(n,i,a)}else{const t=(new e.Transaction).add(m);await e.sendAndConfirmTransaction(n,t,[r],a)}return p},exports.createAtaInterfaceIdempotentInstruction=bt,exports.createDecompressOutputState=Ae,exports.createLightTokenFreezeAccountInstruction=function(n,r,o){return new e.TransactionInstruction({programId:t.LIGHT_TOKEN_PROGRAM_ID,keys:[{pubkey:n,isSigner:0,isWritable:1},{pubkey:r,isSigner:0,isWritable:0},{pubkey:o,isSigner:1,isWritable:0}],data:nr})},exports.createLightTokenThawAccountInstruction=function(n,r,o){return new e.TransactionInstruction({programId:t.LIGHT_TOKEN_PROGRAM_ID,keys:[{pubkey:n,isSigner:0,isWritable:1},{pubkey:r,isSigner:0,isWritable:0},{pubkey:o,isSigner:1,isWritable:0}],data:rr})},exports.createLightTokenTransferCheckedInstruction=Yn,exports.createLightTokenTransferInstruction=function(n,r,o,i,s){const a=Buffer.alloc(9);a.writeUInt8(3,0),a.writeBigUInt64LE(BigInt(i),1);const u=null!=s?s:o,c=[{pubkey:n,isSigner:0,isWritable:1},{pubkey:r,isSigner:0,isWritable:1},{pubkey:o,isSigner:1,isWritable:u.equals(o)},{pubkey:e.SystemProgram.programId,isSigner:0,isWritable:0},{pubkey:u,isSigner:!u.equals(o),isWritable:1}];return new e.TransactionInstruction({programId:t.LIGHT_TOKEN_PROGRAM_ID,keys:c,data:a})},exports.createLoadAtaInstructions=Mn,exports.createMint=or,exports.createMintInstruction=Ze,exports.createMintInterface=async function(r,o,i,s,a,u=e.Keypair.generate(),c,l=t.LIGHT_TOKEN_PROGRAM_ID,d,p,m){if(t.assertBetaEnabled(),l.equals(n.TOKEN_PROGRAM_ID)||l.equals(n.TOKEN_2022_PROGRAM_ID))return or(r,o,i,a,u,c,l,s);if(!("secretKey"in i))throw new Error("mintAuthority must be a Signer for light-token mints");if(m&&!m.tree.equals(t.getDefaultAddressTreeInfo().tree))throw new Error(`addressTreeInfo ${null==m?void 0:m.tree.toString()} must be the default address tree info: ${t.getDefaultAddressTreeInfo().tree.toString()}`);const h=s&&"secretKey"in s?s.publicKey:s;m=null!=m?m:t.getBatchAddressTreeInfo(),p=null!=p?p:t.selectStateTreeInfo(await r.getStateTreeInfos());const f=Te(u.publicKey,m),g=await r.getValidityProofV2([],[{address:Uint8Array.from(f),treeInfo:m}],t.DerivationMode.standard),y=Ze(u.publicKey,a,i.publicKey,h,o.publicKey,g,m,p,d),b=t.dedupeSigner(o,[u,i]),{blockhash:I}=await r.getLatestBlockhash(),w=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),y],o,I,b),k=await t.sendAndConfirmTx(r,w);return{mint:Pe(u.publicKey)[0],transactionSignature:k}},exports.createMintToCompressedInstruction=Nn,exports.createMintToInstruction=Un,exports.createMintToInterfaceInstruction=Wn,exports.createRemoveMetadataKeyInstruction=nt,exports.createSplInterface=ho,exports.createTokenMetadata=function(e,t,n,r,o=null){return{name:e,symbol:t,uri:n,updateAuthority:null!=r?r:null,additionalMetadata:null!=o?o:null}},exports.createTokenPool=fo,exports.createTokenPoolAccountsLayout=te,exports.createTokenProgramLookupTable=async function(e,n,r,o,i){const s=await e.getSlot("finalized"),{instructions:a,address:u}=await ve.createTokenProgramLookupTable({payer:n.publicKey,authority:r.publicKey,mints:o,remainingAccounts:i,recentSlot:s}),c=t.dedupeSigner(n,[r]),l=[];for(const r of a){const o=await e.getLatestBlockhash(),i=t.buildAndSignTx([r],n,o.blockhash,c),s=await t.sendAndConfirmTx(e,i,{commitment:"finalized"},o);l.push(s)}return{txIds:l,address:u}},exports.createTransferInterfaceInstructions=Jn,exports.createTransferOutputState=ke,exports.createUnwrapInstruction=tr,exports.createUnwrapInstructions=async function(r,o,i,s,a,u,c,l,d,p,m=0){t.assertBetaEnabled(),null!=c||(c=i);let h=l;if(!h&&(h=(await M(r,s)).find((e=>e.isInitialized)),!h))throw new Error(`No initialized SPL interface found for mint: ${s.toBase58()}. Please create an SPL interface via createSplInterface().`);if(!await r.getAccountInfo(o))throw new Error(`Destination account does not exist: ${o.toBase58()}. Create it first using getOrCreateAssociatedTokenAccount or createAssociatedTokenAccountIdempotentInstruction.`);const f=zt(s,i);let g;try{g=await Wt(r,f,i,s,void 0,void 0,m)}catch(e){if(e instanceof n.TokenAccountNotFoundError)throw new Error(Pt);throw e}Ot(g,"unwrap");const y=g.parsed.amount;if(y===BigInt(0))throw new Error(Pt);const b=null!=u?BigInt(u.toString()):y;if(b===BigInt(0))throw new Error("Unwrap amount must be greater than zero.");if(b>y)throw new Error(`Insufficient light-token balance. Requested: ${b}, Available: ${y}`);const I=await Kn(r,c,g,p,m,f,null!=u?b:void 0,void 0,a),w=tr(f,o,i,s,b,h,a,c,d),k=c.equals(i)?1:2;if(0===I.length){const t=[e.ComputeBudgetProgram.setComputeUnitLimit({units:er(null)}),w];return qn(t,k,"Unwrap batch"),[t]}if(1===I.length){const t=I[0],n=[e.ComputeBudgetProgram.setComputeUnitLimit({units:er(t)}),...t.instructions,w];return qn(n,k,"Unwrap batch"),[n]}const A=[];for(let t=0;t<I.length-1;t++){const n=I[t],r=Rn(n),o=[e.ComputeBudgetProgram.setComputeUnitLimit({units:r}),...n.instructions];qn(o,k,"Unwrap batch"),A.push(o)}const v=I[I.length-1],T=[e.ComputeBudgetProgram.setComputeUnitLimit({units:er(v)}),...v.instructions,w];return qn(T,k,"Unwrap batch"),A.push(T),A},exports.createUpdateFreezeAuthorityInstruction=Ye,exports.createUpdateMetadataAuthorityInstruction=tt,exports.createUpdateMetadataFieldInstruction=et,exports.createUpdateMintAuthorityInstruction=Xe,exports.createWrapInstruction=gn,exports.decodeApproveInstructionData=function(e){const t=ce.decode(e.subarray(f.length));return Object.assign(Object.assign({},t),{proof:pe(t.proof)?null:t.proof})},exports.decodeBatchCompressInstructionData=function(e){return Z.decode(e.subarray(p.length+4))},exports.decodeCompressSplTokenAccountInstructionData=function(e){const t=Q.decode(e.subarray(h.length));return{owner:t.owner,remainingAmount:t.remainingAmount,cpiContext:t.cpiContext}},exports.decodeMintToInstructionData=function(e){return $.decode(e.subarray(d.length))},exports.decodeRevokeInstructionData=function(e){const t=le.decode(e.subarray(g.length));return Object.assign(Object.assign({},t),{proof:pe(t.proof)?null:t.proof})},exports.decodeTokenMetadata=no,exports.decodeTransferInstructionData=function(e){return j.decode(e.slice(m.length+4))},exports.decompress=async function(n,r,o,i,s,a,u,c){i=t.bn(i);const l=await n.getCompressedTokenAccountsByOwner(s.publicKey,{mint:o}),{accounts:d}=D(l.items,i),[p]=K(d,i),m=await n.getValidityProofV0(p.map((e=>({hash:e.compressedAccount.hash,tree:e.compressedAccount.treeInfo.tree,queue:e.compressedAccount.treeInfo.queue})))),h=C(u=null!=u?u:await M(n,o),i),f=await ve.decompress({payer:r.publicKey,inputCompressedTokenAccounts:p,toAddress:a,amount:i,tokenPoolInfos:h,recentInputStateRootIndices:m.rootIndices,recentValidityProof:m.compressedProof}),{blockhash:g}=await n.getLatestBlockhash(),y=t.dedupeSigner(r,[s]),b=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:35e4}),f],r,g,y);return await t.sendAndConfirmTx(n,b,c)},exports.decompressDelegated=async function(n,r,o,i,s,a,u,c){i=t.bn(i);const l=await n.getCompressedTokenAccountsByDelegate(s.publicKey,{mint:o}),{accounts:d}=D(l.items,i),[p]=K(d,i),m=await n.getValidityProofV0(p.map((e=>({hash:e.compressedAccount.hash,tree:e.compressedAccount.treeInfo.tree,queue:e.compressedAccount.treeInfo.queue})))),h=null!=u?u:C(await M(n,o),i),f=await ve.decompress({payer:r.publicKey,inputCompressedTokenAccounts:p,toAddress:a,amount:i,recentInputStateRootIndices:m.rootIndices,recentValidityProof:m.compressedProof,tokenPoolInfos:h}),{blockhash:g}=await n.getLatestBlockhash(),y=t.dedupeSigner(r,[s]),b=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:35e4}),f],r,g,y);return t.sendAndConfirmTx(n,b,c)},exports.deriveCMintAddress=Te,exports.deriveSplInterfaceInfo=v,exports.deriveTokenPoolInfo=function(e,t,n=0){return k(v(e,t,n))},exports.deserializeMint=eo,exports.encodeApproveInstructionData=me,exports.encodeBatchCompressInstructionData=Y,exports.encodeCompressSplTokenAccountInstructionData=J,exports.encodeMintToInstructionData=X,exports.encodeRevokeInstructionData=he,exports.encodeTokenMetadata=function(t){const n=r.Buffer.alloc(2e3),o=t.updateAuthority||new e.PublicKey(0),i=zr.encode({updateAuthority:o,mint:t.mint,name:r.Buffer.from(t.name),symbol:r.Buffer.from(t.symbol),uri:r.Buffer.from(t.uri),additionalMetadata:t.additionalMetadata?t.additionalMetadata.map((e=>({key:r.Buffer.from(e.key),value:r.Buffer.from(e.value)}))):[]},n);return n.subarray(0,i)},exports.encodeTransferInstructionData=ee,exports.estimateTransactionSize=Vn,exports.extractTokenMetadata=oo,exports.findMintAddress=Pe,exports.freezeAccountsLayout=ae,exports.getAccountInterface=Nt,exports.getAssociatedLightTokenAddress=function(n,r){return e.PublicKey.findProgramAddressSync([n.toBuffer(),t.LIGHT_TOKEN_PROGRAM_ID.toBuffer(),r.toBuffer()],t.LIGHT_TOKEN_PROGRAM_ID)[0]},exports.getAssociatedLightTokenAddressAndBump=function(n,r){return e.PublicKey.findProgramAddressSync([n.toBuffer(),t.LIGHT_TOKEN_PROGRAM_ID.toBuffer(),r.toBuffer()],t.LIGHT_TOKEN_PROGRAM_ID)},exports.getAssociatedTokenAddressInterface=zt,exports.getAtaInterface=Wt,exports.getAtaProgramId=mt,exports.getMintInterface=io,exports.getOrCreateAtaInterface=async function(e,n,r,o,i=0,s,a,u=t.LIGHT_TOKEN_PROGRAM_ID,c=mt(u)){return t.assertBetaEnabled(),lo(e,n,r,o,i,s,a,u,c,0)},exports.getSplInterfaceInfos=M,exports.getTokenPoolInfos=async function(e,t,n){return(await M(e,t,n)).map(k)},exports.groupAccountsByTreeType=L,exports.isSingleSplInterfaceInfo=bo,exports.isSingleTokenPoolInfo=Io,exports.loadAta=ao,exports.mergeTokenAccounts=async function(n,r,o,i,s){const a=await n.getCompressedTokenAccountsByOwner(i.publicKey,{mint:o});if(0===a.items.length)throw new Error(`No compressed token accounts found for mint ${o.toBase58()}`);if(1===a.items.length)throw new Error("Only one token account exists, nothing to merge");const{accounts:u,treeType:c}=D(a.items);let l=u,d=c;if(l.length<2){const e=c===t.TreeType.StateV2?t.TreeType.StateV1:t.TreeType.StateV2,n=a.items.filter((t=>t.compressedAccount.treeInfo.treeType===e));if(!(n.length>=2))throw 1===l.length&&1===n.length?new Error("Cannot merge accounts from different tree types (V1/V2). You have 1 V1 and 1 V2 account - nothing to merge within same type."):new Error(`Not enough accounts of the same tree type to merge. Found: ${l.length} ${d===t.TreeType.StateV1?"V1":"V2"} accounts.`);l=n,d=e}const p=l.slice(0,4),m=await n.getValidityProof(p.map((e=>t.bn(e.compressedAccount.hash)))),h=await ve.mergeTokenAccounts({payer:r.publicKey,owner:i.publicKey,inputCompressedTokenAccounts:p,mint:o,recentValidityProof:m.compressedProof,recentInputStateRootIndices:m.rootIndices}),f=[e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),...h],{blockhash:g}=await n.getLatestBlockhash(),y=t.dedupeSigner(r,[i]),b=t.buildAndSignTx(f,r,g,y);return t.sendAndConfirmTx(n,b,s)},exports.mintTo=async function(n,r,o,i,s,a,u,c){t.assertBetaEnabled();const l=s.publicKey.equals(r.publicKey)?void 0:r.publicKey,d=Un({mint:o,destination:i,amount:a,authority:s.publicKey,maxTopUp:null!=u?u:b,feePayer:l}),p=s.publicKey.equals(r.publicKey)?[]:[s],{blockhash:m}=await n.getLatestBlockhash(),h=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:2e5}),d],r,m,p);return await t.sendAndConfirmTx(n,h,c)},exports.mintTo$1=async function(n,r,o,i,s,a,u,c,l){u=null!=u?u:t.selectStateTreeInfo(await n.getStateTreeInfos()),c=null!=c?c:x(await M(n,o));const d=await ve.mintTo({feePayer:r.publicKey,mint:o,authority:s.publicKey,amount:a,toPubkey:i,outputStateTreeInfo:u,tokenPoolInfo:c}),{blockhash:p}=await n.getLatestBlockhash(),m=t.dedupeSigner(r,[s]),h=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),d],r,p,m);return t.sendAndConfirmTx(n,h,l)},exports.mintToAccountsLayout=re,exports.mintToCompressed=async function(n,r,o,i,s,a,u=3,c,l){t.assertBetaEnabled();const d=await io(n,o,null==l?void 0:l.commitment,t.LIGHT_TOKEN_PROGRAM_ID);if(!d.merkleContext)throw new Error(St);if(!d.mintContext)throw new Error("Mint does not have MintContext");const p=d.merkleContext;if(!a){const e=await n.getStateTreeInfos();a=t.selectStateTreeInfo(e)}const m=await n.getValidityProofV2([{hash:t.bn(p.hash),leafIndex:p.leafIndex,treeInfo:p.treeInfo,proveByIndex:p.proveByIndex}],[],t.DerivationMode.compressible),h=Nn(i.publicKey,r.publicKey,m,p,{supply:d.mint.supply,decimals:d.mint.decimals,mintAuthority:d.mint.mintAuthority,freezeAuthority:d.mint.freezeAuthority,splMint:d.mintContext.splMint,cmintDecompressed:d.mintContext.cmintDecompressed,version:d.mintContext.version,mintSigner:d.mintContext.mintSigner,bump:d.mintContext.bump,metadata:d.tokenMetadata?{updateAuthority:d.tokenMetadata.updateAuthority||null,name:d.tokenMetadata.name,symbol:d.tokenMetadata.symbol,uri:d.tokenMetadata.uri}:void 0},s,a,u,c),f=i.publicKey.equals(r.publicKey)?[]:[i],{blockhash:g}=await n.getLatestBlockhash(),y=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),h],r,g,f);return await t.sendAndConfirmTx(n,y,l)},exports.mintToInterface=async function(n,r,o,i,s,a,u=[],c,l){t.assertBetaEnabled();const d=await io(n,o,null==c?void 0:c.commitment,l),p=s instanceof e.PublicKey?s:s.publicKey,m=u.map((e=>e.publicKey)),h=Wn(d,i,p,r.publicKey,a,0,m),f=[];s instanceof e.PublicKey||s.publicKey.equals(r.publicKey)||f.push(s),f.push(...u);const{blockhash:g}=await n.getLatestBlockhash(),y=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:2e5}),h],r,g,f);return await t.sendAndConfirmTx(n,y,c)},exports.mintToLayout=$,exports.packCompressedTokenAccounts=W,exports.parseLightTokenCold=Ut,exports.parseLightTokenHot=Kt,exports.parseMaybeDelegatedTransfer=we,exports.parseTokenData=Ie,exports.removeMetadataKey=async function(n,r,o,i,s,a=0,u=0,c){var l,d;t.assertBetaEnabled();const p=await io(n,o,null==c?void 0:c.commitment,t.LIGHT_TOKEN_PROGRAM_ID);so(p);const m=p.merkleContext,h=null!==(d=null===(l=p.mintContext)||void 0===l?void 0:l.cmintDecompressed)&&void 0!==d&&d?null:await n.getValidityProofV2([{hash:t.bn(m.hash),leafIndex:m.leafIndex,treeInfo:m.treeInfo,proveByIndex:m.proveByIndex}],[],t.DerivationMode.compressible),f=nt(p,i.publicKey,r.publicKey,h,s,a,u),g=i.publicKey.equals(r.publicKey)?[]:[i],{blockhash:y}=await n.getLatestBlockhash(),b=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),f],r,y,g);return await t.sendAndConfirmTx(n,b,c)},exports.rentPerEpoch=I,exports.revoke=async function(n,r,o,i,s){if(L(o).size>1)throw new Error("Cannot revoke accounts from different tree types (V1/V2) in the same transaction. Revoke V1 and V2 accounts separately.");const a=await n.getValidityProofV0(o.map((e=>({hash:e.compressedAccount.hash,tree:e.compressedAccount.treeInfo.tree,queue:e.compressedAccount.treeInfo.queue}))));!function(e,t){if(!e.publicKey.equals(t[0].parsed.owner))throw new Error(`Owner ${e.publicKey.toBase58()} does not match account ${t[0].parsed.owner.toBase58()}`)}(i,o),function(e){if(e.some((e=>null===e.parsed.delegate)))throw new Error("Account is not delegated")}(o);const u=await ve.revoke({payer:r.publicKey,inputCompressedTokenAccounts:o,recentInputStateRootIndices:a.rootIndices,recentValidityProof:a.compressedProof}),{blockhash:c}=await n.getLatestBlockhash(),l=t.dedupeSigner(r,[i]),d=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),u],r,c,l);return t.sendAndConfirmTx(n,d,s)},exports.revokeAccountsLayout=se,exports.selectAccountsByPreferredTreeType=D,exports.selectInputsForAmount=Tn,exports.selectMinCompressedTokenAccountsForDecompression=function(e,t,n=4,r){const[o,i,s,a]=K(e,t,n,r);return{selectedAccounts:o,total:i,totalLamports:s,maxPossibleAmount:a}},exports.selectMinCompressedTokenAccountsForTransfer=K,exports.selectMinCompressedTokenAccountsForTransferOrPartial=U,exports.selectSmartCompressedTokenAccountsForTransfer=function(e,n,r=4,o){const i=O(e,null==o?void 0:o.treeType),[s,a,u,c]=N(i,n,r);if(B(s),a.lt(t.bn(n))){const e=i.reduce(((e,t)=>e.add(t.parsed.amount)),t.bn(0));throw s.length>=r?new Error(`Account limit exceeded: max ${c.toString()} (${r} accounts) per transaction. Total balance: ${e.toString()} (${i.length} accounts). Consider multiple transfers to spend full balance.`):new Error(`Insufficient balance. Required: ${n.toString()}, available: ${e.toString()}.`)}if(0===s.length)throw new Error(_);return[s,a,u,c]},exports.selectSmartCompressedTokenAccountsForTransferOrPartial=N,exports.selectSplInterfaceInfo=x,exports.selectSplInterfaceInfosForDecompression=C,exports.selectTokenAccountsForApprove=R,exports.selectTokenPoolInfo=function(e){return k(x(e.map(A)))},exports.selectTokenPoolInfosForDecompression=function(e,t){return C(e.map(A),t).map(k)},exports.serializeMint=function(t){var o,i;const s=[],a=r.Buffer.alloc(n.MINT_SIZE);n.MintLayout.encode({mintAuthorityOption:t.base.mintAuthority?1:0,mintAuthority:t.base.mintAuthority||new e.PublicKey(0),supply:t.base.supply,decimals:t.base.decimals,isInitialized:t.base.isInitialized,freezeAuthorityOption:t.base.freezeAuthority?1:0,freezeAuthority:t.base.freezeAuthority||new e.PublicKey(0)},a),s.push(a);const u=r.Buffer.alloc($r);jr.encode({version:t.mintContext.version,cmintDecompressed:t.mintContext.cmintDecompressed?1:0,splMint:t.mintContext.splMint},u),s.push(u),s.push(r.Buffer.from(t.mintContext.mintSigner)),s.push(r.Buffer.from([t.mintContext.bump]));const c=null!==(o=t.reserved)&&void 0!==o?o:new Uint8Array(Xr);s.push(r.Buffer.from(c));const l=null!==(i=t.accountType)&&void 0!==i?i:1;if(s.push(r.Buffer.from([l])),t.compression?s.push(function(e){const t=r.Buffer.alloc(96);let n=0;return t.writeUInt16LE(e.configAccountVersion,n),n+=2,t.writeUInt8(e.compressToPubkey,n),n+=1,t.writeUInt8(e.accountVersion,n),n+=1,t.writeUInt32LE(e.lamportsPerWrite,n),n+=4,e.compressionAuthority.toBuffer().copy(t,n),n+=32,e.rentSponsor.toBuffer().copy(t,n),n+=32,t.writeBigUInt64LE(e.lastClaimedSlot,n),n+=8,t.writeUInt32LE(e.rentExemptionPaid,n),n+=4,t.writeUInt32LE(e.reserved,n),n+=4,t.writeUInt16LE(e.rentConfig.baseRent,n),n+=2,t.writeUInt16LE(e.rentConfig.compressionCost,n),n+=2,t.writeUInt8(e.rentConfig.lamportsPerBytePerEpoch,n),n+=1,t.writeUInt8(e.rentConfig.maxFundedEpochs,n),n+=1,t.writeUInt16LE(e.rentConfig.maxTopUp,n),n+=2,t}(t.compression)):s.push(r.Buffer.alloc(96)),t.extensions&&t.extensions.length>0){s.push(r.Buffer.from([1]));const e=r.Buffer.alloc(4);e.writeUInt32LE(t.extensions.length),s.push(e);for(const e of t.extensions)s.push(r.Buffer.from([e.extensionType])),s.push(r.Buffer.from(e.data))}else s.push(r.Buffer.from([0]));return r.Buffer.concat(s)},exports.sliceLast=mo,exports.sumUpTokenAmount=ye,exports.thawAccountsLayout=ue,exports.toAccountInfo=Rt,exports.toOffChainMetadataJson=function(e){const t={name:e.name,symbol:e.symbol};return void 0!==e.description&&(t.description=e.description),void 0!==e.image&&(t.image=e.image),void 0!==e.additionalMetadata&&e.additionalMetadata.length>0&&(t.additionalMetadata=e.additionalMetadata),t},exports.toTokenPoolInfo=k,exports.transfer=async function(n,r,o,i,s,a,u){i=t.bn(i);const c=await n.getCompressedTokenAccountsByOwner(s.publicKey,{mint:o}),{accounts:l}=D(c.items,i),[d]=K(l,i),p=await n.getValidityProofV0(d.map((e=>({hash:e.compressedAccount.hash,tree:e.compressedAccount.treeInfo.tree,queue:e.compressedAccount.treeInfo.queue})))),m=await ve.transfer({payer:r.publicKey,inputCompressedTokenAccounts:d,toAddress:a,amount:i,recentInputStateRootIndices:p.rootIndices,recentValidityProof:p.compressedProof}),{blockhash:h}=await n.getLatestBlockhash(),f=t.dedupeSigner(r,[s]),g=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),m],r,h,f);return t.sendAndConfirmTx(n,g,u)},exports.transferAccountsLayout=oe,exports.transferDelegated=async function(n,r,o,i,s,a,u){i=t.bn(i);const c=await n.getCompressedTokenAccountsByDelegate(s.publicKey,{mint:o}),{accounts:l}=D(c.items,i),[d]=K(l,i),p=await n.getValidityProofV0(d.map((e=>({hash:e.compressedAccount.hash,tree:e.compressedAccount.treeInfo.tree,queue:e.compressedAccount.treeInfo.queue})))),m=await ve.transfer({payer:r.publicKey,inputCompressedTokenAccounts:d,toAddress:a,amount:i,recentInputStateRootIndices:p.rootIndices,recentValidityProof:p.compressedProof}),{blockhash:h}=await n.getLatestBlockhash(),f=t.dedupeSigner(r,[s]),g=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),m],r,h,f);return t.sendAndConfirmTx(n,g,u)},exports.transferInterface=async function(e,n,r,o,i,s,a,u=t.LIGHT_TOKEN_PROGRAM_ID,c,l,d=0,p){var m;t.assertBetaEnabled();const h=zt(o,null!==(m=null==l?void 0:l.owner)&&void 0!==m?m:s.publicKey,0,u);if(!r.equals(h))throw new Error(`Source mismatch. Expected ${h.toBase58()}, got ${r.toBase58()}`);const f=BigInt(a.toString()),g=null!=p?p:(await io(e,o)).mint.decimals,y=await Jn(e,n.publicKey,o,f,s.publicKey,i,g,Object.assign(Object.assign({},l),{wrap:d,programId:u})),b=t.dedupeSigner(n,[s]),{rest:I,last:w}=mo(y);await Promise.all(I.map((async r=>{const{blockhash:o}=await e.getLatestBlockhash(),i=t.buildAndSignTx(r,n,o,b);return t.sendAndConfirmTx(e,i,c)})));const{blockhash:k}=await e.getLatestBlockhash(),A=t.buildAndSignTx(w,n,k,b);return t.sendAndConfirmTx(e,A,c)},exports.unpackMintData=function(e){const t=eo(e instanceof r.Buffer?e:r.Buffer.from(e)),n=oo(t.extensions);return{mintContext:t.mintContext,tokenMetadata:n||void 0,extensions:t.extensions||void 0}},exports.unpackMintInterface=function(e,o,i=n.TOKEN_PROGRAM_ID){const s=o instanceof r.Buffer?o:o instanceof Uint8Array?r.Buffer.from(o):o.data;if(i.equals(t.LIGHT_TOKEN_PROGRAM_ID)){const t=eo(s),n={address:e,mintAuthority:t.base.mintAuthority,supply:t.base.supply,decimals:t.base.decimals,isInitialized:t.base.isInitialized,freezeAuthority:t.base.freezeAuthority,tlvData:r.Buffer.alloc(0)},o=oo(t.extensions),a={mint:n,programId:i,mintContext:t.mintContext,tokenMetadata:o||void 0,extensions:t.extensions||void 0,compression:t.compression};if(!a.mintContext)throw new Error("Invalid light mint: mintContext is required for LIGHT_TOKEN_PROGRAM_ID");return a}const a=o;return{mint:n.unpackMint(e,a,i),programId:i}},exports.updateFreezeAuthority=async function(n,r,o,i,s,a){var u,c;t.assertBetaEnabled();const l=await io(n,o,null==a?void 0:a.commitment,t.LIGHT_TOKEN_PROGRAM_ID);if(!l.merkleContext)throw new Error(St);const d=l.merkleContext,p=null!==(c=null===(u=l.mintContext)||void 0===u?void 0:u.cmintDecompressed)&&void 0!==c&&c?null:await n.getValidityProofV2([{hash:t.bn(d.hash),leafIndex:d.leafIndex,treeInfo:d.treeInfo,proveByIndex:d.proveByIndex}],[],t.DerivationMode.compressible),m=Ye(l,i.publicKey,s,r.publicKey,p),h=i.publicKey.equals(r.publicKey)?[]:[i],{blockhash:f}=await n.getLatestBlockhash(),g=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),m],r,f,h);return await t.sendAndConfirmTx(n,g,a)},exports.updateMetadataAuthority=async function(n,r,o,i,s,a=0,u){var c,l;t.assertBetaEnabled();const d=await io(n,o,null==u?void 0:u.commitment,t.LIGHT_TOKEN_PROGRAM_ID);so(d);const p=d.merkleContext,m=null!==(l=null===(c=d.mintContext)||void 0===c?void 0:c.cmintDecompressed)&&void 0!==l&&l?null:await n.getValidityProofV2([{hash:t.bn(p.hash),leafIndex:p.leafIndex,treeInfo:p.treeInfo,proveByIndex:p.proveByIndex}],[],t.DerivationMode.compressible),h=tt(d,i.publicKey,s,r.publicKey,m,a),f=i.publicKey.equals(r.publicKey)?[]:[i],{blockhash:g}=await n.getLatestBlockhash(),y=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),h],r,g,f);return await t.sendAndConfirmTx(n,y,u)},exports.updateMetadataField=async function(n,r,o,i,s,a,u,c=0,l){var d,p;t.assertBetaEnabled();const m=await io(n,o,null==l?void 0:l.commitment,t.LIGHT_TOKEN_PROGRAM_ID);so(m);const h=m.merkleContext,f=null!==(p=null===(d=m.mintContext)||void 0===d?void 0:d.cmintDecompressed)&&void 0!==p&&p?null:await n.getValidityProofV2([{hash:t.bn(h.hash),leafIndex:h.leafIndex,treeInfo:h.treeInfo,proveByIndex:h.proveByIndex}],[],t.DerivationMode.compressible),g=et(m,i.publicKey,r.publicKey,f,s,a,u,c),y=i.publicKey.equals(r.publicKey)?[]:[i],{blockhash:b}=await n.getLatestBlockhash(),I=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),g],r,b,y);return await t.sendAndConfirmTx(n,I,l)},exports.updateMintAuthority=async function(n,r,o,i,s,a){var u,c;t.assertBetaEnabled();const l=await io(n,o,null==a?void 0:a.commitment,t.LIGHT_TOKEN_PROGRAM_ID);if(!l.merkleContext)throw new Error(St);const d=l.merkleContext,p=null!==(c=null===(u=l.mintContext)||void 0===u?void 0:u.cmintDecompressed)&&void 0!==c&&c?null:await n.getValidityProofV2([{hash:t.bn(d.hash),leafIndex:d.leafIndex,treeInfo:d.treeInfo,proveByIndex:d.proveByIndex}],[],t.DerivationMode.compressible),m=Xe(l,i.publicKey,s,r.publicKey,p),h=i.publicKey.equals(r.publicKey)?[]:[i],{blockhash:f}=await n.getLatestBlockhash(),g=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),m],r,f,h);return await t.sendAndConfirmTx(n,g,a)},exports.validateSameTokenOwner=be,exports.wrap=async function(r,o,i,s,a,u,c,l,d,p){t.assertBetaEnabled();let m=l;if(!m&&(m=(await M(r,u)).find((e=>e.isInitialized)),!m))throw new Error(`No initialized SPL interface found for mint: ${u.toBase58()}. Please create an SPL interface via createSplInterface().`);const h=await n.getMint(r,u,void 0,m.tokenProgram),f=gn(i,s,a.publicKey,u,c,m,h.decimals,o.publicKey,d),{blockhash:g}=await r.getLatestBlockhash(),y=t.dedupeSigner(o,[a]),b=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:2e5}),f],o,g,y);return await t.sendAndConfirmTx(r,b,p)};
|
|
2
|
+
//# sourceMappingURL=types-DgmOPYyc.cjs.map
|