Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incentivized Liquidation System for Leverage and Perpetual Market #660

Merged
merged 3 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions x/leveragelp/spec/incentivized_liquidation_system.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

# Incentivized Liquidation System for Leverage Market

## Diagram

```plaintext
+------------+ +------------+ +-------------+
| | | | | |
| Depositors | | Borrowers | | Liquidators |
amityadav0 marked this conversation as resolved.
Show resolved Hide resolved
| | | | | |
+-----+------+ +-----+------+ +-----+-------+
| | |
| Deposit stable coins | Borrow stable coins | Check positions
| and earn interest | to open leverage positions | for liquidation or if certain price is met(stop loss)
| | |
+-----v------+ +-----v------+ +-----v-------+
| | | | | |
| Stable |<-----------------| Leverage |<-----------------| Liquidation |
| Coin Pool | Borrow coins | Position | Monitor | Function | Monitor
| Module | | Module | positions | | positions
+------------+ +------------+ +-------------+
| | |
| | |
| Interest | Position health calculated | If health < threshold, or certain price is met(stop loss)
| | as lpAmount / debt | trigger liquidation
amityadav0 marked this conversation as resolved.
Show resolved Hide resolved
| | | and receive reward
| | |
+-----v------+ +-----v------+ +-----v-------+
| | | | | |
| Depositor | | Borrower | | Liquidator |
| Earns | | Manages | | Earns |
| Interest | | Position | | Reward |
+------------+ +------------+ +-------------+
```

## Explanation

- **Depositors** provide liquidity to the system and earn interest.
- **Borrowers** take leveraged positions by borrowing from the pool.
- **Liquidators** and **Bots** monitor positions and execute liquidations when necessary.
amityadav0 marked this conversation as resolved.
Show resolved Hide resolved
- The system rewards liquidators and bots for maintaining the health of the market.
- The **Liquidation Function** is responsible for managing the logic of liquidations and distributing rewards.

This approach distributes the load of monitoring and liquidation to incentivized users and bots, making the system more efficient and scalable.
39 changes: 39 additions & 0 deletions x/leveragelp/spec/incentivized_liquidation_system_spec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

# Specification: Incentivized Liquidation System

## Overview
The Incentivized Liquidation System ensures the stability and health of the leverage market by allowing users and bots to monitor and liquidate undercollateralized positions and postions that met a certain price(stop loss). Liquidators are rewarded for their efforts, creating an incentivized mechanism to maintain market health.

## Scalability Advantage
Unlike a system that requires traversing and evaluating all positions in each block—which is not scalable—the incentivized liquidation approach delegates the monitoring and liquidation tasks to users and bots. This significantly reduces the computational load on the blockchain, making the system scalable and capable of handling a large number of positions efficiently.

## Incentivized Liquidation by Users and Bots

Users and bots can monitor positions and trigger liquidations when necessary. They are rewarded for their actions, ensuring continuous monitoring and prompt liquidation of undercollateralized positions and stop loss.

### Pseudo Code

```plaintext
function IncentivizedCheckAndLiquidate(ctx, positionId, liquidator):
position = getPosition(ctx, positionId)
health = calculateHealth(position)

if health < LIQUIDATION_THRESHOLD || lp_price <= stop_loss_price::
executeLiquidation(ctx, position)
rewardLiquidator(ctx, liquidator)
```

## Workflow

1. **Monitoring**: Users and bots monitor the health of positions.
2. **Triggering Liquidation**: If a position's health falls below the threshold, users or bots call the `IncentivizedCheckAndLiquidate` function.
3. **Executing Liquidation**: The system executes the liquidation, sells the assets, covers the debt, and marks the position as liquidated.
4. **Rewarding Liquidators**: The liquidator is rewarded for their action.

## Note
If a user reports an incorrect position for liquidation, they will incur the extra fees associated with the transaction.

## Incentive value (TODO)
- Fixed vs proportional
- Fixed Incentive: A fixed incentive means that liquidators receive a predetermined reward amount for each successful liquidation, regardless of the size of the position.
- Proportional Incentive with Minimum Threshold: A proportional incentive means that the reward is a percentage of the liquidated position's assets. To ensure fairness and adequate motivation, a minimum reward threshold is set.
Loading