Protocol Flow Charts
This page provides visual flowcharts that illustrate the main processes in the Satoshi Perps protocol. Understanding these flows is essential for traders, developers, and integrators.Position Lifecycle
Opening a Position
The following flow chart illustrates the complete process of opening a position through the protocol: Position Opening Steps:- User calls
createIncreasePosition
on PositionRouter - PositionRouter stores request data in queue
- PositionRouter transfers tokens from user
- Keeper calls
executeIncreasePosition
on PositionRouter - PositionRouter validates request parameters
- If invalid, tokens are refunded to user
- If valid, calls Vault’s
increasePosition
function - Vault gets price from VaultPriceFeed
- Vault verifies sufficient collateral
- Vault calculates fees, updates position data
- Vault reserves tokens and updates global open interest
- PositionRouter executes optional callback
- PositionRouter sends execution fee to keeper
Closing a Position
This flow chart shows the process of closing or decreasing a position: Position Closing Steps:- User calls
createDecreasePosition
on PositionRouter - PositionRouter stores request data in queue
- Keeper calls
executeDecreasePosition
on PositionRouter - PositionRouter validates request parameters
- If invalid, execution fee is refunded to user
- If valid, calls Vault’s
decreasePosition
function - Vault gets price from VaultPriceFeed
- Vault calculates profit or loss
- If profitable, applies minimum profit time rule
- If not, processes the loss
- Deducts fees and updates position data
- Releases reserved tokens and updates open interest
- Transfers tokens to the receiver
- PositionRouter executes optional callback
- PositionRouter sends execution fee to keeper
Liquidation Process
This flow chart illustrates the liquidation process for underwater positions: Liquidation Steps:- Liquidator calls
liquidatePosition
on Vault - Vault checks if the position exists
- If it doesn’t exist, reverts the transaction
- If it exists, gets the position data
- Checks current price from VaultPriceFeed
- Determines if position is liquidatable based on leverage and collateral
- If not liquidatable, reverts the transaction
- If liquidatable, calculates remaining collateral
- Calculates liquidation fee for the liquidator
- Updates position data (zeroes out the position)
- Releases reserved tokens
- Updates global open interest
- Pays liquidation fee to the liquidator
- Transfers remaining collateral to fee receiver
- Emits LiquidatePosition event
Order Execution Process
This flow chart illustrates how limit orders are processed by the OrderBook contract: Order Execution Steps:- User creates an order via the OrderBook contract
- OrderBook checks if the user has provided sufficient collateral
- Order is stored with price trigger conditions
- Keeper periodically calls update functions to check if orders can be executed
- OrderBook checks if price conditions are met
- If conditions are met, executes the order via BasePositionManager
- BasePositionManager calls the Vault to execute the position change
- Execution fee is paid to the keeper
Liquidity Provision Flow
Liquidity Provision Steps:- User calls
addLiquidity
on SlpManager - SlpManager calls Vault’s
buyUSDG
function - Vault converts tokens to USDG stablecoins
- Vault increases the pool amount for the token
- USDG is returned to SlpManager
- SlpManager mints SLP tokens to the user based on the current SLP price
- AddLiquidity event is emitted