-
Notifications
You must be signed in to change notification settings - Fork 25
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
feat(interchain-token-service): apply scaling factor on token transfer based on token decimals #675
Conversation
4c1556e
to
905d6c9
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## AXE-6168-Calculate-the-scaling-factor-at-token-deployment-and-store-it-in-the-ITS-hub #675 +/- ##
=========================================================================================================================
- Coverage 93.56% 93.52% -0.05%
=========================================================================================================================
Files 237 237
Lines 35220 35293 +73
=========================================================================================================================
+ Hits 32955 33009 +54
- Misses 2265 2284 +19 ☔ View full report in Codecov by Sentry. |
d7abd6e
to
b79e9ea
Compare
3714ab1
to
966d69b
Compare
ce2be5e
to
6637f40
Compare
6637f40
to
641cce2
Compare
0b8008f
to
f196d7a
Compare
f196d7a
to
9c6d991
Compare
// It's intentionally written in this way since the end result may still be fine even if | ||
// 1) amount * (10 ^ (dest_chain_decimals)) overflows | ||
// 2) amount / (10 ^ (src_chain_decimals)) is zero | ||
let scaling_factor = Uint256::from_u128(10) | ||
.checked_pow(source_decimals.abs_diff(destination_decimals).into()) | ||
.change_context_lazy(|| Error::InvalidTransferAmount { | ||
source_chain: source_chain.to_owned(), | ||
destination_chain: destination_chain.to_owned(), | ||
amount: source_amount, | ||
})?; | ||
let destination_amount = if source_decimals > destination_decimals { | ||
source_amount | ||
.checked_div(scaling_factor) | ||
.expect("scaling_factor must be non-zero") | ||
} else { | ||
source_amount | ||
.checked_mul(scaling_factor) | ||
.change_context_lazy(|| Error::InvalidTransferAmount { | ||
source_chain: source_chain.to_owned(), | ||
destination_chain: destination_chain.to_owned(), | ||
amount: source_amount, | ||
})? | ||
}; | ||
|
||
if destination_amount.gt(&destination_max_uint) { | ||
bail!(Error::InvalidTransferAmount { | ||
source_chain: source_chain.to_owned(), | ||
destination_chain: destination_chain.to_owned(), | ||
amount: source_amount, | ||
}) | ||
} | ||
|
||
nonempty::Uint256::try_from(destination_amount).change_context_lazy(|| { | ||
Error::InvalidTransferAmount { | ||
source_chain: source_chain.to_owned(), | ||
destination_chain: destination_chain.to_owned(), | ||
amount: source_amount, | ||
} | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this calculation could get extracted into it's own function
Description
Todos
Steps to Test
Expected Behaviour
Other Notes