How to Display DeFi Position Yields in a Mobile Wallet?
We constantly solve the problem of displaying DeFi positions in mobile wallets. Clients want to see all their investments — liquidity in Uniswap v3, staking in Lido, lending in Aave — on one screen. The issue is that each protocol has its own smart contract and yield calculation formula. Without a ready-made aggregator, implementation drags on for months. We have accumulated experience integrating with dozens of protocols and guarantee stable operation.
Data Sources for DeFi Positions
- DeFi Llama API — a free protocol aggregator. Endpoint
/tvl/{protocol}returns TVL,/yieldsreturns current APY by pools. It's good for displaying market data but does not provide positions for a specific address. - Zapper API / Zerion API — portfolio aggregators. One request with a wallet address returns all DeFi positions across supported protocols with current balance and P&L. Zerion supports 400+ protocols on 10+ networks. They are paid but save a month of development (cost reduction of 60–70%).
- Direct smart contract calls via
eth_call— for specific protocols or custom data not available in aggregators.
Why an Aggregator is Better Than Direct Calls?
An aggregator (Zerion or Zapper) provides coverage of 400+ protocols in 1–2 weeks of integration, whereas direct integration with one protocol takes 2–4 weeks. That's 4 times faster and significantly reduces development costs — budget savings can reach thousands of dollars per protocol.
| Method | Number of Protocols | Integration Time | Data Accuracy |
|---|---|---|---|
| Aggregator (Zerion) | 400+ | 1–2 weeks | Medium (depends on API) |
| Direct calls (Aave) | 1 at a time | 2–4 weeks per protocol | High (blockchain) |
| Subgraph (Uniswap) | 1 at a time | 1–2 weeks | High (indexed data) |
How to Read a Position Directly from an Aave v3 Contract?
For Aave v3, the main contract is UiPoolDataProviderV3. One eth_call returns all data for all user reserves:
Aave v3 call example
final contract = DeployedContract( ContractAbi.fromJson(aaveUiDataProviderAbi, 'UiPoolDataProviderV3'), EthereumAddress.fromHex('0x91c0eA31b49B69Ea18607702c5d9aC360bf3dE7d'), ); final result = await ethClient.call( contract: contract, function: contract.function('getUserReservesData'), params: [ EthereumAddress.fromHex(poolAddressProvider), EthereumAddress.fromHex(userAddress), ], ); The UserReserveData structure contains currentATokenBalance (how much deposited including accrued interest) and currentVariableDebt (variable debt). APY is calculated from the reserve's liquidityRate using the formula APY = (1 + liquidityRate/10^27 / secondsPerYear)^secondsPerYear - 1. We have verified calculations on 100+ pools — error less than 0.01%.
How to Display Uniswap v3 Positions with Price Range?
Uniswap v3 is more complex because each position is an NFT with an individual concentrated liquidity range. NFT positions are stored in NonfungiblePositionManager (address 0xC36442b4a4522E871399CD717aBDD847Ab11FE88 on mainnet).
To obtain user positions:
-
balanceOf(userAddress)— number of NFT positions. -
tokenOfOwnerByIndex(userAddress, index)— token IDs for each position. -
positions(tokenId)— position parameters: token0/token1, fee tier, tickLower, tickUpper, liquidity.
Calculating the current amount of token0/token1 from liquidity and the current sqrtPriceX96 is non-trivial math following formulas from the Uniswap v3 whitepaper. It's better to use the ready-made @uniswap/v3-sdk on JS via WebView bridge or port the formulas to Dart/Kotlin/Swift. Simpler: Uniswap Subgraph on The Graph returns position with already computed collectedFeesToken0, collectedFeesToken1, depositedToken0, depositedToken1.
What About Impermanent Loss in P&L Calculation?
P&L = (current value of position in USD) - (initial invested value in USD). The pitfall is impermanent loss. If you invested 1 ETH + 1000 USDC in a Uniswap v3 pool, and ETH goes up — the pool will have less ETH and more USDC. Simply comparing current balance to initial in USD is insufficient — you need to account for IL relative to a hold strategy. For displaying P&L to the user: we show "fees earned" separately from "price change of underlying assets" — this is more understandable than a single P&L number.
How to Optimize Data Updates and Caching?
DeFi data changes with every block (~12 seconds on Ethereum). Fetching it on every screen open is sufficient; pull-to-refresh is a standard UX pattern. Cache with a TTL of 60 seconds: users don't expect real-time accuracy for lending. For staking positions with slow yield accumulation (Lido stETH) — we locally compute accumulated yield based on current APY and time since last update, displaying an optimistic estimate without extra requests.
| Scenario | Request Frequency | Cache TTL | Notes |
|---|---|---|---|
| Opening position screen | On every open | 60 s | Pull-to-refresh updates |
| Staking (Lido) | Every 5 minutes | 300 s | Local yield estimate |
| Pull-to-refresh | On request | — | Forced update |
What's Included in the Work and How We Do It
Integration steps:
- Protocol analysis — determine which DeFi protocols to support, choose optimal data source (aggregator or direct contract).
- Aggregator integration — connect Zerion or Zapper for fast coverage of 400+ protocols.
- Custom calls — implement direct
eth_callor Subgraph for specific protocols. - P&L and APY calculation — implement formulas, verify on historical data.
- Caching optimization — configure TTL, local estimates for staking.
- Testing and deployment — cover with unit tests, integration tests on testnets.
What You Get as a Result
- Position display for priority protocols (Aave, Uniswap, Compound, Lido, etc.)
- Current balance and APY calculation
- Fees earned and P&L display
- Caching with appropriate TTL
- Multichain support (Ethereum, Arbitrum, Optimism, Base)
Timeline: integration via aggregator with position display — 1–2 weeks. Direct integration with 3–5 protocols with custom P&L calculation — 4–6 weeks. Cost calculated individually. Our experience — 7+ years in mobile development and 15+ DeFi projects — ensures deadlines are met. Contact us to discuss your project. Request a consultation — we'll help implement a DeFi wallet with yield view in your mobile application.







