Reposting an offer in the posthook
Last updated
Last updated
In the the offer was fully taken by the taker at the end.
In case an offer is , the maker may want to repost a new offer for the residual.
In the tutorial, the 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 will repost the residual.
OfferMakerTutorial.sol
When writing posthooks to repost residuals there are both caveats and points to be aware:
Beware that updates can fail, e.g., due to too low density.
MangroveOffer.sol
Use 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 than using .
Use the helper method supplied to calculate the residual (see example below).
Make sure to refer to the guidelines on .
Note that the parameters to __posthookSuccess__
already point out the old offer. This can save storage since we do not have to store of posted offers.
Beware of gas usage changes on different code paths. As an example, the 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 ) scenarios.