This indexer tracks events emitted by usdc ("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48") on the ethereum mainnet and is meant to track Approval adjusted value at risk for the Aave pool contract "0x7BeA39867e4169DBe237d55C8242a8f2fcDcc387". I track this risk through the VaR entity.
Logic:
Since the risk is based on the aave pool balance as well as the total possible amount which can be withdrawn from user balances through allowed amounts, I use transfer, burn, and mint events to keep a track of account balances and track approval events specifically where the aave contract is the spender.
The main part of the logic is that the sum of min(balance, approved amount) can change everytime a users balance changes or theres a new approval. I track this sum using a parameter on the VaR entity called totalOfSum. The logic file is used to take care of the following situation:
If a user has a lower balance than approved amount only the balance is added to the totalOfSum. However, if they then get a transfer which increases their balance above the approved amount the risk needs to increase, so the function in the logic file calculates what they originally contributed (the min of balance and approval) and subtracts that before adding the new value. Same logic goes for approval events etc.
Please refer to the documentation website for a thorough guide on all Envio indexer features
pnpm devVisit http://localhost:8080 to see the GraphQL Playground, local password is testing.
pnpm codegen