CollateralPool

🏦 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)

  • Allows a trader to deposit collateral.

  • Emits: CollateralDeposited

withdrawCollateral(uint256 amount)

  • Lets a trader withdraw unused collateral, assuming rent requirements are still met.

  • Emits: CollateralWithdrawn

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, uint256 substractCount)

  • 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

  • Returns user information for a specific user.

getUserFees(address user) β†’ uint256

  • Returns the current fees per second for a given user.

balanceOf(address user) β†’ uint256

  • Returns the current balance for a given user.

getRewardsForLP(uint256 index, uint256 id) β†’ uint256

  • Returns the rewards for a given LP.

canOpenContract(address user, uint256 rent) β†’ bool

  • Determines if a user can open a contract based on their collateral and rent.

needLiquidation(address user) β†’ bool

  • Checks if a user needs to be liquidated.

getCollateralToken() β†’ address

  • Returns the address of the collateral token used.

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

Feature
Purpose

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