Skip to content

fix(tonco-dex): fix GraphQL bugs in pool stats and positions tools#143

Merged
xlabtg merged 3 commits intoxlabtg:mainfrom
konard:issue-141-de6e8f5ef03d
Apr 11, 2026
Merged

fix(tonco-dex): fix GraphQL bugs in pool stats and positions tools#143
xlabtg merged 3 commits intoxlabtg:mainfrom
konard:issue-141-de6e8f5ef03d

Conversation

@konard
Copy link
Copy Markdown

@konard konard commented Apr 11, 2026

Summary

Fixes two critical GraphQL bugs reported in #141.

Bug 1: tonco_get_pool_stats — silent wrong-result when pool_address missing

Root cause: When pool_address was undefined/empty, normalizeToRaw() returned undefined. JSON serialization silently drops undefined fields, so { address: undefined } became {} — the indexer then returned all pools instead of the requested one. The first pool in the response was silently used.

Fix: Added explicit early-return validation before normalizeToRaw():

if (!params.pool_address) {
  return { success: false, error: "pool_address parameter is required" };
}

Bug 2: tonco_get_positions — GraphQL validation error on pool subfield

Root cause: The TONCO indexer's Position.pool field is a String! (raw pool address), not an embedded object type. The old query selected subfields on it:

pool {
  address version fee tick tickSpacing priceSqrt liquidity
  jetton0 { ... } jetton1 { ... }
}

This caused: "Field 'pool' must not have a selection since type 'String!' has no subfields."

Fix:

  • Query pool as a bare scalar string (the pool address)
  • Use Position's own jetton0/jetton1 fields (which ARE object types) for token info
  • Add a separate pools query to fetch tick, version, fee, tickSpacing for in-range calculation
  • Fix creationTime parsing: the indexer returns ISO date strings, not Unix timestamps

How to reproduce the issues

Bug 1:

await tonco_get_pool_stats.execute({}) // pool_address missing
// Before fix: silently returned stats for the first pool in the database
// After fix:  { success: false, error: "pool_address parameter is required" }

Bug 2:

await tonco_get_positions.execute({ owner_address: "EQ..." })
// Before fix: { success: false, error: "GraphQL error: Field 'pool' must not have a selection since type 'String!' has no subfields." }
// After fix:  { success: true, data: { positions: [...] } }

Tests

Regression tests added in plugins/tonco-dex/tests/index.test.js:

  • Bug #141 fix: tonco_get_pool_stats validates pool_address — 3 tests
  • Bug #141 fix: tonco_get_positions uses correct GraphQL schema — 3 tests

All 37 tests pass (node --test plugins/tonco-dex/tests/index.test.js).

Fixes #141

konard and others added 2 commits April 11, 2026 23:06
Adding .gitkeep for PR creation (default mode).
This file will be removed when the task is complete.

Issue: xlabtg#141
Bug 1 (tonco_get_pool_stats): When pool_address was missing or empty,
normalizeToRaw() returned undefined, JSON serialization silently dropped
the field, and the indexer returned ALL pools instead of erroring. Added
explicit early-return validation before normalizeToRaw().

Bug 2 (tonco_get_positions): The TONCO indexer's Position.pool field is
a String! (pool address scalar), NOT an embedded object type. The old
query selected subfields on it (pool { address version fee ... }), causing
a GraphQL validation error: "Field 'pool' must not have a selection since
type 'String!' has no subfields." Fixed by:
- Querying pool as a bare scalar field
- Using Position's own jetton0/jetton1 fields for token info
- Adding a separate pools query to fetch tick/version/fee for in-range calc
- Fixing creationTime parsing (indexer returns ISO string, not Unix timestamp)

Added regression tests for both bugs in index.test.js.

Fixes xlabtg#141

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@konard konard changed the title [WIP] [CRITICAL] TONCO DEX Plugin Multiple GraphQL Bugs - Pool Stats & Positions Tools Broken fix(tonco-dex): fix GraphQL bugs in pool stats and positions tools Apr 11, 2026
@konard konard marked this pull request as ready for review April 11, 2026 23:12
@konard
Copy link
Copy Markdown
Author

konard commented Apr 11, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost: $1.323729

📊 Context and tokens usage:

  • Context window: 90.1K / 1M (9%) input tokens, 17.7K / 64K (28%) output tokens

Total: (85.7K + 2.5M cached) input tokens, 17.7K output tokens, $1.323729 cost

🤖 Models used:

  • Tool: Anthropic Claude Code
  • Requested: sonnet
  • Model: Claude Sonnet 4.6 (claude-sonnet-4-6)

📎 Log file uploaded as Gist (1454KB)


Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Copy Markdown
Author

konard commented Apr 11, 2026

✅ Ready to merge

This pull request is now ready to be merged:

  • All CI checks have passed
  • No merge conflicts
  • No pending changes

Monitored by hive-mind with --auto-restart-until-mergeable flag

@xlabtg xlabtg merged commit ce76028 into xlabtg:main Apr 11, 2026
8 checks passed
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.

[CRITICAL] TONCO DEX Plugin Multiple GraphQL Bugs - Pool Stats & Positions Tools Broken

2 participants