I put together a beacon-chain accounting design validation document (pseudocode) and a python project, including pytests to prove the eODS beacon-chain accounting design.
We can add delegated
boolean entry in the records:
Actual balance is stored in the BeaconState
records, as a registry of validators and their balances.
We can add a fee List
structure, mapping each Validator in the registry with its fee rate (NULL
if delegated
entry defined in class Validator
is False
):
We can add beacon chain class Delegator
:
Delegator balances are to be stored in the BeaconState
records, as a registry of delegators and their balances:
We can add Delegators registry inside BeaconState
For toy-project purposes, I wrote a toy class Delegator
and imported it in the code file. The delegator IDs are stored as string, i.e. Validator_no1, Validator_no2, instead of delegator pubkeys
The code file stores delegators' data as a list of Delegator
instances. If we dig deeper into the implementation, we can observe that the following functions perform balance sheet operations, as follows:
delegate
- Delegates capital to the DelegatedValidator
, updates delegator's balance, and recalculates delegators' quotas.withdraw
- Allows a delegator to withdraw up to their balance, updating their quotaadjust_DelegatedValidator_balance
- Adjusts the total DelegatedValidator value (profit/loss) without changing individual quotas._recalculate_quotas
- Recalculates and updates all delegator quotas to ensure the sum is 1.Helper functions
get_delegator_quota
- Returns the delegator's quota as a percentage of the total balance of the delegated validator.get_all_quotas
- Returns a list with all delegators' quotas.get_delegator_index_by_pubkey
- Returns de index of a delegator with a given pubkeyThe following 4 tests are OK:
test_add_delegate
- Add a delegator and set its balance.test_add_multiple_delegates
- Add multiple delegators and set their balance.test_adjust_DelegatedValidator_value_quota
- Adjust the DelegatedValidator value and have the delegators balance updated.test_adjust_DelegatedValidator_balance_quota
- Adjust the DelegatedValidator balance and have the delegators' quota unchanged.Write final dev update & project presentation