📖
Bella "Tuner" - A Uniswap V3 Simulator
  • Getting Started
    • Overview
    • How "Tuner" Library Works?
    • Installing "Tuner"
    • Quick Start
  • Configuration
    • Configuration
  • Guides
    • (Basic)For anyone who is interested in the Uniswap v3 model
      • Building a client instance
      • About Core Pool Config
      • Getting a Core Pool instance
      • Interacting with Core Pool
    • (Typical)For a quant developer who works on a real pool on mainnet
      • Fetching all the data of a certain pool from Ethereum
      • Getting a pool instance with the data fetched
      • Loading and streaming events into a pool
    • (Advanced)For a better user experience as a state machine
      • PoolState & Transition
      • Post-processor
      • Forking & Retracing
      • Persisting & Recovering
      • SimulatorRoadmapManager
  • Performance
    • Performance
  • Examples
    • Uniswap-v3-Events-Downloader
    • Uniswap-v3-Strategy-Backtest
    • Uniswap-v3-Risk-Analysis(will be available soon)
  • Contributing
    • Contributing
Powered by GitBook
On this page
  1. Guides
  2. (Typical)For a quant developer who works on a real pool on mainnet

Getting a pool instance with the data fetched

PreviousFetching all the data of a certain pool from EthereumNextLoading and streaming events into a pool

Last updated 3 years ago

Usually before work begins, the preparation includes the following steps:

  1. Using mainnet data to initialize a core pool

  2. Replaying events up to the specified block

SimulatorClient(clientInstance.initCorePoolFromMainnet and clientInstance.recoverFromMainnetEventDBFile) is designed to do that. See .

If you have tried MainnetDataDownloader to download or update event logs(See ), then you are supposed to get the pool instance in this way:

// the database name containing downloaded-and-pre-processed mainnet events
let mainnetEventDBFilePath =
  "events_0x8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8.db";

let simulationDataManager: SimulationDataManager =
  await SQLiteSimulationDataManager.buildInstance(
    "Your file path to save the internal data"
  );
let clientInstance: SimulatorClient = new SimulatorClient(
  simulationDataManager
);

// Specify an endBlock number
// the SimulatorClient will replay events up to that block
let endBlock = 12374077;

let configurableCorePool: ConfigurableCorePool =
  await clientInstance.recoverFromMainnetEventDBFile(
    mainnetEventDBFilePath,
    endBlock
  );

// Now you can do whatever you want with the simulated pool
// here we simply print out the square root price of the pool at the specified block height
console.log(configurableCorePool.getCorePool().sqrtPriceX96.toString());
Fetching all the data of a certain pool from Ethereum
Uniswap-v3-Events-Downloader