feat: Add Peer/ZKP2P yield adapter#2799
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a Peer adaptor that reads Base escrow liquidity, oracle rates, and intent events to calculate per-platform USDC APY and export the resulting pools. ChangesPeer APY calculation
Estimated code review effort: 4 (Complex) | ~45 minutes Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant Apy
participant Liquidity
participant Rates
participant Stats
participant BaseContracts
Apy->>Liquidity: read escrow deposits and routes
Liquidity->>BaseContracts: query deposit and payment data
Apy->>Rates: read currency market rates
Rates->>BaseContracts: query oracle rounds
Apy->>Stats: process intent outcomes
Stats->>BaseContracts: query intent and transfer events
Liquidity-->>Apy: return platform TVL
Stats-->>Apy: return volume and weighted spread
Apy-->>Apy: derive APY pool results
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 peer adapter exports pools: Test Suites: 1 passed, 1 total |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/adaptors/peer/index.js (1)
261-284: 🚀 Performance & Scalability | 🔵 Trivial
fetchPlatformLiquidityrescans every historical deposit on each run.
fetchDepositIdsenumerates0..depositCounterandgetDepositis multicalled for the entire set before closed/zero-liquidity deposits are filtered out. This cost grows unbounded with the protocol's lifetime deposit count (not just active liquidity), so eachapy()invocation gets progressively heavier. Consider bounding the scan (e.g., an on-chain active-deposit enumerator, an off-chain index, or a lower deposit-id watermark) as the protocol scales.🤖 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 `@src/adaptors/peer/index.js` around lines 261 - 284, `fetchPlatformLiquidity` is scanning the full historical deposit range on every `apy()` run via `fetchDepositIds`, which makes the work grow with total deposits rather than active ones. Update `fetchDepositIds` and the `getDeposit` call path to avoid enumerating all IDs each time, using a bounded source such as an on-chain active-deposit enumerator, an off-chain index, or a stored lower watermark so only new or relevant deposit IDs are queried.
🤖 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 `@src/adaptors/peer/index.js`:
- Around line 424-442: The oracle read in the feed loop is missing a freshness
check, so stale completed rounds can still be used. Update the `for` loop in the
peer adaptor to also read `updatedAt` from `entry.output` and skip the feed when
it is older than the feed’s expected heartbeat. Use the existing `tupleField`,
`asBigNumber`, and `config` data in this block to compare the timestamp against
the allowed staleness before assigning `rates[code]`.
---
Nitpick comments:
In `@src/adaptors/peer/index.js`:
- Around line 261-284: `fetchPlatformLiquidity` is scanning the full historical
deposit range on every `apy()` run via `fetchDepositIds`, which makes the work
grow with total deposits rather than active ones. Update `fetchDepositIds` and
the `getDeposit` call path to avoid enumerating all IDs each time, using a
bounded source such as an on-chain active-deposit enumerator, an off-chain
index, or a stored lower watermark so only new or relevant deposit IDs are
queried.
🪄 Autofix (Beta)
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: defaults
Review profile: CHILL
Plan: Pro
Run ID: 9bbb0bb0-5ae2-4564-b994-0eed0a0f1b45
📒 Files selected for processing (1)
src/adaptors/peer/index.js
|
The peer adapter exports pools: Test Suites: 1 passed, 1 total |
| apyBase, | ||
| underlyingTokens: [BASE_USDC], | ||
| token: null, | ||
| poolMeta: `${liquidity.platform.label} (${currencyMeta}) seller liquidity (24h fee APR)`, |
There was a problem hiding this comment.
reduce pool meta, too long.. should be a few words max
There was a problem hiding this comment.
Addressed in 01706776: poolMeta is now only the payment platform label (Venmo, Cash App, etc.), so it is a few words at most.
| underlyingTokens: [BASE_USDC], | ||
| token: null, | ||
| poolMeta: `${liquidity.platform.label} (${currencyMeta}) seller liquidity (24h fee APR)`, | ||
| url: 'https://www.peer.xyz/', |
There was a problem hiding this comment.
Addressed in 01706776: each pool now links directly to https://app.peer.xyz/liquidity instead of the project homepage. The URL was verified to return HTTP 200.
| @@ -0,0 +1,635 @@ | |||
| const sdk = require('@defillama/sdk'); | |||
| const { ethers } = require('ethers'); | |||
There was a problem hiding this comment.
ethers isn't needed we can replace BigNumber with native BigInt, formatUnits with Number(x)/10**dec, and utils.id('USD'/'EUR'/'GBP') with the three precomputed keccak constants; that drops the direct ethers import
There was a problem hiding this comment.
Addressed in 01706776: removed the direct ethers import, replaced BigNumber operations with native BigInt, replaced formatUnits with numeric decimal scaling, and precomputed the USD/EUR/GBP keccak hashes.
0xkr3p
left a comment
There was a problem hiding this comment.
hi @richardliang, thanks for the PR. Can you check the TVL is not being double counted or overstated? pls also use defillama price api helper for usdc
|
The peer adapter exports pools: Test Suites: 1 passed, 1 total |
|
@0xkr3p Addressed the TVL accounting and USDC pricing points in
I also ran fixed-block before/after smoke snapshots on three reproducibly sampled dates (seed
Validation: 53/53 adapter tests passed locally, and both the GitHub |
|
@richardliang thanks for the fast changes, the APY figures look relatively high, we tend to show lower bounds of what a user will receive. I'm thinking we could compute apy over 7d or 30d to give a more realistic view on what apy figures could be achieved. |
|
@0xkr3p Addressed in b9a361b: the adapter now computes fee APY over 7 days and annualizes by 365 / 7, while retaining the extra five-day signal lookup needed to join early-window fulfillments. I compared 7d and 30d using identical fixed Base blocks, allocated TVL, spread logic, and USDC pricing:
We selected 7d because it produced the lower aggregate figure in three of four samples and, at the latest block, was lower for seven of eight platform pools. It also reduces the mismatch from dividing a long period of historical fees by only the current allocated TVL. For example, Monzo had about $77 of current TVL: its 7d APY was 165.32%, while 30d produced 2,014.11% because it included fees earned before liquidity fell to its current level. Seven days still smooths one-day volatility without carrying as much stale liquidity history as 30 days. Validation: the live Peer adapter suite passes 53/53 tests and exports all eight pools. |
|
The peer adapter exports pools: Test Suites: 1 passed, 1 total |
Summary
Adds a Peer yield adapter for Base USDC seller liquidity.
The adapter returns platform-level pools for current Peer Earn-supported rails:
0xf752c7d19698ecb0bb8988abf9b9a53a4c3657f3bc8850a6fb59fdf3e3ce8cd3)Legacy Zelle method hashes, N26, Mercado Pago, and Luxon are intentionally excluded from the yield pools.
Methodology
EscrowV2usingdepositCounter()andgetDeposit().getDepositPaymentMethods(),getDepositPaymentMethodActive(),getDepositCurrencies(), andgetEffectiveRate().IntentFulfilledevents that have matchingEscrowV2.FundsUnlockedAndTransferredevents.Platform pools combine currencies inside the same platform. Liquidity is platform-serviceable liquidity, so it is not intended to be summed across Peer pools.
Sample Data
Latest on-chain smoke sample, UTC 2026-07-09 22:02:39:
Historical APY smoke samples:
Validation
node --check peer/index.js npm run test --adapter=peer -- --runInBandThe DefiLlama adapter harness passes and currently returns 8 pools. Monzo is below DefiLlama's $10k display threshold.
Summary by CodeRabbit