-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add config for max fee estimations
closes #2039
- Loading branch information
Showing
8 changed files
with
115 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/app/common/transactions/use-fee-estimations-max-values.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { | ||
useConfigFeeEstimationsEnabled, | ||
useConfigFeeEstimationsMaxValues, | ||
} from '@app/query/hiro-config/hiro-config.query'; | ||
|
||
const defaultFeeEstimationsMaxValues = [500000, 750000, 2000000]; | ||
|
||
export function useFeeEstimationsMaxValues() { | ||
// Get it first from the config | ||
const configFeeEstimationsEnabled = useConfigFeeEstimationsEnabled(); | ||
const configFeeEstimationsMaxValues = useConfigFeeEstimationsMaxValues(); | ||
// Only when the remote config file explicitly sets the maxValuesEnabled as false, we return no cap for fees | ||
if (configFeeEstimationsEnabled === false) return; | ||
return configFeeEstimationsMaxValues || defaultFeeEstimationsMaxValues; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { DEFAULT_FEE_RATE } from '@shared/constants'; | ||
import { FeeEstimation } from '@shared/models/fees-types'; | ||
import { BigNumber } from 'bignumber.js'; | ||
|
||
export function getFeeEstimationsWithMaxValues( | ||
feeEstimations: FeeEstimation[], | ||
feeEstimationsMaxValues: number[] | undefined | ||
) { | ||
return feeEstimations.map((feeEstimation, index) => { | ||
if ( | ||
feeEstimationsMaxValues && | ||
new BigNumber(feeEstimation.fee).isGreaterThan(feeEstimationsMaxValues[index]) | ||
) { | ||
return { fee: feeEstimationsMaxValues[index], fee_rate: 0 }; | ||
} else { | ||
return feeEstimation; | ||
} | ||
}); | ||
} | ||
|
||
function calculateFeeFromFeeRate(txBytes: number, feeRate: number) { | ||
return new BigNumber(txBytes).multipliedBy(feeRate); | ||
} | ||
|
||
const marginFromDefaultFeeDecimalPercent = 0.1; | ||
|
||
export function getDefaultSimulatedFeeEstimations(estimatedByteLength: number): FeeEstimation[] { | ||
const fee = calculateFeeFromFeeRate(estimatedByteLength, DEFAULT_FEE_RATE); | ||
return [ | ||
{ fee: fee.multipliedBy(1 - marginFromDefaultFeeDecimalPercent).toNumber(), fee_rate: 0 }, | ||
{ fee: fee.toNumber(), fee_rate: 0 }, | ||
{ fee: fee.multipliedBy(1 + marginFromDefaultFeeDecimalPercent).toNumber(), fee_rate: 0 }, | ||
]; | ||
} |