fix(tonco-dex): pass swap msg.body to sendTON and use correct pTON wallet#138
fix(tonco-dex): pass swap msg.body to sendTON and use correct pTON wallet#138xlabtg merged 3 commits intoxlabtg:mainfrom
Conversation
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>
🤖 Solution Draft LogThis log file contains the complete execution trace of the AI solution draft process. 💰 Cost: $1.749869📊 Context and tokens usage:
Total: (84.1K + 4.0M cached) input tokens, 16.2K output tokens, $1.749869 cost 🤖 Models used:
📎 Log file uploaded as Gist (1834KB)Now working session is ended, feel free to review and add any feedback on the solution draft. |
🔄 Auto-restart 1/3Detected uncommitted changes from previous run. Starting new session to review and commit or discard them. Uncommitted files: 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. |
🔄 Auto-restart 1/3 LogThis log file contains the complete execution trace of the AI solution draft process. 💰 Cost: $0.137779📊 Context and tokens usage:
Total: (16.9K + 184.3K cached) input tokens, 1.3K output tokens, $0.137779 cost 🤖 Models used:
📎 Log file uploaded as Gist (3119KB)Now working session is ended, feel free to review and add any feedback on the solution draft. |
✅ Ready to mergeThis pull request is now ready to be merged:
Monitored by hive-mind with --auto-restart-until-mergeable flag |
This reverts commit bab7b02.
Problem
Fixes two critical bugs in
tonco_execute_swapreported in issue #137.P1 — Swap body dropped (critical)
sendTON(msg.to, value, **undefined**)discarded the entire Cell payload built byPoolMessageManager.createSwapExactInMessage. The router/pTON wallet received a plain TON transfer with no swap instruction, so no swap ever executed on-chain.Root cause:
msgfrom the SDK is{ to, value, body: Cell }. The third argument tosendTONwas hardcoded asundefinedinstead ofmsg.body.Fix: Pass
msg.bodyas the third argument tosendTON.P2 — Wrong pTON wallet when TON is jetton1 (routing failure)
When a pool stores TON as
jetton1(i.e.zeroToOne = false),tokenInisj1Data— but the code unconditionally read the pTON wallet fromj0Data.wallet / j0Data.walletV1_5. This fed the wrong wallet address tocreateSwapExactInMessage, causing incorrect routing or transaction failure.Root cause: The
isTonInbranch hardcodedj0Datainstead of usingtokenIn(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 intonco_execute_swapplugins/tonco-dex/tests/index.test.js— two new test suites covering the fixesHow to reproduce
Both issues can be observed by reading
plugins/tonco-dex/index.js:Tests
sendTONarguments via a mock and asserts thebodyis notundefined/nullwhen the swap message is built.isTonInbranch referencestokenIn.wallet, notj0Data.wallet.All 332 tests pass locally (
npm test), 0 lint errors.🤖 Generated with Claude Code
Fixes #137