PROTO-835: fix: use precise ui amounts for sending and receiving token transfers#179
Merged
Conversation
toninorair
reviewed
Feb 4, 2026
toninorair
approved these changes
Feb 4, 2026
SC4RECOIN
approved these changes
Feb 4, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the V1 Solana Portal to use precise UI amounts for token transfers, aligning with changes to the ext_swap program. The changes ensure correct rounding behavior: minting rounds UP to guarantee sufficient tokens, while burning rounds DOWN to prevent over-burning.
Changes:
- Receiving/minting now uses
amount_to_principal_upto ensure users receive at least the bridged amount - Sending/burning now uses
amount_to_principal_downto protect users from over-burning - Updated
ext_swapIDL to work with the modified swap facility
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/portal.test.ts | Added comprehensive test suite covering rounding behavior, fuzz tests, and edge cases for amount conversions |
| tests/test-utils.ts | Added conversion helper functions mirroring Rust logic for amount/principal transformations |
| programs/portal/src/instructions/transfer_extension.rs | Renamed variable from m_amount to m_principal for clarity |
| programs/portal/src/instructions/transfer.rs | Updated to use amount_to_principal_down for burning operations |
| programs/portal/src/instructions/release_inbound_extension.rs | Simplified to use UI amount directly instead of calculating from balance delta |
| programs/portal/src/instructions/release_inbound.rs | Changed from amount_to_principal_down to amount_to_principal_up for minting |
| programs/portal/idls/ext_swap.json | Updated IDL with new instruction, reformatted arrays, and modified account constraints |
| CLAUDE.md | Added new documentation file for Claude Code guidance |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.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.
This PR updates the V1 Solana Portal to use precise UI amounts when receiving and sending token transfers. Specifically, it updates the
transfer_*andrelease_inbound_*instructions to work with the updatedext_swapprogram. The changes to swap facility are described in m0-platform/solana-m-extensions#65.Additionally, the rounding behavior when minting M on received messages is changed to round up the principal amount so that we guarantee the extension program receives enough M principal to equate to the expected UI value. When burning the principal amount for the corresponding UI value is rounded down, to ensure we don't try to burn more M than received from the extension program. This could result in a slight gradual increase in excess M (10^-6 at a time per roundtrip), but it can be managed by adding M to the HubPortal on Ethereum or holding an amount on Solana for this purpose.