Skip to content

pagcrypto#5790

Open
straucoin wants to merge 11 commits intoDefiLlama:masterfrom
straucoin:master
Open

pagcrypto#5790
straucoin wants to merge 11 commits intoDefiLlama:masterfrom
straucoin:master

Conversation

@straucoin
Copy link

@straucoin straucoin commented Feb 1, 2026

NOTE

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


  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 It is a different repo, you can find your listing in this file: https://github.com/DefiLlama/defillama-server/blob/master/defi/src/protocols/data4.ts, you can edit it there and put up a PR
  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):

PagCrypto

Twitter Link:

https://x.com/PagCryptoFi

List of audit links if any:

N/A

Website Link:

https://pagcrypto.finance

Logo (High resolution, will be shown with rounded borders):

https://media.pagcrypto.finance/shared/logos/logo.svg

Current TVL:

N/A (this PR adds a fees/revenue adapter, not a TVL adapter)

Treasury Addresses (if the protocol has treasury):

Treasury and fee-collector wallet addresses are configured in the adapter and tracked per chain (Solana, Base, Polygon, Tron, XRPL).

Chain:

Solana, Base, Polygon, Tron, XRPL

Coingecko ID (so your TVL can appear on Coingecko, leave empty if not listed):

pagcrypto

Coinmarketcap ID (so your TVL can appear on Coinmarketcap, leave empty if not listed):

N/A

Short Description (to be shown on DefiLlama):

PagCrypto is a crypto-to-fiat payments infrastructure that enables on-chain assets to be used for real-world payments through local payment rails such as PIX, with multi-chain support.

Token address and ticker if any:

N/A (protocol does not have a publicly traded governance token)

