|
| 1 | +#!/usr/bin/env -S node --import ts-blank-space/register |
| 2 | +/* eslint-env node */ |
| 3 | +/* eslint-disable @jessie.js/safe-await-separator */ |
| 4 | + |
| 5 | +/** |
| 6 | + * You can paste the output of this into a spreadsheet for analysis. |
| 7 | + * E.g. https://docs.google.com/spreadsheets/d/15CZGF-GyqfimwZgrkFTIAkp8xEfHlLQhkp83flXqI84/edit?pli=1&gid=1340327751#gid=1340327751 |
| 8 | + */ |
| 9 | + |
| 10 | +// module |
| 11 | +export { }; |
| 12 | + |
| 13 | +/** |
| 14 | + * Fetches GraphQL data, converts it to a table, and prints it as TSV. |
| 15 | + * @param {string} graphqlEndpoint - The GraphQL endpoint URL. |
| 16 | + * @param {string} query - The GraphQL query string. |
| 17 | + */ |
| 18 | +export async function dumpTransactions( |
| 19 | + graphqlEndpoint: string, |
| 20 | + query: string, |
| 21 | +): Promise<void> { |
| 22 | + try { |
| 23 | + // Fetch the GraphQL response |
| 24 | + const response = await fetch(graphqlEndpoint, { |
| 25 | + method: 'POST', |
| 26 | + headers: { 'Content-Type': 'application/json' }, |
| 27 | + body: JSON.stringify({ query }), |
| 28 | + }); |
| 29 | + |
| 30 | + if (!response.ok) { |
| 31 | + throw new Error( |
| 32 | + `GraphQL request failed with status ${response.status}: ${response.statusText}`, |
| 33 | + ); |
| 34 | + } |
| 35 | + |
| 36 | + const { data } = await response.json(); |
| 37 | + |
| 38 | + if (!data) { |
| 39 | + throw new Error('No data received from GraphQL response'); |
| 40 | + } |
| 41 | + |
| 42 | + const transactions = data.fastUsdcTransactions.edges.map( |
| 43 | + (edge: any) => edge.node, |
| 44 | + ); |
| 45 | + |
| 46 | + // Convert the data to a table format |
| 47 | + const rows: string[][] = []; |
| 48 | + const headers = Object.keys(transactions[0]); |
| 49 | + rows.push(headers); |
| 50 | + |
| 51 | + for (const txn of transactions) { |
| 52 | + rows.push(headers.map(header => String(txn[header] ?? ''))); |
| 53 | + } |
| 54 | + |
| 55 | + // Print the table as TSV |
| 56 | + for (const row of rows) { |
| 57 | + console.log(row.join('\t')); |
| 58 | + } |
| 59 | + } catch (error) { |
| 60 | + console.error('Error dumping transactions:', error); |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | +const graphqlEndpoint = 'https://api.subquery.network/sq/agoric-labs/internal'; |
| 65 | +const query = ` |
| 66 | +query TransactionsQuery { |
| 67 | + fastUsdcTransactions(orderBy: SOURCE_BLOCK_TIMESTAMP_DESC) { |
| 68 | + edges { |
| 69 | + node { |
| 70 | + id |
| 71 | + sourceAddress |
| 72 | + sourceChainId |
| 73 | + sourceBlockTimestamp |
| 74 | + eud |
| 75 | + usdcAmount |
| 76 | + status |
| 77 | + statusHeight |
| 78 | + contractFee |
| 79 | + poolFee |
| 80 | + risksIdentified |
| 81 | + heightObserved |
| 82 | + heightAdvanced |
| 83 | + heightDisbursed |
| 84 | + timeObserved |
| 85 | + timeAdvanced |
| 86 | + timeDisbursed |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | + } |
| 91 | +`; |
| 92 | + |
| 93 | +dumpTransactions(graphqlEndpoint, query).catch(err => { |
| 94 | + console.error('Unhandled error:', err); |
| 95 | +}); |
0 commit comments