factory.ts
path: /src/mappings/factory.ts
handlePoolCreated()
Params:
- event (PoolCreated): Event entity representing the Factory Contracts's Pool created event
ReturnType: void
- Eth Mainnet, Polygon
- Arbitrum-One
- Optimism
Ignored Pool
The following pool address is ignored by the function: 0x8fe8d9bb8eeba3ed688069c3d6b556c9ca258248 (MULAN-USDT)
- Loads the factory entity at
FACTORY_ADDRESS
, or creates one if not found. Creates the bundle entity while creating factory. Initializes the new entity toZERO_BD
,ZERO_BI
. - Increment the factory's pool count.
- Creates new
Token
entity for each of the tokens in the pool if not already present. Initializes the token parameters usingfetchTokenSymbol()
,fetchTokenName()
,fetchTokenTotalSupply()
,fetchTokenDecimals()
and metrics toZERO_BD
orZERO_BI
. - If a token is present in the
WHITELIST_TOKENS
list, it is added to the other token'swhitelistPools
list, which is used for calculating the amount in USD. - Creates a new
Pool
entity for the token pair. Uses the event parameters, andtoken
entities to initialize the values, while sets the metrics toZERO_BI
orZERO_BD
. - Finally, using
Pool
(Template), adds a new pool entity to listen for events from the new pool.
Token decimals mandatory
While creating either of the tokens, if the decimals value is not available, the pool entity is not created and the function returns without changing any entity. Only the bundle entity is still created if factory entity didn't exist.
Entities:
- Factory - Read/Create & Write Entity
- Bundle - Create Entity
- Pool - Create Entity
- Token - Read/Create & Write
Contracts
- Pool (Template) - Create
Dependencies:
- FACTORY_ADDRESS
- ADDRESS_ZERO
- ZERO_BD
- ZERO_BI
- ONE_BI
- fetchTokenSymbol()
- fetchTokenName()
- fetchTokenTotalSupply()
- fetchTokenDecimals()
- WHITELIST_TOKENS
Invoked at:
- Same logic as mainnet, but doesn't initialize
pool.feeGrowthGlobal0X128
andpool.feeGrowthGlobal1X128
values.
- If factory doesn't exists, initializes poolCount to
104
instead ofZERO_BI
andfactory.populated
tofalse
- Before saving the pool entity, if
factory.populated
is false, invokespopulateEmptyPools()
to load the pool before regenisis and setsfactory.populated = true
.