Skip to content

Add trustline-removal preconditions to the ChangeTrust example - #90

Merged
kaankacar merged 2 commits into
mainfrom
copilot/add-trustline-removal-preconditions
Aug 13, 2026
Merged

Add trustline-removal preconditions to the ChangeTrust example#90
kaankacar merged 2 commits into
mainfrom
copilot/add-trustline-removal-preconditions

Conversation

Copilot AI commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

The assets skill taught trustline removal as a bare limit: "10000", // 0 to remove trustline comment, omitting the preconditions that make ChangeTrust(limit: 0) succeed: a zero balance, no buying liabilities from open offers, and no liquidity pool references (CAP-0038). It also didn't distinguish an actual trustline from wallet-display or claimable-balance state.

Changes to skills/assets/SKILL.md

  • New "Remove Trustline" section documenting the four preconditions:

    1. Identify the asset by code and issuer — display entries and claimable balances are not trustlines and can't be removed via ChangeTrust
    2. Zero the balance (send back to issuer to burn, or elsewhere)
    3. Cancel open offers buying the asset (buying liabilities)
    4. Exit liquidity pool positions referencing the asset (liquidity_pool_use_count > 0 blocks deletion per CAP-0038)
  • Example code that pre-checks trustline state before submitting, then maps failures to specific result codes:

    const codes = e.response?.data?.extras?.result_codes?.operations ?? [];
    if (codes.includes("op_invalid_limit")) {
      // CHANGE_TRUST_INVALID_LIMIT: balance or buying liabilities remain
    }
    if (codes.includes("op_cannot_delete")) {
      // CHANGE_TRUST_CANNOT_DELETE: trustline is used by a liquidity pool
    }
  • Create-trustline comment now points to the new section instead of the bare "0 to remove" hint

  • Trustline Management best practices gain a removal-precondition bullet

Result code strings verified against Stellar's Horizon mapping (ChangeTrustCannotDelete"op_cannot_delete", ChangeTrustInvalidLimit"op_invalid_limit").

…skill

Co-authored-by: kaankacar <103106776+kaankacar@users.noreply.github.com>
Copilot AI changed the title [WIP] Add trustline-removal preconditions to ChangeTrust example Add trustline-removal preconditions to the ChangeTrust example Aug 13, 2026
Copilot AI requested a review from kaankacar August 13, 2026 13:07
@kaankacar
kaankacar marked this pull request as ready for review August 13, 2026 13:15
Copilot AI balanced review requested due to automatic review settings August 13, 2026 13:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Documents safe trustline removal in the assets skill.

Changes:

  • Adds removal preconditions and error handling.
  • Updates creation guidance and best practices.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread skills/assets/SKILL.md
Comment on lines +253 to +255
3. **Clear offers / buying liabilities.** Open DEX offers that buy the asset
create buying liabilities; cancel them (`manageSellOffer`/`manageBuyOffer`
with `amount: "0"`) before removal.
Comment thread skills/assets/SKILL.md
Comment on lines +274 to +275
if (parseFloat(trustline.buying_liabilities) !== 0)
throw new Error("Cancel open offers buying this asset first");
@kaankacar

Copy link
Copy Markdown
Contributor

🤖 Automated message from Kaan's Automated Triage Bot.

Verified before merging: the Horizon result-codes reference maps op_invalid_limitCHANGE_TRUST_INVALID_LIMIT, and the operations reference confirms CHANGE_TRUST_CANNOT_DELETE means the trustline is still referenced by a liquidity pool (CAP-38) — exactly how the new section explains them. The pre-check snippet uses real Horizon balance-line fields and the standard SDK error shape, and the four removal preconditions match protocol behavior. CI is green — merging.

@kaankacar kaankacar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Result codes and deletion preconditions verified against the Horizon and operations references.

@kaankacar
kaankacar merged commit 1d54f5c into main Aug 13, 2026
6 checks passed
@kaankacar
kaankacar deleted the copilot/add-trustline-removal-preconditions branch August 13, 2026 14:05
@kaankacar

Copy link
Copy Markdown
Contributor

🤖 Automated message from Kaan's Automated Triage Bot.

Both review points were correct and are addressed in #91: the removal guidance now says manageBuyOffer cancels with buyAmount: "0" (verified against the js-stellar-base source), and the preflight snippet notes that pool usage isn't visible on the balance line and surfaces as op_cannot_delete at submit.

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.

Add trustline-removal preconditions to the ChangeTrust example

3 participants