Skip to content

Commit

Permalink
performance improved; fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bgodlin committed Jan 5, 2024
1 parent 9da516b commit 9aefc8b
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions Fantom/fantom-memecoins/src/mappings/mappingHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,35 @@ export async function handleLog(log: TransferLog): Promise<void> {
logger.info(`New transfer transaction log at block ${log.blockNumber}`);
assert(log.args, "No log.args");

let from = await getOrCreateAddress(log.args.from);
let to = await getOrCreateAddress(log.args.to);
const [from, to, fromBalance, toBalance] = await Promise.all([
getOrCreateAddress(log.args.from),
getOrCreateAddress(log.args.to),
(await erc20.balanceOf(log.args.from)).toBigInt(),
(await erc20.balanceOf(log.args.to)).toBigInt(),
]);
let value = log.args.value.toBigInt();

const transfer = Transfer.create({
id: log.transactionHash + "-" + log.logIndex,
blockHeight: BigInt(log.blockNumber),
toId: to.id,
fromId: from.id,
value: value,
contractAddress: log.address,
});

from.balance = BigInt(from.balance) - value;
to.balance = BigInt(to.balance) + value;

await transfer.save();
await from.save();
await to.save();
await Promise.all([
(async () => {
const transfer = Transfer.create({
id: log.transactionHash + "-" + log.logIndex,
blockHeight: BigInt(log.blockNumber),
toId: to.id,
fromId: from.id,
value: value,
contractAddress: log.address,
});
await transfer.save();
})(),
(async () => {
from.balance = fromBalance;
await from.save();
})(),
(async () => {
to.balance = toBalance;
await to.save();
})(),
]);
}

export async function handleTransaction(tx: ApproveTransaction): Promise<void> {
Expand Down

0 comments on commit 9aefc8b

Please sign in to comment.