Balance Update Log
The BalanceUpdate log is used to track changes in user pool balances. It is emitted each time a deposit or withdraw action is called to reflect a user's portfolio update.
Data Structure
The BalanceUpdate log contains the following data:
strategyId
(uint16): Identifier for the strategypoolId
(bytes4): Identifier for the poolbalanceBefore
(uint256): User's balance before the updatebalanceAfter
(uint256): User's balance after the updatefeeInTokens
(uint256): Amount of fee taken in tokens
Notes
If the pool issues share tokens, balances are expressed using these tokens
If the pool doesn't issue share tokens, balances are expressed using the deposited currency
Both
balanceBefore
andbalanceAfter
are logged to account for tokens that accrue over time
Importance of Logging Both Balances
We log both balanceBefore
and balanceAfter
for several important reasons:
Accrual Tokens
Some tokens accrue value over time. By logging both balances, we can accurately capture this accrual between actions.
Complete Accounting
To fully account for a balance update, we need to consider:
The balance before the action
The balance after the action
Fees taken (logged separately as
feeInTokens
)Any deposit or withdrawal amount (derived from the other values)
Accurate Historical Data
If we only logged the balanceAfter
and relied on the previous action's balanceAfter
as the current balanceBefore
, we would miss any token accrual between actions.
Simplified Calculations
Having both balances makes it easier to calculate the exact change in balance due to the action, separate from any accrual or other factors.
Summary
By logging both balances, we ensure that our system can accurately track and account for all changes in user balances, regardless of the token type or any value accrual mechanisms.
Last updated