-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add banana gun sonic trades spellbook
- Loading branch information
1 parent
5236549
commit 7bfca02
Showing
4 changed files
with
239 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
196 changes: 196 additions & 0 deletions
196
dbt_subprojects/dex/models/bot_trades/banana_gun/sonic/banana_gun_sonic_bot_trades.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
{{ config( | ||
alias = 'bot_trades', | ||
schema = 'banana_gun_sonic', | ||
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 = 'Banana Gun' %} | ||
{% set project_start_date = '2024-12-10' %} | ||
{% set blockchain = 'sonic' %} | ||
{% set bot_deployer_1 = '0x37aAb97476bA8dC785476611006fD5dDA4eed66B' %} | ||
{% set wrapped_sonic = '0x039e2fb66102314ce7b64ce5ce3e5183bc94ad38' %} | ||
{% set fee_token_symbol = 'S' %} | ||
|
||
WITH | ||
botContracts AS ( | ||
SELECT | ||
address | ||
FROM | ||
{{ source('sonic','creation_traces') }} | ||
WHERE | ||
( | ||
"from" = {{bot_deployer_1}} | ||
) | ||
AND block_time >= TIMESTAMP '{{project_start_date}}' | ||
), | ||
botTrades AS ( | ||
SELECT | ||
trades.block_time, | ||
amount_usd, | ||
IF( | ||
token_sold_address = {{wrapped_sonic}}, | ||
'Buy', | ||
'Sell' | ||
) AS type, | ||
token_bought_amount, | ||
token_bought_symbol, | ||
token_bought_address, | ||
token_sold_amount, | ||
token_sold_symbol, | ||
token_sold_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 botContracts ON trades.tx_to = botContracts.address | ||
WHERE | ||
trades.blockchain = '{{blockchain}}' | ||
{% if is_incremental() %} | ||
AND {{ incremental_predicate('trades.block_time') }} | ||
{% else %} | ||
AND trades.block_time >= TIMESTAMP '{{project_start_date}}' | ||
{% endif %} | ||
), | ||
highestEventIndexForEachTrade AS ( | ||
SELECT | ||
tx_hash, | ||
MAX(evt_index) AS highestEventIndex | ||
FROM | ||
botTrades | ||
GROUP BY | ||
tx_hash | ||
), | ||
botSONICDeposits AS ( | ||
SELECT | ||
tx_hash, | ||
block_number, | ||
CAST(value AS DECIMAL (38, 0)) AS deltaGwei, | ||
CAST(value AS DECIMAL (38, 0)) AS depositGwei | ||
FROM | ||
{{ source('sonic','traces') }} | ||
JOIN botContracts ON to = botContracts.address | ||
WHERE | ||
{% if is_incremental() %} | ||
{{ incremental_predicate('block_time') }} | ||
{% else %} | ||
block_time >= TIMESTAMP '{{project_start_date}}' | ||
{% endif %} | ||
AND value > CAST(0 AS UINT256) | ||
), | ||
botSONICWithdrawals AS ( | ||
SELECT | ||
tx_hash, | ||
block_number, | ||
CAST(value AS DECIMAL (38, 0)) * -1 AS deltaGwei, | ||
0 AS depositGwei, | ||
block_hash, | ||
to | ||
FROM | ||
{{ source('sonic','traces') }} | ||
JOIN botContracts ON "from" = botContracts.address | ||
WHERE | ||
{% if is_incremental() %} | ||
{{ incremental_predicate('block_time') }} | ||
{% else %} | ||
block_time >= TIMESTAMP '{{project_start_date}}' | ||
{% endif %} | ||
AND value > CAST(0 AS UINT256) | ||
), | ||
botSONICTransfers AS ( | ||
/* Deposits */ | ||
( | ||
SELECT | ||
tx_hash, | ||
block_number, | ||
deltaGwei, | ||
depositGwei | ||
FROM | ||
botSONICDeposits | ||
) | ||
UNION ALL | ||
/* Withdrawals */ | ||
( | ||
SELECT | ||
tx_hash, | ||
block_number, | ||
deltaGwei, | ||
depositGwei | ||
FROM | ||
botSONICWithdrawals | ||
) | ||
), | ||
botSONICDeltas AS ( | ||
SELECT | ||
tx_hash, | ||
block_number, | ||
SUM(deltaGwei) AS feeGwei, | ||
SUM(depositGwei) AS depositGwei | ||
FROM | ||
botSONICTransfers | ||
GROUP BY | ||
tx_hash, | ||
block_number | ||
) | ||
SELECT | ||
block_time, | ||
date_trunc('day', botTrades.block_time) as block_date, | ||
date_trunc('month', botTrades.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( | ||
CAST(feeGwei AS DOUBLE) / CAST(depositGwei AS DOUBLE), | ||
/* Round feePercentage to 0.01% steps */ | ||
4 | ||
) AS fee_percentage_fraction, | ||
(feeGwei / 1e18) * price AS fee_usd, | ||
feeGwei / 1e18 fee_token_amount, | ||
'{{fee_token_symbol}}' AS fee_token_symbol, | ||
{{wrapped_sonic}} AS fee_token_address, | ||
-- Dex | ||
project, | ||
version, | ||
token_pair, | ||
project_contract_address, | ||
-- User | ||
user, | ||
botTrades.tx_hash, | ||
evt_index, | ||
IF(evt_index = highestEventIndex, true, false) AS is_last_trade_in_transaction | ||
FROM | ||
botTrades | ||
JOIN highestEventIndexForEachTrade ON botTrades.tx_hash = highestEventIndexForEachTrade.tx_hash | ||
LEFT JOIN botSONICDeltas ON botTrades.tx_hash = botSONICDeltas.tx_hash | ||
LEFT JOIN {{ source('prices', 'usd') }} ON ( | ||
blockchain = '{{blockchain}}' | ||
AND contract_address = {{wrapped_sonic}} | ||
AND minute = DATE_TRUNC('minute', block_time) | ||
{% if is_incremental() %} | ||
AND {{ incremental_predicate('minute') }} | ||
{% endif %} | ||
) | ||
ORDER BY | ||
block_time DESC, | ||
evt_index DESC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
dbt_subprojects/dex/seeds/bot_trades/banana_gun/banana_gun_sonic_trades_seed.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
block_time,block_date,block_month,bot,block_number,blockchain,amount_usd,type,token_bought_amount,token_bought_symbol,token_bought_address,token_sold_amount,token_sold_symbol,token_sold_address,fee_percentage_fraction,fee_usd,fee_token_amount,fee_token_symbol,fee_token_address,project,version,token_pair,project_contract_address,user,tx_hash,evt_index,is_last_trade_in_transaction | ||
2024-09-07 08:46:55.000 UTC,2024-09-07 00:00:00.000 UTC,2024-09-01 00:00:00.000 UTC,Banana Gun,19454734,base,3441.57,Sell,1.5,WETH,0x4200000000000000000000000000000000000006,206629.39352997296,MIGGLES,0xb1a03eda10342529bbf8eb700a06c60441fef25d,0.005,34.4157,0.015,ETH,0x4200000000000000000000000000000000000006,uniswap,2,MIGGLES-WETH,0x17a3ad8c74c4947005afeda9965305ae2eb2518a,0x40237a6d80e9a4d9cd8341c5ad42ce3733b822c1,0xda8352e2a41cc3d5793e2211816d7c234ddad30db2b97860f4b6c26be6d5aa67,7,true | ||
2024-09-01 14:10:41.000 UTC,2024-09-01 00:00:00.000 UTC,2024-09-01 00:00:00.000 UTC,Banana Gun,19205247,base,48.757227722772264,Buy,836176.1213013215,DarkPepePope,0xdc3793eab4681e57b2755783403b3dcc573f220b,0.0198019801980198,WETH,0x4200000000000000000000000000000000000006,0.005,0.48757227722772517,0.000198019801980199,ETH,0x4200000000000000000000000000000000000006,uniswap,2,DarkPepePope-WETH,0x67a45158523835d8477a1877c756c7b8c252d722,0x117c921e599ee1c4f73fe74b08ca584db08475e4,0x25c17e72dc3ede0eec14d4e34b198a7b6854904e8bd862af99814d28e4566204,12,true | ||
2024-09-01 14:10:41.000 UTC,2024-09-01 00:00:00.000 UTC,2024-09-01 00:00:00.000 UTC,Banana Gun,19205247,base,731.358415841584,Buy,538747.542958548,MUNCHER,0xdcce6d3d2f6fe2e9201de68422f7568610b39860,0.297029702970297,WETH,0x4200000000000000000000000000000000000006,0.005,7.313584158415843,0.002970297029702971,ETH,0x4200000000000000000000000000000000000006,uniswap,2,MUNCHER-WETH,0x3be1dd1c8f859fc49f1da72b1d1328b6595a297d,0x56714990cef7019a7ee8a5bc0e8e6ad991aa76e5,0x0ee0458c7dd96ee1125196cbdb414f31de5c2ab6561ec05be72c791359264e3a,5,true | ||
2024-09-10 09:14:03.000 UTC,2024-09-10 00:00:00.000 UTC,2024-09-01 00:00:00.000 UTC,Banana Gun,19585148,base,349.26831683168314,Buy,9105325812.505402,D.O.G.E,0x755b004d7d5dc8fdc92c39333134811e3a69955d,0.1485148514851485,WETH,0x4200000000000000000000000000000000000006,0.005,3.4926831683168333,0.001485148514851486,ETH,0x4200000000000000000000000000000000000006,uniswap,2,D.O.G.E-WETH,0x45b992355d1fa3c5c50ba446c90b578a7b779433,0xaaf1df00167fe59d43c8d1944a6f28aaf8f40f83,0xf09148ffe271bfe5d28c3547362073257ce0d2bb86e6ef788fe6195247441a43,4,true | ||
2024-09-06 15:51:25.000 UTC,2024-09-06 00:00:00.000 UTC,2024-09-01 00:00:00.000 UTC,Banana Gun,19424269,base,112.36625779738371,Sell,0.048872106175385115,WETH,0x4200000000000000000000000000000000000006,1027321.7559139789,UBPS,0x0c90c756350fb803a7d5d9f9ee5ac29e77369973,0.005,1.1236625779738343,0.00048872106175385,ETH,0x4200000000000000000000000000000000000006,uniswap,2,UBPS-WETH,0x4557eacd191e266d4166c603131ef3b006836cae,0x24acc9d9517c1ccfd7ffeaaefbc8666a582fc64b,0xdf164d9670faa4429521a5339a0676d7f47c74817a86fd03cf85fb8e9083757c,9,true | ||
2024-09-05 05:14:37.000 UTC,2024-09-05 00:00:00.000 UTC,2024-09-01 00:00:00.000 UTC,Banana Gun,19361965,base,4.844921559141894,Sell,0.002009432065639148,WETH,0x4200000000000000000000000000000000000006,74784.28391180358,BARIO,0x814fe70e85025bec87d4ad3f3b713bdcaac0579b,0.005,0.04844921559141778,0.000020094320656391,ETH,0x4200000000000000000000000000000000000006,uniswap,3,BARIO-WETH,0x19efcd30370cd4858df84415d9b63eda2048ef27,0x012cd7fb379b72d4c19988d377c3076aa81583a6,0xca1fd9509fd36d1eb4174857b14bfb9dd1fe8ab18fc31c61ad5425301c9b9017,2,true | ||
2024-09-04 00:57:23.000 UTC,2024-09-04 00:00:00.000 UTC,2024-09-01 00:00:00.000 UTC,Banana Gun,19311048,base,0.4824217821782178,Buy,26.822871758695317,MIGGLES,0xb1a03eda10342529bbf8eb700a06c60441fef25d,0.000198019801980198,WETH,0x4200000000000000000000000000000000000006,0.005,0.004824217821782226,0.000001980198019802,ETH,0x4200000000000000000000000000000000000006,uniswap,2,MIGGLES-WETH,0x17a3ad8c74c4947005afeda9965305ae2eb2518a,0xbd5ce37cf9c61d781b28ba8c1d612e12f6507243,0x70166ba1b17ce988996e5240a8fd71021e716b29863236a468c636ededbe5b18,35,true | ||
2024-09-05 16:51:15.000 UTC,2024-09-05 00:00:00.000 UTC,2024-09-01 00:00:00.000 UTC,Banana Gun,19382864,base,141.05584158415843,Buy,16561085558.942457,PEPE,0x52b492a33e447cdb854c7fc19f1e57e8bfa1777d,0.05940594059405941,WETH,0x4200000000000000000000000000000000000006,0.005,1.4105584158415865,0.000594059405940595,ETH,0x4200000000000000000000000000000000000006,uniswap,3,PEPE-WETH,0x0fb597d6cfe5be0d5258a7f017599c2a4ece34c7,0xa7650835f35c4997f93a9e3bb40bc6c0ba8d059d,0x49b82a258a59bd179c4da535038bad40186d59224c431e7fad34a0adf50bf68a,3,true | ||
2024-09-05 22:16:21.000 UTC,2024-09-05 00:00:00.000 UTC,2024-09-01 00:00:00.000 UTC,Banana Gun,19392617,base,117.19306930693071,Buy,8673078.991486527,XRAY,0x3c48ae7b78bf9ba91fc8e5f6f6bf9f089f278328,0.04950495049504951,WETH,0x4200000000000000000000000000000000000006,0.005,1.1719306930693094,0.000495049504950496,ETH,0x4200000000000000000000000000000000000006,uniswap,2,WETH-XRAY,0xb924036f602fa75f0d4ac9545ee4d6d00261c8ad,0xc4dd8211988263c932c0afb59677dd92ab898046,0x6fcd2bc0c758a0aff18c18069a13173f90e7455ed93d8f5317ff62d78dd1cf61,11,true | ||
2024-09-05 21:22:43.000 UTC,2024-09-05 00:00:00.000 UTC,2024-09-01 00:00:00.000 UTC,Banana Gun,19391008,base,235.0237623762376,Buy,17697.68136626327,WELL,0xa88594d404727625a9437c3f886c7643872296ae,0.09900990099009901,WETH,0x4200000000000000000000000000000000000006,0.005,2.350237623762378,0.000990099009900991,ETH,0x4200000000000000000000000000000000000006,aerodrome,1,WELL-WETH,0x89d0f320ac73dd7d9513ffc5bc58d1161452a657,0x56d0ffbb368ecfb8111a6637fc698d6325e8bc01,0x553bf030f289a28cdb96e4da372ebb3ecf8b138062845edc5266494744d894a3,6,true | ||
2024-09-01 16:31:43.000 UTC,2024-09-01 00:00:00.000 UTC,2024-09-01 00:00:00.000 UTC,Banana Gun,19209478,base,0.23501467838723727,Sell,0.000094977299170814,WETH,0x4200000000000000000000000000000000000006,51.4387631,Nermie,0x519a319e9bb1000c504a20485084df2337c4c14d,0.005,0.0023501467838670776,9.49772991706e-7,ETH,0x4200000000000000000000000000000000000006,sushiswap,1,Nermie-WETH,0xeb5b859dcc061e1e567d89c8ea5bacbe570b6c4e,0x2f0fcdfda8b4065a4d266ddc53c077750e3b485f,0xa203f9e3f43c2288aff00fc6a9f2aea8a3dc6f84f2c32abcd70c8d6a272ba743,10,true | ||
2024-09-01 12:09:59.000 UTC,2024-09-01 00:00:00.000 UTC,2024-09-01 00:00:00.000 UTC,Banana Gun,19201626,base,4959.661963579478,Sell,1.9988723188013517,WETH,0x4200000000000000000000000000000000000006,,,0xc53eb9ecc247465e2e1fb16b2ede3a6446053170,0.005,49.59661963579477,0.01998872318801351,ETH,0x4200000000000000000000000000000000000006,uniswap,2,,0xa854492182dcbda450bcd9ee04870818484dd8ad,0x591be26c53aa3ed600c1c994ecbc2deb545bebb4,0x0c581fc5af9d3a53525f5d31fb09fb9d4dbe5772629ed1c5b2879ad6a59ba30c,11,true | ||
2024-09-01 12:09:59.000 UTC,2024-09-01 00:00:00.000 UTC,2024-09-01 00:00:00.000 UTC,Banana Gun,19201626,base,51.84239373333868,Sell,0.020893828356637105,WETH,0x4200000000000000000000000000000000000006,,,0xc53eb9ecc247465e2e1fb16b2ede3a6446053170,0.005,49.59661963579477,0.01998872318801351,ETH,0x4200000000000000000000000000000000000006,uniswap,2,,0xa854492182dcbda450bcd9ee04870818484dd8ad,0x591be26c53aa3ed600c1c994ecbc2deb545bebb4,0x0c581fc5af9d3a53525f5d31fb09fb9d4dbe5772629ed1c5b2879ad6a59ba30c,3,false | ||
2024-09-04 15:30:23.000 UTC,2024-09-04 00:00:00.000 UTC,2024-09-01 00:00:00.000 UTC,Banana Gun,19337238,base,24.098712871287123,Buy,878817.008049761,TRFY,0xa7ebc5f9b67e790ac0b5d24ed0d531d319cea597,0.0099009900990099,WETH,0x4200000000000000000000000000000000000006,0.005,0.2409871287128737,0.0000990099009901,ETH,0x4200000000000000000000000000000000000006,uniswap,2,TRFY-WETH,0x5f27785b5e2c8263bdec279c75245b980099ac9d,0x64c23d3f619d825bab287f3c52a0f39d3a03c263,0x37c292515191685a193c9400f4fed0ecdc3e1e8dc08e2a527f79cbc000cec727,4,true | ||
2024-09-02 16:30:51.000 UTC,2024-09-02 00:00:00.000 UTC,2024-09-01 00:00:00.000 UTC,Banana Gun,19252652,base,33.64625262721495,Sell,0.013366804770162664,WETH,0x4200000000000000000000000000000000000006,1541948.1284249476,BEE,0xfd09f108d1728e6b6ed241ccd254775e322f1ed6,0.005,0.3364625262721479,0.000133668047701626,ETH,0x4200000000000000000000000000000000000006,uniswap,2,BEE-WETH,0x500e45173f466c058e6dcecd15b27a1e091d92d4,0x64c23d3f619d825bab287f3c52a0f39d3a03c263,0x097dd6b26059fce8166f8fea84aaa12ae13b075cf0d077f717cc1bc31e41ec1b,5,true | ||
2024-09-05 21:11:25.000 UTC,2024-09-05 00:00:00.000 UTC,2024-09-01 00:00:00.000 UTC,Banana Gun,19390669,base,117.3920792079208,Buy,5649267.692887611,COFFEE,0xc54b2b7ee65918a8ec08048cd2377998e7415312,0.04950495049504951,WETH,0x4200000000000000000000000000000000000006,0.005,1.1739207920792103,0.000495049504950496,ETH,0x4200000000000000000000000000000000000006,uniswap,2,COFFEE-WETH,0xe28afb7f1cac4bbf87cd9875aa06f470aec965a4,0xe3ea037ca6ea651cc3f476712b30374c2115e74e,0xdaf6c33941140880d5baff25f8c65f1362048575535d31bff39d07a56ac510ae,11,true | ||
2024-09-05 21:11:25.000 UTC,2024-09-05 00:00:00.000 UTC,2024-09-01 00:00:00.000 UTC,Banana Gun,19390669,base,117.3920792079208,Buy,4982612.726137387,COFFEE,0xc54b2b7ee65918a8ec08048cd2377998e7415312,0.04950495049504951,WETH,0x4200000000000000000000000000000000000006,0.005,1.1739207920792103,0.000495049504950496,ETH,0x4200000000000000000000000000000000000006,uniswap,2,COFFEE-WETH,0xe28afb7f1cac4bbf87cd9875aa06f470aec965a4,0xb73bc3772cf29da413966f36fe18a1dd392cf1b6,0xcc475368ad6c4e6e30df134aaad618fc9fcc9101cf01518c2be3d3170ee11d3c,32,true | ||
2024-09-05 21:11:55.000 UTC,2024-09-05 00:00:00.000 UTC,2024-09-01 00:00:00.000 UTC,Banana Gun,19390684,base,117.3920792079208,Buy,4786468.142259231,COFFEE,0xc54b2b7ee65918a8ec08048cd2377998e7415312,0.04950495049504951,WETH,0x4200000000000000000000000000000000000006,0.005,1.1739207920792103,0.000495049504950496,ETH,0x4200000000000000000000000000000000000006,uniswap,2,COFFEE-WETH,0xe28afb7f1cac4bbf87cd9875aa06f470aec965a4,0xe9869a8c089502b8a8b54b53a9df3ce295a4c17b,0x6909a7e16826cf57cbf3b836e57dcb850150f86902c7d62892db55ab02916947,4,true | ||
2024-09-05 21:11:25.000 UTC,2024-09-05 00:00:00.000 UTC,2024-09-01 00:00:00.000 UTC,Banana Gun,19390669,base,117.3920792079208,Buy,5191072.771597835,COFFEE,0xc54b2b7ee65918a8ec08048cd2377998e7415312,0.04950495049504951,WETH,0x4200000000000000000000000000000000000006,0.005,1.1739207920792103,0.000495049504950496,ETH,0x4200000000000000000000000000000000000006,uniswap,2,COFFEE-WETH,0xe28afb7f1cac4bbf87cd9875aa06f470aec965a4,0xfe906d692a47246518fe05cd5852501bfb51f012,0x2935af8e620e15691ca2b9e5dc78d1179dc2b4222d1835a35d5955d3951c7a36,25,true | ||
2024-09-05 21:11:55.000 UTC,2024-09-05 00:00:00.000 UTC,2024-09-01 00:00:00.000 UTC,Banana Gun,19390684,base,117.3920792079208,Buy,4601687.433549198,COFFEE,0xc54b2b7ee65918a8ec08048cd2377998e7415312,0.04950495049504951,WETH,0x4200000000000000000000000000000000000006,0.005,1.1739207920792103,0.000495049504950496,ETH,0x4200000000000000000000000000000000000006,uniswap,2,COFFEE-WETH,0xe28afb7f1cac4bbf87cd9875aa06f470aec965a4,0xfe906d692a47246518fe05cd5852501bfb51f012,0x3f15863dd32a63136646bde0b816fa080f6153c0d6d74d94d7b0bb5fa3d59140,11,true |