Skip to content

Commit

Permalink
Merge pull request #287 from kodadot/main
Browse files Browse the repository at this point in the history
🔖 Stick would deserve new release
  • Loading branch information
vikiival authored Jun 27, 2024
2 parents 2769e8e + 3de49cb commit 0cfb1cf
Show file tree
Hide file tree
Showing 23 changed files with 504 additions and 453 deletions.
11 changes: 11 additions & 0 deletions db/migrations/1719489409922-Data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = class Data1719489409922 {
name = 'Data1719489409922'

async up(db) {
await db.query(`ALTER TABLE "collection_entity" ADD "base_uri" text`)
}

async down(db) {
await db.query(`ALTER TABLE "collection_entity" DROP COLUMN "base_uri"`)
}
}
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3"

services:
db:
container_name: subsquid_db
Expand Down
672 changes: 361 additions & 311 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
},
"dependencies": {
"@kodadot1/hyperdata": "^0.0.1-rc.4",
"@kodadot1/metasquid": "^0.3.0-rc.0",
"@kodadot1/minipfs": "^0.4.3-rc.1",
"@kodadot1/metasquid": "^0.3.1-rc.0",
"@kodadot1/minipfs": "^0.4.3-rc.2",
"@subsquid/archive-registry": "3.3.2",
"@subsquid/graphql-server": "4.5.1",
"@subsquid/graphql-server": "4.6.0",
"@subsquid/ss58": "2.0.2",
"@subsquid/substrate-processor": "8.2.2",
"@subsquid/substrate-processor": "8.4.1",
"@subsquid/typeorm-migration": "1.3.0",
"@subsquid/typeorm-store": "1.3.0",
"@subsquid/typeorm-store": "1.5.1",
"dotenv": "^16.4.5",
"md5": "^2.3.0",
"nanoid": "3.3.4",
Expand All @@ -34,8 +34,8 @@
},
"devDependencies": {
"@subsquid/substrate-metadata-explorer": "3.1.2",
"@subsquid/substrate-typegen": "8.0.2",
"@subsquid/typeorm-codegen": "1.3.3",
"@subsquid/substrate-typegen": "8.1.0",
"@subsquid/typeorm-codegen": "2.0.1",
"@types/md5": "^2.3.5",
"@types/node": "18.11.18",
"@types/pg": "^8.11.4",
Expand Down
1 change: 1 addition & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# https://github.com/paritytech/polkadot-sdk/blob/b8ad0d1f565659f004165c5244acba78828d0bf7/substrate/frame/nfts/src/lib.rs#L217
type CollectionEntity @entity {
attributes: [Attribute!]
baseUri: String
blockNumber: BigInt @index
burned: Boolean!
createdAt: DateTime! @index
Expand Down
2 changes: 1 addition & 1 deletion speck.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
manifestVersion: subsquid.io/v0.1
name: speck
version: 12
version: 13
description: 'SubSquid indexer for Uniques and Assets on Statemint'
build:
deploy:
Expand Down
2 changes: 1 addition & 1 deletion squid.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
manifestVersion: subsquid.io/v0.1
name: stick
version: 11
version: 13
description: 'SubSquid indexer for Uniques and Assets on Statemine'
build:
deploy:
Expand Down
14 changes: 6 additions & 8 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 = 'kusama' | 'rococo' | 'polkadot'

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

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

// Statemint
// const DEV_ARCHIVE_URL = lookupArchive('statemint', { release: 'FireSquid' })
// const DEV_NODE_URL = 'wss://statemint-rpc.polkadot.io'

export const isProd = CHAIN !== 'rococo'

console.log(`Using ${CHAIN} chain ${isProd ? 'production' : 'development'} environment`)
console.table({
CHAIN, ARCHIVE_URL, NODE_URL, STARTING_BLOCK,
disabledRPC: false,
environment: isProd ? 'production' : 'development',
})

export const getArchiveUrl = (): string => ARCHIVE_URL
export const getNodeUrl = (): string => NODE_URL
4 changes: 2 additions & 2 deletions src/mappings/nfts/mint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { handleMetadata } from '../shared/metadata'
import { unwrap } from '../utils/extract'
import { debug, pending, success } from '../utils/logger'
import { Action, Context, createTokenId } from '../utils/types'
import { calculateCollectionOwnerCountAndDistribution, versionOf } from '../utils/helper'
import { calculateCollectionOwnerCountAndDistribution, tokenUri, versionOf } from '../utils/helper'
import { mintHandler } from '../shared/token'
import { getCreateTokenEvent } from './getters'

Expand Down Expand Up @@ -42,7 +42,7 @@ export async function handleTokenCreate(context: Context): Promise<void> {
final.blockNumber = BigInt(event.blockNumber)
final.collection = collection
final.sn = BigInt(event.sn)
final.metadata = event.metadata || collection.metadata
final.metadata = event.metadata || tokenUri(collection.baseUri, event.sn) || collection.metadata
final.price = BigInt(0)
final.burned = false
final.createdAt = event.timestamp
Expand Down
11 changes: 8 additions & 3 deletions src/mappings/nfts/setAttribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,20 @@ export async function handleAttributeSet(context: Context): Promise<void> {

if ('royalty' in final && event.trait === 'royalty') {
const value = unHex(event.value)
final.royalty = final.royalty ?? Number.parseFloat(value || '0')
final.royalty = final.royalty || Number.parseFloat(value || '0')
}

if ('baseUri' in final && event.trait === 'baseUri') {
const value = unHex(event.value)
final.baseUri = final.baseUri || value
}

if ('recipient' in final && event.trait === 'recipient') {
try {
final.recipient = final.recipient ?? addressOf(event.value as string)
final.recipient = final.recipient || addressOf(event.value as string)
} catch (error) {
console.log(error)
final.recipient = final.recipient ?? (event.value as string)
final.recipient = '' // final.recipient ?? (event.value as string)
}
}

Expand Down
18 changes: 15 additions & 3 deletions src/mappings/utils/helper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { emOf } from '@kodadot1/metasquid/entity'
import { ArchiveCallWithOptionalValue, Store } from '@kodadot1/metasquid/types'
import { ArchiveCallWithOptionalValue, Optional, Store } from '@kodadot1/metasquid/types'
import * as ss58 from '@subsquid/ss58'
import { decodeHex } from '@subsquid/substrate-processor'
import { CHAIN } from '../../environment'
Expand All @@ -11,8 +11,6 @@ const codec = CHAIN
export const UNIQUE_PREFIX = 'u' as const
export const EMPTY = '' as const

type Optional<T> = T | undefined

/**
* Check if an object is empty
* @param obj - the object to check
Expand Down Expand Up @@ -61,6 +59,20 @@ export function unHex<T>(value: T): T | string {
return isHex(value) ? decodeHex(value).toString() : value
}

/**
* create a token uri from the base uri and the token id
* @param baseUri - base uri from the collection
* @param tokenId - the token id
**/
export function tokenUri(baseUri: Optional<string>, tokenId: Optional<string>): string {
if (!baseUri || !tokenId) {
return ''
}

const uri = baseUri.endsWith('/') ? baseUri : `${baseUri}/`
return `${uri}${tokenId}`
}

/**
* @deprecated Use the unjs/ufo package
**/
Expand Down
2 changes: 1 addition & 1 deletion src/mappings/utils/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const fetchMetadata = async <T extends Content>(metadata: string): Promis
if (!metadata) {
return ensure<T>({})
}
const value = await $obtain<T>(metadata, ['rmrk', 'infura_kodadot1'], true)
const value = await $obtain<T>(metadata, ['kodadot', 'w3s'], true)
return contentFrom(value as any) as T
} catch (e) {
logger.error(`[MINIPFS] ${e}`)
Expand Down
8 changes: 4 additions & 4 deletions src/model/generated/assetEntity.model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_} from "typeorm"
import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_, StringColumn as StringColumn_, IntColumn as IntColumn_} from "@subsquid/typeorm-store"

@Entity_()
export class AssetEntity {
Expand All @@ -9,12 +9,12 @@ export class AssetEntity {
@PrimaryColumn_()
id!: string

@Column_("text", {nullable: true})
@StringColumn_({nullable: true})
name!: string | undefined | null

@Column_("text", {nullable: true})
@StringColumn_({nullable: true})
symbol!: string | undefined | null

@Column_("int4", {nullable: true})
@IntColumn_({nullable: true})
decimals!: number | undefined | null
}
4 changes: 2 additions & 2 deletions src/model/generated/cacheStatus.model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_} from "typeorm"
import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_, DateTimeColumn as DateTimeColumn_} from "@subsquid/typeorm-store"

@Entity_()
export class CacheStatus {
Expand All @@ -9,6 +9,6 @@ export class CacheStatus {
@PrimaryColumn_()
id!: string

@Column_("timestamp with time zone", {nullable: false})
@DateTimeColumn_({nullable: false})
lastBlockTimestamp!: Date
}
49 changes: 26 additions & 23 deletions src/model/generated/collectionEntity.model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_, Index as Index_, OneToMany as OneToMany_, ManyToOne as ManyToOne_} from "typeorm"
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"
import * as marshal from "./marshal"
import {Attribute} from "./_attribute"
import {CollectionEvent} from "./collectionEvent.model"
Expand All @@ -16,93 +16,96 @@ export class CollectionEntity {
@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})
attributes!: (Attribute)[] | undefined | null

