You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# AUTO-GENERATED. DO NOT EDIT.specVersion: 1.0.0description: univ3sps Substreams-powered-Subgraphschema:
file: ./schema.graphqldataSources:
- kind: substreamsname: filtered_eventsnetwork: mainnetsource:
package:
moduleName: map_eventsfile: univ3sps-v0.1.0.spkgmapping:
apiVersion: 0.0.7kind: substreams/graph-entities # Would want to update to `substreams/triggers` ?file: ./src/generated/substreams_handler.tshandler: generatedSubstreamsHandler
and the src/generated/substreams_handler.ts looks like:
exportfunctiongeneratedSubstreamsHandler(bytes: Uint8Array): void{// NOTE: OBTAINS _all_ events from the block, in a single swiftconstevents: Events=Protobuf.decode<Events>(bytes,Events.decode)constblock=extractBlockFromMessage(events)events.factoryPoolCreateds.forEach((factoryPoolCreated: Factory_PoolCreated)=>{letconverted=newPoolCreated(Address.fromBytes(Bytes.fromUint8Array(factoryPoolCreated.pool)),// AddressBigInt.fromI32(factoryPoolCreated.evtIndexasi32),BigInt.fromI32(factoryPoolCreated.evtTrxIndexasi32),"PoolCreated",// logTypeblock,extractTransactionFromEvent(factoryPoolCreated),[newethereum.EventParam("token0",ethereum.Value.fromAddress(Address.fromBytes(Bytes.fromUint8Array(factoryPoolCreated.token0)))),newethereum.EventParam("token1",ethereum.Value.fromAddress(Address.fromBytes(Bytes.fromUint8Array(factoryPoolCreated.token1)))),newethereum.EventParam("fee",ethereum.Value.fromI32(factoryPoolCreated.feeasi32)),newethereum.EventParam("tickSpacing",ethereum.Value.fromI32(factoryPoolCreated.tickSpacingasi32)),newethereum.EventParam("pool",ethereum.Value.fromAddress(Address.fromBytes(Bytes.fromUint8Array(factoryPoolCreated.pool)))),],null,// receipt)// THIS CALLS ORIGINAL SUBGRAPH CODE:handlePoolCreated(converted)})events.poolInitializes.forEach((poolInitialize: Pool_Initialize)=>{if(Pool.load("0x"+poolInitialize.evtAddress)==null){// check if the dynamic template was created, for now we rely on poolreturn;}letconverted=newInitialize(Address.fromString(poolInitialize.evtAddress),// AddressBigInt.fromI32(poolInitialize.evtIndexasi32),BigInt.fromI32(poolInitialize.evtTrxIndexasi32),"Initialize",block,extractTransactionFromEvent(poolInitialize),[newethereum.EventParam("sqrtPriceX96",ethereum.Value.fromSignedBigInt(BigInt.fromString(poolInitialize.sqrtPriceX96))),newethereum.EventParam("tick",ethereum.Value.fromI32(poolInitialize.tickasi32)),],null,)// THIS CALLS ORIGINAL SUBGRAPH CODE:handleInitialize(converted)})events.poolSwaps.forEach((poolSwap: Pool_Swap)=>{if(Pool.load("0x"+poolSwap.evtAddress)==null){return;}letconverted=newSwap(Address.fromString(poolSwap.evtAddress),BigInt.fromI32(poolSwap.evtIndexasi32),BigInt.fromI32(poolSwap.evtTrxIndexasi32),"Swap",block,extractTransactionFromEvent(poolSwap),[newethereum.EventParam("sender",ethereum.Value.fromAddress(Address.fromBytes(Bytes.fromUint8Array(poolSwap.sender)))),newethereum.EventParam("recipient",ethereum.Value.fromAddress(Address.fromBytes(Bytes.fromUint8Array(poolSwap.recipient)))),newethereum.EventParam("amount0",ethereum.Value.fromSignedBigInt(BigInt.fromString(poolSwap.amount0))),newethereum.EventParam("amount1",ethereum.Value.fromSignedBigInt(BigInt.fromString(poolSwap.amount1))),newethereum.EventParam("sqrtPriceX96",ethereum.Value.fromSignedBigInt(BigInt.fromString(poolSwap.sqrtPriceX96))),newethereum.EventParam("liquidity",ethereum.Value.fromSignedBigInt(BigInt.fromString(poolSwap.liquidity))),newethereum.EventParam("tick",ethereum.Value.fromI32(poolSwap.tickasi32)),],null,)// THIS CALLS ORIGINAL SUBGRAPH CODE:handleSwap(converted)})// More handlers here for burns, mint, collect...}
alongside the protobuf-as generated models for the dynamically created protobuf messages exchanged between Substreams and the subgraph.
Result
Preliminary results show a ~2x speed increase when using this method. This avoids reconnections to firehose when a new Dynamic Data Source is added, which is potentially a source of slowdown.
Assess caveats
The Template.create function would need to work under the substreams, and simply store that as an entity, and have no bearing on reconnections or other tweaks from the substreams source. That would require tweaks to graph-node.
Missing eth_calls when using a substreams source. Will need to add support in graph-node, backed by another RPC endpoint.
The substreams_handler will need to sort the events by ordinal before calling them to reproduce the handler ordering of the original subgraph. This is trivial but not represented in the code snippets here for simplicity.
The text was updated successfully, but these errors were encountered:
abourget
changed the title
Prototype Dynamic Data Source codegen from subgraph.yaml
SpS autogenerated from Ethereum subgraph.yaml
Jul 5, 2024
Goal: go validate with customers that having a no-code 2x speed increase by just wrapping their subgraph into a SpS is desirable
We want to validate that 2x is real (stepd has done good work on that).
We want to show what the experience would look like.
Feature
subgraph.yaml
,Example
Original
subgraph.yaml
Starting from Uniswap V3's original subgraph.yaml here:
https://github.com/Uniswap/v3-subgraph/blob/main/subgraph.yaml
:Produced SpS manifest
and the
src/generated/substreams_handler.ts
looks like:alongside the
protobuf-as
generated models for the dynamically created protobuf messages exchanged between Substreams and the subgraph.Result
Preliminary results show a ~2x speed increase when using this method. This avoids reconnections to firehose when a new Dynamic Data Source is added, which is potentially a source of slowdown.
Assess caveats
Template.create
function would need to work under thesubstreams
, and simply store that as an entity, and have no bearing on reconnections or other tweaks from thesubstreams
source. That would require tweaks tograph-node
.eth_calls
when using asubstreams
source. Will need to add support ingraph-node
, backed by another RPC endpoint.The text was updated successfully, but these errors were encountered: