fix: always register contracts with wallet PXE#10
Closed
alejoamiras wants to merge 1 commit intomainfrom
Closed
Conversation
… check The old code called getContractMetadata before registration and skipped contracts where metadata.result.instance was truthy. This caused "Unknown contract" errors during simulation because: 1. getContractMetadata.instance comes from pxe.getContractInstance() (LMDB local read). A wallet with persistent storage from a prior session returns truthy instance data even when the artifact is missing (e.g. after a wallet update or SDK version change). 2. The wallet SDK's registerContract (base_wallet.ts:257-293) treats matching class IDs as a no-op—it does NOT verify the artifact is still present. So skipping registration left the PXE with instance data but no artifact, causing getContract() to return undefined and simulation to throw "Unknown contract". 3. gregoCoinPremium was registered with undefined artifact, relying on gregoCoin's class being registered first in the same sequential batch. This was fragile and would break if gregoCoin was skipped. The fix: - Remove the getContractMetadata check entirely (also saves a batch round-trip through the wallet SDK communication layer) - Always construct instances and register all contracts with their artifacts in a single batch - registerContract is idempotent by design (base_wallet.ts checks pxe.getContractInstance internally), so re-registering is safe Applied the same fix to registerDripContracts for consistency. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
🚀 Deployed to Vercel! Preview URL: https://gregoswap-jvtr72yqh-thunkars-projects.vercel.app |
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.
Summary
Fixes "Unknown contract" error during the onboarding simulation step (
balance_of_privateon gregoCoin).getContractMetadatacheck before contract registration in bothregisterSwapContractsandregisterDripContractsundefinedartifact, now explicitly passesTokenContractArtifactRoot cause
The old code used
getContractMetadatato skip registration whenmetadata.result.instancewas truthy. This broke because:instancecomes from PXE's LMDB (pxe.getContractInstance()— pure local read, no node fallback). A wallet with persistent storage from a prior session returns truthy instance data even when the artifact is missing (e.g. after wallet extension update or SDK version change).The wallet SDK's
registerContract(base_wallet.ts:264-273) treats matching class IDs as a no-op — it does not verify the artifact is still present. So the old code skipping registration left the PXE with instance data but no artifact.During simulation,
contractStore.getContract()needs both instance AND artifact. It returnedundefined→getFunctionCall()threwUnknown contract.Why this fix is safe
registerContractis idempotent by design — the wallet SDK internally checkspxe.getContractInstance()before writinggetContractMetadatabatch call, saving one round-trip through the wallet SDK communication layerKnown limitation
If the wallet's PXE has a stale instance with a matching class ID but the artifact was lost, the wallet SDK's
registerContractwill no-op (it only callspxe.updateContractwhen class IDs differ). This is a wallet SDK concern — it should verify artifact presence, not just class ID equality.Test plan
🤖 Generated with Claude Code