UNPKG

@sega-so/sega-sdk

Version:

An SDK for building applications on top of SEGA.

2 lines 9.61 kB
var J=Object.defineProperty,X=Object.defineProperties;var $=Object.getOwnPropertyDescriptors;var W=Object.getOwnPropertySymbols;var Q=Object.prototype.hasOwnProperty,ee=Object.prototype.propertyIsEnumerable;var V=(n,e,t)=>e in n?J(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,g=(n,e)=>{for(var t in e||(e={}))Q.call(e,t)&&V(n,t,e[t]);if(W)for(var t of W(e))ee.call(e,t)&&V(n,t,e[t]);return n},h=(n,e)=>X(n,$(e));import B from"bn.js";import no from"bn.js";import io from"decimal.js-light";import{PublicKey as Ee}from"@solana/web3.js";import{get as v,set as te}from"lodash";var R=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(i=>typeof i=="object"?JSON.stringify(i):i).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}},K={},ne={};function o(n){let e=v(K,n);if(!e){let t=v(ne,n);e=new R({name:n,logLevel:t}),te(K,n,e)}return e}import{MINT_SIZE as Ve,TOKEN_PROGRAM_ID as ve,getTransferFeeConfig as Ke,unpackMint as _e}from"@solana/spl-token";var qe=o("Sega_accountInfo_util");import l from"bn.js";import Vn from"decimal.js";import le from"big.js";import ct from"bn.js";import re from"toformat";var ie=re,T=ie;import A from"big.js";import se from"bn.js";import ae from"decimal.js-light";import y from"bn.js";var _=9007199254740991;function c(n){let e=o("Sega_parseBigNumberish");if(n instanceof y)return n;if(typeof n=="string"){if(n.match(/^-?[0-9]+$/))return new y(n);e.logWithError(`invalid BigNumberish string: ${n}`)}return typeof n=="number"?(n%1&&e.logWithError(`BigNumberish number underflow: ${n}`),(n>=_||n<=-_)&&e.logWithError(`BigNumberish number overflow: ${n}`),new y(String(n))):typeof n=="bigint"?new y(n.toString()):(e.error(`invalid BigNumberish value: ${n}`),new y(0))}var k=o("module/fraction"),D=T(A),w=T(ae),ce={0:w.ROUND_DOWN,1:w.ROUND_HALF_UP,2:w.ROUND_UP},ue={0:A.roundDown,1:A.roundHalfUp,2:A.roundUp},u=class n{constructor(e,t=new se(1)){this.numerator=c(e),this.denominator=c(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(c(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(c(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(c(e));return new n(this.numerator.mul(t.numerator),this.denominator.mul(t.denominator))}div(e){let t=e instanceof n?e:new n(c(e));return new n(this.numerator.mul(t.denominator),this.denominator.mul(t.numerator))}toSignificant(e,t={groupSeparator:""},i=1){Number.isInteger(e)||k.logWithError(`${e} is not an integer.`),e<=0&&k.logWithError(`${e} is not positive.`),w.set({precision:e+1,rounding:ce[i]});let s=new w(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(e);return s.toFormat(s.decimalPlaces(),t)}toFixed(e,t={groupSeparator:""},i=1){return Number.isInteger(e)||k.logWithError(`${e} is not an integer.`),e<0&&k.logWithError(`${e} is negative.`),D.DP=e,D.RM=ue[i]||1,new D(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,t)}isZero(){return this.numerator.isZero()}};var bt=o("Sega_amount"),Tt=T(le);import{PublicKey as pe}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as q}from"@solana/spl-token";var U={chainId:101,address:pe.default.toBase58(),programId:q.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:q.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 E}from"@solana/web3.js";import{PublicKey as r,SystemProgram as G,SYSVAR_RENT_PUBKEY as de}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as fe}from"@solana/spl-token";function M({pubkey:n,isSigner:e=!1,isWritable:t=!0}){return{pubkey:n,isWritable:t,isSigner:e}}var At=[M({pubkey:fe,isWritable:!1}),M({pubkey:G.programId,isWritable:!1}),M({pubkey:de,isWritable:!1})];function j({publicKey:n,transformSol:e}){let t=z(n.toString());if(t instanceof r)return e&&t.equals(x)?F:t;if(e&&t.toString()===x.toBase58())return F;if(typeof t=="string"){if(t===r.default.toBase58())return r.default;try{return new r(t)}catch(i){throw new Error("invalid public key")}}throw new Error("invalid public key")}function z(n){try{return new r(n)}catch(e){return n}}var Ct=new r("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),It=new r("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Nt=new r("SysvarRent111111111111111111111111111111111"),Rt=new r("SysvarC1ock11111111111111111111111111111111"),ge=new r("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),Ft=new r("Sysvar1nstructions1111111111111111111111111"),Dt=G.programId,Mt=new r("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),Et=new r("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),Lt=new r("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),Ot=new r("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),Wt=new r("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),Vt=new r("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),vt=new r("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),Kt=new r("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),_t=new r("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),qt=new r("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),Ut=new r("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),F=new r("So11111111111111111111111111111111111111112"),x=r.default;var C=class C{constructor({mint:e,decimals:t,symbol:i,name:s,skipMint:f=!1,isToken2022:a=!1}){if(e===x.toBase58()||e instanceof E&&x.equals(e)){this.decimals=d.decimals,this.symbol=d.symbol,this.name=d.name,this.mint=new E(d.address),this.isToken2022=!1;return}this.decimals=t,this.symbol=i||e.toString().substring(0,6),this.name=s||e.toString().substring(0,6),this.mint=f?E.default:j({publicKey:e}),this.isToken2022=a}equals(e){return this===e?!0:this.mint.equals(e.mint)}};C.WSOL=new C(h(g({},d),{mint:d.address}));var S=C;var I=class I{constructor({decimals:e,symbol:t="UNKNOWN",name:i="UNKNOWN"}){this.decimals=e,this.symbol=t,this.name=i}equals(e){return this===e}};I.SOL=new I(U);var L=I;import he from"bn.js";var nn=new u(new he(100));var un=o("Sega_price");import{PublicKey as An}from"@solana/web3.js";import In from"bn.js";var be=new l(0),Yn=new l(1),Zn=new l(2),Jn=new l(3),Xn=new l(5),me=new l(10),$n=new l(100),Qn=new l(1e3),er=new l(1e4);import{PublicKey as Ir}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Rr}from"@solana/spl-token";import{ComputeBudgetProgram as ur,Keypair as pr,PublicKey as dr,Transaction as gr,TransactionMessage as br,VersionedTransaction as Tr}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Sr}from"@solana/spl-token";var Br=o("Sega_txUtil");import{PublicKey as p}from"@solana/web3.js";var Lr=new p("SegazTQwbYWknDZkJ6j2Kgvm5gw3MrHGKtWstZdoNKZ"),Or=new p("Ajk8d9bERSaFdeoT1d8JUVfaDayrYLnAdgeB47TFMUaG"),Wr=new p("2HbjxVVKJ7Ct72Rcd8WK4VTqmwTXL5aAggkH1CHGFGmh"),we=new p("auetiVUVJkRxvNPLYEvVnz8UJSqQ1VgoA83PcicHVD1"),xe=new p("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),Se=new p("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y");var Vr={SERUM_MARKET:p.default,UTIL1216:p.default,CREATE_CPMM_POOL_PROGRAM:we,CREATE_CPMM_POOL_AUTH:xe,CREATE_CPMM_POOL_FEE_ACC:Se};import _r from"bn.js";import{PublicKey as Hr,AddressLookupTableAccount as Yr}from"@solana/web3.js";import{PublicKey as mi,sendAndConfirmTransaction as pi,SystemProgram as gi,Transaction as hi,TransactionMessage as Ti,VersionedTransaction as yi}from"@solana/web3.js";import xi from"axios";import{Connection as Ni}from"@solana/web3.js";import Be from"bn.js";var Xi=new Be(1e6);function N(n,e){if(e.isZero())throw Error("divisor is zero");return n.mod(e)}function Pe(n,e){if(e.isZero())throw Error("rhs is zero");let t=n.div(e);if(t.isZero())throw Error("quotient is zero");let i=N(n,e);return i.gt(b)&&(t=t.add(new B(1)),e=n.div(t),i=N(n,t),i.gt(b)&&(e=e.add(new B(1)))),[t,e]}var b=new B(0),O=class{static swapWithoutFees(e,t,i){let s=t.mul(i),f=t.add(e),[a]=Pe(s,f),m=i.sub(a);if(m.isZero())throw Error("destinationAmountSwapped is zero");return{destinationAmountSwapped:m}}static lpTokensToTradingTokens(e,t,i,s,f){let a=e.mul(i).div(t),m=e.mul(s).div(t);if(f===0)return{tokenAmount0:a,tokenAmount1:m};if(f===1)return N(e.mul(i),t).gt(b)&&a.gt(b)&&(a=a.add(new B(1))),N(e.mul(s),t).gt(b)&&m.gt(b)&&(m=m.add(new B(1))),{tokenAmount0:a,tokenAmount1:m};throw Error("roundDirection value error")}};export{O as ConstantProductCurve}; //# sourceMappingURL=constantProduct.mjs.map