# Wallet Token P&L & FIFO Cost Basis Analyzer

> Wallet Token P&L & FIFO Cost Basis Analyzer is a paid API for AI agents from x402-deployer.x402-deployer.workers.dev, paid per call via x402, $0.05/call, status unknown (last checked 2026-09-13).

Calculates realized and unrealized profit/loss, FIFO cost basis, and current balance for any ERC-20 token in a wallet on a given EVM chain using historical Etherscan transfers priced with CoinGecko spot rates.

## Facts

- Endpoint: POST https://x402-deployer.x402-deployer.workers.dev/wallet-pnl
- Price: $0.05/call
- Payment: x402
- Status: unknown
- Last checked: 2026-09-13
- Activations on Zero: 0
- Tags: x402
- Canonical page: https://www.zero.xyz/c/x402-deployer-x402-deployer-workers-dev-6cf6264b
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_0pD2IDR4Dyi1CVQfG73O4

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 x402-deployer-x402-deployer-workers-dev-6cf6264b -d '<json body>'
```

Example prompt: What's my realized and unrealized P&L for USDC (contract 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48) in my Ethereum wallet 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045 — I want FIFO cost basis, current balance, and total gain breakdown.

## When to prefer this

Use this endpoint when you need FIFO-based tax cost basis or realized/unrealized P&L for a specific ERC-20 token in a specific EVM wallet. Prefer it over general portfolio dashboards when you need programmatic, per-token accounting with historical USD pricing. Best suited for on-demand analytics on a single (wallet, token, chain) triple rather than broad multi-asset sweeps.

## Known failure modes

- Wallet address not found or invalid — returns error
- ERC-20 contract address not recognized by Etherscan — empty transfer list
- Chain not supported by Etherscan v2 — error response
- CoinGecko rate unavailable for a historical timestamp — may result in incomplete pricing
- More than 500 transfers exist — results capped, older cost basis may be inaccurate
- Rate limiting from Etherscan or CoinGecko — timeout or partial result
- Malformed wallet or token address — validation error

## How this service works

Wallet token P&L / FIFO cost basis / realized + unrealized profit / EVM portfolio analytics. For any (wallet, ERC-20, chain) triple, pulls all transfers from Etherscan v2, prices each one at the historical USD spot via CoinGecko, runs FIFO accounting and reports cost basis, realized gain, unrealized gain, current balance, and tx count. Capped at the most recent 500 transfers.

## Output

Returns cost basis in USD, realized gain/loss, unrealized gain/loss, current token balance, and transaction count — all computed via FIFO accounting across the most recent 500 transfers, with each transfer priced at its historical USD spot rate.

## Request schema (JSON Schema)

```json
{
 "$schema": "https://json-schema.org/draft/2020-12/schema",
 "type": "object",
 "properties": {
  "input": {
   "type": "object",
   "properties": {
    "type": {
     "type": "string",
     "const": "http"
    },
    "method": {
     "type": "string",
     "enum": [
      "POST"
     ]
    },
    "bodyType": {
     "type": "string",
     "enum": [
      "json",
      "form-data",
      "text"
     ]
    },
    "body": {
     "properties": {
      "wallet": {
       "type": "string",
       "description": "0x-prefixed 20-byte wallet address."
      },
      "token_address": {
       "type": "string",
       "description": "0x-prefixed 20-byte ERC-20 contract."
      },
      "chain": {
       "type": "string",
       "enum": [
        "base",
        "ethereum",
        "polygon",
        "arbitrum",
        "optimism"
       ],
       "description": "EVM chain. Default 'ethereum'."
      }
     },
     "required": [
      "wallet",
      "token_address"
     ]
    }
   },
   "required": [
    "type",
    "method",
    "bodyType",
    "body"
   ],
   "additionalProperties": false
  },
  "output": {
   "type": "object",
   "properties": {
    "type": {
     "type": "string"
    },
    "example": {
     "type": "object",
     "properties": {
      "wallet": {
       "type": "string"
      },
      "token": {
       "type": "string"
      },
      "chain": {
       "type": "string"
      },
      "symbol": {
       "type": "string"
      },
      "decimals": {
       "type": "integer"
      },
      "tx_count": {
       "type": "integer"
      },
      "transfers_in": {
       "type": "number"
      },
      "transfers_out": {
       "type": "number"
      },
      "current_balance": {
       "type": "number"
      },
      "current_price_usd": {
       "type": "number"
      },
      "cost_basis_usd": {
       "type": "number"
      },
      "realized_pnl_usd": {
       "type": "number"
      },
      "unrealized_pnl_usd": {
       "type": "number"
      },
      "total_pnl_usd": {
       "type": "number"
      },
      "capped_at": {
       "type": "null"
      },
      "coingecko_id": {
       "type": "string"
      },
      "source": {
       "type": "string"
      }
     }
    }
   },
   "required": [
    "type"
   ]
  }
 },
 "required": [
  "input"
 ]
}
```

## More

- Live health (JSON, refreshed every minute): https://www.zero.xyz/c/x402-deployer-x402-deployer-workers-dev-6cf6264b/health.json
- [Zero catalog index](https://www.zero.xyz/llms.txt)
- [Other services from x402-deployer.x402-deployer.workers.dev](https://www.zero.xyz/host/x402-deployer.x402-deployer.workers.dev/llms.txt)
