get_liquidations
Retrieve liquidation events with customizable filters and pagination for Morpho markets, enabling precise tracking of seized or repaid assets within specified timeframes.
Instructions
Get liquidation events with filtering and pagination.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| endTimestamp | No | ||
| first | No | ||
| marketUniqueKeys | No | ||
| orderBy | No | ||
| orderDirection | No | ||
| skip | No | ||
| startTimestamp | No |
Implementation Reference
- src/index.ts:1288-1357 (handler)The main handler function for the 'get_liquidations' tool. It constructs a GraphQL query to fetch liquidation transactions from the Morpho API, applies filters for market keys and timestamps, paginates and orders results, validates the response, and returns the formatted data.if (name === GET_LIQUIDATIONS_TOOL) { try { const liquidationParams = params as LiquidationsParams; const where: Record<string, any> = { type_in: ['MarketLiquidation'] }; if (liquidationParams.marketUniqueKeys?.length) { where.marketUniqueKey_in = liquidationParams.marketUniqueKeys; } if (liquidationParams.startTimestamp) { where.timestamp_gte = liquidationParams.startTimestamp; } if (liquidationParams.endTimestamp) { where.timestamp_lte = liquidationParams.endTimestamp; } const queryParams = buildQueryParams({ first: liquidationParams.first, skip: liquidationParams.skip, orderBy: liquidationParams.orderBy, orderDirection: liquidationParams.orderDirection, where }); const query = ` query { transactions${queryParams} { pageInfo { count countTotal } items { blockNumber hash type timestamp user { address } data { ... on MarketLiquidationTransactionData { seizedAssets repaidAssets seizedAssetsUsd repaidAssetsUsd badDebtAssetsUsd liquidator market { uniqueKey } } } } } }`; const response = await axios.post(MORPHO_API_BASE, { query }); const validatedData = LiquidationsResponseSchema.parse(response.data); return { content: [{ type: 'text', text: JSON.stringify(validatedData.data.transactions, null, 2) }], }; } catch (error: any) { return { isError: true, content: [{ type: 'text', text: `Error retrieving liquidations: ${error.message}` }], }; } }
- src/index.ts:742-766 (registration)Registration of the 'get_liquidations' tool in the listTools handler, including name, description, and input schema definition.{ name: GET_LIQUIDATIONS_TOOL, description: 'Get liquidation events with filtering and pagination.', inputSchema: { type: 'object', properties: { marketUniqueKeys: { type: 'array', items: { type: 'string' } }, startTimestamp: { type: 'number' }, endTimestamp: { type: 'number' }, first: { type: 'number' }, skip: { type: 'number' }, orderBy: { type: 'string', enum: ['Timestamp', 'SeizedAssetsUsd', 'RepaidAssetsUsd'] }, orderDirection: { type: 'string', enum: ['Asc', 'Desc'] } } }, },
- src/index.ts:301-308 (schema)Zod schema for validating the response from the liquidations GraphQL query.const LiquidationsResponseSchema = z.object({ data: z.object({ transactions: z.object({ pageInfo: PageInfoSchema, items: z.array(TransactionSchema), }), }), });
- src/index.ts:234-253 (schema)Zod schema defining the structure of transaction objects used in liquidations response.const TransactionSchema = z.object({ blockNumber: z.number(), hash: z.string(), type: z.string(), timestamp: z.number(), user: z.object({ address: z.string(), }), data: z.object({ seizedAssets: z.union([z.string(), z.number()]).transform(stringToNumber).optional(), repaidAssets: z.union([z.string(), z.number()]).transform(stringToNumber).optional(), seizedAssetsUsd: z.union([z.string(), z.number()]).transform(stringToNumber).optional(), repaidAssetsUsd: z.union([z.string(), z.number()]).transform(stringToNumber).optional(), badDebtAssetsUsd: z.union([z.string(), z.number()]).transform(stringToNumber).optional(), liquidator: z.string().optional(), market: z.object({ uniqueKey: z.string(), }).optional(), }).optional(), });
- src/index.ts:314-314 (registration)Constant defining the tool name 'get_liquidations' used throughout the code.const GET_LIQUIDATIONS_TOOL = 'get_liquidations';