Skip to content

fix: improve handling of zero volume on InsightX - #8674

Open
Peipak wants to merge 10 commits into
DefiLlama:masterfrom
insightx-finance:master
Open

fix: improve handling of zero volume on InsightX#8674
Peipak wants to merge 10 commits into
DefiLlama:masterfrom
insightx-finance:master

Conversation

@Peipak

@Peipak Peipak commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

NOTE

Please enable "Allow edits by maintainers" while putting up the PR.


  • If you would like to add a tvl adapter please submit the PR here.
  1. Once your adapter has been merged, it takes time to show on the UI. If more than 24 hours have passed, please let us know in Discord.
  2. Please fill the form below only if the PR is for listing a new protocol else it can be ignored/replaced with reason/details about the PR
  3. For updating listing info Please send a mail to metadata@defillama.com
  4. Do not edit/push package.json/package-lock.json file as part of your changes
  5. No need to go to our discord/other channel and announce that you've created a PR, we monitor all PRs and will review it asap

Name (to be shown on DefiLlama): InsightX
Twitter Link: https://x.com/InsightXHQ
List of audit links if any:
Website Link: https://app.insightx.finance/
Logo (High resolution, will be shown with rounded borders): https://pbs.twimg.com/profile_images/2056251692086366208/jaRjMLop_400x400.jpg
Current TVL: $10,742.05
Treasury Addresses (if the protocol has treasury) https://mantlescan.xyz/address/0x117420b0c145c60bccb62003414367f9f2384279
Chain: Mantle
Coingecko ID (so your TVL can appear on Coingecko, leave empty if not listed): (https://api.coingecko.com/api/v3/coins/list)
Coinmarketcap ID (so your TVL can appear on Coinmarketcap, leave empty if not listed): (https://api.coinmarketcap.com/data-api/v3/map/all?listing_status=active,inactive,untracked&start=1&limit=10000)
Short Description (to be shown on DefiLlama): InsightX is an AI-native InfoFi prediction market protocol that transforms real-world information, expectations and market signals into tradable, verifiable, and yield-generating on-chain assets.
Token address and ticker if any:
Category (full list at https://defillama.com/categories) *Please choose only one: Prediction Market
Oracle Provider(s): Specify the oracle(s) used (e.g., Chainlink, Band, API3, TWAP, etc.):
Implementation Details: Briefly describe how the oracle is integrated into your project:
Documentation/Proof: Provide links to documentation or any other resources that verify the oracle's usage:
forkedFrom (Does your project originate from another project):
methodology (what is being counted as tvl, how is tvl being calculated):
Github org/user (Optional, if your code is open source, we can track activity): https://github.com/insightx-finance
Does this project have a referral program?

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Summary by CodeRabbit

  • Bug Fixes
    • Improved InsightX response handling when volume data is missing or empty.
    • Missing volume and fee values now default to 0 instead of causing validation errors.

Walkthrough

InsightX fetch validation now rejects only absent API responses. Missing or falsy volume values become 0 when daily balances are created. Fee defaults remain unchanged.

Changes

InsightX volume handling

Layer / File(s) Summary
Handle missing volume values
dexs/insightx/index.ts
The fetch logic rejects only absent responses and uses 0 for missing or falsy volume values when creating daily balances.

Estimated code review effort: 2 (Simple) | ~5 minutes

Possibly related PRs

Suggested labels: dexs, bug-fix

Suggested reviewers: 0xshubhs

🚥 Pre-merge checks | ✅ 10 | ❌ 5

❌ Failed checks (5 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title describes the zero-volume fix but does not follow the required [type] protocol-name - description format. Rewrite the title in the required format, for example: [fix] InsightX - handle zero transaction volume.
Breakdown Methodology Check ⚠️ Warning InsightX returns dailyFees at lines 36–43, but the adapter has no breakdownMethodology property; comparable fee adapters export one. Add a breakdownMethodology object for the fees metric and include it in the exported adapter object.
Income Statement Compliance ⚠️ Warning InsightX returns only dailyFees from data.fees; it omits dailyRevenue and dailySupplySideRevenue, so the required Gross Profit/Cost of Funds split and reconciliation are absent. Add dailyRevenue and dailySupplySideRevenue using a documented fee allocation, and ensure dailyRevenue equals dailyFees minus dailySupplySideRevenue.
Income Statement Balance ⚠️ Warning InsightX returns nonzero dailyFees but no dailyRevenue or dailySupplySideRevenue, so the required dailyFees = dailyRevenue + dailySupplySideRevenue balance is not represented. Add destination accounting that sums to dailyFees, with dailyRevenue and dailySupplySideRevenue; split dailyRevenue into dailyProtocolRevenue and dailyHoldersRevenue when both destinations apply.
Adapter Shape ⚠️ Warning InsightX has one chain, but lines 47-55 put fetch and the sole start under adapter[CHAIN.MANTLE] instead of using chains: [CHAIN.MANTLE] with top-level fetch/start. Refactor the adapter to set chains: [CHAIN.MANTLE], fetch, and start: "2026-06-03" at the top level; use a chainConfig object only if per-chain settings are needed.
✅ Passed checks (10 passed)
Check name Status Explanation
Description check ✅ Passed The description follows the repository template and provides the main InsightX listing details; blank fields appear applicable where no value is provided.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Version 2 Required ✅ Passed InsightX already existed as v1 from commit d80a540; this PR only updates that adapter's zero-volume handling, so the existing-v1 exception applies.
Pullhourly Required For Version 2 ✅ Passed InsightX exports version: 1 at dexs/insightx/index.ts:48, so the version-2 pullHourly requirement does not apply.
Dune Adapters Are Version 1 ✅ Passed InsightX uses only httpGet against its backend API, with no Dune helper or TIME_RANGE query; its SimpleAdapter exports version: 1.
Fetchoptions Usage ✅ Passed InsightX uses fetch(options: FetchOptions), reads options.dateString, and returns only dailyVolume and dailyFees; it is v1 and has no timestamp or raw time/block recomputation.
Efficiency And Error Handling ✅ Passed InsightX uses one documented httpGet call and no getLogs, post-filtering, single-call loops, try/catch swallowing, allowNegativeValue, or hardcoded rate/address.
Methodology Keys ✅ Passed InsightX has no methodology object; AST and text searches found no methodology keys, so no code-field keys violate the check.
✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

The insightx adapter exports:

> adapters@1.0.0 test
> ts-node --transpile-only cli/testAdapter.ts dexs insightx

🦙 Running INSIGHTX adapter 🦙
---------------------------------------------------
Start Date:	Sun, 09 Aug 2026 00:00:00 GMT
End Date:	Mon, 10 Aug 2026 00:00:00 GMT
---------------------------------------------------

MANTLE 👇
Backfill start time: 3/6/2026
Daily volume: 9.35 M
Daily fees: 23.38 k




FEES BREAKDOWN 👇

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@dexs/insightx/index.ts`:
- Around line 31-32: Update the missing-response error message in the data
validation block to state that no response was returned, using the existing
options.dateString context; do not describe the failure as missing volume
because this condition only checks whether data is absent.
- Line 38: Update the InsightXDailyStats interface to mark volume as optional,
matching the fallback handling in dailyVolume.addUSDValue and the API’s possible
omission of this field.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 993f872b-72d8-4c09-b87f-6cd43f5db869

📥 Commits

Reviewing files that changed from the base of the PR and between 1e05f37 and bccab5d.

📒 Files selected for processing (1)
  • dexs/insightx/index.ts

Comment thread dexs/insightx/index.ts
Comment on lines +31 to 32
if (!data) {
throw new Error(`insightx api returned no volume for ${options.dateString}`);

@coderabbitai coderabbitai Bot Aug 10, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Correct the missing-response error message.

This condition rejects only an absent data response. It does not detect a response with no volume. Use an error message such as insightx api returned no response for ${options.dateString} so logs identify the actual failure.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@dexs/insightx/index.ts` around lines 31 - 32, Update the missing-response
error message in the data validation block to state that no response was
returned, using the existing options.dateString context; do not describe the
failure as missing volume because this condition only checks whether data is
absent.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 volume is a normal occurrence, while the error thrown prevents the process from executing.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Peipak, agreed. Zero volume is valid and must not fail the fetch.

The current condition permits zero volume. It throws only when the API returns no response. My comment applies only to the error text, which should describe the absent response rather than missing volume.

🐇


✏️ Learnings added
Learnt from: Peipak
Repo: DefiLlama/dimension-adapters PR: 8674
File: dexs/insightx/index.ts:31-32
Timestamp: 2026-08-10T03:29:17.496Z
Learning: In `dexs/insightx/index.ts`, a zero `volume` from the InsightX daily stats API is a valid result and must be recorded as zero without throwing. Only an absent API response is an error.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


🧠 Learnings used
Learnt from: Shaileshkhote
Repo: DefiLlama/dimension-adapters PR: 7173
File: dexs/fulcrom-finance-derivatives.ts:46-52
Timestamp: 2026-05-24T20:51:03.000Z
Learning: In this repository’s adapter fetch functions (e.g., files under `dexs/`), if the subgraph response yields empty arrays or missing entries (such as `volumeStats[0]` / `tradingStats[0]` being `undefined`), do not fall back to returning `0` values. Returning zeros creates incorrect historical chart data. Instead, fail by letting the code throw (or explicitly throw on missing data) so the infrastructure marks the day as unavailable/missing.

Learnt from: Shaileshkhote
Repo: DefiLlama/dimension-adapters PR: 7255
File: dexs/sunperp/index.ts:11-23
Timestamp: 2026-05-27T20:15:23.682Z
Learning: In DefiLlama/dimension-adapters, when a per-contract kline fetch fails inside a PromisePool callback (e.g., in a dexs/*/index.ts adapter), do not catch the error and return a sentinel value like `0`. Returning `0` creates incorrect historical volume data. Instead, let the error propagate so the job infrastructure can mark the corresponding day as unavailable/missing. Follow the repo principle: "no data is better than wrong data."

You are interacting with an AI system.

Comment thread dexs/insightx/index.ts
@bheluga bheluga self-assigned this Aug 10, 2026
@bheluga

bheluga commented Aug 10, 2026

Copy link
Copy Markdown
Member

@Peipak thanks for the PR
Our team had requested to move this to on-chain tracking, any progress on that?
Till then , volume won't appear on mantle chain

@Peipak

Peipak commented Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

@Peipak thanks for the PR Our team had requested to move this to on-chain tracking, any progress on that? Till then , volume won't appear on mantle chain

@bheluga The volume is generated by off-chain trading on InsightX platform, and the order operations are signed through smart contract and recorded on the on-chain of Mantle

@bheluga

bheluga commented Aug 10, 2026

Copy link
Copy Markdown
Member

@Peipak thanks for the PR Our team had requested to move this to on-chain tracking, any progress on that? Till then , volume won't appear on mantle chain

@bheluga The volume is generated by off-chain trading on InsightX platform, and the order operations are signed through smart contract and recorded on the on-chain of Mantle

Can we get relevant contract addresses on Mantle

@Peipak

Peipak commented Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

@g1nt0ki

g1nt0ki commented Aug 10, 2026

Copy link
Copy Markdown
Member

hi @Peipak
what is this contract? can you share bridge address on mantle?

@Peipak

Peipak commented Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

Hi @g1nt0ki
The contract I shared above (0xd22a5ffdb71221b7b2f081e2679c8a0149d58be9) is the InsightX PredictTrade contract on Mantle, which is used to encrypt the order data that passes the review and verify its consistency before being on-chain. It is not a bridge contract.

I might not have fully understood what you meant by "bridge address".

@g1nt0ki

g1nt0ki commented Aug 10, 2026

Copy link
Copy Markdown
Member

@Peipak where do users deposit funds to trade on the platform?

@Peipak

Peipak commented Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

@Peipak where do users deposit funds to trade on the platform?

@g1nt0ki Oh I see. Users deposit funds into 0x117420b0c145C60bcCB62003414367f9F2384279 (our hot wallet)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants