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

feat: add flokibot evm bot trades spellbook #7214

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
060a584
chore: add pepeboost to dex_evm.bot_trades
whalehunting Nov 30, 2024
836f0b7
fix: remove trailing commas
whalehunting Nov 30, 2024
e8ac96f
chore: add seeds + seed schema
whalehunting Nov 30, 2024
9e914cf
feat: add flokibot ethereum spellbook
whalehunting Nov 30, 2024
eca35ef
fix: typo
whalehunting Nov 30, 2024
ff0b4a4
fix: typo
whalehunting Nov 30, 2024
a46d703
fix: typo
whalehunting Nov 30, 2024
9bad2c9
chore: format with sqlfmt
whalehunting Nov 30, 2024
2041dbb
chore: add aggregator trades and fee payments
whalehunting Nov 30, 2024
3a1a43c
refactor: get fees from treasury + buyback fee deposits
whalehunting Nov 30, 2024
63e75b0
fix: use source syntax
whalehunting Nov 30, 2024
d542e67
fix: add block_time to deployed routers
whalehunting Nov 30, 2024
9637d92
fix: remove block_number for routers
whalehunting Nov 30, 2024
dc95c3f
fix: typo
whalehunting Nov 30, 2024
6eba811
test: add ethereum seed
whalehunting Nov 30, 2024
69b9a5c
fix: sum fees per tx to avoid duplicates
whalehunting Dec 1, 2024
7df91e7
test: add seed
whalehunting Dec 1, 2024
d674f74
feat: add base spellbook
whalehunting Dec 1, 2024
9c9dec1
fix: do not escape blockchain
whalehunting Dec 1, 2024
1f00bae
fix: typo
whalehunting Dec 1, 2024
7084d15
fix: typo
whalehunting Dec 1, 2024
0cf1f68
chore: add base schema
whalehunting Dec 1, 2024
666d7d4
test: add base seed
whalehunting Dec 1, 2024
b0d0946
feat: add bnb spellbook + schema
whalehunting Dec 1, 2024
94352d3
fix: correct base deployers + start date
whalehunting Dec 1, 2024
b9e4ed6
fix: add source for openocean bnb
whalehunting Dec 1, 2024
5e09e86
test: add bnb seed file
whalehunting Dec 1, 2024
8643524
Merge branch 'main' into feat-add-flokibot-bot-trades-spellbook
jeff-dude Dec 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 57 additions & 1 deletion dbt_subprojects/dex/models/bot_trades/_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ models:
- check_bot_trades_seed:
seed_file: ref('banana_gun_base_trades_seed')


- name: pepeboost_ethereum_bot_trades
meta:
blockchain: ethereum
Expand All @@ -150,3 +149,60 @@ models:
- evt_index
- check_bot_trades_seed:
seed_file: ref('pepeboost_ethereum_trades_seed')

- name: flokibot_ethereum_bot_trades
meta:
blockchain: ethereum
sector: dex
project: flokibot
contributors: whale_hunter
config:
tags: ["evm", "dex", "flokibot", "trades"]
description: >
Flokibot trades on Ethereum
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- blockchain
- tx_hash
- evt_index
- check_bot_trades_seed:
seed_file: ref('flokibot_ethereum_trades_seed')

- name: flokibot_base_bot_trades
meta:
blockchain: base
sector: dex
project: flokibot
contributors: whale_hunter
config:
tags: ["evm", "dex", "flokibot", "trades"]
description: >
Flokibot trades on Base
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- blockchain
- tx_hash
- evt_index
- check_bot_trades_seed:
seed_file: ref('flokibot_base_trades_seed')

- name: flokibot_bnb_bot_trades
meta:
blockchain: bnb
sector: dex
project: flokibot
contributors: whale_hunter
config:
tags: ["evm", "dex", "flokibot", "trades"]
description: >
Flokibot trades on BNB
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- blockchain
- tx_hash
- evt_index
- check_bot_trades_seed:
seed_file: ref('flokibot_bnb_trades_seed')
8 changes: 6 additions & 2 deletions dbt_subprojects/dex/models/bot_trades/dex_evm_bot_trades.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@


{% set evm_trading_bots = [
ref('banana_gun_ethereum_bot_trades')
,ref('banana_gun_base_bot_trades')
ref('banana_gun_base_bot_trades')
,ref('banana_gun_ethereum_bot_trades')
,ref('pepeboost_ethereum_bot_trades')
,ref('flokibot_base_bot_trades')
,ref('flokibot_bnb_bot_trades')
,ref('flokibot_ethereum_bot_trades')
] %}

{% for bot in evm_trading_bots %}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
{{
config(
alias='bot_trades',
schema='flokibot_base',
partition_by=['block_month'],
materialized='incremental',
file_format='delta',
incremental_strategy='merge',
incremental_predicates=[
incremental_predicate('DBT_INTERNAL_DEST.block_time')
],
unique_key=['blockchain', 'tx_hash', 'evt_index'],
)
}}

