Fathom Protocol
  • Introduction
  • FXD Stablecoin
    • FXD Smart Contract Architecture
    • Minting and Burning Mechanisms with LTV Ratio
    • Soft-Pegging to the US Dollar
    • Opening and closing position flows
    • BookKeeping mechanism
      • Stablecoin Accounting
      • Collateral Accounting
    • Liquidation
      • Fixed Spread Liquidation Strategy
      • Liquidation process walk through
    • Emergency Shutdown
    • Maths for position safety
    • Fee structure
    • Risk Management
    • Interfaces
      • ProxyWalletRegistry
      • ProxyWallet
        • FathomStablecoinProxyActions
      • CollateralPoolConfig
      • BookKeeper
      • FXD
      • LiquidationEngine
      • FlashMintModule
      • PriceFeed
      • ShowStopper
      • StabilityFeeCollector
      • SystemDebtEngine
      • AdminControls
    • Deployments
      • XDC Network
    • User Guides
      • Open FXD position
      • Top Up FXD Position
      • Repay and close FXD position
    • Fathom Stablecoin Smart Contracts
    • Fathom Stablecoin Subgraph
  • Vaults
    • Key Features
    • Definitions
    • Architecture
    • Fees
    • Workflows
    • Vault Management
    • Strategy Creation
    • Interfaces
      • Factory
      • Vault
      • BaseStrategy
      • TokenizedStrategy
    • Deployments
      • XDC Network
    • User Guides
      • Deposit and Withdraw in Vault
    • Fathom Vaults Smart Contracts
    • Fathom Vaults Subgraph
  • Lending
    • Core Concepts
    • Protocol Mechanics
    • Architecture
    • Interfaces
      • FmToken
      • VariableDebtToken
      • StableDebtToken
      • L2Pool
      • PoolAddressesProvider
    • User Guides
      • Supply, Borrow, Repay and Withdraw Asset
    • Deployments
      • XDC Network
    • Fathom Lending Smart Contracts
    • Fathom Lending Subgraph
  • DEX
    • Core Concepts
    • Architecture
    • Interfaces
      • Factory
      • Pair
      • Router
    • User Guides
      • Providing Liquidity
      • Swapping Assets
    • Deployments
      • XDC Network
    • Fathom DEX Smart Contracts
    • Fathom DEX Subgraph
  • DAO
    • DAO Structure
    • Governance Process
    • Staking Process
    • Treasury Management
    • Risk Management and Security Measures
    • Contributing to Fathom DAO
    • Interfaces
      • FTHM
      • Staking
        • Vault
        • RewardsCalculator
        • vFTHM
      • Governance
        • TimelockController
    • Deployments
      • XDC Network
    • User Guides
      • Staking
      • Proposing
      • Voting
    • Fathom DAO Smart Contracts
    • Fathom DAO Subgraph
  • Whitepaper
    • Version 1.0
  • Resources
  • FXD Deployments
  • FTHM Deployments
  • Privacy Policy
  • Terms of Service
Powered by GitBook

Copyright© Fathom App 2024.

On this page

Was this helpful?

Export as PDF
  1. FXD Stablecoin
  2. Interfaces

FlashMintModule

https://github.com/Into-the-Fathom/fathom-stablecoin-smart-contracts/blob/master/contracts/main/flash-mint/FlashMintModule.sol

The FlashMintModule contract facilitates the issuance of flash loans within the protocol. This contract allows borrowing a specified amount of stablecoins, executing arbitrary operations, and repaying the loan within a single transaction. It adheres to the ERC-3156 standard for flash loans.

