@sega-so/sega-sdk
Version:
An SDK for building applications on top of SEGA.
2 lines • 12.6 kB
JavaScript
"use strict";var be=Object.create;var I=Object.defineProperty,ye=Object.defineProperties,xe=Object.getOwnPropertyDescriptor,we=Object.getOwnPropertyDescriptors,Pe=Object.getOwnPropertyNames,X=Object.getOwnPropertySymbols,Se=Object.getPrototypeOf,Q=Object.prototype.hasOwnProperty,Ae=Object.prototype.propertyIsEnumerable;var $=(t,e,n)=>e in t?I(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,T=(t,e)=>{for(var n in e||(e={}))Q.call(e,n)&&$(t,n,e[n]);if(X)for(var n of X(e))Ae.call(e,n)&&$(t,n,e[n]);return t},b=(t,e)=>ye(t,we(e));var ke=(t,e)=>{for(var n in e)I(t,n,{get:e[n],enumerable:!0})},ee=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Pe(e))!Q.call(t,o)&&o!==n&&I(t,o,{get:()=>e[o],enumerable:!(r=xe(e,o))||r.enumerable});return t};var a=(t,e,n)=>(n=t!=null?be(Se(t)):{},ee(e||!t||!t.__esModule?I(n,"default",{value:t,enumerable:!0}):n,t)),Ce=t=>ee(I({},"__esModule",{value:!0}),t);var y=(t,e,n)=>new Promise((r,o)=>{var d=m=>{try{f(n.next(m))}catch(B){o(B)}},h=m=>{try{f(n.throw(m))}catch(B){o(B)}},f=m=>m.done?r(m.value):Promise.resolve(m.value).then(d,h);f((n=n.apply(t,e)).next())});var $e={};ke($e,{getTimestamp:()=>Xe,jsonInfo2PoolKeys:()=>J,notInnerObject:()=>Z,sleep:()=>Je});module.exports=Ce($e);var ge=require("@solana/web3.js"),he=a(require("bn.js"));var fe=a(require("big.js")),O=a(require("bn.js"));var p=a(require("bn.js")),Ee=a(require("decimal.js"));var te=require("@solana/web3.js"),K=require("@solana/spl-token"),ne={chainId:101,address:te.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 E=require("@solana/web3.js");var i=require("@solana/web3.js"),re=require("@solana/spl-token");function v({pubkey:t,isSigner:e=!1,isWritable:n=!0}){return{pubkey:t,isWritable:n,isSigner:e}}var nt=[v({pubkey:re.TOKEN_PROGRAM_ID,isWritable:!1}),v({pubkey:i.SystemProgram.programId,isWritable:!1}),v({pubkey:i.SYSVAR_RENT_PUBKEY,isWritable:!1})];function ie({publicKey:t,transformSol:e}){let n=U(t.toString());if(n instanceof i.PublicKey)return e&&n.equals(R)?q:n;if(e&&n.toString()===R.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 U(t){try{return new i.PublicKey(t)}catch(e){return t}}var rt=new i.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),it=new i.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),ot=new i.PublicKey("SysvarRent111111111111111111111111111111111"),st=new i.PublicKey("SysvarC1ock11111111111111111111111111111111"),Be=new i.PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),at=new i.PublicKey("Sysvar1nstructions1111111111111111111111111"),ct=i.SystemProgram.programId,ut=new i.PublicKey("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),lt=new i.PublicKey("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),mt=new i.PublicKey("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),pt=new i.PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),dt=new i.PublicKey("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),ft=new i.PublicKey("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),gt=new i.PublicKey("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),ht=new i.PublicKey("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),Tt=new i.PublicKey("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),bt=new i.PublicKey("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),yt=new i.PublicKey("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),q=new i.PublicKey("So11111111111111111111111111111111111111112"),R=i.PublicKey.default;var F=class F{constructor({mint:e,decimals:n,symbol:r,name:o,skipMint:d=!1,isToken2022:h=!1}){if(e===R.toBase58()||e instanceof E.PublicKey&&R.equals(e)){this.decimals=g.decimals,this.symbol=g.symbol,this.name=g.name,this.mint=new E.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?E.PublicKey.default:ie({publicKey:e}),this.isToken2022=h}equals(e){return this===e?!0:this.mint.equals(e.mint)}};F.WSOL=new F(b(T({},g),{mint:g.address}));var x=F;var _=class _{constructor({decimals:e,symbol:n="UNKNOWN",name:r="UNKNOWN"}){this.decimals=e,this.symbol=n,this.name=r}equals(e){return this===e}};_.SOL=new _(ne);var G=_;var D=a(require("big.js")),ce=a(require("bn.js")),ue=a(require("decimal.js-light"));var M=require("lodash");var j=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={},Ie={};function c(t){let e=(0,M.get)(oe,t);if(!e){let n=(0,M.get)(Ie,t);e=new j({name:t,logLevel:n}),(0,M.set)(oe,t,e)}return e}var w=a(require("bn.js"));var se=9007199254740991;function u(t){let e=c("Sega_parseBigNumberish");if(t instanceof w.default)return t;if(typeof t=="string"){if(t.match(/^-?[0-9]+$/))return new w.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 w.default(String(t))):typeof t=="bigint"?new w.default(t.toString()):(e.error(`invalid BigNumberish value: ${t}`),new w.default(0))}var ae=a(require("toformat")),Re=ae.default,N=Re;var V=c("module/fraction"),H=N(D.default),L=N(ue.default),Ne={0:L.ROUND_DOWN,1:L.ROUND_HALF_UP,2:L.ROUND_UP},De={0:D.default.roundDown,1:D.default.roundHalfUp,2:D.default.roundUp},s=class t{constructor(e,n=new ce.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.`),L.set({precision:e+1,rounding:Ne[r]});let o=new L(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.`),H.DP=e,H.RM=De[r]||1,new H(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,n)}isZero(){return this.numerator.isZero()}};var me=a(require("bn.js"));var le=new s(new me.default(100)),P=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 Le=c("Sega_price"),S=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(Y(n.decimals),Y(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&&Le.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 Oe=new p.default(0),cn=new p.default(1),un=new p.default(2),ln=new p.default(3),mn=new p.default(5),z=new p.default(10),pn=new p.default(100),dn=new p.default(1e3),fn=new p.default(1e4);function Y(t){return z.pow(u(t))}var Fe=require("@solana/web3.js");var W=require("@solana/spl-token");var An=c("Sega_accountInfo_util");var We=require("@solana/web3.js"),Ke=require("@solana/spl-token");var k=require("@solana/web3.js");var Ve=require("@solana/spl-token");var Wn=c("Sega_txUtil");var l=require("@solana/web3.js"),Hn=new l.PublicKey("SegazTQwbYWknDZkJ6j2Kgvm5gw3MrHGKtWstZdoNKZ"),Yn=new l.PublicKey("Ajk8d9bERSaFdeoT1d8JUVfaDayrYLnAdgeB47TFMUaG"),zn=new l.PublicKey("2HbjxVVKJ7Ct72Rcd8WK4VTqmwTXL5aAggkH1CHGFGmh"),ve=new l.PublicKey("TegaRdjn9Qeh9DfUU28X19aPPpJtj9gs8ntSYrR5H4K "),qe=new l.PublicKey("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),Ue=new l.PublicKey("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),Zn=new l.PublicKey("SegaXNnoXYTZiqUt9Xn2XqGcL56b25yzXLuJSpadcMu"),Jn=new l.PublicKey("2t1hV2YqnDCPuJZqr7Fy8oAygGwZE5Q9uaQzpLC1QryJ"),Xn=new l.PublicKey("BLxynZeHE123MmQgNJZiV1pwW4VYh46oZYyC66xwmtTY");var Ge={SERUM_MARKET:l.PublicKey.default,UTIL1216:l.PublicKey.default,CREATE_CPMM_POOL_PROGRAM:ve,CREATE_CPMM_POOL_AUTH:qe,CREATE_CPMM_POOL_FEE_ACC:Ue};var je=a(require("bn.js"));var pe=require("@solana/web3.js");var C=require("@solana/web3.js"),He=a(require("axios"));var Ye=require("@solana/web3.js");var ze=c("Sega_amount"),de=N(fe.default);function Ze(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")):ze.logWithError(`invalid number string, num: ${t}`)}else n=t;return[n,r.slice(0,e)||r]}var A=class t extends s{constructor(e,n,r=!0,o){let d=new O.default(0),h=z.pow(new O.default(e.decimals));if(r)d=u(n);else{let f=new O.default(0),m=new O.default(0);if(typeof n=="string"||typeof n=="number"||typeof n=="bigint"){let[B,Te]=Ze(n.toString(),e.decimals);f=u(B),m=u(Te)}f=f.mul(h),d=f.add(m)}super(d,h),this.logger=c(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 de.DP=this.token.decimals,new de(this.numerator.toString()).div(this.denominator.toString()).toFormat(e)}};function Je(t){return y(this,null,function*(){new Promise(e=>setTimeout(e,t))})}function Xe(){return new Date().getTime()}function Z(t){return typeof t=="object"&&t!==null&&![x,A,ge.PublicKey,s,he.default,S,P].some(e=>typeof e=="object"&&t instanceof e)}function J(t){return typeof t=="string"?U(t):Array.isArray(t)?t.map(e=>J(e)):Z(t)?Object.fromEntries(Object.entries(t).map(([e,n])=>[e,J(n)])):t}0&&(module.exports={getTimestamp,jsonInfo2PoolKeys,notInnerObject,sleep});
//# sourceMappingURL=utility.js.map