UNPKG

@sega-so/sega-sdk

Version:

An SDK for building applications on top of SEGA.

2 lines 12.1 kB
"use strict";var fe=Object.create;var k=Object.defineProperty,ge=Object.defineProperties,he=Object.getOwnPropertyDescriptor,Te=Object.getOwnPropertyDescriptors,be=Object.getOwnPropertyNames,J=Object.getOwnPropertySymbols,ye=Object.getPrototypeOf,X=Object.prototype.hasOwnProperty,xe=Object.prototype.propertyIsEnumerable;var Z=(n,e,t)=>e in n?k(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,T=(n,e)=>{for(var t in e||(e={}))X.call(e,t)&&Z(n,t,e[t]);if(J)for(var t of J(e))xe.call(e,t)&&Z(n,t,e[t]);return n},b=(n,e)=>ge(n,Te(e));var we=(n,e)=>{for(var t in e)k(n,t,{get:e[t],enumerable:!0})},$=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of be(e))!X.call(n,o)&&o!==t&&k(n,o,{get:()=>e[o],enumerable:!(r=he(e,o))||r.enumerable});return n};var c=(n,e,t)=>(t=n!=null?fe(ye(n)):{},$(e||!n||!n.__esModule?k(t,"default",{value:n,enumerable:!0}):t,n)),Pe=n=>$(k({},"__esModule",{value:!0}),n);var je={};we(je,{CurrencyAmount:()=>O,TokenAmount:()=>x,splitNumber:()=>Y});module.exports=Pe(je);var de=c(require("big.js")),f=c(require("bn.js"));var l=c(require("bn.js")),Me=c(require("decimal.js"));var Q=require("@solana/web3.js"),_=require("@solana/spl-token"),ee={chainId:101,address:Q.PublicKey.default.toBase58(),programId:_.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"}},h={chainId:101,address:"So11111111111111111111111111111111111111112",programId:_.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 D=require("@solana/web3.js");var i=require("@solana/web3.js"),te=require("@solana/spl-token");function q({pubkey:n,isSigner:e=!1,isWritable:t=!0}){return{pubkey:n,isWritable:t,isSigner:e}}var Je=[q({pubkey:te.TOKEN_PROGRAM_ID,isWritable:!1}),q({pubkey:i.SystemProgram.programId,isWritable:!1}),q({pubkey:i.SYSVAR_RENT_PUBKEY,isWritable:!1})];function ne({publicKey:n,transformSol:e}){let t=re(n.toString());if(t instanceof i.PublicKey)return e&&t.equals(A)?U:t;if(e&&t.toString()===A.toBase58())return U;if(typeof t=="string"){if(t===i.PublicKey.default.toBase58())return i.PublicKey.default;try{return new i.PublicKey(t)}catch(r){throw new Error("invalid public key")}}throw new Error("invalid public key")}function re(n){try{return new i.PublicKey(n)}catch(e){return n}}var Ze=new i.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Xe=new i.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),$e=new i.PublicKey("SysvarRent111111111111111111111111111111111"),Qe=new i.PublicKey("SysvarC1ock11111111111111111111111111111111"),Se=new i.PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),et=new i.PublicKey("Sysvar1nstructions1111111111111111111111111"),tt=i.SystemProgram.programId,nt=new i.PublicKey("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),rt=new i.PublicKey("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),it=new i.PublicKey("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),ot=new i.PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),st=new i.PublicKey("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),at=new i.PublicKey("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),ct=new i.PublicKey("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),ut=new i.PublicKey("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),lt=new i.PublicKey("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),mt=new i.PublicKey("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),pt=new i.PublicKey("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),U=new i.PublicKey("So11111111111111111111111111111111111111112"),A=i.PublicKey.default;var M=class M{constructor({mint:e,decimals:t,symbol:r,name:o,skipMint:m=!1,isToken2022:g=!1}){if(e===A.toBase58()||e instanceof D.PublicKey&&A.equals(e)){this.decimals=h.decimals,this.symbol=h.symbol,this.name=h.name,this.mint=new D.PublicKey(h.address),this.isToken2022=!1;return}this.decimals=t,this.symbol=r||e.toString().substring(0,6),this.name=o||e.toString().substring(0,6),this.mint=m?D.PublicKey.default:ne({publicKey:e}),this.isToken2022=g}equals(e){return this===e?!0:this.mint.equals(e.mint)}};M.WSOL=new M(b(T({},h),{mint:h.address}));var B=M;var F=class F{constructor({decimals:e,symbol:t="UNKNOWN",name:r="UNKNOWN"}){this.decimals=e,this.symbol=t,this.name=r}equals(e){return this===e}};F.SOL=new F(ee);var G=F;var N=c(require("big.js")),ae=c(require("bn.js")),ce=c(require("decimal.js-light"));var C=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 t=e.map(r=>typeof r=="object"?JSON.stringify(r):r).join(", ");throw new Error(t)}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}},ie={},ke={};function a(n){let e=(0,C.get)(ie,n);if(!e){let t=(0,C.get)(ke,n);e=new j({name:n,logLevel:t}),(0,C.set)(ie,n,e)}return e}var y=c(require("bn.js"));var oe=9007199254740991;function s(n){let e=a("Sega_parseBigNumberish");if(n instanceof y.default)return n;if(typeof n=="string"){if(n.match(/^-?[0-9]+$/))return new y.default(n);e.logWithError(`invalid BigNumberish string: ${n}`)}return typeof n=="number"?(n%1&&e.logWithError(`BigNumberish number underflow: ${n}`),(n>=oe||n<=-oe)&&e.logWithError(`BigNumberish number overflow: ${n}`),new y.default(String(n))):typeof n=="bigint"?new y.default(n.toString()):(e.error(`invalid BigNumberish value: ${n}`),new y.default(0))}var se=c(require("toformat")),Ae=se.default,I=Ae;var L=a("module/fraction"),H=I(N.default),R=I(ce.default),Ce={0:R.ROUND_DOWN,1:R.ROUND_HALF_UP,2:R.ROUND_UP},Ie={0:N.default.roundDown,1:N.default.roundHalfUp,2:N.default.roundUp},u=class n{constructor(e,t=new ae.default(1)){this.numerator=s(e),this.denominator=s(t)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new n(this.denominator,this.numerator)}add(e){let t=e instanceof n?e:new n(s(e));return this.denominator.eq(t.denominator)?new n(this.numerator.add(t.numerator),this.denominator):new n(this.numerator.mul(t.denominator).add(t.numerator.mul(this.denominator)),this.denominator.mul(t.denominator))}sub(e){let t=e instanceof n?e:new n(s(e));return this.denominator.eq(t.denominator)?new n(this.numerator.sub(t.numerator),this.denominator):new n(this.numerator.mul(t.denominator).sub(t.numerator.mul(this.denominator)),this.denominator.mul(t.denominator))}mul(e){let t=e instanceof n?e:new n(s(e));return new n(this.numerator.mul(t.numerator),this.denominator.mul(t.denominator))}div(e){let t=e instanceof n?e:new n(s(e));return new n(this.numerator.mul(t.denominator),this.denominator.mul(t.numerator))}toSignificant(e,t={groupSeparator:""},r=1){Number.isInteger(e)||L.logWithError(`${e} is not an integer.`),e<=0&&L.logWithError(`${e} is not positive.`),R.set({precision:e+1,rounding:Ce[r]});let o=new R(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(e);return o.toFormat(o.decimalPlaces(),t)}toFixed(e,t={groupSeparator:""},r=1){return Number.isInteger(e)||L.logWithError(`${e} is not an integer.`),e<0&&L.logWithError(`${e} is negative.`),H.DP=e,H.RM=Ie[r]||1,new H(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,t)}isZero(){return this.numerator.isZero()}};var ue=c(require("bn.js"));var Mt=new u(new ue.default(100));var Wt=a("Sega_price");var Re=require("@solana/web3.js"),De=c(require("bn.js"));var Ne=new l.default(0),Tn=new l.default(1),bn=new l.default(2),yn=new l.default(3),xn=new l.default(5),z=new l.default(10),wn=new l.default(100),Pn=new l.default(1e3),Sn=new l.default(1e4);var Fe=require("@solana/web3.js");var V=require("@solana/spl-token");var Mn=a("Sega_accountInfo_util");var Oe=require("@solana/web3.js"),Ve=require("@solana/spl-token");var w=require("@solana/web3.js");var Ee=require("@solana/spl-token");var zn=a("Sega_txUtil");var d=require("@solana/web3.js"),er=new d.PublicKey("SegazTQwbYWknDZkJ6j2Kgvm5gw3MrHGKtWstZdoNKZ"),tr=new d.PublicKey("Ajk8d9bERSaFdeoT1d8JUVfaDayrYLnAdgeB47TFMUaG"),nr=new d.PublicKey("2HbjxVVKJ7Ct72Rcd8WK4VTqmwTXL5aAggkH1CHGFGmh"),We=new d.PublicKey("auetiVUVJkRxvNPLYEvVnz8UJSqQ1VgoA83PcicHVD1"),Ke=new d.PublicKey("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),ve=new d.PublicKey("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y");var rr={SERUM_MARKET:d.PublicKey.default,UTIL1216:d.PublicKey.default,CREATE_CPMM_POOL_PROGRAM:We,CREATE_CPMM_POOL_AUTH:Ke,CREATE_CPMM_POOL_FEE_ACC:ve};var _e=c(require("bn.js"));var pe=require("@solana/web3.js");var P=require("@solana/web3.js"),qe=c(require("axios"));var Ue=require("@solana/web3.js");var Ge=a("Sega_amount"),W=I(de.default);function Y(n,e){let t="0",r="0";if(n.includes(".")){let o=n.split(".");o.length===2?([t,r]=o,r=r.padEnd(e,"0")):Ge.logWithError(`invalid number string, num: ${n}`)}else t=n;return[t,r.slice(0,e)||r]}var x=class n extends u{constructor(e,t,r=!0,o){let m=new f.default(0),g=z.pow(new f.default(e.decimals));if(r)m=s(t);else{let p=new f.default(0),S=new f.default(0);if(typeof t=="string"||typeof t=="number"||typeof t=="bigint"){let[K,v]=Y(t.toString(),e.decimals);p=s(K),S=s(v)}p=p.mul(g),m=p.add(S)}super(m,g),this.logger=a(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 n(this.token,this.raw.add(e.raw))}subtract(e){return this.token.equals(e.token)||this.logger.logWithError("sub token not equals"),new n(this.token,this.raw.sub(e.raw))}toSignificant(e=this.token.decimals,t,r=0){return super.toSignificant(e,t,r)}toFixed(e=this.token.decimals,t,r=0){return e>this.token.decimals&&this.logger.logWithError("decimals overflow"),super.toFixed(e,t,r)}toExact(e={groupSeparator:""}){return W.DP=this.token.decimals,new W(this.numerator.toString()).div(this.denominator.toString()).toFormat(e)}},O=class n extends u{constructor(e,t,r=!0,o){let m=new f.default(0),g=z.pow(new f.default(e.decimals));if(r)m=s(t);else{let p=new f.default(0),S=new f.default(0);if(typeof t=="string"||typeof t=="number"||typeof t=="bigint"){let[K,v]=Y(t.toString(),e.decimals);p=s(K),S=s(v)}p=p.mul(g),m=p.add(S)}super(m,g),this.logger=a(o||"TokenAmount"),this.currency=e}get raw(){return this.numerator}isZero(){return this.raw.isZero()}gt(e){return this.currency.equals(e.currency)||this.logger.logWithError("gt currency not equals"),this.raw.gt(e.raw)}lt(e){return this.currency.equals(e.currency)||this.logger.logWithError("lt currency not equals"),this.raw.lt(e.raw)}add(e){return this.currency.equals(e.currency)||this.logger.logWithError("add currency not equals"),new n(this.currency,this.raw.add(e.raw))}sub(e){return this.currency.equals(e.currency)||this.logger.logWithError("sub currency not equals"),new n(this.currency,this.raw.sub(e.raw))}toSignificant(e=this.currency.decimals,t,r=0){return super.toSignificant(e,t,r)}toFixed(e=this.currency.decimals,t,r=0){return e>this.currency.decimals&&this.logger.logWithError("decimals overflow"),super.toFixed(e,t,r)}toExact(e={groupSeparator:""}){return W.DP=this.currency.decimals,new W(this.numerator.toString()).div(this.denominator.toString()).toFormat(e)}};0&&(module.exports={CurrencyAmount,TokenAmount,splitNumber}); //# sourceMappingURL=amount.js.map