@sega-so/sega-sdk
Version:
An SDK for building applications on top of SEGA.
1 lines • 54.6 kB
JavaScript
"use strict";var un=Object.create;var be=Object.defineProperty,ln=Object.defineProperties,mn=Object.getOwnPropertyDescriptor,pn=Object.getOwnPropertyDescriptors,dn=Object.getOwnPropertyNames,Ie=Object.getOwnPropertySymbols,fn=Object.getPrototypeOf,$e=Object.prototype.hasOwnProperty,yt=Object.prototype.propertyIsEnumerable;var xt=Math.pow,bt=(t,e,n)=>e in t?be(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,K=(t,e)=>{for(var n in e||(e={}))$e.call(e,n)&&bt(t,n,e[n]);if(Ie)for(var n of Ie(e))yt.call(e,n)&&bt(t,n,e[n]);return t},j=(t,e)=>ln(t,pn(e));var Ne=(t,e)=>{var n={};for(var r in t)$e.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&Ie)for(var r of Ie(t))e.indexOf(r)<0&&yt.call(t,r)&&(n[r]=t[r]);return n};var gn=(t,e)=>{for(var n in e)be(t,n,{get:e[n],enumerable:!0})},wt=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of dn(e))!$e.call(t,i)&&i!==n&&be(t,i,{get:()=>e[i],enumerable:!(r=mn(e,i))||r.enumerable});return t};var G=(t,e,n)=>(n=t!=null?un(fn(t)):{},wt(e||!t||!t.__esModule?be(n,"default",{value:t,enumerable:!0}):n,t)),hn=t=>wt(be({},"__esModule",{value:!0}),t);var g=(t,e,n)=>new Promise((r,i)=>{var s=u=>{try{o(n.next(u))}catch(a){i(a)}},c=u=>{try{o(n.throw(u))}catch(a){i(a)}},o=u=>u.done?r(u.value):Promise.resolve(u.value).then(s,c);o((n=n.apply(t,e)).next())});var Mr={};gn(Mr,{ACCOUNT_TYPE_SIZE:()=>bn,ALL_PROGRAM_ID:()=>kr,ANAMint:()=>vn,AccountType:()=>At,BNDivCeil:()=>me,BN_100:()=>ir,BN_1000:()=>or,BN_10000:()=>sr,BN_FIVE:()=>rr,BN_ONE:()=>er,BN_TEN:()=>ne,BN_THREE:()=>nr,BN_TWO:()=>tr,BN_ZERO:()=>$,CLOCK_PROGRAM_ID:()=>In,CREATE_CPMM_POOL_AUTH:()=>Qt,CREATE_CPMM_POOL_FEE_ACC:()=>en,CREATE_CPMM_POOL_PROGRAM:()=>$t,DEVNET_PROGRAM_ID:()=>Ar,DEV_CREATE_CPMM_POOL_AUTH:()=>nn,DEV_CREATE_CPMM_POOL_FEE_ACC:()=>rn,DEV_CREATE_CPMM_POOL_PROGRAM:()=>tn,ETHMint:()=>_n,INSTRUCTION_PROGRAM_ID:()=>Nn,InstructionType:()=>ge,LOOKUP_TABLE_CACHE:()=>Be,LogLevel:()=>Pt,Logger:()=>Re,MAX_BASE64_SIZE:()=>dt,MEMO_PROGRAM_ID:()=>An,MEMO_PROGRAM_ID2:()=>Bn,METADATA_PROGRAM_ID:()=>ve,NRVMint:()=>Kn,Network:()=>an,Owner:()=>mt,PAIMint:()=>Mn,RAYMint:()=>Dn,RENT_PROGRAM_ID:()=>Cn,Rounding:()=>Fe,SOLMint:()=>fe,SRMMint:()=>Fn,SYSTEM_PROGRAM_ID:()=>Rn,TxBuilder:()=>ht,TxVersion:()=>pt,USDCMint:()=>Ln,USDHMint:()=>Wn,USDTMint:()=>En,WSOLMint:()=>ye,accountMeta:()=>Ve,add:()=>Xn,addComputeBudget:()=>Se,checkLegacyTxSize:()=>he,checkV0TxSize:()=>Te,chunkArray:()=>De,commonSystemAccountMeta:()=>kn,confirmTransaction:()=>ke,createLogger:()=>q,decimalToFraction:()=>Gt,div:()=>zn,divCeil:()=>ar,eq:()=>Wt,fetchMultipleMintInfos:()=>yn,findProgramAddress:()=>Je,forecastTransactionSize:()=>ft,getATAAddress:()=>Pr,getConnection:()=>Nr,getDate:()=>lt,getEpochInfo:()=>xr,getMax:()=>Zn,getMultipleAccountsInfo:()=>Me,getMultipleAccountsInfoWithCustomFlags:()=>kt,getMultipleLookupTableInfo:()=>Ze,getPdaMetadataKey:()=>Sr,getRecentBlockHash:()=>le,getTime:()=>Ht,getTimestamp:()=>Qn,getTransferAmountFee:()=>Br,getTransferAmountFeeV2:()=>Cr,gt:()=>Vt,gte:()=>Hn,intersection:()=>fr,isDateAfter:()=>pr,isDateBefore:()=>mr,isDecimal:()=>jt,isMeaningfulNumber:()=>Jn,isNumber:()=>ut,jsonInfo2PoolKeys:()=>ot,lt:()=>Gn,lte:()=>jn,mSOLMint:()=>On,minExpirationTime:()=>Ir,mul:()=>He,notInnerObject:()=>ze,offsetDateTime:()=>dr,parseBigNumberish:()=>_,parseNumberInfo:()=>ie,parseSimulateLogToJson:()=>br,parseSimulateValue:()=>yr,printSimulate:()=>oe,recursivelyDecimalToFraction:()=>at,setLoggerLevel:()=>Tn,shakeFractionDecimal:()=>qt,simulateMultipleInstruction:()=>Tr,simulateTransaction:()=>Yt,sleep:()=>$n,solToWSol:()=>nt,stSOLMint:()=>Vn,sub:()=>Yn,tenExponential:()=>je,toBN:()=>Ut,toBuffer:()=>gt,toFraction:()=>ct,toFractionWithDecimals:()=>Un,toPercent:()=>cr,toTokenPrice:()=>ur,toTotalPrice:()=>lr,toUsdCurrency:()=>st,transformTxToBase64:()=>wr,tryParsePublicKey:()=>Ke,txToBase64:()=>Jt,uniq:()=>hr,validateAndParsePublicKey:()=>We,xor:()=>gr});module.exports=hn(Mr);var tt=require("@solana/web3.js");var ce=require("lodash"),Pt=(i=>(i[i.Error=0]="Error",i[i.Warning=1]="Warning",i[i.Info=2]="Info",i[i.Debug=3]="Debug",i))(Pt||{}),Re=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 n=e.map(r=>typeof r=="object"?JSON.stringify(r):r).join(", ");throw new Error(n)}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}},Qe={},St={};function q(t){let e=(0,ce.get)(Qe,t);if(!e){let n=(0,ce.get)(St,t);e=new Re({name:t,logLevel:n}),(0,ce.set)(Qe,t,e)}return e}function Tn(t,e){(0,ce.set)(St,t,e);let n=(0,ce.get)(Qe,t);n&&(n.level=e)}var te=require("@solana/spl-token");var et=q("Sega_accountInfo_util");function Me(t,e,n){return g(this,null,function*(){let{batchRequest:r,commitment:i="confirmed",chunkCount:s=100}=K({batchRequest:!1},n),c=De(e,s),o=new Array(c.length).fill([]);if(r){let u=c.map(h=>({methodName:"getMultipleAccounts",args:t._buildArgs([h.map(w=>w.toBase58())],i,"base64")})),a=De(u,10);o=(yield(yield Promise.all(a.map(h=>g(this,null,function*(){return yield t._rpcBatchRequest(h)})))).flat()).map(h=>(h.error&&et.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${h.error.message}`),h.result.value.map(S=>{if(S){let{data:w,executable:T,lamports:x,owner:m,rentEpoch:k}=S;return w.length!==2&&w[1]!=="base64"&&et.logWithError("info must be base64 encoded, RPC_ERROR"),{data:Buffer.from(w[0],"base64"),executable:T,lamports:x,owner:new tt.PublicKey(m),rentEpoch:k}}return null})))}else try{o=yield Promise.all(c.map(u=>t.getMultipleAccountsInfo(u,i)))}catch(u){u instanceof Error&&et.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${u.message}`)}return o.flat()})}function kt(t,e,n){return g(this,null,function*(){let r=yield Me(t,e.map(i=>i.pubkey),n);return e.map((i,s)=>j(K({},i),{accountInfo:r[s]}))})}var At=(r=>(r[r.Uninitialized=0]="Uninitialized",r[r.Mint=1]="Mint",r[r.Account=2]="Account",r))(At||{}),bn=1;function yn(r){return g(this,arguments,function*({connection:t,mints:e,config:n}){var c,o,u;if(e.length===0)return{};let i=yield kt(t,e.map(a=>({pubkey:nt(a)})),n),s={};for(let a of i){if(!a.accountInfo||a.accountInfo.data.length<te.MINT_SIZE){console.log("invalid mint account",a.pubkey.toBase58());continue}let l=(0,te.unpackMint)(a.pubkey,a.accountInfo,(c=a.accountInfo)==null?void 0:c.owner);s[a.pubkey.toString()]=j(K({},l),{programId:((o=a.accountInfo)==null?void 0:o.owner)||te.TOKEN_PROGRAM_ID,feeConfig:(u=(0,te.getTransferFeeConfig)(l))!=null?u:void 0})}return s[tt.PublicKey.default.toBase58()]=s[ye.toBase58()],s})}var F=G(require("bn.js")),_t=G(require("decimal.js"));var Rt=G(require("big.js")),Z=G(require("bn.js"));var Bt=G(require("toformat")),xn=Bt.default,xe=xn;var we=G(require("big.js")),It=G(require("bn.js")),Nt=G(require("decimal.js-light"));var de=G(require("bn.js"));var Fe=(r=>(r[r.ROUND_DOWN=0]="ROUND_DOWN",r[r.ROUND_HALF_UP=1]="ROUND_HALF_UP",r[r.ROUND_UP=2]="ROUND_UP",r))(Fe||{}),Ct=9007199254740991;function _(t){let e=q("Sega_parseBigNumberish");if(t instanceof de.default)return t;if(typeof t=="string"){if(t.match(/^-?[0-9]+$/))return new de.default(t);e.logWithError(`invalid BigNumberish string: ${t}`)}return typeof t=="number"?(t%1&&e.logWithError(`BigNumberish number underflow: ${t}`),(t>=Ct||t<=-Ct)&&e.logWithError(`BigNumberish number overflow: ${t}`),new de.default(String(t))):typeof t=="bigint"?new de.default(t.toString()):(e.error(`invalid BigNumberish value: ${t}`),new de.default(0))}var Le=q("module/fraction"),rt=xe(we.default),Pe=xe(Nt.default),wn={0:Pe.ROUND_DOWN,1:Pe.ROUND_HALF_UP,2:Pe.ROUND_UP},Pn={0:we.default.roundDown,1:we.default.roundHalfUp,2:we.default.roundUp},R=class t{constructor(e,n=new It.default(1)){this.numerator=_(e),this.denominator=_(n)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new t(this.denominator,this.numerator)}add(e){let n=e instanceof t?e:new t(_(e));return this.denominator.eq(n.denominator)?new t(this.numerator.add(n.numerator),this.denominator):new t(this.numerator.mul(n.denominator).add(n.numerator.mul(this.denominator)),this.denominator.mul(n.denominator))}sub(e){let n=e instanceof t?e:new t(_(e));return this.denominator.eq(n.denominator)?new t(this.numerator.sub(n.numerator),this.denominator):new t(this.numerator.mul(n.denominator).sub(n.numerator.mul(this.denominator)),this.denominator.mul(n.denominator))}mul(e){let n=e instanceof t?e:new t(_(e));return new t(this.numerator.mul(n.numerator),this.denominator.mul(n.denominator))}div(e){let n=e instanceof t?e:new t(_(e));return new t(this.numerator.mul(n.denominator),this.denominator.mul(n.numerator))}toSignificant(e,n={groupSeparator:""},r=1){Number.isInteger(e)||Le.logWithError(`${e} is not an integer.`),e<=0&&Le.logWithError(`${e} is not positive.`),Pe.set({precision:e+1,rounding:wn[r]});let i=new Pe(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(e);return i.toFormat(i.decimalPlaces(),n)}toFixed(e,n={groupSeparator:""},r=1){return Number.isInteger(e)||Le.logWithError(`${e} is not an integer.`),e<0&&Le.logWithError(`${e} is negative.`),rt.DP=e,rt.RM=Pn[r]||1,new rt(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,n)}isZero(){return this.numerator.isZero()}};var Sn=q("Sega_amount"),Ee=xe(Rt.default);function Dt(t,e){let n="0",r="0";if(t.includes(".")){let i=t.split(".");i.length===2?([n,r]=i,r=r.padEnd(e,"0")):Sn.logWithError(`invalid number string, num: ${t}`)}else n=t;return[n,r.slice(0,e)||r]}var X=class t extends R{constructor(e,n,r=!0,i){let s=new Z.default(0),c=ne.pow(new Z.default(e.decimals));if(r)s=_(n);else{let o=new Z.default(0),u=new Z.default(0);if(typeof n=="string"||typeof n=="number"||typeof n=="bigint"){let[a,l]=Dt(n.toString(),e.decimals);o=_(a),u=_(l)}o=o.mul(c),s=o.add(u)}super(s,c),this.logger=q(i||"TokenAmount"),this.token=e}get raw(){return this.numerator}isZero(){return this.raw.isZero()}gt(e){return this.token.equals(e.token)||this.logger.logWithError("gt token not equals"),this.raw.gt(e.raw)}lt(e){return this.token.equals(e.token)||this.logger.logWithError("lt token not equals"),this.raw.lt(e.raw)}add(e){return this.token.equals(e.token)||this.logger.logWithError("add token not equals"),new t(this.token,this.raw.add(e.raw))}subtract(e){return this.token.equals(e.token)||this.logger.logWithError("sub token not equals"),new t(this.token,this.raw.sub(e.raw))}toSignificant(e=this.token.decimals,n,r=0){return super.toSignificant(e,n,r)}toFixed(e=this.token.decimals,n,r=0){return e>this.token.decimals&&this.logger.logWithError("decimals overflow"),super.toFixed(e,n,r)}toExact(e={groupSeparator:""}){return Ee.DP=this.token.decimals,new Ee(this.numerator.toString()).div(this.denominator.toString()).toFormat(e)}},Oe=class t extends R{constructor(e,n,r=!0,i){let s=new Z.default(0),c=ne.pow(new Z.default(e.decimals));if(r)s=_(n);else{let o=new Z.default(0),u=new Z.default(0);if(typeof n=="string"||typeof n=="number"||typeof n=="bigint"){let[a,l]=Dt(n.toString(),e.decimals);o=_(a),u=_(l)}o=o.mul(c),s=o.add(u)}super(s,c),this.logger=q(i||"TokenAmount"),this.currency=e}get raw(){return this.numerator}isZero(){return this.raw.isZero()}gt(e){return this.currency.equals(e.currency)||this.logger.logWithError("gt currency not equals"),this.raw.gt(e.raw)}lt(e){return this.currency.equals(e.currency)||this.logger.logWithError("lt currency not equals"),this.raw.lt(e.raw)}add(e){return this.currency.equals(e.currency)||this.logger.logWithError("add currency not equals"),new t(this.currency,this.raw.add(e.raw))}sub(e){return this.currency.equals(e.currency)||this.logger.logWithError("sub currency not equals"),new t(this.currency,this.raw.sub(e.raw))}toSignificant(e=this.currency.decimals,n,r=0){return super.toSignificant(e,n,r)}toFixed(e=this.currency.decimals,n,r=0){return e>this.currency.decimals&&this.logger.logWithError("decimals overflow"),super.toFixed(e,n,r)}toExact(e={groupSeparator:""}){return Ee.DP=this.currency.decimals,new Ee(this.numerator.toString()).div(this.denominator.toString()).toFormat(e)}};var Mt=require("@solana/web3.js"),it=require("@solana/spl-token"),Ft={chainId:101,address:Mt.PublicKey.default.toBase58(),programId:it.TOKEN_PROGRAM_ID.toBase58(),decimals:9,symbol:"SOL",name:"solana",logoURI:"https://img-v1.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"sega",extensions:{coingeckoId:"solana"}},ue={chainId:101,address:"So11111111111111111111111111111111111111112",programId:it.TOKEN_PROGRAM_ID.toBase58(),decimals:9,symbol:"WSOL",name:"Wrapped SOL",logoURI:"https://img-v1.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"sega",extensions:{coingeckoId:"solana"}};var _e=require("@solana/web3.js");var N=require("@solana/web3.js"),Lt=require("@solana/spl-token");function Ve({pubkey:t,isSigner:e=!1,isWritable:n=!0}){return{pubkey:t,isWritable:n,isSigner:e}}var kn=[Ve({pubkey:Lt.TOKEN_PROGRAM_ID,isWritable:!1}),Ve({pubkey:N.SystemProgram.programId,isWritable:!1}),Ve({pubkey:N.SYSVAR_RENT_PUBKEY,isWritable:!1})];function We({publicKey:t,transformSol:e}){let n=Ke(t.toString());if(n instanceof N.PublicKey)return e&&n.equals(fe)?ye:n;if(e&&n.toString()===fe.toBase58())return ye;if(typeof n=="string"){if(n===N.PublicKey.default.toBase58())return N.PublicKey.default;try{return new N.PublicKey(n)}catch(r){throw new Error("invalid public key")}}throw new Error("invalid public key")}function Ke(t){try{return new N.PublicKey(t)}catch(e){return t}}var An=new N.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Bn=new N.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Cn=new N.PublicKey("SysvarRent111111111111111111111111111111111"),In=new N.PublicKey("SysvarC1ock11111111111111111111111111111111"),ve=new N.PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),Nn=new N.PublicKey("Sysvar1nstructions1111111111111111111111111"),Rn=N.SystemProgram.programId,Dn=new N.PublicKey("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),Mn=new N.PublicKey("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),Fn=new N.PublicKey("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),Ln=new N.PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),En=new N.PublicKey("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),On=new N.PublicKey("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),Vn=new N.PublicKey("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),Wn=new N.PublicKey("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),Kn=new N.PublicKey("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),vn=new N.PublicKey("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),_n=new N.PublicKey("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),ye=new N.PublicKey("So11111111111111111111111111111111111111112"),fe=N.PublicKey.default;function nt(t){return We({publicKey:t,transformSol:!0})}var qe=class qe{constructor({mint:e,decimals:n,symbol:r,name:i,skipMint:s=!1,isToken2022:c=!1}){if(e===fe.toBase58()||e instanceof _e.PublicKey&&fe.equals(e)){this.decimals=ue.decimals,this.symbol=ue.symbol,this.name=ue.name,this.mint=new _e.PublicKey(ue.address),this.isToken2022=!1;return}this.decimals=n,this.symbol=r||e.toString().substring(0,6),this.name=i||e.toString().substring(0,6),this.mint=s?_e.PublicKey.default:We({publicKey:e}),this.isToken2022=c}equals(e){return this===e?!0:this.mint.equals(e.mint)}};qe.WSOL=new qe(j(K({},ue),{mint:ue.address}));var re=qe;var Ge=class Ge{constructor({decimals:e,symbol:n="UNKNOWN",name:r="UNKNOWN"}){this.decimals=e,this.symbol=n,this.name=r}equals(e){return this===e}};Ge.SOL=new Ge(Ft);var Ue=Ge;var Ot=G(require("bn.js"));var Et=new R(new Ot.default(100)),H=class extends R{toSignificant(e=5,n,r){return this.mul(Et).toSignificant(e,n,r)}toFixed(e=2,n,r){return this.mul(Et).toFixed(e,n,r)}};var qn=q("Sega_price"),z=class t extends R{constructor(e){let{baseToken:n,quoteToken:r,numerator:i,denominator:s}=e;super(i,s),this.baseToken=n,this.quoteToken=r,this.scalar=new R(je(n.decimals),je(r.decimals))}get raw(){return new R(this.numerator,this.denominator)}get adjusted(){return super.mul(this.scalar)}invert(){return new t({baseToken:this.quoteToken,quoteToken:this.baseToken,denominator:this.numerator,numerator:this.denominator})}mul(e){this.quoteToken!==e.baseToken&&qn.logWithError("mul token not equals");let n=super.mul(e);return new t({baseToken:this.baseToken,quoteToken:e.quoteToken,denominator:n.denominator,numerator:n.numerator})}toSignificant(e=this.quoteToken.decimals,n,r){return this.adjusted.toSignificant(e,n,r)}toFixed(e=this.quoteToken.decimals,n,r){return this.adjusted.toFixed(e,n,r)}};function O(t){if(t instanceof H)return new R(t.numerator,t.denominator);if(t instanceof z)return t.adjusted;if(t instanceof X)try{return O(t.toExact())}catch(r){return new R($)}if(t instanceof R)return t;let e=String(t),n=ie(e);return new R(n.numerator,n.denominator)}function Un(t){var r;if(t instanceof H)return{fr:new R(t.numerator,t.denominator)};if(t instanceof z)return{fr:t.adjusted};if(t instanceof X)return{fr:O(t.toExact()),decimals:t.token.decimals};if(t instanceof R)return{fr:t};let e=String(t),n=ie(e);return{fr:new R(n.numerator,n.denominator),decimals:(r=n.dec)==null?void 0:r.length}}function Gn(t,e){if(t==null||e==null)return!1;let n=O(t),r=O(e);return n.sub(r).numerator,n.sub(r).numerator.lt($)}function Vt(t,e){if(t==null||e==null)return!1;let n=O(t),r=O(e);return n.sub(r).numerator.gt($)}function jn(t,e){if(t==null||e==null)return!1;let n=O(t),r=O(e);return n.sub(r).numerator.lte($)}function Hn(t,e){if(t==null||e==null)return!1;let n=O(t),r=O(e);return n.sub(r).numerator.gte($)}function Wt(t,e){if(t==null||e==null)return!1;let n=O(t),r=O(e);return n.sub(r).numerator.eq($)}function zn(t,e){if(t==null||e==null)return;let n=O(t),r=O(e);try{return n.div(r)}catch(i){return n}}function Yn(t,e){if(t==null||e==null)return;let n=O(t),r=O(e);return n.sub(r)}function Jn(t){return t==null?!1:!Wt(t,0)}function Zn(t,e){return Vt(e,t)?e:t}function He(t,e){if(t==null||e==null)return;let n=O(t),r=O(e);return n.mul(r)}function Xn(t,e){if(t==null||e==null)return;let n=O(t),r=O(e);return n.add(r)}var Kt=require("@solana/web3.js"),vt=G(require("bn.js"));function $n(t){return g(this,null,function*(){new Promise(e=>setTimeout(e,t))})}function Qn(){return new Date().getTime()}function ze(t){return typeof t=="object"&&t!==null&&![re,X,Kt.PublicKey,R,vt.default,z,H].some(e=>typeof e=="object"&&t instanceof e)}function ot(t){return typeof t=="string"?Ke(t):Array.isArray(t)?t.map(e=>ot(e)):ze(t)?Object.fromEntries(Object.entries(t).map(([e,n])=>[e,ot(n)])):t}var $=new F.default(0),er=new F.default(1),tr=new F.default(2),nr=new F.default(3),rr=new F.default(5),ne=new F.default(10),ir=new F.default(100),or=new F.default(1e3),sr=new F.default(1e4);function je(t){return ne.pow(_(t))}function ie(t){var o;if(t===void 0)return{denominator:"1",numerator:"0"};if(t instanceof F.default)return{numerator:t.toString(),denominator:"1"};if(t instanceof R)return{denominator:t.denominator.toString(),numerator:t.numerator.toString()};let e=String(t),[,n="",r="",i=""]=(o=e.replace(",","").match(/(-?)(\d*)\.?(\d*)/))!=null?o:[],s="1"+"0".repeat(i.length),c=n+(r==="0"?"":r)+i||"0";return{denominator:s,numerator:c,sign:n,int:r,dec:i}}function ar(t,e){let n=t.divmod(e);return n.mod.isZero()?n.div:n.div.isNeg()?n.div.isubn(1):n.div.iaddn(1)}function qt(t){var r;let[,e="",n=""]=(r=t.toFixed(2).match(/(-?)(\d*)\.?(\d*)/))!=null?r:[];return`${e}${n}`}function Ut(t,e=0){return t instanceof F.default?t:new F.default(qt(ct(t).mul(ne.pow(new F.default(String(e))))))}function ct(t){if(t instanceof H)return new R(t.numerator,t.denominator);if(t instanceof z)return t.adjusted;if(t instanceof X)try{return ct(t.toExact())}catch(r){return new R($)}if(t instanceof R)return t;let e=String(t),n=ie(e);return new R(n.numerator,n.denominator)}function cr(t,e){let{numerator:n,denominator:r}=ie(t);return new H(new F.default(n),new F.default(r).mul(e!=null&&e.alreadyDecimaled?new F.default(100):new F.default(1)))}function ur(t){let{token:e,numberPrice:n,decimalDone:r}=t,i=new re({mint:"",decimals:6,symbol:"usd",name:"usd",skipMint:!0}),{numerator:s,denominator:c}=ie(n),o=r?new F.default(s).mul(ne.pow(new F.default(e.decimals))):s,u=new F.default(c).mul(ne.pow(new F.default(i.decimals)));return new z({baseToken:i,denominator:u.toString(),quoteToken:new re(j(K({},e),{skipMint:!0,mint:""})),numerator:o.toString()})}function st(t){let e=new Ue({decimals:6,symbol:"usd",name:"usd"}),n=Ut(He(t,xt(10,e.decimals)));return new Oe(e,n)}function lr(t,e){return st(!e||!t?0:He(t,e))}function Gt(t){if(t==null)return;let{numerator:e,denominator:n}=ie(t.toString());return new R(e,n)}function jt(t){return t instanceof _t.default}function at(t){return jt(t)?Gt(t):Array.isArray(t)?t.map(e=>at(e)):ze(t)?Object.fromEntries(Object.entries(t).map(([e,n])=>[e,at(n)])):t}var ut=t=>typeof t=="number",lt=t=>t?new Date(t):new Date,Ht=t=>lt(t).getTime();function mr(t,e,n){let r=ut(e)?e*((n==null?void 0:n.unit)==="s"?1e3:1):e;return new Date(t).getTime()<=+r}function pr(t,e,n){let r=ut(e)?e*((n==null?void 0:n.unit)==="s"?1e3:1):e;return new Date(t).getTime()>+r}function dr(t,e){let r=Ht(t)+(e.days?e.days*24*60*60*1e3:0)+(e.hours?e.hours*60*60*1e3:0)+(e.minutes?e.minutes*60*1e3:0)+(e.seconds?e.seconds*1e3:0)+(e.milliseconds?e.milliseconds:0);return lt(r)}function De(t,e=1,n=[]){let r=[...t];if(e<=0)return n;for(;r.length;)n.push(r.splice(0,e));return n}function fr(t,...e){return t.filter(n=>e.every(r=>r.includes(n)))}function gr(t,...e){return t.filter(n=>e.every(r=>!r.includes(n)))}function hr(t){return[...new Set(t)]}var mt=class t{constructor(e){this._owner=e}get publicKey(){return t.isKeyPair(this._owner)?this._owner.publicKey:this._owner}get signer(){return t.isKeyPair(this._owner)?this._owner:void 0}get isKeyPair(){return t.isKeyPair(this._owner)}get isPublicKey(){return t.isPublicKey(this._owner)}static isKeyPair(e){return e.secretKey!==void 0}static isPublicKey(e){return!t.isKeyPair(e)}};var Zt=require("@solana/web3.js"),Xt=require("@solana/spl-token");var W=require("@solana/web3.js");var pt=(n=>(n[n.V0=0]="V0",n[n.LEGACY=1]="LEGACY",n))(pt||{}),ge={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 zt=require("@solana/spl-token");var Q=q("Sega_txUtil"),dt=1644;function Se(t){let e=[],n=[];return t.microLamports&&(e.push(W.ComputeBudgetProgram.setComputeUnitPrice({microLamports:t.microLamports})),n.push(ge.SetComputeUnitPrice)),t.units&&(e.push(W.ComputeBudgetProgram.setComputeUnitLimit({units:t.units})),n.push(ge.SetComputeUnitLimit)),{instructions:e,instructionTypes:n}}function le(t,e){return g(this,null,function*(){var r,i;let n=e!=null?e:"confirmed";return(i=yield(r=t.getLatestBlockhash)==null?void 0:r.call(t,{commitment:n}))==null?void 0:i.blockhash})}function ke(t,e){return g(this,null,function*(){return t.getSignatureStatuses([e]),new Promise((n,r)=>{let i=setTimeout(r,6e4);t.onSignature(e,s=>{if(clearTimeout(i),!s.err){n("");return}r(Object.assign(s.err,{txId:e}))},"confirmed")})})}function ft(t,e){t.length<1&&Q.logWithError(`no instructions provided: ${t.toString()}`),e.length<1&&Q.logWithError(`no signers provided:, ${e.toString()}`);let n=new W.Transaction;n.recentBlockhash="11111111111111111111111111111111",n.feePayer=e[0],n.add(...t);try{return Buffer.from(n.serialize({verifySignatures:!1})).toString("base64").length<dt}catch(r){return!1}}function Tr(t,e,n,r=!0){return g(this,null,function*(){let i=new W.PublicKey("SegaSimuLateTransaction11111111111111111"),s=[],c=new W.Transaction;c.feePayer=i;for(let a of e)ft([...c.instructions,a],[i])||(s.push(c),c=new W.Transaction,c.feePayer=i),c.add(a);c.instructions.length>0&&s.push(c);let o=[];try{if(o=yield Yt(t,s,r),o.find(a=>a.err!==null))throw Error("rpc simulateTransaction error")}catch(a){a instanceof Error&&Q.logWithError("failed to simulate for instructions","RPC_ERROR",{message:a.message})}let u=[];for(let a of o)if(Q.debug("simulate result:",a),a.logs){let l=a.logs.filter(h=>h&&h.includes(n));Q.debug("filteredLog:",u),l.length||Q.logWithError("simulate log not match keyword","keyword",n),u.push(...l)}return u})}function br(t,e){let n=t.match(/{["\w:,]+}/g);return!n||n.length!==1?Q.logWithError(`simulate log fail to match json, keyword: ${e}`):n[0]}function yr(t,e){let r=new RegExp(`"${e}":(\\d+)`,"g").exec(t);return!r||r.length!==2?Q.logWithError(`simulate log fail to match key", key: ${e}`):r[1]}function Je(t,e){let[n,r]=W.PublicKey.findProgramAddressSync(t,e);return{publicKey:n,nonce:r}}function Yt(t,e,n){return g(this,null,function*(){let r=[];if(n){let i=yield t.getLatestBlockhash(),s=[];for(let a of e){a.recentBlockhash=i.blockhash,a.lastValidBlockHeight=i.lastValidBlockHeight;let h=a._compile().serialize(),w=a._serialize(h).toString("base64");s.push(w)}let c=s.map(a=>({methodName:"simulateTransaction",args:t._buildArgs([a],void 0,"base64")})),o=[],u=20;for(let a=0;a<Math.ceil(c.length/u);a++)o.push(c.slice(a*u,(a+1)*u));r=yield(yield Promise.all(o.map(a=>g(this,null,function*(){return(yield t._rpcBatchRequest(a)).map(l=>l.result.value)})))).flat()}else try{r=yield Promise.all(e.map(i=>g(this,null,function*(){return yield(yield t.simulateTransaction(i)).value})))}catch(i){i instanceof Error&&Q.logWithError("failed to get info for multiple accounts","RPC_ERROR",{message:i.message})}return r})}function he({instructions:t,payer:e,signers:n}){return ft(t,[e,...n])}function Te({instructions:t,payer:e,lookupTableAddressAccount:n,recentBlockhash:r=W.Keypair.generate().publicKey.toString()}){let s=new W.TransactionMessage({payerKey:e,recentBlockhash:r,instructions:t}).compileToV0Message(Object.values(n!=null?n:{}));try{return Buffer.from(new W.VersionedTransaction(s).serialize()).toString("base64").length<dt}catch(c){return!1}}var Ye={time:0,data:void 0};function xr(t){return g(this,null,function*(){if(!Ye.data||(Date.now()-Ye.time)/1e3>30){let e=yield t.getEpochInfo();return Ye={time:Date.now(),data:e},e}else return Ye.data})}var gt=t=>Buffer.isBuffer(t)?t:t instanceof Uint8Array?Buffer.from(t.buffer,t.byteOffset,t.byteLength):Buffer.from(t),Jt=t=>{let e=t.serialize({requireAllSignatures:!1,verifySignatures:!1});t instanceof W.VersionedTransaction&&(e=gt(e));try{return e instanceof Buffer?e.toString("base64"):Buffer.from(e).toString("base64")}catch(n){return e.toString("base64")}};function oe(t){let e=[];return t.forEach(n=>{n instanceof W.Transaction&&(n.recentBlockhash||(n.recentBlockhash=zt.TOKEN_PROGRAM_ID.toBase58()),n.feePayer||(n.feePayer=W.Keypair.generate().publicKey)),e.push(Jt(n))}),console.log("simulate tx string:",e),e}function wr(t){let e=t.serialize({requireAllSignatures:!1,verifySignatures:!1});return t instanceof W.VersionedTransaction&&(e=gt(e)),e.toString("base64")}function Pr(t,e,n){return Je([t.toBuffer(),(n!=null?n:Xt.TOKEN_PROGRAM_ID).toBuffer(),e.toBuffer()],new Zt.PublicKey("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"))}function Sr(t){return Je([Buffer.from("metadata","utf8"),ve.toBuffer(),t.toBuffer()],ve)}var ee=require("@solana/web3.js"),$t=new ee.PublicKey("SegazTQwbYWknDZkJ6j2Kgvm5gw3MrHGKtWstZdoNKZ"),Qt=new ee.PublicKey("Ajk8d9bERSaFdeoT1d8JUVfaDayrYLnAdgeB47TFMUaG"),en=new ee.PublicKey("2HbjxVVKJ7Ct72Rcd8WK4VTqmwTXL5aAggkH1CHGFGmh"),tn=new ee.PublicKey("auetiVUVJkRxvNPLYEvVnz8UJSqQ1VgoA83PcicHVD1"),nn=new ee.PublicKey("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),rn=new ee.PublicKey("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),kr={CREATE_CPMM_POOL_PROGRAM:$t,CREATE_CPMM_POOL_AUTH:Qt,CREATE_CPMM_POOL_FEE_ACC:en},Ar={SERUM_MARKET:ee.PublicKey.default,UTIL1216:ee.PublicKey.default,CREATE_CPMM_POOL_PROGRAM:tn,CREATE_CPMM_POOL_AUTH:nn,CREATE_CPMM_POOL_FEE_ACC:rn};var V=G(require("bn.js"));var Y=1e4;function Br(t,e,n,r){if(e===void 0)return{amount:t,fee:void 0,expirationTime:void 0};let i=n.epoch<e.newerTransferFee.epoch?e.olderTransferFee:e.newerTransferFee,s=new V.default(i.maximumFee.toString()),c=n.epoch<e.newerTransferFee.epoch?(Number(e.newerTransferFee.epoch)*n.slotsInEpoch-n.absoluteSlot)*400/1e3:void 0;if(r)if(i.transferFeeBasisPoints===Y){let o=new V.default(i.maximumFee.toString());return{amount:t.add(o),fee:o,expirationTime:c}}else{let o=me(t.mul(new V.default(Y)),new V.default(Y-i.transferFeeBasisPoints)),u=new V.default(i.maximumFee.toString()),a=o.sub(t).gt(u)?t.add(u):o,l=me(a.mul(new V.default(i.transferFeeBasisPoints)),new V.default(Y)),h=l.gt(s)?s:l;return{amount:a,fee:h,expirationTime:c}}else{let o=me(t.mul(new V.default(i.transferFeeBasisPoints)),new V.default(Y)),u=o.gt(s)?s:o;return{amount:t,fee:u,expirationTime:c}}}function Cr(t,e,n,r){if(e===void 0)return{amount:t,fee:void 0,expirationTime:void 0};let i=j(K({},e),{olderTransferFee:{epoch:BigInt(e.olderTransferFee.epoch),maximumFee:BigInt(e.olderTransferFee.maximumFee),transferFeeBasisPoints:e.olderTransferFee.transferFeeBasisPoints},newerTransferFee:{epoch:BigInt(e.newerTransferFee.epoch),maximumFee:BigInt(e.newerTransferFee.maximumFee),transferFeeBasisPoints:e.newerTransferFee.transferFeeBasisPoints}}),s=n.epoch<i.newerTransferFee.epoch?i.olderTransferFee:i.newerTransferFee,c=new V.default(s.maximumFee.toString()),o=n.epoch<i.newerTransferFee.epoch?(Number(i.newerTransferFee.epoch)*n.slotsInEpoch-n.absoluteSlot)*400/1e3:void 0;if(r)if(s.transferFeeBasisPoints===Y){let u=new V.default(s.maximumFee.toString());return{amount:t.add(u),fee:u,expirationTime:o}}else{let u=me(t.mul(new V.default(Y)),new V.default(Y-s.transferFeeBasisPoints)),a=new V.default(s.maximumFee.toString()),l=u.sub(t).gt(a)?t.add(a):u,h=me(l.mul(new V.default(s.transferFeeBasisPoints)),new V.default(Y)),S=h.gt(c)?c:h;return{amount:l,fee:S,expirationTime:o}}else{let u=me(t.mul(new V.default(s.transferFeeBasisPoints)),new V.default(Y)),a=u.gt(c)?c:u;return{amount:t,fee:a,expirationTime:o}}}function Ir(t,e){return t===void 0?e:e===void 0?t:Math.min(t,e)}function me(t,e){let{div:n,mod:r}=t.divmod(e);return r.gt(new V.default(0))?n.add(new V.default(1)):n}var Ae=require("@solana/web3.js");function Ze(n){return g(this,arguments,function*({connection:t,address:e}){let r=yield Me(t,[...new Set(e.map(s=>s.toString()))].map(s=>new Ae.PublicKey(s))),i={};for(let s=0;s<e.length;s++){let c=r[s],o=e[s];if(!c)continue;let u=new Ae.AddressLookupTableAccount({key:o,state:Ae.AddressLookupTableAccount.deserialize(c.data)});i[o.toString()]=u,Be[o.toString()]=u}return i})}var Be={};var C=require("@solana/web3.js"),on=G(require("axios"));var Xe=2e3,ht=class{constructor(e){this.instructions=[];this.endInstructions=[];this.lookupTableAddress=[];this.signers=[];this.instructionTypes=[];this.endInstructionTypes=[];this.connection=e.connection,this.feePayer=e.feePayer,this.signAllTransactions=e.signAllTransactions,this.owner=e.owner,this.cluster=e.cluster,this.blockhashCommitment=e.blockhashCommitment,this.loopMultiTxStatus=!!e.loopMultiTxStatus}get AllTxData(){return{instructions:this.instructions,endInstructions:this.endInstructions,signers:this.signers,instructionTypes:this.instructionTypes,endInstructionTypes:this.endInstructionTypes,lookupTableAddress:this.lookupTableAddress}}get allInstructions(){return[...this.instructions,...this.endInstructions]}getComputeBudgetConfig(){return g(this,null,function*(){var r;let e=(yield on.default.get("https://solanacompass.com/api/fees?cacheFreshTime=300000")).data,{avg:n}=(r=e==null?void 0:e[15])!=null?r:{};if(n)return{units:6e5,microLamports:Math.min(Math.ceil(n*1e6/6e5),25e3)}})}addCustomComputeBudget(e){if(e){let{instructions:n,instructionTypes:r}=Se(e);return this.instructions.unshift(...n),this.instructionTypes.unshift(...r),!0}return!1}addTipInstruction(e){var n;return e?(this.endInstructions.push(C.SystemProgram.transfer({fromPubkey:(n=e.feePayer)!=null?n:this.feePayer,toPubkey:new C.PublicKey(e.address),lamports:BigInt(e.amount.toString())})),this.endInstructionTypes.push(ge.TransferTip),!0):!1}calComputeBudget(r){return g(this,arguments,function*({config:e,defaultIns:n}){try{let i=e||(yield this.getComputeBudgetConfig());if(this.addCustomComputeBudget(i))return;n&&this.instructions.unshift(...n)}catch(i){n&&this.instructions.unshift(...n)}})}addInstruction({instructions:e=[],endInstructions:n=[],signers:r=[],instructionTypes:i=[],endInstructionTypes:s=[],lookupTableAddress:c=[]}){return this.instructions.push(...e),this.endInstructions.push(...n),this.signers.push(...r),this.instructionTypes.push(...i),this.endInstructionTypes.push(...s),this.lookupTableAddress.push(...c.filter(o=>o!==C.PublicKey.default.toString())),this}versionBuild(r){return g(this,arguments,function*({txVersion:e,extInfo:n}){return e===0?yield this.buildV0(K({},n||{})):this.build(n)})}build(e){var r;let n=new C.Transaction;return this.allInstructions.length&&n.add(...this.allInstructions),n.feePayer=this.feePayer,(r=this.owner)!=null&&r.signer&&!this.signers.some(i=>i.publicKey.equals(this.owner.publicKey))&&this.signers.push(this.owner.signer),{builder:this,transaction:n,signers:this.signers,instructionTypes:[...this.instructionTypes,...this.endInstructionTypes],execute:i=>g(this,null,function*(){var a;let{recentBlockHash:s,skipPreflight:c=!0,sendAndConfirm:o}=i||{},u=s!=null?s:yield le(this.connection,this.blockhashCommitment);if(n.recentBlockhash=u,this.signers.length&&n.sign(...this.signers),oe([n]),(a=this.owner)!=null&&a.isKeyPair)return{txId:o?yield(0,C.sendAndConfirmTransaction)(this.connection,n,this.signers.find(h=>h.publicKey.equals(this.owner.publicKey))?this.signers:[...this.signers,this.owner.signer],{skipPreflight:c}):yield this.connection.sendRawTransaction(n.serialize(),{skipPreflight:c}),signedTx:n};if(this.signAllTransactions){let l=yield this.signAllTransactions([n]);if(this.signers.length)for(let h of l)try{h.sign(...this.signers)}catch(S){}return{txId:yield this.connection.sendRawTransaction(l[0].serialize(),{skipPreflight:c}),signedTx:l[0]}}throw new Error("please provide owner in keypair format or signAllTransactions function")}),extInfo:e||{}}}buildMultiTx(e){var a;let{extraPreBuildData:n=[],extInfo:r}=e,{transaction:i}=this.build(r),s=n.filter(l=>l.transaction.instructions.length>0),c=[i,...s.map(l=>l.transaction)],o=[this.signers,...s.map(l=>l.signers)],u=[...this.instructionTypes,...s.map(l=>l.instructionTypes).flat()];return(a=this.owner)!=null&&a.signer&&o.forEach(l=>{l.some(h=>h.publicKey.equals(this.owner.publicKey))||this.signers.push(this.owner.signer)}),{builder:this,transactions:c,signers:o,instructionTypes:u,execute:l=>g(this,null,function*(){var k;let{sequentially:h,onTxUpdate:S,skipTxCount:w=0,recentBlockHash:T,skipPreflight:x=!0}=l||{},m=T!=null?T:yield le(this.connection,this.blockhashCommitment);if((k=this.owner)!=null&&k.isKeyPair){if(h){let b=[],A=0;for(let f of c){if(++A,A<=w)continue;let d=yield(0,C.sendAndConfirmTransaction)(this.connection,f,this.signers.find(p=>p.publicKey.equals(this.owner.publicKey))?this.signers:[...this.signers,this.owner.signer],{skipPreflight:x});b.push(d)}return{txIds:b,signedTxs:c}}return{txIds:yield yield Promise.all(c.map(b=>g(this,null,function*(){return b.recentBlockhash=m,yield this.connection.sendRawTransaction(b.serialize(),{skipPreflight:x})}))),signedTxs:c}}if(this.signAllTransactions){let b=c.map((f,d)=>(f.recentBlockhash=m,o[d].length&&f.sign(...o[d]),f));oe(b);let A=yield this.signAllTransactions(b);if(h){let f=0,d=[],p=()=>g(this,null,function*(){if(!A[f])return;let P=yield this.connection.sendRawTransaction(A[f].serialize(),{skipPreflight:x});d.push({txId:P,status:"sent",signedTx:A[f]}),S==null||S([...d]),f++;let y=!1,B=null,D=null,L=I=>{B!==null&&clearInterval(B),D!==null&&this.connection.removeSignatureListener(D);let M=d.findIndex(E=>E.txId===P);if(M>-1){if(d[M].status==="error"||d[M].status==="success")return;d[M].status=I.err?"error":"success"}S==null||S([...d]),I.err||p()};this.loopMultiTxStatus&&(B=setInterval(()=>g(this,null,function*(){var I;if(y){clearInterval(B);return}try{let M=yield this.connection.getTransaction(P,{commitment:"confirmed",maxSupportedTransactionVersion:0});M&&(y=!0,clearInterval(B),L({err:((I=M.meta)==null?void 0:I.err)||null}),console.log("tx status from getTransaction:",P))}catch(M){y=!0,clearInterval(B),console.error("getTransaction timeout:",M,P)}}),Xe)),D=this.connection.onSignature(P,I=>{if(y){this.connection.removeSignatureListener(D);return}y=!0,L(I)},"confirmed"),this.connection.getSignatureStatus(P)});return yield p(),{txIds:d.map(P=>P.txId),signedTxs:A}}else{let f=[];for(let d=0;d<A.length;d+=1){let p=yield this.connection.sendRawTransaction(A[d].serialize(),{skipPreflight:x});f.push(p)}return{txIds:f,signedTxs:A}}}throw new Error("please provide owner in keypair format or signAllTransactions function")}),extInfo:r||{}}}versionMultiBuild(i){return g(this,arguments,function*({extraPreBuildData:e,txVersion:n,extInfo:r}){return n===0?yield this.buildV0MultiTx({extraPreBuildData:e,buildProps:r||{}}):this.buildMultiTx({extraPreBuildData:e,extInfo:r})})}buildV0(e){return g(this,null,function*(){var x;let T=e||{},{lookupTableCache:n={},lookupTableAddress:r=[],forerunCreate:i,recentBlockhash:s}=T,c=Ne(T,["lookupTableCache","lookupTableAddress","forerunCreate","recentBlockhash"]),o=K(K({},this.cluster==="devnet"?{}:Be),n),u=Array.from(new Set([...r,...this.lookupTableAddress])),a=[];for(let m of u)o[m]===void 0&&a.push(new C.PublicKey(m));let l=yield Ze({connection:this.connection,address:a});for(let[m,k]of Object.entries(l))o[m]=k;let h=i?C.PublicKey.default.toBase58():s!=null?s:yield le(this.connection,this.blockhashCommitment),S=new C.TransactionMessage({payerKey:this.feePayer,recentBlockhash:h,instructions:[...this.allInstructions]}).compileToV0Message(Object.values(o));(x=this.owner)!=null&&x.signer&&!this.signers.some(m=>m.publicKey.equals(this.owner.publicKey))&&this.signers.push(this.owner.signer);let w=new C.VersionedTransaction(S);return w.sign(this.signers),{builder:this,transaction:w,signers:this.signers,instructionTypes:[...this.instructionTypes,...this.endInstructionTypes],execute:m=>g(this,null,function*(){var A;let{skipPreflight:k=!0,sendAndConfirm:b}=m||{};if(oe([w]),(A=this.owner)!=null&&A.isKeyPair){let f=yield this.connection.sendTransaction(w,{skipPreflight:k});return b&&(yield ke(this.connection,f)),{txId:f,signedTx:w}}if(this.signAllTransactions){let f=yield this.signAllTransactions([w]);if(this.signers.length)for(let d of f)try{d.sign(this.signers)}catch(p){}return{txId:yield this.connection.sendTransaction(f[0],{skipPreflight:k}),signedTx:f[0]}}throw new Error("please provide owner in keypair format or signAllTransactions function")}),extInfo:c||{}}})}buildV0MultiTx(e){return g(this,null,function*(){var a;let{extraPreBuildData:n=[],buildProps:r}=e,{transaction:i}=yield this.buildV0(r),s=n.filter(l=>l.builder.instructions.length>0),c=[i,...s.map(l=>l.transaction)],o=[this.signers,...s.map(l=>l.signers)],u=[...this.instructionTypes,...s.map(l=>l.instructionTypes).flat()];return(a=this.owner)!=null&&a.signer&&o.forEach(l=>{l.some(h=>h.publicKey.equals(this.owner.publicKey))||this.signers.push(this.owner.signer)}),c.forEach((l,h)=>g(this,null,function*(){l.sign(o[h])})),{builder:this,transactions:c,signers:o,instructionTypes:u,buildProps:r,execute:l=>g(this,null,function*(){var x;let{sequentially:h,onTxUpdate:S,recentBlockHash:w,skipPreflight:T=!0}=l||{};if(w&&c.forEach(m=>m.message.recentBlockhash=w),oe(c),(x=this.owner)!=null&&x.isKeyPair){if(h){let m=[];for(let k of c){let b=yield this.connection.sendTransaction(k,{skipPreflight:T});yield ke(this.connection,b),m.push(b)}return{txIds:m,signedTxs:c}}return{txIds:yield Promise.all(c.map(m=>g(this,null,function*(){return yield this.connection.sendTransaction(m,{skipPreflight:T})}))),signedTxs:c}}if(this.signAllTransactions){let m=yield this.signAllTransactions(c);if(h){let k=0,b=[],A=()=>g(this,null,function*(){if(!m[k])return;let f=yield this.connection.sendTransaction(m[k],{skipPreflight:T});b.push({txId:f,status:"sent",signedTx:m[k]}),S==null||S([...b]),k++;let d=!1,p=null,P=null,y=B=>{p!==null&&clearInterval(p),P!==null&&this.connection.removeSignatureListener(P);let D=b.findIndex(L=>L.txId===f);if(D>-1){if(b[D].status==="error"||b[D].status==="success")return;b[D].status=B.err?"error":"success"}S==null||S([...b]),B.err||A()};this.loopMultiTxStatus&&(p=setInterval(()=>g(this,null,function*(){var B;if(d){clearInterval(p);return}try{let D=yield this.connection.getTransaction(f,{commitment:"confirmed",maxSupportedTransactionVersion:0});D&&(d=!0,clearInterval(p),y({err:((B=D.meta)==null?void 0:B.err)||null}),console.log("tx status from getTransaction:",f))}catch(D){d=!0,clearInterval(p),console.error("getTransaction timeout:",D,f)}}),Xe)),P=this.connection.onSignature(f,B=>{if(d){this.connection.removeSignatureListener(P);return}d=!0,y(B)},"confirmed"),this.connection.getSignatureStatus(f)});return A(),{txIds:[],signedTxs:m}}else{let k=[];for(let b=0;b<m.length;b+=1){let A=yield this.connection.sendTransaction(m[b],{skipPreflight:T});k.push(A)}return{txIds:k,signedTxs:m}}}throw new Error("please provide owner in keypair format or signAllTransactions function")}),extInfo:r||{}}})}sizeCheckBuild(e){return g(this,null,function*(){var S;let h=e||{},{splitIns:n=[],computeBudgetConfig:r}=h,i=Ne(h,["splitIns","computeBudgetConfig"]),s=r?Se(r):{instructions:[],instructionTypes:[]},c=this.signers.reduce((w,T)=>j(K({},w),{[T.publicKey.toBase58()]:T}),{}),o=[],u=[],a=[],l=0;if(this.allInstructions.forEach(w=>{let T=[...a,w],x=r?[...s.instructions,...T]:T,k=[...new Set(T.map(b=>b.keys.filter(A=>A.isSigner).map(A=>A.pubkey.toString())).flat()).values()].map(b=>new C.PublicKey(b));if(w!==n[l]&&a.length<12&&(he({instructions:x,payer:this.feePayer,signers:k})||he({instructions:T,payer:this.feePayer,signers:k})))a.push(w);else{if(a.length===0)throw Error("item ins too big");l+=w===n[l]?1:0,he({instructions:r?[...s.instructions,...a]:[...a],payer:this.feePayer,signers:k})?o.push(new C.Transaction().add(...s.instructions,...a)):o.push(new C.Transaction().add(...a)),u.push(Array.from(new Set(a.map(b=>b.keys.filter(A=>A.isSigner).map(A=>A.pubkey.toString())).flat())).map(b=>c[b]).filter(b=>b!==void 0)),a=[w]}}),a.length>0){let T=[...new Set(a.map(x=>x.keys.filter(m=>m.isSigner).map(m=>m.pubkey.toString())).flat()).values()].map(x=>c[x]).filter(x=>x!==void 0);he({instructions:r?[...s.instructions,...a]:[...a],payer:this.feePayer,signers:T.map(x=>x.publicKey)})?o.push(new C.Transaction().add(...s.instructions,...a)):o.push(new C.Transaction().add(...a)),u.push(T)}return o.forEach(w=>w.feePayer=this.feePayer),(S=this.owner)!=null&&S.signer&&u.forEach(w=>{w.some(T=>T.publicKey.equals(this.owner.publicKey))||w.push(this.owner.signer)}),{builder:this,transactions:o,signers:u,instructionTypes:this.instructionTypes,execute:w=>g(this,null,function*(){var f;let{sequentially:T,onTxUpdate:x,skipTxCount:m=0,recentBlockHash:k,skipPreflight:b=!0}=w||{},A=k!=null?k:yield le(this.connection,this.blockhashCommitment);if(o.forEach((d,p)=>g(this,null,function*(){d.recentBlockhash=A,u[p].length&&d.sign(...u[p])})),oe(o),(f=this.owner)!=null&&f.isKeyPair){if(T){let d=0,p=[];for(let P of o){if(++d,d<=m){p.push("tx skipped");continue}let y=yield(0,C.sendAndConfirmTransaction)(this.connection,P,this.signers.find(B=>B.publicKey.equals(this.owner.publicKey))?this.signers:[...this.signers,this.owner.signer],{skipPreflight:b});p.push(y)}return{txIds:p,signedTxs:o}}return{txIds:yield Promise.all(o.map(d=>g(this,null,function*(){return yield this.connection.sendRawTransaction(d.serialize(),{skipPreflight:b})}))),signedTxs:o}}if(this.signAllTransactions){let d=yield this.signAllTransactions(o.slice(m,o.length)),p=[...o.slice(0,m),...d];if(T){let P=0,y=[],B=()=>g(this,null,function*(){if(!p[P])return;P<m&&(y.push({txId:"",status:"success",signedTx:p[P]}),x==null||x([...y]),P++,B());let D=yield this.connection.sendRawTransaction(p[P].serialize(),{skipPreflight:b});y.push({txId:D,status:"sent",signedTx:p[P]}),x==null||x([...y]),P++;let L=!1,I=null,M=null,E=U=>{I!==null&&clearInterval(I),M!==null&&this.connection.removeSignatureListener(M);let v=y.findIndex(se=>se.txId===D);if(v>-1){if(y[v].status==="error"||y[v].status==="success")return;y[v].status=U.err?"error":"success"}x==null||x([...y]),U.err||B()};this.loopMultiTxStatus&&(I=setInterval(()=>g(this,null,function*(){var U;if(L){clearInterval(I);return}try{let v=yield this.connection.getTransaction(D,{commitment:"confirmed",maxSupportedTransactionVersion:0});v&&(L=!0,clearInterval(I),E({err:((U=v.meta)==null?void 0:U.err)||null}),console.log("tx status from getTransaction:",D))}catch(v){L=!0,clearInterval(I),console.error("getTransaction timeout:",v,D)}}),Xe)),M=this.connection.onSignature(D,U=>{if(L){this.connection.removeSignatureListener(M);return}L=!0,E(U)},"confirmed"),this.connection.getSignatureStatus(D)});return yield B(),{txIds:y.map(D=>D.txId),signedTxs:p}}else{let P=[];for(let y=0;y<p.length;y+=1){let B=yield this.connection.sendRawTransaction(p[y].serialize(),{skipPreflight:b});P.push(B)}return{txIds:P,signedTxs:p}}}throw new Error("please provide owner in keypair format or signAllTransactions function")}),extInfo:i||{}}})}sizeCheckBuildV0(e){return g(this,null,function*(){var A;let b=e||{},{computeBudgetConfig:n,splitIns:r=[],lookupTableCache:i={},lookupTableAddress:s=[]}=b,c=Ne(b,["computeBudgetConfig","splitIns","lookupTableCache","lookupTableAddress"]),o=K(K({},this.cluster==="devnet"?{}:Be),i),u=Array.from(new Set([...this.lookupTableAddress,...s])),a=[];for(let f of u)o[f]===void 0&&a.push(new C.PublicKey(f));let l=yield Ze({connection:this.connection,address:a});for(let[f,d]of Object.entries(l))o[f]=d;let h=n?Se(n):{instructions:[],instructionTypes:[]},S=yield le(this.connection,this.blockhashCommitment),w=this.signers.reduce((f,d)=>j(K({},f),{[d.publicKey.toBase58()]:d}),{}),T=[],x=[],m=[],k=0;if(this.allInstructions.forEach(f=>{let d=[...m,f],p=n?[...h.instructions,...d]:d;if(f!==r[k]&&m.length<12&&(Te({instructions:p,payer:this.feePayer,lookupTableAddressAccount:o})||Te({instructions:d,payer:this.feePayer,lookupTableAddressAccount:o})))m.push(f);else{if(m.length===0)throw Error("item ins too big");k+=f===r[k]?1:0;let P={};for(let y of[...new Set(u)])o[y]!==void 0&&(P[y]=o[y]);if(n&&Te({instructions:[...h.instructions,...m],payer:this.feePayer,lookupTableAddressAccount:o,recentBlockhash:S})){let y=new C.TransactionMessage({payerKey:this.feePayer,recentBlockhash:S,instructions:[...h.instructions,...m]}).compileToV0Message(Object.values(o));T.push(new C.VersionedTransaction(y))}else{let y=new C.TransactionMessage({payerKey:this.feePayer,recentBlockhash:S,instructions:[...m]}).compileToV0Message(Object.values(o));T.push(new C.VersionedTransaction(y))}x.push(Array.from(new Set(m.map(y=>y.keys.filter(B=>B.isSigner).map(B=>B.pubkey.toString())).flat())).map(y=>w[y]).filter(y=>y!==void 0)),m=[f]}}),m.length>0){let d=[...new Set(m.map(p=>p.keys.filter(P=>P.isSigner).map(P=>P.pubkey.toString())).flat()).values()].map(p=>w[p]).filter(p=>p!==void 0);if(n&&Te({instructions:[...h.instructions,...m],payer:this.feePayer,lookupTableAddressAccount:o,recentBlockhash:S})){let p=new C.TransactionMessage({payerKey:this.feePayer,recentBlockhash:S,instructions:[...h.instructions,...m]}).compileToV0Message(Object.values(o));T.push(new C.VersionedTransaction(p))}else{let p=new C.TransactionMessage({payerKey:this.feePayer,recentBlockhash:S,instructions:[...m]}).compileToV0Message(Object.values(o));T.push(new C.VersionedTransaction(p))}x.push(d)}return(A=this.owner)!=null&&A.signer&&x.forEach(f=>{f.some(d=>d.pu