Skip to content

Commit 2134de3

Browse files
nooxxloicttn
authored andcommitted
sol: update get stakes and rewards functions
1 parent 2b02c44 commit 2134de3

File tree

3 files changed

+91
-9
lines changed

3 files changed

+91
-9
lines changed

examples/sol.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ const f = async () => {
3939
// const hash = await k.sol.broadcast(signedTx);
4040
// console.log(hash);
4141

42+
// const stakes = await k.sol.getStakesByAccounts(['771254de-ac5a-4911-afdf-1d5b7e802dc9']);
43+
// const stakes = await k.sol.getStakesByStakeAccounts(['22njeUeaSxRL9RUf6cFrn5BMBGhpotAgVvjfnWfh2qsm']);
44+
// const stakes = await k.sol.getStakesByWallets(['c5oiYqNcFYVMvWvQ8ifLTjZTsJ8s3X9gitRHFaNi2rk']);
45+
// console.log(stakes);
46+
47+
// const rewards = await k.sol.getRewardsByAccounts(['771254de-ac5a-4911-afdf-1d5b7e802dc9']);
48+
// const rewards = await k.sol.getRewardsByStakeAccounts(['22njeUeaSxRL9RUf6cFrn5BMBGhpotAgVvjfnWfh2qsm']);
49+
// const rewards = await k.sol.getRewardsByWallets(['c5oiYqNcFYVMvWvQ8ifLTjZTsJ8s3X9gitRHFaNi2rk']);
50+
// console.log(rewards);
51+
4252
// const accounts = await k.sol.getAccountsRewards(['771254de-ac5a-4911-afdf-1d5b7e802dc9']);
4353
// console.log(accounts);
4454
// const tx = await k.sol.getTxStatus('26GZcovnvTGvf5fXFysbtJkNob5r4K9v4H8ZU9tSm8oF5hgUuUm231cabS8LCiC1cqQMFiRkNRNEgqtiVwpr2Bek');

src/services/sol.ts

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
SolanaTx,
2323
SolanaTxStatus,
2424
SolNetworkStats,
25+
SolRewards,
2526
SolStakes,
2627
TaggedStake,
2728
} from '../types/sol';
@@ -507,10 +508,10 @@ export class SolService extends Service {
507508

508509
/**
509510
* Retrieve stakes of given kiln accounts
510-
* @param accountIds: account ids of which you wish to retrieve rewards
511+
* @param accountIds: kiln account ids of which you wish to retrieve stakes
511512
* @returns {SolStakes} Solana Stakes
512513
*/
513-
async getAccountsRewards(
514+
async getStakesByAccounts(
514515
accountIds: string[],
515516
): Promise<SolStakes> {
516517
const { data } = await api.get<SolStakes>(
@@ -519,13 +520,63 @@ export class SolService extends Service {
519520
}
520521

521522
/**
522-
* Retrieve stake on given stake accounts
523-
* @param stakeAccountAddresses validator addresses of which you wish to retrieve rewards
523+
* Retrieve stakes of given stake accounts
524+
* @param stakeAccounts: stake account addresses of which you wish to retrieve rewards
524525
* @returns {SolStakes} Solana Stakes
525526
*/
526-
async getStakesRewards(stakeAccountAddresses: string[]): Promise<SolStakes> {
527+
async getStakesByStakeAccounts(
528+
stakeAccounts: string[],
529+
): Promise<SolStakes> {
527530
const { data } = await api.get<SolStakes>(
528-
`/v1/sol/stakes?stakeaccounts=${stakeAccountAddresses.join(',')}`,
531+
`/v1/sol/stakes?stake_accounts=${stakeAccounts.join(',')}`);
532+
return data;
533+
}
534+
535+
/**
536+
* Retrieve stakes of given wallets
537+
* @param wallets: wallet addresses of which you wish to retrieve rewards
538+
* @returns {SolStakes} Solana Stakes
539+
*/
540+
async getStakesByWallets(
541+
wallets: string[],
542+
): Promise<SolStakes> {
543+
const { data } = await api.get<SolStakes>(
544+
`/v1/sol/stakes?wallets=${wallets.join(',')}`);
545+
return data;
546+
}
547+
548+
/**
549+
* Retrieve rewards for given accounts
550+
* @param accountIds kiln account ids of which you wish to retrieve rewards
551+
* @returns {SolRewards} Solana rewards
552+
*/
553+
async getRewardsByAccounts(accountIds: string[]): Promise<SolRewards> {
554+
const { data } = await api.get<SolRewards>(
555+
`/v1/sol/rewards?accounts=${accountIds.join(',')}`,
556+
);
557+
return data;
558+
}
559+
560+
/**
561+
* Retrieve rewards for given stake accounts
562+
* @param stakeAccounts stake account addresses of which you wish to retrieve rewards
563+
* @returns {SolRewards} Solana rewards
564+
*/
565+
async getRewardsByStakeAccounts(stakeAccounts: string[]): Promise<SolRewards> {
566+
const { data } = await api.get<SolRewards>(
567+
`/v1/sol/rewards?stake_accounts=${stakeAccounts.join(',')}`,
568+
);
569+
return data;
570+
}
571+
572+
/**
573+
* Retrieve rewards for given stake accounts
574+
* @param wallets wallet addresses of which you wish to retrieve rewards
575+
* @returns {SolRewards} Solana rewards
576+
*/
577+
async getRewardsByWallets(wallets: string[]): Promise<SolRewards> {
578+
const { data } = await api.get<SolRewards>(
579+
`/v1/sol/rewards?wallets=${wallets.join(',')}`,
529580
);
530581
return data;
531582
}

src/types/sol.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,39 @@ export type InternalSolanaConfig = {
99

1010
export type SolanaTx = Transaction;
1111

12+
type Epoch = {
13+
nb: number;
14+
begin_at: string;
15+
};
16+
17+
export type StakeState = 'activating' | 'active' | 'deactivating' | 'inactive';
18+
1219
export type SolStake = {
1320
stake_account: string;
1421
withdraw_pubkey: string;
15-
balance: number;
16-
rewards: number;
17-
apy: number;
22+
balance: string;
23+
rewards: string;
24+
activation_epoch: Epoch | null;
25+
deactivation_epoch: Epoch | null;
26+
state: StakeState;
27+
net_apy: number;
28+
vote_account: string;
1829
};
1930

2031
export type SolStakes = {
2132
data: SolStake[];
2233
}
2334

35+
export type SolReward = {
36+
epoch: Epoch;
37+
rewards: number;
38+
net_apy: number;
39+
};
40+
41+
export type SolRewards = {
42+
data: SolReward[];
43+
}
44+
2445
export type SolNetworkStats = {
2546
data: {
2647
timestamp: string;

0 commit comments

Comments
 (0)