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
  • poolStablecoinIssued
  • totalStablecoinIssued

Was this helpful?

Export as PDF
  1. FXD Stablecoin
  2. BookKeeping mechanism

Stablecoin Accounting

This section provides a deep understanding of how the accounting of issued stablecoin is done in the BookKeeper contract.

PreviousBookKeeping mechanismNextCollateral Accounting

Last updated 11 months ago

Was this helpful?


totalStablecoinIssued=poolStablecoinIssued+totalUnbackedStablecointotalStablecoinIssued = poolStablecoinIssued + totalUnbackedStablecointotalStablecoinIssued=poolStablecoinIssued+totalUnbackedStablecoin

The formula mentioned above is used in all the functions that manipulate the totalStablecoinIssued and poolStablecoinIssued variables. If the value on the right-hand side of the equation changes, the value on the left side must be changed exactly the same way.

Now, let's delve deeper into the functions that manipulate the poolStablecoinIssued and totalStablecoinIssued variables. We will see how the above mentioned equation affects each function, starting with poolStablecoinIssued.

The variable poolStablecoinIssued is stored in the BookKeeper contract. Three functions manipulate poolStablecoinIssued.

This function manipulates both poolStablecoinIssued and totalStablecoinIssued.

The adjustPosition function changes the lockedCollateral and debtShare values mapped to each position. When the debtShare in a position decreases, poolStablecoinIssued also decreases. Conversely, when the debtShare in a position increases, the value of poolStablecoinIssued increases. It calculates the amount by which the debt value in a position has increased or decreased and adjusts the poolStablecoinIssued value accordingly. The adjustPosition function also manipulates the totalStablecoinIssued variable.

For example:

If debtShare in position, which is of collateral XYZ, decreases by 10, then

  • poolStablecoinissued[XYZ] decreases by 10*debtAccumulatedRate

  • totalStablecoinIssued decreases by 10*debtAccumulatedRate

This function manipulates both poolStablecoinIssued and totalUnbackedStablecoin but not totalStablecoinIssued.

The confiscatePosition function removes collateral and debt from a position and transfers them to addresses specified in the function arguments. During this process, the pool-specific balance is deducted. The amount of debt deducted from poolStablecoinIssued results in an increase in both the systemBadDebt[_stablecoinDebtor] and totalUnbackedStablecoin.

However, the totalStablecoinIssued is unaffected because it is the sum of all poolStablecoinIssued values and totalUnbackedStablecoin. The confiscatePosition function essentially transfers values from poolStablecoinIssued to totalUnbackedStablecoin, ensuring that the totalStablecoinIssued remains unchanged.

What the confiscatePosition function does is transition from equation A to equation B.

Equation A

Equation B

When α represents the amount of debt transferred from poolStablecoinIssued tot unbackedStablecoin by confiscatePosition function.

This function manipulates both poolStablecoinIssued and totalStablecoinIssued variables.

The accrueStabilityFee function increases the value of poolStablecoinIssued[_collateralPoolId]. This action of accruing stability fees involves recalculating the total amount of debt issued from a specific collateral type. Due to the increase in poolStablecoinIssued[_collateralPoolId], the totalStablecoinIssued value also increases.

Where β represents the amount by which the debtValue increases as the inflated value of _debtAccumulatedRate is reflected in the debtVault when the accrueStabilityFee function is called.

totalStablecoinIssued is the variable stored in the BookKeeper contract. Four functions manipulate totalStablecoinIssued.

The adjustPosition function adjusts the values of totalStablecoinIssued and poolStablecoinIssued based on the changes made to a position. For more details, please refer to the fn adjustPosition section under poolStablecoinIssued.

If a position's debt increases because a user borrows (more) FXD,

If a position's debt decreases as a user pays back FXD,

The settleSystemBadDebt function utilizes the internal balance of stablecoin in the SystemDebtEngine within the bookKeeper to settle the bad debt. When the bad debt is settled, the value of totalUnbackedStablecoin decreases, and so does the value of totalStablecoinIssued.

The mintUnbackedStablecoin function increases the amount of totalUnbackedStablecoin and totalStablecoinIssued.

Where β represents the amount by which the debtValue increases as the inflated value of _debtAccummulatedRate is reflected in the debtValue when the accrueStabilityFee function is called.

totalStablecoinIssued↓=poolStablecoinIssued↓+totalUnbackedStablecointotalStablecoinIssued ↓ = poolStablecoinIssued↓ + totalUnbackedStablecointotalStablecoinIssued↓=poolStablecoinIssued↓+totalUnbackedStablecoin

totalStablecoinIssued=ΣpoolStablecoinIssued+totalUnbackedStablecointotalStablecoinIssued = ΣpoolStablecoinIssued + totalUnbackedStablecointotalStablecoinIssued=ΣpoolStablecoinIssued+totalUnbackedStablecoin
totalStablecoinIssued=[ΣpoolStablecoinIssued−α]+[totalUnbackedStablecoin+α]totalStablecoinIssued = [ΣpoolStablecoinIssued - α] + [totalUnbackedStablecoin + α]totalStablecoinIssued=[ΣpoolStablecoinIssued−α]+[totalUnbackedStablecoin+α]

totalStablecoinIssued+β=[ΣpoolStablecoinIssued+β]+totalUnbackedStablecointotalStablecoinIssued + β = [ΣpoolStablecoinIssued + β] + totalUnbackedStablecointotalStablecoinIssued+β=[ΣpoolStablecoinIssued+β]+totalUnbackedStablecoin

totalStablecoinIssued↑=poolStablecoinIssued↑+totalUnbackedStablecointotalStablecoinIssued ↑ = poolStablecoinIssued↑ + totalUnbackedStablecointotalStablecoinIssued↑=poolStablecoinIssued↑+totalUnbackedStablecoin
totalStablecoinIssued↓=poolStablecoinIssued↓+totalUnbackedStablecointotalStablecoinIssued ↓ = poolStablecoinIssued↓ + totalUnbackedStablecointotalStablecoinIssued↓=poolStablecoinIssued↓+totalUnbackedStablecoin

totalStablecoinIssued↓=ΣpoolStablecoinIssued↓+totalUnbackedStablecointotalStablecoinIssued ↓ = ΣpoolStablecoinIssued↓ + totalUnbackedStablecointotalStablecoinIssued↓=ΣpoolStablecoinIssued↓+totalUnbackedStablecoin

totalStablecoinIssued↑=ΣpoolStablecoinIssued↑+totalUnbackedStablecointotalStablecoinIssued ↑ = ΣpoolStablecoinIssued↑ + totalUnbackedStablecointotalStablecoinIssued↑=ΣpoolStablecoinIssued↑+totalUnbackedStablecoin

totalStablecoinIssued+β=[ΣpoolStablecoinIssued+β]+totalUnbackedStablecointotalStablecoinIssued + β = [ΣpoolStablecoinIssued + β] + totalUnbackedStablecointotalStablecoinIssued+β=[ΣpoolStablecoinIssued+β]+totalUnbackedStablecoin

For a more detailed explanation, please refer to the previous section on .

fn confiscatePosition
fn accrueStabilityFee
totalStablecoinIssued
fn adjustPosition
fn settleSystemBadDebt
fn mintUnbackedStablecoin
fn accrueStabilityFee
accrueStabilityFee
totalStablecoinIssued
poolStablecoinIssued
fn adjustPosition