From 8cfbf74e891ecf4f8573de573e1fbee87e1dcd1c Mon Sep 17 00:00:00 2001 From: openhands Date: Thu, 19 Mar 2026 22:59:21 +0000 Subject: [PATCH] fix: address review feedback on bootstrap recovery (#644) - Fix positions() ABI selector: uint256 -> uint8 (Stage enum) - Replace fixed sleeps with polling loops checking on-chain timestamps - Add trailing period to 'amplitude not reached.' error hint - Remove 'was never set' feeDestination scenario (always set by deploy) - Clarify warning comment scope in bootstrap-common.sh Co-Authored-By: Claude Opus 4.6 (1M context) --- docs/mainnet-bootstrap.md | 4 ++-- scripts/bootstrap-common.sh | 2 +- scripts/recover-bootstrap.sh | 32 ++++++++++++++++++++++++++------ 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/docs/mainnet-bootstrap.md b/docs/mainnet-bootstrap.md index 9010bc3..44fb68a 100644 --- a/docs/mainnet-bootstrap.md +++ b/docs/mainnet-bootstrap.md @@ -256,7 +256,7 @@ cast call $LM_ADDRESS "feeDestination()(address)" --rpc-url $BASE_RPC cast call $LM_ADDRESS "feeDestinationLocked()(bool)" --rpc-url $BASE_RPC # Check if positions exist (non-zero liquidity = positions deployed) -cast call $LM_ADDRESS "positions(uint256)(int24,int24,uint128)" 1 --rpc-url $BASE_RPC +cast call $LM_ADDRESS "positions(uint8)(int24,int24,uint128)" 1 --rpc-url $BASE_RPC ``` ### Recovery steps @@ -278,7 +278,7 @@ cast call $LM_ADDRESS "positions(uint256)(int24,int24,uint128)" 1 --rpc-url $BAS 4. **Verify** — confirm `cumulativeVolume > 0` (Step 7) -5. **If `feeDestination` needs correction** (e.g., was never set or was set to the wrong address): +5. **If `feeDestination` needs correction** (e.g., was set to the wrong address): ```bash # Only works if feeDestinationLocked is false cast send $LM_ADDRESS \ diff --git a/scripts/bootstrap-common.sh b/scripts/bootstrap-common.sh index c72b486..c7fa9b1 100755 --- a/scripts/bootstrap-common.sh +++ b/scripts/bootstrap-common.sh @@ -121,7 +121,7 @@ fund_liquidity_manager() { bootstrap_vwap() { detect_swap_router - # WARNING: If the second recenter() below fails mid-sequence, the LM is left + # WARNING: If the second recenter() call later in this function fails mid-sequence, the LM is left # with positions deployed but cumulativeVolume == 0 (partial bootstrap). # For mainnet recovery see docs/mainnet-bootstrap.md or scripts/recover-bootstrap.sh. # Idempotency guard: if a previous run already bootstrapped VWAP, skip. diff --git a/scripts/recover-bootstrap.sh b/scripts/recover-bootstrap.sh index a49ec6e..93f5743 100755 --- a/scripts/recover-bootstrap.sh +++ b/scripts/recover-bootstrap.sh @@ -139,8 +139,17 @@ if [[ "$NOW" -lt "$COOLDOWN_END" ]]; then if [[ "$DRY_RUN" == "true" ]]; then exit 0 fi - info "Waiting ${REMAINING}s for cooldown ..." - sleep "$REMAINING" + info "Polling for recenter cooldown to elapse ..." + while true; do + NOW="$(cast block latest --rpc-url "$RPC_URL" --field timestamp 2>/dev/null || echo "0")" + if [[ "$NOW" -ge "$COOLDOWN_END" ]]; then + info "Recenter cooldown elapsed." + break + fi + REMAINING=$(( COOLDOWN_END - NOW )) + info " ${REMAINING}s remaining ..." + sleep 5 + done fi # ── Optional: extra seed buy ───────────────────────────────────────── @@ -173,9 +182,20 @@ if [[ -n "$SEED_ETH" && -n "$KRAIKEN" ]]; then "($WETH,$KRAIKEN,10000,$DEPLOYER_ADDR,$SEED_WEI,0,$SQRT_LIMIT)" info "Seed buy complete." - # Wait for cooldown after potential recenter trigger - info "Waiting 65s for recenter cooldown ..." - sleep 65 + # Poll until recenter cooldown elapses + info "Polling for recenter cooldown to elapse ..." + LAST_RECENTER_AFTER="$(cast call --rpc-url "$RPC_URL" "$LM_ADDRESS" "lastRecenterTime()(uint256)" 2>/dev/null || echo "0")" + COOLDOWN_TARGET=$(( LAST_RECENTER_AFTER + 60 )) + while true; do + NOW="$(cast block latest --rpc-url "$RPC_URL" --field timestamp 2>/dev/null || echo "0")" + if [[ "$NOW" -ge "$COOLDOWN_TARGET" ]]; then + info "Recenter cooldown elapsed." + break + fi + REMAINING=$(( COOLDOWN_TARGET - NOW )) + info " ${REMAINING}s remaining ..." + sleep 5 + done fi fi @@ -191,7 +211,7 @@ if ! cast send --rpc-url "$RPC_URL" --private-key "$PRIVATE_KEY" \ "$LM_ADDRESS" "recenter()" 2>&1; then error "recenter() reverted. Check the revert reason above." error "Common causes:" - error " - 'amplitude not reached' -> need larger seed buy (use --seed-eth with --kraiken)" + error " - 'amplitude not reached.' -> need larger seed buy (use --seed-eth with --kraiken)" error " - 'price deviated from oracle' -> wait for TWAP history" error " - 'recenter cooldown' -> wait 60s and retry" exit 1