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
    • Integrations
      • Integrate with a Blend Pool
      • Fee Vault
    • Potential Improvements
Powered by GitBook
On this page
  • How does it work?
  • Take Rate
  • Capped Rate
  • Calculating Rates
Export as PDF
  1. Tech Docs
  2. Integrations

Fee Vault

PreviousIntegrate with a Blend PoolNextPotential Improvements

Last updated 8 days ago

The Fee Vault is a contract that allows an admin to earn fees on funds supplied to Blend pools. The Fee Vault is designed for wallets or other integrating protocols that want to add an additional revenue stream based on their users' activity on Blend.

How does it work?

The Fee Vault works by being an intermediary between the Blend pool and the user. It tracks the interest generated by user deposits and determines what amount of that interest should be taken as a fee for the admin.

Each Fee Vault supports at most one Blend pool, but can support multiple assets (reserves) within the same Blend pool. The admin must enable a vault for each reserve they want to support. Each reserve vault is an -style vault that tracks interest generated by the users and enables the contract to fairly share that interest across all users.

The Fee Vault supports two types of fee modes, take rate and capped rate, and the fee mode and amount can be changed at any time.

Take Rate

In take rate mode, the vault takes a fixed percentage of the interest generated by the user deposits. For example, if the vaults earn 100 USDC in interest and the take rate is 10%, the Fee Vault will take 10 USDC as a fee for the admin, and users will earn 90 USDC.

Capped Rate

In capped rate mode, the vault calculates how much interest should have been earned by the user deposits to reach the capped rate. If the vault generated more interest, the excess is taken as a fee for the admin.

For example, if the vault has a capped rate of 10% and the vault earns 12% (e.g. 120 USDC) over the period, the users will earn 100 USDC and the admin will take 20 USDC as a fee. If the vault only earns 8% (e.g. 80 USDC), the users will earn 80 USDC and the admin will take 0 USDC as a fee.

Calculating Rates

The core math of the vault is how rates and interest earned are calculated. In both fee modes, the vault tracks interest earned between update periods on the vault. That is, if a user interacted with the vault on block 100, and another user interacted with the vault on block 200, the vault will calculate the interest earned between block 100 and block 200, and then calculate the fee based on that interest.

For extremely high frequency interactions, like every block, this can lead to situations where rounding can start to impact fee calculations. The Fee Vault protects against this by rounding against the admin, such that rounding can never impact expected user earnings.

All calculations are done based on the last stored reserve vault, and the reserve's b_rate for the current block. The vault data struct is shown below:

#[contracttype]
pub struct ReserveVault {
    /// The reserve asset address
    pub address: Address,
    /// The reserve's last bRate
    pub b_rate: i128,
    /// The timestamp of the last update
    pub last_update_timestamp: u64,
    /// The total shares issued by the reserve vault
    pub total_shares: i128,
    /// The total bToken deposits owned by the reserve vault depositors. Excludes accrued fees.
    pub total_b_tokens: i128,
    /// The number of bTokens the admin is due
    pub accrued_fees: i128,
}

Variables

R=current_reserve_dataR = current\_reserve\_dataR=current_reserve_data
V=last_vault_dataV = last\_vault\_dataV=last_vault_data

Take Rate Math

ฮ”bRate=bRateRโˆ’bRateV\Delta bRate = bRate_{R} - bRate_{V}ฮ”bRate=bRateRโ€‹โˆ’bRateVโ€‹
interest=bTokensVโˆ—ฮ”bRateinterest = bTokens_{V} * \Delta bRateinterest=bTokensVโ€‹โˆ—ฮ”bRate
adminFees=interestโˆ—takeRateadminFees = interest * takeRateadminFees=interestโˆ—takeRate
bTokenAdminFees=โŒŠadminInterestbRateRโŒ‹bTokenAdminFees = \lfloor\frac{adminInterest}{bRate_{R}}\rfloorbTokenAdminFees=โŒŠbRateRโ€‹adminInterestโ€‹โŒ‹

Capped Rate Math

ฮ”time=currentTimestampโˆ’lastUpdateTimestampV\Delta time = currentTimestamp - lastUpdateTimestamp_{V}ฮ”time=currentTimestampโˆ’lastUpdateTimestampVโ€‹
bRatetarget=(1+โŒˆcappedRateโˆ—ฮ”T31536000โŒ‰)โˆ—bRateVbRate_{target} = (1 + \lceil\frac{cappedRate* \Delta T}{31536000}\rceil) * bRate_{V}bRatetargetโ€‹=(1+โŒˆ31536000cappedRateโˆ—ฮ”Tโ€‹โŒ‰)โˆ—bRateVโ€‹
bTokenAdminFees=max(bRateRโˆ’bRatetarget,0)โˆ—bTokensVbTokenAdminFees = max(bRate_{R} - bRate_{target}, 0) * bTokens_{V}bTokenAdminFees=max(bRateRโ€‹โˆ’bRatetargetโ€‹,0)โˆ—bTokensVโ€‹

Applying bTokenAdminFees

The bTokenAdminFees is the amount of bTokens that the admin is due from the vault. To apply this, the vault deducts the bTokenAdminFees from the total_b_tokens of the vault, adds it to the accrued_fees of the vault, and sets the last_update_timestamp to the current block timestamp.

๐Ÿ“š
Github Link
ERC4626
GitHub Link