# sDAI Gnosis Chain Indexer [SubQuery](https://subquery.network) indexer for tracking sDAI (Savings xDAI) metrics on Gnosis Chain. **This SubQuery project indexes sDAI exchange rates, APY, deposits, withdrawals, and transfers for [Savings xDAI](https://gnosisscan.io/address/0xaf204776c7245bf4147c2612bf6e5972ee483701) (`0xaf204776c7245bf4147c2612bf6e5972ee483701`) on Gnosis Network** ## What it Indexes - **Exchange Rates**: Historical sDAI to DAI exchange rates (hourly & daily snapshots) - **APY Calculations**: Automated 7-day and 30-day rolling APY calculations - **Deposits & Withdrawals**: All ERC4626 deposit/withdraw events - **Transfers**: sDAI transfer events for holder tracking - **Global Stats**: Total deposits, withdrawals, holder count, current rates ## Queries ### Get Current APY and Stats ```graphql query { globalStats(id: "global") { currentExchangeRate latestApy7d latestApy30d holderCount totalDeposits totalWithdrawals totalDepositCount totalWithdrawalCount } } ``` ### Get Historical APY (Last 30 Days) ```graphql query { dailySnapshots( orderBy: TIMESTAMP_DESC first: 30 ) { nodes { id timestamp exchangeRate apy7d apy30d totalSupply totalAssets holderCount } } } ``` ### Get Recent Deposits ```graphql query { deposits( orderBy: TIMESTAMP_DESC first: 10 ) { nodes { id timestamp sender owner assets shares transactionHash } } } ``` ## How It Works ### Exchange Rate Calculation (Event-Based) This indexer uses a **fully deterministic, event-based approach** to calculate the sDAI exchange rate: - Every `Deposit` and `Withdraw` event contains both `assets` (DAI) and `shares` (sDAI) - Exchange rate = `(assets * 1e18) / shares` - This gives us the exact conversion rate at the moment of each event - No external RPC calls needed - everything is derived from on-chain events ### APY Calculation APY is calculated using the formula: ``` APY = (1 + rate_change)^(365/period) - 1 ``` Where: - `rate_change` = (current_rate - previous_rate) / previous_rate - `period` = 7 or 30 days APYs are stored as basis points (e.g., 650 = 6.50%)