DeFi and Taxation in Spain: Swaps, Pools, and Yield Farming
Decentralized Finance (DeFi) represents one of the greatest challenges for crypto taxation. The AEAT has not published a specific guide for every DeFi operation, but applying the general principles of IRPF allows for the establishment of a reasonably secure framework.
1. Swaps on DEX (Uniswap, 1inch, Jupiter…)
A swap on a decentralized exchange—exchanging one token for another—has exactly the same tax treatment as an exchange on a CEX: it is considered a capital transfer (transmisión patrimonial).
Example: ETH → USDC swap on Uniswap
- You sold ETH for USDC.
- The gain or loss is calculated by the difference between the value in EUR of the USDC received and the FIFO acquisition cost of the ETH delivered.
- It is taxed as a capital gain/loss (ganancia/pérdida patrimonial) in the savings base.
Gas fees paid in ETH are also deductible from the transfer value (reducing the gain).
2. Liquidity Provision (LP)
When you add a pair of tokens to a liquidity pool (for example, ETH + USDC on Uniswap), the AEAT considers that you are transferring those tokens in exchange for LP tokens.
- LP_ADD: generates a gain/loss based on the difference between the market value of the contributed tokens and their FIFO cost.
- LP_REMOVE: generates a gain/loss based on the difference between the recovered tokens (at market price) and the cost of the LP tokens.
- Impermanent loss: unrealized loss within the pool is not deductible until the funds are withdrawn.
3. Yield Farming and Reward Farming
Farming rewards (protocol tokens received for depositing liquidity) are taxed as investment income (rendimientos del capital mobiliario) at the time of credit.
The mentioned reward token received takes the market value at the time of receipt as its acquisition cost for future sales.
4. Lending and Collateral (Aave, Compound…)
- Depositing tokens as collateral in a lending protocol does not generate a taxable event if you retain economic ownership of the assets.
- Interests received (in aToken or cToken) are taxed as investment income (rendimientos del capital mobiliario).
- If the protocol automatically liquidates your collateral, a capital transfer (transmisión patrimonial) is generated at the liquidation price.
5. Bridging Between Networks
Moving assets from Ethereum to Polygon (or any other network) via a bridge is a self-transfer operation if you use the same asset. It does not generate a taxable event if you can prove that the tokens belong to you on both networks.
Note: if the bridge issues a different wrapped token (such as WBTC instead of BTC), it could be argued that there is a transfer and an acquisition at market price.
DeFi Tax Treatment Summary Table
| Operation | Classification | Timing of Taxation |
|---|---|---|
| DEX Swap | Capital gain/loss | At the time of the swap |
| LP Add | Capital gain/loss | At the time of contribution |
| LP Remove | Capital gain/loss | At the time of withdrawal |
| Farming Rewards | Investment income | At the time of credit |
| Lending Interest | Investment income | Periodically |
| Deposited Collateral | Not taxed | — |
| Bridge (same asset) | Not taxed | — |
Practical Recommendations
- Save the transaction hashes for every DeFi operation—they are your proof.
- Export the history of each protocol periodically (many have APIs or CSV exporters).
- Use specialized tools that automatically detect the type of DeFi operation.
Conclusion
DeFi adds enormous complexity to tax calculations, but the principle remains the same: every transfer of assets generates a taxable event. Keeping an exhaustive record from day one makes the difference between a correct tax return and a complicated audit.


