Subscribe

PNL Calculation and Reconciliation in DeFi

- Co-PR with Pendle

PNL Calculation and Reconciliation in DeFi

Revisiting DeFi yield farming

In 2021, 1Token’s article already introduced the basics about DeFi yield farming. Over the next 2 to 3 years, institutions widely adopted the practice of providing liquidity for returns.

While the classics are still on (Compound, AAVE, Uniswap, Lido…), new game rules like L2, airdrops, and GMX have been generating yield with varying risk appetites to varying size of capital. GameFi, NFTs, and other strategies also generated high returns in short time frames.

Investment managers actively farmed DeFi liquidity pools for yield, while operations teams faced challenges in calculating and reporting yields. They need tools that are updated with DeFi developments to track data and automate yield calculations.

What’s special about DeFi in reconciliation?

As introduced in previous article How to calculate P&L in crypto trading, the detailed PnL calculation (i.e., realized and unrealized PnL by source / by position…) is calculated based on transaction records. However, in DeFi farming, more often than not, there’s no transaction records as CeFi or traditional finance.

Let’s use an example, farming on Arbitrum GMX V2 (address 0xfc7e45a3e96e682ca43d60b456a8cd83db0ce606), the whole process of farming WBTC-USDC liquidity pool between Oct.23 to Dec.10, you will see only 2 transactions on ARBISCAN:

1. Deposit 50,000 USDC into GMX V2 protocol

The highlighted address is the GMX DepositVault address:

0xf89e77e8dc11691c9e8757e84aafbcd8a67d7a55

2. Buy 47,359 WBTC+USDC GM token (for liquidity providing on GMX BTC-USD market)

The highlighted address is the WBTC-USDC GM address: 0x47c031236e19d024b42f8AE6780E44A573170703

  1. Weekly ARB token award

The whole process is also recorded by the 1Token PMS system. Before the on-chain operations on October 23, there was a 50k USDC balance in the account.

On the same day (October 23), after the on-chain transactions, the balance becomes a pair of coins (WBTC+USDC LP, with 0.87 WBTC and 23,514.43 USDC, totaling $50,092.40), as shown in the blockchain transaction.

After 50 days on December 10, the balance in the liquidity pool has changed significantly (WBTC+USDC LP, with 0.69 WBTC and 29,410.49 USDC, plus the accumulated 310.73 ARB tokens, totaling $59,819.85) due to the liquidity reward and impermanent loss.

Though the balance kept changing between October 23 and December 10, the transaction records are not shown anywhere—not on the blockchain scanner nor the GMX website (see snapshot below).

This makes sense with some explanation. The mechanism of GMX yield farming is liquidity pooling, and every single farmer takes a portion of the pool, which changes as farmers enter or exit on each block. Just imagine when many investors invest in the same hedge fund: the trading is done by the hedge fund, so the trading history is only on the fund level, not for each investor.

How to reconcile DeFi transactions?

To generalize the above example, for blockchain smart contracts, there can be single-coin (GMX, AAVE), or a pair of coins (Uniswap) or even three currencies as a group (Curve Tri-pool), where the trades are settled every block at the protocol level (block interval is usually a few seconds depending on blockchains), then the protocol has its own mechanism to distribute awards into each liquidity provider, so

  • Are there balance movements and hence PnL? Yes, every block.
  • Are there detailed transaction records on any ledger? Not on every block, only when the liquidity pool is manually adjusted.

How to reconcile this balance change without having the detailed transactions? There can be 2 types of realization:

Approach

Definition

Pros

Cons

Pure bottom-up

List each block’s balance movements as transactions. Like on block #x there’s a balance, on block #x+1 there’s a new balance, so there’s a virtual transaction between block #x to #x+1, and so on so forth

Perfect mirror of the activities on blockchain

Huge cost of maintaining and analyzing blockchain data

Hybrid

Use on-chain transactions to identify fund in/out from LP in a bottom-up way, and use top-down balance movement to classify the change into buckets like rewards, impermanent loss…

Efficiency in PnL classification and calculation

Top-down balance movement might mix multiple types of PnL

Comparably, pure bottom-up approach is ideal, but hybrid approach is realistic.

What’s special about DeFi in PnL calculation?

The output of PnL calculation is standard financial reporting template, so should be the same among DeFi and CeFi and traditional finance, which is realized PnL, unrealized PnL into different categories.

