fix: add more pools to Yuzu Money#2320
Conversation
📝 WalkthroughWalkthroughRefactors the Yuzu Money adaptor to support multiple chains (plasma, ethereum, monad) via centralized multi-chain/token metadata and helpers; adds chain-aware price, supply, TVL, redemption price, APY calculations, and multi-chain pool generation while preserving the public apy API. Changes
Sequence Diagram(s)sequenceDiagram
participant Adapter as Yuzu Adaptor
participant RPC as Blockchain RPCs (plasma / ethereum / monad)
participant PriceAPI as External Price API
participant Aggregator as Pools Aggregator
Adapter->>RPC: getTotalSupply(chain, token)
RPC-->>Adapter: totalSupply
Adapter->>RPC: getRedemptionPrice(chain, blockNumber, token, underlyingUnit)
RPC-->>Adapter: redemptionPriceData
Adapter->>PriceAPI: fetch price for chain+token address
PriceAPI-->>Adapter: tokenPrice
Adapter->>Aggregator: calculateTvlByToken & calculateApy
Aggregator-->>Adapter: pool objects per chain/token
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 yuzu-money adapter exports pools: Test Suites: 1 passed, 1 total |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@src/adaptors/yuzu-money/index.js`:
- Around line 75-81: getUsdPrice currently returns undefined on missing API data
and lets network errors bubble up; wrap the axios call in a try/catch inside
getUsdPrice, validate that data.coins[priceKey]?.price is a finite number, and
on failure either return a safe numeric fallback (e.g., 0) or throw a
descriptive error that includes chain and token.address so callers can handle
it; also consider logging the axios error before rethrowing or returning the
fallback to aid debugging.
- Around line 119-126: The plasma TVL computation can become negative due to
timing mismatches between supply fetches; update the return calculation that
uses plasmaSupply, monadSupply, ethereumSupply and tokenPrice (the block using
getUsdPrice('plasma', yuzuConfig.plasma[tokenKey]) and computing plasma:
(plasmaSupply - monadSupply - ethereumSupply) * tokenPrice) to clamp the plasma
component to a non-negative value (e.g., compute netPlasma = Math.max(0,
plasmaSupply - monadSupply - ethereumSupply) and use netPlasma * tokenPrice) so
plasma TVL never goes below zero.
🧹 Nitpick comments (1)
src/adaptors/yuzu-money/index.js (1)
61-73: Unusedchainparameter ingetUnderlyingTokensfor syzUSD.The
chainparameter on line 66 is accepted but never used—it always returns the plasma yzUSD address. If this is intentional (canonical underlying always on plasma), consider removing the parameter for consistency withyzPP, or add a comment clarifying the design choice.♻️ Suggested cleanup if chain is intentionally unused
const TOKEN_META = { syzUSD: { symbol: 'syzUSD', url: 'https://app.yuzu.money/yzusd-syzusd', - getUnderlyingTokens: (chain) => [yuzuConfig['plasma'].yzUSD.address], + getUnderlyingTokens: () => [yuzuConfig['plasma'].yzUSD.address], },
|
The yuzu-money adapter exports pools: Test Suites: 1 passed, 1 total |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@src/adaptors/yuzu-money/index.js`:
- Around line 61-72: The TOKEN_META entries (syzUSD and yzPP) currently ignore
the chain parameter in their getUnderlyingTokens functions and always return
plasma-only addresses; update getUnderlyingTokens for syzUSD and yzPP to use the
supplied chain argument (e.g., yuzuConfig[chain].yzUSD.address or a
chain-indexed PLASMA_USDT_ADDRESS map) so each chain returns the correct
underlying token address, or explicitly validate and document that the same
address is valid across chains if that is intentionally the case; locate and
change getUnderlyingTokens in the TOKEN_META object to perform a chain lookup
instead of returning a hardcoded plasma address.
- Around line 141-157: The calculateApy function can produce Infinity/NaN when
startPrice is zero or non-finite; after obtaining startPrice (from
getRedemptionPrice) add a guard that checks Number.isFinite(startPrice) and
startPrice > 0 and, if the check fails, return a safe fallback (e.g., 0 or null)
instead of proceeding to compute appreciationRatio and the power expression;
keep all other logic and use the existing constants APY_REFERENCE_PERIOD_IN_DAYS
and YEAR_IN_DAYS for the calculation.
|
The yuzu-money adapter exports pools: Test Suites: 1 passed, 1 total |
Summary by CodeRabbit
New Features
Refactor
✏️ Tip: You can customize this high-level summary in your review settings.