Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PLA-1021 Populate Genesis Storage data #441

Merged
merged 14 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"airbnb-base",
"airbnb-typescript/base",
"plugin:@typescript-eslint/recommended",
"plugin:sonarjs/recommended",
// "plugin:sonarjs/recommended",
// "plugin:unicorn/recommended",
"plugin:prettier/recommended",
"prettier"
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ codegen:
typegen:
@npx squid-substrate-typegen typegen/typegen.json

local-up:
@docker-compose up -d --build
up:
@docker-compose up -d

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"dotenv": "^16.0.3",
"lodash": "^4.17.21",
"node-cache": "^5.1.2",
"ora": "^5.4.1",
"pg": "^8.11.0",
"pusher": "^5.1.3",
"type-graphql": "^1.2.0-rc.1"
Expand All @@ -39,8 +40,8 @@
"@subsquid/substrate-metadata-explorer": "^1.1.2",
"@subsquid/substrate-typegen": "^2.2.1",
"@subsquid/typeorm-codegen": "^0.3.3",
"@types/lodash": "^4.14.195",
"@types/bull": "^4.10.0",
"@types/lodash": "^4.14.195",
"@types/node": "^16.18.6",
"@typescript-eslint/eslint-plugin": "^5.59.7",
"@typescript-eslint/parser": "^5.59.7",
Expand Down
1 change: 1 addition & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ type Listing @entity {

# Extras
highestPrice: BigInt!
deadListing: Boolean

createdAt: DateTime!
updatedAt: DateTime!
Expand Down
4 changes: 4 additions & 0 deletions src/mappings/balances/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,7 @@ export async function save(ctx: CommonContext, block: SubstrateBlock, event: Eve

return undefined
}

export const addAccountsToSet = (accounts: string[]) => {
accounts.forEach((id) => accountsSet.add(id))
}
13 changes: 7 additions & 6 deletions src/mappings/multiTokens/events/token_created.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ import { Call, Event } from '../../../types/generated/support'
import {
DefaultMintParams_CreateToken,
MultiTokensCall_mint,
TokenCap,
TokenCap_Supply,
TokenMarketBehavior,
TokenMarketBehavior_HasRoyalty,
} from '../../../types/generated/efinityV3012'
import { TokenCap as TokenCap_v3014 } from '../../../types/generated/efinityV3014'
import { MultiTokensCall_mint as MultiTokensCall_mint_rV3012 } from '../../../types/generated/rocfinityV3012'
import {
DefaultMintParams_CreateToken as DefaultMintParamsCreateToken_v500,
Expand Down Expand Up @@ -60,20 +59,22 @@ interface EventData {
initialSupply: bigint
}

function getCapType(cap: TokenCap): TokenCapSupply | TokenCapSingleMint {
if (cap.__kind === CapType.Supply.toString()) {
export function getCapType(cap: TokenCap_v3014) {
if (cap.__kind === CapType.Supply) {
return new TokenCapSupply({
type: CapType.Supply,
supply: (cap as TokenCap_Supply).value,
supply: cap.value,
})
}

// TODO: add collapsing

return new TokenCapSingleMint({
type: CapType.SingleMint,
})
}

function getFreezeState(state: FreezeState_v500): FreezeState | null {
export function getFreezeState(state: FreezeState_v500): FreezeState | null {
switch (state.__kind) {
case 'Permanent':
return FreezeState.Permanent
Expand Down
3 changes: 3 additions & 0 deletions src/model/generated/listing.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ export class Listing {
@Column_("numeric", {transformer: marshal.bigintTransformer, nullable: false})
highestPrice!: bigint

@Column_("bool", {nullable: true})
deadListing!: boolean | undefined | null

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

Expand Down
87 changes: 31 additions & 56 deletions src/model/generated/token.model.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
import {
Entity as Entity_,
Column as Column_,
PrimaryColumn as PrimaryColumn_,
Index as Index_,
ManyToOne as ManyToOne_,
OneToMany as OneToMany_,
} from 'typeorm'
import * as marshal from './marshal'
import { FreezeState } from './_freezeState'
import { TokenCap, fromJsonTokenCap } from './_tokenCap'
import { TokenBehavior, fromJsonTokenBehavior } from './_tokenBehavior'
import { Collection } from './collection.model'
import { TokenAccount } from './tokenAccount.model'
import { Attribute } from './attribute.model'
import { Listing } from './listing.model'
import { TraitToken } from './traitToken.model'
import { Metadata } from './_metadata'
import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_, Index as Index_, ManyToOne as ManyToOne_, OneToMany as OneToMany_} from "typeorm"
import * as marshal from "./marshal"
import {FreezeState} from "./_freezeState"
import {TokenCap, fromJsonTokenCap} from "./_tokenCap"
import {TokenBehavior, fromJsonTokenBehavior} from "./_tokenBehavior"
import {Collection} from "./collection.model"
import {TokenAccount} from "./tokenAccount.model"
import {Attribute} from "./attribute.model"
import {Listing} from "./listing.model"
import {TraitToken} from "./traitToken.model"
import {Metadata} from "./_metadata"

@Entity_()
export class Token {
Expand All @@ -27,82 +20,64 @@ export class Token {
id!: string

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

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

@Column_('bool', { nullable: false })
@Column_("bool", {nullable: false})
isFrozen!: boolean

@Column_('varchar', { length: 9, nullable: true })
@Column_("varchar", {length: 9, nullable: true})
freezeState!: FreezeState | undefined | null

@Column_('jsonb', {
transformer: {
to: (obj) => (obj == null ? undefined : obj.toJSON()),
from: (obj) => (obj == null ? undefined : fromJsonTokenCap(obj)),
},
nullable: true,
})
@Column_("jsonb", {transformer: {to: obj => obj == null ? undefined : obj.toJSON(), from: obj => obj == null ? undefined : fromJsonTokenCap(obj)}, nullable: true})
cap!: TokenCap | undefined | null

@Column_('jsonb', {
transformer: {
to: (obj) => (obj == null ? undefined : obj.toJSON()),
from: (obj) => (obj == null ? undefined : fromJsonTokenBehavior(obj)),
},
nullable: true,
})
@Column_("jsonb", {transformer: {to: obj => obj == null ? undefined : obj.toJSON(), from: obj => obj == null ? undefined : fromJsonTokenBehavior(obj)}, nullable: true})
behavior!: TokenBehavior | undefined | null

@Column_('bool', { nullable: false })
@Column_("bool", {nullable: false})
listingForbidden!: boolean

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

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

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

@Column_('int4', { nullable: false })
@Column_("int4", {nullable: false})
attributeCount!: number

@Index_()
@ManyToOne_(() => Collection, { nullable: true })
@ManyToOne_(() => Collection, {nullable: true})
collection!: Collection

@OneToMany_(() => TokenAccount, (e) => e.token)
@OneToMany_(() => TokenAccount, e => e.token)
tokenAccounts!: TokenAccount[]

@OneToMany_(() => Attribute, (e) => e.token)
@OneToMany_(() => Attribute, e => e.token)
attributes!: Attribute[]

@OneToMany_(() => Listing, (e) => e.makeAssetId)
@OneToMany_(() => Listing, e => e.makeAssetId)
listings!: Listing[]

@OneToMany_(() => Listing, (e) => e.takeAssetId)
@OneToMany_(() => Listing, e => e.takeAssetId)
offers!: Listing[]

@OneToMany_(() => TraitToken, (e) => e.token)
@OneToMany_(() => TraitToken, e => e.token)
traits!: TraitToken[]

@Column_('bool', { nullable: false })
@Column_("bool", {nullable: false})
nonFungible!: boolean

@Column_('jsonb', {
transformer: {
to: (obj) => (obj == null ? undefined : obj.toJSON()),
from: (obj) => (obj == null ? undefined : new Metadata(undefined, obj)),
},
nullable: true,
})
@Column_("jsonb", {transformer: {to: obj => obj == null ? undefined : obj.toJSON(), from: obj => obj == null ? undefined : new Metadata(undefined, obj)}, nullable: true})
metadata!: Metadata | undefined | null

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