Skip to content
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

[feature] Smart Gas Price #44

Open
roynalnaruto opened this issue Jul 30, 2019 · 25 comments
Open

[feature] Smart Gas Price #44

roynalnaruto opened this issue Jul 30, 2019 · 25 comments
Labels
bounty This issue has a bounty associated with it

Comments

@roynalnaruto
Copy link

roynalnaruto commented Jul 30, 2019

At present, DigixDAO platform uses a hard-coded value of 10 gwei for the default gas price.

We would like to integrate Ethgasstation API to:

  1. Provide user-friendly clickable options for gas price
  2. Provide time estimate for the transaction to be mined

Details

  • Fetch gas price data from the Ethgasstation API
    • fill up the default options with gas price and estimated time
  • Transaction Fee
transaction fee = gas limit * gas price

Note: the gas limit can be found out from the txData object (refer)

gasLimit = txData.gas

API

Endpoint: https://ethgasstation.info/json/ethgasAPI.json

Note:

  • To convert the gas price values to gwei unit, divide them by 10
  • The wait times are in minutes. Please convert them to hours and minutes and seconds
    • 0.4 would be 24 seconds
    • 1.3 would be 1 minutes 18 seconds
    • 61.5 would be 1 hours 1 minutes 30 seconds

If sample response is:

{
	"fast": 40.0,
	"fastest": 60.0,
	"safeLow": 10.0,
	"average": 10.0,
	"block_time": 12.534883720930232,
	"blockNum": 8243182,
	"speed": 0.8315751882176169,
	"safeLowWait": 3.6,
	"avgWait": 3.6,
	"fastWait": 0.5,
	"fastestWait": 0.4
}

Then:

  • Gas price for fast transaction is 4 gwei
  • Gas price for fastest transaction is 6 gwei
  • Gas price for safeLow transaction is 1 gwei
  • Gas price for average transaction is 1 gwei
  • Estimated time for fast transaction is 30 seconds
  • Estimated time for fastest transaction is 24 seconds
  • Estimated time for safeLow transaction is 3 minutes 36 seconds
  • Estimated time for average transaction is 3 minutes 36 seconds

Design

SmartGasPrice01
SmartGasPrice02

Behaviour

If response is the json response from the API call

  • Default state
    • fast option is selected
    • Gas price is response.fast/10
    • Estimated wait time is format(response.fastWait)
    • The slider under advanced section is set to the gas price value
    • The Transaction Fee is set to txData.gas * gasPrice
  • Clicking on any option (safe low/average/fast/fastest) will
    • Deselect the previously selected option
    • Select the clicked option
    • Update the gas price as per response
    • Update the estimated wait time response
    • Update the slider under advanced section, set it to the gas price value
    • Update the Transaction Fee based on the newly selected gasPrice
  • Moving the slider under advanced section will
    • Deselect all the gas price options (safe low, average, fast, fastest)
    • Update the gas price as per slider value
    • Remove the estimated wait time for transaction (we show this only in the case of selected options from the API)
    • Update the Transaction Fee based on the newly selected gasPrice

Note: If the Ethgasstation API is down and returns null values:

  • Deselect all options
  • Set the slider and gas price to a default value of 10 gwei
@roynalnaruto roynalnaruto added the bounty This issue has a bounty associated with it label Jul 30, 2019
@gitcoinbot
Copy link

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


This issue now has a funding of 1.272 ETH (250.06 USD @ $196.59/ETH) attached to it.

@gitcoinbot
Copy link

gitcoinbot commented Aug 21, 2019

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


Work has been started.

These users each claimed they can complete the work by 267 years, 1 month from now.
Please review their action plans below:

1) eswarasai has been approved to start work.

Requirements are pretty straight forward and clear enough along with the UI/UX behaviour. If approved, I'd be able to wrap up this task in the next couple of days and provide a WIP PR for further feedback. Thanks!

Learn more on the Gitcoin Issue Details page.

@gitcoinbot
Copy link

@eswarasai Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!

  • reminder (3 days)
  • escalation to mods (6 days)

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

4 similar comments
@gitcoinbot
Copy link

@eswarasai Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!

  • reminder (3 days)
  • escalation to mods (6 days)

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

@gitcoinbot
Copy link

@eswarasai Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!

  • reminder (3 days)
  • escalation to mods (6 days)

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

@gitcoinbot
Copy link

@eswarasai Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!

  • reminder (3 days)
  • escalation to mods (6 days)

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

@gitcoinbot
Copy link

@eswarasai Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!

  • reminder (3 days)
  • escalation to mods (6 days)

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

@eswarasai
Copy link
Contributor

Will put up a WIP PR in the next couple of days. Sorry about the delay!

@gitcoinbot
Copy link

@eswarasai Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!

  • reminder (3 days)
  • escalation to mods (6 days)

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

@eswarasai
Copy link
Contributor

Sorry about not being able to update earlier. I'm halfway through the changes and there's a slight delay due to missing elements and matching their design to the above spec. Will put up a WIP PR in the next couple of days. Thanks!

@gitcoinbot
Copy link

@eswarasai Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!

  • reminder (3 days)
  • escalation to mods (6 days)

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

1 similar comment
@gitcoinbot
Copy link

@eswarasai Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!

  • reminder (3 days)
  • escalation to mods (6 days)

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

@gitcoinbot
Copy link

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


@eswarasai due to inactivity, we have escalated this issue to Gitcoin's moderation team. Let us know if you believe this has been done in error!

  • reminder (3 days)
  • escalation to mods (6 days)

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

@mandres-digix
Copy link
Contributor

I'll be describing here the general flow of gasPrice and how it moves from the governance-ui-components code to the governance-ui code to help devs understand the UI and data flow better, and how the two codebases communicate with each other.

In general, governance-ui handles the transactions and the UI for it (the transaction modal) while governance-ui-components handles the UI for the DAO website.

In the governance-ui-components, we have set the default gas price in src/constants.js at L28.

export const DEFAULT_GAS_PRICE = 10 * 1e9;

This is then passed to the <TransactionSigningOverlay/> component in the governance-ui code, which handles the rendering for the transaction modal. The file is found in src/libs/material-ui/components/transactions/transaction_signing_overlay.jsx.

The default gas price for this component is 20, as shown in L40:

const defaultState = {
  loading: false,
  autoBroadcast: true,
  signedTx: null,
  signingAction: undefined,
  openAdvanced: false,
  gasPrice: 20, // default value for state.gasPrice
  showAdvancedTab: true,
};

But we update this with the gasPrice we get from governance-ui-components:

componentWillReceiveProps = nextProps => {
  const { data } = nextProps;
  if (data) {
    const { txData } = data;
    const { gasPrice } = txData;  // txData comes from governance-ui-components
    this.setState({ gasPrice: gasPrice / 1e9 });
  }
}

We have a method for updating the gasPrice at L162:

setGasPrice = gasPrice => {
  this.setState({ gasPrice });
};

which is the callback that's called by the Slider component when the value is updated. See L299.

<Slider onUpdate={this.setGasPrice} range={range} start={[gasPrice]} step={1} />

For this task, you will probably want to update the UI for renderAdvancedTab.

@gitcoinbot
Copy link

gitcoinbot commented Sep 13, 2019

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


@eswarasai due to inactivity, we have escalated this issue to Gitcoin's moderation team. Let us know if you believe this has been done in error!

  • reminder (3 days)
  • escalation to mods (6 days)

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

@eswarasai
Copy link
Contributor

@mandres-digix - Thanks for the detailed explanation. I'll accommodate the above mentioned changes and update the PR accordingly 🙂

@eswarasai
Copy link
Contributor

@mandres-digix -- I'd be needing some help for testing in order to wrap up the feature on the UI. I'm not sure in which scenario I'd be able to trigger the screen of TransactionSigningOverlay component. Can you please help me out with the steps? Also I'm unable to create project locally because of the KYC error message. Not sure if I need to get that verified though.

@mandres-digix
Copy link
Contributor

@eswarasai okay sure. You don't need to KYC your user. You can just try to lock some DGDs first - that will make the transaction modal show up. @mikej-digix will message you on discord to help you with the process. 👍

@eswarasai
Copy link
Contributor

@mandres-digix - Thanks for the quick response. I'll get in touch with @mikej-digix on Discord regarding the same 🙂

@eswarasai
Copy link
Contributor

eswarasai commented Sep 17, 2019

@mandres-digix - Is it okay if I keep the component of GasPrice in the governance-ui-components and import it into the governance-ui's TransactionSigningOverlay? This would be a very minimal change on my end and the component is super easy to import across the packages if needed, which exposes a handler for setGasPrice whilst keeping all the UI and internal behaviour within the GasPrice component. Let me know if this sounds good, I'll go ahead and update the PRs with necessary changes. Thanks!

import GasPrice from '@digix/gov-ui/components/common/blocks/gas-price';

<GasPrice
  gas={gasLimitConfig.DEFAULT}
  onGasPriceChange={this.onGasPriceChange}
/>

@mandres-digix
Copy link
Contributor

@eswarasai sure, sounds good to me! At least that way we can keep styled components, right?

@eswarasai
Copy link
Contributor

@mandres-digix - Yep, we can keep the styled components. Will update the PR in a few. Thanks!

@gitcoinbot
Copy link

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


Work for 1.272 ETH (269.57 USD @ $211.93/ETH) has been submitted by:

  1. @eswarasai

@tymat please take a look at the submitted work:


mikej-digix pushed a commit that referenced this issue Sep 30, 2019
Ref: #44 DigixGlobal/governance-ui-components#381

Description
Added a Smart Gas Price component with Advanced options mode to be able to switch fast between the amount of gas price user would like to pay based on transaction times whose values are being fetched directly from ETHGasStation API.

Current behaviour just had a slider for gas price without any advanced options to quickly select it.

Test Plan
Before firing up the dev env, please make sure you also have the governance-ui-components PR is linked with this one during setup
Once you have dev setup up and running, open the app and login using Import JSON option
After logging in, click on Lock DGD button on the Header and enter the amount you'd like to lock
In the transaction details and signing screen, you should now see options to select the gas price similar to the design mentioned in the issue description
mikej-digix pushed a commit to DigixGlobal/governance-ui-components that referenced this issue Sep 30, 2019
Ref: DigixGlobal/governance-ui#44 DigixGlobal/governance-ui#46

Description
Added a Smart Gas Price component with Advanced options mode to be able to switch fast between the amount of gas price user would like to pay based on transaction times whose values are being fetched directly from ETHGasStation API.

Current behaviour just had a slider for gas price without any advanced options to quickly select it.

Test Plan
Once you have dev setup up and running, open the app and login using Import JSON option
After logging in, click on Lock DGD button on the Header and enter the amount you'd like to lock
In the transaction details and signing screen, you should now see options to select the gas price similar to the design mentioned in the issue description
mikej-digix pushed a commit that referenced this issue Sep 30, 2019
Ref: #44 DigixGlobal/governance-ui-components#381

Description
Added a Smart Gas Price component with Advanced options mode to be able to switch fast between the amount of gas price user would like to pay based on transaction times whose values are being fetched directly from ETHGasStation API.

Current behaviour just had a slider for gas price without any advanced options to quickly select it.

Test Plan
Before firing up the dev env, please make sure you also have the governance-ui-components PR is linked with this one during setup
Once you have dev setup up and running, open the app and login using Import JSON option
After logging in, click on Lock DGD button on the Header and enter the amount you'd like to lock
In the transaction details and signing screen, you should now see options to select the gas price similar to the design mentioned in the issue description
mikej-digix pushed a commit to DigixGlobal/governance-ui-components that referenced this issue Sep 30, 2019
    Ref: DigixGlobal/governance-ui#44 DigixGlobal/governance-ui#46

    Description
    Added a Smart Gas Price component with Advanced options mode to be able to switch fast between the amount of gas price user would like to pay based on transaction times whose values are being fetched directly from ETHGasStation API.

    Current behaviour just had a slider for gas price without any advanced options to quickly select it.

    Test Plan
    Once you have dev setup up and running, open the app and login using Import JSON option
    After logging in, click on Lock DGD button on the Header and enter the amount you'd like to lock
    In the transaction details and signing screen, you should now see options to select the gas price similar to the design mentioned in the issue description
mikej-digix pushed a commit to DigixGlobal/governance-ui-components that referenced this issue Sep 30, 2019
    Ref: DigixGlobal/governance-ui#44 DigixGlobal/governance-ui#46

    Description
    Added a Smart Gas Price component with Advanced options mode to be able to switch fast between the amount of gas price user would like to pay based on transaction times whose values are being fetched directly from ETHGasStation API.

    Current behaviour just had a slider for gas price without any advanced options to quickly select it.

    Test Plan
    Once you have dev setup up and running, open the app and login using Import JSON option
    After logging in, click on Lock DGD button on the Header and enter the amount you'd like to lock
    In the transaction details and signing screen, you should now see options to select the gas price similar to the design mentioned in the issue description
mikej-digix pushed a commit that referenced this issue Sep 30, 2019
Ref: #44 DigixGlobal/governance-ui-components#381

Description
Added a Smart Gas Price component with Advanced options mode to be able to switch fast between the amount of gas price user would like to pay based on transaction times whose values are being fetched directly from ETHGasStation API.

Current behaviour just had a slider for gas price without any advanced options to quickly select it.

Test Plan
Before firing up the dev env, please make sure you also have the governance-ui-components PR is linked with this one during setup
Once you have dev setup up and running, open the app and login using Import JSON option
After logging in, click on Lock DGD button on the Header and enter the amount you'd like to lock
In the transaction details and signing screen, you should now see options to select the gas price similar to the design mentioned in the issue description
@eswarasai
Copy link
Contributor

@tymat - Any update on the payment for this one? It's been a while since I've heard back from you.

mikej-digix pushed a commit to DigixGlobal/governance-ui-components that referenced this issue Oct 8, 2019
    Ref: DigixGlobal/governance-ui#44 DigixGlobal/governance-ui#46

    Description
    Added a Smart Gas Price component with Advanced options mode to be able to switch fast between the amount of gas price user would like to pay based on transaction times whose values are being fetched directly from ETHGasStation API.

    Current behaviour just had a slider for gas price without any advanced options to quickly select it.

    Test Plan
    Once you have dev setup up and running, open the app and login using Import JSON option
    After logging in, click on Lock DGD button on the Header and enter the amount you'd like to lock
    In the transaction details and signing screen, you should now see options to select the gas price similar to the design mentioned in the issue description
mikej-digix pushed a commit that referenced this issue Oct 8, 2019
Ref: #44 DigixGlobal/governance-ui-components#381

Description
Added a Smart Gas Price component with Advanced options mode to be able to switch fast between the amount of gas price user would like to pay based on transaction times whose values are being fetched directly from ETHGasStation API.

Current behaviour just had a slider for gas price without any advanced options to quickly select it.

Test Plan
Before firing up the dev env, please make sure you also have the governance-ui-components PR is linked with this one during setup
Once you have dev setup up and running, open the app and login using Import JSON option
After logging in, click on Lock DGD button on the Header and enter the amount you'd like to lock
In the transaction details and signing screen, you should now see options to select the gas price similar to the design mentioned in the issue description
mikej-digix pushed a commit to DigixGlobal/governance-ui-components that referenced this issue Oct 8, 2019
    Ref: DigixGlobal/governance-ui#44 DigixGlobal/governance-ui#46

    Description
    Added a Smart Gas Price component with Advanced options mode to be able to switch fast between the amount of gas price user would like to pay based on transaction times whose values are being fetched directly from ETHGasStation API.

    Current behaviour just had a slider for gas price without any advanced options to quickly select it.

    Test Plan
    Once you have dev setup up and running, open the app and login using Import JSON option
    After logging in, click on Lock DGD button on the Header and enter the amount you'd like to lock
    In the transaction details and signing screen, you should now see options to select the gas price similar to the design mentioned in the issue description
@gitcoinbot
Copy link

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


The funding of 1.272 ETH (229.03 USD @ $180.05/ETH) attached to this issue has been approved & issued to @eswarasai.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bounty This issue has a bounty associated with it
Projects
None yet
Development

No branches or pull requests

4 participants