# Fund Allocation

Last updated

Last updated

Fund Allocation Rules

High-yield liquidity pools have allocation priority.

The capital invested in a single liquidity pool cannot exceed 20% of the total assets under management.

The capital allocated to a single liquidity pool cannot exceed 50% of their existing lock-up amount.

The total capital invested on different liquidity pools from the same protocol cannot exceed 30% of the total assets under management.

Funds allocation is adjusted automatically to ensure the most cost-efficient position.

Fund Allocation Mechanism

doHardWork

doHardWork is also known as the first fund allocation onto strategies. The inputs into the position adjustment of the algorithm are the official APY of the third-party protocol, the gas required for investment of each strategy, the limit of exchange slippage, and the rules of fund allocation. Meanwhile, the strategy and amount of the funds to be invested are the outputs.

Parameters

Set parameters | ETH | Polygon |
---|---|---|

Allocation / Position Adjustment

Compared with `doHardWork`

, `allocation`

has an additional step: it withdraws the funds of the low APY strategy, then uses the official APY of the third-party protocols, the gas required for investment of each strategy, the exchange slippage limit, fund allocation rules, and the position adjustment algorithm as inputs, and the outputs are the strategy and the amount of the awaiting investment funds.

Procedure

The position adjusting process mainly includes the following steps:

Invoke the optimal matching algorithm, allocate Vault funds, and issue a position adjustment report.

Lock-up; users will not be able to perform investment and redemption operations at this time.

According to the position adjustment report, perform the redeem operation on the strategy that needs to withdraw funds to return the funds to the Vault.

Calculate the currencies (token type(s)) and the amount needed for strategies investments.

Execute tokens swapping.

Invest the funds (swapped tokens) into the strategies.

Terminate the lock-up and complete the position adjustment.

Parameters

Fund Allocation Algorithm

**Profit before position adjustment**

**Changed earnings**

**Changed apr**

After substituting apr2 in gain2 using the above equation:

Hence the relationship between the changed income of a single strategy and the changed assets is:

**Cost of changing funds for a single strategy**

Find the maximum sum of `deltaGain`

for all strategies:

In the formula above (profitChange), the only variable is the deltaAsset for each strategy. Meanwhile, the solution needs to be limited by:

**Restrictions**

The same protocol strategy (multiple constraints) funds do not exceed 30% of the total funds.

The sum of all asset changes in and out is 0.

**Boundary conditions**

Strategic assets do not exceed 20% of the total assets.

The strategic funds do not exceed 50% of the targetted pool assets.

Use python scipy's `optimize.minimize`

to find the current optimal rebalancing scheme.

Public Parameter Configuration

Strategy APY Calculation

Strategy profits are mainly obtained from the four sources of yield as below:

Governance token rewards.

DEX market-making fees.

Interest from over-collateralized lending.

Rewards from ETH2.0 staking.

In particular, for the ConvexIronBank protocol, BoC needs to pay a borrowing interest, therefore yields are negative.

Official APY Calculation Rules

Governance tokens yield

Obtain the mining rate and mining coverage period of the pool of the start block and the end block respectively.

According to the data obtained in Step 1 above, calculate the average mining rate in a day, and calculate the total number of governance tokens that can be received by the pool in a day

Based on the weighted totalSupply amount within 24 hours, the total principal of the reward pool is calculated.

Divide the total value of governance tokens received by the pool by the total principal of the pool, and annualize the income to obtain the APR rewarded by Curve (CRV).

Convert APR to APY.

DEX market-making fees

To obtain the rate of change of the targeted contract LP in net value. Taking the liquidity income provided by Curve as an example, the program obtains the two block heights within 24 hours in the past day, and obtains the virtualPrice of the two blocks using `getVirtualPrice()`

. The rate of change is then calculated and annualized.

Interest from over-collateralized lending

To obtain the value of the loan rate interface of the targeted contract. Taking the lending interest provided by DForce as an example, the program obtains the two block heights within 24 hours of the past day, and uses `getSupplyTokenData()`

to obtain the lending rate values of the two blocks before annualizing them.

Rewards from ETH2.0 staking

The protocol strategies holding wstETH and rETH will enjoy ETH2.0 staking rewards. Taking the protocol strategy holding wstETH as an example, the program obtains the two block heights within 24 hours in the past day, and uses `stEthPerToken()`

to obtain the change of the net value of the two blocks before annualizing them.

Interest borrowing

In order to avoid the risk exposure of holding foreign exchange tokens[particularly the ConvexIronBank-like protocol(Convex)], foreign exchange will be borrowed by collateralizing USDC in the IronBank protocol. Therefore, the BoC needs to pay a borrowing interest, the yield is thus negative.

The program obtains the borrowing rate of the two block heights in the IronBank foreign tokens contract within 24 hours in the past day by using `getBorrowInterest()`

, and annualizing the averaged value of that to borrow interest.

Verified APY Calculation Rules

BoC Verified APY includes Realized APY and Unrealized APY. The daily scheduled task of the program generates the Verified APY of the day before:

Governance tokens yield

The strategy's governance token revenue is recovered by executing the `harvest()`

method.

