Skip to content

Add CoinCode enum - #48

Merged
neto737 merged 1 commit into
mainfrom
feat/3.0-coin-code
Oct 30, 2026
Merged

neto737 merged 1 commit into
mainfrom
feat/3.0-coin-code

Conversation

@neto737

@neto737 neto737 commented Oct 30, 2026

Copy link
Copy Markdown
Owner

Adds CoinCode, a backed enum of BitGo's codes for the major coins and their testnets. BitGo::coin() now takes a CoinCode or any string.

$bitgo->coin(CoinCode::TBTC)->wallet($walletId)->get();   // same request as coin('tbtc')
Amount::fromDisplay('0.5', CoinCode::TBTC->decimals());   // '50000000'

What's in it

  • 28 chains, mainnet and testnet, for 56 cases: UTXO coins (BTC, BCH, LTC, DOGE, DASH, ZEC), EVM chains (ETH, Polygon, Arbitrum, Optimism, Base, BSC, Avalanche C), and SOL, XRP, XLM, TRX, ALGO, ADA, DOT, ATOM, NEAR, SUI, APT, TON, HBAR and XTZ.
  • The source: every code and decimal count comes from BitGo's public asset list (GET /api/v1/all/publicAssets), production and test, checked 2026-10-30. That turned up two things:
    • Bitcoin has tbtc (testnet3) and tbtc4 (testnet4). BitGo's docs now use tbtc4 as the Bitcoin testnet, so both are in.
    • Ethereum's testnets are hteth (now Hoodi) and sepeth (Sepolia). There's no teth.
  • decimals() returns each code's decimals, for Amount. They're set per code, not per chain: Polkadot has 10 and its testnet 12. The match has no default arm, so PHPStan fails (match.unhandled) if a case is added without its decimals. I checked that it does.
  • Any string still works for coins the enum doesn't list, such as 'ttao', so a new BitGo coin never needs an SDK release. Tokens are left out on purpose: they're the part of 2.x's CurrencyCode that went stale (B16).

Tests

5 new tests, 182 in all. composer check passes, and line coverage is 100%.

  • An enum and a string send the same request (the done-when case).
  • A code missing from the enum works as a string.
  • Each case is named after its code.
  • The full decimals table matches BitGo's asset list.
  • decimals() works with Amount, including Polkadot's testnet at 12.

For review

  • Coin choice: the list is my pick of the major chains. Adding or dropping one is a one-line change, and 3.1 already has a step to review the enum against BitGo's list.
  • decimals() goes beyond the roadmap line. It's the coin table that 3.0: Amount value object for exact amounts #47 left out, and since it comes from BitGo's own list, the risk of a wrong entry is low. It's easy to drop if you'd rather keep decimals out of the enum.

…testnets with their decimals; coin() takes a CoinCode or any string.
@codecov

codecov Bot commented Oct 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (f4d6eb9) to head (a1241c9).

Additional details and impacted files
@@             Coverage Diff             @@
##                main       #48   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
- Complexity       151       161   +10     
===========================================
  Files             15        16    +1     
  Lines            354       370   +16     
===========================================
+ Hits             354       370   +16     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@neto737
neto737 merged commit 7761f26 into main Oct 30, 2026
13 checks passed
@neto737
neto737 deleted the feat/3.0-coin-code branch October 30, 2026 06:50
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.

1 participant