Skip to content

Commit

Permalink
Add a maximumFeeRateCalculator function for hard-coded FeeInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
samholmes committed Oct 11, 2023
1 parent 847b975 commit db629ad
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 17 deletions.
19 changes: 19 additions & 0 deletions src/common/plugin/util/maximumFeeRateCalculator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { EdgeCurrencyInfo } from 'edge-core-js/types'

/**
* Calculates a maximum fee rate of 1 USD per vByte given a USD exchange rate
* (usdPrice).
*/
export const maximumFeeRateCalculator = (
currencyInfo: EdgeCurrencyInfo,
usdPrice: number
): string | undefined => {
const { currencyCode, denominations } = currencyInfo
const primaryDenomination = denominations.find(
denom => denom.name === currencyCode
)
if (primaryDenomination == null) return undefined

const decimals: number = primaryDenomination.multiplier.length - 1
return Math.round((1 / usdPrice) * 10 ** decimals).toString()
}
4 changes: 3 additions & 1 deletion src/common/utxobased/info/bitcoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { EdgeCurrencyInfo } from 'edge-core-js/types'

import { IMAGE_SERVER_URL } from '../../constants'
import { CoinInfo, EngineInfo, PluginInfo } from '../../plugin/types'
import { maximumFeeRateCalculator } from '../../plugin/util/maximumFeeRateCalculator'
import { memoInfo } from './commonInfo'

