Browse Source

feat(staking): add reward custody account

keyvan 1 year ago
parent
commit
71dd9f4d33

+ 5 - 1
apps/staking/src/components/Header/stats.tsx

@@ -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 }) =>
@@ -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,
   };
 };
 

+ 13 - 0
governance/pyth_staking_sdk/src/pyth-staking-client.ts

@@ -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);
+  }
 }