diff --git a/proxy/plugin/gas_price_calculator.py b/proxy/plugin/gas_price_calculator.py index 903f46574..8dabb9e56 100644 --- a/proxy/plugin/gas_price_calculator.py +++ b/proxy/plugin/gas_price_calculator.py @@ -1,4 +1,5 @@ from datetime import datetime +from decimal import Decimal import time from logged_groups import logged_group from ..indexer.pythnetwork import PythNetworkClient @@ -38,12 +39,12 @@ def start_update_gas_price(self, cur_time): while True: try: - price = self.pyth_network_client.get_price() + price = self.pyth_network_client.get_price('Crypto.SOL/USD') if price['status'] != 1: # tradable raise Exception('Price status is not tradable') self.recent_sol_price_update_time = cur_time - self.min_gas_price = (price['price'] / NEON_PRICE_USD) * (1 + OPERATOR_FEE) + self.min_gas_price = (price['price'] / NEON_PRICE_USD) * (1 + OPERATOR_FEE) * pow(Decimal(10), 9) return except Exception as err: diff --git a/proxy/testing/test_gas_price_calculator.py b/proxy/testing/test_gas_price_calculator.py index 65c734d30..88d6d8de1 100644 --- a/proxy/testing/test_gas_price_calculator.py +++ b/proxy/testing/test_gas_price_calculator.py @@ -31,11 +31,11 @@ def test_success_update_price(self, mock_get_price, mock_get_current_time): mock_get_price.side_effect = [{'status': 1, 'price': sol_price}] gas_price = self.testee.get_min_gas_price() - expected_price = (sol_price / NEON_PRICE_USD) * (1 + OPERATOR_FEE) + expected_price = (sol_price / NEON_PRICE_USD) * (1 + OPERATOR_FEE) * pow(Decimal(10), 9) self.assertEqual(gas_price, expected_price) mock_get_current_time.assert_called_once() - mock_get_price.assert_called_once() + mock_get_price.assert_called_once_with('Crypto.SOL/USD') @patch.object(GasPriceCalculator, 'get_current_time') @@ -53,11 +53,11 @@ def test_success_update_price_after_retry_due_to_wrong_price_status(self, mock_g ] gas_price = self.testee.get_min_gas_price() - expected_price = (sol_price / NEON_PRICE_USD) * (1 + OPERATOR_FEE) + expected_price = (sol_price / NEON_PRICE_USD) * (1 + OPERATOR_FEE) * pow(Decimal(10), 9) self.assertEqual(gas_price, expected_price) mock_get_current_time.assert_called_once() - mock_get_price.assert_has_calls([call()] * 2) + mock_get_price.assert_has_calls([call('Crypto.SOL/USD')] * 2) @patch.object(GasPriceCalculator, 'get_current_time') @@ -76,11 +76,11 @@ def test_success_update_price_after_retry_due_to_get_price_exception(self, mock_ ] gas_price = self.testee.get_min_gas_price() - expected_price = (sol_price / NEON_PRICE_USD) * (1 + OPERATOR_FEE) + expected_price = (sol_price / NEON_PRICE_USD) * (1 + OPERATOR_FEE) * pow(Decimal(10), 9) self.assertEqual(gas_price, expected_price) mock_get_current_time.assert_called_once() - mock_get_price.assert_has_calls([call()] * 2) + mock_get_price.assert_has_calls([call('Crypto.SOL/USD')] * 2) @patch.object(GasPriceCalculator, 'get_current_time') @@ -99,7 +99,7 @@ def test_failed_update_retries_exhausted(self, mock_get_price, mock_get_current_ self.testee.get_min_gas_price() mock_get_current_time.assert_called_once() - mock_get_price.assert_has_calls([call()] * GET_SOL_PRICE_MAX_RETRIES) + mock_get_price.assert_has_calls([call('Crypto.SOL/USD')] * GET_SOL_PRICE_MAX_RETRIES) @patch.object(GasPriceCalculator, 'get_current_time') @@ -123,15 +123,15 @@ def test_success_get_price_time_intervals(self, mock_get_price, mock_get_current {'status': 1, 'price': sol_price2}] gas_price1 = self.testee.get_min_gas_price() - expected_price1 = (sol_price1 / NEON_PRICE_USD) * (1 + OPERATOR_FEE) + expected_price1 = (sol_price1 / NEON_PRICE_USD) * (1 + OPERATOR_FEE) * pow(Decimal(10), 9) self.assertEqual(gas_price1, expected_price1) gas_price2 = self.testee.get_min_gas_price() self.assertEqual(gas_price2, expected_price1) gas_price3 = self.testee.get_min_gas_price() - expected_price2 = (sol_price2 / NEON_PRICE_USD) * (1 + OPERATOR_FEE) + expected_price2 = (sol_price2 / NEON_PRICE_USD) * (1 + OPERATOR_FEE) * pow(Decimal(10), 9) self.assertEqual(gas_price3, expected_price2) mock_get_current_time.assert_has_calls([call()] * 3) - mock_get_price.assert_has_calls([call()] * 2) \ No newline at end of file + mock_get_price.assert_has_calls([call('Crypto.SOL/USD')] * 2) \ No newline at end of file