Feat/btc staking - #27
Open
tomer-shoham wants to merge 98 commits into
Open
Conversation
[FIREHOG-BYPASS] not secrets
[FIREHOG-BYPASS] not a secret
… check for maximum allowed fee
… provided in replaceTransaction method
…d of hex deserialization
…signStructuredMessage
…eout in FireblocksSigner
…n CosignerService
…o specific version
There was a problem hiding this comment.
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.
…es and improve nonce retrieval
…nhanced transaction customization
# 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
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.