require(`../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../constants/chains.constants.cjs`),t=require(`../../crypto/poseidon.cjs`);require(`./keys.cjs`);const n=require(`../utxo/Utxo.cjs`);let r=require(`ethers`),i=require(`@solana/web3.js`);var a=`solana-on-chain-utxo:`,o=8,s=e=>{if(e.length!==o)throw Error(`Expected ${o} on-chain fields, received ${e.length}`);let t=e.map((e,t)=>{let n=e instanceof Uint8Array?e:Uint8Array.from(e);if(n.length!==32)throw Error(`Expected bytes32 length 32 at position ${t}, got ${n.length}`);return`0x${Buffer.from(n).toString(`hex`)}`});return`${a}${r.ethers.AbiCoder.defaultAbiCoder().encode([`bytes32[8]`],[t])}`},c=e=>e.startsWith(a),l=e=>{if(!c(e))throw Error(`Invalid encoded Solana UTXO payload`);let[n]=r.ethers.AbiCoder.defaultAbiCoder().decode([`bytes32[8]`],e.slice(21)),a=n;if(!Array.isArray(a)||a.length!==o)throw Error(`Malformed encoded Solana UTXO payload`);let[s,l,u,d,f,p,m,h]=a,g=BigInt(s),_=BigInt(d),v=r.ethers.toBeHex(BigInt(f)),y=BigInt(p),b=BigInt(m),x=BigInt(h).toString(),S=Array.from(r.ethers.getBytes(l)),C=Array.from(r.ethers.getBytes(u)),w=new i.PublicKey(Uint8Array.from([...S.slice(16),...C.slice(16)])).toBase58();return{amount:g,erc20TokenAddress:t.poseidonHash(BigInt(l),BigInt(u)),mintAddress:w,randomization:_,stealthAddress:v,H0:y,H1:b,timeStamp:x}},u=e=>{let t=r.ethers.AbiCoder.defaultAbiCoder().decode([`uint256`,`address`,`tuple(uint256, uint256, uint256, uint256)`,`uint256`,`uint256`],e);return{amount:BigInt(t[0]),erc20TokenAddress:t[1],randomization:BigInt(t[2][0]),stealthAddress:r.ethers.toBeHex(BigInt(t[2][1])),H0:BigInt(t[2][2]),H1:BigInt(t[2][3]),timeStamp:BigInt(t[3]).toString(),tokenId:Number(t[4])}},d=(t,n,r)=>{if(e.isSolanaLike(r)){let{amount:e,erc20TokenAddress:r,mintAddress:i,randomization:a,stealthAddress:o,timeStamp:s}=l(t);return{amount:e,erc20TokenAddress:r,mintAddress:i,timeStamp:s,tokenId:0,randomization:a,shieldedPrivateKey:n,stealthAddress:o}}let{amount:i,erc20TokenAddress:a,timeStamp:o,tokenId:s,randomization:c,stealthAddress:d}=u(t);return{amount:i,erc20TokenAddress:a,timeStamp:o,tokenId:s,randomization:c,shieldedPrivateKey:n,stealthAddress:d}},f=(e,t,r)=>new n.Utxo(d(e,t,r));exports.abiDecodeUtxo=u,exports.decodeSolanaOnChainUtxo=l,exports.decodeUtxo=f,exports.decodeUtxoConstructorArgs=d,exports.encodeSolanaOnChainUtxo=s,exports.isSolanaOnChainUtxo=c;