UNPKG

@sega-so/sega-sdk

Version:

An SDK for building applications on top of SEGA.

2 lines 9.78 kB
var J=Object.defineProperty,X=Object.defineProperties;var $=Object.getOwnPropertyDescriptors;var _=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(_)for(var t of _(e))ee.call(e,t)&&V(n,t,e[t]);return n},h=(n,e)=>X(n,$(e));import P from"bn.js";import uo from"bn.js";import mo from"decimal.js-light";import{PublicKey as Oe}from"@solana/web3.js";import{get as W,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}},v={},ne={};function o(n){let e=W(v,n);if(!e){let t=W(ne,n);e=new R({name:n,logLevel:t}),te(v,n,e)}return e}import{MINT_SIZE as We,TOKEN_PROGRAM_ID as ve,getTransferFeeConfig as Ke,unpackMint as qe}from"@solana/spl-token";var Ue=o("Sega_accountInfo_util");import m from"bn.js";import Wn from"decimal.js";import le from"big.js";import ut from"bn.js";import re from"toformat";var ie=re,T=ie;import k from"big.js";import se from"bn.js";import ae from"decimal.js-light";import y from"bn.js";var K=9007199254740991;function u(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>=K||n<=-K)&&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 A=o("module/fraction"),F=T(k),w=T(ae),ce={0:w.ROUND_DOWN,1:w.ROUND_HALF_UP,2:w.ROUND_UP},ue={0:k.roundDown,1:k.roundHalfUp,2:k.roundUp},l=class n{constructor(e,t=new se(1)){this.numerator=u(e),this.denominator=u(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(u(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(u(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(u(e));return new n(this.numerator.mul(t.numerator),this.denominator.mul(t.denominator))}div(e){let t=e instanceof n?e:new n(u(e));return new n(this.numerator.mul(t.denominator),this.denominator.mul(t.numerator))}toSignificant(e,t={groupSeparator:""},i=1){Number.isInteger(e)||A.logWithError(`${e} is not an integer.`),e<=0&&A.logWithError(`${e} is not positive.`),w.set({precision:e+1,rounding:ce[i]});let a=new w(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(e);return a.toFormat(a.decimalPlaces(),t)}toFixed(e,t={groupSeparator:""},i=1){return Number.isInteger(e)||A.logWithError(`${e} is not an integer.`),e<0&&A.logWithError(`${e} is negative.`),F.DP=e,F.RM=ue[i]||1,new F(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,t)}isZero(){return this.numerator.isZero()}};var Tt=o("Sega_amount"),yt=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 D({pubkey:n,isSigner:e=!1,isWritable:t=!0}){return{pubkey:n,isWritable:t,isSigner:e}}var Ct=[D({pubkey:fe,isWritable:!1}),D({pubkey:G.programId,isWritable:!1}),D({pubkey:de,isWritable:!1})];function j({publicKey:n,transformSol:e}){let t=z(n.toString());if(t instanceof r)return e&&t.equals(x)?M:t;if(e&&t.toString()===x.toBase58())return M;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 It=new r("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Nt=new r("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Rt=new r("SysvarRent111111111111111111111111111111111"),Mt=new r("SysvarC1ock11111111111111111111111111111111"),ge=new r("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),Ft=new r("Sysvar1nstructions1111111111111111111111111"),Dt=G.programId,Et=new r("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),Ot=new r("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),Lt=new r("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),_t=new r("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),Vt=new r("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),Wt=new r("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),vt=new r("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),Kt=new r("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),qt=new r("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),Ut=new r("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),Gt=new r("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),M=new r("So11111111111111111111111111111111111111112"),x=r.default;var C=class C{constructor({mint:e,decimals:t,symbol:i,name:a,skipMint:f=!1,isToken2022:c=!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=a||e.toString().substring(0,6),this.mint=f?E.default:j({publicKey:e}),this.isToken2022=c}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 O=I;import he from"bn.js";var rn=new l(new he(100));var ln=o("Sega_price");import{PublicKey as Cn}from"@solana/web3.js";import Nn from"bn.js";var be=new m(0),Zn=new m(1),Jn=new m(2),Xn=new m(3),$n=new m(5),me=new m(10),Qn=new m(100),er=new m(1e3),tr=new m(1e4);import{PublicKey as Nr}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Mr}from"@solana/spl-token";import{ComputeBudgetProgram as lr,Keypair as dr,PublicKey as fr,Transaction as hr,TransactionMessage as Tr,VersionedTransaction as yr}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Pr}from"@solana/spl-token";var Br=o("Sega_txUtil");import{PublicKey as s}from"@solana/web3.js";var Lr=new s("SegazTQwbYWknDZkJ6j2Kgvm5gw3MrHGKtWstZdoNKZ"),_r=new s("Ajk8d9bERSaFdeoT1d8JUVfaDayrYLnAdgeB47TFMUaG"),Vr=new s("2HbjxVVKJ7Ct72Rcd8WK4VTqmwTXL5aAggkH1CHGFGmh"),we=new s("auetiVUVJkRxvNPLYEvVnz8UJSqQ1VgoA83PcicHVD1"),xe=new s("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),Se=new s("GzqQwxPSmUZnTyCfX9YWqi32MJg43ujP786ZoacL559Y"),Wr=new s("SegaXNnoXYTZiqUt9Xn2XqGcL56b25yzXLuJSpadcMu"),vr=new s("2t1hV2YqnDCPuJZqr7Fy8oAygGwZE5Q9uaQzpLC1QryJ"),Kr=new s("BLxynZeHE123MmQgNJZiV1pwW4VYh46oZYyC66xwmtTY");var Pe={SERUM_MARKET:s.default,UTIL1216:s.default,CREATE_CPMM_POOL_PROGRAM:we,CREATE_CPMM_POOL_AUTH:xe,CREATE_CPMM_POOL_FEE_ACC:Se};import Gr from"bn.js";import{PublicKey as Jr,AddressLookupTableAccount as Xr}from"@solana/web3.js";import{PublicKey as fi,sendAndConfirmTransaction as gi,SystemProgram as Ti,Transaction as yi,TransactionMessage as xi,VersionedTransaction as Si}from"@solana/web3.js";import Bi from"axios";import{Connection as Ei}from"@solana/web3.js";import Be from"bn.js";var io=new Be(1e6);function N(n,e){if(e.isZero())throw Error("divisor is zero");return n.mod(e)}function Ae(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 P(1)),e=n.div(t),i=N(n,t),i.gt(b)&&(e=e.add(new P(1)))),[t,e]}var b=new P(0),L=class{static swapWithoutFees(e,t,i){let a=t.mul(i),f=t.add(e),[c]=Ae(a,f),p=i.sub(c);if(p.isZero())throw Error("destinationAmountSwapped is zero");return{destinationAmountSwapped:p}}static lpTokensToTradingTokens(e,t,i,a,f){let c=e.mul(i).div(t),p=e.mul(a).div(t);if(f===0)return{tokenAmount0:c,tokenAmount1:p};if(f===1)return N(e.mul(i),t).gt(b)&&c.gt(b)&&(c=c.add(new P(1))),N(e.mul(a),t).gt(b)&&p.gt(b)&&(p=p.add(new P(1))),{tokenAmount0:c,tokenAmount1:p};throw Error("roundDirection value error")}};export{L as ConstantProductCurve}; //# sourceMappingURL=constantProduct.mjs.map