Skip to content

[BCN] Multi Provider With Alchemy Adapter#4111

Merged
kajoseph merged 13 commits intobitpay:masterfrom
leolambo:multiProviderAlchemy
Mar 16, 2026
Merged

[BCN] Multi Provider With Alchemy Adapter#4111
kajoseph merged 13 commits intobitpay:masterfrom
leolambo:multiProviderAlchemy

Conversation

@leolambo
Copy link
Copy Markdown
Contributor

@leolambo leolambo commented Feb 24, 2026

Description

Add multi-provider external chain state adapter with Alchemy integration, enabling failover between multiple indexed API providers for EVM chains.

Follow-up:

Moralis Adapter, API streaming improvements, Integration tests

Changelog

  • Add adapter error taxonomy with health-affecting classification
  • Add provider health tracker using consecutive-failure counter and cooldown
  • Add IIndexedAPIAdapter interface, config types, and AdapterFactory
  • Add AlchemyAdapter with asset transfer stream
  • Add multi-provider chain state provider with round-robin failover and block-time caching
  • Align provider config with Moralis patterns (dynamic URL resolution, isBreakerableaffectsHealth)

Testing Notes

cd packages/bitcore-node && npm run tests

Checklist

  • I have read CONTRIBUTING.md and verified that this PR follows the guidelines and requirements outlined in it.
  • I have added the appropriate package tag(s) (e.g. BWC if modifying the bitcore-wallet-client package, CLI if modifying the bitcore-cli package, etc.)
  • I have verified that this is not an existing PR (open or closed)

Replace the circuit breaker state machine with a simpler
consecutive-failure counter and cooldown approach.
N failures in a row, skip for M seconds, then retry.
- Fix getBlockBeforeTime signature to match
  GetBlockBeforeTimeParams
- Fix AlchemyAssetTransferStream field collision
  with base class
- Fix blockHeight possibly undefined in confirmation
- Remove unused imports and dead code
- Cast test args as any to satisfy type constraints
- Add operational logging to csp.ts (stream lifecycle,
  failover events, block-by-date resolution)
- Rename _enforceFloorSemantics to _verifyBlockBeforeDate
- Rename IProviderConfig to IMultiProviderConfig with
  only health/priority/timeout fields
- Move apiKey to global config.externalProviders.alchemy
  (matches Moralis pattern)
- Resolve Alchemy URLs dynamically per-call via
  ALCHEMY_NETWORK_MAP
- Add chain/network to AdapterBlockByDateParams for
  dynamic URL resolution
- Add blockAtTimeCache (LRU per chain:network) to
  multi-provider CSP
- Rename isBreakerable to affectsHealth across error
  taxonomy
- Update all tests (47 passing)
@kajoseph kajoseph added the BCN This pull request modifies the bitcore-node package label Feb 27, 2026
Copy link
Copy Markdown
Collaborator

@kajoseph kajoseph left a comment

Choose a reason for hiding this comment

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

Lots of lint errors, particularly with imports. Make sure you have the eslint extension installed and you may need to clear all your node_modules:

npx lerna exec rm -rf node_modules

Still functionally testing, but so far this is looking good!

Separate per-network routing order from provider credentials.
The externalProviders key at the config root now holds only API
keys, while indexedProviderRouting defines the priority-ordered
adapter list per network.
BigInt values from external providers can exceed
Number.MAX_SAFE_INTEGER, losing precision when cast to number.
Accept string alongside number in gasLimit, gasPrice, nonce,
value, and transactionIndex to preserve full precision.
Replace static ALCHEMY_NETWORK_MAP with convention-based URL
derivation so new chains need no code change. Return RPC
quantity fields as BigInt strings to avoid IEEE 754 precision
loss. Update test assertions accordingly.
Copy link
Copy Markdown
Collaborator

@kajoseph kajoseph left a comment

Choose a reason for hiding this comment

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

Nice work!!

@kajoseph kajoseph merged commit 77ac2c5 into bitpay:master Mar 16, 2026
14 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BCN This pull request modifies the bitcore-node package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants