From fa2990fe2113a07e3ec41b0616d22f91c89f34ba Mon Sep 17 00:00:00 2001 From: Alexander Burkut Date: Mon, 2 Oct 2023 11:52:54 +0300 Subject: [PATCH] add fix for getTopPoolsForToken --- src/dex/dexalot/dexalot.ts | 61 ++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 22 deletions(-) diff --git a/src/dex/dexalot/dexalot.ts b/src/dex/dexalot/dexalot.ts index 99880a9e2..6c0f3626c 100644 --- a/src/dex/dexalot/dexalot.ts +++ b/src/dex/dexalot/dexalot.ts @@ -279,6 +279,12 @@ export class Dexalot extends SimpleExchange implements IDex { : address.toLowerCase(); } + denormalizeAddress(address: string): string { + return address.toLowerCase() === NULL_ADDRESS + ? ETHER_ADDRESS + : address.toLowerCase(); + } + // Dexalot protocol for native token expects 0x00000... instead of 0xeeeee... normalizeToken(token: Token): Token { return { @@ -287,6 +293,13 @@ export class Dexalot extends SimpleExchange implements IDex { }; } + denormalizeToken(token: Token): Token { + return { + address: this.denormalizeAddress(token.address), + decimals: token.decimals, + }; + } + calculateOrderPrice( amounts: bigint[], orderbook: string[][], @@ -864,31 +877,35 @@ export class Dexalot extends SimpleExchange implements IDex { let pairsByLiquidity = []; for (const pairName of Object.keys(pairs)) { - if (pairName.includes(tokenSymbol)) { - const tokensInPair = pairName.split('/'); - if (tokensInPair.length !== 2) { - continue; - } + if (!pairName.includes(tokenSymbol)) { + continue; + } - const addr = tokensAddr[tokensInPair[0].toLowerCase()]; - let outputToken = this.getTokenFromAddress(addr); - if (tokensInPair[0] === tokenSymbol) { - const addr = tokensAddr[tokensInPair[1].toLowerCase()]; - outputToken = this.getTokenFromAddress(addr); - } + const tokensInPair = pairName.split('/'); + if (tokensInPair.length !== 2) { + continue; + } - const connectorToken = { - address: outputToken.address, - decimals: outputToken.decimals, - }; - const pairData: PoolLiquidity = { - exchange: this.dexKey, - address: this.mainnetRFQAddress, - connectorTokens: [connectorToken], - liquidityUSD: pairs[pairName].liquidityUSD, - }; - pairsByLiquidity.push(pairData); + 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); + const wrappedToken = this.dexHelper.config.wrapETH(denormalizedToken); + + pairsByLiquidity.push({ + exchange: this.dexKey, + address: this.mainnetRFQAddress, + connectorTokens: [{ + address: wrappedToken.address, + decimals: wrappedToken.decimals, + }], + liquidityUSD: pairs[pairName].liquidityUSD, + }); } pairsByLiquidity.sort(