Collateral Accounting
This section provides a deep understanding of how the accounting of collateral is done in the BookKeeper contract.
Last updated
Was this helpful?
This section provides a deep understanding of how the accounting of collateral is done in the BookKeeper contract.
Last updated
Was this helpful?
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 has the value as Position
struct, and the struct's first member, lockedCollateral
keeps track of the collateral.
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
.
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
.