Skip to content

fix(earn-quest): use per-asset decimals in convert_reward_amount (#1947) - #2167

Merged
RUKAYAT-CODER merged 1 commit into
EarnQuestOne:mainfrom
EmeditWeb:fix/1947-convert-reward-amount-decimals
Aug 18, 2026
Merged

fix(earn-quest): use per-asset decimals in convert_reward_amount (#1947)#2167
RUKAYAT-CODER merged 1 commit into
EarnQuestOne:mainfrom
EmeditWeb:fix/1947-convert-reward-amount-decimals

Conversation

@EmeditWeb

Copy link
Copy Markdown
Contributor

Closes #1947

Summary

convert_reward_amount hardcoded a 7-decimal assumption (10_000_000) for every conversion, silently producing incorrect results for reward tokens with a different decimal count. This PR makes the conversion use each asset's actual decimals.

Changes

  • src/lib.rs: convert_reward_amount now looks up each asset's actual decimals via the SEP-41 TokenClient::decimals() interface and uses the oracle price's reported decimals. The conversion scales by 10^(from_decimals + price_decimals - to_decimals) instead of the hardcoded constant.
  • src/oracle.rs: get_aggregated_price now reports the decimal precision of the underlying price sources instead of a fixed 7.
  • tests/test_reward_conversion.rs: new integration tests covering 6/7/18-decimal assets, non-7 price quotes (8 decimals), Stellar asset contracts, mixed decimals with non-integer prices, legacy 7/7 behavior preservation, and the AmountTooLarge overflow guard.

Verification

  • New test suite: 9/9 pass
  • Full contract test suite: all pass
  • cargo fmt --check and cargo clippy --all-targets --all-features -- -D warnings clean

@RUKAYAT-CODER

Copy link
Copy Markdown
Contributor

Thank you for contributing to the project

@RUKAYAT-CODER
RUKAYAT-CODER merged commit 23bb0fd into EarnQuestOne:main Aug 18, 2026
3 checks passed
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.

Fix hardcoded 7-decimal assumption in convert_reward_amount

2 participants