UNPKG

@sega-so/sega-sdk

Version:

An SDK for building applications on top of SEGA.

2 lines 11.7 kB
var ne=Object.defineProperty,re=Object.defineProperties;var ie=Object.getOwnPropertyDescriptors;var q=Object.getOwnPropertySymbols;var oe=Object.prototype.hasOwnProperty,se=Object.prototype.propertyIsEnumerable;var U=(n,e,t)=>e in n?ne(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,h=(n,e)=>{for(var t in e||(e={}))oe.call(e,t)&&U(n,t,e[t]);if(q)for(var t of q(e))se.call(e,t)&&U(n,t,e[t]);return n},T=(n,e)=>re(n,ie(e));var b=(n,e,t)=>new Promise((r,s)=>{var l=u=>{try{p(t.next(u))}catch(S){s(S)}},g=u=>{try{p(t.throw(u))}catch(S){s(S)}},p=u=>u.done?r(u.value):Promise.resolve(u.value).then(l,g);p((t=t.apply(n,e)).next())});import{PublicKey as Re}from"@solana/web3.js";import De from"bn.js";import Ce from"big.js";import M from"bn.js";import m from"bn.js";import jt from"decimal.js";import{PublicKey as ae}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as G}from"@solana/spl-token";var j={chainId:101,address:ae.default.toBase58(),programId:G.toBase58(),decimals:9,symbol:"SOL",name:"solana",logoURI:"https://img-v1.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"sega",extensions:{coingeckoId:"solana"}},f={chainId:101,address:"So11111111111111111111111111111111111111112",programId:G.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 O}from"@solana/web3.js";import{PublicKey as i,SystemProgram as H,SYSVAR_RENT_PUBKEY as ce}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as ue}from"@solana/spl-token";function F({pubkey:n,isSigner:e=!1,isWritable:t=!0}){return{pubkey:n,isWritable:t,isSigner:e}}var Ke=[F({pubkey:ue,isWritable:!1}),F({pubkey:H.programId,isWritable:!1}),F({pubkey:ce,isWritable:!1})];function z({publicKey:n,transformSol:e}){let t=E(n.toString());if(t instanceof i)return e&&t.equals(k)?L:t;if(e&&t.toString()===k.toBase58())return L;if(typeof t=="string"){if(t===i.default.toBase58())return i.default;try{return new i(t)}catch(r){throw new Error("invalid public key")}}throw new Error("invalid public key")}function E(n){try{return new i(n)}catch(e){return n}}var ve=new i("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),_e=new i("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),qe=new i("SysvarRent111111111111111111111111111111111"),Ue=new i("SysvarC1ock11111111111111111111111111111111"),le=new i("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),Ge=new i("Sysvar1nstructions1111111111111111111111111"),je=H.programId,He=new i("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),ze=new i("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),Ye=new i("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),Je=new i("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),Ze=new i("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),Xe=new i("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),$e=new i("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),Qe=new i("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),et=new i("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),tt=new i("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),nt=new i("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),L=new i("So11111111111111111111111111111111111111112"),k=i.default;var I=class I{constructor({mint:e,decimals:t,symbol:r,name:s,skipMint:l=!1,isToken2022:g=!1}){if(e===k.toBase58()||e instanceof O&&k.equals(e)){this.decimals=f.decimals,this.symbol=f.symbol,this.name=f.name,this.mint=new O(f.address),this.isToken2022=!1;return}this.decimals=t,this.symbol=r||e.toString().substring(0,6),this.name=s||e.toString().substring(0,6),this.mint=l?O.default:z({publicKey:e}),this.isToken2022=g}equals(e){return this===e?!0:this.mint.equals(e.mint)}};I.WSOL=new I(T(h({},f),{mint:f.address}));var y=I;var N=class N{constructor({decimals:e,symbol:t="UNKNOWN",name:r="UNKNOWN"}){this.decimals=e,this.symbol=t,this.name=r}equals(e){return this===e}};N.SOL=new N(j);var V=N;import D from"big.js";import he from"bn.js";import Te from"decimal.js-light";import{get as Y,set as me}from"lodash";var W=class{constructor(e){this.logLevel=e.logLevel!==void 0?e.logLevel:0,this.name=e.name}set level(e){this.logLevel=e}get time(){return Date.now().toString()}get moduleName(){return this.name}isLogLevel(e){return e<=this.logLevel}error(...e){return this.isLogLevel(0)?(console.error(this.time,this.name,"sdk logger error",...e),this):this}logWithError(...e){let t=e.map(r=>typeof r=="object"?JSON.stringify(r):r).join(", ");throw new Error(t)}warning(...e){return this.isLogLevel(1)?(console.warn(this.time,this.name,"sdk logger warning",...e),this):this}info(...e){return this.isLogLevel(2)?(console.info(this.time,this.name,"sdk logger info",...e),this):this}debug(...e){return this.isLogLevel(3)?(console.debug(this.time,this.name,"sdk logger debug",...e),this):this}},J={},pe={};function a(n){let e=Y(J,n);if(!e){let t=Y(pe,n);e=new W({name:n,logLevel:t}),me(J,n,e)}return e}import A from"bn.js";var Z=9007199254740991;function c(n){let e=a("Sega_parseBigNumberish");if(n instanceof A)return n;if(typeof n=="string"){if(n.match(/^-?[0-9]+$/))return new A(n);e.logWithError(`invalid BigNumberish string: ${n}`)}return typeof n=="number"?(n%1&&e.logWithError(`BigNumberish number underflow: ${n}`),(n>=Z||n<=-Z)&&e.logWithError(`BigNumberish number overflow: ${n}`),new A(String(n))):typeof n=="bigint"?new A(n.toString()):(e.error(`invalid BigNumberish value: ${n}`),new A(0))}import de from"toformat";var fe=de,B=fe;var R=a("module/fraction"),K=B(D),C=B(Te),be={0:C.ROUND_DOWN,1:C.ROUND_HALF_UP,2:C.ROUND_UP},ye={0:D.roundDown,1:D.roundHalfUp,2:D.roundUp},o=class n{constructor(e,t=new he(1)){this.numerator=c(e),this.denominator=c(t)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new n(this.denominator,this.numerator)}add(e){let t=e instanceof n?e:new n(c(e));return this.denominator.eq(t.denominator)?new n(this.numerator.add(t.numerator),this.denominator):new n(this.numerator.mul(t.denominator).add(t.numerator.mul(this.denominator)),this.denominator.mul(t.denominator))}sub(e){let t=e instanceof n?e:new n(c(e));return this.denominator.eq(t.denominator)?new n(this.numerator.sub(t.numerator),this.denominator):new n(this.numerator.mul(t.denominator).sub(t.numerator.mul(this.denominator)),this.denominator.mul(t.denominator))}mul(e){let t=e instanceof n?e:new n(c(e));return new n(this.numerator.mul(t.numerator),this.denominator.mul(t.denominator))}div(e){let t=e instanceof n?e:new n(c(e));return new n(this.numerator.mul(t.denominator),this.denominator.mul(t.numerator))}toSignificant(e,t={groupSeparator:""},r=1){Number.isInteger(e)||R.logWithError(`${e} is not an integer.`),e<=0&&R.logWithError(`${e} is not positive.`),C.set({precision:e+1,rounding:be[r]});let s=new C(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(e);return s.toFormat(s.decimalPlaces(),t)}toFixed(e,t={groupSeparator:""},r=1){return Number.isInteger(e)||R.logWithError(`${e} is not an integer.`),e<0&&R.logWithError(`${e} is negative.`),K.DP=e,K.RM=ye[r]||1,new K(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,t)}isZero(){return this.numerator.isZero()}};import xe from"bn.js";var X=new o(new xe(100)),x=class extends o{toSignificant(e=5,t,r){return this.mul(X).toSignificant(e,t,r)}toFixed(e=2,t,r){return this.mul(X).toFixed(e,t,r)}};var we=a("Sega_price"),w=class n extends o{constructor(e){let{baseToken:t,quoteToken:r,numerator:s,denominator:l}=e;super(s,l),this.baseToken=t,this.quoteToken=r,this.scalar=new o(v(t.decimals),v(r.decimals))}get raw(){return new o(this.numerator,this.denominator)}get adjusted(){return super.mul(this.scalar)}invert(){return new n({baseToken:this.quoteToken,quoteToken:this.baseToken,denominator:this.numerator,numerator:this.denominator})}mul(e){this.quoteToken!==e.baseToken&&we.logWithError("mul token not equals");let t=super.mul(e);return new n({baseToken:this.baseToken,quoteToken:e.quoteToken,denominator:t.denominator,numerator:t.numerator})}toSignificant(e=this.quoteToken.decimals,t,r){return this.adjusted.toSignificant(e,t,r)}toFixed(e=this.quoteToken.decimals,t,r){return this.adjusted.toFixed(e,t,r)}};var Pe=new m(0),tn=new m(1),nn=new m(2),rn=new m(3),on=new m(5),_=new m(10),sn=new m(100),an=new m(1e3),cn=new m(1e4);function v(n){return _.pow(c(n))}import{PublicKey as Tn}from"@solana/web3.js";import{MINT_SIZE as wn,TOKEN_PROGRAM_ID as Pn,getTransferFeeConfig as Sn,unpackMint as kn}from"@solana/spl-token";var An=a("Sega_accountInfo_util");import{PublicKey as er}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as nr}from"@solana/spl-token";import{ComputeBudgetProgram as En,Keypair as Wn,PublicKey as Kn,Transaction as _n,TransactionMessage as Un,VersionedTransaction as Gn}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Yn}from"@solana/spl-token";var Jn=a("Sega_txUtil");import{PublicKey as d}from"@solana/web3.js";var ar=new d("SegazTQwbYWknDZkJ6j2Kgvm5gw3MrHGKtWstZdoNKZ"),cr=new d("Ajk8d9bERSaFdeoT1d8JUVfaDayrYLnAdgeB47TFMUaG"),ur=new d("2HbjxVVKJ7Ct72Rcd8WK4VTqmwTXL5aAggkH1CHGFGmh"),ke=new d("auetiVUVJkRxvNPLYEvVnz8UJSqQ1VgoA83PcicHVD1"),Ae=new d("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),Be=new d("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y");var lr={SERUM_MARKET:d.default,UTIL1216:d.default,CREATE_CPMM_POOL_PROGRAM:ke,CREATE_CPMM_POOL_AUTH:Ae,CREATE_CPMM_POOL_FEE_ACC:Be};import dr from"bn.js";import{PublicKey as yr,AddressLookupTableAccount as xr}from"@solana/web3.js";import{PublicKey as Vr,sendAndConfirmTransaction as Wr,SystemProgram as _r,Transaction as qr,TransactionMessage as Gr,VersionedTransaction as jr}from"@solana/web3.js";import zr from"axios";import{Connection as ti}from"@solana/web3.js";var Ie=a("Sega_amount"),Q=B(Ce);function Ne(n,e){let t="0",r="0";if(n.includes(".")){let s=n.split(".");s.length===2?([t,r]=s,r=r.padEnd(e,"0")):Ie.logWithError(`invalid number string, num: ${n}`)}else t=n;return[t,r.slice(0,e)||r]}var P=class n extends o{constructor(e,t,r=!0,s){let l=new M(0),g=_.pow(new M(e.decimals));if(r)l=c(t);else{let p=new M(0),u=new M(0);if(typeof t=="string"||typeof t=="number"||typeof t=="bigint"){let[S,te]=Ne(t.toString(),e.decimals);p=c(S),u=c(te)}p=p.mul(g),l=p.add(u)}super(l,g),this.logger=a(s||"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 n(this.token,this.raw.add(e.raw))}subtract(e){return this.token.equals(e.token)||this.logger.logWithError("sub token not equals"),new n(this.token,this.raw.sub(e.raw))}toSignificant(e=this.token.decimals,t,r=0){return super.toSignificant(e,t,r)}toFixed(e=this.token.decimals,t,r=0){return e>this.token.decimals&&this.logger.logWithError("decimals overflow"),super.toFixed(e,t,r)}toExact(e={groupSeparator:""}){return Q.DP=this.token.decimals,new Q(this.numerator.toString()).div(this.denominator.toString()).toFormat(e)}};function ji(n){return b(this,null,function*(){new Promise(e=>setTimeout(e,n))})}function Hi(){return new Date().getTime()}function $(n){return typeof n=="object"&&n!==null&&![y,P,Re,o,De,w,x].some(e=>typeof e=="object"&&n instanceof e)}function ee(n){return typeof n=="string"?E(n):Array.isArray(n)?n.map(e=>ee(e)):$(n)?Object.fromEntries(Object.entries(n).map(([e,t])=>[e,ee(t)])):n}export{Hi as getTimestamp,ee as jsonInfo2PoolKeys,$ as notInnerObject,ji as sleep}; //# sourceMappingURL=utility.mjs.map