Skip to content

Commit

Permalink
Merge pull request #149 from kodadot/main
Browse files Browse the repository at this point in the history
🎉  Stick v7
  • Loading branch information
vikiival authored Nov 16, 2023
2 parents 9855f0e + aa58e8a commit c16047c
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 20 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Update Squid
run-name: Update "${{ inputs.squid }}" by @${{ github.actor }}
on:
workflow_dispatch:
inputs:
squid:
description: 'Name of the squid'
required: true
default: 'squid'
type: choice
options:
- squid
- speck

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: ${{ github.event.inputs.squid }} update
title: ${{ github.event.inputs.squid }} update
body: |
Update ${{ github.event.inputs.squid }}
base: release-${{ github.event.inputs.squid }}
branch: main
assignees: ${{ github.actor }}
19 changes: 19 additions & 0 deletions db/migrations/1700144394115-Data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = class Data1700144394115 {
name = 'Data1700144394115'

async up(db) {
await db.query(`ALTER TABLE "token_entity" DROP CONSTRAINT "FK_637db5c040f1d9f935817ae1e8a"`)
await db.query(`DROP INDEX "public"."IDX_637db5c040f1d9f935817ae1e8"`)
await db.query(`ALTER TABLE "token_entity" DROP COLUMN "cheapest_id"`)
await db.query(`ALTER TABLE "collection_entity" ADD "recipient" text`)
await db.query(`ALTER TABLE "collection_entity" ADD "royalty" numeric`)
}

async down(db) {
await db.query(`ALTER TABLE "token_entity" ADD CONSTRAINT "FK_637db5c040f1d9f935817ae1e8a" FOREIGN KEY ("cheapest_id") REFERENCES "nft_entity"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`)
await db.query(`CREATE INDEX "IDX_637db5c040f1d9f935817ae1e8" ON "token_entity" ("cheapest_id") `)
await db.query(`ALTER TABLE "token_entity" ADD "cheapest_id" character varying`)
await db.query(`ALTER TABLE "collection_entity" DROP COLUMN "recipient"`)
await db.query(`ALTER TABLE "collection_entity" DROP COLUMN "royalty"`)
}
}
2 changes: 2 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type CollectionEntity @entity {
nftCount: Int! @index
nfts: [NFTEntity!] @derivedFrom(field: "collection")
ownerCount: Int!
recipient: String
royalty: Float
supply: Int! @index
updatedAt: DateTime! @index
version: Int!
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: 6
version: 8
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: 6
version: 7
description: 'SubSquid indexer for Uniques and Assets on Statemine'
build:
deploy:
Expand Down
23 changes: 13 additions & 10 deletions src/mappings/nfts/buy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getWith } from '@kodadot1/metasquid/entity'
import { NFTEntity as NE } from '../../model'
import { getOrFail } from '@kodadot1/metasquid/entity'
import { CollectionEntity as CE, NFTEntity as NE } from '../../model'
import { createEvent } from '../shared/event'
import { unwrap } from '../utils/extract'
import { debug, pending, success } from '../utils/logger'
Expand All @@ -15,31 +15,34 @@ export async function handleTokenBuy(context: Context): Promise<void> {
debug(OPERATION, event, true)

const id = createTokenId(event.collectionId, event.sn)
const entity = await getWith(context.store, NE, id, { collection: true })
const entity = await getOrFail<NE>(context.store, NE, id)
const collection = await getOrFail<CE>(context.store, CE, event.collectionId)

const originalPrice = entity.price
const originalPrice = event.price
const originalOwner = entity.currentOwner ?? undefined

entity.price = BigInt(0)
entity.currentOwner = event.caller
entity.updatedAt = event.timestamp

if (originalPrice) {
entity.collection.volume += originalPrice
if (originalPrice > entity.collection.highestSale) {
entity.collection.highestSale = originalPrice
collection.volume += originalPrice
if (originalPrice > collection.highestSale) {
collection.highestSale = originalPrice
}
}
const { ownerCount, distribution } = await calculateCollectionOwnerCountAndDistribution(
context.store,
entity.collection.id,
collection.id,
entity.currentOwner,
originalOwner
)
entity.collection.ownerCount = ownerCount
entity.collection.distribution = distribution
collection.ownerCount = ownerCount
collection.distribution = distribution

success(OPERATION, `${id} by ${event.caller} for ${String(event.price)}`)
await context.store.save(entity)
await context.store.save(collection)
const meta = String(event.price || '')
await createEvent(entity, OPERATION, event, meta, context.store, event.currentOwner)
}
13 changes: 8 additions & 5 deletions src/mappings/nfts/list.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getWith } from '@kodadot1/metasquid/entity'
import { NFTEntity as NE } from '../../model'
import { getOrFail } from '@kodadot1/metasquid/entity'
import { CollectionEntity as CE, NFTEntity as NE } from '../../model'
import { unwrap } from '../utils/extract'
import { debug, pending, success } from '../utils/logger'
import { Action, Context, createTokenId } from '../utils/types'
Expand All @@ -15,15 +15,18 @@ export async function handleTokenList(context: Context): Promise<void> {
debug(OPERATION, event, true)

const id = createTokenId(event.collectionId, event.sn)
const entity = await getWith(context.store, NE, id, { collection: true })
const entity = await getOrFail<NE>(context.store, NE, id)
const collection = await getOrFail<CE>(context.store, CE, event.collectionId)

entity.price = event.price

if (entity.price && (entity.collection.floor === 0n || entity.price < entity.collection.floor)) {
entity.collection.floor = entity.price
if (event.price && (collection.floor === 0n || event.price < collection.floor)) {
collection.floor = event.price
}

success(OPERATION, `${id} by ${event.caller}} for ${String(event.price)}`)
await context.store.save(entity)
await context.store.save(collection)
const meta = String(event.price || '')
const interaction = event.price ? OPERATION : UNLIST
await createEvent(entity, interaction, event, meta, context.store)
Expand Down
2 changes: 2 additions & 0 deletions src/mappings/nfts/mint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export async function handleTokenCreate(context: Context): Promise<void> {
final.updatedAt = event.timestamp
final.lewd = false
final.version = versionOf(context)
final.recipient = collection.recipient
final.royalty = collection.royalty

collection.updatedAt = event.timestamp
collection.nftCount += 1
Expand Down
2 changes: 1 addition & 1 deletion src/mappings/shared/token/tokenAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class TokenAPI {
const token = createEntity(TE, tokenId, {
createdAt: nft.createdAt,
collection,
name: tokenName(nft.name),
name: tokenName(nft.name, collection.id),
count: 1,
supply: 1,
hash: md5(tokenId),
Expand Down
18 changes: 16 additions & 2 deletions src/mappings/shared/token/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import md5 from 'md5'
import { NFTEntity as NE } from '../../../model'
import { warn } from '../../utils/logger'
import { CHAIN } from '../../../environment'

export const OPERATION = 'TokenEntity' as any

Expand All @@ -19,5 +20,18 @@ export const mediaOf = (nft: NE): string | undefined => {
return nftMedia
}

export const tokenName = (nftName: string | undefined | null): string =>
typeof nftName === 'string' ? nftName?.replace(/([#_]\d+$)/g, '').trim() : ''
export const collectionsToKeepNameAsIs: Record<string, string[]> = {
statemine: [
'176', // chained - generative art
],
}

export const tokenName = (nftName: string | undefined | null, collectionId: string): string => {
if (typeof nftName !== 'string') {
return ''
}

const doNotAlter = collectionsToKeepNameAsIs[CHAIN]?.includes(collectionId)

return doNotAlter ? nftName : nftName.replace(/([#_]\d+$)/g, '')
}
6 changes: 6 additions & 0 deletions src/model/generated/collectionEntity.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ export class CollectionEntity {
@Column_("int4", {nullable: false})
ownerCount!: number

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

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

@Index_()
@Column_("int4", {nullable: false})
supply!: number
Expand Down
15 changes: 15 additions & 0 deletions src/types/statemine/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,21 @@ export class NftsNextCollectionIdIncrementedEvent {
assert(this.isV9420)
return this._chain.decodeEvent(this.event)
}

/**
* Event gets emitted when the `NextCollectionId` gets incremented.
*/
get isV1000000(): boolean {
return this._chain.getEventHash('Nfts.NextCollectionIdIncremented') === 'cd3fe8f02b8e066babd9b85bf60f6760d52be27f9e088f03bf00392c80d5fc5d'
}

/**
* Event gets emitted when the `NextCollectionId` gets incremented.
*/
get asV1000000(): {nextId: (number | undefined)} {
assert(this.isV1000000)
return this._chain.decodeEvent(this.event)
}
}

export class NftsOwnerChangedEvent {
Expand Down

0 comments on commit c16047c

Please sign in to comment.