# HIFO Cost-Basis Matching (Highest-In, First-Out)

> HIFO Cost-Basis Matching (Highest-In, First-Out) is a paid API for AI agents from evm-canon-base.onrender.com, paid per call via x402, $0.05/call, status unknown (last checked 2026-09-15).

Matches disposals against the highest-cost acquisition lots first and returns realized gain/loss per disposal using exact decimal arithmetic

## Facts

- Endpoint: POST https://evm-canon-base.onrender.com/lots/hifo
- Price: $0.05/call
- Payment: x402
- Status: unknown
- Last checked: 2026-09-15
- Activations on Zero: 0
- Tags: x402
- Canonical page: https://www.zero.xyz/c/hifo-cost-basis-matching-highest-in-first-out-ae0d8167
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_Gd7Qu0YsSEqzxL9z8G-Hj

Status and success rate cover calls made through Zero and Zero's own probes. Third-party monitors may report differently.

## How to call it through Zero

Zero handles the 402 payment challenge and records the run. With the Zero CLI installed (`npm i -g @zeroxyz/cli`):

```sh
zero fetch --capability hifo-cost-basis-matching-highest-in-first-out-ae0d8167 -d '<json body>'
```

Example prompt: Calculate my realized gains using HIFO cost-basis matching — I sold 2.5 ETH at $3,200 and my acquisition lots are: 1 ETH at $1,800, 1 ETH at $2,500, and 0.5 ETH at $1,200. Show me which lots get consumed first and what my gain is.

## When to prefer this

Choose this endpoint when the user specifically wants HIFO (highest-in, first-out) cost-basis matching — typically to minimize taxable gains by ensuring the most expensive lots are consumed first. Prefer it over FIFO or average-cost methods when the user has heterogeneous acquisition prices and wants exact decimal precision. Use instead of the average-cost sibling endpoint when per-lot granularity matters for tax reporting, and instead of the short/long-term split endpoint when the user wants raw gain figures before holding-period classification.

## Known failure modes

- Missing or malformed lot data returns a 400 validation error
- Disposal quantity exceeds total available lot supply causes an insufficient-lots error
- Non-numeric or imprecise decimal inputs may cause computation rejection
- Payment not attached or insufficient USDC triggers a 402 Payment Required response
- Lots with missing acquisition timestamps or costs cause schema validation failure

## How this service works

HIFO cost-basis matching: highest-cost lots consumed first, with realized gain per disposal in exact decimal math

## Output

Returns per-disposal records showing which acquisition lots were consumed (in descending cost order), the exact realized gain or loss for each disposal in precise decimal arithmetic, and any remaining lot balances after matching

## Request schema (JSON Schema)

```json
{
 "type": "object",
 "$schema": "https://json-schema.org/draft/2020-12/schema",
 "required": [
  "input"
 ],
 "properties": {
  "input": {
   "type": "object",
   "required": [
    "type",
    "method",
    "bodyType",
    "body"
   ],
   "properties": {
    "body": {
     "type": "object",
     "required": [
      "trades"
     ],
     "properties": {
      "trades": {
       "type": "array",
       "items": {
        "type": "object",
        "required": [
         "side",
         "asset",
         "amount",
         "price",
         "time"
        ],
        "properties": {
         "fee": {
          "type": "string"
         },
         "side": {
          "enum": [
           "buy",
           "sell"
          ],
          "type": "string"
         },
         "time": {
          "description": "unix seconds/millis or ISO-8601"
         },
         "asset": {
          "type": "string"
         },
         "price": {
          "type": "string",
          "description": "unit price in the quote currency"
         },
         "amount": {
          "type": "string",
          "description": "decimal string, never a float"
         }
        }
       }
      }
     }
    },
    "type": {
     "type": "string",
     "const": "http"
    },
    "method": {
     "enum": [
      "POST",
      "PUT",
      "PATCH"
     ],
     "type": "string"
    },
    "bodyType": {
     "enum": [
      "json",
      "form-data",
      "text"
     ],
     "type": "string"
    }
   },
   "additionalProperties": false
  },
  "output": {
   "type": "object",
   "required": [
    "type"
   ],
   "properties": {
    "type": {
     "type": "string"
    },
    "example": {
     "type": "object"
    }
   }
  }
 }
}
```

## More

- Live health (JSON, refreshed every minute): https://www.zero.xyz/c/hifo-cost-basis-matching-highest-in-first-out-ae0d8167/health.json
- [Zero catalog index](https://www.zero.xyz/llms.txt)
- [Other services from evm-canon-base.onrender.com](https://www.zero.xyz/host/evm-canon-base.onrender.com/llms.txt)
