Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sdk: quote destination amount truncation fix #560

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

kev1n-peters
Copy link
Contributor

@kev1n-peters kev1n-peters commented Nov 27, 2024

Fixes an issue where calling quote with an amount that has more fractional digits than the destination chain supports throws an error. We need to truncate and scale the destination amount to destination chain decimals (min(srcDecimals, dstDecimals, 8). If the transfer amount has dust, the contract will revert:

revert TransferAmountHasDust(amount, amount - newAmount);
. The SDK will strip off any dust instead of letting the transaction revert. This may result in the actual transfer amount being slightly different than the input amount, but that is a tradeoff we're making here to avoid adding additional complexity for Connect to handle (e.g. amount can't contain dust).

// remove dust to avoid `TransferAmountHasDust` revert reason
const truncatedAmount = amount.truncate(
amt,
Math.min(amt.decimals, dstTokenDecimals, NttRoute.TRIMMED_DECIMALS)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

See:

let to_decimals = TRIMMED_DECIMALS.min(from_decimals).min(to_decimals);

Fixes an issue where calling quote with an amount that has
more fractional digits than the destination chain supports
throws an error. We need to truncate and scale the destination
amount to destination chain decimals.
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.

3 participants