@sega-so/sega-sdk
Version:
An SDK for building applications on top of SEGA.
2 lines • 15.3 kB
JavaScript
var me=Object.defineProperty,pe=Object.defineProperties;var de=Object.getOwnPropertyDescriptors;var z=Object.getOwnPropertySymbols;var fe=Object.prototype.hasOwnProperty,ge=Object.prototype.propertyIsEnumerable;var J=Math.pow,Z=(t,e,n)=>e in t?me(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,x=(t,e)=>{for(var n in e||(e={}))fe.call(e,n)&&Z(t,n,e[n]);if(z)for(var n of z(e))ge.call(e,n)&&Z(t,n,e[n]);return t},w=(t,e)=>pe(t,de(e));import s from"bn.js";import Ke from"decimal.js";import Ve from"big.js";import b from"bn.js";import{get as X,set as he}from"lodash";var K=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}},$={},Te={};function m(t){let e=X($,t);if(!e){let n=X(Te,t);e=new K({name:t,logLevel:n}),he($,t,e)}return e}import{PublicKey as $e}from"@solana/web3.js";import{MINT_SIZE as nt,TOKEN_PROGRAM_ID as rt,getTransferFeeConfig as it,unpackMint as ot}from"@solana/spl-token";var st=m("Sega_accountInfo_util");import k from"bn.js";var Q=9007199254740991;function u(t){let e=m("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>=Q||t<=-Q)&&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{PublicKey as be}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as ee}from"@solana/spl-token";var te={chainId:101,address:be.default.toBase58(),programId:ee.toBase58(),decimals:9,symbol:"SOL",name:"solana",logoURI:"https://img-v1.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"sega",extensions:{coingeckoId:"solana"}},P={chainId:101,address:"So11111111111111111111111111111111111111112",programId:ee.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 U}from"@solana/web3.js";import{PublicKey as o,SystemProgram as ne,SYSVAR_RENT_PUBKEY as ye}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as xe}from"@solana/spl-token";function q({pubkey:t,isSigner:e=!1,isWritable:n=!0}){return{pubkey:t,isWritable:n,isSigner:e}}var wt=[q({pubkey:xe,isWritable:!1}),q({pubkey:ne.programId,isWritable:!1}),q({pubkey:ye,isWritable:!1})];function re({publicKey:t,transformSol:e}){let n=ie(t.toString());if(n instanceof o)return e&&n.equals(C)?v:n;if(e&&n.toString()===C.toBase58())return v;if(typeof n=="string"){if(n===o.default.toBase58())return o.default;try{return new o(n)}catch(r){throw new Error("invalid public key")}}throw new Error("invalid public key")}function ie(t){try{return new o(t)}catch(e){return t}}var Pt=new o("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),St=new o("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),At=new o("SysvarRent111111111111111111111111111111111"),kt=new o("SysvarC1ock11111111111111111111111111111111"),we=new o("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),Ct=new o("Sysvar1nstructions1111111111111111111111111"),Bt=ne.programId,It=new o("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),Rt=new o("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),Mt=new o("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),Nt=new o("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),Dt=new o("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),Lt=new o("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),Ot=new o("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),Et=new o("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),Ft=new o("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),_t=new o("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),Vt=new o("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),v=new o("So11111111111111111111111111111111111111112"),C=o.default;var M=class M{constructor({mint:e,decimals:n,symbol:r,name:a,skipMint:c=!1,isToken2022:p=!1}){if(e===C.toBase58()||e instanceof U&&C.equals(e)){this.decimals=P.decimals,this.symbol=P.symbol,this.name=P.name,this.mint=new U(P.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=c?U.default:re({publicKey:e}),this.isToken2022=p}equals(e){return this===e?!0:this.mint.equals(e.mint)}};M.WSOL=new M(w(x({},P),{mint:P.address}));var h=M;var D=class D{constructor({decimals:e,symbol:n="UNKNOWN",name:r="UNKNOWN"}){this.decimals=e,this.symbol=n,this.name=r}equals(e){return this===e}};D.SOL=new D(te);var N=D;import Pe from"toformat";var Se=Pe,B=Se;import O from"big.js";import ke from"bn.js";import Ce from"decimal.js-light";var L=m("module/fraction"),G=B(O),I=B(Ce),Be={0:I.ROUND_DOWN,1:I.ROUND_HALF_UP,2:I.ROUND_UP},Ie={0:O.roundDown,1:O.roundHalfUp,2:O.roundUp},i=class t{constructor(e,n=new ke(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)||L.logWithError(`${e} is not an integer.`),e<=0&&L.logWithError(`${e} is not positive.`),I.set({precision:e+1,rounding:Be[r]});let a=new I(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)||L.logWithError(`${e} is not an integer.`),e<0&&L.logWithError(`${e} is negative.`),G.DP=e,G.RM=Ie[r]||1,new G(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,n)}isZero(){return this.numerator.isZero()}};import Re from"bn.js";var oe=new i(new Re(100)),f=class extends i{toSignificant(e=5,n,r){return this.mul(oe).toSignificant(e,n,r)}toFixed(e=2,n,r){return this.mul(oe).toFixed(e,n,r)}};var Me=m("Sega_price"),g=class t extends i{constructor(e){let{baseToken:n,quoteToken:r,numerator:a,denominator:c}=e;super(a,c),this.baseToken=n,this.quoteToken=r,this.scalar=new i(j(n.decimals),j(r.decimals))}get raw(){return new i(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&&Me.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)}};function E(t){if(t instanceof f)return new i(t.numerator,t.denominator);if(t instanceof g)return t.adjusted;if(t instanceof T)try{return E(t.toExact())}catch(r){return new i(Y)}if(t instanceof i)return t;let e=String(t),n=A(e);return new i(n.numerator,n.denominator)}function H(t,e){if(t==null||e==null)return;let n=E(t),r=E(e);return n.mul(r)}import{PublicKey as Jn}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as $n}from"@solana/spl-token";import{ComputeBudgetProgram as Nn,Keypair as On,PublicKey as En,Transaction as _n,TransactionMessage as Wn,VersionedTransaction as Kn}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Gn}from"@solana/spl-token";var jn=m("Sega_txUtil");import{PublicKey as d}from"@solana/web3.js";var rr=new d("SegazTQwbYWknDZkJ6j2Kgvm5gw3MrHGKtWstZdoNKZ"),ir=new d("Ajk8d9bERSaFdeoT1d8JUVfaDayrYLnAdgeB47TFMUaG"),or=new d("2HbjxVVKJ7Ct72Rcd8WK4VTqmwTXL5aAggkH1CHGFGmh"),De=new d("TegaRdjn9Qeh9DfUU28X19aPPpJtj9gs8ntSYrR5H4K "),Le=new d("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),Oe=new d("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),sr=new d("SegaXNnoXYTZiqUt9Xn2XqGcL56b25yzXLuJSpadcMu"),ar=new d("2t1hV2YqnDCPuJZqr7Fy8oAygGwZE5Q9uaQzpLC1QryJ"),cr=new d("BLxynZeHE123MmQgNJZiV1pwW4VYh46oZYyC66xwmtTY");var Ee={SERUM_MARKET:d.default,UTIL1216:d.default,CREATE_CPMM_POOL_PROGRAM:De,CREATE_CPMM_POOL_AUTH:Le,CREATE_CPMM_POOL_FEE_ACC:Oe};import mr from"bn.js";import{PublicKey as Tr,AddressLookupTableAccount as br}from"@solana/web3.js";import{PublicKey as Er,sendAndConfirmTransaction as Fr,SystemProgram as Wr,Transaction as Kr,TransactionMessage as qr,VersionedTransaction as Ur}from"@solana/web3.js";import jr from"axios";import{PublicKey as Fe}from"@solana/web3.js";import _e from"bn.js";function se(t){return typeof t=="object"&&t!==null&&![h,T,Fe,i,_e,g,f].some(e=>typeof e=="object"&&t instanceof e)}import{Connection as ai}from"@solana/web3.js";var We=m("Sega_amount"),F=B(Ve);function ae(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")):We.logWithError(`invalid number string, num: ${t}`)}else n=t;return[n,r.slice(0,e)||r]}var T=class t extends i{constructor(e,n,r=!0,a){let c=new b(0),p=S.pow(new b(e.decimals));if(r)c=u(n);else{let l=new b(0),y=new b(0);if(typeof n=="string"||typeof n=="number"||typeof n=="bigint"){let[V,W]=ae(n.toString(),e.decimals);l=u(V),y=u(W)}l=l.mul(p),c=l.add(y)}super(c,p),this.logger=m(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 F.DP=this.token.decimals,new F(this.numerator.toString()).div(this.denominator.toString()).toFormat(e)}},_=class t extends i{constructor(e,n,r=!0,a){let c=new b(0),p=S.pow(new b(e.decimals));if(r)c=u(n);else{let l=new b(0),y=new b(0);if(typeof n=="string"||typeof n=="number"||typeof n=="bigint"){let[V,W]=ae(n.toString(),e.decimals);l=u(V),y=u(W)}l=l.mul(p),c=l.add(y)}super(c,p),this.logger=m(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 t(this.currency,this.raw.add(e.raw))}sub(e){return this.currency.equals(e.currency)||this.logger.logWithError("sub currency not equals"),new t(this.currency,this.raw.sub(e.raw))}toSignificant(e=this.currency.decimals,n,r=0){return super.toSignificant(e,n,r)}toFixed(e=this.currency.decimals,n,r=0){return e>this.currency.decimals&&this.logger.logWithError("decimals overflow"),super.toFixed(e,n,r)}toExact(e={groupSeparator:""}){return F.DP=this.currency.decimals,new F(this.numerator.toString()).div(this.denominator.toString()).toFormat(e)}};var Y=new s(0),$i=new s(1),Qi=new s(2),eo=new s(3),to=new s(5),S=new s(10),no=new s(100),ro=new s(1e3),io=new s(1e4);function j(t){return S.pow(u(t))}function A(t){var l;if(t===void 0)return{denominator:"1",numerator:"0"};if(t instanceof s)return{numerator:t.toString(),denominator:"1"};if(t instanceof i)return{denominator:t.denominator.toString(),numerator:t.numerator.toString()};let e=String(t),[,n="",r="",a=""]=(l=e.replace(",","").match(/(-?)(\d*)\.?(\d*)/))!=null?l:[],c="1"+"0".repeat(a.length),p=n+(r==="0"?"":r)+a||"0";return{denominator:c,numerator:p,sign:n,int:r,dec:a}}function oo(t,e){let n=t.divmod(e);return n.mod.isZero()?n.div:n.div.isNeg()?n.div.isubn(1):n.div.iaddn(1)}function ve(t){var r;let[,e="",n=""]=(r=t.toFixed(2).match(/(-?)(\d*)\.?(\d*)/))!=null?r:[];return`${e}${n}`}function qe(t,e=0){return t instanceof s?t:new s(ve(le(t).mul(S.pow(new s(String(e))))))}function le(t){if(t instanceof f)return new i(t.numerator,t.denominator);if(t instanceof g)return t.adjusted;if(t instanceof T)try{return le(t.toExact())}catch(r){return new i(Y)}if(t instanceof i)return t;let e=String(t),n=A(e);return new i(n.numerator,n.denominator)}function so(t,e){let{numerator:n,denominator:r}=A(t);return new f(new s(n),new s(r).mul(e!=null&&e.alreadyDecimaled?new s(100):new s(1)))}function ao(t){let{token:e,numberPrice:n,decimalDone:r}=t,a=new h({mint:"",decimals:6,symbol:"usd",name:"usd",skipMint:!0}),{numerator:c,denominator:p}=A(n),l=r?new s(c).mul(S.pow(new s(e.decimals))):c,y=new s(p).mul(S.pow(new s(a.decimals)));return new g({baseToken:a,denominator:y.toString(),quoteToken:new h(w(x({},e),{skipMint:!0,mint:""})),numerator:l.toString()})}function ce(t){let e=new N({decimals:6,symbol:"usd",name:"usd"}),n=qe(H(t,J(10,e.decimals)));return new _(e,n)}function co(t,e){return ce(!e||!t?0:H(t,e))}function Ue(t){if(t==null)return;let{numerator:e,denominator:n}=A(t.toString());return new i(e,n)}function Ge(t){return t instanceof Ke}function ue(t){return Ge(t)?Ue(t):Array.isArray(t)?t.map(e=>ue(e)):se(t)?Object.fromEntries(Object.entries(t).map(([e,n])=>[e,ue(n)])):t}export{no as BN_100,ro as BN_1000,io as BN_10000,to as BN_FIVE,$i as BN_ONE,S as BN_TEN,eo as BN_THREE,Qi as BN_TWO,Y as BN_ZERO,Ue as decimalToFraction,oo as divCeil,Ge as isDecimal,A as parseNumberInfo,ue as recursivelyDecimalToFraction,ve as shakeFractionDecimal,j as tenExponential,qe as toBN,le as toFraction,so as toPercent,ao as toTokenPrice,co as toTotalPrice,ce as toUsdCurrency};
//# sourceMappingURL=bignumber.mjs.map