Skip to content

Fix zero-liquidity division-by-zero in DEX liquidity queries #823

Description

@nanaf6203-bit

Problem Statement

Several DEX view functions compute utilisation that can divide by zero on a fresh pool.

Why it matters

Reliability.

Technical Context

Add a guarded divide with explicit ZeroLiquidity errors.

Expected Outcome

Zero liquidity returns clean error rather than aborting.

Acceptance Criteria

  1. Tests cover empty pools.
  2. ZeroLiquidity error defined.
  3. SDK reflects.

Implementation Notes

Add is_zero checks.

Files or modules likely to be affected

contracts/dex/src/lib.rs.

Dependencies

None.

Difficulty level

EASY.

Estimated effort

S (~1 day).

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions