DXgovernance / davi-monorepo

https://davi-monorepo-davi.vercel.app
8 stars 12 forks source link

Feat/holographic consensus #339

Open dcrescimbeni opened 1 year ago

dcrescimbeni commented 1 year ago

Description

image

image

image

https://www.loom.com/share/e8ca35fc435e4dea87cbd3ca8a67f9ea

Holographic consensus

Added a sidebar component, modal, and logic to stake tokens, that will be shown on an active proposal on Gov 1.5 DAOs. The option to stake tokens will only show if the user has a balance on the staking token.

The component shows a speedometer to reflect the token amount staked on either option.

Clicking on the stake amounts or the expand button on the card header will toggle the stake details. Each new stake is shown in a new line, so if a user stakes multiple times, it will show multiple stakes (not just one staked with the total stakes of the user).

If the user hasn't already staked on the proposal, it must choose an option and an amount. The amount varies between 0 and the user token balance. To set the amount, either use the slider, or click on the "Max" button to set it to all the available balance.

If the user already staked in the proposal, it won't be able to change its option, just increasing the stakes.

While staking, it will calculate the potential reward, assuming that the user-selected option will win (if it loses, it will lose all the staked tokens).

The "Lock" button will show an "Approve" text if the selected staking amount exceeds the current token allowance. If the user needs to approve, an approve transaction will be created with the required amount by default.

Notes

Pending things:

Subgraph

Hooks

Types

General stuff

Closes #16 (issue)

Type of change

How Has This Been Tested?

I extracted functions that deal with numbers into utils, and added unit tests.

Setup to test the staking functionality:

  1. Go to packages/dxdao-contracts/deploy/avatarScheme.js and set this default parameters (they increase the time to interact with the proposal):
    const defaultParameters = {
    queuedVoteRequiredPercentage: 5000,
    queuedVotePeriodLimit: 60000000,
    boostedVotePeriodLimit: 60000000,
    preBoostedVotePeriodLimit: 10000000,
    thresholdConst: 2000,
    quietEndingPeriod: 10000000,
    daoBounty: web3.utils.toWei("0.1"),
    boostedVoteRequiredPercentage: 100,
    };
  2. Run the whole app (hardhat, subgraph and front end)
  3. Go to the DAO URL: http://localhost:3000/#/localhost/0x77f7df7de7ab705eb54982a12d8e1ac65bfa05d3
  4. Click on the proposal
  5. You will see the "Predictions" sidebar card
  6. Switch to either Address #1, #2 or #3 (check hardhat.config.js) since those are the ones with DXD token balance and thus can stake
  7. Click on the thumbs-up or thumbs-down buttons to open the staking modal
  8. Select the staking option (if you haven't already staked), move the slider to increase the staking amount, and then lock/approve tokens
  9. After confirming the stake, reload the page (this is only needed in localhost)

Currently, there's no way to redeem or finish the proposal.

Checklist:

vercel[bot] commented 1 year ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
davi ❌ Failed (Inspect) Mar 30, 2023 at 0:38AM (UTC)
AugustoL commented 1 year ago

IMO using "predictions" as a name for the action is wrong, it is a stake or a bet where you PAY for a specific outcome. There is no money in predictions, I can predict that tomorrow will rain for free, but on stakes and bets there is money involved, like here.

rossneilson commented 1 year ago

Seeing this in vercel build Screenshot 2023-03-28 at 11 43 03

dcrescimbeni commented 1 year ago

Seeing this in vercel build Screenshot 2023-03-28 at 11 43 03

Does the repo redeploy a subgraph? Because stakingTokenAddress is a new parameter, and if it tries to get it from an old subgraph deploy, it won't find it.

dcrescimbeni commented 1 year ago

Looks good to me, great job!!

Some comments regarding my UX impression:

  • When i'm approving amount to stake i receive this alert from metamask:
image

here i can put a different amount from the one i put before on the slider. Afterwards the app uses the one from metamask which sounds fair, but i don't know if maybe we can send the amount to the approval transaction so that the user doesn't have to insert it twice.

  • On my first impression it was weird to have to click twice the thumbs up (or thumbs down). Once on the proposal page and another on the modal. Maybe the first time could be just a stake button and afterwards which staking option you want...
  • Once i already staked that the previous staked selection is 'clicked' maybe we can disable the other option?

Anyway, just opinions here, you can try them and see how they look or maybe a designer can have a better opinion

About the approval window MetaMask shows, you need to click "use default" to auto-populate the amount we send (in this case, the amount needed approval), it won't fill it automatically. That's a choice on their end.

Yes... about the staking button, that makes sense. I don't have a strong opinion on either of the options.