Skip to content

Commit

Permalink
restore getTopPoolsForToken for Dexalot
Browse files Browse the repository at this point in the history
  • Loading branch information
aburkut committed Dec 12, 2024
1 parent d727c36 commit 9b596e4
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion src/dex/dexalot/dexalot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,56 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
tokenAddress: Address,
limit: number,
): Promise<PoolLiquidity[]> {
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 {
Expand Down

0 comments on commit 9b596e4

Please sign in to comment.