Skip to content

fix(statics): reject duplicate contract address and NFT index keys in coinmap#8966

Draft
nvjsr wants to merge 1 commit into
masterfrom
CGD-715-fix
Draft

fix(statics): reject duplicate contract address and NFT index keys in coinmap#8966
nvjsr wants to merge 1 commit into
masterfrom
CGD-715-fix

Conversation

@nvjsr
Copy link
Copy Markdown
Contributor

@nvjsr nvjsr commented Jun 8, 2026

TICKET: CGD-715

This pull request introduces stricter checks and error handling for duplicate contract addresses and NFT collection IDs when registering tokens in the coin map. It ensures that two tokens cannot be registered with the same contract address or NFT collection ID for the same network, preventing subtle bugs and improving the reliability of token management. The changes also include new error types, updates to the core logic in CoinMap, and expanded test coverage.

Error handling and validation improvements:

  • Added new error classes: DuplicateContractAddressDefinitionError and DuplicateNftCollectionIdDefinitionError to provide clear error messages when a duplicate contract address or NFT collection ID is detected during token registration.
  • Updated the CoinMap class to check for and throw these errors in addCoin if a token with the same contract address or NFT collection ID already exists for the same network. [1] [2]
  • Introduced helper methods in CoinMap (contractAddressKey, nftCollectionIdKey, and hasTokenAddressConflict) to centralize and simplify collision detection logic.

Token registration and deduplication:

  • Modified createTokenMapUsingConfigDetails to skip adding tokens that would conflict with an existing contract address, preventing runtime errors during map creation.
  • Refactored code to use the new helper methods for consistent key generation and deletion in CoinMap.

Test coverage:

  • Added unit tests to verify that attempting to register tokens with duplicate contract addresses or NFT collection IDs correctly throws the new errors.
  • Added tests to ensure that dynamically created tokens with conflicting contract addresses are skipped, and that the static token remains accessible.

Other updates:

  • Updated contract addresses for test tokens in erc7984Tokens.ts to use unique values.
  • Updated imports in test files to include new helper functions.

@linear-code
Copy link
Copy Markdown

linear-code Bot commented Jun 8, 2026

CGD-715

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.

1 participant