Mangrove
Developper
Developper
  • Welcome
  • Protocol
    • Introduction
    • Technical References
      • Overview
      • Ticks, ratios, and prices
      • Offer-list
        • Views on offers
      • Market-order
        • Delegation
      • Creating & Updating offers
        • Maker contract
        • Offer provisions
        • Gas requirement
        • Public data structures
        • Executing offers
      • Cleaning offers
      • Governance-parameters
        • Global variables
        • Local variables
        • Data structures and views
      • Periphery Contracts
        • MgvReader
        • MgvOracle
      • Literate Source Code
    • Background
      • Taking available liquidity
      • Making liquidity available
      • Reneging on offers
  • Strat Lib
    • What is the Strat Library?
    • Getting-started
      • Set Up Your Local Environment
      • Post a Smart Offer
    • Guides
      • Unlocking liquidity
      • Reposting an offer in the posthook
      • Using last look to renege trades
      • Determining gas requirements
      • Creating a Direct contract
      • Deploying your contract
      • Testing a maker contract
      • Safe offer logic guidelines
      • Approvals
    • Technical references
      • Principal hooks
      • Liquidity routing
      • API preferences
        • Core
          • SRC
            • IMangrove
        • Strats
          • SRC
            • Strategies
              • MangroveOffer
              • MangroveOrder
              • Integrations
                • AaveV3Borrower
                • AaveV3BorrowerImplementation
                • AaveV3BorrowerStorage
                • AaveV3Lender
                • CompoundModule
              • Interfaces
                • IForwarder
                • ILiquidityProvider
                • IOfferLogic
                • IOrderLogic
              • Offer_forwarder
                • Abstract
                  • Forwarder
              • Offer_maker
                • Abstract
                  • Direct
                • Market_making
                  • Kandel
                    • AaveKandel
                    • AaveKandelSeeder
                    • KandelSeeder
                    • Abstract
                      • AbstractKandelSeeder
                      • CoreKandel
                      • DirectWithBidsAndAsksDistribution
                      • GeometricKandel
                      • HasIndexedBidsAndAsks
                      • KandelLib
                      • TradesBaseQuotePair
              • Routeurs
                • SimpleRouter
                • Abstract
                  • AbstractRouter
                • Integrations
                  • AavePooledRouter
                  • HasAaveBalanceMemoizer
              • Utils
                • AccessControlled
              • Vendor
                • AAVE
                  • V3
                    • Contracts
                      • Dependencies
                        • Oppenzeppelin
                          • Contracts
                            • IERC20
                      • Interfaces
                        • IAToken
                        • IAaveIncentivesController
                        • IAaveOracle
                        • ICreditDelegationToken
                        • IInitializableAToken
                        • IPool
                        • IPoolAddressesProvider
                        • IPriceOracleGetter
                        • IScaledBalanceToken
                      • Protocol
                        • Libraries
                          • Configurations
                            • ReserveConfiguration
                          • Helpers
                            • Errors
                          • Types
                            • DataTypes
                    • Periphery
                      • Contracts
                        • MISC
                          • Interfaces
                            • IEACAggregatorProxy
                        • Rewards
                          • Interfaces
                            • IRewardsController
                            • IRewardsDistributor
                            • ITransferStrategyBase
                          • Libraries
                            • RewardsDataTypes
                • Compound
                  • CarefulMath
                  • Exponential
                  • ExponentialNoError
                  • ICompound
    • Background
      • Building Blocks
        • MangroveOffer
        • Direct
        • Forwarder
  • Vaults
    • Understanding vaults
      • Oracles
    • Managing a vault (CLI)
      • Deploying an oracle
      • Creating a vault
      • Monitoring the vault
      • Setting the vault position
      • Setting the fee data
      • Rebalancing
      • Adding or removing liquidity
    • Custom interactions
      • Oracles
      • Vault Factory
      • Managing a vault
        • Setting the position
        • Rebalancing
        • Setting a manager
        • Setting fee
  • Keeper Bots
    • Keeper Bots
    • Guides
      • Using borrowed funds for cleaning
    • Backgroud
      • The role of cleaning bots in Mangrove
      • The role of gas price updater bots in Mangrove
  • Adresses
    • Deployment Addresses
  • Quick Links
    • Glossary
    • Website
    • Whitepaper
Powered by GitBook
On this page
  1. Strat Lib
  2. Guides

Reposting an offer in the posthook

PreviousUnlocking liquidityNextUsing last look to renege trades

Last updated 28 days ago

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.

Repost in posthook

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

  function __posthookSuccess__(MgvLib.SingleOrder calldata order, bytes32 makerData)
    internal
    virtual
    override
    returns (bytes32)
  {
    emit OfferTakenSuccessfully(42);
    // repost offer residual if any
    return super.__posthookSuccess__(order, makerData);
  }
}

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

function __posthookSuccess__(MgvLib.SingleOrder calldata order, bytes32 makerData)
  internal
  virtual
  returns (bytes32 data)
{
  // now trying to repost residual
  (uint newGives, Tick newTick) = __residualValues__(order);
  // Density check at each repost would be too gas costly.
  // We only treat the special case of `gives==0` or `wants==0` (total fill).
  // Note: wants (given by `inboundFromOutbound`) can be 0 due to rounding given the price. We could repost to get rid of the last gives at 0 wants,
  // but the maker does not need to give away these tokens for free, so we skip it.
  // Offer below the density will cause Mangrove to throw so we encapsulate the call to `updateOffer` in order not to revert posthook for posting at dust level.
  if (newGives == 0 || newTick.inboundFromOutbound(newGives) == 0) {
    return COMPLETE_FILL;
  }
  data = _updateOffer(
    OfferArgs({
      olKey: order.olKey,
      tick: newTick,
      gives: newGives,
      gasreq: order.offerDetail.gasreq(),
      gasprice: order.offerDetail.gasprice(),
      noRevert: true,
      fund: 0
    }),
    order.offerId
  );
  // logs if anything went wrong
  logRepostStatus(order, makerData, data);
}

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.

smart offer tutorial
partially taken
​
posthook
__posthookSuccess__
See entire file on GitHub
_updateOffer
cheaper
_newOffer
__residualvalues__
Safe offer logic guidelines
IDs
gas requirements
density
See entire file on GitHub