Skip to content

Commit

Permalink
Add v1003 to all calls (#759)
Browse files Browse the repository at this point in the history
add metadata v1003
  • Loading branch information
justraman authored Dec 14, 2023
1 parent a7cf197 commit 2565448
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 2 deletions.
2 changes: 1 addition & 1 deletion schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ type Token @entity {
id: ID!

# Extrinsic defaults
tokenId: BigInt!
tokenId: BigInt! @index
supply: BigInt!
isFrozen: Boolean!
freezeState: FreezeState
Expand Down
6 changes: 6 additions & 0 deletions src/mappings/fuelTanks/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { DispatchRuleDescriptor as DispatchRuleDescriptorV602 } from '../../type
import { DispatchRuleDescriptor as DispatchRuleDescriptorV601 } from '../../types/generated/v601'
import { DispatchRuleDescriptor as DispatchRuleDescriptorV600 } from '../../types/generated/v600'
import { DispatchRuleDescriptor as DispatchRuleDescriptorv1000 } from '../../types/generated/v1000'
import { DispatchRuleDescriptor as DispatchRuleDescriptorv1003 } from '../../types/generated/v1003'
import {
MaxFuelBurnPerTransaction,
UserFuelBudget,
Expand All @@ -25,6 +26,7 @@ export function rulesToMap(
| DispatchRuleDescriptorV601[]
| DispatchRuleDescriptorV600[]
| DispatchRuleDescriptorv1000[]
| DispatchRuleDescriptorv1003[]
) {
let whitelistedCallers: string[] | undefined
let whitelistedCollections: string[] | undefined
Expand Down Expand Up @@ -98,6 +100,10 @@ export function getTankDataFromCall(ctx: CommonContext, call: Call) {
return data.asMatrixEnjinV603
}

if (data.isV1003) {
return data.asV1003
}

if (data.isV1000) {
return data.asV1000
}
Expand Down
5 changes: 5 additions & 0 deletions src/mappings/fuelTanks/events/fuelTankCreated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ function getCallData(ctx: CommonContext, call: Call) {
if (data.isMatrixEnjinV603) {
return data.asMatrixEnjinV603
}

if (data.isV1003) {
return data.asV1003
}

if (data.isV1000) {
return data.asV1000
}
Expand Down
4 changes: 4 additions & 0 deletions src/mappings/fuelTanks/events/ruleSetInserted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ function getCallData(ctx: CommonContext, call: Call) {
return data.asMatrixEnjinV603
}

if (data.isV1003) {
return data.asV1003
}

if (data.isV1000) {
return data.asV1000
}
Expand Down
20 changes: 20 additions & 0 deletions src/mappings/multiTokens/events/collection_created.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,26 @@ async function getCallData(ctx: CommonContext, call: Call) {
}
}

if (
data.isV1003 &&
data.asV1003.call.__kind === 'MultiTokens' &&
data.asV1003.call.value.__kind === 'create_collection'
) {
const { descriptor } = data.asV1003.call.value
const { maxTokenCount, maxTokenSupply, forceSingleMint } = descriptor.policy.mint
const royalty = descriptor.policy.market?.royalty
const market = royalty ? await getMarket(ctx, royalty) : null
const { explicitRoyaltyCurrencies } = descriptor

return {
maxTokenCount,
maxTokenSupply,
forceSingleMint,
market,
explicitRoyaltyCurrencies,
}
}

if (
data.isV1000 &&
data.asV1000.call.__kind === 'MultiTokens' &&
Expand Down
33 changes: 33 additions & 0 deletions src/mappings/multiTokens/events/token_created.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,39 @@ async function getCallData(ctx: CommonContext, call: Call, event: ReturnType<typ
}
}

if (data.isV1003 && data.asV1003.call.__kind === 'MultiTokens' && data.asV1003.call.value.__kind === 'batch_mint') {
const { collectionId, recipients } = data.asV1003.call.value
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_Enjin_v603
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.isV1000 && data.asV1000.call.__kind === 'MultiTokens' && data.asV1000.call.value.__kind === 'batch_mint') {
const { collectionId, recipients } = data.asV1000.call.value
const recipientCall = recipients.find((r) => r.params.tokenId === event.tokenId && r.params.__kind === 'CreateToken')
Expand Down
7 changes: 7 additions & 0 deletions src/mappings/xcm/events/attempted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ async function getCallData(ctx: CommonContext, call: Call) {
) {
return data.asMatrixEnjinV603.call.value
}
if (
data.isV1003 &&
data.asV1003.call.__kind === 'PolkadotXcm' &&
(data.asV1003.call.value.__kind === 'teleport_assets' || data.asV1003.call.value.__kind === 'limited_teleport_assets')
) {
return data.asV1003.call.value
}

if (
data.isV1000 &&
Expand Down
3 changes: 2 additions & 1 deletion src/model/generated/token.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_, ManyToOne as ManyToOne_, Index as Index_, OneToMany as OneToMany_} from "typeorm"
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"
Expand All @@ -19,6 +19,7 @@ export class Token {
@PrimaryColumn_()
id!: string

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

Expand Down

0 comments on commit 2565448

Please sign in to comment.