function purchaseBond(uint256 id_, uint256 amount_, uint256 minAmountOut_ ) external
Intended behavior.
Exchange quote tokens for a bond in a specified market
Negative behavior.
Should only be callable by the
BondBaseTeller
inheriting contract, revert otherwise (this check is put in place)Shouldn’t allow the purchase of bonds from
id
s that have no registered marketShould disallow the purchase if the amount of bonds is less than the
minAmountOut
(this check is put in place) #slippagecheck
Preconditions.
Assumes that a teller is working properly and that the
msg.sender
is the teller in the cause.Assumes that the market exists (through its
id
) and that it’s not closedAlso, the check on
currentTime
should be > thanterm.conclusion
since it may close within same block.
Postconditions..
If
maxDebt
was reached, the market has to be closed, otherwise,tuned
accordingly.market.capacity
will decrease based on theamount
orpayout
values.market.purchase += amount_
market.sold += payout
Inputs.
uint256 id_: full control, check that the market[id] has not concluded.
uint256 amount_: full control.
uint256 minAmountOut_: slippage check, is checked properly.
Examine all function calls the function makes.
a.
(price, payout) = decayAndGetPrice(id, amount_, uint48(block.timestamp))
What is controllable? (callee, params, return value): id - controllable; amount - controllable - affects the number of
payout
tokens;block.timestamp
- partially controlledIf return value is controllable, how is it used and how can it go wrong: price - even if something goes wrong, the
price
cannot be less than themarket.minPrice
; payout - if it is calculated incorrectly and the capacity value wasn't set (in a case when it was set for quoteToken) andmarket.minPrice
value wasn’t set properly by the market owner, then it can be possible to steal the owner's funds.What happens if it reverts or tries to reenter: not a problem.