Skip to content

fix(tonco-dex): pass swap msg.body to sendTON and use correct pTON wallet#138

Merged
xlabtg merged 3 commits intoxlabtg:mainfrom
konard:issue-137-59cddc9d2fd7
Apr 11, 2026
Merged

fix(tonco-dex): pass swap msg.body to sendTON and use correct pTON wallet#138
xlabtg merged 3 commits intoxlabtg:mainfrom
konard:issue-137-59cddc9d2fd7

Conversation

@konard
Copy link
Copy Markdown

@konard konard commented Apr 11, 2026

Problem

Fixes two critical bugs in tonco_execute_swap reported in issue #137.

P1 — Swap body dropped (critical)

sendTON(msg.to, value, **undefined**) discarded the entire Cell payload built by PoolMessageManager.createSwapExactInMessage. The router/pTON wallet received a plain TON transfer with no swap instruction, so no swap ever executed on-chain.

Root cause: msg from the SDK is { to, value, body: Cell }. The third argument to sendTON was hardcoded as undefined instead of msg.body.

Fix: Pass msg.body as the third argument to sendTON.

P2 — Wrong pTON wallet when TON is jetton1 (routing failure)

When a pool stores TON as jetton1 (i.e. zeroToOne = false), tokenIn is j1Data — but the code unconditionally read the pTON wallet from j0Data.wallet / j0Data.walletV1_5. This fed the wrong wallet address to createSwapExactInMessage, causing incorrect routing or transaction failure.

Root cause: The isTonIn branch hardcoded j0Data instead of using tokenIn (the variable that already resolves to the correct side).

Fix: Use tokenIn.wallet / tokenIn.walletV1_5 — this is always the TON-side token regardless of pool ordering.

Changes

  • plugins/tonco-dex/index.js — two one-line fixes in tonco_execute_swap
  • plugins/tonco-dex/tests/index.test.js — two new test suites covering the fixes

How to reproduce

Both issues can be observed by reading plugins/tonco-dex/index.js:

// P1 — before fix
await _sdk.ton.sendTON(msg.to.toString(), value, undefined);   // body silently dropped

// P2 — before fix (isTonIn branch)
userJettonInWallet = Address.parse(j0Data.wallet);  // wrong when TON is jetton1

Tests

  • P1 test: captures sendTON arguments via a mock and asserts the body is not undefined/null when the swap message is built.
  • P2 test: reads the plugin source and asserts the isTonIn branch references tokenIn.wallet, not j0Data.wallet.

All 332 tests pass locally (npm test), 0 lint errors.

🤖 Generated with Claude Code

Fixes #137

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

Issue: xlabtg#137
…llet

P1: Pass msg.body when calling sendTON for swap execution.
Previously the code called sendTON(msg.to, value, undefined), silently
discarding the TONCO Cell payload. The router/pTON wallet received a
plain TON transfer with no swap instruction, so no swap ever executed
on-chain. Fixed by passing msg.body as the third argument.

P2: Select pTON wallet from tokenIn (the actual TON-side token) instead
of hardcoding j0Data. When a pool stores TON as jetton1 (zeroToOne=false),
j0Data is NOT the TON side — using j0Data.wallet in that case sends
the wrong pTON wallet address to createSwapExactInMessage. Fixed by
using tokenIn.wallet / tokenIn.walletV1_5, which always refers to the
correct input-side token regardless of pool ordering.

Tests: added unit tests that verify both fixes.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@konard konard changed the title [WIP] Problems with the TONCO DEX plugin fix(tonco-dex): pass swap msg.body to sendTON and use correct pTON wallet Apr 11, 2026
@konard konard marked this pull request as ready for review April 11, 2026 21:40
@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.749869

📊 Context and tokens usage:

  • Context window: 89.3K / 1M (9%) input tokens, 16.2K / 64K (25%) output tokens

Total: (84.1K + 4.0M cached) input tokens, 16.2K output tokens, $1.749869 cost

🤖 Models used:

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

📎 Log file uploaded as Gist (1834KB)


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

🔄 Auto-restart 1/3

Detected uncommitted changes from previous run. Starting new session to review and commit or discard them.

Uncommitted files:

?? full-test-output.txt
?? issue-137.txt
?? test-output.txt
?? test-output2.txt

Auto-restart will stop after changes are committed or discarded, or after 2 more iterations. Please wait until working session will end and give your feedback.

@konard
Copy link
Copy Markdown
Author

konard commented Apr 11, 2026

🔄 Auto-restart 1/3 Log

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

💰 Cost: $0.137779

📊 Context and tokens usage:

  • Context window: 28.6K / 1M (3%) input tokens, 1.3K / 64K (2%) output tokens

Total: (16.9K + 184.3K cached) input tokens, 1.3K output tokens, $0.137779 cost

🤖 Models used:

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

📎 Log file uploaded as Gist (3119KB)


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 65ba162 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.

Problems with the TONCO DEX plugin

2 participants