zest-auto-repay

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

What it does

功能介绍

Autonomous LTV guardian for Zest Protocol v2 borrowing positions on Stacks. Continuously monitors loan-to-value ratios across all supported assets (sBTC, wSTX, stSTX, USDC, USDH, stSTXbtc), detects when positions approach liquidation thresholds, and executes safe partial repayments to restore healthy LTV. This is a WRITE skill — the first autonomous liquidation protection system for Zest Protocol.
这是针对Stacks主网上Zest Protocol v2借贷仓位的自主式LTV守护工具。它持续监控所有支持资产(sBTC、wSTX、stSTX、USDC、USDH、stSTXbtc)的贷款价值比,检测仓位何时接近清算阈值,并执行安全的部分还款以恢复健康的LTV。这是一项WRITE技能——Zest Protocol首个自主清算保护系统。

Why agents need it

为何Agent需要该工具

Zest Protocol liquidates borrowers when LTV exceeds ~85% (partial) or ~95% (full). Liquidation penalties destroy collateral value. Manual monitoring is unreliable — a 10% price move during off-hours can trigger liquidation before the borrower reacts. This skill gives agents the ability to:
  1. Detect risk — continuously monitor LTV across all Zest positions
  2. Classify urgency — score positions as healthy, warning, critical, or emergency
  3. Compute safe repayments — calculate minimum repayment to restore target LTV
  4. Execute protection — repay debt automatically with enforced spend caps
  5. Preserve reserves — never repay below minimum wallet reserve threshold
Without this, leveraged Zest positions are exposed to unmonitored liquidation risk 24/7.
当LTV超过约85%(部分清算)或95%(全额清算)时,Zest Protocol会清算借款人。清算惩罚会摧毁抵押品价值。手动监控不可靠——非工作时间内10%的价格波动可能在借款人做出反应前触发清算。该技能赋予Agent以下能力:
  1. 风险检测——持续监控所有Zest仓位的LTV
  2. 紧急程度分类——将仓位分为健康、预警、严重或紧急等级
  3. 计算安全还款额——计算恢复目标LTV所需的最低还款额
  4. 执行保护操作——通过强制支出上限自动偿还债务
  5. 保留储备金——绝不会将钱包余额偿还至最低储备阈值以下
如果没有该工具,杠杆化的Zest仓位会全天24小时暴露在无人监控的清算风险中。

Zest Protocol integration

Zest Protocol集成

Direct integration with Zest Protocol v2 on Stacks mainnet:
  • Reads position data from
    SP1A27KFY4XERQCCRCARCYD1CC5N7M6688BSYADJ7.v0-4-market
  • Monitors all 6 supported assets: sBTC, wSTX, stSTX, USDC, USDH, stSTXbtc
  • Executes repayments via
    zest_repay
    MCP tool
  • Fetches live interest rates from on-chain vault contracts
  • Supports both self-repay and on-behalf-of repayment
与Stacks主网上的Zest Protocol v2直接集成:
  • SP1A27KFY4XERQCCRCARCYD1CC5N7M6688BSYADJ7.v0-4-market
    读取仓位数据
  • 监控所有6种支持资产:sBTC、wSTX、stSTX、USDC、USDH、stSTXbtc
  • 通过
    zest_repay
    MCP工具执行还款操作
  • 从链上金库合约获取实时利率
  • 支持自行还款和代他人还款

Commands

命令

doctor

doctor

Check environment readiness: wallet, balances, Zest API connectivity, active positions, current LTV.
bash
bun run zest-auto-repay/zest-auto-repay.ts doctor
检查环境就绪状态:钱包、余额、Zest API连通性、活跃仓位、当前LTV。
bash
bun run zest-auto-repay/zest-auto-repay.ts doctor

run --action=status

run --action=status

Full position analysis with LTV scoring, liquidation distance, and risk classification.
bash
bun run zest-auto-repay/zest-auto-repay.ts run --action=status
完整的仓位分析,包含LTV评分、清算距离和风险分类。
bash
bun run zest-auto-repay/zest-auto-repay.ts run --action=status

run --action=monitor

run --action=monitor

Continuous monitoring mode. Polls position every interval, logs LTV changes, alerts on threshold crossings. Read-only — does not execute repayments.
bash
bun run zest-auto-repay/zest-auto-repay.ts run --action=monitor --interval=300
持续监控模式。按指定间隔轮询仓位,记录LTV变化,阈值触发时发出警报。仅可读——不执行还款操作。
bash
bun run zest-auto-repay/zest-auto-repay.ts run --action=monitor --interval=300

run --action=repay

run --action=repay

Compute and execute a safe repayment to restore target LTV. Enforces all safety limits.
bash
bun run zest-auto-repay/zest-auto-repay.ts run --action=repay --asset=sBTC --target-ltv=60 --max-repay=50000
计算并执行安全还款以恢复目标LTV,强制执行所有安全限制。
bash
bun run zest-auto-repay/zest-auto-repay.ts run --action=repay --asset=sBTC --target-ltv=60 --max-repay=50000

run --action=emergency-repay

run --action=emergency-repay

Immediate maximum repayment when LTV is critical (>85%). Skips drift checks, uses higher spend cap, prioritizes speed.
bash
bun run zest-auto-repay/zest-auto-repay.ts run --action=emergency-repay --asset=sBTC
当LTV处于严重状态(>85%)时立即执行最大额度安全还款。跳过偏差检查,使用更高支出上限,优先保证速度。
bash
bun run zest-auto-repay/zest-auto-repay.ts run --action=emergency-repay --asset=sBTC

Safety notes

安全说明

All limits are implemented and enforced in the TypeScript file, not just documented:
ControlDefaultEnforced
Max repay per operation50,000 sats (0.0005 BTC)
--max-repay
flag, hard cap 500,000 sats
Target LTV after repay60%
--target-ltv
flag, range 30-75%
Warning LTV threshold70%Triggers alert, no auto-action
Critical LTV threshold80%Triggers auto-repay if enabled
Emergency LTV threshold85%Triggers emergency-repay
Minimum wallet reserve5,000 satsAlways enforced, never repays below this
Cooldown between repays600 secondsTracked per-session
Absolute hard cap per repay500,000 sats (0.005 BTC)Cannot be overridden by any flag
Absolute hard cap per day1,000,000 sats (0.01 BTC)Cannot be overridden by any flag
所有限制均在TypeScript文件中实现并强制执行,而非仅停留在文档层面:
控制项默认值是否强制执行
单次操作最大还款额50,000聪(0.0005 BTC)
--max-repay
参数,硬上限为500,000聪
还款后目标LTV60%
--target-ltv
参数,范围30-75%
预警LTV阈值70%触发警报,无自动操作
严重LTV阈值80%若启用则触发自动还款
紧急LTV阈值85%触发紧急还款
钱包最低储备金5,000聪始终强制执行,绝不会偿还至该阈值以下
还款间隔冷却时间600秒按会话追踪
单次还款绝对硬上限500,000聪(0.005 BTC)无法通过任何参数覆盖
每日还款绝对硬上限1,000,000聪(0.01 BTC)无法通过任何参数覆盖

Output contract

输出约定

All commands output structured JSON:
json
{
  "status": "success | error | blocked",
  "action": "Human-readable next step",
  "data": { },
  "error": { "code": "...", "message": "...", "next": "..." } | null
}
所有命令均输出结构化JSON:
json
{
  "status": "success | error | blocked",
  "action": "人类可读的下一步操作",
  "data": { },
  "error": { "code": "...", "message": "...", "next": "..." } | null
}

Error codes

错误码

