-
-
Notifications
You must be signed in to change notification settings - Fork 279
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(suite): hide non-Everstake Solana staking accounts #17181
base: develop
Are you sure you want to change the base?
fix(suite): hide non-Everstake Solana staking accounts #17181
Conversation
WalkthroughThe changes update the Solana staking module and associated reward fetching functionality. The import for ✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 2
🧹 Nitpick comments (2)
suite-common/wallet-core/src/stake/stakeConstants.ts (1)
19-19
: Consider consolidating the validator public key constant.The same validator public key is duplicated in
stakingAccounts.ts
. Consider consolidating this into a single constant to avoid potential maintenance issues.Move the constant to a common location and import it in both files:
-export const EVERSTAKE_VALIDATOR = '9QU2QSxhb24FUX3Tu2FpczXjpK3VYrvRudywSZaM29mF'; +// Move to a common location (e.g., common/constants.ts) +export const EVERSTAKE_VALIDATOR_PUBKEYS = { + mainnet: '9QU2QSxhb24FUX3Tu2FpczXjpK3VYrvRudywSZaM29mF', + devnet: 'GkqYQysEGmuL6V2AJoNnWZUz2ZBGWhzQXsJiXm2CLKAN', +} as const; +export const EVERSTAKE_VALIDATOR = EVERSTAKE_VALIDATOR_PUBKEYS.mainnet;packages/blockchain-link/src/workers/solana/stakingAccounts.ts (1)
7-10
: Consider using an enum or object for voter public keys.Using array indices for different environments is error-prone and less maintainable.
-const EVERSTAKE_VOTER_PUBKEYS = [ - '9QU2QSxhb24FUX3Tu2FpczXjpK3VYrvRudywSZaM29mF', // mainnet - 'GkqYQysEGmuL6V2AJoNnWZUz2ZBGWhzQXsJiXm2CLKAN', // devnet -]; +const EVERSTAKE_VOTER_PUBKEYS = { + mainnet: '9QU2QSxhb24FUX3Tu2FpczXjpK3VYrvRudywSZaM29mF', + devnet: 'GkqYQysEGmuL6V2AJoNnWZUz2ZBGWhzQXsJiXm2CLKAN', +} as const;Then update the includes check:
- if (!EVERSTAKE_VOTER_PUBKEYS.includes(voterPubkey)) return; + if (voterPubkey !== EVERSTAKE_VOTER_PUBKEYS[isTestnet ? 'devnet' : 'mainnet']) return;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
packages/blockchain-link/src/workers/solana/index.ts
(1 hunks)packages/blockchain-link/src/workers/solana/stakingAccounts.ts
(1 hunks)suite-common/wallet-core/src/stake/stakeConstants.ts
(1 hunks)suite-common/wallet-core/src/stake/stakeThunks.ts
(2 hunks)
✅ Files skipped from review due to trivial changes (1)
- packages/blockchain-link/src/workers/solana/index.ts
🔇 Additional comments (1)
suite-common/wallet-core/src/stake/stakeThunks.ts (1)
131-135
: LGTM! The request configuration is properly implemented.The changes correctly:
- Include the validator parameter in the request body
- URL encode the parameter value
- Set the appropriate Content-Type header
if (state && 'fields' in state) { | ||
const { fields } = state; | ||
|
||
const voterPubkey = fields[1]?.delegation?.voterPubkey; | ||
if (!EVERSTAKE_VOTER_PUBKEYS.includes(voterPubkey)) return; // filter out non-everstake accounts | ||
|
||
return { | ||
rentExemptReserve: fields[0]?.rentExemptReserve, | ||
stake: fields[1]?.delegation?.stake, | ||
status: stakeState, | ||
}; | ||
} |
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.
🛠️ Refactor suggestion
Add type safety for state fields access.
The code assumes the structure of fields
array without proper type checking, which could lead to runtime errors.
if (state && 'fields' in state) {
const { fields } = state;
+ const meta = fields[0];
+ const stake = fields[1];
+
+ if (!meta || !stake || !('delegation' in stake)) {
+ return;
+ }
- const voterPubkey = fields[1]?.delegation?.voterPubkey;
+ const voterPubkey = stake.delegation.voterPubkey;
if (!EVERSTAKE_VOTER_PUBKEYS.includes(voterPubkey)) return;
return {
- rentExemptReserve: fields[0]?.rentExemptReserve,
- stake: fields[1]?.delegation?.stake,
+ rentExemptReserve: meta.rentExemptReserve,
+ stake: stake.delegation.stake,
status: stakeState,
};
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
if (state && 'fields' in state) { | |
const { fields } = state; | |
const voterPubkey = fields[1]?.delegation?.voterPubkey; | |
if (!EVERSTAKE_VOTER_PUBKEYS.includes(voterPubkey)) return; // filter out non-everstake accounts | |
return { | |
rentExemptReserve: fields[0]?.rentExemptReserve, | |
stake: fields[1]?.delegation?.stake, | |
status: stakeState, | |
}; | |
} | |
if (state && 'fields' in state) { | |
const { fields } = state; | |
const meta = fields[0]; | |
const stake = fields[1]; | |
if (!meta || !stake || !('delegation' in stake)) { | |
return; | |
} | |
const voterPubkey = stake.delegation.voterPubkey; | |
if (!EVERSTAKE_VOTER_PUBKEYS.includes(voterPubkey)) return; // filter out non-everstake accounts | |
return { | |
rentExemptReserve: meta.rentExemptReserve, | |
stake: stake.delegation.stake, | |
status: stakeState, | |
}; | |
} |
Description
Hid non-Everstake Solana staking accounts and rewards
Related Issue
Resolve #15229
Screenshots: