UNPKG

@sega-so/sega-sdk

Version:

An SDK for building applications on top of SEGA.

2 lines 41.5 kB
var wt=Object.defineProperty,St=Object.defineProperties;var Bt=Object.getOwnPropertyDescriptors;var he=Object.getOwnPropertySymbols;var Je=Object.prototype.hasOwnProperty,Xe=Object.prototype.propertyIsEnumerable;var Ye=(n,e,t)=>e in n?wt(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,M=(n,e)=>{for(var t in e||(e={}))Je.call(e,t)&&Ye(n,t,e[t]);if(he)for(var t of he(e))Xe.call(e,t)&&Ye(n,t,e[t]);return n},G=(n,e)=>St(n,Bt(e));var ye=(n,e)=>{var t={};for(var r in n)Je.call(n,r)&&e.indexOf(r)<0&&(t[r]=n[r]);if(n!=null&&he)for(var r of he(n))e.indexOf(r)<0&&Xe.call(n,r)&&(t[r]=n[r]);return t};var P=(n,e,t)=>new Promise((r,f)=>{var i=h=>{try{o(t.next(h))}catch(y){f(y)}},s=h=>{try{o(t.throw(h))}catch(y){f(y)}},o=h=>h.done?r(h.value):Promise.resolve(h.value).then(i,s);o((t=t.apply(n,e)).next())});import{PublicKey as an,Transaction as He,TransactionInstruction as un}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as cn}from"@solana/spl-token";import xt from"bn.js";import{PublicKey as It}from"@solana/web3.js";import{get as Ze,set as kt}from"lodash";var Ne=class{constructor(e){this.logLevel=e.logLevel!==void 0?e.logLevel:0,this.name=e.name}set level(e){this.logLevel=e}get time(){return Date.now().toString()}get moduleName(){return this.name}isLogLevel(e){return e<=this.logLevel}error(...e){return this.isLogLevel(0)?(console.error(this.time,this.name,"sdk logger error",...e),this):this}logWithError(...e){let t=e.map(r=>typeof r=="object"?JSON.stringify(r):r).join(", ");throw new Error(t)}warning(...e){return this.isLogLevel(1)?(console.warn(this.time,this.name,"sdk logger warning",...e),this):this}info(...e){return this.isLogLevel(2)?(console.info(this.time,this.name,"sdk logger info",...e),this):this}debug(...e){return this.isLogLevel(3)?(console.debug(this.time,this.name,"sdk logger debug",...e),this):this}},$e={},At={};function F(n){let e=Ze($e,n);if(!e){let t=Ze(At,n);e=new Ne({name:n,logLevel:t}),kt($e,n,e)}return e}import{MINT_SIZE as xn,TOKEN_PROGRAM_ID as Pn,getTransferFeeConfig as wn,unpackMint as Sn}from"@solana/spl-token";var Oe=F("Sega_accountInfo_util");function be(n,e,t){return P(this,null,function*(){let{batchRequest:r,commitment:f="confirmed",chunkCount:i=100}=M({batchRequest:!1},t),s=De(e,i),o=new Array(s.length).fill([]);if(r){let h=s.map(u=>({methodName:"getMultipleAccounts",args:n._buildArgs([u.map(b=>b.toBase58())],f,"base64")})),y=De(h,10);o=(yield(yield Promise.all(y.map(u=>P(this,null,function*(){return yield n._rpcBatchRequest(u)})))).flat()).map(u=>(u.error&&Oe.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${u.error.message}`),u.result.value.map(S=>{if(S){let{data:b,executable:d,lamports:T,owner:a,rentEpoch:A}=S;return b.length!==2&&b[1]!=="base64"&&Oe.logWithError("info must be base64 encoded, RPC_ERROR"),{data:Buffer.from(b[0],"base64"),executable:d,lamports:T,owner:new It(a),rentEpoch:A}}return null})))}else try{o=yield Promise.all(s.map(h=>n.getMultipleAccountsInfo(h,f)))}catch(h){h instanceof Error&&Oe.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${h.message}`)}return o.flat()})}import q from"bn.js";import To from"decimal.js";import Mt from"big.js";import Un from"bn.js";import Lt from"toformat";var Ct=Lt,re=Ct;import xe from"big.js";import Ot from"bn.js";import Dt from"decimal.js-light";import oe from"bn.js";var Qe=9007199254740991;function v(n){let e=F("Sega_parseBigNumberish");if(n instanceof oe)return n;if(typeof n=="string"){if(n.match(/^-?[0-9]+$/))return new oe(n);e.logWithError(`invalid BigNumberish string: ${n}`)}return typeof n=="number"?(n%1&&e.logWithError(`BigNumberish number underflow: ${n}`),(n>=Qe||n<=-Qe)&&e.logWithError(`BigNumberish number overflow: ${n}`),new oe(String(n))):typeof n=="bigint"?new oe(n.toString()):(e.error(`invalid BigNumberish value: ${n}`),new oe(0))}var Te=F("module/fraction"),Re=re(xe),ie=re(Dt),Et={0:ie.ROUND_DOWN,1:ie.ROUND_HALF_UP,2:ie.ROUND_UP},Rt={0:xe.roundDown,1:xe.roundHalfUp,2:xe.roundUp},U=class n{constructor(e,t=new Ot(1)){this.numerator=v(e),this.denominator=v(t)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new n(this.denominator,this.numerator)}add(e){let t=e instanceof n?e:new n(v(e));return this.denominator.eq(t.denominator)?new n(this.numerator.add(t.numerator),this.denominator):new n(this.numerator.mul(t.denominator).add(t.numerator.mul(this.denominator)),this.denominator.mul(t.denominator))}sub(e){let t=e instanceof n?e:new n(v(e));return this.denominator.eq(t.denominator)?new n(this.numerator.sub(t.numerator),this.denominator):new n(this.numerator.mul(t.denominator).sub(t.numerator.mul(this.denominator)),this.denominator.mul(t.denominator))}mul(e){let t=e instanceof n?e:new n(v(e));return new n(this.numerator.mul(t.numerator),this.denominator.mul(t.denominator))}div(e){let t=e instanceof n?e:new n(v(e));return new n(this.numerator.mul(t.denominator),this.denominator.mul(t.numerator))}toSignificant(e,t={groupSeparator:""},r=1){Number.isInteger(e)||Te.logWithError(`${e} is not an integer.`),e<=0&&Te.logWithError(`${e} is not positive.`),ie.set({precision:e+1,rounding:Et[r]});let f=new ie(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(e);return f.toFormat(f.decimalPlaces(),t)}toFixed(e,t={groupSeparator:""},r=1){return Number.isInteger(e)||Te.logWithError(`${e} is not an integer.`),e<0&&Te.logWithError(`${e} is negative.`),Re.DP=e,Re.RM=Rt[r]||1,new Re(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,t)}isZero(){return this.numerator.isZero()}};var Zn=F("Sega_amount"),$n=re(Mt);import{PublicKey as _t}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as et}from"@solana/spl-token";var tt={chainId:101,address:_t.default.toBase58(),programId:et.toBase58(),decimals:9,symbol:"SOL",name:"solana",logoURI:"https://img-v1.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"sega",extensions:{coingeckoId:"solana"}},Y={chainId:101,address:"So11111111111111111111111111111111111111112",programId:et.toBase58(),decimals:9,symbol:"WSOL",name:"Wrapped SOL",logoURI:"https://img-v1.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"sega",extensions:{coingeckoId:"solana"}};import{PublicKey as Fe}from"@solana/web3.js";import{PublicKey as N,SystemProgram as nt,SYSVAR_RENT_PUBKEY as Kt}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Vt}from"@solana/spl-token";function Me({pubkey:n,isSigner:e=!1,isWritable:t=!0}){return{pubkey:n,isWritable:t,isSigner:e}}var sr=[Me({pubkey:Vt,isWritable:!1}),Me({pubkey:nt.programId,isWritable:!1}),Me({pubkey:Kt,isWritable:!1})];function rt({publicKey:n,transformSol:e}){let t=ot(n.toString());if(t instanceof N)return e&&t.equals(se)?Ee:t;if(e&&t.toString()===se.toBase58())return Ee;if(typeof t=="string"){if(t===N.default.toBase58())return N.default;try{return new N(t)}catch(r){throw new Error("invalid public key")}}throw new Error("invalid public key")}function ot(n){try{return new N(n)}catch(e){return n}}var ar=new N("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),ur=new N("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),cr=new N("SysvarRent111111111111111111111111111111111"),lr=new N("SysvarC1ock11111111111111111111111111111111"),Wt=new N("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),mr=new N("Sysvar1nstructions1111111111111111111111111"),pr=nt.programId,dr=new N("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),fr=new N("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),gr=new N("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),hr=new N("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),yr=new N("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),br=new N("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),Tr=new N("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),xr=new N("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),Pr=new N("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),wr=new N("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),Sr=new N("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),Ee=new N("So11111111111111111111111111111111111111112"),se=N.default;var Pe=class Pe{constructor({mint:e,decimals:t,symbol:r,name:f,skipMint:i=!1,isToken2022:s=!1}){if(e===se.toBase58()||e instanceof Fe&&se.equals(e)){this.decimals=Y.decimals,this.symbol=Y.symbol,this.name=Y.name,this.mint=new Fe(Y.address),this.isToken2022=!1;return}this.decimals=t,this.symbol=r||e.toString().substring(0,6),this.name=f||e.toString().substring(0,6),this.mint=i?Fe.default:rt({publicKey:e}),this.isToken2022=s}equals(e){return this===e?!0:this.mint.equals(e.mint)}};Pe.WSOL=new Pe(G(M({},Y),{mint:Y.address}));var K=Pe;var we=class we{constructor({decimals:e,symbol:t="UNKNOWN",name:r="UNKNOWN"}){this.decimals=e,this.symbol=t,this.name=r}equals(e){return this===e}};we.SOL=new we(tt);var _e=we;import vt from"bn.js";var Fr=new U(new vt(100));var Ur=F("Sega_price");import{PublicKey as io}from"@solana/web3.js";import ao from"bn.js";var Ut=new q(0),Co=new q(1),No=new q(2),Oo=new q(3),Do=new q(5),Ft=new q(10),Eo=new q(100),Ro=new q(1e3),Mo=new q(1e4);function De(n,e=1,t=[]){let r=[...n];if(e<=0)return t;for(;r.length;)t.push(r.splice(0,e));return t}import{PublicKey as ei}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as ni}from"@solana/spl-token";import{ComputeBudgetProgram as ut,Keypair as lt,PublicKey as qt,Transaction as mt,TransactionMessage as Gt,VersionedTransaction as pt}from"@solana/web3.js";var ae={CreateAccount:"CreateAccount",InitAccount:"InitAccount",CreateATA:"CreateATA",CloseAccount:"CloseAccount",TransferAmount:"TransferAmount",InitMint:"InitMint",MintTo:"MintTo",InitMarket:"InitMarket",Util1216OwnerClaim:"Util1216OwnerClaim",SetComputeUnitPrice:"SetComputeUnitPrice",SetComputeUnitLimit:"SetComputeUnitLimit",ClmmCreatePool:"ClmmCreatePool",ClmmOpenPosition:"ClmmOpenPosition",ClmmIncreasePosition:"ClmmIncreasePosition",ClmmDecreasePosition:"ClmmDecreasePosition",ClmmClosePosition:"ClmmClosePosition",ClmmSwapBaseIn:"ClmmSwapBaseIn",ClmmSwapBaseOut:"ClmmSwapBaseOut",ClmmInitReward:"ClmmInitReward",ClmmSetReward:"ClmmSetReward",ClmmCollectReward:"ClmmCollectReward",ClmmLockPosition:"ClmmLockPosition",ClmmHarvestLockPosition:"ClmmHarvestLockPosition",AmmV4Swap:"AmmV4Swap",AmmV4AddLiquidity:"AmmV4AddLiquidity",AmmV4RemoveLiquidity:"AmmV4RemoveLiquidity",AmmV4SimulatePoolInfo:"AmmV4SimulatePoolInfo",AmmV4SwapBaseIn:"AmmV4SwapBaseIn",AmmV4SwapBaseOut:"AmmV4SwapBaseOut",AmmV4CreatePool:"AmmV4CreatePool",AmmV4InitPool:"AmmV4InitPool",AmmV5AddLiquidity:"AmmV5AddLiquidity",AmmV5RemoveLiquidity:"AmmV5RemoveLiquidity",AmmV5SimulatePoolInfo:"AmmV5SimulatePoolInfo",AmmV5SwapBaseIn:"AmmV5SwapBaseIn",AmmV5SwapBaseOut:"AmmV5SwapBaseOut",RouteSwap:"RouteSwap",RouteSwap1:"RouteSwap1",RouteSwap2:"RouteSwap2",FarmV3Deposit:"FarmV3Deposit",FarmV3Withdraw:"FarmV3Withdraw",FarmV3CreateLedger:"FarmV3CreateLedger",FarmV4Withdraw:"FarmV4Withdraw",FarmV5Deposit:"FarmV5Deposit",FarmV5Withdraw:"FarmV5Withdraw",FarmV5CreateLedger:"FarmV5CreateLedger",FarmV6Deposit:"FarmV6Deposit",FarmV6Withdraw:"FarmV6Withdraw",FarmV6Create:"FarmV6Create",FarmV6Restart:"FarmV6Restart",FarmV6CreatorAddReward:"FarmV6CreatorAddReward",FarmV6CreatorWithdraw:"FarmV6CreatorWithdraw",CpmmCreatePool:"CpmmCreatePool",CpmmAddLiquidity:"CpmmAddLiquidity",CpmmWithdrawLiquidity:"CpmmWithdrawLiquidity",CpmmSwapBaseIn:"CpmmSwapBaseIn",CpmmSwapBaseOut:"CpmmSwapBaseOut",CpmmLockLp:"CpmmLockLp",CpmmCollectLockFee:"CpmmCollectLockFee",TransferTip:"TransferTip"};import{TOKEN_PROGRAM_ID as jt}from"@solana/spl-token";var ct=F("Sega_txUtil"),dt=1644;function Se(n){let e=[],t=[];return n.microLamports&&(e.push(ut.setComputeUnitPrice({microLamports:n.microLamports})),t.push(ae.SetComputeUnitPrice)),n.units&&(e.push(ut.setComputeUnitLimit({units:n.units})),t.push(ae.SetComputeUnitLimit)),{instructions:e,instructionTypes:t}}function $(n,e){return P(this,null,function*(){var r,f;let t=e!=null?e:"confirmed";return(f=yield(r=n.getLatestBlockhash)==null?void 0:r.call(n,{commitment:t}))==null?void 0:f.blockhash})}function Be(n,e){return P(this,null,function*(){return n.getSignatureStatuses([e]),new Promise((t,r)=>{let f=setTimeout(r,6e4);n.onSignature(e,i=>{if(clearTimeout(f),!i.err){t("");return}r(Object.assign(i.err,{txId:e}))},"confirmed")})})}function Ke(n,e){n.length<1&&ct.logWithError(`no instructions provided: ${n.toString()}`),e.length<1&&ct.logWithError(`no signers provided:, ${e.toString()}`);let t=new mt;t.recentBlockhash="11111111111111111111111111111111",t.feePayer=e[0],t.add(...n);try{return Buffer.from(t.serialize({verifySignatures:!1})).toString("base64").length<dt}catch(r){return!1}}function ke(n,e){let[t,r]=qt.findProgramAddressSync(n,e);return{publicKey:t,nonce:r}}function ue({instructions:n,payer:e,signers:t}){return Ke(n,[e,...t])}function ce({instructions:n,payer:e,lookupTableAddressAccount:t,recentBlockhash:r=lt.generate().publicKey.toString()}){let i=new Gt({payerKey:e,recentBlockhash:r,instructions:n}).compileToV0Message(Object.values(t!=null?t:{}));try{return Buffer.from(new pt(i).serialize()).toString("base64").length<dt}catch(s){return!1}}var Ht=n=>Buffer.isBuffer(n)?n:n instanceof Uint8Array?Buffer.from(n.buffer,n.byteOffset,n.byteLength):Buffer.from(n),zt=n=>{let e=n.serialize({requireAllSignatures:!1,verifySignatures:!1});n instanceof pt&&(e=Ht(e));try{return e instanceof Buffer?e.toString("base64"):Buffer.from(e).toString("base64")}catch(t){return e.toString("base64")}};function J(n){let e=[];return n.forEach(t=>{t instanceof mt&&(t.recentBlockhash||(t.recentBlockhash=jt.toBase58()),t.feePayer||(t.feePayer=lt.generate().publicKey)),e.push(zt(t))}),console.log("simulate tx string:",e),e}import{PublicKey as j}from"@solana/web3.js";var ai=new j("SegazTQwbYWknDZkJ6j2Kgvm5gw3MrHGKtWstZdoNKZ"),ui=new j("Ajk8d9bERSaFdeoT1d8JUVfaDayrYLnAdgeB47TFMUaG"),ci=new j("2HbjxVVKJ7Ct72Rcd8WK4VTqmwTXL5aAggkH1CHGFGmh"),Yt=new j("auetiVUVJkRxvNPLYEvVnz8UJSqQ1VgoA83PcicHVD1"),Jt=new j("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),Xt=new j("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y");var li={SERUM_MARKET:j.default,UTIL1216:j.default,CREATE_CPMM_POOL_PROGRAM:Yt,CREATE_CPMM_POOL_AUTH:Jt,CREATE_CPMM_POOL_FEE_ACC:Xt};import di from"bn.js";import{PublicKey as Zt,AddressLookupTableAccount as ft}from"@solana/web3.js";function Ve(t){return P(this,arguments,function*({connection:n,address:e}){let r=yield be(n,[...new Set(e.map(i=>i.toString()))].map(i=>new Zt(i))),f={};for(let i=0;i<e.length;i++){let s=r[i],o=e[i];if(!s)continue;let h=new ft({key:o,state:ft.deserialize(s.data)});f[o.toString()]=h,Ae[o.toString()]=h}return f})}var Ae={};import{PublicKey as Q,sendAndConfirmTransaction as We,SystemProgram as $t,Transaction as le,TransactionMessage as me,VersionedTransaction as pe}from"@solana/web3.js";import Qt from"axios";var Ie=2e3,Le=class{constructor(e){this.instructions=[];this.endInstructions=[];this.lookupTableAddress=[];this.signers=[];this.instructionTypes=[];this.endInstructionTypes=[];this.connection=e.connection,this.feePayer=e.feePayer,this.signAllTransactions=e.signAllTransactions,this.owner=e.owner,this.cluster=e.cluster,this.blockhashCommitment=e.blockhashCommitment,this.loopMultiTxStatus=!!e.loopMultiTxStatus}get AllTxData(){return{instructions:this.instructions,endInstructions:this.endInstructions,signers:this.signers,instructionTypes:this.instructionTypes,endInstructionTypes:this.endInstructionTypes,lookupTableAddress:this.lookupTableAddress}}get allInstructions(){return[...this.instructions,...this.endInstructions]}getComputeBudgetConfig(){return P(this,null,function*(){var r;let e=(yield Qt.get("https://solanacompass.com/api/fees?cacheFreshTime=300000")).data,{avg:t}=(r=e==null?void 0:e[15])!=null?r:{};if(t)return{units:6e5,microLamports:Math.min(Math.ceil(t*1e6/6e5),25e3)}})}addCustomComputeBudget(e){if(e){let{instructions:t,instructionTypes:r}=Se(e);return this.instructions.unshift(...t),this.instructionTypes.unshift(...r),!0}return!1}addTipInstruction(e){var t;return e?(this.endInstructions.push($t.transfer({fromPubkey:(t=e.feePayer)!=null?t:this.feePayer,toPubkey:new Q(e.address),lamports:BigInt(e.amount.toString())})),this.endInstructionTypes.push(ae.TransferTip),!0):!1}calComputeBudget(r){return P(this,arguments,function*({config:e,defaultIns:t}){try{let f=e||(yield this.getComputeBudgetConfig());if(this.addCustomComputeBudget(f))return;t&&this.instructions.unshift(...t)}catch(f){t&&this.instructions.unshift(...t)}})}addInstruction({instructions:e=[],endInstructions:t=[],signers:r=[],instructionTypes:f=[],endInstructionTypes:i=[],lookupTableAddress:s=[]}){return this.instructions.push(...e),this.endInstructions.push(...t),this.signers.push(...r),this.instructionTypes.push(...f),this.endInstructionTypes.push(...i),this.lookupTableAddress.push(...s.filter(o=>o!==Q.default.toString())),this}versionBuild(r){return P(this,arguments,function*({txVersion:e,extInfo:t}){return e===0?yield this.buildV0(M({},t||{})):this.build(t)})}build(e){var r;let t=new le;return this.allInstructions.length&&t.add(...this.allInstructions),t.feePayer=this.feePayer,(r=this.owner)!=null&&r.signer&&!this.signers.some(f=>f.publicKey.equals(this.owner.publicKey))&&this.signers.push(this.owner.signer),{builder:this,transaction:t,signers:this.signers,instructionTypes:[...this.instructionTypes,...this.endInstructionTypes],execute:f=>P(this,null,function*(){var y;let{recentBlockHash:i,skipPreflight:s=!0,sendAndConfirm:o}=f||{},h=i!=null?i:yield $(this.connection,this.blockhashCommitment);if(t.recentBlockhash=h,this.signers.length&&t.sign(...this.signers),J([t]),(y=this.owner)!=null&&y.isKeyPair)return{txId:o?yield We(this.connection,t,this.signers.find(u=>u.publicKey.equals(this.owner.publicKey))?this.signers:[...this.signers,this.owner.signer],{skipPreflight:s}):yield this.connection.sendRawTransaction(t.serialize(),{skipPreflight:s}),signedTx:t};if(this.signAllTransactions){let p=yield this.signAllTransactions([t]);if(this.signers.length)for(let u of p)try{u.sign(...this.signers)}catch(S){}return{txId:yield this.connection.sendRawTransaction(p[0].serialize(),{skipPreflight:s}),signedTx:p[0]}}throw new Error("please provide owner in keypair format or signAllTransactions function")}),extInfo:e||{}}}buildMultiTx(e){var y;let{extraPreBuildData:t=[],extInfo:r}=e,{transaction:f}=this.build(r),i=t.filter(p=>p.transaction.instructions.length>0),s=[f,...i.map(p=>p.transaction)],o=[this.signers,...i.map(p=>p.signers)],h=[...this.instructionTypes,...i.map(p=>p.instructionTypes).flat()];return(y=this.owner)!=null&&y.signer&&o.forEach(p=>{p.some(u=>u.publicKey.equals(this.owner.publicKey))||this.signers.push(this.owner.signer)}),{builder:this,transactions:s,signers:o,instructionTypes:h,execute:p=>P(this,null,function*(){var A;let{sequentially:u,onTxUpdate:S,skipTxCount:b=0,recentBlockHash:d,skipPreflight:T=!0}=p||{},a=d!=null?d:yield $(this.connection,this.blockhashCommitment);if((A=this.owner)!=null&&A.isKeyPair){if(u){let g=[],k=0;for(let m of s){if(++k,k<=b)continue;let l=yield We(this.connection,m,this.signers.find(c=>c.publicKey.equals(this.owner.publicKey))?this.signers:[...this.signers,this.owner.signer],{skipPreflight:T});g.push(l)}return{txIds:g,signedTxs:s}}return{txIds:yield yield Promise.all(s.map(g=>P(this,null,function*(){return g.recentBlockhash=a,yield this.connection.sendRawTransaction(g.serialize(),{skipPreflight:T})}))),signedTxs:s}}if(this.signAllTransactions){let g=s.map((m,l)=>(m.recentBlockhash=a,o[l].length&&m.sign(...o[l]),m));J(g);let k=yield this.signAllTransactions(g);if(u){let m=0,l=[],c=()=>P(this,null,function*(){if(!k[m])return;let w=yield this.connection.sendRawTransaction(k[m].serialize(),{skipPreflight:T});l.push({txId:w,status:"sent",signedTx:k[m]}),S==null||S([...l]),m++;let x=!1,B=null,I=null,D=L=>{B!==null&&clearInterval(B),I!==null&&this.connection.removeSignatureListener(I);let C=l.findIndex(E=>E.txId===w);if(C>-1){if(l[C].status==="error"||l[C].status==="success")return;l[C].status=L.err?"error":"success"}S==null||S([...l]),L.err||c()};this.loopMultiTxStatus&&(B=setInterval(()=>P(this,null,function*(){var L;if(x){clearInterval(B);return}try{let C=yield this.connection.getTransaction(w,{commitment:"confirmed",maxSupportedTransactionVersion:0});C&&(x=!0,clearInterval(B),D({err:((L=C.meta)==null?void 0:L.err)||null}),console.log("tx status from getTransaction:",w))}catch(C){x=!0,clearInterval(B),console.error("getTransaction timeout:",C,w)}}),Ie)),I=this.connection.onSignature(w,L=>{if(x){this.connection.removeSignatureListener(I);return}x=!0,D(L)},"confirmed"),this.connection.getSignatureStatus(w)});return yield c(),{txIds:l.map(w=>w.txId),signedTxs:k}}else{let m=[];for(let l=0;l<k.length;l+=1){let c=yield this.connection.sendRawTransaction(k[l].serialize(),{skipPreflight:T});m.push(c)}return{txIds:m,signedTxs:k}}}throw new Error("please provide owner in keypair format or signAllTransactions function")}),extInfo:r||{}}}versionMultiBuild(f){return P(this,arguments,function*({extraPreBuildData:e,txVersion:t,extInfo:r}){return t===0?yield this.buildV0MultiTx({extraPreBuildData:e,buildProps:r||{}}):this.buildMultiTx({extraPreBuildData:e,extInfo:r})})}buildV0(e){return P(this,null,function*(){var T;let d=e||{},{lookupTableCache:t={},lookupTableAddress:r=[],forerunCreate:f,recentBlockhash:i}=d,s=ye(d,["lookupTableCache","lookupTableAddress","forerunCreate","recentBlockhash"]),o=M(M({},this.cluster==="devnet"?{}:Ae),t),h=Array.from(new Set([...r,...this.lookupTableAddress])),y=[];for(let a of h)o[a]===void 0&&y.push(new Q(a));let p=yield Ve({connection:this.connection,address:y});for(let[a,A]of Object.entries(p))o[a]=A;let u=f?Q.default.toBase58():i!=null?i:yield $(this.connection,this.blockhashCommitment),S=new me({payerKey:this.feePayer,recentBlockhash:u,instructions:[...this.allInstructions]}).compileToV0Message(Object.values(o));(T=this.owner)!=null&&T.signer&&!this.signers.some(a=>a.publicKey.equals(this.owner.publicKey))&&this.signers.push(this.owner.signer);let b=new pe(S);return b.sign(this.signers),{builder:this,transaction:b,signers:this.signers,instructionTypes:[...this.instructionTypes,...this.endInstructionTypes],execute:a=>P(this,null,function*(){var k;let{skipPreflight:A=!0,sendAndConfirm:g}=a||{};if(J([b]),(k=this.owner)!=null&&k.isKeyPair){let m=yield this.connection.sendTransaction(b,{skipPreflight:A});return g&&(yield Be(this.connection,m)),{txId:m,signedTx:b}}if(this.signAllTransactions){let m=yield this.signAllTransactions([b]);if(this.signers.length)for(let l of m)try{l.sign(this.signers)}catch(c){}return{txId:yield this.connection.sendTransaction(m[0],{skipPreflight:A}),signedTx:m[0]}}throw new Error("please provide owner in keypair format or signAllTransactions function")}),extInfo:s||{}}})}buildV0MultiTx(e){return P(this,null,function*(){var y;let{extraPreBuildData:t=[],buildProps:r}=e,{transaction:f}=yield this.buildV0(r),i=t.filter(p=>p.builder.instructions.length>0),s=[f,...i.map(p=>p.transaction)],o=[this.signers,...i.map(p=>p.signers)],h=[...this.instructionTypes,...i.map(p=>p.instructionTypes).flat()];return(y=this.owner)!=null&&y.signer&&o.forEach(p=>{p.some(u=>u.publicKey.equals(this.owner.publicKey))||this.signers.push(this.owner.signer)}),s.forEach((p,u)=>P(this,null,function*(){p.sign(o[u])})),{builder:this,transactions:s,signers:o,instructionTypes:h,buildProps:r,execute:p=>P(this,null,function*(){var T;let{sequentially:u,onTxUpdate:S,recentBlockHash:b,skipPreflight:d=!0}=p||{};if(b&&s.forEach(a=>a.message.recentBlockhash=b),J(s),(T=this.owner)!=null&&T.isKeyPair){if(u){let a=[];for(let A of s){let g=yield this.connection.sendTransaction(A,{skipPreflight:d});yield Be(this.connection,g),a.push(g)}return{txIds:a,signedTxs:s}}return{txIds:yield Promise.all(s.map(a=>P(this,null,function*(){return yield this.connection.sendTransaction(a,{skipPreflight:d})}))),signedTxs:s}}if(this.signAllTransactions){let a=yield this.signAllTransactions(s);if(u){let A=0,g=[],k=()=>P(this,null,function*(){if(!a[A])return;let m=yield this.connection.sendTransaction(a[A],{skipPreflight:d});g.push({txId:m,status:"sent",signedTx:a[A]}),S==null||S([...g]),A++;let l=!1,c=null,w=null,x=B=>{c!==null&&clearInterval(c),w!==null&&this.connection.removeSignatureListener(w);let I=g.findIndex(D=>D.txId===m);if(I>-1){if(g[I].status==="error"||g[I].status==="success")return;g[I].status=B.err?"error":"success"}S==null||S([...g]),B.err||k()};this.loopMultiTxStatus&&(c=setInterval(()=>P(this,null,function*(){var B;if(l){clearInterval(c);return}try{let I=yield this.connection.getTransaction(m,{commitment:"confirmed",maxSupportedTransactionVersion:0});I&&(l=!0,clearInterval(c),x({err:((B=I.meta)==null?void 0:B.err)||null}),console.log("tx status from getTransaction:",m))}catch(I){l=!0,clearInterval(c),console.error("getTransaction timeout:",I,m)}}),Ie)),w=this.connection.onSignature(m,B=>{if(l){this.connection.removeSignatureListener(w);return}l=!0,x(B)},"confirmed"),this.connection.getSignatureStatus(m)});return k(),{txIds:[],signedTxs:a}}else{let A=[];for(let g=0;g<a.length;g+=1){let k=yield this.connection.sendTransaction(a[g],{skipPreflight:d});A.push(k)}return{txIds:A,signedTxs:a}}}throw new Error("please provide owner in keypair format or signAllTransactions function")}),extInfo:r||{}}})}sizeCheckBuild(e){return P(this,null,function*(){var S;let u=e||{},{splitIns:t=[],computeBudgetConfig:r}=u,f=ye(u,["splitIns","computeBudgetConfig"]),i=r?Se(r):{instructions:[],instructionTypes:[]},s=this.signers.reduce((b,d)=>G(M({},b),{[d.publicKey.toBase58()]:d}),{}),o=[],h=[],y=[],p=0;if(this.allInstructions.forEach(b=>{let d=[...y,b],T=r?[...i.instructions,...d]:d,A=[...new Set(d.map(g=>g.keys.filter(k=>k.isSigner).map(k=>k.pubkey.toString())).flat()).values()].map(g=>new Q(g));if(b!==t[p]&&y.length<12&&(ue({instructions:T,payer:this.feePayer,signers:A})||ue({instructions:d,payer:this.feePayer,signers:A})))y.push(b);else{if(y.length===0)throw Error("item ins too big");p+=b===t[p]?1:0,ue({instructions:r?[...i.instructions,...y]:[...y],payer:this.feePayer,signers:A})?o.push(new le().add(...i.instructions,...y)):o.push(new le().add(...y)),h.push(Array.from(new Set(y.map(g=>g.keys.filter(k=>k.isSigner).map(k=>k.pubkey.toString())).flat())).map(g=>s[g]).filter(g=>g!==void 0)),y=[b]}}),y.length>0){let d=[...new Set(y.map(T=>T.keys.filter(a=>a.isSigner).map(a=>a.pubkey.toString())).flat()).values()].map(T=>s[T]).filter(T=>T!==void 0);ue({instructions:r?[...i.instructions,...y]:[...y],payer:this.feePayer,signers:d.map(T=>T.publicKey)})?o.push(new le().add(...i.instructions,...y)):o.push(new le().add(...y)),h.push(d)}return o.forEach(b=>b.feePayer=this.feePayer),(S=this.owner)!=null&&S.signer&&h.forEach(b=>{b.some(d=>d.publicKey.equals(this.owner.publicKey))||b.push(this.owner.signer)}),{builder:this,transactions:o,signers:h,instructionTypes:this.instructionTypes,execute:b=>P(this,null,function*(){var m;let{sequentially:d,onTxUpdate:T,skipTxCount:a=0,recentBlockHash:A,skipPreflight:g=!0}=b||{},k=A!=null?A:yield $(this.connection,this.blockhashCommitment);if(o.forEach((l,c)=>P(this,null,function*(){l.recentBlockhash=k,h[c].length&&l.sign(...h[c])})),J(o),(m=this.owner)!=null&&m.isKeyPair){if(d){let l=0,c=[];for(let w of o){if(++l,l<=a){c.push("tx skipped");continue}let x=yield We(this.connection,w,this.signers.find(B=>B.publicKey.equals(this.owner.publicKey))?this.signers:[...this.signers,this.owner.signer],{skipPreflight:g});c.push(x)}return{txIds:c,signedTxs:o}}return{txIds:yield Promise.all(o.map(l=>P(this,null,function*(){return yield this.connection.sendRawTransaction(l.serialize(),{skipPreflight:g})}))),signedTxs:o}}if(this.signAllTransactions){let l=yield this.signAllTransactions(o.slice(a,o.length)),c=[...o.slice(0,a),...l];if(d){let w=0,x=[],B=()=>P(this,null,function*(){if(!c[w])return;w<a&&(x.push({txId:"",status:"success",signedTx:c[w]}),T==null||T([...x]),w++,B());let I=yield this.connection.sendRawTransaction(c[w].serialize(),{skipPreflight:g});x.push({txId:I,status:"sent",signedTx:c[w]}),T==null||T([...x]),w++;let D=!1,L=null,C=null,E=_=>{L!==null&&clearInterval(L),C!==null&&this.connection.removeSignatureListener(C);let R=x.findIndex(H=>H.txId===I);if(R>-1){if(x[R].status==="error"||x[R].status==="success")return;x[R].status=_.err?"error":"success"}T==null||T([...x]),_.err||B()};this.loopMultiTxStatus&&(L=setInterval(()=>P(this,null,function*(){var _;if(D){clearInterval(L);return}try{let R=yield this.connection.getTransaction(I,{commitment:"confirmed",maxSupportedTransactionVersion:0});R&&(D=!0,clearInterval(L),E({err:((_=R.meta)==null?void 0:_.err)||null}),console.log("tx status from getTransaction:",I))}catch(R){D=!0,clearInterval(L),console.error("getTransaction timeout:",R,I)}}),Ie)),C=this.connection.onSignature(I,_=>{if(D){this.connection.removeSignatureListener(C);return}D=!0,E(_)},"confirmed"),this.connection.getSignatureStatus(I)});return yield B(),{txIds:x.map(I=>I.txId),signedTxs:c}}else{let w=[];for(let x=0;x<c.length;x+=1){let B=yield this.connection.sendRawTransaction(c[x].serialize(),{skipPreflight:g});w.push(B)}return{txIds:w,signedTxs:c}}}throw new Error("please provide owner in keypair format or signAllTransactions function")}),extInfo:f||{}}})}sizeCheckBuildV0(e){return P(this,null,function*(){var k;let g=e||{},{computeBudgetConfig:t,splitIns:r=[],lookupTableCache:f={},lookupTableAddress:i=[]}=g,s=ye(g,["computeBudgetConfig","splitIns","lookupTableCache","lookupTableAddress"]),o=M(M({},this.cluster==="devnet"?{}:Ae),f),h=Array.from(new Set([...this.lookupTableAddress,...i])),y=[];for(let m of h)o[m]===void 0&&y.push(new Q(m));let p=yield Ve({connection:this.connection,address:y});for(let[m,l]of Object.entries(p))o[m]=l;let u=t?Se(t):{instructions:[],instructionTypes:[]},S=yield $(this.connection,this.blockhashCommitment),b=this.signers.reduce((m,l)=>G(M({},m),{[l.publicKey.toBase58()]:l}),{}),d=[],T=[],a=[],A=0;if(this.allInstructions.forEach(m=>{let l=[...a,m],c=t?[...u.instructions,...l]:l;if(m!==r[A]&&a.length<12&&(ce({instructions:c,payer:this.feePayer,lookupTableAddressAccount:o})||ce({instructions:l,payer:this.feePayer,lookupTableAddressAccount:o})))a.push(m);else{if(a.length===0)throw Error("item ins too big");A+=m===r[A]?1:0;let w={};for(let x of[...new Set(h)])o[x]!==void 0&&(w[x]=o[x]);if(t&&ce({instructions:[...u.instructions,...a],payer:this.feePayer,lookupTableAddressAccount:o,recentBlockhash:S})){let x=new me({payerKey:this.feePayer,recentBlockhash:S,instructions:[...u.instructions,...a]}).compileToV0Message(Object.values(o));d.push(new pe(x))}else{let x=new me({payerKey:this.feePayer,recentBlockhash:S,instructions:[...a]}).compileToV0Message(Object.values(o));d.push(new pe(x))}T.push(Array.from(new Set(a.map(x=>x.keys.filter(B=>B.isSigner).map(B=>B.pubkey.toString())).flat())).map(x=>b[x]).filter(x=>x!==void 0)),a=[m]}}),a.length>0){let l=[...new Set(a.map(c=>c.keys.filter(w=>w.isSigner).map(w=>w.pubkey.toString())).flat()).values()].map(c=>b[c]).filter(c=>c!==void 0);if(t&&ce({instructions:[...u.instructions,...a],payer:this.feePayer,lookupTableAddressAccount:o,recentBlockhash:S})){let c=new me({payerKey:this.feePayer,recentBlockhash:S,instructions:[...u.instructions,...a]}).compileToV0Message(Object.values(o));d.push(new pe(c))}else{let c=new me({payerKey:this.feePayer,recentBlockhash:S,instructions:[...a]}).compileToV0Message(Object.values(o));d.push(new pe(c))}T.push(l)}return(k=this.owner)!=null&&k.signer&&T.forEach(m=>{m.some(l=>l.publicKey.equals(this.owner.publicKey))||m.push(this.owner.signer)}),{builder:this,transactions:d,buildProps:e,signers:T,instructionTypes:this.instructionTypes,execute:m=>P(this,null,function*(){var I;let{sequentially:l,onTxUpdate:c,skipTxCount:w=0,recentBlockHash:x,skipPreflight:B=!0}=m||{};if(d.map((D,L)=>P(this,null,function*(){T[L].length&&D.sign(T[L]),x&&(D.message.recentBlockhash=x)})),J(d),(I=this.owner)!=null&&I.isKeyPair){if(l){let D=0,L=[];for(let C of d){if(++D,D<=w){console.log("skip tx: ",D),L.push("tx skipped");continue}let E=yield this.connection.sendTransaction(C,{skipPreflight:B});yield Be(this.connection,E),L.push(E)}return{txIds:L,signedTxs:d}}return{txIds:yield Promise.all(d.map(D=>P(this,null,function*(){return yield this.connection.sendTransaction(D,{skipPreflight:B})}))),signedTxs:d}}if(this.signAllTransactions){let D=yield this.signAllTransactions(d.slice(w,d.length)),L=[...d.slice(0,w),...D];if(l){let C=0,E=[],_=()=>P(this,null,function*(){if(!L[C])return;if(C<w){E.push({txId:"",status:"success",signedTx:L[C]}),c==null||c([...E]),C++,_();return}let R=yield this.connection.sendTransaction(L[C],{skipPreflight:B});E.push({txId:R,status:"sent",signedTx:L[C]}),c==null||c([...E]),C++;let H=!1,Z=null,ge=null,ze=z=>{Z!==null&&clearInterval(Z),ge!==null&&this.connection.removeSignatureListener(ge);let W=E.findIndex(Pt=>Pt.txId===R);if(W>-1){if(E[W].status==="error"||E[W].status==="success")return;E[W].status=z.err?"error":"success"}c==null||c([...E]),z.err||_()};this.loopMultiTxStatus&&(Z=setInterval(()=>P(this,null,function*(){var z;if(H){clearInterval(Z);return}try{let W=yield this.connection.getTransaction(R,{commitment:"confirmed",maxSupportedTransactionVersion:0});W&&(H=!0,clearInterval(Z),ze({err:((z=W.meta)==null?void 0:z.err)||null}),console.log("tx status from getTransaction:",R))}catch(W){H=!0,clearInterval(Z),console.error("getTransaction timeout:",W,R)}}),Ie)),ge=this.connection.onSignature(R,z=>{if(H){this.connection.removeSignatureListener(ge);return}H=!0,ze(z)},"confirmed"),this.connection.getSignatureStatus(R)});return _(),{txIds:[],signedTxs:L}}else{let C=[];for(let E=0;E<L.length;E+=1){let _=yield this.connection.sendTransaction(L[E],{skipPreflight:B});C.push(_)}return{txIds:C,signedTxs:L}}}throw new Error("please provide owner in keypair format or signAllTransactions function")}),extInfo:s||{}}})}};import{Connection as Fi}from"@solana/web3.js";import{PublicKey as sn}from"@solana/web3.js";import bt,{isBN as Tt}from"bn.js";import{bits as os,BitStructure as is,blob as en,Blob as ss,cstr as as,f32 as us,f32be as cs,f64 as ls,f64be as ms,greedy as ps,Layout as tn,ns64 as ds,ns64be as fs,nu64 as gs,nu64be as hs,offset as ys,s16 as bs,s16be as Ts,s24 as xs,s24be as Ps,s32 as ws,s32be as Ss,s40 as Bs,s40be as ks,s48 as As,s48be as Is,s8 as Ls,seq as nn,struct as Cs,Structure as rn,u16 as Ns,u16be as Os,u24 as Ds,u24be as Es,u32 as Rs,u32be as Ms,u40 as Fs,u40be as _s,u48 as Ks,u48be as Vs,u8 as Ws,UInt as on,union as vs,Union as Us,unionLayoutDiscriminator as qs,utf8 as Gs}from"@solana/buffer-layout";var ve=tn,gt=rn;var ht=on;var yt=nn;var ee=en;var Ue=class extends ve{constructor(e,t,r){super(e,r),this.blob=ee(e),this.signed=t}decode(e,t=0){let r=new bt(this.blob.decode(e,t),10,"le");return this.signed?r.fromTwos(this.span*8).clone():r}encode(e,t,r=0){return typeof e=="number"&&(e=new bt(e)),this.signed&&(e=e.toTwos(this.span*8)),this.blob.encode(e.toArrayLike(Buffer,"le",this.span),t,r)}};function te(n){return new ht(1,n)}function V(n){return new Ue(8,!1,n)}var qe=class extends ve{constructor(e,t,r,f){super(e.span,f),this.layout=e,this.decoder=t,this.encoder=r}decode(e,t){return this.decoder(this.layout.decode(e,t))}encode(e,t,r){return this.layout.encode(this.encoder(e),t,r)}getSpan(e,t){return this.layout.getSpan(e,t)}};function X(n){return new qe(ee(32),e=>new sn(e),e=>e.toBuffer(),n)}var Ge=class extends gt{decode(e,t){return super.decode(e,t)}};function ne(n,e,t){return new Ge(n,e,t)}function de(n,e,t){let r,f=typeof e=="number"?e:Tt(e)?e.toNumber():new Proxy(e,{get(i,s){if(!r){let o=Reflect.get(i,"count");r=Tt(o)?o.toNumber():o,Reflect.set(i,"count",r)}return Reflect.get(i,s)},set(i,s,o){return s==="count"&&(r=o),Reflect.set(i,s,o)}});return yt(n,f,t)}var je=(...n)=>n.map(e=>{try{return typeof e=="object"?JSON.stringify(e):e}catch(t){return e}}).join(", "),fe=class{constructor({scope:e,moduleName:t}){this.disabled=!1;this.scope=e,this.logger=F(t)}createTxBuilder(e){return this.scope.checkOwner(),new Le({connection:this.scope.connection,feePayer:e||this.scope.ownerPubKey,cluster:this.scope.cluster,owner:this.scope.owner,blockhashCommitment:this.scope.blockhashCommitment,loopMultiTxStatus:this.scope.loopMultiTxStatus,api:this.scope.api,signAllTransactions:this.scope.signAllTransactions})}logDebug(...e){this.logger.debug(je(e))}logInfo(...e){this.logger.info(je(e))}logAndCreateError(...e){let t=je(e);throw new Error(t)}checkDisabled(){(this.disabled||!this.scope)&&this.logAndCreateError("module not working")}};var O=class O extends fe{static getPdaPoolId(e,t){return ke([O.SEED_CONFIG.pool.id,t.toBuffer()],e)}static getPdaOwnerId(e,t,r,f){return ke([O.SEED_CONFIG.owner.id,t.toBuffer(),r.toBuffer(),Buffer.from(new xt(f).toArray())],e)}static getAllInfo(s){return P(this,arguments,function*({connection:e,programId:t,poolIds:r,wallet:f,chainTime:i}){if(r.length===0)return[];let o=r.map(u=>O.getPdaPoolId(t,u).publicKey),h=[];for(let u=0;u<O.VERSION_PROJECT.length;u++)h.push(...o.map(S=>O.getPdaOwnerId(t,S,f,u).publicKey));let y=yield be(e,[...o,...h]),p=[];for(let u=0;u<y.length;u++){let S=Math.floor(u/r.length),b=u%r.length,d=o[b],T=h[u],a=y[b],A=y[r.length+u];if(!(a&&A)||a.data.length!==O.POOL_LAYOUT.span||A.data.length!==O.OWNER_LAYOUT.span)continue;let g=O.POOL_LAYOUT.decode(a.data),k=O.OWNER_LAYOUT.decode(A.data),m=g.openTime.toNumber(),l=g.endTime.toNumber(),c=k.tokenInfo.map(B=>B.debtAmount.gt(new xt(0))).filter(B=>!B).length!==3,w=i>m&&i<l&&g.status===1,x=c&&w;p.push({programId:t,poolId:d,ammId:g.ammId,ownerAccountId:T,snapshotLpAmount:k.lpAmount,project:O.VERSION_PROJECT[S],openTime:m,endTime:l,canClaim:x,canClaimErrorType:c?w?void 0:"outOfOperationalTime":"alreadyClaimIt",tokenInfo:g.tokenInfo.map((B,I)=>({mintAddress:B.mintAddress,mintVault:B.mintVault,mintDecimals:B.mintDecimals,perLpLoss:B.perLpLoss,debtAmount:k.tokenInfo[I].debtAmount.add(k.tokenInfo[I].claimedAmount)}))})}return p})}makeClaimTransaction(f){return P(this,arguments,function*({poolInfo:e,ownerInfo:t,feePayer:r}){t.wallet||this.scope.checkOwner();let i=this.createTxBuilder(r),s=t.wallet||this.scope.ownerPubKey,o=[];for(let p of e.tokenInfo){let{account:u,instructionParams:S}=yield this.scope.account.getOrCreateTokenAccount({mint:p.mintAddress,owner:this.scope.ownerPubKey,notUseTokenAccount:p.mintAddress.equals(K.WSOL.mint),createInfo:{payer:s,amount:0},skipCloseAccount:!p.mintAddress.equals(K.WSOL.mint),associatedOnly:p.mintAddress.equals(K.WSOL.mint)?!1:t.associatedOnly});S&&i.addInstruction(S),o.push(u)}i.addInstruction({instructions:[O.makeClaimInstruction({programId:e.programId,poolInfo:e,ownerInfo:{wallet:s,ownerPda:e.ownerAccountId,claimAddress:o}})]});let{transaction:h,signers:y}=i.build();return[{transaction:h,signer:y}]})}makeClaimAllTransaction(f){return P(this,arguments,function*({poolInfos:e,ownerInfo:t,feePayer:r}){let i=this.createTxBuilder(r),s=t.wallet||this.scope.ownerPubKey,o={};for(let u of e){let S=[];for(let b of u.tokenInfo){let{account:d,instructionParams:T}=yield this.scope.account.getOrCreateTokenAccount({mint:b.mintAddress,owner:this.scope.ownerPubKey,notUseTokenAccount:b.mintAddress.equals(K.WSOL.mint),createInfo:{payer:s,amount:0},skipCloseAccount:!b.mintAddress.equals(K.WSOL.mint),associatedOnly:b.mintAddress.equals(K.WSOL.mint)?!1:t.associatedOnly});T&&i.addInstruction(T),d&&(o[b.mintAddress.toString()]=d,S.push(d))}i.addInstruction({instructions:[O.makeClaimInstruction({programId:u.programId,poolInfo:u,ownerInfo:{wallet:s,ownerPda:u.ownerAccountId,claimAddress:S}})]})}let{transaction:h,signers:y}=i.build(),p=i.allInstructions;return Ke(p,[s,...y.map(u=>u.publicKey)])?[{transaction:h,signer:y}]:[{transaction:new He().add(...p.slice(0,i.AllTxData.instructions.length-1)),signer:y},{transaction:new He().add(...p.slice(i.AllTxData.instructions.length-1)),signer:[]},{transaction:new He().add(...i.AllTxData.endInstructions),signer:[]}]})}static makeClaimInstruction({programId:e,poolInfo:t,ownerInfo:r}){let f=ne([]),i=[{pubkey:r.wallet,isSigner:!0,isWritable:!0},{pubkey:t.poolId,isSigner:!1,isWritable:!0},{pubkey:r.ownerPda,isSigner:!1,isWritable:!0},...r.claimAddress.map(h=>({pubkey:h,isSigner:!1,isWritable:!0})),...t.tokenInfo.map(({mintVault:h})=>({pubkey:h,isSigner:!1,isWritable:!0})),{pubkey:cn,isSigner:!1,isWritable:!1}],s=Buffer.alloc(f.span);f.encode({},s);let o=Buffer.from([10,66,208,184,161,6,191,98,...s]);return new un({keys:i,programId:e,data:o})}};O.CLAIMED_NUM=3,O.POOL_LAYOUT=ne([ee(8),te("bump"),te("status"),V("openTime"),V("endTime"),X("ammId"),de(ne([te("mintDecimals"),X("mintAddress"),X("mintVault"),V("perLpLoss"),V("totalClaimedAmount")]),O.CLAIMED_NUM,"tokenInfo"),de(V(),10,"padding")]),O.OWNER_LAYOUT=ne([ee(8),te("bump"),te("version"),X("poolId"),X("owner"),V("lpAmount"),de(ne([X("mintAddress"),V("debtAmount"),V("claimedAmount")]),O.CLAIMED_NUM,"tokenInfo"),de(V(),4,"padding")]),O.DEFAULT_POOL_ID=["58oQChx4yWmvKdwLLZzBi4ChoCc2fqCUWBkwMihLYQo2","6UmmUiYoBjSrhakAobJw8BvkmJtDVxaeBtbt7rxWo1mg","AVs9TA4nWDzfPJE9gGVNJMVhcQy3V9PGazuz33BfG2RA","DVa7Qmb5ct9RCpaU7UTpSaf3GVMYz17vNVU67XpdCRut","7XawhbbxtsRcQA8KTkHT9f9nc6d69UwqCDh6U5EEbEmX","6a1CsrpeZubDjEJE9s1CMVheB6HWM5d7m1cj2jkhyXhj","EoNrn8iUhwgJySD1pHu8Qxm5gSQqLK3za4m8xzD2RuEb","AceAyRTWt4PyB2pHqf2qhDgNZDtKVNaxgL8Ru3V4aN1P","6tmFJbMk5yVHFcFy7X2K8RwHjKLr6KVFLYXpgpBNeAxB"].map(e=>new an(e)),O.SEED_CONFIG={pool:{id:Buffer.from("pool_seed","utf8")},owner:{id:Buffer.from("user_claim_seed","utf8")}},O.VERSION_PROJECT=[void 0,"Francium","Tulip","Larix"];var Ce=O;export{Ce as default}; //# sourceMappingURL=index.mjs.map