UNPKG

@sega-so/sega-sdk

Version:

An SDK for building applications on top of SEGA.

2 lines 12.4 kB
var re=Object.defineProperty,ie=Object.defineProperties;var oe=Object.getOwnPropertyDescriptors;var I=Object.getOwnPropertySymbols;var U=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable;var q=(t,e,n)=>e in t?re(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,u=(t,e)=>{for(var n in e||(e={}))U.call(e,n)&&q(t,n,e[n]);if(I)for(var n of I(e))G.call(e,n)&&q(t,n,e[n]);return t},p=(t,e)=>ie(t,oe(e));var B=(t,e)=>{var n={};for(var r in t)U.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&I)for(var r of I(t))e.indexOf(r)<0&&G.call(t,r)&&(n[r]=t[r]);return n};var b=(t,e,n)=>new Promise((r,o)=>{var s=m=>{try{h(n.next(m))}catch(w){o(w)}},x=m=>{try{h(n.throw(m))}catch(w){o(w)}},h=m=>m.done?r(m.value):Promise.resolve(m.value).then(s,x);h((n=n.apply(t,e)).next())});import{PublicKey as Re}from"@solana/web3.js";import{MintLayout as te,TOKEN_PROGRAM_ID as Me}from"@solana/spl-token";import Ce from"big.js";import O from"bn.js";import g from"bn.js";import nn from"decimal.js";import{PublicKey as se}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as j}from"@solana/spl-token";var P={chainId:101,address:se.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"}},d={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 V}from"@solana/web3.js";import{PublicKey as i,SystemProgram as H,SYSVAR_RENT_PUBKEY as ae}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as ce}from"@solana/spl-token";function D({pubkey:t,isSigner:e=!1,isWritable:n=!0}){return{pubkey:t,isWritable:n,isSigner:e}}var Ve=[D({pubkey:ce,isWritable:!1}),D({pubkey:H.programId,isWritable:!1}),D({pubkey:ae,isWritable:!1})];function _({publicKey:t,transformSol:e}){let n=Y(t.toString());if(n instanceof i)return e&&n.equals(S)?E:n;if(e&&n.toString()===S.toBase58())return E;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 Y(t){try{return new i(t)}catch(e){return t}}var We=new i("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Ke=new i("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),ve=new i("SysvarRent111111111111111111111111111111111"),qe=new i("SysvarC1ock11111111111111111111111111111111"),ue=new i("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),Ue=new i("Sysvar1nstructions1111111111111111111111111"),Ge=H.programId,je=new i("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),He=new i("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),Ye=new i("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),ze=new i("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),Ze=new i("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),Je=new i("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),Xe=new i("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),$e=new i("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),Qe=new i("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),et=new i("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),tt=new i("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),E=new i("So11111111111111111111111111111111111111112"),S=i.default;function R(t){return _({publicKey:t,transformSol:!0})}var M=class M{constructor({mint:e,decimals:n,symbol:r,name:o,skipMint:s=!1,isToken2022:x=!1}){if(e===S.toBase58()||e instanceof V&&S.equals(e)){this.decimals=d.decimals,this.symbol=d.symbol,this.name=d.name,this.mint=new V(d.address),this.isToken2022=!1;return}this.decimals=n,this.symbol=r||e.toString().substring(0,6),this.name=o||e.toString().substring(0,6),this.mint=s?V.default:_({publicKey:e}),this.isToken2022=x}equals(e){return this===e?!0:this.mint.equals(e.mint)}};M.WSOL=new M(p(u({},d),{mint:d.address}));var T=M;var N=class N{constructor({decimals:e,symbol:n="UNKNOWN",name:r="UNKNOWN"}){this.decimals=e,this.symbol=n,this.name=r}equals(e){return this===e}};N.SOL=new N(P);var W=N;import L from"big.js";import ge from"bn.js";import he from"decimal.js-light";import{get as z,set as le}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}},Z={},me={};function a(t){let e=z(Z,t);if(!e){let n=z(me,t);e=new K({name:t,logLevel:n}),le(Z,t,e)}return e}import k from"bn.js";var J=9007199254740991;function c(t){let e=a("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>=J||t<=-J)&&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 pe from"toformat";var de=pe,A=de;var F=a("module/fraction"),v=A(L),C=A(he),Te={0:C.ROUND_DOWN,1:C.ROUND_HALF_UP,2:C.ROUND_UP},be={0:L.roundDown,1:L.roundHalfUp,2:L.roundUp},f=class t{constructor(e,n=new ge(1)){this.numerator=c(e),this.denominator=c(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(c(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(c(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(c(e));return new t(this.numerator.mul(n.numerator),this.denominator.mul(n.denominator))}div(e){let n=e instanceof t?e:new t(c(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.`),C.set({precision:e+1,rounding:Te[r]});let o=new C(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(e);return o.toFormat(o.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.`),v.DP=e,v.RM=be[r]||1,new v(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,n)}isZero(){return this.numerator.isZero()}};import ye from"bn.js";var Rt=new f(new ye(100));var Dt=a("Sega_price");import{PublicKey as Gt}from"@solana/web3.js";import Ht from"bn.js";var xe=new g(0),dn=new g(1),fn=new g(2),gn=new g(3),hn=new g(5),Q=new g(10),Tn=new g(100),bn=new g(1e3),yn=new g(1e4);import{PublicKey as In}from"@solana/web3.js";import{MINT_SIZE as Nn,TOKEN_PROGRAM_ID as Fn,getTransferFeeConfig as Ln,unpackMint as On}from"@solana/spl-token";var Dn=a("Sega_accountInfo_util");import{PublicKey as lr}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as pr}from"@solana/spl-token";import{ComputeBudgetProgram as jn,Keypair as zn,PublicKey as Zn,Transaction as Xn,TransactionMessage as Qn,VersionedTransaction as er}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as ir}from"@solana/spl-token";var or=a("Sega_txUtil");import{PublicKey as l}from"@solana/web3.js";var Tr=new l("SegazTQwbYWknDZkJ6j2Kgvm5gw3MrHGKtWstZdoNKZ"),br=new l("Ajk8d9bERSaFdeoT1d8JUVfaDayrYLnAdgeB47TFMUaG"),yr=new l("2HbjxVVKJ7Ct72Rcd8WK4VTqmwTXL5aAggkH1CHGFGmh"),Pe=new l("TegaRdjn9Qeh9DfUU28X19aPPpJtj9gs8ntSYrR5H4K "),Se=new l("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),ke=new l("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),xr=new l("SegaXNnoXYTZiqUt9Xn2XqGcL56b25yzXLuJSpadcMu"),wr=new l("2t1hV2YqnDCPuJZqr7Fy8oAygGwZE5Q9uaQzpLC1QryJ"),Pr=new l("BLxynZeHE123MmQgNJZiV1pwW4VYh46oZYyC66xwmtTY");var Ae={SERUM_MARKET:l.default,UTIL1216:l.default,CREATE_CPMM_POOL_PROGRAM:Pe,CREATE_CPMM_POOL_AUTH:Se,CREATE_CPMM_POOL_FEE_ACC:ke};import Ar from"bn.js";import{PublicKey as Nr,AddressLookupTableAccount as Fr}from"@solana/web3.js";import{PublicKey as zr,sendAndConfirmTransaction as Zr,SystemProgram as $r,Transaction as Qr,TransactionMessage as ti,VersionedTransaction as ni}from"@solana/web3.js";import ii from"axios";import{Connection as fi}from"@solana/web3.js";var Ie=a("Sega_amount"),ee=A(Ce);function Be(t,e){let n="0",r="0";if(t.includes(".")){let o=t.split(".");o.length===2?([n,r]=o,r=r.padEnd(e,"0")):Ie.logWithError(`invalid number string, num: ${t}`)}else n=t;return[n,r.slice(0,e)||r]}var y=class t extends f{constructor(e,n,r=!0,o){let s=new O(0),x=Q.pow(new O(e.decimals));if(r)s=c(n);else{let h=new O(0),m=new O(0);if(typeof n=="string"||typeof n=="number"||typeof n=="bigint"){let[w,ne]=Be(n.toString(),e.decimals);h=c(w),m=c(ne)}h=h.mul(x),s=h.add(m)}super(s,x),this.logger=a(o||"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)}};var lo=n=>b(void 0,[n],function*({connection:t,mint:e}){let r=yield t.getAccountInfo(new Re(e));return!r||r.data.length!==te.span?void 0:te.decode(r.data)}),mo=({mint:t,decimals:e,programId:n=Me,logoURI:r="",priority:o=3})=>{let s=t.toBase58().substring(0,6);return{address:t.toBase58(),decimals:e,symbol:s,logoURI:r,extensions:{},chainId:101,programId:n.toString(),name:s,tags:[],priority:o}},po=t=>new T({mint:t.address,decimals:t.decimals,symbol:t.symbol,name:t.name}),fo=o=>{var s=o,{amount:t,isRaw:e,name:n}=s,r=B(s,["amount","isRaw","name"]);return new y(new T({mint:R(r.address).toBase58(),decimals:r.decimals,symbol:r.symbol,name:n}),t,e,n)};function go(t){return t.address===P.address?d:t}function ho(t){return t.address===d.address?P:t}var To=o=>{var s=o,{address:t,programId:e,decimals:n}=s,r=B(s,["address","programId","decimals"]);return u({chainId:101,address:R(t).toBase58(),programId:e,logoURI:"",symbol:"",name:"",decimals:n,tags:[],extensions:r.extensions||{}},r)},bo=t=>t?p(u({},t),{transferFeeConfigAuthority:t.transferFeeConfigAuthority.toBase58(),withdrawWithheldAuthority:t.withdrawWithheldAuthority.toBase58(),withheldAmount:t.withheldAmount.toString(),olderTransferFee:p(u({},t.olderTransferFee),{epoch:t.olderTransferFee.epoch.toString(),maximumFee:t.olderTransferFee.maximumFee.toString()}),newerTransferFee:p(u({},t.newerTransferFee),{epoch:t.newerTransferFee.epoch.toString(),maximumFee:t.newerTransferFee.maximumFee.toString()})}):void 0;export{lo as parseTokenInfo,go as solToWSolToken,To as toApiV3Token,bo as toFeeConfig,po as toToken,fo as toTokenAmount,mo as toTokenInfo,ho as wSolToSolToken}; //# sourceMappingURL=utils.mjs.map