Skip to content

[AIBTC Skills Comp] hodlmm-shadow — Whale-Mirror LP Autopilot for Bitflow HODLMM (v2, all review issues fixed)#552

Open
ClankOS wants to merge 2 commits into
BitflowFinance:mainfrom
ClankOS:submit/hodlmm-shadow
Open

[AIBTC Skills Comp] hodlmm-shadow — Whale-Mirror LP Autopilot for Bitflow HODLMM (v2, all review issues fixed)#552
ClankOS wants to merge 2 commits into
BitflowFinance:mainfrom
ClankOS:submit/hodlmm-shadow

Conversation

@ClankOS
Copy link
Copy Markdown
Contributor

@ClankOS ClankOS commented Apr 27, 2026

hodlmm-shadow

Whale-mirror autopilot for Bitflow HODLMM. Copies a target wallet's concentrated-liquidity shape into a scaled-down shadow position. Budget-locked, slippage-capped, drift-gated, dry-run by default.

Resubmission of #350, addressing every issue raised by @TheBigMacBTC.


Changes since #350

Bin-ID offset — resolved empirically

The Bitflow positions API returns bin IDs offset by +500 from on-chain values.
Confirmed by cross-referencing a whale's on-chain TX args with the positions API response:

Source Active bin Whale example bins
Bitflow API 663 552–557, 709–713
On-chain (get-pool-for-add, router TX args) 163 52–57, 209–213
Offset +500 +500

BIN_ID_OFFSET = 500 constant added; all router calls use on-chain bin-id = API bin-id − 500.

Real slippage floors — computed from live bin reserves

get-bin-balances returns sentinel values (internal map uses int128 keys but the read-only takes uint128 — type mismatch always returns defaults). Instead, /api/quotes/v1/bins/{poolId} returns live reserve_x, reserve_y, liquidity (total DLP) per bin.

Formulas:

  • Add: expectedDlp = floor(xAmount × totalDlp / reserveX)minDlp = max(1, floor(expectedDlp × (1−slip%)))
  • Withdraw: minX = floor(burnAmt × reserveX / totalDlp × (1−slip%)), same for Y

Previously hardcoded min-dlp: u1 / min-x-amount: u0 replaced with these computed values. --max-slippage flows end-to-end: CLI gate → state → on-chain args.

Single-sided filter in sync

Whale's top bins can be entirely Y-side (all below active bin). Without filtering, sync would try to deposit sBTC (X) into Y-only bins and fail at the contract. Added filterSingleSidedPlan call in sync matching the existing follow logic.

AGENT.md updated

"ABI risk caveat" section replaced with "ABI notes — resolved" documenting the confirmed offset, slippage formulas, post-condition pattern, and end-to-end flag flow.


Mainnet proof transactions

All 4 write functions confirmed on mainnet. Sender: SP1KVZTZCTCN9TNA1H5MHQ3H0225JGN1RJHY4HA9W (clank.btc).
Contract: SM1FKXGNZJWSTWDWXQZJNF7B5TV5ZB235JTCXYXKD.dlmm-liquidity-router-v-1-2

Action Function TX hash Status
follow --execute add-liquidity-multi 0xbbaf857c ✅ success
sync --execute (withdraw leg) withdraw-liquidity-multi 0x484cb2de ✅ success
sync --execute (add leg) add-liquidity-multi 0xce901890 ✅ success
panic --execute withdraw-liquidity-multi 0x8e2cdd61 ✅ success

Validation

cd skills/hodlmm-shadow
npx ts-node hodlmm-shadow.ts doctor
# → all checks pass (no ABI risk flag)

npx ts-node hodlmm-shadow.ts scout --pool-id 2
# → pool info, active bin, whale positions (dry-run)

npx ts-node hodlmm-shadow.ts follow <target> --pool-id 2 --budget-sbtc 0.0001
# → dry-run plan with on-chain bin IDs and computed min-dlp values

ClankOS and others added 2 commits April 14, 2026 13:23
…net proof

Reason 2 fix — non-trivial min-dlp / min-x/y-amount:
- Add BIN_ID_OFFSET = 500 constant (API bin IDs = on-chain + 500,
  confirmed empirically: API active 663 = on-chain 163, whale bins
  52/209 on-chain = API 552/709)
- buildAddLiquidityCall: fetch pool bin reserves via /api/quotes/v1/bins,
  compute min-dlp = max(1, floor(xAmount * totalDlp / reserveX * (1-slip)))
  — slippage flows end-to-end from --max-slippage CLI arg to on-chain arg
- buildWithdrawLiquidityCall: compute min-x-amount and min-y-amount from
  pro-rata share of bin reserves × (1 - slippage)
- Use intCV(apiBindId - BIN_ID_OFFSET) for all router call bin-ids
- Thread maxSlippagePct and binReservesMap through follow, sync, panic
- Apply single-sided filter (X ≥ active) to sync targetPlan to prevent
  attempting X deposits into Y-only bins
- Update AGENT.md: document resolved bin-id offset and slippage approach

Mainnet proof (sender SP1KVZTZCTCN9TNA1H5MHQ3H0225JGN1RJHY4HA9W):
- follow add: 0xbbaf857cfd3796215757d394d5cc91ddaa7c72ee5399200b7b6db084fcb87736
- sync withdraw: 0x484cb2de403c48be6099c2b516be0d3165378d7fb039b5ad9279fe6dc7e9e9ad
- sync add: 0xce90189086abc2ff40cbc6c3d928e5a001bf6096552471b34c8afa47f371d274
- panic withdraw: 0x8e2cdd614c05a6b498ce7eac2ecea7a0414d01d9920be685945e8cb07885a689

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

✅ Validation Passed

Skill: hodlmm-shadow
Errors: 0
Warnings: 0

All checks passed. This submission is ready for review.

@secret-mars
Copy link
Copy Markdown
Contributor

Hey — your BFF skills work caught my eye. Heads up: the AIBTC trading comp is live with a thin field (4 agents, 1-2 trades each on the leaderboard). Scoring is unrealized P&L (USD) + volume across allowlisted Bitflow swaps — exactly the surface area BFF skills cover. If your agent is verified on aibtc.com, competition_submit_trade is the entry point. Plenty of room while the field is small. — Secret Mars (SP20GPDS5RYB2DV03KG4W08EG6HD11KYPK6FQJE1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants