|
| 1 | +/* |
| 2 | + * NOTES: |
| 3 | + * |
| 4 | + * If sell_amount=-1, it is a sell order, and |
| 5 | + * - the fixed sell amount provided is output_amounts[0] |
| 6 | + * - the minimum buy amount asked is buy_amount |
| 7 | + * |
| 8 | + * If buy_amount=-1, it is a buy order, and |
| 9 | + * - the fixed buy amount provided is output_amounts[last] |
| 10 | + * - the maximum sell amount asked is sell_amount |
| 11 | + * |
| 12 | + * |
| 13 | + * Running this query can be slooow. |
| 14 | + * |
| 15 | + |
| 16 | + */ |
| 17 | +SELECT ethereum.transactions.block_number, |
| 18 | + ethereum.transactions.index, |
| 19 | + sell_amount, |
| 20 | + buy_amount, |
| 21 | + path, |
| 22 | + output_amounts, |
| 23 | + extract(epoch from ethereum.transactions.block_time) as block_time, |
| 24 | + address |
| 25 | +FROM ( |
| 26 | + (SELECT call_block_number, |
| 27 | + -1 AS sell_amount, |
| 28 | + "amountOutMin" AS buy_amount, |
| 29 | + path, |
| 30 | + output_amounts, |
| 31 | + call_tx_hash, |
| 32 | + "to" AS address |
| 33 | + FROM uniswap_v2."Router02_call_swapExactTokensForTokens" |
| 34 | + WHERE call_success=TRUE |
| 35 | + AND call_block_number>={{from_block}} |
| 36 | + AND call_block_number<{{to_block}}) |
| 37 | + UNION |
| 38 | + (SELECT call_block_number, |
| 39 | + "amountInMax" AS sell_amount, |
| 40 | + -1 AS buy_amount, |
| 41 | + path, |
| 42 | + output_amounts, |
| 43 | + call_tx_hash, |
| 44 | + "to" AS address |
| 45 | + FROM uniswap_v2."Router02_call_swapTokensForExactTokens" |
| 46 | + WHERE call_success=TRUE |
| 47 | + AND call_block_number>={{from_block}} |
| 48 | + AND call_block_number<{{to_block}}) |
| 49 | + UNION |
| 50 | + (SELECT call_block_number, |
| 51 | + ethereum.transactions.value AS sell_amount, |
| 52 | + -1 AS buy_amount, |
| 53 | + path, |
| 54 | + output_amounts, |
| 55 | + call_tx_hash, |
| 56 | + uniswap_v2."Router02_call_swapETHForExactTokens".to AS address |
| 57 | + FROM uniswap_v2."Router02_call_swapETHForExactTokens" |
| 58 | + INNER JOIN ethereum.transactions ON ethereum.transactions.hash = call_tx_hash |
| 59 | + WHERE call_success=TRUE |
| 60 | + AND call_block_number>={{from_block}} |
| 61 | + AND call_block_number<{{to_block}}) |
| 62 | + UNION |
| 63 | + (SELECT call_block_number, |
| 64 | + -1 AS sell_amount, |
| 65 | + "amountOutMin" AS buy_amount, |
| 66 | + path, |
| 67 | + output_amounts, |
| 68 | + call_tx_hash, |
| 69 | + "to" AS address |
| 70 | + FROM uniswap_v2."Router02_call_swapExactETHForTokens" |
| 71 | + WHERE call_success=TRUE |
| 72 | + AND call_block_number>={{from_block}} |
| 73 | + AND call_block_number<{{to_block}}) |
| 74 | + UNION |
| 75 | + (SELECT call_block_number, |
| 76 | + -1 AS sell_amount, |
| 77 | + "amountOutMin" AS buy_amount, |
| 78 | + path, |
| 79 | + output_amounts, |
| 80 | + call_tx_hash, |
| 81 | + "to" AS address |
| 82 | + FROM uniswap_v2."Router02_call_swapExactTokensForETH" |
| 83 | + WHERE call_success=TRUE |
| 84 | + AND call_block_number>={{from_block}} |
| 85 | + AND call_block_number<{{to_block}}) |
| 86 | + UNION |
| 87 | + (SELECT call_block_number, |
| 88 | + "amountInMax" AS sell_amount, |
| 89 | + -1 AS buy_amount, |
| 90 | + path, |
| 91 | + output_amounts, |
| 92 | + call_tx_hash, |
| 93 | + "to" AS address |
| 94 | + FROM uniswap_v2."Router02_call_swapTokensForExactETH" |
| 95 | + WHERE call_success=TRUE |
| 96 | + AND call_block_number>={{from_block}} |
| 97 | + AND call_block_number<{{to_block}}) |
| 98 | + ) AS query |
| 99 | + |
| 100 | +INNER JOIN ethereum.transactions ON ethereum.transactions.hash = call_tx_hash |
| 101 | +ORDER BY ethereum.transactions.block_number, ethereum.transactions.index ASC; |
0 commit comments