AccountTokenLib

Overview

This is the library that is used by the Accounts contract to track the balances of each user.
In the Accounts contract, there is a field mapping(address => Account) public accounts; that is used to record the balance status, and Account struct is:
1
struct Account {
2
mapping(address => AccountTokenLib.TokenInfo) tokenInfos;
3
uint128 depositBitmap;
4
uint128 borrowBitmap;
5
}
Copied!
The depositBitmap and borrowBitmap are used to check whether one user has depositings/borrowings for each specific token with less gas cost.
And the TokenInfo struct is the following:
1
struct TokenInfo {
2
// Deposit info
3
uint256 depositPrincipal; // total deposit principal of ther user
4
uint256 depositInterest; // total deposit interest of the user
5
uint256 lastDepositBlock; // the block number of user's last deposit
6
// Borrow info
7
uint256 borrowPrincipal; // total borrow principal of ther user
8
uint256 borrowInterest; // total borrow interest of ther user
9
uint256 lastBorrowBlock; // the block number of user's last borrow
10
}
Copied!
For each operation one user interacting with our contract, we update accounts field.

TokenInfoRegistry

Token Info Registry to manage Token information. The Owner of the contract allowed to update the information. TokenInfo struct stores Token Information, this includes: ERC20 Token address, Compound Token address, ChainLink Aggregator address etc.
1
struct TokenInfo {
2
// Token index, can store upto 255
3
uint8 index;
4
// ERC20 Token decimal
5
uint8 decimals;
6
// If token is enabled / disabled
7
bool enabled;
8
// Is ERC20 token charge transfer fee?
9
bool isTransferFeeEnabled;
10
// Is Token supported on Compound
11
bool isSupportedOnCompound;
12
// cToken address on Compound
13
address cToken;
14
// Chain Link Aggregator address for TOKEN/ETH pair
15
address chainLinkAggregator;
16
// Borrow LTV, by default 60%
17
uint256 borrowLTV;
18
// Liquidation threshold, by default 85%
19
uint256 liquidationThreshold;
20
// Liquidation discount ratio, by default 95%
21
uint256 liquidationDiscountRatio;
22
}
Copied!
Last modified 1yr ago
Copy link