---
# System prepended metadata

title: Decentralized Yearn Vault Allocation

---

# Decentralized Yearn Vault Allocation

**Repos**
STARKDebtAllocator: https://github.com/0xSacha/debtAllocatorLendingVaultV3
Yearn V3 Vaults: https://github.com/jmonteer/yearn-vaults-v3

## The problem
Figuring out the best debt allocation between strategies of a vault is complex. It requires frequent updates due to market conditions changes and cannot be delegated to the public to due to its importance. It is usually a point of centralization that requires to trust a set of players to do the best work.

## The idea
1. Create a set of pre-agreed upon rules that need to be respected by any debt allocation (how to calculate APR per strategy, max debt per strategy, assumptions to use for calculating APR, ..). This is done at strategy deployment time and can be updated by governance.
2. Create a mechanism for anyone to be able to prove that it followed the rules to find a solution, without asking them to reveal the mechanism they used to find that solution
3. Create a rewards mechanism: pay per second that the solution is used
4. Let anyone propose the optimal debt allocation

We believe that if the reward is paid per second, there's always an incentive to push a better debt allocation if possible (i.e. the current solution is not optimal for current market conditions). 

This allows the protocol to decentralize tasks that require sensible work in a safe way and reward ANY player offering solutions, turning the task into a constant competition with a fixed cost for the protocol, open to anyone to participate.

## The solution
We created a DebtAllocator contract ([find here](https://etherscan.io/address/0x08677d13ea8ef4bfc39c71477f5420352038306e)) that implements the above stated idea. Repo: https://github.com/0xSacha/debtAllocatorLendingVaultV3#starkdebtallocator

#### Verifiable Computation
To verify that the rules were followed by the solution proposer, we use STARKs, Starkware's Cairo, Verifiers, and SHARP.

STARKs allow anyone to prove that used a pre-agreed upon program (set of rules, code, ...) to calculate the outputs. Verifying it is a lot cheaper in terms of computation than replicating the computation that is being proved

#### Rewards
For rewards, we use LlamaPay streams, that are directed to the current proposer until a new solution comes in. Find code here: https://github.com/0xSacha/debtAllocatorLendingVaultV3/blob/ab759f6f54cde4375acf234764ff24bf0c91e666/contracts/DebtAllocator.sol#L289

Currently working stream: https://llamapay.io/salaries/withdraw/Ethereum/0x64750a3a179e3c1cb8773ed7f0cec510155e982783e16a7c8339475345028b18

#### Operations
Every new solution proposal has 4 steps: 
1. Taking a snapshot of blockchain state, extracting variables required to check the rules. These will be used as input for calculations (on-chain `saveSnapshot`)
2. Finding an optimal solution (off-chain, private and propietary code)
3. Generating the proof (sending Execution Trace to Starkware's Prover)
4. Sending the solution to DebtAllocator contract (on-chain `verifySolution`). Once the proof is verified on-chain

#### Pre-requisites
- DebtAllocator is a contract that has the DEBT_MANAGER, ACCOUNTING MANAGER and KEEPER roles in a yearn v3 vault (e.g. [this one](https://etherscan.io/address/0x2438960887b40f1812ec28ebfe2f229d6136bcf7); repo https://github.com/jmonteer/yearn-vaults-v3 (currently in audits))
- DebtAllocator has been correctly set up (i.e. strategies for the mentioned vault has been added to the DebtAllocator vault). Some example tx: [1](https://etherscan.io/tx/0x3db221ee83d383963a9ef62801159776697542e0c049a10a48fd4f84f44c03a3), [2](https://etherscan.io/tx/0x94bd63386208bda5dca3a2ff1c614ac53761abeec2b293952129a96250395da7), [3](https://etherscan.io/tx/0xb620a145c80c0d551270d0d2fcf7a0a7c602ba0b4f73ab8cb12c0f3940f4984d)


#### Working in prod example
Save Snapshot
https://etherscan.io/tx/0xa21460e1060943b9fa7deeb806b8a7897e6cd7432a335b3e4deeb0076eb6b63a

Verify Solution (and rebalance of strategies in a vault)
https://etherscan.io/tx/0xb4c0f14c2760f682306cddb2f39dc4a5707be19911ced5a6611e0d0a16014622

Claim Rewards
https://etherscan.io/tx/0x90737d9bcc08fb2257769302bc928786d3c3e9e0b4c26e4977df70024bd011e2

