Skip to content

Commit

Permalink
feat(staking): add reward custody account
Browse files Browse the repository at this point in the history
  • Loading branch information
keyvankhademi committed Oct 8, 2024
1 parent 92efb88 commit 71dd9f4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion apps/staking/src/components/Header/stats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const Loading = () => (
const fetchStats = async (connection: Connection) => {
const client = new PythStakingClient({ connection });
const poolData = await client.getPoolDataAccount();
const rewardCustodyAccount = await client.getRewardCustodyAccount();
const totalDelegated = sum(
poolData.delState.map(
({ totalDelegation, deltaDelegation }) =>
Expand All @@ -73,7 +74,10 @@ const fetchStats = async (connection: Connection) => {

return {
totalStaked: totalDelegated + totalSelfStaked,
rewardsDistributed: poolData.claimableRewards + INITIAL_REWARD_POOL_SIZE,
rewardsDistributed:
poolData.claimableRewards +
INITIAL_REWARD_POOL_SIZE -
rewardCustodyAccount.amount,
};
};

Expand Down
13 changes: 13 additions & 0 deletions governance/pyth_staking_sdk/src/pyth-staking-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -974,4 +974,17 @@ export class PythStakingClient {
const globalConfig = await this.getGlobalConfig();
return getMint(this.connection, globalConfig.pythTokenMint);
}

public async getRewardCustodyAccount(): Promise<Account> {
const poolConfigAddress = getPoolConfigAddress();
const config = await this.getGlobalConfig();

const rewardCustodyAccountAddress = getAssociatedTokenAddressSync(
config.pythTokenMint,
poolConfigAddress,
true,
);

return getAccount(this.connection, rewardCustodyAccountAddress);
}
}

0 comments on commit 71dd9f4

Please sign in to comment.