> For the complete documentation index, see [llms.txt](https://positron-3.gitbook.io/pos/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://positron-3.gitbook.io/pos/how-it-works/interactive-blocks.md).

# How we optimize across pools

## Band Optimisation

We define a quality function

$$
Q:{1,\dots,N}\times {1,\dots,P}\to\mathbb{R}\_{\ge 0},
$$

where $$Q(t,p)$$ is the quality of tick $$t$$ in pool $$p$$. $$Q$$ is a function of market signals (liquidity depth, trading volume, fee generation, IL risk, historical performance, etc.) and estimates how much work a unit of liquidity is expected to do at that tick. Apart from market signals, $$Q$$ is also a function of the desired LP Range and Liquidity.&#x20;

The goal is to choose bands (price ranges) across pools to efficiently maximize total quality, while respecting execution costs, minimum band size, slippage protection, and protocol rules.&#x20;

{% hint style="info" %}
Importantly, we must keep the aggregate liquidity of the bands consistent with the user's desired LP range and input liquidity L, but shift liquidity allocation towards higher-quality ticks. This way the aggregate position remains exactly equal to the users desired range.&#x20;
{% endhint %}

***

### Pools and Ticks

For each pool $$p$$, let its available ticks be

$$
\bigl(P\_p(1),,P\_p(2),,\dots,,P\_p(N\_p)\bigr),
$$

where $$P\_p(i)$$ returns the $$i$$-th available tick in pool $$p$$.

> Note: different pools can have different tick spacings; their available ticks may not overlap. We solve this by transforming different pools into a shared domain where we can compare implied prices - not included here for simplicity.&#x20;

***

### Bands

A band for pool $$p$$ is a contiguous set of ticks, specified by pool indices $$1\le j\<i\le N\_p$$ and covers the tick range

$$
\bigl\[P\_p(j),,P\_p(i)\bigr);=;{,P\_p(j),P\_p(j{+}1),\dots,P\_p(i{-}1),}.
$$

Per-pool prefix sums (used to reduce time complexity for $$S$$):

$$
F\_p(u)=\sum\_{v=1}^{u} Q\bigl(P\_p(v),p\bigr).
$$

Band quality is defined as the sum of the quality of ticks in its set:

$$
S(p,j,i)=\sum\_{u=j}^{i-1} Q\bigl(P\_p(u),p\bigr)=F\_p(i-1)-F\_p(j-1).
$$

> Note: bands can be extended to take any proportion of desired liquidity in Uni-V2 and V3 style liquidity.&#x20;
>
> For instance, a Uni-V2 LP range of liquidity L could be split into 4 overlapping bands, such that their individual liquidities sum to L.&#x20;

***

### Constraints on Bands

Minimum band length: we enforce a minimum length of each subposition

$$
i-j\ \ge\ L\_{\min}.
$$

Stabilisation: band boundaries must lie outside a window around the reference price $$t'$$

$$
P\_p(j)\notin \[,t'-w,\ t'+w,],\qquad
P\_p(i-1)\notin \[,t'-w,\ t'+w,],
$$

with $$w$$ widened under higher volatility to minimize slippage.&#x20;

> Note: slippage only affects in-range bands

Edge slack: for any given LP range, allow skipping up to $$E$$ ticks at each extreme.

This is to avoid forced short edge bands, and it means we could slightly shorten or elongate an LP range. This slack lets us be unconstrained by only using pools with small tick spacings at the edges.&#x20;

***

### Optimisation

Each candidate band $$(p,\[j,i))$$ has an integer cost $$c(p;j,i)\ge 1$$. With total budget $$K$$ (this allows us to restrict the total selected bands to an integer, by default 4, we can define c to work with any protocol-level restrictions):

$$
\max\_{\mathcal{B}\subseteq{(p,\[j,i))}}
\ \sum\_{(p,\[j,i))\in\mathcal{B}} S(p,j,i)
\quad
\text{s.t.}\quad
\sum\_{(p,\[j,i))\in\mathcal{B}} c(p;j,i)\ \le\ K,
$$

and every band in $$\mathcal{B}$$ satisfies our constraints.

Let $$V(i,k)$$ be the maximum total quality using budget $$\le k$$. Initialise with edge slack $$E$$:

$$
V(s,0)=0\ \ (0\le s\le E),\qquad
V(i,0)=-\infty\ \text{otherwise}.
$$

Solve the recurrence (for all pools $$p$$ and starts $$j\<i$$ valid in that pool):

$$
V(i,k)=\max\_{\substack{p,\ j\<i\\
c(p;j,i)\le k\\
i-j\ge L\_{\min}\\
P\_p(j),,P\_p(i-1)\notin\[,t'-w,\ t'+w,]}}
\Bigl{,V\bigl(j,,k-c(p;j,i)\bigr)+S(p,j,i)\Bigr}.
$$

$$
\operatorname{OPT}=\max\_{\substack{k\le K\ i\ \text{near the right edge}}} V(i,k),
$$

OPT will be the maximum quality bands subject to our constraints.&#x20;


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://positron-3.gitbook.io/pos/how-it-works/interactive-blocks.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
