Skip to content

Pool Accounting

Lucas Manuel edited this page Apr 7, 2021 · 7 revisions

In the Maple protocol, financial accounting of Pools must be done using a combination of ERC-20 balances and state variable accounting. The reason for this is that for a given Pool, a significant portion of the capital that is managed in the Pool is not actually held within the LiquidityLocker, where it can be actively withdrawn by Liquidity Providers.

In order to maintain consistency between the total value of a Pool and the total claimable funds by Liquidity Providers, the following invariant must be satisfied:

liquidityLockerBal + principalOut = fdtTotalSupply + interestSum - poolLosses

The left side of the equation represents actual ERC-20 balances (using USDC as an example):

  • liquidityLockerBal is the current balance of USDC in the LiquidityLocker.
  • principalOut is the total amount of USDC that has been moved out of the LiquidityLocker to fund active Loans.

The right side of the equation represents the accounting used to account for LP claimable funds

  • fdtTotalSupply is equal to the net amount of deposits/withdrawals of USDC that have made by LPs.
  • interestSum is the sum of all interest that has been claimed by the Pool since instantiation.
  • poolLosses is the sum of all losses incurred by the Pool since instantiation. This value is only incremented when a Loan defaults, the maximum of BPTs have been burned, and there is still a shortfall. This concept is covered in more depth on this page.

Below is an example of how this accounting works for interest payments and BPT shortfalls:

/**********************************************************/
/*** Starting State (LPs have added 1000 USDC of funds) ***/
/**********************************************************/

liquidityLockerBal = 1000
principalOut       = 0

fdtTotalSupply = 1000
interestSum    = 0
poolLosses     = 0

Invariant: 1000 + 0 = 1000 + 0 - 0 

/**************************************/
/*** Pool Funds a Loan for 500 USDC ***/
/**************************************/

liquidityLockerBal = 500
principalOut       = 500

fdtTotalSupply = 1000
interestSum    = 0
poolLosses     = 0

Invariant: 500 + 500 = 1000 + 0 - 0 

/*****************************************************/
/*** Borrower Makes an Interest Payment of 50 USDC ***/
/*****************************************************/

liquidityLockerBal = 550
principalOut       = 500

fdtTotalSupply = 1000
interestSum    = 50
poolLosses     = 0

Invariant: 550 + 500 = 1000 + 50 - 0 

/*******************************************/
/*** Borrower Gets Liquidated            ***/
/*** 100 USDC is recovered               ***/
/*** 200 USDC of BPTs are burned         ***/
/*** 200 USDC of losses are moved to LPs ***/
/*******************************************/

liquidityLockerBal = 550 + 100 + 200
                   = 850
principalOut       = 500 - 500
                   = 0

fdtTotalSupply = 1000
interestSum    = 50
poolLosses     = 200

Invariant: 850 + 0 = 1000 + 50 - 200