import { PubSub } from '@google-cloud/pubsub'
import { commonAbis, evmEventDecoder, evmPortalStream } from '@subsquid/pipes/evm'
import { pubsubTarget } from '@subsquid/pipes/targets/pubsub'
await evmPortalStream({
id: 'base-erc20-transfers',
portal: 'https://portal.sqd.dev/datasets/base-mainnet',
outputs: evmEventDecoder({
range: { from: 'latest' },
events: { transfers: commonAbis.erc20.events.Transfer },
}),
}).pipeTo(
pubsubTarget({
pubsub: new PubSub({ projectId: 'my-gcp-project' }),
// Cursor + rollback manifest + outbox + sequence counter, one transaction per batch.
state: { path: './state/base-erc20-transfers.sqlite' },
// The id space consumers see. Pinned so renaming the pipe does not silently start a new one.
namespace: 'base-erc20',
allowColdStart: true, // drop once the namespace has published
attributes: { chain: 'base', table: 'erc20_transfers' },
topics: {
transfers: {
topic: 'evm.base.erc20-transfers',
map: ({ data }) =>
data.map((t) => ({
data: {
// Hash-based, so a fork's re-streamed events get fresh ids instead of aliasing
// the orphaned ones.
_id: `${t.block.hash}:${t.rawEvent.logIndex}`,
token: t.rawEvent.address,
from: t.event.from,
to: t.event.to,
amount: t.event.value,
block: t.block.number,
timestamp: t.timestamp,
},
block: t.block,
attributes: {
token: t.rawEvent.address,
from: t.event.from,
to: t.event.to,
},
})),
},
},
}),
)