@sega-so/sega-sdk
Version:
An SDK for building applications on top of SEGA.
2 lines • 14.1 kB
JavaScript
"use strict";var xe=Object.create;var C=Object.defineProperty,we=Object.defineProperties,Pe=Object.getOwnPropertyDescriptor,Se=Object.getOwnPropertyDescriptors,Ae=Object.getOwnPropertyNames,J=Object.getOwnPropertySymbols,ke=Object.getPrototypeOf,$=Object.prototype.hasOwnProperty,Ce=Object.prototype.propertyIsEnumerable;var X=(t,e,n)=>e in t?C(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,w=(t,e)=>{for(var n in e||(e={}))$.call(e,n)&&X(t,n,e[n]);if(J)for(var n of J(e))Ce.call(e,n)&&X(t,n,e[n]);return t},P=(t,e)=>we(t,Se(e));var Be=(t,e)=>{for(var n in e)C(t,n,{get:e[n],enumerable:!0})},Q=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Ae(e))!$.call(t,o)&&o!==n&&C(t,o,{get:()=>e[o],enumerable:!(r=Pe(e,o))||r.enumerable});return t};var c=(t,e,n)=>(n=t!=null?xe(ke(t)):{},Q(e||!t||!t.__esModule?C(n,"default",{value:t,enumerable:!0}):n,t)),Ie=t=>Q(C({},"__esModule",{value:!0}),t);var ct={};Be(ct,{add:()=>at,default:()=>a,div:()=>rt,eq:()=>Te,getMax:()=>st,gt:()=>he,gte:()=>nt,isMeaningfulNumber:()=>ot,lt:()=>et,lte:()=>tt,mul:()=>pe,sub:()=>it,toFractionWithDecimals:()=>Qe});module.exports=Ie(ct);var ge=c(require("big.js")),L=c(require("bn.js"));var p=c(require("bn.js")),Ve=c(require("decimal.js"));var ee=require("@solana/web3.js"),K=require("@solana/spl-token"),te={chainId:101,address:ee.PublicKey.default.toBase58(),programId:K.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"}},g={chainId:101,address:"So11111111111111111111111111111111111111112",programId:K.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 O=require("@solana/web3.js");var i=require("@solana/web3.js"),ne=require("@solana/spl-token");function v({pubkey:t,isSigner:e=!1,isWritable:n=!0}){return{pubkey:t,isWritable:n,isSigner:e}}var pt=[v({pubkey:ne.TOKEN_PROGRAM_ID,isWritable:!1}),v({pubkey:i.SystemProgram.programId,isWritable:!1}),v({pubkey:i.SYSVAR_RENT_PUBKEY,isWritable:!1})];function re({publicKey:t,transformSol:e}){let n=ie(t.toString());if(n instanceof i.PublicKey)return e&&n.equals(B)?q:n;if(e&&n.toString()===B.toBase58())return q;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 ie(t){try{return new i.PublicKey(t)}catch(e){return t}}var dt=new i.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),ft=new i.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),gt=new i.PublicKey("SysvarRent111111111111111111111111111111111"),ht=new i.PublicKey("SysvarC1ock11111111111111111111111111111111"),Re=new i.PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),Tt=new i.PublicKey("Sysvar1nstructions1111111111111111111111111"),bt=i.SystemProgram.programId,yt=new i.PublicKey("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),xt=new i.PublicKey("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),wt=new i.PublicKey("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),Pt=new i.PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),St=new i.PublicKey("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),At=new i.PublicKey("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),kt=new i.PublicKey("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),Ct=new i.PublicKey("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),Bt=new i.PublicKey("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),It=new i.PublicKey("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),Rt=new i.PublicKey("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),q=new i.PublicKey("So11111111111111111111111111111111111111112"),B=i.PublicKey.default;var E=class E{constructor({mint:e,decimals:n,symbol:r,name:o,skipMint:d=!1,isToken2022:x=!1}){if(e===B.toBase58()||e instanceof O.PublicKey&&B.equals(e)){this.decimals=g.decimals,this.symbol=g.symbol,this.name=g.name,this.mint=new O.PublicKey(g.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=d?O.PublicKey.default:re({publicKey:e}),this.isToken2022=x}equals(e){return this===e?!0:this.mint.equals(e.mint)}};E.WSOL=new E(P(w({},g),{mint:g.address}));var I=E;var F=class F{constructor({decimals:e,symbol:n="UNKNOWN",name:r="UNKNOWN"}){this.decimals=e,this.symbol=n,this.name=r}equals(e){return this===e}};F.SOL=new F(te);var U=F;var N=c(require("big.js")),ce=c(require("bn.js")),ue=c(require("decimal.js-light"));var R=require("lodash");var G=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}},oe={},Me={};function u(t){let e=(0,R.get)(oe,t);if(!e){let n=(0,R.get)(Me,t);e=new G({name:t,logLevel:n}),(0,R.set)(oe,t,e)}return e}var S=c(require("bn.js"));var se=9007199254740991;function l(t){let e=u("Sega_parseBigNumberish");if(t instanceof S.default)return t;if(typeof t=="string"){if(t.match(/^-?[0-9]+$/))return new S.default(t);e.logWithError(`invalid BigNumberish string: ${t}`)}return typeof t=="number"?(t%1&&e.logWithError(`BigNumberish number underflow: ${t}`),(t>=se||t<=-se)&&e.logWithError(`BigNumberish number overflow: ${t}`),new S.default(String(t))):typeof t=="bigint"?new S.default(t.toString()):(e.error(`invalid BigNumberish value: ${t}`),new S.default(0))}var ae=c(require("toformat")),Ne=ae.default,M=Ne;var _=u("module/fraction"),j=M(N.default),D=M(ue.default),Le={0:D.ROUND_DOWN,1:D.ROUND_HALF_UP,2:D.ROUND_UP},Oe={0:N.default.roundDown,1:N.default.roundHalfUp,2:N.default.roundUp},s=class t{constructor(e,n=new ce.default(1)){this.numerator=l(e),this.denominator=l(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(l(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(l(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(l(e));return new t(this.numerator.mul(n.numerator),this.denominator.mul(n.denominator))}div(e){let n=e instanceof t?e:new t(l(e));return new t(this.numerator.mul(n.denominator),this.denominator.mul(n.numerator))}toSignificant(e,n={groupSeparator:""},r=1){Number.isInteger(e)||_.logWithError(`${e} is not an integer.`),e<=0&&_.logWithError(`${e} is not positive.`),D.set({precision:e+1,rounding:Le[r]});let o=new D(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)||_.logWithError(`${e} is not an integer.`),e<0&&_.logWithError(`${e} is negative.`),j.DP=e,j.RM=Oe[r]||1,new j(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,n)}isZero(){return this.numerator.isZero()}};var me=c(require("bn.js"));var le=new s(new me.default(100)),h=class extends s{toSignificant(e=5,n,r){return this.mul(le).toSignificant(e,n,r)}toFixed(e=2,n,r){return this.mul(le).toFixed(e,n,r)}};var Ee=u("Sega_price"),T=class t extends s{constructor(e){let{baseToken:n,quoteToken:r,numerator:o,denominator:d}=e;super(o,d),this.baseToken=n,this.quoteToken=r,this.scalar=new s(H(n.decimals),H(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&&Ee.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)}};var Fe=require("@solana/web3.js"),_e=c(require("bn.js"));var y=new p.default(0),Tn=new p.default(1),bn=new p.default(2),yn=new p.default(3),xn=new p.default(5),Y=new p.default(10),wn=new p.default(100),Pn=new p.default(1e3),Sn=new p.default(1e4);function H(t){return Y.pow(l(t))}function z(t){var f;if(t===void 0)return{denominator:"1",numerator:"0"};if(t instanceof p.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=""]=(f=e.replace(",","").match(/(-?)(\d*)\.?(\d*)/))!=null?f:[],d="1"+"0".repeat(o.length),x=n+(r==="0"?"":r)+o||"0";return{denominator:d,numerator:x,sign:n,int:r,dec:o}}var We=require("@solana/web3.js");var W=require("@solana/spl-token");var Ln=u("Sega_accountInfo_util");var qe=require("@solana/web3.js"),Ue=require("@solana/spl-token");var A=require("@solana/web3.js");var ve=require("@solana/spl-token");var zn=u("Sega_txUtil");var m=require("@solana/web3.js"),tr=new m.PublicKey("SegazTQwbYWknDZkJ6j2Kgvm5gw3MrHGKtWstZdoNKZ"),nr=new m.PublicKey("Ajk8d9bERSaFdeoT1d8JUVfaDayrYLnAdgeB47TFMUaG"),rr=new m.PublicKey("2HbjxVVKJ7Ct72Rcd8WK4VTqmwTXL5aAggkH1CHGFGmh"),Ge=new m.PublicKey("TegaRdjn9Qeh9DfUU28X19aPPpJtj9gs8ntSYrR5H4K "),je=new m.PublicKey("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),He=new m.PublicKey("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),ir=new m.PublicKey("SegaXNnoXYTZiqUt9Xn2XqGcL56b25yzXLuJSpadcMu"),or=new m.PublicKey("2t1hV2YqnDCPuJZqr7Fy8oAygGwZE5Q9uaQzpLC1QryJ"),sr=new m.PublicKey("BLxynZeHE123MmQgNJZiV1pwW4VYh46oZYyC66xwmtTY");var Ye={SERUM_MARKET:m.PublicKey.default,UTIL1216:m.PublicKey.default,CREATE_CPMM_POOL_PROGRAM:Ge,CREATE_CPMM_POOL_AUTH:je,CREATE_CPMM_POOL_FEE_ACC:He};var ze=c(require("bn.js"));var de=require("@solana/web3.js");var k=require("@solana/web3.js"),Ze=c(require("axios"));var Je=require("@solana/web3.js");var Xe=u("Sega_amount"),fe=M(ge.default);function $e(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")):Xe.logWithError(`invalid number string, num: ${t}`)}else n=t;return[n,r.slice(0,e)||r]}var b=class t extends s{constructor(e,n,r=!0,o){let d=new L.default(0),x=Y.pow(new L.default(e.decimals));if(r)d=l(n);else{let f=new L.default(0),Z=new L.default(0);if(typeof n=="string"||typeof n=="number"||typeof n=="bigint"){let[be,ye]=$e(n.toString(),e.decimals);f=l(be),Z=l(ye)}f=f.mul(x),d=f.add(Z)}super(d,x),this.logger=u(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 fe.DP=this.token.decimals,new fe(this.numerator.toString()).div(this.denominator.toString()).toFormat(e)}};function a(t){if(t instanceof h)return new s(t.numerator,t.denominator);if(t instanceof T)return t.adjusted;if(t instanceof b)try{return a(t.toExact())}catch(r){return new s(y)}if(t instanceof s)return t;let e=String(t),n=z(e);return new s(n.numerator,n.denominator)}function Qe(t){var r;if(t instanceof h)return{fr:new s(t.numerator,t.denominator)};if(t instanceof T)return{fr:t.adjusted};if(t instanceof b)return{fr:a(t.toExact()),decimals:t.token.decimals};if(t instanceof s)return{fr:t};let e=String(t),n=z(e);return{fr:new s(n.numerator,n.denominator),decimals:(r=n.dec)==null?void 0:r.length}}function et(t,e){if(t==null||e==null)return!1;let n=a(t),r=a(e);return n.sub(r).numerator,n.sub(r).numerator.lt(y)}function he(t,e){if(t==null||e==null)return!1;let n=a(t),r=a(e);return n.sub(r).numerator.gt(y)}function tt(t,e){if(t==null||e==null)return!1;let n=a(t),r=a(e);return n.sub(r).numerator.lte(y)}function nt(t,e){if(t==null||e==null)return!1;let n=a(t),r=a(e);return n.sub(r).numerator.gte(y)}function Te(t,e){if(t==null||e==null)return!1;let n=a(t),r=a(e);return n.sub(r).numerator.eq(y)}function rt(t,e){if(t==null||e==null)return;let n=a(t),r=a(e);try{return n.div(r)}catch(o){return n}}function it(t,e){if(t==null||e==null)return;let n=a(t),r=a(e);return n.sub(r)}function ot(t){return t==null?!1:!Te(t,0)}function st(t,e){return he(e,t)?e:t}function pe(t,e){if(t==null||e==null)return;let n=a(t),r=a(e);return n.mul(r)}function at(t,e){if(t==null||e==null)return;let n=a(t),r=a(e);return n.add(r)}0&&(module.exports={add,div,eq,getMax,gt,gte,isMeaningfulNumber,lt,lte,mul,sub,toFractionWithDecimals});
//# sourceMappingURL=fractionUtil.js.map