feat(sdk-api): add registerWithBaseCoin for dynamic token registration#8589
feat(sdk-api): add registerWithBaseCoin for dynamic token registration#8589manas-at-bitgo wants to merge 1 commit intomasterfrom
Conversation
9d9b444 to
e6fac36
Compare
pranavjain97
left a comment
There was a problem hiding this comment.
the approach works but creates duplication that will drift. registerWithCoinMap copies the 4 base coin + ERC721 registrations from register(), and registerWithBaseCoin on BitGoBase is a public interface change for what's really an internal concern. simpler: have registerWithCoinMap call register(sdk) internally, then just add the dynamic token part with GlobalCoinFactory.registerToken() directly. no interface change needed.
also, no tests added for registerWithBaseCoin or the updated registerWithCoinMap.
e6fac36 to
25cc4fe
Compare
f1e5ea4 to
c2a6e6d
Compare
|
c2a6e6d to
87e4d9e
Compare
87e4d9e to
e03258b
Compare
TICKET: CSHLD-24 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
e03258b to
dd521b8
Compare
| // Registration for dynamic ERC20 tokens that are not hardcoded in the SDK, but are present in the coin map generated using AMS. | ||
| const formattedTokens = getFormattedErc20Tokens(coinMap); | ||
| Erc20Token.createTokenConstructors(formattedTokens).forEach(({ name, coinConstructor }) => { | ||
| // Register constructor for both type names and contract addresses | ||
| sdk.register(name, coinConstructor); | ||
| }); |
There was a problem hiding this comment.
Will this not throw an error if coin is not present in the coin map maintained by the coin factory?
| setRequestTracer(reqTracer: IRequestTracer): void; | ||
| url(path: string, version?: number): string; | ||
| register(name: string, coin: CoinConstructor): void; | ||
| registerWithBaseCoin(coin: CoinConstructor, baseCoin: Readonly<StaticsBaseCoin>): void; |
There was a problem hiding this comment.
Base Coin can get confusing, there are two types of base coin, one used for coin map and one used for coin factory, we can rename it to registerWithStaticsCoin or something similar
Summary
registerWithBaseCoinmethod toBitGoAPIthat wrapsGlobalCoinFactory.registerToken()— adds a token to both the global coin map and constructor map in one callregisterWithCoinMapinsdk-coin-ethto be a drop-in replacement forregister()— callsregister(sdk)internally for hardcoded coins, then registers dynamic ERC20 tokens from a consumer-providedCoinMap@bitgo/staticsdependency tosdk-apiMotivation
Enables dynamic token onboarding: consumers build a
CoinMapfrom AMS (which drifts ahead of what's baked into@bitgo/statics) and pass it toregisterWithCoinMap. New tokens become available viabitgo.coin()without an SDK version bump.TICKET: CSHLD-24
Test plan
register()registers base ETH coins + ERC20/ERC721 constructorsregisterWithCoinMap()delegates toregister()then adds dynamic tokens viaregisterWithBaseCoinregisterWithCoinMap()registers constructors by both type name and contract addressregisterWithBaseCoincallsnpx mocha --require tsx modules/sdk-coin-eth/test/unit/register.ts🤖 Generated with Claude Code