reactjs - ¿Cómo devuelve "bestTradeExactIn" el valor [interfaz de PancakeSwap]?
Estaba intentando entender cómo se determinan los precios de intercambio de tokens en PancakeSwap al mirar los códigos y finalmente llegué al punto donde se calcula el mejor precio basado en algunos valores.
El método es el siguiente:
/**
* Given a list of pairs, and a fixed amount in, returns the top `maxNumResults` trades that go from an input token
* amount to an output token, making at most `maxHops` hops.
* Note this does not consider aggregation, as routes are linear. It's possible a better route exists by splitting
* the amount in among multiple routes.
* @param pairs the pairs to consider in finding the best trade
* @param currencyAmountIn exact amount of input currency to spend
* @param currencyOut the desired currency out
* @param maxNumResults maximum number of results to return
* @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pair
* @param currentPairs used in recursion; the current list of pairs
* @param originalAmountIn used in recursion; the original value of the currencyAmountIn parameter
* @param bestTrades used in recursion; the current list of best trades
*/
static bestTradeExactIn(pairs: Pair[], currencyAmountIn: CurrencyAmount, currencyOut: Currency, { maxNumResults, maxHops }?: BestTradeOptions, currentPairs?: Pair[], originalAmountIn?: CurrencyAmount, bestTrades?: Trade[]): Trade[];
El código anterior está escrito en Trade Class. Hasta donde sé, no se ha escrito ningún proceso, pero aparentemente devuelve algún valor donde se utiliza como se muestra a continuación:
const currentTrade: Trade | null =
Trade.bestTradeExactIn(allowedPairs, currencyAmountIn, currencyOut, { maxHops: i, maxNumResults: 1 })[0] ??
null
console.log('currentTrade : ', currentTrade)
¿Cómo es que "Trade.bestTradeExactIn(args...)" devuelve un valor sin ningún código para este método?
Código frontend de PancakeSwap: https://github.com/pancakeswap/pancake-frontend