Skip to content

Commit 0cfb1cf

Browse files
authoredJun 27, 2024
Merge pull request #287 from kodadot/main
🔖 Stick would deserve new release
2 parents 2769e8e + 3de49cb commit 0cfb1cf

23 files changed

+504
-453
lines changed
 

‎db/migrations/1719489409922-Data.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = class Data1719489409922 {
2+
name = 'Data1719489409922'
3+
4+
async up(db) {
5+
await db.query(`ALTER TABLE "collection_entity" ADD "base_uri" text`)
6+
}
7+
8+
async down(db) {
9+
await db.query(`ALTER TABLE "collection_entity" DROP COLUMN "base_uri"`)
10+
}
11+
}

‎docker-compose.yml

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: "3"
2-
31
services:
42
db:
53
container_name: subsquid_db

‎package-lock.json

+361-311
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
},
1818
"dependencies": {
1919
"@kodadot1/hyperdata": "^0.0.1-rc.4",
20-
"@kodadot1/metasquid": "^0.3.0-rc.0",
21-
"@kodadot1/minipfs": "^0.4.3-rc.1",
20+
"@kodadot1/metasquid": "^0.3.1-rc.0",
21+
"@kodadot1/minipfs": "^0.4.3-rc.2",
2222
"@subsquid/archive-registry": "3.3.2",
23-
"@subsquid/graphql-server": "4.5.1",
23+
"@subsquid/graphql-server": "4.6.0",
2424
"@subsquid/ss58": "2.0.2",
25-
"@subsquid/substrate-processor": "8.2.2",
25+
"@subsquid/substrate-processor": "8.4.1",
2626
"@subsquid/typeorm-migration": "1.3.0",
27-
"@subsquid/typeorm-store": "1.3.0",
27+
"@subsquid/typeorm-store": "1.5.1",
2828
"dotenv": "^16.4.5",
2929
"md5": "^2.3.0",
3030
"nanoid": "3.3.4",
@@ -34,8 +34,8 @@
3434
},
3535
"devDependencies": {
3636
"@subsquid/substrate-metadata-explorer": "3.1.2",
37-
"@subsquid/substrate-typegen": "8.0.2",
38-
"@subsquid/typeorm-codegen": "1.3.3",
37+
"@subsquid/substrate-typegen": "8.1.0",
38+
"@subsquid/typeorm-codegen": "2.0.1",
3939
"@types/md5": "^2.3.5",
4040
"@types/node": "18.11.18",
4141
"@types/pg": "^8.11.4",

‎schema.graphql

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# https://github.com/paritytech/polkadot-sdk/blob/b8ad0d1f565659f004165c5244acba78828d0bf7/substrate/frame/nfts/src/lib.rs#L217
44
type CollectionEntity @entity {
55
attributes: [Attribute!]
6+
baseUri: String
67
blockNumber: BigInt @index
78
burned: Boolean!
89
createdAt: DateTime! @index

‎speck.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
manifestVersion: subsquid.io/v0.1
22
name: speck
3-
version: 12
3+
version: 13
44
description: 'SubSquid indexer for Uniques and Assets on Statemint'
55
build:
66
deploy:

‎squid.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
manifestVersion: subsquid.io/v0.1
22
name: stick
3-
version: 11
3+
version: 13
44
description: 'SubSquid indexer for Uniques and Assets on Statemine'
55
build:
66
deploy:

‎src/environment.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { lookupArchive } from '@subsquid/archive-registry'
2-
31
export type Chain = 'kusama' | 'rococo' | 'polkadot'
42

53
export const CHAIN: Chain = process.env.CHAIN as Chain || 'kusama'
@@ -9,16 +7,16 @@ const UNIQUE_STARTING_BLOCK = 323_750 // 618838;
97
export const STARTING_BLOCK = UNIQUE_STARTING_BLOCK
108

119
// Asset Hub
12-
const ARCHIVE_URL = lookupArchive(`asset-hub-${CHAIN}`, { release: 'ArrowSquid' })
10+
const ARCHIVE_URL = `https://v2.archive.subsquid.io/network/asset-hub-${CHAIN}`
1311
const NODE_URL = `wss://${CHAIN}-asset-hub-rpc.polkadot.io`
1412

15-
// Statemint
16-
// const DEV_ARCHIVE_URL = lookupArchive('statemint', { release: 'FireSquid' })
17-
// const DEV_NODE_URL = 'wss://statemint-rpc.polkadot.io'
18-
1913
export const isProd = CHAIN !== 'rococo'
2014

21-
console.log(`Using ${CHAIN} chain ${isProd ? 'production' : 'development'} environment`)
15+
console.table({
16+
CHAIN, ARCHIVE_URL, NODE_URL, STARTING_BLOCK,
17+
disabledRPC: false,
18+
environment: isProd ? 'production' : 'development',
19+
})
2220

2321
export const getArchiveUrl = (): string => ARCHIVE_URL
2422
export const getNodeUrl = (): string => NODE_URL

‎src/mappings/nfts/mint.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { handleMetadata } from '../shared/metadata'
77
import { unwrap } from '../utils/extract'
88
import { debug, pending, success } from '../utils/logger'
99
import { Action, Context, createTokenId } from '../utils/types'
10-
import { calculateCollectionOwnerCountAndDistribution, versionOf } from '../utils/helper'
10+
import { calculateCollectionOwnerCountAndDistribution, tokenUri, versionOf } from '../utils/helper'
1111
import { mintHandler } from '../shared/token'
1212
import { getCreateTokenEvent } from './getters'
1313

@@ -42,7 +42,7 @@ export async function handleTokenCreate(context: Context): Promise<void> {
4242
final.blockNumber = BigInt(event.blockNumber)
4343
final.collection = collection
4444
final.sn = BigInt(event.sn)
45-
final.metadata = event.metadata || collection.metadata
45+
final.metadata = event.metadata || tokenUri(collection.baseUri, event.sn) || collection.metadata
4646
final.price = BigInt(0)
4747
final.burned = false
4848
final.createdAt = event.timestamp

‎src/mappings/nfts/setAttribute.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,20 @@ export async function handleAttributeSet(context: Context): Promise<void> {
2525

2626
if ('royalty' in final && event.trait === 'royalty') {
2727
const value = unHex(event.value)
28-
final.royalty = final.royalty ?? Number.parseFloat(value || '0')
28+
final.royalty = final.royalty || Number.parseFloat(value || '0')
29+
}
30+
31+
if ('baseUri' in final && event.trait === 'baseUri') {
32+
const value = unHex(event.value)
33+
final.baseUri = final.baseUri || value
2934
}
3035

3136
if ('recipient' in final && event.trait === 'recipient') {
3237
try {
33-
final.recipient = final.recipient ?? addressOf(event.value as string)
38+
final.recipient = final.recipient || addressOf(event.value as string)
3439
} catch (error) {
3540
console.log(error)
36-
final.recipient = final.recipient ?? (event.value as string)
41+
final.recipient = '' // final.recipient ?? (event.value as string)
3742
}
3843
}
3944

‎src/mappings/utils/helper.ts

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { emOf } from '@kodadot1/metasquid/entity'
2-
import { ArchiveCallWithOptionalValue, Store } from '@kodadot1/metasquid/types'
2+
import { ArchiveCallWithOptionalValue, Optional, Store } from '@kodadot1/metasquid/types'
33
import * as ss58 from '@subsquid/ss58'
44
import { decodeHex } from '@subsquid/substrate-processor'
55
import { CHAIN } from '../../environment'
@@ -11,8 +11,6 @@ const codec = CHAIN
1111
export const UNIQUE_PREFIX = 'u' as const
1212
export const EMPTY = '' as const
1313

14-
type Optional<T> = T | undefined
15-
1614
/**
1715
* Check if an object is empty
1816
* @param obj - the object to check
@@ -61,6 +59,20 @@ export function unHex<T>(value: T): T | string {
6159
return isHex(value) ? decodeHex(value).toString() : value
6260
}
6361

62+
/**
63+
* create a token uri from the base uri and the token id
64+
* @param baseUri - base uri from the collection
65+
* @param tokenId - the token id
66+
**/
67+
export function tokenUri(baseUri: Optional<string>, tokenId: Optional<string>): string {
68+
if (!baseUri || !tokenId) {
69+
return ''
70+
}
71+
72+
const uri = baseUri.endsWith('/') ? baseUri : `${baseUri}/`
73+
return `${uri}${tokenId}`
74+
}
75+
6476
/**
6577
* @deprecated Use the unjs/ufo package
6678
**/

‎src/mappings/utils/metadata.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const fetchMetadata = async <T extends Content>(metadata: string): Promis
1616
if (!metadata) {
1717
return ensure<T>({})
1818
}
19-
const value = await $obtain<T>(metadata, ['rmrk', 'infura_kodadot1'], true)
19+
const value = await $obtain<T>(metadata, ['kodadot', 'w3s'], true)
2020
return contentFrom(value as any) as T
2121
} catch (e) {
2222
logger.error(`[MINIPFS] ${e}`)
+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_} from "typeorm"
1+
import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_, StringColumn as StringColumn_, IntColumn as IntColumn_} from "@subsquid/typeorm-store"
22

33
@Entity_()
44
export class AssetEntity {
@@ -9,12 +9,12 @@ export class AssetEntity {
99
@PrimaryColumn_()
1010
id!: string
1111

12-
@Column_("text", {nullable: true})
12+
@StringColumn_({nullable: true})
1313
name!: string | undefined | null
1414

15-
@Column_("text", {nullable: true})
15+
@StringColumn_({nullable: true})
1616
symbol!: string | undefined | null
1717

18-
@Column_("int4", {nullable: true})
18+
@IntColumn_({nullable: true})
1919
decimals!: number | undefined | null
2020
}

‎src/model/generated/cacheStatus.model.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_} from "typeorm"
1+
import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_, DateTimeColumn as DateTimeColumn_} from "@subsquid/typeorm-store"
22

33
@Entity_()
44
export class CacheStatus {
@@ -9,6 +9,6 @@ export class CacheStatus {
99
@PrimaryColumn_()
1010
id!: string
1111

12-
@Column_("timestamp with time zone", {nullable: false})
12+
@DateTimeColumn_({nullable: false})
1313
lastBlockTimestamp!: Date
1414
}

‎src/model/generated/collectionEntity.model.ts

+26-23
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_, Index as Index_, OneToMany as OneToMany_, ManyToOne as ManyToOne_} from "typeorm"
1+
import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_, StringColumn as StringColumn_, BigIntColumn as BigIntColumn_, Index as Index_, BooleanColumn as BooleanColumn_, DateTimeColumn as DateTimeColumn_, IntColumn as IntColumn_, OneToMany as OneToMany_, ManyToOne as ManyToOne_, FloatColumn as FloatColumn_} from "@subsquid/typeorm-store"
22
import * as marshal from "./marshal"
33
import {Attribute} from "./_attribute"
44
import {CollectionEvent} from "./collectionEvent.model"
@@ -16,93 +16,96 @@ export class CollectionEntity {
1616
@Column_("jsonb", {transformer: {to: obj => obj == null ? undefined : obj.map((val: any) => val.toJSON()), from: obj => obj == null ? undefined : marshal.fromList(obj, val => new Attribute(undefined, marshal.nonNull(val)))}, nullable: true})
1717
attributes!: (Attribute)[] | undefined | null
1818

19+
@StringColumn_({nullable: true})
20+
baseUri!: string | undefined | null
21+
1922
@Index_()
20-
@Column_("numeric", {transformer: marshal.bigintTransformer, nullable: true})
23+
@BigIntColumn_({nullable: true})
2124
blockNumber!: bigint | undefined | null
2225

23-
@Column_("bool", {nullable: false})
26+
@BooleanColumn_({nullable: false})
2427
burned!: boolean
2528

2629
@Index_()
27-
@Column_("timestamp with time zone", {nullable: false})
30+
@DateTimeColumn_({nullable: false})
2831
createdAt!: Date
2932

30-
@Column_("text", {nullable: false})
33+
@StringColumn_({nullable: false})
3134
currentOwner!: string
3235

33-
@Column_("int4", {nullable: false})
36+
@IntColumn_({nullable: false})
3437
distribution!: number
3538

3639
@OneToMany_(() => CollectionEvent, e => e.collection)
3740
events!: CollectionEvent[]
3841

3942
@Index_()
40-
@Column_("numeric", {transformer: marshal.bigintTransformer, nullable: false})
43+
@BigIntColumn_({nullable: false})
4144
floor!: bigint
4245

4346
@Index_({unique: true})
44-
@Column_("text", {nullable: false})
47+
@StringColumn_({nullable: false})
4548
hash!: string
4649

4750
@Index_()
48-
@Column_("numeric", {transformer: marshal.bigintTransformer, nullable: false})
51+
@BigIntColumn_({nullable: false})
4952
highestSale!: bigint
5053

5154
@PrimaryColumn_()
5255
id!: string
5356

54-
@Column_("text", {nullable: true})
57+
@StringColumn_({nullable: true})
5558
image!: string | undefined | null
5659

57-
@Column_("text", {nullable: false})
60+
@StringColumn_({nullable: false})
5861
issuer!: string
5962

60-
@Column_("int4", {nullable: true})
63+
@IntColumn_({nullable: true})
6164
max!: number | undefined | null
6265

63-
@Column_("text", {nullable: true})
66+
@StringColumn_({nullable: true})
6467
media!: string | undefined | null
6568

6669
@Index_()
6770
@ManyToOne_(() => MetadataEntity, {nullable: true})
6871
meta!: MetadataEntity | undefined | null
6972

70-
@Column_("text", {nullable: true})
73+
@StringColumn_({nullable: true})
7174
metadata!: string | undefined | null
7275

7376
@Index_()
74-
@Column_("text", {nullable: true})
77+
@StringColumn_({nullable: true})
7578
name!: string | undefined | null
7679

7780
@Index_()
78-
@Column_("int4", {nullable: false})
81+
@IntColumn_({nullable: false})
7982
nftCount!: number
8083

8184
@OneToMany_(() => NFTEntity, e => e.collection)
8285
nfts!: NFTEntity[]
8386

84-
@Column_("int4", {nullable: false})
87+
@IntColumn_({nullable: false})
8588
ownerCount!: number
8689

87-
@Column_("text", {nullable: true})
90+
@StringColumn_({nullable: true})
8891
recipient!: string | undefined | null
8992

90-
@Column_("numeric", {transformer: marshal.floatTransformer, nullable: true})
93+
@FloatColumn_({nullable: true})
9194
royalty!: number | undefined | null
9295

9396
@Index_()
94-
@Column_("int4", {nullable: false})
97+
@IntColumn_({nullable: false})
9598
supply!: number
9699

97100
@Index_()
98-
@Column_("timestamp with time zone", {nullable: false})
101+
@DateTimeColumn_({nullable: false})
99102
updatedAt!: Date
100103

101-
@Column_("int4", {nullable: false})
104+
@IntColumn_({nullable: false})
102105
version!: number
103106

104107
@Index_()
105-
@Column_("numeric", {transformer: marshal.bigintTransformer, nullable: false})
108+
@BigIntColumn_({nullable: false})
106109
volume!: bigint
107110

108111
@Column_("varchar", {length: 8, nullable: true})

‎src/model/generated/collectionEvent.model.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_, ManyToOne as ManyToOne_, Index as Index_} from "typeorm"
2-
import * as marshal from "./marshal"
1+
import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_, BigIntColumn as BigIntColumn_, DateTimeColumn as DateTimeColumn_, StringColumn as StringColumn_, ManyToOne as ManyToOne_, Index as Index_} from "@subsquid/typeorm-store"
32
import {Interaction} from "./_interaction"
43
import {CollectionEntity} from "./collectionEntity.model"
54

@@ -12,22 +11,22 @@ export class CollectionEvent {
1211
@PrimaryColumn_()
1312
id!: string
1413

15-
@Column_("numeric", {transformer: marshal.bigintTransformer, nullable: true})
14+
@BigIntColumn_({nullable: true})
1615
blockNumber!: bigint | undefined | null
1716

18-
@Column_("timestamp with time zone", {nullable: false})
17+
@DateTimeColumn_({nullable: false})
1918
timestamp!: Date
2019

21-
@Column_("text", {nullable: false})
20+
@StringColumn_({nullable: false})
2221
caller!: string
2322

24-
@Column_("text", {nullable: true})
23+
@StringColumn_({nullable: true})
2524
currentOwner!: string | undefined | null
2625

2726
@Column_("varchar", {length: 12, nullable: false})
2827
interaction!: Interaction
2928

30-
@Column_("text", {nullable: false})
29+
@StringColumn_({nullable: false})
3130
meta!: string
3231

3332
@Index_()

0 commit comments

Comments
 (0)
Please sign in to comment.