Skip to content

Commit

Permalink
add fix for getTopPoolsForToken
Browse files Browse the repository at this point in the history
  • Loading branch information
aburkut committed Oct 2, 2023
1 parent db71a36 commit fa2990f
Showing 1 changed file with 39 additions and 22 deletions.
61 changes: 39 additions & 22 deletions src/dex/dexalot/dexalot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,12 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
: 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 {
Expand All @@ -287,6 +293,13 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
};
}

denormalizeToken(token: Token): Token {
return {
address: this.denormalizeAddress(token.address),
decimals: token.decimals,
};
}

calculateOrderPrice(
amounts: bigint[],
orderbook: string[][],
Expand Down Expand Up @@ -864,31 +877,35 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {

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(
Expand Down

0 comments on commit fa2990f

Please sign in to comment.