Skip to content

Commit

Permalink
update v1000
Browse files Browse the repository at this point in the history
  • Loading branch information
justraman committed Nov 29, 2023
1 parent 1f2bb31 commit 16c0294
Show file tree
Hide file tree
Showing 17 changed files with 14,193 additions and 61 deletions.
5 changes: 5 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,10 @@ type WhitelistedCallers {
value: [String!]!
}

type WhitelistedPallets {
value: [String!]!
}

type MaxFuelBurnPerTransaction {
value: BigInt!
}
Expand Down Expand Up @@ -813,6 +817,7 @@ type FuelTankRuleSet @entity {

whitelistedCallers: [String!]
whitelistedCollections: [String]
whitelistedPallets: [String!]
maxFuelBurnPerTransaction: MaxFuelBurnPerTransaction
userFuelBudget: UserFuelBudget
tankFuelBudget: TankFuelBudget
Expand Down
12 changes: 11 additions & 1 deletion src/mappings/fuelTanks/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DispatchRuleDescriptor } from '../../types/generated/matrixEnjinV603'
import { DispatchRuleDescriptor as DispatchRuleDescriptorV602 } from '../../types/generated/v602'
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 {
MaxFuelBurnPerTransaction,
UserFuelBudget,
Expand All @@ -18,7 +19,12 @@ import { UnknownVersionError } from '../../common/errors'

export function rulesToMap(
ruleId: string,
rules: DispatchRuleDescriptor[] | DispatchRuleDescriptorV602[] | DispatchRuleDescriptorV601[] | DispatchRuleDescriptorV600[]
rules:
| DispatchRuleDescriptor[]
| DispatchRuleDescriptorV602[]
| DispatchRuleDescriptorV601[]
| DispatchRuleDescriptorV600[]
| DispatchRuleDescriptorv1000[]
) {
let whitelistedCallers: string[] | undefined
let whitelistedCollections: string[] | undefined
Expand All @@ -28,6 +34,7 @@ export function rulesToMap(
let requireToken: RequireToken | undefined
let permittedCalls: string[] | undefined
let permittedExtrinsics: PermittedExtrinsics[] | undefined
let whitelistedPallets: string[] | undefined

rules.forEach((rule, index) => {
if (rule.__kind === 'WhitelistedCallers') {
Expand Down Expand Up @@ -57,6 +64,8 @@ export function rulesToMap(
extrinsicName: r.value.__kind,
})
)
} else if (rule.__kind === 'WhitelistedPallets') {
whitelistedPallets = rule.value.map((p) => p.toString())
}
})

Expand All @@ -69,6 +78,7 @@ export function rulesToMap(
requireToken,
permittedCalls,
permittedExtrinsics,
whitelistedPallets,
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/mappings/fuelTanks/events/accountRuleDataRemoved.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ function getEventData(ctx: CommonContext, event: Event) {
return data.asMatrixEnjinV603
}

if (data.isV1000) {
return data.asV1000
}

throw new UnknownVersionError(data.constructor.name)
}

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 @@ -63,6 +63,9 @@ function getCallData(ctx: CommonContext, call: Call) {
if (data.isMatrixEnjinV603) {
return data.asMatrixEnjinV603
}
if (data.isV1000) {
return data.asV1000
}

throw new UnknownVersionError(data.constructor.name)
}
Expand Down Expand Up @@ -144,6 +147,7 @@ export async function fuelTankCreated(
requireToken,
permittedCalls,
permittedExtrinsics,
whitelistedPallets,
} = rulesToMap(`${fuelTank.id}-${index}`, rules)

const ruleSetModel = new FuelTankRuleSet({
Expand All @@ -159,6 +163,7 @@ export async function fuelTankCreated(
tankFuelBudget,
requireToken,
permittedCalls,
whitelistedPallets,
})

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

if (data.isV604) {
return data.asV604
Expand Down Expand Up @@ -76,6 +79,7 @@ export async function ruleSetInserted(
requireToken,
permittedCalls,
permittedExtrinsics,
whitelistedPallets,
} = rulesToMap(ruleSetId, callData.rules)

const ruleSet = new FuelTankRuleSet({
Expand All @@ -91,6 +95,7 @@ export async function ruleSetInserted(
tankFuelBudget,
requireToken,
permittedCalls,
whitelistedPallets,
})
await ctx.store.save(ruleSet)

Expand Down
4 changes: 2 additions & 2 deletions src/mappings/multiTokens/events/claim_tokens_completed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { Sns } from '../../../common/sns'
function getEventData(ctx: CommonContext, event: Event) {
const data = new MultiTokensClaimTokensCompletedEvent(ctx, event)

if (data.isMatrixEnjinV605) {
return data.asMatrixEnjinV605
if (data.isV1000) {
return data.asV1000
}
throw new UnknownVersionError(data.constructor.name)
}
Expand Down
4 changes: 2 additions & 2 deletions src/mappings/multiTokens/events/claim_tokens_initiated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { Sns } from '../../../common/sns'
function getEventData(ctx: CommonContext, event: Event) {
const data = new MultiTokensClaimTokensInitiatedEvent(ctx, event)

if (data.isMatrixEnjinV605) {
return data.asMatrixEnjinV605
if (data.isV1000) {
return data.asV1000
}
throw new UnknownVersionError(data.constructor.name)
}
Expand Down
20 changes: 10 additions & 10 deletions src/mappings/multiTokens/events/collection_created.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ async function getCallData(ctx: CommonContext, call: Call) {
}

if (
data.isMatrixEnjinV605 &&
data.asMatrixEnjinV605.call.__kind === 'MultiTokens' &&
data.asMatrixEnjinV605.call.value.__kind === 'create_collection'
data.isV1000 &&
data.asV1000.call.__kind === 'MultiTokens' &&
data.asV1000.call.value.__kind === 'create_collection'
) {
const { descriptor } = data.asMatrixEnjinV605.call.value
const { descriptor } = data.asV1000.call.value
const { maxTokenCount, maxTokenSupply, forceSingleMint } = descriptor.policy.mint
const royalty = descriptor.policy.market?.royalty
const market = royalty ? await getMarket(ctx, royalty) : null
Expand Down Expand Up @@ -136,11 +136,11 @@ async function getCallData(ctx: CommonContext, call: Call) {
if (call.name === 'MultiTokens.force_create_ethereum_collection') {
const data = new MultiTokensForceCreateEthereumCollectionCall(ctx, call)

if (data.isMatrixEnjinV605) {
const { maxTokenCount, maxTokenSupply, forceSingleMint } = data.asMatrixEnjinV605.descriptor.policy.mint
const royalty = data.asMatrixEnjinV605.descriptor.policy.market?.royalty
if (data.isV1000) {
const { maxTokenCount, maxTokenSupply, forceSingleMint } = data.asV1000.descriptor.policy.mint
const royalty = data.asV1000.descriptor.policy.market?.royalty
const market = royalty ? await getMarket(ctx, royalty) : null
const { explicitRoyaltyCurrencies } = data.asMatrixEnjinV605.descriptor
const { explicitRoyaltyCurrencies } = data.asV1000.descriptor

return {
maxTokenCount,
Expand Down Expand Up @@ -243,15 +243,15 @@ export async function collectionCreated(
await ctx.store.save(collection)

const royaltyPromises = callData.explicitRoyaltyCurrencies
.map((currency) => {
.map((currency: any) => {
const tokenId = `${currency.collectionId.toString()}-${currency.tokenId.toString()}`
return new RoyaltyCurrency({
id: `${collection.id}-${tokenId}`,
collection,
token: new Token({ id: tokenId }),
})
})
.map((rc) => ctx.store.insert(RoyaltyCurrency, rc as any))
.map((rc: any) => ctx.store.insert(RoyaltyCurrency, rc as any))

await Promise.all(royaltyPromises)

Expand Down
66 changes: 66 additions & 0 deletions src/mappings/multiTokens/events/token_created.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,39 @@ async function getCallData(ctx: CommonContext, call: Call, event: ReturnType<typ
}
}

if (
data.isV1000 &&
data.asV1000.call.__kind === 'MultiTokens' &&
(data.asV1000.call.value.__kind === 'mint' || data.asV1000.call.value.__kind === 'force_mint')
) {
const { collectionId } = data.asV1000.call.value
const recipient = data.asV1000.call.value.recipient.value as Uint8Array
const params = data.asV1000.call.value.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.isMatrixEnjinV603 &&
data.asMatrixEnjinV603.call.__kind === 'MultiTokens' &&
Expand Down Expand Up @@ -408,6 +441,39 @@ async function getCallData(ctx: CommonContext, call: Call, event: ReturnType<typ
}
}

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')

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,
}
}
}

throw new UnknownVersionError(data.constructor.name)
}

Expand Down
9 changes: 4 additions & 5 deletions src/mappings/xcm/events/attempted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@ async function getCallData(ctx: CommonContext, call: Call) {
data = new FuelTanksDispatchAndTouchCall(ctx, call)
}
if (
data.isMatrixEnjinV605 &&
data.asMatrixEnjinV605.call.__kind === 'PolkadotXcm' &&
(data.asMatrixEnjinV605.call.value.__kind === 'teleport_assets' ||
data.asMatrixEnjinV605.call.value.__kind === 'limited_teleport_assets')
data.isV1000 &&
data.asV1000.call.__kind === 'PolkadotXcm' &&
(data.asV1000.call.value.__kind === 'teleport_assets' || data.asV1000.call.value.__kind === 'limited_teleport_assets')
) {
return data.asMatrixEnjinV605.call.value
return data.asV1000.call.value
}

if (
Expand Down
3 changes: 3 additions & 0 deletions src/model/generated/fuelTankRuleSet.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export class FuelTankRuleSet {
@Column_("text", {array: true, nullable: true})
whitelistedCollections!: (string | undefined | null)[] | undefined | null

@Column_("text", {array: true, nullable: true})
whitelistedPallets!: (string)[] | undefined | null

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

Expand Down
Loading

0 comments on commit 16c0294

Please sign in to comment.