const currencyInfo: EdgeCurrencyInfo = {
Expand Down Expand Up @@ -65,7 +66,8 @@ const engineInfo: EngineInfo = {
standardFeeLow: '50',
standardFeeHigh: '100',
standardFeeLowAmount: '173200',
standardFeeHighAmount: '8670000'
standardFeeHighAmount: '8670000',
maximumFeeRate: maximumFeeRateCalculator(currencyInfo, 27460.65)
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/common/utxobased/info/bitcoincash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { EdgeCurrencyInfo } from 'edge-core-js/types'

import { IMAGE_SERVER_URL } from '../../constants'
import { CoinInfo, EngineInfo, PluginInfo } from '../../plugin/types'
import { maximumFeeRateCalculator } from '../../plugin/util/maximumFeeRateCalculator'
import { memoInfo } from './commonInfo'
import { scriptTemplates } from './scriptTemplates/bitcoincashScriptTemplates'

Expand Down Expand Up @@ -66,7 +67,8 @@ const engineInfo: EngineInfo = {
standardFeeLow: '5',
standardFeeHigh: '10',
standardFeeLowAmount: '1000000',
standardFeeHighAmount: '65000000'
standardFeeHighAmount: '65000000',
maximumFeeRate: maximumFeeRateCalculator(currencyInfo, 212.86)
},
scriptTemplates,
asBlockbookAddress: asCodec(
Expand Down
4 changes: 3 additions & 1 deletion src/common/utxobased/info/bitcoingold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Psbt } from 'altcoin-js'
import { EdgeCurrencyInfo } from 'edge-core-js/types'

import { CoinInfo, EngineInfo, PluginInfo } from '../../plugin/types'
import { maximumFeeRateCalculator } from '../../plugin/util/maximumFeeRateCalculator'
import { memoInfo } from './commonInfo'

const currencyInfo: EdgeCurrencyInfo = {
Expand Down Expand Up @@ -57,7 +58,8 @@ const engineInfo: EngineInfo = {
standardFeeLow: '15',
standardFeeHigh: '140',
standardFeeLowAmount: '17320',
standardFeeHighAmount: '86700000'
standardFeeHighAmount: '86700000',
maximumFeeRate: maximumFeeRateCalculator(currencyInfo, 12.62)
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/common/utxobased/info/bitcoinsv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { EdgeCurrencyInfo } from 'edge-core-js/types'

import { IMAGE_SERVER_URL } from '../../constants'
import { CoinInfo, EngineInfo, PluginInfo } from '../../plugin/types'
import { maximumFeeRateCalculator } from '../../plugin/util/maximumFeeRateCalculator'
import {
addressToScriptPubkey,
AddressTypeEnum,
Expand Down Expand Up @@ -63,7 +64,8 @@ const engineInfo: EngineInfo = {
standardFeeLow: '5',
standardFeeHigh: '10',
standardFeeLowAmount: '1000000',
standardFeeHighAmount: '65000000'
standardFeeHighAmount: '65000000',
maximumFeeRate: maximumFeeRateCalculator(currencyInfo, 33.61)
},
/*
This is to support cashaddr and 1-addresses coming from the network.
Expand Down
4 changes: 3 additions & 1 deletion src/common/utxobased/info/dash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { asBoolean, asMaybe, asObject, asOptional } from 'cleaners'
import { EdgeCurrencyInfo } from 'edge-core-js/types'

import { CoinInfo, EngineInfo, PluginInfo } from '../../plugin/types'
import { maximumFeeRateCalculator } from '../../plugin/util/maximumFeeRateCalculator'
import { IProcessorTransaction } from '../db/types'
import { memoInfo } from './commonInfo'

Expand Down Expand Up @@ -58,7 +59,8 @@ const engineInfo: EngineInfo = {
standardFeeLow: '150',
standardFeeHigh: '200',
standardFeeLowAmount: '20000000',
standardFeeHighAmount: '981000000'
standardFeeHighAmount: '981000000',
maximumFeeRate: maximumFeeRateCalculator(currencyInfo, 25.8)
},
txSpecificHandling: (
tx: IProcessorTransaction,
Expand Down
4 changes: 3 additions & 1 deletion src/common/utxobased/info/digibyte.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { EdgeCurrencyInfo } from 'edge-core-js/types'

import { CoinInfo, EngineInfo, PluginInfo } from '../../plugin/types'
import { maximumFeeRateCalculator } from '../../plugin/util/maximumFeeRateCalculator'
import { memoInfo } from './commonInfo'

const currencyInfo: EdgeCurrencyInfo = {
Expand Down Expand Up @@ -50,7 +51,8 @@ const engineInfo: EngineInfo = {
standardFeeLow: '50',
standardFeeHigh: '100',
standardFeeLowAmount: '173200',
standardFeeHighAmount: '8670000'
standardFeeHighAmount: '8670000',
maximumFeeRate: maximumFeeRateCalculator(currencyInfo, 0.006176)
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/common/utxobased/info/dogecoin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { EdgeCurrencyInfo } from 'edge-core-js/types'

import { CoinInfo, EngineInfo, PluginInfo } from '../../plugin/types'
import { maximumFeeRateCalculator } from '../../plugin/util/maximumFeeRateCalculator'
import { memoInfo } from './commonInfo'
import { makeDogeUtxoPicker } from './utxoPickers/dogeUtxoPicker'

Expand Down Expand Up @@ -54,7 +55,8 @@ const engineInfo: EngineInfo = {
standardFeeLow: '526316',
standardFeeHigh: '526316',
standardFeeLowAmount: '2000000000',
standardFeeHighAmount: '98100000000'
standardFeeHighAmount: '98100000000',
maximumFeeRate: maximumFeeRateCalculator(currencyInfo, 0.05938)
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/common/utxobased/info/eboost.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { EdgeCurrencyInfo } from 'edge-core-js/types'

import { CoinInfo, EngineInfo, PluginInfo } from '../../plugin/types'
import { maximumFeeRateCalculator } from '../../plugin/util/maximumFeeRateCalculator'
import { memoInfo } from './commonInfo'

const currencyInfo: EdgeCurrencyInfo = {
Expand Down Expand Up @@ -49,7 +50,8 @@ const engineInfo: EngineInfo = {
standardFeeLow: '150',
standardFeeHigh: '200',
standardFeeLowAmount: '20000000',
standardFeeHighAmount: '981000000'
standardFeeHighAmount: '981000000',
maximumFeeRate: maximumFeeRateCalculator(currencyInfo, 0.0033)
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/common/utxobased/info/feathercoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { EdgeCurrencyInfo } from 'edge-core-js/types'

import { IMAGE_SERVER_URL } from '../../constants'
import { CoinInfo, EngineInfo, PluginInfo } from '../../plugin/types'
import { maximumFeeRateCalculator } from '../../plugin/util/maximumFeeRateCalculator'
import { memoInfo } from './commonInfo'

export const currencyInfo: EdgeCurrencyInfo = {
Expand Down Expand Up @@ -54,7 +55,8 @@ export const engineInfo: EngineInfo = {
standardFeeLow: '600',
standardFeeHigh: '800',
standardFeeLowAmount: '2000000000',
standardFeeHighAmount: '98100000000'
standardFeeHighAmount: '98100000000',
maximumFeeRate: maximumFeeRateCalculator(currencyInfo, 0.002275)
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/common/utxobased/info/groestlcoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { EdgeCurrencyInfo } from 'edge-core-js/types'
import * as wifgrs from 'wifgrs'

import { CoinInfo, EngineInfo, PluginInfo } from '../../plugin/types'
import { maximumFeeRateCalculator } from '../../plugin/util/maximumFeeRateCalculator'
import { memoInfo } from './commonInfo'

const currencyInfo: EdgeCurrencyInfo = {
Expand Down Expand Up @@ -55,7 +56,8 @@ const engineInfo: EngineInfo = {
standardFeeLow: '50',
standardFeeHigh: '100',
standardFeeLowAmount: '173200',
standardFeeHighAmount: '8670000'
standardFeeHighAmount: '8670000',
maximumFeeRate: maximumFeeRateCalculator(currencyInfo, 0.4705)
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/common/utxobased/info/litecoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { EdgeCurrencyInfo } from 'edge-core-js/types'

import { IMAGE_SERVER_URL } from '../../constants'
import { CoinInfo, EngineInfo, PluginInfo } from '../../plugin/types'
import { maximumFeeRateCalculator } from '../../plugin/util/maximumFeeRateCalculator'
import { memoInfo } from './commonInfo'

export const currencyInfo: EdgeCurrencyInfo = {
Expand Down Expand Up @@ -61,7 +62,8 @@ export const engineInfo: EngineInfo = {
standardFeeLow: '150',
standardFeeHigh: '200',
standardFeeLowAmount: '20000000',
standardFeeHighAmount: '981000000'
standardFeeHighAmount: '981000000',
maximumFeeRate: maximumFeeRateCalculator(currencyInfo, 63.64)
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/common/utxobased/info/qtum.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { EdgeCurrencyInfo } from 'edge-core-js/types'

import { CoinInfo, EngineInfo, PluginInfo } from '../../plugin/types'
import { maximumFeeRateCalculator } from '../../plugin/util/maximumFeeRateCalculator'
import { memoInfo } from './commonInfo'

const currencyInfo: EdgeCurrencyInfo = {
Expand Down Expand Up @@ -46,7 +47,8 @@ const engineInfo: EngineInfo = {
standardFeeLow: '450',
standardFeeHigh: '700',
standardFeeLowAmount: '20000000',
standardFeeHighAmount: '981000000'
standardFeeHighAmount: '981000000',
maximumFeeRate: maximumFeeRateCalculator(currencyInfo, 2.13)
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/common/utxobased/info/ravencoin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { EdgeCurrencyInfo } from 'edge-core-js/types'

import { CoinInfo, EngineInfo, PluginInfo } from '../../plugin/types'
import { maximumFeeRateCalculator } from '../../plugin/util/maximumFeeRateCalculator'
import { memoInfo } from './commonInfo'

const currencyInfo: EdgeCurrencyInfo = {
Expand Down Expand Up @@ -46,7 +47,8 @@ const engineInfo: EngineInfo = {
standardFeeLow: '50',
standardFeeHigh: '100',
standardFeeLowAmount: '173200',
standardFeeHighAmount: '8670000'
standardFeeHighAmount: '8670000',
maximumFeeRate: maximumFeeRateCalculator(currencyInfo, 0.01419)
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/common/utxobased/info/smartcash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { EdgeCurrencyInfo } from 'edge-core-js/types'
import * as wifsmart from 'wif-smart'

import { CoinInfo, EngineInfo, PluginInfo } from '../../plugin/types'
import { maximumFeeRateCalculator } from '../../plugin/util/maximumFeeRateCalculator'
import { memoInfo } from './commonInfo'

const currencyInfo: EdgeCurrencyInfo = {
Expand Down Expand Up @@ -52,7 +53,8 @@ const engineInfo: EngineInfo = {
standardFeeLow: '500',
standardFeeHigh: '1000',
standardFeeLowAmount: '1732000',
standardFeeHighAmount: '86700000'
standardFeeHighAmount: '86700000',
maximumFeeRate: maximumFeeRateCalculator(currencyInfo, 0.0002171)
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/common/utxobased/info/ufo.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { EdgeCurrencyInfo } from 'edge-core-js/types'

import { CoinInfo, EngineInfo, PluginInfo } from '../../plugin/types'
import { maximumFeeRateCalculator } from '../../plugin/util/maximumFeeRateCalculator'
import { memoInfo } from './commonInfo'

const currencyInfo: EdgeCurrencyInfo = {
Expand Down Expand Up @@ -49,7 +50,8 @@ const engineInfo: EngineInfo = {
standardFeeLow: '1100',
standardFeeHigh: '2000',
standardFeeLowAmount: '51282051282051',
standardFeeHighAmount: '5128205128205100'
standardFeeHighAmount: '5128205128205100',
maximumFeeRate: maximumFeeRateCalculator(currencyInfo, 0.000137)
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/common/utxobased/info/vertcoin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { EdgeCurrencyInfo } from 'edge-core-js/types'

import { CoinInfo, EngineInfo, PluginInfo } from '../../plugin/types'
import { maximumFeeRateCalculator } from '../../plugin/util/maximumFeeRateCalculator'
import { memoInfo } from './commonInfo'

const currencyInfo: EdgeCurrencyInfo = {
Expand Down Expand Up @@ -56,7 +57,8 @@ const engineInfo: EngineInfo = {
standardFeeLow: '50',
standardFeeHigh: '100',
standardFeeLowAmount: '173200',
standardFeeHighAmount: '8670000'
standardFeeHighAmount: '8670000',
maximumFeeRate: maximumFeeRateCalculator(currencyInfo, 0.04662)
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/common/utxobased/info/zcoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { EdgeCurrencyInfo } from 'edge-core-js/types'

import { IMAGE_SERVER_URL } from '../../constants'
import { CoinInfo, EngineInfo, PluginInfo } from '../../plugin/types'
import { maximumFeeRateCalculator } from '../../plugin/util/maximumFeeRateCalculator'
import { memoInfo } from './commonInfo'

export const currencyInfo: EdgeCurrencyInfo = {
Expand Down Expand Up @@ -55,7 +56,8 @@ export const engineInfo: EngineInfo = {
standardFeeLow: '50',
standardFeeHigh: '100',
standardFeeLowAmount: '173200',
standardFeeHighAmount: '8670000'
standardFeeHighAmount: '8670000',
maximumFeeRate: maximumFeeRateCalculator(currencyInfo, 1.39)
}
}

Expand Down

0 comments on commit db629ad

Please sign in to comment.