LogoLogo
  • Blend v2 Documentation
  • ๐Ÿ“„Blend Whitepaper
  • ๐ŸงชMedia Kit
  • ๐Ÿš€Deployments
  • ๐Ÿ•ต๏ธโ€โ™‚๏ธAudits & Bug Bounties
  • ๐Ÿง‘โ€๐ŸญGithub
  • v1 Docs
  • ๐Ÿ‘ฅUsers
    • General/FAQ
    • Choosing Pools
    • Lending-Borrowing
      • Lending
      • Borrowing
      • Liquidations
    • Backstopping
    • BLND Token
    • Auctions
  • Emissions
  • ๐ŸŒŠPool Creators
    • General
    • Tutorial: Setting Up a Pool
    • Adding Assets
      • Risk Parameters
      • Interest Rates
      • Emissions
    • Pool Management
    • Selecting an Oracle
    • Setting Backstop Take Rate
    • Setting Max Positions
    • Backstop Bootstrapping
    • Required Infrastructure
  • ๐Ÿ“šTech Docs
    • General
    • Core Contracts
      • Emitter
        • Backstop Management
        • Blend Distribution
      • Backstop
        • Deposit Management
        • Drawing and Donating
        • Emission Distribution
      • Pool Factory
        • Lending Pool Deployment
      • Lending Pool
        • Fund Management
        • Liquidation Management
        • Emission Management
        • Interest Management
        • Pool Management
        • Bad Debt Management
        • Protocol Tokens
    • Guides
      • Deploying a Pool
    • Potential Improvements
Powered by GitBook
On this page
  • Storing User Backstop Deposits
  • Deposits
  • Withdrawals
Export as PDF
  1. Tech Docs
  2. Core Contracts
  3. Backstop

Deposit Management

The Backstop contract allows users to deposit backstop tokens and allocate them towards different pools.

Storing User Backstop Deposits

Users backstop deposits are allocated to individual pools. Their deposits are stored by the Backstop contract in a hashmap where the key is a PoolUserKey struct

pub struct PoolUserKey {
    pool: Address, // Pool Contract Address
    user: Address, // User Account Address
}

and the value is a UserBalance struct

pub struct UserBalance {
    pub shares: i128,  // the balance of shares the user owns
    pub q4w: Vec<Q4W>, // a list of queued withdrawals
}

Deposits

Users deposit backstop tokens into the backstop contract using the deposit() function which accepts a deposit amount and a pool address. The specified amount will be sent to the backstop contract, and recorded as a user's deposit in the specified pool. The deposit amount is accounted for as a number of shares, calculated as:

SharesIssued=DepositAmountโˆ—TotalSharesTotalTokensSharesIssued = DepositAmount * \frac{TotalShares}{TotalTokens}SharesIssued=DepositAmountโˆ—TotalTokensTotalSharesโ€‹

The number of backstop tokens each share is worth fluctuates based on the behavior of the pool the deposit is allocated to

  • Share value increases when the associated pool pays interest to the backstop as this increases the pool's total_tokens

  • Share value decreases when deposits are used to cover bad debt as this decreases the pool's total_tokens

Once the deposit is finalized the pool's total_tokens will be increased by the deposit amount and the pool's total_shares will be increased by the number of shares issued.

deposit() calls will fail if the user attempts to deposit into a pool not listed as a deployed_pool by the designated Pool Factory contract

Withdrawals

Backstop withdrawals are handled in two steps.

  1. The user calls queue_withdrawal with the amount they wish to withdraw and the pool they wish to withdraw from. This will queue a withdrawal for the specified amount of tokens from the specified pool.

While deposits are queued for withdrawal the user will no longer receive emissions from the backstop. They will still receive their share of interest from the pool.

  1. User waits for the 17-day withdrawal queue to expire

At any point, the user can cancel a queued withdrawal using the cancel_withdrawal() function.

A withdrawal queue is required to prevent backstop depositors from leaving a pool before their backstop deposits can be used to cover bad debt.

  1. User calls withdraw() to withdraw the shares. This will transfer the tokens to the user and reduce the pool total_tokens and total_shares accordingly.

    1. Tokens received are calculated as:

TokensReceived=SharesWithdrwawnโˆ—TotalTokensTotalSharesTokensReceived = SharesWithdrwawn * \frac{TotalTokens}{TotalShares}TokensReceived=SharesWithdrwawnโˆ—TotalSharesTotalTokensโ€‹

PreviousBackstopNextDrawing and Donating

Last updated 2 months ago

๐Ÿ“š