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 │
├─────────┼──────┼──────────────────────────────────────────────┼────────────────────┼────────────────────────┤
05572'0xA4C7c59EB3D4Ab5CA4E6fB012CeD9c8F9A5Ecdd8'100.51.00099502487562189055
13137'0x2CB51201CD176CcEa67a9c0B64391aE34e50C058'1883.818944601731.00346413248309787013
21384'0x4326Ab97823d7509C1f0CB3bF68151081B26c970'1143.17145061627931.00346467660785745789
31669'0x4326Ab97823d7509C1f0CB3bF68151081B26c970'1376.62734385504151.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.00345100.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.

packages/mangrove.js/examples/how-tos/update-offer.js
loading...
┌─────────┬──────┬──────────────────────────────────────────────┬────────────────────┬────────────────────────┐
(index)id │ maker │ volume │ price │
├─────────┼──────┼──────────────────────────────────────────────┼────────────────────┼────────────────────────┤
05572'0xA4C7c59EB3D4Ab5CA4E6fB012CeD9c8F9A5Ecdd8'100.51.00345
13137'0x2CB51201CD176CcEa67a9c0B64391aE34e50C058'1883.818944601731.00346413248309787013
21384'0x4326Ab97823d7509C1f0CB3bF68151081B26c970'1143.17145061627931.00346467660785745789
31669'0x4326Ab97823d7509C1f0CB3bF68151081B26c970'1376.62734385504151.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, your contracts address and if your contract is a forwarder (remember to import the type first, e.g., using const { OfferLogic } = require("@mangrovedao/mangrove.js");).

packages/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.

packages/mangrove.js/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.

packages/mangrove.js/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.