feat: add TON network support (native TON + USDT-Jetton) - #69
Open
vectorsss wants to merge 3 commits into
Open
Conversation
Adds the "ton" network alongside the existing Tron/EVM/Solana/Plasma listeners. Uses xssnick/tonutils-go to talk to mainnet/testnet lite servers; the rpc_nodes URL is the TON global.config.json endpoint. - ton_task: polling-style scan of each owner's recent transactions, decoding internal messages into either Jetton TransferNotification payments (matched via the owner's deterministically-derived jetton wallet contract) or native TON value transfers. - listen_ton_job: 5s cron job mirroring the Solana scheduler. - Address normalization collapses the three TON surface forms (bounceable EQ, non-bounceable UQ, raw 0:hex) into one canonical storage key at the wallet_address and transaction_lock layers so admin input and chain-derived addresses match. - API client and per-owner jetton wallet address are cached across ticks to keep lite-server round-trips bounded. Enabling TON still requires admin-side seed rows in chains, chain_tokens and rpc_nodes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ver config Adds TON to the three idempotent seeders in mdb_table_init so a fresh install boots with TON enabled and ready to receive payments. Existing deployments pick up the new rows on next start; ON CONFLICT DO NOTHING preserves any admin edits. Seeded values: - chains: ton (DisplayName "TON", MinConfirmations 1). - chain_tokens: USDT Jetton master EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs at 6 decimals, plus a native TON row at 9 decimals. - rpc_nodes: ton-blockchain.github.io/global.config.json. type=http describes how tonutils-go fetches the config; lite-server traffic itself runs over ADNL/TCP after that. A new package test asserts the TON rows land and that a second seed pass is a no-op. testutil also includes ton in its standard chains list so IsChainEnabled checks remain consistent across the codebase. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Hardens the TON listener against three classes of correctness gap that could miss legitimate payments or settle unconfirmed ones. - Outcome enum on processing. Only terminal outcomes (processed/irrelevant) seed the dedup cache; transient failures and not-yet-visible orders return retry so the next tick gets another shot instead of turning into a multi-hour blind spot. - Block-count confirmation gate. First sight records the current masterchain seqno as a safe upper bound on the tx's anchor and defers; later sights settle once the live master seqno has advanced by min_confirmations. No wall-clock head-start (which would over-credit under cadence variance or clock skew). The scan cutoff extends by the gate's max wait so high min_confirmations values don't age out before settling. effectiveTonMinConfirmations clamps admin misconfigs with a warn, and the same clamped value extends the TON order's transaction_lock TTL via lockExpirationForNetwork so the lock can't expire under the gate. - Plain-transfer body classifier. Native TON acceptance now requires an empty body or a 32-bit opcode of tonOpTextComment / tonOpEncryptedComment. Contract notifications carrying forwarding TON are rejected, preventing amount-collision false credits. - Defensive guards: empty tx.Hash is skipped (would otherwise dedup-collide), bounced messages are filtered, no-active-lock logs are debug-level so active wallets don't flood the journal. Behavior verified end-to-end on TON testnet through several confirmation cycles. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds TON (The Open Network) as a new supported network. Both native
TON and USDT-Jetton receiving paths work end-to-end on TON testnet
and have been verified against the Tether-issued USDT-Jetton master
on mainnet (decode-only). Related: #68 (frontend cashier UI).
What's included
Backend listener (
src/model/service/ton_task.go,src/task/listen_ton_job.go)query per tick, decodes both native TON and Jetton transfer
notifications.
xssnick/tonutils-gov1.16.0 (native lite-server / ADNLprotocol — no third-party indexer dependency, no API key needed).
not wall-clock estimates) honouring
chains.min_confirmations.retrying; only terminal outcomes seed the dedup cache.
0x00000000/0x2167da4b(TEP-1 encrypted comment) prefixes;rejects contract notifications carrying forwarding TON.
0:hex...collapse to onecanonical form at the wallet and transaction_lock layers.
Seed data (
src/model/dao/mdb_table_init.go)chainsrow forton,chain_tokensrows for USDT-Jetton masterEQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs(6 decimals) andnative TON (9 decimals),
rpc_nodesrow pointing atton-blockchain.github.io/global.config.json.ON CONFLICT DO NOTHING).Order-creation side
transaction_lock.expires_atbymin_confirmations × 5sso the listener's confirmation gate can'toutlive the lock it gates.
Test evidence
encrypted, jetton notification, NFT opcode), confirmation gate
(first-sight defer, block-advance, no over-credit), TTL scaling +
eviction, clamp policy for misconfigured
min_confirmations, TONaddress canonicalization (EQ/UQ/raw), seed idempotency.
go vet ./...clean./payments/gmpay/v1/order/create-transaction, sent the exactactual_amountfrom a separate testnet wallet, observed thelistener match the
transaction_lock, callOrderProcessing,mark the order
paidand write the on-chain tx hash.Known limitation — frontend cashier
The compiled
src/www/admin SPA / cashier page is not affected bybackend changes alone. The cashier
_trade_id-*.jshas a hard-codedchain metadata table (
ut) that lacks a TON entry, andsrc/www/images/chains/has noton.png. This renders TON orderswith the lowercase string
tonand a missing logo. Functionally thepayment still completes — only the visual presentation is affected.
The frontend source for
src/www/does not appear to be in thisrepository, so the fix needs to come from the upstream frontend
build. Opened as #68 for visibility.
Test plan
go build ./...go vet ./...go test ./model/...(new tests + existing pass)transactions correctly classified)
🤖 Generated with Claude Code