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
withdrawCollateral(uint256 amount)
withdrawCollateral(uint256 amount)
Lets a trader withdraw unused collateral, assuming rent requirements are still met.
Emits:
CollateralWithdrawn
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
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
π 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.
getUserFees(address user) β uint256
getUserFees(address user) β uint256
Returns the current fees per second for a given user.
balanceOf(address user) β uint256
balanceOf(address user) β uint256
Returns the current balance for a given user.
getRewardsForLP(uint256 index, uint256 id) β uint256
getRewardsForLP(uint256 index, uint256 id) β uint256
Returns the rewards for a given LP.
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.
needLiquidation(address user) β bool
needLiquidation(address user) β bool
Checks if a user needs to be liquidated.
getCollateralToken() β address
getCollateralToken() β address
Returns the address of the collateral token used.
getMain() β address
getMain() β address
Returns the address of the main contract that oversees protocol governance.
π§ 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