DeFindex Docs
  • DeFindex Protocol
    • Welcome
    • What is DeFindex?
  • Getting Started
    • How DeFindex Works
    • Creating a DeFindex Vault
    • Mainnet Deployment
  • Whitepaper
    • Whitepaper
      • Introduction
        • Core Concepts
      • The DeFindex Approach
        • Design Decisions
      • Smart Contracts
        • DeFindex Vault
        • DeFindex Strategy
        • DeFindex Zapper
      • Strategy Examples
      • State of the Art
        • Yearn Finance
      • Appendix
        • Why Not Swap in Deposit
  • WALLET DEVELOPER
    • Flutter SDK
    • Typescript SDK
    • Vault APY
  • STRATEGIES
    • What is a strategy?
    • What is Blend Capital?
    • Strategies APY
  • Users
    • About Us
    • General/FAQ
      • Additional Resources
  • Security
    • Security Audit
Powered by GitBook
On this page
  • Example Scenario
  • Fixed Price Per Share Approach
  • Calculating Price Per Share (PPS):
Edit on GitHub
  1. Whitepaper
  2. Whitepaper
  3. Appendix

Why Not Swap in Deposit

When depositing (or investing) in DeFindex, a user receives dfTokens, which represent their share of the DeFindex portfolio. These tokens are minted based on the amount of assets deposited and the current price per share (denoted as $p_{ps}$). Later, the user can burn these tokens to withdraw their assets.

The challenge arises when calculating this price per share.

Example Scenario

Consider a DeFindex with a single strategy: 100% allocation to XLM on Xycloans, while the DeFindex receives deposits in USDC. The price per share $p_{ps}$ could be calculated as the amount of USDC one receives after withdrawing from Xycloans and swapping the XLM to USDC, divided by the total supply of dfTokens:

pps(m)=TdfTokenspXLM(m)⋅MXLMp_{ps}(m) = \frac{T_{dfTokens}}{p_{XLM}(m) \cdot M_{XLM}}pps​(m)=pXLM​(m)⋅MXLM​TdfTokens​​

Where:

  • $p_{XLM}(m)$ is the price of XLM in terms of USDC after liquidating $m$ XLM.

  • $M_{XLM}$ is the total amount of XLM held by the DeFindex.

  • $T_{dfTokens}$ is the total supply of dfTokens.

The problem is that the price of XLM $p_{XLM}(m)$ will depend on the amount of XLM we need to withdraw. This price can be manipulated by a large swap. For instance, someone could swap a large amount of USDC for XLM, artificially inflating the price of XLM. As a result, the price per share would increase, allowing the user to receive more USDC when burning their dfTokens.

Fixed Price Per Share Approach

Given the manipulation risk with a variable price per share, let's consider using a fixed price per share.

Assume $p_0$ is the nominal (initial or fixed) price of XLM in USDC. The amount of USDC received by a user who swaps $m_{XLM}$ XLM for USDC will be:

mUSDC=pXLM(mXLM)⋅mXLMm_{USDC} = p_{XLM}(m_{XLM}) \cdot m_{XLM}mUSDC​=pXLM​(mXLM​)⋅mXLM​

The price per share would then be:

pps=p0⋅MXLMTdfTokensp_{ps} = \frac{p_0 \cdot M_{XLM}}{T_{dfTokens}}pps​=TdfTokens​p0​⋅MXLM​​

After burning $m_{dfTokens}$ dfTokens, the user should receive:

mUSDC=pps⋅mdfTokens=p0⋅MXLM⋅mdfTokensTdfTokensm_{USDC} = p_{ps} \cdot m_{dfTokens} = \frac{p_0 \cdot M_{XLM} \cdot m_{dfTokens}}{T_{dfTokens}}mUSDC​=pps​⋅mdfTokens​=TdfTokens​p0​⋅MXLM​⋅mdfTokens​​

Where:

  • $m_{XLM}$ is the amount of XLM the DeFindex needs to liquidate to pay the user.

  • $m_{dfTokens}$ is the amount of dfTokens the user is burning to withdraw their share.

The amount of XLM to be liquidated, $m_{XLM}$, is given by:

mXLM=MXLM⋅mdfTokensTdfTokensm_{XLM} = M_{XLM} \cdot \frac{m_{dfTokens}}{T_{dfTokens}}mXLM​=MXLM​⋅TdfTokens​mdfTokens​​

The USDC received after the swap, denoted as ( m_{USDCout} ), would be:

mUSDCout=pXLM(mXLM)⋅mXLM=pXLM(mXLM)⋅MXLM⋅mdfTokensTdfTokensm_{USDCout} = p_{XLM}(m_{XLM}) \cdot m_{XLM} = p_{XLM}(m_{XLM}) \cdot M_{XLM} \cdot \frac{m_{dfTokens}}{T_{dfTokens}}mUSDCout​=pXLM​(mXLM​)⋅mXLM​=pXLM​(mXLM​)⋅MXLM​⋅TdfTokens​mdfTokens​​

Since ( p_0 ) is the nominal price and ( p_{XLM}(m_{XLM}) ) is the actual price after liquidation, we have:

pXLM(mXLM)<p0∀ mXLM>0p_{XLM}(m_{XLM}) < p_0 \quad \forall \, m_{XLM} > 0pXLM​(mXLM​)<p0​∀mXLM​>0

Thus, we have:

pXLM(mXLM)⋅MXLM⋅mdfTokensTdfTokens<p0⋅MXLM⋅mdfTokensTdfTokensp_{XLM}(m_{XLM}) \cdot M_{XLM} \cdot \frac{m_{dfTokens}}{T_{dfTokens}} < p_0 \cdot M_{XLM} \cdot \frac{m_{dfTokens}}{T_{dfTokens}}pXLM​(mXLM​)⋅MXLM​⋅TdfTokens​mdfTokens​​<p0​⋅MXLM​⋅TdfTokens​mdfTokens​​

In summary:

mUSDCout<mUSDCm_{USDCout} < m_{USDC}mUSDCout​<mUSDC​

This inequality shows that the user would request more USDC than what they can actually receive after the swap. This discrepancy leads to a potential loss of funds for DeFindex, highlighting why we can't rely on swapping assets during the deposit process.

We can argue that when using any fixed price per share, the amount of USDC received after a swap, denoted as $m_{USDCout}$, will differ from the expected amount $m_{USDC}$. This discrepancy introduces a vulnerability, making the protocol susceptible to manipulation.

Calculating Price Per Share (PPS):

The PPS is a crucial metric for ensuring users receive the correct value for their dfTokens. It is calculated as follows:

PPS=Total AssetsTotal Supply of dfTokensPPS = \frac{\text{Total Assets}}{\text{Total Supply of } dfTokens}PPS=Total Supply of dfTokensTotal Assets​

Where:

  • Total Assets: The sum of the value of assets managed by all adapters plus any idle assets held directly by the DeFindex contract.

  • Total Supply of dfTokens: The total number of dfTokens issued to users.

To illustrate, consider the following scenario:

  • DeFindex has three adapters managing different investments:

    • Adapter A manages $50,000 in a liquidity pool.

    • Adapter B manages $30,000 in a lending pool.

    • Adapter C manages $20,000 in a staking protocol.

  • The DeFindex contract holds an additional $10,000 in idle assets.

The Total Assets would be:

50,000+30,000+20,000+10,000=110,000 USDC50,000 + 30,000 + 20,000 + 10,000 = 110,000 \text{ USDC} 50,000+30,000+20,000+10,000=110,000 USDC

If the Total Supply of dfTokens is 100,000, the PPS would be:

PPS=110, ⁣000 USDC100, ⁣000 dfTokens=1.1 USDC/dfTokenPPS = \frac{110,\!000 \ \text{USDC}}{100,\!000 \ \text{dfTokens}} = 1.1 \ \text{USDC/dfToken}PPS=100,000 dfTokens110,000 USDC​=1.1 USDC/dfToken

This calculation ensures users can accurately determine the value of their holdings in DeFindex, promoting transparency and trust.

PreviousAppendixNextFlutter SDK

Last updated 17 days ago

Page cover image