Skip to content

[37] Implement set_token_decimals refund path for overpayment in reward-pool #37

Description

@merlik787-droi

Problem Statement

reward-pool::distribute_reward panics on amount <= 0. If a caller passes a too-large amount that exceeds the contract's balance, the token transfer reverts with token::Error. There's no defensive check, so a misconfigured caller could repeatedly hit the distribute_reward and incur transaction fees without the contract being able to fulfill. Also, REWARD_TOKEN_DECIMALS: u32 = 7 is declared but unused. There's no public getter for the token decimals, so off-chain callers can't pre-validate.

Why It Matters

  • A misconfigured integration could trigger a denial-of-wallet pattern.
  • Lack of fee/cost analysis means a maintenance burden.

Expected Outcome

  • Add a assert!(amount <= token.balance(contract), "Insufficient pool balance") check before transfer.
  • Add a token_decimals(env) -> u32 getter.
  • Add a pool_balance(env) -> i128 view function.
  • Tests confirm the new getter and assertion.

Acceptance Criteria

  • New getters work and emit no events.
  • Insufficient-balance check prevents wasted fees.

Implementation Notes

  • Tie REWARD_TOKEN_DECIMALS to the network's actual USDC decimals (testnet=7, public=depends).
  • Consider assert_contract_balance_at_least(env, amount) helper.

Files / Modules Affected

  • contracts/reward-pool/src/lib.rs
  • contracts/reward-pool/src/test.rs
  • contracts/reward-pool/README.md

Dependencies

None.

Difficulty

Easy.

Estimated Effort

2 hours.

Suggested Labels

correctness, P2, reward-pool


Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions