@sega-so/sega-sdk
Version:
An SDK for building applications on top of SEGA.
2 lines • 13.2 kB
JavaScript
"use strict";var Te=Object.create;var C=Object.defineProperty,be=Object.defineProperties,ye=Object.getOwnPropertyDescriptor,xe=Object.getOwnPropertyDescriptors,we=Object.getOwnPropertyNames,D=Object.getOwnPropertySymbols,Pe=Object.getPrototypeOf,U=Object.prototype.hasOwnProperty,$=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,m=(t,e)=>{for(var n in e||(e={}))U.call(e,n)&&X(t,n,e[n]);if(D)for(var n of D(e))$.call(e,n)&&X(t,n,e[n]);return t},d=(t,e)=>be(t,xe(e));var E=(t,e)=>{var n={};for(var r in t)U.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&D)for(var r of D(t))e.indexOf(r)<0&&$.call(t,r)&&(n[r]=t[r]);return n};var Se=(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 we(e))!U.call(t,o)&&o!==n&&C(t,o,{get:()=>e[o],enumerable:!(r=ye(e,o))||r.enumerable});return t};var a=(t,e,n)=>(n=t!=null?Te(Pe(t)):{},Q(e||!t||!t.__esModule?C(n,"default",{value:t,enumerable:!0}):n,t)),ke=t=>Q(C({},"__esModule",{value:!0}),t);var y=(t,e,n)=>new Promise((r,o)=>{var s=p=>{try{T(n.next(p))}catch(A){o(A)}},w=p=>{try{T(n.throw(p))}catch(A){o(A)}},T=p=>p.done?r(p.value):Promise.resolve(p.value).then(s,w);T((n=n.apply(t,e)).next())});var rt={};Se(rt,{parseTokenInfo:()=>Ze,solToWSolToken:()=>Qe,toApiV3Token:()=>tt,toFeeConfig:()=>nt,toToken:()=>Xe,toTokenAmount:()=>$e,toTokenInfo:()=>Je,wSolToSolToken:()=>et});module.exports=ke(rt);var ge=require("@solana/web3.js"),O=require("@solana/spl-token");var fe=a(require("big.js")),L=a(require("bn.js"));var h=a(require("bn.js")),Oe=a(require("decimal.js"));var ee=require("@solana/web3.js"),G=require("@solana/spl-token"),I={chainId:101,address:ee.PublicKey.default.toBase58(),programId:G.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"}},f={chainId:101,address:"So11111111111111111111111111111111111111112",programId:G.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 V=require("@solana/web3.js");var i=require("@solana/web3.js"),te=require("@solana/spl-token");function j({pubkey:t,isSigner:e=!1,isWritable:n=!0}){return{pubkey:t,isWritable:n,isSigner:e}}var at=[j({pubkey:te.TOKEN_PROGRAM_ID,isWritable:!1}),j({pubkey:i.SystemProgram.programId,isWritable:!1}),j({pubkey:i.SYSVAR_RENT_PUBKEY,isWritable:!1})];function Y({publicKey:t,transformSol:e}){let n=ne(t.toString());if(n instanceof i.PublicKey)return e&&n.equals(B)?H:n;if(e&&n.toString()===B.toBase58())return H;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 ne(t){try{return new i.PublicKey(t)}catch(e){return t}}var ct=new i.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),ut=new i.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),lt=new i.PublicKey("SysvarRent111111111111111111111111111111111"),mt=new i.PublicKey("SysvarC1ock11111111111111111111111111111111"),Ae=new i.PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),pt=new i.PublicKey("Sysvar1nstructions1111111111111111111111111"),dt=i.SystemProgram.programId,ft=new i.PublicKey("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),gt=new i.PublicKey("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),ht=new i.PublicKey("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),Tt=new i.PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),bt=new i.PublicKey("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),yt=new i.PublicKey("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),xt=new i.PublicKey("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),wt=new i.PublicKey("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),Pt=new i.PublicKey("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),St=new i.PublicKey("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),kt=new i.PublicKey("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),H=new i.PublicKey("So11111111111111111111111111111111111111112"),B=i.PublicKey.default;function _(t){return Y({publicKey:t,transformSol:!0})}var W=class W{constructor({mint:e,decimals:n,symbol:r,name:o,skipMint:s=!1,isToken2022:w=!1}){if(e===B.toBase58()||e instanceof V.PublicKey&&B.equals(e)){this.decimals=f.decimals,this.symbol=f.symbol,this.name=f.name,this.mint=new V.PublicKey(f.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=s?V.PublicKey.default:Y({publicKey:e}),this.isToken2022=w}equals(e){return this===e?!0:this.mint.equals(e.mint)}};W.WSOL=new W(d(m({},f),{mint:f.address}));var b=W;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(I);var z=K;var N=a(require("big.js")),se=a(require("bn.js")),ae=a(require("decimal.js-light"));var R=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}},re={},Ce={};function c(t){let e=(0,R.get)(re,t);if(!e){let n=(0,R.get)(Ce,t);e=new Z({name:t,logLevel:n}),(0,R.set)(re,t,e)}return e}var P=a(require("bn.js"));var ie=9007199254740991;function u(t){let e=c("Sega_parseBigNumberish");if(t instanceof P.default)return t;if(typeof t=="string"){if(t.match(/^-?[0-9]+$/))return new P.default(t);e.logWithError(`invalid BigNumberish string: ${t}`)}return typeof t=="number"?(t%1&&e.logWithError(`BigNumberish number underflow: ${t}`),(t>=ie||t<=-ie)&&e.logWithError(`BigNumberish number overflow: ${t}`),new P.default(String(t))):typeof t=="bigint"?new P.default(t.toString()):(e.error(`invalid BigNumberish value: ${t}`),new P.default(0))}var oe=a(require("toformat")),Ie=oe.default,M=Ie;var v=c("module/fraction"),J=M(N.default),F=M(ae.default),Re={0:F.ROUND_DOWN,1:F.ROUND_HALF_UP,2:F.ROUND_UP},Me={0:N.default.roundDown,1:N.default.roundHalfUp,2:N.default.roundUp},g=class t{constructor(e,n=new se.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.`),F.set({precision:e+1,rounding:Re[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)||v.logWithError(`${e} is not an integer.`),e<0&&v.logWithError(`${e} is negative.`),J.DP=e,J.RM=Me[r]||1,new J(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,n)}isZero(){return this.numerator.isZero()}};var ce=a(require("bn.js"));var Gt=new g(new ce.default(100));var Jt=c("Sega_price");var Fe=require("@solana/web3.js"),Le=a(require("bn.js"));var Ne=new h.default(0),wn=new h.default(1),Pn=new h.default(2),Sn=new h.default(3),kn=new h.default(5),me=new h.default(10),An=new h.default(100),Cn=new h.default(1e3),In=new h.default(1e4);var De=require("@solana/web3.js");var q=require("@solana/spl-token");var En=c("Sega_accountInfo_util");var Ve=require("@solana/web3.js"),We=require("@solana/spl-token");var S=require("@solana/web3.js");var _e=require("@solana/spl-token");var Xn=c("Sega_txUtil");var l=require("@solana/web3.js"),ir=new l.PublicKey("SegazTQwbYWknDZkJ6j2Kgvm5gw3MrHGKtWstZdoNKZ"),or=new l.PublicKey("Ajk8d9bERSaFdeoT1d8JUVfaDayrYLnAdgeB47TFMUaG"),sr=new l.PublicKey("2HbjxVVKJ7Ct72Rcd8WK4VTqmwTXL5aAggkH1CHGFGmh"),Ke=new l.PublicKey("TegaRdjn9Qeh9DfUU28X19aPPpJtj9gs8ntSYrR5H4K "),ve=new l.PublicKey("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),qe=new l.PublicKey("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),ar=new l.PublicKey("SegaXNnoXYTZiqUt9Xn2XqGcL56b25yzXLuJSpadcMu"),cr=new l.PublicKey("2t1hV2YqnDCPuJZqr7Fy8oAygGwZE5Q9uaQzpLC1QryJ"),ur=new l.PublicKey("BLxynZeHE123MmQgNJZiV1pwW4VYh46oZYyC66xwmtTY");var Ue={SERUM_MARKET:l.PublicKey.default,UTIL1216:l.PublicKey.default,CREATE_CPMM_POOL_PROGRAM:Ke,CREATE_CPMM_POOL_AUTH:ve,CREATE_CPMM_POOL_FEE_ACC:qe};var Ge=a(require("bn.js"));var pe=require("@solana/web3.js");var k=require("@solana/web3.js"),je=a(require("axios"));var He=require("@solana/web3.js");var Ye=c("Sega_amount"),de=M(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")):Ye.logWithError(`invalid number string, num: ${t}`)}else n=t;return[n,r.slice(0,e)||r]}var x=class t extends g{constructor(e,n,r=!0,o){let s=new L.default(0),w=me.pow(new L.default(e.decimals));if(r)s=u(n);else{let T=new L.default(0),p=new L.default(0);if(typeof n=="string"||typeof n=="number"||typeof n=="bigint"){let[A,he]=ze(n.toString(),e.decimals);T=u(A),p=u(he)}T=T.mul(w),s=T.add(p)}super(s,w),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)}};var Ze=n=>y(void 0,[n],function*({connection:t,mint:e}){let r=yield t.getAccountInfo(new ge.PublicKey(e));return!r||r.data.length!==O.MintLayout.span?void 0:O.MintLayout.decode(r.data)}),Je=({mint:t,decimals:e,programId:n=O.TOKEN_PROGRAM_ID,logoURI:r="",priority:o=3})=>{let s=t.toBase58().substring(0,6);return{address:t.toBase58(),decimals:e,symbol:s,logoURI:r,extensions:{},chainId:101,programId:n.toString(),name:s,tags:[],priority:o}},Xe=t=>new b({mint:t.address,decimals:t.decimals,symbol:t.symbol,name:t.name}),$e=o=>{var s=o,{amount:t,isRaw:e,name:n}=s,r=E(s,["amount","isRaw","name"]);return new x(new b({mint:_(r.address).toBase58(),decimals:r.decimals,symbol:r.symbol,name:n}),t,e,n)};function Qe(t){return t.address===I.address?f:t}function et(t){return t.address===f.address?I:t}var tt=o=>{var s=o,{address:t,programId:e,decimals:n}=s,r=E(s,["address","programId","decimals"]);return m({chainId:101,address:_(t).toBase58(),programId:e,logoURI:"",symbol:"",name:"",decimals:n,tags:[],extensions:r.extensions||{}},r)},nt=t=>t?d(m({},t),{transferFeeConfigAuthority:t.transferFeeConfigAuthority.toBase58(),withdrawWithheldAuthority:t.withdrawWithheldAuthority.toBase58(),withheldAmount:t.withheldAmount.toString(),olderTransferFee:d(m({},t.olderTransferFee),{epoch:t.olderTransferFee.epoch.toString(),maximumFee:t.olderTransferFee.maximumFee.toString()}),newerTransferFee:d(m({},t.newerTransferFee),{epoch:t.newerTransferFee.epoch.toString(),maximumFee:t.newerTransferFee.maximumFee.toString()})}):void 0;0&&(module.exports={parseTokenInfo,solToWSolToken,toApiV3Token,toFeeConfig,toToken,toTokenAmount,toTokenInfo,wSolToSolToken});
//# sourceMappingURL=utils.js.map