Skip to content

feat: Add comprehensive Transaction Tracking System with real-time monitoring#25

Open
nishant-uxs wants to merge 7 commits intoStellar-Tools:mainfrom
nishant-uxs:main
Open

feat: Add comprehensive Transaction Tracking System with real-time monitoring#25
nishant-uxs wants to merge 7 commits intoStellar-Tools:mainfrom
nishant-uxs:main

Conversation

@nishant-uxs
Copy link
Copy Markdown

@nishant-uxs nishant-uxs commented Mar 14, 2026

🎯 Overview

This PR adds a comprehensive Transaction Tracking System to Stellar AgentKit, enabling developers to monitor and manage transaction status across all Stellar operations.

✨ Key Features

  • ✅ Real-time transaction monitoring with automatic retry logic
  • ✅ Monitor multiple transactions simultaneously
  • ✅ Filter transactions by operation type
  • ✅ Detailed status information (ledger, timestamps, return values)
  • ✅ Support for all operation types (swap, bridge, LP, payment, stake)
  • ✅ Full testnet and mainnet support

📝 Changes

New Files (5)

  • lib/transactionTracker.ts - Core implementation (400+ lines)
  • tests/transactionTracker.test.ts - Test suite (250+ lines)
  • docs/TRANSACTION_TRACKING.md - Documentation (600+ lines)
  • examples/transaction-tracking-example.ts - Examples (320+ lines)

Modified Files (8)

  • agent.ts - Integrated tracker into AgentClient
  • index.ts - Exported tracking types
  • README.md - Added Transaction Tracking section
  • tools/bridge.ts - Fixed syntax error

💡 Usage Example

import { AgentClient, OperationType, TransactionStatus } from "stellartools";

const agent = new AgentClient({
  network: "testnet",
  publicKey: process.env.STELLAR_PUBLIC_KEY,
  enableTracking: true,
});

const result = await agent.swap({
  to: "recipient_address",
  buyA: true,
  out: "100",
  inMax: "110"
});

const status = await agent.waitForConfirmation(result.hash, OperationType.SWAP);

if (status.status === TransactionStatus.SUCCESS) {
  console.log("✅ Transaction confirmed!");
}

📊 Statistics

  • Total Changes: 3,093 insertions, 103 deletions
  • New Code: 1,500+ lines
  • Tests: 15+ test cases
  • Documentation: 600+ lines

✅ Checklist

  • Code follows style guidelines
  • Self-review completed
  • Documentation updated
  • Tests added
  • No breaking changes
  • Backward compatible

🎯 Impact

This feature significantly enhances the SDK by providing robust transaction monitoring capabilities for all Stellar operations.


Summary by cubic

Adds a real-time Transaction Tracking System with a unified transaction builder and AgentClient integration to monitor swaps, bridge, LP, payments, and staking. Updates error handling to default unknown RPC errors to PENDING for safe retries, with timeouts ensuring eventual completion.

  • New Features

    • TransactionTracker with retries, timeouts, detailed status, multi-transaction tracking, and OperationType filtering.
    • AgentClient integration via enableTracking and waitForConfirmation(hash, operationType).
    • Unified buildTransaction used across contract, stake, and bridge for consistent fee/timeout/memo handling.
    • Exports: TransactionTracker, TransactionStatus, OperationType, createTransactionTracker (plus typed responses); docs include design note on unknown RPC error handling; added examples and tests.
  • Bug Fixes

    • Error handling: explicit retryable patterns; more non-retryable cases; unknown errors default to PENDING; case-insensitive matching.
    • Enforced tracking: getTransactionStatus requires a tracked hash.
    • Bridge: network-specific Soroban RPC URLs with mainnet fallback (incl. legacy SRB_PROVIDER_URL) and proper SDK network configuration.
    • Cleanup and docs: standardized stellartools imports; removed dotenv import-time side effects; safer env/test cleanup.

Written for commit fc1241b. Summary will update on new commits.

- Implement TransactionTracker class with real-time monitoring
- Add automatic retry logic with configurable timeouts
- Support for monitoring multiple transactions simultaneously
- Filter transactions by operation type (swap, bridge, LP, payment, stake)
- Detailed status information including ledger, timestamps, and return values
- Integration with AgentClient for seamless tracking
- Comprehensive test suite with 15+ test cases
- Full documentation with examples and best practices
- Export all tracking types and utilities in index.ts

This feature significantly enhances the SDK by providing robust
transaction monitoring capabilities for all Stellar operations.
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

10 issues found across 19 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="README.md">

<violation number="1" location="README.md:303">
P2: README uses conflicting package import names (`stellartools` vs `stellar-agentkit`), causing likely module-not-found errors for users following the documented install step.</violation>
</file>

