UNPKG

@sega-so/sega-sdk

Version:

An SDK for building applications on top of SEGA.

2 lines 14.3 kB
"use strict";var Re=Object.create;var C=Object.defineProperty,Fe=Object.defineProperties,Me=Object.getOwnPropertyDescriptor,_e=Object.getOwnPropertyDescriptors,Ee=Object.getOwnPropertyNames,E=Object.getOwnPropertySymbols,Oe=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty,ce=Object.prototype.propertyIsEnumerable;var ue=(t,e,n)=>e in t?C(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,l=(t,e)=>{for(var n in e||(e={}))j.call(e,n)&&ue(t,n,e[n]);if(E)for(var n of E(e))ce.call(e,n)&&ue(t,n,e[n]);return t},f=(t,e)=>Fe(t,_e(e));var O=(t,e)=>{var n={};for(var r in t)j.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&E)for(var r of E(t))e.indexOf(r)<0&&ce.call(t,r)&&(n[r]=t[r]);return n};var Ve=(t,e)=>{for(var n in e)C(t,n,{get:e[n],enumerable:!0})},le=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Ee(e))!j.call(t,s)&&s!==n&&C(t,s,{get:()=>e[s],enumerable:!(r=Me(e,s))||r.enumerable});return t};var u=(t,e,n)=>(n=t!=null?Re(Oe(t)):{},le(e||!t||!t.__esModule?C(n,"default",{value:t,enumerable:!0}):n,t)),Ke=t=>le(C({},"__esModule",{value:!0}),t);var x=(t,e,n)=>new Promise((r,s)=>{var a=d=>{try{b(n.next(d))}catch(L){s(L)}},w=d=>{try{b(n.throw(d))}catch(L){s(L)}},b=d=>d.done?r(d.value):Promise.resolve(d.value).then(a,w);b((n=n.apply(t,e)).next())});var bt={};Ve(bt,{SOL_INFO:()=>S,SPL_MINT_LAYOUT:()=>We,TOKEN_WSOL:()=>p,parseTokenInfo:()=>lt,solToWSolToken:()=>ft,toApiV3Token:()=>ht,toFeeConfig:()=>yt,toToken:()=>pt,toTokenAmount:()=>dt,toTokenInfo:()=>mt,wSolToSolToken:()=>gt});module.exports=Ke(bt);var me=require("@solana/web3.js"),z=require("@solana/spl-token"),S={chainId:101,address:me.PublicKey.default.toBase58(),programId:z.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"}},p={chainId:101,address:"So11111111111111111111111111111111111111112",programId:z.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 de=require("@solana/web3.js"),V=u(require("bn.js"));var o=require("@solana/buffer-layout"),H=o.Layout,pe=o.Structure;var Y=o.UInt;var J=o.blob;var Z=class extends H{constructor(e,n,r){super(e,r),this.blob=J(e),this.signed=n}decode(e,n=0){let r=new V.default(this.blob.decode(e,n),10,"le");return this.signed?r.fromTwos(this.span*8).clone():r}encode(e,n,r=0){return typeof e=="number"&&(e=new V.default(e)),this.signed&&(e=e.toTwos(this.span*8)),this.blob.encode(e.toArrayLike(Buffer,"le",this.span),n,r)}};function Q(t){return new Y(1,t)}function ee(t){return new Y(4,t)}function fe(t){return new Z(8,!1,t)}var X=class extends H{constructor(e,n,r,s){super(e.span,s),this.layout=e,this.decoder=n,this.encoder=r}decode(e,n){return this.decoder(this.layout.decode(e,n))}encode(e,n,r){return this.layout.encode(this.encoder(e),n,r)}getSpan(e,n){return this.layout.getSpan(e,n)}};function te(t){return new X(J(32),e=>new de.PublicKey(e),e=>e.toBuffer(),t)}var $=class extends pe{decode(e,n){return super.decode(e,n)}};function ge(t,e,n){return new $(t,e,n)}var We=ge([ee("mintAuthorityOption"),te("mintAuthority"),fe("supply"),Q("decimals"),Q("isInitialized"),ee("freezeAuthorityOption"),te("freezeAuthority")]);var Ne=require("@solana/web3.js"),_=require("@solana/spl-token");var Ie=u(require("big.js")),M=u(require("bn.js"));var h=u(require("bn.js")),Ze=u(require("decimal.js"));var W=require("@solana/web3.js");var i=require("@solana/web3.js"),he=require("@solana/spl-token");function ne({pubkey:t,isSigner:e=!1,isWritable:n=!0}){return{pubkey:t,isWritable:n,isSigner:e}}var Ot=[ne({pubkey:he.TOKEN_PROGRAM_ID,isWritable:!1}),ne({pubkey:i.SystemProgram.programId,isWritable:!1}),ne({pubkey:i.SYSVAR_RENT_PUBKEY,isWritable:!1})];function oe({publicKey:t,transformSol:e}){let n=ye(t.toString());if(n instanceof i.PublicKey)return e&&n.equals(I)?re:n;if(e&&n.toString()===I.toBase58())return re;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 ye(t){try{return new i.PublicKey(t)}catch(e){return t}}var Vt=new i.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Kt=new i.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Wt=new i.PublicKey("SysvarRent111111111111111111111111111111111"),vt=new i.PublicKey("SysvarC1ock11111111111111111111111111111111"),ve=new i.PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),Ut=new i.PublicKey("Sysvar1nstructions1111111111111111111111111"),qt=i.SystemProgram.programId,Gt=new i.PublicKey("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),jt=new i.PublicKey("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),zt=new i.PublicKey("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),Ht=new i.PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),Yt=new i.PublicKey("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),Jt=new i.PublicKey("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),Zt=new i.PublicKey("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),Xt=new i.PublicKey("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),$t=new i.PublicKey("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),Qt=new i.PublicKey("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),en=new i.PublicKey("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),re=new i.PublicKey("So11111111111111111111111111111111111111112"),I=i.PublicKey.default;function K(t){return oe({publicKey:t,transformSol:!0})}var v=class v{constructor({mint:e,decimals:n,symbol:r,name:s,skipMint:a=!1,isToken2022:w=!1}){if(e===I.toBase58()||e instanceof W.PublicKey&&I.equals(e)){this.decimals=p.decimals,this.symbol=p.symbol,this.name=p.name,this.mint=new W.PublicKey(p.address),this.isToken2022=!1;return}this.decimals=n,this.symbol=r||e.toString().substring(0,6),this.name=s||e.toString().substring(0,6),this.mint=a?W.PublicKey.default:oe({publicKey:e}),this.isToken2022=w}equals(e){return this===e?!0:this.mint.equals(e.mint)}};v.WSOL=new v(f(l({},p),{mint:p.address}));var T=v;var U=class U{constructor({decimals:e,symbol:n="UNKNOWN",name:r="UNKNOWN"}){this.decimals=e,this.symbol=n,this.name=r}equals(e){return this===e}};U.SOL=new U(S);var ie=U;var R=u(require("big.js")),Pe=u(require("bn.js")),we=u(require("decimal.js-light"));var N=require("lodash");var se=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}},be={},Ue={};function c(t){let e=(0,N.get)(be,t);if(!e){let n=(0,N.get)(Ue,t);e=new se({name:t,logLevel:n}),(0,N.set)(be,t,e)}return e}var B=u(require("bn.js"));var Te=9007199254740991;function m(t){let e=c("Sega_parseBigNumberish");if(t instanceof B.default)return t;if(typeof t=="string"){if(t.match(/^-?[0-9]+$/))return new B.default(t);e.logWithError(`invalid BigNumberish string: ${t}`)}return typeof t=="number"?(t%1&&e.logWithError(`BigNumberish number underflow: ${t}`),(t>=Te||t<=-Te)&&e.logWithError(`BigNumberish number overflow: ${t}`),new B.default(String(t))):typeof t=="bigint"?new B.default(t.toString()):(e.error(`invalid BigNumberish value: ${t}`),new B.default(0))}var xe=u(require("toformat")),qe=xe.default,D=qe;var q=c("module/fraction"),ae=D(R.default),F=D(we.default),je={0:F.ROUND_DOWN,1:F.ROUND_HALF_UP,2:F.ROUND_UP},ze={0:R.default.roundDown,1:R.default.roundHalfUp,2:R.default.roundUp},g=class t{constructor(e,n=new Pe.default(1)){this.numerator=m(e),this.denominator=m(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(m(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(m(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(m(e));return new t(this.numerator.mul(n.numerator),this.denominator.mul(n.denominator))}div(e){let n=e instanceof t?e:new t(m(e));return new t(this.numerator.mul(n.denominator),this.denominator.mul(n.numerator))}toSignificant(e,n={groupSeparator:""},r=1){Number.isInteger(e)||q.logWithError(`${e} is not an integer.`),e<=0&&q.logWithError(`${e} is not positive.`),F.set({precision:e+1,rounding:je[r]});let s=new F(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(e);return s.toFormat(s.decimalPlaces(),n)}toFixed(e,n={groupSeparator:""},r=1){return Number.isInteger(e)||q.logWithError(`${e} is not an integer.`),e<0&&q.logWithError(`${e} is negative.`),ae.DP=e,ae.RM=ze[r]||1,new ae(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,n)}isZero(){return this.numerator.isZero()}};var Se=u(require("bn.js"));var Pn=new g(new Se.default(100));var Ln=c("Sega_price");var Ye=require("@solana/web3.js"),Je=u(require("bn.js"));var He=new h.default(0),Xn=new h.default(1),$n=new h.default(2),Qn=new h.default(3),er=new h.default(5),Ae=new h.default(10),tr=new h.default(100),nr=new h.default(1e3),rr=new h.default(1e4);var Xe=require("@solana/web3.js");var G=require("@solana/spl-token");var pr=c("Sega_accountInfo_util");var et=require("@solana/web3.js"),tt=require("@solana/spl-token");var k=require("@solana/web3.js");var Qe=require("@solana/spl-token");var Lr=c("Sega_txUtil");var y=require("@solana/web3.js"),Mr=new y.PublicKey("SegazTQwbYWknDZkJ6j2Kgvm5gw3MrHGKtWstZdoNKZ"),_r=new y.PublicKey("Ajk8d9bERSaFdeoT1d8JUVfaDayrYLnAdgeB47TFMUaG"),Er=new y.PublicKey("2HbjxVVKJ7Ct72Rcd8WK4VTqmwTXL5aAggkH1CHGFGmh"),nt=new y.PublicKey("auetiVUVJkRxvNPLYEvVnz8UJSqQ1VgoA83PcicHVD1"),rt=new y.PublicKey("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),ot=new y.PublicKey("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y");var Or={SERUM_MARKET:y.PublicKey.default,UTIL1216:y.PublicKey.default,CREATE_CPMM_POOL_PROGRAM:nt,CREATE_CPMM_POOL_AUTH:rt,CREATE_CPMM_POOL_FEE_ACC:ot};var it=u(require("bn.js"));var Le=require("@solana/web3.js");var A=require("@solana/web3.js"),st=u(require("axios"));var at=require("@solana/web3.js");var ut=c("Sega_amount"),Ce=D(Ie.default);function ct(t,e){let n="0",r="0";if(t.includes(".")){let s=t.split(".");s.length===2?([n,r]=s,r=r.padEnd(e,"0")):ut.logWithError(`invalid number string, num: ${t}`)}else n=t;return[n,r.slice(0,e)||r]}var P=class t extends g{constructor(e,n,r=!0,s){let a=new M.default(0),w=Ae.pow(new M.default(e.decimals));if(r)a=m(n);else{let b=new M.default(0),d=new M.default(0);if(typeof n=="string"||typeof n=="number"||typeof n=="bigint"){let[L,De]=ct(n.toString(),e.decimals);b=m(L),d=m(De)}b=b.mul(w),a=b.add(d)}super(a,w),this.logger=c(s||"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 Ce.DP=this.token.decimals,new Ce(this.numerator.toString()).div(this.denominator.toString()).toFormat(e)}};var lt=n=>x(void 0,[n],function*({connection:t,mint:e}){let r=yield t.getAccountInfo(new Ne.PublicKey(e));return!r||r.data.length!==_.MintLayout.span?void 0:_.MintLayout.decode(r.data)}),mt=({mint:t,decimals:e,programId:n=_.TOKEN_PROGRAM_ID,logoURI:r="",priority:s=3})=>{let a=t.toBase58().substring(0,6);return{address:t.toBase58(),decimals:e,symbol:a,logoURI:r,extensions:{},chainId:101,programId:n.toString(),name:a,tags:[],priority:s}},pt=t=>new T({mint:t.address,decimals:t.decimals,symbol:t.symbol,name:t.name}),dt=s=>{var a=s,{amount:t,isRaw:e,name:n}=a,r=O(a,["amount","isRaw","name"]);return new P(new T({mint:K(r.address).toBase58(),decimals:r.decimals,symbol:r.symbol,name:n}),t,e,n)};function ft(t){return t.address===S.address?p:t}function gt(t){return t.address===p.address?S:t}var ht=s=>{var a=s,{address:t,programId:e,decimals:n}=a,r=O(a,["address","programId","decimals"]);return l({chainId:101,address:K(t).toBase58(),programId:e,logoURI:"",symbol:"",name:"",decimals:n,tags:[],extensions:r.extensions||{}},r)},yt=t=>t?f(l({},t),{transferFeeConfigAuthority:t.transferFeeConfigAuthority.toBase58(),withdrawWithheldAuthority:t.withdrawWithheldAuthority.toBase58(),withheldAmount:t.withheldAmount.toString(),olderTransferFee:f(l({},t.olderTransferFee),{epoch:t.olderTransferFee.epoch.toString(),maximumFee:t.olderTransferFee.maximumFee.toString()}),newerTransferFee:f(l({},t.newerTransferFee),{epoch:t.newerTransferFee.epoch.toString(),maximumFee:t.newerTransferFee.maximumFee.toString()})}):void 0;0&&(module.exports={SOL_INFO,SPL_MINT_LAYOUT,TOKEN_WSOL,parseTokenInfo,solToWSolToken,toApiV3Token,toFeeConfig,toToken,toTokenAmount,toTokenInfo,wSolToSolToken}); //# sourceMappingURL=index.js.map