@sega-so/sega-sdk
Version:
An SDK for building applications on top of SEGA.
2 lines • 16.4 kB
JavaScript
"use strict";var De=Object.create;var R=Object.defineProperty,Le=Object.defineProperties,Oe=Object.getOwnPropertyDescriptor,Ee=Object.getOwnPropertyDescriptors,Fe=Object.getOwnPropertyNames,ie=Object.getOwnPropertySymbols,_e=Object.getPrototypeOf,se=Object.prototype.hasOwnProperty,Ve=Object.prototype.propertyIsEnumerable;var ae=Math.pow,oe=(t,e,n)=>e in t?R(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,P=(t,e)=>{for(var n in e||(e={}))se.call(e,n)&&oe(t,n,e[n]);if(ie)for(var n of ie(e))Ve.call(e,n)&&oe(t,n,e[n]);return t},S=(t,e)=>Le(t,Ee(e));var We=(t,e)=>{for(var n in e)R(t,n,{get:e[n],enumerable:!0})},ce=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Fe(e))!se.call(t,o)&&o!==n&&R(t,o,{get:()=>e[o],enumerable:!(r=Oe(e,o))||r.enumerable});return t};var p=(t,e,n)=>(n=t!=null?De(_e(t)):{},ce(e||!t||!t.__esModule?R(n,"default",{value:t,enumerable:!0}):n,t)),Ke=t=>ce(R({},"__esModule",{value:!0}),t);var bt={};We(bt,{BN_100:()=>mt,BN_1000:()=>pt,BN_10000:()=>dt,BN_FIVE:()=>lt,BN_ONE:()=>at,BN_TEN:()=>x,BN_THREE:()=>ut,BN_TWO:()=>ct,BN_ZERO:()=>G,decimalToFraction:()=>Me,divCeil:()=>ft,isDecimal:()=>Ne,parseNumberInfo:()=>k,recursivelyDecimalToFraction:()=>ne,shakeFractionDecimal:()=>Ie,tenExponential:()=>q,toBN:()=>Re,toFraction:()=>re,toPercent:()=>gt,toTokenPrice:()=>ht,toTotalPrice:()=>Tt,toUsdCurrency:()=>te});module.exports=Ke(bt);var a=p(require("bn.js")),Be=p(require("decimal.js"));var ke=p(require("big.js")),T=p(require("bn.js"));var M=require("lodash");var Z=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}},ue={},ve={};function m(t){let e=(0,M.get)(ue,t);if(!e){let n=(0,M.get)(ve,t);e=new Z({name:t,logLevel:n}),(0,M.set)(ue,t,e)}return e}var qe=require("@solana/web3.js");var F=require("@solana/spl-token");var Ct=m("Sega_accountInfo_util");var C=p(require("bn.js"));var le=9007199254740991;function u(t){let e=m("Sega_parseBigNumberish");if(t instanceof C.default)return t;if(typeof t=="string"){if(t.match(/^-?[0-9]+$/))return new C.default(t);e.logWithError(`invalid BigNumberish string: ${t}`)}return typeof t=="number"?(t%1&&e.logWithError(`BigNumberish number underflow: ${t}`),(t>=le||t<=-le)&&e.logWithError(`BigNumberish number overflow: ${t}`),new C.default(String(t))):typeof t=="bigint"?new C.default(t.toString()):(e.error(`invalid BigNumberish value: ${t}`),new C.default(0))}var me=require("@solana/web3.js"),X=require("@solana/spl-token"),pe={chainId:101,address:me.PublicKey.default.toBase58(),programId:X.TOKEN_PROGRAM_ID.toBase58(),decimals:9,symbol:"SOL",name:"solana",logoURI:"https://img-v1.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"sega",extensions:{coingeckoId:"solana"}},A={chainId:101,address:"So11111111111111111111111111111111111111112",programId:X.TOKEN_PROGRAM_ID.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"}};var _=require("@solana/web3.js");var i=require("@solana/web3.js"),de=require("@solana/spl-token");function $({pubkey:t,isSigner:e=!1,isWritable:n=!0}){return{pubkey:t,isWritable:n,isSigner:e}}var Ft=[$({pubkey:de.TOKEN_PROGRAM_ID,isWritable:!1}),$({pubkey:i.SystemProgram.programId,isWritable:!1}),$({pubkey:i.SYSVAR_RENT_PUBKEY,isWritable:!1})];function fe({publicKey:t,transformSol:e}){let n=ge(t.toString());if(n instanceof i.PublicKey)return e&&n.equals(N)?J:n;if(e&&n.toString()===N.toBase58())return J;if(typeof n=="string"){if(n===i.PublicKey.default.toBase58())return i.PublicKey.default;try{return new i.PublicKey(n)}catch(r){throw new Error("invalid public key")}}throw new Error("invalid public key")}function ge(t){try{return new i.PublicKey(t)}catch(e){return t}}var _t=new i.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Vt=new i.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Wt=new i.PublicKey("SysvarRent111111111111111111111111111111111"),Kt=new i.PublicKey("SysvarC1ock11111111111111111111111111111111"),Ue=new i.PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),vt=new i.PublicKey("Sysvar1nstructions1111111111111111111111111"),qt=i.SystemProgram.programId,Ut=new i.PublicKey("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),Gt=new i.PublicKey("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),jt=new i.PublicKey("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),Ht=new i.PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),Yt=new i.PublicKey("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),zt=new i.PublicKey("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),Zt=new i.PublicKey("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),Jt=new i.PublicKey("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),Xt=new i.PublicKey("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),$t=new i.PublicKey("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),Qt=new i.PublicKey("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),J=new i.PublicKey("So11111111111111111111111111111111111111112"),N=i.PublicKey.default;var V=class V{constructor({mint:e,decimals:n,symbol:r,name:o,skipMint:c=!1,isToken2022:f=!1}){if(e===N.toBase58()||e instanceof _.PublicKey&&N.equals(e)){this.decimals=A.decimals,this.symbol=A.symbol,this.name=A.name,this.mint=new _.PublicKey(A.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=c?_.PublicKey.default:fe({publicKey:e}),this.isToken2022=f}equals(e){return this===e?!0:this.mint.equals(e.mint)}};V.WSOL=new V(S(P({},A),{mint:A.address}));var b=V;var K=class K{constructor({decimals:e,symbol:n="UNKNOWN",name:r="UNKNOWN"}){this.decimals=e,this.symbol=n,this.name=r}equals(e){return this===e}};K.SOL=new K(pe);var W=K;var he=p(require("toformat")),Ge=he.default,D=Ge;var L=p(require("big.js")),Te=p(require("bn.js")),be=p(require("decimal.js-light"));var v=m("module/fraction"),Q=D(L.default),O=D(be.default),He={0:O.ROUND_DOWN,1:O.ROUND_HALF_UP,2:O.ROUND_UP},Ye={0:L.default.roundDown,1:L.default.roundHalfUp,2:L.default.roundUp},s=class t{constructor(e,n=new Te.default(1)){this.numerator=u(e),this.denominator=u(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(u(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(u(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(u(e));return new t(this.numerator.mul(n.numerator),this.denominator.mul(n.denominator))}div(e){let n=e instanceof t?e:new t(u(e));return new t(this.numerator.mul(n.denominator),this.denominator.mul(n.numerator))}toSignificant(e,n={groupSeparator:""},r=1){Number.isInteger(e)||v.logWithError(`${e} is not an integer.`),e<=0&&v.logWithError(`${e} is not positive.`),O.set({precision:e+1,rounding:He[r]});let o=new O(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)||v.logWithError(`${e} is not an integer.`),e<0&&v.logWithError(`${e} is negative.`),Q.DP=e,Q.RM=Ye[r]||1,new Q(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,n)}isZero(){return this.numerator.isZero()}};var xe=p(require("bn.js"));var ye=new s(new xe.default(100)),g=class extends s{toSignificant(e=5,n,r){return this.mul(ye).toSignificant(e,n,r)}toFixed(e=2,n,r){return this.mul(ye).toFixed(e,n,r)}};var ze=m("Sega_price"),h=class t extends s{constructor(e){let{baseToken:n,quoteToken:r,numerator:o,denominator:c}=e;super(o,c),this.baseToken=n,this.quoteToken=r,this.scalar=new s(q(n.decimals),q(r.decimals))}get raw(){return new s(this.numerator,this.denominator)}get adjusted(){return super.mul(this.scalar)}invert(){return new t({baseToken:this.quoteToken,quoteToken:this.baseToken,denominator:this.numerator,numerator:this.denominator})}mul(e){this.quoteToken!==e.baseToken&&ze.logWithError("mul token not equals");let n=super.mul(e);return new t({baseToken:this.baseToken,quoteToken:e.quoteToken,denominator:n.denominator,numerator:n.numerator})}toSignificant(e=this.quoteToken.decimals,n,r){return this.adjusted.toSignificant(e,n,r)}toFixed(e=this.quoteToken.decimals,n,r){return this.adjusted.toFixed(e,n,r)}};function U(t){if(t instanceof g)return new s(t.numerator,t.denominator);if(t instanceof h)return t.adjusted;if(t instanceof y)try{return U(t.toExact())}catch(r){return new s(G)}if(t instanceof s)return t;let e=String(t),n=k(e);return new s(n.numerator,n.denominator)}function ee(t,e){if(t==null||e==null)return;let n=U(t),r=U(e);return n.mul(r)}var Xe=require("@solana/web3.js"),$e=require("@solana/spl-token");var B=require("@solana/web3.js");var Je=require("@solana/spl-token");var jn=m("Sega_txUtil");var d=require("@solana/web3.js"),$n=new d.PublicKey("SegazTQwbYWknDZkJ6j2Kgvm5gw3MrHGKtWstZdoNKZ"),Qn=new d.PublicKey("Ajk8d9bERSaFdeoT1d8JUVfaDayrYLnAdgeB47TFMUaG"),er=new d.PublicKey("2HbjxVVKJ7Ct72Rcd8WK4VTqmwTXL5aAggkH1CHGFGmh"),Qe=new d.PublicKey("TegaRdjn9Qeh9DfUU28X19aPPpJtj9gs8ntSYrR5H4K "),et=new d.PublicKey("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),tt=new d.PublicKey("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),tr=new d.PublicKey("SegaXNnoXYTZiqUt9Xn2XqGcL56b25yzXLuJSpadcMu"),nr=new d.PublicKey("2t1hV2YqnDCPuJZqr7Fy8oAygGwZE5Q9uaQzpLC1QryJ"),rr=new d.PublicKey("BLxynZeHE123MmQgNJZiV1pwW4VYh46oZYyC66xwmtTY");var nt={SERUM_MARKET:d.PublicKey.default,UTIL1216:d.PublicKey.default,CREATE_CPMM_POOL_PROGRAM:Qe,CREATE_CPMM_POOL_AUTH:et,CREATE_CPMM_POOL_FEE_ACC:tt};var rt=p(require("bn.js"));var we=require("@solana/web3.js");var I=require("@solana/web3.js"),it=p(require("axios"));var Pe=require("@solana/web3.js"),Se=p(require("bn.js"));function Ae(t){return typeof t=="object"&&t!==null&&![b,y,Pe.PublicKey,s,Se.default,h,g].some(e=>typeof e=="object"&&t instanceof e)}var ot=require("@solana/web3.js");var st=m("Sega_amount"),j=D(ke.default);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")):st.logWithError(`invalid number string, num: ${t}`)}else n=t;return[n,r.slice(0,e)||r]}var y=class t extends s{constructor(e,n,r=!0,o){let c=new T.default(0),f=x.pow(new T.default(e.decimals));if(r)c=u(n);else{let l=new T.default(0),w=new T.default(0);if(typeof n=="string"||typeof n=="number"||typeof n=="bigint"){let[Y,z]=Ce(n.toString(),e.decimals);l=u(Y),w=u(z)}l=l.mul(f),c=l.add(w)}super(c,f),this.logger=m(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 j.DP=this.token.decimals,new j(this.numerator.toString()).div(this.denominator.toString()).toFormat(e)}},H=class t extends s{constructor(e,n,r=!0,o){let c=new T.default(0),f=x.pow(new T.default(e.decimals));if(r)c=u(n);else{let l=new T.default(0),w=new T.default(0);if(typeof n=="string"||typeof n=="number"||typeof n=="bigint"){let[Y,z]=Ce(n.toString(),e.decimals);l=u(Y),w=u(z)}l=l.mul(f),c=l.add(w)}super(c,f),this.logger=m(o||"TokenAmount"),this.currency=e}get raw(){return this.numerator}isZero(){return this.raw.isZero()}gt(e){return this.currency.equals(e.currency)||this.logger.logWithError("gt currency not equals"),this.raw.gt(e.raw)}lt(e){return this.currency.equals(e.currency)||this.logger.logWithError("lt currency not equals"),this.raw.lt(e.raw)}add(e){return this.currency.equals(e.currency)||this.logger.logWithError("add currency not equals"),new t(this.currency,this.raw.add(e.raw))}sub(e){return this.currency.equals(e.currency)||this.logger.logWithError("sub currency not equals"),new t(this.currency,this.raw.sub(e.raw))}toSignificant(e=this.currency.decimals,n,r=0){return super.toSignificant(e,n,r)}toFixed(e=this.currency.decimals,n,r=0){return e>this.currency.decimals&&this.logger.logWithError("decimals overflow"),super.toFixed(e,n,r)}toExact(e={groupSeparator:""}){return j.DP=this.currency.decimals,new j(this.numerator.toString()).div(this.denominator.toString()).toFormat(e)}};var G=new a.default(0),at=new a.default(1),ct=new a.default(2),ut=new a.default(3),lt=new a.default(5),x=new a.default(10),mt=new a.default(100),pt=new a.default(1e3),dt=new a.default(1e4);function q(t){return x.pow(u(t))}function k(t){var l;if(t===void 0)return{denominator:"1",numerator:"0"};if(t instanceof a.default)return{numerator:t.toString(),denominator:"1"};if(t instanceof s)return{denominator:t.denominator.toString(),numerator:t.numerator.toString()};let e=String(t),[,n="",r="",o=""]=(l=e.replace(",","").match(/(-?)(\d*)\.?(\d*)/))!=null?l:[],c="1"+"0".repeat(o.length),f=n+(r==="0"?"":r)+o||"0";return{denominator:c,numerator:f,sign:n,int:r,dec:o}}function ft(t,e){let n=t.divmod(e);return n.mod.isZero()?n.div:n.div.isNeg()?n.div.isubn(1):n.div.iaddn(1)}function Ie(t){var r;let[,e="",n=""]=(r=t.toFixed(2).match(/(-?)(\d*)\.?(\d*)/))!=null?r:[];return`${e}${n}`}function Re(t,e=0){return t instanceof a.default?t:new a.default(Ie(re(t).mul(x.pow(new a.default(String(e))))))}function re(t){if(t instanceof g)return new s(t.numerator,t.denominator);if(t instanceof h)return t.adjusted;if(t instanceof y)try{return re(t.toExact())}catch(r){return new s(G)}if(t instanceof s)return t;let e=String(t),n=k(e);return new s(n.numerator,n.denominator)}function gt(t,e){let{numerator:n,denominator:r}=k(t);return new g(new a.default(n),new a.default(r).mul(e!=null&&e.alreadyDecimaled?new a.default(100):new a.default(1)))}function ht(t){let{token:e,numberPrice:n,decimalDone:r}=t,o=new b({mint:"",decimals:6,symbol:"usd",name:"usd",skipMint:!0}),{numerator:c,denominator:f}=k(n),l=r?new a.default(c).mul(x.pow(new a.default(e.decimals))):c,w=new a.default(f).mul(x.pow(new a.default(o.decimals)));return new h({baseToken:o,denominator:w.toString(),quoteToken:new b(S(P({},e),{skipMint:!0,mint:""})),numerator:l.toString()})}function te(t){let e=new W({decimals:6,symbol:"usd",name:"usd"}),n=Re(ee(t,ae(10,e.decimals)));return new H(e,n)}function Tt(t,e){return te(!e||!t?0:ee(t,e))}function Me(t){if(t==null)return;let{numerator:e,denominator:n}=k(t.toString());return new s(e,n)}function Ne(t){return t instanceof Be.default}function ne(t){return Ne(t)?Me(t):Array.isArray(t)?t.map(e=>ne(e)):Ae(t)?Object.fromEntries(Object.entries(t).map(([e,n])=>[e,ne(n)])):t}0&&(module.exports={BN_100,BN_1000,BN_10000,BN_FIVE,BN_ONE,BN_TEN,BN_THREE,BN_TWO,BN_ZERO,decimalToFraction,divCeil,isDecimal,parseNumberInfo,recursivelyDecimalToFraction,shakeFractionDecimal,tenExponential,toBN,toFraction,toPercent,toTokenPrice,toTotalPrice,toUsdCurrency});
//# sourceMappingURL=bignumber.js.map