Skip to content

Conversation

@Fletch153
Copy link
Collaborator

@Fletch153 Fletch153 commented Dec 10, 2025

Closes #DS-990

Description

Adds a new CBTC Bitcoin Proof of Reserves adapter that queries Bitcoin blockchain UTXOs directly to verify BTC reserves across configured vault addresses.

Changes

  • Add new @chainlink/dlc-cbtc-btc-por-adapter package
  • Implement Bitcoin UTXO querying via Electrs-compatible API
  • Add confirmation threshold check (configurable, default 6 blocks)
  • Implement iBTC-style pending withdrawal handling to prevent temporary reserve dips during unconfirmed spends
  • Add unit tests for reserve calculation logic
  • Add integration tests with mocked Bitcoin API responses

Steps to Test

  1. Build the adapter:

    cd packages/sources/dlc-cbtc-btc-por && yarn build
  2. Run unit tests:

    yarn jest packages/sources/dlc-cbtc-btc-por/test/unit/reserves.test.ts --no-coverage
  3. Start the adapter locally:

    BITCOIN_RPC_ENDPOINT="https://mainnet.dlc.link/electrs" \
    VAULT_ADDRESSES="bc1pckcdqraqg7gy83w4ddvvc3hks8wvcjvldw2kchlvyre5v9fw37jqse4kn0,bc1p90eyryydrg2w3pswwp0qa2p9elgp09jte34ykxqn0uk6g7dnzqks9n3342" \
    EA_PORT=8080 \
    yarn start
  4. Query the reserves endpoint:

    curl -X POST http://localhost:8080 -H "Content-Type: application/json" -d '{"endpoint": "reserves"}'
  5. Verify the response returns total reserves in satoshis:

    {
      "result": 301089400,
      "data": { "result": 301089400 },
      "statusCode": 200
    }

Quality Assurance

  • If a new adapter was made, or an existing one was modified so that its environment variables have changed, update the relevant infra-k8s configuration file.

  • If a new adapter was made, or an existing one was modified so that its environment variables have changed, update the relevant adapter-secrets configuration file.

  • If a new adapter was made, or a new endpoint was added, update the test-payload.json file with relevant requests.

  • The branch naming follows git flow (feature/x, chore/x, release/x, hotfix/x, fix/x) or is created from Jira.

  • This is related to a maximum of one Jira story or GitHub issue.

  • Types are safe (avoid TypeScript/TSLint features like any and disable, instead use more specific types).

  • All code changes have 100% unit and integration test coverage. If testing is not applicable or too difficult to justify doing, the reasoning should be documented explicitly in the PR.

@changeset-bot
Copy link

changeset-bot bot commented Dec 10, 2025

🦋 Changeset detected

Latest commit: 2cf4156

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@chainlink/dlc-cbtc-por-adapter Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

…es Adapters

- Added @chainlink/dlc-cbtc-btc-attester-por-adapter for querying Bitcoin reserves.
- Introduced @chainlink/dlc-cbtc-canton-digital-assets-por-adapter for retrieving total CBTC supply from the Digital Asset API.
- Updated .pnp.cjs and .yarnrc.yml to reflect new package references and enabled ESM loader.
- Created necessary configuration, endpoints, and transport layers for both adapters.
- Included comprehensive tests for both adapters to ensure functionality and accuracy.
- Added dependencies for Bitcoin address calculation: bip32, bitcoinjs-lib, and tiny-secp256k1.
- Introduced CHANGELOG.md for the @chainlink/dlc-cbtc-btc-por-adapter, documenting the initial release and key features.
- Updated README.md to reflect changes in configuration and functionality.
- Implemented address calculation logic in address.ts, ensuring trustless verification against the Attester API.
- Enhanced reserves calculation logic in por.ts, including confirmation counting and pending spend handling.
- Added comprehensive unit and integration tests to validate the adapter's functionality.
Copy link
Contributor

@mmcallister-cll mmcallister-cll left a comment

Choose a reason for hiding this comment

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

This doesn't look like the correct structure. We don't have instances of nested EAs under a since source EA. You might want to consider separating these out into multiple packages/sources EAs for discrete APIs and/or packages/composites for EAs that call other EAs.

@Fletch153 Fletch153 force-pushed the DS-990/cbtc_btc_reserve_calculation branch from 0181e81 to 0226225 Compare January 6, 2026 23:01
@Fletch153 Fletch153 force-pushed the DS-990/cbtc_btc_reserve_calculation branch from cd12877 to 23e9fcd Compare January 7, 2026 20:10
- Updated configuration to use `ATTESTER_API_URLS` as a comma-separated list of URLs.
- Introduced utility functions `parseUrls` and `medianBigInt` for handling URL parsing and median calculation.
- Modified transport logic to query multiple attesters and calculate reserves independently.
- Adjusted integration and unit tests to accommodate changes in configuration and functionality.
- Updated configuration to utilize `ATTESTER_API_URLS` for multiple attester endpoints.
- Added utility functions `buildUrl`, `parseUrls`, and `medianBigInt` for improved URL handling and median calculations.
- Modified transport logic to fetch data from multiple attesters in parallel and compute the median supply.
- Adjusted integration and unit tests to reflect the new configuration and functionality.
- Introduced the new adapter for CBTC Proof of Reserves, supporting multiple endpoints: `attesterSupply`, `daSupply`, and `reserves`.
- Added configuration options for API URLs and execution intervals.
- Developed utility functions for URL handling and median calculations.
- Created integration and unit tests to validate the adapter's functionality and ensure accurate responses.
- Removed the deprecated BTC PoR adapter and its associated files to streamline the codebase.
Fletch153 and others added 3 commits January 8, 2026 08:12
* update changeset, remove unused test-payload file

* removing customInputValidation on required config
mmcallister-cll
mmcallister-cll previously approved these changes Jan 8, 2026
mmcallister-cll
mmcallister-cll previously approved these changes Jan 8, 2026
@Fletch153 Fletch153 enabled auto-merge (squash) January 8, 2026 12:32
@Fletch153 Fletch153 disabled auto-merge January 8, 2026 12:49
@Fletch153 Fletch153 enabled auto-merge (squash) January 8, 2026 12:49
@Fletch153 Fletch153 merged commit 3a73c41 into main Jan 8, 2026
16 checks passed
@Fletch153 Fletch153 deleted the DS-990/cbtc_btc_reserve_calculation branch January 8, 2026 13:01
This was referenced Jan 8, 2026
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.

3 participants