Smart contracts for managing credit line collateral within the Wildcat protocol. This implementation provides a mechanism for borrowers to deposit collateral that can be liquidated in case of delinquency.
This repository contains Solidity smart contracts for collateral management in Wildcat markets:
WildcatMarketCollateral: Core contract for collateral managementWildcatMarketCollateralFactory: Factory contract for deploying collateral contractsSimpleMarketCollateral: Simplified collateral implementationSimpleMarketCollateralMultiParty: Multi-party collateral implementation
The SimpleMarketCollateralMultiParty contract is the core collateral management system designed for Wildcat markets with these key features:
A collateral contract that supports multiple depositors providing collateral assets that can be liquidated when the underlying Wildcat market enters a penalized delinquency state. The contract integrates with Bebop PMM (Private Market Maker) for efficient liquidation processing.
- Multi-Party Deposit System: Allows multiple users to deposit collateral assets while maintaining individual accounting.
- Share-Based Accounting: Users receive shares equivalent to their deposit amounts, with internal accounting to track liquidations.
- Liquidation Management: Liquidations are processed through Bebop PMM by approved liquidators when markets enter penalized delinquency.
- Liquidation Points: Utilizes a dividend-like system (but for debits) to track the amount of collateral liquidated from each user's deposit.
- Fair Distribution: New depositors are not penalized for liquidations that occurred before their deposits.
- Reclaim Mechanism: Users can withdraw their remaining collateral once the underlying market is terminated.
- Token Rescue: Borrowers can rescue tokens mistakenly sent to the contract.
The WildcatMarketCollateralFactory is responsible for deploying SimpleMarketCollateralMultiParty contracts using these key mechanisms:
-
Deterministic Deployment: Uses Create2 for deterministic address generation, ensuring contracts can be located predictably.
-
Collateral Parameters: Temporarily stores parameters (collateral token, associated market, borrower) in transient storage during deployment.
-
Deployment Process:
- Market participants call
deployCollateralContract(collateralToken, associatedMarket) - Factory creates a unique salt based on the collateral token and associated market
- Factory verifies no duplicate contract exists for the same parameters
- Factory retrieves the borrower from the associated market
- Parameters are temporarily stored for the contract constructor to access
- Contract is deployed using LibStoredInitCode for efficient deployment
- Deployed contract is registered in the factory's tracking system
- Market participants call
-
Contract Registry: Maintains a mapping of deployed collateral contracts by market, allowing query functions like
listCollateralMarkets(market, asset) -
Liquidator Management: Provides functions to approve and remove liquidators who can execute collateral liquidations
- The liquidation process carries an inherent risk where a malicious executor collaborating with a malicious maker on Bebop could potentially process liquidations at unfavorable prices.
- The contract does not support rebasing tokens or assets with non-standard transfer semantics due to its internal balance tracking approach.
- Liquidations are restricted by cooldown periods and maximum repayment limits to prevent abuse.
deposit(uint256 _amount): Allows users to deposit collateralliquidateCollateral(bytes, uint, uint, uint): Sells collateral to repay delinquent debt via Bebop PMMreclaimCollateral(): Allows users to reclaim their remaining collateral after market terminationgetLiquidatedCollateral(address): Returns the total collateral that has been liquidated from an accountgetReclaimableAmount(address): Returns the amount of collateral that can be reclaimed by an account
This project uses Foundry for Ethereum development.
# Clone the repository with submodules
git clone --recursive https://github.com/wildcat-finance/collateral-contract.git
cd collateral-contract
# Install dependencies
forge installforge buildforge testyarn coverageApache-2.0 WITH LicenseRef-Commons-Clause-1.0