Balance Approximation
Metera - Balance Approximation on Deposit and Withdraw Operations
Last updated
Metera - Balance Approximation on Deposit and Withdraw Operations
Last updated
Currently in V1, underlying assets can´t be removed or added. To address this need, in order to re-balance the index to adjust the weights of assets to match the target weights, the rebalancing is done via transactions (e.g., making a deposit or withdraw).
The acceptance or rejection of a deposit or withdraw operation relies only on the weights present in the portfolio and the states of the MTK before and after the operation, more precisely, on the weights of the tokens in the MTK. We propose to measure the L1 distance[1] between the weights of the current MTK and the weights indicated by the oracle, and the L1 distance between the weights of the MTKafter the interaction and the weights indicated by the oracle. If the latter valuation is lower, the transaction is accepted.
Let’s define:
target balance as the weights vector described in the MTK,
current balance as the weights vector that can be measured from the MTK´s value,
distance to target of a token as the absolute value of the difference between the weights of the token in the current balance and the target balance,
balance measure of an MTK as the sum of the distances to the target of every asset in the MTK, divided by the total number of assets.
We say that one of these operations approximates the target balance if the balance measure of the MTK after the operation is lesser or equal to the balance measure before the operation. In this sense, we can define a boolean function approximatesBalance
, which takes the weights vector before and after the operation, and the weights vector provided by the MTK, and returns true if the condition mentioned above is met, otherwise it returns false:
Deposit Operation Fails
Deposit Operation Succeeds
Withdraw Operations
Withdraw operations examples are analogous, since the evaluation of the balance approximation criteria only depends on the index input and outputs states, and not on other inputs/outputs, mint/burn of MTK tokens, etc.
Deposit Function
Users may want to decide how much ADA they want to deposit in the index. We need then to have functionality that supports this input, and calculates an appropriate set of assets such that the whole input can be added to the index. This of course considers the needed amount of tokens for the index to be balanced, and if there was a remaining amount of user Ada input, then calculate the tokens to add according to the balance required.