Skip to content

Commit 122d340

Browse files
feat(staking): estimated next apy (#1917)
* feat(staking): extimated next apy * fix * fix * fix type
1 parent b3fe3d4 commit 122d340

File tree

5 files changed

+40
-18
lines changed

5 files changed

+40
-18
lines changed

apps/staking/src/api.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ type Data = {
5151
publicKey: PublicKey;
5252
stakeAccount: PublicKey | undefined;
5353
selfStake: bigint;
54+
selfStakeDelta: bigint;
5455
poolCapacity: bigint;
5556
poolUtilization: bigint;
57+
poolUtilizationDelta: bigint;
5658
numFeeds: number;
5759
qualityRanking: number;
5860
apyHistory: { date: Date; apy: number }[];
@@ -301,9 +303,11 @@ const loadPublisherData = async (
301303
numFeeds: publisherRanking?.numSymbols ?? 0,
302304
poolCapacity: getPublisherCap(publisherCaps, publisher.pubkey),
303305
poolUtilization: publisher.totalDelegation,
306+
poolUtilizationDelta: publisher.totalDelegationDelta,
304307
publicKey: publisher.pubkey,
305308
qualityRanking: publisherRanking?.rank ?? 0,
306309
selfStake: publisher.selfDelegation,
310+
selfStakeDelta: publisher.selfDelegationDelta,
307311
stakeAccount: publisher.stakeAccount ?? undefined,
308312
};
309313
});

apps/staking/src/components/OracleIntegrityStaking/index.tsx

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ export const OracleIntegrityStaking = ({
125125
<thead className="bg-pythpurple-400/30 font-light">
126126
<tr>
127127
<PublisherTableHeader>Pool</PublisherTableHeader>
128-
<PublisherTableHeader>Last epoch APY</PublisherTableHeader>
128+
<PublisherTableHeader>
129+
Estimated next APY
130+
</PublisherTableHeader>
129131
<PublisherTableHeader>Historical APY</PublisherTableHeader>
130132
<PublisherTableHeader>Number of feeds</PublisherTableHeader>
131133
<PublisherTableHeader>Quality ranking</PublisherTableHeader>
@@ -570,7 +572,7 @@ const PublisherList = ({
570572
sort={sort}
571573
setSort={updateSort}
572574
>
573-
APY
575+
Estimated next APY
574576
</SortablePublisherTableHeader>
575577
<PublisherTableHeader>Historical APY</PublisherTableHeader>
576578
<SortablePublisherTableHeader
@@ -657,16 +659,16 @@ const doSort = (
657659
return (
658660
calculateApy({
659661
isSelf: false,
660-
selfStake: a.selfStake,
662+
selfStake: a.selfStake + a.selfStakeDelta,
661663
poolCapacity: a.poolCapacity,
662-
poolUtilization: a.poolUtilization,
664+
poolUtilization: a.poolUtilization + a.poolUtilizationDelta,
663665
yieldRate,
664666
}) -
665667
calculateApy({
666668
isSelf: false,
667-
selfStake: b.selfStake,
669+
selfStake: b.selfStake + b.selfStakeDelta,
668670
poolCapacity: b.poolCapacity,
669-
poolUtilization: b.poolUtilization,
671+
poolUtilization: b.poolUtilization + b.poolUtilizationDelta,
670672
yieldRate,
671673
})
672674
);
@@ -755,8 +757,10 @@ type PublisherProps = {
755757
publicKey: PublicKey;
756758
stakeAccount: PublicKey | undefined;
757759
selfStake: bigint;
760+
selfStakeDelta: bigint;
758761
poolCapacity: bigint;
759762
poolUtilization: bigint;
763+
poolUtilizationDelta: bigint;
760764
numFeeds: number;
761765
qualityRanking: number;
762766
apyHistory: { date: Date; apy: number }[];
@@ -870,9 +874,10 @@ const Publisher = ({
870874
<div>
871875
{calculateApy({
872876
isSelf: isSelf ?? false,
873-
selfStake: publisher.selfStake,
877+
selfStake: publisher.selfStake + publisher.selfStakeDelta,
874878
poolCapacity: publisher.poolCapacity,
875-
poolUtilization: publisher.poolUtilization,
879+
poolUtilization:
880+
publisher.poolUtilization + publisher.poolUtilizationDelta,
876881
yieldRate,
877882
})}
878883
%
@@ -1074,20 +1079,26 @@ const NewApy = ({
10741079
...(isSelf
10751080
? {
10761081
isSelf: true,
1077-
selfStake: publisher.selfStake + children,
1082+
selfStake:
1083+
publisher.selfStake + publisher.selfStakeDelta + children,
10781084
}
10791085
: {
10801086
isSelf: false,
10811087
selfStake: publisher.selfStake,
1082-
poolUtilization: publisher.poolUtilization + children,
1088+
poolUtilization:
1089+
publisher.poolUtilization +
1090+
publisher.poolUtilizationDelta +
1091+
children,
10831092
}),
10841093
}),
10851094
[
10861095
publisher.poolCapacity,
10871096
yieldRate,
10881097
isSelf,
10891098
publisher.selfStake,
1099+
publisher.selfStakeDelta,
10901100
publisher.poolUtilization,
1101+
publisher.poolUtilizationDelta,
10911102
children,
10921103
],
10931104
);

governance/pyth_staking_sdk/src/pyth-staking-client.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,9 @@ export class PythStakingClient {
153153
stakeAccountPositions: PublicKey,
154154
publisher: PublicKey,
155155
) {
156-
const delegationRecord =
157-
await this.integrityPoolProgram.account.delegationRecord.fetch(
158-
getDelegationRecordAddress(stakeAccountPositions, publisher),
159-
);
160-
return convertBNToBigInt(delegationRecord);
156+
return this.integrityPoolProgram.account.delegationRecord
157+
.fetch(getDelegationRecordAddress(stakeAccountPositions, publisher))
158+
.then((record) => convertBNToBigInt(record));
161159
}
162160

163161
public async getStakeAccountCustody(
@@ -624,16 +622,19 @@ export class PythStakingClient {
624622
totalRewards += BigInt("0x" + buffer.toString("hex"));
625623
}
626624

627-
const delegationRecords = await Promise.all(
625+
const delegationRecords = await Promise.allSettled(
628626
instructions.publishers.map(({ pubkey }) =>
629627
this.getDelegationRecord(stakeAccountPositions, pubkey),
630628
),
631629
);
632630

633631
let lowestEpoch: bigint | undefined;
634632
for (const record of delegationRecords) {
635-
if (lowestEpoch === undefined || record.lastEpoch < lowestEpoch) {
636-
lowestEpoch = record.lastEpoch;
633+
if (record.status === "fulfilled") {
634+
const { lastEpoch } = record.value;
635+
if (lowestEpoch === undefined || lastEpoch < lowestEpoch) {
636+
lowestEpoch = lastEpoch;
637+
}
637638
}
638639
}
639640

governance/pyth_staking_sdk/src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ export type PublisherData = {
5252
pubkey: PublicKey;
5353
stakeAccount: PublicKey | null;
5454
totalDelegation: bigint;
55+
totalDelegationDelta: bigint;
5556
selfDelegation: bigint;
57+
selfDelegationDelta: bigint;
5658
apyHistory: { epoch: bigint; apy: number; selfApy: number }[];
5759
}[];
5860

governance/pyth_staking_sdk/src/utils/pool.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ export const extractPublisherData = (
1919
totalDelegation:
2020
(poolData.delState[index]?.totalDelegation ?? 0n) +
2121
(poolData.selfDelState[index]?.totalDelegation ?? 0n),
22+
totalDelegationDelta:
23+
(poolData.delState[index]?.deltaDelegation ?? 0n) +
24+
(poolData.selfDelState[index]?.deltaDelegation ?? 0n),
2225
selfDelegation: poolData.selfDelState[index]?.totalDelegation ?? 0n,
26+
selfDelegationDelta: poolData.selfDelState[index]?.deltaDelegation ?? 0n,
2327
apyHistory: poolData.events
2428
.filter((event) => event.epoch > 0n)
2529
.map((event) => ({

0 commit comments

Comments
 (0)