Store contract addresses in uni-info-watcher entities in lowercase (#322)

This commit is contained in:
prathamesh0 2021-12-17 17:55:41 +05:30 committed by GitHub
parent 5dc6582ec8
commit 5b632a72aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 49 additions and 23 deletions

View File

@ -24,7 +24,7 @@ export const fetchTokenSymbol = async (ethProvider: BaseProvider, blockHash: str
const result = await contractSymbolBytes.symbol({ blockTag: blockHash });
// For broken pairs that have no symbol function exposed.
if (!isNullEthValue(result)) {
if (!isNullEthValue(utils.hexlify(result))) {
symbolValue = utils.parseBytes32String(result);
} else {
// Try with the static definition.
@ -56,7 +56,7 @@ export const fetchTokenName = async (ethProvider: BaseProvider, blockHash: strin
const result = await contractNameBytes.name({ blockTag: blockHash });
// For broken pairs that have no name function exposed.
if (!isNullEthValue(result)) {
if (!isNullEthValue(utils.hexlify(result))) {
nameValue = utils.parseBytes32String(result);
} else {
// Try with the static definition.

View File

@ -83,11 +83,12 @@ export class StaticTokenDefinition {
// Helper for hardcoded tokens.
static fromAddress (tokenAddress: string) : StaticTokenDefinition | null {
const staticDefinitions = this.getStaticDefinitions();
const tokenAddressHex = utils.hexlify(tokenAddress);
// Search the definition using the address.
for (let i = 0; i < staticDefinitions.length; i++) {
const staticDefinition = staticDefinitions[i];
if (utils.getAddress(staticDefinition.address) === utils.getAddress(tokenAddress)) {
if (utils.getAddress(utils.hexlify(staticDefinition.address)) === utils.getAddress(tokenAddressHex)) {
return staticDefinition;
}
}

View File

@ -406,7 +406,11 @@ export class Indexer implements IndexerInterface {
}
async _handlePoolCreated (block: Block, contractAddress: string, tx: Transaction, poolCreatedEvent: PoolCreatedEvent): Promise<void> {
const { token0: token0Address, token1: token1Address, fee, pool: poolAddress } = poolCreatedEvent;
let { token0: token0Address, token1: token1Address, fee, pool: poolAddress } = poolCreatedEvent;
// Get the addresses in lowercase.
token0Address = utils.hexlify(token0Address);
token1Address = utils.hexlify(token1Address);
poolAddress = utils.hexlify(poolAddress);
// Temp fix from Subgraph mapping code.
if (utils.getAddress(poolAddress) === utils.getAddress('0x8fe8d9bb8eeba3ed688069c3d6b556c9ca258248')) {
@ -533,8 +537,10 @@ export class Indexer implements IndexerInterface {
const dbTx = await this._db.createTransactionRunner();
try {
const pool = await this._db.getPool(dbTx, { id: contractAddress, blockHash: block.hash });
assert(pool, `Pool ${contractAddress} not found.`);
// Get the contract address in lowercase as pool address.
const poolAddress = utils.hexlify(contractAddress);
const pool = await this._db.getPool(dbTx, { id: poolAddress, blockHash: block.hash });
assert(pool, `Pool ${poolAddress} not found.`);
// Update Pool.
pool.sqrtPrice = BigInt(sqrtPriceX96);
@ -584,7 +590,9 @@ export class Indexer implements IndexerInterface {
try {
const bundle = await this._db.getBundle(dbTx, { id: '1', blockHash: block.hash });
assert(bundle);
const poolAddress = contractAddress;
// Get the contract address in lowercase as pool address.
const poolAddress = utils.hexlify(contractAddress);
let pool = await this._db.getPool(dbTx, { id: poolAddress, blockHash: block.hash });
assert(pool);
@ -742,7 +750,9 @@ export class Indexer implements IndexerInterface {
try {
const bundle = await this._db.getBundle(dbTx, { id: '1', blockHash: block.hash });
assert(bundle);
const poolAddress = contractAddress;
// Get the contract address in lowercase as pool address.
const poolAddress = utils.hexlify(contractAddress);
let pool = await this._db.getPool(dbTx, { id: poolAddress, blockHash: block.hash });
assert(pool);
@ -888,7 +898,9 @@ export class Indexer implements IndexerInterface {
// Currently fetching first factory in database as only one exists.
const [factory] = await this._db.getModelEntities(dbTx, Factory, { hash: block.hash }, {}, { limit: 1 });
let pool = await this._db.getPool(dbTx, { id: contractAddress, blockHash: block.hash });
// Get the contract address in lowercase as pool address.
const poolAddress = utils.hexlify(contractAddress);
let pool = await this._db.getPool(dbTx, { id: poolAddress, blockHash: block.hash });
assert(pool);
// Hot fix for bad pricing.
@ -1305,7 +1317,8 @@ export class Indexer implements IndexerInterface {
}
async _loadTickUpdateFeeVarsAndSave (dbTx:QueryRunner, tickId: number, block: Block, contractAddress: string): Promise<void> {
const poolAddress = contractAddress;
// Get the contract address in lowercase as pool address.
const poolAddress = utils.hexlify(contractAddress);
const tick = await this._db.getTick(
dbTx,
@ -1348,9 +1361,12 @@ export class Indexer implements IndexerInterface {
const [factory] = await this._db.getModelEntitiesNoTx(Factory, { hash: blockHash }, {}, { limit: 1 });
console.time('time:indexer#_getPosition-eth_call_for_getPool');
const { value: poolAddress } = await this._uniClient.callGetPool(blockHash, factory.id, positionResult.token0, positionResult.token1, positionResult.fee);
let { value: poolAddress } = await this._uniClient.callGetPool(blockHash, factory.id, positionResult.token0, positionResult.token1, positionResult.fee);
console.timeEnd('time:indexer#_getPosition-eth_call_for_getPool');
// Get the pool address in lowercase.
poolAddress = utils.hexlify(poolAddress);
position = new Position();
position.id = tokenId.toString();
@ -1359,8 +1375,8 @@ export class Indexer implements IndexerInterface {
position.pool = pool;
const [token0, token1] = await Promise.all([
this._db.getTokenNoTx({ id: positionResult.token0, blockHash }),
this._db.getTokenNoTx({ id: positionResult.token1, blockHash })
this._db.getTokenNoTx({ id: utils.hexlify(positionResult.token0), blockHash }),
this._db.getTokenNoTx({ id: utils.hexlify(positionResult.token1), blockHash })
]);
assert(token0 && token1);
position.token0 = token0;

View File

@ -3,7 +3,7 @@
//
import { expect } from 'chai';
import { ethers, Contract, Signer, constants } from 'ethers';
import { ethers, Contract, Signer, constants, utils } from 'ethers';
import 'mocha';
import _ from 'lodash';
@ -121,6 +121,10 @@ describe('uni-info-watcher', () => {
before(async () => {
// Deploy 2 tokens.
({ token0Address, token1Address } = await deployTokens(signer));
// Convert the addresses to lowercase.
token0Address = utils.hexlify(token0Address);
token1Address = utils.hexlify(token1Address);
expect(token0Address).to.not.be.empty;
expect(token1Address).to.not.be.empty;
});
@ -175,8 +179,11 @@ describe('uni-info-watcher', () => {
// Initializing the token variables.
token0Address = await pool.token0();
token0Address = utils.hexlify(token0Address);
token0 = new Contract(token0Address, TESTERC20_ABI, signer);
token1Address = await pool.token1();
token1Address = utils.hexlify(token1Address);
token1 = new Contract(token1Address, TESTERC20_ABI, signer);
});
});
@ -812,7 +819,7 @@ describe('uni-info-watcher', () => {
const expectedOwner = eventValue.event.to;
expect(position.pool.id).to.be.equal(pool.address);
expect(position.pool.id).to.be.equal(utils.hexlify(pool.address));
expect(position.token0.id).to.be.equal(token0.address);
expect(position.token1.id).to.be.equal(token1.address);
expect(positionTickLower).to.be.equal(tickLower.toString());

View File

@ -2,7 +2,7 @@
// Copyright 2021 Vulcanize, Inc.
//
import { BigNumber } from 'ethers';
import { BigNumber, utils } from 'ethers';
import { QueryRunner } from 'typeorm';
import { GraphDecimal } from '@vulcanize/util';
@ -31,11 +31,13 @@ export const convertTokenToDecimal = (tokenAmount: bigint, exchangeDecimals: big
export const loadTransaction = async (db: Database, dbTx: QueryRunner, event: { block: Block, tx: Transaction }): Promise<TransactionEntity> => {
const { tx, block } = event;
let transaction = await db.getTransaction(dbTx, { id: tx.hash, blockHash: block.hash });
// Get the txHash in lowercase.
const txHash = utils.hexlify(tx.hash);
let transaction = await db.getTransaction(dbTx, { id: txHash, blockHash: block.hash });
if (!transaction) {
transaction = new TransactionEntity();
transaction.id = tx.hash;
transaction.id = txHash;
}
transaction.blockNumber = block.number;

View File

@ -3,7 +3,7 @@
//
import assert from 'assert';
import { BigNumber } from 'ethers';
import { BigNumber, utils } from 'ethers';
import { QueryRunner } from 'typeorm';
import { Database } from '../database';
@ -53,11 +53,11 @@ export const updatePoolDayData = async (db: Database, dbTx: QueryRunner, event:
const dayID = Math.floor(block.timestamp / 86400);
const dayStartTimestamp = dayID * 86400;
const dayPoolID = contractAddress
const dayPoolID = utils.hexlify(contractAddress)
.concat('-')
.concat(dayID.toString());
const pool = await db.getPool(dbTx, { id: contractAddress, blockHash: block.hash });
const pool = await db.getPool(dbTx, { id: utils.hexlify(contractAddress), blockHash: block.hash });
assert(pool);
let poolDayData = await db.getPoolDayData(dbTx, { id: dayPoolID, blockHash: block.hash });
@ -101,11 +101,11 @@ export const updatePoolHourData = async (db: Database, dbTx: QueryRunner, event:
const hourIndex = Math.floor(block.timestamp / 3600); // Get unique hour within unix history.
const hourStartUnix = hourIndex * 3600; // Want the rounded effect.
const hourPoolID = contractAddress
const hourPoolID = utils.hexlify(contractAddress)
.concat('-')
.concat(hourIndex.toString());
const pool = await db.getPool(dbTx, { id: contractAddress, blockHash: block.hash });
const pool = await db.getPool(dbTx, { id: utils.hexlify(contractAddress), blockHash: block.hash });
assert(pool);
let poolHourData = await db.getPoolHourData(dbTx, { id: hourPoolID, blockHash: block.hash });