web3 supports simulating the writing method of calling the contract to get the returned result, which is the basis for the program to obtain Unrealized APY. The program calculates the `harvest()`

method under the daily start and end blocks to obtain the type and quantity of governance tokens that can be recovered by the strategy in that particular harvest.

The operational logic of the current strategy is to do the harvest at UTC 22:00:00. Regardless of whether the strategy does Harvest on that day, the strategy will have daily Unrealized APY. This is due to the presence of uncovered profits after the strategy harvest between UTC 22:00:00~UTC 23:59:59, which is also categorized as Unrealized APY.

As for the yield of Unrealized APY, since there is no actual selling action, the APY of the day is estimated and calculated by obtaining the exchange rate of the governance token to USD/ETH under the current block, and the next time when the actual selling is done, the price will be written back and updated. Unrealized APY will also be verified and converted into Realized APY.

DEX market-making fees

The basic income of the day is calculated by accumulating the income during the operation period of the strategy in that day. By default, the DEX market-making income is issued in real time, which is categorized as Realized APY. Taking the liquidity income provided by Curve as an example, the main calculation process is as follows:

Read the operations of the strategy on a daily basis: lend/withdraw/redeem/harvest.

Calculate the profit in each operation segment within the one-day range through Curve's

`getVirtualPrice()`

.After accumulating the income of each segment, calculate the APR with the weighted principal of the day.

Interest from over-collateralized lending

Similar to the DEX market-making income, the program calculates the APR by accumulating the interest sum of all operating periods of the strategy within a day and the weighted principal of that day. The default interest is charged in real time, which is categorized as Realized APY.

Rewards from ETH2.0 staking

Similar to the DEX market-making income, the program calculates the APR by accumulating the staking rewards of all operating periods of the strategy within a day and the weighted principal of that day. The default staking reward is charged in real time, which is categorized as Realized APY.

Interest borrowing

Similar to the DEX market-making income, the program calculates the APR by accumulating the interest borrowed sum of all operating periods of the strategy within a day and the weighted principal of that day. The default interest borrowed is charged in real time, which is categorized as Realized APY.

Set parameters | ETH | Polygon |
---|---|---|

Variable | Meaning |
---|---|

$gain1 = \frac{asset1 \times apr1 \times durationDays}{yearDays}$

$gain2 = \frac{(asset1+deltaAsset-exchangeLoss)\times apr2 \times durationDays}{yearDays}$

$apr2 = \frac{apr1 \times poolAssets1}{(poolAssets1+deltaAsset-exchangeLoss)}$

$gain2=\frac{apr1 \times durationDays/yearDays \times (asset1+deltaAsset) \times poolAssets1}{poolAssets1+deltaAsset-exchangeLoss}$

$deltaGain = gain2-gain1 = \frac{deltaAsset \times (poolAsset1-asset1) \times apr1 \times durationDays}{(poolAsset1+deltaAsset-exchangeLoss) \times yearDays}$

variable name | Details |
---|---|

$profitChangeFee=withdrawFee+lendFee+exchangeLoss+harvestFee$

$withdrawFee = gasPrice \times withdrawGas$

$lendFee= gasPrice \times lendGas$

$exchangeLoss=deltaAsset \times exchangeLossRate$

$harvestFee=harvestGas \times durationDays$

$profitChange=MAX\sum_{i=1}^m(deltaGain_i -withdrawFee_i-lendFee_i - exchangeLoss_i-harvestFee_i)$

$profitChange=MAX\sum_{i=1}^m(\frac{deltaAsset_i \times (poolAsset_i-asset_i) \times apr_i * durationDays_i}{(poolAsset_i+deltaAsset_i-exchangeLoss_i) \times yearDays_i}$

$- operateFee_i - exchangeLoss_i - harvestFee_i)$

Set parameters | ETH | Polygon |
---|---|---|

$baseApr = \frac{endVirtualPrice - startVirtualPrice}{startVirtualPrice} \times 365$

$baseApr = \frac{startSupplyTokenData[0]- endSupplyTokenData[0]}{2}$

$baseApr = \frac{endstEthPerToken - startstEthPerToken}{startstEthPerToken} \times 365$

$baseApr = -\frac{endBorrowInterest + startBorrowInterest}{2} \times oneDayBlocks \times 365$

$Verified APY = Realized APY + Unrealized APY$

Scheduled Task Trigger Cycle

7 am daily besides Mon.

7 am daily besides Mon.

Cost-benefit Calculation Period X (If the profit of investment X days >= cost, “doHardwork” can be done)

365 days

365 days

Pre-adjusted position report trigger timing

every Sun. (after doHardWork)

every Sun. (after doHardWork)

Scheduled task trigger cycle

7 am every Monday

7 am every Monday

Cost-benefit calculation period X (If the profit of rebalancing X days >= cost, “allocation” can be done)

30 days

30 days

"durationDays"

The cycle of rebalancing needs to ensure that in a cycle after rebalancing, $the profit after rebalancing - the profit before rebalancing - the cost of rebalancing > 0$ (has to be greater than 0)

"yearDays"

365days

"asset1"

The original assets of the strate