Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Token provider getHighestLiquidityPair #547

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the same code in two places can we create a function and reuse it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they are being used by different token providers in each chain plugin, right now the only common place is core and maybe not a good place to add it. For now I thinks its fine like this, maybe creating a service for proving tokens would be better place for this

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah makes sense feel free to just add an issue or TODO comment so it doesn't get lost. LGTM otherwise thanks so much!

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