Reposting an offer in the posthook
In the smart offer tutorial the offer was fully taken by the taker at the end.
In case an offer is partially taken, the maker may want to repost a new offer for the residual.
Repost in posthookβ
In the tutorial, the posthook emitted an event. However, since reposting is such a common action, it is already implemented for the simple cases - if you invoke super
like below, then the base implementation of __posthookSuccess__
will repost the residual.
loading...
When writing posthooks to repost residuals there are both caveats and points to be aware:
- Use
_updateOffer
instead of posting a new offer. The old offer is not alive and can be reused (and the storage is possibly hot during the execution of the offer logic), this is cheaper than using_newOffer
. - Use the helper method
__residualvalues__
supplied to calculate the residual (see example below). - Beware that updates can fail, e.g., due to too low density.
- Make sure to refer to the guidelines on Safe offer logic guidelines.
- Note that the parameters to
__posthookSuccess__
already point out the old offer. This can save storage since we do not have to store IDs of posted offers. - Beware of gas usage changes on different code paths. As an example, the gas requirements for the tutorial increases to 80,000 to be able to repost.
If you need to write a custom hook, for instance, for reposting multiple offers, then it can be a good idea to look at the base implementation of __posthookSuccess__
(from MangroveOffer
) below. A good exercise is to change the code above to emit the value returned from super
and trigger the reposted
and dust
(see density) scenarios.
loading...