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

feat(interchain-token-service): apply scaling factor on token transfer based on token decimals #675

Conversation

fish-sammy
Copy link
Collaborator

@fish-sammy fish-sammy commented Nov 1, 2024

Description

Todos

  • Unit tests
  • Manual tests
  • Documentation
  • Connect epics/issues

Steps to Test

Expected Behaviour

Other Notes

@fish-sammy fish-sammy requested a review from a team as a code owner November 1, 2024 15:48
@fish-sammy fish-sammy changed the base branch from main to AXE-6168-Calculate-the-scaling-factor-at-token-deployment-and-store-it-in-the-ITS-hub November 1, 2024 15:49
@fish-sammy fish-sammy force-pushed the AXE-6169-Apply-the-scaling-factor-at-token-transfer branch from 4c1556e to 905d6c9 Compare November 1, 2024 15:50
@fish-sammy fish-sammy changed the title AXE 6169 Apply the scaling factor at token transfer feat(interchain-token-service): apply scaling factor on token transfer based on token decimals Nov 1, 2024
Copy link

codecov bot commented Nov 1, 2024

Codecov Report

Attention: Patch coverage is 75.64103% with 19 lines in your changes missing coverage. Please review.

Project coverage is 93.52%. Comparing base (b1f1511) to head (83ade73).

Files with missing lines Patch % Lines
...s/interchain-token-service/src/contract/execute.rs 74.32% 19 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

@fish-sammy fish-sammy force-pushed the AXE-6169-Apply-the-scaling-factor-at-token-transfer branch 5 times, most recently from d7abd6e to b79e9ea Compare November 1, 2024 16:15
@fish-sammy fish-sammy force-pushed the AXE-6169-Apply-the-scaling-factor-at-token-transfer branch from 3714ab1 to 966d69b Compare November 1, 2024 17:23
@fish-sammy fish-sammy force-pushed the AXE-6169-Apply-the-scaling-factor-at-token-transfer branch from ce2be5e to 6637f40 Compare November 1, 2024 20:42
@fish-sammy fish-sammy force-pushed the AXE-6169-Apply-the-scaling-factor-at-token-transfer branch from 6637f40 to 641cce2 Compare November 1, 2024 20:44
@fish-sammy fish-sammy force-pushed the AXE-6169-Apply-the-scaling-factor-at-token-transfer branch 5 times, most recently from 0b8008f to f196d7a Compare November 3, 2024 15:14
@fish-sammy fish-sammy force-pushed the AXE-6169-Apply-the-scaling-factor-at-token-transfer branch from f196d7a to 9c6d991 Compare November 3, 2024 15:15
Comment on lines +304 to +342
// 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,
}
})
Copy link
Contributor

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

@fish-sammy fish-sammy deleted the branch AXE-6168-Calculate-the-scaling-factor-at-token-deployment-and-store-it-in-the-ITS-hub November 4, 2024 15:34
@fish-sammy fish-sammy closed this Nov 4, 2024
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