> ## Documentation Index
> Fetch the complete documentation index at: https://docs.robin.markets/llms.txt
> Use this file to discover all available pages before exploring further.

# Reading on-chain state

> Query a wallet's shares, loss-adjusted assets, and pending yield — plus market state and previews — with the stateless RobinLens aggregator.

`RobinLens` is a stateless batch view aggregator that reads vault state for many markets in a single call. Use it for trustless on-chain reads over RPC, or use the [Integration API](/developers/api-overview) when you want ready-made APY and positions without running an RPC client.

All `RobinLens` reads key on a wallet's **resolved Robin staking wallet** — the user's Polymarket on-chain account (`DepositWallet` or Safe proxy), never the raw EOA. See [Wallets](/developers/wallets) for how to resolve it. See [Contracts overview](/contracts/overview) for the full address list.

## RobinLens functions

Every function is a `public view`. Return arrays are aligned to the input `conditionIds` (or `sides`) by index. All amounts are 6-decimal fixed-point integers (`UNDERLYING_DECIMALS=6`).

| Function                                                                                                                    | Returns                                                                                                                        |
| --------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| `batchGetUserShares(address user, bytes32[] conditionIds)`                                                                  | `(uint256[] yesShares, uint256[] noShares)` — raw ERC-1155 share balances per side.                                            |
| `batchGetUserAssets(address user, bytes32[] conditionIds)`                                                                  | `(uint256[] yesAssets, uint256[] noAssets)` — loss-adjusted outcome-token amounts the shares are currently worth.              |
| `batchGetUserYield(address user, bytes32[] conditionIds, uint256[] twapPricesYes)`                                          | `(uint256[] yesYield, uint256[] noYield)` — pending organic USDC yield per side.                                               |
| `batchGetUserPortfolio(address user, bytes32[] conditionIds, uint256[] twapPricesYes)`                                      | `(yesShares, noShares, yesAssets, noAssets, yesYield, noYield)` — shares, loss-adjusted assets, and pending yield in one call. |
| `batchGetUserSharesAndAssets(address user, bytes32[] conditionIds)`                                                         | `(yesShares, noShares, yesAssets, noAssets)` — shares plus loss-adjusted assets (no yield, no TWAP needed).                    |
| `batchPreviewDeposit(bytes32[] conditionIds, Side[] sides, uint256[] amounts)`                                              | `(uint256[] shares)` — shares a deposit of `amounts` would mint per `(conditionId, side)`.                                     |
| `batchPreviewWithdraw(address user, bytes32[] conditionIds, Side[] sides, uint256[] sharesToBurn, uint256[] twapPricesYes)` | `(uint256[] tokenAssets, uint256[] yieldUsdc)` — outcome tokens and organic USDC yield a withdrawal would return.              |
| `batchGetMarketState(bytes32[] conditionIds)`                                                                               | `(MarketState[])` — per-market vault state.                                                                                    |
| `batchGetMarketIndexes(bytes32[] conditionIds, uint256[] twapPricesYes)`                                                    | `(IndexResult[])` — current `lossIndex` / `yieldPerShare` indexes per market.                                                  |
| `checkBatchDepositCapacity(bytes32[] conditionIds, uint256[] yesAmounts, uint256[] noAmounts)`                              | `(bool)` — whether the markets can absorb the requested amounts.                                                               |
| `vault()`                                                                                                                   | `(address)` — the `RobinStakingVault` proxy this Lens reads from.                                                              |

<Info>
  `Side` is an enum where `YES=0` and `NO=1`. `assets` are loss-adjusted — they
  reflect the vault's `lossIndex` accounting, so they can be lower than the
  originally deposited token amount after impermanent loss.
</Info>

## twapPricesYes parameter

The functions that compute yield or indexes take a `twapPricesYes` array. This is the time-weighed-average price since the last contract interaction (same as submitted before deposits and withdrawals). Its values are interpreted per market against `PRICE_SCALE` (1e6 = 100%).

<Note>
  Pass a value `<= PRICE_SCALE` (1e6) to force **that** YES price for the calculation. Pass any value `> PRICE_SCALE` to use the oracle's **stored TWAP** for that market. Functions without this parameter (`batchGetUserShares`, `batchGetUserAssets`, `batchGetUserSharesAndAssets`) do not depend on price.
</Note>

## Events to index

To track vault state from logs emitted by `RobinStakingVault`, index these events.

| Event               | Key fields                                                                                                                 |
| ------------------- | -------------------------------------------------------------------------------------------------------------------------- |
| `Deposited`         | `user`, `referralCode`, `conditionIds[]`, `yesAmounts[]`, `noAmounts[]`, `yesShares[]`, `noShares[]`                       |
| `Withdrawn`         | `user`, `referralCode`, `conditionIds[]`, `yesShares[]`, `noShares[]`, `yesAssets[]`, `noAssets[]`, `yield`, `protocolFee` |
| `IndexesUpdated`    | `conditionId`, `lossIndexYes`, `lossIndexNo`, `yieldPerShareYes`, `yieldPerShareNo`                                        |
| `MarketInitialized` | `conditionId`, `yesPositionId`, `noPositionId`, `negRisk`                                                                  |
| `TwapUpdated`       | `conditionId`, `twapAccumulatorYes`, `timestamp`                                                                           |

<Note>
  `Withdrawn` carries `yield` (the organic on-chain yield returned) and
  `protocolFee` (Robin may take a protocol fee on the organic yield only). Vault
  indexes use `INDEX_SCALE=1e18`. The off-chain bonus payout (guarantee,
  matching, points) is **not** in these events — it is computed at withdrawal
  and sent separately from Robin's operator wallet.
</Note>

## API vs on-chain

<Tip>
  The [Integration API](/developers/api-overview) returns ready-made positions
  with a full APY breakdown (base / matching / points) and accrued yield as JSON
  — no RPC client, ABI, or TWAP handling required. Reach for `RobinLens` when
  you need trustless reads straight from chain, want to avoid a hosted
  dependency, or are already running an RPC client. The on-chain organic yield
  from `RobinLens` excludes the off-chain bonus programme; the API folds bonuses
  into its totals.
</Tip>

## Next steps

<CardGroup cols={2}>
  <Card title="Integration API overview" icon="server" href="/developers/api-overview">
    Read positions, quotes, and APY breakdowns over HTTP — no RPC required.
  </Card>

  <Card title="Withdrawals" icon="arrow-up-from-bracket" href="/developers/withdrawals">
    Burn shares to reclaim outcome tokens and organic yield via `batchWithdraw`.
  </Card>
</CardGroup>
