Take a Midnight offer group
Builds and simulates a take of one active Midnight offer group identified by <chain_id>:<group_id>. group_id values come from the Morpho API /v0/midnight/users/{user_address}/offer-groups or the groups returned by the offer-publication routes.
The side is read from the group: a group whose maker lends (buy: true) is taken by borrowing, optionally with collateral_supplies; a group whose maker borrows (buy: false) is taken by lending and requires funding. When the group has live offers on more than one market, market_id is required and selects one market to take from. Exactly one guard is required: slippage, a WAD-scaled per-second simple rate (max_rate on the borrow side or min_rate on the lend side), or one absolute bound — max_units for assets / min_assets for units on the borrow side, min_units for assets / max_assets for units on the lend side. Rate guards also work with p2p: true and markets that have not yet been created. On the borrow side with slippage, the guarded seller price is also never below the price implied by a 100% fixed APR to maturity, and quotes below that floor are rejected. On the lend side with only slippage, the guarded buyer price is capped at par (one loan-token base unit per credit unit). If the best quoted price is already above par, the route returns 422 QUOTE_INSUFFICIENT; to accept an above-par price, use an amount with unit set to units and a max_assets guard. With native or auto funding and a units target, the API wraps native tokens up to max_lend_assets, the worst-case spend, and any wrapped amount the fill doesn't use stays in the account as the wrapped token (for example WETH). With an assets target nothing is left over. reduce_only, expired, cancelled, filled, or not-yet-active groups are rejected. With p2p: true, the take uses the offer group shared directly by the maker, including offers that aren't in the public offer book. For vault adapter offers shared with p2p: true, borrowing is limited by the vault's idle loan assets plus available variable-rate funding, and lending is limited by the maker's gross credit after accrued fees. Remaining pending fees are not subtracted again. Unrecognized funding sources add no available amount. If the offer group has enough remaining amount but the maker cannot fund the request, the route returns 422 OFFER_GROUP_MAKER_CANNOT_PAY. Requests above the group's remaining amount return 422 QUOTE_INSUFFICIENT. Vault allocation and duration limits are checked by simulation.
Authorization
ApiKeyAuth Send your Morpho-issued key on every action request. JWKS needs no key on every host; public documentation needs no key.
In: header
Path Parameters
Midnight offer-group selector formatted as <chain_id>:<group_id>. The colon may be sent literally or as %3A.
^(?:[1-9][0-9]{0,14}|[1-8][0-9]{15}|900[0-6][0-9]{12}|90070[0-9]{11}|90071[0-8][0-9]{10}|900719[0-8][0-9]{9}|9007199[0-1][0-9]{8}|90071992[0-4][0-9]{7}|900719925[0-3][0-9]{6}|9007199254[0-6][0-9]{5}|90071992547[0-3][0-9]{4}|9007199254740[0-8][0-9]{2}|90071992547409[0-8][0-9]{1}|9007199254740990|9007199254740991):0x[0-9a-fA-F]{64}$Request Body
application/json
TypeScript Definitions
Use the request body type in TypeScript.
Response Body
application/json
application/json
application/json
application/json
application/json
application/json
application/json
curl -X POST "https://example.com/v0/actions/midnight/offer-groups/{group-selector}/take" \ -H "Content-Type: application/json" \ -d '{ "account": "0x6aBB9Aeb93e9aF04c8D9FD2b84BF6ca8EDC3eAf2", "amount": { "unit": "assets", "value": "1000000" }, "guard": { "type": "slippage", "bps": 50 } }'{ "data": { "action_id": "act_0123456789abcdef0123456789abcdef", "status": "prepared", "chain_id": 8453, "account": "0x6aBB9Aeb93e9aF04c8D9FD2b84BF6ca8EDC3eAf2", "expires_at": 1760001800, "market": { "id": "0xcdea4ca06837feca3026b23a95f0bd96c3eabdc77d1211472ce0346fcc200649", "loan_asset": { "address": "0x4200000000000000000000000000000000000006" }, "collaterals": [ { "address": "0x2Ae3F1Ec7F1F5012CFEab0185bfc7aa3cf0DEc22" }, { "address": "0xFa750DD0099eAdB72d401244De73ce7B89edf90F" } ], "tick_spacing": 4 }, "action": "midnight.take_borrow", "amount": { "unit": "assets", "value": "1000000" }, "guard": { "type": "slippage", "bps": 50 }, "quote": { "average_best_price_wad": "999701089374277091", "average_worst_price_wad": "994702583927405705", "available_assets": "1000000", "available_units": "1000299", "offer_count": 1 }, "max_borrow_units": "1005326", "calls": [ { "id": "call_0", "kind": "borrow", "to": "0x0bF30B530f816a619C3F28a3b9f44C441122555D", "data": "0xca7de09c000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000f424000000000000000000000000000000000000000000000000000000000000f570e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000006abb9aeb93e9af04c8d9fd2b84bf6ca8edc3eaf2000000000000000000000000000000000000000000000000000000000000038000000000000000000000000000000000000000000000000000000000000003a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000068e77f0800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002105000000000000000000000000adedd8ab6de832766fedf0fac4992e5c4d3ea18a00000000000000000000000042000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000006ae4b0f00000000000000000000000000000000000000000000000003782dace9d9000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000002ae3f1ec7f1f5012cfeab0185bfc7aa3cf0dec220000000000000000000000000000000000000000000000000d1d507e40be80000000000000000000000000000000000000000000000000000429d069189e0000000000000000000000000000b03855ad5afd6b8db8091dd5551cac4ed621d9e6000000000000000000000000fa750dd0099eadb72d401244de73ce7b89edf90f0000000000000000000000000000000000000000000000000d99a8cec7e200000000000000000000000000000000000000000000000000000429d069189e0000000000000000000000000000a02f629871be35d6db0f88c944cf955554ec87c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000048000000000000000000000000000000000000000000000000000000000000f436b00000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000200000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000068e77f08000000000000000000000000000000000000000000000000000000000000138800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005000000000000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001e8480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002105000000000000000000000000adedd8ab6de832766fedf0fac4992e5c4d3ea18a00000000000000000000000042000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000006ae4b0f00000000000000000000000000000000000000000000000003782dace9d9000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000002ae3f1ec7f1f5012cfeab0185bfc7aa3cf0dec220000000000000000000000000000000000000000000000000d1d507e40be80000000000000000000000000000000000000000000000000000429d069189e0000000000000000000000000000b03855ad5afd6b8db8091dd5551cac4ed621d9e6000000000000000000000000fa750dd0099eadb72d401244de73ce7b89edf90f0000000000000000000000000000000000000000000000000d99a8cec7e200000000000000000000000000000000000000000000000000000429d069189e0000000000000000000000000000a02f629871be35d6db0f88c944cf955554ec87c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000021234000000000000000000000000000000000000000000000000000000000000", "value": "0" } ], "simulation": { "status": "success", "block": { "number": "21000000", "timestamp": 1760000000 }, "wallet_changes": [ { "asset": { "type": "erc20", "address": "0x4200000000000000000000000000000000000006" }, "difference": "1000000" } ], "position_changes": { "credit_units": "0", "debt_units": "1000299" }, "effects": { "borrowed_assets": "1000000", "borrowed_units": "1000299", "referral_fee_assets": "0" } }, "group": "0x0000000000000000000000000000000000000000000000000000000000000000", "maker": "0x2000000000000000000000000000000000000002", "collateral_supplies": [] }}{ "error": { "code": "REQUEST_ABORTED", "message": "string", "details": [ { "code": "string", "message": "string", "path": [ "string" ], "rule": "string", "details": { "min_assets": "string", "loan_token": "string" } } ], "request_id": "string" }}{ "error": { "code": "MARKET_NOT_FOUND", "message": "string", "details": [ { "code": "string", "message": "string", "path": [ "string" ], "rule": "string", "details": { "min_assets": "string", "loan_token": "string" } } ], "request_id": "string" }}{ "error": { "code": "PAYLOAD_TOO_LARGE", "message": "string", "details": [ { "code": "string", "message": "string", "path": [ "string" ], "rule": "string", "details": { "min_assets": "string", "loan_token": "string" } } ], "request_id": "string" }}This action is unavailable on the selected chain.
{ "error": { "code": "ACTION_UNSUPPORTED", "message": "Midnight offer-group takes are not supported on this chain.", "details": null, "request_id": "req_0123456789abcdef" }}{ "error": { "code": "INTERNAL_ERROR", "message": "string", "details": [ { "code": "string", "message": "string", "path": [ "string" ], "rule": "string", "details": { "min_assets": "string", "loan_token": "string" } } ], "request_id": "string" }}{ "error": { "code": "CONTRACT_CODE_MISSING", "message": "string", "details": [ { "code": "string", "message": "string", "path": [ "string" ], "rule": "string", "details": { "min_assets": "string", "loan_token": "string" } } ], "request_id": "string" }}POSTWithdraw a lend offer's supplied funding
Recovers the entire supply position held by the account's funding address in a variable-rate market.
POSTBuild a quoted Midnight lend
Builds a lend of an exact loan-asset spend (unit: assets, inclusive of any referral fee) or an exact credit-unit amount (unit: units; credit units are the…