fix(wasmbinding): set top-level Metadata.Decimals in SetTokenMetadata translation#38
Open
danvaneijck wants to merge 1 commit into
Conversation
… 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix(wasmbinding): set top-level
Metadata.DecimalsinSetTokenMetadatatranslationSummary
Fixes #37.
The CosmWasm
SetTokenMetadatawasm-binding translation built the bankMetadatastruct without setting the top-levelDecimalsfield, leaving it as the zero default. The bank precompile readsmetadata.Decimals(notDenomUnits[i].Exponent) when servingdecimals()to auto-deployed ERC20 wrappers — so adapter-wrapped denoms whose metadata was set via wasm bindings produce ERC20s that reportdecimals() == 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.goSetTokenMetadatatranslation, settingMetadata.Decimals = mt.Decimalsso the precompile and the secondDenomUnit.Exponentagree.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/wasmbindingpackage currently has no test infrastructure, so validation is via manual reproduction on a local testnet:decimals = 18.inj14ej…).RegisterCw20ContractthenUpdateMetadataon the adapter for that CW20.injectived q bank denom-metadata factory/<adapter>/<cw20>—decimalsshould now be18(was0before this fix).MsgCreateTokenPairfor the denom; auto-deploy the wrapper.decimals()on the resulting ERC20 via EVM RPC — should return18.Mainnet evidence of the bug (pre-fix), included for context:
factory/inj14ej…/inj1300xcg9…87xm8(SHROOM/shroomin):decimals=0, display-unit exponent=18 (afterUpdateMetadata).factory/inj14ej…/inj1x997dy…zcnq(TRUINJ): same pattern.factory/inj178zy…/DRUGS(control — set via directMsgSetDenomMetadata, prop 594):decimals=6populated correctly, ERC20 at0x7F073F52051eEF8512519ee7A627F8db1cD63303reportsdecimals()=6via EVM RPC.Compatibility
Decimals=0untilUpdateMetadatais re-run after the fix lands. The patch only affects future translations.tokenfactory.MsgServer.SetDenomMetadatavalidation: the existing checkexistingMetadata.Decimals != 0 && existingMetadata.Decimals != msg.Metadata.Decimalsstill works — first-time set passes (existing=0), and re-runs with matching decimals pass too.Metadata.Validate(): standard SDK validation does not restrict the extendedDecimalsfield.Notes
The CW20 Adapter contract (
inj14ej…) is immutable (wasmdadmin: ""), 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 awasmbinding_test.gofor this package; defaulted to no test to keep the patch minimal.