Skip to main content

Strategy Weights

For a based application, it is important to know how much capital each strategy has allocated to the bApp. This is because the bApp's security mechanism is based on the total capital at risk.

You can read more about the Risk Expressive Model here.

How to calculate the weights of a strategy

info

To do this programmatically, read this section in the Based Applications developer documentation.

To do this manually, follow the steps below and obtain the information by querying the Based Application Subgraph.

For all the strategies that opted-in to a given bApp, clients will need to:

1. Gather Obligated Balances

Get the obligated balance from each strategy, for each token used by the bApp.

ObligatedBalance mapping(Token -> Strategy -> Amount)

This is done by multiplying the percentage of obligated tokens by the balance of such tokens deposited to the strategy.

2. Sum Obligations

From ObligatedBalance, bApps should sum all obligations and compute the total amount obligated to the bApp by all strategies.

TotalBAppBalance mapping(Token -> Amount)

3. Calculate Risk

For each token, it should get the risk (token-over usage) of each strategy. This is obtained by summing all the percentages in all Obligations for a given token, and dividing it by 100.

Risk mapping(Token -> Strategy -> Float)

4. Compute Risk-Aware Weights

With this information, bApps can compute the weight of a participant for a certain token by

Wstrategy, token=ctoken×ObligatedBalance[token][strategy]TotalBAppBalance[token]eβtoken×max(1,Risk[token][strategy])W_{\text{strategy, token}} = c_{\text{token}} \times \dfrac{ObligatedBalance[\text{token}][\text{strategy}]}{TotalBAppBalance[\text{token}]} e^{-\beta_{\text{token}} \times max(1, Risk[\text{token}][\text{strategy}])}

where ctokenc_{\text{token}} is a normalization constant defined as

ctoken=(strategyObligatedBalance[token][strategy]TotalBAppBalance[token]eβtoken×max(1,Risk[token][strategy]))1c_{\text{token}} = \left( \sum_{\text{strategy}} \dfrac{ObligatedBalance[\text{token}][\text{strategy}]}{TotalBAppBalance[\text{token}]} e^{-\beta_{\text{token}} \times max(1, Risk[\text{token}][\text{strategy}])} \right)^{-1}

5. If the bApp uses validator balance

The client should also generate a mapping of Strategy -> Validator Balance with the amount from each strategy. Clients will need to do this in a couple of steps:

a. Gather Delegated Balances: Get all the delegations made to the owner of a strategy for all the strategies that opted in to a bApp.

DelegatedBalance mapping(Strategy -> Amount)

Bear in mind, these are stored as percentages. The effective validator balance can be looked up the beacon chain (the based-apps-sdk provides a function to do this: getValidatorsBalance(account)), and then multiplied by the percentage that is delegated. These values need to be summed, in order to obtain the delegated balance for each owner.

b. Sum all delegated balances for all strategies.

TotalBAppDelegatedBalance mapping(Validator Balance -> Amount)

d. Compute Weights. As this capital doesn't involve any type of risk, all risk values can be set to 0. Thus, for this capital, this is equivalent to:

Wstrategy, validator balance=ObligatedBalance[validator balance][strategy]TotalBAppBalance[validator balance]W_{\text{strategy, validator balance}} = \dfrac{ObligatedBalance[\text{validator balance}][\text{strategy}]}{TotalBAppBalance[\text{validator balance}]}

6. Combine into the Final Weight

With the per-token weights, the final step is to compute a final weight for the participant using a combination function. Such function is defined by the bApp and can be tailored to its specific needs. Traditional examples include the arithmetic mean, geometric mean, and harmonic mean.

Example: Let's consider a bApp that uses tokens AA and BB, and considers AA to be twice as important as BB. Then, it could use the following weighted harmonic mean as its combination function:

Wstrategyfinal=cfinal×12/3Wstrategy, A+1/3Wstrategy, BW^{\text{final}}_{\text{strategy}} = c_{\text{final}} \times \dfrac{1}{\dfrac{2/3}{W_{\text{strategy, A}}} + \dfrac{1/3}{W_{\text{strategy, B}}}}

where cfinalc_{\text{final}} is a normalization constant computed as

cfinal=(strategy12/3Wstrategy, A+1/3Wstrategy, B)1c_{\text{final}} = \left( \sum_{\text{strategy}} \dfrac{1}{\dfrac{2/3}{W_{\text{strategy, A}}} + \dfrac{1/3}{W_{\text{strategy, B}}}} \right)^{-1}