@sega-so/sega-sdk
Version:
An SDK for building applications on top of SEGA.
2 lines • 14 kB
JavaScript
var he=Object.defineProperty,ye=Object.defineProperties;var be=Object.getOwnPropertyDescriptors;var L=Object.getOwnPropertySymbols;var $=Object.prototype.hasOwnProperty,Q=Object.prototype.propertyIsEnumerable;var X=(t,e,n)=>e in t?he(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,u=(t,e)=>{for(var n in e||(e={}))$.call(e,n)&&X(t,n,e[n]);if(L)for(var n of L(e))Q.call(e,n)&&X(t,n,e[n]);return t},m=(t,e)=>ye(t,be(e));var C=(t,e)=>{var n={};for(var r in t)$.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&L)for(var r of L(t))e.indexOf(r)<0&&Q.call(t,r)&&(n[r]=t[r]);return n};var b=(t,e,n)=>new Promise((r,i)=>{var s=l=>{try{g(n.next(l))}catch(P){i(P)}},x=l=>{try{g(n.throw(l))}catch(P){i(P)}},g=l=>l.done?r(l.value):Promise.resolve(l.value).then(s,x);g((n=n.apply(t,e)).next())});import{PublicKey as Te}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as ee}from"@solana/spl-token";var w={chainId:101,address:Te.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 Be}from"@solana/web3.js";import ne,{isBN as $t}from"bn.js";import{bits as Qe,BitStructure as et,blob as xe,Blob as tt,cstr as nt,f32 as rt,f32be as ot,f64 as it,f64be as st,greedy as at,Layout as Pe,ns64 as ut,ns64be as ct,nu64 as lt,nu64be as mt,offset as pt,s16 as dt,s16be as ft,s24 as gt,s24be as ht,s32 as yt,s32be as bt,s40 as Tt,s40be as xt,s48 as Pt,s48be as wt,s8 as St,seq as Bt,struct as kt,Structure as we,u16 as At,u16be as Lt,u24 as Ct,u24be as It,u32 as Nt,u32be as Dt,u40 as Rt,u40be as Ft,u48 as Mt,u48be as _t,u8 as Et,UInt as Se,union as Ot,Union as Vt,unionLayoutDiscriminator as Kt,utf8 as Wt}from"@solana/buffer-layout";var _=Pe,te=we;var E=Se;var O=xe;var V=class extends _{constructor(e,n,r){super(e,r),this.blob=O(e),this.signed=n}decode(e,n=0){let r=new ne(this.blob.decode(e,n),10,"le");return this.signed?r.fromTwos(this.span*8).clone():r}encode(e,n,r=0){return typeof e=="number"&&(e=new ne(e)),this.signed&&(e=e.toTwos(this.span*8)),this.blob.encode(e.toArrayLike(Buffer,"le",this.span),n,r)}};function v(t){return new E(1,t)}function U(t){return new E(4,t)}function re(t){return new V(8,!1,t)}var K=class extends _{constructor(e,n,r,i){super(e.span,i),this.layout=e,this.decoder=n,this.encoder=r}decode(e,n){return this.decoder(this.layout.decode(e,n))}encode(e,n,r){return this.layout.encode(this.encoder(e),n,r)}getSpan(e,n){return this.layout.getSpan(e,n)}};function q(t){return new K(O(32),e=>new Be(e),e=>e.toBuffer(),t)}var W=class extends te{decode(e,n){return super.decode(e,n)}};function oe(t,e,n){return new W(t,e,n)}var on=oe([U("mintAuthorityOption"),q("mintAuthority"),re("supply"),v("decimals"),v("isInitialized"),U("freezeAuthorityOption"),q("freezeAuthority")]);import{PublicKey as ze}from"@solana/web3.js";import{MintLayout as fe,TOKEN_PROGRAM_ID as He}from"@solana/spl-token";import qe from"big.js";import M from"bn.js";import f from"bn.js";import Cr from"decimal.js";import{PublicKey as H}from"@solana/web3.js";import{PublicKey as o,SystemProgram as ie,SYSVAR_RENT_PUBKEY as ke}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Ae}from"@solana/spl-token";function G({pubkey:t,isSigner:e=!1,isWritable:n=!0}){return{pubkey:t,isWritable:n,isSigner:e}}var ln=[G({pubkey:Ae,isWritable:!1}),G({pubkey:ie.programId,isWritable:!1}),G({pubkey:ke,isWritable:!1})];function z({publicKey:t,transformSol:e}){let n=se(t.toString());if(n instanceof o)return e&&n.equals(S)?j:n;if(e&&n.toString()===S.toBase58())return j;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 se(t){try{return new o(t)}catch(e){return t}}var mn=new o("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),pn=new o("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),dn=new o("SysvarRent111111111111111111111111111111111"),fn=new o("SysvarC1ock11111111111111111111111111111111"),Le=new o("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),gn=new o("Sysvar1nstructions1111111111111111111111111"),hn=ie.programId,yn=new o("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),bn=new o("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),Tn=new o("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),xn=new o("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),Pn=new o("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),wn=new o("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),Sn=new o("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),Bn=new o("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),kn=new o("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),An=new o("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),Ln=new o("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),j=new o("So11111111111111111111111111111111111111112"),S=o.default;function I(t){return z({publicKey:t,transformSol:!0})}var N=class N{constructor({mint:e,decimals:n,symbol:r,name:i,skipMint:s=!1,isToken2022:x=!1}){if(e===S.toBase58()||e instanceof H&&S.equals(e)){this.decimals=p.decimals,this.symbol=p.symbol,this.name=p.name,this.mint=new H(p.address),this.isToken2022=!1;return}this.decimals=n,this.symbol=r||e.toString().substring(0,6),this.name=i||e.toString().substring(0,6),this.mint=s?H.default:z({publicKey:e}),this.isToken2022=x}equals(e){return this===e?!0:this.mint.equals(e.mint)}};N.WSOL=new N(m(u({},p),{mint:p.address}));var h=N;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(w);var Y=D;import F from"big.js";import Fe from"bn.js";import Me from"decimal.js-light";import{get as ae,set as Ce}from"lodash";var J=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}},ue={},Ie={};function a(t){let e=ae(ue,t);if(!e){let n=ae(Ie,t);e=new J({name:t,logLevel:n}),Ce(ue,t,e)}return e}import B from"bn.js";var ce=9007199254740991;function c(t){let e=a("Sega_parseBigNumberish");if(t instanceof B)return t;if(typeof t=="string"){if(t.match(/^-?[0-9]+$/))return new B(t);e.logWithError(`invalid BigNumberish string: ${t}`)}return typeof t=="number"?(t%1&&e.logWithError(`BigNumberish number underflow: ${t}`),(t>=ce||t<=-ce)&&e.logWithError(`BigNumberish number overflow: ${t}`),new B(String(t))):typeof t=="bigint"?new B(t.toString()):(e.error(`invalid BigNumberish value: ${t}`),new B(0))}import Ne from"toformat";var De=Ne,k=De;var R=a("module/fraction"),Z=k(F),A=k(Me),_e={0:A.ROUND_DOWN,1:A.ROUND_HALF_UP,2:A.ROUND_UP},Ee={0:F.roundDown,1:F.roundHalfUp,2:F.roundUp},d=class t{constructor(e,n=new Fe(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)||R.logWithError(`${e} is not an integer.`),e<=0&&R.logWithError(`${e} is not positive.`),A.set({precision:e+1,rounding:_e[r]});let i=new A(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(e);return i.toFormat(i.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.`),Z.DP=e,Z.RM=Ee[r]||1,new Z(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,n)}isZero(){return this.numerator.isZero()}};import Oe from"bn.js";var tr=new d(new Oe(100));var ar=a("Sega_price");import{PublicKey as hr}from"@solana/web3.js";import br from"bn.js";var Ve=new f(0),Vr=new f(1),Kr=new f(2),Wr=new f(3),vr=new f(5),pe=new f(10),Ur=new f(100),qr=new f(1e3),Gr=new f(1e4);import{PublicKey as $r}from"@solana/web3.js";import{MINT_SIZE as no,TOKEN_PROGRAM_ID as ro,getTransferFeeConfig as oo,unpackMint as io}from"@solana/spl-token";var so=a("Sega_accountInfo_util");import{PublicKey as Eo}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Vo}from"@solana/spl-token";import{ComputeBudgetProgram as yo,Keypair as xo,PublicKey as Po,Transaction as So,TransactionMessage as ko,VersionedTransaction as Ao}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as No}from"@solana/spl-token";var Do=a("Sega_txUtil");import{PublicKey as y}from"@solana/web3.js";var qo=new y("SegazTQwbYWknDZkJ6j2Kgvm5gw3MrHGKtWstZdoNKZ"),Go=new y("Ajk8d9bERSaFdeoT1d8JUVfaDayrYLnAdgeB47TFMUaG"),jo=new y("2HbjxVVKJ7Ct72Rcd8WK4VTqmwTXL5aAggkH1CHGFGmh"),We=new y("auetiVUVJkRxvNPLYEvVnz8UJSqQ1VgoA83PcicHVD1"),ve=new y("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),Ue=new y("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y");var zo={SERUM_MARKET:y.default,UTIL1216:y.default,CREATE_CPMM_POOL_PROGRAM:We,CREATE_CPMM_POOL_AUTH:ve,CREATE_CPMM_POOL_FEE_ACC:Ue};import Jo from"bn.js";import{PublicKey as ti,AddressLookupTableAccount as ni}from"@solana/web3.js";import{PublicKey as bi,sendAndConfirmTransaction as Ti,SystemProgram as wi,Transaction as Si,TransactionMessage as ki,VersionedTransaction as Ai}from"@solana/web3.js";import Ci from"axios";import{Connection as Ei}from"@solana/web3.js";var Ge=a("Sega_amount"),de=k(qe);function je(t,e){let n="0",r="0";if(t.includes(".")){let i=t.split(".");i.length===2?([n,r]=i,r=r.padEnd(e,"0")):Ge.logWithError(`invalid number string, num: ${t}`)}else n=t;return[n,r.slice(0,e)||r]}var T=class t extends d{constructor(e,n,r=!0,i){let s=new M(0),x=pe.pow(new M(e.decimals));if(r)s=c(n);else{let g=new M(0),l=new M(0);if(typeof n=="string"||typeof n=="number"||typeof n=="bigint"){let[P,ge]=je(n.toString(),e.decimals);g=c(P),l=c(ge)}g=g.mul(x),s=g.add(l)}super(s,x),this.logger=a(i||"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 de.DP=this.token.decimals,new de(this.numerator.toString()).div(this.denominator.toString()).toFormat(e)}};var Ns=n=>b(void 0,[n],function*({connection:t,mint:e}){let r=yield t.getAccountInfo(new ze(e));return!r||r.data.length!==fe.span?void 0:fe.decode(r.data)}),Ds=({mint:t,decimals:e,programId:n=He,logoURI:r="",priority:i=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:i}},Rs=t=>new h({mint:t.address,decimals:t.decimals,symbol:t.symbol,name:t.name}),Fs=i=>{var s=i,{amount:t,isRaw:e,name:n}=s,r=C(s,["amount","isRaw","name"]);return new T(new h({mint:I(r.address).toBase58(),decimals:r.decimals,symbol:r.symbol,name:n}),t,e,n)};function Ms(t){return t.address===w.address?p:t}function _s(t){return t.address===p.address?w:t}var Es=i=>{var s=i,{address:t,programId:e,decimals:n}=s,r=C(s,["address","programId","decimals"]);return u({chainId:101,address:I(t).toBase58(),programId:e,logoURI:"",symbol:"",name:"",decimals:n,tags:[],extensions:r.extensions||{}},r)},Os=t=>t?m(u({},t),{transferFeeConfigAuthority:t.transferFeeConfigAuthority.toBase58(),withdrawWithheldAuthority:t.withdrawWithheldAuthority.toBase58(),withheldAmount:t.withheldAmount.toString(),olderTransferFee:m(u({},t.olderTransferFee),{epoch:t.olderTransferFee.epoch.toString(),maximumFee:t.olderTransferFee.maximumFee.toString()}),newerTransferFee:m(u({},t.newerTransferFee),{epoch:t.newerTransferFee.epoch.toString(),maximumFee:t.newerTransferFee.maximumFee.toString()})}):void 0;export{w as SOL_INFO,on as SPL_MINT_LAYOUT,p as TOKEN_WSOL,Ns as parseTokenInfo,Ms as solToWSolToken,Es as toApiV3Token,Os as toFeeConfig,Rs as toToken,Fs as toTokenAmount,Ds as toTokenInfo,_s as wSolToSolToken};
//# sourceMappingURL=index.mjs.map