-
Notifications
You must be signed in to change notification settings - Fork 18
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
KEEP/NU <> T Vending Machine #3
Conversation
The Vending Machine allows to wrap KEEP/NU into T and unwrap it back with the provided wrap ratio. This is just an initial flow and it will be extended with a mapping of token holders who wrapped/unwrapped so that T earned as a stakerd reward or bough on the exchange can not be unwrapped back to KEEP/NU.
It is not possible to unwrap T into KEEP/NU if the given account has not previously wrapped KEEP/NU to T. Also, the given account can not unwrap more than it previously wrapped.
In practice, both tToken and wrappedToken are trusted contracts so there is no risk of reentrancy. In theory, there could be a risk of reentrancy if tToken or wrappedToken are evil or could be exploited and Slither is complaining about it. Let's make Slither happy and change the order of calls!
Updated version to point to commit hash from main branch after PRs with token and clone factory have been merged.
This is the version referenced in contract Solidity files. The goal is not to use the most recent version per auditor's recommendation.
#2 got merged so I could update the code here and undraft the PR. This is ready! |
Generalizing test amounts and minor refinements
Renamed `_amount` to `amount`. The convention we used so far was to use underscore only when we had conflicts with other names, for example in constructor where parameter names are conflicting with contract field names.
We are always going to let to convert the entire wrapped token supply, so renaming _maxWrappedToken constructor parameter to _wrappedTokenSupply should hopefully explain its meaning better.
contracts/vending/VendingMachine.sol
Outdated
tToken = _tToken; | ||
ratio = | ||
(FLOATING_POINT_DIVISOR * _tTokenAllocation) / | ||
_wrappedTokenSupply; |
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.
What do you think about adding a few required
for the input values? I know we control these parameters, but it costs nothing in terms of gas / code size.
address indexed recipient, | ||
uint256 tTokenAmount, | ||
uint256 wrappedTokenAmount | ||
); |
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.
To make it perfect we can add docstrings for events too (and generate docs from contracts in some moment in a future)
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.
Opened #11
…verted. Previous behavior produced unintended results when the amount converted wasn't exact wrt to the conversion ratio. E.g, for a 10:3 ratio, the vending machine had different balances if the token holder converts 10 (resulting in 3), than converting 5 twice (resulting in 1+1 due to rounding). New behavior converts from the approved amount the max amount that can be converted exactly
We already need to restrict T token supply to uint96 anyway for GovernorBravo
Allow only exact conversions when wrapping/unwrapping
Refs #1
Depends on #2 (keeping it as a draft until the dependency is merged)This Pull Request addresses the first two points of the Plan of the game described in #1.
VendingMachine
contract implements a special lending protocol to enable KEEP/NUtoken holders to wrap their tokens as collateral and borrow T tokens against that collateral
based on the wrap ratio. This will go on indefinitely and enable NU and KEEP token holders
to join T network without needing to buy or sell any assets. Logistically, anyone holding NU
or KEEP can wrap those assets in order to receive T. They can also unwrap T in order to go
back to the underlying asset. There will be a separate instance of this contract deployed for
KEEP holders and a separate instance of this contract deployed for NU holders.