gn-provider 1.1.9 → 1.2.1

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.
Files changed (2) hide show
  1. package/dist/gn-provider.js +22 -12
  2. package/package.json +1 -1
@@ -83,22 +83,32 @@ class GNProvider extends abstract_provider_1.Provider {
83
83
  yield this._ready();
84
84
  const headers = this._getHeaders();
85
85
  try {
86
- const now = Math.floor(Date.now() / 1000);
87
- const from = now - 1800; // 30 minutos atrás
88
- const res = yield superagent.get(`${this.apiPrefix()}/miner/fees?from=${from}&to=${now}`)
86
+ // Paso 1: Obtener la información de la cadena para obtener la altura actual
87
+ const chainInfoRes = yield superagent.get(`${this.apiPrefix()}/chain/info`)
89
88
  .set(headers);
90
- if (res.body && Array.isArray(res.body) && res.body.length > 0) {
91
- const totalFeeRate = res.body.reduce((sum, minerData) => {
92
- return sum + minerData.min_fee_rate;
93
- }, 0);
94
- const averageFeeRate = totalFeeRate / res.body.length;
95
- const feeRateWithMargin = averageFeeRate * 1.3;
96
- return Math.round(feeRateWithMargin * 100) / 100;
89
+ const currentHeight = chainInfoRes.body.blocks;
90
+ // Paso 2: Obtener las estadísticas del bloque actual
91
+ const blockStatsRes = yield superagent.get(`${this.apiPrefix()}/block/height/${currentHeight}/stats`)
92
+ .set(headers);
93
+ const blockStats = blockStatsRes.body;
94
+ const totalFee = blockStats.total_fee;
95
+ const size = blockStats.size;
96
+ // Si el tamaño es 0, evitar división por cero
97
+ if (size === 0) {
98
+ throw new Error('Block size is zero');
97
99
  }
98
- throw new Error("No fee data available");
100
+ // Calcular tarifa por kilobyte: (total_fee * 1024) / size
101
+ const feePerKb = (totalFee * 1024) / size;
102
+ // Aplicar un multiplicador para asegurar una tarifa competitiva (1.5x)
103
+ const competitiveFee = feePerKb * 1.5;
104
+ // Establecer un mínimo de 50 sat/kb y un máximo de 5000 sat/kb para evitar valores extremos
105
+ const safeFee = Math.max(50, Math.min(competitiveFee, 5000));
106
+ console.log(`Calculated fee rate: ${safeFee.toFixed(2)} sat/kb from block ${currentHeight}`);
107
+ return Math.round(safeFee * 100) / 100;
99
108
  }
100
109
  catch (error) {
101
- return 1.05;
110
+ console.warn('Fee estimation from block stats failed, using fallback');
111
+ return 500; // Fallback a 500 sat/kb
102
112
  }
103
113
  });
104
114
  this.isConnected = () => this._isConnected;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gn-provider",
3
- "version": "1.1.9",
3
+ "version": "1.2.1",
4
4
  "files": [
5
5
  "dist",
6
6
  "scripts",