Closed dpaiton closed 9 months ago
There are a few things that come to mind here. First, we need to incorporate the minimum share reserves into the expected vault shares. If you just add the minimum shares to the expected calculation, that should be fixed. Second, this calculation doesn't account for matured positions. Now that @jrhea has landed #685, we'll be able to update this invariant in the next release.
Ok, we will wait for the next release to update this check
Revising this issue, we're able to reproduce by:
The expected vault shares is calculated below:
expected_vault_shares = (
pool_state.pool_info.share_reserves
# The term below replaces this calculation:
+ pool_state.pool_info.shorts_outstanding / pool_state.pool_info.share_price
+ pool_state.gov_fees_accrued
+ pool_state.pool_info.withdrawal_shares_proceeds
+ pool_state.pool_info.zombie_share_reserves
)
actual_vault_shares = yield_contract.functions.balanceOf(hyperdrive_contract.address).call()
Opening a short for 11111 base results in a difference of 5.556133872366779485. Turning off the flat fee reduces the discrepancy here to 0.000634189461510241
Turning off variable rate and replacing the expected_vault_shares
to below fixes this issue:
expected_vault_shares = (
pool_state.pool_info.share_reserves
# + pool_state.pool_info.shorts_outstanding / pool_state.pool_info.share_price
+ (
pool_state.pool_info.shorts_outstanding
+ (pool_state.pool_info.shorts_outstanding * pool_state.pool_config.fees.flat)
)
/ pool_state.pool_info.share_price
+ pool_state.gov_fees_accrued
+ pool_state.pool_info.withdrawal_shares_proceeds
+ pool_state.pool_info.zombie_share_reserves
)
The difference here is due to shorts outstanding accumulating variable rate. Solved by using the expected_vault_shares
as a lower bound to ensure the pool is always solvent.
Crash Report
https://app.rollbar.com/a/delv/fix/item/FirstProject/40
Description
Bots are running in competition mode (one block is mined every 12 seconds; every mined block accelerates time by 52*12 seconds).
Test: fuzz_bot_invariant_checks.py
Expected Behavior
The expected & actual vault shares should be the same.
epsilon = 1e-4
, so1e14 WEI
Actual Behavior
The expected and actual returned amounts do not match. The difference in WEI is always off by the same amount (
25
counts, all identically4.225176e+19
, or approximately40 ETH
).Steps to Reproduce
Run the fuzz test
Logs or Stack Traces
fuzz_bots_invariant_checks2023_12_12_18_10_10_Z.json