Improved empty mempool as well as medium and low fee estimations.
refs #65
This commit is contained in:
parent
766bd0d1e0
commit
15bb5a966b
@ -1,4 +1,5 @@
|
|||||||
const config = require('../../mempool-config.json');
|
const config = require('../../mempool-config.json');
|
||||||
|
import { MempoolBlock } from '../interfaces';
|
||||||
import projectedBlocks from './mempool-blocks';
|
import projectedBlocks from './mempool-blocks';
|
||||||
|
|
||||||
class FeeApi {
|
class FeeApi {
|
||||||
@ -8,6 +9,7 @@ class FeeApi {
|
|||||||
|
|
||||||
public getRecommendedFee() {
|
public getRecommendedFee() {
|
||||||
const pBlocks = projectedBlocks.getMempoolBlocks();
|
const pBlocks = projectedBlocks.getMempoolBlocks();
|
||||||
|
|
||||||
if (!pBlocks.length) {
|
if (!pBlocks.length) {
|
||||||
return {
|
return {
|
||||||
'fastestFee': this.defaultFee,
|
'fastestFee': this.defaultFee,
|
||||||
@ -15,14 +17,10 @@ class FeeApi {
|
|||||||
'hourFee': this.defaultFee,
|
'hourFee': this.defaultFee,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
let firstMedianFee = Math.ceil(pBlocks[0].medianFee);
|
|
||||||
|
|
||||||
if (pBlocks.length === 1 && pBlocks[0].blockVSize <= 500000) {
|
const firstMedianFee = this.optimizeMedianFee(pBlocks[0]);
|
||||||
firstMedianFee = this.defaultFee;
|
const secondMedianFee = pBlocks[1] ? this.optimizeMedianFee(pBlocks[1], firstMedianFee) : this.defaultFee;
|
||||||
}
|
const thirdMedianFee = pBlocks[2] ? this.optimizeMedianFee(pBlocks[2], secondMedianFee) : this.defaultFee;
|
||||||
|
|
||||||
const secondMedianFee = pBlocks[1] ? Math.ceil(pBlocks[1].medianFee) : this.defaultFee;
|
|
||||||
const thirdMedianFee = pBlocks[2] ? Math.ceil(pBlocks[2].medianFee) : this.defaultFee;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'fastestFee': firstMedianFee,
|
'fastestFee': firstMedianFee,
|
||||||
@ -30,6 +28,18 @@ class FeeApi {
|
|||||||
'hourFee': thirdMedianFee,
|
'hourFee': thirdMedianFee,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private optimizeMedianFee(pBlock: MempoolBlock, previousFee?: number): number {
|
||||||
|
const useFee = previousFee ? (pBlock.medianFee + previousFee / 2) : pBlock.medianFee;
|
||||||
|
if (pBlock.blockVSize <= 500000) {
|
||||||
|
return this.defaultFee;
|
||||||
|
}
|
||||||
|
if (pBlock.blockVSize <= 950000) {
|
||||||
|
const multiplier = (pBlock.blockVSize - 500000) / 500000;
|
||||||
|
return Math.max(Math.round(useFee * multiplier), this.defaultFee);
|
||||||
|
}
|
||||||
|
return Math.round(useFee);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default new FeeApi();
|
export default new FeeApi();
|
||||||
|
@ -2,6 +2,7 @@ import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core';
|
|||||||
import { StateService } from 'src/app/services/state.service';
|
import { StateService } from 'src/app/services/state.service';
|
||||||
import { map, filter } from 'rxjs/operators';
|
import { map, filter } from 'rxjs/operators';
|
||||||
import { merge, Observable } from 'rxjs';
|
import { merge, Observable } from 'rxjs';
|
||||||
|
import { MempoolBlock } from 'src/app/interfaces/websocket.interface';
|
||||||
|
|
||||||
interface FeeEstimations {
|
interface FeeEstimations {
|
||||||
fastestFee: number;
|
fastestFee: number;
|
||||||
@ -18,13 +19,14 @@ interface FeeEstimations {
|
|||||||
export class FeesBoxComponent implements OnInit {
|
export class FeesBoxComponent implements OnInit {
|
||||||
feeEstimations$: Observable<FeeEstimations>;
|
feeEstimations$: Observable<FeeEstimations>;
|
||||||
isLoadingWebSocket$: Observable<boolean>;
|
isLoadingWebSocket$: Observable<boolean>;
|
||||||
|
defaultFee: number;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private stateService: StateService,
|
private stateService: StateService,
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
const defaultFee = this.stateService.network === 'liquid' ? 0.1 : 1;
|
this.defaultFee = this.stateService.network === 'liquid' ? 0.1 : 1;
|
||||||
|
|
||||||
this.isLoadingWebSocket$ = this.stateService.isLoadingWebSocket$;
|
this.isLoadingWebSocket$ = this.stateService.isLoadingWebSocket$;
|
||||||
this.feeEstimations$ = this.stateService.mempoolBlocks$
|
this.feeEstimations$ = this.stateService.mempoolBlocks$
|
||||||
@ -32,19 +34,15 @@ export class FeesBoxComponent implements OnInit {
|
|||||||
map((pBlocks) => {
|
map((pBlocks) => {
|
||||||
if (!pBlocks.length) {
|
if (!pBlocks.length) {
|
||||||
return {
|
return {
|
||||||
'fastestFee': defaultFee,
|
'fastestFee': this.defaultFee,
|
||||||
'halfHourFee': defaultFee,
|
'halfHourFee': this.defaultFee,
|
||||||
'hourFee': defaultFee,
|
'hourFee': this.defaultFee,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
let firstMedianFee = Math.ceil(pBlocks[0].medianFee);
|
|
||||||
|
|
||||||
if (pBlocks.length === 1 && pBlocks[0].blockVSize <= 500000) {
|
const firstMedianFee = this.optimizeMedianFee(pBlocks[0]);
|
||||||
firstMedianFee = defaultFee;
|
const secondMedianFee = pBlocks[1] ? this.optimizeMedianFee(pBlocks[1], firstMedianFee) : this.defaultFee;
|
||||||
}
|
const thirdMedianFee = pBlocks[2] ? this.optimizeMedianFee(pBlocks[2], secondMedianFee) : this.defaultFee;
|
||||||
|
|
||||||
const secondMedianFee = pBlocks[1] ? Math.ceil(pBlocks[1].medianFee) : defaultFee;
|
|
||||||
const thirdMedianFee = pBlocks[2] ? Math.ceil(pBlocks[2].medianFee) : defaultFee;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'fastestFee': firstMedianFee,
|
'fastestFee': firstMedianFee,
|
||||||
@ -55,4 +53,16 @@ export class FeesBoxComponent implements OnInit {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
optimizeMedianFee(pBlock: MempoolBlock, previousFee?: number): number {
|
||||||
|
const useFee = previousFee ? (pBlock.medianFee + previousFee / 2) : pBlock.medianFee;
|
||||||
|
if (pBlock.blockVSize <= 500000) {
|
||||||
|
return this.defaultFee;
|
||||||
|
}
|
||||||
|
if (pBlock.blockVSize <= 950000) {
|
||||||
|
const multiplier = (pBlock.blockVSize - 500000) / 500000;
|
||||||
|
return Math.max(Math.round(useFee * multiplier), this.defaultFee);
|
||||||
|
}
|
||||||
|
return Math.round(useFee);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user