Modify _deposit
and other functions to accept the exact amount of the asset's decimals and internally normalizing it
#8
Replies: 3 comments 2 replies
-
Thanks for opening this. Interesting idea.
i am not sure what you mean,
i'm not sure this is true. we would still need to get the
my counterargument to this is that the user still needs to perform a conversion to 18 decimals for one more thing about the this means we would need two functions for these conversions (lower decimals to 18 decimals and 18 decimals to higher decimals):
we would also need a
for 1. although i agree that some users might find it problematic to normalize before deposit, i believe that we would offer a better DX once we release the for 2.: as covered at the beginning, i don't see it as an advantage. whether it is a pure or view function, it's still a constant function, which is what matters after all if we weigh the advantages and disadvantages, i think keeping only please correct me if i misunderstood something, and also @IaroslavMazur what is your take here? |
Beta Was this translation helpful? Give feedback.
-
Having the assets represented throughout the smart contracts in both the normalized and their original form would be fairly (and unnecessarily) complicated and error-prone. Therefore, unless we come up with a way of applying the suggested approach to also address this issue from README, the current solution is better, imo. |
Beta Was this translation helpful? Give feedback.
-
Closing this discussion since I also agree with the |
Beta Was this translation helpful? Give feedback.
-
Suggestions
_calculateTransferAmount
to_normalizeDecimalsTo18
to accurately represents its functionality and can be set as a pure function._deposit
to use the provided user value without requiring pre-normalization. Currently, the_deposit
function expects users to input a normalized value, causing inconvenience and potential errors. By allowing this function to accept the exact amount of the asset's decimals and internally normalizing it will simplify user interactions and prevent miscalculations.Context
The
_deposit
function currently requires users to manually convert their asset amounts to match the contract's expected 18-decimal format. By modifying this function to handle the normalization internally, users can directly input their desired asset amount, reducing complexity.Current _deposit Function:
Consider the following scenario: A user wishes to deposit 1000 USDC (=${1000}*10^{6}$ ). He will have to back calculate the normalized amount, ${1000}*10^{18}$ in this case, and use that as an input to the above function.
Updated _deposit Function:
In this approach, user does not have to do any additional calculation.
New _normalizeDecimalsTo18 function:
Similarly, all other public functions will use the same design where they accept exact amount of the asset's decimals and internally normalize it.
Advantages
_normalizeDecimalsTo18
accurately represents its functionality and can be set as a pure function.Would love to have comments from @andreivladbrg and @IaroslavMazur what do you think?
Beta Was this translation helpful? Give feedback.
All reactions