From c86697ef8da163d6fa16df5765e7915ebaedded2 Mon Sep 17 00:00:00 2001 From: Eric Laurello Date: Wed, 6 Sep 2023 08:46:59 -0400 Subject: [PATCH] fix swap logic with chain upgrade --- models/silver/defi/silver__swaps.sql | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/models/silver/defi/silver__swaps.sql b/models/silver/defi/silver__swaps.sql index d47dd17..695a2c8 100644 --- a/models/silver/defi/silver__swaps.sql +++ b/models/silver/defi/silver__swaps.sql @@ -90,6 +90,8 @@ pre_final AS ( b.value :tokenOutMinAmount :: NUMBER, b.value :token_out_min_amount :: NUMBER ) AS to_amount, + b.value :token_in :amount :: NUMBER from_amount, + b.value :token_in :denom :: STRING from_currency, b.value :routes AS routes, _inserted_timestamp, b.index AS _body_index @@ -307,10 +309,19 @@ pre_final2 AS ( p.tx_id, tx_succeeded, trader, - f.from_amount, - f.from_currency, + COALESCE( + f.from_amount, + p.from_amount + ) AS from_amount, + COALESCE( + f.from_currency, + p.from_currency + ) AS from_currency, CASE - WHEN f.from_currency LIKE 'gamm/pool/%' THEN 18 + WHEN COALESCE( + f.from_currency, + p.from_currency + ) LIKE 'gamm/pool/%' THEN 18 ELSE l.decimal END AS from_decimal, tt.to_amount, @@ -337,7 +348,10 @@ pre_final2 AS ( ON tt.to_currency = A.address LEFT OUTER JOIN {{ ref('silver__asset_metadata') }} l - ON f.from_currency = l.address + ON COALESCE( + f.from_currency, + p.from_currency + ) = l.address ) SELECT block_id,