intervalUpdates.ts
path: /src/utils/intervalUpdates.ts
updateUniswapDayData()
Params:
- event (ethereum.Event): The event used to determine dayId
ReturnType: UniswapDayData
Updates the tvlUSD
and txCount
parameters for UniswapDayData
entity for a given day. Sets the variables to factory
entity's totalValueLockedUSD
and txCount
values respectively.
Uses event.block.timestamp.toI32() / 86400
to determine the dayID
for UniswapDayData
. If a UniswapDayData
entity for the given day doesn't exist already, it is first created, with rest of the metrics initialized to ZERO_BD
.
Entities:
- Factory - Read
- UniswapDayData - Read/Create & Write
Dependencies:
Invoked at:
updatePoolDayData()
Params:
- event (ethereum.Event): The event used to determine pool address and dayId to get the PoolId
ReturnType: PoolDayData
- Other Chains
- Arbitrum-One
Using event.block.timestamp.toI32()/86400
and event.address.toHexString()
to get the dayID
and poolID
respectively. Together also give the poolDayDataID
.
Creates a new PoolDayData
entity for the day if not found. The new entity's metrics are initialized to ZERO_BD
or ZERO_BI
, while the open
, high
, low
and close
values are set to pool.token0price
.
Updates the PoolDayData
values high
or low
conditionally by comparing pool.token0Price
with the existing values.
Updates the rest of the metrics using values from Pool
entity.
Note: Currently updates poolDayData.close
only when a new entity is created.
Entities:
- Pool - Read
- PoolDayData - Read/Create & Write
Dependencies:
Invoked at:
- Uses the logic of mainnet but doesn't initialize or update
poolDayData.feeGrowthGlobal0X128
andpoolDayData.feeGrowthGlobal1X128
values.
updatePoolHourData()
Params:
- event (ethereum.Event): The event used to determine pool address and hourId to get the HourPoolId
ReturnType: PoolHourData
- Other Chains
- Arbitrum-One
Using event.block.timestamp.toI32()/3600
and event.address.toHexString()
to get the hourIndex
and poolID
respectively. Together also give the hourPoolID
.
Creates a new PoolHourData
entity for the specific hour if not found. The new entity's metrics are initialized to ZERO_BD
or ZERO_BI
, while the open
, high
, low
and close
values are set to pool.token0price
.
Updates the PoolHourData
values high
or low
conditionally by comparing pool.token0Price
with the existing values.
Updates the rest of the metrics using values from Pool
entity.
Entities:
- Pool - Read
- PoolHourData - Read/Create & Write
Dependencies:
Invoked at:
- Uses the logic of mainnet but doesn't initialize or update
poolHourData.feeGrowthGlobal0X128
andpoolHourData.feeGrowthGlobal1X128
values.
updateTokenDayData()
Params:
- token (Token): token to update the daily metrics for
- event (ethereum.Event): The event used to determine the dayID
ReturnType: TokenDayData
Uses event.block.timestamp.toI32() / 86400
to determine the dayID
. Uses dayId
and token.id.toString()
to get the tokenDayID
.
Uses token
's value in terms of eth and multiplies it with eth's price in USD using bundle.ethPriceUSD
to get tokenPrice
.
Creates a new TokenDayData
entity if one for tokenDayID
is not found. Initializes the metrics to ZERO_BD
, while the open
, high
, low
and close
are set to tokenPrice
.
Updates the TokenDayData
values high
or low
conditionally by comparing pool.token0Price
with the existing values.
Upadates the rest of the metrics using valus from Token
entity.
Entities:
- Bundle - Read
- TokenDayData - Read/Create & Write
Dependencies:
Invoked at:
updateTokenHourData()
Params:
- token (Token): token to update hourly metrics for
- event (ethereum.Event): The event used to determine the hourIndex
ReturnType: TokenHourData
Using event.block.timestamp.toI32()/3600
to get the hourIndex
. Uses hourIndex
and token.id.toString()
to get the tokenHourID
.
Uses token
's value in terms of eth and multiplies it with eth's price in USD using bundle.ethPriceUSD
to get tokenPrice
.
Creates a new TokenHourData
entity for the specific hour if not found. The new entity's metrics are initialized to ZERO_BD
, while the open
, high
, low
and close
values are set to tokenPrice
.
Updates the TokenHourData
values high
or low
conditionally by comparing tokenPrice
with the existing values.
Updates the rest of the metrics using values from token
entity.
Entities:
- Bundle - Read
- TokenHourData - Read/Create & Write
Dependencies:
Invoked at:
updateTickDayData()
Params:
- tick (Tick): Tick to update daily metrics for
- event (ethereum.Event): The event used to determine the dayId
ReturnType: TickDayData
- Other Chains
- Arbitrum-One
Uses event.block.timestamp.toI32() / 86400
to determine the dayID
. Uses dayId
and tick.id
to get the tickDayDataID
.
Creates a new TickDayData
entity for the specific day if not found. Initializes the fields pool
and tick
using tick.pool
and tick.id
respectively.
Sets the TickDayData
entity's field values using corresponding fields from tick
.
Entities:
- TickDayData - Read/Create & Write
Invoked at:
- Uses the logic of mainnet but doesn't initialize or update
tickDayData.feeGrowthOutside0X128
andtickDayData.feeGrowthOutside1X128
values.