Skip to content

Commit 566201f

Browse files
committed
update stake pool api page to include section explaining how jito frontend handles APY calculations.
1 parent 67a327e commit 566201f

File tree

1 file changed

+92
-7
lines changed
  • jitosol/jitosol-liquid-staking/for-developers/stake-pool-api

1 file changed

+92
-7
lines changed

jitosol/jitosol-liquid-staking/for-developers/stake-pool-api/index.md

Lines changed: 92 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
title: Validator Performance API
3-
subtitle: "Network analytics, validator rankings, and stake pool metrics"
2+
title: Validator API
3+
subtitle: "Network analytics, validator rankings, and stake pool APY metrics"
44
section_type: page
55
order: 10
66
---
@@ -436,11 +436,6 @@ curl -X POST \
436436

437437
**Base URL**: `https://kobe.mainnet.jito.network`
438438

439-
#### Query Parameters
440-
441-
| Parameter | Type | Required | Default | Description |
442-
| --------- | ------ | -------- |-------- | ------------------------------ |
443-
444439
#### Response Fields
445440

446441
| Field | Type | Description |
@@ -558,6 +553,96 @@ curl -X POST \
558553

559554
---
560555

556+
## Frontend APY Calculation
557+
558+
The Jito frontend calculates the current APY displayed to users by fetching historical stake pool data and using the most recent available data point.
559+
560+
### Jito Frontend Implementation
561+
562+
Here's how the Jito frontend retrieves and processes APY data:
563+
564+
```javascript
565+
export default async function handler(req, res) {
566+
const apiUrl = 'https://kobe.mainnet.jito.network/api/v1/stake_pool_stats'
567+
568+
// Set up start and end dates
569+
const start = new Date('2022-10-31T00:00:00Z') // Launch date
570+
const end = new Date()
571+
572+
const statsRequest = {
573+
bucket_type: 'Daily',
574+
range_filter: {
575+
start: start.toISOString(),
576+
end: end.toISOString(),
577+
},
578+
sort_by: {
579+
field: 'BlockTime',
580+
order: 'Asc',
581+
},
582+
}
583+
584+
try {
585+
const response = await fetch(apiUrl, {
586+
method: 'POST',
587+
headers: {
588+
'Content-Type': 'application/json',
589+
},
590+
body: JSON.stringify(statsRequest),
591+
})
592+
593+
if (!response.ok) {
594+
throw new Error(`HTTP error! status: ${response.status}`)
595+
}
596+
597+
const data = await response.json()
598+
599+
if (data) {
600+
const {
601+
aggregated_mev_rewards: aggregatedMevRewards,
602+
apy,
603+
mev_rewards: mevRewards,
604+
num_validators: numValidators,
605+
supply,
606+
tvl,
607+
} = data
608+
609+
const camelCaseData = {
610+
getStakePoolStats: {
611+
aggregatedMevRewards,
612+
apy,
613+
mevRewards,
614+
numValidators,
615+
supply,
616+
tvl,
617+
},
618+
}
619+
620+
res.status(200).json(camelCaseData)
621+
} else {
622+
res.status(200).json(data)
623+
}
624+
} catch (error) {
625+
console.error('Error fetching data:', error)
626+
res.status(500).json({ message: `Error fetching data: ${error.message}` })
627+
}
628+
}
629+
```
630+
631+
### APY Selection Logic
632+
633+
To display the current APY on the frontend:
634+
635+
1. **Fetch Complete History**: The API call retrieves all historical data from JitoSOL's launch date (October 31, 2022) to the present
636+
2. **Select Most Recent**: The frontend uses the most recent data point from the `apy` array
637+
3. **Display Current Rate**: This most recent APY value represents the current annualized yield rate shown to users
638+
639+
The `apy` field in the response contains time-series data where each entry includes:
640+
- `data`: The APY as a decimal value (e.g., 0.07184861225308525 = ~7.18%)
641+
- `date`: The timestamp when this APY was calculated
642+
643+
Note that the stake_pool_stats endpoint returns smoothed values when requesting for periods longer than 10 epochs. Hence, the APY data we show on our frontend is smoothed.
644+
645+
---
561646

562647
## Notes & Caveats
563648
* The **current epoch** always reports `mev_rewards = 0` because rewards are finalized at epoch-close.

0 commit comments

Comments
 (0)