Skip to content

DorkFiMCP: detect borrow cap and fail early in borrow_txn #8

@temptemp3

Description

@temptemp3

Summary

DorkFiMCP's borrow_txn (and related borrow flows) should detect when a borrow would exceed the market borrow cap and fail early with a clear error, instead of building/signing and potentially failing on-chain or giving a confusing result.

Problem

When a user calls borrow_txn with an amount that would push total borrowed (e.g. existing borrows + accrued interest + new borrow) over the market's borrow cap:

  • The MCP may build transactions that will fail on-chain or behave unexpectedly
  • Users get a poor experience (e.g. signing then failure, or unclear reason for failure)
  • No upfront validation against the borrow cap in the MCP layer

Expected behavior

  • Before building borrow_txn, DorkFiMCP should:
    1. Resolve the market's borrow cap (if any) and current total borrowed / user borrow (including accrued interest where applicable)
    2. Compute whether current borrowed + borrow amount would exceed the cap
    3. If over cap: return a clear error (e.g. "Borrow would exceed market cap: current X, cap Y, requested Z") and do not return transaction bytes
  • If there is no cap or cap is not applicable, proceed as today

Suggested implementation

  • In the code path that handles borrow_txn (and any wrapper that uses it):
    • Fetch market info (e.g. via get_market or equivalent) including borrow cap and current borrowed amounts (principal + interest)
    • Optionally fetch user's current borrow in that market
    • Validate (user_current_borrow + borrow_amount) and/or (total_borrowed + borrow_amount) against cap
    • If over cap, return a structured error and no txn payload
  • Add or extend MCP/unit tests for: at-cap, over-cap, and no-cap scenarios

Context

Improves UX and reliability for DorkFi MCP callers; aligns with borrow cap behavior in the app (see e.g. DorkFi/dorkfi-app#248). Complements early deposit-cap check in UluOS#7.

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