Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
My diagnosis of this bug was two fold.
The first is that the code for calculating the veOgv in the smart contract is quite different from the one used in the dApp.
OgvStaking.sol
LockupForm.tsx
The typescript version yields quite a similar output but it has a lot of rounding errors that often would go unnoticed because it's not huge; but often wouldn't. So changed that to follow the smart contract's calculation method.
The second and bigger issue (and the one that was the crux of the bug @micahalcorn found) came from a use of a static
block.timestamp
. TheblockTimestamp
used in the dApp is one that is fetched in the initial page load and then never updated. This is a problem because theblock.timestamp
is part of the calculation for the output veOgv quantity.If a user were to go on the page, leave for an hour and come back to confirm their transaction... they would find a very different veOgv output quantity.
The change made here is to wrap an already existing block timestamp fetching hook in a
useInterval()
delimited at 4s. At an average 15s block production time, this is more than enough to ensure a non-stale timestamp.One thing to note is the formula in dApp will use the current block timestamp as opposed to the next (the one in which the user's transaction will be confirmed). However, the difference in output is negligible.
Closes #342