Project Structure
Dependencies
The project depends on solady's ultra-efficient libraries. It also draws inspiration from its optimization tricks throughout the codebase.
Another honorable mention goes to Mangrove Core, which is the inspiration for the tick tree as well as the binary exponentiations for the conversion from tick to price.
The project uses Foundry for development, testing, and scripting as well as native dependency management with git submodules.
Project structure
The project is organized into the following directories:
src: contains the core contracts of the protocoltest: contains the tests for the protocolscript: contains the scripts for the protocollib: contains the external dependencies through git submodulesscript: contains the deployment scripts
Interfaces
Under the src/interfaces folder, you will find the interfaces for the protocol.
./src/interfaces
├── base
│ ├── IVifAuthorizer.sol
│ ├── IVifCore.sol
│ ├── IVifMaking.sol
│ ├── IVifManager.sol
│ └── IVifTaking.sol
├── eip2330
│ └── IExtLoad.sol
├── ILockCallback.sol
├── IVif.sol
└── periphery
└── IVifRouter.solThe base subfolder contains the specific components that compose the core contracts. IVif combines all the base interfaces.
IExtLoad is also a parent interface for the IVif interface, which helps us load the contract state.
Libraries
Under the src/libraries folder, you will find the libraries for the protocol.
src/libraries
├── external
│ ├── LibAuthorizationExt.sol
│ ├── LibBlackListExt.sol
│ ├── LibDeltasExt.sol
│ ├── LibExtLoader.sol
│ ├── LibFeesExt.sol
│ ├── LibLockExt.sol
│ ├── LibMarketExt.sol
│ ├── LibOfferExt.sol
│ ├── LibOfferListExt.sol
│ ├── LibPausableExt.sol
│ ├── LibProvisionExt.sol
│ └── LibTreeExt.sol
├── LibAuthorization.sol
├── LibBit.sol
├── LibBlackList.sol
├── LibDeltas.sol
├── LibFees.sol
├── LibLock.sol
├── LibMarket.sol
├── LibOffer.sol
├── LibOfferList.sol
├── LibPausable.sol
├── LibProvision.sol
├── LibTick.sol
├── periphery
│ ├── Commands.sol
│ └── Types.sol
└── tree
├── LibFlags.sol
└── LibTree.solThe libraries are subdivided into two main categories:
- The external libraries, which are used by periphery contracts to get the state of the core contract through the
IExtLoadinterface andLibExtLoaderlibrary. - The core libraries, which are used by the core contract to mutate and check state internally.
Periphery Contracts
Under the src/periphery folder, you will find the periphery contracts for the protocol.
src/periphery
├── dispatcher
│ ├── base
│ │ ├── GeneralDispatcher.sol
│ │ ├── OrdersDispatcher.sol
│ │ └── SettlementDispatcher.sol
│ └── Dispatcher.sol
├── VifReader.sol
└── VifRouter.solThe reader is a contract that allows reading the state of the core contract off-chain. It has functions to get the list of markets, order books, offers, etc.
The router contract inherits the Dispatcher contract and implements the IVifRouter interface. It batches operations through the commands defined in the Commands library, with input and output types defined in the Types library.
Core contract
Finally, the core contract, which is the sum of the base contracts, is defined in the src/Vif.sol file.