# Sifchain Rebalancing Policy
[Return to README](https://hackmd.io/Hcp07U4OT3i9UfZtH_-oDQ)
The rebalancing policy ensures that the revenue earned by participants in the validator system and the liquidity system are balanced at preset target ratios $\gamma_t, \gamma_v, \gamma_l$ and $\gamma_c$, determined through an external governance process.
The rebalacing policy informs the control rules within each subsystem so as to drive incentives towards error minimization.
We want to design a rebalancing policy in a 3-dimensional stochastic vector that represents a basin of attraction, wherein the stable equilibrium are defined as the point where: $$\rho_v = \gamma_v$$ $$\rho_l = \gamma_l$$ $$\rho_f = \gamma_f$$
This method scales to an arbitrary n-dimensional stochastic vector where each dimension represents a subsystem, which presents a way to regulate the effects of external economies that are composable to Sifchain. We've stubbed in a hypothetical future subsystem to highlight this feature.
Due to the property of ratios we can compute the residual or slack supply that constitutes the circulating economy like so $$\rho_v + \rho_l + \rho_f+ \rho_c = \gamma_v + \gamma_l+ \gamma_f + \gamma_c = 1$$ $$\rho_c = 1-(\rho_v + \rho_l + \rho_f)$$ $$\gamma_c = 1 -(\gamma_v + \gamma_l + \gamma_f)$$ This ensures that the circulating supply is balanced $$\rho_c = \gamma_c$$
The point where $\rho_v = \gamma_v$, $\rho_l = \gamma_l$ , $\rho_f = \gamma_f$ and $\rho_c = \gamma_c$ is the joint stable equilibrium between the 4 dynamical systems: the Validator Subsystem, the Liquidity Provider Subsystem, a Future Subsystem, and the Circulating Economy.
<!-- VERSION 3 -->
![](https://i.imgur.com/1qFo6oL.png)
<!-- VERSION 2 ![](https://i.imgur.com/MtbFqQT.png) -->
<!-- VERSION 1 ![](https://i.imgur.com/tstkR4i.png) -->
## Policy Inputs
The input to the control system is the observed current state of the system, represented by a vector of ratios, $\overrightarrow \rho$.
- The observed proportion of supply in Validator Subsystem ${\rho_v}$
- The observed proportion of supply in Liquidity Provider Subsystem ${\rho_l}$
- The observed proportion of supply in Future Subsystem ${\rho_f}$
- The observed proportion of supply in Circulating Economy ${\rho_c}$
$$\overrightarrow \rho = \left\{{\rho_v}, {\rho_l}, {\rho_f}...{\rho_c} \right\} $$
Each ratio component, $\rho_{x}$, is defined as its portion of the supply with the respect to the total supply:
$$\rho_{X} = \frac{\mathbf{S_X}}{\mathbf{S}}$$
This formulation allows for composition of any two sets of supply. For example, if the ratio supply staked in validation to the circulating supply desired, then it can be obtained according to its $\rho$ components:
$$ \frac{\mathbf{S_v}}{\mathbf{S_c}} = \frac{\rho_v}{\rho_c}$$
Economic metrics can be defined to compare subsystems against other subsystems. The performance of a particular subsystem in attracting activity from the circulating economy can be defined in this manner. We can define any combination of relative economic ratios in this manner, where the economy in subsystem is $x$ compared to any partition $y$ is defined as:
$$ \rho_{x,y} = \frac{\mathbf{S_x}}{\mathbf{S_y}} = \frac{\rho_x}{\rho_y}$$
The relative set of these comparative metrics may be used in reporting and analytics to support user, investor, and governance decisions. However, no relative of these relative metrics should be used directly in the control policy, because these metrics will not be bound in the domain $[0,1]$. Therefore, a misalignment would likely be introduced both in target setting and balancing with respect to other susbsystems.
The control parameter, $\overrightarrow{\lambda}$ is defined as the set of components:
$$\overrightarrow{\lambda} = \{\lambda_v, \lambda_l,\lambda_f...\lambda_c\}$$
## Error
The error term, $\overrightarrow{\epsilon}$ , in the controller is defined as the difference between the goal ratio and the observed ratio, where ratios are serving as indicators of economic activity:
$$\overrightarrow{e} = \overrightarrow{\gamma} - \overrightarrow{\rho}$$
The error function is defined as:
$$\Psi(\overrightarrow{\rho}) = \Vert\overrightarrow{\gamma} - \overrightarrow{\rho}\Vert^2 $$
## Objective Function
The error function provides an update to $\overrightarrow{\lambda}$ such that the update must result in decreasing the error function. Thus, the difference should be decreasing:
$$\nabla \Psi(\overrightarrow{\rho}) < 0 $$
There is an expectation that this condition can be realized but not enforced through the behavior of actors on the system:
$$\mathbb{E}[\nabla \Psi(\overrightarrow{\rho}) \vert \mathcal{B}] $$
## Control Function
![](https://i.imgur.com/3mNGyab.png)
Proportional control provides the update to $\overrightarrow{\lambda}$ through directional gain.
If $\overrightarrow{\lambda}$ is vectorized as:
$$ \left[ \begin{array}{1} \lambda_v \\ \lambda_l \\ \lambda_f \\ . \\. \\ . \\ \lambda_c \end{array} \right] $$
$$\overrightarrow{\lambda}^+ = K_p\overrightarrow{\lambda}$$
where:
$$ K_p = \left[ \begin{array}{4} K_v & 0 & 0 & 0\\ 0 & K_l & 0 & 0 \\ 0 & 0 & K_f & 0 \\ 0 & 0 & 0 & K_c\end{array} \right] $$
In the case of only considering the validator and liquidity subsystem in this control policy, $K_P$ reduces to:
$$ \left[ \begin{array}{2} K_l & 0 \\ 0 & K_v\end{array} \right] $$
In order to acheive directional correction over the error $e$, the sign of the error partitions the policy into a piecewise function.
### Control Parameter Update
$$\overrightarrow{\lambda}^+ = \begin{array}{rcl}
1 - (1- |e|)\cdot(1-\lambda) & \mbox{for}
& e>0 \\ (1- |e|)\cdot \lambda & \mbox{for} & e < 0
\\ \lambda & \mbox{for} & e = 0
\end{array}$$
* Note for $e = 0$, either of the piecewise partitions may be used, as each partition resolves to $\lambda$.
#### Psuedocode Implementation
```
error = gamma - rho
control = lambda
if error > 0:
lambda = 1 - (1- np.abs(error)) * (1 - control)
else:
lambda = (1- np.abs(error)) * (control)
```
### Parameter Update Edge Cases
The maximum correction occurs when $|e| =1$, although this extreme value is an edge case that is not actually achievable. The entirety of the supply would have to be completely committed to its portion of the economy $\rho$, with the desired portion $\gamma$ being set to the to opposite extreme.
In the case where $e = -1$, meaning $\gamma$ set to 0 and $\rho$ being 1, the maximum change to $\lambda$ is $-\lambda$. (See Appendix A) The lowest any given lambda can become is zero. This ensures that $\lambda$ cannot become negative.
In the case where $e = 1$, meaning $\gamma$ set to 1 and $\rho$ being 0, the maximum change to $\lambda$ is $1-\lambda$. (See Appendix B) If $\lambda$ was 0, $\lambda^+$ would become 1 and if $\lambda$ was 1, $\lambda^+$ would become 0. This ensures that $\lambda$ cannot be greater than 1.
### Gain Control over Update Rate
$K$ can be introduced into the control function to exercise control over the rate at which $\lambda$ will update in response to $e$.
$$\overrightarrow{\lambda}^+ = \begin{array}{rcl}
1 - \frac{(K- |e|)}{K} \cdot(1-\lambda) & \mbox{for}
& e>0 \\ \frac{(K- |e|)}{K}\cdot \lambda & \mbox{for} & e < 0
\\ \lambda & \mbox{for} & e = 0
\end{array}$$
* Note for $e = 0$, either of the piecewise partitions may be used, as each partition resolves to $\frac{K}{K}\lambda$ or just $\lambda$.
Where $K \geq 1$.
For the $K=1$ edge case is equivalent to the control function without control over the update rate. In all other cases, $K$ must chosen greater than 1.
Any $K < 1$ introduces the possibility that $K < |e|$, which would cause $\lambda$ to exceed 1 in the first partition and become negative in the second partition, violating the domain of $\lambda$ at both ends.
The choice of $K$ should be made in conjunction with the frequency with which this module would be called. If attenutating the response is desired, higher values of $K$ would be associated high frequency (i.e. by block or hourly) calls of this module. If the rebalancing frequency is slower (i.e. daily or weekly), then lower values of $K$ are more likely to be recommended.
#### Psuedocode Implementation
```
if error > 0:
lambda = 1 - (K- np.abs(error)) / K * (1 - lambda)
else:
lambda = (K - np.abs(error)) / K * lambda
```
### Bound
Introduce $\epsilon$ as a bound on both upper and lower values of $\lambda$. While approaching the edge cases of 0 and 1 are not a problem in a numerical environment, implementation on a blockchain presents a risk where approaching the edges of 0 and 1 can result equalling that value.
As a measure of safety against this rounding to 0 or 1, we can impose a small value bound, $\epsilon$, on the update to the control function where:
$$\epsilon < \lambda^+ < (1-\epsilon)$$
Thus:
```
if lambda_update > 1 - bound:
lambda_update = 1 - bound
if lambda_update < bound:
lambda_update = bound
```
### Small Error Handling
While the rebalancing policy is continuous at $e=0$, there is a case to be made that computation around repeated $e \approx 0$ values would not be valuable. While near zero error of a subsystem would indicate effective institution of a policy towards a targeted economy, we would want to avoid both unnecessary computation and the risk of inducing a hysteresis.
We can introduce a small value delta, $\delta$ where the error must be greater than in order to proceed with computing the updated rebalancing parameter for that subsystem. This produces a condition for proceeding with a valid update on $\lambda$:
$$\overrightarrow{\lambda}^+ = \begin{array}{rcl}
1 - \frac{(K- |e|)}{K} \cdot(1-\lambda) & \mbox{for}
& e>0 \\ \frac{(K- |e|)}{K}\cdot \lambda & \mbox{for} & e < 0
\\ \lambda & \mbox{for} & e = 0
\end{array}$$
**For: $|e| \geq \delta$**
#### Psuedocode Implementation
``` python
if |error| < delta:
return previous_lambda_value
if |error| >= delta:
proceed with rebalance
```
### Update Frequency
The rebalancing policy update frequency is expected to occur every block. Likewise, every subsystem within the purview of the rebalancing policy should be updated at the same rate.
Failure to update one subsystem and not another would create incentive misalignment and introduce attack vectors capitalizing on this misalignment. This represents propogation failure of the control signal, where the control signal propogates too slowly.
There is also the case where a subsystem could update its activity at a frequency greater than the reblancing policy update. This again cannot be done without filtering the incoming signal from the subsystem. Again, this case should be avoided and cannot wihtout computing some average signal if the update to rebalnacing were to occur greater than block time (lower frequency).
### Target and Activity Proportion Range of Values
The rebalancing policy acts on the difference between a target proportion and actual activity proportion, and may be extended to more future developed subsystems. Both the target, which may be set through governance, and activity proportions have well-defined ranges of values that they make take on due to their proportional definition and this definition lends itself to that extendibility.
The space of $\rho$ where each component is dependent upon the remaining slack variable. Governance over the choice of $\gamma$ is a point (in the case of 2 subsystems) within this space.
![](https://i.imgur.com/TieH77i.png)
### Appendix A: Edge Case of $e = -1$
1. Negative $e$ partition of $\lambda^+$ function: $$\overrightarrow{\lambda}^+ = (1- |e|)\cdot \lambda$$
2. Adding a $-\lambda$ to both sides: $$\overrightarrow{\lambda}^+ - \lambda = (1- |e|)\cdot \lambda - \lambda$$
3. Distributing: $$\overrightarrow{\lambda}^+ - \lambda = \lambda - |e|\cdot \lambda - \lambda$$
4. Simplifying: $$\overrightarrow{\lambda}^+ - \lambda = -|e|\cdot \lambda$$
5. Substituting $e = -1$: $$\overrightarrow{\lambda}^+ - \lambda = - \lambda$$
### Appendix B: Edge Case of $e = 1$
1. Positive $e$ partition of $\lambda^+$ function:$$\overrightarrow{\lambda}^+ = 1 - (1- |e|)\cdot(1-\lambda)$$
2. Distributing: $$\overrightarrow{\lambda}^+ = 1 - [1 - \lambda - |e| + |e| \cdot \lambda] $$
3. Simplifying: $$\overrightarrow{\lambda}^+ = 1 -1 + \lambda + |e| - |e| \cdot \lambda $$
4. Simplifying: $$\overrightarrow{\lambda}^+ - \lambda = |e| -|e|\cdot \lambda$$
5. Substituting $e = 1$: $$\overrightarrow{\lambda}^+ - \lambda = 1 - \lambda$$