Skip to main content

Update Your Offer

Intro​

This will explain how you update an offer using mangrove.js.

Since you need to have an offer on the book in order to update it, this will assume that you already have an offer on the book. In this case we will use the offer id 5572. But make sure you use your own offer id. See for instance Post a simple offer.

Update offer​

We start by logging all the asks on the DAI-USDC market. For this guide we will assume that the offer is an ask on the DAI-USDC market. If your offer is on another market, make sure to connect to the market where your offer is posted.

Here we can see that my offer has a volume of 100.5 and a price of 1.00099. Lets say we want to update the offer to match the price of the next best offer.

market.consoleAsks();
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ (index) β”‚ id β”‚ maker β”‚ volume β”‚ price β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 0 β”‚ 5572 β”‚ '0xA4C7c59EB3D4Ab5CA4E6fB012CeD9c8F9A5Ecdd8' β”‚ 100.5 β”‚ 1.00099502487562189055 β”‚
β”‚ 1 β”‚ 3137 β”‚ '0x2CB51201CD176CcEa67a9c0B64391aE34e50C058' β”‚ 1883.81894460173 β”‚ 1.00346413248309787013 β”‚
β”‚ 2 β”‚ 1384 β”‚ '0x4326Ab97823d7509C1f0CB3bF68151081B26c970' β”‚ 1143.1714506162793 β”‚ 1.00346467660785745789 β”‚
β”‚ 3 β”‚ 1669 β”‚ '0x4326Ab97823d7509C1f0CB3bF68151081B26c970' β”‚ 1376.6273438550415 β”‚ 1.00346478817687987934 β”‚

To update the offer we use the updateAsk function on our liquidityProvider. This has two options available in the OfferParams. First, you can provide wants and gives. If we chose to use this, we would have to calculate what gives should be, given that wants stays a 100.5 and we want the price to be slightly better than the next best offer, e.g. 1.00345. wantsprice=gives\frac{wants}{price}=gives -> 100.51.00345β‰ˆ100.1494\frac{100.5}{1.00345}\approx 100.1494.

Second, you can provide volume and price, since this is exactly what we want to use, we don't have to calculate gives. We then just update the offer using volume: 100.5 and price: 1.00345.

examples/how-tos/update-offer.js
loading...
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ (index) β”‚ id β”‚ maker β”‚ volume β”‚ price β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 0 β”‚ 5572 β”‚ '0xA4C7c59EB3D4Ab5CA4E6fB012CeD9c8F9A5Ecdd8' β”‚ 100.5 β”‚ 1.00345 β”‚
β”‚ 1 β”‚ 3137 β”‚ '0x2CB51201CD176CcEa67a9c0B64391aE34e50C058' β”‚ 1883.81894460173 β”‚ 1.00346413248309787013 β”‚
β”‚ 2 β”‚ 1384 β”‚ '0x4326Ab97823d7509C1f0CB3bF68151081B26c970' β”‚ 1143.1714506162793 β”‚ 1.00346467660785745789 β”‚
β”‚ 3 β”‚ 1669 β”‚ '0x4326Ab97823d7509C1f0CB3bF68151081B26c970' β”‚ 1376.6273438550415 β”‚ 1.00346478817687987934 β”‚

Changing the price of an offer can change its rank in the offer book.

Update offer using OfferLogic​

When we updated our offer before, we used a liquidityProvider and we created this using Mangrove. This means that when we updated our offer, we did using Mangrove directly. But if you have your own contract with your own update offer logic, you can use that by creating an OfferLogic. This is simply done by calling the constructor with Mangrove (remember to import the type first, e.g., using const { OfferLogic } = require("@mangrovedao/mangrove.js");).

examples/how-tos/update-offer.js
loading...

When you have a OfferLogic you can the call update offer directly on the underlying contract (which is assumed to implement the ILiquidityProvider interface, but this requires a lot more info and unit conversions.

examples/how-tos/update-offer.js
loading...

To keep things more simple you can create a liquidityProvider with your offerLogic and a market. This way the LiquidityProvider will make sure to update your offer using your offerLogic. This saves you for taking any other decisions than wants and gives or volume and price.

examples/how-tos/update-offer.js
loading...

You can only update offers you own as a maker. And from the consoleAsks() above you can see the maker of each offer. So for instance, you cannot update an offer posted directly in Post a simple offer using your offerLogic's liquitidyProvider - it has to be an offer posted by the offerLogic.