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:
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.
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.
Last updated