Skip to content

Commit

Permalink
Merge pull request #547 from bmgalego/fix-token-providers
Browse files Browse the repository at this point in the history
fix: Token provider getHighestLiquidityPair
  • Loading branch information
jkbrooks authored Nov 25, 2024
2 parents 97518d6 + 6ca7501 commit 56631d7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 28 deletions.
20 changes: 6 additions & 14 deletions packages/plugin-solana/src/providers/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -604,21 +604,13 @@ export class TokenProvider {
}

// Sort pairs by both liquidity and market cap to get the highest one
return dexData.pairs.reduce((highestPair, currentPair) => {
const currentLiquidity = currentPair.liquidity.usd;
const currentMarketCap = currentPair.marketCap;
const highestLiquidity = highestPair.liquidity.usd;
const highestMarketCap = highestPair.marketCap;

if (
currentLiquidity > highestLiquidity ||
(currentLiquidity === highestLiquidity &&
currentMarketCap > highestMarketCap)
) {
return currentPair;
return dexData.pairs.sort((a, b) => {
const liquidityDiff = b.liquidity.usd - a.liquidity.usd;
if (liquidityDiff !== 0) {
return liquidityDiff; // Higher liquidity comes first
}
return highestPair;
});
return b.marketCap - a.marketCap; // If liquidity is equal, higher market cap comes first
})[0];
}

async analyzeHolderDistribution(
Expand Down
20 changes: 6 additions & 14 deletions packages/plugin-starknet/src/providers/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,21 +385,13 @@ export class TokenProvider {
}

// Sort pairs by both liquidity and market cap to get the highest one
return dexData.pairs.reduce((highestPair, currentPair) => {
const currentLiquidity = currentPair.liquidity.usd;
const currentMarketCap = currentPair.marketCap;
const highestLiquidity = highestPair.liquidity.usd;
const highestMarketCap = highestPair.marketCap;

if (
currentLiquidity > highestLiquidity ||
(currentLiquidity === highestLiquidity &&
currentMarketCap > highestMarketCap)
) {
return currentPair;
return dexData.pairs.sort((a, b) => {
const liquidityDiff = b.liquidity.usd - a.liquidity.usd;
if (liquidityDiff !== 0) {
return liquidityDiff; // Higher liquidity comes first
}
return highestPair;
});
return b.marketCap - a.marketCap; // If liquidity is equal, higher market cap comes first
})[0];
}

// TODO:
Expand Down

0 comments on commit 56631d7

Please sign in to comment.