@sega-so/sega-sdk
Version:
An SDK for building applications on top of SEGA.
2 lines • 13.9 kB
JavaScript
var ue=Object.defineProperty,le=Object.defineProperties;var me=Object.getOwnPropertyDescriptors;var R=Object.getOwnPropertySymbols;var j=Object.prototype.hasOwnProperty,Y=Object.prototype.propertyIsEnumerable;var H=(t,e,n)=>e in t?ue(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,f=(t,e)=>{for(var n in e||(e={}))j.call(e,n)&&H(t,n,e[n]);if(R)for(var n of R(e))Y.call(e,n)&&H(t,n,e[n]);return t},g=(t,e)=>le(t,me(e));var F=(t,e)=>{var n={};for(var r in t)j.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&R)for(var r of R(t))e.indexOf(r)<0&&Y.call(t,r)&&(n[r]=t[r]);return n};var u=(t,e,n)=>new Promise((r,s)=>{var c=l=>{try{a(n.next(l))}catch(m){s(m)}},o=l=>{try{a(n.throw(l))}catch(m){s(m)}},a=l=>l.done?r(l.value):Promise.resolve(l.value).then(c,o);a((n=n.apply(t,e)).next())});import ae from"axios";import{PublicKey as ve}from"@solana/web3.js";import{get as z,set as pe}from"lodash";var D=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}},$={},fe={};function p(t){let e=z($,t);if(!e){let n=z(fe,t);e=new D({name:t,logLevel:n}),pe($,t,e)}return e}import{MINT_SIZE as He,TOKEN_PROGRAM_ID as je,getTransferFeeConfig as Ye,unpackMint as ze}from"@solana/spl-token";var $e=p("Sega_accountInfo_util");import b from"bn.js";import jn from"decimal.js";import we from"big.js";import gt from"bn.js";import de from"toformat";var ge=de,C=ge;import O from"big.js";import Te from"bn.js";import be from"decimal.js-light";import A from"bn.js";var J=9007199254740991;function h(t){let e=p("Sega_parseBigNumberish");if(t instanceof A)return t;if(typeof t=="string"){if(t.match(/^-?[0-9]+$/))return new A(t);e.logWithError(`invalid BigNumberish string: ${t}`)}return typeof t=="number"?(t%1&&e.logWithError(`BigNumberish number underflow: ${t}`),(t>=J||t<=-J)&&e.logWithError(`BigNumberish number overflow: ${t}`),new A(String(t))):typeof t=="bigint"?new A(t.toString()):(e.error(`invalid BigNumberish value: ${t}`),new A(0))}var L=p("module/fraction"),V=C(O),k=C(be),ye={0:k.ROUND_DOWN,1:k.ROUND_HALF_UP,2:k.ROUND_UP},xe={0:O.roundDown,1:O.roundHalfUp,2:O.roundUp},T=class t{constructor(e,n=new Te(1)){this.numerator=h(e),this.denominator=h(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(h(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(h(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(h(e));return new t(this.numerator.mul(n.numerator),this.denominator.mul(n.denominator))}div(e){let n=e instanceof t?e:new t(h(e));return new t(this.numerator.mul(n.denominator),this.denominator.mul(n.numerator))}toSignificant(e,n={groupSeparator:""},r=1){Number.isInteger(e)||L.logWithError(`${e} is not an integer.`),e<=0&&L.logWithError(`${e} is not positive.`),k.set({precision:e+1,rounding:ye[r]});let s=new k(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(e);return s.toFormat(s.decimalPlaces(),n)}toFixed(e,n={groupSeparator:""},r=1){return Number.isInteger(e)||L.logWithError(`${e} is not an integer.`),e<0&&L.logWithError(`${e} is negative.`),V.DP=e,V.RM=xe[r]||1,new V(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,n)}isZero(){return this.numerator.isZero()}};var It=p("Sega_amount"),Ct=C(we);import{PublicKey as Se}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Z}from"@solana/spl-token";var X={chainId:101,address:Se.default.toBase58(),programId:Z.toBase58(),decimals:9,symbol:"SOL",name:"solana",logoURI:"https://img-v1.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"sega",extensions:{coingeckoId:"solana"}},x={chainId:101,address:"So11111111111111111111111111111111111111112",programId:Z.toBase58(),decimals:9,symbol:"WSOL",name:"Wrapped SOL",logoURI:"https://img-v1.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"sega",extensions:{coingeckoId:"solana"}};import{PublicKey as v}from"@solana/web3.js";import{PublicKey as i,SystemProgram as Q,SYSVAR_RENT_PUBKEY as Ie}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Ce}from"@solana/spl-token";function W({pubkey:t,isSigner:e=!1,isWritable:n=!0}){return{pubkey:t,isWritable:n,isSigner:e}}var Et=[W({pubkey:Ce,isWritable:!1}),W({pubkey:Q.programId,isWritable:!1}),W({pubkey:Ie,isWritable:!1})];function ee({publicKey:t,transformSol:e}){let n=te(t.toString());if(n instanceof i)return e&&n.equals(B)?K:n;if(e&&n.toString()===B.toBase58())return K;if(typeof n=="string"){if(n===i.default.toBase58())return i.default;try{return new i(n)}catch(r){throw new Error("invalid public key")}}throw new Error("invalid public key")}function te(t){try{return new i(t)}catch(e){return t}}var Mt=new i("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),_t=new i("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Ft=new i("SysvarRent111111111111111111111111111111111"),Dt=new i("SysvarC1ock11111111111111111111111111111111"),Ae=new i("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),Kt=new i("Sysvar1nstructions1111111111111111111111111"),Vt=Q.programId,Wt=new i("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),vt=new i("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),qt=new i("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),Ut=new i("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),Gt=new i("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),Ht=new i("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),jt=new i("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),Yt=new i("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),zt=new i("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),$t=new i("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),Jt=new i("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),K=new i("So11111111111111111111111111111111111111112"),B=i.default;var E=class E{constructor({mint:e,decimals:n,symbol:r,name:s,skipMint:c=!1,isToken2022:o=!1}){if(e===B.toBase58()||e instanceof v&&B.equals(e)){this.decimals=x.decimals,this.symbol=x.symbol,this.name=x.name,this.mint=new v(x.address),this.isToken2022=!1;return}this.decimals=n,this.symbol=r||e.toString().substring(0,6),this.name=s||e.toString().substring(0,6),this.mint=c?v.default:ee({publicKey:e}),this.isToken2022=o}equals(e){return this===e?!0:this.mint.equals(e.mint)}};E.WSOL=new E(g(f({},x),{mint:x.address}));var N=E;var M=class M{constructor({decimals:e,symbol:n="UNKNOWN",name:r="UNKNOWN"}){this.decimals=e,this.symbol=n,this.name=r}equals(e){return this===e}};M.SOL=new M(X);var q=M;import ke from"bn.js";var ln=new T(new ke(100));var hn=p("Sega_price");import{PublicKey as En}from"@solana/web3.js";import _n from"bn.js";function oe(t){return u(this,null,function*(){new Promise(e=>setTimeout(e,t))})}var Be=new b(0),nr=new b(1),rr=new b(2),ir=new b(3),or=new b(5),Pe=new b(10),sr=new b(100),ar=new b(1e3),cr=new b(1e4);import{PublicKey as Fr}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Kr}from"@solana/spl-token";import{ComputeBudgetProgram as Tr,Keypair as xr,PublicKey as wr,Transaction as Sr,TransactionMessage as Cr,VersionedTransaction as Ar}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Rr}from"@solana/spl-token";var Lr=p("Sega_txUtil");import{PublicKey as y}from"@solana/web3.js";var Ur=new y("SegazTQwbYWknDZkJ6j2Kgvm5gw3MrHGKtWstZdoNKZ"),Gr=new y("Ajk8d9bERSaFdeoT1d8JUVfaDayrYLnAdgeB47TFMUaG"),Hr=new y("2HbjxVVKJ7Ct72Rcd8WK4VTqmwTXL5aAggkH1CHGFGmh"),Re=new y("auetiVUVJkRxvNPLYEvVnz8UJSqQ1VgoA83PcicHVD1"),Le=new y("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),Oe=new y("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y");var jr={SERUM_MARKET:y.default,UTIL1216:y.default,CREATE_CPMM_POOL_PROGRAM:Re,CREATE_CPMM_POOL_AUTH:Le,CREATE_CPMM_POOL_FEE_ACC:Oe};import $r from"bn.js";import{PublicKey as ti,AddressLookupTableAccount as ni}from"@solana/web3.js";import{PublicKey as bi,sendAndConfirmTransaction as yi,SystemProgram as Pi,Transaction as Si,TransactionMessage as Ci,VersionedTransaction as Ai}from"@solana/web3.js";import Bi from"axios";import{Connection as Fi}from"@solana/web3.js";var d={BASE_HOST:"https://api.sega.so/api",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",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://tokens.jup.ag/tokens?tags=lst,community",POOL_LIST:"/pools/info/list",POOL_SEARCH_BY_ID:"/pools/info/ids",POOL_SEARCH_MINT:"/pools/info/mint",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_IDO:"/main/ido/{owner}",OWNER_STAKE_FARMS:"/position/stake/{owner}",OWNER_LOCK_POSITION:"/position/clmm-lock/{owner}",IDO_KEYS:"/ido/key/ids",SWAP_COMPUTE:"/compute/",SWAP_TX:"/transaction/",MINT_PRICE:"/mint/price",MIGRATE_CONFIG:"/main/migrate-lp",PRIORITY_FEE:"/main/auto-fee"},ro=f({},d);var se="ray_tab_hash",U="ray_req_hash",Ee=()=>{if(typeof window===void 0)return"";let t=sessionStorage.getItem(se);return t||(t=`ray-${Date.now()}`,sessionStorage.setItem(se,t)),t},_=r=>u(void 0,null,function*(){var s=r,{logCount:t=1e3,removeLastLog:e}=s,n=F(s,["logCount","removeLastLog"]);if(typeof window===void 0)return new Promise(o=>o());let c=JSON.parse(localStorage.getItem(U)||"[]").slice(0,t-1);e&&c.pop(),new Blob([JSON.stringify(n.data)]).size>1024&&(n.data=JSON.stringify(n.data).substring(0,200)+"..."),c.unshift(g(f({},n),{time:Date.now(),session:Ee()}));try{localStorage.setItem(U,JSON.stringify(c))}catch(o){if(e){let a=!1,l=JSON.stringify(n.data).substring(0,100);for(c[0].data=l+(l.length>100?"...":"");!a;){c.pop();let m=JSON.stringify(n.data).substring(0,100);c[0].data=m+(m.length>100?"...":"");try{localStorage.setItem(U,JSON.stringify(c)),a=!0}catch(w){a=!1}}return new Promise(m=>m())}return _(g(f({},n),{logCount:t,removeLastLog:!0}))}});var P=p("Sega_Api"),G=new Map;function go(t,e,n=1e3){return u(this,null,function*(){let r;for(;r==null;)try{P.debug(`Request ${t} through endlessRetry`),r=yield e()}catch(s){P.error(`Request ${t} failed, retry after ${n} ms`,s),yield oe(n)}return r})}var ce=class{constructor({cluster:e,timeout:n,logRequests:r,logCount:s,urlConfigs:c}){this.cluster=e,this.urlConfigs=c||{},this.logCount=s||1e3,this.api=ae.create({baseURL:this.urlConfigs.BASE_HOST||d.BASE_HOST,timeout:n}),this.api.interceptors.request.use(o=>{let{method:a,baseURL:l,url:m}=o;return P.debug(`${a==null?void 0:a.toUpperCase()} ${l}${m}`),o},o=>(P.error("Request failed"),Promise.reject(o))),this.api.interceptors.response.use(o=>{let{config:a,data:l,status:m}=o,{method:w,baseURL:S,url:I}=a;return r&&_({status:m,url:`${S}${I}`,params:a.params,data:l,logCount:this.logCount}),P.debug(`${w==null?void 0:w.toUpperCase()} ${S}${I} ${m}`),l},o=>{let{config:a,response:l={}}=o,{status:m}=l,{method:w,baseURL:S,url:I}=a;return r&&_({status:m,url:`${S}${I}`,params:a.params,data:o.message,logCount:this.logCount}),P.error(`${w.toUpperCase()} ${S}${I} ${m||o.message}`),Promise.reject(o)})}getCpmmConfigs(){return u(this,null,function*(){return(yield this.api.get(this.urlConfigs.CPMM_CONFIG||d.CPMM_CONFIG)).data})}getBlockSlotCountForSecond(e){return u(this,null,function*(){if(!e)return 2;let r=(yield ae.post(e,{id:"getRecentPerformanceSamples",jsonrpc:"2.0",method:"getRecentPerformanceSamples",params:[4]})).result.map(s=>s.numSlots);return r.reduce((s,c)=>s+c,0)/r.length/60})}getChainTimeOffset(){return u(this,null,function*(){return(yield this.api.get(this.urlConfigs.CHAIN_TIME||d.CHAIN_TIME)).data})}fetchPoolKeysById(e){return u(this,null,function*(){let{idList:n}=e,r=[],s=n.filter(o=>G.has(o)?(r.push(G.get(o)),!1):!0),c=[];return s.length&&(c=(yield this.api.get((this.urlConfigs.POOL_KEY_BY_ID||d.POOL_KEY_BY_ID)+`?ids=${s.join(",")}`)).data.filter(Boolean),c.forEach(a=>{G.set(a.id,a)})),r.concat(c)})}getRpcs(){return u(this,null,function*(){return this.api.get(this.urlConfigs.RPCS||d.RPCS)})}getTokenList(){return u(this,null,function*(){return(yield this.api.get(this.urlConfigs.TOKEN_LIST||d.TOKEN_LIST)).data})}getJupTokenList(){return u(this,null,function*(){return this.api.get("",{baseURL:this.urlConfigs.JUP_TOKEN_LIST||d.JUP_TOKEN_LIST})})}getTokenInfo(e){return u(this,null,function*(){return(yield this.api.get((this.urlConfigs.MINT_INFO_ID||d.MINT_INFO_ID)+`?mints=${e.map(r=>r.toString()).join(",")}`)).data})}fetchAvailabilityStatus(){return u(this,null,function*(){return(yield this.api.get(this.urlConfigs.CHECK_AVAILABILITY||d.CHECK_AVAILABILITY)).data})}};export{ce as Api,go as endlessRetry};
//# sourceMappingURL=api.mjs.map