# The hAIrberger Protocol

## Problem / Current Situation:

A static liquidity provider strategy in a dynamic market leads to:
- impermanent loss
- reduced earnings

Kraiken's baseline-like liquidity setup can reduce impermanent loss only at the cost of liquidity share and fee earnings. Token-printing-priviliges gives unfair advantage, but not forever.

## Succesfull/Dynamic LP strategies use indicators:
onchain:
- current and historic price
- current and historic volume
- current and historic liquidity distribution

offchain:
- TA
- Macro
- Sentiment

## Making the Kraiken LP strategy dynamic

- **Oracle Problem \#1:** The offchain indicators can not be used by decentralized communities at all, having a unsolved oracle trust issue.
    - use staking, an egoistic marketplace, as data source for sentiment
        - % staked
        - average tax rate
        => egoistic oracle marketplace

- **Using historic data:** The onchain indicators need to be digested, e.g. TA to get signals.
    - algorithmic trading / backtesting => model => deep learning
    - fold historic data into AI model training

- **Oracle Problem \#2:** Any algorithm running offchain can not be trusted by community. AI models can not run onchain. Trained models can't react to real-time data (see LMM knowledge cutoff).
    - use on-chain algorithm that works with real-time data, historic knowledge and limited gas
    => **follow-up problem:** "write an algorithm that uses limited gas to maximize fees earned, starting with no training data."
    
- **Metaheuristic:** is a higher-level procedure  designed to find, generate, and tune partial search algorithm that may provide a sufficiently good solution to a machine learning problem, especially with incomplete or imperfect information or limited computation capacity.
    - **Genetic algorithms** are used to generate solutions to optimization problems via biologically inspired operators such as selection, crossover, and mutation.
    - selection can be applied on:
        - gas usage
        - fees earned after running scenarios
            - scenarios can be replaced by historic trading data after launch of project
    - result of evolution (latest generation) can be deployed onchain and integrated into recenter
        - recenter() => getDynamicLiqParams() => _scrapePositions() => _setPositions()
        - function getDynamicLiqParams(inputs) returns (params) is an EA living in upgradeable contract
    => **follow-up problem:** EVM op-codes can not be used in Evolution, too much grammar
    => **follow-up problem:** upgradeable contract needs governance
    
- **Evolving Stack Machines** instead of reverting, invalid op-codes should be ignored. 
    - [Push3 by Lee Spector](https://www.youtube.com/watch?v=ryW9w5cAwaI)
    => implement Push3 runtime in solidity
    
- **Governance** tbd
    
## Conclusion
- a dynamic strategy is possible, first using human-generated solutions (sentiment function), and later upgrading into GA.
- basic governance to be solved before GA.
