Skip to content

Commit

Permalink
feat: WAPI-1197 MultiToken migration (#717)
Browse files Browse the repository at this point in the history
  • Loading branch information
justraman authored Nov 29, 2023
1 parent 28d72e9 commit 6560b07
Show file tree
Hide file tree
Showing 38 changed files with 14,786 additions and 84 deletions.
15 changes: 15 additions & 0 deletions db/migrations/1700133046667-Data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = class Data1700133046667 {
name = 'Data1700133046667'

async up(db) {
await db.query(`CREATE TABLE "multi_tokens_claims" ("id" character varying NOT NULL, "eth_account" text NOT NULL, "completed" boolean NOT NULL, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL, "account_id" character varying, CONSTRAINT "PK_f074c8e8d71ea5023df43762615" PRIMARY KEY ("id"))`)
await db.query(`CREATE INDEX "IDX_c8aaf94cba10437b7503292814" ON "multi_tokens_claims" ("account_id") `)
await db.query(`ALTER TABLE "multi_tokens_claims" ADD CONSTRAINT "FK_c8aaf94cba10437b75032928149" FOREIGN KEY ("account_id") REFERENCES "account"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`)
}

async down(db) {
await db.query(`DROP TABLE "multi_tokens_claims"`)
await db.query(`DROP INDEX "public"."IDX_c8aaf94cba10437b7503292814"`)
await db.query(`ALTER TABLE "multi_tokens_claims" DROP CONSTRAINT "FK_c8aaf94cba10437b75032928149"`)
}
}
13 changes: 13 additions & 0 deletions db/migrations/1701280554423-Data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = class Data1701280554423 {
name = 'Data1701280554423'

async up(db) {
await db.query(`ALTER TABLE "fuel_tank_rule_set" ADD "is_permitted_extrinsics_null" boolean NOT NULL`)
await db.query(`ALTER TABLE "fuel_tank_rule_set" ADD "whitelisted_pallets" text array`)
}

async down(db) {
await db.query(`ALTER TABLE "fuel_tank_rule_set" DROP COLUMN "is_permitted_extrinsics_null"`)
await db.query(`ALTER TABLE "fuel_tank_rule_set" DROP COLUMN "whitelisted_pallets"`)
}
}
128 changes: 127 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"node-cache": "^5.1.2",
"ora": "^5.4.1",
"pg": "^8.11.3",
"type-graphql": "^1.2.0-rc.1"
"type-graphql": "^1.2.0-rc.1",
"web3-validator": "^2.0.3"
},
"devDependencies": {
"@subsquid/substrate-metadata-explorer": "^1.1.2",
Expand Down
31 changes: 28 additions & 3 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ union EventData = MultiTokensApproved | MultiTokensAttributeRemoved | MultiToken
| MultiTokensTokenDestroyed | MultiTokensTokenMutated | MultiTokensTransferred | MultiTokensUnapproved
| MarketplaceAuctionFinalized | MarketplaceBidPlaced | MarketplaceListingCancelled | MarketplaceListingCreated
| MarketplaceListingFilled | BalancesTransfer | TeleportBalanceWithdrawn | ClaimsClaimRequested | ClaimsClaimed
| FuelTankCreated | FuelTankDestroyed
| FuelTankCreated | FuelTankDestroyed | MultiTokensClaimTokensInitiated | MultiTokensClaimTokensCompleted

type BalancesTransfer {
from: Account!
Expand Down Expand Up @@ -277,6 +277,16 @@ type FuelTankDestroyed {
tank: String!
}

type MultiTokensClaimTokensInitiated {
account: Account!
ethAccount: String!
}

type MultiTokensClaimTokensCompleted {
account: Account!
ethAccount: String!
}

type Balance {
transferable: BigInt!
free: BigInt!
Expand Down Expand Up @@ -729,22 +739,36 @@ type ClaimDetails @entity {
totalUnclaimedAmount: BigInt!
}

type MultiTokensClaims @entity {
id: ID!

account: Account!
ethAccount: String!
completed: Boolean!

createdAt: DateTime!
}

type WhitelistedCallers {
value: [String!]!
}

type WhitelistedPallets {
value: [String!]!
}

type MaxFuelBurnPerTransaction {
value: BigInt!
}

type UserFuelBudget {
amount: BigInt
resetPeriod: Int
resetPeriod: BigInt
}

type TankFuelBudget {
amount: BigInt
resetPeriod: Int
resetPeriod: BigInt
}

type RequireToken {
Expand Down Expand Up @@ -793,6 +817,7 @@ type FuelTankRuleSet @entity {

whitelistedCallers: [String!]
whitelistedCollections: [String]
whitelistedPallets: [String!]
maxFuelBurnPerTransaction: MaxFuelBurnPerTransaction
userFuelBudget: UserFuelBudget
tankFuelBudget: TankFuelBudget
Expand Down
5 changes: 5 additions & 0 deletions src/job-handlers/process-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ export default async (job: Queue.Job<JobData>, done: Queue.DoneCallback) => {
uriAttribute = { ...collectionUriAttribute, value: collectionUriAttribute.value.replace('{id}', resource.id) }
}

// check if token/collection has {id} placeholder in it's own attribute
if (uriAttribute && uriAttribute.value.includes('{id}')) {
uriAttribute = { ...uriAttribute, value: uriAttribute.value.replace('{id}', resource.id) }
}

let externalMetadata: any = {}
let metadata = new Metadata()

Expand Down
28 changes: 15 additions & 13 deletions src/mappings/claims/events/claimRequested.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,21 @@ export async function claimRequested(

await Promise.all([ctx.store.insert(ClaimRequest, claim), ctx.store.save(claimDetails)])

await Sns.getInstance().send({
id: item.event.id,
name: item.event.name,
body: {
who: account.account,
accountType: account.type,
amountClaimable: eventData.amountClaimable,
amountBurned: eventData.amountBurned,
hash: u8aToHex(eventData.transactionHash).toString(),
isEfiToken: eventData.isEfiToken,
extrinsic: item.event.extrinsic.id,
},
})
if (item.event.extrinsic) {
await Sns.getInstance().send({
id: item.event.id,
name: item.event.name,
body: {
who: account.account,
accountType: account.type,
amountClaimable: eventData.amountClaimable,
amountBurned: eventData.amountBurned,
hash: u8aToHex(eventData.transactionHash).toString(),
isEfiToken: eventData.isEfiToken,
extrinsic: item.event.extrinsic.id,
},
})
}

return new EventModel({
id: item.event.id,
Expand Down
20 changes: 17 additions & 3 deletions 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 All @@ -37,9 +44,9 @@ export function rulesToMap(
} else if (rule.__kind === 'MaxFuelBurnPerTransaction') {
maxFuelBurnPerTransaction = new MaxFuelBurnPerTransaction({ value: rule.value })
} else if (rule.__kind === 'UserFuelBudget') {
userFuelBudget = new UserFuelBudget({ amount: rule.value.amount, resetPeriod: rule.value.resetPeriod })
userFuelBudget = new UserFuelBudget({ amount: rule.value.amount, resetPeriod: BigInt(rule.value.resetPeriod) })
} else if (rule.__kind === 'TankFuelBudget') {
tankFuelBudget = new TankFuelBudget({ amount: rule.value.amount, resetPeriod: rule.value.resetPeriod })
tankFuelBudget = new TankFuelBudget({ amount: rule.value.amount, resetPeriod: BigInt(rule.value.resetPeriod) })
} else if (rule.__kind === 'RequireToken') {
requireToken = new RequireToken({
tokenId: rule.value.tokenId,
Expand All @@ -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 All @@ -84,6 +94,10 @@ export function getTankDataFromCall(ctx: CommonContext, call: Call) {
return data.asMatrixEnjinV603
}

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

if (data.isV604) {
return data.asV604
}
Expand Down
Loading

0 comments on commit 6560b07

Please sign in to comment.