Skip to content

[REFACTOR] Remove defensive asserts from position aggregation queries #1793

@purplesmoke05

Description

@purplesmoke05

Background

The position endpoints still depend on tuple casts, nullable coupon consumption fields, and runtime asserts that assume token cache rows exist for the selected token type. These guards are hiding missing SQL-side guarantees and make the response-building code harder to reason about.

Description

Tighten the position queries so the selected rows guarantee the token-specific cache record that matches each token type, and ensure coupon consumption values used in the response are handled consistently at the schema level. Once the query invariants are explicit, align the typing and remove the defensive asserts and broad tuple casts from the position router.

Scope

  • Review the aggregated position queries that join Listing, IDXPosition, IDXLockedPosition, IDXConsumeCoupon, and token cache tables.
  • Add SQL-side guarantees or query restructuring for token-type-specific joins.
  • Decide and implement the correct nullability for consumption.block_timestamp and consumption.amount in the response path.
  • Remove redundant asserts and overly broad casts in the position router.
  • Add or update tests for bond, share, coupon, and membership position responses.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions