UNPKG

@shogun-sdk/money-legos

Version:

Shogun Money Legos: clients and types for quotes, memes, prices, balances, fees, validations, etc.

48 lines 1.57 kB
import { fetchQuote } from '@shogun-sdk/money-legos'; import { isBscSwap } from '../utils/index.js'; import { tryHandleFourMemeQuote } from '../quoteHandlers/index.js'; export class OneShotClient { constructor(apiKey, apiUrl) { Object.defineProperty(this, "apiKey", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "apiUrl", { enumerable: true, configurable: true, writable: true, value: void 0 }); this.apiKey = apiKey; this.apiUrl = apiUrl; } /** * Fetches a quote from the Shogun API * @param params Quote parameters * @param signal AbortSignal for cancelling the request * @returns Promise<QuoteTypes> */ async fetchQuote(params, signal) { const result = await this.tryToHandleQuoteManually(params); if (result.error) { return { error: result.error }; } if (result.isHandled) { return result.quote; } return fetchQuote({ key: this.apiKey, url: this.apiUrl, }, params, signal || new AbortSignal()); } async tryToHandleQuoteManually(params) { if (isBscSwap(params)) { // if its a bsc swap then it might be a four meme swap return tryHandleFourMemeQuote(this.apiKey, this.apiUrl, params); } return { isHandled: false }; } } //# sourceMappingURL=one-shot-client.js.map