Roadmap step 6 after Chronik sync: bigint CP exact-in / exact-out (SPEC
formulas), seller+slush fungible reserve sums (batons excluded), spot and
maker-fee-on-top quote helpers. Startup logs per-token reserves and per-pair
spot. Pure unit tests; no HTTP quote routes yet.
Details
- Reviewers
Fabien - Group Reviewers
Restricted Project - Commits
- rABC7dbcde8b7c0d: [alp-dex] Add constant-product pricing from seller+slush reserves
- cd apps/alp-dex && pnpm test
- cd apps/alp-dex && pnpm run build
Diff Detail
- Repository
- rABC Bitcoin ABC
- Lint
Lint Not Applicable - Unit
Tests Not Applicable
Event Timeline
Build Bitcoin ABC Diffs / Diff Testing (ai-review) passed.
CodeRabbit Review
Diff : committed changes only
Compare : HEAD → master
Directory : work
────────────────────────────────────────
(\(\
(• .•) Just keep coding, just keep coding... I'll handle the reviews.
────────────────────────────────────────────────────────────────────────
major [Functional Correctness]
→ ]8;;vscode://file//work/apps/alp-dex/src/pricing/reserves.ts:60apps/alp-dex/src/pricing/reserves.ts:60-71]8;;
Do not consume one-shot iterables twice.
Iterable permits generators. Computing reserveIn exhausts each
generator, so reserveOut is incorrectly 0n. Aggregate both token IDs
in one traversal.
Proposed fix
): PairReserves => {
+ const normalizedFromTokenId = fromTokenId.toLowerCase();
+ const normalizedToTokenId = toTokenId.toLowerCase();
+ let reserveIn = 0n;
+ let reserveOut = 0n;
+
+ for (const utxos of [sellerUtxos, slushUtxos]) {
+ for (const { token } of utxos) {
+ if (token === undefined || token.isMintBaton) {
+ continue;
+ }
+ const tokenId = token.tokenId.toLowerCase();
+ if (tokenId === normalizedFromTokenId) {
+ reserveIn += token.atoms;
+ }
+ if (tokenId === normalizedToTokenId) {
+ reserveOut += token.atoms;
+ }
+ }
+ }
+
return {
- fromTokenId: fromTokenId.toLowerCase(),
- toTokenId: toTokenId.toLowerCase(),
- reserveIn: pricingReserveAtoms(sellerUtxos, slushUtxos, fromTokenId),
- reserveOut: pricingReserveAtoms(sellerUtxos, slushUtxos, toTokenId),
+ fromTokenId: normalizedFromTokenId,
+ toTokenId: normalizedToTokenId,
+ reserveIn,
+ reserveOut,
};
};────────────────────────────────────────
Review complete
1 finding ✔
Major 1
6 files reviewed:
- apps/alp-dex/README.md
- apps/alp-dex/index.ts
- apps/alp-dex/src/pricing/cp.ts
- apps/alp-dex/src/pricing/quotes.ts
- apps/alp-dex/src/pricing/reserves.ts
- apps/alp-dex/test/pricing.test.ts
────────────────────────────────────────
Print all AI prompts: coderabbit review --show-prompts
Build Bitcoin ABC Diffs / Diff Testing (ai-review) passed.
CodeRabbit Review
Diff : committed changes only
Compare : HEAD → master
Directory : work
────────────────────────────────────────
(\(\
(• .•) 💣 Deploying bug fixes in 3... 2... 1...
────────────────────────────────────────────────────────────────────────
minor [Functional Correctness]
→ ]8;;vscode://file//work/apps/alp-dex/src/pricing/reserves.ts:69apps/alp-dex/src/pricing/reserves.ts:69-85]8;;
Reject same-token pairs before aggregating reserves.
When the normalized IDs match, every UTXO is added to both reserveIn and
reserveOut at Line 81 and Line 84, creating a fictitious pool for a
self-swap. Require distinct IDs before iterating.
Proposed fix
const normalizedFromTokenId = fromTokenId.toLowerCase();
const normalizedToTokenId = toTokenId.toLowerCase();
+ if (normalizedFromTokenId === normalizedToTokenId) {
+ throw new Error('Pair token IDs must differ');
+ }
let reserveIn = 0n;────────────────────────────────────────────────────────────────────────
minor [Stability & Availability]
→ ]8;;vscode://file//work/apps/alp-dex/index.ts:61apps/alp-dex/index.ts:61-80]8;;
Do not swallow unexpected spot-calculation failures.
These catch blocks handle every exception, although the comments only
describe empty reserves. A malformed reserve/decimal input or helper
defect would be logged as n/a, masking invalid pricing data during
startup. Check the zero-reserve condition explicitly or catch a dedicated
empty-reserve error, while allowing unexpected failures to surface.
Suggested fix
- let spotAtoB = 'n/a';
- let spotBtoA = 'n/a';
- try {
- spotAtoB = spotToPerWholeFrom(
+ const spotAtoB =
+ reserveA === 0n
+ ? 'n/a'
+ : spotToPerWholeFrom(
reserveA,
reserveB,
tokenA.decimals,
tokenB.decimals,
- );
- } catch {
- // empty from-reserve
- }
- try {
- spotBtoA = spotToPerWholeFrom(
+ );
+ const spotBtoA =
+ reserveB === 0n
+ ? 'n/a'
+ : spotToPerWholeFrom(
reserveB,
reserveA,
tokenB.decimals,
tokenA.decimals,
- );
- } catch {
- // empty from-reserve
- }
+ );────────────────────────────────────────
Review complete
2 findings ✔
Minor 2
6 files reviewed:
- apps/alp-dex/README.md
- apps/alp-dex/index.ts
- apps/alp-dex/src/pricing/cp.ts
- apps/alp-dex/src/pricing/quotes.ts
- apps/alp-dex/src/pricing/reserves.ts
- apps/alp-dex/test/pricing.test.ts
────────────────────────────────────────
Print all AI prompts: coderabbit review --show-prompts
Tail of the build log:
/work /work/abc-ci-builds/ai-review Connecting to CodeRabbit... 0s elapsed Preparing review... 0s elapsed ✗ Review limit reached Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. You're only billed for reviews past your plan's rate limits ($0.25/file). You can wait 5 minutes for the limit to reset. https://app.coderabbit.ai/settings/billing?tab=usage&orgId=79839cd4-7849-4bd5-8d6d-5ecaf453356e Build ai-review failed with exit code 1
Build Bitcoin ABC Diffs / Diff Testing (ai-review) passed.
CodeRabbit Review
Diff : committed changes only
Compare : HEAD → master
Directory : work
────────────────────────────────────────
(\(\
(• .•) I don't chase bugs; they surrender.
────────────────────────────────────────────────────────────────────────
minor [Functional Correctness]
→ ]8;;vscode://file//work/apps/alp-dex/index.ts:59apps/alp-dex/index.ts:59-76]8;;
Guard both reserves before calculating either spot.
The startup-log contract says to emit n/a when either reserve is zero,
but each branch checks only its source reserve. For example, `reserveB ===
0n still allows spotAtoB to call spotToPerWholeFrom`.
Proposed fix
+ const hasEmptyReserve = reserveA === 0n || reserveB === 0n;
const spotAtoB =
- reserveA === 0n
+ hasEmptyReserve
? 'n/a'
: spotToPerWholeFrom(
@@
const spotBtoA =
- reserveB === 0n
+ hasEmptyReserve
? 'n/a'
: spotToPerWholeFrom(────────────────────────────────────────
Review complete
1 finding ✔
Minor 1
7 files reviewed:
- apps/alp-dex/README.md
- apps/alp-dex/index.ts
- apps/alp-dex/src/pricing/cp.ts
- apps/alp-dex/src/pricing/quotes.ts
- apps/alp-dex/src/pricing/reserves.ts
- apps/alp-dex/test/pricing.test.ts
- apps/alp-dex/test/tradedConfig.test.ts
────────────────────────────────────────
Print all AI prompts: coderabbit review --show-prompts
Build Bitcoin ABC Diffs / Diff Testing (ai-review) passed.
CodeRabbit Review
Diff : committed changes only
Compare : HEAD → master
Directory : work
────────────────────────────────────────
(\(\
(• .•) My other GPU is a Blackwell
────────────────────────────────────────
Review complete
No findings ✔
7 files reviewed:
- apps/alp-dex/README.md
- apps/alp-dex/index.ts
- apps/alp-dex/src/pricing/cp.ts
- apps/alp-dex/src/pricing/quotes.ts
- apps/alp-dex/src/pricing/reserves.ts
- apps/alp-dex/test/pricing.test.ts
- apps/alp-dex/test/tradedConfig.test.ts
────────────────────────────────────────
| apps/alp-dex/index.ts | ||
|---|---|---|
| 62 ↗ | (On Diff #60610) | Since you return 'n/a' if any reserve is 0, can't you simplify and return a pair of spot prices (A/B and B/A) directly ? Once can be computed from the other |
| apps/alp-dex/test/pricing.test.ts | ||
| 27 ↗ | (On Diff #60610) | Please also test the error cases |
| 39 ↗ | (On Diff #60610) | why >= and not === ? |
Address Fabien feedback: pairSpotPrices helper for both directions (n/a when either reserve empty); exact-out asserts exact inverse; broader pricing error-case tests.
Build Bitcoin ABC Diffs / Diff Testing (ai-review) passed.
CodeRabbit Review
Diff : committed changes only
Compare : HEAD → master
Directory : work
────────────────────────────────────────
(\(\
(• .•) Estimate to avoid surprises. Estimate before you start. You'll spot potential problems up front.
────────────────────────────────────────────────────────────────────────
major [Functional Correctness] → ]8;;vscode://file//work/apps/alp-dex/src/pricing/cp.ts:81apps/alp-dex/src/pricing/cp.ts:81-95]8;; Preserve the configured fee rate at the configuration boundary. feePct accepts any finite value in [0, 1], but makerFeeAtoms rounds it to a 1e-9 scale. Thus, 4e-10 becomes zero, 5e-10 becomes 1e-9, and 0.1234567899 becomes 0.12345679. Accept a validated scaled bigint fee rate, or reject values that are not exact 1e-9 increments. Update the quote API and configuration boundary together.
────────────────────────────────────────
Review complete
1 finding ✔
Major 1
7 files reviewed:
- apps/alp-dex/README.md
- apps/alp-dex/index.ts
- apps/alp-dex/src/pricing/cp.ts
- apps/alp-dex/src/pricing/quotes.ts
- apps/alp-dex/src/pricing/reserves.ts
- apps/alp-dex/test/pricing.test.ts
- apps/alp-dex/test/tradedConfig.test.ts
────────────────────────────────────────
Print all AI prompts: coderabbit review --show-prompts