@raydium-io/raydium-sdk-v2
Version:
An SDK for building applications on top of Raydium.
2 lines • 115 kB
JavaScript
var xr=Object.create;var bt=Object.defineProperty,Cr=Object.defineProperties,Rr=Object.getOwnPropertyDescriptor,Lr=Object.getOwnPropertyDescriptors,Or=Object.getOwnPropertyNames,Wt=Object.getOwnPropertySymbols,Nr=Object.getPrototypeOf,An=Object.prototype.hasOwnProperty,Ao=Object.prototype.propertyIsEnumerable;var Po=(i,e,t)=>e in i?bt(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,O=(i,e)=>{for(var t in e||(e={}))An.call(e,t)&&Po(i,t,e[t]);if(Wt)for(var t of Wt(e))Ao.call(e,t)&&Po(i,t,e[t]);return i},V=(i,e)=>Cr(i,Lr(e));var ke=(i,e)=>{var t={};for(var o in i)An.call(i,o)&&e.indexOf(o)<0&&(t[o]=i[o]);if(i!=null&&Wt)for(var o of Wt(i))e.indexOf(o)<0&&Ao.call(i,o)&&(t[o]=i[o]);return t};var Mr=(i,e)=>{for(var t in e)bt(i,t,{get:e[t],enumerable:!0})},wo=(i,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Or(e))!An.call(i,r)&&r!==t&&bt(i,r,{get:()=>e[r],enumerable:!(o=Rr(e,r))||o.enumerable});return i};var x=(i,e,t)=>(t=i!=null?xr(Nr(i)):{},wo(e||!i||!i.__esModule?bt(t,"default",{value:i,enumerable:!0}):t,i)),Fr=i=>wo(bt({},"__esModule",{value:!0}),i);var nc={};Mr(nc,{AUTH_SEED:()=>Fi,BondingCurveParam:()=>nr,CONFIG_SEED:()=>vi,CREATOR_FEE_VAULT_AUTH_SEED:()=>Di,CpmmCreatorFeeOn:()=>mo,Curve:()=>Ge,CurveBase:()=>Re,CurveRuleGroup:()=>ir,FixedPriceCurve:()=>vt,LAUNCHPAD_CURVE_RULE_CONSTANT_PRODUCT_ONLY_FIELDS:()=>co,LAUNCHPAD_MAX_CONSTRAINTS_PER_GROUP:()=>Pn,LAUNCHPAD_MAX_CURVE_RULE_GROUPS:()=>gn,LaunchConstantProductCurve:()=>Mt,LaunchpadConfig:()=>Ji,LaunchpadCurveRuleBaseTokenProgram:()=>Mi,LaunchpadCurveRuleField:()=>uo,LaunchpadCurveRuleOp:()=>lo,LaunchpadMintProgramBit:()=>ar,LaunchpadPool:()=>tr,LaunchpadPoolInitParam:()=>Xu,LaunchpadVesting:()=>Wu,LinearPriceCurve:()=>Vt,MathLaunch:()=>pt,PLATFORM_ALLOW_CONFIG_SEED:()=>qi,PLATFORM_CURVE_RULE_SEED:()=>Ui,PLATFORM_FEE_VAULT_AUTH_SEED:()=>Ei,PLATFORM_GLOBAL_ACCESS_SEED:()=>Wi,PLATFORM_SEED:()=>Vi,POOL_VESTING_SEED:()=>_i,ParamConstraint:()=>or,PlatformConfig:()=>io,PlatformCurveParam:()=>qu,PlatformCurveRule:()=>rr,VestingSchedule:()=>er,anchorDataBuf:()=>ee,buyExactInInstruction:()=>ro,buyExactOutInstruction:()=>lr,checkCurveRuleGroupWritable:()=>tc,checkLaunchAgainstCurveRule:()=>ec,checkPoolToAmm:()=>Uu,claimCreatorFee:()=>Pr,claimPlatformFee:()=>fr,claimPlatformFeeFromVault:()=>gr,claimVestedToken:()=>dr,closePlatformAllowConfigIns:()=>kr,closePlatformCurveRuleIns:()=>Br,createPlatformAllowConfigIns:()=>wr,createPlatformConfig:()=>yr,createPlatformCurveRuleIns:()=>Tr,createPlatformVestingAccountIns:()=>Ar,createVestingAccount:()=>pr,getCurveRuleFieldValue:()=>bo,getLaunchpadPoolMintAProgram:()=>Oi,getLaunchpadPoolMintBProgram:()=>Gu,getLaunchpadPoolMintProgram:()=>fo,getPdaCpiEvent:()=>Ce,getPdaCreatorFeeVaultAuth:()=>Zi,getPdaCreatorVault:()=>oo,getPdaLaunchpadAuth:()=>to,getPdaLaunchpadConfigId:()=>Gi,getPdaLaunchpadPoolId:()=>zi,getPdaLaunchpadVaultId:()=>Xi,getPdaPlatformAllowConfig:()=>$i,getPdaPlatformConfigAccess:()=>Du,getPdaPlatformCurveRule:()=>ji,getPdaPlatformFeeVaultAuth:()=>Qi,getPdaPlatformId:()=>Yi,getPdaPlatformVault:()=>no,getPdaVestId:()=>Hi,initialize:()=>$u,initializeV2:()=>ur,initializeWithToken2022:()=>cr,isCurveRuleConstraintSatisfied:()=>Sr,removePlatformCurveRuleIns:()=>Ir,sellExactInInstruction:()=>ao,sellExactOut:()=>mr,toLaunchpadMintProgramFlag:()=>sr,updatePlatformConfig:()=>br,updatePlatformCurveRuleIns:()=>hr,usdMintBSet:()=>Yu});module.exports=Fr(nc);var To=require("@solana/web3.js");var gt=require("lodash");var wn=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(o=>typeof o=="object"?JSON.stringify(o):o).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}},ko={},vr={};function z(i){let e=(0,gt.get)(ko,i);if(!e){let t=(0,gt.get)(vr,i);e=new wn({name:i,logLevel:t}),(0,gt.set)(ko,i,e)}return e}var qt=require("@solana/spl-token"),kn=z("Raydium_accountInfo_util");async function Ke(i,e,t){let{batchRequest:o,commitment:r="confirmed",chunkCount:a=100}=O({batchRequest:!1},t),s=Tn(e,a),c=new Array(s.length).fill([]);if(o){let p=s.map(k=>{let I=i._buildArgs([k.map(h=>h.toBase58())],r,"base64");return{methodName:"getMultipleAccounts",args:I}}),g=Tn(p,10);c=(await(await Promise.all(g.map(async k=>await i._rpcBatchRequest(k)))).flat()).map(k=>(k.error&&kn.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${k.error.message}`),k.result.value.map(I=>{if(I){let{data:h,executable:S,lamports:T,owner:P,rentEpoch:A}=I;return h.length!==2&&h[1]!=="base64"&&kn.logWithError("info must be base64 encoded, RPC_ERROR"),{data:Buffer.from(h[0],"base64"),executable:S,lamports:T,owner:new To.PublicKey(P),rentEpoch:A}}return null})))}else try{c=await Promise.all(s.map(p=>i.getMultipleAccountsInfo(p,r)))}catch(p){p instanceof Error&&kn.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${p.message}`)}return c.flat()}var Le=x(require("bn.js")),Zu=x(require("decimal.js"));var Ko=x(require("big.js")),Wr=x(require("bn.js"));var ho=x(require("toformat")),_r=ho.default,At=_r;var wt=x(require("big.js")),Bo=x(require("bn.js")),So=x(require("decimal.js-light"));var Qe=x(require("bn.js"));var Io=9007199254740991;function me(i){let e=z("Raydium_parseBigNumberish");if(i instanceof Qe.default)return i;if(typeof i=="string"){if(i.match(/^-?[0-9]+$/))return new Qe.default(i);e.logWithError(`invalid BigNumberish string: ${i}`)}return typeof i=="number"?(i%1&&e.logWithError(`BigNumberish number underflow: ${i}`),(i>=Io||i<=-Io)&&e.logWithError(`BigNumberish number overflow: ${i}`),new Qe.default(String(i))):typeof i=="bigint"?new Qe.default(i.toString()):(e.error(`invalid BigNumberish value: ${i}`),new Qe.default(0))}var Ut=z("module/fraction"),hn=At(wt.default),kt=At(So.default),Er={[0]:kt.ROUND_DOWN,[1]:kt.ROUND_HALF_UP,[2]:kt.ROUND_UP},Dr={[0]:wt.default.roundDown,[1]:wt.default.roundHalfUp,[2]:wt.default.roundUp},Q=class{constructor(e,t=new Bo.default(1)){this.numerator=me(e),this.denominator=me(t)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new Q(this.denominator,this.numerator)}add(e){let t=e instanceof Q?e:new Q(me(e));return this.denominator.eq(t.denominator)?new Q(this.numerator.add(t.numerator),this.denominator):new Q(this.numerator.mul(t.denominator).add(t.numerator.mul(this.denominator)),this.denominator.mul(t.denominator))}sub(e){let t=e instanceof Q?e:new Q(me(e));return this.denominator.eq(t.denominator)?new Q(this.numerator.sub(t.numerator),this.denominator):new Q(this.numerator.mul(t.denominator).sub(t.numerator.mul(this.denominator)),this.denominator.mul(t.denominator))}mul(e){let t=e instanceof Q?e:new Q(me(e));return new Q(this.numerator.mul(t.numerator),this.denominator.mul(t.denominator))}div(e){let t=e instanceof Q?e:new Q(me(e));return new Q(this.numerator.mul(t.denominator),this.denominator.mul(t.numerator))}toSignificant(e,t={groupSeparator:""},o=1){Number.isInteger(e)||Ut.logWithError(`${e} is not an integer.`),e<=0&&Ut.logWithError(`${e} is not positive.`),kt.set({precision:e+1,rounding:Er[o]});let r=new kt(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(e);return r.toFormat(r.decimalPlaces(),t)}toFixed(e,t={groupSeparator:""},o=1){return Number.isInteger(e)||Ut.logWithError(`${e} is not an integer.`),e<0&&Ut.logWithError(`${e} is negative.`),hn.DP=e,hn.RM=Dr[o]||1,new hn(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,t)}isZero(){return this.numerator.isZero()}};var Kc=z("Raydium_amount"),xc=At(Ko.default);var xo=require("@solana/web3.js"),In=require("@solana/spl-token"),Gt={chainId:101,address:xo.PublicKey.default.toBase58(),programId:In.TOKEN_PROGRAM_ID.toBase58(),decimals:9,symbol:"SOL",name:"solana",logoURI:"https://img-v1.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}},Te={chainId:101,address:"So11111111111111111111111111111111111111112",programId:In.TOKEN_PROGRAM_ID.toBase58(),decimals:9,symbol:"WSOL",name:"Wrapped SOL",logoURI:"https://img-v1.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}};var zt=require("@solana/web3.js");var Y=require("@solana/web3.js"),Co=require("@solana/spl-token");function Ze({pubkey:i,isSigner:e=!1,isWritable:t=!0}){return{pubkey:i,isWritable:t,isSigner:e}}var Ur=[Ze({pubkey:Co.TOKEN_PROGRAM_ID,isWritable:!1}),Ze({pubkey:Y.SystemProgram.programId,isWritable:!1}),Ze({pubkey:Y.SYSVAR_RENT_PUBKEY,isWritable:!1})];function Ro({publicKey:i,transformSol:e}){let t=Lo(i.toString());if(t instanceof Y.PublicKey)return e&&t.equals(_e)?xe:t;if(e&&t.toString()===_e.toBase58())return xe;if(typeof t=="string"){if(t===Y.PublicKey.default.toBase58())return Y.PublicKey.default;try{return new Y.PublicKey(t)}catch{throw new Error("invalid public key")}}throw new Error("invalid public key")}function Lo(i){try{return new Y.PublicKey(i)}catch{return i}}var Bn=new Y.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Ve=new Y.PublicKey("SysvarRent111111111111111111111111111111111"),Oc=new Y.PublicKey("SysvarC1ock11111111111111111111111111111111"),$e=new Y.PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),Gr=new Y.PublicKey("Sysvar1nstructions1111111111111111111111111"),zr=Y.SystemProgram.programId,Nc=new Y.PublicKey("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),Mc=new Y.PublicKey("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),Fc=new Y.PublicKey("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),vc=new Y.PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),_c=new Y.PublicKey("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),Vc=new Y.PublicKey("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),Ec=new Y.PublicKey("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),Dc=new Y.PublicKey("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),Wc=new Y.PublicKey("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),qc=new Y.PublicKey("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),Uc=new Y.PublicKey("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),xe=new Y.PublicKey("So11111111111111111111111111111111111111112"),_e=Y.PublicKey.default;var Sn=class{constructor({mint:e,decimals:t,symbol:o,name:r,skipMint:a=!1,isToken2022:s=!1}){if(e===_e.toBase58()||e instanceof zt.PublicKey&&_e.equals(e)){this.decimals=Te.decimals,this.symbol=Te.symbol,this.name=Te.name,this.mint=new zt.PublicKey(Te.address),this.isToken2022=!1;return}this.decimals=t,this.symbol=o||e.toString().substring(0,6),this.name=r||e.toString().substring(0,6),this.mint=a?zt.PublicKey.default:Ro({publicKey:e}),this.isToken2022=s}equals(e){return this===e?!0:this.mint.equals(e.mint)}},se=Sn;se.WSOL=new Sn(V(O({},Te),{mint:Te.address}));var Kn=class{constructor({decimals:e,symbol:t="UNKNOWN",name:o="UNKNOWN"}){this.decimals=e,this.symbol=t,this.name=o}equals(e){return this===e}},Xt=Kn;Xt.SOL=new Kn(Gt);var Oo=x(require("bn.js"));var Jc=new Q(new Oo.default(100));var rl=z("Raydium_price");var Qu=require("lodash");var Yr=x(require("axios"));var No={BASE_HOST:"https://api-v3.raydium.io",OWNER_BASE_HOST:"https://owner-v1.raydium.io",SERVICE_BASE_HOST:"https://service.raydium.io",MONITOR_BASE_HOST:"https://monitor.raydium.io",SERVICE_1_BASE_HOST:"https://service-v1.raydium.io",TEMP_HOST:"https://temp-api-v1.raydium.io",SEND_TRANSACTION:"/send-transaction",FARM_ARP:"/main/farm/info",FARM_ARP_LINE:"/main/farm-apr-tv",CLMM_CONFIG:"/main/clmm-config",CPMM_CONFIG:"/main/cpmm-config",CLMM_DYNAMIC_CONFIG:"/main/clmm-dynamic-config",VERSION:"/main/version",CHECK_AVAILABILITY:"/v3/main/AvailabilityCheckAPI",RPCS:"/main/rpcs",INFO:"/main/info",STAKE_POOLS:"/main/stake-pools",CHAIN_TIME:"/main/chain-time",TOKEN_LIST:"/mint/list",MINT_INFO_ID:"/mint/ids",JUP_TOKEN_LIST:"https://lite-api.jup.ag/tokens/v2/tag?query=verified",POOL_LIST:"/pools/info/list-v2",POOL_SEARCH_BY_ID:"/pools/info/ids",POOL_SEARCH_MINT:"/pools/info/list-v2",POOL_SEARCH_LP:"/pools/info/lps",POOL_KEY_BY_ID:"/pools/key/ids",POOL_LIQUIDITY_LINE:"/pools/line/liquidity",POOL_POSITION_LINE:"/pools/line/position",FARM_INFO:"/farms/info/ids",FARM_LP_INFO:"/farms/info/lp",FARM_KEYS:"/farms/key/ids",OWNER_CREATED_FARM:"/create-pool/{owner}",OWNER_STAKE_FARMS:"/position/stake/{owner}",OWNER_LOCK_POSITION:"/position/clmm-lock/{owner}",SWAP_HOST:"https://transaction-v1.raydium.io",SWAP_COMPUTE:"/compute/",SWAP_TX:"/transaction/",MINT_PRICE:"/mint/price",MIGRATE_CONFIG:"/main/migrate-lp",PRIORITY_FEE:"/main/auto-fee",CPMM_LOCK:"https://dynamic-ipfs.raydium.io/lock/cpmm/position",LAUNCH_AUTH_HOST:"https://launch-auth-v1.raydium.io",LAUNCH_COMMENT_HOST:"hhttps://launch-forum-v1.raydium.io",LAUNCH_HISTORY_HOST:"https://launch-history-v1.raydium.io",LAUNCH_MINT_HOST:"https://launch-mint-v1.raydium.io"},Xr=V(O({},No),{BASE_HOST:"https://api-v3-devnet.raydium.io",OWNER_BASE_HOST:"https://owner-v1-devnet.raydium.io",SWAP_HOST:"https://transaction-v1-devnet.raydium.io",CPMM_LOCK:"https://dynamic-ipfs-devnet.raydium.io/lock/cpmm/position",TEMP_HOST:"https://temp-api-v1-devnet.raydium.io",LAUNCH_AUTH_HOST:"https://launch-auth-v1-devnet.raydium.io",LAUNCH_COMMENT_HOST:"https://launch-forum-v1-devnet.raydium.io",LAUNCH_HISTORY_HOST:"https://launch-history-v1-devnet.raydium.io",LAUNCH_MINT_HOST:"https://launch-mint-v1-devnet.raydium.io"});var Fl=z("Raydium_Api");var Yo=require("@solana/web3.js");var nn=require("@solana/spl-token");var X=require("@solana/web3.js"),_o=x(require("axios"));var be=require("@solana/web3.js");async function xn({connection:i,address:e,cluster:t="mainnet"}){let o=await Ke(i,[...new Set(e.map(a=>a.toString()))].map(a=>new be.PublicKey(a))),r={};for(let a=0;a<e.length;a++){let s=o[a],c=e[a];if(!s)continue;let p=new be.AddressLookupTableAccount({key:c,state:be.AddressLookupTableAccount.deserialize(s.data)});r[c.toString()]=p,t==="devnet"?Je[c.toString()]=p:je[c.toString()]=p}return r}var je={},Cn=async i=>{let e="AcL1Vo8oy1ULiavEcjSUcwfBSForXMudcZvDZy5nzJkU";if(je[e])return je;let t=new be.PublicKey(e),o=await i.getAccountInfo(t);return o&&(je[e]=new be.AddressLookupTableAccount({key:t,state:be.AddressLookupTableAccount.deserialize(o.data)})),je},Je={},Rn=async i=>{let e="EFhMuDw1PKEuckuFRW9PavNfTH4LKP5uKHgyXDmWpFCq";if(Je[e])return Je;let t=new be.PublicKey(e),o=await i.getAccountInfo(t);return o&&(Je[e]=new be.AddressLookupTableAccount({key:t,state:be.AddressLookupTableAccount.deserialize(o.data)})),Je};var ne={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"};var ue=require("@solana/web3.js");var Fo=require("@solana/spl-token"),Mo=z("Raydium_txUtil"),vo=1644;function Yt(i){let e=[],t=[];return i.microLamports&&(e.push(ue.ComputeBudgetProgram.setComputeUnitPrice({microLamports:i.microLamports})),t.push(ne.SetComputeUnitPrice)),i.units&&(e.push(ue.ComputeBudgetProgram.setComputeUnitLimit({units:i.units})),t.push(ne.SetComputeUnitLimit)),{instructions:e,instructionTypes:t}}async function et(i,e){var o,r;let t=e!=null?e:"confirmed";return(r=await((o=i.getLatestBlockhash)==null?void 0:o.call(i,{commitment:t})))==null?void 0:r.blockhash}async function Ht(i,e){return i.getSignatureStatuses([e]),new Promise((t,o)=>{let r=setTimeout(o,6e4);i.onSignature(e,a=>{if(clearTimeout(r),!a.err){t("");return}o(Object.assign(a.err,{txId:e}))},"confirmed")})}function Ln(i,e){i.length<1&&Mo.logWithError(`no instructions provided: ${i.toString()}`),e.length<1&&Mo.logWithError(`no signers provided:, ${e.toString()}`);let t=new ue.Transaction;t.recentBlockhash="11111111111111111111111111111111",t.feePayer=e[0],t.add(...i);try{return Buffer.from(t.serialize({verifySignatures:!1})).toString("base64").length<vo}catch{return!1}}function $(i,e){let[t,o]=ue.PublicKey.findProgramAddressSync(i,e);return{publicKey:t,nonce:o}}function Tt({instructions:i,payer:e,signers:t}){return Ln(i,[e,...t])}function ht({instructions:i,payer:e,lookupTableAddressAccount:t,recentBlockhash:o=ue.Keypair.generate().publicKey.toString()}){let a=new ue.TransactionMessage({payerKey:e,recentBlockhash:o,instructions:i}).compileToV0Message(Object.values(t!=null?t:{}));try{return Buffer.from(new ue.VersionedTransaction(a).serialize()).toString("base64").length<vo}catch{return!1}}var Hr=i=>Buffer.isBuffer(i)?i:i instanceof Uint8Array?Buffer.from(i.buffer,i.byteOffset,i.byteLength):Buffer.from(i),Qr=i=>{let e=i.serialize({requireAllSignatures:!1,verifySignatures:!1});i instanceof ue.VersionedTransaction&&(e=Hr(e));try{return e instanceof Buffer?e.toString("base64"):Buffer.from(e).toString("base64")}catch{return e.toString("base64")}};function Ee(i){let e=[];return i.forEach(t=>{t instanceof ue.Transaction&&(t.recentBlockhash||(t.recentBlockhash=Fo.TOKEN_PROGRAM_ID.toBase58()),t.feePayer||(t.feePayer=ue.Keypair.generate().publicKey)),e.push(Qr(t))}),console.log("simulate tx string:",e),e}var Qt=2e3,Zt=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]}async getComputeBudgetConfig(){var o;let e=(await _o.default.get(`https://solanacompass.com/api/fees?cacheFreshTime=${3e5}`)).data,{avg:t}=(o=e==null?void 0:e[15])!=null?o:{};if(!!t)return{units:6e5,microLamports:Math.min(Math.ceil(t*1e6/6e5),25e3)}}addCustomComputeBudget(e){if(e){let{instructions:t,instructionTypes:o}=Yt(e);return this.instructions.unshift(...t),this.instructionTypes.unshift(...o),!0}return!1}addTipInstruction(e){var t;return e?(this.endInstructions.push(X.SystemProgram.transfer({fromPubkey:(t=e.feePayer)!=null?t:this.feePayer,toPubkey:new X.PublicKey(e.address),lamports:BigInt(e.amount.toString())})),this.endInstructionTypes.push(ne.TransferTip),!0):!1}async calComputeBudget({config:e,defaultIns:t}){try{let o=e||await this.getComputeBudgetConfig();if(this.addCustomComputeBudget(o))return;t&&this.instructions.unshift(...t)}catch{t&&this.instructions.unshift(...t)}}addInstruction({instructions:e=[],endInstructions:t=[],signers:o=[],instructionTypes:r=[],endInstructionTypes:a=[],lookupTableAddress:s=[]}){return this.instructions.push(...e),this.endInstructions.push(...t),this.signers.push(...o),this.instructionTypes.push(...r),this.endInstructionTypes.push(...a),this.lookupTableAddress.push(...s.filter(c=>c!==X.PublicKey.default.toString())),this}async versionBuild({txVersion:e,extInfo:t,lookupTableAddress:o}){return e===0?await this.buildV0(V(O({},t||{}),{lookupTableAddress:o})):this.build(t)}build(e){var o;let t=new X.Transaction;return this.allInstructions.length&&t.add(...this.allInstructions),t.feePayer=this.feePayer,((o=this.owner)==null?void 0:o.signer)&&!this.signers.some(r=>r.publicKey.equals(this.owner.publicKey))&&this.signers.push(this.owner.signer),{builder:this,transaction:t,signers:this.signers,instructionTypes:[...this.instructionTypes,...this.endInstructionTypes],execute:async r=>{var y;let{recentBlockHash:a,skipPreflight:s=!0,sendAndConfirm:c,notSendToRpc:p}=r||{},g=a!=null?a:await et(this.connection,this.blockhashCommitment);if(t.recentBlockhash=g,this.signers.length&&t.sign(...this.signers),Ee([t]),(y=this.owner)!=null&&y.isKeyPair)return{txId:c?await(0,X.sendAndConfirmTransaction)(this.connection,t,this.signers.find(I=>I.publicKey.equals(this.owner.publicKey))?this.signers:[...this.signers,this.owner.signer],{skipPreflight:s}):await this.connection.sendRawTransaction(t.serialize(),{skipPreflight:s}),signedTx:t};if(this.signAllTransactions){let k=await this.signAllTransactions([t]);if(this.signers.length)for(let I of k)try{I.sign(...this.signers)}catch{}return{txId:p?"":await this.connection.sendRawTransaction(k[0].serialize(),{skipPreflight:s}),signedTx:k[0]}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:e||{}}}buildMultiTx(e){var g;let{extraPreBuildData:t=[],extInfo:o}=e,{transaction:r}=this.build(o),a=t.filter(y=>y.transaction.instructions.length>0),s=[r,...a.map(y=>y.transaction)],c=[this.signers,...a.map(y=>y.signers)],p=[...this.instructionTypes,...a.map(y=>y.instructionTypes).flat()];return(g=this.owner)!=null&&g.signer&&c.forEach(y=>{y.some(k=>k.publicKey.equals(this.owner.publicKey))||this.signers.push(this.owner.signer)}),{builder:this,transactions:s,signers:c,instructionTypes:p,execute:async y=>{var A;let{sequentially:k,onTxUpdate:I,skipTxCount:h=0,recentBlockHash:S,skipPreflight:T=!0}=y||{},P=S!=null?S:await et(this.connection,this.blockhashCommitment);if((A=this.owner)!=null&&A.isKeyPair){if(k){let w=[],f=0;for(let R of s){if(++f,f<=h)continue;let b=await(0,X.sendAndConfirmTransaction)(this.connection,R,this.signers.find(B=>B.publicKey.equals(this.owner.publicKey))?this.signers:[...this.signers,this.owner.signer],{skipPreflight:T});w.push(b)}return{txIds:w,signedTxs:s}}return{txIds:await await Promise.all(s.map(async w=>(w.recentBlockhash=P,await this.connection.sendRawTransaction(w.serialize(),{skipPreflight:T})))),signedTxs:s}}if(this.signAllTransactions){let w=s.map((R,b)=>(R.recentBlockhash=P,c[b].length&&R.sign(...c[b]),R));Ee(w);let f=await this.signAllTransactions(w);if(k){let R=0,b=[],B=async()=>{if(!f[R])return;let C=await this.connection.sendRawTransaction(f[R].serialize(),{skipPreflight:T});b.push({txId:C,status:"sent",signedTx:f[R]}),I==null||I([...b]),R++;let N=!1,M=null,v=null,H=G=>{M!==null&&clearInterval(M),v!==null&&this.connection.removeSignatureListener(v);let W=b.findIndex(j=>j.txId===C);if(W>-1){if(b[W].status==="error"||b[W].status==="success")return;b[W].status=G.err?"error":"success"}I==null||I([...b]),G.err||B()};this.loopMultiTxStatus&&(M=setInterval(async()=>{var G;if(N){clearInterval(M);return}try{let W=await this.connection.getTransaction(C,{commitment:"confirmed",maxSupportedTransactionVersion:1});W&&(N=!0,clearInterval(M),H({err:((G=W.meta)==null?void 0:G.err)||null}),console.log("tx status from getTransaction:",C))}catch(W){N=!0,clearInterval(M),console.error("getTransaction timeout:",W,C)}},Qt)),v=this.connection.onSignature(C,G=>{if(N){this.connection.removeSignatureListener(v);return}N=!0,H(G)},"confirmed"),this.connection.getSignatureStatus(C)};return await B(),{txIds:b.map(C=>C.txId),signedTxs:f}}else{let R=[];for(let b=0;b<f.length;b+=1){let B=await this.connection.sendRawTransaction(f[b].serialize(),{skipPreflight:T});R.push(B)}return{txIds:R,signedTxs:f}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:o||{}}}async versionMultiBuild({extraPreBuildData:e,txVersion:t,extInfo:o}){return t===0?await this.buildV0MultiTx({extraPreBuildData:e,buildProps:o||{}}):this.buildMultiTx({extraPreBuildData:e,extInfo:o})}async buildV0(e){var T;let S=e||{},{lookupTableCache:t={},lookupTableAddress:o=[],forerunCreate:r,recentBlockhash:a}=S,s=ke(S,["lookupTableCache","lookupTableAddress","forerunCreate","recentBlockhash"]),c=O(O({},this.cluster==="devnet"?await Rn(this.connection):await Cn(this.connection)),t),p=Array.from(new Set([...o,...this.lookupTableAddress])),g=[];for(let P of p)c[P]===void 0&&g.push(new X.PublicKey(P));let y=await xn({connection:this.connection,address:g});for(let[P,A]of Object.entries(y))c[P]=A;let k=r?X.PublicKey.default.toBase58():a!=null?a:await et(this.connection,this.blockhashCommitment),I=new X.TransactionMessage({payerKey:this.feePayer,recentBlockhash:k,instructions:[...this.allInstructions]}).compileToV0Message(Object.values(c));((T=this.owner)==null?void 0:T.signer)&&!this.signers.some(P=>P.publicKey.equals(this.owner.publicKey))&&this.signers.push(this.owner.signer);let h=new X.VersionedTransaction(I);return h.sign(this.signers),{builder:this,transaction:h,signers:this.signers,instructionTypes:[...this.instructionTypes,...this.endInstructionTypes],execute:async P=>{var R;let{skipPreflight:A=!0,sendAndConfirm:w,notSendToRpc:f}=P||{};if(Ee([h]),(R=this.owner)!=null&&R.isKeyPair){let b=await this.connection.sendTransaction(h,{skipPreflight:A});return w&&await Ht(this.connection,b),{txId:b,signedTx:h}}if(this.signAllTransactions){let b=await this.signAllTransactions([h]);if(this.signers.length)for(let B of b)try{B.sign(this.signers)}catch{}return{txId:f?"":await this.connection.sendTransaction(b[0],{skipPreflight:A}),signedTx:b[0]}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:s||{}}}async buildV0MultiTx(e){var g;let{extraPreBuildData:t=[],buildProps:o}=e,{transaction:r}=await this.buildV0(o),a=t.filter(y=>y.builder.instructions.length>0),s=[r,...a.map(y=>y.transaction)],c=[this.signers,...a.map(y=>y.signers)],p=[...this.instructionTypes,...a.map(y=>y.instructionTypes).flat()];return(g=this.owner)!=null&&g.signer&&c.forEach(y=>{y.some(k=>k.publicKey.equals(this.owner.publicKey))||this.signers.push(this.owner.signer)}),s.forEach(async(y,k)=>{y.sign(c[k])}),{builder:this,transactions:s,signers:c,instructionTypes:p,buildProps:o,execute:async y=>{var T;let{sequentially:k,onTxUpdate:I,recentBlockHash:h,skipPreflight:S=!0}=y||{};if(h&&s.forEach(P=>P.message.recentBlockhash=h),Ee(s),(T=this.owner)!=null&&T.isKeyPair){if(k){let P=[];for(let A of s){let w=await this.connection.sendTransaction(A,{skipPreflight:S});await Ht(this.connection,w),P.push(w)}return{txIds:P,signedTxs:s}}return{txIds:await Promise.all(s.map(async P=>await this.connection.sendTransaction(P,{skipPreflight:S}))),signedTxs:s}}if(this.signAllTransactions){let P=await this.signAllTransactions(s);if(k){let A=0,w=[],f=async()=>{if(!P[A])return;let R=await this.connection.sendTransaction(P[A],{skipPreflight:S});w.push({txId:R,status:"sent",signedTx:P[A]}),I==null||I([...w]),A++;let b=!1,B=null,C=null,N=M=>{B!==null&&clearInterval(B),C!==null&&this.connection.removeSignatureListener(C);let v=w.findIndex(H=>H.txId===R);if(v>-1){if(w[v].status==="error"||w[v].status==="success")return;w[v].status=M.err?"error":"success"}I==null||I([...w]),M.err||f()};this.loopMultiTxStatus&&(B=setInterval(async()=>{var M;if(b){clearInterval(B);return}try{let v=await this.connection.getTransaction(R,{commitment:"confirmed",maxSupportedTransactionVersion:1});v&&(b=!0,clearInterval(B),N({err:((M=v.meta)==null?void 0:M.err)||null}),console.log("tx status from getTransaction:",R))}catch(v){b=!0,clearInterval(B),console.error("getTransaction timeout:",v,R)}},Qt)),C=this.connection.onSignature(R,M=>{if(b){this.connection.removeSignatureListener(C);return}b=!0,N(M)},"confirmed"),this.connection.getSignatureStatus(R)};return f(),{txIds:[],signedTxs:P}}else{let A=[];for(let w=0;w<P.length;w+=1){let f=await this.connection.sendTransaction(P[w],{skipPreflight:S});A.push(f)}return{txIds:A,signedTxs:P}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:o||{}}}async sizeCheckBuild(e){var I;let k=e||{},{splitIns:t=[],computeBudgetConfig:o}=k,r=ke(k,["splitIns","computeBudgetConfig"]),a=o?Yt(o):{instructions:[],instructionTypes:[]},s=this.signers.reduce((h,S)=>V(O({},h),{[S.publicKey.toBase58()]:S}),{}),c=[],p=[],g=[],y=0;if(this.allInstructions.forEach(h=>{let S=[...g,h],T=o?[...a.instructions,...S]:S,A=[...new Set(S.map(w=>w.keys.filter(f=>f.isSigner).map(f=>f.pubkey.toString())).flat()).values()].map(w=>new X.PublicKey(w));if(h!==t[y]&&g.length<12&&(Tt({instructions:T,payer:this.feePayer,signers:A})||Tt({instructions:S,payer:this.feePayer,signers:A})))g.push(h);else{if(g.length===0)throw Error("item ins too big");y+=h===t[y]?1:0,Tt({instructions:o?[...a.instructions,...g]:[...g],payer:this.feePayer,signers:A})?c.push(new X.Transaction().add(...a.instructions,...g)):c.push(new X.Transaction().add(...g)),p.push(Array.from(new Set(g.map(w=>w.keys.filter(f=>f.isSigner).map(f=>f.pubkey.toString())).flat())).map(w=>s[w]).filter(w=>w!==void 0)),g=[h]}}),g.length>0){let S=[...new Set(g.map(T=>T.keys.filter(P=>P.isSigner).map(P=>P.pubkey.toString())).flat()).values()].map(T=>s[T]).filter(T=>T!==void 0);Tt({instructions:o?[...a.instructions,...g]:[...g],payer:this.feePayer,signers:S.map(T=>T.publicKey)})?c.push(new X.Transaction().add(...a.instructions,...g)):c.push(new X.Transaction().add(...g)),p.push(S)}return c.forEach(h=>h.feePayer=this.feePayer),(I=this.owner)!=null&&I.signer&&p.forEach(h=>{h.some(S=>S.publicKey.equals(this.owner.publicKey))||h.push(this.owner.signer)}),{builder:this,transactions:c,signers:p,instructionTypes:this.instructionTypes,execute:async h=>{var R;let{sequentially:S,onTxUpdate:T,skipTxCount:P=0,recentBlockHash:A,skipPreflight:w=!0}=h||{},f=A!=null?A:await et(this.connection,this.blockhashCommitment);if(c.forEach(async(b,B)=>{b.recentBlockhash=f,p[B].length&&b.sign(...p[B])}),Ee(c),(R=this.owner)!=null&&R.isKeyPair){if(S){let b=0,B=[];for(let C of c){if(++b,b<=P){B.push("tx skipped");continue}let N=await(0,X.sendAndConfirmTransaction)(this.connection,C,this.signers.find(M=>M.publicKey.equals(this.owner.publicKey))?this.signers:[...this.signers,this.owner.signer],{skipPreflight:w});B.push(N)}return{txIds:B,signedTxs:c}}return{txIds:await Promise.all(c.map(async b=>await this.connection.sendRawTransaction(b.serialize(),{skipPreflight:w}))),signedTxs:c}}if(this.signAllTransactions){let b=await this.signAllTransactions(c.slice(P,c.length)),B=[...c.slice(0,P),...b];if(S){let C=0,N=[],M=async()=>{if(!B[C])return;C<P&&(N.push({txId:"",status:"success",signedTx:B[C]}),T==null||T([...N]),C++,M());let v=await this.connection.sendRawTransaction(B[C].serialize(),{skipPreflight:w});N.push({txId:v,status:"sent",signedTx:B[C]}),T==null||T([...N]),C++;let H=!1,G=null,W=null,j=q=>{G!==null&&clearInterval(G),W!==null&&this.connection.removeSignatureListener(W);let le=N.findIndex(Be=>Be.txId===v);if(le>-1){if(N[le].status==="error"||N[le].status==="success")return;N[le].status=q.err?"error":"success"}T==null||T([...N]),q.err||M()};this.loopMultiTxStatus&&(G=setInterval(async()=>{var q;if(H){clearInterval(G);return}try{let le=await this.connection.getTransaction(v,{commitment:"confirmed",maxSupportedTransactionVersion:1});le&&(H=!0,clearInterval(G),j({err:((q=le.meta)==null?void 0:q.err)||null}),console.log("tx status from getTransaction:",v))}catch(le){H=!0,clearInterval(G),console.error("getTransaction timeout:",le,v)}},Qt)),W=this.connection.onSignature(v,q=>{if(H){this.connection.removeSignatureListener(W);return}H=!0,j(q)},"confirmed"),this.connection.getSignatureStatus(v)};return await M(),{txIds:N.map(v=>v.txId),signedTxs:B}}else{let C=[];for(let N=0;N<B.length;N+=1){let M=await this.connection.sendRawTransaction(B[N].serialize(),{skipPreflight:w});C.push(M)}return{txIds:C,signedTxs:B}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:r||{}}}async sizeCheckBuildV0(e){var R;let f=e||{},{computeBudgetConfig:t,splitIns:o=[],lookupTableCache:r={},lookupTableAddress:a=[],insCountLimit:s=12}=f,c=ke(f,["computeBudgetConfig","splitIns","lookupTableCache","lookupTableAddress","insCountLimit"]),p=O(O({},this.cluster==="devnet"?await Rn(this.connection):await Cn(this.connection)),r),g=Array.from(new Set([...this.lookupTableAddress,...a])),y=[];for(let b of g)p[b]===void 0&&y.push(new X.PublicKey(b));let k=await xn({connection:this.connection,address:y});for(let[b,B]of Object.entries(k))p[b]=B;let I=t?Yt(t):{instructions:[],instructionTypes:[]},h=await et(this.connection,this.blockhashCommitment),S=this.signers.reduce((b,B)=>V(O({},b),{[B.publicKey.toBase58()]:B}),{}),T=[],P=[],A=[],w=0;if(this.allInstructions.forEach(b=>{let B=[...A,b],C=t?[...I.instructions,...B]:B;if(b!==o[w]&&A.length<s&&(ht({instructions:C,payer:this.feePayer,lookupTableAddressAccount:p})||ht({instructions:B,payer:this.feePayer,lookupTableAddressAccount:p})))A.push(b);else{if(A.length===0)throw Error("item ins too big");w+=b===o[w]?1:0;let N={};for(let M of[...new Set(g)])p[M]!==void 0&&(N[M]=p[M]);if(t&&ht({instructions:[...I.instructions,...A],payer:this.feePayer,lookupTableAddressAccount:p,recentBlockhash:h})){let M=new X.TransactionMessage({payerKey:this.feePayer,recentBlockhash:h,instructions:[...I.instructions,...A]}).compileToV0Message(Object.values(p));T.push(new X.VersionedTransaction(M))}else{let M=new X.TransactionMessage({payerKey:this.feePayer,recentBlockhash:h,instructions:[...A]}).compileToV0Message(Object.values(p));T.push(new X.VersionedTransaction(M))}P.push(Array.from(new Set(A.map(M=>M.keys.filter(v=>v.isSigner).map(v=>v.pubkey.toString())).flat())).map(M=>S[M]).filter(M=>M!==void 0)),A=[b]}}),A.length>0){let B=[...new Set(A.map(C=>C.keys.filter(N=>N.isSigner).map(N=>N.pubkey.toString())).flat()).values()].map(C=>S[C]).filter(C=>C!==void 0);if(t&&ht({instructions:[...I.instructions,...A],payer:this.feePayer,lookupTableAddressAccount:p,recentBlockhash:h})){let C=new X.TransactionMessage({payerKey:this.feePayer,recentBlockhash:h,instructions:[...I.instructions,...A]}).compileToV0Message(Object.values(p));T.push(new X.VersionedTransaction(C))}else{let C=new X.TransactionMessage({payerKey:this.feePayer,recentBlockhash:h,instructions:[...A]}).compileToV0Message(Object.values(p));T.push(new X.VersionedTransaction(C))}P.push(B)}return(R=this.owner)!=null&&R.signer&&P.forEach(b=>{b.some(B=>B.publicKey.equals(this.owner.publicKey))||b.push(this.owner.signer)}),T.forEach((b,B)=>{b.sign(P[B])}),{builder:this,transactions:T,buildProps:e,signers:P,instructionTypes:this.instructionTypes,execute:async b=>{var H;let{sequentially:B,onTxUpdate:C,skipTxCount:N=0,recentBlockHash:M,skipPreflight:v=!0}=b||{};if(T.map(async(G,W)=>{P[W].length&&G.sign(P[W]),M&&(G.message.recentBlockhash=M)}),Ee(T),(H=this.owner)!=null&&H.isKeyPair){if(B){let G=0,W=[];for(let j of T){if(++G,G<=N){console.log("skip tx: ",G),W.push("tx skipped");continue}let q=await this.connection.sendTransaction(j,{skipPreflight:v});await Ht(this.connection,q),W.push(q)}return{txIds:W,signedTxs:T}}return{txIds:await Promise.all(T.map(async G=>await this.connection.sendTransaction(G,{skipPreflight:v}))),signedTxs:T}}if(this.signAllTransactions){let G=await this.signAllTransactions(T.slice(N,T.length)),W=[...T.slice(0,N),...G];if(B){let j=0,q=[],le=async()=>{if(!W[j])return;if(j<N){q.push({txId:"",status:"success",signedTx:W[j]}),C==null||C([...q]),j++,le();return}let Be=await this.connection.sendTransaction(W[j],{skipPreflight:v});q.push({txId:Be,status:"sent",signedTx:W[j]}),C==null||C([...q]),j++;let yt=!1,He=null,Dt=null,go=ve=>{He!==null&&clearInterval(He),Dt!==null&&this.connection.removeSignatureListener(Dt);let Se=q.findIndex(Kr=>Kr.txId===Be);if(Se>-1){if(q[Se].status==="error"||q[Se].status==="success")return;q[Se].status=ve.err?"error":"success"}C==null||C([...q]),ve.err||le()};this.loopMultiTxStatus&&(He=setInterval(async()=>{var ve;if(yt){clearInterval(He);return}try{let Se=await this.connection.getTransaction(Be,{commitment:"confirmed",maxSupportedTransactionVersion:1});Se&&(yt=!0,clearInterval(He),go({err:((ve=Se.meta)==null?void 0:ve.err)||null}),console.log("tx status from getTransaction:",Be))}catch(Se){yt=!0,clearInterval(He),console.error("getTransaction timeout:",Se,Be)}},Qt)),Dt=this.connection.onSignature(Be,ve=>{if(yt){this.connection.removeSignatureListener(Dt);return}yt=!0,go(ve)},"confirmed"),this.connection.getSignatureStatus(Be)};return le(),{txIds:[],signedTxs:W}}else{let j=[];for(let q=0;q<W.length;q+=1){let le=await this.connection.sendTransaction(W[q],{skipPreflight:v});j.push(le)}return{txIds:j,signedTxs:W}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:c||{}}}};var On=(...i)=>i.map(e=>{try{return typeof e=="object"?JSON.stringify(e):e}catch{return e}}).join(", "),fe=class{constructor({scope:e,moduleName:t}){this.disabled=!1;this.scope=e,this.logger=z(t)}createTxBuilder(e){return this.scope.checkOwner(),new Zt({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(On(e))}logInfo(...e){this.logger.info(On(e))}logAndCreateError(...e){let t=On(e);throw new Error(t)}checkDisabled(){(this.disabled||!this.scope)&&this.logAndCreateError("module not working")}};var zo=require("@solana/web3.js"),ta=x(require("bn.js"));var tn=require("@solana/spl-token");var Go=require("@solana/web3.js"),Jr=x(require("bn.js"));var ea=require("@solana/spl-token");var Wo=require("@solana/web3.js"),tt=x(require("bn.js"));var L=require("@solana/buffer-layout"),$t=L.Layout,Vo=L.Structure;var Nn=L.UInt;var Eo=L.u8,Z=L.u16;var It=L.u32;var ge=L.s32;var Do=L.seq;var D=L.blob;var Mn=L.bits,Fn=L.offset;var We=class extends $t{constructor(t,o,r){super(t,r);this.blob=D(t),this.signed=o}decode(t,o=0){let r=new tt.default(this.blob.decode(t,o),10,"le");return this.signed?r.fromTwos(this.span*8).clone():r}encode(t,o,r=0){return typeof t=="number"&&(t=new tt.default(t)),this.signed&&(t=t.toTwos(this.span*8)),this.blob.encode(t.toArrayLike(Buffer,"le",this.span),o,r)}},jt=class extends $t{constructor(t){super(8,t);this._lower=Mn(It(),!1),this._upper=Mn(It(),!1)}addBoolean(t){this._lower.fields.length<32?this._lower.addBoolean(t):this._upper.addBoolean(t)}decode(t,o=0){let r=this._lower.decode(t,o),a=this._upper.decode(t,o+this._lower.span);return O(O({},r),a)}encode(t,o,r=0){return this._lower.encode(t,o,r)+this._upper.encode(t,o,r+this._lower.span)}};function l(i){return new Nn(1,i)}function J(i){return new Nn(4,i)}function n(i){return new We(8,!1,i)}function _(i){return new We(16,!1,i)}function qo(i){return new We(1,!0,i)}function nt(i){return new We(8,!0,i)}function Uo(i){return new We(16,!0,i)}var qe=class extends $t{constructor(t,o,r,a){super(t.span,a);this.layout=t,this.decoder=o,this.encoder=r}decode(t,o){return this.decoder(this.layout.decode(t,o))}encode(t,o,r){return this.layout.encode(this.encoder(t),o,r)}getSpan(t,o){return this.layout.getSpan(t,o)}};function u(i){return new qe(D(32),e=>new Wo.PublicKey(e),e=>e.toBuffer(),i)}function ye(i){return new qe(Eo(),Zr,$r,i)}function Zr(i){if(i===0)return!1;if(i===1)return!0;throw new Error("Invalid bool: "+i)}function $r(i){return i?1:0}function _n(i,e){let t=It("length"),o=m([t,K(i,Fn(t,-t.span),"values")]);return new qe(o,({values:r})=>r,r=>({values:r}),e)}function jr(i){let e=It("length"),t=m([e,D(Fn(e,-e.span),"data")]);return new qe(t,({data:o})=>o,o=>({data:o}),i)}function re(i){return new qe(jr(),e=>e.toString("utf-8"),e=>Buffer.from(e,"utf-8"),i)}var vn=class extends Vo{decode(e,t){return super.decode(e,t)}};function m(i,e,t){return new vn(i,e,t)}function K(i,e,t){let o,r=typeof e=="number"?e:(0,tt.isBN)(e)?e.toNumber():new Proxy(e,{get(a,s){if(!o){let c=Reflect.get(a,"count");o=(0,tt.isBN)(c)?c.toNumber():c,Reflect.set(a,"count",o)}return Reflect.get(a,s)},set(a,s,c){return s==="count"&&(o=c),Reflect.set(a,s,c)}});return Do(i,r,t)}var Jt=m([u("mint"),u("owner"),n("amount"),J("delegateOption"),u("delegate"),l("state"),J("isNativeOption"),n("isNative"),n("delegatedAmount"),J("closeAuthorityOption"),u("closeAuthority")]);var Ti=require("@solana/web3.js"),Ys=require("@solana/spl-token");var oa=require("@solana/web3.js"),ia=require("@solana/spl-token");var F=require("@solana/web3.js"),Ho=new F.PublicKey("EhhTKczWMGQt46ynNeRX1WfeagwwJd7ufHvCDjRxjo5Q"),Qo=new F.PublicKey("CBuCnLe26faBpcBP2fktp4rp8abpcAnTWft6ZrP5Q4T"),Zo=new F.PublicKey("9KEPoZmtHUrBbhWN1v1KWLMkkvwY6WLtAVUCPRtRjP4z"),Vn=new F.PublicKey("FarmqiPv5eAj3j1GMdMCMUGXqPUvmquZtMy86QH6rzhG"),od=new F.PublicKey("CLaimxFqjHzgTJtAGHU47NPhg6qrc5sCnpC4tBLyABQS"),ra=new F.PublicKey("srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX"),$o=new F.PublicKey("9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"),jo=new F.PublicKey("675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"),id=new F.PublicKey("5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h"),aa=new F.PublicKey("CDSr3ssLcRB6XYPJwAfFt18MZvEZp4LjHcvzBVZ45duo"),Jo=new F.PublicKey("CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK"),sa=new F.PublicKey("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),ua=new F.PublicKey("kN1kEznaF5Xbd8LYuqtEFcxzWSBk5Fv6ygX6SqEGJVy"),ei=new F.PublicKey("CDSr3ssLcRB6XYPJwAfFt18MZvEZp4LjHcvzBVZ45duo"),rd=new F.PublicKey("routeUGWgWzqBWFcrCfv8tritsqukccJPu3q5GPP3xS"),ca=new F.PublicKey("7YttLkHDoNj9wyDur5pM1ejNaAvT9X4eqaYcHQqtj2G5"),En=new F.PublicKey("CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C"),la=new F.PublicKey("GpMZbSM2GgvTKHJirzeGfMFoaZ8UR2X7F4v8vHTvxFbL"),ad=new F.PublicKey("DNXgeM9EiiaAbaWvwjHj9fQQLAX5ZsfHyvmYUNRAdNC8"),ma=new F.PublicKey("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),da=new F.PublicKey("3f7GcQFG397GAaEnv51zR6tsTVihYRydnydDD1cXekxH"),pa=new F.PublicKey("LanMV9sAd7wArD4vJFi2qDdfnVhFxYSUg6eADduJ3uj"),sd=new F.PublicKey("WLHv2UAZm6z4KyaaELi5pjdbJh6RESMva1Rnn8pJVVh"),ud=new F.PublicKey("DRay6fNdQ5J82H7xV6uq2aV3mNrUZ1J4PgSKsWgptcm6"),cd=new F.PublicKey("5xqNaZXX5eUi4p5HU4oz9i5QnwRNT2y6oN7yyn4qENeq"),ld=new F.PublicKey("4Bu96XjU84XjPDSpveTVf6LYGCkfW5FK7SNkREWcEfV4"),md=new F.PublicKey("6s1xP3hpbAfFoNtUNF8mfHsjr2Bd97JxFJRWLbL6aHuX");var Ne={OPEN_BOOK_PROGRAM:new F.PublicKey("EoTcMgcDRTJVZDMZWBoU6rhYHZfkNTVEAfz3uUJRcYGj"),SERUM_PROGRAM_ID_V3:new F.PublicKey("Ray1111111111111111111111111111111111111111"),AMM_V4:new F.PublicKey("DRaya7Kj3aMWQSy19kSjvmuwq9docCHofyP9kanQGaav"),AMM_STABLE:new F.PublicKey("DRayDdXc1NZQ9C3hRWmoSf8zK4iapgMnjdNZWrfwsP8m"),CLMM_PROGRAM_ID:new F.PublicKey("DRayAUgENGQBKVaX8owNhgzkEDyoHTGVEGHVJT1E9pfH"),CLMM_LOCK_PROGRAM_ID:new F.PublicKey("DRay25Usp3YJAi7beckgpGUC7mGJ2cR1AVPxhYfwVCUX"),CLMM_LOCK_AUTH_ID:new F.PublicKey("6Aoh8h2Lw2m5UGxYR8AdAL87jTWYeKoxM52mJRzfYwN"),CREATE_CPMM_POOL_PROGRAM:new F.PublicKey("DRaycpLY18LhpbydsBWbVJtxpNv9oXPgjRSfpF2bWpYb"),CREATE_CPMM_POOL_AUTH:new F.PublicKey("CXniRufdq5xL8t8jZAPxsPZDpuudwuJSPWnbcD5Y5Nxq"),CREATE_CPMM_POOL_FEE_ACC:new F.PublicKey("3oE58BKVt8KuYkGxx8zBojugnymWmBiyafWgMrnb6eYy"),LOCK_CPMM_PROGRAM:new F.PublicKey("DRay25Usp3YJAi7beckgpGUC7mGJ2cR1AVPxhYfwVCUX"),LOCK_CPMM_AUTH:new F.PublicKey("7qWVV8UY2bRJfDLP4s37YzBPKUkVB46DStYJBpYbQzu3"),UTIL1216:F.PublicKey.default,Router:new F.PublicKey("DRaybByLpbUL57LJARs3j8BitTxVfzBg351EaMr5UTCd"),FARM_PROGRAM_ID_V3:new F.PublicKey("DRayWyrLmEW5KEeqs8kdTMMaBabapqagaBC7KWpGtJeZ"),FARM_PROGRAM_ID_V4:new F.PublicKey("Ray1111111111111111111111111111111111111111"),FARM_PROGRAM_ID_V5:new F.PublicKey("DRayiCGSZgku1GTK6rXD6mVDdingXy6APAH1R6R5L2LC"),FARM_PROGRAM_ID_V6:new F.PublicKey("DRayzbYakXs45ELHkzH6vC3fuhQqTAnv5A68gdFuvZyZ"),LAUNCHPAD_PROGRAM:new F.PublicKey("DRay6fNdQ5J82H7xV6uq2aV3mNrUZ1J4PgSKsWgptcm6"),LAUNCHPAD_AUTH:new F.PublicKey("5xqNaZXX5eUi4p5HU4oz9i5QnwRNT2y6oN7yyn4qENeq"),LAUNCHPAD_PLATFORM:new F.PublicKey("2Jx4KTDrVSdWNazuGpcA8n3ZLTRGGBDxAWhuKe2Xcj2a"),LAUNCHPAD_CONFIG:new F.PublicKey("7ZR4zD7PYfY2XxoG1Gxcy2EgEeGYrpxrwzPuwdUBssEt"),FEE_DESTINATION_ID:new F.PublicKey("9y8ENuuZ3b19quffx9hQvRVygG5ky6snHfRvGpuSfeJy"),MODEL_DATA_PUBKEY:new F.PublicKey("Ray1111111111111111111111111111111111111111")};var Hs=x(require("decimal.js"));var Yn=require("@solana/spl-token"),cs=require("@solana/web3.js"),ls=x(require("bn.js")),ms=x(require("decimal.js"));var ya=require("@solana/spl-token"),ba=require("@solana/web3.js");var fa=m([J("mintAuthorityOption"),u("mintAuthority"),n("supply"),l("decimals"),l("isInitialized"),J("freezeAuthorityOption"),u("freezeAuthority")]);var zn=require("@solana/spl-token"),ln=require("@solana/web3.js"),as=x(require("bn.js"));var U=x(require("bn.js")),Pe=new U.default(1).shln(64);var ga=new U.default(1).shln(128),on=new U.default(1).shln(64).subn(1),Pa=new U.default(1).shln(128).subn(1);var it=new U.default("4295048016"),rt=new U.default("79226673521066979257578248091"),Aa=new U.default("59543866431248"),wa=new U.default("184467440737095516"),ka=new U.default("15793534762490258745");var Dn=60,vd=new U.default("18446743708227953217"),Ta=[{bit:0,factor:new U.default("fffcb933bd6fb800",16)},{bit:1,factor:new U.default("fff97272373d4000",16)},{bit:2,factor:new U.default("fff2e50f5f657000",16)},{bit:3,factor:new U.default("ffe5caca7e10f000",16)},{bit:4,factor:new U.default("ffcb9843d60f7000",16)},{bit:5,factor:new U.default("ff973b41fa98e800",16)},{bit:6,factor:new U.default("ff2ea16466c9b000",16)},{bit:7,factor:new U.default("fe5dee046a9a3800",16)},{bit:8,factor:new U.default("fcbe86c7900bb000",16)},{bit:9,factor:new U.default("f987a7253ac65800",16)},{bit:10,factor:new U.default("f3392b0822bb6000",16)},{bit:11,factor:new U.default("e7159475a2caf000",16)},{bit:12,factor:new U.default("d097f3bdfd2f2000",16)},{bit:13,factor:new U.default("a9f746462d9f8000",16)},{bit:14,factor:new U.default("70d869a156f31c00",16)},{bit:15,factor:new U.default("31be135f97ed3200",16)},{bit:16,factor:new U.default("9aa508b5b85a500",16)},{bit:17,factor:new U.default("5d6af8dedc582c",16)},{bit:18,factor:new U.default("2216e584f5fa",16)}];var Bt=3,ti=100;var ni=10,oi=100,rn=14;var oe=new U.default(0),at=new U.default(1),_d=new U.default(-1);var Vd=new U.default("18446744073700000000");var ha=m([D(8),l("bump"),Z("index"),u("owner"),J("protocolFeeRate"),J("tradeFeeRate"),Z("tickSpacing"),J("fundFeeRate"),K(J(),1),u("fundOwner"),K(n(),3)]),Ia=m([J("blockTimestamp"),nt("tickCumulative"),K(n(),4)]),ii=m([D(8),ye("initialized"),n("recentEpoch"),Z("observationIndex"),u("poolId"),K(Ia,ti,"observations"),K(n(),4)]),Ba=m([Z("filterPeriod"),Z("decayPeriod"),Z("reductionFactor"),J("dynamicFeeControl"),J("maxVolatilityAccumulator"),ge("tickSpacingIndexReference"),J("volatilityReference"),J("volatilityAccumulator"),n("lastUpdateTimestamp"),K(l(),46)]),Sa=m([l("state"),n("openTime"),n("endTime"),n("lastUpdateTime"),_("emissionsPerSecondX64"),n("totalEmissioned"),n("claimed"),u("mint"),u("vault"),u("creator"),_("growthGlobalX64")]),Wn=m([D(8),l("bump"),u("configId"),u("creator"),u("mintA"),u("mintB"),u("vaultA"),u("vaultB"),u("observationId"),l("mintDecimalsA"),l("mintDecimalsB"),Z("tickSpacing"),_("liquidity"),_("sqrtPriceX64"),ge("tickCurrent"),J(),_("feeGrowthGlobalX64A"),_("feeGrowthGlobalX64B"),n("protocolFeesTokenA"),n("protocolFeesTokenB"),K(_(),4),l("status"),l("feeOn"),D(6),K(Sa,Bt,"rewardInfos"),D(8*16,"tickArrayBitmap"),K(n(),4),n("fundFeesTokenA"),n("fundFeesTokenB"),n("startTime"),n("recentEpoch"),Ba.replicate("dynamicFeeInfo"),K(n(),46)]),Ka=m([_("growthInsideLastX64"),n("rewardAmountOwed")]),xa=m([D(8),l("bump"),u("nftMint"),u("poolId"),ge("tickLower"),ge("tickUpper"),_("liquidity"),_("feeGrowthInsideLastX64A"),_("feeGrowthInsideLastX64B"),n("tokenFeesOwedA"),n("tokenFeesOwedB"),K(Ka,Bt,"rewardInfos"),n("recentEpoch"),K(n(),7)]),qd=m([D(8),l("bump"),u("poolId"),ge("tickLower"),ge("tickUpper"),_("liquidity"),_("feeGrowthInsideLastX64A"),_("feeGrowthInsideLastX64B"),n("tokenFeesOwedA"),n("tokenFeesOwedB"),K(_(),Bt,"rewardGrowthInside"),n("recentEpoch"),K(n(),7)]),Ca=m([ge("tick"),Uo("liquidityNet"),_("liquidityGross"),_("feeGrowthOutsideX64A"),_("feeGrowthOutsideX64B"),K(_(),Bt,"rewardGrowthsOutsideX64"),n("orderPhase"),n("ordersAmount"),n("partFilledOrdersRemaining"),_("unfilledRatioX64"),K(J(),3)]),ri=m([D(8),u("poolId"),ge("startTickIndex"),K(Ca,Dn,"ticks"),l("initializedTickCount"),n("recentEpoch"),K(l(),107)]),Ra=m([D(8),l("bump"),K(u(),ni,"operationOwners"),K(u(),oi,"whitelistMints")]),La=m([D(8),u("poolId"),u("owner"),ge("tick"),ye("zeroForOne"),n("orderPhase"),n("totalAmount"),n("filledAmount"),n("settleBase"),n("settleOutput"),n("openTime"),_("unfilledRatioX64"),K(n(),4)]),ai=m([D(8),u("poolId"),D(8*8*rn,"positiveTickArrayBitmap"),D(8*8*rn,"negativeTickArrayBitmap")]),Ud=m([D(8),Z("index"),Z("filterPeriod"),Z("decayPeriod"),Z("reductionFactor"),J("dynamicFeeControl"),J("maxVolatilityAccumulator"),K(n(),8)]),Oa=m([D(8),u("wallet"),l("nonceIndex"),n("orderNonce"),K(n(),4)]),Gd=m([n(),l("bump"),u("owner"),u("poolId"),u("positionId"),u("nftAccount"),K(n(),8)]),Na=m([D(8),l("bump"),u("lockOwner"),u("poolId"),u("positionId"),u("nftAccount"),u("lockNftMint"),n("recentEpoch"),K(n(),8)]);var Ma=x(require("bn.js"));function qn(i){let e=Buffer.alloc(2);return e.writeUInt16LE(i),e}var np=Buffer.from("amm_config","utf8"),si=Buffer.from("pool","utf8"),ui=Buffer.from("pool_vault","utf8"),op=Buffer.from("pool_reward_vault","utf8"),ip=Buffer.from("position","utf8"),rp=Buffer.from("tick_array","utf8"),ap=Buffer.from("operation","utf8"),sp=Buffer.from("pool_tick_array_bitmap_extension","utf8"),up=Buffer.from("observation","utf8"),cp=Buffer.from("support_mint","utf8"),lp=Buffer.from("dynamic_fee_config","utf8"),mp=Buffer.from("permission","utf8");var dp=Buffer.from("locked_position","utf8");var yi=require("js-sha256");var ci=x(require("bn.js")),Fa=x(require("decimal.js"));var yp=new ci.default(1).shln(256).subn(1);var Va=x(require("bn.js"));var va=x(require("bn.js")),_a=x(require("decimal.js"));var Wa=x(require("bn.js")),qa=x(require("decimal.js"));var Qa=require("@solana/web3.js"),Za=x(require("bn.js"));var pi=require("@solana/spl-token");var $a=x(require("decimal.js"));var Xa=x(require("bn.js"));var Ga=x(require("bn.js"));var es=x(require("bn.js"));function ie(i){let e=`global:${i}`;return Buffer.from(yi.sha256.digest(e)).slice(0,8)}ii.span;var ly=z("Raydium_Clmm"),my={createPool:ie("create_pool"),createCustomizablePool:ie("create_customizable_pool"),createPermissionedPool:ie("create_permissioned_pool"),openPositionV2:ie("open_position_v2"),openPositionWithToken22Nft:ie("open_position_with_token22_nft"),closePosition:ie("close_position"),increaseLiquidityV2:ie("increase_liquidity_v2"),decreaseLiquidityV2:ie("decrease_liquidity_v2"),initializeReward:ie("initialize_reward"),setRewardParams:ie("set_reward_params"),updateRewardInfos:ie("update_reward_infos"),collectRemainingRewards:ie("collect_remaining_rewards"),swapV2:ie("swap_v2"),openLimitOrder:ie("open_limit_order"),increaseLimitOrder:ie("increase_limit_order"),decreaseLimitOrder:ie("decrease_limit_order"),settleLimitOrder:ie("settle_limit_order"),closeLimitOrder:ie("close_limit_order")};var mn=require("@solana/web3.js");var ps=m([l("instruction")]),fs=m([l("instruction")]),ys=m([n("rewardState"),n("rewardOpenTime"),n("rewardEndTime"),n("rewardLastUpdateTime"),n("totalReward"),n("totalRewardEmissioned"),n("rewardClaimed"),n("rewardPerSecond"),_("accRewardPerShare"),u("rewardVault"),u("rewardMint"),u("rewardSender"),n("rewardType"),K(n(),15,"padding")]),bs=m([n("state"),n("nonce"),u("lpVault"),u("rewardVault"),u(),u(),n(),n(),n("totalReward"),_("perShareReward"),n("lastSlot"),n("perSlotReward")]),gs=m([n("state"),n("nonce"),u("lpVault"),u("rewardVaultA"),n("totalRewardA"),_("perShareRewardA"),n("perSlotRewardA"),l("option"),u("rewardVaultB"),D(7),n("totalRewardB"),_("perShareRewardB"),n("perSlotRewardB"),n("lastSlot"),u()]),Ps=m([n(),n("state"),n("nonce"),n("validRewardTokenNum"),_("rewardMultiplier"),n("rewardPeriodMax"),n("rewardPeriodMin"),n("rewardPeriodExtend"),u("lpMint"),u("lpVault"),K(ys,5,"rewardInfos"),u("creator"),u(),K(n(),32,"padding")]),As=new Proxy(bs,{get(i,e,t){return e==="decode"?(...o)=>{let r=i.decode(...o);return V(O({},r),{version:3,rewardInfos:[{rewardVault:r.rewardVault,totalReward:r.totalReward,perSlotReward:r.perSlotReward,perShareReward:r.perShareReward}]})}:Reflect.get(i,e,t)}}),ws=new Proxy(gs,{get(i,e,t){return e==="decode"?(...o)=>{let r=i.decode(...o);return V(O({},r),{version:5,rewardInfos:[{rewardVault:r.rewardVaultA,totalReward:r.totalRewardA,perSlotReward:r.perSlotRewardA,perShareReward:r.perShareRewardA},{rewardVault:r.rewardVaultB,totalReward:r.totalRewardB,perSlotReward:r.perSlotRewardB,perShareReward:r.perShareRewardB}]})}:Reflect.get(i,e,t)}}),Pi=new Proxy(Ps,{get(i,e,t){return e==="decode"?(...o)=>{let r=i.decode(...o);return V(O({},r),{version:6,rewardInfos:r.rewardInfos.map(a=>{var s;return V(O({},a),{rewardType:((s=Object.entries(xt).find(c=>String(c[1])===a.rewardType.toString()))!=null?s:["Standard SPL"])[0]})})})}:Reflect.get(i,e,t)}}),ks=m([n("isSet"),n("rewardPerSecond"),n("rewardOpenTime"),n("rewardEndTime"),n("rewardType")]),Ts=m([l("instruction"),n("nonce"),K(ks,5,"rewardTimeInfo")]),hs=m([l("instruction"),n("rewardReopenTime"),n("rewardEndTime"),n("rewardPerSecond")]),Is=m([l("instruction"),n("isSet"),n("rewardPerSecond"),n("rewardOpenTime"),n("rewardEndTime"),n("rewardType")]),Zy=m([n("state"),u("id"),u("owner"),n("deposited"),K(n(),1,"rewardDebts")]),Ai=m([n("state"),u("id"),u("owner"),n("deposited"),K(_(),1,"rewardDebts"),n(""),n("voteLockedBalance"),K(n(),15)]),$y=m([n("state"),u("id"),u("owner"),n("deposited"),K(n(),2,"rewardDebts")]),Bs=m([n("state"),u("id"),u("owner"),n("deposited"),K(_(),2,"rewardDebts"),K(n(),17)]),Ss=m([n(),n("state"),u("id"),u("owner"),n("deposited"),K(_(),5,"rewardDebts"),K(n(),16)]),Ks=m([l("instruction"),n("amount")]),xs=m([u("mint"),u("grantAuthority"),n("baselineVoteWeightScaledFactor"),n("maxExtraLockupVoteWeightScaledFactor"),n("lockupSaturationSecs"),qo("digitShift"),K(l(),7,"reserved1"),K(n(),7,"reserved2")]),Cs=m([D(8),u("governanceProgramId"),u("realm"),u("realmGoverningTokenMint"),u("realmAuthority"),K(l(),32,"reserved1"),K(xs,4,"votingMints"),nt("timeOffset"),l("bump"),K(l(),7,"reserved2"),K(n(),11,"reserved3")]),Rs=m([nt("startTime"),nt("endTime"),l("kind"),K(l(),15,"reserved")]),Ls=m([K(Rs,1,"lockup"),n("amountDeposited_native"),n("amountInitiallyLockedNative"),ye("isUsed"),ye("allowClawback"),l("votingMintConfigIdx"),K(l(),29,"reserved")]),Os=m([D(8),u("voterAuthority"),u("registrar"),K(Ls,32,"deposits"),l("voterBump"),l("voterWweightRecordBump"),K(l(),94,"reserved")]);var Ns=require("@solana/spl-token"),ib=z("Raydium_farm_config"),Ms=new mn.PublicKey("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),Fs=new mn.PublicKey("FrspKwj8i3pNmKwXreTveC4fu7KL5ZbGeXdZBe2XViu1");var rb=new mn.PublicKey("3TRTX4dXUpp2eqxi3tvQDFYUV7SdDJjcPE3Y4mbtftaX");var xt={"Standard SPL":0,"Option tokens":1},wi={[Ho.toString()]:3,[Qo.toString()]:4,[Zo.toString()]:5,[Vn.toString()]:6,[Ne.FARM_PROGRAM_ID_V3.toString()]:3,[Ne.FARM_PROGRAM_ID_V4.toString()]:4,[Ne.FARM_PROGRAM_ID_V5.toString()]:5,[Ne.FARM_PROGRAM_ID_V6.toString()]:6};var Ct=require("@solana/web3.js"),Ws=x(require("bn.js")),Qn=require("@solana/spl-token");var Ds=x(require("bn.js"));var vs=require("@solana/web3.js"),_s=x(require("bn.js"));var Kb=z("Raydium.farm.util");var Yb=z("Raydium_farm_instruction"),Hb={voterStakeRegistryCreateVoter:Buffer.from([6,24,245,52,243,255,148,25]),voterStakeRegistryCreateDepositEntry:Buffer.from([185,131,167,186,159,125,19,67]),voterStakeRegistryDeposit:Buffer.from([242,35,198,137,82,225,242,182]),voterStakeRegistryWithdraw:Buffer.from([183,18,70,156,148,109,161,34]),voterStakeRegistryUpdateVoterWeightRecord:Buffer.from([45,185,3,36,109,190,115,169])};var Qs=x(require("bn.js"));var Tu=require("@solana/web3.js"),yn=require("@solana/spl-token");var ae=x(require("bn.js")),Rt=1e4;function dn(i,e){let{div:t,mod:o}=i.divmod(e);return o.gt(new ae.default(0))?t.add(new ae.default(1)):t}function Ue(i,e){if(i.isZero())return new ae.default(0);let t=i.div(e);return t.isZero()?new ae.default(1):i.mod(e).gt(new ae.default(0))?t.add(new ae.default(1)):t}function Lt(i,e,t){if(e===void 0)return{amount:i,fee:void 0,expirationTime:void 0};let o=Math.floor(t/432e3),r=o<e.newerTransferFee.epoch?e.olderTransferFee:e.newerTransferFee,a=new ae.default(r.maximumFee.toString()),s=o<e.newerTransferFee.epoch?(Number(e.newerTransferFee.epoch)*432e3-t)*400/1e3:void 0,c=dn(i.mul(new ae.default(r.transferFeeBasisPoints)),new ae.default(Rt)),p=c.gt(a)?a:c;return{amount:i,fee:p,expirationTime:s}}function ct(i,e,t){if(e===void 0)return{amount:i,fee:void 0,expirationTime:void 0};let o=Math.floor(t/432e3),r=o<e.newerTransferFee.epoch?e.olderTransferFee:e.newerTransferFee,a=new ae.default(r.maximumFee.toString()),s=o<e.newerTransferFee.epoch?(Number(e.newerTransferFee.epoch)*432e3-t)*400/1e3:void 0;if(r.transferFeeBasisPoints===Rt){let c=new ae.default(r.maximumFee.toString());return{amount:i.add(c),fee:c,expirationTime:s}}else{let c=dn(i.mul(new ae.default(Rt)),new ae.default(Rt-r.transferFeeBasisPoints)),p=new ae.default(r.maximumFee.toString()),g=c.sub(i).gt(p)?i.add(p):c,y=dn(g.mul(new ae.default(r.transferFeeBasisPoints)),new ae.default(Rt)),k=y.gt(a)?a:y;return{amount:g,fee:k,expirationTime:s}}}var Zn=x(require("bn.js")),Zs=new Zn.default(25),$s=new Zn.default(1e4);var Ii=require("@solana/spl-token"),pn=require("@solana/web3.js");var iu=x(require("bn.js"));var js=m([l("instruction"),n("amountIn"),n("minAmountOut")]),Js=m([l("instruction"),n("maxAmountIn"),n("amountOut")]),Gg=m([l("instruction"),l("nonce")]),eu=m([l("instruction"),l("nonce"),n("startTime")]),hi=m([n("status"),n("nonce"),n("maxOrder"),n("depth"),n("baseDecimal"),n("quoteDecimal"),n("state"),n("resetFlag"),n("minSize"),n("volMaxCutRatio"),n("amountWaveRatio"),n("baseLotSize"),n("quoteLotSize"),n("minPriceMultiplier"),n("maxPriceMultiplier"),n("systemDecimalValue"),n("minSeparateNumerator"),n("minSeparateDenominator"),n("tradeFeeNumerator"),n("tradeFeeDenominator"),n("pnlNumerator"),n("pnlDenominator"),n("swapFeeNumerator"),n("swapFeeDenominator"),n("baseNeedTakePnl"),n("quoteNeedTakePnl"),n("quoteTotalPnl"),n("baseTotalPnl"),n("poolOpenTime"),n("punishPcAmount"),n("punishCoinAmount"),n("orderbookToInitTime"),_("swapBaseInAmount"),_("swapQuoteOutAmount"),n("swapBase2QuoteFee"),_("swapQuoteInAmount"),_("swapBaseOutAmount"),n("swapQuote2BaseFee"),u("baseVault"),u("quoteVault"),u("baseMint"),u("quoteMint"),u("lpMint"),u("openOrders"),u("marketId"),u("marketProgramId"),u("targetOrders"),u("withdrawQueue"),u("lpVault"),u("owner"),n("lpReserve"),K(n(),3,"padding")]),zg=m([n("accountType"),n("status"),n("nonce"),n("maxOrder"),n("depth"),n("baseDecimal"),n("quoteDecimal"),n("state"),n("resetFlag"),n("minSize"),n("volMaxCutRatio"),n("amountWaveRatio"),n("baseLotSize"),n("quoteLotSize"),n("minPriceMultiplier"),n("maxPriceMultiplier"),n("systemDecimalsValue"),n("abortTradeFactor"),n("priceTickMultiplier"),n("priceTick"),n("minSeparateNumerator"),n("minSeparateDenominator"),n("tradeFeeNumerator"),n("tradeFeeDenominator"),n("pnlNumerator"),n("pnlDenominator"),n("swapFeeNumerator"),n("swapFeeDenominator"),n("baseNeedTakePnl"),n("quoteNeedTakePnl"),n("quoteTotalPnl"),n("baseTotalPnl"),n("poolOpenTime"),n("punishPcAmount"),n("punishCoinAmount"),n("orderbookToInitTime"),_("swapBaseInAmount"),_("swapQuoteOutAmount"),_("swapQuoteInAmount"),_("swapBaseOutAmount"),n("swapQuote2BaseFee"),n("swapBase2QuoteFee"),u("baseVault"),u("quoteVault"),u("baseMint"),u("quoteMint"),u("lpMint"),u("modelDataAccount"),u("openOrders"),u("marketId"),u("marketProgramId"),u("targetOrders"),u("owner"),K(n(),64,"padding")]),tu=m([l("instruction"),n("baseAmountIn"),n("quoteAmountIn"),n("fixedSide"),n("otherAmountMin")]),nu=m([l("instruction"),n("lpAmount"),n("baseAmountMin"),n("quoteAmountMin")]);var ou=m([n("fee")]);var tP=z("Raydium_liquidity_instruction");var ru=5e4,au=m([n("x"),n("y"),n("price")]),rP=m([n("accountType"),n("status"),n("multiplier"),n("validDataCount"),K(au,ru,"DataElement")]);var uu=require("@solana/web3.js"),cu=x(require("decimal.js")),lu=require("@solana/spl-token");var su=require("@solana/web3.js");var lP=z("Raydium_liquidity_serum");var hu=x(require("bn.js")),Iu=x(require("decimal.js"));var fu=require("@solana/spl-token"),yu=require("@solana/web3.js"),bu=x(require("bn.js"));var fn=require("@solana/web3.js"),Bi=require("@solana/spl-token");function mu(i="accountFlags"){let e=new jt(i);return e.addBoolean("initialized"),e.addBoolean("market"),e.addBoolean("openOrders"),e.addBoolean("requestQueue"),e.addBoolean("eventQueue"),e.addBoolean("bids"),e.addBoolean("asks"),e}var du=m([D(5),mu("accountFlags"),u("ownAddress"),n("vaultSignerNonce"),u("baseMint"),u("quoteMint"),u("baseVault"),n("baseDepositsTotal"),n("baseFeesAccrued"),u("quoteVault"),n("quoteDepositsTotal"),n("quoteFeesAccrued"),n("quoteDustThreshold"),u("requestQueue"),u("eventQueue"),u("bids"),u("asks"),n("baseLotSize"),n("quoteLotSize"),n("feeRateBps"),n("referrerRebatesAccrued"),D(7)]);var Lu=require("@solana/web3.js"),Ot=require("@solana/spl-token");var Su=x(require("bn.js"));var Si=x(require("bn.js"));var BA=new Si.default(0);var Bu=x(require("bn.js"));var Ki=x(require("bn.js")),Ie=new Ki.default(1e6);var Ou=x(require("bn.js")),Nu=x(require("decimal.js"));var bn=require("@solana/web3.js"),jn=require("@solana/spl-token");var EA=Buffer.from("vault_and_lp_mint_auth_seed","utf8"),DA=Buffer.from("amm_config","utf8"),WA=Buffer.from("pool","utf8"),qA=Buffer.from("pool_lp_mint","utf8"),UA=Buffer.from("pool_vault","utf8"),GA=Buffer.from("observation","utf8"),zA=Buffer.from("permission","utf8"),XA=Buffer.from("support_mint","utf8"),YA=Buffer.from("creator_fee_share","utf8");var HA=Buffer.from("locked_liquidity","utf8");var aw=z("Raydium_cpmm"),sw={initialize:[175,175,109,31,13,152,155,237],deposit:[242,35,198,137,82,225,242,182],withdraw:[183,18,70,156,148,109,161,34],swapBaseInput:[143,190,90,218,196,30,51,222],swapBaseOutput:[55,217,98,86,163,74,180,173],lockCpLiquidity:[216,157,29,78,38,51,31,26],collectCpFee:[8,30,51,199,209,184,247,133],createPermissionPda:Buffer.from([135,136,2,216,137,169,181,202]),closePermissionPda:Buffer.from([156,84,32,118,69,135,70,123]),initializeWithPermission:Buffer.from([63,55,254,65,49,178,89,121]),collectCreatorFee:Buffer.from([20,22,86,123,198,28,219,132]),collectCreatorFeePermissionless:Buffer.from([202,202,34,83,226,122,145,229])};var xu=m([D(8),l("bump"),ye("disableCreatePool"),Z("index"),n("tradeFeeRate"),n("protocolFeeRate"),n("fundFeeRate"),n("createPoolFee"),u("protocolOwner"),u("fundOwner"),n("creatorFeeRate"),n("creatorFeeShareRate"),K(n(),14)]),xi=m([D(8),u("configId"),u("poolCreator"),u("vaultA"),u("vaultB"),u("mintLp"),u("mintA"),u("mintB"),u("mintProgramA"),u("mintProgramB"),u("observationId"),l("bump"),l("status"),l("lpDecimals"),l("mintDecimalA"),l("mintDecimalB"),n("lpAmount"),n("protocolFeesMintA"),n("protocolFeesMintB"),n("fundFeesMintA"),n("fundFeesMintB"),n("openTime"),n("epoch"),l("feeOn"),ye("enableCreatorFee"),K(l(),6),n("creatorFeesMintA"),n("creatorFeesMintB"),K(n(),28)]),lw=m([D(8),u("configId"),K(n(),30)]),mw=m([D(8),l("bump"),u("creator"),u("ammConfig"),n("shareRate"),K(n(),8)]);var Ri=require("@solana/web3.js"),lt=require("@solana/spl-token"),Li=x(require("bn.js")),Vu=x(require("decimal.js"));var Mu={[$o.toBase58()]:3};var Fu=m([D(5),D(8),u("ownAddress"),n("vaultSignerNonce"),u("baseMint"),u("quoteMint"),u("baseVault"),n("baseDepositsTotal"),n("baseFeesAccrued"),u("quoteVault"),n("quoteDepositsTotal"),n("quoteFeesAccrued"),n("quoteDustThreshold"),u("requestQueue"),u("eventQueue"),u("bids"),u("asks"),n("baseLotSize"),n("quoteLotSize"),n("feeRateBps"),n("referrerRebatesAccrued"),D(7)]);var vu=require("@solana/web3.js");var Mk=z("Serum");var Jn=require("@solana/spl-token"),eo=require("@solana/web3.js"),_u=x(require("bn.js"));var CT=new Li.default(0);var Me=require("@solana/web3.js"),Ni=require("@solana/spl-token"),so=x(require("bn.js"));var ce=class extends fe{static getPdaPoolId(e,t){return $([ce.SEED_CONFIG.pool.id,t.toBuffer()],e)}static getPdaOwnerId(e,t,o,r){return $([ce.SEED_CONFIG.owner.id,t.toBuffer(),o.toBuffer(),Buffer.from(new so.default(r).toArray())],e)}static async getAllInfo({connection:e,programId:t,poolIds:o,wallet:r,chainTime:a}){if(o.length===0)return[];let s=o.map(y=>ce.getPdaPoolId(t,y).publicKey),c=[];for(let y=0;y<ce.VERSION_PROJECT.length;y++)c.push(...s.map(k=>ce.getPdaOwnerId(t,k,r,y).publicKey));let p=await Ke(e,[...s,...c]),g=[];for(let y=0;y<p.length;y++){let k=Math.floor(y/o.length),I=y%o.length,h=s[I],S=c[y],T=p[I],P=p[o.length+y];if(!(T&&P)||T.data.length!==ce.POOL_LAYOUT.span||P.data.length!==ce.OWNER_LAYOUT.span)continue;let A=ce.POOL_LAYOUT.decode(T.data),w=ce.OWNER_LAYOUT.decode(P.data),f=A.openTime.toNumber(),R=A.endTime.toNumber(),b=w.tokenInfo.map(N=>N.debtAmount.gt(new so.default(0))).filter(N=>!N).length!==3,B=a>f&&a<R&&A.status===1,C=b&&B;g.push({programId:t,poolId:h,ammId:A.ammId,ownerAccountId:S,snapshotLpAmount:w.lpAmount,project:ce.VERSION_PROJECT[k],openTime:f,endTime:R,canClaim:C,canClaimErrorType:b?B?void 0:"outOfOperationalTime":"alreadyClaimIt",tokenInfo:A.tokenInfo.map((N,M)=>({mintAddress:N.mintAddress,mintVault:N.mintVault,mintDecimals:N.mintDecimals,perLpLoss:N.perLpLoss,debtAmount:w.tokenInfo[M].debtAmount.add(w.tokenInfo[M].claimedAmount)}))})}return g}async makeClaimTransaction({poolInfo:e,ownerInfo:t,feePayer:o}){t.wallet||this.scope.checkOwner();let r=this.createTxBuilder(o),a=t.wallet||this.scope.ownerPubKey,s=[];for(let g of e.tokenInfo){let{account:y,instructionParams:k}=await this.scope.account.getOrCreateTokenAccount({mint:g.mintAddress,owner:this.scope.ownerPubKey,notUseTokenAccount:g.mintAddress.equals(se.WSOL.mint),createInfo:{payer:a,amount:0},skipCloseAccount:!g.mintAddress.equals(se.WSOL.mint),associatedOnly:g.mintAddress.equals(se.WSOL.mint)?!1:t.associatedOnly});k&&r.addInstruction(k),s.push(y)}r.addInstruction({instructions:[ce.makeClaimInstruction({programId:e.programId,poolInfo:e,ownerInfo:{wallet:a,ownerPda:e.ownerAccountId,claimAddress:s}})]});let{transaction:c,signers:p}=r.build();return[{transaction:c,signer:p}]}async makeClaimAllTransaction({poolInfos:e,ownerInfo:t,feePayer:o}){let r=this.createTxBuilder(o),a=t.wallet||this.scope.ownerPubKey,s={};for(let y of e){let k=[];for(let I of y.tokenInfo){let{account:h,instructionParams:S}=await this.scope.account.getOrCreateTokenAccount({mint:I.mintAddress,owner:this.scope.ownerPubKey,notUseTokenAccount:I.mintAddress.equals(se.WSOL.mint),createInfo:{payer:a,amount:0},skipCloseAccount:!I.mintAddress.equals(se.WSOL.mint),associatedOnly:I.mintAddress.equals(se.WSOL.mint)?!1:t.associatedOnly});S&&r.addInstruction(S),h&&(s[I.mintAddress.toString()]=h,k.push(h))}r.addInstruction({instructions:[ce.makeClaimInstruction({programId:y.programId,poolInfo:y,ownerInfo:{wallet:a,ownerPda:y.ownerAccountId,claimAddress:k}})]})}let{transaction:c,signers:p}=r.build(),g=r.allInstructions;return Ln(g,[a,...p.map(y=>y.publicKey)])?[{transaction:c,signer:p}]:[{transaction:new Me.Transaction().add(...g.slice(0,r.AllTxData.instructions.length-1)),signer:p},{transaction:new Me.Transaction().add(...g.slice(r.AllTxData.instructions.length-1)),signer:[]},{transaction:new Me.Transaction().add(...r.AllTxData.endInstructions),signer:[]}]}static makeClaimInstruction({programId:e,poolInfo:t,ownerInfo:o}){let r=m([]),a=[{pubkey:o.wallet,isSigner:!0,isWritable:!0},{pubkey:t.poolId,isSigner:!1,isWritable:!0},{pubkey:o.ownerPda,isSigner:!1,isWritable:!0},...o.claimAddress.map(p=>({pubkey:p,isSigner:!1,isWritable:!0})),...t.tokenInfo.map(({mintVault:p})=>({pubkey:p,isSigner:!1,isWritable:!0})),{pubkey:Ni.TOKEN_PROGRAM_ID,isSigner:!1,isWritable:!1}],s=Buffer.alloc(r.span);r.encode({},s);let c=Buffer.from([10,66,208,184,161,6,191,98,...s]);return new Me.TransactionInstruction({keys:a,programId:e,data:c})}},Ae=ce;Ae.CLAIMED_NUM=3,Ae.POOL_LAYOUT=m([D(8),l("bump"),l("status"),n("openTime"),n("endTime"),u("ammId"),K(m([l("mintDecimals"),u("mintAddress"),u("mintVault"),n("perLpLoss"),n("totalClaimedAmount")]),ce.CLAIMED_NUM,"tokenInfo"),K(n(),10,"padding")]),Ae.OWNER_LAYOUT=m([D(8),l("bump"),l("version"),u("poolId"),u("owner"),n("lpAmount"),K(m([u("mintAddress"),n("debtAmount"),n("claimedAmount")]),ce.CLAIMED_NUM,"tokenInfo"),K(n(),4,"padding")]),Ae.DEFAULT_POOL_ID=["58oQChx4yWmvKdwLLZzBi4ChoCc2fqCUWBkwMihLYQo2","6UmmUiYoBjSrhakAobJw8BvkmJtDVxaeBtbt7rxWo1mg","AVs9TA4nWDzfPJE9gGVNJMVhcQy3V9PGazuz33BfG2RA","DVa7Qmb5ct9RCpaU7UTpSaf3GVMYz17vNVU67XpdCRut","7XawhbbxtsRcQA8KTkHT9f9nc6d69UwqCDh6U5EEbEmX","6a1CsrpeZubDjEJE9s1CMVheB6HWM5d7m1cj2jkhyXhj","EoNrn8iUhwgJySD1pHu8Qxm5gSQqLK3za4m8xzD2RuEb","AceAyRTWt4PyB2pHqf2qhDgNZDtKVNaxgL8Ru3V4aN1P","6tmFJbMk5yVHFcFy7X2K8RwHjKLr6KVFLYXpgpBNeAxB"].map(e=>new Me.PublicKey(e)),Ae.SEED_CONFIG={pool:{id:Buffer.from("pool_seed","utf8")},owner:{id:Buffer.from("user_claim_seed","utf8")}},Ae.VERSION_PROJECT=[void 0,"Francium","Tulip","Larix"];var uo=(f=>(f[f.CurveType=0]="CurveType",f[f.MigrateType=1]="MigrateType",f[f.MigrateCpmmFeeOn=2]="MigrateCpmmFeeOn",f[f.Supply=3]="Supply",f[f.TotalSellA=4]="TotalSellA",f[f.TotalFundRaisingB=5]="TotalFundRaisingB",f[f.TotalLockedAmount=6]="TotalLockedAmount",f[f.CliffPeriod=7]="CliffPeriod",f[f.UnlockPeriod=8]="UnlockPeriod",f[f.BaseTokenProgram=9]="BaseTokenProgram",f[f.TransferFeeEnabled=10]="TransferFeeEnabled",f[f.TransferFeeBasisPoints=11]="TransferFeeBasisPoints",f[f.TransferFeeMaximumFee=12]="TransferFeeMaximumFee",f[f.SellRateA=13]="SellRateA",f[f.LockRate=14]="LockRate",f[f.MigrateAmountA=15]="MigrateAmountA",f[f.MigrateRateA=16]="MigrateRateA",f[f.FundRaisingRateB=17]="FundRaisingRateB",f[f.UnixTimestamp=18]="UnixTimestamp",f))(uo||{}),co=[4,13,15,16],lo=(r=>(r[r.Eq=0]="Eq",r[r.Gte=1]="Gte",r[r.Lte=2]="Lte",r[r.Neq=3]="Neq",r))(lo||{}),Mi=(t=>(t[t.SplToken=0]="SplToken",t[t.Token2022=1]="Token2022",t))(Mi||{}),gn=10,Pn=25,mo=(t=>(t[t.OnlyTokenB=0]="OnlyTokenB",t[t.BothToken=1]="BothToken",t))(mo||{});var Fi=Buffer.from("vault_auth_seed","utf8"),vi=Buffer.from("global_config","utf8"),_i=Buffer.from("pool_vesting","utf8"),Vi=Buffer.from("platform_config","utf8"),Ei=Buffer.from("platform_fee_vault_auth_seed","utf8"),Di=Buffer.from("creator_fee_vault_auth_seed","utf8"),Wi=Buffer.from("platform_global_access","utf8"),qi=Buffer.from("platform_allow_config","utf8"),Ui=Buffer.from("platform_curve_rule","utf8");function to(i){return $([Fi],i)}function Gi(i,e,t,o){return $([vi,e.toBuffer(),Eu(t),qn(o)],i)}function zi(i,e,t){return $([si,e.toBuffer(),t.toBuffer()],i)}function Xi(i,e,t){return $([ui,e.toBuffer(),t.toBuffer()],i)}function Ce(i){return $([Buffer.from("__event_authority","utf8")],i)}function Eu(i){let e=new ArrayBuffer(1);return new DataView(e).setUint8(0,i),new Uint8Array(e)}function Yi(i,e){return $([Vi,e.toBuffer()],i)}function Hi(i,e,t){return $([_i,e.toBuffer(),t.toBuffer()],i)}function no(i,e,t){return $([e.toBuffer(),t.toBuffer()],i)}function Qi(i){return $([Ei],i)}function oo(i,e,t){return $([e.toBuffer(),t.toBuffer()],i)}function Zi(i){return $([Di],i)}function Du(i,e,t){return $([Wi,e.toBuffer(),t.toBuffer()],i)}function $i(i,e,t){return $([qi,e.toBuffer(),t.toBuffer()],i)}function ji(i,e,t){return $([Ui,e.toBuffer(),t.toBuffer()],i)}var Xe=require("@solana/spl-token"),te=x(require("bn.js")),yo=require("@solana/web3.js");var Ji=m([n(),n("epoch"),l("curveType"),Z("index"),n("migrateFee"),n("tradeFeeRate"),n("maxShareFeeRate"),n("minSupplyA"),n("maxLockRate"),n("minSellRateA"),n("minMigrateRateA"),n("minFundRaisingB"),u("mintB"),u("protocolFeeOwner"),u("migrateFeeOwner"),u("migrateToAmmWallet"),u("migrateToCpmmWallet"),K(n(),16)]),er=m([n("totalLockedAmount"),n("cliffPeriod"),n("unlockPeriod"),n("startTime"),n("totalAllocatedShare")]),tr=m([n(),n("epoch"),l("bump"),l("status"),l("mintDecimalsA"),l("mintDecimalsB"),l("migrateType"),n("supply"),n("totalSellA"),n("virtualA"),n("virtualB"),n("realA"),n("realB"),n("totalFundRaisingB"),n("protocolFee"),n("platformFee"),n("migrateFee"),er.replicate("vestingSchedule"),u("configId"),u("platformId"),u("mintA"),u("mintB"),u("vaultA"),u("vaultB"),u("creator"),l("mintProgramFlag"),l("cpmmCreatorFeeOn"),n("platformVestingShare"),K(l(),54)]),Wu=m([n(),n("epoch"),u("poolId"),u("beneficiary"),n("claimedAmount"),n("tokenShareAmount"),K(n(),8)]),nr=m([l("migrateType"),l("migrateCpmmFeeOn"),n("supply"),n("totalSellA"),n("totalFundRaisingB"),n("totalLockedAmount"),n("cliffPeriod"),n("unlockPeriod")]),qu=m([n("epoch"),l("index"),u("configId"),nr.replicate("bondingCurveParam"),K(n(),50)]),io=m([n(),n("epoch"),u("platformClaimFeeWallet"),u("platformLockNftWallet"),n("platformScale"),n("creatorScale"),n("burnScale"),n("feeRate"),K(l(),64,"name"),K(l(),256,"web"),K(l(),256,"img"),u("cpConfigId"),n("creatorFeeRate"),u("transferFeeExtensionAuth"),u("platformVestingWallet"),n("platformVestingScale"),u("platformCpCreator"),l("restrictGlobalConfig"),l("restrictCurveParam"),u("curveRuleManager"),K(l(),78)]),or=m([l("field"),l("op"),_("value")]),ir=m([Z("groupId"),n("epoch"),_n(or,"constraints")]),rr=m([n(),l("bump"),l("version"),u("platformId"),u("configId"),n("epoch"),K(n(),8),_n(ir,"groups")]);var pe=x(require("bn.js")),po=x(require("decimal.js"));var Nt=x(require("bn.js")),mt=x(require("decimal.js"));var Re=class{static getPoolInitPriceByPool({poolInfo:e,decimalA:t,decimalB:o}){throw Error()}static getPoolInitPriceByInit({a:e,b:t,decimalA:o,decimalB:r}){throw Error()}static getPoolPrice({poolInfo:e,decimalA:t,decimalB:o}){throw Error()}static getPoolEndPrice({supply:e,totalSell:t,totalLockedAmount:o,totalFundRaising:r,migrateFee:a,decimalA:s,decimalB:c}){throw Error()}static getPoolEndPriceReal({poolInfo:e,decimalA:t,decimalB:o}){throw Error()}static getInitParam({supply:e,totalFundRaising:t,totalSell:o,totalLockedAmount:r,migrateFee:a}){throw Error()}static buyExactIn({poolInfo:e,amount:t}){throw Error()}static buyExactOut({poolInfo:e,amount:t}){throw Error()}static sellExactIn({poolInfo:e,amount:t}){throw Error()}static sellExactOut({poolInfo:e,amount:t}){throw Error()}};var Mt=class extends Re{static getPoolInitPriceByPool({poolInfo:e,decimalA:t,decimalB:o}){return new mt.default(e.virtualB.toString()).div(e.virtualA.toString()).mul(10**(t-o))}static getPoolInitPriceByInit({a:e,b:t,decimalA:o,decimalB:r}){return new mt.default(t.toString()).div(e.toString()).mul(10**(o-r))}static getPoolPrice({poolInfo:e,decimalA:t,decimalB:o}){return new mt.default(e.virtualB.add(e.realB).toString()).div(e.virtualA.sub(e.realA).toString()).mul(10**(t-o))}static getPoolEndPrice({supply:e,totalSell:t,totalLockedAmount:o,totalFundRaising:r,migrateFee:a,decimalA:s,decimalB:c}){return new mt.default(r.sub(a).toString()).div(e.sub(t).sub(o).toString()).mul(10**(s-c))}static getPoolEndPriceReal({poolInfo:e,decimalA:t,decimalB:o}){let r=e.totalSellA.sub(e.realA),a=e.totalFundRaisingB.sub(e.realB);return new mt.default(e.virtualB.add(e.realB.add(a)).toString()).div(e.virtualA.sub(e.realA.add(r)).toString()).mul(10**(t-o))}static getInitParam({supply:e,totalFundRaising:t,totalSell:o,totalLockedAmount:r,migrateFee:a}){if(e.lte(o))throw Error("supply need gt total sell");let s=e.sub(o).sub(r);if(s.lte(new Nt.default(0)))throw Error("supplyMinusSellLocked <= 0");let c=t.sub(a);if(c.lte(new Nt.default(0)))throw Error("tfMinusMf <= 0");let p=c.mul(o).mul(o).div(s),g=c.mul(o).div(s).sub(t),y=p.div(g),k=t.mul(t).div(g);if(y.lt(new Nt.default(0))||k.lt(new Nt.default(0)))throw Error("invalid input 0");return{a:y,b:k,c:o}}static buyExactIn({poolInfo:e,amount:t}){return this.getAmountOut({amountIn:t,inputReserve:e.virtualB.add(e.realB),outputReserve:e.virtualA.sub(e.realA)})}static buyExactOut({poolInfo:e,amount:t}){return this.getAmountIn({amountOut:t,inputReserve:e.virtualB.add(e.realB),outputReserve:e.virtualA.sub(e.realA)})}static sellExactIn({poolInfo:e,amount:t}){return this.getAmountOut({amountIn:t,inputReserve:e.virtualA.sub(e.realA),outputReserve:e.virtualB.add(e.realB)})}static sellExactOut({poolInfo:e,amount:t}){return this.getAmountIn({amountOut:t,inputReserve:e.virtualA.sub(e.realA),outputReserve:e.virtualB.add(e.realB)})}static getAmountOut({amountIn:e,inputReserve:t,outputReserve:o}){let r=e.mul(o),a=t.add(e);return r.div(a)}static getAmountIn({amountOut:e,inputReserve:t,outputReserve:o}){let r=t.mul(e),a=o.sub(e);return Ue(r,a)}};var Ft=x(require("bn.js")),dt=x(require("decimal.js"));var vt=class extends Re{static getPoolInitPriceByPool({poolInfo:e,decimalA:t,decimalB:o}){return new dt.default(e.virtualB.toString()).div(e.virtualA.toString()).mul(10**(t-o))}static getPoolInitPriceByInit({a:e,b:t,decimalA:o,decimalB:r}){return new dt.default(t.toString()).div(e.toString()).mul(10**(o-r))}static getPoolPrice({poolInfo:e,decimalA:t,decimalB:o}){return new dt.default(e.virtualB.toString()).div(e.virtualA.toString()).mul(10**(t-o))}static getPoolEndPrice({supply:e,totalSell:t,totalLockedAmount:o,totalFundRaising:r,migrateFee:a,decimalA:s,decimalB:c}){return new dt.default(r.sub(a).toString()).div(e.sub(t).sub(o).toString()).mul(10**(s-c))}static getPoolEndPriceReal({poolInfo:e,decimalA:t,decimalB:o}){let r=e.totalSellA.sub(e.realA),a=e.totalFundRaisingB.sub(e.realB);return new dt.default(e.virtualB.add(e.realB).add(a).toString()).div(e.virtualA.sub(e.realA).add(r).toString()).mul(10**(t-o))}static getInitParam({supply:e,totalFundRaising:t,totalSell:o,totalLockedAmount:r,migrateFee:a}){let s=e.sub(r);if(s.lte(new Ft.default(0)))throw Error("invalid input 1");let c=new Ft.default(2).mul(t).sub(a),g=t.mul(s).div(c);if(g.lt(new Ft.default(0))||t.lt(new Ft.default(0)))throw Error("invalid input 0");return{a:g,b:t,c:g}}static buyExactIn({poolInfo:e,amount:t}){return this.getAmountOut({amountIn:t,initInput:e.virtualB,initOutput:e.virtualA})}static buyExactOut({poolInfo:e,amount:t}){return this.getAmountIn({amountOut:t,initInput:e.virtualB,initOutput:e.virtualA})}static sellExactIn({poolInfo:e,amount:t}){return this.getAmountOut({amountIn:t,initInput:e.virtualA,initOutput:e.virtualB})}static sellExactOut({poolInfo:e,amount:t}){return this.getAmountIn({amountOut:t,initInput:e.virtualA,initOutput:e.virtualB})}static getAmountOut({amountIn:e,initInput:t,initOutput:o}){return o.mul(e).div(t)}static getAmountIn({amountOut:e,initInput:t,initOutput:o}){let r=t.mul(e);return Ue(r,o)}};var de=x(require("bn.js")),Fe=x(require("decimal.js"));var ze=x(require("bn.js")),_t=x(require("decimal.js")),pt=class{static _multipler(e){return new _t.default(10).pow(e)}static getPrice({priceX64:e,decimalA:t,decimalB:o}){return new _t.default(e.toString()).div(this._Q64).mul(this._multipler(t)).div(this._multipler(o))}static getPriceX64({price:e,decimalA:t,decimalB:o}){let r=e.mul(this._multipler(o)).div(this._multipler(t));return new ze.default(r.mul(this._Q64).toFixed(0))}};pt._Q64=new _t.default(new ze.default(1).shln(64).toString());function Uu({supply:i,totalFundRaisingB:e,totalLockedAmount:t,totalSellA:o,migrateType:r,decimalsA:a}){let s=i.sub(o).sub(t),c=new ze.default(new _t.default(s.mul(e).toString()).sqrt().toFixed(0));if(r==="amm"){if(c.gt(new ze.default(10).pow(new ze.default(a))))return!0}else if(r==="cpmm"){if(c.gt(new ze.default(100)))return!0}else throw Error("migrate type error");return!1}var Vt=class extends Re{static getPoolInitPriceByPool({poolInfo:e,decimalA:t,decimalB:o}){return new Fe.default(0)}static getPoolInitPriceByInit({a:e,b:t,decimalA:o,decimalB:r}){return new Fe.default(0)}static getPoolPrice({poolInfo:e,decimalA:t,decimalB:o}){return new Fe.default(e.virtualA.mul(e.realA).toString()).div(pt._Q64).mul(10**(t-o))}static getPoolEndPrice({supply:e,totalSell:t,totalLockedAmount:o,totalFundRaising:r,migrateFee:a,decimalA:s,decimalB:c}){return new Fe.default(r.sub(a).toString()).div(e.sub(t).sub(o).toString()).mul(10**(s-c))}static getPoolEndPriceReal({poolInfo:e,decimalA:t,decimalB:o}){let r=e.totalSellA.sub(e.realA),a=e.totalFundRaisingB.sub(e.realB);return new Fe.default(e.virtualB.add(e.realB).add(a).toString()).div(e.virtualA.sub(e.realA).add(r).toString()).mul(10**(t-o))}static getInitParam({supply:e,totalFundRaising:t,totalSell:o,totalLockedAmount:r,migrateFee:a}){let s=e.sub(r);if(s.lte(new de.default(0)))throw Error("supplyMinusLocked need gt 0");let c=t.mul(new de.default(3)).sub(a),g=t.mul(new de.default(2)).mul(s).div(c),y=g.mul(g),k=t.mul(new de.default(2)).mul(Pe).div(y);if(!k.gt(new de.default(0)))throw Error("a need gt 0");if(!on.gt(k))throw Error("a need lt u64 max");if(k.lt(new de.default(0))||g.lt(new de.default(0)))throw Error("invalid input 0");return{a:k,b:new de.default(0),c:g}}static buyExactIn({poolInfo:e,amount:t}){let o=e.realB.add(t),r=new de.default(2).mul(o).mul(Pe).div(e.virtualA);return new de.default(new Fe.default(r.toString()).sqrt().toFixed(0)).sub(e.realA)}static buyExactOut({poolInfo:e,amount:t}){let o=e.realA.add(t),r=o.mul(o);return Ue(e.virtualA.mul(r),new de.default(2).mul(Pe)).sub(e.realB)}static sellExactIn({poolInfo:e,amount:t}){let o=e.realA.sub(t),r=o.mul(o),a=Ue(e.virtualA.mul(r),new de.default(2).mul(Pe));return e.realB.sub(a)}static sellExactOut({poolInfo:e,amount:t}){let o=e.realB.sub(t),r=new de.default(2).mul(o).mul(Pe).div(e.virtualA),a=new de.default(new Fe.default(r.toString()).sqrt().toFixed(0));return e.realA.sub(a)}};var Ge=class{static getPoolCurvePointByPoolInfo({curveType:e,pointCount:t,poolInfo:o}){return this.getPoolCurvePointByInit({curveType:e,pointCount:t,supply:o.supply,totalFundRaising:o.totalFundRaisingB,totalSell:o.totalSellA,totalLockedAmount:o.vestingSchedule.totalLockedAmount,migrateFee:o.migrateFee,decimalA:o.mintDecimalsA,decimalB:o.mintDecimalsB})}static getPoolCurvePointByInit({curveType:e,pointCount:t,supply:o,totalFundRaising:r,totalSell:a,totalLockedAmount:s,migrateFee:c,decimalA:p,decimalB:g}){if(t<3)throw Error("point count < 3");let y=this.getCurve(e),k=y.getInitParam({supply:o,totalFundRaising:r,totalSell:a,totalLockedAmount:s,migrateFee:c}),I=y.getPoolInitPriceByInit(V(O({},k),{decimalA:p,decimalB:g})),h=r.div(new pe.default(t-1)),S=new pe.default(0),T=[{price:I,totalSellSupply:0}],{a:P,b:A}=k,w=S,f=S;for(let R=1;R<t;R++){let b=R!==t-1?h:r.sub(f),B=this.buyExactIn({poolInfo:{virtualA:P,virtualB:A,realA:w,realB:f,totalFundRaisingB:r,totalSellA:a},amountB:b,protocolFeeRate:S,platformFeeRate:S,curveType:e,shareFeeRate:S,creatorFeeRate:S,transferFeeConfigA:void 0,transferFeeConfigB:void 0,slot:0});w=w.add(B.amountA.amount),f=f.add(B.amountB);let C=this.getPrice({poolInfo:{virtualA:P,virtualB:A,realA:w,realB:f},decimalA:p,decimalB:g,curveType:e});T.push({price:C,totalSellSupply:new po.default(w.toString()).div(10**p).toNumber()})}return T}static getPoolInitPriceByPool({poolInfo:e,decimalA:t,decimalB:o,curveType:r}){return this.getCurve(r).getPoolInitPriceByPool({poolInfo:e,decimalA:t,decimalB:o})}static getPoolInitPriceByInit({a:e,b:t,decimalA:o,decimalB:r,curveType:a}){return this.getCurve(a).getPoolInitPriceByInit({a:e,b:t,decimalA:o,decimalB:r})}static getPrice({poolInfo:e,curveType:t,decimalA:o,decimalB:r}){return this.getCurve(t).getPoolPrice({poolInfo:e,decimalA:o,decimalB:r})}static getEndPrice({poolInfo:e,curveType:t,decimalA:o,decimalB:r}){return this.getCurve(t).getPoolPrice({poolInfo:e,decimalA:o,decimalB:r})}static getPoolEndPriceReal({poolInfo:e,curveType:t,decimalA:o,decimalB:r}){return this.getCurve(t).getPoolEndPriceReal({poolInfo:e,decimalA:o,decimalB:r})}static checkParam({supply:e,totalFundRaising:t,totalSell:o,totalLockedAmount:r,decimals:a,config:s,migrateType:c}){if(Number(a)!==6)throw Error("decimals = 6");if(e.mul(s.maxLockRate).div(Ie).lt(r))throw Error("total lock amount gte max lock amount");if(e.lt(s.minSupplyA.mul(new pe.default(10**a))))throw Error("supply lt min supply");let g=e.mul(s.minSellRateA).div(Ie);if(o.lt(g))throw Error("invalid input");if(t.lt(s.minFundRaisingB))throw Error("total fund raising lt min fund raising");let y=e.sub(o).sub(r),k=e.mul(s.minMigrateRateA).div(Ie);if(y.lt(k))throw Error("migrate lt min migrate amoount");let I=e.sub(o).sub(r),h=new pe.default(new po.default(I.mul(t).toString()).sqrt().toFixed(0));if(c==="amm"){let S=new pe.default(10).pow(new pe.default(a));if(h.lte(S))throw Error("check migrate lp error")}else if(c==="cpmm"){let S=new pe.default(100);if(h.lte(S))throw Error("check migrate lp error")}else throw Error("migrate type error")}static buyExactIn({poolInfo:e,amountB:t,protocolFeeRate:o,platformFeeRate:r,curveType:a,shareFeeRate:s,creatorFeeRate:c,transferFeeConfigA:p,transferFeeConfigB:g,slot:y}){var N;let k=Lt(t,g,y),I=t.sub((N=k.fee)!=null?N:new pe.default(0)),h=this.totalFeeRate({protocolFeeRate:o,platformFeeRate:r,shareFeeRate:s,creatorFeeRate:c}),S=this.calculateFee({amount:I,feeRate:h}),T=I.sub(S),P=this.getCurve(a),A=P.buyExactIn({poolInfo:e,amount:T}),w=e.totalSellA.sub(e.realA),f,R,b,B;if(A.gt(w)){f=w;let M=P.buyExactOut({poolInfo:e,amount:f}),v=this.calculatePreFee({postFeeAmount:M,feeRate:h});b=v.sub(M);let H=ct(v,g,y);R=H.amount,B=H.fee}else f=A,R=t,b=S,B=k.fee;let C=this.splitFee({totalFee:b,protocolFeeRate:o,platformFeeRate:r,shareFeeRate:s,creatorFeeRate:c});return{amountA:Lt(f,p,y),amountB:R,splitFee:C,transferFeeB:B}}static buyExactOut({poolInfo:e,amountA:t,protocolFeeRate:o,platformFeeRate:r,curveType:a,shareFeeRate:s,creatorFeeRate:c,transferFeeConfigA:p,transferFeeConfigB:g,slot:y}){let k=e.totalSellA.sub(e.realA),I=ct(t,p,y),h=I.fee?I.amount.add(I.fee):I.amount;t.gt(k)&&(h=k);let T=this.getCurve(a).buyExactOut({poolInfo:e,amount:h}),P=this.totalFeeRate({protocolFeeRate:o,platformFeeRate:r,shareFeeRate:s,creatorFeeRate:c}),A=this.calculatePreFee({postFeeAmount:T,feeRate:P}),w=A.sub(T),f=ct(A,g,y),R=this.splitFee({totalFee:w,protocolFeeRate:o,platformFeeRate:r,shareFeeRate:s,creatorFeeRate:c});return{amountA:I,amountB:f.amount,splitFee:R,transferFeeB:f.fee}}static sellExactIn({poolInfo:e,amountA:t,protocolFeeRate:o,platformFeeRate:r,curveType:a,shareFeeRate:s,creatorFeeRate:c,transferFeeConfigA:p,transferFeeConfigB:g,slot:y}){var f;let k=this.getCurve(a),I=Lt(t,p,y),h=I.fee?I.amount.sub(I.fee):I.amount,S=k.sellExactIn({poolInfo:e,amount:h}),T=this.calculateFee({amount:S,feeRate:this.totalFeeRate({protocolFeeRate:o,platformFeeRate:r,shareFeeRate:s,creatorFeeRate:c})}),P=this.splitFee({totalFee:T,protocolFeeRate:o,platformFeeRate:r,shareFeeRate:s,creatorFeeRate:c}),A=S.sub(T),w=Lt(A,g,y);return{amountA:I,amountB:A.sub((f=w.fee)!=null?f:new pe.default(0)),splitFee:P,transferFeeB:w.fee}}static sellExactOut({poolInfo:e,amountB:t,protocolFeeRate:o,platformFeeRate:r,curveType:a,shareFeeRate:s,creatorFeeRate:c,transferFeeConfigA:p,transferFeeConfigB:g,slot:y}){let k=this.totalFeeRate({protocolFeeRate:o,platformFeeRate:r,shareFeeRate:s,creatorFeeRate:c}),I=ct(t,g,y),h=I.amount,S=this.calculatePreFee({postFeeAmount:h,feeRate:k});if(e.realB.lt(S))throw Error("Insufficient liquidity");let T=S.sub(h),A=Ge.getCurve(a).sellExactOut({poolInfo:e,amount:S});if(A.gt(e.realA))throw Error();let w=this.splitFee({totalFee:T,protocolFeeRate:o,platformFeeRate:r,shareFeeRate:s,creatorFeeRate:c});return{amountA:ct(A,p,y),amountB:t,splitFee:w,transferFeeB:I.fee}}static splitFee({totalFee:e,protocolFeeRate:t,platformFeeRate:o,shareFeeRate:r,creatorFeeRate:a}){let s=this.totalFeeRate({protocolFeeRate:t,platformFeeRate:o,shareFeeRate:r,creatorFeeRate:a}),c=s.isZero()?new pe.default(0):e.mul(o).div(s),p=s.isZero()?new pe.default(0):e.mul(r).div(s),g=s.isZero()?new pe.default(0):e.mul(a).div(s),y=e.sub(c).sub(p).sub(g);return{platformFee:c,shareFee:p,protocolFee:y,creatorFee:g}}static calculateFee({amount:e,feeRate:t}){return $n(e,t,Ie)}static calculatePreFee({postFeeAmount:e,feeRate:t}){if(t.isZero())return e;let o=e.mul(Ie),r=Ie.sub(t);return o.add(r).sub(new pe.default(1)).div(r)}static totalFeeRate({protocolFeeRate:e,platformFeeRate:t,shareFeeRate:o,creatorFeeRate:r}){if(e.add(t).add(o).add(r).gt(new pe.default(1e6)))throw Error("total fee rate gt 1_000_000");return e.add(t).add(o).add(r)}static getCurve(e){switch(e){case 0:return Mt;case 1:return vt;case 2:return Vt}throw Error("find curve error")}};var ft=require("@solana/spl-token"),ar=(t=>(t[t.MintA=0]="MintA",t[t.MintB=1]="MintB",t))(ar||{});function fo(i,e){return i>>e&1?ft.TOKEN_2022_PROGRAM_ID:ft.TOKEN_PROGRAM_ID}function Oi(i){return fo(i,0)}function Gu(i){return fo(i,1)}function sr({mintAProgram:i,mintBProgram:e}){return(i.equals(ft.TOKEN_2022_PROGRAM_ID)?1<<0:0)|(e.equals(ft.TOKEN_2022_PROGRAM_ID)?1<<1:0)}var zu=x(require("decimal.js")),Xu={initPriceX64:new te.default("515752397214619"),supply:new te.default(1e15),totalSellA:new te.default(7931e11),totalFundRaisingB:new te.default(85e9),totalFundRaisingBUSD:new te.default(125e8),totalLockedAmount:new te.default("0"),cliffPeriod:new te.default("0"),unlockPeriod:new te.default("0"),decimals:6,virtualA:new te.default("1073471847374405"),virtualB:new te.default("30050573465"),realA:new te.default(0),realB:new te.default(0),protocolFee:new te.default(0),platformId:new yo.PublicKey("4Bu96XjU84XjPDSpveTVf6LYGCkfW5FK7SNkREWcEfV4"),vestingSchedule:{totalLockedAmount:new te.default(0),cliffPeriod:new te.default(0),unlockPeriod:new te.default(0),startTime:new te.default(0),totalAllocatedShare:new te.default(0)}},tI=new te.default(1e4),Yu=new Set(["USDCoctVLVnvTXBEuP9s8hntucdJokbo17RwHuNXemT","USD1ttGY1N17NEEHLmELoaybftRBUSErhqYiQzvEmuB"]);var Hu=require("@solana/web3.js"),Et=require("@solana/spl-token");var SB=new Le.default(2),KB=new Le.default(3),xB=new Le.default(5),qr=new Le.default(10),CB=new Le.default(100),RB=new Le.default(1e3),LB=new Le.default(1e4);function $n(i,e,t){return i.mul(e).add(t).sub(new Le.default(1)).div(t)}function Tn(i,e=1,t=[]){let o=[...i];if(e<=0)return t;for(;o.length;)t.push(o.splice(0,e));return t}var we=require("@solana/spl-token"),E=require("@solana/web3.js"),Ye=x(require("bn.js"));var ee={initialize:Buffer.from([175,175,109,31,13,152,155,237]),initializeV2:Buffer.from([67,153,175,39,218,16,38,32]),buyExactIn:Buffer.from([250,234,13,123,213,156,19,236]),buyExactOut:Buffer.from([24,211,116,40,105,3,153,56]),sellExactIn:Buffer.from([149,39,222,155,211,124,152,26]),sellExactOut:Buffer.from([95,200,71,34,8,9,11,166]),createVestingAccount:Buffer.from([129,178,2,13,217,172,230,218]),claimVestedToken:Buffer.from([49,33,104,30,189,157,79,35]),createPlatformConfig:Buffer.from([176,90,196,175,253,113,220,20]),claimPlatformFee:Buffer.from([156,39,208,135,76,237,61,72]),updatePlaformConfig:Buffer.from([195,60,76,129,146,45,67,143]),initializeWithToken2022:Buffer.from([37,190,126,222,44,154,171,17]),claimPlatformFeeFromVault:Buffer.from([117,241,198,168,248,218,80,29]),claimCreatorFee:Buffer.from([26,97,138,203,132,171,141,252]),createPlatformVestingAccount:Buffer.from([146,71,173,69,98,19,15,106]),createPlatformAllowConfig:Buffer.from([69,71,168,7,214,250,107,102]),closePlatformAllowConfig:Buffer.from([82,205,36,216,16,6,240,215]),createPlatformCurveRule:Buffer.from([148,71,180,136,122,144,59,21]),updatePlatformCurveRule:Buffer.from([90,100,206,196,54,117,120,139]),removePlatformCurveRule:Buffer.from([236,77,154,138,32,145,127,219]),closePlatformCurveRule:Buffer.from([194,114,82,45,136,88,169,159])};function $u(i,e,t,o,r,a,s,c,p,g,y,k,I,h,S,T,P,A,w,f){throw new Error("*** launchlab initialize has been deprecated, please use initializeV2 instead! ***")}function ur(i,e,t,o,r,a,s,c,p,g,y,k,I,h,S,T,P,A,w,f,R,b,B,C){let N=m([l("decimals"),re("name"),re("symbol"),re("uri")]),M=m([n("totalLockedAmount"),n("cliffPeriod"),n("unlockPeriod"),l("cpmmCreatorFeeOn")]),v=m([l("index"),n("supply"),n("totalFundRaisingB"),l("migrateType")]),H=m([l("index"),n("supply"),n("totalSellA"),n("totalFundRaisingB"),l("migrateType")]),G=[{pubkey:e,isSigner:!0,isWritable:!0},{pubkey:t,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!1,isWritable:!1},{pubkey:a,isSigner:!1,isWritable:!1},{pubkey:s,isSigner:!1,isWritable:!0},{pubkey:c,isSigner:!0,isWritable:!0},{pubkey:p,isSigner:!1,isWritable:!1},{pubkey:g,isSigner:!1,isWritable:!0},{pubkey:y,isSigner:!1,isWritable:!0},{pubkey:k,isSigner:!1,isWritable:!0},{pubkey:we.TOKEN_PROGRAM_ID,isSigner:!1,isWritable:!1},{pubkey:I,isSigner:!1,isWritable:!1},{pubkey:$e,isSigner:!1,isWritable:!1},{pubkey:E.SystemProgram.programId,isSigner:!1,isWritable:!1},{pubkey:Ve,isSigner:!1,isWritable:!1},{pubkey:Ce(i).publicKey,isSigner:!1,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!1}];B&&G.push({pubkey:B,isSigner:!1,isWritable:!1}),C&&G.push({pubkey:C,isSigner:!1,isWritable:!1});let W=Buffer.alloc(Buffer.from(S,"utf-8").length+Buffer.from(T,"utf-8").length+Buffer.from(P,"utf-8").length+4*3+1),j=Buffer.alloc(M.span),q=Buffer.alloc(A.type==="ConstantCurve"?H.span:v.span);return N.encode({decimals:h,name:S,symbol:T,uri:P},W),A.type==="ConstantCurve"?H.encode(V(O({index:0},A),{migrateType:A.migrateType==="amm"?0:1}),q):A.type==="FixedCurve"?v.encode(V(O({index:1},A),{migrateType:A.migrateType==="amm"?0:1}),q):A.type==="LinearCurve"&&v.encode(V(O({index:2},A),{migrateType:A.migrateType==="amm"?0:1}),q),M.encode({totalLockedAmount:w,cliffPeriod:f,unlockPeriod:R,cpmmCreatorFeeOn:b},j),new E.TransactionInstruction({keys:G,programId:i,data:Buffer.from([...ee.initializeV2,...W,...q,...j])})}function cr(i,e,t,o,r,a,s,c,p,g,y,k,I,h,S,T,P,A,w,f,R,b,B,C){let N=m([l("decimals"),re("name"),re("symbol"),re("uri")]),M=m([n("totalLockedAmount"),n("cliffPeriod"),n("unlockPeriod"),l("cpmmCreatorFeeOn"),l("transferFeeExtensionParamsOption"),m([Z("transferFeeBasePoints"),n("maxinumFee")]).replicate("transferFeeExtensionParams")]),v=m([l("index"),n("supply"),n("totalFundRaisingB"),l("migrateType")]),H=m([l("index"),n("supply"),n("totalSellA"),n("totalFundRaisingB"),l("migrateType")]),G=[{pubkey:e,isSigner:!0,isWritable:!0},{pubkey:t,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!1,isWritable:!1},{pubkey:a,isSigner:!1,isWritable:!1},{pubkey:s,isSigner:!1,isWritable:!0},{pubkey:c,isSigner:!0,isWritable:!0},{pubkey:p,isSigner:!1,isWritable:!1},{pubkey:g,isSigner:!1,isWritable:!0},{pubkey:y,isSigner:!1,isWritable:!0},{pubkey:we.TOKEN_2022_PROGRAM_ID,isSigner:!1,isWritable:!1},{pubkey:k,isSigner:!1,isWritable:!1},{pubkey:E.SystemProgram.programId,isSigner:!1,isWritable:!1},{pubkey:Ce(i).publicKey,isSigner:!1,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!1}];B&&G.push({pubkey:B,isSigner:!1,isWritable:!1}),C&&G.push({pubkey:C,isSigner:!1,isWritable:!1});let W=Buffer.alloc(Buffer.from(h,"utf-8").length+Buffer.from(S,"utf-8").length+Buffer.from(T,"utf-8").length+4*3+1),j=Buffer.alloc(M.span),q=Buffer.alloc(P.type==="ConstantCurve"?H.span:v.span);return N.encode({decimals:I,name:h,symbol:S,uri:T},W),P.type==="ConstantCurve"?H.encode(V(O({index:0},P),{migrateType:P.migrateType==="amm"?0:1}),q):P.type==="FixedCurve"?v.encode(V(O({index:1},P),{migrateType:P.migrateType==="amm"?0:1}),q):P.type==="LinearCurve"&&v.encode(V(O({index:2},P),{migrateType:P.migrateType==="amm"?0:1}),q),M.encode({totalLockedAmount:A,cliffPeriod:w,unlockPeriod:f,cpmmCreatorFeeOn:R,transferFeeExtensionParamsOption:b?1:0,transferFeeExtensionParams:b!=null?b:{transferFeeBasePoints:0,maxinumFee:new Ye.default(0)}},j),new E.TransactionInstruction({keys:G,programId:i,data:Buffer.from([...ee.initializeWithToken2022,...W,...q,...j])})}function ro(i,e,t,o,r,a,s,c,p,g,y,k,I,h,S,T,P,A,w,f){let R=m([n("amountB"),n("minAmountA"),n("shareFeeRate")]),b=[{pubkey:e,isSigner:!0,isWritable:!0},{pubkey:t,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!1,isWritable:!1},{pubkey:a,isSigner:!1,isWritable:!0},{pubkey:s,isSigner:!1,isWritable:!0},{pubkey:c,isSigner:!1,isWritable:!0},{pubkey:p,isSigner:!1,isWritable:!0},{pubkey:g,isSigner:!1,isWritable:!0},{pubkey:y,isSigner:!1,isWritable:!1},{pubkey:k,isSigner:!1,isWritable:!1},{pubkey:I,isSigner:!1,isWritable:!1},{pubkey:h,isSigner:!1,isWritable:!1},{pubkey:Ce(i).publicKey,isSigner:!1,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!1}];f&&b.push({pubkey:f,isSigner:!1,isWritable:!0}),b.push({pubkey:E.SystemProgram.programId,isSigner:!1,isWritable:!1}),b.push({pubkey:S,isSigner:!1,isWritable:!0}),b.push({pubkey:T,isSigner:!1,isWritable:!0});let B=Buffer.alloc(R.span);return R.encode({amountB:P,minAmountA:A,shareFeeRate:w!=null?w:new Ye.default(0)},B),new E.TransactionInstruction({keys:b,programId:i,data:Buffer.from([...ee.buyExactIn,...B])})}function lr(i,e,t,o,r,a,s,c,p,g,y,k,I,h,S,T,P,A,w,f){let R=m([n("amountA"),n("maxAmountB"),n("shareFeeRate")]),b=[{pubkey:e,isSigner:!0,isWritable:!0},{pubkey:t,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!1,isWritable:!1},{pubkey:a,isSigner:!1,isWritable:!0},{pubkey:s,isSigner:!1,isWritable:!0},{pubkey:c,isSigner:!1,isWritable:!0},{pubkey:p,isSigner:!1,isWritable:!0},{pubkey:g,isSigner:!1,isWritable:!0},{pubkey:y,isSigner:!1,isWritable:!1},{pubkey:k,isSigner:!1,isWritable:!1},{pubkey:I,isSigner:!1,isWritable:!1},{pubkey:h,isSigner:!1,isWritable:!1},{pubkey:Ce(i).publicKey,isSigner:!1,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!1}];f&&b.push({pubkey:f,isSigner:!1,isWritable:!0}),b.push({pubkey:E.SystemProgram.programId,isSigner:!1,isWritable:!1}),b.push({pubkey:S,isSigner:!1,isWritable:!0}),b.push({pubkey:T,isSigner:!1,isWritable:!0});let B=Buffer.alloc(R.span);return R.encode({amountA:P,maxAmountB:A,shareFeeRate:w!=null?w:new Ye.default(0)},B),new E.TransactionInstruction({keys:b,programId:i,data:Buffer.from([...ee.buyExactOut,...B])})}function ao(i,e,t,o,r,a,s,c,p,g,y,k,I,h,S,T,P,A,w,f){let R=m([n("amountA"),n("minAmountB"),n("shareFeeRate")]),b=[{pubkey:e,isSigner:!0,isWritable:!0},{pubkey:t,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!1,isWritable:!1},{pubkey:a,isSigner:!1,isWritable:!0},{pubkey:s,isSigner:!1,isWritable:!0},{pubkey:c,isSigner:!1,isWritable:!0},{pubkey:p,isSigner:!1,isWritable:!0},{pubkey:g,isSigner:!1,isWritable:!0},{pubkey:y,isSigner:!1,isWritable:!1},{pubkey:k,isSigner:!1,isWritable:!1},{pubkey:I,isSigner:!1,isWritable:!1},{pubkey:h,isSigner:!1,isWritable:!1},{pubkey:Ce(i).publicKey,isSigner:!1,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!1}];f&&b.push({pubkey:f,isSigner:!1,isWritable:!0}),b.push({pubkey:E.SystemProgram.programId,isSigner:!1,isWritable:!1}),b.push({pubkey:S,isSigner:!1,isWritable:!0}),b.push({pubkey:T,isSigner:!1,isWritable:!0});let B=Buffer.alloc(R.span);return R.encode({amountA:P,minAmountB:A,shareFeeRate:w!=null?w:new Ye.default(0)},B),new E.TransactionInstruction({keys:b,programId:i,data:Buffer.from([...ee.sellExactIn,...B])})}function mr(i,e,t,o,r,a,s,c,p,g,y,k,I,h,S,T,P,A,w,f){let R=m([n("amountB"),n("maxAmountA"),n("shareFeeRate")]),b=[{pubkey:e,isSigner:!0,isWritable:!0},{pubkey:t,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!1,isWritable:!1},{pubkey:a,isSigner:!1,isWritable:!0},{pubkey:s,isSigner:!1,isWritable:!0},{pubkey:c,isSigner:!1,isWritable:!0},{pubkey:p,isSigner:!1,isWritable:!0},{pubkey:g,isSigner:!1,isWritable:!0},{pubkey:y,isSigner:!1,isWritable:!1},{pubkey:k,isSigner:!1,isWritable:!1},{pubkey:I,isSigner:!1,isWritable:!1},{pubkey:h,isSigner:!1,isWritable:!1},{pubkey:Ce(i).publicKey,isSigner:!1,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!1}];f&&b.push({pubkey:f,isSigner:!1,isWritable:!0}),b.push({pubkey:E.SystemProgram.programId,isSigner:!1,isWritable:!1}),b.push({pubkey:S,isSigner:!1,isWritable:!0}),b.push({pubkey:T,isSigner:!1,isWritable:!0});let B=Buffer.alloc(R.span);return R.encode({amountB:P,maxAmountA:A,shareFeeRate:w!=null?w:new Ye.default(0)},B),new E.TransactionInstruction({keys:b,programId:i,data:Buffer.from([...ee.sellExactOut,...B])})}function dr(i,e,t,o,r,a,s,c,p){let g=m([]),y=[{pubkey:e,isSigner:!0,isWritable:!0},{pubkey:t,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:s,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!1,isWritable:!0},{pubkey:c,isSigner:!1,isWritable:!1},{pubkey:p,isSigner:!1,isWritable:!1},{pubkey:E.SystemProgram.programId,isSigner:!1,isWritable:!1},{pubkey:we.ASSOCIATED_TOKEN_PROGRAM_ID,isSigner:!1,isWritable:!1}],k=Buffer.alloc(g.span);return g.encode({},k),new E.TransactionInstruction({keys:y,programId:i,data:Buffer.from([...ee.claimVestedToken,...k])})}function pr(i,e,t,o,r,a){let s=m([n("shareAmount")]),c=[{pubkey:e,isSigner:!0,isWritable:!0},{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:E.SystemProgram.programId,isSigner:!1,isWritable:!1}],p=Buffer.alloc(s.span);return s.encode({shareAmount:a},p),new E.TransactionInstruction({keys:c,programId:i,data:Buffer.from([...ee.createVestingAccount,...p])})}function fr(i,e,t,o,r,a,s,c,p){let g=[{pubkey:e,isSigner:!0,isWritable:!0},{pubkey:t,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!1,isWritable:!0},{pubkey:s,isSigner:!1,isWritable:!0},{pubkey:c,isSigner:!1,isWritable:!0},{pubkey:p,isSigner:!1,isWritable:!0},{pubkey:E.SystemProgram.programId,isSigner:!1,isWritable:!0},{pubkey:we.ASSOCIATED_TOKEN_PROGRAM_ID,isSigner:!1,isWritable:!0}];return new E.TransactionInstruction({keys:g,programId:i,data:ee.claimPlatformFee})}function yr(i,e,t,o,r,a,s,c,p,g,y,k,I,h,S){let T=m([n("platformScale"),n("creatorScale"),n("burnScale"),n("feeRate"),re("name"),re("web"),re("img"),n("creatorFeeRate"),n("platformVestingScale")]),P=[{pubkey:e,isSigner:!0,isWritable:!0},{pubkey:t,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!1,isWritable:!1},{pubkey:a,isSigner:!1,isWritable:!0},{pubkey:s,isSigner:!1,isWritable:!0},{pubkey:E.SystemProgram.programId,isSigner:!1,isWritable:!1},{pubkey:c,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!1,isWritable:!1}],A=Buffer.alloc(8*6+Buffer.from(k,"utf-8").length+Buffer.from(I,"utf-8").length+Buffer.from(h,"utf-8").length+4*3);return T.encode({platformScale:p.platformScale,creatorScale:p.creatorScale,burnScale:p.burnScale,feeRate:g,name:k,web:I,img:h,creatorFeeRate:y,platformVestingScale:S},A),new E.TransactionInstruction({keys:P,programId:i,data:Buffer.from([...ee.createPlatformConfig,...A])})}function br(i,e,t,o){let r=[{pubkey:e,isSigner:!0,isWritable:!1},{pubkey:t,isSigner:!1,isWritable:!0}],a;if(o.type==="updateClaimFeeWallet"){let s=m([l("index"),u("value")]);a=Buffer.alloc(s.span),s.encode({index:0,value:o.value},a)}else if(o.type==="updateLockNftWallet"){let s=m([l("index"),u("value")]);a=Buffer.alloc(s.span),s.encode({index:1,value:o.value},a)}else if(o.type==="migrateCpLockNftScale"){let s=m([l("index"),n("platformScale"),n("creatorScale"),n("burnScale")]);a=Buffer.alloc(s.span),s.encode(O({index:2},o.value),a)}else if(o.type==="updateFeeRate"){let s=m([l("index"),n("value")]);a=Buffer.alloc(s.span),s.encode({index:3,value:o.value},a)}else if(o.type==="updateImg"||o.type==="updateName"||o.type==="updateWeb"){let s=m([l("index"),re("value")]);a=Buffer.alloc(Buffer.from(o.value,"utf-8").length+4+1*1),o.type==="updateName"?s.encode({index:4,value:o.value},a):o.type==="updateWeb"?s.encode({index:5,value:o.value},a):o.type==="updateImg"&&s.encode({index:6,value:o.value},a)}else if(o.type==="updateCpConfigId"){r.push({pubkey:o.value,isSigner:!1,isWritable:!1});let s=m([l("index")]);a=Buffer.alloc(s.span),s.encode({index:7},a)}else if(o.type==="updateAll"){r.push({pubkey:o.value.cpConfigId,isSigner:!1,isWritable:!1});let s=m([l("index"),u("platformClaimFeeWallet"),u("platformLockNftWallet"),n("platformScale"),n("creatorScale"),n("burnScale"),n("feeRate"),re("name"),re("web"),re("img"),u("transferFeeExtensionAuth"),n("creatorFeeRate"),n("platformVestingScale"),u("platformVestingWallet")]);a=Buffer.alloc(1+32+32+32+8*5+4*3+Buffer.from(o.value.name,"utf-8").length+Buffer.from(o.value.web,"utf-8").length+Buffer.from(o.value.img,"utf-8").length+32+8),s.encode({index:8,platformClaimFeeWallet:o.value.platformClaimFeeWallet,platformLockNftWallet:o.value.platformLockNftWallet,platformVestingWallet:o.value.platformVestingWallet,platformScale:o.value.migrateCpLockNftScale.platformScale,creatorScale:o.value.migrateCpLockNftScale.creatorScale,burnScale:o.value.migrateCpLockNftScale.burnScale,feeRate:o.value.feeRate,name:o.value.name,web:o.value.web,img:o.value.img,transferFeeExtensionAuth:o.value.transferFeeExtensionAuth,creatorFeeRate:o.value.creatorFeeRate,platformVestingScale:o.value.platformVestingScale},a)}else if(o.type==="updateVestingWallet"){let s=m([l("index"),u("value")]);a=Buffer.alloc(s.span),s.encode({index:9,value:o.value},a)}else if(o.type==="updatePlatformVestingScale"){let s=m([l("index"),n("value")]);a=Buffer.alloc(s.span),s.encode({index:10,value:o.value},a)}else if(o.type==="updatePlatformCpCreator"){let s=m([l("index"),u("value")]);a=Buffer.alloc(s.span),s.encode({index:11,value:o.value},a)}else if(o.type==="updateRestrictGlobalConfig"){let s=m([l("index"),n("value")]);a=Buffer.alloc(s.span),s.encode({index:12,value:o.value},a)}else if(o.type==="updateRestrictCurveParam"){let s=m([l("index"),n("value")]);a=Buffer.alloc(s.span),s.encode({index:13,value:o.value},a)}else if(o.type==="updateCurveRuleManager"){let s=m([l("index"),u("value")]);a=Buffer.alloc(s.span),s.encode({index:14,value:o.value},a)}else throw Error("updateInfo params type error");return new E.TransactionInstruction({keys:r,programId:i,data:Buffer.from([...ee.updatePlaformConfig,...a])})}function gr(i,e,t,o,r,a,s,c){let p=[{pubkey:t,isSigner:!0,isWritable:!0},{pubkey:o,isSigner:!1,isWritable:!1},{pubkey:e,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!1,isWritable:!0},{pubkey:s,isSigner:!1,isWritable:!1},{pubkey:c,isSigner:!1,isWritable:!1},{pubkey:E.SystemProgram.programId,isSigner:!1,isWritable:!1},{pubkey:we.ASSOCIATED_TOKEN_PROGRAM_ID,isSigner:!1,isWritable:!1}];return new E.TransactionInstruction({keys:p,programId:i,data:ee.claimPlatformFeeFromVault})}function Pr(i,e,t,o,r,a,s){let c=[{pubkey:e,isSigner:!0,isWritable:!0},{pubkey:t,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!1,isWritable:!1},{pubkey:s,isSigner:!1,isWritable:!1},{pubkey:E.SystemProgram.programId,isSigner:!1,isWritable:!1},{pubkey:we.ASSOCIATED_TOKEN_PROGRAM_ID,isSigner:!1,isWritable:!1}];return new E.TransactionInstruction({keys:c,programId:i,data:ee.claimCreatorFee})}var iS=new Ye.default("18446744073709551615");function Ar(i,e,t,o,r,a){let s=[{pubkey:e,isSigner:!0,isWritable:!0},{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!1,isWritable:!0},{pubkey:E.SystemProgram.programId,isSigner:!1,isWritable:!1}];return new E.TransactionInstruction({keys:s,programId:i,data:ee.createPlatformVestingAccount})}function wr(i,e,t,o,r){let a=[{pubkey:e,isSigner:!0,isWritable:!0},{pubkey:t,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:E.SystemProgram.programId,isSigner:!1,isWritable:!1}];return new E.TransactionInstruction({keys:a,programId:i,data:ee.createPlatformAllowConfig})}function kr(i,e,t,o,r){let a=[{pubkey:e,isSigner:!0,isWritable:!0},{pubkey:t,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!1,isWritable:!0}];return new E.TransactionInstruction({keys:a,programId:i,data:ee.closePlatformAllowConfig})}function ju(i){let e=m([l("field"),l("op"),_("value")]),t=Buffer.alloc(4+i.length*e.span);return t.writeUInt32LE(i.length,0),i.forEach((o,r)=>{e.encode(o,t,4+r*e.span)}),t}function Tr(i,e,t,o,r){let a=[{pubkey:e,isSigner:!0,isWritable:!0},{pubkey:t,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:E.SystemProgram.programId,isSigner:!1,isWritable:!1}];return new E.TransactionInstruction({keys:a,programId:i,data:ee.createPlatformCurveRule})}function hr(i,e,t,o,r,a,s){let c=[{pubkey:e,isSigner:!0,isWritable:!0},{pubkey:t,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:E.SystemProgram.programId,isSigner:!1,isWritable:!1}],p=Buffer.alloc(Z().span);return Z().encode(a,p),new E.TransactionInstruction({keys:c,programId:i,data:Buffer.from([...ee.updatePlatformCurveRule,...p,...ju(s)])})}function Ir(i,e,t,o,r,a){let s=[{pubkey:e,isSigner:!0,isWritable:!0},{pubkey:t,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:E.SystemProgram.programId,isSigner:!1,isWritable:!1}],c=Buffer.alloc(Z().span);return Z().encode(a,c),new E.TransactionInstruction({keys:s,programId:i,data:Buffer.from([...ee.removePlatformCurveRule,...c])})}function Br(i,e,t,o,r){let a=[{pubkey:e,isSigner:!0,isWritable:!0},{pubkey:t,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!1,isWritable:!0}];return new E.TransactionInstruction({keys:a,programId:i,data:ee.closePlatformCurveRule})}var Oe=x(require("bn.js"));var Ju=new Oe.default(1e6);function bo(i,e){var r,a,s,c;let t=p=>i.supply.isZero()?void 0:p.mul(Ju).div(i.supply),o=()=>{let p=i.supply.sub(i.totalSellA).sub(i.totalLockedAmount);return p.isNeg()?void 0:p};switch(e){case 0:return new Oe.default(i.curveType);case 1:return new Oe.default(i.migrateType);case 2:return new Oe.default(i.migrateCpmmFeeOn);case 3:return i.supply;case 4:return i.totalSellA;case 5:return i.totalFundRaisingB;case 6:return i.totalLockedAmount;case 7:return i.cliffPeriod;case 8:return i.unlockPeriod;case 9:return new Oe.default(i.baseTokenProgram);case 10:return new Oe.default(i.transferFee===void 0?0:1);case 11:return new Oe.default((a=(r=i.transferFee)==null?void 0:r.basisPoints)!=null?a:0);case 12:return(c=(s=i.transferFee)==null?void 0:s.maximumFee)!=null?c:new Oe.default(0);case 13:return t(i.totalSellA);case 14:return t(i.totalLockedAmount);case 15:return o();case 16:{let p=o();return p===void 0?void 0:t(p)}case 17:return t(i.totalFundRaisingB);case 18:return i.unixTimestamp;default:return}}function Sr(i,e){let t=bo(e,i.field);if(t===void 0)return!1;switch(i.op){case 0:return t.eq(i.value);case 1:return t.gte(i.value);case 2:return t.lte(i.value);case 3:return!t.eq(i.value);default:return!1}}function ec({rule:i,context:e}){var r;let t=(r=i==null?void 0:i.groups)!=null?r:[];if(t.length===0)return{ok:!0,groupFailures:[]};let o=[];for(let a of t){let s=a.constraints.filter(c=>!Sr(c,e)).map(c=>V(O({},c),{actual:bo(e,c.field)}));if(s.length===0)return{ok:!0,matchedGroupId:a.groupId,groupFailures:[]};o.push({groupId:a.groupId,unsatisfied:s})}return{ok:!1,groupFailures:o}}function tc({groupId:i,constraints:e,curveType:t,existingGroupIds:o=[]}){let r=[];!o.includes(i)&&o.length>=gn&&r.push({code:"CurveRuleGroupsExceeded",message:`a rule holds at most ${gn} groups, and group ${i} would be a new one`}),e.length>Pn&&r.push({code:"InvalidCurveRuleConstraint",message:`a group holds at most ${Pn} constraints, got ${e.length}`});let a=new Set;return e.forEach((s,c)=>{s.field>18&&r.push({code:"InvalidCurveRuleConstraint",message:`constraint ${c}: unknown field id ${s.field}`}),s.op>3&&r.push({code:"InvalidCurveRuleConstraint",message:`constraint ${c}: unknown op id ${s.op}`});let p=`${s.field}/${s.op}`;a.has(p)&&r.push({code:"InvalidCurveRuleConstraint",message:`constraint ${c}: field ${s.field} already has an op ${s.op} constraint in this group. A range uses two different ops on one field`}),a.add(p),t!==0&&co.includes(s.field)&&r.push({code:"CurveRuleFieldNotSupportedByCurve",message:`constraint ${c}: field ${s.field} reads totalSellA, which curve type ${t} derives itself, so the program refuses it on this config`})}),{ok:r.length===0,errors:r}}0&&(module.exports={AUTH_SEED,BondingCurveParam,CONFIG_SEED,CREATOR_FEE_VAULT_AUTH_SEED,CpmmCreatorFeeOn,Curve,CurveBase,CurveRuleGroup,FixedPriceCurve,LAUNCHPAD_CURVE_RULE_CONSTANT_PRODUCT_ONLY_FIELDS,LAUNCHPAD_MAX_CONSTRAINTS_PER_GROUP,LAUNCHPAD_MAX_CURVE_RULE_GROUPS,LaunchConstantProductCurve,LaunchpadConfig,LaunchpadCurveRuleBaseTokenProgram,LaunchpadCurveRuleField,LaunchpadCurveRuleOp,LaunchpadMintProgramBit,LaunchpadPool,LaunchpadPoolInitParam,LaunchpadVesting,LinearPriceCurve,MathLaunch,PLATFORM_ALLOW_CONFIG_SEED,PLATFORM_CURVE_RULE_SEED,PLATFORM_FEE_VAULT_AUTH_SEED,PLATFORM_GLOBAL_ACCESS_SEED,PLATFORM_SEED,POOL_VESTING_SEED,ParamConstraint,PlatformConfig,PlatformCurveParam,PlatformCurveRule,VestingSchedule,anchorDataBuf,buyExactInInstruction,buyExactOutInstruction,checkCurveRuleGroupWritable,checkLaunchAgainstCurveRule,checkPoolToAmm,claimCreatorFee,claimPlatformFee,claimPlatformFeeFromVault,claimVestedToken,closePlatformAllowConfigIns,closePlatformCurveRuleIns,createPlatformAllowConfigIns,createPlatformConfig,createPlatformCurveRuleIns,createPlatformVestingAccountIns,createVestingAccount,getCurveRuleFieldValue,getLaunchpadPoolMintAProgram,getLaunchpadPoolMintBProgram,getLaunchpadPoolMintProgram,getPdaCpiEvent,getPdaCreatorFeeVaultAuth,getPdaCreatorVault,getPdaLaunchpadAuth,getPdaLaunchpadConfigId,getPdaLaunchpadPoolId,getPdaLaunchpadVaultId,getPdaPlatformAllowConfig,getPdaPlatformConfigAccess,getPdaPlatformCurveRule,getPdaPlatformFeeVaultAuth,getPdaPlatformId,getPdaPlatformVault,getPdaVestId,initialize,initializeV2,initializeWithToken2022,isCurveRuleConstraintSatisfied,removePlatformCurveRuleIns,sellExactInInstruction,sellExactOut,toLaunchpadMintProgramFlag,updatePlatformConfig,updatePlatformCurveRuleIns,usdMintBSet});
//# sourceMappingURL=index.js.map