-
Notifications
You must be signed in to change notification settings - Fork 19
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
PricerRule convertPayCurrencyToToken method missing factor fix #163
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abhayks1
requested review from
benjaminbollen and
pgev
and removed request for
benjaminbollen
February 27, 2019 17:01
abhayks1
changed the title
Pricer rule calculation fix
[WIP] - Pricer rule calculation fix
Feb 28, 2019
payCurrencyAmount = $20 = 20*10^18 conversionRateFromBaseCurrencyToToken = 100000 (For 1 OST = 1 BT) conversionRateDecimalsFromBaseCurrencyToToken = 5 baseCurrencyPriceInPayCurrency = $0.02 = 2 * 10^16 requiredPriceOracleDecimals = 18
…lockDelay. else test was breaking intermittently
Added more unit tests with variation of eip20TokenDecimals and requiredPriceOracleDecimals
abhayks1
changed the title
[WIP] - Pricer rule calculation fix
Pricer Rule convertPayCurrencyToToken Missing Factor Fix
Mar 1, 2019
abhayks1
changed the title
Pricer Rule convertPayCurrencyToToken Missing Factor Fix
PricerRule convertPayCurrencyToToken method missing factor fix
Mar 1, 2019
This was referenced Mar 4, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The PR adds missing decimals factor in Function
convertPayCurrencyToTokens
.Added below unit tests:
Theoretically, the Number of BT needs to be transferred for payment shouldn’t depend on requiredPriceOracleDecimals value. If 20 dollar payment needs to be done, it would require 1000 BT for $0.02 per BT value. Number of BT needs to be transferred shouldn't depend on price oracle decimal.
requiredPriceOracleDecimals simply decides minimum value in currency(say USD) that can be transferred.
Below two test cases have different price oracle decimals. For test case 1st, requiredPriceOracleDecimals is 18 and the number of BT which will be transferred after the calculation is 1000BT which is expected.
Total value in USD = 1000 * 0.02 = 20$ (where value of each BT is 0.02$)
However for test case two, requiredPriceOracleDecimals is 5 and the number of calculated BT is 10^8 wei BT.
Total value in USD = (10^8 * 0.02) / (10^18) = 2*10 ^ (-12) $
Case 1
Input :
requiredPriceOracleDecimals = 18
payCurrencyAmount = $20 = 20*10^18
baseCurrencyPriceInPayCurrency = $0.02 = 0.02 * 10^18
conversionRateFromBaseCurrencyToToken = 100000 (For 1 OST = 1 BT)
conversionRateDecimalsFromBaseCurrencyToToken = 5
eip20TokenDecimals = 18
Expected Transferred Amount:
1000 BT = 1000 * 10^18
Transferred Amount with Pay method:
1000 BT = 1000 * 10^18
Unit Test Status:
Pass
Case 2
Input :
requiredPriceOracleDecimals = 5
payCurrencyAmount = $20 = 20*10^5
baseCurrencyPriceInPayCurrency = $0.02 = 0.02 * 10^5
conversionRateFromBaseCurrencyToToken = 100000 (For 1 OST = 1 BT)
conversionRateDecimalsFromBaseCurrencyToToken = 5
eip20TokenDecimals = 18
Expected Transferred Amount:
1000 BT = 1000 * 10^18 BTWei
Transferred Amount with Pay method:
10^8 BTWei
Unit Test Status:
FailPass
Travis CI Result:https://travis-ci.org/OpenSTFoundation/openst-contracts/builds/499911526?utm_source=github_status&utm_medium=notificationCalculation with BT decimal = 20
Gist Discussion:
https://gist.github.com/abhayks1/ca49a7db6c0e89ddf4dd9ba568abfac1
cc: @benjaminbollen @pgev @schemar @sarvesh-ost