Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Feat/142 collection stats #170

Merged
merged 11 commits into from
Apr 24, 2023
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@

.DS_Store
dump_*.sql

.env
vikiival marked this conversation as resolved.
Show resolved Hide resolved
13 changes: 13 additions & 0 deletions db/migrations/1681318561000-Data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = class Data1681318561000 {
name = 'Data1681318561000'

async up(db) {
await db.query(`ALTER TABLE "collection_entity" ADD "volume" numeric`)
await db.query(`ALTER TABLE "collection_entity" ADD "highest_sale_price" numeric`)
}

async down(db) {
await db.query(`ALTER TABLE "collection_entity" DROP COLUMN "volume"`)
await db.query(`ALTER TABLE "collection_entity" DROP COLUMN "highest_sale_price"`)
}
}
2 changes: 2 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type CollectionEntity @entity {
nftCount: Int!
supply: Int!
type: CollectionType!
volume: BigInt!
highestSalePrice: BigInt!
}

type NFTEntity @entity {
Expand Down
6 changes: 6 additions & 0 deletions src/mappings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ export async function handleCollectionCreate(context: Context): Promise<void> {
final.nftCount = 0;
final.supply = 0;
final.type = type;
final.volume = BigInt(0);
final.highestSalePrice = BigInt(0);

logger.debug(`metadata: ${final.metadata}`);

Expand Down Expand Up @@ -248,6 +250,10 @@ export async function handleTokenBuy(context: Context): Promise<void> {

const collection = ensure<CE>(await get<CE>(context.store, CE, event.collectionId));
plsBe(real, collection);
collection.volume++;
alko89 marked this conversation as resolved.
Show resolved Hide resolved
if (event.price && collection.highestSalePrice < event.price) {
collection.highestSalePrice = event.price;
}
collection.updatedAt = event.timestamp;

logger.success(`[BUY] ${id} by ${event.caller}`);
Expand Down
6 changes: 6 additions & 0 deletions src/model/generated/collectionEntity.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,10 @@ export class CollectionEntity {

@Column_("varchar", {length: 15, nullable: false})
type!: CollectionType

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

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