UNPKG

@sega-so/sega-sdk

Version:

An SDK for building applications on top of SEGA.

2 lines 11 kB
var ae=Object.defineProperty,ce=Object.defineProperties;var ue=Object.getOwnPropertyDescriptors;var q=Object.getOwnPropertySymbols;var le=Object.prototype.hasOwnProperty,me=Object.prototype.propertyIsEnumerable;var U=(t,e,n)=>e in t?ae(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,p=(t,e)=>{for(var n in e||(e={}))le.call(e,n)&&U(t,n,e[n]);if(q)for(var n of q(e))me.call(e,n)&&U(t,n,e[n]);return t},T=(t,e)=>ce(t,ue(e));var d=(t,e,n)=>new Promise((r,s)=>{var c=o=>{try{m(n.next(o))}catch(a){s(a)}},l=o=>{try{m(n.throw(o))}catch(a){s(a)}},m=o=>o.done?r(o.value):Promise.resolve(o.value).then(c,l);m((n=n.apply(t,e)).next())});import{PublicKey as ne}from"@solana/web3.js";import h from"bn.js";import Ln from"decimal.js";import we from"big.js";import rt from"bn.js";import{get as G,set as pe}from"lodash";var L=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}},j={},de={};function u(t){let e=G(j,t);if(!e){let n=G(de,t);e=new L({name:t,logLevel:n}),pe(j,t,e)}return e}import fe from"toformat";var ge=fe,P=ge;import I from"big.js";import Te from"bn.js";import be from"decimal.js-light";import S from"bn.js";var H=9007199254740991;function f(t){let e=u("Sega_parseBigNumberish");if(t instanceof S)return t;if(typeof t=="string"){if(t.match(/^-?[0-9]+$/))return new S(t);e.logWithError(`invalid BigNumberish string: ${t}`)}return typeof t=="number"?(t%1&&e.logWithError(`BigNumberish number underflow: ${t}`),(t>=H||t<=-H)&&e.logWithError(`BigNumberish number overflow: ${t}`),new S(String(t))):typeof t=="bigint"?new S(t.toString()):(e.error(`invalid BigNumberish value: ${t}`),new S(0))}var C=u("module/fraction"),E=P(I),k=P(be),ye={0:k.ROUND_DOWN,1:k.ROUND_HALF_UP,2:k.ROUND_UP},xe={0:I.roundDown,1:I.roundHalfUp,2:I.roundUp},g=class t{constructor(e,n=new Te(1)){this.numerator=f(e),this.denominator=f(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(f(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(f(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(f(e));return new t(this.numerator.mul(n.numerator),this.denominator.mul(n.denominator))}div(e){let n=e instanceof t?e:new t(f(e));return new t(this.numerator.mul(n.denominator),this.denominator.mul(n.numerator))}toSignificant(e,n={groupSeparator:""},r=1){Number.isInteger(e)||C.logWithError(`${e} is not an integer.`),e<=0&&C.logWithError(`${e} is not positive.`),k.set({precision:e+1,rounding:ye[r]});let s=new k(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(e);return s.toFormat(s.decimalPlaces(),n)}toFixed(e,n={groupSeparator:""},r=1){return Number.isInteger(e)||C.logWithError(`${e} is not an integer.`),e<0&&C.logWithError(`${e} is negative.`),E.DP=e,E.RM=xe[r]||1,new E(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,n)}isZero(){return this.numerator.isZero()}};var pt=u("Sega_amount"),dt=P(we);import{PublicKey as Se}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as z}from"@solana/spl-token";var Y={chainId:101,address:Se.default.toBase58(),programId:z.toBase58(),decimals:9,symbol:"SOL",name:"solana",logoURI:"https://img-v1.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"sega",extensions:{coingeckoId:"solana"}},x={chainId:101,address:"So11111111111111111111111111111111111111112",programId:z.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 W}from"@solana/web3.js";import{PublicKey as i,SystemProgram as J,SYSVAR_RENT_PUBKEY as ke}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Ae}from"@solana/spl-token";function O({pubkey:t,isSigner:e=!1,isWritable:n=!0}){return{pubkey:t,isWritable:n,isSigner:e}}var wt=[O({pubkey:Ae,isWritable:!1}),O({pubkey:J.programId,isWritable:!1}),O({pubkey:ke,isWritable:!1})];function V({publicKey:t,transformSol:e}){let n=Z(t.toString());if(n instanceof i)return e&&n.equals(A)?N:n;if(e&&n.toString()===A.toBase58())return N;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 Z(t){try{return new i(t)}catch(e){return t}}var Pt=new i("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),St=new i("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),kt=new i("SysvarRent111111111111111111111111111111111"),At=new i("SysvarC1ock11111111111111111111111111111111"),Be=new i("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),Bt=new i("Sysvar1nstructions1111111111111111111111111"),Ct=J.programId,It=new i("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),Nt=new i("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),Rt=new i("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),Dt=new i("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),Mt=new i("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),Ft=new i("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),Lt=new i("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),Et=new i("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),Ot=new i("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),Vt=new i("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),Wt=new i("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),N=new i("So11111111111111111111111111111111111111112"),A=i.default;function X(t){return V({publicKey:t,transformSol:!0})}var R=class R{constructor({mint:e,decimals:n,symbol:r,name:s,skipMint:c=!1,isToken2022:l=!1}){if(e===A.toBase58()||e instanceof W&&A.equals(e)){this.decimals=x.decimals,this.symbol=x.symbol,this.name=x.name,this.mint=new W(x.address),this.isToken2022=!1;return}this.decimals=n,this.symbol=r||e.toString().substring(0,6),this.name=s||e.toString().substring(0,6),this.mint=c?W.default:V({publicKey:e}),this.isToken2022=l}equals(e){return this===e?!0:this.mint.equals(e.mint)}};R.WSOL=new R(T(p({},x),{mint:x.address}));var B=R;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(Y);var K=D;import Ce from"bn.js";var Xt=new g(new Ce(100));var rn=u("Sega_price");import{PublicKey as wn}from"@solana/web3.js";import Sn from"bn.js";var Ie=new h(0),Gn=new h(1),jn=new h(2),Hn=new h(3),zn=new h(5),Pe=new h(10),Yn=new h(100),Jn=new h(1e3),Zn=new h(1e4);function v(t,e=1,n=[]){let r=[...t];if(e<=0)return n;for(;r.length;)n.push(r.splice(0,e));return n}import{PublicKey as kr}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Br}from"@solana/spl-token";import{ComputeBudgetProgram as or,Keypair as cr,PublicKey as ur,Transaction as mr,TransactionMessage as dr,VersionedTransaction as fr}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as br}from"@solana/spl-token";var yr=u("Sega_txUtil");import{PublicKey as b}from"@solana/web3.js";var Dr=new b("SegazTQwbYWknDZkJ6j2Kgvm5gw3MrHGKtWstZdoNKZ"),Mr=new b("Ajk8d9bERSaFdeoT1d8JUVfaDayrYLnAdgeB47TFMUaG"),Fr=new b("2HbjxVVKJ7Ct72Rcd8WK4VTqmwTXL5aAggkH1CHGFGmh"),Re=new b("auetiVUVJkRxvNPLYEvVnz8UJSqQ1VgoA83PcicHVD1"),De=new b("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),Me=new b("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y");var Lr={SERUM_MARKET:b.default,UTIL1216:b.default,CREATE_CPMM_POOL_PROGRAM:Re,CREATE_CPMM_POOL_AUTH:De,CREATE_CPMM_POOL_FEE_ACC:Me};import Vr from"bn.js";import{PublicKey as qr,AddressLookupTableAccount as Ur}from"@solana/web3.js";import{PublicKey as si,sendAndConfirmTransaction as ai,SystemProgram as li,Transaction as mi,TransactionMessage as di,VersionedTransaction as fi}from"@solana/web3.js";import hi from"axios";import{Connection as ki}from"@solana/web3.js";import{MINT_SIZE as Fe,TOKEN_PROGRAM_ID as Le,getTransferFeeConfig as Ee,unpackMint as Oe}from"@solana/spl-token";var _=u("Sega_accountInfo_util");function te(t,e,n){return d(this,null,function*(){let{batchRequest:r,commitment:s="confirmed",chunkCount:c=100}=p({batchRequest:!1},n),l=v(e,c),m=new Array(l.length).fill([]);if(r){let o=l.map(y=>({methodName:"getMultipleAccounts",args:t._buildArgs([y.map(w=>w.toBase58())],s,"base64")})),a=v(o,10);m=(yield(yield Promise.all(a.map(y=>d(this,null,function*(){return yield t._rpcBatchRequest(y)})))).flat()).map(y=>(y.error&&_.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${y.error.message}`),y.result.value.map(F=>{if(F){let{data:w,executable:re,lamports:ie,owner:oe,rentEpoch:se}=F;return w.length!==2&&w[1]!=="base64"&&_.logWithError("info must be base64 encoded, RPC_ERROR"),{data:Buffer.from(w[0],"base64"),executable:re,lamports:ie,owner:new ne(oe),rentEpoch:se}}return null})))}else try{m=yield Promise.all(l.map(o=>t.getMultipleAccountsInfo(o,s)))}catch(o){o instanceof Error&&_.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${o.message}`)}return m.flat()})}function Ve(t,e,n){return d(this,null,function*(){let r=yield te(t,e.map(s=>s.pubkey),n);return e.map((s,c)=>T(p({},s),{accountInfo:r[c]}))})}var We=(r=>(r[r.Uninitialized=0]="Uninitialized",r[r.Mint=1]="Mint",r[r.Account=2]="Account",r))(We||{}),$i=1;function Qi(r){return d(this,arguments,function*({connection:t,mints:e,config:n}){var l,m,o;if(e.length===0)return{};let s=yield Ve(t,e.map(a=>({pubkey:X(a)})),n),c={};for(let a of s){if(!a.accountInfo||a.accountInfo.data.length<Fe){console.log("invalid mint account",a.pubkey.toBase58());continue}let M=Oe(a.pubkey,a.accountInfo,(l=a.accountInfo)==null?void 0:l.owner);c[a.pubkey.toString()]=T(p({},M),{programId:((m=a.accountInfo)==null?void 0:m.owner)||Le,feeConfig:(o=Ee(M))!=null?o:void 0})}return c[ne.default.toBase58()]=c[N.toBase58()],c})}export{$i as ACCOUNT_TYPE_SIZE,We as AccountType,Qi as fetchMultipleMintInfos,te as getMultipleAccountsInfo,Ve as getMultipleAccountsInfoWithCustomFlags}; //# sourceMappingURL=accountInfo.mjs.map