CollateralPool
π¦ CollateralPool.sol
CollateralPool.sol
The CollateralPool
contract is a key component of the Scall.io protocol. It handles the collateral management system, which powers all perpetual option contracts.
This contract manages:
User deposits and withdrawals of collateral tokens (e.g., USDC)
Real-time rent deduction from traders
Liquidation logic based on collateral balances
Reward distribution for liquidity providers (LPs)
π§© What It Does
Accepts and stores collateral deposits from traders
Tracks user rent balance and updates it per block
Enables safe withdrawals based on collateral/rent levels
Handles liquidation if rent coverage becomes insufficient
Distributes protocol rewards to LPs and other participants
π οΈ Public & External Functions
depositCollateral(uint256 amount)
depositCollateral(uint256 amount)
Allows a trader to deposit collateral.
Emits:
CollateralDeposited
/// @notice Allows a user to deposit collateral into their account.
/// @param _amount The amount of collateral to deposit.
function depositCollateral(uint256 _amount) external
withdrawCollateral(uint256 amount)
withdrawCollateral(uint256 amount)
Lets a trader withdraw unused collateral, assuming rent requirements are still met.
Emits:
CollateralWithdrawn
/// @notice Allows a user to withdraw collateral if they have sufficient balance.
/// @param _amount The amount of collateral to withdraw.
function withdrawCollateral(uint256 _amount) external
liquidateContract(address user, address market, uint256 contractId)
liquidateContract(address user, address market, uint256 contractId)
Called by any liquidator when a userβs collateral balance drops below the minimum threshold (e.g., one week of rent).
Automatically closes the userβs contracts and redistributes a penalty to the liquidator.
Emits:
ContractLiquidated
/// @notice Liquidates a user's contract if they meet the liquidation criteria.
/// @param _user The address of the user.
/// @param _index The market index.
/// @param _id The ID of the user's position.
/// @return The penalty amount awarded to the liquidator (18 decimals).
function liquidateContract(address _user, uint256 _index, uint256 _id) external returns(uint256)
claimRewards(uint256 index, uint256 id)
claimRewards(uint256 index, uint256 id)
Allows LPs or users with eligible NFTs to claim rent rewards based on usage and time.
Emits:
RewardsClaimed
/// @notice Allows a user to claim rewards for a position they own.
/// @param _index The market index.
/// @param _id The ID of the user's position.
/// @return claimedRewards The reward amount received by the LP (token decimals).
function claimRewards(uint256 _index, uint256 _id) external returns(uint256)
π View Functions
These read-only functions help frontends or users query internal state:
getUserInfos(address user) β uint256
getUserInfos(address user) β uint256
Returns user information for a specific user.
struct UserInfos {
uint256 collateral;
uint256 rent;
uint256 lastUpdate;
}
/// @notice Returns user information for a specific user.
/// @param _user The address of the user.
/// @return UserInfos structure containing collateral, rent, and last update timestamp.
function getUserInfos(address _user) external view returns(UserInfos memory)
getUserFees(address user) β uint256
getUserFees(address user) β uint256
Returns the current fees per second for a given user.
/// @notice Calculates the accumulated fees for a user.
/// @param _user The address of the user.
/// @return The total fees accumulated for the user (18 decimals).
function getUserFees(address _user) external view returns(uint256)
balanceOf(address user) β uint256
balanceOf(address user) β uint256
Returns the current balance for a given user.
/// @notice Returns the balance of collateral for a user after deducting rent fees.
/// @param _user The address of the user.
/// @return The net balance of the user (18 decimals).
function balanceOf(address _user) public view returns(uint256)
getRewardsForLP(uint256 index, uint256 id) β uint256
getRewardsForLP(uint256 index, uint256 id) β uint256
Returns the rewards for a given LP.
/// @notice Calculates the rewards for a liquidity provider after deducting fees.
/// @param _index The market index.
/// @param _id The ID of the user's position in the market.
/// @return The net rewards after fees (18 decimals).
function getRewardsForLp(uint256 _index, uint256 _id) external view returns(uint256)
canOpenContract(address user, uint256 rent) β bool
canOpenContract(address user, uint256 rent) β bool
Determines if a user can open a contract based on their collateral and rent.
/// @notice Determines if a user can open a contract based on their collateral and rent.
/// @param _user The address of the user.
/// @param _rent The rent amount for the new contract.
/// @return True if the user has sufficient collateral, otherwise false.
function canOpenContract(address _user, uint256 _rent) external view returns(bool)
needLiquidation(address user) β bool
needLiquidation(address user) β bool
Checks if a user needs to be liquidated.
/// @notice Checks if a user needs to be liquidated.
/// @param _user The address of the user.
/// @return True if liquidation is required, otherwise false.
function needLiquidation(address _user) external view returns(bool)
getCollateralToken() β address
getCollateralToken() β address
Returns the address of the collateral token used.
/// @notice Returns the address of the collateral Token.
/// @return Address of the collateral Token.
function getCollateralToken() external view returns(address)
getMain() β address
getMain() β address
Returns the address of the main contract that oversees protocol governance.
/// @notice Returns the address of the main contract.
/// @return Address of the main contract.
function getMain() external view returns(address)
π§ How It Works
The contract stores user collateral in a mapping and tracks rent accrual per second. If a userβs collateral drops below one week of required rent, their positions are eligible for liquidation.
When rent is collected, the protocol distributes it across:
Liquidity providers
The DAO (if enabled)
Potential rewards for liquidators
π Summary
Deposit/Withdraw
Manage user collateral balances
Rent Tracking
Ensure options remain funded in real-time
Liquidation
Protect LPs by auto-closing underfunded trades
Rewards Claiming
Enable LPs to receive protocol-generated income
Last updated