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
  • SetGasprice
  • Parameters
  • SetGasreq
  • Parameters
  • SetStepSize
  • Parameters
  • Credit
  • Parameters
  • Debit
  • Parameters
  • Params
  • Parameters
  • params
  • setStepSize
  • Parameters
  • setGasprice
  • Parameters
  • setGasreq
  • Parameters
  • setParams
  • Parameters
  • constructor
  • Parameters
  • populate
  • Parameters
  • populateChunk
  • Parameters
  • reserveBalance
  • Parameters
  • Return Values
  • logUpdateOfferStatus
  • Parameters
  • transportSuccessfulOrder
  • Parameters
  • transportLogic
  • Parameters
  • Return Values
  • pending
  • Parameters
  • Return Values
  • depositFunds
  • Parameters
  • withdrawFunds
  • Parameters
  • withdrawFundsForToken
  • Parameters
  • retractAndWithdraw
  • Parameters
  1. Strat Lib
  2. Technical references
  3. API preferences
  4. Strats
  5. SRC
  6. Strategies
  7. Offer_maker
  8. Market_making
  9. Kandel
  10. Abstract

CoreKandel

CoreKandel is agnostic to the chosen price distribution.

SetGasprice

event SetGasprice(uint256 value)

the gasprice has been set. By emitting this data, an indexer will be able to keep track of what gasprice is used.

Parameters

Name
Type
Description

value

uint256

the gasprice for offers.

SetGasreq

event SetGasreq(uint256 value)

the gasreq has been set. By emitting this data, an indexer will be able to keep track of what gasreq is used.

Parameters

Name
Type
Description

value

uint256

the gasreq (including router's gasreq) for offers

SetStepSize

event SetStepSize(uint256 value)

the step size has been set.

Parameters

Name
Type
Description

value

uint256

the step size in amount of price points to jump for posting dual offer

Credit

event Credit(contract IERC20 token, uint256 amount)

the Kandel instance is credited of amount by its owner. By emitting this data, an indexer will be able to keep track of what credits are made.

Parameters

Name
Type
Description

token

contract IERC20

the asset. This is indexed so that RPC calls can filter on it.

amount

uint256

the amount.

Debit

event Debit(contract IERC20 token, uint256 amount)

the Kandel instance is debited of amount by its owner. By emitting this data, an indexer will be able to keep track of what debits are made.

Parameters

Name
Type
Description

token

contract IERC20

the asset. This is indexed so that RPC calls can filter on it.

amount

uint256

the amount.

Params

Core Kandel parameters

Parameters

struct Params {
  uint32 gasprice;
  uint24 gasreq;
  uint32 stepSize;
  uint32 pricePoints;
}

params

struct CoreKandel.Params params

Storage of the parameters for the strat.

setStepSize

function setStepSize(uint256 stepSize) public

sets the step size

Parameters

Name
Type
Description

stepSize

uint256

the step size.

setGasprice

function setGasprice(uint256 gasprice) public

sets the gasprice for offers

Parameters

Name
Type
Description

gasprice

uint256

the gasprice.

setGasreq

function setGasreq(uint256 gasreq) public

sets the gasreq (including router's gasreq) for offers

Parameters

Name
Type
Description

gasreq

uint256

the gasreq.

setParams

function setParams(struct CoreKandel.Params newParams) internal

Updates the params to new values.

Parameters

Name
Type
Description

newParams

struct CoreKandel.Params

the new params to set.

constructor

constructor(contract IMangrove mgv, struct OLKey olKeyBaseQuote, address reserveId) internal

Constructor

Parameters

Name
Type
Description

mgv

contract IMangrove

The Mangrove deployment.

olKeyBaseQuote

struct OLKey

The OLKey for the outbound_tkn base and inbound_tkn quote offer list Kandel will act on, the flipped OLKey is used for the opposite offer list.

reserveId

address

identifier of this contract's reserve when using a router.

populate

function populate(struct DirectWithBidsAndAsksDistribution.Distribution distribution, struct CoreKandel.Params parameters, uint256 baseAmount, uint256 quoteAmount) public payable

publishes bids/asks for the distribution in the indices. Care must be taken to publish offers in meaningful chunks. For Kandel an offer and its dual should be published in the same chunk (one being optionally initially dead).

This function is used at initialization and can fund with provision for the offers. Use populateChunk to split up initialization or re-initialization with same parameters, as this function will emit. If this function is invoked with different pricePoints or stepSize, then first retract all offers. msg.value must be enough to provision all posted offers (for chunked initialization only one call needs to send native tokens).

Parameters

Name
Type
Description

distribution

struct DirectWithBidsAndAsksDistribution.Distribution

the distribution of bids and asks to populate

parameters

struct CoreKandel.Params

the parameters for Kandel. Only changed parameters will cause updates. Set gasreq and gasprice to 0 to keep existing values.

baseAmount

uint256

base amount to deposit

quoteAmount

uint256

quote amount to deposit

populateChunk

function populateChunk(struct DirectWithBidsAndAsksDistribution.Distribution distribution) external

Publishes bids/asks for the distribution in the indices. Care must be taken to publish offers in meaningful chunks. For Kandel an offer and its dual should be published in the same chunk (one being optionally initially dead). This function is used externally after populate to reinitialize some indices or if multiple transactions are needed to split initialization due to gas cost. This function is not payable, use populate to fund along with populate.

Parameters

Name
Type
Description

distribution

struct DirectWithBidsAndAsksDistribution.Distribution

the distribution of bids and asks to populate

reserveBalance

function reserveBalance(enum OfferType ba) public view virtual returns (uint256 balance)

the total balance available for the strat of the offered token for the given offer type.

Parameters

Name
Type
Description

ba

enum OfferType

the offer type.

Return Values

Name
Type
Description

balance

uint256

the balance of the token.

logUpdateOfferStatus

function logUpdateOfferStatus(uint256 offerId, struct IOfferLogic.OfferArgs args, bytes32 updateOfferStatus) internal

takes care of status for updating dual and logging of potential issues.

Parameters

Name
Type
Description

offerId

uint256

the Mangrove offer id.

args

struct IOfferLogic.OfferArgs

the arguments of the offer.

updateOfferStatus

bytes32

the status returned from the _updateOffer function.

transportSuccessfulOrder

function transportSuccessfulOrder(struct MgvLib.SingleOrder order) internal

update or create dual offer according to transport logic

Parameters

Name
Type
Description

order

struct MgvLib.SingleOrder

is a recall of the taker order that is at the origin of the current trade.

transportLogic

function transportLogic(enum OfferType ba, struct MgvLib.SingleOrder order) internal virtual returns (uint256 dualOfferId, struct IOfferLogic.OfferArgs args)

transport logic followed by Kandel

Parameters

Name
Type
Description

ba

enum OfferType

whether the offer that was executed is a bid or an ask

order

struct MgvLib.SingleOrder

a recap of the taker order (order.offer is the executed offer)

Return Values

Name
Type
Description

dualOfferId

uint256

the offer id of the dual offer

args

struct IOfferLogic.OfferArgs

the argument for updating an offer

pending

function pending(enum OfferType ba) external view returns (int256)

gets pending liquidity for base (ask) or quote (bid). Will be negative if funds are not enough to cover all offer's promises.

Gas costly function, better suited for off chain calls.

Parameters

Name
Type
Description

ba

enum OfferType

offer type.

Return Values

Name
Type
Description

[0]

int256

the pending amount

depositFunds

function depositFunds(uint256 baseAmount, uint256 quoteAmount) public virtual

Deposits funds to the contract's reserve

Parameters

Name
Type
Description

baseAmount

uint256

the amount of base tokens to deposit.

quoteAmount

uint256

the amount of quote tokens to deposit.

withdrawFunds

function withdrawFunds(uint256 baseAmount, uint256 quoteAmount, address recipient) public virtual

withdraws funds from the contract's reserve

it is up to the caller to make sure there are still enough funds for live offers.

Parameters

Name
Type
Description

baseAmount

uint256

the amount of base tokens to withdraw. Use type(uint).max to denote the entire reserve balance.

quoteAmount

uint256

the amount of quote tokens to withdraw. Use type(uint).max to denote the entire reserve balance.

recipient

address

the address to which the withdrawn funds should be sent to.

withdrawFundsForToken

function withdrawFundsForToken(contract IERC20 token, uint256 amount, address recipient) internal virtual

withdraws funds from the contract's reserve for the given token

Parameters

Name
Type
Description

token

contract IERC20

the token to withdraw.

amount

uint256

the amount of tokens to withdraw. Use type(uint).max to denote the entire reserve balance.

recipient

address

the address to which the withdrawn funds should be sent to.

retractAndWithdraw

function retractAndWithdraw(uint256 from, uint256 to, uint256 baseAmount, uint256 quoteAmount, uint256 freeWei, address payable recipient) external

Retracts offers, withdraws funds, and withdraws free wei from Mangrove.

Parameters

Name
Type
Description

from

uint256

retract offers starting from this index.

to

uint256

retract offers until this index.

baseAmount

uint256

the amount of base tokens to withdraw. Use type(uint).max to denote the entire reserve balance.

quoteAmount

uint256

the amount of quote tokens to withdraw. Use type(uint).max to denote the entire reserve balance.

freeWei

uint256

the amount of wei to withdraw from Mangrove. Use type(uint).max to withdraw entire available balance.

recipient

address payable

the recipient of the funds.

PreviousAbstractKandelSeederNextDirectWithBidsAndAsksDistribution