Category (full list at https://defillama.com/categories) *Please choose only one:

Payments

Oracle Provider(s): Specify the oracle(s) used (e.g., Chainlink, Band, API3, TWAP, etc.):

Pyth Network, Chainlink (asset pricing)

Implementation Details: Briefly describe how the oracle is integrated into your project:

Asset prices are obtained via on-chain and off-chain oracle feeds to determine fiat-equivalent values for crypto payments and settlement flows. Oracle prices are used for conversion, validation, and fee calculation, while final fee/revenue accounting is derived from on-chain settlement transfers.

Documentation/Proof: Provide links to documentation or any other resources that verify the oracle's usage:

https://docs.pagcrypto.finance
https://pyth.network
https://coingecko.com

forkedFrom (Does your project originate from another project):

No

methodology (what is being counted as tvl, how is tvl being calculated):

This PR does not track TVL.
The adapter tracks fees/revenue by summing the USD value of on-chain token transfers received by PagCrypto-controlled fee-collector and treasury wallets across supported chains, filtered by an allowlist of supported assets.
Data is sourced from Dune Analytics curated transfer tables.

Github org/user (Optional, if your code is open source, we can track activity):

https://github.com/pagcrypto

Does this project have a referral program?

Yes

Summary by CodeRabbit

  • New Features
    • Added PagCrypto revenue adapter supporting Solana, Base, Polygon, Tron, and XRPL.
    • Tracks fee, revenue, and protocol-revenue metrics with daily USD aggregation.
    • Implements per-chain inflow fetching and a unified fetch flow with wallet configuration validation.
    • Includes documented methodology and per-chain start dates for reported metrics.

✏️ Tip: You can customize this high-level summary in your review settings.

@llamabutler
Copy link

The pagcrypto adapter exports:

> adapters@1.0.0 test
> ts-node --transpile-only cli/testAdapter.ts fees pagcrypto

🦙 Running PAGCRYPTO adapter 🦙
---------------------------------------------------
Start Date:	Sat, 31 Jan 2026 00:00:00 GMT
End Date:	Sun, 01 Feb 2026 00:00:00 GMT
---------------------------------------------------

------ ERROR ------
TypeError: items.map is not a function
    at sqlList (/home/runner/work/dimension-adapters/dimension-adapters/fees/pagcrypto/index.ts:121:16)
    at buildSolanaSql (/home/runner/work/dimension-adapters/dimension-adapters/fees/pagcrypto/index.ts:146:28)
items.map is not a function

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 1, 2026

📝 Walkthrough

Walkthrough

Adds a new PagCrypto SimpleAdapter implementing multi-chain revenue fetching (Solana, Base, Polygon, Tron, XRPL), with per-chain inflow strategies, wallet configuration validation, a prefetch that aggregates USD volumes, and a fetch that returns dailyFees/dailyRevenue/dailyProtocolRevenue.

Changes

Cohort / File(s) Summary
PagCrypto Revenue Adapter
fees/pagcrypto/index.ts
New file exporting a SimpleAdapter. Adds chain configs (assets, statuses, wallets), wallet configuration verifier, per-chain inflow fetchers (Solana-specific, EVM-style for Base/Polygon, stubs for Tron/XRPL), a prefetch that aggregates USD volume, unified fetch selecting per-chain strategy, dependencies/start dates, and a methodology section.

Sequence Diagram

sequenceDiagram
    participant App as Application
    participant Adapter as PagCrypto SimpleAdapter
    participant Prefetch as Prefetch
    participant SQL as SQL Builders
    participant Dune as Dune (query executor)
    participant Fetch as Fetch Handler
    participant Bal as Daily Balances

    App->>Adapter: request data
    Adapter->>Prefetch: run prefetch
    Prefetch->>SQL: build per-chain queries (Solana, Base, Polygon, Tron, XRPL)
    SQL-->>Prefetch: SQL statements
    Prefetch->>Dune: execute UNION ALL aggregated query
    Dune-->>Prefetch: USD volume results
    Prefetch-->>Adapter: aggregated volumes
    Adapter->>Fetch: invoke fetch (select chain strategy)
    Fetch->>Bal: inject USD volume into daily balances
    Bal-->>Fetch: confirm balances
    Fetch-->>Adapter: return dailyFees/dailyRevenue/dailyProtocolRevenue
    Adapter-->>App: deliver results
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 I hopped through ledgers, tokens in tow,
Counting volumes where on-chain flows go,
I UNIONed queries, checked each wallet's name,
Fed fees into days — a tiny rabbit's claim,
Cheers to PagCrypto's new revenue game.

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'pagcrypto' is too vague and does not clearly describe the nature of the change; it only names the protocol without indicating this adds a fees/revenue adapter. Use a more descriptive title like 'Add PagCrypto fees/revenue adapter' to clearly convey what is being added to the codebase.
✅ Passed checks (1 passed)
Check name Status Explanation
Description check ✅ Passed The PR description comprehensively fills out the template with protocol details, oracle integration, methodology, and metadata required for listing a new fees adapter.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

@llamabutler
Copy link

The pagcrypto adapter exports:

> adapters@1.0.0 test
> ts-node --transpile-only cli/testAdapter.ts fees pagcrypto

🦙 Running PAGCRYPTO adapter 🦙
---------------------------------------------------
Start Date:	Sat, 31 Jan 2026 00:00:00 GMT
End Date:	Sun, 01 Feb 2026 00:00:00 GMT
---------------------------------------------------

------ ERROR ------
TypeError: items.map is not a function
    at sqlList (/home/runner/work/dimension-adapters/dimension-adapters/fees/pagcrypto/index.ts:121:16)
    at buildSolanaSql (/home/runner/work/dimension-adapters/dimension-adapters/fees/pagcrypto/index.ts:147:28)
items.map is not a function

@llamabutler
Copy link

The pagcrypto adapter exports:

> adapters@1.0.0 test
> ts-node --transpile-only cli/testAdapter.ts fees pagcrypto

🦙 Running PAGCRYPTO adapter 🦙
---------------------------------------------------
Start Date:	Sat, 31 Jan 2026 00:00:00 GMT
End Date:	Sun, 01 Feb 2026 00:00:00 GMT
---------------------------------------------------

------ ERROR ------
TypeError: WALLETS[chainKey].map is not a function
    at buildEvmSql (/home/runner/work/dimension-adapters/dimension-adapters/fees/pagcrypto/index.ts:175:37)
    at prefetch (/home/runner/work/dimension-adapters/dimension-adapters/fees/pagcrypto/index.ts:229:40)
WALLETS[chainKey].map is not a function

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🤖 Fix all issues with AI agents
In `@fees/pagcrypto/index.ts`:
- Around line 192-199: The current buildXrplSql function returns a stubbed SQL
that always reports 0 volume; replace this with a fail-fast behavior so XRPL
cannot silently produce wrong data: change buildXrplSql to throw a clear Error
(or otherwise abort) with a message like "XRPL SQL not implemented" whenever
called, or ensure the caller excludes/enables XRPL only if a real implementation
exists; reference buildXrplSql to locate and update the stubbed implementation
so the system fails fast instead of returning zeroed results.
- Around line 98-114: WALLETS is declared as Record<ChainKey, string[]> but
populated with string values, causing .map failures in sqlList/buildEvmSql;
update WALLETS so each chain value is an array (e.g., wrap existing string
literals in arrays) or modify initialization to parse the
PAGCRYPTO_<CHAIN>_WALLETS env var into arrays, and keep assertWalletsConfigured
(and its use of WALLETS[k].length) intact; ensure callers like sqlList and
buildEvmSql receive arrays so .map works correctly and no runtime crash occurs.
- Around line 131-152: buildSolanaSql only queries SPL token transfers and
therefore omits native SOL volume; update buildSolanaSql (referencing the
function name, wallets, splMints, and enabledAssets usage) to include native SOL
transfers: add a query branch that selects native transfers (e.g., where
token_mint_address = 'native' or from the native transfer table used in your
Dune schema), convert lamports to USD using the appropriate price/amount_usd
column or join to a price table, and UNION (or SUM together) the native SOL
usd_in with SPL usd_in so volume_usd includes both; alternatively, if your
dataset can't support native SOL yet, detect enabledAssets('solana') includes
"native" and throw/return an error to fail fast and disable SOL until
implemented.
- Around line 156-173: buildEvmSql currently only sums ERC20 transfers
(erc20s/token_address) so any enabled native assets (address === "native" from
enabledAssets) are ignored; update buildEvmSql to handle natives by either
removing "native" from erc20s and adding a second SELECT (or UNION) that sums
native transfers (use the same time/window/blockchain/wallet filters but target
native transfer rows — e.g. token_address = 'native' or the DB’s native-transfer
indicator) or, if you prefer to disallow natives, filter them out earlier (in
enabledAssets or before building erc20s) so native assets are not considered
enabled. Ensure you reference buildEvmSql, enabledAssets, erc20s, token_address,
and the wallet filter (lower("to") IN ...) when making the change.
- Around line 179-188: The buildTronSql function currently returns a stub that
reports 0 while CONFIG.tron.status is true, causing misleading reports; either
implement the real Tron SQL using Tron transfer tables and pricing joins or fail
fast. Update buildTronSql (and any caller that relies on it) to detect
unimplemented state when CONFIG.tron.status === true and either throw a clear
error or return a non-enabled signal (e.g., disable reporting) instead of
returning zero; if you choose to implement, replace the stub with a proper Dune
SQL that joins Tron transfer tables to pricing data and apply the same contract
filtering pattern used for EVM wallets (reference WALLETS.tron for token list).
Ensure callers handle the thrown error or disabled flag so the adapter does not
publish a zero value.
🧹 Nitpick comments (2)
fees/pagcrypto/index.ts (2)

120-122: Guard sqlList against empty allowlists.

IN () will produce invalid SQL if wallets/assets are empty. Consider a defensive fallback so the query returns no rows instead of failing.

♻️ Suggested fix
 function sqlList(items: string[]) {
+  if (!items.length) return "NULL";
   return items.map((x) => `'${x}'`).join(", ");
 }

205-224: Handle the case where no chains are enabled.

If all CONFIG.*.status are false, the CTE is invalid. Add a guard to return empty results.

♻️ Suggested fix
 const prefetch = async (options: FetchOptions) => {
   assertWalletsConfigured();

   const queries: string[] = [];
@@
-  // union results from all enabled chains
+  if (!queries.length) return [];
+  // union results from all enabled chains
   const sql = `

@llamabutler
Copy link

The pagcrypto adapter exports:

> adapters@1.0.0 test
> ts-node --transpile-only cli/testAdapter.ts fees pagcrypto

🦙 Running PAGCRYPTO adapter 🦙
---------------------------------------------------
Start Date:	Sat, 31 Jan 2026 00:00:00 GMT
End Date:	Sun, 01 Feb 2026 00:00:00 GMT
---------------------------------------------------

------ ERROR ------
Error: Request failed with status code 401
    at _queryDune (/home/runner/work/dimension-adapters/dimension-adapters/helpers/dune.ts:219:22)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
Request failed with status code 401

@llamabutler
Copy link

The pagcrypto adapter exports:

> adapters@1.0.0 test
> ts-node --transpile-only cli/testAdapter.ts fees pagcrypto

🦙 Running PAGCRYPTO adapter 🦙
---------------------------------------------------
Start Date:	Sat, 31 Jan 2026 00:00:00 GMT
End Date:	Sun, 01 Feb 2026 00:00:00 GMT
---------------------------------------------------

------ ERROR ------
ReferenceError: Cannot access 'splMints' before initialization
    at buildSolanaSql (/home/runner/work/dimension-adapters/dimension-adapters/fees/pagcrypto/index.ts:152:27)
    at prefetch (/home/runner/work/dimension-adapters/dimension-adapters/fees/pagcrypto/index.ts:248:42)
Cannot access 'splMints' before initialization

@llamabutler
Copy link

The pagcrypto adapter exports:

> adapters@1.0.0 test
> ts-node --transpile-only cli/testAdapter.ts fees pagcrypto

🦙 Running PAGCRYPTO adapter 🦙
---------------------------------------------------
Start Date:	Sat, 31 Jan 2026 00:00:00 GMT
End Date:	Sun, 01 Feb 2026 00:00:00 GMT
---------------------------------------------------

------ ERROR ------
Error: Request failed with status code 401
    at _queryDune (/home/runner/work/dimension-adapters/dimension-adapters/helpers/dune.ts:219:22)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
Request failed with status code 401

@llamabutler
Copy link

The pagcrypto adapter exports:

> adapters@1.0.0 test
> ts-node --transpile-only cli/testAdapter.ts fees pagcrypto

🦙 Running PAGCRYPTO adapter 🦙
---------------------------------------------------
Start Date:	Sat, 31 Jan 2026 00:00:00 GMT
End Date:	Sun, 01 Feb 2026 00:00:00 GMT
---------------------------------------------------

chain     | Daily fees | Daily revenue | Daily protocol revenue | Start Time
---       | ---        | ---           | ---                    | ---       
solana    | 0.00       | 0.00          | 0.00                   | 1/1/2024  
base      | 0.00       | 0.00          | 0.00                   | 1/1/2024  
polygon   | 0.00       | 0.00          | 0.00                   | 1/1/2024  
tron      | 0.00       | 0.00          | 0.00                   | 1/1/2024  
xrpl      | 0.00       | 0.00          | 0.00                   | 1/1/2024  
Aggregate | 0.00       | 0.00          | 0.00                   |           

@llamabutler
Copy link

The pagcrypto adapter exports:

> adapters@1.0.0 test
> ts-node --transpile-only cli/testAdapter.ts fees pagcrypto

🦙 Running PAGCRYPTO adapter 🦙
---------------------------------------------------
Start Date:	Sat, 31 Jan 2026 00:00:00 GMT
End Date:	Sun, 01 Feb 2026 00:00:00 GMT
---------------------------------------------------

chain     | Daily fees | Daily revenue | Daily protocol revenue | Start Time
---       | ---        | ---           | ---                    | ---       
solana    | 0.00       | 0.00          | 0.00                   | 1/1/2025  
base      | 0.00       | 0.00          | 0.00                   | 1/1/2025  
polygon   | 0.00       | 0.00          | 0.00                   | 1/1/2025  
tron      | 0.00       | 0.00          | 0.00                   | 1/1/2025  
xrpl      | 0.00       | 0.00          | 0.00                   | 1/1/2025  
Aggregate | 0.00       | 0.00          | 0.00                   |           

@treeoflife2 treeoflife2 self-assigned this Feb 3, 2026
Copy link
Member

@treeoflife2 treeoflife2 left a comment

Choose a reason for hiding this comment

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

.


const queries: string[] = [];

if (CONFIG.solana.status) queries.push(buildSolanaSql(options));
Copy link
Member

Choose a reason for hiding this comment

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

can you use this token inflows helper where chain is supported?

export async function addTokensReceived(params: AddTokensReceivedParams) {

you can use dune if chain is not supported, and please remove unnecessary comments and keep adapter file lean.

Copy link
Author

Choose a reason for hiding this comment

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

Updated to use addTokensReceived for supported EVM chains (Base, Polygon) and removed Dune/SQL.
Solana/Tron/XRPL are excluded for now since the helper doesn’t reliably support them.

@llamabutler
Copy link

The pagcrypto adapter exports:

> adapters@1.0.0 test
> ts-node --transpile-only cli/testAdapter.ts fees pagcrypto

🦙 Running PAGCRYPTO adapter 🦙
---------------------------------------------------
Start Date:	Mon, 02 Feb 2026 12:00:34 GMT
End Date:	Tue, 03 Feb 2026 12:00:34 GMT
---------------------------------------------------

------ ERROR ------
Error: Allium API Key is required[Ignore this error for github bot]
    at _queryAllium (/home/runner/work/dimension-adapters/dimension-adapters/helpers/allium.ts:47:11)
    at /home/runner/work/dimension-adapters/dimension-adapters/helpers/allium.ts:9:71
Allium API Key is required[Ignore this error for github bot]

@llamabutler
Copy link

The pagcrypto adapter exports:

> adapters@1.0.0 test
> ts-node --transpile-only cli/testAdapter.ts fees pagcrypto

🦙 Running PAGCRYPTO adapter 🦙
---------------------------------------------------
Start Date:	Mon, 02 Feb 2026 12:00:44 GMT
End Date:	Tue, 03 Feb 2026 12:00:44 GMT
---------------------------------------------------

------ ERROR ------
Error: Allium API Key is required[Ignore this error for github bot]
    at _queryAllium (/home/runner/work/dimension-adapters/dimension-adapters/helpers/allium.ts:47:11)
    at /home/runner/work/dimension-adapters/dimension-adapters/helpers/allium.ts:9:71
Allium API Key is required[Ignore this error for github bot]

@llamabutler
Copy link

The pagcrypto adapter exports:

> adapters@1.0.0 test
> ts-node --transpile-only cli/testAdapter.ts fees pagcrypto

🦙 Running PAGCRYPTO adapter 🦙
---------------------------------------------------
Start Date:	Mon, 02 Feb 2026 17:32:32 GMT
End Date:	Tue, 03 Feb 2026 17:32:32 GMT
---------------------------------------------------

------ ERROR ------
Error: Allium API Key is required[Ignore this error for github bot]
    at _queryAllium (/home/runner/work/dimension-adapters/dimension-adapters/helpers/allium.ts:47:11)
    at /home/runner/work/dimension-adapters/dimension-adapters/helpers/allium.ts:9:71
Allium API Key is required[Ignore this error for github bot]

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.

3 participants