UNPKG

@sega-so/sega-sdk

Version:

An SDK for building applications on top of SEGA.

2 lines 13.6 kB
"use strict";var he=Object.create;var B=Object.defineProperty,Te=Object.defineProperties,be=Object.getOwnPropertyDescriptor,ye=Object.getOwnPropertyDescriptors,xe=Object.getOwnPropertyNames,Q=Object.getOwnPropertySymbols,we=Object.getPrototypeOf,te=Object.prototype.hasOwnProperty,Pe=Object.prototype.propertyIsEnumerable;var ee=(n,e,t)=>e in n?B(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,b=(n,e)=>{for(var t in e||(e={}))te.call(e,t)&&ee(n,t,e[t]);if(Q)for(var t of Q(e))Pe.call(e,t)&&ee(n,t,e[t]);return n},y=(n,e)=>Te(n,ye(e));var Se=(n,e)=>{for(var t in e)B(n,t,{get:e[t],enumerable:!0})},ne=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of xe(e))!te.call(n,o)&&o!==t&&B(n,o,{get:()=>e[o],enumerable:!(r=be(e,o))||r.enumerable});return n};var u=(n,e,t)=>(t=n!=null?he(we(n)):{},ne(e||!n||!n.__esModule?B(t,"default",{value:n,enumerable:!0}):t,n)),Ae=n=>ne(B({},"__esModule",{value:!0}),n);var Je={};Se(Je,{Currency:()=>E,CurrencyAmount:()=>K,Fraction:()=>a,Percent:()=>w,Price:()=>P,Token:()=>p,TokenAmount:()=>S,_100_PERCENT:()=>J,currencyEquals:()=>Ce,splitNumber:()=>$});module.exports=Ae(Je);var ge=u(require("big.js")),g=u(require("bn.js"));var d=u(require("bn.js")),Fe=u(require("decimal.js"));var re=require("@solana/web3.js"),j=require("@solana/spl-token"),ie={chainId:101,address:re.PublicKey.default.toBase58(),programId:j.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"}},T={chainId:101,address:"So11111111111111111111111111111111111111112",programId:j.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 L=require("@solana/web3.js");var i=require("@solana/web3.js"),oe=require("@solana/spl-token");function H({pubkey:n,isSigner:e=!1,isWritable:t=!0}){return{pubkey:n,isWritable:t,isSigner:e}}var et=[H({pubkey:oe.TOKEN_PROGRAM_ID,isWritable:!1}),H({pubkey:i.SystemProgram.programId,isWritable:!1}),H({pubkey:i.SYSVAR_RENT_PUBKEY,isWritable:!1})];function se({publicKey:n,transformSol:e}){let t=ae(n.toString());if(t instanceof i.PublicKey)return e&&t.equals(I)?Y:t;if(e&&t.toString()===I.toBase58())return Y;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 ae(n){try{return new i.PublicKey(n)}catch(e){return n}}var tt=new i.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),nt=new i.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),rt=new i.PublicKey("SysvarRent111111111111111111111111111111111"),it=new i.PublicKey("SysvarC1ock11111111111111111111111111111111"),ke=new i.PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),ot=new i.PublicKey("Sysvar1nstructions1111111111111111111111111"),st=i.SystemProgram.programId,at=new i.PublicKey("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),ct=new i.PublicKey("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),ut=new i.PublicKey("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),lt=new i.PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),mt=new i.PublicKey("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),pt=new i.PublicKey("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),dt=new i.PublicKey("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),ft=new i.PublicKey("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),gt=new i.PublicKey("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),ht=new i.PublicKey("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),Tt=new i.PublicKey("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),Y=new i.PublicKey("So11111111111111111111111111111111111111112"),I=i.PublicKey.default;var O=class O{constructor({mint:e,decimals:t,symbol:r,name:o,skipMint:m=!1,isToken2022:h=!1}){if(e===I.toBase58()||e instanceof L.PublicKey&&I.equals(e)){this.decimals=T.decimals,this.symbol=T.symbol,this.name=T.name,this.mint=new L.PublicKey(T.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?L.PublicKey.default:se({publicKey:e}),this.isToken2022=h}equals(e){return this===e?!0:this.mint.equals(e.mint)}};O.WSOL=new O(y(b({},T),{mint:T.address}));var p=O;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(ie);var E=F;function Ce(n,e){return n instanceof p&&e instanceof p?n.equals(e):n instanceof p||e instanceof p?!1:n===e}var N=u(require("big.js")),me=u(require("bn.js")),pe=u(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 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}},ce={},Be={};function c(n){let e=(0,R.get)(ce,n);if(!e){let t=(0,R.get)(Be,n);e=new z({name:n,logLevel:t}),(0,R.set)(ce,n,e)}return e}var x=u(require("bn.js"));var ue=9007199254740991;function s(n){let e=c("Sega_parseBigNumberish");if(n instanceof x.default)return n;if(typeof n=="string"){if(n.match(/^-?[0-9]+$/))return new x.default(n);e.logWithError(`invalid BigNumberish string: ${n}`)}return typeof n=="number"?(n%1&&e.logWithError(`BigNumberish number underflow: ${n}`),(n>=ue||n<=-ue)&&e.logWithError(`BigNumberish number overflow: ${n}`),new x.default(String(n))):typeof n=="bigint"?new x.default(n.toString()):(e.error(`invalid BigNumberish value: ${n}`),new x.default(0))}var le=u(require("toformat")),Ie=le.default,M=Ie;var _=c("module/fraction"),Z=M(N.default),D=M(pe.default),Me={0:D.ROUND_DOWN,1:D.ROUND_HALF_UP,2:D.ROUND_UP},Ne={0:N.default.roundDown,1:N.default.roundHalfUp,2:N.default.roundUp},a=class n{constructor(e,t=new me.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)||_.logWithError(`${e} is not an integer.`),e<=0&&_.logWithError(`${e} is not positive.`),D.set({precision:e+1,rounding:Me[r]});let o=new D(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)||_.logWithError(`${e} is not an integer.`),e<0&&_.logWithError(`${e} is negative.`),Z.DP=e,Z.RM=Ne[r]||1,new Z(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,t)}isZero(){return this.numerator.isZero()}};var de=u(require("bn.js"));var J=new a(new de.default(100)),w=class extends a{toSignificant(e=5,t,r){return this.mul(J).toSignificant(e,t,r)}toFixed(e=2,t,r){return this.mul(J).toFixed(e,t,r)}};var De=c("Sega_price"),P=class n extends a{constructor(e){let{baseToken:t,quoteToken:r,numerator:o,denominator:m}=e;super(o,m),this.baseToken=t,this.quoteToken=r,this.scalar=new a(X(t.decimals),X(r.decimals))}get raw(){return new a(this.numerator,this.denominator)}get adjusted(){return super.mul(this.scalar)}invert(){return new n({baseToken:this.quoteToken,quoteToken:this.baseToken,denominator:this.numerator,numerator:this.denominator})}mul(e){this.quoteToken!==e.baseToken&&De.logWithError("mul token not equals");let t=super.mul(e);return new n({baseToken:this.baseToken,quoteToken:e.quoteToken,denominator:t.denominator,numerator:t.numerator})}toSignificant(e=this.quoteToken.decimals,t,r){return this.adjusted.toSignificant(e,t,r)}toFixed(e=this.quoteToken.decimals,t,r){return this.adjusted.toFixed(e,t,r)}};var Oe=require("@solana/web3.js"),Ee=u(require("bn.js"));var Le=new d.default(0),mn=new d.default(1),pn=new d.default(2),dn=new d.default(3),fn=new d.default(5),W=new d.default(10),gn=new d.default(100),hn=new d.default(1e3),Tn=new d.default(1e4);function X(n){return W.pow(s(n))}var _e=require("@solana/web3.js");var v=require("@solana/spl-token");var Cn=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 vn=c("Sega_txUtil");var l=require("@solana/web3.js"),zn=new l.PublicKey("SegazTQwbYWknDZkJ6j2Kgvm5gw3MrHGKtWstZdoNKZ"),Zn=new l.PublicKey("Ajk8d9bERSaFdeoT1d8JUVfaDayrYLnAdgeB47TFMUaG"),Jn=new l.PublicKey("2HbjxVVKJ7Ct72Rcd8WK4VTqmwTXL5aAggkH1CHGFGmh"),qe=new l.PublicKey("TegaRdjn9Qeh9DfUU28X19aPPpJtj9gs8ntSYrR5H4K "),Ue=new l.PublicKey("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),Ge=new l.PublicKey("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),Xn=new l.PublicKey("SegaXNnoXYTZiqUt9Xn2XqGcL56b25yzXLuJSpadcMu"),$n=new l.PublicKey("2t1hV2YqnDCPuJZqr7Fy8oAygGwZE5Q9uaQzpLC1QryJ"),Qn=new l.PublicKey("BLxynZeHE123MmQgNJZiV1pwW4VYh46oZYyC66xwmtTY");var je={SERUM_MARKET:l.PublicKey.default,UTIL1216:l.PublicKey.default,CREATE_CPMM_POOL_PROGRAM:qe,CREATE_CPMM_POOL_AUTH:Ue,CREATE_CPMM_POOL_FEE_ACC:Ge};var He=u(require("bn.js"));var fe=require("@solana/web3.js");var k=require("@solana/web3.js"),Ye=u(require("axios"));var ze=require("@solana/web3.js");var Ze=c("Sega_amount"),q=M(ge.default);function $(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")):Ze.logWithError(`invalid number string, num: ${n}`)}else t=n;return[t,r.slice(0,e)||r]}var S=class n extends a{constructor(e,t,r=!0,o){let m=new g.default(0),h=W.pow(new g.default(e.decimals));if(r)m=s(t);else{let f=new g.default(0),C=new g.default(0);if(typeof t=="string"||typeof t=="number"||typeof t=="bigint"){let[U,G]=$(t.toString(),e.decimals);f=s(U),C=s(G)}f=f.mul(h),m=f.add(C)}super(m,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 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 q.DP=this.token.decimals,new q(this.numerator.toString()).div(this.denominator.toString()).toFormat(e)}},K=class n extends a{constructor(e,t,r=!0,o){let m=new g.default(0),h=W.pow(new g.default(e.decimals));if(r)m=s(t);else{let f=new g.default(0),C=new g.default(0);if(typeof t=="string"||typeof t=="number"||typeof t=="bigint"){let[U,G]=$(t.toString(),e.decimals);f=s(U),C=s(G)}f=f.mul(h),m=f.add(C)}super(m,h),this.logger=c(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 q.DP=this.currency.decimals,new q(this.numerator.toString()).div(this.denominator.toString()).toFormat(e)}};0&&(module.exports={Currency,CurrencyAmount,Fraction,Percent,Price,Token,TokenAmount,_100_PERCENT,currencyEquals,splitNumber}); //# sourceMappingURL=index.js.map