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
Tokenentity for each of the tokens in the pool if not already present. Initializes the token parameters usingfetchTokenSymbol(),fetchTokenName(),fetchTokenTotalSupply(),fetchTokenDecimals()and metrics toZERO_BDorZERO_BI. - If a token is present in the
WHITELIST_TOKENSlist, it is added to the other token'swhitelistPoolslist, which is used for calculating the amount in USD. - Creates a new
Poolentity for the token pair. Uses the event parameters, andtokenentities to initialize the values, while sets the metrics toZERO_BIorZERO_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.feeGrowthGlobal0X128andpool.feeGrowthGlobal1X128values.
- If factory doesn't exists, initializes poolCount to
104instead ofZERO_BIandfactory.populatedtofalse - Before saving the pool entity, if
factory.populatedis false, invokespopulateEmptyPools()to load the pool before regenisis and setsfactory.populated = true.