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(suite): hide non-Everstake Solana staking accounts #17181

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
3 changes: 2 additions & 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 Expand Up @@ -384,6 +384,7 @@ const getAccountInfo = async (
payload.descriptor,
isTestnet,
solEpoch,
api.clusterUrl,
);
misc = {
owner: accountInfo?.owner,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { Network, Solana, isStake, stakeAccountState } from '@everstake/wallet-sdk-solana';

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

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

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

// Find the blockchain configuration for the specified chain and environment
const blockchainConfig = config.find(c =>
c.blockchain.name.toLowerCase().includes(`solana ${blockchainEnvironment}`),
);
const serverUrl = blockchainConfig?.blockchain.server[0];
serverUrl: string,
): Promise<SolanaStakingAccount[]> => {
const network = isTestnet ? Network.Devnet : Network.Mainnet;

const solanaClient = new Solana(network, serverUrl);
Expand All @@ -37,6 +36,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
Loading