# Notice

Heliad RPC includes a derivative work of:

**atlas-priority-fee-estimator**
Copyright Helius Labs
<https://github.com/helius-labs/atlas-priority-fee-estimator>
Licensed under the Apache License, Version 2.0.
Ported from commit `d15db477f400cc7e295837e13e50d785ea3c7965`.

A copy of the licence is in `third_party/atlas-priority-fee-estimator-LICENSE.txt`.

Heliad is an independent project. It is not affiliated with, endorsed by or
connected to Helius. The names "Helius" and "Atlas" are used here only to
credit the origin of the code, as the licence requires.

## What was ported

The fee engine in `api/rpc.js` is a JavaScript port of the following parts of
the upstream Rust source:

| Upstream | In this project |
| --- | --- |
| `src/priority_fee.rs`: `resolve_priority_rate`, `v1_priority_rate` | `readBudget` |
| `src/priority_fee.rs`: `construct_writable_accounts` | `isWritableIndex`, `writableAccountsOf` |
| `src/priority_fee.rs`: `PriorityFeeTracker::consume` | `indexBlock` |
| `src/priority_fee.rs`: `estimate_max_values`, `calculate_priority_fee_details` | `estimateMaxValues`, `detailsFromData` |
| `src/priority_fee_calculation.rs`: `v2::get_priority_fee_estimates` | `collectFeeData` |
| `src/model.rs`: `PriorityLevel` percentiles | `LEVELS` |
| `src/rpc_server.rs`: request validation, response selection, `get_recommended_fee` | `getPriorityFeeEstimate`, `recommendedFee` |

The percentile function reproduces the R8 quantile estimator of the `statrs`
crate that upstream depends on.

## Changes from upstream

- Rewritten from Rust to JavaScript.
- Data source: upstream consumes a Yellowstone gRPC block stream and keeps the
  last 150 slots. This port reads confirmed blocks over JSON-RPC on demand and
  keeps at most 30 blocks in memory while an instance is warm.
- Vote detection: upstream uses the stream's `is_vote` flag. This port flags a
  transaction as a vote when it calls the Vote program.
- Compute budget: upstream runs the Solana SDK's instruction processor. This
  port reads `SetComputeUnitPrice` and `SetComputeUnitLimit` directly and skips
  a sample when either instruction is duplicated.
- Serialized transactions: upstream resolves address lookup tables with an RPC
  call. This port uses the static account keys only, and does not decode
  serialized v1 transactions.
- Only the V2 calculation is exposed. `getPriorityFeeEstimateV1` is not ported.
- Skewness in `includeDetails` uses the adjusted Fisher-Pearson formula and was
  not checked against upstream.
- Metrics (statsd) are removed.
- Three response headers are added: `X-Heliad-Source`, `X-Heliad-Slots` and
  `X-Heliad-Samples`.
- If no block can be read, the endpoint falls back to
  `getRecentPrioritizationFees`, which upstream does not do.

## Not derived from upstream

`getTransactionFeeReport`, the request forwarding, the rate limiting and the
website are original to Heliad.
