Solvers are a new, improved framework for building Haiko Vaults. They take the best parts of Strategies (e.g. convenience, 1-click automation) and make them simpler, more powerful, and less error-prone.
Whereas Strategies place and update liquidity positions on Haiko's AMM, Solvers are stateless, meaning they never mint any liquidity positions or interact with any AMM. Instead, traders swap directly against liquidity deposited to Solver contracts. Swap quotes are generated on the fly based on an oracle price feed and a set of market configurations.
By using a stateless architecture, Solvers are:
- More gas efficient for LPs and swappers, as they avoid the gas cost of on-chain position storage and rebalancing
- Less error-prone, as they do not rely on external AMM state
- More flexible, as they can be used to create markets based on any pricing formula, not just those adopting Uniswap-style liquidity
In addition, our first Replicating Solver introduces powerful new features for LPs:
- Zero-Cost Rebalancing: Solvers are now constantly rebalanced at zero gas cost to swappers and LPs
- Impermanent Loss Caps: pools can apply a hard cap on impermanent loss by rejecting swaps that bring the pool above its maximum allowed level of portfolio skew
- Private Vaults: liquidity providers can now create Private Vaults that are closed to third party depositors, offering greater flexibility over deposit / withdrawals and other admin actions, and enabling new use cases such as protocol-owned or liquidity bootstrapping pools (for new token issues)
- Pool-level Governance: pool ownership is now tracked via an ERC20 token, enabling micro-governance amongst pool depositors for better optimised pool parameters
There are some key differences between AMM markets and Solver markets. These are summarised in the table below.
Feature | AMM / Strategies | Solver |
---|---|---|
Swap fees | Fixed swap fee rate per market | Agnostic to fee formula, can charge a swap fee, add a dynamic spread on swap quotes, or use another fee formula |
Tick width | Fixed tick width per market | Can accomodate any tick width |
Price | Stores current price | Stateless, does not need to store current price |
Rebalancing | Uses swap hooks for rebalancing | Constantly rebalanced, as positions are calculated on the fly at the point of swap |
This monorepo contains both the core solver libraries and contracts (in package core
) and individual solver implementations (in remaining packages).
Solver Core (core
)
The SolverComponent
in the core
package implements most of the core functionality of a Solver
contract, including:
- Creating and managing new solver markets (which comprise of a
base_token
andquote_token
pair, anowner
andis_public
flag) - Managing deposits and withdrawals from solver markets, which are tracked using ERC20 vault tokens for composability
- Swapping assets through a solver market
- Managing and collecting withdraw fees (if enabled)
- Admin actions such as pausing and unpausing, upgrading and transferring ownership of the contract
Solvers currently support two vault types:
- Public Vaults, which are open to 3rd party depositors and track ERC20 vault tokens for composability
- Private Vaults, which are closed to a single admin owner and offer more granular control and flexible access to admin functions
A Solver implementation must:
- Inherit the base functionality of
SolverComponent
- Implement
SolverHooks
which contains methods for generating quotes, minting initial vault liquidity tokens and other callbacks - Implement hooks for other components used (e.g.
GovernorHooks
for theGovernor
component used for decentralised governance of pool parameters)
The core SolverComponent
component will eventually be moved to its own repo to be reused across multiple Solvers. We currently store it as a package under a single monorepo for ease of development.
Solver implementations are standalone contracts that inherits from SolverComponent
and implement the SolverHooks
and other trait. You can read more about these implementations here.
Solver | Description | Package |
---|---|---|
Replicating | Quotes based on Pragma oracle price feed | replicating |
Reversion | Uses a zkML trend classifier to capture fees / spreads on trend reversion | reversion |
# Build contracts
scarb build
# Run the tests
snforge test --max-n-steps 4294967295
- Scarb 2.6.3
- Cairo 2.6.3
- Starknet Foundry 0.21.0
- OpenZeppelin Contracts 0.11.0