Skip to content

Commit

Permalink
add spec matrix1012 (#1269)
Browse files Browse the repository at this point in the history
Add spec Matrix1012
  • Loading branch information
justraman authored Sep 11, 2024
1 parent f1bf3e3 commit b2f814f
Show file tree
Hide file tree
Showing 95 changed files with 30,074 additions and 6,376 deletions.
11 changes: 11 additions & 0 deletions db/migrations/1725967507033-Data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = class Data1725967507033 {
name = 'Data1725967507033'

async up(db) {
await db.query(`ALTER TABLE "fuel_tank_rule_set" ADD "minimum_infusion" numeric`)
}

async down(db) {
await db.query(`ALTER TABLE "fuel_tank_rule_set" DROP COLUMN "minimum_infusion"`)
}
}
1 change: 1 addition & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,7 @@ type FuelTankRuleSet @entity {
tankFuelBudget: TankFuelBudget
requireToken: RequireToken
permittedCalls: [String!]
minimumInfusion: BigInt
permittedExtrinsics: [PermittedExtrinsics] @derivedFrom(field: "ruleSet")
}

Expand Down
14 changes: 14 additions & 0 deletions src/mappings/fuelTanks/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { DispatchRuleDescriptor as DispatchRuleDescriptorv1005 } from '../../typ
import { DispatchRuleDescriptor as DispatchRuleDescriptorv1010 } from '../../types/generated/v1010'
import { DispatchRuleDescriptor as DispatchRuleDescriptorv1011 } from '../../types/generated/v1011'
import { DispatchRuleDescriptor as DispatchRuleDescriptorv1012 } from '../../types/generated/v1012'
import { DispatchRuleDescriptor as DispatchRuleDescriptorvMatrix1012 } from '../../types/generated/matrixEnjinV1012'

import {
MaxFuelBurnPerTransaction,
Expand Down Expand Up @@ -36,6 +37,7 @@ export function rulesToMap(
| DispatchRuleDescriptorv1010[]
| DispatchRuleDescriptorv1011[]
| DispatchRuleDescriptorv1012[]
| DispatchRuleDescriptorvMatrix1012[]
) {
let whitelistedCallers: string[] | undefined
let whitelistedCollections: string[] | undefined
Expand All @@ -47,6 +49,7 @@ export function rulesToMap(
let permittedExtrinsics: PermittedExtrinsics[] | undefined
let whitelistedPallets: string[] | undefined
let requireSignature: string | undefined
let minimumInfusion: bigint | undefined

rules.forEach((rule, index) => {
if (rule.__kind === 'WhitelistedCallers') {
Expand Down Expand Up @@ -80,6 +83,8 @@ export function rulesToMap(
extrinsicName: r.value.__kind,
})
)
} else if (rule.__kind === 'MinimumInfusion') {
minimumInfusion = rule.value
}
})

Expand All @@ -94,11 +99,16 @@ export function rulesToMap(
permittedCalls,
permittedExtrinsics,
requireSignature,
minimumInfusion,
}
}

export function getTankDataFromCall(ctx: CommonContext, call: CallItem) {
if (call.name === 'FuelTanks.dispatch') {
if (fuelTanks.dispatch.matrixEnjinV1012.is(call)) {
return fuelTanks.dispatch.matrixEnjinV1012.decode(call)
}

if (fuelTanks.dispatch.matrixEnjinV1005.is(call)) {
return fuelTanks.dispatch.matrixEnjinV1005.decode(call)
}
Expand Down Expand Up @@ -170,6 +180,10 @@ export function getTankDataFromCall(ctx: CommonContext, call: CallItem) {
throw new UnknownVersionError(fuelTanks.dispatch.name)
}

if (fuelTanks.dispatchAndTouch.matrixEnjinV1012.is(call)) {
return fuelTanks.dispatchAndTouch.matrixEnjinV1012.decode(call)
}

if (fuelTanks.dispatchAndTouch.matrixEnjinV1005.is(call)) {
return fuelTanks.dispatchAndTouch.matrixEnjinV1005.decode(call)
}
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 @@ -4,6 +4,10 @@ import { Event as EventModel, FuelTankRuleSet, PermittedExtrinsics } from '../..
import { CommonContext, BlockHeader, EventItem } from '../../types/contexts'

function getEventData(event: EventItem) {
if (fuelTanks.accountRuleDataRemoved.matrixEnjinV1012.is(event)) {
return fuelTanks.accountRuleDataRemoved.matrixEnjinV1012.decode(event)
}

if (fuelTanks.accountRuleDataRemoved.v1012.is(event)) {
return fuelTanks.accountRuleDataRemoved.v1010.decode(event)
}
Expand Down
10 changes: 10 additions & 0 deletions src/mappings/fuelTanks/events/fuelTankCreated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ function getEventData(event: EventItem) {

function getCallData(ctx: CommonContext, call: CallItem) {
if (call.name === 'FuelTanks.force_create_fuel_tank') {
if (calls.fuelTanks.forceCreateFuelTank.matrixEnjinV1012.is(call)) {
return calls.fuelTanks.forceCreateFuelTank.matrixEnjinV1012.decode(call)
}

if (calls.fuelTanks.forceCreateFuelTank.matrixEnjinV1005.is(call)) {
return calls.fuelTanks.forceCreateFuelTank.matrixEnjinV1005.decode(call)
}
Expand Down Expand Up @@ -84,6 +88,10 @@ function getCallData(ctx: CommonContext, call: CallItem) {
throw new UnknownVersionError(calls.fuelTanks.forceCreateFuelTank.name)
}

if (calls.fuelTanks.createFuelTank.matrixEnjinV1012.is(call)) {
return calls.fuelTanks.createFuelTank.matrixEnjinV1012.decode(call)
}

if (calls.fuelTanks.createFuelTank.matrixEnjinV1005.is(call)) {
return calls.fuelTanks.createFuelTank.matrixEnjinV1005.decode(call)
}
Expand Down Expand Up @@ -240,6 +248,7 @@ export async function fuelTankCreated(ctx: CommonContext, block: BlockHeader, it
requireToken,
permittedCalls,
permittedExtrinsics,
minimumInfusion,
} = rulesToMap(`${fuelTank.id}-${index}`, rules)

const ruleSetModel = new FuelTankRuleSet({
Expand All @@ -257,6 +266,7 @@ export async function fuelTankCreated(ctx: CommonContext, block: BlockHeader, it
tankFuelBudget,
requireToken,
permittedCalls,
minimumInfusion,
})

await ctx.store.save(ruleSetModel)
Expand Down
3 changes: 3 additions & 0 deletions src/mappings/fuelTanks/events/fuelTankMutated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import {
import { CommonContext, BlockHeader, EventItem } from '../../types/contexts'

function getEventData(event: EventItem) {
if (fuelTanks.fuelTankMutated.matrixEnjinV1012.is(event)) {
return fuelTanks.fuelTankMutated.matrixEnjinV1012.decode(event)
}
if (fuelTanks.fuelTankMutated.v1010.is(event)) {
return fuelTanks.fuelTankMutated.v1010.decode(event)
}
Expand Down
6 changes: 6 additions & 0 deletions src/mappings/fuelTanks/events/ruleSetInserted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ function getEventData(event: EventItem) {
}

function getCallData(call: CallItem) {
if (calls.fuelTanks.insertRuleSet.matrixEnjinV1012.is(call)) {
return calls.fuelTanks.insertRuleSet.matrixEnjinV1012.decode(call)
}

if (calls.fuelTanks.insertRuleSet.matrixEnjinV1005.is(call)) {
return calls.fuelTanks.insertRuleSet.matrixEnjinV1005.decode(call)
}
Expand Down Expand Up @@ -117,6 +121,7 @@ export async function ruleSetInserted(ctx: CommonContext, block: BlockHeader, it
permittedCalls,
permittedExtrinsics,
requireSignature,
minimumInfusion,
} = rulesToMap(ruleSetId, 'ruleSet' in callData ? callData.ruleSet.rules : callData.rules)

const ruleSet = new FuelTankRuleSet({
Expand All @@ -134,6 +139,7 @@ export async function ruleSetInserted(ctx: CommonContext, block: BlockHeader, it
tankFuelBudget,
requireToken,
permittedCalls,
minimumInfusion,
requireSignature,
})
await ctx.store.save(ruleSet)
Expand Down
4 changes: 4 additions & 0 deletions src/mappings/marketplace/events/counter_offer_answered.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import { Sns } from '../../../common/sns'
import { getOrCreateAccount } from '../../util/entities'

function getEventData(event: EventItem) {
if (events.marketplace.counterOfferAnswered.matrixEnjinV1012.is(event)) {
return events.marketplace.counterOfferAnswered.matrixEnjinV1012.decode(event)
}

if (events.marketplace.counterOfferAnswered.v1011.is(event)) {
return events.marketplace.counterOfferAnswered.v1011.decode(event)
}
Expand Down
4 changes: 4 additions & 0 deletions src/mappings/marketplace/events/counter_offer_placed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import { Sns } from '../../../common/sns'
import { getOrCreateAccount } from '../../util/entities'

function getEventData(event: EventItem) {
if (events.marketplace.counterOfferPlaced.matrixEnjinV1012.is(event)) {
return events.marketplace.counterOfferPlaced.matrixEnjinV1012.decode(event)
}

if (events.marketplace.counterOfferPlaced.v1010.is(event)) {
return events.marketplace.counterOfferPlaced.v1010.decode(event)
}
Expand Down
4 changes: 2 additions & 2 deletions src/mappings/marketplace/events/counter_offer_removed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import { Sns } from '../../../common/sns'
import { getOrCreateAccount } from '../../util/entities'

function getEventData(event: EventItem) {
if (events.marketplace.counterOfferRemoved.v1011.is(event)) {
return events.marketplace.counterOfferRemoved.v1011.decode(event)
if (events.marketplace.counterOfferRemoved.matrixEnjinV1012.is(event)) {
return events.marketplace.counterOfferRemoved.matrixEnjinV1012.decode(event)
}
throw new UnknownVersionError(events.marketplace.counterOfferRemoved.name)
}
Expand Down
4 changes: 4 additions & 0 deletions src/mappings/marketplace/events/listing_created.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ import { Sns } from '../../../common/sns'
import { syncCollectionStats } from '../../../jobs/collection-stats'

function getEventData(ctx: CommonContext, event: EventItem) {
if (events.marketplace.listingCreated.matrixEnjinV1012.is(event)) {
return events.marketplace.listingCreated.matrixEnjinV1012.decode(event)
}

if (events.marketplace.listingCreated.v1011.is(event)) {
return events.marketplace.listingCreated.v1011.decode(event)
}
Expand Down
4 changes: 4 additions & 0 deletions src/mappings/marketplace/events/listing_filled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import { syncCollectionStats } from '../../../jobs/collection-stats'
import { Sns } from '../../../common/sns'

function getEventData(ctx: CommonContext, event: EventItem) {
if (events.marketplace.listingFilled.matrixEnjinV1012.is(event)) {
return events.marketplace.listingFilled.matrixEnjinV1012.decode(event)
}

if (events.marketplace.listingFilled.matrixEnjinV603.is(event)) {
return events.marketplace.listingFilled.matrixEnjinV603.decode(event)
}
Expand Down
48 changes: 48 additions & 0 deletions src/mappings/multiTokens/events/collection_created.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ async function getCallData(ctx: CommonContext, call: CallItem) {
}

if (call.name === 'MultiTokens.force_create_collection') {
if (calls.multiTokens.forceCreateCollection.matrixEnjinV1012.is(call)) {
const data = calls.multiTokens.forceCreateCollection.matrixEnjinV1012.decode(call)
const { maxTokenCount, maxTokenSupply, forceCollapsingSupply: forceSingleMint } = data.descriptor.policy.mint
const royalty = data.descriptor.policy.market?.royalty
const market = royalty ? await getMarket(ctx, royalty) : null
const { explicitRoyaltyCurrencies } = data.descriptor

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

if (calls.multiTokens.forceCreateCollection.v1010.is(call)) {
const data = calls.multiTokens.forceCreateCollection.v1010.decode(call)
const { maxTokenCount, maxTokenSupply, forceCollapsingSupply: forceSingleMint } = data.descriptor.policy.mint
Expand Down Expand Up @@ -79,6 +95,22 @@ async function getCallData(ctx: CommonContext, call: CallItem) {
}

if (call.name === 'MultiTokens.create_collection') {
if (calls.multiTokens.createCollection.matrixEnjinV1012.is(call)) {
const data = calls.multiTokens.createCollection.matrixEnjinV1012.decode(call)
const { maxTokenCount, maxTokenSupply, forceCollapsingSupply: forceSingleMint } = data.descriptor.policy.mint
const royalty = data.descriptor.policy.market?.royalty
const market = royalty ? await getMarket(ctx, royalty) : null
const { explicitRoyaltyCurrencies } = data.descriptor

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

if (calls.multiTokens.createCollection.v1010.is(call)) {
const data = calls.multiTokens.createCollection.v1010.decode(call)
const { maxTokenCount, maxTokenSupply, forceCollapsingSupply: forceSingleMint } = data.descriptor.policy.mint
Expand Down Expand Up @@ -115,6 +147,22 @@ async function getCallData(ctx: CommonContext, call: CallItem) {
}

if (call.name === 'MultiTokens.force_create_ethereum_collection') {
if (calls.multiTokens.forceCreateEthereumCollection.matrixEnjinV1012.is(call)) {
const data = calls.multiTokens.forceCreateEthereumCollection.matrixEnjinV1012.decode(call)
const { maxTokenCount, maxTokenSupply, forceCollapsingSupply: forceSingleMint } = data.descriptor.policy.mint
const royalty = data.descriptor.policy.market?.royalty
const market = royalty ? await getMarket(ctx, royalty) : null
const { explicitRoyaltyCurrencies } = data.descriptor

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

if (calls.multiTokens.forceCreateEthereumCollection.v1010.is(call)) {
const data = calls.multiTokens.forceCreateEthereumCollection.v1010.decode(call)
const { maxTokenCount, maxTokenSupply, forceCollapsingSupply: forceSingleMint } = data.descriptor.policy.mint
Expand Down
4 changes: 2 additions & 2 deletions src/mappings/multiTokens/events/infused.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { CommonContext, BlockHeader, EventItem } from '../../types/contexts'
import { UnknownVersionError } from '../../../common/errors'

function getEventData(ctx: CommonContext, event: EventItem) {
if (events.multiTokens.infused.v1010.is(event)) {
return events.multiTokens.infused.v1010.decode(event)
if (events.multiTokens.infused.matrixEnjinV1012.is(event)) {
return events.multiTokens.infused.matrixEnjinV1012.decode(event)
}

throw new UnknownVersionError(events.multiTokens.infused.name)
Expand Down
Loading

0 comments on commit b2f814f

Please sign in to comment.