Skip to main content
Glama

Refund your leg

refund_leg
Destructive

Reclaim a funded swap leg after its timelock passes when the counterparty never claims it, signing with the agent's own key across EVM, TRON, Solana, and Bitcoin.

Instructions

AUTONOMOUS SETTLEMENT: take back YOUR funded leg after its timelock has passed and the counterparty never claimed it, signing with the agent's own key. Works on every rail — EVM and TRON call the escrow, Solana and Bitcoin sign a transaction the server builds. On Bitcoin a node also rejects it until the chain's MEDIAN TIME PAST has passed the timelock, which trails real time by roughly an hour. Each rail sends the money where it was agreed it would go: the leg's refund address on Bitcoin and Solana, and on EVM and TRON the wallet that funded the escrow — the agent's own key. Returns the on-chain tx id.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "swap_id": "<swap_id>"
    },
    "name": "refund_leg"
  }
}

Input Schema

NameRequiredDescriptionDefault
swap_idYesSwap id (swap.id from deal_status, or swapId once a deal is agreed)

Output Schema

NameRequiredDescriptionDefault
txNoOn-chain tx id
legNo
chainNo
errorNoSet instead when the call failed

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed4 schema fields changedv1.11.1
    • removedInput schema / additionalProperties
      Removed value: -false
    • addedInput schema / properties / swap_id / description
      Added value: +"Swap id (swap.id from deal_status, or swapId once a deal is agreed)"
    • addedInput schema / properties / swap_id / pattern
      Added value: +"^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
    • changedOutput schema / (root)
      Previous value: -nullNew value: +{
      +  "$schema": "http://json-schema.org/draft-07/schema#",
      +  "additionalProperties": {},
      +  "properties": {
      +    "chain": {
      +      "type": "string"
      +    },
      +    "error": {
      +      "additionalProperties": {},
      +      "description": "Set instead when the call failed",
      +      "properties": {
      +        "code": {
      +          "type": "string"
      +        },
      +        "is_retryable": {
      +          "type": "boolean"
      +        },
      +        "message": {
      +          "type": "string"
      +        },
      +        "recovery_hint": {
      +          "type": "string"
      +        }
      +      },
      +      "type": "object"
      +    },
      +    "leg": {
      +      "type": "string"
      +    },
      +    "tx": {
      +      "description": "On-chain tx id",
      +      "type": "string"
      +    }
      +  },
      +  "type": "object"
      +}
  2. Addedv0.10.0

TDQS

A4.3/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Beyond the destructive/non-idempotent annotations, it discloses rail-specific mechanics: EVM/TRON invoke the escrow while Solana/Bitcoin sign a server-built transaction, and Bitcoin additionally requires the chain's median-time-past to clear the timelock, which lags real time by about an hour. It also states where the funds land per rail and that a tx id is returned — context the annotations cannot supply.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

It leads with the precondition framing and each sentence carries non-redundant rail information. The clause describing EVM/TRON payout destinations ('the wallet that funded the escrow — the agent's own key') is slightly convoluted and could be tighter.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a destructive, single-parameter settlement tool it covers preconditions, rail variance, timing caveats and payout destinations, and an output schema exists so return shape needn't be spelled out. Failure modes (leg not funded, already claimed) are only implied by the precondition statement.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

There is a single required parameter with 100% schema description coverage, so the schema already explains swap_id's origin. The description adds no format or sourcing detail beyond that, which is the expected baseline when the schema does the work.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description names a specific verb and resource ('take back YOUR funded leg') plus the exact conditions that make it valid ('after its timelock has passed and the counterparty never claimed it'), which cleanly separates it from fund_leg and claim_leg. An agent can tell what this does without opening the schema.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The preconditions are explicit: the leg must be funded, the timelock must have elapsed, and the counterparty must not have claimed. That implicitly states when not to use it, but no sibling tool (e.g. claim_leg) is named as the alternative for the other branches.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.