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
BondBaseTellerinheriting contract, revert otherwise (this check is put in place)Shouldn’t allow the purchase of bonds from
ids 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.senderis the teller in the cause.Assumes that the market exists (through its
id) and that it’s not closedAlso, the check on
currentTimeshould be > thanterm.conclusionsince it may close within same block.
Postconditions..
If
maxDebtwas reached, the market has to be closed, otherwise,tunedaccordingly.market.capacitywill decrease based on theamountorpayoutvalues.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
payouttokens;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
pricecannot 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.minPricevalue 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.