{"uid":"cap_Gd7Qu0YsSEqzxL9z8G-Hj","slug":"hifo-cost-basis-matching-highest-in-first-out-ae0d8167","name":"HIFO Cost-Basis Matching (Highest-In, First-Out)","description":"HIFO cost-basis matching: highest-cost lots consumed first, with realized gain per disposal in exact decimal math","url":"https://evm-canon-base.onrender.com/lots/hifo","method":"POST","headers":{},"bodySchema":{"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"}}}}},"responseSchema":null,"example":null,"exampleRequest":null,"tags":["x402"],"displayCostAmount":"0.05","displayCostAsset":"USDC","priceDynamic":false,"priceHint":null,"priceStatus":"priced","priceSource":"probe","requiresHandshake":false,"reviewCount":0,"rating":{"score":"0.00","successRate":"0.00","reviews":0,"stars":null,"state":"unrated"},"availabilityStatus":"unknown","priceObserved":null,"sessionDeposit":null,"pricing":{"kind":"static","summary":"$0.05/call","primary":{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.05","per":"call","confidence":"exact"},"accepted":[{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.05","per":"call","confidence":"exact"}]},"paymentMethods":[{"uid":"pm_nXQp00LE2MglyG9zsz0us","protocol":"x402","methodType":"crypto","chain":"base","mode":"charge","costAmount":"0.05","costPer":"request","priority":0,"asset":"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913","unit":"request","depositMicros":null,"planRef":null}],"brandName":null,"brandSlug":null,"brandBaseUrl":null,"brandDocsUrl":null,"whatItDoes":"Matches disposals against the highest-cost acquisition lots first and returns realized gain/loss per disposal using exact decimal arithmetic","exampleAgentPrompt":"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.","exampleUseCases":[{"title":"Crypto tax reporting with HIFO","prompt":"I need to figure out my capital gains for the year using the HIFO method. I bought ETH in several batches — 3 ETH at $1,500, 2 ETH at $2,800, and 1 ETH at $3,500 — and then sold 4 ETH at $3,000. Which lots get consumed and what's my realized gain?"},{"title":"Minimizing taxable gains on token sale","prompt":"I want to minimize my taxable gains by using HIFO lot matching. I have USDC acquisition lots at various prices and I just disposed of 500 tokens at $1.05 each — can you run HIFO matching and tell me my realized gain per lot consumed?"},{"title":"DeFi portfolio tax reconciliation","prompt":"Help me reconcile my DeFi trades for tax purposes using HIFO accounting. I have a series of WBTC acquisitions and disposals from on-chain activity — apply highest-cost-first lot matching and give me the exact realized gain in decimal math for each disposal event."}],"resultDescription":"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","failureModes":["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"],"whenToPreferThis":"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.","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-09-15T06:49:33.505Z","isFirstParty":false}