Skip to content

Commit 7d3ffb6

Browse files
authored
Merge pull request #20 from vikiival/feat/polish
feat/polish
2 parents 81d6fd2 + 782c451 commit 7d3ffb6

File tree

7 files changed

+53
-28
lines changed

7 files changed

+53
-28
lines changed

basick.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ deploy:
1515
- lib/main
1616
env:
1717
CHAIN: base-mainnet
18+
PREINDEX_BLOCK: 13156864
1819
STARTING_BLOCK: 14542021
1920
CONTRACT_REGISTRY: '0xcacfe59736172a192c2518f0f83b825b984cc399'
2021
api:

src/environment.ts

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const CHAIN: PossibleChain = process.env.CHAIN as ChainWithEnv || 'base-m
1010

1111
export const STARTING_BLOCK = Number(process.env.STARTING_BLOCK || 0)
1212
export const FINALITY_CONFIRMATION = Number(process.env.FINALITY_CONFIRMATION || 75)
13+
export const PREINDEX_BLOCK = Number(process.env.PREINDEX_BLOCK || 0)
1314

1415
export const ENV_CONTRACTS = {
1516
REGISTRY: process.env.CONTRACT_REGISTRY || '0x672c524543454a5ffb0840131158a26296b0426c'

src/mappings/index.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import { logger } from '@kodadot1/metasquid/logger'
33
import { Optional } from '@kodadot1/metasquid/types'
44
import * as erc721 from '../abi/ERC721'
55
import { Multicall } from '../abi/multicall'
6-
import { ENV_CONTRACTS } from '../environment'
6+
import { ENV_CONTRACTS, PREINDEX_BLOCK } from '../environment'
77
import { CollectionEntity as CE, Interaction, MetadataEntity, NFTEntity as NE } from '../model'
8-
import { Contracts } from '../processable'
8+
import { Contracts, contractList } from '../processable'
99
import { ERC721_TRANSFER, handler as handle721Token } from './erc721'
1010
import { REGISTRY } from './registry'
11-
import { handleCollectionAdd } from './registry/add'
11+
import { forceCollectionCreate, handleCollectionAdd } from './registry/add'
1212
import { handleMetadata } from './shared/metadata'
1313
import { BASE_URI_MAP, MULTICALL_ADDRESS, MULTICALL_BATCH_SIZE } from './utils/constants'
1414
import { findByIdListAsMap } from './utils/entity'
@@ -19,6 +19,13 @@ import { groupedItemsByCollection, uniqueEntitySets } from './utils/unique'
1919

2020
export async function mainFrame(ctx: Context): Promise<void> {
2121
logger.info(`Processing ${ctx.blocks.length} blocks from ${ctx.blocks[0].header.height} to ${ctx.blocks[ctx.blocks.length - 1].header.height}`)
22+
23+
if (ctx.blocks[0].header.height === PREINDEX_BLOCK) {
24+
const cached = contractList.map(forceCollectionCreate).filter(Boolean) as CE[]
25+
await ctx.store.save(cached)
26+
console.log(`Cached ${cached.length} collections`)
27+
}
28+
2229
const items = []
2330

2431
for (const block of ctx.blocks) {

src/mappings/registry/add.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { getOrCreate } from '@kodadot1/metasquid/entity'
1+
import { create, getOrCreate } from '@kodadot1/metasquid/entity'
22
import md5 from 'md5'
33
import { CollectionEntity as CE, CollectionType } from '../../model'
44
import { handleMetadata } from '../shared/metadata'
55
import { contractOf, unwrap } from '../utils/extract'
66
import { debug, pending, success } from '../utils/logger'
77
import { Action, Context, Log } from '../utils/types'
88
import { getCreateCollectionEvent } from './getters'
9+
import { Contracts, ContractsMap } from '../../processable'
10+
import { BASE_URI_MAP } from '../utils/constants'
911

1012

1113
const OPERATION = Action.CREATE
@@ -50,3 +52,15 @@ export async function handleCollectionAdd(context: Log, process: Context): Promi
5052
await process.store.save(final)
5153
success(OPERATION, `[COLLECTION] ${final.id}`)
5254
}
55+
56+
57+
export function forceCollectionCreate(collection: string): CE | undefined {
58+
const cache = ContractsMap[collection as Contracts];
59+
const baseUri = BASE_URI_MAP[collection as Contracts]
60+
61+
if (cache) {
62+
return create(CE, collection, {...cache, hash: md5(collection), baseUri })
63+
}
64+
65+
return undefined
66+
}

src/mappings/utils/lookups.ts

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { Context, EnMap } from './types'
77
export async function finalizeCollections(collectionSet: Set<string>, ctx: Context): Promise<EnMap<CE>> {
88
// ctx.store.findBy(CE, {id: In([...collectionMap.keys()])})
99
const knownCollections = await findByIdListAsMap(ctx.store, CE, collectionSet)
10-
// debug('finalizeCollections' as any , { knownCollections: knownCollections.size })
1110
ctx.log.info(`[finalizeCollections] ${knownCollections.size} collections found`)
1211
// const newCollections: CE[] = []
1312

src/processable.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,6 @@ function toMap(
122122
ownerCount: 0,
123123
supply: max,
124124
volume: BigInt(0),
125-
version: 1
125+
version: 721,
126126
};
127127
}

src/processor.ts

+25-22
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
import { Store } from '@subsquid/typeorm-store'
1010
import { events as erc721 } from './abi/ERC721'
1111
import { events as registry } from './abi/Registry'
12-
import { ENV_CONTRACTS, FINALITY_CONFIRMATION, STARTING_BLOCK, disabledRPC, getArchiveUrl, getNodeUrl } from './environment'
12+
import { ENV_CONTRACTS, FINALITY_CONFIRMATION, PREINDEX_BLOCK, STARTING_BLOCK, disabledRPC, getArchiveUrl, getNodeUrl } from './environment'
1313
import { contractList } from './processable'
1414

1515
// export const CONTRACT_ADDRESS = '0x6e0bed56fb3eb7d2fecc5bb71f99e844cd3c2a0b'
@@ -33,10 +33,10 @@ export const processor = new EvmBatchProcessor()
3333
})
3434
.setRpcDataIngestionSettings({ disabled: disabledRPC })
3535
.setFinalityConfirmation(FINALITY_CONFIRMATION)
36-
.setBlockRange({
37-
from: STARTING_BLOCK
38-
// from: 2_852_779
39-
})
36+
// .setBlockRange({
37+
// from: STARTING_BLOCK
38+
// // from: 2_852_779
39+
// })
4040
.setFields({
4141
log: {
4242
topics: true,
@@ -47,30 +47,33 @@ export const processor = new EvmBatchProcessor()
4747
.addLog({
4848
address: [ENV_CONTRACTS.REGISTRY],
4949
topic0: [registry.CollectionRegistered.topic],
50-
// range: {
51-
// from: STARTING_BLOCK
52-
// }
50+
range: {
51+
from: STARTING_BLOCK
52+
}
5353
// transaction: true
5454
})
5555
.addLog({
5656
topic0: [erc721.Transfer.topic],
57-
// range: {
58-
// from: STARTING_BLOCK
59-
// }
57+
range: {
58+
from: STARTING_BLOCK
59+
}
6060
// transaction: true
6161
})
6262

63-
// contractList.forEach((contract) => {
64-
// processor.addLog({
65-
// address: [contract],
66-
// topic0: [erc721.Transfer.topic],
67-
// range: {
68-
// from: 0,
69-
// to: STARTING_BLOCK
70-
// }
71-
// // transaction: true
72-
// })
73-
// })
63+
if (PREINDEX_BLOCK) {
64+
contractList.forEach((contract) => {
65+
processor.addLog({
66+
address: [contract],
67+
topic0: [erc721.Transfer.topic],
68+
range: {
69+
from: PREINDEX_BLOCK,
70+
to: STARTING_BLOCK
71+
}
72+
// transaction: true
73+
})
74+
})
75+
}
76+
7477

7578
// .addLog({
7679
// address: [Contracts.Conjunto],

0 commit comments

Comments
 (0)