Skip to content
Open
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
2 changes: 1 addition & 1 deletion codegenerator/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ HyperIndex is a fast, developer-friendly multichain indexer, optimized for both
- **[Reorg support](https://docs.envio.dev/docs/HyperIndex/reorgs-support)** – Graceful handling of blockchain reorganizations
- **GraphQL API** – Easy-to-query indexed data
- **Flexible language support** – JavaScript, TypeScript, and ReScript
- **Factory contract support** – Index data from 100,000+ factory contracts seamlessly
- **Factory contract support** – Index data from 1M+ dynamically registered contracts seamlessly
- **On-chain & off-chain data integration** – Easily combine multiple data sources
- **[Self-hosted & managed options](https://docs.envio.dev/docs/HyperIndex/hosted-service)** – Run your own setup or use HyperIndex hosted services
- **Detailed logging & error reporting** – Debug and optimize with clarity
Expand Down
5 changes: 5 additions & 0 deletions codegenerator/cli/npm/envio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
"@envio-dev/hypersync-client": "0.6.5",
"rescript": "11.1.3",
"rescript-schema": "9.3.0",
"@rescript/react": "0.12.1",
"ink": "3.2.0",
"ink-big-text": "1.2.0",
"ink-spinner": "4.0.3",
"ink-use-stdout-dimensions": "1.0.5",
"viem": "2.21.0",
"bignumber.js": "9.1.2",
"pino": "8.16.1",
Expand Down
5 changes: 5 additions & 0 deletions codegenerator/cli/npm/envio/package.json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
"@envio-dev/hypersync-client": "0.6.5",
"rescript": "11.1.3",
"rescript-schema": "9.3.0",
"@rescript/react": "0.12.1",
"ink": "3.2.0",
"ink-big-text": "1.2.0",
"ink-spinner": "4.0.3",
"ink-use-stdout-dimensions": "1.0.5",
"viem": "2.21.0",
"bignumber.js": "9.1.2",
"pino": "8.16.1",
Expand Down
564 changes: 564 additions & 0 deletions codegenerator/cli/npm/envio/pnpm-lock.yaml

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion codegenerator/cli/npm/envio/rescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@
"in-source": true
},
"gentypeconfig": {
"shims": {
"Js": "Js"
},
"generatedFileExtension": ".gen.ts"
},
"bs-dependencies": ["rescript-schema"],
"jsx": {
"version": 4
},
"bs-dependencies": ["rescript-schema", "@rescript/react"],
"bsc-flags": ["-open RescriptSchema"]
}
39 changes: 21 additions & 18 deletions codegenerator/cli/npm/envio/src/FetchState.res
Original file line number Diff line number Diff line change
Expand Up @@ -818,20 +818,27 @@ let getNextQuery = (
if (
p->checkIsFetchingPartition->not && p.latestFetchedBlock.blockNumber < maxQueryBlockNumber
) {
switch p->makePartitionQuery(
~indexingContracts,
~endBlock=switch blockLag {
| 0 => endBlock
| _ =>
switch endBlock {
| Some(endBlock) => Some(Pervasives.min(headBlock, endBlock))
// Force head block as an endBlock when blockLag is set
// because otherwise HyperSync might return bigger range
| None => Some(headBlock)
}
},
~mergeTarget,
) {
let endBlock = switch blockLag {
| 0 => endBlock
| _ =>
switch endBlock {
| Some(endBlock) => Some(Pervasives.min(headBlock, endBlock))
// Force head block as an endBlock when blockLag is set
// because otherwise HyperSync might return bigger range
| None => Some(headBlock)
}
}
// Enforce the respose range up until target block
// Otherwise for indexers with 100+ partitions
// we might blow up the buffer size to more than 600k events
// simply because of HyperSync returning extra blocks
let endBlock = switch (endBlock, maxQueryBlockNumber < currentBlockHeight) {
| (Some(endBlock), true) => Some(Pervasives.min(maxQueryBlockNumber, endBlock))
| (None, true) => Some(maxQueryBlockNumber)
| (_, false) => endBlock
}

switch p->makePartitionQuery(~indexingContracts, ~endBlock, ~mergeTarget) {
| Some(q) => queries->Array.push(q)
| None => ()
}
Expand Down Expand Up @@ -1061,10 +1068,6 @@ let make = (
Prometheus.IndexingPartitions.set(~partitionsCount=partitions->Array.length, ~chainId)
Prometheus.IndexingBufferSize.set(~bufferSize=0, ~chainId)
Prometheus.IndexingBufferBlockNumber.set(~blockNumber=latestFetchedBlock.blockNumber, ~chainId)
switch endBlock {
| Some(endBlock) => Prometheus.IndexingEndBlock.set(~endBlock, ~chainId)
| None => ()
}

{
partitions,
Expand Down
43 changes: 31 additions & 12 deletions codegenerator/cli/npm/envio/src/Hasura.res
Original file line number Diff line number Diff line change
Expand Up @@ -222,24 +222,43 @@ let trackDatabase = async (
~endpoint,
~auth,
~pgSchema,
~allStaticTables,
~allEntityTables,
~userEntities: array<Internal.entityConfig>,
~aggregateEntities,
~responseLimit,
~schema,
) => {
let trackOnlyInternalTableNames = [
InternalTable.Chains.table.tableName,
InternalTable.EventSyncState.table.tableName,
InternalTable.PersistedState.table.tableName,
InternalTable.EndOfBlockRangeScannedData.table.tableName,
InternalTable.DynamicContractRegistry.table.tableName,
]
let exposedInternalTableNames = [
InternalTable.RawEvents.table.tableName,
InternalTable.Views.metaViewName,
InternalTable.Views.chainMetadataViewName,
]
let userTableNames = userEntities->Js.Array2.map(entity => entity.table.tableName)

Logging.info("Tracking tables in Hasura")

let _ = await clearHasuraMetadata(~endpoint, ~auth)
let tableNames =
[allStaticTables, allEntityTables]
->Belt.Array.concatMany
->Js.Array2.map(({tableName}: Table.table) => tableName)

await trackTables(~endpoint, ~auth, ~pgSchema, ~tableNames)
await trackTables(
~endpoint,
~auth,
~pgSchema,
~tableNames=[
exposedInternalTableNames,
trackOnlyInternalTableNames,
userTableNames,
]->Belt.Array.concatMany,
)

let _ =
await tableNames
await [exposedInternalTableNames, userTableNames]
->Belt.Array.concatMany
->Js.Array2.map(tableName =>
createSelectPermissions(
~endpoint,
Expand All @@ -251,11 +270,11 @@ let trackDatabase = async (
)
)
->Js.Array2.concatMany(
allEntityTables->Js.Array2.map(table => {
let {tableName} = table
userEntities->Js.Array2.map(entityConfig => {
let {tableName} = entityConfig.table
[
//Set array relationships
table
entityConfig.table
->Table.getDerivedFromFields
->Js.Array2.map(derivedFromField => {
//determines the actual name of the underlying relational field (if it's an entity mapping then suffixes _id for eg.)
Expand All @@ -275,7 +294,7 @@ let trackDatabase = async (
)
}),
//Set object relationships
table
entityConfig.table
->Table.getLinkedEntityFields
->Js.Array2.map(((field, linkedEntityName)) => {
createEntityRelationship(
Expand Down
11 changes: 7 additions & 4 deletions codegenerator/cli/npm/envio/src/Internal.res
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,16 @@ let fuelTransferParamsSchema = S.schema(s => {
})

type entity = private {id: string}
type entityConfig = {
type genericEntityConfig<'entity> = {
name: string,
schema: S.t<entity>,
rowsSchema: S.t<array<entity>>,
schema: S.t<'entity>,
rowsSchema: S.t<array<'entity>>,
table: Table.table,
entityHistory: EntityHistory.t<entity>,
entityHistory: EntityHistory.t<'entity>,
}
type entityConfig = genericEntityConfig<entity>
external fromGenericEntityConfig: genericEntityConfig<'entity> => entityConfig = "%identity"

type enum
type enumConfig<'enum> = {
name: string,
Expand Down
22 changes: 22 additions & 0 deletions codegenerator/cli/npm/envio/src/InternalConfig.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// TODO: rename the file to Config.res after finishing the migration from codegen
// And turn it into PublicConfig instead
// For internal use we should create Indexer.res with a stateful type

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,
confirmedBlockThreshold: int,
contracts: array<contract>,
sources: array<Source.t>,
}

type ecosystem = | @as("evm") Evm | @as("fuel") Fuel
11 changes: 11 additions & 0 deletions codegenerator/cli/npm/envio/src/Js.shim.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export type Json_t =
| string
| boolean
| number
| null
| { [key: string]: Json_t }
| Json_t[];

export type t = unknown;

export type Exn_t = Error;
18 changes: 12 additions & 6 deletions codegenerator/cli/npm/envio/src/LoadManager.res
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,32 @@ let schedule = async loadManager => {
}
})

if inputsToLoad->Utils.Array.isEmpty->not {
let isSuccess = if inputsToLoad->Utils.Array.isEmpty->not {
try {
await group.load(inputsToLoad)
true
} catch {
| exn => {
let exn = exn->Utils.prettifyExn
currentInputKeys->Array.forEach(inputKey => {
let call = calls->Js.Dict.unsafeGet(inputKey)
call.reject(exn)
})
false
}
}
} else {
true
}

if currentInputKeys->Utils.Array.isEmpty->not {
currentInputKeys->Js.Array2.forEach(inputKey => {
let call = calls->Js.Dict.unsafeGet(inputKey)
calls->Utils.Dict.deleteInPlace(inputKey)
call.resolve(group.getUnsafeInMemory(inputKey))
})
if isSuccess {
currentInputKeys->Js.Array2.forEach(inputKey => {
let call = calls->Js.Dict.unsafeGet(inputKey)
calls->Utils.Dict.deleteInPlace(inputKey)
call.resolve(group.getUnsafeInMemory(inputKey))
})
}

// Clean up executed batch to reset
// provided load function which
Expand Down
Loading
Loading