Skip to content

Commit

Permalink
Merge pull request #55 from subquery/update-jay
Browse files Browse the repository at this point in the history
Fix types and use tx from log
  • Loading branch information
jiqiang90 authored Nov 7, 2023
2 parents 86e14aa + bd5df89 commit 39219cf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
9 changes: 6 additions & 3 deletions Ethereum/ethereum-uniswap-v3/src/mappings/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ import {
} from "../types/contracts/Pool";
import { Pool__factory } from "../types/contracts/factories/Pool__factory";
import assert from "assert";
import {InitializeLog, MintLog, SwapLog, SwapTransaction} from "../types/abi-interfaces/Pool";

export async function handleInitialize(
event: EthereumLog<InitializeEvent["args"]>
event: InitializeLog
): Promise<void> {
const [pool, ethPrice] = await Promise.all([
Pool.get(event.address),
Expand Down Expand Up @@ -76,8 +77,9 @@ export async function handleInitialize(
}

export async function handleMint(
event: EthereumLog<MintEvent["args"]>
event: MintLog
): Promise<void> {

const poolAddress = event.address;
const pool = await Pool.get(poolAddress);

Expand Down Expand Up @@ -353,7 +355,7 @@ export async function handleBurn(
}

export async function handleSwap(
event: EthereumLog<SwapEvent["args"]>
event: SwapLog
): Promise<void> {
const poolContract = Pool__factory.connect(event.address, api);
const [
Expand All @@ -375,6 +377,7 @@ export async function handleSwap(
]);
assert(pool);


// hot fix for bad pricing
if (pool.id == "0x9663f2ca0454accad3e094448ea6f77443880454") {
return;
Expand Down
22 changes: 7 additions & 15 deletions Ethereum/ethereum-uniswap-v3/src/mappings/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,20 @@ export function convertTokenToDecimal(
}

export async function loadTransaction(
event: EthereumLog
log: EthereumLog
): Promise<Transaction> {
let transaction = await Transaction.get(event.transactionHash);
let transaction = await Transaction.get(log.transactionHash);
if (transaction === undefined) {
transaction = Transaction.create({
id: event.transactionHash,
blockNumber: BigInt(event.blockNumber),
timestamp: event.block.timestamp,
id: log.transactionHash,
blockNumber: BigInt(log.blockNumber),
timestamp: log.block.timestamp,
gasPrice: BigInt(0),
gasUsed: BigInt(0),
});
}

// transaction.gasPrice = event.block.gasPrice
const eventTransaction = event.block.transactions.find(
(transaction) =>
transaction.transactionIndex ==
BigNumber.from(event.transactionIndex).toBigInt()
);
assert(eventTransaction);
transaction.gasUsed = (await eventTransaction.receipt()).gasUsed;
transaction.gasPrice = eventTransaction.gasPrice;
transaction.gasUsed = (await log.transaction.receipt()).gasUsed;
transaction.gasPrice = log.transaction.gasPrice;
await transaction.save();
return transaction;
}

0 comments on commit 39219cf

Please sign in to comment.