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.
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