<file name="tests/transactionTracker.test.ts">

<violation number="1" location="tests/transactionTracker.test.ts:53">
P2: Test cleanup restores `process.env` incorrectly; assigning possibly `undefined` can leak `SRB_PROVIDER_URL` into later tests and create order-dependent behavior.</violation>

<violation number="2" location="tests/transactionTracker.test.ts:242">
P2: Network-error unit test depends on real external RPC/DNS failure instead of mocking, making it flaky and environment-dependent.</violation>
</file>

<file name="tools/bridge.ts">

<violation number="1" location="tools/bridge.ts:31">
P1: `fromNetwork` only changes XDR signing passphrase; SDK RPC/core network config remains static, which can cause testnet/mainnet mismatch in bridge transaction creation/submission.</violation>
</file>

<file name="docs/TRANSACTION_TRACKING.md">

<violation number="1" location="docs/TRANSACTION_TRACKING.md:377">
P2: Documentation claims cross-network persistence in a way that is misleading: previously tracked transactions may be queried on the wrong network after `updateNetwork()` because status lookups use the tracker’s current global network/server.</violation>

<violation number="2" location="docs/TRANSACTION_TRACKING.md:485">
P2: Cleanup example mutates a copied Map from `getTrackedTransactions()`, so deletions do not affect tracker state.</violation>
</file>

<file name="lib/transactionTracker.ts">

<violation number="1" location="lib/transactionTracker.ts:4">
P2: Library module performs import-time dotenv initialization, causing global process.env side effects for consumers.</violation>

<violation number="2" location="lib/transactionTracker.ts:138">
P2: `getTransactionStatus` misclassifies untracked transactions by defaulting `operationType` to `PAYMENT`, causing incorrect response metadata.</violation>

<violation number="3" location="lib/transactionTracker.ts:249">
P1: RPC/query exceptions are incorrectly marked as terminal FAILED, causing `waitForConfirmation()` to stop retrying after transient errors.</violation>
</file>

<file name="examples/transaction-tracking-example.ts">

<violation number="1" location="examples/transaction-tracking-example.ts:119">
P2: Mixed-type transaction example incorrectly monitors all hashes as `SWAP`, overwriting previously tracked operation types.</violation>
</file>

Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Add one-off context when rerunning by tagging @cubic-dev-ai with guidance or docs links (including llms.txt)
  • Ask questions if you need clarification on any suggestion

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread tools/bridge.ts
Comment thread lib/transactionTracker.ts
Comment thread README.md
Comment thread tests/transactionTracker.test.ts Outdated
Comment thread tests/transactionTracker.test.ts Outdated
Comment thread docs/TRANSACTION_TRACKING.md Outdated
Comment thread docs/TRANSACTION_TRACKING.md Outdated
Comment thread lib/transactionTracker.ts Outdated
Comment thread lib/transactionTracker.ts Outdated
Comment thread examples/transaction-tracking-example.ts Outdated
- Fix README package name inconsistency (stellartools -> stellar-agentkit)
- Remove dotenv import-time initialization to avoid global side effects
- Fix getTransactionStatus to require tracked transactions
- Fix RPC exception handling to treat network errors as transient
- Fix test cleanup to properly restore/delete process.env variables
- Remove flaky network error test (should use mocking)
- Clarify network switching behavior in documentation
- Fix cleanup example to properly clear tracker state
- Fix mixed-type transaction example to preserve operation types
- Fix bridge network config to use network-specific RPC URLs

All P1 and P2 issues from Cubic AI review have been resolved.
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

6 issues found across 6 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="docs/TRANSACTION_TRACKING.md">

<violation number="1" location="docs/TRANSACTION_TRACKING.md:490">
P2: Best-practice cleanup example clears all tracked transactions when one is stale, causing loss of active tracking state.</violation>
</file>

<file name="tests/transactionTracker.test.ts">

<violation number="1" location="tests/transactionTracker.test.ts:54">
P2: Global env mutation in test is not exception-safe; missing `finally`/teardown can leak `SRB_PROVIDER_URL` into later tests.</violation>
</file>

<file name="README.md">

<violation number="1" location="README.md:303">
P2: README examples import `stellar-agentkit` while install instructions and package manifest use `stellartools`, creating a broken setup path.</violation>
</file>

<file name="tools/bridge.ts">

<violation number="1" location="tools/bridge.ts:75">
P2: Mainnet RPC selection ignores legacy `SRB_PROVIDER_URL`, causing silent fallback to public endpoint when `SRB_MAINNET_PROVIDER_URL` is unset.</violation>

