UNPKG

@sega-so/sega-sdk

Version:

An SDK for building applications on top of SEGA.

2 lines 12.7 kB
var ne=Object.defineProperty,re=Object.defineProperties;var ie=Object.getOwnPropertyDescriptors;var G=Object.getOwnPropertySymbols;var oe=Object.prototype.hasOwnProperty,se=Object.prototype.propertyIsEnumerable;var j=(n,e,t)=>e in n?ne(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,T=(n,e)=>{for(var t in e||(e={}))oe.call(e,t)&&j(n,t,e[t]);if(G)for(var t of G(e))se.call(e,t)&&j(n,t,e[t]);return n},b=(n,e)=>re(n,ie(e));import Ie from"big.js";import f from"bn.js";import d from"bn.js";import Qt from"decimal.js";import{PublicKey as ae}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as H}from"@solana/spl-token";var Y={chainId:101,address:ae.default.toBase58(),programId:H.toBase58(),decimals:9,symbol:"SOL",name:"solana",logoURI:"https://img-v1.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"sega",extensions:{coingeckoId:"solana"}},h={chainId:101,address:"So11111111111111111111111111111111111111112",programId:H.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 V}from"@solana/web3.js";import{PublicKey as i,SystemProgram as z,SYSVAR_RENT_PUBKEY as ce}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as ue}from"@solana/spl-token";function F({pubkey:n,isSigner:e=!1,isWritable:t=!0}){return{pubkey:n,isWritable:t,isSigner:e}}var _e=[F({pubkey:ue,isWritable:!1}),F({pubkey:z.programId,isWritable:!1}),F({pubkey:ce,isWritable:!1})];function Z({publicKey:n,transformSol:e}){let t=J(n.toString());if(t instanceof i)return e&&t.equals(x)?_:t;if(e&&t.toString()===x.toBase58())return _;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 J(n){try{return new i(n)}catch(e){return n}}var Ve=new i("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),We=new i("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Ke=new i("SysvarRent111111111111111111111111111111111"),ve=new i("SysvarC1ock11111111111111111111111111111111"),le=new i("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),qe=new i("Sysvar1nstructions1111111111111111111111111"),Ue=z.programId,Ge=new i("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),je=new i("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),He=new i("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),Ye=new i("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),ze=new i("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),Ze=new i("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),Je=new i("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),Xe=new i("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),$e=new i("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),Qe=new i("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),et=new i("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),_=new i("So11111111111111111111111111111111111111112"),x=i.default;var B=class B{constructor({mint:e,decimals:t,symbol:r,name:c,skipMint:u=!1,isToken2022:g=!1}){if(e===x.toBase58()||e instanceof V&&x.equals(e)){this.decimals=h.decimals,this.symbol=h.symbol,this.name=h.name,this.mint=new V(h.address),this.isToken2022=!1;return}this.decimals=t,this.symbol=r||e.toString().substring(0,6),this.name=c||e.toString().substring(0,6),this.mint=u?V.default:Z({publicKey:e}),this.isToken2022=g}equals(e){return this===e?!0:this.mint.equals(e.mint)}};B.WSOL=new B(b(T({},h),{mint:h.address}));var p=B;var I=class I{constructor({decimals:e,symbol:t="UNKNOWN",name:r="UNKNOWN"}){this.decimals=e,this.symbol=t,this.name=r}equals(e){return this===e}};I.SOL=new I(Y);var W=I;function lt(n,e){return n instanceof p&&e instanceof p?n.equals(e):n instanceof p||e instanceof p?!1:n===e}import M from"big.js";import he from"bn.js";import Te from"decimal.js-light";import{get as X,set as me}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 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}},$={},pe={};function a(n){let e=X($,n);if(!e){let t=X(pe,n);e=new K({name:n,logLevel:t}),me($,n,e)}return e}import w from"bn.js";var Q=9007199254740991;function o(n){let e=a("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>=Q||n<=-Q)&&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 de from"toformat";var fe=de,P=fe;var R=a("module/fraction"),v=P(M),S=P(Te),be={0:S.ROUND_DOWN,1:S.ROUND_HALF_UP,2:S.ROUND_UP},ye={0:M.roundDown,1:M.roundHalfUp,2:M.roundUp},s=class n{constructor(e,t=new he(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)||R.logWithError(`${e} is not an integer.`),e<=0&&R.logWithError(`${e} is not positive.`),S.set({precision:e+1,rounding:be[r]});let c=new S(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(e);return c.toFormat(c.decimalPlaces(),t)}toFixed(e,t={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=ye[r]||1,new v(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,t)}isZero(){return this.numerator.isZero()}};import xe from"bn.js";var ee=new s(new xe(100)),A=class extends s{toSignificant(e=5,t,r){return this.mul(ee).toSignificant(e,t,r)}toFixed(e=2,t,r){return this.mul(ee).toFixed(e,t,r)}};var we=a("Sega_price"),k=class n extends s{constructor(e){let{baseToken:t,quoteToken:r,numerator:c,denominator:u}=e;super(c,u),this.baseToken=t,this.quoteToken=r,this.scalar=new s(q(t.decimals),q(r.decimals))}get raw(){return new s(this.numerator,this.denominator)}get adjusted(){return super.mul(this.scalar)}invert(){return new n({baseToken:this.quoteToken,quoteToken:this.baseToken,denominator:this.numerator,numerator:this.denominator})}mul(e){this.quoteToken!==e.baseToken&&we.logWithError("mul token not equals");let t=super.mul(e);return new n({baseToken:this.baseToken,quoteToken:e.quoteToken,denominator:t.denominator,numerator:t.numerator})}toSignificant(e=this.quoteToken.decimals,t,r){return this.adjusted.toSignificant(e,t,r)}toFixed(e=this.quoteToken.decimals,t,r){return this.adjusted.toFixed(e,t,r)}};import{PublicKey as vt}from"@solana/web3.js";import Ut from"bn.js";var Pe=new d(0),ln=new d(1),mn=new d(2),pn=new d(3),dn=new d(5),D=new d(10),fn=new d(100),gn=new d(1e3),hn=new d(1e4);function q(n){return D.pow(o(n))}import{PublicKey as An}from"@solana/web3.js";import{MINT_SIZE as In,TOKEN_PROGRAM_ID as Rn,getTransferFeeConfig as Mn,unpackMint as Nn}from"@solana/spl-token";var Dn=a("Sega_accountInfo_util");import{PublicKey as ar}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as ur}from"@solana/spl-token";import{ComputeBudgetProgram as qn,Keypair as jn,PublicKey as Hn,Transaction as zn,TransactionMessage as Jn,VersionedTransaction as Xn}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as tr}from"@solana/spl-token";var nr=a("Sega_txUtil");import{PublicKey as l}from"@solana/web3.js";var fr=new l("SegazTQwbYWknDZkJ6j2Kgvm5gw3MrHGKtWstZdoNKZ"),gr=new l("Ajk8d9bERSaFdeoT1d8JUVfaDayrYLnAdgeB47TFMUaG"),hr=new l("2HbjxVVKJ7Ct72Rcd8WK4VTqmwTXL5aAggkH1CHGFGmh"),Ae=new l("TegaRdjn9Qeh9DfUU28X19aPPpJtj9gs8ntSYrR5H4K "),ke=new l("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),Ce=new l("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),Tr=new l("SegaXNnoXYTZiqUt9Xn2XqGcL56b25yzXLuJSpadcMu"),br=new l("2t1hV2YqnDCPuJZqr7Fy8oAygGwZE5Q9uaQzpLC1QryJ"),yr=new l("BLxynZeHE123MmQgNJZiV1pwW4VYh46oZYyC66xwmtTY");var Be={SERUM_MARKET:l.default,UTIL1216:l.default,CREATE_CPMM_POOL_PROGRAM:Ae,CREATE_CPMM_POOL_AUTH:ke,CREATE_CPMM_POOL_FEE_ACC:Ce};import Pr from"bn.js";import{PublicKey as Ir,AddressLookupTableAccount as Rr}from"@solana/web3.js";import{PublicKey as Hr,sendAndConfirmTransaction as Yr,SystemProgram as Jr,Transaction as Xr,TransactionMessage as Qr,VersionedTransaction as ei}from"@solana/web3.js";import ni from"axios";import{Connection as pi}from"@solana/web3.js";var Re=a("Sega_amount"),L=P(Ie);function te(n,e){let t="0",r="0";if(n.includes(".")){let c=n.split(".");c.length===2?([t,r]=c,r=r.padEnd(e,"0")):Re.logWithError(`invalid number string, num: ${n}`)}else t=n;return[t,r.slice(0,e)||r]}var C=class n extends s{constructor(e,t,r=!0,c){let u=new f(0),g=D.pow(new f(e.decimals));if(r)u=o(t);else{let m=new f(0),y=new f(0);if(typeof t=="string"||typeof t=="number"||typeof t=="bigint"){let[O,E]=te(t.toString(),e.decimals);m=o(O),y=o(E)}m=m.mul(g),u=m.add(y)}super(u,g),this.logger=a(c||"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 L.DP=this.token.decimals,new L(this.numerator.toString()).div(this.denominator.toString()).toFormat(e)}},U=class n extends s{constructor(e,t,r=!0,c){let u=new f(0),g=D.pow(new f(e.decimals));if(r)u=o(t);else{let m=new f(0),y=new f(0);if(typeof t=="string"||typeof t=="number"||typeof t=="bigint"){let[O,E]=te(t.toString(),e.decimals);m=o(O),y=o(E)}m=m.mul(g),u=m.add(y)}super(u,g),this.logger=a(c||"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 L.DP=this.currency.decimals,new L(this.numerator.toString()).div(this.denominator.toString()).toFormat(e)}};export{W as Currency,U as CurrencyAmount,s as Fraction,A as Percent,k as Price,p as Token,C as TokenAmount,ee as _100_PERCENT,lt as currencyEquals,te as splitNumber}; //# sourceMappingURL=index.mjs.map