BloomPool.sol

Overview

The BloomPool contract is a decentralized application built on the Ethereum blockchain. It's a lending platform that takes in deposits from both lenders and borrowers, with the main functionality driven by a state machine.

Key Features

  • Commitment processing for both borrowers and lenders.

  • Integration with external components like Whitelist, SwapFacility and BPSFeed.

  • State transitions and time-bound operations.

  • Handles swaps between two tokens using SwapFacility.

Libraries and Interfaces

  • ERC20.sol: Used for handling operations related to ERC20 tokens.

  • IBloomPool.sol: Interface to define methods for the BloomPool contract.

  • ISwapRecipient.sol: Interface that defines methods for a contract that can receive tokens as a result of a swap operation.

  • SafeTransferLib.sol: Used for safe token transfers, reverts transaction if the transfer fails.

  • SafeCastLib.sol: Used for safe casting of integer types, prevents overflows.

  • FixedPointMathLib.sol: Provides mathematical functions for fixed-point arithmetic.

  • CommitmentsLib.sol: Provides functions to handle commitments of borrowers and lenders.

  • IWhitelist.sol: Interface that defines methods for whitelist checking of an address.

  • ISwapFacility.sol: Interface that defines methods for swapping tokens.

  • IBPSFeed.sol: Interface that defines methods to get the Basis Point feed.

Core Parameters

The constructor of the contract sets the immutable state variables that determine the behavior of the contract:

  • UNDERLYING_TOKEN: ERC20 token that is being deposited by lenders and borrowers.

  • BILL_TOKEN: Token to be received as a result of swap operations.

  • WHITELIST: Contract for checking if an address is whitelisted.

  • SWAP_FACILITY: Contract for handling swap operations.

  • TREASURY: Address of the treasury where the fees are sent.

  • LENDER_RETURN_BPS_FEED: Contract for getting the Basis Point feed for lender returns.

  • EMERGENCY_HANDLER: Address that can handle emergency situations.

  • LEVERAGE_BPS: The leverage rate in Basis Points.

  • MIN_BORROW_DEPOSIT: Minimum deposit required from a borrower.

  • COMMIT_PHASE_END: Block timestamp marking the end of the commit phase.

  • PRE_HOLD_SWAP_TIMEOUT_END: Block timestamp marking the end of pre-hold swap timeout.

  • POOL_PHASE_END: Block timestamp marking the end of the pool phase.

  • POOL_PHASE_DURATION: Duration of the pool phase.

  • LENDER_RETURN_FEE: Fee that a lender must pay.

  • BORROWER_RETURN_FEE: Fee that a borrower must pay.

Modifiers

  • onlyState(State expectedState): Allows function execution only if the current state of the contract is the expected state.

  • onlyAfterState(State lastInvalidState): Allows function execution only if the current state of the contract is after the last invalid state.

Functions

This section provides a brief overview of the key functions available in the contract:

  • depositBorrower: Allows a whitelisted borrower to deposit a specified amount of the underlying token.

  • depositLender: Allows a lender to deposit a specified amount of the underlying token.

  • processBorrowerCommit: Processes the commitment of a borrower, splits the committed amount based on the leverage ratio, and returns the excluded amount to the borrower.

  • processLenderCommit: Processes the commitment of a lender, splits the committed amount based on the leverage ratio, transfers the excluded amount back to the lender, and mints equivalent pool tokens.

  • initiatePreHoldSwap: Initiates the swap operation from the underlying token to the bill token.

  • initiatePostHoldSwap: Initiates the swap operation from the bill token back to the underlying token.

  • completeSwap: Completes the swap operation, should be called by the ISwapFacility contract after a swap is successfully executed.

  • emergencyHandlerCall: Allows the designated emergency handler to intervene and transfer assets from the pool in emergency situations.

Events

  • BorrowerCommit: Emitted when a borrower commits some amount to the pool.

  • LenderCommit: Emitted when a lender commits some amount to the pool.

  • BorrowerCommitmentProcessed: Emitted when a borrower's commitment is processed.

  • LenderCommitmentProcessed: Emitted when a lender's commitment is processed.

  • ExplictStateTransition: Emitted when a state transition is triggered explicitly.

  • SwapComplete: Emitted when a swap operation is successfully completed.

  • EmergencyHandlerCall: Emitted when the emergency handler intervenes.

State Transitions

The contract maintains different states that it transitions through, governed by the time-bound phases and operations. The states include Commit, ReadyPreHoldSwap, PendingPreHoldSwap, Hold, ReadyPostHoldSwap, PendingPostHoldSwap, ReadyToWithdraw, and Emergency.

Last updated