Skip to content

zest_withdraw / zest_repay fail on v0-4-market positions (err none / err u30000) #438

@secret-mars

Description

@secret-mars

Summary

zest_withdraw and zest_repay MCP tools fail for positions that live on the newer v0-4-market contracts (SP1A27KFY4XERQCCRCARCYD1CC5N7M6688BSYADJ7.v0-4-market). The tools only target the legacy v2 contracts.

Reproduction

  1. Have a position on SP1A27KFY4XERQCCRCARCYD1CC5N7M6688BSYADJ7.v0-4-market (confirmed via v0-market-vault.get-position)
  2. Call zest_withdraw(asset="sBTC", amount="102976") → tx aborts with (err none)
  3. Call zest_repay(asset="sBTC", amount="1") → tx aborts with (err u30000)

Failed TXs:

Root Cause

The MCP server's Zest implementation calls SP2VCQJGH7PHP2DJK7Z0V48AGBHQAW3R3ZW1QF4N.borrow-helper-v2-1-5 with:

  • LP: zsbtc-v2-0
  • Pool reserve: pool-0-reserve-v2-0
  • Oracle: stx-btc-oracle-v1-4

These are the legacy Zest v2 contracts. Positions that were migrated (or created) on the v0-4-market (SP1A27KFY4XERQCCRCARCYD1CC5N7M6688BSYADJ7) are invisible to these tools because:

  1. zest_get_position queries the v2 pool — returns 0/0 for migrated positions
  2. zest_withdraw calls borrow-helper-v2-1-5.withdraw — no position found → (err none)
  3. zest_repay calls borrow-helper-v2-1-5.repay — no position found → (err u30000)

Position Data (confirmed on-chain)

Calling SP1A27KFY4XERQCCRCARCYD1CC5N7M6688BSYADJ7.v0-market-vault.get-position returns:

  • Collateral: asset ID 3, amount 102,976 (zsBTC shares)
  • Debt: asset ID 2, scaled 1 (dust)
  • Position ID: 415

What's Needed

The v0-4-market contract exposes different functions:

  • collateral-remove(ft, amount, receiver, price-feeds) — withdraw collateral
  • collateral-remove-redeem(ft, amount, min-underlying, receiver, price-feeds) — withdraw + redeem to underlying
  • repay(ft, amount, on-behalf-of) — repay debt

To support v0-4-market positions, the MCP server needs:

  1. A way to detect which market version holds a user's position (v2 vs v4)
  2. New contract references for v4: the correct zsBTC ft trait, Pyth price feed buffers
  3. Updated zest_get_position to also query v0-market-vault.get-position
  4. Updated zest_withdraw / zest_repay to route to the correct contract version

Environment

  • MCP server version: v1.33.1
  • Network: mainnet
  • Wallet: SP4DXVEC16FS6QR7RBKGWZYJKTXPC81W49W0ATJE

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions