Skip to content

Commit

Permalink
fix(suite): hide non-Everstake Solana staking accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-pvl committed Feb 28, 2025
1 parent 0598bb8 commit ed7f152
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/blockchain-link/src/workers/solana/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ import { IntervalId } from '@trezor/type-utils';
import { BigNumber, createDeferred, createLazy } from '@trezor/utils';

import { getBaseFee, getPriorityFee } from './fee';
import { getSolanaStakingData } from './stakingAccounts';
import { BaseWorker, CONTEXT, ContextType } from '../baseWorker';
import { getSolanaStakingData } from './utils';

export type SolanaAPI = Readonly<{
clusterUrl: ClusterUrl;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { Network, Solana, isStake, stakeAccountState } from '@everstake/wallet-sdk-solana';

import config from '../../ui/config';
import { SolanaStakingAccount } from '@trezor/blockchain-link-types/src/solana';

import config from './../../ui/config';

const EVERSTAKE_VOTER_PUBKEYS = [
'9QU2QSxhb24FUX3Tu2FpczXjpK3VYrvRudywSZaM29mF', // mainnet
'GkqYQysEGmuL6V2AJoNnWZUz2ZBGWhzQXsJiXm2CLKAN', // devnet
];

export const getSolanaStakingData = async (
descriptor: string,
isTestnet: boolean,
epoch: number,
) => {
): Promise<SolanaStakingAccount[]> => {
const blockchainEnvironment = isTestnet ? 'devnet' : 'mainnet';

// Find the blockchain configuration for the specified chain and environment
Expand Down Expand Up @@ -37,6 +44,9 @@ export const getSolanaStakingData = async (
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,
Expand Down
2 changes: 2 additions & 0 deletions suite-common/wallet-core/src/stake/stakeConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ export const EVERSTAKE_ENDPOINT_PREFIX: Record<

export const EVERSTAKE_REWARDS_SOLANA_ENPOINT =
'https://stake-sync-api.everstake.one/solana/rewards';

export const EVERSTAKE_VALIDATOR = '9QU2QSxhb24FUX3Tu2FpczXjpK3VYrvRudywSZaM29mF';
10 changes: 9 additions & 1 deletion suite-common/wallet-core/src/stake/stakeThunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import {
import { TimerId } from '@trezor/type-utils';
import { BigNumber } from '@trezor/utils/src/bigNumber';

import { EVERSTAKE_ENDPOINT_PREFIX, EVERSTAKE_REWARDS_SOLANA_ENPOINT } from './stakeConstants';
import {
EVERSTAKE_ENDPOINT_PREFIX,
EVERSTAKE_REWARDS_SOLANA_ENPOINT,
EVERSTAKE_VALIDATOR,
} from './stakeConstants';
import { selectEverstakeData } from './stakeSelectors';
import {
EVERSTAKE_ASSET_ENDPOINT_TYPES,
Expand Down Expand Up @@ -124,7 +128,11 @@ export const fetchEverstakeRewards = createThunk<
try {
const response = await fetch(`${EVERSTAKE_REWARDS_SOLANA_ENPOINT}/${address}`, {
method: 'POST',
body: `validator=${encodeURIComponent(EVERSTAKE_VALIDATOR)}`,
signal,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
});

if (!response.ok) {
Expand Down

0 comments on commit ed7f152

Please sign in to comment.