# Behodler AMM

Behodler AMM orchestrates trades using an omnischedule bonding curve.The name is inspired by the Beholder of D\&D, a monster with multiple arms ending in eyes peering in all directions.

The Behodler is a smart contract that can see the prices of all tokens simultaneously without need for composition or delay. The hodl part of Behodler refers to the fact that with every trade, the liquidity of the respective token held by Behodler increases.

Behodler v1 demonstrated the utility of omnischedule token bonding curves in creating an AMM. The bonding token, Scarcity (SCX) became a medium of exchange to facilitate trading. In Behodler v2, the basic principles remain and Scarcity still plays the same role. However, computationally expensive algorithms such as square root calculations are no longer performed on chain. The entire calculation of the bonding curve movement is left to the calling client. Behodler simply validates the calculations were correctly performed which is computationally much cheaper. This system of Invariant Analysis is akin to the assymetry present in proof of work where calculating the correct hash is very expensive but validating is cheap. The process of trading has been simplified into the exchange equation:

```
Let b be the burn fee, a ratio. 
Let F = 1-b

_f signifies final balance of a token held in Behodler at the end of a trade. 
_i signifies initial balance of the token.
I is input token and O is for output token.

Therefore, I_f is the final balance of input token.

The exchange equation is then:

√F(√I_f - √I_i) = (√O_i - √O_f)/(F)
```

Because fees are levied on both Scarcity and Input in the implementation, the presence of F on both sides of the equation is not simplified.

## Smart Contracts:

<table><thead><tr><th width="150">Contract</th><th width="562">Description</th></tr></thead><tbody><tr><td><a href="https://github.com/Behodler/behodler2/blob/master/contracts/Behodler.sol">Behodler</a></td><td>Behodler AMM orchestrates trades using an omni schedule bonding curve</td></tr><tr><td><a href="https://github.com/Behodler/behodler2/blob/master/contracts/Lachesis.sol">Lachesis</a></td><td>Lachesis, one of the three Moirai, the inflexible, decides which tokens are active within Behodler.</td></tr><tr><td><a href="https://github.com/Behodler/behodler2/blob/master/contracts/Scarcity.sol">Scarcity</a></td><td>Scarcity is the bonding curve token that underpins Behodler functionality. SCX burns on transfer and also exacts a fee outside of Behodler.</td></tr><tr><td></td><td></td></tr><tr><td><a href="https://github.com/Behodler/behodler2/blob/master/contracts/WETH10.sol">WETH10</a></td><td>Wrapped Ethereum implementation</td></tr></tbody></table>

{% content-ref url="/pages/f6xOcEzi7GwSVzQvSBFI" %}
[Deployments](/dev/deployments/mainnet.md)
{% endcontent-ref %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.behodler.io/dev/smart-contracts/behodler-amm.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
