Skip to content

Commit

Permalink
Merge pull request #20 from vikiival/feat/polish
Browse files Browse the repository at this point in the history
feat/polish
  • Loading branch information
vikiival committed May 21, 2024
2 parents 81d6fd2 + 782c451 commit 7d3ffb6
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 28 deletions.
1 change: 1 addition & 0 deletions basick.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ deploy:
- lib/main
env:
CHAIN: base-mainnet
PREINDEX_BLOCK: 13156864
STARTING_BLOCK: 14542021
CONTRACT_REGISTRY: '0xcacfe59736172a192c2518f0f83b825b984cc399'
api:
Expand Down
1 change: 1 addition & 0 deletions src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const CHAIN: PossibleChain = process.env.CHAIN as ChainWithEnv || 'base-m

export const STARTING_BLOCK = Number(process.env.STARTING_BLOCK || 0)
export const FINALITY_CONFIRMATION = Number(process.env.FINALITY_CONFIRMATION || 75)
export const PREINDEX_BLOCK = Number(process.env.PREINDEX_BLOCK || 0)

export const ENV_CONTRACTS = {
REGISTRY: process.env.CONTRACT_REGISTRY || '0x672c524543454a5ffb0840131158a26296b0426c'
Expand Down
13 changes: 10 additions & 3 deletions src/mappings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { logger } from '@kodadot1/metasquid/logger'
import { Optional } from '@kodadot1/metasquid/types'
import * as erc721 from '../abi/ERC721'
import { Multicall } from '../abi/multicall'
import { ENV_CONTRACTS } from '../environment'
import { ENV_CONTRACTS, PREINDEX_BLOCK } from '../environment'
import { CollectionEntity as CE, Interaction, MetadataEntity, NFTEntity as NE } from '../model'
import { Contracts } from '../processable'
import { Contracts, contractList } from '../processable'
import { ERC721_TRANSFER, handler as handle721Token } from './erc721'
import { REGISTRY } from './registry'
import { handleCollectionAdd } from './registry/add'
import { forceCollectionCreate, handleCollectionAdd } from './registry/add'
import { handleMetadata } from './shared/metadata'
import { BASE_URI_MAP, MULTICALL_ADDRESS, MULTICALL_BATCH_SIZE } from './utils/constants'
import { findByIdListAsMap } from './utils/entity'
Expand All @@ -19,6 +19,13 @@ import { groupedItemsByCollection, uniqueEntitySets } from './utils/unique'

export async function mainFrame(ctx: Context): Promise<void> {
logger.info(`Processing ${ctx.blocks.length} blocks from ${ctx.blocks[0].header.height} to ${ctx.blocks[ctx.blocks.length - 1].header.height}`)

if (ctx.blocks[0].header.height === PREINDEX_BLOCK) {
const cached = contractList.map(forceCollectionCreate).filter(Boolean) as CE[]
await ctx.store.save(cached)
console.log(`Cached ${cached.length} collections`)
}

const items = []

for (const block of ctx.blocks) {
Expand Down
16 changes: 15 additions & 1 deletion src/mappings/registry/add.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { getOrCreate } from '@kodadot1/metasquid/entity'
import { create, getOrCreate } from '@kodadot1/metasquid/entity'
import md5 from 'md5'
import { CollectionEntity as CE, CollectionType } from '../../model'
import { handleMetadata } from '../shared/metadata'
import { contractOf, unwrap } from '../utils/extract'
import { debug, pending, success } from '../utils/logger'
import { Action, Context, Log } from '../utils/types'
import { getCreateCollectionEvent } from './getters'
import { Contracts, ContractsMap } from '../../processable'
import { BASE_URI_MAP } from '../utils/constants'


const OPERATION = Action.CREATE
Expand Down Expand Up @@ -50,3 +52,15 @@ export async function handleCollectionAdd(context: Log, process: Context): Promi
await process.store.save(final)
success(OPERATION, `[COLLECTION] ${final.id}`)
}


export function forceCollectionCreate(collection: string): CE | undefined {
const cache = ContractsMap[collection as Contracts];
const baseUri = BASE_URI_MAP[collection as Contracts]

if (cache) {
return create(CE, collection, {...cache, hash: md5(collection), baseUri })
}

return undefined
}
1 change: 0 additions & 1 deletion src/mappings/utils/lookups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { Context, EnMap } from './types'
export async function finalizeCollections(collectionSet: Set<string>, ctx: Context): Promise<EnMap<CE>> {
// ctx.store.findBy(CE, {id: In([...collectionMap.keys()])})
const knownCollections = await findByIdListAsMap(ctx.store, CE, collectionSet)
// debug('finalizeCollections' as any , { knownCollections: knownCollections.size })
ctx.log.info(`[finalizeCollections] ${knownCollections.size} collections found`)
// const newCollections: CE[] = []

Expand Down
2 changes: 1 addition & 1 deletion src/processable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,6 @@ function toMap(
ownerCount: 0,
supply: max,
volume: BigInt(0),
version: 1
version: 721,
};
}
47 changes: 25 additions & 22 deletions src/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { Store } from '@subsquid/typeorm-store'
import { events as erc721 } from './abi/ERC721'
import { events as registry } from './abi/Registry'
import { ENV_CONTRACTS, FINALITY_CONFIRMATION, STARTING_BLOCK, disabledRPC, getArchiveUrl, getNodeUrl } from './environment'
import { ENV_CONTRACTS, FINALITY_CONFIRMATION, PREINDEX_BLOCK, STARTING_BLOCK, disabledRPC, getArchiveUrl, getNodeUrl } from './environment'
import { contractList } from './processable'

// export const CONTRACT_ADDRESS = '0x6e0bed56fb3eb7d2fecc5bb71f99e844cd3c2a0b'
Expand All @@ -33,10 +33,10 @@ export const processor = new EvmBatchProcessor()
})
.setRpcDataIngestionSettings({ disabled: disabledRPC })
.setFinalityConfirmation(FINALITY_CONFIRMATION)
.setBlockRange({
from: STARTING_BLOCK
// from: 2_852_779
})
// .setBlockRange({
// from: STARTING_BLOCK
// // from: 2_852_779
// })
.setFields({
log: {
topics: true,
Expand All @@ -47,30 +47,33 @@ export const processor = new EvmBatchProcessor()
.addLog({
address: [ENV_CONTRACTS.REGISTRY],
topic0: [registry.CollectionRegistered.topic],
// range: {
// from: STARTING_BLOCK
// }
range: {
from: STARTING_BLOCK
}
// transaction: true
})
.addLog({
topic0: [erc721.Transfer.topic],
// range: {
// from: STARTING_BLOCK
// }
range: {
from: STARTING_BLOCK
}
// transaction: true
})

// contractList.forEach((contract) => {
// processor.addLog({
// address: [contract],
// topic0: [erc721.Transfer.topic],
// range: {
// from: 0,
// to: STARTING_BLOCK
// }
// // transaction: true
// })
// })
if (PREINDEX_BLOCK) {
contractList.forEach((contract) => {
processor.addLog({
address: [contract],
topic0: [erc721.Transfer.topic],
range: {
from: PREINDEX_BLOCK,
to: STARTING_BLOCK
}
// transaction: true
})
})
}


// .addLog({
// address: [Contracts.Conjunto],
Expand Down

0 comments on commit 7d3ffb6

Please sign in to comment.