Skip to content

Commit

Permalink
Fix typeorm bigint transformer and convert to checksum contract address
Browse files Browse the repository at this point in the history
  • Loading branch information
nikugogoi committed May 11, 2023
1 parent 03dad21 commit 68ceea3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion packages/util/src/graph/state-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import assert from 'assert';
import debug from 'debug';
import _ from 'lodash';
import { Between, ValueTransformer } from 'typeorm';
import { ethers } from 'ethers';

import { jsonBigIntStringReplacer } from '../misc';
import { IndexerInterface, StateInterface } from '../types';
Expand Down Expand Up @@ -150,7 +151,7 @@ export const getContractEntitiesMap = (dataSources: any[]): Map<string, string[]
// Populate contractEntitiesMap using data sources from subgraph
dataSources.forEach((dataSource: any) => {
const { source: { address: contractAddress }, mapping: { entities } } = dataSource;
contractEntitiesMap.set(contractAddress, entities as string[]);
contractEntitiesMap.set(ethers.utils.getAddress(contractAddress), entities as string[]);
});

return contractEntitiesMap;
Expand Down
12 changes: 6 additions & 6 deletions packages/util/src/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ export const wait = async (time: number): Promise<void> => new Promise(resolve =
*/
export const graphDecimalTransformer: ValueTransformer = {
to: (value?: GraphDecimal) => {
if (value !== undefined) {
if (value !== undefined && value !== null) {
return value.toFixed();
}

return value;
},
from: (value?: string) => {
if (value !== undefined) {
if (value !== undefined && value !== null) {
return new GraphDecimal(value);
}

Expand All @@ -57,14 +57,14 @@ export const graphDecimalTransformer: ValueTransformer = {
*/
export const decimalTransformer: ValueTransformer = {
to: (value?: Decimal) => {
if (value !== undefined) {
if (value !== undefined && value !== null) {
return value.toString();
}

return value;
},
from: (value?: string) => {
if (value !== undefined) {
if (value !== undefined && value !== null) {
return new Decimal(value);
}

Expand All @@ -77,14 +77,14 @@ export const decimalTransformer: ValueTransformer = {
*/
export const bigintTransformer: ValueTransformer = {
to: (value?: bigint) => {
if (value !== undefined) {
if (value !== undefined && value !== null) {
return value.toString();
}

return value;
},
from: (value?: string) => {
if (value !== undefined) {
if (value !== undefined && value !== null) {
return BigInt(value);
}

Expand Down

0 comments on commit 68ceea3

Please sign in to comment.