{% set project_name = 'Floki Trading Bot' %}
{% set project_start_date = '2024-02-13' %}
{% set blockchain = 'base' %}
{% set bot_deployer_1 = '0xdeb9e55e0f20bc59029271372ecea50e67182a3a' %}
{% set bot_deployer_2 = '0xcE6a13955EC32B6B1b7EBe089302b536Ad40aeC3' %}
{% set treasury_fee_wallet_1 = '0xc69df57dbb39e52d5836753e6abb71a9ab271c2d' %}
{% set treasury_fee_wallet_2 = '0x800E2f14a25Ae52300209b2D7Fb45cC27ae91a9d' %}
{% set buyback_fee_wallet_1 = '0xCc5374Be204990A3205EB9f93C5bD37B4f8e2c5e' %}
{% set aggregator_fee_wallet_1 = '0x7b41114eCB5C09d483343116C229Be3d3eb3b0fC' %}
{% set weth = '0x4200000000000000000000000000000000000006' %}
{% set fee_token_symbol = 'ETH' %}

with
bot_contracts as (
select block_time, address
from {{ source('base', 'creation_traces') }}
where
("from" = {{ bot_deployer_1 }} or "from" = {{ bot_deployer_2 }})
and block_time >= timestamp '{{project_start_date}}'
),
fees as (
select sum(value) / 1e18 as fee_token_amount, tx_hash
from {{ source('base', 'traces') }}
where
(
to = {{ treasury_fee_wallet_1 }}
or to = {{ treasury_fee_wallet_2 }}
or to = {{ buyback_fee_wallet_1 }}
)
and tx_success = true
and value > 0
{% if is_incremental() %}
and {{ incremental_predicate('block_time') }}
{% else %} and block_time >= timestamp '{{project_start_date}}'
{% endif %}
group by tx_hash
),
oneinch_aggregator_trades as (
select call_block_time as block_time, call_tx_hash as tx_hash
from {{ source('oneinch_base', 'AggregationRouterV6_call_swap') }}
where
(
varbinary_position(data, {{ aggregator_fee_wallet_1 }}) > 0
or varbinary_position(data, {{ treasury_fee_wallet_2 }}) > 0
)
and call_success
{% if is_incremental() %}
and {{ incremental_predicate('call_block_time') }}
{% else %} and call_block_time >= timestamp '{{project_start_date}}'
{% endif %}
),
trade_transactions as (
select block_time, address, null as tx_hash
from bot_contracts
union all
select block_time, null as address, tx_hash
from oneinch_aggregator_trades
),
bot_trades as (
select
trades.block_time,
trades.block_number,
amount_usd,
if(token_sold_address = {{ weth }}, 'Buy', 'Sell') as type,
token_bought_amount,
token_bought_symbol,
token_bought_address,
token_sold_amount,
token_sold_symbol,
token_sold_address,
fee_token_amount,
'{{fee_token_symbol}}' as fee_token_symbol,
{{ weth }} as fee_token_address,
project,
version,
token_pair,
project_contract_address,
tx_from as user,
tx_to as bot,
trades.tx_hash,
evt_index
from {{ source('dex', 'trades') }} as trades
join trade_transactions ON (
(
trades.tx_to = trade_transactions.address
OR trades.tx_hash = trade_transactions.tx_hash
)
AND trades.block_time >= trade_transactions.block_time
)
left join fees on fees.tx_hash = trades.tx_hash
where
trades.blockchain = '{{blockchain}}'
{% if is_incremental() %}
and {{ incremental_predicate('trades.block_time') }}
{% else %} and trades.block_time >= timestamp '{{project_start_date}}'
{% endif %}
),
highest_event_index_for_each_trade as (
select tx_hash, max(evt_index) as highest_event_index
from bot_trades
group by tx_hash
)
select
block_time,
date_trunc('day', bot_trades.block_time) as block_date,
date_trunc('month', bot_trades.block_time) as block_month,
'{{project_name}}' as bot,
block_number,
'{{blockchain}}' as blockchain,
-- Trade
amount_usd,
type,
token_bought_amount,
token_bought_symbol,
token_bought_address,
token_sold_amount,
token_sold_symbol,
token_sold_address,
-- Fees
round(
fee_token_amount * price / cast(amount_usd as double),
4 -- Round feePercentage to 0.01% steps
) as fee_percentage_fraction,
fee_token_amount * price as fee_usd,
fee_token_amount,
'{{fee_token_symbol}}' as fee_token_symbol,
fee_token_address,
-- Dex
project,
version,
token_pair,
project_contract_address,
-- User
user as user,
bot_trades.tx_hash,
evt_index,
if(evt_index = highest_event_index, true, false) as is_last_trade_in_transaction
from bot_trades
join
highest_event_index_for_each_trade
on bot_trades.tx_hash = highest_event_index_for_each_trade.tx_hash
left join
{{ source('prices', 'usd') }}
on (
blockchain = '{{blockchain}}'
and contract_address = {{ weth }}
and minute = date_trunc('minute', block_time)
{% if is_incremental() %} and {{ incremental_predicate('minute') }} {% endif %}
)
order by block_time desc, evt_index desc
Loading
Loading