Tarot Deep Dive: Part Two

We continue to explore the core protocol mechanics which power leveraged yield farming.

6 min readJul 23, 2021

A keen relationship between esoteric knowledge systems is formed, and perspective is expressed with clarity. Deep insight is achieved.

Tarot is a decentralized lending protocol for liquidity provider (LPs) to leverage their LP tokens for enhanced yield farming and staking rewards.

In this article, we take a look at the nuances of pricing LP tokens with the Tarot Price Oracle, Tarot Vault-enabled lending pools, and the liquidation mechanics that ensure stability of the Tarot Protocol.

Tarot Deep Dive: Part One can be found here.

Pricing LP Tokens

In order to determine how much collateral is necessary for borrowing and ensure borrowers can’t borrow more than the value of their collateral, the Tarot Protocol uses the Tarot Price Oracle to reliably calculate the value of LP tokens.

The marginal price of an LP token can be computed by dividing the total value of the reserves in the token pair by the total supply of LP tokens:

However, this price shouldn’t be used as-is for an on-chain price oracle, since it is trivial to manipulate.

Suppose a vulnerable contract uses this LP token price to determine the collateral needed for loans. An attacker who wishes to manipulate the LP token price can take out a flash loan to provide liquidity for the underlying token pair and receive LP tokens, then swap the remainder of the flash loan in the same token pair to skew the reserve quantities. This leads to an inflated LP token price.

The attacker could then use the LP tokens as overpriced collateral to borrow tokens from the vulnerable contract, swap back to the token pair to trade it back to the true price, and repay the flash loan in an atomic transaction, keeping any remaining borrowed tokens and allowing the vulnerable, undercollateralized loan to default.

Instead of using the marginal price, Tarot calculates the LP token price by combining the secure, time-weighted average price oracle for the underlying tokens with adjusted reserve quantities to determine the collateral needed for loans in a way that’s fair and resistant to manipulation.

First, Tarot calculates an adjustment factor, A, based on the time-weighted average price (TWAP) and the current price for the underlying tokens:


Next, Tarot determines the current (unadjusted) prices of the underlying tokens, in units of LP token:

Finally, Tarot uses the adjustment factor to derive the adjusted prices of the underlying tokens, in units of LP token, and then determine the collateral needed for a loan:

The collateral needed, C, for a loan is based on the amount of tokens borrowed, as well as the liquidation fee (l) and safety margin (m) parameters:

The liquidation fee and safety margin parameters work to ensure that even after a volatile price swing in the underlying tokens, there will always be enough collateral to both repay the loan and pay a liquidator in the event of liquidation.

Crucially, the collateral needed for a loan is based on the adjusted reserve quantities, a figure analogous to the time-weighted average prices for the underlying tokens.

More information on pricing LP tokens can be found here and here.

Tarot Vault

Many popular DEXs offer farming programs to incentivize liquidity for particular token pairs. Liquidity providers who farm their LP tokens earn additional rewards beyond transaction fees.

Users who deposit LP tokens as collateral in Tarot Vault compatible lending pools earn farming rewards, which are compounded automatically as additional collateral. A user’s deposited LP token collateral balance will grow over time as rewards from the farm are reinvested.

The compounding process for Tarot Vaults is permissionless — it can be invoked by anyone. The Tarot Protocol incentivizes this by offering a bounty (1% of the pending reward) for anyone who triggers reinvestment for a Tarot Vault pool. The reinvest action harvests all pending rewards from the DEX’s farm, converts the harvested reward into additional LP tokens for the pool, and adds those LP tokens as additional collateral in Tarot.

Liquidation Incentive

Nearly every decentralized lending protocol relies on timely and swift liquidations to ensure the stability of loans. If a borrower’s loan isn’t sufficiently collateralized, relative to the borrowed amount, the protocol typically sells some of the underlying collateral and repays the loan.

Tarot offers an incentive to liquidators in exchange for liquidating, or buying out, at-risk loans. Anyone can be liquidator as long as they provide the necessary tokens to repay the loan. In return, they receive a percentage of the borrowed amount, deducted from the borrower’s initial collateral. After liquidation, the borrower receives the remaining initial collateral.

This process ensures borrowers keep their positions sufficiently collateralized to avoid penalization.

Flash Liquidation

Tarot allows flash liquidations, making the liquidation process as seamless as possible. Anyone can borrow the amount of tokens needed to liquidate a position and repay the borrowed amount, all in the same atomic transaction.

When a liquidator wants to liquidate a loan, the Tarot Protocol optimistically sends tokens to the liquidator and checks that the loan is repaid at the end of the transaction.

Consider the following transaction to liquidate a loan:

  1. A liquidator initiates the liquidation for a specific loan, indicating the borrower and the amount of the loan to be repaid.
  2. Tarot optimistically sends LP tokens through the flash liquidation mechanism and executes the callback contract to remove liquidity from the DEX for the amount of underlying tokens needed to repay the loan. This calculation includes the liquidation incentive.
  3. The liquidator repays the loans and keeps any remaining tokens.
  4. Once the callback is completed, Tarot checks that the liquidator repaid the loan by the amount initially indicated. If not, the entire transaction reverts.
  5. The borrower keeps any remaining initial collateral after the loan is repaid and the liquidation incentive is deducted.

At the end of this transaction, the loan is repaid and the liquidator will keep any remaining tokens, as a liquidation incentive, for performing the liquidation.

The core mechanics of Tarot ensure a stable decentralized lending protocol for borrowers and lenders.

Join us to discover DeFi’s most advanced leveraged yield farming experience:




Tarot is a multi-chain decentralized lending protocol.