Add Surge Credit lending yields adapter - #2859
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a Base-chain Surge Credit adapter. It discovers active markets, calculates supply and borrow APYs, derives liquidity metrics, creates one pool per market, and exposes protocol metadata and market-specific URLs. ChangesSurge Credit adapter
Estimated code review effort: 3 (Moderate) | ~20 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 surge-credit adapter exports pools: Test Suites: 1 passed, 1 total |
There was a problem hiding this comment.
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 `@src/adaptors/surge-credit/index.js`:
- Line 58: Update the TVL assignment in the Surge credit adaptor to use net
supplied assets, calculating totalSupplyUsd minus totalBorrowUsd instead of
availableBorrowUsd. Keep availableBorrowUsd exposed separately for idle
liquidity reporting.
- Line 61: Update the `apyBaseBorrow` calculation in the market-rate mapping to
convert the annual borrow APR returned by `getMarketBorrowRate()` into APY,
matching the supply APY convention; do not expose the raw `borrowRateBps / 100`
APR value.
🪄 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 Plus
Run ID: 54d13a17-f1e3-4de5-a68f-a8ff8eada64a
📒 Files selected for processing (1)
src/adaptors/surge-credit/index.js
|
The surge-credit adapter exports pools: Test Suites: 1 passed, 1 total |
|
The surge-credit adapter exports pools: Test Suites: 1 passed, 1 total |
|
The surge-credit adapter exports pools: Test Suites: 1 passed, 1 total |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/surge-credit/index.js`:
- Around line 66-72: Update the pool object near tvlUsd to calculate TVL as net
supplied liquidity, using totalSupplyUsd minus totalBorrowUsd. Keep maxBorrowUsd
exclusively for availableBorrowUsd and leave the other APY and supply/borrow
fields unchanged.
🪄 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 Plus
Run ID: 65931cfe-b8c0-43d8-86dc-9b40e1d7c5b9
📒 Files selected for processing (1)
src/adaptors/surge-credit/index.js
| chain: utils.formatChain(CHAIN), | ||
| project: 'surge-credit', | ||
| symbol: 'USDC', | ||
| tvlUsd: maxBorrowUsd, |
There was a problem hiding this comment.
tvl formula should be totalSupplyUsd - totalBorrowUsd
| const totalBorrowUsd = Number(market.totalBorrowAssets) / 1e6 | ||
|
|
||
| pools.push({ | ||
| pool: `surge-credit-${m}-${CHAIN}`, |
There was a problem hiding this comment.
better to use address here, such as ${LIQUIDITY_POOL.toLowerCase()}-${m}-${chain}
|
The surge-credit adapter exports pools: Test Suites: 1 passed, 1 total |
…dle 0; address-based pool ids
|
The surge-credit adapter exports pools: Test Suites: 1 passed, 1 total |
There was a problem hiding this comment.
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 `@src/adaptors/surge-credit/index.js`:
- Around line 64-80: Add an explicit token: null field to the pool object
constructed in the adaptor’s pools.push call, preventing triggerAdaptor.js from
inferring LIQUIDITY_POOL as the token while preserving the existing
underlyingTokens: [USDC] declaration.
- Around line 50-62: Separate TVL from borrowable liquidity in the market
mapping: keep the accounting difference represented by idleUsd for tvlUsd, but
calculate availableBorrowUsd from physical liquidity using totalPhysicalSupply
minus totalPhysicalBorrow or the existing getAvailableLiquidity helper. Update
the relevant mapping logic around isFixed and idleUsd without treating
reserve-accrued accounting value as withdrawable liquidity.
🪄 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: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 7d91c201-8368-40d8-8f5c-fbc4221ed271
📒 Files selected for processing (1)
src/adaptors/surge-credit/index.js
|
@0xkr3p Thanks for the review - addressed both comments and fixed the TVL methodology.
Fixed to the standard lending convention: tvlUsd = totalSupplyUsd - totalBorrowUsd (available/idle liquidity), computed per market from that market's own supply and borrow. The two markets' supplied figures are a disjoint partition of the same lender base. When a lender's capital is allocated to a fixed loan it moves out of Market 0's supply and into Market 1's, so each dollar is now counted once.
So the fixed market appears with its true supplied/borrowed figures but a $0 headline TVL, which I think can be better represented given it does not hold separate capital. So is there a convention you would rather we follow? |
…orrowUsd from physical liquidity
|
The surge-credit adapter exports pools: Test Suites: 1 passed, 1 total |
|
hi @punithbm, thanks for the changes. The adapter APY figure seems slightly overstated compared to the surge UI - is there any reason for this? Happy to proceed with TVL as is for fixed market for now |
Adds a yields adapter for Surge Credit, a BTC-collateralized USDC lending protocol on Base.
The protocol is already listed (DefiLlama-Adapters TVL PR is merged and live at https://defillama.com/protocol/surge-credit).
surge-credit8328src/adaptors/surge-credit/index.js(single new file)Pools
One pool per on-chain market on the LiquidityPool contract
0xEE755F1BbcbF6e3260469D0f473522d71d3bdDda:How the numbers are computed
Everything is read live on-chain from the pool contract via
@defillama/sdk(no external API or fetch, no hardcoded rates):apyBase(lender supply APY) =borrowRate * utilization * (1 - reserveRate), then annualized ase^r - 1because the pool accrues interest with continuous compounding (ExpMath.wCompoundFactor).apyBaseBorrow= the current borrow rate fromgetMarketBorrowRate.reserveRateis read live per market frommarkets(id).reserveRateBps(currently 20% on both), so the supply APY stays correct if it changes.totalSupplyUsdandtotalBorrowUsdcome from the market struct.tvlUsd= available liquidity (supplied minus borrowed), fromgetAvailableLiquidity.ltv=maxLtvBps.USDC is the only underlying, priced at ~$1.
Expected low tvlUsd
The two markets currently run at 97 to 100 percent utilization, so available liquidity (
tvlUsd) is small right now (market 0 about $7k, market 1 about $1). The test prints the standard "pools with <10k TVL won't be shown" notice. This is expected:tvlUsdis the correct lending value (supplied minus borrowed), not gross supply. The pools store fine and become visible once available liquidity rises above the threshold.totalSupplyUsd(about $261k and $108k) and the APYs are stored regardless.Testing
npm run test --adapter=surge-creditpasses all 27 checks against live Base mainnet.Only one file is added. No changes to
package.json, lockfiles, or any other adapter. "Allow edits by maintainers" is enabled.Summary by CodeRabbit