-
Notifications
You must be signed in to change notification settings - Fork 515
Added fee market components. #653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,14 @@ | ||
| import { | ||
| averageNativeSegwitTransactionVsize, | ||
| feeEstimateTargets, | ||
| satoshisPerBitcoin, | ||
| } from '../const' | ||
|
|
||
| const MAX_BLOCK_VSIZE = 1000000 | ||
|
|
||
| export const getFeeTierBoundaries = feeEst => { | ||
| const low = feeEst && feeEst[12] | ||
| , high = feeEst && feeEst[3] | ||
| const low = feeEst && feeEst[feeEstimateTargets.low] | ||
| , high = feeEst && feeEst[feeEstimateTargets.average] | ||
|
|
||
| return Number.isFinite(low) && Number.isFinite(high) && low >= 0 && high >= 0 | ||
| ? { low, high: Math.max(low, high) } | ||
|
|
@@ -38,6 +44,16 @@ export function getConfEstimate(fee_estimates, feerate) { | |
| return target_est ? target_est[0] : -1 | ||
| } | ||
|
|
||
| // Estimate the USD cost of a typical native SegWit transaction at a given fee-rate. | ||
| export function estimateNativeSegwitTransactionFeeUsd(bitcoinPrice, feerate) { | ||
| return Number.isFinite(bitcoinPrice) && bitcoinPrice >= 0 | ||
| && Number.isFinite(feerate) && feerate >= 0 | ||
| ? (bitcoinPrice / satoshisPerBitcoin) * | ||
| feerate * | ||
| averageNativeSegwitTransactionVsize | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We render this block for both networks. On the Liquid Network, the concept of a "Native SegWit transaction" does not apply in the same way as on Bitcoin. Liquid uses a modified transaction architecture built on the Elements codebase, where default transfers are Confidential Transactions that bundle cryptographic range proofs and Pedersen commitments for privacy. A standard single-input, dual-output Liquid transaction is significantly larger than a plain Bitcoin Native SegWit (P2WPKH) transaction - averaging roughly 1500 to 2000 bytes/vBytes instead of ~141 vBytes due to the mandatory inclusion of size-heavy range proofs (bulletproofs) that hide asset types and amounts. |
||
| : null | ||
| } | ||
|
|
||
| // Squash the fee histogram into fixed feerate ranges | ||
| export function squashFeeHistogram(histogram) { | ||
| let i = 0 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| export const getBitcoinPrices = marketChart => | ||
| ((marketChart && marketChart.prices) || []) | ||
| .map(price => price && price[1]) | ||
| .filter(Number.isFinite) | ||
|
Comment on lines
+1
to
+4
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better to add check for array value, and we can simplify code like |
||
|
|
||
| export const getLatestBitcoinPrice = marketChart => { | ||
| const prices = getBitcoinPrices(marketChart) | ||
| return prices.length ? prices[prices.length - 1] : null | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import { InfoCard } from "../components/info-card"; | ||
| import { feeEstimateTargets } from "../const"; | ||
| import { estimateNativeSegwitTransactionFeeUsd } from "../lib/fees"; | ||
| import { getLatestBitcoinPrice } from "../lib/market"; | ||
| import { formatFeeRate, formatUsd } from "./util"; | ||
|
|
||
| const getFeeMarketLevels = (t) => [ | ||
| { | ||
| key: "low", | ||
| title: t`Low`, | ||
| tooltip: t`A lower-priority fee rate estimated to confirm within ${feeEstimateTargets.low} blocks.`, | ||
| }, | ||
| { | ||
| key: "average", | ||
| title: t`Average`, | ||
| tooltip: t`A balanced fee rate estimated to confirm within ${feeEstimateTargets.average} blocks.`, | ||
| }, | ||
| { | ||
| key: "high", | ||
| title: t`High`, | ||
| tooltip: t`A higher-priority fee rate estimated to confirm in the next block.`, | ||
| }, | ||
| ]; | ||
|
|
||
| export const feeMarket = ({ feeEst, bitcoinMarketChart, t } = {}) => { | ||
| const bitcoinPrice = getLatestBitcoinPrice(bitcoinMarketChart); | ||
| const unavailable = t`N/A`; | ||
|
|
||
| return ( | ||
| <div className="fee-market"> | ||
| <p className="section-title">{t`Fee Market`}</p> | ||
| <div className="fee-market-body"> | ||
| {getFeeMarketLevels(t).map(({ key, title, tooltip }) => { | ||
| const feerate = feeEst && feeEst[feeEstimateTargets[key]]; | ||
| const feeUsd = estimateNativeSegwitTransactionFeeUsd( | ||
| bitcoinPrice, | ||
| feerate, | ||
| ); | ||
|
|
||
| return ( | ||
| <InfoCard | ||
| className={`fee-market-${key}`} | ||
| title={title} | ||
| tooltip={tooltip} | ||
| value={formatFeeRate(feerate, unavailable)} | ||
| footer={formatUsd(feeUsd, unavailable)} | ||
|
Comment on lines
+45
to
+46
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can use default fallback instead of |
||
| /> | ||
| ); | ||
| })} | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You take
feeEstimateTargets.averagebut marked it ashight. This could lead to misunderstandings in feature.