Skip to main content

Using last look to renege trades

Example​

A maker can renege on a trade if the market conditions are no longer favorable. This can be done in multiple ways, but the strat lib has made it easy by adding a __lastLook__ function which can be overridden.

You can follow the smart offer tutorial, and extend it with the following function:

OfferMakerTutorialResidual.sol
loading...

This override of the __lastLook__ will renege if the offer is not fully taken. Note that since the provision is lost as a bounty to the taker, care must be taken to select the right circumstances to renege. This uses the mechanisms for compensating the taker on failure, and therefore the maker should renege early.

Exercises​

  1. Try posting an offer with a maker contract with the above implementation of __lastlook__ above.

  2. Then, try out targeting this offer with a market order that takes only part of the tokens that the offer gives. The result should be a makerExecute fail with the reason that the offer must be fully taken.

Note

For your offer to be targeted by a market order, it needs to sit at the top of the order book. Make sure to choose a very favorable price (i.e. tick) when posting your offer. For an example of how to calculate a tick from a ratio, check the Solidity snippets of Posting a new offer.

In a Foundry trace, it would look like this:

    β”‚   β”‚   └─ ← 0x0000000000000000000000000000000000000000000000000000000000000001
β”‚ β”œβ”€ [623] OfferMakerTutorial::makerExecute((0x63E537A69b3f5B03F4f46c5765c82861BD874b6e, 0xC87385b5E62099f92d490750Fcd6C901a524BBcA, 565, 13965252376515437924197781608061731723491045742767017537776374226616320, 100000000000000000, 170000000000000000000, 114972889140951241694864433974031885472888135242322246917362470694355803832320, 95685385232850624329487581946028423310341827134083876137913628388789126692864, 452312848583266388373324160192082719549164520795168960635552751154278432768))
β”‚ β”‚ └─ ← "tutorial/mustBeFullyTaken"
β”‚ └─ ← "Custom Error 6d67762f:(0x0000000000000000000000000000000000000000, 15120238736495)"