Skip to main content

factory.ts

path: /src/mappings/factory.ts

handlePoolCreated()

Params:
- event (PoolCreated): Event entity representing the Factory Contracts's Pool created event

ReturnType: void
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 to ZERO_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 using fetchTokenSymbol(), fetchTokenName(), fetchTokenTotalSupply(), fetchTokenDecimals() and metrics to ZERO_BD or ZERO_BI.
  • If a token is present in the WHITELIST_TOKENS list, it is added to the other token's whitelistPools list, which is used for calculating the amount in USD.
  • Creates a new Pool entity for the token pair. Uses the event parameters, and token entities to initialize the values, while sets the metrics to ZERO_BI or ZERO_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:

  1. Factory - Read/Create & Write Entity
  2. Bundle - Create Entity
  3. Pool - Create Entity
  4. Token - Read/Create & Write

Contracts

  1. Pool (Template) - Create

Dependencies:

  1. FACTORY_ADDRESS
  2. ADDRESS_ZERO
  3. ZERO_BD
  4. ZERO_BI
  5. ONE_BI
  6. fetchTokenSymbol()
  7. fetchTokenName()
  8. fetchTokenTotalSupply()
  9. fetchTokenDecimals()
  10. WHITELIST_TOKENS

Invoked at:

  1. PoolCreated Event (Handler)