Fix TON STON.fi quote after reserve and jetton swap#1110
Merged
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request refactors fee calculation and quote value resolution across the gem_ton and swapper crates. In gem_ton, the calculate_transaction_fee function now returns a Result and correctly handles swap-attached values, while the signer was updated to ensure token swaps use the sender's Jetton wallet as the destination. In the swapper crate, resolve_max_quote_value was refactored into quote_value_after_reserve and quote_value_after_reserve_by_chain to allow for provider-specific reserved fees, such as the new constant introduced for Stonfi native swaps. All swapper providers and the swapper checklist were updated to reflect these changes. I have no feedback to provide.
gemcoder21
reviewed
May 6, 2026
d65c09a to
2ae8ef5
Compare
Direct Jetton-origin STON.fi swaps to the sender jetton wallet and keep TON preload fee checks aligned with contract swap message reserves. Transfer-style TON swaps reuse normal TON transfer fee handling.
2ae8ef5 to
d0f63f6
Compare
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
Issues Fixed
STON.fi Jetton -> TON could fail after moving from the core-ts proxy swapper to the native Rust provider.
STON.fi TON swap confirmation could under-report the required native TON balance.
0.30 TONfor Jetton-origin swaps andquote.from_value + 0.31 TONfor TON-origin swaps).0.31 TONnative reserve ingem_tonpreload. Transfer quote data continues through the normal TON transfer fee path, so Near Intents is not over-reserved as a STON.fi contract swap.Near Intents TON Jetton -> EVM swaps could fail during preload with TON API decode errors.
destination_address. For USDT -> ETH/BNB that is an EVM0x...address, and TON preload tried to call/jetton/wallets?owner_address=0x....swap_data.data.toas the recipient jetton owner for transfer-style swaps, which is the actual TON deposit address. Contract swaps skip recipient jetton lookup because that metadata is not used by the signer.Follow-up
Source
0.3 TON: https://github.com/ston-fi/sdk/blob/main/packages/sdk/src/contracts/dex/v2_1/router/BaseRouterV2_1.ts#L34-L45
0.01 pTON: https://github.com/ston-fi/sdk/blob/main/packages/sdk/src/contracts/pTON/v2_1/PtonV2_1.ts#L24-L27
Validation
cargo fmt --all --checkcargo test -p gem_ton --features rpc provider::preload::testscargo test -p primitives swap_mockcargo test -p swapper stonfi::provider::testscargo test -p swapper near_intents::provider::testscargo clippy -p gem_ton -p primitives --features gem_ton/rpc --all-targets -- -D warningscargo clippy -p swapper -p gem_ton --features gem_ton/rpc --all-targets -- -D warnings