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
  • Where is a position's collateral recorded?
  • How is a position's collateral recorded?

Was this helpful?

Export as PDF
  1. FXD Stablecoin
  2. BookKeeping mechanism

Collateral Accounting

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

PreviousStablecoin AccountingNextLiquidation

Last updated 11 months ago

Was this helpful?

Where is a position's collateral recorded?

Each position's collateral amount and debt are recorded in the BookKeeper contract. In the BookKeeper contract, are the double mapping that keeps track of each position's lockedCollateral and debtShare.

mapping(bytes32 => mapping(address => Position)) public positions;

mapping has the value as Position struct, and the struct's first member, lockedCollateral keeps track of the collateral.

struct Position {
    uint256 lockedCollateral; // Locked collateral inside this position
    uint256 debtShare;
}

How is a position's collateral recorded?

position.lockedCollateral represents the amount of collateral locked in a specific position. It serves as the primary reference to determine the amount of collateral a particular position holds. The value of position.lockedCollateral increases when a position is opened and decreases when it is closed. During the position opening flow, the value of variable , and later gets transferred to position.lockedCollateral.

mapping(bytes32 => mapping(address => uint256)) public collateralToken;

Similarly, the position value.lockedCollateral is temporarily transferred to the CollateralToken variable during the position closing flow. Then, when the collateral gets withdrawn from CollateralTokenAdapter, the temporarily increased number on decreases as much as .

Three functions are directly involved in lockedCollateral accounting.

in BookKeeper.

in BookKeeper.

in CollateralTokenAdapter.

in CollateralTokenAdapter.

positions
positions
position.lockedCollateral
CollateralToken
increase temporarily
CollateralToken
withdrawn
fn adjustPosition
fn moveCollateral
fn withdraw
fn deposit