Files
pezkuwi-subquery/src/mappings/Transfers.ts
T
pezkuwichain 2f1d6dd316 Migrate to native @pezkuwi packages and remove swap integrations
Replace npm aliases (@polkadot -> @pezkuwi) with direct @pezkuwi package
imports. Add tsconfig path mappings to redirect @polkadot type references
from @subql/types to @pezkuwi equivalents, enabling proper type resolution
without installing @polkadot packages. Remove Polkadot ecosystem swap/bridge
integrations (HydraDx, AssetConversion) as they're incompatible with Pezkuwi.
2026-02-13 01:36:52 +03:00

64 lines
1.3 KiB
TypeScript

import { HistoryElement, Transfer } from "../types";
import { SubstrateEvent } from "@subql/types";
import {
blockNumber,
eventId,
calculateFeeAsString,
timestamp,
getEventData,
} from "./common";
export async function handleTransfer(event: SubstrateEvent): Promise<void> {
const [from, to, amount] = getEventData(event);
await createTransfer(
event,
from.toString(),
"-from",
from.toString(),
to.toString(),
amount.toString(),
);
await createTransfer(
event,
to.toString(),
"-to",
from.toString(),
to.toString(),
amount.toString(),
);
}
async function createTransfer(
event: SubstrateEvent,
address: string,
suffix: string,
from: string,
to: string,
amount: string,
): Promise<void> {
const transfer: Transfer = {
amount: amount,
from: from,
to: to,
fee: calculateFeeAsString(event.extrinsic, from),
eventIdx: event.idx,
success: true,
};
const element = new HistoryElement(
`${eventId(event)}${suffix}`,
blockNumber(event),
timestamp(event.block),
address,
);
if (event.extrinsic !== undefined) {
element.extrinsicHash = event.extrinsic.extrinsic.hash.toString();
element.extrinsicIdx = event.extrinsic.idx;
}
element.transfer = transfer;
await element.save();
}