Skip to content

Conversation

@danoctua
Copy link
Collaborator

Implement deletion of missing jettons and nfts

Description

Implemented logic to correctly prune Jetton Wallets and NFT Items that are no longer returned by the indexer-blockchain API. Previously, items that were transferred out or had zero balance (and thus disappeared from the API response) remained in the database as stale data. Use a chunked deletion strategy to handle large datasets efficiently.

Checklist

Before submitting your pull request, please ensure the following:

  • I have read the contributing guidelines.
  • I ran all tests and they passed successfully.
  • I added/updated documentation (if applicable).
  • I reviewed my own code and followed the project's code style.
  • I included relevant details in the PR description or commit messages.

Changes

  • Refactor: Added delete_missing methods to JettonWalletService and NftItemService which identify and delete stale records.
  • Feat: Updated indexer_blockchain/tasks.py to invoke these deletion methods after fetching current wallet details.
  • Perf: Implemented chunked deletion using core.utils.misc.batched to avoid SQL parameter limits.
  • Test: Added comprehensive unit tests in tests/unit/core/services/test_sync_logic.py.
  • Test: Added factories UserWalletFactory, JettonWalletFactory, NftItemFactory to support testing.

How Has This Been Tested?

Ran new unit tests using pytest tests/unit/core/services/test_sync_logic.py. Verified that:

  • Jetton Wallets missing from the keep list are deleted.
  • NFT Items missing from the keep list are deleted.
  • Existing items in the keep list are preserved.
  • Empty keep list results in full deletion of user's items.

Additional Notes

Factories were created (backend/tests/factories/wallet.py, backend/tests/factories/nft.py) to facilitate these tests and future testing needs.

@danoctua danoctua self-assigned this Jan 30, 2026
@danoctua danoctua added bug Something isn't working vibecoded labels Jan 30, 2026
- Remove duplicate comments in NftItemService and JettonWalletService
- Consolidate DB sessions in fetch_wallet_details task to ensure atomic consistency
- Improve logging terminology
- Pre-fetch NFT whitelist addresses to minimize DB session time
@danoctua danoctua merged commit f58818a into dev Jan 30, 2026
2 checks passed
@danoctua danoctua deleted the fix/zeroing-balances branch January 30, 2026 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working vibecoded

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant