UNPKG

@sega-so/sega-sdk

Version:

An SDK for building applications on top of SEGA.

2 lines 15.1 kB
var me=Object.defineProperty,pe=Object.defineProperties;var de=Object.getOwnPropertyDescriptors;var Y=Object.getOwnPropertySymbols;var fe=Object.prototype.hasOwnProperty,ge=Object.prototype.propertyIsEnumerable;var Z=Math.pow,J=(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)&&J(t,n,e[n]);if(Y)for(var n of Y(e))ge.call(e,n)&&J(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 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}},$={},Te={};function m(t){let e=X($,t);if(!e){let n=X(Te,t);e=new v({name:t,logLevel:n}),he($,t,e)}return e}import{PublicKey as Xe}from"@solana/web3.js";import{MINT_SIZE as tt,TOKEN_PROGRAM_ID as nt,getTransferFeeConfig as rt,unpackMint as it}from"@solana/spl-token";var ot=m("Sega_accountInfo_util");import A from"bn.js";var Q=9007199254740991;function u(t){let e=m("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>=Q||t<=-Q)&&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{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 xt=[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(B)?_:n;if(e&&n.toString()===B.toBase58())return _;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 wt=new o("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Pt=new o("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),St=new o("SysvarRent111111111111111111111111111111111"),kt=new o("SysvarC1ock11111111111111111111111111111111"),we=new o("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),At=new o("Sysvar1nstructions1111111111111111111111111"),Bt=ne.programId,Ct=new o("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),It=new o("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),Nt=new o("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),Rt=new o("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),Dt=new o("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),Mt=new o("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),Ft=new o("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),Lt=new o("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),Et=new o("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),Ot=new o("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),Vt=new o("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),_=new o("So11111111111111111111111111111111111111112"),B=o.default;var R=class R{constructor({mint:e,decimals:n,symbol:r,name:a,skipMint:c=!1,isToken2022:p=!1}){if(e===B.toBase58()||e instanceof U&&B.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)}};R.WSOL=new R(w(x({},P),{mint:P.address}));var g=R;var M=class M{constructor({decimals:e,symbol:n="UNKNOWN",name:r="UNKNOWN"}){this.decimals=e,this.symbol=n,this.name=r}equals(e){return this===e}};M.SOL=new M(te);var D=M;import Pe from"toformat";var Se=Pe,C=Se;import L from"big.js";import Ae from"bn.js";import Be from"decimal.js-light";var F=m("module/fraction"),G=C(L),I=C(Be),Ce={0:I.ROUND_DOWN,1:I.ROUND_HALF_UP,2:I.ROUND_UP},Ie={0:L.roundDown,1:L.roundHalfUp,2:L.roundUp},i=class t{constructor(e,n=new Ae(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)||F.logWithError(`${e} is not an integer.`),e<=0&&F.logWithError(`${e} is not positive.`),I.set({precision:e+1,rounding:Ce[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)||F.logWithError(`${e} is not an integer.`),e<0&&F.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 Ne from"bn.js";var oe=new i(new Ne(100)),d=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 Re=m("Sega_price"),f=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&&Re.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 d)return new i(t.numerator,t.denominator);if(t instanceof f)return t.adjusted;if(t instanceof h)try{return E(t.toExact())}catch(r){return new i(z)}if(t instanceof i)return t;let e=String(t),n=k(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 Xn}from"@solana/spl-token";import{ComputeBudgetProgram as Rn,Keypair as Fn,PublicKey as Ln,Transaction as On,TransactionMessage as Wn,VersionedTransaction as Kn}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Un}from"@solana/spl-token";var Gn=m("Sega_txUtil");import{PublicKey as T}from"@solana/web3.js";var nr=new T("SegazTQwbYWknDZkJ6j2Kgvm5gw3MrHGKtWstZdoNKZ"),rr=new T("Ajk8d9bERSaFdeoT1d8JUVfaDayrYLnAdgeB47TFMUaG"),ir=new T("2HbjxVVKJ7Ct72Rcd8WK4VTqmwTXL5aAggkH1CHGFGmh"),Me=new T("auetiVUVJkRxvNPLYEvVnz8UJSqQ1VgoA83PcicHVD1"),Fe=new T("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),Le=new T("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y");var or={SERUM_MARKET:T.default,UTIL1216:T.default,CREATE_CPMM_POOL_PROGRAM:Me,CREATE_CPMM_POOL_AUTH:Fe,CREATE_CPMM_POOL_FEE_ACC:Le};import cr from"bn.js";import{PublicKey as fr,AddressLookupTableAccount as gr}from"@solana/web3.js";import{PublicKey as Mr,sendAndConfirmTransaction as Fr,SystemProgram as Or,Transaction as Vr,TransactionMessage as Kr,VersionedTransaction as vr}from"@solana/web3.js";import qr from"axios";import{PublicKey as Ee}from"@solana/web3.js";import Oe from"bn.js";function se(t){return typeof t=="object"&&t!==null&&![g,h,Ee,i,Oe,f,d].some(e=>typeof e=="object"&&t instanceof e)}import{Connection as ni}from"@solana/web3.js";var We=m("Sega_amount"),O=C(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 h=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[W,K]=ae(n.toString(),e.decimals);l=u(W),y=u(K)}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 O.DP=this.token.decimals,new O(this.numerator.toString()).div(this.denominator.toString()).toFormat(e)}},V=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[W,K]=ae(n.toString(),e.decimals);l=u(W),y=u(K)}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 O.DP=this.currency.decimals,new O(this.numerator.toString()).div(this.denominator.toString()).toFormat(e)}};var z=new s(0),ji=new s(1),Hi=new s(2),zi=new s(3),Yi=new s(5),S=new s(10),Ji=new s(100),Zi=new s(1e3),Xi=new s(1e4);function j(t){return S.pow(u(t))}function k(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 $i(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 _e(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 d)return new i(t.numerator,t.denominator);if(t instanceof f)return t.adjusted;if(t instanceof h)try{return le(t.toExact())}catch(r){return new i(z)}if(t instanceof i)return t;let e=String(t),n=k(e);return new i(n.numerator,n.denominator)}function Qi(t,e){let{numerator:n,denominator:r}=k(t);return new d(new s(n),new s(r).mul(e!=null&&e.alreadyDecimaled?new s(100):new s(1)))}function eo(t){let{token:e,numberPrice:n,decimalDone:r}=t,a=new g({mint:"",decimals:6,symbol:"usd",name:"usd",skipMint:!0}),{numerator:c,denominator:p}=k(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 f({baseToken:a,denominator:y.toString(),quoteToken:new g(w(x({},e),{skipMint:!0,mint:""})),numerator:l.toString()})}function ce(t){let e=new D({decimals:6,symbol:"usd",name:"usd"}),n=_e(H(t,Z(10,e.decimals)));return new V(e,n)}function to(t,e){return ce(!e||!t?0:H(t,e))}function qe(t){if(t==null)return;let{numerator:e,denominator:n}=k(t.toString());return new i(e,n)}function Ue(t){return t instanceof Ke}function ue(t){return Ue(t)?qe(t):Array.isArray(t)?t.map(e=>ue(e)):se(t)?Object.fromEntries(Object.entries(t).map(([e,n])=>[e,ue(n)])):t}export{Ji as BN_100,Zi as BN_1000,Xi as BN_10000,Yi as BN_FIVE,ji as BN_ONE,S as BN_TEN,zi as BN_THREE,Hi as BN_TWO,z as BN_ZERO,qe as decimalToFraction,$i as divCeil,Ue as isDecimal,k as parseNumberInfo,ue as recursivelyDecimalToFraction,ve as shakeFractionDecimal,j as tenExponential,_e as toBN,le as toFraction,Qi as toPercent,eo as toTokenPrice,to as toTotalPrice,ce as toUsdCurrency}; //# sourceMappingURL=bignumber.mjs.map