@sega-so/sega-sdk
Version:
An SDK for building applications on top of SEGA.
2 lines • 13.3 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 Re from"big.js";import D from"bn.js";import m 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 Y,SYSVAR_RENT_PUBKEY as ue}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as le}from"@solana/spl-token";function L({pubkey:t,isSigner:e=!1,isWritable:n=!0}){return{pubkey:t,isWritable:n,isSigner:e}}var ve=[L({pubkey:le,isWritable:!1}),L({pubkey:Y.programId,isWritable:!1}),L({pubkey:ue,isWritable:!1})];function z({publicKey:t,transformSol:e}){let n=Z(t.toString());if(n instanceof i)return e&&n.equals(P)?O:n;if(e&&n.toString()===P.toBase58())return O;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 Z(t){try{return new i(t)}catch(e){return t}}var qe=new i("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Ue=new i("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Ge=new i("SysvarRent111111111111111111111111111111111"),je=new i("SysvarC1ock11111111111111111111111111111111"),me=new i("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),He=new i("Sysvar1nstructions1111111111111111111111111"),Ye=Y.programId,ze=new i("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),Ze=new i("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),Je=new i("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),Xe=new i("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),$e=new i("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),Qe=new i("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),et=new i("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),tt=new i("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),nt=new i("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),rt=new i("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),it=new i("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),O=new i("So11111111111111111111111111111111111111112"),P=i.default;var B=class B{constructor({mint:e,decimals:n,symbol:r,name:a,skipMint:p=!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=p?E.default:z({publicKey:e}),this.isToken2022=y}equals(e){return this===e?!0:this.mint.equals(e.mint)}};B.WSOL=new B(w(x({},f),{mint:f.address}));var S=B;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 F=I;import M from"big.js";import Te from"bn.js";import be from"decimal.js-light";import{get as J,set as pe}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 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=J(X,t);if(!e){let n=J(de,t);e=new _({name:t,logLevel:n}),pe(X,t,e)}return e}import A from"bn.js";var $=9007199254740991;function u(t){let e=c("Sega_parseBigNumberish");if(t instanceof A)return t;if(typeof t=="string"){if(t.match(/^-?[0-9]+$/))return new A(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 A(String(t))):typeof t=="bigint"?new A(t.toString()):(e.error(`invalid BigNumberish value: ${t}`),new A(0))}import fe from"toformat";var ge=fe,k=ge;var R=c("module/fraction"),V=k(M),C=k(be),ye={0:C.ROUND_DOWN,1:C.ROUND_HALF_UP,2:C.ROUND_UP},xe={0:M.roundDown,1:M.roundHalfUp,2:M.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)||R.logWithError(`${e} is not an integer.`),e<=0&&R.logWithError(`${e} is not positive.`),C.set({precision:e+1,rounding:ye[r]});let a=new C(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)||R.logWithError(`${e} is not an integer.`),e<0&&R.logWithError(`${e} is negative.`),V.DP=e,V.RM=xe[r]||1,new V(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:p}=e;super(a,p),this.baseToken=n,this.quoteToken=r,this.scalar=new o(W(n.decimals),W(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 m(0),an=new m(1),cn=new m(2),un=new m(3),ln=new m(5),K=new m(10),mn=new m(100),pn=new m(1e3),dn=new m(1e4);function W(t){return K.pow(u(t))}function v(t){var d;if(t===void 0)return{denominator:"1",numerator:"0"};if(t instanceof m)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:[],p="1"+"0".repeat(a.length),y=n+(r==="0"?"":r)+a||"0";return{denominator:p,numerator:y,sign:n,int:r,dec:a}}import{PublicKey as Pn}from"@solana/web3.js";import{MINT_SIZE as Cn,TOKEN_PROGRAM_ID as Bn,getTransferFeeConfig as In,unpackMint as Rn}from"@solana/spl-token";var Mn=c("Sega_accountInfo_util");import{PublicKey as or}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as ar}from"@solana/spl-token";import{ComputeBudgetProgram as Kn,Keypair as Un,PublicKey as Gn,Transaction as Hn,TransactionMessage as zn,VersionedTransaction as Zn}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Qn}from"@solana/spl-token";var er=c("Sega_txUtil");import{PublicKey as l}from"@solana/web3.js";var pr=new l("SegazTQwbYWknDZkJ6j2Kgvm5gw3MrHGKtWstZdoNKZ"),dr=new l("Ajk8d9bERSaFdeoT1d8JUVfaDayrYLnAdgeB47TFMUaG"),fr=new l("2HbjxVVKJ7Ct72Rcd8WK4VTqmwTXL5aAggkH1CHGFGmh"),ke=new l("TegaRdjn9Qeh9DfUU28X19aPPpJtj9gs8ntSYrR5H4K "),Ce=new l("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),Be=new l("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),gr=new l("SegaXNnoXYTZiqUt9Xn2XqGcL56b25yzXLuJSpadcMu"),hr=new l("2t1hV2YqnDCPuJZqr7Fy8oAygGwZE5Q9uaQzpLC1QryJ"),Tr=new l("BLxynZeHE123MmQgNJZiV1pwW4VYh46oZYyC66xwmtTY");var Ie={SERUM_MARKET:l.default,UTIL1216:l.default,CREATE_CPMM_POOL_PROGRAM:ke,CREATE_CPMM_POOL_AUTH:Ce,CREATE_CPMM_POOL_FEE_ACC:Be};import xr from"bn.js";import{PublicKey as Cr,AddressLookupTableAccount as Br}from"@solana/web3.js";import{PublicKey as Gr,sendAndConfirmTransaction as jr,SystemProgram as zr,Transaction as Zr,TransactionMessage as Xr,VersionedTransaction as $r}from"@solana/web3.js";import ei from"axios";import{Connection as li}from"@solana/web3.js";var Me=c("Sega_amount"),ee=k(Re);function Ne(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")):Me.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 p=new D(0),y=K.pow(new D(e.decimals));if(r)p=u(n);else{let d=new D(0),q=new D(0);if(typeof n=="string"||typeof n=="number"||typeof n=="bigint"){let[te,ne]=Ne(n.toString(),e.decimals);d=u(te),q=u(ne)}d=d.mul(y),p=d.add(q)}super(p,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=v(e);return new o(n.numerator,n.denominator)}function to(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=v(e);return{fr:new o(n.numerator,n.denominator),decimals:(r=n.dec)==null?void 0:r.length}}function no(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 ro(t,e){if(t==null||e==null)return!1;let n=s(t),r=s(e);return n.sub(r).numerator.lte(b)}function io(t,e){if(t==null||e==null)return!1;let n=s(t),r=s(e);return n.sub(r).numerator.gte(b)}function Le(t,e){if(t==null||e==null)return!1;let n=s(t),r=s(e);return n.sub(r).numerator.eq(b)}function oo(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 so(t,e){if(t==null||e==null)return;let n=s(t),r=s(e);return n.sub(r)}function ao(t){return t==null?!1:!Le(t,0)}function co(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 uo(t,e){if(t==null||e==null)return;let n=s(t),r=s(e);return n.add(r)}export{uo as add,s as default,oo as div,Le as eq,co as getMax,De as gt,io as gte,ao as isMeaningfulNumber,no as lt,ro as lte,Se as mul,so as sub,to as toFractionWithDecimals};
//# sourceMappingURL=fractionUtil.mjs.map