UNPKG

@sega-so/sega-sdk

Version:

An SDK for building applications on top of SEGA.

2 lines 12.2 kB
var re=Object.defineProperty,ie=Object.defineProperties;var oe=Object.getOwnPropertyDescriptors;var C=Object.getOwnPropertySymbols;var U=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable;var q=(t,e,n)=>e in t?re(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,u=(t,e)=>{for(var n in e||(e={}))U.call(e,n)&&q(t,n,e[n]);if(C)for(var n of C(e))G.call(e,n)&&q(t,n,e[n]);return t},m=(t,e)=>ie(t,oe(e));var I=(t,e)=>{var n={};for(var r in t)U.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&C)for(var r of C(t))e.indexOf(r)<0&&G.call(t,r)&&(n[r]=t[r]);return n};var b=(t,e,n)=>new Promise((r,o)=>{var s=l=>{try{g(n.next(l))}catch(w){o(w)}},x=l=>{try{g(n.throw(l))}catch(w){o(w)}},g=l=>l.done?r(l.value):Promise.resolve(l.value).then(s,x);g((n=n.apply(t,e)).next())});import{PublicKey as Ie}from"@solana/web3.js";import{MintLayout as te,TOKEN_PROGRAM_ID as Ne}from"@solana/spl-token";import Ae from"big.js";import L from"bn.js";import f from"bn.js";import tn from"decimal.js";import{PublicKey as se}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as j}from"@solana/spl-token";var S={chainId:101,address:se.default.toBase58(),programId:j.toBase58(),decimals:9,symbol:"SOL",name:"solana",logoURI:"https://img-v1.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"sega",extensions:{coingeckoId:"solana"}},p={chainId:101,address:"So11111111111111111111111111111111111111112",programId:j.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 W}from"@solana/web3.js";import{PublicKey as i,SystemProgram as H,SYSVAR_RENT_PUBKEY as ae}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as ce}from"@solana/spl-token";function E({pubkey:t,isSigner:e=!1,isWritable:n=!0}){return{pubkey:t,isWritable:n,isSigner:e}}var Ve=[E({pubkey:ce,isWritable:!1}),E({pubkey:H.programId,isWritable:!1}),E({pubkey:ae,isWritable:!1})];function V({publicKey:t,transformSol:e}){let n=z(t.toString());if(n instanceof i)return e&&n.equals(P)?O:n;if(e&&n.toString()===P.toBase58())return O;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 z(t){try{return new i(t)}catch(e){return t}}var We=new i("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Ke=new i("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),_e=new i("SysvarRent111111111111111111111111111111111"),ve=new i("SysvarC1ock11111111111111111111111111111111"),ue=new i("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),qe=new i("Sysvar1nstructions1111111111111111111111111"),Ue=H.programId,Ge=new i("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),je=new i("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),He=new i("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),ze=new i("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),Ye=new i("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),Je=new i("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),Ze=new i("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),Xe=new i("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),$e=new i("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),Qe=new i("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),et=new i("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),O=new i("So11111111111111111111111111111111111111112"),P=i.default;function N(t){return V({publicKey:t,transformSol:!0})}var F=class F{constructor({mint:e,decimals:n,symbol:r,name:o,skipMint:s=!1,isToken2022:x=!1}){if(e===P.toBase58()||e instanceof W&&P.equals(e)){this.decimals=p.decimals,this.symbol=p.symbol,this.name=p.name,this.mint=new W(p.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=s?W.default:V({publicKey:e}),this.isToken2022=x}equals(e){return this===e?!0:this.mint.equals(e.mint)}};F.WSOL=new F(m(u({},p),{mint:p.address}));var h=F;var R=class R{constructor({decimals:e,symbol:n="UNKNOWN",name:r="UNKNOWN"}){this.decimals=e,this.symbol=n,this.name=r}equals(e){return this===e}};R.SOL=new R(S);var K=R;import D from"big.js";import ge from"bn.js";import he from"decimal.js-light";import{get as Y,set as le}from"lodash";var _=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}},J={},me={};function a(t){let e=Y(J,t);if(!e){let n=Y(me,t);e=new _({name:t,logLevel:n}),le(J,t,e)}return e}import k from"bn.js";var Z=9007199254740991;function c(t){let e=a("Sega_parseBigNumberish");if(t instanceof k)return t;if(typeof t=="string"){if(t.match(/^-?[0-9]+$/))return new k(t);e.logWithError(`invalid BigNumberish string: ${t}`)}return typeof t=="number"?(t%1&&e.logWithError(`BigNumberish number underflow: ${t}`),(t>=Z||t<=-Z)&&e.logWithError(`BigNumberish number overflow: ${t}`),new k(String(t))):typeof t=="bigint"?new k(t.toString()):(e.error(`invalid BigNumberish value: ${t}`),new k(0))}import pe from"toformat";var de=pe,A=de;var M=a("module/fraction"),v=A(D),B=A(he),Te={0:B.ROUND_DOWN,1:B.ROUND_HALF_UP,2:B.ROUND_UP},be={0:D.roundDown,1:D.roundHalfUp,2:D.roundUp},d=class t{constructor(e,n=new ge(1)){this.numerator=c(e),this.denominator=c(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(c(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(c(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(c(e));return new t(this.numerator.mul(n.numerator),this.denominator.mul(n.denominator))}div(e){let n=e instanceof t?e:new t(c(e));return new t(this.numerator.mul(n.denominator),this.denominator.mul(n.numerator))}toSignificant(e,n={groupSeparator:""},r=1){Number.isInteger(e)||M.logWithError(`${e} is not an integer.`),e<=0&&M.logWithError(`${e} is not positive.`),B.set({precision:e+1,rounding:Te[r]});let o=new B(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)||M.logWithError(`${e} is not an integer.`),e<0&&M.logWithError(`${e} is negative.`),v.DP=e,v.RM=be[r]||1,new v(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,n)}isZero(){return this.numerator.isZero()}};import ye from"bn.js";var It=new d(new ye(100));var Lt=a("Sega_price");import{PublicKey as Ut}from"@solana/web3.js";import jt from"bn.js";var xe=new f(0),pn=new f(1),dn=new f(2),fn=new f(3),gn=new f(5),Q=new f(10),hn=new f(100),Tn=new f(1e3),bn=new f(1e4);import{PublicKey as Bn}from"@solana/web3.js";import{MINT_SIZE as Fn,TOKEN_PROGRAM_ID as Rn,getTransferFeeConfig as Mn,unpackMint as Dn}from"@solana/spl-token";var Ln=a("Sega_accountInfo_util");import{PublicKey as ur}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as mr}from"@solana/spl-token";import{ComputeBudgetProgram as Gn,Keypair as zn,PublicKey as Yn,Transaction as Zn,TransactionMessage as $n,VersionedTransaction as Qn}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as rr}from"@solana/spl-token";var ir=a("Sega_txUtil");import{PublicKey as T}from"@solana/web3.js";var hr=new T("SegazTQwbYWknDZkJ6j2Kgvm5gw3MrHGKtWstZdoNKZ"),Tr=new T("Ajk8d9bERSaFdeoT1d8JUVfaDayrYLnAdgeB47TFMUaG"),br=new T("2HbjxVVKJ7Ct72Rcd8WK4VTqmwTXL5aAggkH1CHGFGmh"),Se=new T("auetiVUVJkRxvNPLYEvVnz8UJSqQ1VgoA83PcicHVD1"),Pe=new T("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),ke=new T("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y");var yr={SERUM_MARKET:T.default,UTIL1216:T.default,CREATE_CPMM_POOL_PROGRAM:Se,CREATE_CPMM_POOL_AUTH:Pe,CREATE_CPMM_POOL_FEE_ACC:ke};import Sr from"bn.js";import{PublicKey as Ir,AddressLookupTableAccount as Nr}from"@solana/web3.js";import{PublicKey as jr,sendAndConfirmTransaction as Hr,SystemProgram as Jr,Transaction as Zr,TransactionMessage as $r,VersionedTransaction as Qr}from"@solana/web3.js";import ti from"axios";import{Connection as ui}from"@solana/web3.js";var Be=a("Sega_amount"),ee=A(Ae);function Ce(t,e){let n="0",r="0";if(t.includes(".")){let o=t.split(".");o.length===2?([n,r]=o,r=r.padEnd(e,"0")):Be.logWithError(`invalid number string, num: ${t}`)}else n=t;return[n,r.slice(0,e)||r]}var y=class t extends d{constructor(e,n,r=!0,o){let s=new L(0),x=Q.pow(new L(e.decimals));if(r)s=c(n);else{let g=new L(0),l=new L(0);if(typeof n=="string"||typeof n=="number"||typeof n=="bigint"){let[w,ne]=Ce(n.toString(),e.decimals);g=c(w),l=c(ne)}g=g.mul(x),s=g.add(l)}super(s,x),this.logger=a(o||"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)}};var ro=n=>b(void 0,[n],function*({connection:t,mint:e}){let r=yield t.getAccountInfo(new Ie(e));return!r||r.data.length!==te.span?void 0:te.decode(r.data)}),io=({mint:t,decimals:e,programId:n=Ne,logoURI:r="",priority:o=3})=>{let s=t.toBase58().substring(0,6);return{address:t.toBase58(),decimals:e,symbol:s,logoURI:r,extensions:{},chainId:101,programId:n.toString(),name:s,tags:[],priority:o}},oo=t=>new h({mint:t.address,decimals:t.decimals,symbol:t.symbol,name:t.name}),so=o=>{var s=o,{amount:t,isRaw:e,name:n}=s,r=I(s,["amount","isRaw","name"]);return new y(new h({mint:N(r.address).toBase58(),decimals:r.decimals,symbol:r.symbol,name:n}),t,e,n)};function ao(t){return t.address===S.address?p:t}function co(t){return t.address===p.address?S:t}var uo=o=>{var s=o,{address:t,programId:e,decimals:n}=s,r=I(s,["address","programId","decimals"]);return u({chainId:101,address:N(t).toBase58(),programId:e,logoURI:"",symbol:"",name:"",decimals:n,tags:[],extensions:r.extensions||{}},r)},lo=t=>t?m(u({},t),{transferFeeConfigAuthority:t.transferFeeConfigAuthority.toBase58(),withdrawWithheldAuthority:t.withdrawWithheldAuthority.toBase58(),withheldAmount:t.withheldAmount.toString(),olderTransferFee:m(u({},t.olderTransferFee),{epoch:t.olderTransferFee.epoch.toString(),maximumFee:t.olderTransferFee.maximumFee.toString()}),newerTransferFee:m(u({},t.newerTransferFee),{epoch:t.newerTransferFee.epoch.toString(),maximumFee:t.newerTransferFee.maximumFee.toString()})}):void 0;export{ro as parseTokenInfo,ao as solToWSolToken,uo as toApiV3Token,lo as toFeeConfig,oo as toToken,so as toTokenAmount,io as toTokenInfo,co as wSolToSolToken}; //# sourceMappingURL=utils.mjs.map