UNPKG

@sega-so/sega-sdk

Version:

An SDK for building applications on top of SEGA.

2 lines 11.6 kB
var ee=Object.defineProperty,te=Object.defineProperties;var ne=Object.getOwnPropertyDescriptors;var v=Object.getOwnPropertySymbols;var re=Object.prototype.hasOwnProperty,ie=Object.prototype.propertyIsEnumerable;var q=(n,e,t)=>e in n?ee(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,h=(n,e)=>{for(var t in e||(e={}))re.call(e,t)&&q(n,t,e[t]);if(v)for(var t of v(e))ie.call(e,t)&&q(n,t,e[t]);return n},T=(n,e)=>te(n,ne(e));import ke from"big.js";import d from"bn.js";import p from"bn.js";import an from"decimal.js";import{PublicKey as oe}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as U}from"@solana/spl-token";var G={chainId:101,address:oe.default.toBase58(),programId:U.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:U.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"}};import{PublicKey as E}from"@solana/web3.js";import{PublicKey as i,SystemProgram as j,SYSVAR_RENT_PUBKEY as se}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as ae}from"@solana/spl-token";function L({pubkey:n,isSigner:e=!1,isWritable:t=!0}){return{pubkey:n,isWritable:t,isSigner:e}}var Oe=[L({pubkey:ae,isWritable:!1}),L({pubkey:j.programId,isWritable:!1}),L({pubkey:se,isWritable:!1})];function H({publicKey:n,transformSol:e}){let t=Y(n.toString());if(t instanceof i)return e&&t.equals(y)?O:t;if(e&&t.toString()===y.toBase58())return O;if(typeof t=="string"){if(t===i.default.toBase58())return i.default;try{return new i(t)}catch(r){throw new Error("invalid public key")}}throw new Error("invalid public key")}function Y(n){try{return new i(n)}catch(e){return n}}var Ee=new i("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Fe=new i("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),_e=new i("SysvarRent111111111111111111111111111111111"),Ve=new i("SysvarC1ock11111111111111111111111111111111"),ce=new i("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),We=new i("Sysvar1nstructions1111111111111111111111111"),Ke=j.programId,ve=new i("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),qe=new i("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),Ue=new i("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),Ge=new i("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),je=new i("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),He=new i("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),Ye=new i("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),ze=new i("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),Ze=new i("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),Je=new i("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),Xe=new i("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),O=new i("So11111111111111111111111111111111111111112"),y=i.default;var k=class k{constructor({mint:e,decimals:t,symbol:r,name:a,skipMint:l=!1,isToken2022:f=!1}){if(e===y.toBase58()||e instanceof E&&y.equals(e)){this.decimals=g.decimals,this.symbol=g.symbol,this.name=g.name,this.mint=new E(g.address),this.isToken2022=!1;return}this.decimals=t,this.symbol=r||e.toString().substring(0,6),this.name=a||e.toString().substring(0,6),this.mint=l?E.default:H({publicKey:e}),this.isToken2022=f}equals(e){return this===e?!0:this.mint.equals(e.mint)}};k.WSOL=new k(T(h({},g),{mint:g.address}));var x=k;var C=class C{constructor({decimals:e,symbol:t="UNKNOWN",name:r="UNKNOWN"}){this.decimals=e,this.symbol=t,this.name=r}equals(e){return this===e}};C.SOL=new C(G);var F=C;import I from"big.js";import fe from"bn.js";import ge from"decimal.js-light";import{get as z,set as ue}from"lodash";var _=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}},Z={},le={};function s(n){let e=z(Z,n);if(!e){let t=z(le,n);e=new _({name:n,logLevel:t}),ue(Z,n,e)}return e}import w from"bn.js";var J=9007199254740991;function o(n){let e=s("Sega_parseBigNumberish");if(n instanceof w)return n;if(typeof n=="string"){if(n.match(/^-?[0-9]+$/))return new w(n);e.logWithError(`invalid BigNumberish string: ${n}`)}return typeof n=="number"?(n%1&&e.logWithError(`BigNumberish number underflow: ${n}`),(n>=J||n<=-J)&&e.logWithError(`BigNumberish number overflow: ${n}`),new w(String(n))):typeof n=="bigint"?new w(n.toString()):(e.error(`invalid BigNumberish value: ${n}`),new w(0))}import me from"toformat";var pe=me,P=pe;var B=s("module/fraction"),V=P(I),S=P(ge),he={0:S.ROUND_DOWN,1:S.ROUND_HALF_UP,2:S.ROUND_UP},Te={0:I.roundDown,1:I.roundHalfUp,2:I.roundUp},c=class n{constructor(e,t=new fe(1)){this.numerator=o(e),this.denominator=o(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(o(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(o(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(o(e));return new n(this.numerator.mul(t.numerator),this.denominator.mul(t.denominator))}div(e){let t=e instanceof n?e:new n(o(e));return new n(this.numerator.mul(t.denominator),this.denominator.mul(t.numerator))}toSignificant(e,t={groupSeparator:""},r=1){Number.isInteger(e)||B.logWithError(`${e} is not an integer.`),e<=0&&B.logWithError(`${e} is not positive.`),S.set({precision:e+1,rounding:he[r]});let a=new S(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(e);return a.toFormat(a.decimalPlaces(),t)}toFixed(e,t={groupSeparator:""},r=1){return Number.isInteger(e)||B.logWithError(`${e} is not an integer.`),e<0&&B.logWithError(`${e} is negative.`),V.DP=e,V.RM=Te[r]||1,new V(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,t)}isZero(){return this.numerator.isZero()}};import be from"bn.js";var kt=new c(new be(100));var Nt=s("Sega_price");import{PublicKey as zt}from"@solana/web3.js";import Jt from"bn.js";var ye=new p(0),Tn=new p(1),bn=new p(2),yn=new p(3),xn=new p(5),W=new p(10),wn=new p(100),Pn=new p(1e3),Sn=new p(1e4);import{PublicKey as Nn}from"@solana/web3.js";import{MINT_SIZE as En,TOKEN_PROGRAM_ID as Fn,getTransferFeeConfig as _n,unpackMint as Vn}from"@solana/spl-token";var Wn=s("Sega_accountInfo_util");import{PublicKey as fr}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as hr}from"@solana/spl-token";import{ComputeBudgetProgram as Zn,Keypair as $n,PublicKey as Qn,Transaction as tr,TransactionMessage as rr,VersionedTransaction as ir}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as cr}from"@solana/spl-token";var ur=s("Sega_txUtil");import{PublicKey as u}from"@solana/web3.js";var wr=new u("SegazTQwbYWknDZkJ6j2Kgvm5gw3MrHGKtWstZdoNKZ"),Pr=new u("Ajk8d9bERSaFdeoT1d8JUVfaDayrYLnAdgeB47TFMUaG"),Sr=new u("2HbjxVVKJ7Ct72Rcd8WK4VTqmwTXL5aAggkH1CHGFGmh"),we=new u("TegaRdjn9Qeh9DfUU28X19aPPpJtj9gs8ntSYrR5H4K "),Pe=new u("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),Se=new u("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),Ar=new u("SegaXNnoXYTZiqUt9Xn2XqGcL56b25yzXLuJSpadcMu"),kr=new u("2t1hV2YqnDCPuJZqr7Fy8oAygGwZE5Q9uaQzpLC1QryJ"),Cr=new u("BLxynZeHE123MmQgNJZiV1pwW4VYh46oZYyC66xwmtTY");var Ae={SERUM_MARKET:u.default,UTIL1216:u.default,CREATE_CPMM_POOL_PROGRAM:we,CREATE_CPMM_POOL_AUTH:Pe,CREATE_CPMM_POOL_FEE_ACC:Se};import Rr from"bn.js";import{PublicKey as Er,AddressLookupTableAccount as Fr}from"@solana/web3.js";import{PublicKey as Qr,sendAndConfirmTransaction as ei,SystemProgram as ri,Transaction as ii,TransactionMessage as si,VersionedTransaction as ai}from"@solana/web3.js";import ui from"axios";import{Connection as yi}from"@solana/web3.js";var Ce=s("Sega_amount"),M=P(ke);function Q(n,e){let t="0",r="0";if(n.includes(".")){let a=n.split(".");a.length===2?([t,r]=a,r=r.padEnd(e,"0")):Ce.logWithError(`invalid number string, num: ${n}`)}else t=n;return[t,r.slice(0,e)||r]}var A=class n extends c{constructor(e,t,r=!0,a){let l=new d(0),f=W.pow(new d(e.decimals));if(r)l=o(t);else{let m=new d(0),b=new d(0);if(typeof t=="string"||typeof t=="number"||typeof t=="bigint"){let[N,D]=Q(t.toString(),e.decimals);m=o(N),b=o(D)}m=m.mul(f),l=m.add(b)}super(l,f),this.logger=s(a||"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 M.DP=this.token.decimals,new M(this.numerator.toString()).div(this.denominator.toString()).toFormat(e)}},K=class n extends c{constructor(e,t,r=!0,a){let l=new d(0),f=W.pow(new d(e.decimals));if(r)l=o(t);else{let m=new d(0),b=new d(0);if(typeof t=="string"||typeof t=="number"||typeof t=="bigint"){let[N,D]=Q(t.toString(),e.decimals);m=o(N),b=o(D)}m=m.mul(f),l=m.add(b)}super(l,f),this.logger=s(a||"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 M.DP=this.currency.decimals,new M(this.numerator.toString()).div(this.denominator.toString()).toFormat(e)}};export{K as CurrencyAmount,A as TokenAmount,Q as splitNumber}; //# sourceMappingURL=amount.mjs.map