Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardocustodio committed Feb 21, 2025
1 parent 7268223 commit 10ad4ad
Show file tree
Hide file tree
Showing 13 changed files with 179 additions and 242 deletions.
280 changes: 132 additions & 148 deletions src/main.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/mappings/claims/events/claimed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { claims } from '../../../types/events'
import { EventItem } from '../../../contexts'
import { UnsupportedEventError } from '../../../utils/errors'
import { match } from 'ts-pattern'
import { Claimed } from './types/claimed'
import { Claimed } from './types'

export function claimed(event: EventItem): Claimed {
return match(event)
Expand Down
2 changes: 1 addition & 1 deletion src/mappings/identity/calls/provide-judgement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { UnsupportedCallError } from '../../../utils/errors'
import { calls } from '../../../types'
import { CallItem } from '../../../contexts'
import { match } from 'ts-pattern'
import { ProvideJudgement } from '../../../mappings/identity/calls/types'
import { ProvideJudgement } from './types'
import { withDispatchCheck } from '../../fuel-tanks/utils'

export const provideJudgement = withDispatchCheck((call: CallItem): ProvideJudgement => {
Expand Down
2 changes: 1 addition & 1 deletion src/mappings/identity/calls/rename-sub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { UnsupportedCallError } from '../../../utils/errors'
import { calls } from '../../../types'
import { CallItem } from '../../../contexts'
import { match } from 'ts-pattern'
import { RenameSub } from '../../../mappings/identity/calls/types'
import { RenameSub } from './types'
import { withDispatchCheck } from '../../fuel-tanks/utils'

export const renameSub = withDispatchCheck((call: CallItem): RenameSub => {
Expand Down
2 changes: 1 addition & 1 deletion src/mappings/identity/calls/set-identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { UnsupportedCallError } from '../../../utils/errors'
import { calls } from '../../../types'
import { CallItem } from '../../../contexts'
import { match } from 'ts-pattern'
import { SetIdentity } from '../../../mappings/identity/calls/types'
import { SetIdentity } from './types'
import { withDispatchCheck } from '../../fuel-tanks/utils'

export const setIdentity = withDispatchCheck((call: CallItem): SetIdentity => {
Expand Down
2 changes: 1 addition & 1 deletion src/mappings/im-online/events/some-offline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { imOnline } from '../../../types/events'
import { EventItem } from '../../../contexts'
import { UnsupportedEventError } from '../../../utils/errors'
import { match } from 'ts-pattern'
import { SomeOffline } from '../../../mappings/im-online/events/types'
import { SomeOffline } from './types'

export function someOffline(event: EventItem): SomeOffline {
return match(event)
Expand Down
2 changes: 1 addition & 1 deletion src/mappings/multi-tokens/storage/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BlockHeader } from '../../../contexts'
import { UnsupportedStorageError } from '../../../utils/errors'
import { storage } from '../../../types'
import { match } from 'ts-pattern'
import { Token } from './types/tokens'
import { Token } from './types'

export async function tokens(block: BlockHeader, collectionId: bigint, tokenId: bigint): Promise<Token | undefined> {
return match(block)
Expand Down
2 changes: 1 addition & 1 deletion src/mappings/nomination-pools/storage/bonded-pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { UnsupportedStorageError } from '../../../utils/errors'
import { BlockHeader } from '@subsquid/substrate-processor'
import { storage } from '../../../types'
import { match } from 'ts-pattern'
import { BondedPools } from '../../../mappings/nomination-pools/storage/types'
import { BondedPools } from './types'

export function bondedPools(block: BlockHeader, poolId: number): Promise<BondedPools | undefined> {
return match(block)
Expand Down
2 changes: 1 addition & 1 deletion src/mappings/nomination-pools/storage/early-bird-shares.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { UnsupportedStorageError } from '../../../utils/errors'
import { BlockHeader } from '@subsquid/substrate-processor'
import { storage } from '../../../types'
import { match } from 'ts-pattern'
import { EarlyBirdShares } from '../../../mappings/nomination-pools/storage/types'
import { EarlyBirdShares } from './types'

export function earlyBirdShares(block: BlockHeader, poolId: number): Promise<EarlyBirdShares> {
return match(block)
Expand Down
2 changes: 1 addition & 1 deletion src/mappings/staking/storage/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BlockHeader } from '../../../contexts'
import { UnsupportedStorageError } from '../../../utils/errors'
import { storage } from '../../../types'
import { match } from 'ts-pattern'
import { StakingLedger } from '../../../mappings/staking/storage/types'
import { StakingLedger } from './types'

export async function ledger(block: BlockHeader, account: string): Promise<StakingLedger | undefined> {
return match(block)
Expand Down
103 changes: 22 additions & 81 deletions src/processor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
import { SubstrateBatchProcessor } from '@subsquid/substrate-processor'
import config from './config'
import { calls, events } from './types'
import { isRelay } from './utils/tools'

const getEventNames = (eventGroup: object) => Object.values(eventGroup).map((event) => event.name)

const matrixEvents: string[] = [...getEventNames(events.claims), ...getEventNames(events.polkadotXcm)]

const relayEvents: string[] = [
...getEventNames(events.imOnline),
...getEventNames(events.nominationPools),
...getEventNames(events.stakeExchange),
...getEventNames(events.staking),
...getEventNames(events.xcmPallet),
]

const commonEvents: string[] = [
...getEventNames(events.balances),
...getEventNames(events.fuelTanks),
...getEventNames(events.identity),
...getEventNames(events.marketplace),
...getEventNames(events.multiTokens),
]

export const processor = new SubstrateBatchProcessor()
.setRpcEndpoint(config.dataSource.chain)
Expand All @@ -10,87 +31,7 @@ export const processor = new SubstrateBatchProcessor()
stack: true,
})
.addEvent({
name: [
events.multiTokens.collectionCreated.name,
events.multiTokens.collectionDestroyed.name,
events.multiTokens.collectionMutated.name,
events.multiTokens.collectionTransferred.name,
events.multiTokens.collectionAccountCreated.name,
events.multiTokens.collectionAccountDestroyed.name,
events.multiTokens.tokenCreated.name,
events.multiTokens.tokenDestroyed.name,
events.multiTokens.tokenMutated.name,
events.multiTokens.tokenAccountCreated.name,
events.multiTokens.tokenAccountDestroyed.name,
events.multiTokens.infused.name,
events.multiTokens.minted.name,
events.multiTokens.burned.name,
events.multiTokens.attributeSet.name,
events.multiTokens.attributeRemoved.name,
events.multiTokens.frozen.name,
events.multiTokens.thawed.name,
events.multiTokens.approved.name,
events.multiTokens.reserved.name,
events.multiTokens.unapproved.name,
events.multiTokens.unreserved.name,
events.multiTokens.transferred.name,
events.multiTokens.claimedCollections.name,
events.multiTokens.claimTokensInitiated.name,
events.multiTokens.claimTokensCompleted.name,
events.balances.balanceSet.name,
events.balances.burned.name,
events.balances.deposit.name,
events.balances.dustLost.name,
events.balances.endowed.name,
events.balances.frozen.name,
events.balances.locked.name,
events.balances.minted.name,
events.balances.reserveRepatriated.name,
events.balances.reserved.name,
events.balances.restored.name,
events.balances.slashed.name,
events.balances.suspended.name,
events.balances.thawed.name,
events.balances.transfer.name,
events.balances.unlocked.name,
events.balances.unreserved.name,
events.balances.withdraw.name,
events.claims.claimed.name,
events.claims.claimRequested.name,
events.claims.delayTimeForClaimSet.name,
events.claims.exchangeRateSet.name,
events.claims.claimRejected.name,
events.claims.claimMinted.name,
events.marketplace.listingCreated.name,
events.marketplace.listingCancelled.name,
events.marketplace.listingFilled.name,
events.marketplace.bidPlaced.name,
events.marketplace.auctionFinalized.name,
events.marketplace.counterOfferPlaced.name,
events.marketplace.counterOfferAnswered.name,
events.marketplace.counterOfferRemoved.name,
events.marketplace.listingRemovedUnderMinimum.name,
events.polkadotXcm.attempted.name,
events.fuelTanks.accountAdded.name,
events.fuelTanks.accountRemoved.name,
events.fuelTanks.accountRuleDataRemoved.name,
events.fuelTanks.freezeStateMutated.name,
events.fuelTanks.fuelTankCreated.name,
events.fuelTanks.fuelTankDestroyed.name,
events.fuelTanks.fuelTankMutated.name,
events.fuelTanks.ruleSetInserted.name,
events.fuelTanks.ruleSetRemoved.name,
events.identity.identityCleared.name,
events.identity.identityKilled.name,
events.identity.identitySet.name,
events.identity.judgementGiven.name,
events.identity.judgementRequested.name,
events.identity.judgementUnrequested.name,
events.identity.registrarAdded.name,
events.identity.subIdentityAdded.name,
events.identity.subIdentityRemoved.name,
events.identity.subIdentityRevoked.name,
],
name: [...commonEvents, ...(isRelay() ? relayEvents : matrixEvents)],
extrinsic: true,
stack: true,
call: true,
Expand Down
14 changes: 11 additions & 3 deletions src/processors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,24 @@ import { marketplace } from './marketplace'
import { xcmPallet } from './xcm-pallet'
import { polkadotXcm } from './polkadot-xcm'
import { fuelTanks } from './fuel-tanks'
import { imOnline } from './im-online'
import { nominationPools } from './nomination-pools'
import { stakeExchange } from './stake-exchange'
import { staking } from './staking'

export const processors = {
balances,
claims,
fuelTanks,
identity,
multiTokens,
imOnline,
marketplace,
xcmPallet,
multiTokens,
nominationPools,
polkadotXcm,
fuelTanks,
stakeExchange,
staking,
xcmPallet,
}

export default processors
6 changes: 5 additions & 1 deletion src/utils/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { hexToU8a, isHex, stringToHex } from '@polkadot/util'
import config from '../config'

export function isMainnet(): boolean {
return config.chainName === 'enjin-matrix'
return ['enjin-relay', 'enjin-matrix'].includes(config.chainName)
}

export function isRelay(): boolean {
return ['enjin-relay', 'canary-relay'].includes(config.chainName)
}

export function isValidAddress(address: string): boolean {
Expand Down

0 comments on commit 10ad4ad

Please sign in to comment.