Skip to content

Commit 9051a50

Browse files
authored
Merge pull request #32 from kodadot/feate/supply-and-count
⚡ calculate supply and count
2 parents 66e55c4 + 74f881c commit 9051a50

File tree

8 files changed

+97
-81
lines changed

8 files changed

+97
-81
lines changed

basick.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
manifestVersion: subsquid.io/v0.1
22
name: basick
3-
version: 8
3+
version: 9
44
description: 'SubSquid indexer for Base'
55
build:
66
deploy:

package-lock.json

Lines changed: 74 additions & 72 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
"@kodadot1/metasquid": "^0.3.0-rc.0",
1111
"@kodadot1/minipfs": "^0.4.3-rc.2",
1212
"@subsquid/archive-registry": "^3.3.2",
13-
"@subsquid/evm-processor": "^1.19.1",
14-
"@subsquid/graphql-server": "^4.6.0",
13+
"@subsquid/evm-processor": "^1.19.2",
14+
"@subsquid/graphql-server": "^4.7.0",
1515
"@subsquid/typeorm-migration": "^1.3.0",
1616
"@subsquid/typeorm-store": "^1.5.1",
1717
"dotenv": "^16.4.5",
@@ -22,8 +22,8 @@
2222
"typeorm": "^0.3.20"
2323
},
2424
"devDependencies": {
25-
"@subsquid/evm-typegen": "^4.1.2",
26-
"@subsquid/typeorm-codegen": "^2.0.1",
25+
"@subsquid/evm-typegen": "^4.3.0",
26+
"@subsquid/typeorm-codegen": "^2.0.2",
2727
"@types/md5": "^2.3.5",
2828
"@types/node": "^20.12.11",
2929
"typescript": "~5.4.5"

src/environment.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { lookupArchive } from '@subsquid/archive-registry'
2-
31
export type Chain = 'zksync' | 'immutable-zkevm' | 'base'
42
export type ChainEnv = 'mainnet'
53
// | 'testnet'
@@ -29,7 +27,7 @@ const nodes: Record<PossibleChain, string> = {
2927
}
3028

3129
// Setup
32-
const ARCHIVE_URL = lookupArchive(CHAIN)
30+
const ARCHIVE_URL = `https://v2.archive.subsquid.io/network/${CHAIN}`
3331
const NODE_URL = nodes[CHAIN]
3432

3533

src/mappings/erc721/burn.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ export function handleTokenBurn({ tokenId }: Transfer, context: Log): ItemStateU
2525
const final = merge(item, this.state)
2626
this.event.nft = final
2727
return final
28+
},
29+
applyFrom(collection) {
30+
// update collection
31+
collection.supply -= 1
32+
return collection
2833
}
2934
}
3035

src/mappings/erc721/mint.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ export function handleTokenCreate({ to, tokenId }: Transfer, context: Log): Item
4444
metadata: tokenUri(collection.baseUri, this.state.sn)
4545
}
4646

47+
// update collection
48+
collection.nftCount += 1;
49+
collection.supply += 1;
50+
4751
return collection
4852
}
4953
}

src/mappings/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export async function whatToDoWithTokens(
8888
const knownTokens = await findByIdListAsMap(ctx.store, NE, tokens)
8989
const events: EventEntity[] = []
9090
const metadataEntities: MetadataEntity[] = []
91+
const collectionsToSave: Set<string> = new Set()
9192

9293
for (const item of items) {
9394
if (!collections.has(item.contract)) {
@@ -101,6 +102,7 @@ export async function whatToDoWithTokens(
101102
if (item.applyFrom) {
102103
const collection = collections.get(item.contract)!
103104
item.applyFrom(collection)
105+
collectionsToSave.add(item.contract)
104106
}
105107
if (item.applyTo) {
106108
knownToken = item.applyTo(knownToken)
@@ -127,6 +129,11 @@ export async function whatToDoWithTokens(
127129
await ctx.store.upsert(values)
128130
await ctx.store.save(events)
129131

132+
if (collectionsToSave.size > 0) {
133+
const toUpsert = [...collectionsToSave.values()].map(id => collections.get(id)!)
134+
await ctx.store.save(toUpsert)
135+
}
136+
130137
if (metadataEntities.length > 0) {
131138
await ctx.store.save(metadataEntities)
132139
}

src/processable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ function toMap(
129129
highestSale: BigInt(0),
130130
nftCount: 0,
131131
ownerCount: 0,
132-
supply: max,
132+
supply: 0,
133133
volume: BigInt(0),
134134
version: 721,
135135
};

0 commit comments

Comments
 (0)