2021-08-12 09:58:13 +00:00
|
|
|
//
|
|
|
|
// Copyright 2021 Vulcanize, Inc.
|
|
|
|
//
|
|
|
|
|
2021-07-02 10:56:32 +00:00
|
|
|
import assert from 'assert';
|
|
|
|
import BigInt from 'apollo-type-bigint';
|
2021-07-29 09:15:38 +00:00
|
|
|
import debug from 'debug';
|
2021-07-02 10:56:32 +00:00
|
|
|
|
2021-08-03 06:26:25 +00:00
|
|
|
import { Indexer, OrderDirection, BlockHeight } from './indexer';
|
2021-07-29 12:42:35 +00:00
|
|
|
import { Burn } from './entity/Burn';
|
2021-07-30 12:19:22 +00:00
|
|
|
import { Bundle } from './entity/Bundle';
|
|
|
|
import { Factory } from './entity/Factory';
|
|
|
|
import { Mint } from './entity/Mint';
|
|
|
|
import { PoolDayData } from './entity/PoolDayData';
|
|
|
|
import { Pool } from './entity/Pool';
|
|
|
|
import { Swap } from './entity/Swap';
|
2021-08-02 10:16:21 +00:00
|
|
|
import { Tick } from './entity/Tick';
|
|
|
|
import { Token } from './entity/Token';
|
2021-08-03 06:26:25 +00:00
|
|
|
import { TokenDayData } from './entity/TokenDayData';
|
|
|
|
import { TokenHourData } from './entity/TokenHourData';
|
|
|
|
import { Transaction } from './entity/Transaction';
|
|
|
|
import { UniswapDayData } from './entity/UniswapDayData';
|
2021-08-10 06:39:00 +00:00
|
|
|
import { Position } from './entity/Position';
|
2021-08-18 10:20:44 +00:00
|
|
|
import { EventWatcher } from './events';
|
2021-07-02 10:56:32 +00:00
|
|
|
|
2021-07-29 09:15:38 +00:00
|
|
|
const log = debug('vulcanize:resolver');
|
|
|
|
|
2021-08-03 06:26:25 +00:00
|
|
|
export { BlockHeight };
|
2021-07-29 09:15:38 +00:00
|
|
|
|
2021-08-18 10:20:44 +00:00
|
|
|
export const createResolvers = async (indexer: Indexer, eventWatcher: EventWatcher): Promise<any> => {
|
2021-07-02 10:56:32 +00:00
|
|
|
assert(indexer);
|
|
|
|
|
|
|
|
return {
|
|
|
|
BigInt: new BigInt('bigInt'),
|
|
|
|
|
2021-08-18 10:20:44 +00:00
|
|
|
Subscription: {
|
|
|
|
onBlockProgressEvent: {
|
|
|
|
subscribe: () => eventWatcher.getBlockProgressEventIterator()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2021-07-29 09:15:38 +00:00
|
|
|
Query: {
|
|
|
|
bundle: async (_: any, { id, block = {} }: { id: string, block: BlockHeight }) => {
|
|
|
|
log('bundle', id, block);
|
|
|
|
|
|
|
|
return indexer.getBundle(id, block);
|
|
|
|
},
|
|
|
|
|
2021-07-30 12:19:22 +00:00
|
|
|
bundles: async (_: any, { block = {}, first }: { first: number, block: BlockHeight }) => {
|
2021-07-29 12:42:35 +00:00
|
|
|
log('bundles', block, first);
|
|
|
|
|
2021-08-03 06:26:25 +00:00
|
|
|
return indexer.getEntities(Bundle, block, {}, { limit: first });
|
2021-07-29 12:42:35 +00:00
|
|
|
},
|
|
|
|
|
2021-08-03 06:26:25 +00:00
|
|
|
burns: async (_: any, { first, orderBy, orderDirection, where }: { first: number, orderBy: string, orderDirection: OrderDirection, where: { [key: string]: any } }) => {
|
2021-07-29 12:42:35 +00:00
|
|
|
log('burns', first, orderBy, orderDirection, where);
|
|
|
|
|
2021-08-03 06:26:25 +00:00
|
|
|
return indexer.getEntities(Burn, {}, where, { limit: first, orderBy, orderDirection }, ['pool', 'transaction']);
|
2021-07-29 12:42:35 +00:00
|
|
|
},
|
|
|
|
|
2021-07-30 12:19:22 +00:00
|
|
|
factories: async (_: any, { block = {}, first }: { first: number, block: BlockHeight }) => {
|
2021-07-29 12:42:35 +00:00
|
|
|
log('factories', block, first);
|
2021-07-29 09:15:38 +00:00
|
|
|
|
2021-08-03 06:26:25 +00:00
|
|
|
return indexer.getEntities(Factory, block, {}, { limit: first });
|
2021-07-30 12:19:22 +00:00
|
|
|
},
|
|
|
|
|
2021-08-03 06:26:25 +00:00
|
|
|
mints: async (_: any, { first, orderBy, orderDirection, where }: { first: number, orderBy: string, orderDirection: OrderDirection, where: { [key: string]: any } }) => {
|
2021-08-11 10:57:42 +00:00
|
|
|
log('mints', first, orderBy, orderDirection, where);
|
2021-07-30 12:19:22 +00:00
|
|
|
|
2021-08-03 06:26:25 +00:00
|
|
|
return indexer.getEntities(Mint, {}, where, { limit: first, orderBy, orderDirection }, ['pool', 'transaction']);
|
2021-07-30 12:19:22 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
pool: async (_: any, { id, block = {} }: { id: string, block: BlockHeight }) => {
|
2021-08-11 10:57:42 +00:00
|
|
|
log('pool', id, block);
|
2021-07-30 12:19:22 +00:00
|
|
|
|
|
|
|
return indexer.getPool(id, block);
|
|
|
|
},
|
|
|
|
|
2021-08-03 06:26:25 +00:00
|
|
|
poolDayDatas: async (_: any, { first, skip, orderBy, orderDirection, where }: { first: number, skip: number, orderBy: string, orderDirection: OrderDirection, where: { [key: string]: any } }) => {
|
2021-07-30 12:19:22 +00:00
|
|
|
log('poolDayDatas', first, skip, orderBy, orderDirection, where);
|
|
|
|
|
2021-08-03 06:26:25 +00:00
|
|
|
return indexer.getEntities(PoolDayData, {}, where, { limit: first, skip, orderBy, orderDirection });
|
2021-07-30 12:19:22 +00:00
|
|
|
},
|
|
|
|
|
2021-08-03 06:26:25 +00:00
|
|
|
pools: async (_: any, { block = {}, first, orderBy, orderDirection, where = {} }: { block: BlockHeight, first: number, orderBy: string, orderDirection: OrderDirection, where: { [key: string]: any } }) => {
|
2021-08-11 10:57:42 +00:00
|
|
|
log('pools', block, first, orderBy, orderDirection, where);
|
2021-07-30 12:19:22 +00:00
|
|
|
|
2021-08-03 06:26:25 +00:00
|
|
|
return indexer.getEntities(Pool, block, where, { limit: first, orderBy, orderDirection }, ['token0', 'token1']);
|
2021-07-30 12:19:22 +00:00
|
|
|
},
|
|
|
|
|
2021-08-03 06:26:25 +00:00
|
|
|
swaps: async (_: any, { first, orderBy, orderDirection, where }: { first: number, orderBy: string, orderDirection: OrderDirection, where: { [key: string]: any } }) => {
|
2021-07-30 12:19:22 +00:00
|
|
|
log('swaps', first, orderBy, orderDirection, where);
|
|
|
|
|
2021-08-03 06:26:25 +00:00
|
|
|
return indexer.getEntities(Swap, {}, where, { limit: first, orderBy, orderDirection }, ['pool', 'transaction']);
|
2021-08-02 10:16:21 +00:00
|
|
|
},
|
|
|
|
|
2021-08-03 06:26:25 +00:00
|
|
|
ticks: async (_: any, { block = {}, first, skip, where = {} }: { block: BlockHeight, first: number, skip: number, where: { [key: string]: any } }) => {
|
2021-08-02 10:16:21 +00:00
|
|
|
log('ticks', block, first, skip, where);
|
|
|
|
|
2021-08-03 06:26:25 +00:00
|
|
|
return indexer.getEntities(Tick, block, where, { limit: first, skip });
|
2021-08-02 10:16:21 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
token: async (_: any, { id, block = {} }: { id: string, block: BlockHeight }) => {
|
|
|
|
log('token', id, block);
|
|
|
|
|
|
|
|
return indexer.getToken(id, block);
|
|
|
|
},
|
|
|
|
|
2021-08-03 06:26:25 +00:00
|
|
|
tokens: async (_: any, { orderBy, orderDirection, where }: { orderBy: string, orderDirection: OrderDirection, where: { [key: string]: any } }) => {
|
2021-08-02 10:16:21 +00:00
|
|
|
log('tokens', orderBy, orderDirection, where);
|
|
|
|
|
2021-08-03 06:26:25 +00:00
|
|
|
return indexer.getEntities(Token, {}, where, { orderBy, orderDirection });
|
|
|
|
},
|
|
|
|
|
|
|
|
tokenDayDatas: async (_: any, { first, skip, orderBy, orderDirection, where }: { first: number, skip: number, orderBy: string, orderDirection: OrderDirection, where: { [key: string]: any } }) => {
|
|
|
|
log('tokenDayDatas', first, skip, orderBy, orderDirection, where);
|
|
|
|
|
|
|
|
return indexer.getEntities(TokenDayData, {}, where, { limit: first, skip, orderBy, orderDirection });
|
|
|
|
},
|
|
|
|
|
|
|
|
tokenHourDatas: async (_: any, { first, skip, orderBy, orderDirection, where }: { first: number, skip: number, orderBy: string, orderDirection: OrderDirection, where: { [key: string]: any } }) => {
|
2021-08-11 10:57:42 +00:00
|
|
|
log('tokenHourDatas', first, skip, orderBy, orderDirection, where);
|
2021-08-03 06:26:25 +00:00
|
|
|
|
|
|
|
return indexer.getEntities(TokenHourData, {}, where, { limit: first, skip, orderBy, orderDirection });
|
|
|
|
},
|
|
|
|
|
|
|
|
transactions: async (_: any, { first, orderBy, orderDirection }: { first: number, orderBy: string, orderDirection: OrderDirection}) => {
|
|
|
|
log('transactions', first, orderBy, orderDirection);
|
|
|
|
|
|
|
|
return indexer.getEntities(Transaction, {}, {}, { limit: first, orderBy, orderDirection }, ['burns', 'mints', 'swaps']);
|
|
|
|
},
|
|
|
|
|
|
|
|
uniswapDayDatas: async (_: any, { first, skip, orderBy, orderDirection, where }: { first: number, skip: number, orderBy: string, orderDirection: OrderDirection, where: { [key: string]: any } }) => {
|
|
|
|
log('uniswapDayDatas', first, skip, orderBy, orderDirection, where);
|
|
|
|
|
|
|
|
return indexer.getEntities(UniswapDayData, {}, where, { limit: first, skip, orderBy, orderDirection });
|
2021-08-10 06:39:00 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
positions: async (_: any, { first, where }: { first: number, where: { [key: string]: any } }) => {
|
2021-08-11 10:57:42 +00:00
|
|
|
log('positions', first, where);
|
2021-08-10 06:39:00 +00:00
|
|
|
|
|
|
|
return indexer.getEntities(Position, {}, where, { limit: first }, ['pool', 'token0', 'token1', 'tickLower', 'tickUpper', 'transaction']);
|
2021-08-13 09:36:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
blocks: async (_: any, { first, orderBy, orderDirection, where }: { first: number, orderBy: string, orderDirection: OrderDirection, where: { [key: string]: any } }) => {
|
|
|
|
log('blocks', first, orderBy, orderDirection, where);
|
|
|
|
|
|
|
|
return indexer.getBlocks(where, { limit: first, orderBy, orderDirection });
|
2021-07-29 09:15:38 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-02 10:56:32 +00:00
|
|
|
};
|
|
|
|
};
|