feat: add sBTC testnet faucet endpoint#2581
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Description
As a developer building on Stacks testnet, I want a faucet that dispenses sBTC so I can test sBTC-dependent flows without manually acquiring tokens — mirroring the existing STX and regtest-BTC faucets.
This PR adds a new endpoint
POST /extended/v1/faucets/sbtcthat sends an sBTC SIP-010 token transfer to a requested testnet address.What was changed:
src/api/routes/v1/faucets.ts):POST /extended/v1/faucets/sbtc?address=<ST...>. It performs a SIP-010transfercontract call from the first key inFAUCET_PRIVATE_KEYto the recipient, with an exact-amount fungible-token post-condition. It reuses the STX faucet's nonce tracking, custom chain-ID detection, and fee-estimation fallback (fixed fee when the node can't estimate), and is rate-limited to 5 requests / 5 minutes per address.src/env.ts):TESTNET_SBTC_FAUCET_ENABLED— defaults tofalse(opt-in, since it requires the faucet account to actually hold sBTC).TESTNET_SBTC_FAUCET_ASSET_IDENTIFIER— fully-qualified asset id{address}.{contract}::{asset}. Defaults to the official testnet sBTC deploymentST1F7QA2MDF17S807EPA36TSS8AMEFY4KA9TVGWXT.sbtc-token::sbtc-token.TESTNET_SBTC_FAUCET_AMOUNT— sats per request, defaults to10000(0.0001 sBTC).DbFaucetRequestCurrency.SBTCandgetSBTCFaucetRequestsfor rate-limit tracking. Thefaucet_requests.currencycolumn is a plain string, so no migration is needed.openapi.yamlandclient/src/generated/schema.d.ts. The diff also picks up the v3 principal balance endpoints from feat: materialized locked-STX table and v3 principal balance endpoints #2577, which were never regenerated when that PR merged.How this impacts application developers:
A new opt-in testnet-only faucet endpoint is available. Existing behavior is unchanged; the endpoint returns 403 unless
TESTNET_SBTC_FAUCET_ENABLED=true.Example:
Type of Change
Does this introduce a breaking change?
No.
Are documentation updates required?
run_faucet_sbtc).Testing information
Added
tests/krypton/faucet-sbtc/faucet-sbtc.test.ts, which deploys a minimalsbtc-tokencontract from the faucet account on the krypton devnet, points the env at it, and asserts: the request succeeds, the tx mines as atransfercontract call, the recipient's FT balance matches the configured amount, and the 400 (missing address) / 403 (disabled) error paths. Run withnpm run test:krypton:faucet-sbtc— all 5 tests pass locally against Docker.Note: the krypton node image only accepts up to Clarity 2, so the test deploy pins
clarityVersion: Clarity2. The CI matrix entry is added but commented out, matching the other krypton suites.🤖 Generated with Claude Code