UNPKG

@sega-so/sega-sdk

Version:

An SDK for building applications on top of SEGA.

2 lines 12.4 kB
"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,ke=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))ke.call(e,n)&&$(t,n,e[n]);return t},b=(t,e)=>ye(t,we(e));var Ae=(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)),Be=t=>ee(I({},"__esModule",{value:!0}),t);var y=(t,e,n)=>new Promise((r,o)=>{var p=l=>{try{f(n.next(l))}catch(C){o(C)}},h=l=>{try{f(n.throw(l))}catch(C){o(C)}},f=l=>l.done?r(l.value):Promise.resolve(l.value).then(p,h);f((n=n.apply(t,e)).next())});var Xe={};Ae(Xe,{getTimestamp:()=>Ze,jsonInfo2PoolKeys:()=>Z,notInnerObject:()=>J,sleep:()=>Je});module.exports=Be(Xe);var ge=require("@solana/web3.js"),he=a(require("bn.js"));var fe=a(require("big.js")),L=a(require("bn.js"));var m=a(require("bn.js")),Ee=a(require("decimal.js"));var te=require("@solana/web3.js"),v=require("@solana/spl-token"),ne={chainId:101,address:te.PublicKey.default.toBase58(),programId:v.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:v.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 _({pubkey:t,isSigner:e=!1,isWritable:n=!0}){return{pubkey:t,isWritable:n,isSigner:e}}var tt=[_({pubkey:re.TOKEN_PROGRAM_ID,isWritable:!1}),_({pubkey:i.SystemProgram.programId,isWritable:!1}),_({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(N)?q:n;if(e&&n.toString()===N.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 nt=new i.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),rt=new i.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),it=new i.PublicKey("SysvarRent111111111111111111111111111111111"),ot=new i.PublicKey("SysvarC1ock11111111111111111111111111111111"),Ce=new i.PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),st=new i.PublicKey("Sysvar1nstructions1111111111111111111111111"),at=i.SystemProgram.programId,ct=new i.PublicKey("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),ut=new i.PublicKey("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),lt=new i.PublicKey("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),mt=new i.PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),pt=new i.PublicKey("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),dt=new i.PublicKey("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),ft=new i.PublicKey("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),gt=new i.PublicKey("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),ht=new i.PublicKey("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),Tt=new i.PublicKey("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),bt=new i.PublicKey("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),q=new i.PublicKey("So11111111111111111111111111111111111111112"),N=i.PublicKey.default;var O=class O{constructor({mint:e,decimals:n,symbol:r,name:o,skipMint:p=!1,isToken2022:h=!1}){if(e===N.toBase58()||e instanceof E.PublicKey&&N.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=p?E.PublicKey.default:ie({publicKey:e}),this.isToken2022=h}equals(e){return this===e?!0:this.mint.equals(e.mint)}};O.WSOL=new O(b(T({},g),{mint:g.address}));var x=O;var V=class V{constructor({decimals:e,symbol:n="UNKNOWN",name:r="UNKNOWN"}){this.decimals=e,this.symbol=n,this.name=r}equals(e){return this===e}};V.SOL=new V(ne);var G=V;var M=a(require("big.js")),ce=a(require("bn.js")),ue=a(require("decimal.js-light"));var R=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,R.get)(oe,t);if(!e){let n=(0,R.get)(Ie,t);e=new j({name:t,logLevel:n}),(0,R.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")),Ne=ae.default,D=Ne;var W=c("module/fraction"),H=D(M.default),F=D(ue.default),De={0:F.ROUND_DOWN,1:F.ROUND_HALF_UP,2:F.ROUND_UP},Me={0:M.default.roundDown,1:M.default.roundHalfUp,2:M.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)||W.logWithError(`${e} is not an integer.`),e<=0&&W.logWithError(`${e} is not positive.`),F.set({precision:e+1,rounding:De[r]});let o=new F(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)||W.logWithError(`${e} is not an integer.`),e<0&&W.logWithError(`${e} is negative.`),H.DP=e,H.RM=Me[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 Fe=c("Sega_price"),S=class t extends s{constructor(e){let{baseToken:n,quoteToken:r,numerator:o,denominator:p}=e;super(o,p),this.baseToken=n,this.quoteToken=r,this.scalar=new s(z(n.decimals),z(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&&Fe.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 Le=new m.default(0),an=new m.default(1),cn=new m.default(2),un=new m.default(3),ln=new m.default(5),Y=new m.default(10),mn=new m.default(100),pn=new m.default(1e3),dn=new m.default(1e4);function z(t){return Y.pow(u(t))}var Oe=require("@solana/web3.js");var K=require("@solana/spl-token");var Sn=c("Sega_accountInfo_util");var Ke=require("@solana/web3.js"),ve=require("@solana/spl-token");var A=require("@solana/web3.js");var We=require("@solana/spl-token");var Wn=c("Sega_txUtil");var d=require("@solana/web3.js"),jn=new d.PublicKey("SegazTQwbYWknDZkJ6j2Kgvm5gw3MrHGKtWstZdoNKZ"),Hn=new d.PublicKey("Ajk8d9bERSaFdeoT1d8JUVfaDayrYLnAdgeB47TFMUaG"),zn=new d.PublicKey("2HbjxVVKJ7Ct72Rcd8WK4VTqmwTXL5aAggkH1CHGFGmh"),_e=new d.PublicKey("auetiVUVJkRxvNPLYEvVnz8UJSqQ1VgoA83PcicHVD1"),qe=new d.PublicKey("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),Ue=new d.PublicKey("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y");var Yn={SERUM_MARKET:d.PublicKey.default,UTIL1216:d.PublicKey.default,CREATE_CPMM_POOL_PROGRAM:_e,CREATE_CPMM_POOL_AUTH:qe,CREATE_CPMM_POOL_FEE_ACC:Ue};var Ge=a(require("bn.js"));var pe=require("@solana/web3.js");var B=require("@solana/web3.js"),je=a(require("axios"));var He=require("@solana/web3.js");var ze=c("Sega_amount"),de=D(fe.default);function Ye(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 k=class t extends s{constructor(e,n,r=!0,o){let p=new L.default(0),h=Y.pow(new L.default(e.decimals));if(r)p=u(n);else{let f=new L.default(0),l=new L.default(0);if(typeof n=="string"||typeof n=="number"||typeof n=="bigint"){let[C,Te]=Ye(n.toString(),e.decimals);f=u(C),l=u(Te)}f=f.mul(h),p=f.add(l)}super(p,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 Ze(){return new Date().getTime()}function J(t){return typeof t=="object"&&t!==null&&![x,k,ge.PublicKey,s,he.default,S,P].some(e=>typeof e=="object"&&t instanceof e)}function Z(t){return typeof t=="string"?U(t):Array.isArray(t)?t.map(e=>Z(e)):J(t)?Object.fromEntries(Object.entries(t).map(([e,n])=>[e,Z(n)])):t}0&&(module.exports={getTimestamp,jsonInfo2PoolKeys,notInnerObject,sleep}); //# sourceMappingURL=utility.js.map