Skip to content

Commit

Permalink
feat(release): updates to dex.trades, balancer, curve, 1inch, clipper…
Browse files Browse the repository at this point in the history
…, and LBPs

Signed-off-by: sam bacha <sam@manifoldfinance.com>
  • Loading branch information
sambacha committed Aug 14, 2021
1 parent 84c3dfd commit 5dd8115
Show file tree
Hide file tree
Showing 17 changed files with 704 additions and 304 deletions.
18 changes: 0 additions & 18 deletions CHANGELOG.md

This file was deleted.

2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.8.1
v1.8.2
40 changes: 19 additions & 21 deletions dune/balancer/view_swaps.sql
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
CREATE OR REPLACE VIEW balancer.view_swaps AS
SELECT
block_time,
token_a_symbol,
token_b_symbol,
token_a_amount,
token_b_amount,
trader_a,
trader_b,
token_a_amount_raw,
token_b_amount_raw,
usd_amount,
token_a_address,
token_b_address,
exchange_contract_address AS contract_address,
tx_hash,
tx_from,
trace_address,
evt_index
FROM
dex.trades
WHERE
project = 'Balancer';
block_time,
token_a_symbol,
token_b_symbol,
token_a_amount,
token_b_amount,
trader_a,
trader_b,
token_a_amount_raw,
token_b_amount_raw,
usd_amount,
token_a_address,
token_b_address,
exchange_contract_address AS contract_address,
tx_hash,
tx_from,
trace_address,
evt_index
FROM dex.trades
WHERE project = 'Balancer'
36 changes: 18 additions & 18 deletions dune/curvefi/view_trades.sql
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ CREATE OR REPLACE VIEW curvefi.view_trades (
evt_tx_hash AS tx_hash,
NULL::integer[] AS trace_address,
evt_index
FROM curvefi."susd_v2_evt_TokenExchange"
FROM curvefi."susd_swap_evt_TokenExchange"

UNION

Expand Down Expand Up @@ -64,7 +64,7 @@ SELECT
evt_tx_hash AS tx_hash,
NULL::integer[] AS trace_address,
evt_index
FROM curvefi."susd_v2_evt_TokenExchangeUnderlying"
FROM curvefi."susd_swap_evt_TokenExchangeUnderlying"

UNION

Expand Down Expand Up @@ -208,7 +208,7 @@ SELECT
evt_tx_hash AS tx_hash,
NULL::integer[] AS trace_address,
evt_index
FROM curvefi."compound_v3_evt_TokenExchange"
FROM curvefi."compound_swap_evt_TokenExchange"

UNION

Expand All @@ -232,7 +232,7 @@ SELECT
evt_tx_hash AS tx_hash,
NULL::integer[] AS trace_address,
evt_index
FROM curvefi."compound_v3_evt_TokenExchangeUnderlying"
FROM curvefi."compound_swap_evt_TokenExchangeUnderlying"

UNION

Expand All @@ -258,7 +258,7 @@ SELECT
evt_tx_hash AS tx_hash,
NULL::integer[] AS trace_address,
evt_index
FROM curvefi."usdt_evt_TokenExchange"
FROM curvefi."usdt_swap_evt_TokenExchange"

UNION

Expand All @@ -284,7 +284,7 @@ SELECT
evt_tx_hash AS tx_hash,
NULL::integer[] AS trace_address,
evt_index
FROM curvefi."usdt_evt_TokenExchangeUnderlying"
FROM curvefi."usdt_swap_evt_TokenExchangeUnderlying"

UNION

Expand Down Expand Up @@ -312,7 +312,7 @@ SELECT
evt_tx_hash AS tx_hash,
NULL::integer[] AS trace_address,
evt_index
FROM curvefi."y_evt_TokenExchange"
FROM curvefi."y_swap_evt_TokenExchange"

UNION

Expand Down Expand Up @@ -340,7 +340,7 @@ SELECT
evt_tx_hash AS tx_hash,
NULL::integer[] AS trace_address,
evt_index
FROM curvefi."y_evt_TokenExchangeUnderlying"
FROM curvefi."y_swap_evt_TokenExchangeUnderlying"

UNION

Expand Down Expand Up @@ -368,7 +368,7 @@ SELECT
evt_tx_hash AS tx_hash,
NULL::integer[] AS trace_address,
evt_index
FROM curvefi."busd_evt_TokenExchange"
FROM curvefi."busd_swap_evt_TokenExchange"

UNION

Expand Down Expand Up @@ -396,7 +396,7 @@ SELECT
evt_tx_hash AS tx_hash,
NULL::integer[] AS trace_address,
evt_index
FROM curvefi."busd_evt_TokenExchangeUnderlying"
FROM curvefi."busd_swap_evt_TokenExchangeUnderlying"

UNION

Expand Down Expand Up @@ -424,7 +424,7 @@ SELECT
evt_tx_hash AS tx_hash,
NULL::integer[] AS trace_address,
evt_index
FROM curvefi."pax_evt_TokenExchange"
FROM curvefi."pax_swap_evt_TokenExchange"

UNION

Expand Down Expand Up @@ -452,7 +452,7 @@ SELECT
evt_tx_hash AS tx_hash,
NULL::integer[] AS trace_address,
evt_index
FROM curvefi."pax_evt_TokenExchangeUnderlying"
FROM curvefi."pax_swap_evt_TokenExchangeUnderlying"

UNION

Expand All @@ -478,7 +478,7 @@ SELECT
evt_tx_hash AS tx_hash,
NULL::integer[] AS trace_address,
evt_index
FROM curvefi."renbtc_evt_TokenExchange"
FROM curvefi."ren_swap_evt_TokenExchange"

UNION

Expand Down Expand Up @@ -506,7 +506,7 @@ SELECT
evt_tx_hash AS tx_hash,
NULL::integer[] AS trace_address,
evt_index
FROM curvefi."sbtc_evt_TokenExchange"
FROM curvefi."sbtc_swap_evt_TokenExchange"

UNION

Expand All @@ -532,7 +532,7 @@ SELECT
evt_tx_hash AS tx_hash,
NULL::integer[] AS trace_address,
evt_index
FROM curvefi."hbtc_evt_TokenExchange"
FROM curvefi."hbtc_swap_evt_TokenExchange"

UNION

Expand All @@ -558,7 +558,7 @@ SELECT
evt_tx_hash AS tx_hash,
NULL::integer[] AS trace_address,
evt_index
FROM curvefi."dai_usdc_usdt_evt_TokenExchange"
FROM curvefi."threepool_swap_evt_TokenExchange"

UNION

Expand All @@ -582,7 +582,7 @@ SELECT
evt_tx_hash AS tx_hash,
NULL::integer[] AS trace_address,
evt_index
FROM curvefi."steth_evt_TokenExchange"
FROM curvefi."steth_swap_evt_TokenExchange"

UNION

Expand All @@ -608,4 +608,4 @@ SELECT
evt_tx_hash AS tx_hash,
NULL::integer[] AS trace_address,
evt_index
FROM curvefi."tricrypto_evt_TokenExchange"
FROM curvefi."tricrypto_swap_evt_TokenExchange"
25 changes: 25 additions & 0 deletions dune/dex/trades/insert_1inch.sql
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,31 @@ WITH rows AS (
FROM oneinch."LimitOrderProtocol_call_fillOrder" call
LEFT JOIN ethereum.traces ts ON call_tx_hash = ts.tx_hash AND call_trace_address = ts.trace_address
WHERE call_success

UNION ALL

-- 1inch Limit Order Protocol RFQ
SELECT
call_block_time as block_time,
'1inch Limit Order Protocol' AS project,
'RFQ v1' AS version,
'DEX' AS category,
ts."from" AS trader_a,
decode(substring("order"::jsonb->>'makerAssetData' from 35 for 40), 'hex') AS trader_b,
bytea2numeric(substring(tf2.input from 69 for 32)) AS token_a_amount_raw,
bytea2numeric(substring(tf1.input from 69 for 32)) AS token_b_amount_raw,
NULL::numeric AS usd_amount,
decode(substring("order"::jsonb->>'takerAsset' from 3), 'hex') AS token_a_address,
decode(substring("order"::jsonb->>'makerAsset' from 3), 'hex') AS token_b_address,
contract_address AS exchange_contract_address,
call_tx_hash,
call_trace_address,
NULL AS evt_index
FROM oneinch."LimitOrderProtocol_call_fillOrderRFQ" call
LEFT JOIN ethereum.traces ts ON call_tx_hash = ts.tx_hash AND ts.trace_address = call_trace_address
LEFT JOIN ethereum.traces tf1 ON call_tx_hash = tf1.tx_hash AND tf1.trace_address = COALESCE(call_trace_address, '{}') || (ts.sub_traces-2)
LEFT JOIN ethereum.traces tf2 ON call_tx_hash = tf2.tx_hash AND tf2.trace_address = COALESCE(call_trace_address, '{}') || (ts.sub_traces-1)
WHERE call_success
) dexs
INNER JOIN ethereum.transactions tx
ON dexs.tx_hash = tx.hash
Expand Down
1 change: 1 addition & 0 deletions dune/dex/trades/trades.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ CREATE INDEX IF NOT EXISTS dex_trades_block_time_idx ON dex.trades USING BRIN (b
CREATE INDEX IF NOT EXISTS dex_trades_token_a_idx ON dex.trades (token_a_address);
CREATE INDEX IF NOT EXISTS dex_trades_token_b_idx ON dex.trades (token_b_address);
CREATE INDEX IF NOT EXISTS dex_trades_block_time_project_idx ON dex.trades (block_time, project);
CREATE INDEX CONCURRENTLY IF NOT EXISTS dex_trades_usd_amount_idx ON dex.trades (usd_amount);
3 changes: 2 additions & 1 deletion dune/nft/trades/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ This repo collects trade data of NFT marketplaces in a single table `nft.trades`

The goal is to enable a powerful new wave of Dune dashboards on NFTs, and inspire new contributors to add more marketplaces and NFT data.

ERC721 and ERC1155 `transfer` data is integrated for every trade transaction to enable analysis of trades consisting of multiple NFTs.

Known limitations:
- OpenSea and Rarible support non-ETH trades. Some of the tokens used for these transactions are not in Dune's `prices.usd`. In these cases, the `usd_amount` is `NULL`. At the time of writing (July 2021), for OpenSea and Rarible, the percentage of rows with missing USD values is 2% or less.
- Some column data for less common trades such as bundle sales or multiple transfers in one transaction will be incorrect e.g. the column `nft_token_id`. On the tests we did, the `buyer` and `amount` fields were correct.
- In some cases, there are rounding errors on the `original_amount` fields.


Expand Down

0 comments on commit 5dd8115

Please sign in to comment.