fix: validate amount before calling parseUnits in _getPriceParameters#1974
Open
Sertug17 wants to merge 2 commits into
Open
fix: validate amount before calling parseUnits in _getPriceParameters#1974Sertug17 wants to merge 2 commits into
Sertug17 wants to merge 2 commits into
Conversation
added 2 commits
May 31, 2026 21:13
Chain.Soneium and Chain.AnimeChain were present in the Chain enum but missing from getOfferPaymentToken() and getListingPaymentToken() switch statements, causing a runtime Error when creating listings or offers on these chains. Both chains are OP Stack based: - Soneium (chain ID 1868): uses canonical OP WETH 0x4200...0006 - AnimeChain (chain ID 69000): uses canonical OP WETH 0x4200...0006 Listing payment token for both is native ETH (0x0000...0000). Added test coverage for both chains.
The null guard and negative-amount check were placed *after* amount.toString() was already called, meaning a null or undefined amount would throw a TypeError inside parseUnits before the explicit guard could fire. Fix: move the null check (and the isEther/OFFER check, which is also a precondition) *before* parseUnits is invoked. The negative-bigint check stays after, since it requires amountWei to be computed first. Adds a regression test to misc.spec.ts verifying that passing null does not produce a raw TypeError.
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.
Problem
In
_getPriceParametersthe null guard was placed afteramount.toString()was already called:If
amountisnullorundefined(possible from JavaScript callers or edge cases), this produces an unhandledTypeError: Cannot read properties of null (reading 'toString')instead of the intended validation error.Fix
Move the null check — and the
isEther/OFFER precondition — beforeparseUnitsis called. The negative-bigint guard stays after since it requiresamountWeito exist:Testing
Added a regression test in
test/sdk/misc.spec.tsconfirming that passingnullasamountdoes not surface a rawTypeError.