Skip to content

Conversation

@m-sz
Copy link
Contributor

@m-sz m-sz commented Jan 13, 2026

Description

Aave wants to track specific orders in bulk, knowing their ids.

Changes

Adds POST handler for v1/orders/lookup endpoint that requires a list of order uids and responds with a vector of their data. Has a hardcoded limit of 5000 orders per request.

How to test

Test on staging, query multiple orders using this API.

@m-sz m-sz marked this pull request as ready for review January 23, 2026 14:10
@m-sz m-sz requested a review from a team as a code owner January 23, 2026 14:10
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new endpoint v1/get_orders to retrieve orders in batches using a POST request with a limit of 5000 orders per request. The code adds a new module get_orders_by_uid.rs, modifies api.rs to include the new route, and updates database/orders.rs and orderbook.rs to support fetching multiple orders. I found a missing test case for the MAX_ORDERS_LIMIT validation.

@m-sz
Copy link
Contributor Author

m-sz commented Jan 23, 2026

Tested on sepolia staging:

curl -d "[\"0x4f30bff027049ef2d2f8c8ba17be5e2e452c8fc9ad48273ef44d48c0e210bbc16406ce57254d45d503c7cb3e729aab9ddbbb3ec269738a51\", \"0x4f30bff027049ef2d2f8c8ba17be5e2e452c8fc9ad48273ef44d48c0e210bbc16406ce57254d45d503c7cb3e729aab9ddbbb3ec269738a51\"]" "https://barn.api.cow.fi/sepolia/api/v1/orders/lookup" -H "Content-Type: application/json"

(queries twice for the same order)

response

[
    {
        "creationDate": "2026-01-23T14:18:53.912159Z",
        "owner": "0x6406ce57254d45d503c7cb3e729aab9ddbbb3ec2",
        "uid": "0x4f30bff027049ef2d2f8c8ba17be5e2e452c8fc9ad48273ef44d48c0e210bbc16406ce57254d45d503c7cb3e729aab9ddbbb3ec269738a51",
        "availableBalance": null,
        "executedBuyAmount": "3931710370705679403",
        "executedSellAmount": "4000000000000000000",
        "executedSellAmountBeforeFees": "4000000000000000000",
        "executedFeeAmount": "0",
        "executedFee": "68289629294320597",
        "executedFeeToken": "0xbe72e441bf55620febc26715db68d3494213d8cb",
        "invalidated": false,
        "status": "fulfilled",
        "class": "limit",
        "settlementContract": "0x9008d19f58aabd9ed0d60971565aa8510560ab41",
        "isLiquidityOrder": false,
        "fullAppData": "{\"appCode\":\"CoW Swap\",\"environment\":\"barn\",\"metadata\":{\"orderClass\":{\"orderClass\":\"market\"},\"quote\":{\"slippageBips\":101,\"smartSlippage\":true}},\"version\":\"1.12.0\"}",
        "quote": {
            "gasAmount": "98318.00000000000",
            "gasPrice": "3575917434.000000",
            "sellTokenPrice": "0.008587696541803472",
            "sellAmount": "4000000000000000000",
            "buyAmount": "4000000000000000000",
            "feeAmount": "40939622000450720",
            "solver": "0x99b4136666ca1d13020830350ca8d01a0e5e466b",
            "verified": true,
            "metadata": {
                "interactions": [],
                "jitOrders": [],
                "preInteractions": [],
                "version": "1.0"
            }
        },
        "sellToken": "0xbe72e441bf55620febc26715db68d3494213d8cb",
        "buyToken": "0xbe72e441bf55620febc26715db68d3494213d8cb",
        "receiver": "0x6406ce57254d45d503c7cb3e729aab9ddbbb3ec2",
        "sellAmount": "4000000000000000000",
        "buyAmount": "3919073868181753833",
        "validTo": 1769179729,
        "appData": "0x8a8e8bdd353e10a8fb1aabb9594537fba2f1cce8fc655fdeaaa568286b3b53af",
        "feeAmount": "0",
        "kind": "sell",
        "partiallyFillable": false,
        "sellTokenBalance": "erc20",
        "buyTokenBalance": "erc20",
        "signingScheme": "eip712",
        "signature": "0x6cc9e9e2e8826cffb092a8531b103bbc3e70472e6455185af20245d1be14748e13a440f8e19e88db1a47320cff5d7b4a5ac32f07c76f708f94531616f597e8411b",
        "interactions": {
            "pre": [],
            "post": []
        }
    },
    {
        "creationDate": "2026-01-23T14:18:53.912159Z",
        "owner": "0x6406ce57254d45d503c7cb3e729aab9ddbbb3ec2",
        "uid": "0x4f30bff027049ef2d2f8c8ba17be5e2e452c8fc9ad48273ef44d48c0e210bbc16406ce57254d45d503c7cb3e729aab9ddbbb3ec269738a51",
        "availableBalance": null,
        "executedBuyAmount": "3931710370705679403",
        "executedSellAmount": "4000000000000000000",
        "executedSellAmountBeforeFees": "4000000000000000000",
        "executedFeeAmount": "0",
        "executedFee": "68289629294320597",
        "executedFeeToken": "0xbe72e441bf55620febc26715db68d3494213d8cb",
        "invalidated": false,
        "status": "fulfilled",
        "class": "limit",
        "settlementContract": "0x9008d19f58aabd9ed0d60971565aa8510560ab41",
        "isLiquidityOrder": false,
        "fullAppData": "{\"appCode\":\"CoW Swap\",\"environment\":\"barn\",\"metadata\":{\"orderClass\":{\"orderClass\":\"market\"},\"quote\":{\"slippageBips\":101,\"smartSlippage\":true}},\"version\":\"1.12.0\"}",
        "quote": {
            "gasAmount": "98318.00000000000",
            "gasPrice": "3575917434.000000",
            "sellTokenPrice": "0.008587696541803472",
            "sellAmount": "4000000000000000000",
            "buyAmount": "4000000000000000000",
            "feeAmount": "40939622000450720",
            "solver": "0x99b4136666ca1d13020830350ca8d01a0e5e466b",
            "verified": true,
            "metadata": {
                "interactions": [],
                "jitOrders": [],
                "preInteractions": [],
                "version": "1.0"
            }
        },
        "sellToken": "0xbe72e441bf55620febc26715db68d3494213d8cb",
        "buyToken": "0xbe72e441bf55620febc26715db68d3494213d8cb",
        "receiver": "0x6406ce57254d45d503c7cb3e729aab9ddbbb3ec2",
        "sellAmount": "4000000000000000000",
        "buyAmount": "3919073868181753833",
        "validTo": 1769179729,
        "appData": "0x8a8e8bdd353e10a8fb1aabb9594537fba2f1cce8fc655fdeaaa568286b3b53af",
        "feeAmount": "0",
        "kind": "sell",
        "partiallyFillable": false,
        "sellTokenBalance": "erc20",
        "buyTokenBalance": "erc20",
        "signingScheme": "eip712",
        "signature": "0x6cc9e9e2e8826cffb092a8531b103bbc3e70472e6455185af20245d1be14748e13a440f8e19e88db1a47320cff5d7b4a5ac32f07c76f708f94531616f597e8411b",
        "interactions": {
            "pre": [],
            "post": []
        }
    }
]

