Skip to content

CSHLD-863: feat(statics): identity-guarded AMS refresh of already-registered coins - #10004

Draft
prajwalu142 wants to merge 1 commit into
masterfrom
prajwalu/cshld-1957-guarded-token-refresh
Draft

prajwalu142 wants to merge 1 commit into
masterfrom
prajwalu/cshld-1957-guarded-token-refresh

Conversation

@prajwalu142

Copy link
Copy Markdown
Contributor

Re-lands the AMS-driven refresh of already-registered coins reverted from statics 2138 (#9970 reverting #9922), this time identity-guarded so AMS can never swap a known coin's class or identity.

Problem / Goal

#9922 let createToken replace any known coin matched by an AMS record — including base chains — which rebuilt tlnbtc as a DynamicCoin and broke @bitgo-beta/abstract-lightning (coin is not a lightning coin) → getCoinSingletons() failed in every wallet-platform process on staging (CSHLD-1957). This PR restores the feature with the guard rails that were missing:

  • Known base chains are never replaced — an AMS entry can never swap a known coin's class.
  • Known tokens refresh only through a guarded CoinMap.replace that rejects class changes and identity-field (id / name / contract address) redefinitions.

Implementation details

  • createToken is pure again: known coins are returned untouched; unknown records build via constructToken, extracted from createToken.
  • createTokenMapUsingConfigDetails owns the refresh: known tokens flow instead of being skipped; the refreshed record is written through CoinMap.replace, which throws CoinClassMismatchError on constructor mismatch and CoinImmutableFieldsMismatchError on id / name / contract-address drift (failures warn and keep the existing record). createTokenMapUsingTrimmedConfigDetails enriches and delegates to it.
  • New errors: CoinClassMismatchError, CoinImmutableFieldsMismatchError in statics/errors.ts.

Verification

  • npx mocha test/unit/ in modules/statics: 39697 passing, 0 failing, 0 pending — including new fixture-based tests: base-chain parity canary, tlnbtc regression, refresh with class preservation, class-swap rejection, identity-field rejection, per-family replacement.
  • tsc --noEmit clean; eslint clean.

Ticket: CSHLD-863

@linear-code

linear-code Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

CSHLD-863

CSHLD-1957

@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Unit tests are failing on Node 26.x (Current release line, non-blocking). This is not an LTS version yet, so it does not block merge, but it signals an incompatibility to fix before Node 26.x becomes LTS.

View run

@prajwalu142
prajwalu142 force-pushed the prajwalu/cshld-1957-guarded-token-refresh branch 3 times, most recently from 6ac69f4 to f405dec Compare October 19, 2026 11:08
problem/goal
Re-land the AMS-driven refresh of already-registered coins that was
reverted from statics 2138 (#9970 reverting #9922). The original
implementation replaced any known coin matched by an AMS record,
including base chains, which swapped LightningCoin for DynamicCoin and
broke wallet-platform coin singletons on staging (CSHLD-1957).

implementation details
- createToken stays pure: known coins are returned untouched; unknown
  records build via constructToken (extracted from createToken).
- createTokenMapUsingConfigDetails owns the refresh: known tokens flow
  instead of being skipped, and the refreshed record is written through
  CoinMap.replace, which rejects same-id replacements that change the
  coin class (CoinClassMismatchError) or the immutable identity fields
  id, name, alias and contract address (CoinImmutableFieldsMismatchError).
  Known base chains never reach the refresh path.
- createTokenMapUsingTrimmedConfigDetails lets known tokens continue
  into feature enrichment and delegates the refresh to the config
  details builder.
- New tests pin the base-chain parity canary, the tlnbtc regression,
  refresh with class preservation, class-swap rejection, per-field
  identity rejection (id, name, alias, contract address), alias-drop
  fail-closed on builder refresh, and AMS feature updates flowing
  through while identity stays untouched.

verification
npx mocha test/unit/ in modules/statics: 39700 passing, 0 failing;
tsc --noEmit clean; eslint clean.

Ticket: CSHLD-863
@prajwalu142
prajwalu142 force-pushed the prajwalu/cshld-1957-guarded-token-refresh branch from f405dec to 881f6b6 Compare October 19, 2026 11:17

This branch has not been deployed

No deployments
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