Conversation
📝 WalkthroughWalkthroughA new DEX adapter for x402 is introduced across two files. The facilitators module exports chain-to-address mappings for EVM and Solana networks. The main adapter implements a SimpleAdapter that prefetches token transfer volumes from Dune SQL for Base, Polygon, and Solana, then processes results during fetch operations. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Adapter as x402 Adapter
participant Dune as Dune API
participant EVM as EVM Chains<br/>(Base, Polygon)
participant Solana
User->>Adapter: prefetch(options)
activate Adapter
Adapter->>Dune: Execute SQL Query
activate Dune
Dune->>EVM: Fetch token transfers
EVM-->>Dune: Transfer data (chain, token, volume)
Dune->>Solana: Fetch token transfers
Solana-->>Dune: Transfer data (chain, token, volume)
Dune-->>Adapter: Aggregated volumes per chain
deactivate Dune
Adapter-->>User: Cached results
deactivate Adapter
User->>Adapter: fetch(_, _, options)
activate Adapter
Adapter->>Adapter: Filter cached results by chain
Adapter->>Adapter: Accumulate dailyVolume
Adapter-->>User: {dailyVolume}
deactivate Adapter
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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. Comment |
|
The x402 adapter exports: |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
dexs/x402/facilitators.ts (1)
3-3: Pin the upstream facilitator snapshot.Line 3 points at a moving
mainbranch. Since this list defines the historical accounting scope, please record the exact upstream commit or release used for this snapshot so later updates stay auditable.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@dexs/x402/facilitators.ts` at line 3, The upstream facilitators source URL currently references a moving branch ("main"); replace that with a pinned snapshot by recording the exact commit SHA or release tag used (e.g., change the URL at the top of dexs/x402/facilitators.ts from ".../tree/main/..." to ".../tree/<COMMIT_SHA_OR_TAG>/..."), and also add a nearby single-line comment or constant (e.g., FACILITATOR_SNAPSHOT_COMMIT or a short comment) stating the full commit SHA, author/date, and a brief rationale so the snapshot is auditable and reproducible.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@dexs/x402/index.ts`:
- Around line 19-20: The WHERE clause only excludes rows when t.tx_from equals
the facilitator signer (tx_from) but still allows transfers originated by other
facilitator-owned addresses; update the predicate to exclude any sender or token
account that belongs to the facilitator set (use facilitators.EVM) by checking
both t.tx_from and t."from" (and any other sender fields used later such as
t."to" where relevant) against the facilitators list; modify the expressions
around t.tx_from, t."from", and t."to" (and replicate the same change at the
similar block referenced at lines 29-30) so all facilitator-owned addresses are
filtered out rather than only the tx signer.
- Line 53: The adapter configuration's start field currently reads start:
"2025-05-15" which mismatches the PR screenshots showing Start Time = 5/3/2025;
update the start value to "2025-05-03" in the adapter config (the object
containing the start property) so the x402 adapter begins on May 3, 2025 and
does not skip May 3–14, 2025; after changing, run any existing date-range tests
or validation code that references the start property to ensure no other offsets
or timezone conversions are needed.
---
Nitpick comments:
In `@dexs/x402/facilitators.ts`:
- Line 3: The upstream facilitators source URL currently references a moving
branch ("main"); replace that with a pinned snapshot by recording the exact
commit SHA or release tag used (e.g., change the URL at the top of
dexs/x402/facilitators.ts from ".../tree/main/..." to
".../tree/<COMMIT_SHA_OR_TAG>/..."), and also add a nearby single-line comment
or constant (e.g., FACILITATOR_SNAPSHOT_COMMIT or a short comment) stating the
full commit SHA, author/date, and a brief rationale so the snapshot is auditable
and reproducible.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: dee2d729-0eff-4527-83eb-a0fcd52463b5
📒 Files selected for processing (2)
dexs/x402/facilitators.tsdexs/x402/index.ts
| where t.tx_from IN ( ${facilitators.EVM} ) | ||
| and t."from" != tx_from and t."from" != t."to" and t.blockchain IN ('base', 'polygon') |
There was a problem hiding this comment.
Exclude facilitator-owned senders, not just the signer.
These predicates only drop rows where the transfer sender matches tx_from / tx_signer. They still count payouts from another facilitator-owned address or token account, which does not match the PR goal of removing transfers from facilitator addresses.
Suggested change
+const evmFacilitatorsSql = facilitators.EVM.join(", ")
+const solanaFacilitatorsSql = facilitators[CHAIN.SOLANA]
+ .map((address) => `'${address}'`)
+ .join(", ")
+
const prefetch = async (options: FetchOptions) => {
return queryDuneSql(options, `
select
blockchain as chain,
CAST(contract_address as varchar) as token,
SUM(amount_raw) as volume
from tokens.transfers t
- where t.tx_from IN ( ${facilitators.EVM} )
- and t."from" != tx_from and t."from" != t."to" and t.blockchain IN ('base', 'polygon')
+ where t.tx_from IN ( ${evmFacilitatorsSql} )
+ and t."from" NOT IN ( ${evmFacilitatorsSql} )
+ and t."from" != t."to" and t.blockchain IN ('base', 'polygon')
and TIME_RANGE
group by blockchain, contract_address
union all
select
'solana' as chain,
token_mint_address as token,
SUM(amount) as volume
from tokens_solana.transfers
- where tx_signer IN ( ${facilitators.solana.map(address => `'${address}'`)} )
- and tx_signer != from_owner and from_owner != to_owner
+ where tx_signer IN ( ${solanaFacilitatorsSql} )
+ and from_owner NOT IN ( ${solanaFacilitatorsSql} )
+ and from_owner != to_owner
and TIME_RANGE
group by token_mint_address
`
);
};Also applies to: 29-30
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@dexs/x402/index.ts` around lines 19 - 20, The WHERE clause only excludes rows
when t.tx_from equals the facilitator signer (tx_from) but still allows
transfers originated by other facilitator-owned addresses; update the predicate
to exclude any sender or token account that belongs to the facilitator set (use
facilitators.EVM) by checking both t.tx_from and t."from" (and any other sender
fields used later such as t."to" where relevant) against the facilitators list;
modify the expressions around t.tx_from, t."from", and t."to" (and replicate the
same change at the similar block referenced at lines 29-30) so all
facilitator-owned addresses are filtered out rather than only the tx signer.
Closes https://github.com/DefiLlama/internal-docs/issues/15
Tracks the volume of x402 payments processed by facilitators on base, polygon and solana, removing transfers from the facilitators address and payments between the same address
Test results:



Summary by CodeRabbit
Release Notes