However, in traditional finance, those PnL are usually calculated based on transaction records that fall into standard types, like buy/sell, long/short, options premium/expense, investment income/loss, fees… which enables portfolio management software to use pure transaction-based analysis.

In crypto, transactions of CeFi can be processed in the same way. Though there are many centralized crypto exchanges/OTC/financial service providers, and each has own unique settling and naming scheme, it’s still realistic to classify and map them to standard formats, reconcile and make transaction-based analysis.

While for DeFi, there are similarities and differences to CeFi. Below are the major activities:

- Swap trading: exactly same with CeFi, there are transaction records on blockchain ledger, e.g., swapping WBTC and ARB into USDC

  • Interest from lending and borrowing: similar concept with lending and borrowing in traditional finance, but no transactions records on blockchain ledger, and interest is re-calculated and settled on each block
  • AMM fee income and impermanent loss: a liquidity providing concept that cannot be found in traditional finance, and no transaction records can be found on any blockchain ledger.

The PnL will be calculated according to different types, here are the main types (another angle from https://defillama.com/, with different category naming but overall similar idea).

Type

Details

Sample

Usage

Wallet

Withdraw, deposit, swap

ETH wallet, Solana wallet

High

Single-coin staking

Blockchain node staking, lending and borrowing,

cross-chain bridge

ETH 2.0, Lido, Blast

Compound, AAVE

Stargate, Celer

High

Uniswap V2 AMM

AMM with standard infinite price range (standard LP token)

Uniswap V2, Sushiswap

High

Uniswap V3 AMM

AMM with customized price rage (NFT LP token)

Uniswap V3, Pancakeswap V3

High

Multi-coin AMM

AMM with 3 or more tokens (USDT+USDC+DAI, or USDT+WBTC+ETH)

Curve, Balancer

Mid

LP token re-staking

Stake LP token for additional rewards

Convex, Eigenlayer

Mid

Perpetual swap

AMM on perpetual swap,

Central limited order book

GMX, Perpetual protocol

dYdX

Mid

Options

Options trading

Opyn, Lyra, Deri

Low

NFT related

Provide liquidity with NFT or use as pricing index

Blur, NFT perp

Low

For each type of protocol there can be different PnL items

For Perpetual swap AMM LP like GMX, the PnL items can be

• Cash Unrealized PnL
• Impermanent Loss
• Derivatives Position Unrealized PnL
• Cash Realized PnL
• Derivatives Position Realized PnL
• Reward
• Trading Fee Income
• Gas Fee
• Commission Fee Expense
• Funding Fee

For Uniswap AMM it’ll be less complex, with below PnL items

• Cash Unrealized PnL
• Impermanent Loss
• Cash Realized PnL
• Reward
• Trading Fee Income
• Gas Fee

While the number of DeFi protocols is exponentially more than CeFi exchanges, it can be a huge task to map all the DeFi protocols’ activities into standard types, so the efficient solution is to use a 3(rd) party to clean and standardize data first.

There are DeFi data vendors on the market, like Debank who focus on EVM, and Nansen Portfolio who covers a bit more chains but less protocols, while 1Token aggregates those existing vendors, and add own connection to those uncovered chains and build further analysis based on full DeFi data.

Now we see that it can be quite challenging in analyzing DeFi data, but is there anything easier about DeFi PnL? The answer is yes.

You might sometime hear from centralized exchanges that history query is limited to 180 days, or historical balance is not available through API. Due to the decentralization nature of blockchain, all the data is stored on the blockchain ledger, and can be traced without time limit, so the key to DeFi accounting is to have the right tool to synchronize data from blockchain, and make the reconciliation and PnL analysis.

Pendle: A Case Study in Yield Tokenization and PnL Calculations

While the classics are still on (Compound, AAVE, Uniswap, Lido…), new game rules like L2, airdrops, and GMX have been generating yield with varying risk appetites and capital sizes. GameFi, NFTs, and other strategies have also generated high returns in short time frames. Pendle, a yield tokenization/trading protocol, makes a particularly interesting case study since it comprises multiple types of strategies with various implications:

• Fixed Yield from Principal Token (PT)
• A decaying asset in Yield Token (YT) that streams the underlying yield (and points) to the holder
• LP strategy in a unique AMM that combines exposure to both PT (for fixed yield) and the underlying asset
• Points exposure that translate to airdrops at a later date

How Pendle Works

In summary, Pendle is a permissionless, yield trading protocol. By splitting and tokenizing a yield-bearing asset into its principal and yield components (PT and YT), Pendle creates a yield market that lets users speculate on both elements separately. As a result, users can execute advanced yield strategies such as Fixed Yield and Long Yield.

Principal Token (PT)

Pendle PT is essentially DeFi’s zero-coupon bond.

Take PT-eETH (26 Dec 2024) as an example.

eETH holders normally receive:

• ETH staking yield
• Restaking yield via EigenLayer
• Various points such as EtherFi Loyalty Points that can be redeemed for $ETHFI airdrop at a later date

As a PT-eETH (26 Dec 2024) holder, you are foregoing exposure to all of these yields and points in exchange for a fixed yield.

1 PT-eETH is redeemable for 1 eETH at maturity, which will be on 26 December 2024 in this example.

This means that purchasing 10 PT-eETH (26 Dec 2024) at the current time would translate to +0.0684 eETH of profit, or an APY of 3.981% when annualized.

PnL Calculation Model for PT (Added)

To provide a detailed understanding, we use a mathematical model to calculate the PnL for PT holdings.

Let:

A: The underlying token (e.g., ETH)
B: The yield-bearing token (e.g., eETH)
C: The Principal Token (PT) corresponding to B

At times T₀ and T₁, the prices are:

At T₀:
• Price of A: P_A
• Price of B: P_B = x₀ * P_A = y₀ * P_C
At T₁:
• Price of A: P_A’
• Price of B: P_B’ = x₁ * P_A’ = y₁ * P_C’

Holding 1 unit of token C (PT), the profit is calculated as:

Profit = P_C' - P_C = (x₀ / y₀) * (P_A' - P_A) + [ (x₁ / y₁) - (x₀ / y₀) ] * P_A'

Where:

Cash Balance PnL:

CashBalancePnL = (x₀ / y₀) * (P_A' - P_A)

Yield PnL:

YieldPnL = [ (x₁ / y₁) - (x₀ / y₀) ] * P_A'

This model breaks down the profit into components due to price changes of the underlying asset and changes in the yield factor.

In terms of P&L, considerations include:

• ROI in terms of eETH at maturity
• The peg (and hence price value) of eETH vs. ETH at maturity
• Protocol fees
• Gas fees

As the PT holder, you have flexibility in realizing P&L for PT since P&L at maturity is incurred upon redemption of PT. Note that any yields (e.g. eETH yield after 26 Dec 2024) from unredeemed PTs are collected by Pendle.

As maturity approaches, the value of PT-eETH will converges towards eETH, with possible fluctuations before maturity due to yield trades affecting the Implied APY (and thus price of PT-eETH).

Regardless, PT-eETH will equal 1 eETH at maturity.

Yield Token (YT)

On the other end, there’s the Yield Token (YT), which streams all the yield and points from the underlying asset to the holder.

For many, YTs have been the vehicle to obtain leveraged exposure not just to yield but also to “airdrops” via points.

Using the previous example, a user with 12.2 YT-eETH will receive all the yield and points generated by a 12.2 eETH deposit on EtherFi until maturity (26 December 2024), at the cost of 0.1 ETH. This essentially means that YT-eETH is providing a “12.2x leveraged exposure” to eETH’s yield and points.

The intrinsic value of YT is tied to how much yield and points it can generate, which means that at maturity, YT will have fully decayed to $0.

At maturity:

If Yield + Airdrops Received > Cost of YT → Profit
If Yield + Airdrops Received < Cost of YT → Loss

Note that “airdrops,” unlike yield, do not always align with YT’s maturity. Moreover, if a user has conducted multiple actions qualifying for an airdrop, it can be challenging to attribute the exact amount of airdrop value to YT.

Liquidity Provision (LP)

Pendle’s AMM comprises PT and SY (a wrapped version of the underlying asset).

A user with an LP position in eETH (26 December 2024) holds a balance of:

• SY-eETH
• PT-eETH

Yield Breakdown for Pendle LP in eETH (26 Dec 2024)

SY-eETH:
    • Yield from eETH
    • Points (and hence airdrops) earned via eETH

PT-eETH:
    • Fixed APY

Pendle LP:
    • Swap fees generated from yield trades in the pool
    • PENDLE incentives/rewards

Similar to other LP positions in DeFi, the balance of PT-eETH and SY-eETH may change due to swaps happening in the pool.

At maturity, all PT-eETH in the position can be redeemed for eETH, meaning that unlike other AMMs, Pendle LPs will not be subject to impermanent loss if the position is held to maturity.

PnL Calculation Model for LP (Added)

To calculate the PnL for LP positions, we use the following model.

Let:

A: The underlying token (e.g., eETH)
B: The yield-bearing token (e.g., SY-weETH)

C: The Principal Token (PT)
D: The LP token representing the LP position in the pool of SY (B) and PT (C)

At times T₀ and T₁, the prices are:

At T₀:
• Price of A: P_A
• Price of B: P_B = x₀ * P_A = y₀ * P_C
At T₁:
• Price of A: P_A’
• Price of B: P_B’ = x₁ * P_A’ = y₁ * P_C’

At T₀, 1 unit of LP token D corresponds to:

a₀ units of B
b₀ units of C

At T₁, 1 unit of LP token D corresponds to:

a₁ units of B
b₁ units of C

The profit for holding 1 unit of LP token D is:

Profit = P_D' - P_D = (a₁ * P_B' + b₁ * P_C') - (a₀ * P_B + b₀ * P_C)
= [ (a₁ - a₀) + ( (b₁ / y₁) - (b₀ / y₀) ) ] * P_B'
+ ( a₀ + b₀ / y₀ ) * x₀ * (P_A' - P_A)
+ ( a₀ + b₀ / y₀ ) * ( x₁ - x₀ ) * P_A'

Where:

Cash Balance PnL:

CashBalancePnL = ( a₀ + b₀ / y₀ ) * x₀ * (P_A' - P_A)

Staking Yield:

StakingYield = ( a₀ + b₀ / y₀ ) * ( x₁ - x₀ ) * P_A'

LP Reward:

LPReward = [ (a₁ - a₀) + ( (b₁ / y₁) - (b₀ / y₀) ) ] * P_B'

This model breaks down the profit into components due to changes in token balances within the LP position, price changes of the underlying asset, and staking yields.

It’s also worth noting that all Pendle positions (PT, YT, and LP) can be sold or withdrawn anytime before maturity, allowing P&L to be realized even before maturity (e.g., selling YT at a higher price while keeping the yield and points collected).

Conclusion

DeFi yield farming offers lucrative opportunities but brings challenges in reconciliation and PnL calculation due to the complex nature of protocols like Pendle. Pendle introduces innovative yield strategies through its Principal Tokens (PT) and Yield Tokens (YT), allowing users to engage in fixed and variable yield investments.

1Token addresses these operational challenges by providing tools that synchronize blockchain data, automate balance reconciliation, and accurately calculate PnL. By integrating with Pendle, 1Token enables investors to manage their yield farming activities effectively, ensuring precise financial reporting.

Combining Pendle’s advanced yield tokenization with 1Token’s comprehensive DeFi solutions empowers investors to navigate the DeFi landscape efficiently. This synergy maximizes returns while simplifying the complexities of DeFi operations, allowing investors to focus on strategic decision-making.

What does Pendle do

Pendle is a decentralized protocol that enables the tokenization and trading of future yield. As a yield derivative protocol, they are bringing the TradFi interest derivative market (worth over $500T in notional value) into DeFi, making it accessible to all. Pendle helps unlock the full potential of yield, enabling users to execute advanced yield strategies such as fixed yield and long yield. 

Website: https://www.pendle.finance/

Twitter: @pendle_fi

Telegram: Pendle Finance Official

What does 1Token do

1Token provides Portfolio/Risk/Operations/Accounting Management Systems for Crypto Funds/FoFs/Asset Managers, Lending Institutions/DMA Prime Brokers, and Fund Admins/Auditors serving crypto funds. 1Token keeps up-to-date integration to major crypto trading venues that covers complete instruments and transaction types.

Venue integration includes CeFi exchanges, OTC brokers, custody and OEMS, and DeFi EVM and non-EVM chains and protocols. (see integration list)

Asset coverage includes spot, perps, futures, options and earn products on CeFi, and DeFi yield farming activities like staking, AMM, borrow, lending and derivatives.

https://1token.tech/connectivity

Source

https://app.safe.global/balances?safe=arb1:0xFC7E45A3e96E682Ca43D60b456A8cD83dB0cE606

https://debank.com/profile/0xFC7E45A3e96E682Ca43D60b456A8cD83dB0cE606

https://arbiscan.io/address/0xfc7e45a3e96e682ca43d60b456a8cd83db0ce606