Function create(ERC20 underlying_, uint48 expiry_, uint256 amount_)
NO UNIT-TEST or at least not direct test
Intended behavior.
This function allows any user to get the
amount
value of theBond
tokens in exchange forunderlying_
ERC1155 tokens.
Negative behavior.
Shouldn’t
mint
amount
of tokens if a smaller quantity ofunderlying_
tokens was deposited.Shouldn’t
mint
thetokenId
tokens iftokenMetadata[tokenId]
doesn't exist because otherwise, it would be possible to deposit dummy tokens and then create metadata with a real token and withdraw it. Also, it means that no one should be able to edit already created items oftokenMetadata[tokenId].
Should be rejected if the caller doesn't have enough
underlying_
tokens.Should be rejected if the caller doesn't get the expected value of
Bond
tokens. there is no such check here, but since the fee percentage is unlimited and can be changed at any time, the caller may not agree with the withdrawn fee value. we could add a slippage check here, just as in the other BondFixedExpiryTeller.Shouldn’t emit expired
bondTokens
since that means that they’ve vested already.
Preconditions.
tokenMetadata[tokenId]
should be already created for currentunderlying_
andexpiry_
values.the caller should have enough
underlying_
tokens to pay for a deposit.the correct
tokenId
should be minted (calculated based on the pair between thepayoutToken, expiry
.should make sure that
expiry
is not in the past? as in, the bondToken pair had already vested?
Postconditions.
underlying_.balanceOf(BondFixedTermTeller) >=
oldBalance+amountBondFixedTermTeller.balanceOf(msg.sender) ≤ balanceBefore+payout
Inputs.
ERC20 underlying_ : controlled (!), it can be any address of ERC20 token, there is should exist
tokenMetadata
for this token address andexpiry
value, but it is possible to do overdeploy
function.uint48 expiry : controlled (!)
uint256 amount_ : controlled (!)
Examine all function calls the function makes.
a. Call to
uint256 tokenId = getTokenId(underlying_, expiry_);
What is controllable? (callee, params, return value):
underlying_, expiry_
are controllableIf return value controllable, how is it used and how can it go wrong?
tokenId
should be unique for correspondingunderlying_, expiry_
valuesWhat happens if it reverts or tries to reenter? No problem
b. Call to
_mintToken(msg.sender, tokenId, amount_)
see_handlePayout._mintToken
description