Skip to content

feat: add /positions/reference endpoint#23

Merged
jonathanchw merged 1 commit intodevelopfrom
feat/api-reference-position-endpoint
Mar 2, 2026
Merged

feat: add /positions/reference endpoint#23
jonathanchw merged 1 commit intodevelopfrom
feat/api-reference-position-endpoint

Conversation

@jonathanchw
Copy link
Collaborator

@jonathanchw jonathanchw commented Mar 1, 2026

Summary

  • Adds GET /positions/reference endpoint returning the best reference position per collateral
  • Adds isChallenged to PositionQuery type and Ponder GraphQL query
  • Filters: not closed, not denied, not challenged, principal > 0, not in cooldown, not expired
  • Returns highest priced valid position per collateral for cooldown-free price increases

Why

Provides a valid reference position so bapp can call adjustPriceWithReference / adjustWithReference
without reverting with InvalidPriceReference.
bapp receives the map, looks up map[position.collateral], checks ref.price >= newPrice, and uses the reference if valid.

Smart contract alignment

The API filters mirror the 9 checks in Position.sol _isValidPriceReference():

# Contract check API filter
1 Same hub Implicit (all positions from same Ponder instance)
2 Reference ≠ this position Handled by bapp at call time
3 Same collateral API returns one ref per collateral key
4 Not in cooldown (block.timestamp > ref.cooldown()) cooldown < now
5 Not expired (block.timestamp < ref.expiration()) expiration > now
6 Not challenged (ref.challengedAmount() == 0) isChallenged == false
7 Not closed (!ref.isClosed()) closed == false
8 newPrice <= ref.price() Checked by bapp/contract at call time
9 ref.principal() > 0 principal > 0

Response shape

{
  num: number;            // number of collaterals
  collaterals: Address[]; // list of collateral addresses
  map: {
    [collateral: Address]: PositionQuery; // full PositionQuery per collateral
  }
}

Test

curl -s http://localhost:3001/positions/reference | jq

Returns the highest-priced valid reference position per collateral. Verified locally against dev Ponder (dev.ponder.juicedollar.com).

Depends on

JuiceDollar/ponder#19 (isChallenged field on PositionV2) — merged ✓

@jonathanchw jonathanchw merged commit c209f56 into develop Mar 2, 2026
1 check 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.

2 participants