Skip to content

PROTO-835: fix: use precise ui amounts for sending and receiving token transfers#179

Merged
Oighty merged 5 commits into
mainfrom
fix/precise-values
Feb 18, 2026
Merged

PROTO-835: fix: use precise ui amounts for sending and receiving token transfers#179
Oighty merged 5 commits into
mainfrom
fix/precise-values

Conversation

@Oighty

@Oighty Oighty commented Feb 3, 2026

Copy link
Copy Markdown
Collaborator

This PR updates the V1 Solana Portal to use precise UI amounts when receiving and sending token transfers. Specifically, it updates the transfer_* and release_inbound_* instructions to work with the updated ext_swap program. 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.

Comment thread programs/portal/src/instructions/transfer.rs Outdated
@Oighty Oighty changed the title fix: use precise ui amounts for sending and receiving token transfers PROTO-835: fix: use precise ui amounts for sending and receiving token transfers Feb 4, 2026
@Oighty Oighty marked this pull request as ready for review February 4, 2026 20:04
Copilot AI review requested due to automatic review settings February 4, 2026 20:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_up to ensure users receive at least the bridged amount
  • Sending/burning now uses amount_to_principal_down to protect users from over-burning
  • Updated ext_swap IDL 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.

Comment thread tests/unit/portal.test.ts Outdated
Comment thread tests/unit/portal.test.ts Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@Oighty Oighty merged commit 67bf8a6 into main Feb 18, 2026
5 checks passed
@Oighty Oighty deleted the fix/precise-values branch February 18, 2026 14:46
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.

4 participants