UNPKG

@sega-so/sega-sdk

Version:

An SDK for building applications on top of SEGA.

2 lines 9.47 kB
var z=Object.defineProperty,Y=Object.defineProperties;var J=Object.getOwnPropertyDescriptors;var F=Object.getOwnPropertySymbols;var Z=Object.prototype.hasOwnProperty,X=Object.prototype.propertyIsEnumerable;var L=(n,e,t)=>e in n?z(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,p=(n,e)=>{for(var t in e||(e={}))Z.call(e,t)&&L(n,t,e[t]);if(F)for(var t of F(e))X.call(e,t)&&L(n,t,e[t]);return n},d=(n,e)=>Y(n,J(e));import c from"bn.js";import Ti from"decimal.js";import Te from"big.js";import Qr from"bn.js";import{get as E,set as $}from"lodash";var B=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}},O={},Q={};function o(n){let e=E(O,n);if(!e){let t=E(Q,n);e=new B({name:n,logLevel:t}),$(O,n,e)}return e}import{PublicKey as Be}from"@solana/web3.js";import{MINT_SIZE as Re,TOKEN_PROGRAM_ID as De,getTransferFeeConfig as Me,unpackMint as Fe}from"@solana/spl-token";var Le=o("Sega_accountInfo_util");import f from"bn.js";var V=9007199254740991;function a(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>=V||n<=-V)&&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 W}from"@solana/spl-token";var K={chainId:101,address:ee.default.toBase58(),programId:W.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:W.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 N}from"@solana/web3.js";import{PublicKey as r,SystemProgram as v,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:v.programId,isWritable:!1}),I({pubkey:te,isWritable:!1})];function _({publicKey:n,transformSol:e}){let t=q(n.toString());if(t instanceof r)return e&&t.equals(g)?C:t;if(e&&t.toString()===g.toBase58())return C;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 Ze=new r("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Xe=new r("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),$e=new r("SysvarRent111111111111111111111111111111111"),Qe=new r("SysvarC1ock11111111111111111111111111111111"),re=new r("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),et=new r("Sysvar1nstructions1111111111111111111111111"),tt=v.programId,nt=new r("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),rt=new r("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),it=new r("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),ot=new r("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),st=new r("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),at=new r("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),ct=new r("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),ut=new r("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),lt=new r("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),mt=new r("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),pt=new r("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),C=new r("So11111111111111111111111111111111111111112"),g=r.default;var w=class w{constructor({mint:e,decimals:t,symbol:i,name:m,skipMint:A=!1,isToken2022:H=!1}){if(e===g.toBase58()||e instanceof N&&g.equals(e)){this.decimals=l.decimals,this.symbol=l.symbol,this.name=l.name,this.mint=new N(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=A?N.default:_({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(K);var R=P;import ie from"toformat";var oe=ie,T=oe;import k from"big.js";import ae from"bn.js";import ce from"decimal.js-light";var S=o("module/fraction"),D=T(k),b=T(ce),ue={0:b.ROUND_DOWN,1:b.ROUND_HALF_UP,2:b.ROUND_UP},le={0:k.roundDown,1:k.roundHalfUp,2:k.roundUp},s=class n{constructor(e,t=new ae(1)){this.numerator=a(e),this.denominator=a(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(a(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(a(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(a(e));return new n(this.numerator.mul(t.numerator),this.denominator.mul(t.denominator))}div(e){let t=e instanceof n?e:new n(a(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.`),D.DP=e,D.RM=le[i]||1,new D(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,t)}isZero(){return this.numerator.isZero()}};import me from"bn.js";var Et=new s(new me(100));import{PublicKey as wn}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Sn}from"@solana/spl-token";import{ComputeBudgetProgram as tn,Keypair as on,PublicKey as sn,Transaction as cn,TransactionMessage as ln,VersionedTransaction as mn}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as gn}from"@solana/spl-token";var hn=o("Sega_txUtil");import{PublicKey as u}from"@solana/web3.js";var In=new u("SegazTQwbYWknDZkJ6j2Kgvm5gw3MrHGKtWstZdoNKZ"),Nn=new u("Ajk8d9bERSaFdeoT1d8JUVfaDayrYLnAdgeB47TFMUaG"),Rn=new u("2HbjxVVKJ7Ct72Rcd8WK4VTqmwTXL5aAggkH1CHGFGmh"),fe=new u("auetiVUVJkRxvNPLYEvVnz8UJSqQ1VgoA83PcicHVD1"),ge=new u("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),he=new u("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y");var Dn={SERUM_MARKET:u.default,UTIL1216:u.default,CREATE_CPMM_POOL_PROGRAM:fe,CREATE_CPMM_POOL_AUTH:ge,CREATE_CPMM_POOL_FEE_ACC:he};import Ln from"bn.js";import{PublicKey as vn,AddressLookupTableAccount as _n}from"@solana/web3.js";import{PublicKey as ir,sendAndConfirmTransaction as or,SystemProgram as cr,Transaction as ur,TransactionMessage as mr,VersionedTransaction as pr}from"@solana/web3.js";import fr from"axios";import{PublicKey as Pr}from"@solana/web3.js";import kr from"bn.js";import{Connection as Rr}from"@solana/web3.js";var ci=o("Sega_amount"),ui=T(Te);var pe=new c(0),Ci=new c(1),Ii=new c(2),Ni=new c(3),Ri=new c(5),j=new c(10),Di=new c(100),Mi=new c(1e3),Fi=new c(1e4);function M(n){return j.pow(a(n))}var be=o("Sega_price"),y=class n extends s{constructor(e){let{baseToken:t,quoteToken:i,numerator:m,denominator:A}=e;super(m,A),this.baseToken=t,this.quoteToken=i,this.scalar=new s(M(t.decimals),M(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&&be.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