Skip to content

[ENG-284] Port the price crate to the ts-sdk#100

Open
xbtmatt wants to merge 12 commits intomainfrom
ENG-284
Open

[ENG-284] Port the price crate to the ts-sdk#100
xbtmatt wants to merge 12 commits intomainfrom
ENG-284

Conversation

@xbtmatt
Copy link
Copy Markdown
Contributor

@xbtmatt xbtmatt commented Apr 3, 2026

Summary

Ports the price Rust crate to the TypeScript SDK with unit tests and a few misc extra helper functions for the frontend to use.

Also updates the frontend/tsconfig.json and the ts-sdk/tsconfig.json to work together properly by aliasing the ts-sdk paths to @/ts-sdk/* rather than @/* (which conflicts with the frontend doing the same thing).

Changes

  • Add price module to ts-sdk. This ports the Rust price crate (encoding, decoding, mantissa validation, order info, client helpers) to TypeScript using decimal.js
  • Add quoteFromBase / baseFromQuote conversion utilities with bigint and Decimal overloads
  • Add liquidity utilities (marketLiquidity, totalLiquidity) for aggregating quote-denominated liquidity across order books
  • Add DropsetMarketAccount and DropsetMarketView types
  • Rename getDropsetMarkets to fetchDropsetMarketAccounts and add fetchDropsetMarketViews helper
  • Unify tsconfig path aliases to @/ts-sdk/* across ts-sdk and frontend
  • Add decimal.js dependency (cataloged in pnpm-workspace.yaml)
  • Add unit tests for price module (encoding, decoding, mantissa validation, client helpers, utils) and liquidity utils

Copilot AI review requested due to automatic review settings April 3, 2026 19:01
@linear
Copy link
Copy Markdown

linear bot commented Apr 3, 2026

ENG-284

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Ports the Rust price crate into the TypeScript SDK (ts-sdk) and aligns TS path aliases so the frontend and SDK can coexist without @/* collisions.

Changes:

  • Added a new ts-sdk/src/price/* module (encoding/decoding, conversions, client helpers) with Jest unit tests.
  • Added liquidity helper utilities (marketLiquidity, totalLiquidity) plus unit tests.
  • Updated TS path aliases in ts-sdk and frontend so SDK imports use @/ts-sdk/*.

Reviewed changes

Copilot reviewed 27 out of 27 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
ts-sdk/tsconfig.json Switch SDK path alias to @/ts-sdk/* to avoid frontend conflict.
frontend/tsconfig.json Adds @/ts-sdk and @/ts-sdk/* aliases into the frontend.
ts-sdk/src/price/* New TS port of the Rust price crate (encoding/decoding/helpers).
ts-sdk/src/utils/liquidity.ts New liquidity aggregation helpers built on the price utilities.
ts-sdk/src/utils/index.ts New fetchDropsetMarketAccounts/views helpers; re-exports liquidity helpers.
ts-sdk/src/types/index.ts Adds DropsetMarketAccount / DropsetMarketView convenience types.
ts-sdk/src/tests/unit/** Adds unit tests for price + liquidity; updates imports for new alias.
ts-sdk/src/tests/e2e/dropset-accounts.test.ts Updates e2e tests to use the new fetch helpers and aliases.
ts-sdk/src/dropset-interface/market-view-all.ts, ts-sdk/src/const.ts Updates internal imports to the new @/ts-sdk/* alias.
ts-sdk/package.json, pnpm-workspace.yaml Adds decimal.js and catalogs it.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings April 3, 2026 20:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 35 out of 35 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings April 3, 2026 20:34
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 35 out of 35 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings April 3, 2026 21:42
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 35 out of 35 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 35 out of 35 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@xbtmatt xbtmatt requested a review from Copilot April 3, 2026 22:47
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 35 out of 35 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 35 out of 35 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1 to +6
import { Decimal } from "decimal.js";
import { ensureU8, ensureU32, type U8 } from "../rust-types";
import { decimalPow10 } from "./client-helpers";
import { ENCODED_PRICE_INFINITY, ENCODED_PRICE_ZERO } from "./encoded-price";
import { PriceError } from "./error";
import { BIAS, PRICE_MANTISSA_BITS, PRICE_MANTISSA_MASK } from "./lib";
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a circular module dependency between decoded-price.ts and client-helpers.ts (decoded-price imports decimalPow10 from client-helpers, while client-helpers imports decodePrice/decodedPriceToDecimal from decoded-price). With Jest/ts-jest (CommonJS) this pattern can lead to partially-initialized exports at runtime (e.g. decodePrice being undefined inside client-helpers), depending on evaluation order. Consider breaking the cycle by moving decimalPow10 into a small standalone module (e.g. pow10.ts) or by inlining the power-of-10 logic in decodedPriceToDecimal.

Copilot uses AI. Check for mistakes.
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