From 9b596e4d503ba9def7e03845d892b22c58da2e40 Mon Sep 17 00:00:00 2001 From: Alexander Burkut Date: Thu, 12 Dec 2024 12:59:40 +0300 Subject: [PATCH] restore getTopPoolsForToken for Dexalot --- src/dex/dexalot/dexalot.ts | 51 +++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/src/dex/dexalot/dexalot.ts b/src/dex/dexalot/dexalot.ts index d66e706a3..6fda285df 100644 --- a/src/dex/dexalot/dexalot.ts +++ b/src/dex/dexalot/dexalot.ts @@ -1036,7 +1036,56 @@ export class Dexalot extends SimpleExchange implements IDex { tokenAddress: Address, limit: number, ): Promise { - return []; // not implemented + const normalizedTokenAddress = this.normalizeAddress(tokenAddress); + const pairs = (await this.getCachedPairs()) || {}; + this.tokensMap = (await this.getCachedTokens()) || {}; + const tokensAddr = (await this.getCachedTokensAddr()) || {}; + const token = this.getTokenFromAddress(normalizedTokenAddress); + if (!token) { + return []; + } + + const tokenSymbol = token.symbol?.toLowerCase() || ''; + + let pairsByLiquidity = []; + for (const pairName of Object.keys(pairs)) { + if (!pairName.includes(tokenSymbol)) { + continue; + } + + const tokensInPair = pairName.split('/'); + if (tokensInPair.length !== 2) { + continue; + } + + const [baseToken, quoteToken] = tokensInPair; + const addr = tokensAddr[baseToken.toLowerCase()]; + let outputToken = this.getTokenFromAddress(addr); + if (baseToken === tokenSymbol) { + const addr = tokensAddr[quoteToken.toLowerCase()]; + outputToken = this.getTokenFromAddress(addr); + } + + const denormalizedToken = this.denormalizeToken(outputToken); + + pairsByLiquidity.push({ + exchange: this.dexKey, + address: this.mainnetRFQAddress, + connectorTokens: [ + { + address: denormalizedToken.address, + decimals: denormalizedToken.decimals, + }, + ], + liquidityUSD: pairs[pairName].liquidityUSD, + }); + } + + pairsByLiquidity.sort( + (a: PoolLiquidity, b: PoolLiquidity) => b.liquidityUSD - a.liquidityUSD, + ); + + return pairsByLiquidity.slice(0, limit); } getAPIReqParams(endpoint: string, method: Method): DexalotAPIParameters {