Skip to content

Feat/btc staking - #27

Open
tomer-shoham wants to merge 98 commits into
mainfrom
feat/btc-staking
Open

Feat/btc staking#27
tomer-shoham wants to merge 98 commits into
mainfrom
feat/btc-staking

Conversation

@tomer-shoham

Copy link
Copy Markdown

No description provided.

saraidy added 30 commits April 9, 2026 20:02
[FIREHOG-BYPASS] not secrets
[FIREHOG-BYPASS] not a secret

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

Pull request overview

This PR adds PoX-5 STX staking and BTC bonding/early-exit capabilities to the Stacks Fireblocks SDK and expands the REST API + Swagger docs to expose these new flows. It also introduces nonce management and replace-by-fee (RBF) support to improve transaction reliability and operational control.

Changes:

  • Added PoX-5 endpoints and SDK plumbing for STX staking, BTC bond lifecycle actions, rewards, and an external cosigner flow for early-exit spends.
  • Implemented nonce tooling (API + SDK) and a replace-by-fee route to bump stuck transactions.
  • Updated Swagger/README docs, config/env handling, and added tests for early-exit controller + cosigner service.

Reviewed changes

Copilot reviewed 24 out of 31 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
tsconfig.json Enables JSON imports and TS path mapping for @stacks/bitcoin-staking.
src/utils/validation.ts Adds shared request parsing/validation helpers and a ValidationError type.
src/utils/swagger.ts Swagger metadata improvements + version pulled from package.json.
src/utils/helpers.ts Signature handling hardened (low-S normalization) + PoX-4/PoX-5 PoxInfo compatibility.
src/utils/FireblocksSigner.ts Adds externalTxId support + backoff/timeout for tx polling.
src/utils/constants.ts Adds RBF + PoX-5/BTC bonding constants and new error maps.
src/staking/bonds/unlock-bytes-store.ts Adds a simple unlock-bytes persistence interface and in-memory implementation.
src/services/types.ts Expands response types for PoX-5/bonds/nonce/rewards flows.
src/services/stacks.service.ts Adds nonce fetcher, mempool tx fetcher, endpoint updates, and new signing/broadcast options.
src/services/fireblocks.service.ts Adds BTC transfer support via Fireblocks + passes externalId for idempotency.
src/services/cosigner.service.ts Introduces external cosigner client with local verification safeguards.
src/server.ts Adds middleware to return 400 for ValidationError.
src/pool/types.ts Expands action types for new PoX-5 and bond operations.
src/pool/SdkManager.ts Simplifies metrics output (removes per-vault map).
src/config.ts Adds EARLY_EXIT_SIGNER_URL env support and minor formatting fixes.
src/api/router.ts Adds many PoX-5/bond/rewards routes + Swagger tags and request schemas.
src/api/controller.ts Implements handlers for new routes; adds fee/nonce parsing and RBF handler.
src/api/api.service.ts Wires new action types to SDK method calls.
src/tests/helpers.test.ts Updates/extends signature concatenation tests (incl. high-S normalization).
src/tests/earlyExit.controller.test.ts Adds controller tests for early-exit endpoints.
src/tests/e2e/stx-transfer.e2e.test.ts Improves E2E polling behavior for indexing delays.
src/tests/cosigner.service.test.ts Adds unit tests for cosigner verification and timeout behavior.
README.md Documents new nonce/RBF/PoX-5/BTC bonding APIs and usage examples.
package.json Bumps version and adds new dependencies for BTC bonding.
.gitignore Stops committing .env while allowing .env.example, plus cleanup.
.env.example Adds a safe template for required env vars incl. cosigner URL.

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

Comment thread package.json Outdated
Comment thread src/api/controller.ts
Comment thread src/api/api.service.ts
Comment thread src/services/stacks.service.ts Outdated
Comment thread src/services/stacks.service.ts
Comment thread src/api/router.ts
Comment thread src/services/fireblocks.service.ts
Comment thread README.md
Comment thread README.md
Comment thread README.md
# Conflicts:
#	.gitignore
#	README.md
#	package.json
#	src/StacksSDK.ts
#	src/__tests__/e2e/stx-transfer.e2e.test.ts
#	src/__tests__/helpers.test.ts
#	src/api/api.service.ts
#	src/api/controller.ts
#	src/api/router.ts
#	src/pool/types.ts
#	src/services/stacks.service.ts
#	src/services/types.ts
#	src/utils/FireblocksSigner.ts
#	src/utils/constants.ts
#	src/utils/helpers.ts
#	src/utils/validation.ts
@socket-security

socket-security Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addednpm/​@​stacks/​bitcoin-staking@​7.4.1-pr.1854.5781007494100
Addednpm/​@​stacks/​common@​7.5.01001007698100
Addednpm/​@​scure/​btc-signer@​2.2.09810010085100
Updatednpm/​@​stacks/​network@​7.6.0 ⏵ 7.5.09510010098 +1100
Updatednpm/​@​stacks/​transactions@​7.6.0 ⏵ 7.5.09910010098 +1100

View full report

tomer-shoham and others added 9 commits July 23, 2026 12:55
Implements the fixes for the Stacks Labs PoX-5 audit (all 9 Blockers,
15 Majors, 6 Minors; 2/5 Informational).

Highlights:
- FBS-01/23: single NetworkProfile shared by the PoX-5 client and
  StacksService; account-balance fetch adapter fixes the hexToBigInt crash.
- FBS-02/12/19: run fetchEligible* preflights before signing on every
  PoX-5 mutation; re-check register-for-bond with the SPV proof pre-L2.
- FBS-03: local register-for-bond builder emits the required
  unlock-burn-height per output.
- FBS-04/05: durable BondLockRecord; recovery selects by outpoint and
  treats read failure as unknown; deriveLock honors the bondIndex override.
- FBS-06/24: deny-mode post-conditions on all fund-moving PoX-5 calls
  (reward-claim legs are signer-manager-defined and left permissive).
- FBS-07: fail-closed REST auth (bearer + timingSafeEqual), restricted
  CORS, per-vault allowlist.
- FBS-08/10: reward discovery/claims decoupled from current membership,
  grouped per signer manager, per-bond per-cycle probing, list capped to 6.
- FBS-09: active bond window derived from the cycle (no fixed scans).
- FBS-11: per-instance mutex serializes nonce->sign->broadcast.
- FBS-13/14: updateBondRegistration, createSbtcBond, unstakeSbtc (+ REST);
  sBTC asset resolved from built-in config with bounded post-conditions.
- FBS-16: distinct Fireblocks external ids per grantSignerKey leg.
- FBS-17: liquidity check compares spendable balance directly.
- FBS-20: settlement polling tolerates transient read failures.
- FBS-21/27: position/status reads distinguish failure from absence;
  delegation read gated off PoX-5.
- FBS-22: minimal DER signature encoding (BIP-66) with tests.
- FBS-25/26/28/29/30: RBF-enabled recovery spends, self-transfer guard,
  terminal-vs-pending tx error reporting, claim list cap.
- FBS-33/35: exact-pinned ABI-critical deps; loud warning on non-durable
  lock store for native bond creation.

Tests: 172 pass (adds auth + minimal-DER suites). tsc/build/lint clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

4 participants