fema-pf-calc 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -41
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,13 +18,13 @@ FEMA solves this by scanning recent blocks, building a real fee distribution, an
|
|
|
18
18
|
|
|
19
19
|
## How It Works
|
|
20
20
|
|
|
21
|
-
1. FEMA connects to a
|
|
22
|
-
2. For each transaction in
|
|
21
|
+
1. FEMA connects to Solana via a built-in Helius-backed RPC proxy — no API key or RPC setup required
|
|
22
|
+
2. For each transaction in the last 30 blocks it extracts the fee paid in microLamports per compute unit
|
|
23
23
|
3. It sorts these into a distribution and computes percentiles (p25, p50, p75)
|
|
24
24
|
4. If you specify a protocol or pass your transaction, it filters the data to only transactions that used the same programs as yours
|
|
25
25
|
5. It returns the fee at the percentile matching your chosen speed and strategy
|
|
26
26
|
|
|
27
|
-
Results are cached for
|
|
27
|
+
Results are cached for 7 seconds to avoid hammering the RPC on every call.
|
|
28
28
|
|
|
29
29
|
---
|
|
30
30
|
|
|
@@ -43,10 +43,7 @@ import { init, estimateFee } from "fema-pf-calc";
|
|
|
43
43
|
import { ComputeBudgetProgram } from "@solana/web3.js";
|
|
44
44
|
|
|
45
45
|
// Configure once at app startup
|
|
46
|
-
init({
|
|
47
|
-
cluster: "mainnet-beta", // or "devnet"
|
|
48
|
-
rpcUrl: "https://mainnet.helius-rpc.com/?api-key=YOUR_KEY", // optional override
|
|
49
|
-
});
|
|
46
|
+
init({ cluster: "mainnet-beta" }); // no RPC setup needed
|
|
50
47
|
|
|
51
48
|
// Get the recommended fee
|
|
52
49
|
const { fee } = await estimateFee({ speed: "fast", strategy: "balanced" });
|
|
@@ -57,7 +54,7 @@ const priorityIx = ComputeBudgetProgram.setComputeUnitPrice({
|
|
|
57
54
|
});
|
|
58
55
|
```
|
|
59
56
|
|
|
60
|
-
That is all a developer needs to do. No RPC
|
|
57
|
+
That is all a developer needs to do. No RPC key, no math, no guessing.
|
|
61
58
|
|
|
62
59
|
---
|
|
63
60
|
|
|
@@ -65,12 +62,12 @@ That is all a developer needs to do. No RPC calls, no math, no guessing.
|
|
|
65
62
|
|
|
66
63
|
```ts
|
|
67
64
|
const result = await estimateFee({
|
|
68
|
-
speed: "fast",
|
|
69
|
-
strategy: "balanced",
|
|
70
|
-
protocol: "jupiter",
|
|
65
|
+
speed: "fast", // "slow" | "medium" | "fast"
|
|
66
|
+
strategy: "balanced", // "cheap" | "balanced" | "aggressive"
|
|
67
|
+
protocol: "jupiter", // see supported protocols below
|
|
71
68
|
transaction: myTransaction, // pass your actual tx for automatic protocol detection
|
|
72
|
-
maxFee: 500_000,
|
|
73
|
-
includeStats: true,
|
|
69
|
+
maxFee: 500_000, // optional cap in microLamports
|
|
70
|
+
includeStats: true, // include full distribution in response
|
|
74
71
|
});
|
|
75
72
|
```
|
|
76
73
|
|
|
@@ -172,31 +169,23 @@ The `fee` value is in **microLamports per compute unit** — the exact unit that
|
|
|
172
169
|
|
|
173
170
|
```ts
|
|
174
171
|
init({
|
|
175
|
-
cluster: "mainnet-beta",
|
|
176
|
-
rpcUrl: "https://your-rpc.com", // optional —
|
|
177
|
-
cacheDurationMs: 7000,
|
|
172
|
+
cluster: "mainnet-beta", // "mainnet-beta" | "devnet" (default: "mainnet-beta")
|
|
173
|
+
rpcUrl: "https://your-rpc.com", // optional — bring your own RPC to override the default
|
|
174
|
+
cacheDurationMs: 7000, // how long to cache results in ms (default: 7000)
|
|
178
175
|
});
|
|
179
176
|
```
|
|
180
177
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
| Cluster | Default RPC |
|
|
184
|
-
| -------------- | ------------------------------------- |
|
|
185
|
-
| `mainnet-beta` | `https://api.mainnet-beta.solana.com` |
|
|
186
|
-
| `devnet` | `https://api.devnet.solana.com` |
|
|
187
|
-
|
|
188
|
-
Or configure via `.env`:
|
|
178
|
+
You can also override the RPC via environment variables:
|
|
189
179
|
|
|
190
180
|
```env
|
|
191
|
-
#
|
|
192
|
-
|
|
181
|
+
# Optional: use your own RPC provider (overrides the built-in default)
|
|
182
|
+
SOLANA_RPC_URL=https://your-custom-rpc.com
|
|
193
183
|
|
|
194
|
-
#
|
|
195
|
-
# The base URL is set in code; only your key goes here
|
|
184
|
+
# Or use your own Helius API key
|
|
196
185
|
HELIUS_API_KEY=your-api-key-here
|
|
197
186
|
|
|
198
|
-
#
|
|
199
|
-
|
|
187
|
+
# Network: mainnet-beta (default) or devnet
|
|
188
|
+
SOLANA_CLUSTER=mainnet-beta
|
|
200
189
|
|
|
201
190
|
# How long to cache fee data in milliseconds (default: 7000)
|
|
202
191
|
CACHE_DURATION_MS=7000
|
|
@@ -204,23 +193,13 @@ CACHE_DURATION_MS=7000
|
|
|
204
193
|
|
|
205
194
|
---
|
|
206
195
|
|
|
207
|
-
## RPC Recommendations
|
|
208
|
-
|
|
209
|
-
The public Solana RPC endpoints rate-limit aggressively. For reliable results use a private RPC:
|
|
210
|
-
|
|
211
|
-
- [Helius](https://helius.dev) — free tier available
|
|
212
|
-
- [QuickNode](https://quicknode.com)
|
|
213
|
-
- [Alchemy](https://alchemy.com)
|
|
214
|
-
|
|
215
|
-
---
|
|
216
|
-
|
|
217
196
|
## Project Structure
|
|
218
197
|
|
|
219
198
|
```
|
|
220
199
|
src/
|
|
221
200
|
├── index.ts # SDK entry point — estimateFee() and init()
|
|
222
201
|
├── types.ts # TypeScript types and interfaces
|
|
223
|
-
├── config.ts # Configuration and
|
|
202
|
+
├── config.ts # Configuration and RPC resolution
|
|
224
203
|
├── protocols.ts # Known protocol registry (Jupiter, Raydium, etc.)
|
|
225
204
|
├── engine/
|
|
226
205
|
│ └── feeCalculator.ts # Percentile math, strategy modifiers, outlier filtering
|