@StringColumn_({nullable: true})
baseUri!: string | undefined | null

@Index_()
@Column_("numeric", {transformer: marshal.bigintTransformer, nullable: true})
@BigIntColumn_({nullable: true})
blockNumber!: bigint | undefined | null

@Column_("bool", {nullable: false})
@BooleanColumn_({nullable: false})
burned!: boolean

@Index_()
@Column_("timestamp with time zone", {nullable: false})
@DateTimeColumn_({nullable: false})
createdAt!: Date

@Column_("text", {nullable: false})
@StringColumn_({nullable: false})
currentOwner!: string

@Column_("int4", {nullable: false})
@IntColumn_({nullable: false})
distribution!: number

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

@Index_()
@Column_("numeric", {transformer: marshal.bigintTransformer, nullable: false})
@BigIntColumn_({nullable: false})
floor!: bigint

@Index_({unique: true})
@Column_("text", {nullable: false})
@StringColumn_({nullable: false})
hash!: string

@Index_()
@Column_("numeric", {transformer: marshal.bigintTransformer, nullable: false})
@BigIntColumn_({nullable: false})
highestSale!: bigint

@PrimaryColumn_()
id!: string

@Column_("text", {nullable: true})
@StringColumn_({nullable: true})
image!: string | undefined | null

