Tech Stack

A price feed architecture via Chainlink has been implemented to ensure maximal price accuracy of underlying assets to their spot prices. Price is purely based on Chainlink node price feeds to determine spot prices, not orderbooks or other similar models.

Price Feed Nodes: To construct a dependable price feed, we acquire multiple price points from nodes, ranging between a minimum of 3 and a maximum of 20 nodes. The utilization of multiple nodes not only enhances precision but also fortifies the system against inaccuracies, providing redundancy to counteract potential malicious or erroneous inputs. Notably, the median of the gathered price points is used as the final price point, ensuring a robust and reliable determination of the accurate price.

Unlike traditional chain link oracle systems where price feeds may be intermittent, chain link price requests are sent on demand in real time when trades are open or closed to ensure maximal spot price accuracy. Likewise, Krav also institutes a low latency intermittent price feed to ensure price accuracy while trades are live.

Core Trading and LP Contract Structure

Vault

The Vault contract is the main LP user facing contract. It allows users to deposit and withdrawal their altcoins in liquidity pools. The contract also deals with LP rewards, tracking accumulated awards, calculating user specific rewards, and allowing users to harvest their rewards. Likewise, the contract also holds several functions to send tokens accordingly based on trade interactions, referenced in the KravTradingCallbacks contract.

PriceAggregator

The PriceAggregator contract is the core logic of Chainlink price feed, acting as a middleware between Krav and the Chainlink oracle network. It facilitates the aggregation of price information from multiple oracle nodes and likewise provides functionality for executing callbacks based on received prices. The contract allows for management of price feed nodes, allowing for the addition/removal of oracle nodes as well as the ability to adjust minimum and maximum nodes as needed to ensure price accuracy.

KRAVTrading

The KRAVTrading contract is in essence the trader facing contract, integrating various functions to streamline trade execution and management. Users can initiate or close trades. Many of the core logic related to trading executions are interfaced from the KRAVTradingCallbacks Contract. Trade executions are carried out in the sequential order they are submitted, eliminating race conditions.

KRAVTradingCallbacks

The KravTradingCallbacks is the core logic contract related to trading mechanisms. It interacts with several interfaces including the Priceaggregator interface, PairInfos Interface, and Storage Interface to manage and read essential trading information and pair-specific details to execute trade. The majority of the contract consists of callback functions and price request interfaced from the Price aggregator interface, triggered by external events (e.g., market execution). These functions handle various aspects of trading logic, including opening and closing trades, calculating fees, and interacting with other components of the protocol. Additionally, the contract also interfaces functions from the vault contract to send associated tokens, according to PnL and trade open and closes, from the vault to traders.

KRAVPairInfos

The pair info contract is used to set and get various information regarding various altcoin collateral trading pairs in order to facilitate various trading executions. Pairs are defined by the altcoin used as collateral, and the underlying asset to be bet on. Various trading parameters include funding fee data (open interest), fees, max and min leverage, maximum slippage, and other trading related parameters are set using this contract for each pair, with some parameters being controlled by governance and others managed by Krav. The information is likewise stored in an associated PairStorage Contract.

Storage

The central contract that keeps core data. Admins can use this contract to set the address of each module contract. It's upgradeable and also stores order info.

Last updated