UNPKG

@sega-so/sega-sdk

Version:

An SDK for building applications on top of SEGA.

2 lines 22 kB
"use strict";var $e=Object.create;var U=Object.defineProperty,Qe=Object.defineProperties,et=Object.getOwnPropertyDescriptor,tt=Object.getOwnPropertyDescriptors,nt=Object.getOwnPropertyNames,ye=Object.getOwnPropertySymbols,rt=Object.getPrototypeOf,Pe=Object.prototype.hasOwnProperty,it=Object.prototype.propertyIsEnumerable;var he=(t,e,n)=>e in t?U(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,M=(t,e)=>{for(var n in e||(e={}))Pe.call(e,n)&&he(t,n,e[n]);if(ye)for(var n of ye(e))it.call(e,n)&&he(t,n,e[n]);return t},O=(t,e)=>Qe(t,tt(e));var ot=(t,e)=>{for(var n in e)U(t,n,{get:e[n],enumerable:!0})},Te=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of nt(e))!Pe.call(t,o)&&o!==n&&U(t,o,{get:()=>e[o],enumerable:!(r=et(e,o))||r.enumerable});return t};var S=(t,e,n)=>(n=t!=null?$e(rt(t)):{},Te(e||!t||!t.__esModule?U(n,"default",{value:t,enumerable:!0}):n,t)),st=t=>Te(U({},"__esModule",{value:!0}),t);var N=(t,e,n)=>new Promise((r,o)=>{var c=a=>{try{p(n.next(a))}catch(u){o(u)}},l=a=>{try{p(n.throw(a))}catch(u){o(u)}},p=a=>a.done?r(a.value):Promise.resolve(a.value).then(c,l);p((n=n.apply(t,e)).next())});var Ft={};ot(Ft,{collectCpFeeInstruction:()=>Ot,cpmmLockPositionInstruction:()=>Je,makeCpmmLockInstruction:()=>Et,makeCreateCpmmPoolInInstruction:()=>Mt,makeDepositCpmmInInstruction:()=>Nt,makeSwapCpmmBaseInInstruction:()=>Dt,makeSwapCpmmBaseOutInstruction:()=>Rt,makeWithdrawCpmmInInstruction:()=>_t});module.exports=st(Ft);var g=require("@solana/web3.js"),w=require("@solana/spl-token");var ut=require("@solana/web3.js");var q=require("lodash");var ie=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}},xe={},at={};function k(t){let e=(0,q.get)(xe,t);if(!e){let n=(0,q.get)(at,t);e=new ie({name:t,logLevel:n}),(0,q.set)(xe,t,e)}return e}var Z=require("@solana/spl-token");var zt=k("Sega_accountInfo_util");var A=S(require("bn.js")),ht=S(require("decimal.js"));var Ae=S(require("big.js")),ft=S(require("bn.js"));var we=S(require("toformat")),ct=we.default,G=ct;var j=S(require("big.js")),ke=S(require("bn.js")),Be=S(require("decimal.js-light"));var F=S(require("bn.js"));var Se=9007199254740991;function I(t){let e=k("Sega_parseBigNumberish");if(t instanceof F.default)return t;if(typeof t=="string"){if(t.match(/^-?[0-9]+$/))return new F.default(t);e.logWithError(`invalid BigNumberish string: ${t}`)}return typeof t=="number"?(t%1&&e.logWithError(`BigNumberish number underflow: ${t}`),(t>=Se||t<=-Se)&&e.logWithError(`BigNumberish number overflow: ${t}`),new F.default(String(t))):typeof t=="bigint"?new F.default(t.toString()):(e.error(`invalid BigNumberish value: ${t}`),new F.default(0))}var X=k("module/fraction"),se=G(j.default),H=G(Be.default),mt={0:H.ROUND_DOWN,1:H.ROUND_HALF_UP,2:H.ROUND_UP},pt={0:j.default.roundDown,1:j.default.roundHalfUp,2:j.default.roundUp},L=class t{constructor(e,n=new ke.default(1)){this.numerator=I(e),this.denominator=I(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(I(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(I(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(I(e));return new t(this.numerator.mul(n.numerator),this.denominator.mul(n.denominator))}div(e){let n=e instanceof t?e:new t(I(e));return new t(this.numerator.mul(n.denominator),this.denominator.mul(n.numerator))}toSignificant(e,n={groupSeparator:""},r=1){Number.isInteger(e)||X.logWithError(`${e} is not an integer.`),e<=0&&X.logWithError(`${e} is not positive.`),H.set({precision:e+1,rounding:mt[r]});let o=new H(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(e);return o.toFormat(o.decimalPlaces(),n)}toFixed(e,n={groupSeparator:""},r=1){return Number.isInteger(e)||X.logWithError(`${e} is not an integer.`),e<0&&X.logWithError(`${e} is negative.`),se.DP=e,se.RM=pt[r]||1,new se(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,n)}isZero(){return this.numerator.isZero()}};var gn=k("Sega_amount"),bn=G(Ae.default);var Ie=require("@solana/web3.js"),ae=require("@solana/spl-token"),Le={chainId:101,address:Ie.PublicKey.default.toBase58(),programId:ae.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"}},_={chainId:101,address:"So11111111111111111111111111111111111111112",programId:ae.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 $=require("@solana/web3.js");var s=require("@solana/web3.js"),Ce=require("@solana/spl-token");function ue({pubkey:t,isSigner:e=!1,isWritable:n=!0}){return{pubkey:t,isWritable:n,isSigner:e}}var Tn=[ue({pubkey:Ce.TOKEN_PROGRAM_ID,isWritable:!1}),ue({pubkey:s.SystemProgram.programId,isWritable:!1}),ue({pubkey:s.SYSVAR_RENT_PUBKEY,isWritable:!1})];function Ke({publicKey:t,transformSol:e}){let n=We(t.toString());if(n instanceof s.PublicKey)return e&&n.equals(z)?oe:n;if(e&&n.toString()===z.toBase58())return oe;if(typeof n=="string"){if(n===s.PublicKey.default.toBase58())return s.PublicKey.default;try{return new s.PublicKey(n)}catch(r){throw new Error("invalid public key")}}throw new Error("invalid public key")}function We(t){try{return new s.PublicKey(t)}catch(e){return t}}var xn=new s.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),ce=new s.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),le=new s.PublicKey("SysvarRent111111111111111111111111111111111"),wn=new s.PublicKey("SysvarC1ock11111111111111111111111111111111"),Y=new s.PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),Sn=new s.PublicKey("Sysvar1nstructions1111111111111111111111111"),Me=s.SystemProgram.programId,kn=new s.PublicKey("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),Bn=new s.PublicKey("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),An=new s.PublicKey("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),In=new s.PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),Ln=new s.PublicKey("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),Cn=new s.PublicKey("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),Kn=new s.PublicKey("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),Wn=new s.PublicKey("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),Mn=new s.PublicKey("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),Nn=new s.PublicKey("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),_n=new s.PublicKey("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),oe=new s.PublicKey("So11111111111111111111111111111111111111112"),z=s.PublicKey.default;var Q=class Q{constructor({mint:e,decimals:n,symbol:r,name:o,skipMint:c=!1,isToken2022:l=!1}){if(e===z.toBase58()||e instanceof $.PublicKey&&z.equals(e)){this.decimals=_.decimals,this.symbol=_.symbol,this.name=_.name,this.mint=new $.PublicKey(_.address),this.isToken2022=!1;return}this.decimals=n,this.symbol=r||e.toString().substring(0,6),this.name=o||e.toString().substring(0,6),this.mint=c?$.PublicKey.default:Ke({publicKey:e}),this.isToken2022=l}equals(e){return this===e?!0:this.mint.equals(e.mint)}};Q.WSOL=new Q(O(M({},_),{mint:_.address}));var J=Q;var ee=class ee{constructor({decimals:e,symbol:n="UNKNOWN",name:r="UNKNOWN"}){this.decimals=e,this.symbol=n,this.name=r}equals(e){return this===e}};ee.SOL=new ee(Le);var me=ee;var Ne=S(require("bn.js"));var jn=new L(new Ne.default(100));var Xn=k("Sega_price");var bt=require("@solana/web3.js"),yt=S(require("bn.js"));var gt=new A.default(0),Kr=new A.default(1),Wr=new A.default(2),Mr=new A.default(3),Nr=new A.default(5),dt=new A.default(10),_r=new A.default(100),Dr=new A.default(1e3),Rr=new A.default(1e4);var Ee=require("@solana/web3.js"),Oe=require("@solana/spl-token");var D=require("@solana/web3.js");var te={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 Pt=require("@solana/spl-token");var Zr=k("Sega_txUtil");function V(t,e){let[n,r]=D.PublicKey.findProgramAddressSync(t,e);return{publicKey:n,nonce:r}}function ne(t,e,n){return V([t.toBuffer(),(n!=null?n:Oe.TOKEN_PROGRAM_ID).toBuffer(),e.toBuffer()],new Ee.PublicKey("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"))}function Fe(t){return V([Buffer.from("metadata","utf8"),Y.toBuffer(),t.toBuffer()],Y)}var C=require("@solana/web3.js"),Ve=new C.PublicKey("SegazTQwbYWknDZkJ6j2Kgvm5gw3MrHGKtWstZdoNKZ"),ve=new C.PublicKey("Ajk8d9bERSaFdeoT1d8JUVfaDayrYLnAdgeB47TFMUaG"),ni=new C.PublicKey("2HbjxVVKJ7Ct72Rcd8WK4VTqmwTXL5aAggkH1CHGFGmh"),Tt=new C.PublicKey("auetiVUVJkRxvNPLYEvVnz8UJSqQ1VgoA83PcicHVD1"),xt=new C.PublicKey("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),wt=new C.PublicKey("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y");var ri={SERUM_MARKET:C.PublicKey.default,UTIL1216:C.PublicKey.default,CREATE_CPMM_POOL_PROGRAM:Tt,CREATE_CPMM_POOL_AUTH:xt,CREATE_CPMM_POOL_FEE_ACC:wt};var St=S(require("bn.js"));var Ue=require("@solana/web3.js");var v=require("@solana/web3.js"),kt=S(require("axios"));var Bt=require("@solana/web3.js");var eo=Buffer.from("vault_and_lp_mint_auth_seed","utf8"),to=Buffer.from("amm_config","utf8"),At=Buffer.from("pool","utf8"),no=Buffer.from("pool_lp_mint","utf8"),ro=Buffer.from("pool_vault","utf8"),io=Buffer.from("observation","utf8");function qe(t,e,n,r){return V([At,e.toBuffer(),n.toBuffer(),r.toBuffer()],t)}var It=Buffer.from("locked_liquidity","utf8");function Ge(t,e){return V([It,e.toBuffer()],t)}var Lt=require("@solana/web3.js"),re=S(require("bn.js"));var i=require("@solana/buffer-layout"),pe=i.Layout,je=i.Structure;var He=i.u8;var ze=i.blob;var fe=class extends pe{constructor(e,n,r){super(e,r),this.blob=ze(e),this.signed=n}decode(e,n=0){let r=new re.default(this.blob.decode(e,n),10,"le");return this.signed?r.fromTwos(this.span*8).clone():r}encode(e,n,r=0){return typeof e=="number"&&(e=new re.default(e)),this.signed&&(e=e.toTwos(this.span*8)),this.blob.encode(e.toArrayLike(Buffer,"le",this.span),n,r)}};function x(t){return new fe(8,!1,t)}var de=class extends pe{constructor(e,n,r,o){super(e.span,o),this.layout=e,this.decoder=n,this.encoder=r}decode(e,n){return this.decoder(this.layout.decode(e,n))}encode(e,n,r){return this.layout.encode(this.encoder(e),n,r)}getSpan(e,n){return this.layout.getSpan(e,n)}};function Ye(t){return new de(He(),Ct,Kt,t)}function Ct(t){if(t===0)return!1;if(t===1)return!0;throw new Error("Invalid bool: "+t)}function Kt(t){return t?1:0}var ge=class extends je{decode(e,n){return super.decode(e,n)}};function K(t,e,n){return new ge(t,e,n)}var Wt=k("Sega_cpmm"),R={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]};function Mt(t,e,n,r,o,c,l,p,a,u,P,T,b,y,h,f,m,d,B,W){let E=K([x("amountMaxA"),x("amountMaxB"),x("openTime")]),Ze=qe(t,n,c,l).publicKey,Xe=[{pubkey:e,isSigner:!0,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!o.equals(Ze),isWritable:!0},{pubkey:c,isSigner:!1,isWritable:!1},{pubkey:l,isSigner:!1,isWritable:!1},{pubkey:p,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!1,isWritable:!0},{pubkey:u,isSigner:!1,isWritable:!0},{pubkey:P,isSigner:!1,isWritable:!0},{pubkey:T,isSigner:!1,isWritable:!0},{pubkey:b,isSigner:!1,isWritable:!0},{pubkey:y,isSigner:!1,isWritable:!0},{pubkey:m,isSigner:!1,isWritable:!0},{pubkey:w.TOKEN_PROGRAM_ID,isSigner:!1,isWritable:!1},{pubkey:h,isSigner:!1,isWritable:!1},{pubkey:f,isSigner:!1,isWritable:!1},{pubkey:w.ASSOCIATED_TOKEN_PROGRAM_ID,isSigner:!1,isWritable:!1},{pubkey:Me,isSigner:!1,isWritable:!1},{pubkey:le,isSigner:!1,isWritable:!1}],be=Buffer.alloc(E.span);return E.encode({amountMaxA:d,amountMaxB:B,openTime:W},be),new g.TransactionInstruction({keys:Xe,programId:t,data:Buffer.from([...R.initialize,...be])})}function Nt(t,e,n,r,o,c,l,p,a,u,P,T,b,y,h){let f=K([x("lpAmount"),x("amountMaxA"),x("amountMaxB")]),m=[{pubkey:e,isSigner:!0,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:c,isSigner:!1,isWritable:!0},{pubkey:l,isSigner:!1,isWritable:!0},{pubkey:p,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!1,isWritable:!0},{pubkey:w.TOKEN_PROGRAM_ID,isSigner:!1,isWritable:!1},{pubkey:w.TOKEN_2022_PROGRAM_ID,isSigner:!1,isWritable:!1},{pubkey:u,isSigner:!1,isWritable:!1},{pubkey:P,isSigner:!1,isWritable:!1},{pubkey:T,isSigner:!1,isWritable:!0}],d=Buffer.alloc(f.span);return Wt.debug("cpmm deposit data",{lpAmount:b.toString(),amountMaxA:y.toString(),amountMaxB:h.toString()}),f.encode({lpAmount:b,amountMaxA:y,amountMaxB:h},d),new g.TransactionInstruction({keys:m,programId:t,data:Buffer.from([...R.deposit,...d])})}function _t(t,e,n,r,o,c,l,p,a,u,P,T,b,y,h){let f=K([x("lpAmount"),x("amountMinA"),x("amountMinB")]),m=[{pubkey:e,isSigner:!0,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:c,isSigner:!1,isWritable:!0},{pubkey:l,isSigner:!1,isWritable:!0},{pubkey:p,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!1,isWritable:!0},{pubkey:w.TOKEN_PROGRAM_ID,isSigner:!1,isWritable:!1},{pubkey:w.TOKEN_2022_PROGRAM_ID,isSigner:!1,isWritable:!1},{pubkey:u,isSigner:!1,isWritable:!1},{pubkey:P,isSigner:!1,isWritable:!1},{pubkey:T,isSigner:!1,isWritable:!0},{pubkey:ce,isSigner:!1,isWritable:!1}],d=Buffer.alloc(f.span);return f.encode({lpAmount:b,amountMinA:y,amountMinB:h},d),new g.TransactionInstruction({keys:m,programId:t,data:Buffer.from([...R.withdraw,...d])})}function Dt(t,e,n,r,o,c,l,p,a,u,P,T,b,y,h,f){let m=K([x("amountIn"),x("amounOutMin")]),d=[{pubkey:e,isSigner:!0,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:c,isSigner:!1,isWritable:!0},{pubkey:l,isSigner:!1,isWritable:!0},{pubkey:p,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!1,isWritable:!0},{pubkey:u,isSigner:!1,isWritable:!1},{pubkey:P,isSigner:!1,isWritable:!1},{pubkey:T,isSigner:!1,isWritable:!1},{pubkey:b,isSigner:!1,isWritable:!1},{pubkey:y,isSigner:!1,isWritable:!0}],B=Buffer.alloc(m.span);return m.encode({amountIn:h,amounOutMin:f},B),new g.TransactionInstruction({keys:d,programId:t,data:Buffer.from([...R.swapBaseInput,...B])})}function Rt(t,e,n,r,o,c,l,p,a,u,P,T,b,y,h,f){let m=K([x("amountInMax"),x("amountOut")]),d=[{pubkey:e,isSigner:!0,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:c,isSigner:!1,isWritable:!0},{pubkey:l,isSigner:!1,isWritable:!0},{pubkey:p,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!1,isWritable:!0},{pubkey:u,isSigner:!1,isWritable:!1},{pubkey:P,isSigner:!1,isWritable:!1},{pubkey:T,isSigner:!1,isWritable:!1},{pubkey:b,isSigner:!1,isWritable:!1},{pubkey:y,isSigner:!1,isWritable:!0}],B=Buffer.alloc(m.span);return m.encode({amountInMax:h,amountOut:f},B),new g.TransactionInstruction({keys:d,programId:t,data:Buffer.from([...R.swapBaseOutput,...B])})}function Et(t){return N(this,null,function*(){var m;let{ownerInfo:e,poolInfo:n,poolKeys:r,feeNftOwner:o,getEphemeralSigners:c}=t,l=[],[p,a]=[new g.PublicKey(n.id),new g.PublicKey(n.lpMint.address)],u;if(c)u=new g.PublicKey((yield c(1))[0]);else{let d=g.Keypair.generate();l.push(d),u=d.publicKey}let{publicKey:P}=ne(o,u,w.TOKEN_PROGRAM_ID),{publicKey:T}=Fe(u),{publicKey:b}=Ge(t.lockProgram,u),{publicKey:y}=ne(e.wallet,a,w.TOKEN_PROGRAM_ID),{publicKey:h}=ne(t.lockAuthProgram,a,w.TOKEN_PROGRAM_ID),f=Je({programId:t.lockProgram,auth:t.lockAuthProgram,payer:e.feePayer,liquidityOwner:e.wallet,nftOwner:o,nftMint:u,nftAccount:P,poolId:p,lockPda:b,mintLp:a,userLpVault:y,lockLpVault:h,poolVaultA:new g.PublicKey(r.vault.A),poolVaultB:new g.PublicKey(r.vault.B),metadataAccount:T,lpAmount:t.lpAmount,withMetadata:(m=t.withMetadata)!=null?m:!0});return{address:{nftMint:u,nftAccount:P,metadataAccount:T,lockPda:b,userLpVault:y,lockLpVault:h},instructions:[f],signers:l,instructionTypes:[te.CpmmLockLp],lookupTableAddress:[]}})}function Je({programId:t,auth:e,payer:n,liquidityOwner:r,nftOwner:o,nftMint:c,nftAccount:l,poolId:p,lockPda:a,mintLp:u,userLpVault:P,lockLpVault:T,poolVaultA:b,poolVaultB:y,metadataAccount:h,lpAmount:f,withMetadata:m}){let d=[{pubkey:e,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!0,isWritable:!0},{pubkey:r,isSigner:!0,isWritable:!1},{pubkey:o,isSigner:!1,isWritable:!1},{pubkey:c,isSigner:!0,isWritable:!0},{pubkey:l,isSigner:!1,isWritable:!0},{pubkey:p,isSigner:!1,isWritable:!1},{pubkey:a,isSigner:!1,isWritable:!0},{pubkey:u,isSigner:!1,isWritable:!1},{pubkey:P,isSigner:!1,isWritable:!0},{pubkey:T,isSigner:!1,isWritable:!0},{pubkey:b,isSigner:!1,isWritable:!0},{pubkey:y,isSigner:!1,isWritable:!0},{pubkey:h,isSigner:!1,isWritable:!0},{pubkey:le,isSigner:!1,isWritable:!1},{pubkey:g.SystemProgram.programId,isSigner:!1,isWritable:!1},{pubkey:w.TOKEN_PROGRAM_ID,isSigner:!1,isWritable:!1},{pubkey:w.ASSOCIATED_TOKEN_PROGRAM_ID,isSigner:!1,isWritable:!1},{pubkey:Y,isSigner:!1,isWritable:!1}],B=K([x("lpAmount"),Ye("withMetadata")]),W=Buffer.alloc(B.span);B.encode({lpAmount:f,withMetadata:m},W);let E=Buffer.from([...R.lockCpLiquidity,...W]);return new g.TransactionInstruction({keys:d,programId:t,data:E})}function Ot({programId:t,nftOwner:e,auth:n,nftAccount:r,lockPda:o,poolId:c,mintLp:l,userVaultA:p,userVaultB:a,poolVaultA:u,poolVaultB:P,mintA:T,mintB:b,lockLpVault:y,lpFeeAmount:h,cpmmProgram:f,cpmmAuthProgram:m}){let d=[{pubkey:n,isSigner:!1,isWritable:!1},{pubkey:e,isSigner:!0,isWritable:!1},{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:f!=null?f:Ve,isSigner:!1,isWritable:!1},{pubkey:m!=null?m:ve,isSigner:!1,isWritable:!1},{pubkey:c,isSigner:!1,isWritable:!0},{pubkey:l,isSigner:!1,isWritable:!0},{pubkey:p,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!1,isWritable:!0},{pubkey:u,isSigner:!1,isWritable:!0},{pubkey:P,isSigner:!1,isWritable:!0},{pubkey:T,isSigner:!1,isWritable:!1},{pubkey:b,isSigner:!1,isWritable:!1},{pubkey:y,isSigner:!1,isWritable:!0},{pubkey:w.TOKEN_PROGRAM_ID,isSigner:!1,isWritable:!1},{pubkey:w.TOKEN_2022_PROGRAM_ID,isSigner:!1,isWritable:!1},{pubkey:ce,isSigner:!1,isWritable:!1}],B=K([x("lpFeeAmount")]),W=Buffer.alloc(B.span);B.encode({lpFeeAmount:h},W);let E=Buffer.from([...R.collectCpFee,...W]);return new g.TransactionInstruction({keys:d,programId:t,data:E})}0&&(module.exports={collectCpFeeInstruction,cpmmLockPositionInstruction,makeCpmmLockInstruction,makeCreateCpmmPoolInInstruction,makeDepositCpmmInInstruction,makeSwapCpmmBaseInInstruction,makeSwapCpmmBaseOutInstruction,makeWithdrawCpmmInInstruction}); //# sourceMappingURL=instruction.js.map