Skip to content

Commit 26df65a

Browse files
Fix GMX Arbitrum order updated merge fanout (#9814)
* Fix GMX Arbitrum order updated merge fanout Co-authored-by: tomfutago <tomfutago@users.noreply.github.com> * fix: choose deterministic GMX order created market Co-authored-by: Cursor <cursoragent@cursor.com> * fix: simplify GMX order market selection Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: tomfutago <tomfutago@users.noreply.github.com>
1 parent 21b93da commit 26df65a

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

dbt_subprojects/hourly_spellbook/models/_project/gmx/event/arbitrum/gmx_v2_arbitrum_order_updated.sql

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,25 @@ WITH evt_data_1 AS (
201201
AND ED.block_date = EDP.block_date
202202
)
203203

204+
, order_created_for_update AS (
205+
SELECT
206+
ED.block_date,
207+
ED.tx_hash,
208+
ED.index,
209+
MAX_BY(OC.market, (OC.block_number, OC.index)) AS market
210+
FROM event_data AS ED
211+
LEFT JOIN {{ ref('gmx_v2_arbitrum_order_created') }} AS OC
212+
ON ED.key = OC.key
213+
AND (
214+
OC.block_number < ED.block_number
215+
OR (
216+
OC.block_number = ED.block_number
217+
AND OC.index <= ED.index
218+
)
219+
)
220+
GROUP BY ED.block_date, ED.tx_hash, ED.index
221+
)
222+
204223
-- full data
205224
, full_data AS (
206225
SELECT
@@ -240,8 +259,10 @@ WITH evt_data_1 AS (
240259
ED.tx_to
241260

242261
FROM event_data AS ED
243-
LEFT JOIN {{ ref('gmx_v2_arbitrum_order_created') }} AS OC
244-
ON ED.key = OC.key
262+
LEFT JOIN order_created_for_update AS OC
263+
ON ED.block_date = OC.block_date
264+
AND ED.tx_hash = OC.tx_hash
265+
AND ED.index = OC.index
245266
LEFT JOIN {{ ref('gmx_v2_arbitrum_markets_data') }} AS MD
246267
ON OC.market = MD.market
247268

0 commit comments

Comments
 (0)