VaultPriceFeed
The VaultPriceFeed contract serves as the oracle system for the Satoshi Perps protocol, providing token prices for various operations such as position sizing, liquidation checks, and swap calculations.Contract Overview
The VaultPriceFeed handles:- Fetching token prices from multiple oracle sources
- Validating and adjusting price data
- Providing maximum and minimum prices with configurable spread
- Supporting both chainlink and custom price feeds
The VaultPriceFeed is a crucial component for the protocol as accurate price data is essential for fair position sizing, liquidations, and swaps.
Key Functions
Price Retrieval
Price Feed Configuration
Oracle Sources
The VaultPriceFeed can use multiple sources for price data:- Chainlink Oracle: The primary source for price data, known for its reliability and decentralization
- Secondary Price Feeds: Can be configured as backup or complementary price sources
- AMM-based Pricing: Can use prices derived from AMM pools (though typically less reliable)
The VaultPriceFeed prioritizes Chainlink oracles for price data. Secondary sources are only used when explicitly configured or when primary sources are unavailable.
Price Adjustments
The contract allows for price adjustments to handle various scenarios:- If
_isAdditive
is true, adds or subtracts_adjustmentBps
basis points - If
_isAdditive
is false, multiplies by(10000 +/- _adjustmentBps) / 10000
- The sign depends on
_maximise
(plus for max price, minus for min price)
Spread Mechanism
The price feed implements a spread mechanism that provides slightly different prices depending on the operation:- For buy operations, the
_maximise
parameter is set totrue
, returning a higher price - For sell operations, the
_maximise
parameter is set tofalse
, returning a lower price
Security Considerations
The VaultPriceFeed implements several security features:- Multiple Price Sources: Can fall back to secondary sources if primary fails
- Price Validation: Checks that prices are within reasonable ranges
- Admin Controls: Only authorized addresses can update price feed configurations
- Spread Mechanism: Creates a buffer against price manipulation
The security of the price feed is critical to the overall security of the protocol. Any compromise in price data could potentially affect all protocol operations.
Integration with Vault
The Vault contract uses the VaultPriceFeed for various operations:- Position Sizing: Determines USD value of collateral and position sizes
- Liquidation Checks: Determines if positions are undercollateralized
- Swap Calculations: Determines exchange rates for token swaps
- PnL Calculations: Determines profit and loss for positions
Example Usage
1
Getting Token Price
The Vault needs to get the price of ETH to calculate position value.
2
Configuring Price Feed
An admin wants to set up a new token’s price feed.
3
Applying Price Adjustment
During extreme market conditions, an admin applies a buffer to prices.
Price Feed Failure Handling
The VaultPriceFeed includes fallback mechanisms for handling price feed failures:- If a Chainlink price feed fails, the contract can fall back to secondary price sources
- If all price feeds fail, the governance can update the price feeds or apply temporary adjustments
- In extreme cases, the protocol has circuit breakers to pause operations if price data is unavailable or unreliable
It is critical to monitor the health of price feeds, as inaccurate pricing can lead to unfair liquidations or allow exploitative trades.