Skip to content

Commit 6ca7501

Browse files
committed
fix token provider getHighestLiquidityPair
1 parent a9d8417 commit 6ca7501

File tree

2 files changed

+12
-28
lines changed
  • packages

2 files changed

+12
-28
lines changed

packages/plugin-solana/src/providers/token.ts

+6-14
Original file line numberDiff line numberDiff line change
@@ -604,21 +604,13 @@ export class TokenProvider {
604604
}
605605

606606
// Sort pairs by both liquidity and market cap to get the highest one
607-
return dexData.pairs.reduce((highestPair, currentPair) => {
608-
const currentLiquidity = currentPair.liquidity.usd;
609-
const currentMarketCap = currentPair.marketCap;
610-
const highestLiquidity = highestPair.liquidity.usd;
611-
const highestMarketCap = highestPair.marketCap;
612-
613-
if (
614-
currentLiquidity > highestLiquidity ||
615-
(currentLiquidity === highestLiquidity &&
616-
currentMarketCap > highestMarketCap)
617-
) {
618-
return currentPair;
607+
return dexData.pairs.sort((a, b) => {
608+
const liquidityDiff = b.liquidity.usd - a.liquidity.usd;
609+
if (liquidityDiff !== 0) {
610+
return liquidityDiff; // Higher liquidity comes first
619611
}
620-
return highestPair;
621-
});
612+
return b.marketCap - a.marketCap; // If liquidity is equal, higher market cap comes first
613+
})[0];
622614
}
623615

624616
async analyzeHolderDistribution(

packages/plugin-starknet/src/providers/token.ts

+6-14
Original file line numberDiff line numberDiff line change
@@ -385,21 +385,13 @@ export class TokenProvider {
385385
}
386386

387387
// Sort pairs by both liquidity and market cap to get the highest one
388-
return dexData.pairs.reduce((highestPair, currentPair) => {
389-
const currentLiquidity = currentPair.liquidity.usd;
390-
const currentMarketCap = currentPair.marketCap;
391-
const highestLiquidity = highestPair.liquidity.usd;
392-
const highestMarketCap = highestPair.marketCap;
393-
394-
if (
395-
currentLiquidity > highestLiquidity ||
396-
(currentLiquidity === highestLiquidity &&
397-
currentMarketCap > highestMarketCap)
398-
) {
399-
return currentPair;
388+
return dexData.pairs.sort((a, b) => {
389+
const liquidityDiff = b.liquidity.usd - a.liquidity.usd;
390+
if (liquidityDiff !== 0) {
391+
return liquidityDiff; // Higher liquidity comes first
400392
}
401-
return highestPair;
402-
});
393+
return b.marketCap - a.marketCap; // If liquidity is equal, higher market cap comes first
394+
})[0];
403395
}
404396

405397
// TODO:

0 commit comments

Comments
 (0)