gn-provider 1.2.6 → 1.2.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 CHANGED
@@ -122,7 +122,7 @@ Creates a new provider instance.
122
122
  | `listUnspent(address: string): Promise<UTXO[]>` | Lists UTXOs for an address |
123
123
  | `getBalance(address: string): Promise<{confirmed: number, unconfirmed: number}>` | Gets address balance |
124
124
  | `getTransaction(txHash: string): Promise<Transaction>` | Retrieves transaction details |
125
- | `getFeePerKb(): Promise<number>` | Estimates current fee rate |
125
+ | `getFeePerKb(): Promise<number>` | Enhanced estimation of the fee rate based on current block stats |
126
126
 
127
127
  ## Features
128
128
 
@@ -87,32 +87,28 @@ class GNProvider extends abstract_provider_1.Provider {
87
87
  yield this._ready();
88
88
  const headers = this._getHeaders();
89
89
  try {
90
- // Paso 1: Obtener la información de la cadena para obtener la altura actual
91
- const chainInfoRes = yield superagent.get(`${this.apiPrefix()}/chain/info`)
92
- .set(headers);
90
+ const chainInfoRes = yield superagent.get(`${this.apiPrefix()}/chain/info`).set(headers);
93
91
  const currentHeight = chainInfoRes.body.blocks;
94
- // Paso 2: Obtener las estadísticas del bloque actual
95
- const blockStatsRes = yield superagent.get(`${this.apiPrefix()}/block/height/${currentHeight}/stats`)
96
- .set(headers);
97
- const blockStats = blockStatsRes.body;
98
- const totalFee = blockStats.total_fee;
99
- const size = blockStats.size;
100
- // Si el tamaño es 0, evitar división por cero
101
- if (size === 0) {
102
- throw new Error('Block size is zero');
103
- }
104
- // Calcular tarifa por kilobyte: (total_fee * 1024) / size
105
- const feePerKb = (totalFee * 1024) / size;
106
- // Aplicar un multiplicador para asegurar una tarifa competitiva (1.5x)
92
+ const blockStatsRes = yield superagent.get(`${this.apiPrefix()}/block/height/${currentHeight}/stats`).set(headers);
93
+ const stats = blockStatsRes.body;
94
+ // 1. Extraer mediana de fee y tamaño medio de transacción
95
+ const medianFeePerTx = stats.median_fee; // Satoshis por transacción
96
+ const medianSizePerTx = stats.median_tx_size; // Bytes por transacción
97
+ if (!medianSizePerTx || medianSizePerTx === 0)
98
+ throw new Error('Invalid block stats');
99
+ // 2. Calcular la tasa: (Satoshis / Bytes) * 1000 para obtener sat/kb
100
+ const feePerKb = (medianFeePerTx / medianSizePerTx) * 1000;
101
+ // 3. Aplicar multiplicador competitivo (1.5x es seguro en BSV)
107
102
  const competitiveFee = feePerKb * 1.5;
108
- // Establecer un mínimo de 50 sat/kb y un máximo de 5000 sat/kb para evitar valores extremos
109
- const safeFee = Math.max(50, Math.min(competitiveFee, 5000));
110
- console.log(`Calculated fee rate: ${safeFee.toFixed(2)} sat/kb from block ${currentHeight}`);
103
+ // 4. SafeFee con tus nuevos límites
104
+ // Nota: Subimos el mínimo a 1.1 para asegurar prioridad sobre el polvo de la red
105
+ const safeFee = Math.max(1.1, Math.min(competitiveFee, 500));
106
+ console.log(`Calculated MEDIAN fee rate: ${safeFee.toFixed(2)} sat/kb`);
111
107
  return Math.round(safeFee * 100) / 100;
112
108
  }
113
109
  catch (error) {
114
- console.warn('Fee estimation from block stats failed, using fallback');
115
- return 500; // Fallback a 500 sat/kb
110
+ console.warn('Fee estimation failed, using fallback');
111
+ return 1.1; // Fallback mucho más realista para BSV que 500
116
112
  }
117
113
  });
118
114
  this.isConnected = () => this._isConnected;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gn-provider",
3
- "version": "1.2.6",
3
+ "version": "1.2.7",
4
4
  "files": [
5
5
  "dist",
6
6
  "scripts",