aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2018-01-06 13:24:20 +0800
committerDan Finlay <dan@danfinlay.com>2018-01-06 13:24:20 +0800
commit4bca98d588869fb58796a6b2f29dca48605ceeba (patch)
tree93100a4b5d76c4d0408f5cdddfe70fde3399b80c /app
parent571f6723a64f28f22b7a7439d1f16bcbc9345320 (diff)
downloadtangerine-wallet-browser-4bca98d588869fb58796a6b2f29dca48605ceeba.tar
tangerine-wallet-browser-4bca98d588869fb58796a6b2f29dca48605ceeba.tar.gz
tangerine-wallet-browser-4bca98d588869fb58796a6b2f29dca48605ceeba.tar.bz2
tangerine-wallet-browser-4bca98d588869fb58796a6b2f29dca48605ceeba.tar.lz
tangerine-wallet-browser-4bca98d588869fb58796a6b2f29dca48605ceeba.tar.xz
tangerine-wallet-browser-4bca98d588869fb58796a6b2f29dca48605ceeba.tar.zst
tangerine-wallet-browser-4bca98d588869fb58796a6b2f29dca48605ceeba.zip
Derive gas price estimate from previous transactions
Return the 50th percentile lowest gas price of the previous 20 blocks.
Diffstat (limited to 'app')
-rw-r--r--app/scripts/controllers/blacklist.js1
-rw-r--r--app/scripts/controllers/transactions.js3
-rw-r--r--app/scripts/metamask-controller.js21
3 files changed, 23 insertions, 2 deletions
diff --git a/app/scripts/controllers/blacklist.js b/app/scripts/controllers/blacklist.js
index dd671943f..33c31dab9 100644
--- a/app/scripts/controllers/blacklist.js
+++ b/app/scripts/controllers/blacklist.js
@@ -57,3 +57,4 @@ class BlacklistController {
}
module.exports = BlacklistController
+
diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js
index 7c7efb84d..be7e7221f 100644
--- a/app/scripts/controllers/transactions.js
+++ b/app/scripts/controllers/transactions.js
@@ -32,6 +32,7 @@ module.exports = class TransactionController extends EventEmitter {
this.provider = opts.provider
this.blockTracker = opts.blockTracker
this.signEthTx = opts.signTransaction
+ this.getGasPrice = opts.getGasPrice
this.memStore = new ObservableStore({})
this.query = new EthQuery(this.provider)
@@ -179,7 +180,7 @@ module.exports = class TransactionController extends EventEmitter {
// ensure value
txMeta.gasPriceSpecified = Boolean(txParams.gasPrice)
txMeta.nonceSpecified = Boolean(txParams.nonce)
- const gasPrice = txParams.gasPrice || await this.query.gasPrice()
+ const gasPrice = txParams.gasPrice || this.getGasPrice()
txParams.gasPrice = ethUtil.addHexPrefix(gasPrice.toString(16))
txParams.value = txParams.value || '0x0'
// set gasLimit
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index 23f2a1598..7ffa653e4 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -35,13 +35,15 @@ const accountImporter = require('./account-import-strategies')
const getBuyEthUrl = require('./lib/buy-eth-url')
const Mutex = require('await-semaphore').Mutex
const version = require('../manifest.json').version
+const BN = require('ethereumjs-util').BN
+const GWEI_BN = new BN('1000000000')
+const percentile = require('percentile')
module.exports = class MetamaskController extends EventEmitter {
constructor (opts) {
super()
-
this.sendUpdate = debounce(this.privateSendUpdate.bind(this), 200)
this.opts = opts
@@ -139,6 +141,7 @@ module.exports = class MetamaskController extends EventEmitter {
provider: this.provider,
blockTracker: this.blockTracker,
ethQuery: this.ethQuery,
+ getGasPrice: this.getGasPrice.bind(this),
})
this.txController.on('newUnapprovedTx', opts.showUnapprovedTx.bind(opts))
@@ -484,6 +487,22 @@ module.exports = class MetamaskController extends EventEmitter {
this.emit('update', this.getState())
}
+ getGasPrice () {
+ const { recentBlocksController } = this
+ console.dir(recentBlocksController)
+ const { recentBlocks } = recentBlocksController.store.getState()
+ console.dir(recentBlocks)
+ const lowestPrices = recentBlocks.map((block) => {
+ return block.transactions
+ .sort((a, b) => {
+ return a.gt(b) ? 1 : -1
+ })[0]
+ })
+ .map(number => number.div(GWEI_BN).toNumber())
+ console.dir({ lowestPrices })
+ return percentile(50, lowestPrices)
+ }
+
//
// Vault Management
//