Skip to content

fix(hodlmm-inventory-balancer): fix abort_by_post_condition + single-skill resubmission [Day 24]#546

Open
IamHarrie-Labs wants to merge 1 commit into
BitflowFinance:mainfrom
IamHarrie-Labs:fix/hodlmm-inventory-balancer-v2
Open

fix(hodlmm-inventory-balancer): fix abort_by_post_condition + single-skill resubmission [Day 24]#546
IamHarrie-Labs wants to merge 1 commit into
BitflowFinance:mainfrom
IamHarrie-Labs:fix/hodlmm-inventory-balancer-v2

Conversation

@IamHarrie-Labs
Copy link
Copy Markdown
Contributor

Summary

Resubmission of hodlmm-inventory-balancer as a single-skill PR (split from closed PR #496 per reviewer feedback from @TheBigMacBTC).

Post-condition fix included (addresses the abort_by_post_condition failure on the cited proof TX).

What changed from the closed PR

Root cause of abort_by_post_condition (original TX 0x2130b9c4...)

The original executeCorrectiveSwap built post-conditions manually:

const tAssetName = toToken.split(".")[1] ?? toToken;  // BUG: extracts contract name
Pc.principal(poolPrincipal).willSendGte(amount).ft(toToken, tAssetName);
// e.g. .ft("SM3K....sbtc-token", "sbtc-token")  ← WRONG
//                                                    ↑ should be "sbtc" (define-fungible-token name)

The contract name (sbtc-token) differs from the Clarity FT identifier (sbtc). Every swap aborted because the PC referenced an asset name that doesn't match what the chain actually transferred.

Fix

Replaced manual PC construction with sdk.prepareSwap() (the same pattern used in the proven dca skill). The SDK holds the correct tokenName (the define-fungible-token identifier) for every token in its registry and re-fetches a fresh quote right before broadcast — eliminating both the asset-name mismatch and the quote-staleness window.

const swapParams = await sdk.prepareSwap(
  { route, amount: humanAmount, tokenXDecimals: fromDecimals, tokenYDecimals: toDecimals },
  walletAddress,
  plan.slippage_pct / 100,
);
// swapParams.postConditions uses correct FT identifiers from SDK tokenName field

Skill files

File Purpose
skills/hodlmm-inventory-balancer/SKILL.md Registry frontmatter + documentation
skills/hodlmm-inventory-balancer/AGENT.md 7-step agent decision order + guardrails
skills/hodlmm-inventory-balancer/hodlmm-inventory-balancer.ts CLI implementation

Frontmatter validation

✅ hodlmm-inventory-balancer
   errorCount: 0, warningCount: 0

Single-skill verification

git diff --name-only origin/main...HEAD
# skills/hodlmm-inventory-balancer/AGENT.md
# skills/hodlmm-inventory-balancer/SKILL.md
# skills/hodlmm-inventory-balancer/hodlmm-inventory-balancer.ts

On-chain proof

A new successful proof TX is pending execution after the PC fix. The original TX 0x2130b9c4b445af6bd1bc7f7a91a6a6d8c4d2753bbd1eee6fce3f411c7fa0d558 returned abort_by_post_condition (as identified by reviewer) — the fix addresses the root cause. A replacement proof TX with tx_status: success will be submitted and this PR updated before merge review.

Wallet: SP301E0FY52B19281VCHP41SAKKZFR761BMKQH4QE
Pool: dlmm_6 — STX/sBTC

Safety gates (unchanged — reviewer confirmed strongest static-shape in batch)

Gate Trigger
Confirm gate run without --confirm=BALANCE → dry-run
Cooldown gate < 4 h since last run
Quote freshness Re-fetched inside executeCorrectiveSwap right before broadcast
Thin pool Price impact > 5 %
Unresolved state Prior swap unconfirmed
Gas reserve STX balance < 0.5 STX

🤖 Generated with Claude Code

….prepareSwap for correct FT asset names

The original executeCorrectiveSwap manually built post-conditions by extracting
the FT asset name from the token contract string (.split(".")[1]), which gave the
contract name (e.g. "sbtc-token") instead of the Clarity FT identifier (e.g. "sbtc").
This caused every live swap to abort_by_post_condition.

Fix: replace the manual PC construction with sdk.prepareSwap(), which uses the SDK's
own tokenName field (the correct define-fungible-token identifier) for each FT in the
route. The SDK also re-fetches a fresh quote immediately before broadcast, eliminating
the quote-staleness window between Step 3 (planning) and Step 4 (execution).

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

✅ Validation Passed

Skill: hodlmm-inventory-balancer
Errors: 0
Warnings: 0

All checks passed. This submission is ready for review.

@IamHarrie-Labs
Copy link
Copy Markdown
Contributor Author

@TheBigMacBTC — this is the single-skill resubmission of hodlmm-inventory-balancer from closed PR #496, split per your feedback.

Bundling: this PR now contains exactly one skill directory (skills/hodlmm-inventory-balancer/).

Post-condition fix: the abort_by_post_condition root cause you identified has been resolved. The bug was in executeCorrectiveSwap — it extracted the FT asset name using .split(".")[1] which gives the contract name (e.g. sbtc-token) instead of the Clarity define-fungible-token identifier (e.g. sbtc). Fixed by replacing the manual PC construction with sdk.prepareSwap() (same pattern as the working dca skill), which uses the SDK tokenName field and re-fetches a live quote immediately before broadcast.

A replacement proof TX with tx_status: success is being executed against the fixed code on wallet SP301E0FY52B19281VCHP41SAKKZFR761BMKQH4QE and will be added here once confirmed.

Thank you for the detailed review on #496.

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.

1 participant