Automated liquidation protection for DeFi loans on platforms like AAVE
Cushion is a decetralized protocol to provide automated liquidation protection for DeFi loans on platforms like AAVE. The system consists of two core smart contracts. The Vault (ERC4626) is a liquidity pool where liquidity providers can deposit stable assets (like pyUSD) to earn a yield. The second one is The Loan Wrapper, which will wrap an existing loan from a lending protocol like AAVE into Cushion NFT.
This NFT represents ownership of the loan, which at some point allows our protocol to manage it. When a wrapped loans Health Factor drops to a predetermined risky level, the Vault automatically injects capital, increasing its collateral and moving it away from the liquidation threshold. Once the market recovers and the loans health factor improves, the injected capital, plus a small interest fee, is withdrawn and returned to the Vault, increasing the value of the LP tokens for liquidity providers. If the health factor drops two times, and it is not in our favor to deposit more money, the Vault can liquidate the loan to protect its capital.
Cushion leverages a robust architecture built on battle-tested smart contract standards and key DeFi primitives to deliver automated loan protection. The system is designed with security and capital efficiency in mind.
Core Smart Contracts:
Vault.sol: The heart of the protocol is a sophisticated ERC4626 Tokenized Vault, built using OpenZeppelin Contracts. It accepts deposits in pyUSD from Liquidity Providers (LPs) and issues LP shares representing their stake. This contract holds the core logic for: Calculating the required capital injection amount based on the loan's collateral and debt values (provided by the LoanWrapper). Executing on-chain swaps between pyUSD and ETH using Uniswap V3 via a dedicated internal swap function (_swapPyUsdToEth, _swapEthToPyUsd). Interacting with the LoanWrapper to inject (increaseCollateral) or withdraw (decreaseCollateral) collateral (ETH). Managing the 5% annual interest rate applied to injected capital, tracking it via a global accumulatedInterest index to generate yield for LPs. Initiating and managing the loan liquidation process. Receiving ETH returned from the LoanWrapper via the receive() function and automatically swapping it back to pyUSD.
LoanWrapper.sol: Each protected AAVE loan is represented by an instance of this contract It acts as a smart proxy between the loan owner, the Vault, and the AAVE V3 protocol. Its key responsibilities include:
Holding the AAVE position (interacting with the AAVE IPool). Providing necessary data to the Vault (getTotalCollateralValue, getTotalDebtValue, getDebtToken, getCollateralToken, getBorrowedAmount). Receiving ETH collateral from the Vault via a payable function (increaseCollateral) and supplying it to AAVE. Returning ETH collateral to the Vault (decreaseCollateral), withdrawing it from AAVE first. Repaying the AAVE debt (repayLoan) when instructed by the Vault during liquidation, using funds provided by the Vault. Implementing a locking mechanism (locked state) to restrict owner actions after the Vault has intervened.
Key Mechanisms & Partner Technologies:
Off-Chain Keepers: Health Factor monitoring is intentionally kept off-chain for gas efficiency and flexibility. External Keeper bots constantly monitor the Health Factor of wrapped loans via the LoanWrapper's view functions. When a threshold is crossed, the Keeper triggers the appropriate function (injectToLoan, withdrawFromLoan, liquidate) on the Vault contract. Uniswap V3 Integration: The Vault utilizes the Uniswap V3 Router for all token swaps (pyUSD <-> WETH). It wraps/unwraps ETH automatically using the WETH9 contract. Chainlink Price Feeds: The Vault relies on Chainlink oracles (PYUSD/USD) to accurately convert the USD-denominated injection amount into the required quantity of pyUSD for swapping
Tech Stack: Solidity ^0.8.30 on Hardhat 3 (Sepolia & local) OpenZeppelin (ERC4626, ERC20, Ownable, Math) Uniswap V3 router for PYUSD ↔ WETH swaps (POC also has a deterministic MockSwapAdapter/Router) Chainlink price feeds (ETH/USD, PYUSD/USD) for conversions (8-dec oracle math) Python (Web3.py) Keeper bot (monitor HF, automate actions) Extensive mocks (Aave pool, addresses provider, aToken, variable debt, WETH, ERC20, oracles)