Storage Variables

  • bookKeeper (IBookKeeper):

    • This variable stores the address of the BookKeeper contract, which is used for managing accounting and collateral within the system. It interacts with the bookkeeping functionalities to record transactions related to flash loans.

  • stablecoinAdapter (IStablecoinAdapter):

    • This variable holds the address of the StablecoinAdapter contract. The adapter is used to interact with the stablecoin in a manner consistent with the internal accounting system, such as depositing or withdrawing stablecoin for flash loans.

  • stablecoin (IStablecoin):

    • This variable represents the ERC20 stablecoin used for flash loans. It facilitates operations such as minting, transferring, and burning the stablecoin.

  • systemDebtEngine (address):

    • A crucial contract address for managing the system’s overall debt and fee accrual. It is used primarily to settle fees or bad debt that accrues through flash loan operations.

  • max (uint256):

    • This variable sets the maximum amount of stablecoin that can be borrowed through a single flash loan. It is important for managing liquidity and risk.

  • feeRate (uint256):

    • The fee rate charged for taking out a flash loan. It is expressed as a percentage and calculated over the amount of the loan to generate revenue from flash loan operations.

  • locked (uint256):

    • A reentrancy guard used to prevent reentry into critical functions such as flash loan issuance. This helps protect against certain types of exploits where recursive calls can lead to unintended consequences.

  • flashMintWhitelist (mapping(address => bool)):

    • A whitelist of addresses that are permitted to initiate flash loans. This control mechanism ensures that only approved contracts or addresses can utilize flash loan functionality, which can be essential for maintaining system security.

  • isDecentralizedState (bool):

    • Indicates whether the contract is operating in a decentralized mode. In a decentralized state, the contract might allow a broader set of interactions than when it is in a more controlled state.

Flash Loan Functions

  • flashLoan(IERC3156FlashBorrower _receiver, address _token, uint256 _amount, bytes calldata _data): Executes a flash loan. The _receiver must implement the IERC3156FlashBorrower interface. This function checks the token type, enforces the maximum loan amount, calculates the fee, mints the required stablecoin, sends it to the receiver, and expects repayment within the same transaction.

  • bookKeeperFlashLoan(IBookKeeperFlashBorrower _receiver, uint256 _amount, bytes calldata _data): Similar to flashLoan but interacts with receivers that handle bookkeeping entries directly. It is meant for more integrated system operations, managing loans in terms of the bookkeeping system's RAD units.

Administrative Functions

  • setMax(uint256 _data) and setFeeRate(uint256 _data): Set the maximum loanable amount and the fee rate for loans. The maximum is set in stablecoin units, and the fee rate is a percentage that applies to the borrowed amount.

  • setDecentralizedStatesStatus(bool _status): Toggle the operational mode between a more decentralized setting (where whitelist control might be relaxed) and a more controlled setting.

  • addToWhitelist(address _toBeWhitelisted) and removeFromWhitelist(address _usr): Manage addresses that are allowed to initiate flash loans. This is particularly relevant in a more centralized operational mode to ensure only vetted contracts or addresses can initiate loans.

  • pause() and unpause(): Enable or disable the flash loan operations. This can be critical in situations where the protocol needs to be paused for upgrades or security issues.

Utility Functions

  • convert() and accrue(): Handle internal conversions and accounting adjustments. convert() can be used to convert balance discrepancies into the bookkeeping system, while accrue() moves accrued fees to the system debt engine.

  • refreshApproval(): Refresh the approval of the stablecoin to the maximum value for the stablecoin adapter, ensuring that the contract can always interact with the stablecoin as expected.

Events

  • LogSetMax(uint256 _data), LogSetFeeRate(uint256 _data), and LogFlashLoan(address indexed _receiver, address indexed _token, uint256 _amount, uint256 _fee): Log significant actions and state changes within the contract, providing transparency over flash loan parameters and administrative adjustments.

  • LogDecentralizedStateStatus(bool _oldDecentralizedStateStatus, bool _newDecentralizedStateStatus): Tracks changes in the operational mode of the contract, signaling shifts between centralized and decentralized control.

  • LogAddToWhitelist(address indexed _user) and LogRemoveFromWhitelist(address indexed _user): Document changes to the list of addresses authorized to initiate flash loans.

PreviousLiquidationEngineNextPriceFeed

Last updated 11 months ago

Was this helpful?