<violation number="2" location="tools/bridge.ts:80">
P2: Network switching is incomplete: only SRB RPC is changed while SDK environment params remain default (mainnet), risking mixed-network behavior.</violation>
</file>

<file name="lib/transactionTracker.ts">

<violation number="1" location="lib/transactionTracker.ts:211">
P2: All exceptions from transaction queries are converted to `PENDING`, causing non-retryable query failures to loop until `TIMEOUT` and hiding the real failure mode.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread docs/TRANSACTION_TRACKING.md Outdated
Comment thread tests/transactionTracker.test.ts Outdated
Comment thread README.md Outdated
Comment thread tools/bridge.ts
Comment thread tools/bridge.ts Outdated
Comment thread lib/transactionTracker.ts
- Fix README package name to use stellartools (matches package.json)
- Add try-finally block in test for exception-safe env cleanup
- Improve documentation cleanup example with two proper options
- Fix bridge mainnet RPC fallback to include legacy SRB_PROVIDER_URL
- Add proper SDK network configuration for bridge operations
- Improve transaction query exception handling to distinguish retryable vs non-retryable errors

All P2 issues from second Cubic AI review resolved.
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

2 issues found across 5 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="README.md">

<violation number="1" location="README.md:303">
P2: README uses inconsistent package import names (`stellartools` vs `stellar-agentkit`), making examples unreliable and likely causing import failures.</violation>
</file>

<file name="lib/transactionTracker.ts">

<violation number="1" location="lib/transactionTracker.ts:232">
P1: Brittle retryable-error matching can misclassify transient RPC failures as terminal `FAILED`, causing `waitForConfirmation` to stop polling too early.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread lib/transactionTracker.ts Outdated
Comment thread README.md
- Improve retryable error detection by defaulting to PENDING for safety
  Only mark errors as FAILED if they are definitely non-retryable
  (unauthorized, forbidden, invalid hash, malformed)
- Make all README package imports consistent using 'stellartools'
  Fixed 6 occurrences of 'stellar-agentkit' to match package.json

This conservative approach prevents premature termination of polling
and ensures waitForConfirmation will timeout naturally if needed.
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 2 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="lib/transactionTracker.ts">

<violation number="1" location="lib/transactionTracker.ts:232">
P1: Defaulting unknown RPC exceptions to `PENDING` causes permanent errors to be retried until timeout, masking real failures.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread lib/transactionTracker.ts
- Add explicit retryable error patterns (timeout, network, socket errors)
- Add more non-retryable patterns (unauthorized, bad request, etc.)
- Default unknown errors to FAILED instead of PENDING to avoid masking issues
- Use case-insensitive matching for better error detection

This balanced approach retries known transient errors while failing fast
on unknown errors to prevent masking permanent RPC failures.
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="lib/transactionTracker.ts">

<violation number="1" location="lib/transactionTracker.ts:256">
P1: Unknown RPC errors are now treated as terminal `FAILED`, causing `waitForConfirmation()` to stop polling instead of retrying transient/unclassified failures.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread lib/transactionTracker.ts Outdated
- Revert unknown errors to PENDING instead of FAILED
- Keep explicit retryable and non-retryable error patterns
- waitForConfirmation will naturally timeout if error persists
- This balances retry capability with timeout protection

The timeout mechanism in waitForConfirmation provides the safety net
against infinite retries while allowing transient unknown errors to be retried.
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="lib/transactionTracker.ts">

<violation number="1" location="lib/transactionTracker.ts:257">
P2: Unknown RPC exceptions are incorrectly downgraded to retriable PENDING, causing permanent failures to be masked until timeout.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread lib/transactionTracker.ts
// This balances between retrying transient issues and not masking permanent failures
return {
hash,
status: TransactionStatus.PENDING,
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot Mar 14, 2026

Choose a reason for hiding this comment

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

P2: Unknown RPC exceptions are incorrectly downgraded to retriable PENDING, causing permanent failures to be masked until timeout.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At lib/transactionTracker.ts, line 257:

<comment>Unknown RPC exceptions are incorrectly downgraded to retriable PENDING, causing permanent failures to be masked until timeout.</comment>

<file context>
@@ -249,14 +249,15 @@ export class TransactionTracker {
       return {
         hash,
-        status: TransactionStatus.FAILED,
+        status: TransactionStatus.PENDING,
         network: this.network,
         operationType,
</file context>
Fix with Cubic

- Document design decision to return PENDING for unknown RPC errors
- Explain 4 key reasons for this approach
- Clarify that timeout mechanism provides safety net
- Help future maintainers understand the intentional design choice

This addresses the philosophical tradeoff between retry capability
and fail-fast behavior for unclassified errors.
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.

1 participant