This repository has been archived by the owner on Jul 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 465
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dekz
force-pushed
the
feature/gas-token-bridge
branch
4 times, most recently
from
March 13, 2020 06:04
cc10454
to
3c0e590
Compare
abandeali1
approved these changes
Mar 13, 2020
hysz
reviewed
Mar 13, 2020
hysz
approved these changes
Mar 13, 2020
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! (~‾▿‾)~
To handle the case where GST2 is being traded and the balanceOf checks become confusing
dekz
force-pushed
the
feature/gas-token-bridge
branch
from
March 25, 2020 05:24
3c0e590
to
1e17841
Compare
if (address(gst) != address(0)) { | ||
// (gasUsed + FREE_BASE) / (2 * REIMBURSE - FREE_TOKEN) | ||
// 14154 24000 6870 | ||
uint256 value = (gasBefore - gasleft() + 14154) / 41130; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tries to refund the entire amount of gas consumed, right? Maybe we should just try to refund half. I believe a quirk of the EVM is that refunds are capped at half the gas consumed, so any excess might be wasted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes this calculation gets us to maximum efficiency. You can also play with the calculator (https://gastoken.io/) to confirm.
gasUsed = 2,000,000
value = 48 = (gasUsed + 14154) / 41130
SELFDESTRUCT = -24000 (refund)
SELFDESTRUCT_COST = 700 (CALL) + 5000 (SUICIDE)
refund = -878,400 = SELFDESTRUCT * 48 + SELFDESTRUCT_COST * 48
newGasUsed = 1,121,600 > gasUsed * 0.5
note: also a bit of book keeping w.r.t balance updates is excluded
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Description
When a user makes a trade against a Bridge like Curve (10e5 gas). They spend approximately
(10e5 * 8e9) * 1e-18 * $150
$1.20 in gas. We can reduce this by approximately 40% by freeing gas tokens if we have an available balance. So the user only pays $0.72 to fill on Curve.Calculations are from gastoken.io
freeFrom
Rather than have each bridge use its own balance, we chose to use
freeFromUpTo
to allow a EOA (GST Collector) to hold the GST balance, preventing a drain if GST2 was traded via a Bridge. This keeps the balances of tokens traded distinct from the gst balance. The collector can whitelist certain contracts, and remove contracts if required. If there is no allowance set it does not revert.We also don't loose any unspent (and sent) tokens when we re-deploy bridges.
Process
Notes