@sega-so/sega-sdk
Version:
An SDK for building applications on top of SEGA.
2 lines • 9.64 kB
JavaScript
var Y=Object.defineProperty,z=Object.defineProperties;var Z=Object.getOwnPropertyDescriptors;var L=Object.getOwnPropertySymbols;var J=Object.prototype.hasOwnProperty,X=Object.prototype.propertyIsEnumerable;var O=(n,e,t)=>e in n?Y(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,p=(n,e)=>{for(var t in e||(e={}))J.call(e,t)&&O(n,t,e[t]);if(L)for(var t of L(e))X.call(e,t)&&O(n,t,e[t]);return n},d=(n,e)=>z(n,Z(e));import u from"bn.js";import Ai from"decimal.js";import be from"big.js";import si from"bn.js";import{get as E,set as $}from"lodash";var C=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(i=>typeof i=="object"?JSON.stringify(i):i).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}},F={},Q={};function o(n){let e=E(F,n);if(!e){let t=E(Q,n);e=new C({name:n,logLevel:t}),$(F,n,e)}return e}import{PublicKey as Be}from"@solana/web3.js";import{MINT_SIZE as Ne,TOKEN_PROGRAM_ID as De,getTransferFeeConfig as Le,unpackMint as Oe}from"@solana/spl-token";var Ee=o("Sega_accountInfo_util");import f from"bn.js";var _=9007199254740991;function c(n){let e=o("Sega_parseBigNumberish");if(n instanceof f)return n;if(typeof n=="string"){if(n.match(/^-?[0-9]+$/))return new f(n);e.logWithError(`invalid BigNumberish string: ${n}`)}return typeof n=="number"?(n%1&&e.logWithError(`BigNumberish number underflow: ${n}`),(n>=_||n<=-_)&&e.logWithError(`BigNumberish number overflow: ${n}`),new f(String(n))):typeof n=="bigint"?new f(n.toString()):(e.error(`invalid BigNumberish value: ${n}`),new f(0))}import{PublicKey as ee}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as V}from"@solana/spl-token";var W={chainId:101,address:ee.default.toBase58(),programId:V.toBase58(),decimals:9,symbol:"SOL",name:"solana",logoURI:"https://img-v1.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"sega",extensions:{coingeckoId:"solana"}},l={chainId:101,address:"So11111111111111111111111111111111111111112",programId:V.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 R}from"@solana/web3.js";import{PublicKey as r,SystemProgram as K,SYSVAR_RENT_PUBKEY as te}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as ne}from"@solana/spl-token";function I({pubkey:n,isSigner:e=!1,isWritable:t=!0}){return{pubkey:n,isWritable:t,isSigner:e}}var Je=[I({pubkey:ne,isWritable:!1}),I({pubkey:K.programId,isWritable:!1}),I({pubkey:te,isWritable:!1})];function v({publicKey:n,transformSol:e}){let t=q(n.toString());if(t instanceof r)return e&&t.equals(g)?B:t;if(e&&t.toString()===g.toBase58())return B;if(typeof t=="string"){if(t===r.default.toBase58())return r.default;try{return new r(t)}catch(i){throw new Error("invalid public key")}}throw new Error("invalid public key")}function q(n){try{return new r(n)}catch(e){return n}}var Xe=new r("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),$e=new r("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Qe=new r("SysvarRent111111111111111111111111111111111"),et=new r("SysvarC1ock11111111111111111111111111111111"),re=new r("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),tt=new r("Sysvar1nstructions1111111111111111111111111"),nt=K.programId,rt=new r("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),it=new r("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),ot=new r("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),st=new r("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),at=new r("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),ct=new r("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),ut=new r("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),lt=new r("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),mt=new r("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),pt=new r("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),dt=new r("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),B=new r("So11111111111111111111111111111111111111112"),g=r.default;var w=class w{constructor({mint:e,decimals:t,symbol:i,name:m,skipMint:k=!1,isToken2022:H=!1}){if(e===g.toBase58()||e instanceof R&&g.equals(e)){this.decimals=l.decimals,this.symbol=l.symbol,this.name=l.name,this.mint=new R(l.address),this.isToken2022=!1;return}this.decimals=t,this.symbol=i||e.toString().substring(0,6),this.name=m||e.toString().substring(0,6),this.mint=k?R.default:v({publicKey:e}),this.isToken2022=H}equals(e){return this===e?!0:this.mint.equals(e.mint)}};w.WSOL=new w(d(p({},l),{mint:l.address}));var h=w;var P=class P{constructor({decimals:e,symbol:t="UNKNOWN",name:i="UNKNOWN"}){this.decimals=e,this.symbol=t,this.name=i}equals(e){return this===e}};P.SOL=new P(W);var M=P;import ie from"toformat";var oe=ie,T=oe;import A from"big.js";import ae from"bn.js";import ce from"decimal.js-light";var S=o("module/fraction"),N=T(A),b=T(ce),ue={0:b.ROUND_DOWN,1:b.ROUND_HALF_UP,2:b.ROUND_UP},le={0:A.roundDown,1:A.roundHalfUp,2:A.roundUp},s=class n{constructor(e,t=new ae(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:""},i=1){Number.isInteger(e)||S.logWithError(`${e} is not an integer.`),e<=0&&S.logWithError(`${e} is not positive.`),b.set({precision:e+1,rounding:ue[i]});let m=new b(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(e);return m.toFormat(m.decimalPlaces(),t)}toFixed(e,t={groupSeparator:""},i=1){return Number.isInteger(e)||S.logWithError(`${e} is not an integer.`),e<0&&S.logWithError(`${e} is negative.`),N.DP=e,N.RM=le[i]||1,new N(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,t)}isZero(){return this.numerator.isZero()}};import me from"bn.js";var Ft=new s(new me(100));import{PublicKey as Pn}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as An}from"@solana/spl-token";import{ComputeBudgetProgram as nn,Keypair as sn,PublicKey as an,Transaction as un,TransactionMessage as mn,VersionedTransaction as pn}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as hn}from"@solana/spl-token";var Tn=o("Sega_txUtil");import{PublicKey as a}from"@solana/web3.js";var Rn=new a("SegazTQwbYWknDZkJ6j2Kgvm5gw3MrHGKtWstZdoNKZ"),Mn=new a("Ajk8d9bERSaFdeoT1d8JUVfaDayrYLnAdgeB47TFMUaG"),Nn=new a("2HbjxVVKJ7Ct72Rcd8WK4VTqmwTXL5aAggkH1CHGFGmh"),fe=new a("TegaRdjn9Qeh9DfUU28X19aPPpJtj9gs8ntSYrR5H4K "),ge=new a("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),he=new a("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),Dn=new a("SegaXNnoXYTZiqUt9Xn2XqGcL56b25yzXLuJSpadcMu"),Ln=new a("2t1hV2YqnDCPuJZqr7Fy8oAygGwZE5Q9uaQzpLC1QryJ"),On=new a("BLxynZeHE123MmQgNJZiV1pwW4VYh46oZYyC66xwmtTY");var Te={SERUM_MARKET:a.default,UTIL1216:a.default,CREATE_CPMM_POOL_PROGRAM:fe,CREATE_CPMM_POOL_AUTH:ge,CREATE_CPMM_POOL_FEE_ACC:he};import _n from"bn.js";import{PublicKey as Un,AddressLookupTableAccount as Gn}from"@solana/web3.js";import{PublicKey as ar,sendAndConfirmTransaction as cr,SystemProgram as mr,Transaction as pr,TransactionMessage as fr,VersionedTransaction as gr}from"@solana/web3.js";import Tr from"axios";import{PublicKey as kr}from"@solana/web3.js";import Br from"bn.js";import{Connection as Er}from"@solana/web3.js";var gi=o("Sega_amount"),hi=T(be);var pe=new u(0),Oi=new u(1),Ei=new u(2),Fi=new u(3),_i=new u(5),j=new u(10),Vi=new u(100),Wi=new u(1e3),Ki=new u(1e4);function D(n){return j.pow(c(n))}var ye=o("Sega_price"),y=class n extends s{constructor(e){let{baseToken:t,quoteToken:i,numerator:m,denominator:k}=e;super(m,k),this.baseToken=t,this.quoteToken=i,this.scalar=new s(D(t.decimals),D(i.decimals))}get raw(){return new s(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&&ye.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,i){return this.adjusted.toSignificant(e,t,i)}toFixed(e=this.quoteToken.decimals,t,i){return this.adjusted.toFixed(e,t,i)}};export{y as Price};
//# sourceMappingURL=price.mjs.map