Skip to content

Commit

Permalink
Merge pull request #32 from kodadot/feate/supply-and-count
Browse files Browse the repository at this point in the history
⚡ calculate supply and count
  • Loading branch information
vikiival committed Jul 26, 2024
2 parents 66e55c4 + 74f881c commit 9051a50
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 81 deletions.
2 changes: 1 addition & 1 deletion basick.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
manifestVersion: subsquid.io/v0.1
name: basick
version: 8
version: 9
description: 'SubSquid indexer for Base'
build:
deploy:
Expand Down
146 changes: 74 additions & 72 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"@kodadot1/metasquid": "^0.3.0-rc.0",
"@kodadot1/minipfs": "^0.4.3-rc.2",
"@subsquid/archive-registry": "^3.3.2",
"@subsquid/evm-processor": "^1.19.1",
"@subsquid/graphql-server": "^4.6.0",
"@subsquid/evm-processor": "^1.19.2",
"@subsquid/graphql-server": "^4.7.0",
"@subsquid/typeorm-migration": "^1.3.0",
"@subsquid/typeorm-store": "^1.5.1",
"dotenv": "^16.4.5",
Expand All @@ -22,8 +22,8 @@
"typeorm": "^0.3.20"
},
"devDependencies": {
"@subsquid/evm-typegen": "^4.1.2",
"@subsquid/typeorm-codegen": "^2.0.1",
"@subsquid/evm-typegen": "^4.3.0",
"@subsquid/typeorm-codegen": "^2.0.2",
"@types/md5": "^2.3.5",
"@types/node": "^20.12.11",
"typescript": "~5.4.5"
Expand Down
4 changes: 1 addition & 3 deletions src/environment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { lookupArchive } from '@subsquid/archive-registry'

export type Chain = 'zksync' | 'immutable-zkevm' | 'base'
export type ChainEnv = 'mainnet'
// | 'testnet'
Expand Down Expand Up @@ -29,7 +27,7 @@ const nodes: Record<PossibleChain, string> = {
}

// Setup
const ARCHIVE_URL = lookupArchive(CHAIN)
const ARCHIVE_URL = `https://v2.archive.subsquid.io/network/${CHAIN}`
const NODE_URL = nodes[CHAIN]


Expand Down
5 changes: 5 additions & 0 deletions src/mappings/erc721/burn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ export function handleTokenBurn({ tokenId }: Transfer, context: Log): ItemStateU
const final = merge(item, this.state)
this.event.nft = final
return final
},
applyFrom(collection) {
// update collection
collection.supply -= 1
return collection
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/mappings/erc721/mint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ export function handleTokenCreate({ to, tokenId }: Transfer, context: Log): Item
metadata: tokenUri(collection.baseUri, this.state.sn)
}

// update collection
collection.nftCount += 1;
collection.supply += 1;

return collection
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/mappings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export async function whatToDoWithTokens(
const knownTokens = await findByIdListAsMap(ctx.store, NE, tokens)
const events: EventEntity[] = []
const metadataEntities: MetadataEntity[] = []
const collectionsToSave: Set<string> = new Set()

for (const item of items) {
if (!collections.has(item.contract)) {
Expand All @@ -101,6 +102,7 @@ export async function whatToDoWithTokens(
if (item.applyFrom) {
const collection = collections.get(item.contract)!
item.applyFrom(collection)
collectionsToSave.add(item.contract)
}
if (item.applyTo) {
knownToken = item.applyTo(knownToken)
Expand All @@ -127,6 +129,11 @@ export async function whatToDoWithTokens(
await ctx.store.upsert(values)
await ctx.store.save(events)

if (collectionsToSave.size > 0) {
const toUpsert = [...collectionsToSave.values()].map(id => collections.get(id)!)
await ctx.store.save(toUpsert)
}

if (metadataEntities.length > 0) {
await ctx.store.save(metadataEntities)
}
Expand Down
2 changes: 1 addition & 1 deletion src/processable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function toMap(
highestSale: BigInt(0),
nftCount: 0,
ownerCount: 0,
supply: max,
supply: 0,
volume: BigInt(0),
version: 721,
};
Expand Down

0 comments on commit 9051a50

Please sign in to comment.