@@ -5,12 +5,15 @@ import {
5
5
getAmountByTargetAndState ,
6
6
getCurrentEpoch ,
7
7
PositionState ,
8
+ PythnetClient ,
8
9
PythStakingClient ,
9
10
type StakeAccountPositions ,
10
11
} from "@pythnetwork/staking-sdk" ;
11
12
import { PublicKey } from "@solana/web3.js" ;
12
13
import { z } from "zod" ;
13
14
15
+ import { KNOWN_PUBLISHERS } from "./known-publishers" ;
16
+
14
17
const publishersRankingSchema = z
15
18
. object ( {
16
19
publisher : z . string ( ) ,
@@ -43,8 +46,15 @@ type Data = {
43
46
cooldown2 : bigint ;
44
47
} ;
45
48
yieldRate : bigint ;
49
+ m : bigint ;
50
+ z : bigint ;
46
51
integrityStakingPublishers : {
47
- name : string | undefined ;
52
+ identity :
53
+ | {
54
+ name : string ;
55
+ icon : string ;
56
+ }
57
+ | undefined ;
48
58
publicKey : PublicKey ;
49
59
stakeAccount : PublicKey | undefined ;
50
60
selfStake : bigint ;
@@ -54,7 +64,8 @@ type Data = {
54
64
poolUtilizationDelta : bigint ;
55
65
numFeeds : number ;
56
66
qualityRanking : number ;
57
- apyHistory : { date : Date ; apy : number } [ ] ;
67
+ delegationFee : bigint ;
68
+ apyHistory : { date : Date ; apy : number ; selfApy : number } [ ] ;
58
69
positions ?:
59
70
| {
60
71
warmup ?: bigint | undefined ;
@@ -95,18 +106,29 @@ export const getStakeAccount = async (
95
106
96
107
export const loadData = async (
97
108
client : PythStakingClient ,
109
+ pythnetClient : PythnetClient ,
98
110
hermesClient : HermesClient ,
99
111
stakeAccount ?: PublicKey | undefined ,
100
112
) : Promise < Data > =>
101
113
stakeAccount === undefined
102
- ? loadDataNoStakeAccount ( client , hermesClient )
103
- : loadDataForStakeAccount ( client , hermesClient , stakeAccount ) ;
114
+ ? loadDataNoStakeAccount ( client , pythnetClient , hermesClient )
115
+ : loadDataForStakeAccount (
116
+ client ,
117
+ pythnetClient ,
118
+ hermesClient ,
119
+ stakeAccount ,
120
+ ) ;
104
121
105
122
const loadDataNoStakeAccount = async (
106
123
client : PythStakingClient ,
124
+ pythnetClient : PythnetClient ,
107
125
hermesClient : HermesClient ,
108
126
) : Promise < Data > => {
109
- const { publishers, ...baseInfo } = await loadBaseInfo ( client , hermesClient ) ;
127
+ const { publishers, ...baseInfo } = await loadBaseInfo (
128
+ client ,
129
+ pythnetClient ,
130
+ hermesClient ,
131
+ ) ;
110
132
111
133
return {
112
134
...baseInfo ,
@@ -127,6 +149,7 @@ const loadDataNoStakeAccount = async (
127
149
128
150
const loadDataForStakeAccount = async (
129
151
client : PythStakingClient ,
152
+ pythnetClient : PythnetClient ,
130
153
hermesClient : HermesClient ,
131
154
stakeAccount : PublicKey ,
132
155
) : Promise < Data > => {
@@ -137,7 +160,7 @@ const loadDataForStakeAccount = async (
137
160
claimableRewards ,
138
161
stakeAccountPositions ,
139
162
] = await Promise . all ( [
140
- loadBaseInfo ( client , hermesClient ) ,
163
+ loadBaseInfo ( client , pythnetClient , hermesClient ) ,
141
164
client . getStakeAccountCustody ( stakeAccount ) ,
142
165
client . getUnlockSchedule ( stakeAccount ) ,
143
166
client . getClaimableRewards ( stakeAccount ) ,
@@ -196,45 +219,61 @@ const loadDataForStakeAccount = async (
196
219
197
220
const loadBaseInfo = async (
198
221
client : PythStakingClient ,
222
+ pythnetClient : PythnetClient ,
199
223
hermesClient : HermesClient ,
200
224
) => {
201
- const [ publishers , walletAmount , poolConfig , currentEpoch ] =
225
+ const [ publishers , walletAmount , poolConfig , currentEpoch , parameters ] =
202
226
await Promise . all ( [
203
- loadPublisherData ( client , hermesClient ) ,
227
+ loadPublisherData ( client , pythnetClient , hermesClient ) ,
204
228
client . getOwnerPythBalance ( ) ,
205
229
client . getPoolConfigAccount ( ) ,
206
230
getCurrentEpoch ( client . connection ) ,
231
+ pythnetClient . getStakeCapParameters ( ) ,
207
232
] ) ;
208
233
209
- return { yieldRate : poolConfig . y , walletAmount, publishers, currentEpoch } ;
234
+ return {
235
+ yieldRate : poolConfig . y ,
236
+ walletAmount,
237
+ publishers,
238
+ currentEpoch,
239
+ m : parameters . m ,
240
+ z : parameters . z ,
241
+ } ;
210
242
} ;
211
243
212
244
const loadPublisherData = async (
213
245
client : PythStakingClient ,
246
+ pythnetClient : PythnetClient ,
214
247
hermesClient : HermesClient ,
215
248
) => {
216
- const [ poolData , publisherRankings , publisherCaps ] = await Promise . all ( [
217
- client . getPoolDataAccount ( ) ,
218
- getPublisherRankings ( ) ,
219
- hermesClient . getLatestPublisherCaps ( {
220
- parsed : true ,
221
- } ) ,
222
- ] ) ;
249
+ const [ poolData , publisherRankings , publisherCaps , publisherNumberOfSymbols ] =
250
+ await Promise . all ( [
251
+ client . getPoolDataAccount ( ) ,
252
+ getPublisherRankings ( ) ,
253
+ hermesClient . getLatestPublisherCaps ( {
254
+ parsed : true ,
255
+ } ) ,
256
+ pythnetClient . getPublisherNumberOfSymbols ( ) ,
257
+ ] ) ;
223
258
224
259
return extractPublisherData ( poolData ) . map ( ( publisher ) => {
225
260
const publisherPubkeyString = publisher . pubkey . toBase58 ( ) ;
226
261
const publisherRanking = publisherRankings . find (
227
262
( ranking ) => ranking . publisher === publisherPubkeyString ,
228
263
) ;
229
- const apyHistory = publisher . apyHistory . map ( ( { epoch, apy } ) => ( {
264
+ const numberOfSymbols = publisherNumberOfSymbols [ publisherPubkeyString ] ;
265
+ const apyHistory = publisher . apyHistory . map ( ( { epoch, apy, selfApy } ) => ( {
230
266
date : epochToDate ( epoch + 1n ) ,
231
267
apy,
268
+ selfApy,
232
269
} ) ) ;
233
270
234
271
return {
235
272
apyHistory,
236
- name : undefined , // TODO
237
- numFeeds : publisherRanking ?. numSymbols ?? 0 ,
273
+ identity : (
274
+ KNOWN_PUBLISHERS as Record < string , { name : string ; icon : string } >
275
+ ) [ publisher . pubkey . toBase58 ( ) ] ,
276
+ numFeeds : numberOfSymbols ?? 0 ,
238
277
poolCapacity : getPublisherCap ( publisherCaps , publisher . pubkey ) ,
239
278
poolUtilization : publisher . totalDelegation ,
240
279
poolUtilizationDelta : publisher . totalDelegationDelta ,
@@ -243,6 +282,7 @@ const loadPublisherData = async (
243
282
selfStake : publisher . selfDelegation ,
244
283
selfStakeDelta : publisher . selfDelegationDelta ,
245
284
stakeAccount : publisher . stakeAccount ?? undefined ,
285
+ delegationFee : publisher . delegationFee ,
246
286
} ;
247
287
} ) ;
248
288
} ;
0 commit comments