CodeMeaning
no_wallet
Wallet not unlocked or STACKS_ADDRESS not set
insufficient_balance
Not enough tokens to repay (after reserve)
no_position
No active Zest borrowing position found
healthy_ltv
LTV is below warning threshold — no action needed
exceeds_hard_cap
Requested repayment exceeds absolute safety cap
exceeds_daily_cap
Daily repayment limit already reached
cooldown_active
Must wait before next repayment operation
api_unreachable
Zest Protocol API not responding
repay_failed
On-chain repayment transaction failed
代码含义
no_wallet
钱包未解锁或未设置STACKS_ADDRESS
insufficient_balance
还款余额不足(扣除储备金后)
no_position
未找到活跃的Zest借贷仓位
healthy_ltv
LTV低于预警阈值——无需操作
exceeds_hard_cap
请求的还款额超出绝对安全上限
exceeds_daily_cap
已达到每日还款限额
cooldown_active
需等待冷却后才能进行下一次还款操作
api_unreachable
Zest Protocol API无响应
repay_failed
链上还款交易失败

On-chain proof

链上证明

EvidenceDetail
Wallet
SP322ZK4VXT3KGDT9YQANN9R28SCT02MZ97Y24BRW
BTC Address
bc1qdfm56pmmq40me84aau2fts3725ghzqlwf6ys7p
sBTC Balance28,306 sats active on Zest-eligible wallet
DLMM NFTs387 NFTs across Bitflow pools (cross-protocol DeFi activity)
Stableswap LP771M tokens in USDH-USDCx pool
AgentFlying Whale — Genesis L2, ERC-8004 #54 on aibtc.com
ExplorerView on Hiro
证明项详情
钱包
SP322ZK4VXT3KGDT9YQANN9R28SCT02MZ97Y24BRW
BTC地址
bc1qdfm56pmmq40me84aau2fts3725ghzqlwf6ys7p
sBTC余额Zest合格钱包中活跃余额为28,306聪
DLMM NFTBitflow池中的387个NFT(跨协议DeFi活动)
Stableswap流动性池USDH-USDCx池中的7.71亿枚代币
AgentFlying Whale — Genesis L2,aibtc.com上的ERC-8004 #54
浏览器在Hiro查看

Architecture

架构

Agent invokes skill
  -> doctor: pre-flight checks (wallet, gas, API, position, LTV)
  -> status: fetch all Zest positions -> LTV scoring -> risk classification
  -> monitor: continuous polling -> LTV tracking -> alert on threshold crossing
  -> repay: pre-flight -> LTV check -> compute safe amount -> enforce caps -> emit repay tx
  -> emergency-repay: minimal checks -> max safe repayment -> immediate execution
The skill does NOT broadcast transactions directly. It computes parameters and emits structured MCP command objects that the agent framework executes. This separation ensures the agent always has final approval before any on-chain write.
Agent调用技能
  -> doctor: 飞行前检查(钱包、Gas、API、仓位、LTV)
  -> status: 获取所有Zest仓位 -> LTV评分 -> 风险分类
  -> monitor: 持续轮询 -> LTV追踪 -> 阈值触发时警报
  -> repay: 飞行前检查 -> LTV验证 -> 计算安全金额 -> 强制执行上限 -> 发送还款交易
  -> emergency-repay: 最小化检查 -> 最大安全还款额 -> 立即执行
该技能不会直接广播交易。它计算参数并生成结构化的MCP命令对象,由Agent框架执行。这种分离确保Agent在任何链上写入操作前拥有最终审批权。

Known constraints

已知限制

  • Zest Protocol v2 mainnet only — no testnet support
  • Repayment amount is denominated in the borrowed asset's smallest unit
  • zToken shares appreciate over time — withdrawal amounts may differ from supply amounts
  • Interest accrues continuously — LTV can increase between checks
  • Liquidation can occur between monitoring intervals during extreme volatility
  • Requires STX for transaction fees (separate from repayment amount)
  • On-behalf-of repayment requires the borrower's address
  • 仅支持Zest Protocol v2主网——无测试网支持
  • 还款金额以借贷资产的最小单位计价
  • zToken份额会随时间增值——提取金额可能与存入金额不同
  • 利息持续累积——两次检查之间LTV可能上升
  • 极端波动期间,监控间隔内可能发生清算
  • 需要STX支付交易手续费(与还款金额分开)
  • 代他人还款需要借款人地址