@m-sz
Copy link
Contributor Author

m-sz commented Jan 23, 2026

By the way, we can have a discussion on what the endpoint itself should be.
This has to be a POST request since we need to provide JSON array of order ids and /v1/orders obviously creates an order so there has to be a different name

I got a couple suggestions from Claude

  1. Nested under a "batch" or "bulk" path
    POST /v1/batch/orders
    POST /v1/bulk/orders
    Groups batch operations separately from the main resource routes.
  2. Different verb-like suffix
    POST /v1/orders/fetch
    POST /v1/orders/get
    POST /v1/orders/list
    Less common but unambiguous.
  3. Underscore-prefixed action
    POST /v1/orders/_search
    POST /v1/orders/_mget
    Elasticsearch uses this convention. The underscore signals "this is a special action, not a resource."
  4. Hyphenated compound resource
    POST /v1/order-lookups
    POST /v1/order-queries
    Treats the bulk lookup as its own resource type.
  5. RPC-style separate namespace
    POST /v1/rpc/get-orders
    POST /v1/actions/get-orders

based on the above suggestions I have opted for a custom not-order-id-like name /v1/orders/lookup - to lookup many orders, but I am open for discussion and don't have a strong opinion.

async move {
Result::<_, Infallible>::Ok(match request_result {
Ok(uids) => {
let result = orderbook.get_orders(&uids).await;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will accumulate all the orders in memory, which is probably not a good idea. Can we instead return a stream of data directly from the DB?

Comment on lines 325 to 344
for uid in uids {
results.push(
match orders::single_full_order_with_quote(&mut ex, &ByteArray(uid.0)).await? {
Some(order_with_quote) => {
let (order, quote) = order_with_quote.into_order_and_quote();
Some(full_order_with_quote_into_model_order(
order,
quote.as_ref(),
))
}
None => {
// try to find the order in the JIT orders table
database::jit_orders::get_by_id(&mut ex, &ByteArray(uid.0))
.await?
.map(full_order_into_model_order)
}
}
.transpose(),
);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sequential fetching of 5k orders will result in a nightmare performance.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The best option is to introduce a query to fetch everything at once using the QueryBuilder. There are many examples in the code.

@m-sz m-sz marked this pull request as draft January 26, 2026 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants