UNPKG

@sega-so/sega-sdk

Version:

An SDK for building applications on top of SEGA.

2 lines 11.1 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,d=(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},b=(t,e)=>ce(t,ue(e));var f=(t,e,n)=>new Promise((r,s)=>{var c=o=>{try{p(n.next(o))}catch(a){s(a)}},m=o=>{try{p(n.throw(o))}catch(a){s(a)}},p=o=>o.done?r(o.value):Promise.resolve(o.value).then(c,m);p((n=n.apply(t,e)).next())});import{PublicKey as ne}from"@solana/web3.js";import T from"bn.js";import En from"decimal.js";import we from"big.js";import it from"bn.js";import{get as G,set as pe}from"lodash";var O=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 O({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 g(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 B=u("module/fraction"),E=P(I),A=P(be),ye={0:A.ROUND_DOWN,1:A.ROUND_HALF_UP,2:A.ROUND_UP},xe={0:I.roundDown,1:I.roundHalfUp,2:I.roundUp},h=class t{constructor(e,n=new Te(1)){this.numerator=g(e),this.denominator=g(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(g(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(g(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(g(e));return new t(this.numerator.mul(n.numerator),this.denominator.mul(n.denominator))}div(e){let n=e instanceof t?e:new t(g(e));return new t(this.numerator.mul(n.denominator),this.denominator.mul(n.numerator))}toSignificant(e,n={groupSeparator:""},r=1){Number.isInteger(e)||B.logWithError(`${e} is not an integer.`),e<=0&&B.logWithError(`${e} is not positive.`),A.set({precision:e+1,rounding:ye[r]});let s=new A(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)||B.logWithError(`${e} is not an integer.`),e<0&&B.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 dt=u("Sega_amount"),ft=P(we);import{PublicKey as Se}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Y}from"@solana/spl-token";var z={chainId:101,address:Se.default.toBase58(),programId:Y.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:Y.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 Ae}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as ke}from"@solana/spl-token";function F({pubkey:t,isSigner:e=!1,isWritable:n=!0}){return{pubkey:t,isWritable:n,isSigner:e}}var Pt=[F({pubkey:ke,isWritable:!1}),F({pubkey:Z.programId,isWritable:!1}),F({pubkey:Ae,isWritable:!1})];function _({publicKey:t,transformSol:e}){let n=J(t.toString());if(n instanceof i)return e&&n.equals(k)?R:n;if(e&&n.toString()===k.toBase58())return R;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 J(t){try{return new i(t)}catch(e){return t}}var St=new i("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),At=new i("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),kt=new i("SysvarRent111111111111111111111111111111111"),Ct=new i("SysvarC1ock11111111111111111111111111111111"),Ce=new i("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),Bt=new i("Sysvar1nstructions1111111111111111111111111"),It=Z.programId,Rt=new i("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),Mt=new i("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),Nt=new i("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),Dt=new i("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),Lt=new i("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),Ot=new i("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),Et=new i("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),Ft=new i("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),_t=new i("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),Vt=new i("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),Wt=new i("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),R=new i("So11111111111111111111111111111111111111112"),k=i.default;function X(t){return _({publicKey:t,transformSol:!0})}var M=class M{constructor({mint:e,decimals:n,symbol:r,name:s,skipMint:c=!1,isToken2022:m=!1}){if(e===k.toBase58()||e instanceof V&&k.equals(e)){this.decimals=x.decimals,this.symbol=x.symbol,this.name=x.name,this.mint=new V(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?V.default:_({publicKey:e}),this.isToken2022=m}equals(e){return this===e?!0:this.mint.equals(e.mint)}};M.WSOL=new M(b(d({},x),{mint:x.address}));var C=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(z);var W=N;import Be from"bn.js";var $t=new h(new Be(100));var on=u("Sega_price");import{PublicKey as Pn}from"@solana/web3.js";import An from"bn.js";var Ie=new T(0),jn=new T(1),Hn=new T(2),Yn=new T(3),zn=new T(5),Pe=new T(10),Zn=new T(100),Jn=new T(1e3),Xn=new T(1e4);function K(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 sr,Keypair as ur,PublicKey as lr,Transaction as pr,TransactionMessage as fr,VersionedTransaction as gr}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as yr}from"@solana/spl-token";var xr=u("Sega_txUtil");import{PublicKey as l}from"@solana/web3.js";var Dr=new l("SegazTQwbYWknDZkJ6j2Kgvm5gw3MrHGKtWstZdoNKZ"),Lr=new l("Ajk8d9bERSaFdeoT1d8JUVfaDayrYLnAdgeB47TFMUaG"),Or=new l("2HbjxVVKJ7Ct72Rcd8WK4VTqmwTXL5aAggkH1CHGFGmh"),Me=new l("TegaRdjn9Qeh9DfUU28X19aPPpJtj9gs8ntSYrR5H4K "),Ne=new l("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),De=new l("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),Er=new l("SegaXNnoXYTZiqUt9Xn2XqGcL56b25yzXLuJSpadcMu"),Fr=new l("2t1hV2YqnDCPuJZqr7Fy8oAygGwZE5Q9uaQzpLC1QryJ"),_r=new l("BLxynZeHE123MmQgNJZiV1pwW4VYh46oZYyC66xwmtTY");var Le={SERUM_MARKET:l.default,UTIL1216:l.default,CREATE_CPMM_POOL_PROGRAM:Me,CREATE_CPMM_POOL_AUTH:Ne,CREATE_CPMM_POOL_FEE_ACC:De};import Kr from"bn.js";import{PublicKey as jr,AddressLookupTableAccount as Hr}from"@solana/web3.js";import{PublicKey as ui,sendAndConfirmTransaction as li,SystemProgram as di,Transaction as fi,TransactionMessage as hi,VersionedTransaction as Ti}from"@solana/web3.js";import yi from"axios";import{Connection as Ri}from"@solana/web3.js";import{MINT_SIZE as Oe,TOKEN_PROGRAM_ID as Ee,getTransferFeeConfig as Fe,unpackMint as _e}from"@solana/spl-token";var v=u("Sega_accountInfo_util");function te(t,e,n){return f(this,null,function*(){let{batchRequest:r,commitment:s="confirmed",chunkCount:c=100}=d({batchRequest:!1},n),m=K(e,c),p=new Array(m.length).fill([]);if(r){let o=m.map(y=>({methodName:"getMultipleAccounts",args:t._buildArgs([y.map(w=>w.toBase58())],s,"base64")})),a=K(o,10);p=(yield(yield Promise.all(a.map(y=>f(this,null,function*(){return yield t._rpcBatchRequest(y)})))).flat()).map(y=>(y.error&&v.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${y.error.message}`),y.result.value.map(L=>{if(L){let{data:w,executable:re,lamports:ie,owner:oe,rentEpoch:se}=L;return w.length!==2&&w[1]!=="base64"&&v.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{p=yield Promise.all(m.map(o=>t.getMultipleAccountsInfo(o,s)))}catch(o){o instanceof Error&&v.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${o.message}`)}return p.flat()})}function Ve(t,e,n){return f(this,null,function*(){let r=yield te(t,e.map(s=>s.pubkey),n);return e.map((s,c)=>b(d({},s),{accountInfo:r[c]}))})}var We=(r=>(r[r.Uninitialized=0]="Uninitialized",r[r.Mint=1]="Mint",r[r.Account=2]="Account",r))(We||{}),oo=1;function so(r){return f(this,arguments,function*({connection:t,mints:e,config:n}){var m,p,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<Oe){console.log("invalid mint account",a.pubkey.toBase58());continue}let D=_e(a.pubkey,a.accountInfo,(m=a.accountInfo)==null?void 0:m.owner);c[a.pubkey.toString()]=b(d({},D),{programId:((p=a.accountInfo)==null?void 0:p.owner)||Ee,feeConfig:(o=Fe(D))!=null?o:void 0})}return c[ne.default.toBase58()]=c[R.toBase58()],c})}export{oo as ACCOUNT_TYPE_SIZE,We as AccountType,so as fetchMultipleMintInfos,te as getMultipleAccountsInfo,Ve as getMultipleAccountsInfoWithCustomFlags}; //# sourceMappingURL=accountInfo.mjs.map