@sega-so/sega-sdk
Version:
An SDK for building applications on top of SEGA.
2 lines • 13.2 kB
JavaScript
var re=Object.defineProperty,ie=Object.defineProperties;var oe=Object.getOwnPropertyDescriptors;var U=Object.getOwnPropertySymbols;var se=Object.prototype.hasOwnProperty,ae=Object.prototype.propertyIsEnumerable;var G=(t,e,n)=>e in t?re(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,x=(t,e)=>{for(var n in e||(e={}))se.call(e,n)&&G(t,n,e[n]);if(U)for(var n of U(e))ae.call(e,n)&&G(t,n,e[n]);return t},w=(t,e)=>ie(t,oe(e));import Ie from"big.js";import M from"bn.js";import l from"bn.js";import Jt from"decimal.js";import{PublicKey as ce}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as j}from"@solana/spl-token";var H={chainId:101,address:ce.default.toBase58(),programId:j.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:j.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 z,SYSVAR_RENT_PUBKEY as ue}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as le}from"@solana/spl-token";function F({pubkey:t,isSigner:e=!1,isWritable:n=!0}){return{pubkey:t,isWritable:n,isSigner:e}}var ve=[F({pubkey:le,isWritable:!1}),F({pubkey:z.programId,isWritable:!1}),F({pubkey:ue,isWritable:!1})];function Y({publicKey:t,transformSol:e}){let n=J(t.toString());if(n instanceof i)return e&&n.equals(P)?L:n;if(e&&n.toString()===P.toBase58())return L;if(typeof n=="string"){if(n===i.default.toBase58())return i.default;try{return new i(n)}catch(r){throw new Error("invalid public key")}}throw new Error("invalid public key")}function J(t){try{return new i(t)}catch(e){return t}}var _e=new i("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),qe=new i("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Ue=new i("SysvarRent111111111111111111111111111111111"),Ge=new i("SysvarC1ock11111111111111111111111111111111"),me=new i("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),je=new i("Sysvar1nstructions1111111111111111111111111"),He=z.programId,ze=new i("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),Ye=new i("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),Je=new i("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),Ze=new i("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),Xe=new i("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),$e=new i("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),Qe=new i("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),et=new i("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),tt=new i("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),nt=new i("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),rt=new i("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),L=new i("So11111111111111111111111111111111111111112"),P=i.default;var C=class C{constructor({mint:e,decimals:n,symbol:r,name:a,skipMint:m=!1,isToken2022:y=!1}){if(e===P.toBase58()||e instanceof E&&P.equals(e)){this.decimals=f.decimals,this.symbol=f.symbol,this.name=f.name,this.mint=new E(f.address),this.isToken2022=!1;return}this.decimals=n,this.symbol=r||e.toString().substring(0,6),this.name=a||e.toString().substring(0,6),this.mint=m?E.default:Y({publicKey:e}),this.isToken2022=y}equals(e){return this===e?!0:this.mint.equals(e.mint)}};C.WSOL=new C(w(x({},f),{mint:f.address}));var S=C;var I=class I{constructor({decimals:e,symbol:n="UNKNOWN",name:r="UNKNOWN"}){this.decimals=e,this.symbol=n,this.name=r}equals(e){return this===e}};I.SOL=new I(H);var O=I;import R from"big.js";import Te from"bn.js";import be from"decimal.js-light";import{get as Z,set as pe}from"lodash";var V=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}},X={},de={};function c(t){let e=Z(X,t);if(!e){let n=Z(de,t);e=new V({name:t,logLevel:n}),pe(X,t,e)}return e}import k from"bn.js";var $=9007199254740991;function u(t){let e=c("Sega_parseBigNumberish");if(t instanceof k)return t;if(typeof t=="string"){if(t.match(/^-?[0-9]+$/))return new k(t);e.logWithError(`invalid BigNumberish string: ${t}`)}return typeof t=="number"?(t%1&&e.logWithError(`BigNumberish number underflow: ${t}`),(t>=$||t<=-$)&&e.logWithError(`BigNumberish number overflow: ${t}`),new k(String(t))):typeof t=="bigint"?new k(t.toString()):(e.error(`invalid BigNumberish value: ${t}`),new k(0))}import fe from"toformat";var ge=fe,A=ge;var N=c("module/fraction"),W=A(R),B=A(be),ye={0:B.ROUND_DOWN,1:B.ROUND_HALF_UP,2:B.ROUND_UP},xe={0:R.roundDown,1:R.roundHalfUp,2:R.roundUp},o=class t{constructor(e,n=new Te(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)||N.logWithError(`${e} is not an integer.`),e<=0&&N.logWithError(`${e} is not positive.`),B.set({precision:e+1,rounding:ye[r]});let a=new B(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(e);return a.toFormat(a.decimalPlaces(),n)}toFixed(e,n={groupSeparator:""},r=1){return Number.isInteger(e)||N.logWithError(`${e} is not an integer.`),e<0&&N.logWithError(`${e} is negative.`),W.DP=e,W.RM=xe[r]||1,new W(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,n)}isZero(){return this.numerator.isZero()}};import we from"bn.js";var Q=new o(new we(100)),g=class extends o{toSignificant(e=5,n,r){return this.mul(Q).toSignificant(e,n,r)}toFixed(e=2,n,r){return this.mul(Q).toFixed(e,n,r)}};var Pe=c("Sega_price"),h=class t extends o{constructor(e){let{baseToken:n,quoteToken:r,numerator:a,denominator:m}=e;super(a,m),this.baseToken=n,this.quoteToken=r,this.scalar=new o(K(n.decimals),K(r.decimals))}get raw(){return new o(this.numerator,this.denominator)}get adjusted(){return super.mul(this.scalar)}invert(){return new t({baseToken:this.quoteToken,quoteToken:this.baseToken,denominator:this.numerator,numerator:this.denominator})}mul(e){this.quoteToken!==e.baseToken&&Pe.logWithError("mul token not equals");let n=super.mul(e);return new t({baseToken:this.baseToken,quoteToken:e.quoteToken,denominator:n.denominator,numerator:n.numerator})}toSignificant(e=this.quoteToken.decimals,n,r){return this.adjusted.toSignificant(e,n,r)}toFixed(e=this.quoteToken.decimals,n,r){return this.adjusted.toFixed(e,n,r)}};import{PublicKey as Wt}from"@solana/web3.js";import vt from"bn.js";var b=new l(0),sn=new l(1),an=new l(2),cn=new l(3),un=new l(5),v=new l(10),ln=new l(100),mn=new l(1e3),pn=new l(1e4);function K(t){return v.pow(u(t))}function _(t){var d;if(t===void 0)return{denominator:"1",numerator:"0"};if(t instanceof l)return{numerator:t.toString(),denominator:"1"};if(t instanceof o)return{denominator:t.denominator.toString(),numerator:t.numerator.toString()};let e=String(t),[,n="",r="",a=""]=(d=e.replace(",","").match(/(-?)(\d*)\.?(\d*)/))!=null?d:[],m="1"+"0".repeat(a.length),y=n+(r==="0"?"":r)+a||"0";return{denominator:m,numerator:y,sign:n,int:r,dec:a}}import{PublicKey as wn}from"@solana/web3.js";import{MINT_SIZE as An,TOKEN_PROGRAM_ID as Bn,getTransferFeeConfig as Cn,unpackMint as In}from"@solana/spl-token";var Nn=c("Sega_accountInfo_util");import{PublicKey as ir}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as sr}from"@solana/spl-token";import{ComputeBudgetProgram as Kn,Keypair as qn,PublicKey as Un,Transaction as jn,TransactionMessage as zn,VersionedTransaction as Yn}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as $n}from"@solana/spl-token";var Qn=c("Sega_txUtil");import{PublicKey as p}from"@solana/web3.js";var mr=new p("SegazTQwbYWknDZkJ6j2Kgvm5gw3MrHGKtWstZdoNKZ"),pr=new p("Ajk8d9bERSaFdeoT1d8JUVfaDayrYLnAdgeB47TFMUaG"),dr=new p("2HbjxVVKJ7Ct72Rcd8WK4VTqmwTXL5aAggkH1CHGFGmh"),Ae=new p("auetiVUVJkRxvNPLYEvVnz8UJSqQ1VgoA83PcicHVD1"),Be=new p("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),Ce=new p("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y");var fr={SERUM_MARKET:p.default,UTIL1216:p.default,CREATE_CPMM_POOL_PROGRAM:Ae,CREATE_CPMM_POOL_AUTH:Be,CREATE_CPMM_POOL_FEE_ACC:Ce};import Tr from"bn.js";import{PublicKey as Sr,AddressLookupTableAccount as kr}from"@solana/web3.js";import{PublicKey as _r,sendAndConfirmTransaction as qr,SystemProgram as jr,Transaction as Hr,TransactionMessage as Yr,VersionedTransaction as Jr}from"@solana/web3.js";import Xr from"axios";import{Connection as oi}from"@solana/web3.js";var Ne=c("Sega_amount"),ee=A(Ie);function Re(t,e){let n="0",r="0";if(t.includes(".")){let a=t.split(".");a.length===2?([n,r]=a,r=r.padEnd(e,"0")):Ne.logWithError(`invalid number string, num: ${t}`)}else n=t;return[n,r.slice(0,e)||r]}var T=class t extends o{constructor(e,n,r=!0,a){let m=new M(0),y=v.pow(new M(e.decimals));if(r)m=u(n);else{let d=new M(0),q=new M(0);if(typeof n=="string"||typeof n=="number"||typeof n=="bigint"){let[te,ne]=Re(n.toString(),e.decimals);d=u(te),q=u(ne)}d=d.mul(y),m=d.add(q)}super(m,y),this.logger=c(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 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 ee.DP=this.token.decimals,new ee(this.numerator.toString()).div(this.denominator.toString()).toFormat(e)}};function s(t){if(t instanceof g)return new o(t.numerator,t.denominator);if(t instanceof h)return t.adjusted;if(t instanceof T)try{return s(t.toExact())}catch(r){return new o(b)}if(t instanceof o)return t;let e=String(t),n=_(e);return new o(n.numerator,n.denominator)}function Yi(t){var r;if(t instanceof g)return{fr:new o(t.numerator,t.denominator)};if(t instanceof h)return{fr:t.adjusted};if(t instanceof T)return{fr:s(t.toExact()),decimals:t.token.decimals};if(t instanceof o)return{fr:t};let e=String(t),n=_(e);return{fr:new o(n.numerator,n.denominator),decimals:(r=n.dec)==null?void 0:r.length}}function Ji(t,e){if(t==null||e==null)return!1;let n=s(t),r=s(e);return n.sub(r).numerator,n.sub(r).numerator.lt(b)}function De(t,e){if(t==null||e==null)return!1;let n=s(t),r=s(e);return n.sub(r).numerator.gt(b)}function Zi(t,e){if(t==null||e==null)return!1;let n=s(t),r=s(e);return n.sub(r).numerator.lte(b)}function Xi(t,e){if(t==null||e==null)return!1;let n=s(t),r=s(e);return n.sub(r).numerator.gte(b)}function Me(t,e){if(t==null||e==null)return!1;let n=s(t),r=s(e);return n.sub(r).numerator.eq(b)}function $i(t,e){if(t==null||e==null)return;let n=s(t),r=s(e);try{return n.div(r)}catch(a){return n}}function Qi(t,e){if(t==null||e==null)return;let n=s(t),r=s(e);return n.sub(r)}function eo(t){return t==null?!1:!Me(t,0)}function to(t,e){return De(e,t)?e:t}function Se(t,e){if(t==null||e==null)return;let n=s(t),r=s(e);return n.mul(r)}function no(t,e){if(t==null||e==null)return;let n=s(t),r=s(e);return n.add(r)}export{no as add,s as default,$i as div,Me as eq,to as getMax,De as gt,Xi as gte,eo as isMeaningfulNumber,Ji as lt,Zi as lte,Se as mul,Qi as sub,Yi as toFractionWithDecimals};
//# sourceMappingURL=fractionUtil.mjs.map