Skip to content

Commit

Permalink
new efinity metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardocustodio committed May 31, 2023
1 parent ca3ded3 commit 4cda51b
Show file tree
Hide file tree
Showing 14 changed files with 22,901 additions and 8,136 deletions.
8 changes: 8 additions & 0 deletions src/mappings/claims/events/claimed_enj.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ interface EventData {
function getEventData(ctx: CommonContext, event: Event): EventData {
const data = new ClaimsClaimedEnjEvent(ctx, event)

if (data.isEfinityV3014) {
const { who, amount } = data.asEfinityV3014
return {
who,
amount,
}
}

if (data.isV500) {
const { who, amount } = data.asV500
return {
Expand Down
46 changes: 46 additions & 0 deletions src/mappings/multiTokens/events/frozen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,52 @@ interface EventData {
function getEventData(ctx: CommonContext, event: Event): EventData {
const data = new MultiTokensFrozenEvent(ctx, event)

if (data.isEfinityV3014) {
const { collectionId, freezeType } = data.asEfinityV3014

if (freezeType.__kind === 'Collection') {
return {
collectionId,
freezeType: freezeType.__kind,
freezeState: undefined,
tokenId: undefined,
collectionAccount: undefined,
tokenAccount: undefined,
}
}

if (freezeType.__kind === 'CollectionAccount') {
return {
collectionId,
freezeType: freezeType.__kind,
freezeState: undefined,
collectionAccount: (freezeType as FreezeType_CollectionAccount).value,
tokenId: undefined,
tokenAccount: undefined,
}
}

if (freezeType.__kind === 'Token') {
return {
collectionId,
freezeType: freezeType.__kind,
freezeState: freezeType.freezeState,
tokenId: freezeType.tokenId,
collectionAccount: undefined,
tokenAccount: undefined,
}
}

return {
collectionId,
freezeType: freezeType.__kind,
freezeState: undefined,
tokenId: (freezeType as FreezeType_TokenAccount).tokenId,
tokenAccount: (freezeType as FreezeType_TokenAccount).accountId,
collectionAccount: undefined,
}
}

if (data.isV500) {
const { collectionId, freezeType } = data.asV500

Expand Down
42 changes: 42 additions & 0 deletions src/mappings/multiTokens/events/thawed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,48 @@ interface EventData {
function getEventData(ctx: CommonContext, event: Event): EventData {
const data = new MultiTokensThawedEvent(ctx, event)

if (data.isEfinityV3014) {
const { collectionId, freezeType } = data.asEfinityV3014

if (freezeType.__kind === 'Collection') {
return {
collectionId,
freezeType: freezeType.__kind,
tokenId: undefined,
collectionAccount: undefined,
tokenAccount: undefined,
}
}

if (freezeType.__kind === 'CollectionAccount') {
return {
collectionId,
freezeType: freezeType.__kind,
collectionAccount: (freezeType as FreezeType_CollectionAccount).value,
tokenId: undefined,
tokenAccount: undefined,
}
}

if (freezeType.__kind === 'Token') {
return {
collectionId,
freezeType: freezeType.__kind,
tokenId: (freezeType as FreezeTypeToken_v500).tokenId,
collectionAccount: undefined,
tokenAccount: undefined,
}
}

return {
collectionId,
freezeType: freezeType.__kind,
tokenId: (freezeType as FreezeType_TokenAccount).tokenId,
tokenAccount: (freezeType as FreezeType_TokenAccount).accountId,
collectionAccount: undefined,
}
}

if (data.isV500) {
const { collectionId, freezeType } = data.asV500

Expand Down
103 changes: 103 additions & 0 deletions src/mappings/multiTokens/events/token_created.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,47 @@ async function getCallData(ctx: CommonContext, call: Call, event: EventData): Pr
if (call.name === 'EfinityUtility.batch') {
const data = new EfinityUtilityBatchCall(ctx, call)

if (data.isEfinityV3014) {
const { calls } = data.asEfinityV3014
const recipientCall = calls.find(
(r) =>
r.__kind === 'MultiTokens' &&
r.value.__kind === 'mint' &&
r.value.collectionId === event.collectionId &&
r.value.params.tokenId === event.tokenId &&
r.value.params.__kind === 'CreateToken'
)

if (recipientCall) {
const mintCall = recipientCall.value as MultiTokensCall_mint_v500
const recipient = mintCall.recipient.value as Uint8Array
const params = mintCall.params as DefaultMintParamsCreateToken_v500
const cap = params.cap ? getCapType(params.cap) : null
const behavior = params.behavior ? await getBehavior(ctx, params.behavior) : null
const freezeState = params.freezeState ? getFreezeState(params.freezeState) : null
let unitPrice: bigint | null = 10_000_000_000_000_000n
let minimumBalance = 1n

if (params.sufficiency.__kind === 'Sufficient') {
minimumBalance = (params.sufficiency as SufficiencyParam_Sufficient).minimumBalance
unitPrice = null
}

return {
recipient,
collectionId: mintCall.collectionId,
tokenId: params.tokenId,
initialSupply: params.initialSupply,
minimumBalance,
unitPrice,
cap,
behavior,
freezeState,
listingForbidden: params.listingForbidden ?? false,
}
}
}

if (data.isV602) {
const { calls } = data.asV602
const recipientCall = calls.find(
Expand Down Expand Up @@ -345,6 +386,39 @@ async function getCallData(ctx: CommonContext, call: Call, event: EventData): Pr
if (call.name === 'MultiTokens.batch_mint') {
const data = new MultiTokensBatchMintCall(ctx, call)

if (data.isEfinityV3014) {
const { collectionId, recipients } = data.asEfinityV3014
const recipientCall = recipients.find((r) => r.params.tokenId === event.tokenId && r.params.__kind === 'CreateToken')

if (recipientCall) {
const recipient = recipientCall.accountId
const params = recipientCall.params as DefaultMintParamsCreateToken_v500
const cap = params.cap ? getCapType(params.cap) : null
const behavior = params.behavior ? await getBehavior(ctx, params.behavior) : null
const freezeState = params.freezeState ? getFreezeState(params.freezeState) : null
let unitPrice: bigint | null = 10_000_000_000_000_000n
let minimumBalance = 1n

if (params.sufficiency.__kind === 'Sufficient') {
minimumBalance = (params.sufficiency as SufficiencyParam_Sufficient).minimumBalance
unitPrice = null
}

return {
recipient,
collectionId,
tokenId: params.tokenId,
initialSupply: params.initialSupply,
minimumBalance,
unitPrice,
cap,
behavior,
freezeState,
listingForbidden: params.listingForbidden ?? false,
}
}
}

if (data.isV600) {
const { collectionId, recipients } = data.asV600
const recipientCall = recipients.find((r) => r.params.tokenId === event.tokenId && r.params.__kind === 'CreateToken')
Expand Down Expand Up @@ -483,6 +557,35 @@ async function getCallData(ctx: CommonContext, call: Call, event: EventData): Pr

const data = new MultiTokensMintCall(ctx, call)

if (data.isEfinityV3014) {
const { collectionId } = data.asEfinityV3014
const recipient = data.asEfinityV3014.recipient.value as Uint8Array
const params = data.asV600.params as DefaultMintParamsCreateToken_v500
const cap = params.cap ? getCapType(params.cap) : null
const behavior = params.behavior ? await getBehavior(ctx, params.behavior) : null
const freezeState = params.freezeState ? getFreezeState(params.freezeState) : null
let unitPrice: bigint | null = 10_000_000_000_000_000n
let minimumBalance = 1n

if (params.sufficiency.__kind === 'Sufficient') {
minimumBalance = (params.sufficiency as SufficiencyParam_Sufficient).minimumBalance
unitPrice = null
}

return {
recipient,
collectionId,
tokenId: params.tokenId,
initialSupply: params.initialSupply,
minimumBalance,
unitPrice,
cap,
behavior,
freezeState,
listingForbidden: params.listingForbidden ?? false,
}
}

if (data.isV600) {
const { collectionId } = data.asV600
const recipient = data.asV600.recipient.value as Uint8Array
Expand Down
10 changes: 10 additions & 0 deletions src/mappings/multiTokens/events/token_mutated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ interface EventData {
function getEventData(ctx: CommonContext, event: Event): EventData {
const data = new MultiTokensTokenMutatedEvent(ctx, event)

if (data.isEfinityV3014) {
const { collectionId, tokenId, mutation } = data.asEfinityV3014
return {
collectionId,
tokenId,
behavior: mutation.behavior,
listingForbidden: mutation.listingForbidden,
}
}

if (data.isV500) {
const { collectionId, tokenId, mutation } = data.asV500
return {
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

0 comments on commit 4cda51b

Please sign in to comment.