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
  • Interacting with JS
    • Getting started
  • Query mangrove
  • Market orders
  • Limit orders
  • 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
  • Querying for open markets
  • "Cashness" of a token
  • Calling the SDK for open markets
  • Getting the order book

Query mangrove

Querying for open markets

Mangrove has a built in function in its reader contract to return the list of all open markets diractly from the chain. This function will consist of 2 consecutive RPC calls to get the open markets and the tokens informations. Other than default viem parameters, there are two things to provide to this function; the list of "cashnesses" and symbol overrides. Symbol overrides is a string to string dict to override the returned symbol string.

"Cashness" of a token

The "cashness" of a token defines if in a given market, it will be a base or a quote token. It is up to you to choose, but the mangrove team has these given principles:

  • The ceil "cashness" for a variable asset is 1000, the floor "cashness" for a stable asset is 1000.

  • Higher TVL means higher cashness.

Any case by case scenario can revise this rule, but all in all If asset A has a higher "cashness" than asset B, then A will be the quote asset, and B will be the base asset.

Calling the SDK for open markets

Here is the implementation of the call to get all open markets:

src/markets.ts
import type { MarketParams } from "@mangrovedao/mgv";
import { client } from "./client";

export async function getOpenMarkets(): Promise<MarketParams[]> {
  return client.getOpenMarkets({
    cashnesses: { WETH: 100, WBTC: 200, USDC: 1000 },
    symbolOverrides: {
      USDT0: "USDT",
    },
  });
}

Getting the order book

Now that we have choosen a market, we need to get the order book for that specific market. This function includes only one multicall that queries all orders up to a given depth, as well as market configs.

src/book.ts
import {
  publicMarketActions,
  type Book,
  type MarketParams,
} from "@mangrovedao/mgv";
import { client } from "./client";
import { mangroveConfig } from "./config";

export async function getBook(
  market: MarketParams,
  depth = 100n
): Promise<Book> {
  const marketClient = client.extend(
    publicMarketActions(mangroveConfig, market)
  );
  return marketClient.getBook({ depth });
}

Now with that, we are ready to make market and limit orders.

PreviousGetting startedNextMarket orders

Last updated 5 days ago