-
Notifications
You must be signed in to change notification settings - Fork 11
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
get the raydium pool with the smallest tick spacing #393
get the raydium pool with the smallest tick spacing #393
Conversation
WalkthroughThe changes introduced in the Changes
TipsChat with CodeRabbit Bot (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 2
Files selected for processing (1)
- packages/kamino-sdk/src/Kamino.ts (1 hunks)
Additional comments (Suppressed): 1
packages/kamino-sdk/src/Kamino.ts (1)
- 845-847: The code now handles the case where no matching pools are found by returning a default
PublicKey
. This is a good addition for error handling.
let pools: Pool[] = []; | ||
let raydiumPools = await this.getRaydiumPoolsForTokens(poolTokenA, poolTokenB); | ||
raydiumPools.forEach((element) => { | ||
if (new Decimal(element.ammConfig.tradeFeeRate).div(FullBPS).div(FullPercentage).equals(feeBPS.div(FullBPS))) { | ||
pools.push(element); | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new code introduces a filtering mechanism to select pools based on the tradeFeeRate
from raydiumPools
. This is a good approach to filter out the pools that don't meet the criteria. However, the filtering can be done more efficiently using the filter
method instead of forEach
. This would make the code more readable and maintainable.
- raydiumPools.forEach((element) => {
- if (new Decimal(element.ammConfig.tradeFeeRate).div(FullBPS).div(FullPercentage).equals(feeBPS.div(FullBPS))) {
- pools.push(element);
- }
- });
+ pools = raydiumPools.filter((element) =>
+ new Decimal(element.ammConfig.tradeFeeRate).div(FullBPS).div(FullPercentage).equals(feeBPS.div(FullBPS))
+ );
let pool = PublicKey.default; | ||
let tickSpacing = Number.MAX_VALUE; | ||
pools.forEach((element) => { | ||
if (element.ammConfig.tickSpacing < tickSpacing) { | ||
pool = new PublicKey(element.id); | ||
tickSpacing = element.ammConfig.tickSpacing; | ||
} | ||
}); | ||
return pool; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new code selects the pool with the smallest tickSpacing
value. This is a good approach to optimize the pool selection process. However, the same can be achieved more efficiently using the reduce
method instead of forEach
. This would make the code more readable and maintainable.
- let pool = PublicKey.default;
- let tickSpacing = Number.MAX_VALUE;
- pools.forEach((element) => {
- if (element.ammConfig.tickSpacing < tickSpacing) {
- pool = new PublicKey(element.id);
- tickSpacing = element.ammConfig.tickSpacing;
- }
- });
+ let pool = pools.reduce((prev, curr) =>
+ curr.ammConfig.tickSpacing < (prev.ammConfig.tickSpacing || Number.MAX_VALUE) ? curr : prev,
+ { ammConfig: { tickSpacing: Number.MAX_VALUE } }
+ );
+ pool = new PublicKey(pool.id);
Overall, the changes in the new hunk are a good improvement over the old hunk. The new code is more robust and handles edge cases better. However, the use of filter
and reduce
methods can make the code more efficient and maintainable.
Summary by CodeRabbit
getPool
functionality in the Kamino SDK. The update now provides a more efficient way to find and select the optimal pool from the available options. If no matching pools are found, a default value is returned, ensuring a smoother user experience. This change aims to improve the reliability and performance of pool selection, contributing to a more seamless interaction with the platform.