Skip to content

fix(wasmbinding): set top-level Metadata.Decimals in SetTokenMetadata translation#38

Open
danvaneijck wants to merge 1 commit into
InjectiveFoundation:release/v1.19.xfrom
danvaneijck:fix/wasmbinding-set-token-metadata-decimals
Open

fix(wasmbinding): set top-level Metadata.Decimals in SetTokenMetadata translation#38
danvaneijck wants to merge 1 commit into
InjectiveFoundation:release/v1.19.xfrom
danvaneijck:fix/wasmbinding-set-token-metadata-decimals

Conversation

@danvaneijck

Copy link
Copy Markdown

fix(wasmbinding): set top-level Metadata.Decimals in SetTokenMetadata translation

Summary

Fixes #37.

The CosmWasm SetTokenMetadata wasm-binding translation built the bank Metadata struct without setting the top-level Decimals field, leaving it as the zero default. The bank precompile reads metadata.Decimals (not DenomUnits[i].Exponent) when serving decimals() to auto-deployed ERC20 wrappers — so adapter-wrapped denoms whose metadata was set via wasm bindings produce ERC20s that report decimals() == 0, blocking functional MTS registration for every CW20-adapter-wrapped denom (197 mainnet denoms today).

Change

Single-line addition to injective-chain/wasmbinding/message_plugin.go SetTokenMetadata translation, setting Metadata.Decimals = mt.Decimals so the precompile and the second DenomUnit.Exponent agree.

 Metadata: banktypes.Metadata{
     Base:    mt.Denom,
     Display: mt.Symbol,
     Name:    mt.Name,
     Symbol:  mt.Symbol,
+    Decimals: mt.Decimals,
     DenomUnits: []*banktypes.DenomUnit{ ... },
 },

Test plan

The injective-chain/wasmbinding package currently has no test infrastructure, so validation is via manual reproduction on a local testnet:

  1. Deploy a CW20 contract with decimals = 18.
  2. Deploy the CW20 Adapter (or use the standard mainnet one at inj14ej…).
  3. Call RegisterCw20Contract then UpdateMetadata on the adapter for that CW20.
  4. Query injectived q bank denom-metadata factory/<adapter>/<cw20>decimals should now be 18 (was 0 before this fix).
  5. Submit MsgCreateTokenPair for the denom; auto-deploy the wrapper.
  6. Call decimals() on the resulting ERC20 via EVM RPC — should return 18.

Mainnet evidence of the bug (pre-fix), included for context:

  • factory/inj14ej…/inj1300xcg9…87xm8 (SHROOM/shroomin): decimals=0, display-unit exponent=18 (after UpdateMetadata).
  • factory/inj14ej…/inj1x997dy…zcnq (TRUINJ): same pattern.
  • factory/inj178zy…/DRUGS (control — set via direct MsgSetDenomMetadata, prop 594): decimals=6 populated correctly, ERC20 at 0x7F073F52051eEF8512519ee7A627F8db1cD63303 reports decimals()=6 via EVM RPC.

Compatibility

  • Existing affected denoms keep their current Decimals=0 until UpdateMetadata is re-run after the fix lands. The patch only affects future translations.
  • tokenfactory.MsgServer.SetDenomMetadata validation: the existing check existingMetadata.Decimals != 0 && existingMetadata.Decimals != msg.Metadata.Decimals still works — first-time set passes (existing=0), and re-runs with matching decimals pass too.
  • Metadata.Validate(): standard SDK validation does not restrict the extended Decimals field.

Notes

The CW20 Adapter contract (inj14ej…) is immutable (wasmd admin: ""), and its denoms cannot be reassigned to a different admin contract — so a chain-level fix is the only path to unblock MTS registration for every adapter-wrapped denom. Happy to add a regression test in this PR if the maintainers would like to bootstrap a wasmbinding_test.go for this package; defaulted to no test to keep the patch minimal.

… translation

The bank precompile reads metadata.Decimals when serving decimals() to
auto-deployed ERC20 wrappers, but the wasm-binding translation built
the Metadata struct without setting that field. Adapter-wrapped denoms
whose metadata is set via wasm bindings end up with decimals()==0.

Sets Metadata.Decimals = mt.Decimals so the precompile and the second
DenomUnit.Exponent agree.

Fixes InjectiveFoundation#37

@gorgos gorgos left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM, will add to upstream

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.

[Bug] x/wasmbinding SetTokenMetadata omits top-level Metadata.Decimals, breaking ERC20 decimals() for adapter-wrapped denoms

2 participants