maxFee and maxPriorityFee for eip1559

pull/1432/head
yann300 3 years ago committed by Aniket
parent 670e7ad479
commit 7545b7ce82
  1. 7
      apps/remix-ide/src/app/tabs/runTab/contractDropdown.js
  2. 7
      apps/remix-ide/src/app/tabs/runTab/recorder.js
  3. 62
      apps/remix-ide/src/app/ui/confirmDialog.js
  4. 7
      apps/remix-ide/src/app/ui/sendTxCallbacks.js
  5. 6
      apps/remix-ide/src/blockchain/execution-context.js
  6. 18
      libs/remix-lib/src/execution/txRunnerWeb3.ts

@ -361,7 +361,7 @@ class ContractDropdownUI {
return continueTxExecution(null) return continueTxExecution(null)
} }
const amount = this.blockchain.fromWei(tx.value, true, 'ether') const amount = this.blockchain.fromWei(tx.value, true, 'ether')
const content = confirmDialog(tx, amount, gasEstimation, null, this.blockchain.determineGasFees(tx), this.blockchain.determineGasPrice.bind(this.blockchain)) const content = confirmDialog(tx, network, amount, gasEstimation, this.blockchain.determineGasFees(tx), this.blockchain.determineGasPrice.bind(this.blockchain))
modalDialog('Confirm transaction', content, modalDialog('Confirm transaction', content,
{ {
@ -370,10 +370,9 @@ class ContractDropdownUI {
this.blockchain.config.setUnpersistedProperty('doNotShowTransactionConfirmationAgain', content.querySelector('input#confirmsetting').checked) this.blockchain.config.setUnpersistedProperty('doNotShowTransactionConfirmationAgain', content.querySelector('input#confirmsetting').checked)
// TODO: check if this is check is still valid given the refactor // TODO: check if this is check is still valid given the refactor
if (!content.gasPriceStatus) { if (!content.gasPriceStatus) {
cancelCb('Given gas price is not correct') cancelCb('Given transaction fee is not correct')
} else { } else {
var gasPrice = this.blockchain.toWei(content.querySelector('#gasprice').value, 'gwei') continueTxExecution(content.txFee)
continueTxExecution(gasPrice)
} }
} }
}, { }, {

@ -104,7 +104,7 @@ class RecorderUI extends Plugin {
return continueTxExecution(null) return continueTxExecution(null)
} }
const amount = this.blockchain.fromWei(tx.value, true, 'ether') const amount = this.blockchain.fromWei(tx.value, true, 'ether')
const content = confirmDialog(tx, amount, gasEstimation, null, this.blockchain.determineGasFees(tx), this.blockchain.determineGasPrice.bind(this.blockchain)) const content = confirmDialog(tx, network, amount, gasEstimation, this.blockchain.determineGasFees(tx), this.blockchain.determineGasPrice.bind(this.blockchain))
modalDialog('Confirm transaction', content, modalDialog('Confirm transaction', content,
{ {
@ -113,10 +113,9 @@ class RecorderUI extends Plugin {
this.config.setUnpersistedProperty('doNotShowTransactionConfirmationAgain', content.querySelector('input#confirmsetting').checked) this.config.setUnpersistedProperty('doNotShowTransactionConfirmationAgain', content.querySelector('input#confirmsetting').checked)
// TODO: check if this is check is still valid given the refactor // TODO: check if this is check is still valid given the refactor
if (!content.gasPriceStatus) { if (!content.gasPriceStatus) {
cancelCb('Given gas price is not correct') cancelCb('Given transaction fee is not correct')
} else { } else {
var gasPrice = this.blockchain.toWei(content.querySelector('#gasprice').value, 'gwei') continueTxExecution(content.txFee)
continueTxExecution(gasPrice)
} }
} }
}, { }, {

@ -14,20 +14,36 @@ var css = csjs`
} }
` `
// TODO: self is not actually used and can be removed function confirmDialog (tx, network, amount, gasEstimation, newGasPriceCb, initialParamsCb) {
function confirmDialog (tx, amount, gasEstimation, self, newGasPriceCb, initialParamsCb) { const onGasPriceChange = function () {
var onGasPriceChange = function () {
var gasPrice = el.querySelector('#gasprice').value var gasPrice = el.querySelector('#gasprice').value
newGasPriceCb(gasPrice, (txFeeText, priceStatus) => { newGasPriceCb(gasPrice, (txFeeText, priceStatus) => {
el.querySelector('#txfee').innerHTML = txFeeText el.querySelector('#txfee').innerHTML = txFeeText
el.gasPriceStatus = priceStatus el.gasPriceStatus = priceStatus
el.txFee = { gasPrice }
}) })
} }
var el = yo` const onMaxFeeChange = function () {
var maxFee = el.querySelector('#maxfee').value
var maxPriorityFee = el.querySelector('#maxpriorityfee').value
if (parseInt(network.lastBlock.baseFeePerGas, 16) > parseInt(maxFee)) {
el.querySelector('#txfee').innerHTML = 'Transaction is invalid. Base fee should not be bigger than Max fee'
el.gasPriceStatus = false
return
} else el.gasPriceStatus = true
newGasPriceCb(maxFee, (txFeeText, priceStatus) => {
el.querySelector('#txfee').innerHTML = txFeeText
el.gasPriceStatus = priceStatus
el.txFee = { maxFee, maxPriorityFee, baseFeePerGas: network.lastBlock.baseFeePerGas }
})
}
const el = yo`
<div> <div>
<div>You are about to create a transaction on the Main Network. Confirm the details to send the info to your provider. <div>You are about to create a transaction on ${network.name}. Confirm the details to send the info to your provider.
<br>The provider for many users is MetaMask. The provider will ask you to sign the transaction before it is sent to the Main Network.</div> <br>The provider for many users is MetaMask. The provider will ask you to sign the transaction before it is sent to ${network.name}.</div>
<div class="mt-3 ${css.txInfoBox}"> <div class="mt-3 ${css.txInfoBox}">
<div> <div>
<span class="text-dark mr-2">From:</span> <span class="text-dark mr-2">From:</span>
@ -53,11 +69,29 @@ function confirmDialog (tx, amount, gasEstimation, self, newGasPriceCb, initialP
<span class="text-dark mr-2">Max transaction fee:</span> <span class="text-dark mr-2">Max transaction fee:</span>
<span id='txfee'></span> <span id='txfee'></span>
</div> </div>
<div class="d-flex align-items-center my-1"> ${
<span class="text-dark mr-2">Gas price:</span> network.lastBlock.baseFeePerGas ? yo`<div class="align-items-center my-1">
<input class="form-control mr-1" style='width: 40px; height: 28px;'id='gasprice' oninput=${onGasPriceChange} /> <div>
<span>Gwei (visit <a target='_blank' href='https://ethgasstation.info'>ethgasstation.info</a> for current gas price info.)</span> <span class="text-dark mr-2">Max Priority fee:</span>
</div> <input class="form-control mr-1" style='height: 28px;' value="0" id='maxpriorityfee' />
<span>Gwei</span>
</div>
<div class="text-dark mr-2 font-italic">Represents the part of the tx fee that goes to the miner</div>
</div>
<div class="align-items-center my-1">
<div>
<span class="text-dark mr-2">Max fee:</span>
<input class="form-control mr-1" style='height: 28px;' id='maxfee' oninput=${onMaxFeeChange} />
<span>Gwei</span>
</div>
<div class="text-dark mr-2 font-italic">Represents the maximum amount of fee that you will pay for this transaction. The minimun needs to be set to base fee.</div>
</div>`
: yo`<div class="d-flex align-items-center my-1">
<span class="text-dark mr-2">Gas price:</span>
<input class="form-control mr-1" style='width: 40px; height: 28px;' id='gasprice' oninput=${onGasPriceChange} />
<span>Gwei (visit <a target='_blank' href='https://ethgasstation.info'>ethgasstation.info</a> for current gas price info.)</span>
</div>`
}
<div class="d-flex align-items-center"> <div class="d-flex align-items-center">
<span class="text-dark mr-2 mb-3">Data:</span> <span class="text-dark mr-2 mb-3">Data:</span>
<pre class=${css.wrapword}>${tx.data && tx.data.length > 50 ? tx.data.substring(0, 49) + '...' : tx.data} ${copyToClipboard(() => { return tx.data })}</pre> <pre class=${css.wrapword}>${tx.data && tx.data.length > 50 ? tx.data.substring(0, 49) + '...' : tx.data} ${copyToClipboard(() => { return tx.data })}</pre>
@ -74,10 +108,14 @@ function confirmDialog (tx, amount, gasEstimation, self, newGasPriceCb, initialP
if (txFeeText) { if (txFeeText) {
el.querySelector('#txfee').innerHTML = txFeeText el.querySelector('#txfee').innerHTML = txFeeText
} }
if (gasPriceValue) { if (el.querySelector('#gasprice') && gasPriceValue) {
el.querySelector('#gasprice').value = gasPriceValue el.querySelector('#gasprice').value = gasPriceValue
onGasPriceChange() onGasPriceChange()
} }
if (el.querySelector('#maxfee') && network && network.lastBlock && network.lastBlock.baseFeePerGas && el.querySelector('#maxfee')) {
el.querySelector('#maxfee').value = parseInt(network.lastBlock.baseFeePerGas, 16)
onMaxFeeChange()
}
if (gasPriceStatus !== undefined) { if (gasPriceStatus !== undefined) {
el.gasPriceStatus = gasPriceStatus el.gasPriceStatus = gasPriceStatus
} }

@ -51,7 +51,7 @@ const confirmationCb = function (network, tx, gasEstimation, continueTxExecution
return continueTxExecution(null) return continueTxExecution(null)
} }
var amount = Web3.utils.fromWei(typeConversion.toInt(tx.value), 'ether') var amount = Web3.utils.fromWei(typeConversion.toInt(tx.value), 'ether')
var content = confirmDialog(tx, amount, gasEstimation, self.udappUI, var content = confirmDialog(tx, network, amount, gasEstimation,
(gasPrice, cb) => { (gasPrice, cb) => {
let txFeeText, priceStatus let txFeeText, priceStatus
// TODO: this try catch feels like an anti pattern, can/should be // TODO: this try catch feels like an anti pattern, can/should be
@ -93,10 +93,9 @@ const confirmationCb = function (network, tx, gasEstimation, continueTxExecution
) )
// TODO: check if this is check is still valid given the refactor // TODO: check if this is check is still valid given the refactor
if (!content.gasPriceStatus) { if (!content.gasPriceStatus) {
cancelCb('Given gas price is not correct') cancelCb('Given transaction fee is not correct')
} else { } else {
var gasPrice = Web3.utils.toWei(content.querySelector('#gasprice').value, 'gwei') continueTxExecution(content.txFee)
continueTxExecution(gasPrice)
} }
} }
}, },

@ -20,6 +20,7 @@ export class ExecutionContext {
constructor () { constructor () {
this.event = new EventManager() this.event = new EventManager()
this.executionContext = null this.executionContext = null
this.lastBlock = null
this.blockGasLimitDefault = 4300000 this.blockGasLimitDefault = 4300000
this.blockGasLimit = this.blockGasLimitDefault this.blockGasLimit = this.blockGasLimitDefault
this.currentFork = 'berlin' this.currentFork = 'berlin'
@ -86,10 +87,10 @@ export class ExecutionContext {
web3.eth.getBlock(0, (error, block) => { web3.eth.getBlock(0, (error, block) => {
if (error) console.log('cant query first block') if (error) console.log('cant query first block')
if (block && block.hash !== this.mainNetGenesisHash) name = 'Custom' if (block && block.hash !== this.mainNetGenesisHash) name = 'Custom'
callback(err, { id, name }) callback(err, { id, name, lastBlock: this.lastBlock, currentFork: this.currentFork })
}) })
} else { } else {
callback(err, { id, name }) callback(err, { id, name, lastBlock: this.lastBlock, currentFork: this.currentFork })
} }
}) })
} }
@ -176,6 +177,7 @@ export class ExecutionContext {
const block = await web3.eth.getBlock('latest') const block = await web3.eth.getBlock('latest')
// we can't use the blockGasLimit cause the next blocks could have a lower limit : https://github.com/ethereum/remix/issues/506 // we can't use the blockGasLimit cause the next blocks could have a lower limit : https://github.com/ethereum/remix/issues/506
this.blockGasLimit = (block && block.gasLimit) ? Math.floor(block.gasLimit - (5 * block.gasLimit) / 1024) : this.blockGasLimitDefault this.blockGasLimit = (block && block.gasLimit) ? Math.floor(block.gasLimit - (5 * block.gasLimit) / 1024) : this.blockGasLimitDefault
this.lastBlock = block
try { try {
this.currentFork = execution.forkAt(await web3.eth.net.getId(), block.number) this.currentFork = execution.forkAt(await web3.eth.net.getId(), block.number)
} catch (e) { } catch (e) {

@ -15,8 +15,18 @@ export class TxRunnerWeb3 {
this._api = api this._api = api
} }
_executeTx (tx, gasPrice, api, promptCb, callback) { _executeTx (tx, txFee, api, promptCb, callback) {
if (gasPrice) tx.gasPrice = this.getWeb3().utils.toHex(gasPrice) if (txFee) {
if (txFee.baseFeePerGas) {
tx.maxPriorityFee = this.getWeb3().utils.toHex(this.getWeb3().utils.toWei(txFee.maxPriorityFee, 'gwei'))
tx.maxFee = this.getWeb3().utils.toHex(this.getWeb3().utils.toWei(txFee.maxFee, 'gwei'))
tx.type = 2
} else {
tx.gasPrice = this.getWeb3().utils.toHex(this.getWeb3().utils.toWei(txFee.gasPrice, 'gwei'))
tx.type = 1
}
}
if (api.personalMode()) { if (api.personalMode()) {
promptCb( promptCb(
(value) => { (value) => {
@ -100,8 +110,8 @@ export class TxRunnerWeb3 {
return return
} }
confirmCb(network, tx, tx['gas'], (gasPrice) => { confirmCb(network, tx, tx['gas'], (txFee) => {
return this._executeTx(tx, gasPrice, this._api, promptCb, callback) return this._executeTx(tx, txFee, this._api, promptCb, callback)
}, (error) => { }, (error) => {
callback(error) callback(error)
}) })

Loading…
Cancel
Save