@Column_("text", {nullable: false})
@StringColumn_({nullable: false})
issuer!: string

@Column_("int4", {nullable: true})
@IntColumn_({nullable: true})
max!: number | undefined | null

@Column_("text", {nullable: true})
@StringColumn_({nullable: true})
media!: string | undefined | null

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

@Column_("text", {nullable: true})
@StringColumn_({nullable: true})
metadata!: string | undefined | null

@Index_()
@Column_("text", {nullable: true})
@StringColumn_({nullable: true})
name!: string | undefined | null

@Index_()
@Column_("int4", {nullable: false})
@IntColumn_({nullable: false})
nftCount!: number

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

@Column_("int4", {nullable: false})
@IntColumn_({nullable: false})
ownerCount!: number

@Column_("text", {nullable: true})
@StringColumn_({nullable: true})
recipient!: string | undefined | null

@Column_("numeric", {transformer: marshal.floatTransformer, nullable: true})
@FloatColumn_({nullable: true})
royalty!: number | undefined | null

@Index_()
@Column_("int4", {nullable: false})
@IntColumn_({nullable: false})
supply!: number

@Index_()
@Column_("timestamp with time zone", {nullable: false})
@DateTimeColumn_({nullable: false})
updatedAt!: Date

@Column_("int4", {nullable: false})
@IntColumn_({nullable: false})
version!: number

@Index_()
@Column_("numeric", {transformer: marshal.bigintTransformer, nullable: false})
@BigIntColumn_({nullable: false})
volume!: bigint

@Column_("varchar", {length: 8, nullable: true})
Expand Down
13 changes: 6 additions & 7 deletions src/model/generated/collectionEvent.model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_, ManyToOne as ManyToOne_, Index as Index_} from "typeorm"
import * as marshal from "./marshal"
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"
import {Interaction} from "./_interaction"
import {CollectionEntity} from "./collectionEntity.model"

Expand All @@ -12,22 +11,22 @@ export class CollectionEvent {
@PrimaryColumn_()
id!: string

@Column_("numeric", {transformer: marshal.bigintTransformer, nullable: true})
@BigIntColumn_({nullable: true})
blockNumber!: bigint | undefined | null

@Column_("timestamp with time zone", {nullable: false})
@DateTimeColumn_({nullable: false})
timestamp!: Date

@Column_("text", {nullable: false})
@StringColumn_({nullable: false})
caller!: string

@Column_("text", {nullable: true})
@StringColumn_({nullable: true})
currentOwner!: string | undefined | null

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

@Column_("text", {nullable: false})
@StringColumn_({nullable: false})
meta!: string

@Index_()
Expand Down
Loading

0 comments on commit 0cfb1cf

Please sign in to comment.