fema-pf-calc 1.0.5 → 1.0.7
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 +38 -38
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -62,12 +62,12 @@ That is all a developer needs to do. No RPC key, no math, no guessing.
|
|
|
62
62
|
|
|
63
63
|
```ts
|
|
64
64
|
const result = await estimateFee({
|
|
65
|
-
speed: "fast",
|
|
66
|
-
strategy: "balanced",
|
|
67
|
-
protocol: "jupiter",
|
|
65
|
+
speed: "fast", // "slow" | "medium" | "fast"
|
|
66
|
+
strategy: "balanced", // "cheap" | "balanced" | "aggressive"
|
|
67
|
+
protocol: "jupiter", // see supported protocols below
|
|
68
68
|
transaction: myTransaction, // pass your actual tx for automatic protocol detection
|
|
69
|
-
maxFee: 500_000,
|
|
70
|
-
includeStats: true,
|
|
69
|
+
maxFee: 500_000, // optional cap in microLamports
|
|
70
|
+
includeStats: true, // include full distribution in response
|
|
71
71
|
});
|
|
72
72
|
```
|
|
73
73
|
|
|
@@ -138,11 +138,11 @@ const { fee } = await estimateFee({
|
|
|
138
138
|
|
|
139
139
|
```ts
|
|
140
140
|
{
|
|
141
|
-
fee: 253637,
|
|
142
|
-
congestion: "high",
|
|
143
|
-
percentileUsed: 75,
|
|
144
|
-
sampleSize: 1203,
|
|
145
|
-
programFiltered: true,
|
|
141
|
+
fee: 253637, // microLamports per CU — pass directly to setComputeUnitPrice
|
|
142
|
+
congestion: "high", // "low" | "medium" | "high"
|
|
143
|
+
percentileUsed: 75, // which percentile was used
|
|
144
|
+
sampleSize: 1203, // number of transactions analyzed
|
|
145
|
+
programFiltered: true, // true = fee is based on your protocol's txs specifically
|
|
146
146
|
|
|
147
147
|
// only included when includeStats: true
|
|
148
148
|
stats: {
|
|
@@ -169,44 +169,44 @@ The `fee` value is in **microLamports per compute unit** — the exact unit that
|
|
|
169
169
|
|
|
170
170
|
```ts
|
|
171
171
|
init({
|
|
172
|
-
cluster: "mainnet-beta",
|
|
173
|
-
|
|
174
|
-
cacheDurationMs: 7000, // how long to cache results in ms (default: 7000)
|
|
172
|
+
cluster: "mainnet-beta", // "mainnet-beta" | "devnet" (default: "mainnet-beta")
|
|
173
|
+
cacheDurationMs: 7000, // how long to cache results in ms (default: 7000)
|
|
175
174
|
});
|
|
176
175
|
```
|
|
177
176
|
|
|
178
|
-
|
|
177
|
+
---
|
|
179
178
|
|
|
180
|
-
|
|
181
|
-
# Optional: use your own RPC provider (overrides the built-in default)
|
|
182
|
-
SOLANA_RPC_URL=https://your-custom-rpc.com
|
|
179
|
+
## Sample Code
|
|
183
180
|
|
|
184
|
-
|
|
185
|
-
|
|
181
|
+
```ts
|
|
182
|
+
import express from "express";
|
|
183
|
+
import { init, estimateFee } from "fema-pf-calc";
|
|
184
|
+
import { ComputeBudgetProgram } from "@solana/web3.js";
|
|
186
185
|
|
|
187
|
-
|
|
188
|
-
SOLANA_CLUSTER=mainnet-beta
|
|
186
|
+
const app = express();
|
|
189
187
|
|
|
190
|
-
|
|
191
|
-
CACHE_DURATION_MS=7000
|
|
192
|
-
```
|
|
188
|
+
init({ cluster: "mainnet-beta" }); // no RPC setup needed
|
|
193
189
|
|
|
194
|
-
|
|
190
|
+
app.get("/fee", async (req, res) => {
|
|
191
|
+
try {
|
|
192
|
+
const { fee } = await estimateFee({ speed: "fast", strategy: "balanced" });
|
|
195
193
|
|
|
196
|
-
|
|
194
|
+
const priorityIx = ComputeBudgetProgram.setComputeUnitPrice({
|
|
195
|
+
microLamports: fee,
|
|
196
|
+
});
|
|
197
197
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
198
|
+
res.json({ fee, priorityIx });
|
|
199
|
+
} catch (err) {
|
|
200
|
+
console.error(err);
|
|
201
|
+
res.status(500).json({ error: err.message });
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
app.listen(8000, () => {
|
|
206
|
+
console.log("Server is running on port http://localhost:8000");
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
export default app;
|
|
210
210
|
```
|
|
211
211
|
|
|
212
212
|
---
|