Replicating Solver
Last updated
Last updated
Solver Monorepo: https://github.com/haiko-xyz/solver
The Replicating Solver is the first Solver released by the Haiko team. It is designed for maximal gas efficiency, return market-neutral yield to depositors, and offer principal protection against market volatility using dynamic quoting and impermanent loss caps.
It is based on the original Replicating Strategy, improved for our new Solver architecture.
The Replicating Solver runs a simple market making strategy for each market by placing two positions (bid and ask) positions around the imputed oracle price, plus a dynamically adjusted spread to collect fees and optimise for portfolio skew / execution quality.
Quotes and liquidity positions are calculated on the fly whenever a swap is conducted, meaning positions are never stored in state. This allows Solver markets to be constantly rebalanced at zero cost to both swapper and LP.
Like the core AMM and prior Strategies, the Replicating Solver is built with a singleton design. This means all markets can be served from a single smart contract.
Each market has a set of configurable parameters that can be set by the admin / owner or by pool governance amongst pool depositors, if this feature is enabled.
The parameters are as follows, and are mostly denominated in limits
(1/10 basis point).
Parameter | Description | Example |
---|---|---|
The max_skew
parameter can be used to set Impermanent Loss Caps, rejecting swaps that bring the pool above its maximum allowed portfolio skew.
Vaults are public by default, meaning they are open to third party depositors on a permissionless basis. Vault ownership is tracked using an ERC20 token, which is also used to enable pool-level governance of market parameters amongst pool depositors.
A second vault type, Private Vaults, are closed to third party depositors while offering greater flexibility over deposits and withdrawals, as well as other admin functions. Private Vaults and perfect for use cases such as protocol-owned or liquidity bootstrapping pools.
They can also be used to permissionlessly issue assets on Starknet using just an oracle price feed in the absence of other arbitrage venues.
AMM liquidity positions are subject to Impermanent Loss (IL). This refers to the phenomenon whereby price changes cause the position to be increasingly weighted toward the asset that is falling in value.
With the Replicating Solver, Impermanent Loss is replaced by a Rebalancing P&L:
If rebalancing P&L is outweighed by losses from IL, a net rebalancing loss is reported
If rebalancing profits outperform losses from IL, a net rebalancing gain is reported
Either way, constant rebalancing typically improves IL outcomes as compared to regular positions.
The Solver's execution is highly dependent on the quality of the oracle price feed, which it uses to generate swap quotes.
The oracle price feed is provided by Pragma, a Starkware-backed company that provides oracle infrastructure for Starknet. In addition, we introduce safeguards by internalising a number of safeguards within the Solver logic itself.
In particular, Solver markets will be paused, preventing swaps and new deposits, whenever the oracle feed deteriorates in quality, either when:
A stale price quote is returned (e.g. older than 10 minutes)
A non-robust price quote is returned (e.g. it achieves consensus from <3 publishers)
min_spread
Spread applied to oracle price to calculate bid and ask quotes, before other adjustments
min_spread = 50
Bids start at oracle_p - 0.5% Asks start at oracle_p + 0.5%
range
The range of the virtual liquidity position used to calculate swap amounts, related to its slippage
range = 5000
min_spread = 50
Bid:
[oracle_p - 5.5%, oracle_p - 0.5%] Ask:
[oracle_p + 0.5%, oracle_p + 5.5%]
max_skew
The maximum portfolio skew of the pool, above which swaps are rejected if they worsen the skew
base_assets = 2000
quote_assets = 500
max_skew = 5000
(50%)
Skew = (2000 - 500) / (2000 + 500) = 60% > 50%
Buys are allowed, sells are rejected
max_delta
The amount by which bid and ask quotes are skewed to incentivise an improvement in inventory skew
max_delta = 500
skew = 50%
Delta = 50% * 500 = 250
Bid = Bid - 2.5% (incentivise buys)
Ask = Ask - 2.5% (discourage sells)