Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: IDXR-9 upgrade to Arrowsquid #991

Merged
merged 27 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
process: migrate
@NODE_OPTIONS="--max-old-space-size=16384" node -r dotenv/config lib/processor.js
@NODE_OPTIONS="--max-old-space-size=16384" node -r dotenv/config lib/main.js

build:
@npm run build
Expand Down
15 changes: 15 additions & 0 deletions db/migrations/1713777606632-Data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = class Data1713777606632 {
name = 'Data1713777606632'

async up(db) {
await db.query(`ALTER TABLE "claim_request" ADD "acount_type" character varying(9) NOT NULL`)
await db.query(`ALTER TABLE "claim_request" DROP COLUMN "account"`)
await db.query(`ALTER TABLE "claim_request" ADD "account" text NOT NULL`)
}

async down(db) {
await db.query(`ALTER TABLE "claim_request" DROP COLUMN "acount_type"`)
await db.query(`ALTER TABLE "claim_request" ADD "account" jsonb NOT NULL`)
await db.query(`ALTER TABLE "claim_request" DROP COLUMN "account"`)
}
}
740 changes: 355 additions & 385 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"build": "rm -rf lib && tsc",
"db:migrate": "npx squid-typeorm-migration apply",
"processor:start": "node -r dotenv/config lib/processor.js",
"processor:start": "node -r dotenv/config lib/main.js",
"query-node:start": "squid-graphql-server --subscriptions",
"prom:start": "node -r dotenv/config lib/prom-metrics/index.js",
"worker:start": "node -r dotenv/config lib/job-handlers/worker.js",
Expand All @@ -28,10 +28,10 @@
"@subsquid/archive-registry": "^3.3.0",
"@subsquid/cli": "^2.9.3",
"@subsquid/graphql-server": "^4.5.1",
"@subsquid/ss58": "^1.2.0",
"@subsquid/substrate-processor": "^2.4.1",
"@subsquid/ss58": "^2.0.2",
"@subsquid/substrate-processor": "^8.2.2",
"@subsquid/typeorm-migration": "^1.3.0",
"@subsquid/typeorm-store": "^0.2.1",
"@subsquid/typeorm-store": "^1.3.0",
"axios": "^1.6.8",
"bull": "^4.12.2",
"cacheable-request": "^8.3.1",
Expand All @@ -49,8 +49,8 @@
"devDependencies": {
"@polkadot/typegen": "^10.12.4",
"@subsquid/substrate-metadata-explorer": "^3.1.2",
"@subsquid/substrate-typegen": "^2.2.1",
"@subsquid/typeorm-codegen": "^1.3.2",
"@subsquid/substrate-typegen": "^8.0.2",
"@subsquid/typeorm-codegen": "^1.3.3",
"@types/lodash": "^4.17.0",
"@types/mime-types": "^2.1.4",
"@types/node": "^20.11.16",
Expand All @@ -65,8 +65,8 @@
"typescript": "^5.3.3"
},
"peerDependencies": {
"@subsquid/typeorm-config": "^2.0.2",
"@subsquid/util-internal-hex": "^0.0.1",
"@subsquid/typeorm-config": "4.1.0",
"@subsquid/util-internal-hex": "1.2.2",
"reflect-metadata": "^0.1.13",
"typeorm": "^0.3.11"
}
Expand Down
11 changes: 4 additions & 7 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,9 @@ type MultiTokensUnapproved {
operator: Account!
}

type ClaimAccount {
type: AccountClaimType!
account: String!
}

