feat(statics): add DynamicNetwork and DynamicCoin for AMS-discovered chains#8291
feat(statics): add DynamicNetwork and DynamicCoin for AMS-discovered chains#8291shubham-damkondwar wants to merge 1 commit intomasterfrom
Conversation
badd853 to
04e55d0
Compare
manas-at-bitgo
left a comment
There was a problem hiding this comment.
Must Fix
1. token.features can be undefined — runtime crash
AmsTokenConfig.features is string[] | undefined. In buildDynamicCoin, token.features as string[] passes undefined through to BaseCoin.validateOptions(), which iterates with for...of → TypeError: options.features is not iterable.
- features: token.features as string[],
+ features: (token.features ?? []) as string[],2. Missing denom propagation
AmsTokenConfig.denom is never passed to the DynamicCoin constructor. Cosmos-family chains (and others using denoms) will silently lose this field.
new DynamicCoin({
...
alias: token.alias,
+ denom: token.denom,
})Should Fix
3. EVM-centric baseUnit default
baseUnit defaults to 'wei'. For non-EVM chains (UTXO, Cosmos, Substrate), this is incorrect. Consider requiring AMS to always provide baseUnit, or use a family-aware default.
4. No unit tests
Zero test coverage for DynamicCoin, DynamicNetwork, getNetwork(), buildDynamicCoin(). At minimum:
DynamicCoinconstruction with valid and edge-case AMS payloadsgetNetwork()with JSON string, plain name, and invalid inputbuildDynamicCoin()withfeatures: undefined(the bug above)
5. getNetwork() resolution order may shadow local statics
JSON parse runs before getNetworkByName(). If AMS sends {"name": "bitcoin", "type": "mainnet", "family": "btc"}, a new DynamicNetwork is created instead of returning the existing Networks.main.bitcoin singleton. Code comparing network references (coin.network === Networks.main.bitcoin) would break.
// Check local statics first, then fall back to JSON parse
const networkObj = getNetworkByName(network);
if (networkObj) return networkObj;
// ... then try JSON parse
6. DynamicNetwork instances aren't cached
Every getNetwork() call with the same JSON string creates a new instance. If multiple AMS-discovered tokens share a network, they'll hold different objects. Consider a Map<string, DynamicNetwork> cache keyed on name+type.
04e55d0 to
8a18c8f
Compare
8a18c8f to
46e4e27
Compare
46e4e27 to
dd71efe
Compare
dd71efe to
f834571
Compare
Ticket: CECHO-439