Skip to main content

Reuse Offer

Intro

In this section we will go through how to reuse an offer, that has been taken or has failed. When an offer is taken, the offer still exists in Mangrove. This means that a previous offer made, can be reused again by the same maker. The same applies for an offer that failed when it was taken. The reason for keeping the offers around, is that cleaning up old/dead offers costs gas and by reusing a existing offer we save gas vs posting a completely new offer. This means that when we post an offer, we should save the Offer ID for that offer, in case we ever want to reuse it.

Update existing offer

In order to update an offer that is no longer live, we need the ID of an offer that has been taken or failed. In this example we are going to use ID 5573. If you do not have an offer that has been taken you can simply post a completely new offer and then snipe it. The script has some commented out sections that helps with creating a dead offer.

When we have a dead offer, then we can figure out how much provision is needed when reposting it. This is done by using the computeAskProvision given the offer id. The last thing we need is to give a wants and a gives for the offer. In this case we are going to use wants: 1000.5 and gives: 1000.4.

If we look at the asks before and after we have updated the offer, we now see that our offer has been updated and is at the top of the order book.

packages/mangrove.js/examples/how-tos/reuse-offer.js
loading...
Asks before update
> market.consoleAsks();
┌─────────┬──────┬──────────────────────────────────────────────┬────────────────────┬────────────────────────┐
(index) │ id │ maker │ volume │ price │
├─────────┼──────┼──────────────────────────────────────────────┼────────────────────┼────────────────────────┤
01173'0x4326Ab97823d7509C1f0CB3bF68151081B26c970'844.05364730373031.00354291069746851135
13003'0x2CB51201CD176CcEa67a9c0B64391aE34e50C058'280.695893683274561.00354551434175376498
2967'0x4326Ab97823d7509C1f0CB3bF68151081B26c970'578.30962718675981.00355019649807276339
Asks after update
> market.consoleAsks();
┌─────────┬──────┬──────────────────────────────────────────────┬────────────────────┬────────────────────────┐
(index) │ id │ maker │ volume │ price │
├─────────┼──────┼──────────────────────────────────────────────┼────────────────────┼────────────────────────┤
05573'0xA4C7c59EB3D4Ab5CA4E6fB012CeD9c8F9A5Ecdd8'1000.41.00009996001599360256
11173'0x4326Ab97823d7509C1f0CB3bF68151081B26c970'844.05364730373031.00354291069746851135
23003'0x2CB51201CD176CcEa67a9c0B64391aE34e50C058'280.695893683274561.00354551434175376498