type ClaimsClaimRequested {
who: ClaimAccount!
who: String!,
accountType: AccountClaimType!
hash: String
amountClaimable: BigInt!
amountBurned: BigInt!
Expand Down Expand Up @@ -789,7 +785,8 @@ enum AccountClaimType {
type ClaimRequest @entity {
id: ID!

account: ClaimAccount!
account: String!
acountType: AccountClaimType!
hash: String @unique
amountClaimable: BigInt!
amountBurned: BigInt!
Expand Down
8 changes: 4 additions & 4 deletions src/chainState.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { SubstrateBlock } from '@subsquid/substrate-processor'
import { BlockHeader } from '@subsquid/substrate-processor'
import * as Sentry from '@sentry/node'
import { ChainInfo, Marketplace } from './model'
import config from './config'
import { CommonContext } from './mappings/types/contexts'
import Rpc from './common/rpc'

export async function chainState(ctx: CommonContext, block: SubstrateBlock) {
export async function chainState(ctx: CommonContext, block: BlockHeader<{ block: { timestamp: true } }>) {
try {
const { api } = await Rpc.getInstance()

Expand All @@ -14,11 +14,11 @@ export async function chainState(ctx: CommonContext, block: SubstrateBlock) {

state.genesisHash = config.genesisHash
state.transactionVersion = runtime.transactionVersion.toNumber()
state.specVersion = Number(block.specId.split('@')[1])
state.specVersion = Number(block.specVersion)
state.blockNumber = block.height
state.blockHash = block.hash
state.existentialDeposit = BigInt(api.consts.balances.existentialDeposit.toString())
state.timestamp = new Date(block.timestamp)
state.timestamp = new Date(block.timestamp ?? 0)
state.marketplace = new Marketplace({
protocolFee: 25_000000,
listingActiveDelay: Number(api.consts.marketplace.listingActiveDelay.toString()),
Expand Down
2 changes: 1 addition & 1 deletion src/common/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function isValidAddress(address: any) {
}
}

export function encodeId(id: Uint8Array) {
export function encodeId(id: Uint8Array | string) {
return ss58.codec(config.prefix).encode(id)
}

Expand Down
3 changes: 0 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ const config: ProcessorConfig = {
archive: process.env.ARCHIVE_ENDPOINT || 'https://matrixchain.archive.subsquid.io/graphql',
chain: process.env.CHAIN_ENDPOINT || 'wss://archive.matrix.blockchain.enjin.io',
},
blockRange: {
from: 0,
},
redisHost: process.env.REDIS_HOST || 'indexer_redis',
redisDb: process.env.REDIS_DB ? parseInt(process.env.REDIS_DB, 10) : 0,
redisSupportsTls: Boolean(process.env.REDIS_SUPPORTS_TLS || false),
Expand Down
10 changes: 10 additions & 0 deletions src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,13 @@ const cfg: any = createOrmConfig()
const con = new DataSource({ ...cfg, poolSize: 200, pool: { max: 100 } })

export default con

export const getConnection = async () => {
if (!con.isInitialized) {
await con.initialize().catch((err) => {
throw err
})
}

return con
}
12 changes: 6 additions & 6 deletions src/createEnjToken.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { SubstrateBlock } from '@subsquid/substrate-processor'
import { BlockHeader } from '@subsquid/substrate-processor'
import { CommonContext } from './mappings/types/contexts'
import { getOrCreateAccount } from './mappings/util/entities'
import { Collection, CollectionFlags, CollectionSocials, CollectionStats, MintPolicy, Token, TransferPolicy } from './model'
import { isMainnet } from './common/tools'

export async function createEnjToken(ctx: CommonContext, block: SubstrateBlock) {
export async function createEnjToken(ctx: CommonContext, block: BlockHeader<{ block: { timestamp: true } }>) {
const enj = await ctx.store.findOneBy(Token, { id: '0-0' })

if (!enj) {
Expand Down Expand Up @@ -48,10 +48,10 @@ export async function createEnjToken(ctx: CommonContext, block: SubstrateBlock)
attributePolicy: null,
attributeCount: 0,
totalDeposit: 0n,
createdAt: new Date(block.timestamp),
createdAt: new Date(block.timestamp ?? 0),
})

await ctx.store.insert(Collection, collection as any)
await ctx.store.insert(collection)

const token = new Token({
id: `0-0`,
Expand All @@ -66,9 +66,9 @@ export async function createEnjToken(ctx: CommonContext, block: SubstrateBlock)
attributeCount: 0,
collection,
nonFungible: false,
createdAt: new Date(block.timestamp),
createdAt: new Date(block.timestamp ?? 0),
})

await ctx.store.insert(Token, token as any)
await ctx.store.insert(token)
}
}
Loading