backfill.ts
Only in Optimism
The file is present only for the optimism subgraph
path: /src/utils/backfill.ts
populateToken()
Params:
- tokenAddress (String):
ReturnType: void
- Initializes a new Token Enttity for the token address if not already present.
- Initializes the token parameters using
fetchTokenSymbol()
,fetchTokenName()
,fetchTokenTotalSupply()
,fetchTokenDecimals()
and metrics toZERO_BD
orZERO_BI
.
Entities:
- Token - Read/Create & Write
Dependencies:
Invoked at:
populateEmptyPools()
Params:
- event (ethereum.Event):
ReturnType: void
Create entities for each pool and token before regenesis of optimism chain.
- Iterates through the pools present in
POOL_MAPPINGS
list. Fow each of the items, does the below mentioned steps. - Using PoolABI, loads the pool contract. Creates a new
Pool
entity and sets it'stoken0
,token1
values from POOL_MAPPING and liquidity from the contract read. Iniitalizes all the metrics toZERO_BD
orZERO_BI
. - set
pool.feeTier
by reading it from the contract. - Invokes
populateToken()
for the the two tokens. - For each token, adds pool to
token.whitelistPool
if the other token is present inWHITELIST_TOKENS
list. - Sets
pool.totalValueLockedToken
andtoken.totalValueLocked
by reading the ERC20 contract and invokingbalanceOf()
. - Saves the token and pool entities.
Overwrites Token TVL
token.tokenValueLocked
is set everytime instead of adding it to the existing balance. Thus if a token is present in multiple pools, the TVL in the from the last pool will be shown.
Entities:
Contracts
- Pool (Template) - Create
ABI Dependencies:
- pool.json
- ERC20.json