Skip to content

fix(rates): keep on-chain BTC quoted at the peg - #908

Merged
grunch merged 3 commits into
mainfrom
fix/rates-keep-btc-peg
Oct 28, 2026
Merged

grunch merged 3 commits into
mainfrom
fix/rates-keep-btc-peg

Conversation

@grunch

@grunch grunch commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Linked issue

Refs #907 (item 1). The other items land in follow-up PRs.

Type

fix

What changes and why

A node that quotes bitcoin on other networks (MostroP2P/mostro#1088) publishes on-chain BTC as the inner "BTC" entry of its mostro-rates event, at 100000000 (10⁸ sats per BTC). parse_rates_content dropped every inner "BTC" key to skip a source's self-rate of 1, so it dropped that quote too, and lookup_exchange_rate answered NotQuoted for BTC on every node. It now keeps an inner "BTC" whose value is BTC_PEGGED_RATE and drops any other, in any case. A lower-case "btc" used to slip past the filter.

Affected flow

Exchange-rate lookups for market-priced orders (create order, take order): the Market lock, the range pre-check, the quick chips and the sats estimates all read lookup_exchange_rate. Rust core only: rust/src/mostro/rates.rs.

Blast radius

  • Only the inner "BTC" key changes. A value of 100000000 is kept; 1 and any other value are dropped as before. Every other code parses as before.
  • No rust/src/api/ change, so no regenerated bindings. Nothing is persisted: the snapshot is in memory and node-scoped.
  • On the wire nothing changes.

Platforms tested

None by hand (see Manual testing). cargo test on Linux.

Manual testing

Not run. I could not run the app against a Mostro node that quotes on-chain BTC.

Setup

App built from this branch, against a mostrod with MostroP2P/mostro#1091 and [price.providers.pegged] enabled = true, only = ["BTC"].

Steps

  1. Confirm the node's mostro-rates event carries "BTC": 100000000 under "BTC". Expected: it does.
  2. Call lookup_exchange_rate("BTC") for that node (a debug print, until BTC is in the catalogue). Expected: the rate 100000000. (fails on main): NotQuoted.
  3. Regression: look up USD on the same node. Expected: its rate, as before.

Not covered

The UI: BTC is not in the currency catalogue until the follow-up PR for items 2–8 of #907.

Screenshots

No visible change: BTC cannot be picked yet.

Automated tests

The first commit adds the tests and fails on main:

  • on_chain_btc_quoted_at_the_peg_is_kept: an inner "BTC" of 100000000 (integer or float) is kept next to RBTC and USD.
  • an_inner_btc_that_is_neither_the_self_rate_nor_the_peg_is_dropped: a lower-case "btc": 2 is dropped.

the_btc_self_rate_is_dropped still passes.

cargo test: test result: ok. 1481 passed; 0 failed; 30 ignored

Checklist

  • cd rust && cargo fmt --check && cargo clippy -- -D warnings && cargo test pass locally: cargo clippy -- -D warnings and cargo test pass. My local rustfmt (1.10.0) reports formatting differences in 55 files that main already has, including one line of rates.rs this PR does not touch; the lines this PR adds are formatted.
  • dart format --set-exit-if-changed ., flutter analyze and flutter test pass locally: no Dart change.
  • Changed rust/src/api/ or an .arb: no
  • New or changed user-facing text: no
  • Changed an automation identifier: no
  • Protocol or transport change: no; this reads what docs: add bitcoin on other networks as currencies protocol#90 specifies.
  • Behaviour or contract change: no spec change needed
  • Commits are signed
  • I ran the Manual testing steps myself and can explain every line of this diff: I did not run them (see Manual testing).

AI assistance

Written with Claude Code from #907.

🤖 Generated with Claude Code

https://claude.ai/code/session_016wLvLzCu94YTaE15zLR2Cn

Summary by CodeRabbit

  • Bug Fixes
    • BTC-pegged currency rates are now recognized consistently whether the currency code uses uppercase or lowercase. Only rates matching the expected BTC peg are retained; other BTC self-rates are filtered out.

grunch and others added 2 commits October 28, 2026 11:40
A node that quotes bitcoin on other networks publishes on-chain BTC as
the inner "BTC" entry of its rates event at 100000000 (10^8 sats per
BTC), next to LBTC and RBTC. parse_rates_content drops every inner
"BTC" key, so that quote is lost and the app never prices BTC.

The tests expect an inner "BTC" of 100000000 to be kept, and one that
is neither the self-rate nor the peg to be dropped in any case: a
lower-case "btc" currently slips past the filter and is upper-cased
into the table. Both fail on main.

Refs #907

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016wLvLzCu94YTaE15zLR2Cn
parse_rates_content now keeps an inner "BTC" entry whose value is
BTC_PEGGED_RATE (10^8 sats per BTC): that is a node quoting on-chain
bitcoin as a BTC-pegged order currency (mostro
docs/PRICE_PROVIDERS.md §11.9). Any other inner "BTC", including a
source's self-rate of 1 and a lower-case key, is still dropped.

Without it lookup_exchange_rate answered NotQuoted for BTC on every
node, so Market stayed locked for on-chain BTC and the range
pre-check, quick chips and sats estimates had no rate.

Refs #907 (item 1)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016wLvLzCu94YTaE15zLR2Cn
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T15:31:52.676684Z 74fea14 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 12 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between 7ccba68 and 74fea14.

Files selected for processing: 2
  • .specify/NOSTR_EXCHANGE_RATES.md
  • specs/004-mostro-p2p-client/contracts/nostr.md

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 834e951 and 7ccba68.

Files selected for processing: 1
  • rust/src/mostro/rates.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

The rates parser now retains inner BTC entries when their value equals 100,000,000.0, while continuing to filter other inner BTC values. Tests cover integer and floating-point peg values and a non-peg value.

Changes

BTC Rate Parsing

Layer / File(s) Summary
Define and apply the BTC peg filter
rust/src/mostro/rates.rs
The parser uses the public BTC_PEGGED_RATE constant and compares inner BTC codes without case sensitivity. It retains entries that match the peg value and filters other inner BTC values. Tests cover integer and floating-point peg values, plus a non-peg value.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related issues

  • MostroP2P/app#907: The issue reports that the parser drops the inner BTC quote at 100,000,000; this change retains that quote.
  • MostroP2P/mostro#1088: The issue defines BTC-pegged order pricing that requires an inner BTC rate of 100,000,000; this change retains that rate.

Possibly related PRs

  • MostroP2P/app#894: It adds the exchange-rate lookup contract that uses the rates table affected by this change.

Suggested reviewers: andreadiazcorreia, catrya

Merge Risk: Minimal · previous review 7ccba

The BTC peg parsing change is ready to merge; no actionable current-head risk was identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: retaining on-chain BTC rates at the peg.
Description check Passed The description follows the required template, explains the behavior change and scope, documents testing and limitations, and reports the automated test results. Manual testing was not performed, but …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description follows the required template, explains the behavior change and scope, documents testing and limitations, and reports the automated test results. Manual testing was not performed, but the omission is clearly documented with reproducible steps and a reason.

Full details: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 1 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit checks the rates at dawn,
The BTC peg is kept, not gone.
A hundred million marks the way,
While other BTC quotes stray.
The tests hop through, both whole and float,
And leave the right rate in the quote.

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7ccba68668

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread rust/src/mostro/rates.rs Resolved
The rates contract now accepts an inner "BTC" entry of 100000000: a
node quoting on-chain bitcoin as a BTC-pegged order currency, at 10^8
sats per BTC, as LBTC and RBTC. .specify/NOSTR_EXCHANGE_RATES.md says
how pegged codes are carried and that any other inner "BTC", such as
the self-rate of 1, is dropped; the fetch_exchange_rate contract says
what it returns for these codes.

Refs #907 (item 1)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016wLvLzCu94YTaE15zLR2Cn
@grunch

grunch commented Oct 28, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: 74fea14a1c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@grunch
grunch merged commit 44d8550 into main Oct 28, 2026
6 checks passed
@grunch
grunch deleted the fix/rates-keep-btc-peg branch October 28, 2026 17:42
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.

1 participant