aboutsummaryrefslogtreecommitdiffstats
path: root/packages/pipeline/src/scripts/query_data.ts
diff options
context:
space:
mode:
authorAlex Browne <stephenalexbrowne@gmail.com>2018-09-18 02:27:38 +0800
committerAlex Browne <stephenalexbrowne@gmail.com>2018-12-05 06:21:42 +0800
commit57e7119c0d4f1ab7dd1d4c0118e72dc1706e2151 (patch)
tree68596be050d6f84e3b7e6f51f91d09a542ac3129 /packages/pipeline/src/scripts/query_data.ts
parentc43ba6b3c7082544f8aa8f1c297eb271ca079ea4 (diff)
downloaddexon-sol-tools-57e7119c0d4f1ab7dd1d4c0118e72dc1706e2151.tar
dexon-sol-tools-57e7119c0d4f1ab7dd1d4c0118e72dc1706e2151.tar.gz
dexon-sol-tools-57e7119c0d4f1ab7dd1d4c0118e72dc1706e2151.tar.bz2
dexon-sol-tools-57e7119c0d4f1ab7dd1d4c0118e72dc1706e2151.tar.lz
dexon-sol-tools-57e7119c0d4f1ab7dd1d4c0118e72dc1706e2151.tar.xz
dexon-sol-tools-57e7119c0d4f1ab7dd1d4c0118e72dc1706e2151.tar.zst
dexon-sol-tools-57e7119c0d4f1ab7dd1d4c0118e72dc1706e2151.zip
Rebase pipeline branch off development
Diffstat (limited to 'packages/pipeline/src/scripts/query_data.ts')
-rw-r--r--packages/pipeline/src/scripts/query_data.ts87
1 files changed, 87 insertions, 0 deletions
diff --git a/packages/pipeline/src/scripts/query_data.ts b/packages/pipeline/src/scripts/query_data.ts
new file mode 100644
index 000000000..97e3749ea
--- /dev/null
+++ b/packages/pipeline/src/scripts/query_data.ts
@@ -0,0 +1,87 @@
+import { formatters } from '../utils';
+export const dataFetchingQueries: any = {
+ get_missing_txn_hashes: `
+ SELECT
+ a.txn_hash
+ FROM
+ events_raw a
+ WHERE NOT EXISTS
+ (
+ SELECT
+ *
+ FROM
+ transactions b
+ WHERE
+ b.txn_hash = a.txn_hash
+ )
+ AND
+ a.block_number >= $1
+ AND
+ a.block_number < $2`,
+ get_used_block_numbers: `
+ SELECT DISTINCT
+ a.block_number
+ FROM
+ events_raw a
+ WHERE NOT EXISTS
+ (
+ SELECT
+ *
+ FROM
+ blocks b
+ WHERE
+ b.block_number = a.block_number
+ )
+ AND
+ a.block_number >= $1
+ AND
+ a.block_number < $2`,
+ get_token_registry: `
+ SELECT
+ *
+ FROM
+ tokens`,
+ get_max_block: `
+ SELECT
+ MAX(block_number)
+ FROM
+ events_raw`,
+ get_relayers: `
+ SELECT
+ *
+ FROM
+ relayers`,
+ get_most_recent_pricing_date: `
+ SELECT
+ MAX(DATE(timestamp))
+ FROM
+ prices
+ `,
+ get_top_unknown_token_addresses: `
+ SELECT a.token_address as address, a.txn_value / 2 as total_txn_value
+FROM
+(SELECT token_address, SUM(txn_value) as txn_value
+FROM
+(select a.timestamp, a.maker_token as token_address, (CASE WHEN a.taker_txn_usd_value > a.maker_txn_usd_value OR a.maker_txn_usd_value IS NULL
+ THEN a.taker_txn_usd_value
+ ELSE a.maker_txn_usd_value END) as txn_value
+ from events_full a
+ where a.event_type = 'LogFill'
+ and a.timestamp > (NOW() + INTERVAL '-24 hours')
+ union
+ select a.timestamp, a.taker_token as token_address, (CASE WHEN a.taker_txn_usd_value > a.maker_txn_usd_value OR a.maker_txn_usd_value IS NULL
+ THEN a.taker_txn_usd_value
+ ELSE a.maker_txn_usd_value END) as txn_value
+ from events_full a
+ where a.event_type = 'LogFill'
+ and a.timestamp > (NOW() + INTERVAL '-24 hours')) token_txn_values
+WHERE token_address IS NOT NULL
+AND txn_value > 0
+GROUP BY 1
+ORDER BY 2 DESC) a
+LEFT JOIN tokens b
+ON a.token_address = b.address
+WHERE symbol is NULL
+ORDER BY 2 DESC
+`,
+};