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

PricerRule convertPayCurrencyToToken method missing factor fix #163

Closed
wants to merge 15 commits into from

Conversation

abhayks1
Copy link
Contributor

@abhayks1 abhayks1 commented Feb 27, 2019

The PR adds missing decimals factor in Function convertPayCurrencyToTokens.

Added below unit tests:

  • requiredPriceOracleDecimals = 18 and eip20TokenDecimals = 18
  • requiredPriceOracleDecimals = 5 and eip20TokenDecimals = 18
  • requiredPriceOracleDecimals = 18 and eip20TokenDecimals = 5

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:

Fail
Pass

Travis CI Result:
https://travis-ci.org/OpenSTFoundation/openst-contracts/builds/499911526?utm_source=github_status&utm_medium=notification

Calculation with BT decimal = 20

1 OST = 1 BT
BT CR = 10^5
BT CRD = 5
BT Decimal = 20
USD Price Oracle decimal = 18
OST Base Currency decimal = 18

1 OST = 0.02 USD
Transfer 20 USD

Expected Output: 
	1000 BT = 1000*10^18 BTWei

Current PricerRule Implementation Output:

(20*10^18 * 10^5) / (0.02 * 10^18 * 10^5) = 1000 (BT)

Abhay Calculation Output:

(20*10^18 * 10^5) * 10^20 / (0.02 * 10^18 * 10^5) = 1000 * 10^20 BTWei (1000 BT if BT decimal is considered)
As BT Decimal = 10^20, 1000 * 10^20 units = 1000 * 10^20/10^20 = 1000 BT

Gist Discussion:
https://gist.github.com/abhayks1/ca49a7db6c0e89ddf4dd9ba568abfac1

cc: @benjaminbollen @pgev @schemar @sarvesh-ost

@abhayks1 abhayks1 requested review from benjaminbollen and pgev and removed request for benjaminbollen February 27, 2019 17:01
@abhayks1 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 abhayks1 changed the title [WIP] - Pricer rule calculation fix Pricer Rule convertPayCurrencyToToken Missing Factor Fix Mar 1, 2019
@abhayks1 abhayks1 changed the title Pricer Rule convertPayCurrencyToToken Missing Factor Fix PricerRule convertPayCurrencyToToken method missing factor fix Mar 1, 2019
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.

1 participant