Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions codegenerator/cli/npm/envio/src/Batch.res
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ let hasUnorderedReadyItem = (fetchStates: ChainMap.t<FetchState.t>) => {

let hasMultichainReadyItem = (
fetchStates: ChainMap.t<FetchState.t>,
~multichain: InternalConfig.multichain,
~multichain: Config.multichain,
) => {
switch multichain {
| Ordered => hasOrderedReadyItem(fetchStates)
Expand Down Expand Up @@ -496,7 +496,7 @@ let prepareUnorderedBatch = (
let make = (
~checkpointIdBeforeBatch,
~chainsBeforeBatch: ChainMap.t<chainBeforeBatch>,
~multichain: InternalConfig.multichain,
~multichain: Config.multichain,
~batchSizeTarget,
) => {
if (
Expand Down
124 changes: 124 additions & 0 deletions codegenerator/cli/npm/envio/src/Config.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
open Belt

type ecosystem = | @as("evm") Evm | @as("fuel") Fuel

type sourceSyncOptions = {
initialBlockInterval?: int,
backoffMultiplicative?: float,
accelerationAdditive?: int,
intervalCeiling?: int,
backoffMillis?: int,
queryTimeoutMillis?: int,
fallbackStallTimeout?: int,
}

type contract = {
name: string,
abi: EvmTypes.Abi.t,
addresses: array<Address.t>,
events: array<Internal.eventConfig>,
startBlock: option<int>,
}

type chain = {
id: int,
startBlock: int,
endBlock?: int,
maxReorgDepth: int,
contracts: array<contract>,
sources: array<Source.t>,
}

type sourceSync = {
initialBlockInterval: int,
backoffMultiplicative: float,
accelerationAdditive: int,
intervalCeiling: int,
backoffMillis: int,
queryTimeoutMillis: int,
fallbackStallTimeout: int,
}

type multichain = | @as("ordered") Ordered | @as("unordered") Unordered

type t = {
shouldRollbackOnReorg: bool,
shouldSaveFullHistory: bool,
multichain: multichain,
chainMap: ChainMap.t<chain>,
defaultChain: option<chain>,
ecosystem: ecosystem,
enableRawEvents: bool,
preloadHandlers: bool,
maxAddrInPartition: int,
batchSize: int,
lowercaseAddresses: bool,
addContractNameToContractNameMapping: dict<string>,
}

let make = (
~shouldRollbackOnReorg=true,
~shouldSaveFullHistory=false,
~chains: array<chain>=[],
~enableRawEvents=false,
~preloadHandlers=false,
~ecosystem=Evm,
~batchSize=5000,
~lowercaseAddresses=false,
~multichain=Unordered,
~shouldUseHypersyncClientDecoder=true,
~maxAddrInPartition=5000,
) => {
// Validate that lowercase addresses is not used with viem decoder
if lowercaseAddresses && !shouldUseHypersyncClientDecoder {
Js.Exn.raiseError(
"lowercase addresses is not supported when event_decoder is 'viem'. Please set event_decoder to 'hypersync-client' or change address_format to 'checksum'.",
)
}

let chainMap =
chains
->Js.Array2.map(n => {
(ChainMap.Chain.makeUnsafe(~chainId=n.id), n)
})
->ChainMap.fromArrayUnsafe

// Build the contract name mapping for efficient lookup
let addContractNameToContractNameMapping = Js.Dict.empty()
chains->Array.forEach(chainConfig => {
chainConfig.contracts->Array.forEach(contract => {
let addKey = "add" ++ contract.name->Utils.String.capitalize
addContractNameToContractNameMapping->Js.Dict.set(addKey, contract.name)
})
})

{
shouldRollbackOnReorg,
shouldSaveFullHistory,
multichain,
chainMap,
defaultChain: chains->Array.get(0),
enableRawEvents,
ecosystem,
maxAddrInPartition,
preloadHandlers,
batchSize,
lowercaseAddresses,
addContractNameToContractNameMapping,
}
}

let shouldSaveHistory = (config, ~isInReorgThreshold) =>
config.shouldSaveFullHistory || (config.shouldRollbackOnReorg && isInReorgThreshold)

let shouldPruneHistory = (config, ~isInReorgThreshold) =>
!config.shouldSaveFullHistory && (config.shouldRollbackOnReorg && isInReorgThreshold)

let getChain = (config, ~chainId) => {
let chain = ChainMap.Chain.makeUnsafe(~chainId)
config.chainMap->ChainMap.has(chain)
? chain
: Js.Exn.raiseError(
"No chain with id " ++ chain->ChainMap.Chain.toString ++ " found in config.yaml",
)
}
4 changes: 2 additions & 2 deletions codegenerator/cli/npm/envio/src/EventRegister.res
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ type registrations = {
}

type activeRegistration = {
ecosystem: InternalConfig.ecosystem,
multichain: InternalConfig.multichain,
ecosystem: Config.ecosystem,
multichain: Config.multichain,
preloadHandlers: bool,
registrations: registrations,
mutable finished: bool,
Expand Down
4 changes: 2 additions & 2 deletions codegenerator/cli/npm/envio/src/EventRegister.resi
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ type registrations = {
}

let startRegistration: (
~ecosystem: InternalConfig.ecosystem,
~multichain: InternalConfig.multichain,
~ecosystem: Config.ecosystem,
~multichain: Config.multichain,
~preloadHandlers: bool,
) => unit
let finishRegistration: unit => registrations
Expand Down
5 changes: 5 additions & 0 deletions codegenerator/cli/npm/envio/src/Indexer.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type t = {
config: Config.t,
registrations: EventRegister.registrations,
persistence: Persistence.t,
}
48 changes: 0 additions & 48 deletions codegenerator/cli/npm/envio/src/InternalConfig.res

This file was deleted.

9 changes: 7 additions & 2 deletions codegenerator/cli/npm/envio/src/Persistence.res
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type storage = {
// Should initialize the storage so we can start interacting with it
// Eg create connection, schema, tables, etc.
initialize: (
~chainConfigs: array<InternalConfig.chain>=?,
~chainConfigs: array<Config.chain>=?,
~entities: array<Internal.entityConfig>=?,
~enums: array<Internal.enumConfig<Internal.enum>>=?,
) => promise<initialState>,
Expand Down Expand Up @@ -91,7 +91,10 @@ type t = {
allEntities: array<Internal.entityConfig>,
allEnums: array<Internal.enumConfig<Internal.enum>>,
mutable storageStatus: storageStatus,
storage: storage,
mutable storage: storage,
// FIXME: This is temporary to move it library
// Should be a part of the storage interface and db agnostic
mutable sql: Postgres.sql,
}

let entityHistoryActionEnumConfig: Internal.enumConfig<EntityHistory.RowAction.t> = {
Expand All @@ -106,6 +109,7 @@ let make = (
// TODO: Should only pass userEnums and create internal config in runtime
~allEnums,
~storage,
~sql,
) => {
let allEntities = userEntities->Js.Array2.concat([InternalTable.DynamicContractRegistry.config])
let allEnums =
Expand All @@ -116,6 +120,7 @@ let make = (
allEnums,
storageStatus: Unknown,
storage,
sql,
}
}

Expand Down
Loading
Loading