Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make bonkbot spellbook entries unique again #7083

Merged
merged 10 commits into from
Nov 14, 2024
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{{ config(
alias = 'bot_trades',
schema = 'bonkbot_solana',
tags = ['prod_exclude'],
partition_by = ['block_month'],
materialized = 'incremental',
file_format = 'delta',
Expand Down Expand Up @@ -63,6 +62,33 @@ WITH
tx_id,
fee_token_mint_address
),
solFeePayments AS (
SELECT
*
FROM
allFeePayments
WHERE
feeTokenType = 'SOL'
),
splFeePayments AS (
SELECT
*
FROM
allFeePayments
WHERE
feeTokenType = 'SPL'
),
-- Eliminate duplicates (e.g. both SOL + SPL payment in a single transaction)
allFeePaymentsWithSOLPaymentPreferred AS (
SELECT
COALESCE(solFeePayments.tx_id, splFeePayments.tx_id) AS tx_id,
COALESCE(solFeePayments.feeTokenType, splFeePayments.feeTokenType) AS feeTokenType,
COALESCE(solFeePayments.fee_token_amount, splFeePayments.fee_token_amount) AS fee_token_amount,
COALESCE(solFeePayments.fee_token_mint_address, splFeePayments.fee_token_mint_address) AS fee_token_mint_address
FROM
solFeePayments
FULL JOIN splFeePayments ON solFeePayments.tx_id = splFeePayments.tx_id
),
botTrades AS (
SELECT
trades.block_time,
Expand Down Expand Up @@ -96,7 +122,7 @@ WITH
inner_instruction_index
FROM
{{ ref('dex_solana_trades') }} AS trades
JOIN allFeePayments AS feePayments ON trades.tx_id = feePayments.tx_id
JOIN allFeePaymentsWithSOLPaymentPreferred AS feePayments ON trades.tx_id = feePayments.tx_id
LEFT JOIN {{ source('prices', 'usd') }} AS feeTokenPrices ON (
feeTokenPrices.blockchain = 'solana'
AND fee_token_mint_address = toBase58 (feeTokenPrices.contract_address)
Expand Down
Loading