Fetching all the data of a certain pool from Ethereum

Tuner syncs the full state of the Pool from the event logs on chain, aiming to reproduce 100% as things happened in the mainnet.

For a quant developer, Tuner offers an easy-to-use API to download/update and persist event logs, and then build the core pool instance for the user. According to transaction volume of wanted core pool, the first run will cost some time. See Performance.

Specifically, you can set block number or other key dates as the upper limit from the deployment of your specified core pool, as time range of event logs. The SimulatorClient will download data up to that block and save it to a SQLite database file locally.

Note: The database for event logs(external data) and the one to support functionality of Tuner(internal data) are different SQLite database files.

export type EndBlockTypeWhenInit =
  | number
  | "latest"
  | "afterDeployment"
  | "afterInitialization";

export type EndBlockTypeWhenRecover =
  | number
  | "latestOnChain"
  | "latestDownloaded"
  | "afterDeployment"
  | "afterInitialization";

For downloading mainnet data, we had to pre-process the data because mainnet events of swaps only represent the results of the swap, we had to use a try-and-error logic to test out the actual inputs of that swap.

This means, there is more information added on top of the mainnet events, and this extra information (correct inputs of the swap that emit the event recorded on mainnet) is only added during the download process.

SimulatorClient will handle with processes above and you just need to call clientInstance.initCorePoolFromMainnet to download event logs for a new pool or clientInstance.recoverFromMainnetEventDBFile to update event logs for an existed pool. They both give you an instance of ConfigurableCorePool finally.

An example of the whole process will be:

Note: If a bad gateway error(usually due to the hosted service of subgraph) happens, just wait a few seconds and then give it a re-run. Tuner has taken error handling into consideration to make sure integrality and consistency of events.

Last updated