kopia lustrzana https://github.com/bugout-dev/moonstream
cu dashboard generator.
rodzic
e23fd52453
commit
0c6656fad5
|
@ -1,12 +1,99 @@
|
||||||
import argparse
|
import argparse
|
||||||
import datetime
|
import datetime
|
||||||
from timeit import repeat
|
|
||||||
from eth_typing import Address
|
|
||||||
from moonstream.client import Moonstream
|
from moonstream.client import Moonstream
|
||||||
import time
|
import time
|
||||||
import requests
|
import requests
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
from typing import Any, Dict, Union
|
||||||
|
|
||||||
|
from uuid import UUID
|
||||||
|
|
||||||
|
from .queries import tokenomics_queries, cu_bank_queries
|
||||||
|
|
||||||
|
from ..settings import CUSTOM_CRAWLER_S3_BUCKET, CUSTOM_CRAWLER_S3_BUCKET_PREFIX
|
||||||
|
|
||||||
|
|
||||||
|
def recive_S3_data_from_query(
|
||||||
|
client: Moonstream,
|
||||||
|
token: Union[str, UUID],
|
||||||
|
query_name: str,
|
||||||
|
params: Dict[str, Any],
|
||||||
|
time_await: int = 2,
|
||||||
|
max_retries: int = 20,
|
||||||
|
) -> Any:
|
||||||
|
|
||||||
|
"""
|
||||||
|
Await the query to be update data on S3 with if_modified_since and return new the data.
|
||||||
|
"""
|
||||||
|
|
||||||
|
keep_going = True
|
||||||
|
|
||||||
|
repeat = 0
|
||||||
|
|
||||||
|
if_modified_since_datetime = datetime.datetime.utcnow()
|
||||||
|
if_modified_since = if_modified_since_datetime.strftime("%a, %d %b %Y %H:%M:%S GMT")
|
||||||
|
|
||||||
|
time.sleep(2)
|
||||||
|
|
||||||
|
data_url = client.exec_query(
|
||||||
|
token=token,
|
||||||
|
name=query_name,
|
||||||
|
params=params,
|
||||||
|
) # S3 presign_url
|
||||||
|
|
||||||
|
while keep_going:
|
||||||
|
time.sleep(time_await)
|
||||||
|
data_response = requests.get(
|
||||||
|
data_url.url,
|
||||||
|
headers={"If-Modified-Since": if_modified_since},
|
||||||
|
timeout=10,
|
||||||
|
)
|
||||||
|
|
||||||
|
if data_response.status_code == 200:
|
||||||
|
break
|
||||||
|
|
||||||
|
repeat += 1
|
||||||
|
|
||||||
|
if repeat > max_retries:
|
||||||
|
print("Too many retries")
|
||||||
|
break
|
||||||
|
return data_response.json()
|
||||||
|
|
||||||
|
|
||||||
|
def generate_report(
|
||||||
|
client: Moonstream,
|
||||||
|
token: Union[str, UUID],
|
||||||
|
query_name: str,
|
||||||
|
params: Dict[str, Any],
|
||||||
|
bucket_prefix: str,
|
||||||
|
bucket: str,
|
||||||
|
key: str,
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
Generate the report.
|
||||||
|
"""
|
||||||
|
|
||||||
|
try:
|
||||||
|
|
||||||
|
json_data = recive_S3_data_from_query(
|
||||||
|
client=client,
|
||||||
|
token=token,
|
||||||
|
query_name=query_name,
|
||||||
|
params=params,
|
||||||
|
)
|
||||||
|
|
||||||
|
client.upload_query_results(
|
||||||
|
json.dumps(json_data),
|
||||||
|
bucket,
|
||||||
|
f"{bucket_prefix}/{key}",
|
||||||
|
)
|
||||||
|
print(f"https://{bucket}/{bucket_prefix}/{key}")
|
||||||
|
except Exception as err:
|
||||||
|
print(
|
||||||
|
f"Cant recive or load data for s3, for query: {query_name}, bucket: {bucket}, key: {key}. End with error: {err}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def init_game_bank_queries_handler(args: argparse.Namespace):
|
def init_game_bank_queries_handler(args: argparse.Namespace):
|
||||||
|
|
||||||
|
@ -16,212 +103,20 @@ def init_game_bank_queries_handler(args: argparse.Namespace):
|
||||||
|
|
||||||
client = Moonstream()
|
client = Moonstream()
|
||||||
|
|
||||||
# Create
|
for query in cu_bank_queries:
|
||||||
client.create_query(
|
|
||||||
token=args.moonstream_token,
|
|
||||||
name="cu-bank-blances",
|
|
||||||
query="""
|
|
||||||
WITH game_contract as (
|
|
||||||
SELECT
|
|
||||||
*
|
|
||||||
from
|
|
||||||
polygon_labels
|
|
||||||
where
|
|
||||||
address = '0x94f557dDdb245b11d031F57BA7F2C4f28C4A203e'
|
|
||||||
and label = 'moonworm-alpha'
|
|
||||||
)
|
|
||||||
SELECT
|
|
||||||
address,
|
|
||||||
div(sum(
|
|
||||||
CASE
|
|
||||||
WHEN result_balances.token_address = '0x64060aB139Feaae7f06Ca4E63189D86aDEb51691' THEN amount
|
|
||||||
ELSE 0
|
|
||||||
END
|
|
||||||
), 10^18::decimal) as UNIM_BALANCE,
|
|
||||||
div(sum(
|
|
||||||
CASE
|
|
||||||
WHEN result_balances.token_address = '0x431CD3C9AC9Fc73644BF68bF5691f4B83F9E104f' THEN amount
|
|
||||||
ELSE 0
|
|
||||||
END
|
|
||||||
), 10^18::decimal) as RBW_BALANCE
|
|
||||||
FROM
|
|
||||||
(
|
|
||||||
select
|
|
||||||
transaction_hash,
|
|
||||||
label_data -> 'args' ->> 'player' as address,
|
|
||||||
jsonb_array_elements(label_data -> 'args' -> 'tokenAddresses') ->> 0 as token_address,
|
|
||||||
- jsonb_array_elements(label_data -> 'args' -> 'tokenAmounts') :: decimal as amount
|
|
||||||
from
|
|
||||||
game_contract
|
|
||||||
where
|
|
||||||
label_data ->> 'name' = 'UnstashedMultiple'
|
|
||||||
union
|
|
||||||
ALL
|
|
||||||
select
|
|
||||||
transaction_hash,
|
|
||||||
label_data -> 'args' ->> 'player' as address,
|
|
||||||
label_data -> 'args' ->> 'token' as token_address,
|
|
||||||
-((label_data -> 'args' -> 'amount') :: decimal) as amount
|
|
||||||
from
|
|
||||||
game_contract
|
|
||||||
where
|
|
||||||
label_data ->> 'name' = 'Unstashed'
|
|
||||||
union
|
|
||||||
ALL
|
|
||||||
select
|
|
||||||
transaction_hash,
|
|
||||||
label_data -> 'args' ->> 'player' as address,
|
|
||||||
label_data -> 'args' ->> 'token' as token_address,
|
|
||||||
(label_data -> 'args' ->> 'amount') :: decimal as amount
|
|
||||||
from
|
|
||||||
game_contract
|
|
||||||
where
|
|
||||||
label_data ->> 'name' = 'Stashed'
|
|
||||||
union
|
|
||||||
ALL
|
|
||||||
select
|
|
||||||
transaction_hash,
|
|
||||||
label_data -> 'args' ->> 'player' as address,
|
|
||||||
jsonb_array_elements(label_data -> 'args' -> 'tokenAddresses') ->> 0 as token_address,
|
|
||||||
jsonb_array_elements(label_data -> 'args' -> 'tokenAmounts') :: decimal as amount
|
|
||||||
from
|
|
||||||
game_contract
|
|
||||||
where
|
|
||||||
label_data ->> 'name' = 'StashedMultiple'
|
|
||||||
|
|
||||||
) result_balances
|
try:
|
||||||
group by
|
created_entry = client.create_query(
|
||||||
address
|
token=args.moonstream_token,
|
||||||
ORDER BY
|
name=query["name"],
|
||||||
UNIM_BALANCE DESC,
|
query=query["query"],
|
||||||
RBW_BALANCE DESC;
|
)
|
||||||
""",
|
print(
|
||||||
)
|
f"Created query {query['name']} please validate it in the UI url {created_entry.journal_url}/entries/{created_entry.id}/"
|
||||||
|
)
|
||||||
client.create_query(
|
except Exception as e:
|
||||||
token=args.moonstream_token,
|
print(e)
|
||||||
name="cu-bank-withdrawals-total",
|
pass
|
||||||
query="""
|
|
||||||
WITH game_contract as (
|
|
||||||
SELECT
|
|
||||||
*
|
|
||||||
from
|
|
||||||
polygon_labels
|
|
||||||
where
|
|
||||||
address = '0x94f557dDdb245b11d031F57BA7F2C4f28C4A203e'
|
|
||||||
and label = 'moonworm-alpha'
|
|
||||||
block_timestamp >= :block_timestamp
|
|
||||||
), withdoraws_total as (
|
|
||||||
SELECT
|
|
||||||
address,
|
|
||||||
div(sum(
|
|
||||||
CASE
|
|
||||||
WHEN result_balances.token_address = '0x64060aB139Feaae7f06Ca4E63189D86aDEb51691' THEN amount
|
|
||||||
ELSE 0
|
|
||||||
END
|
|
||||||
), 10^18::decimal) as UNIM_BALANCE,
|
|
||||||
div(sum(
|
|
||||||
CASE
|
|
||||||
WHEN result_balances.token_address = '0x431CD3C9AC9Fc73644BF68bF5691f4B83F9E104f' THEN amount
|
|
||||||
ELSE 0
|
|
||||||
END
|
|
||||||
), 10^18::decimal) as RBW_BALANCE
|
|
||||||
FROM
|
|
||||||
(
|
|
||||||
select
|
|
||||||
transaction_hash,
|
|
||||||
label_data -> 'args' ->> 'player' as address,
|
|
||||||
jsonb_array_elements(label_data -> 'args' -> 'tokenAddresses') ->> 0 as token_address,
|
|
||||||
jsonb_array_elements(label_data -> 'args' -> 'tokenAmounts') :: decimal as amount
|
|
||||||
from
|
|
||||||
game_contract
|
|
||||||
where
|
|
||||||
label_data ->> 'name' = 'UnstashedMultiple'
|
|
||||||
union
|
|
||||||
ALL
|
|
||||||
select
|
|
||||||
transaction_hash,
|
|
||||||
label_data -> 'args' ->> 'player' as address,
|
|
||||||
label_data -> 'args' ->> 'token' as token_address,
|
|
||||||
((label_data -> 'args' -> 'amount') :: decimal) as amount
|
|
||||||
from
|
|
||||||
game_contract
|
|
||||||
where
|
|
||||||
label_data ->> 'name' = 'Unstashed'
|
|
||||||
) result_balances
|
|
||||||
group by
|
|
||||||
address
|
|
||||||
ORDER BY
|
|
||||||
UNIM_BALANCE DESC,
|
|
||||||
RBW_BALANCE DESC
|
|
||||||
)
|
|
||||||
SELECT
|
|
||||||
address,
|
|
||||||
UNIM_BALANCE,
|
|
||||||
RBW_BALANCE,
|
|
||||||
UNIM_BALANCE + RBW_BALANCE as TOTAL
|
|
||||||
FROM
|
|
||||||
withdoraws_total
|
|
||||||
ORDER BY
|
|
||||||
TOTAL DESC;
|
|
||||||
""",
|
|
||||||
)
|
|
||||||
|
|
||||||
client.create_query(
|
|
||||||
token=args.moonstream_token,
|
|
||||||
name="cu-bank-withdrawals-events",
|
|
||||||
query="""
|
|
||||||
WITH game_contract as (
|
|
||||||
SELECT
|
|
||||||
*
|
|
||||||
from
|
|
||||||
polygon_labels
|
|
||||||
where
|
|
||||||
address = '0x94f557dDdb245b11d031F57BA7F2C4f28C4A203e'
|
|
||||||
and label = 'moonworm-alpha'
|
|
||||||
block_timestamp >= :block_timestamp
|
|
||||||
), withdoraws_total as (
|
|
||||||
SELECT
|
|
||||||
address,
|
|
||||||
CASE
|
|
||||||
WHEN result_balances.token_address = '0x64060aB139Feaae7f06Ca4E63189D86aDEb51691' THEN 'UNIM'
|
|
||||||
WHEN result_balances.token_address = '0x431CD3C9AC9Fc73644BF68bF5691f4B83F9E104f' THEN 'RBW'
|
|
||||||
END as currency,
|
|
||||||
div(amount, 10^18::decimal) as amount
|
|
||||||
FROM
|
|
||||||
(
|
|
||||||
select
|
|
||||||
transaction_hash,
|
|
||||||
label_data -> 'args' ->> 'player' as address,
|
|
||||||
jsonb_array_elements(label_data -> 'args' -> 'tokenAddresses') ->> 0 as token_address,
|
|
||||||
jsonb_array_elements(label_data -> 'args' -> 'tokenAmounts') :: decimal as amount
|
|
||||||
from
|
|
||||||
game_contract
|
|
||||||
where
|
|
||||||
label_data ->> 'name' = 'UnstashedMultiple'
|
|
||||||
union
|
|
||||||
ALL
|
|
||||||
select
|
|
||||||
transaction_hash,
|
|
||||||
label_data -> 'args' ->> 'player' as address,
|
|
||||||
label_data -> 'args' ->> 'token' as token_address,
|
|
||||||
((label_data -> 'args' -> 'amount') :: decimal) as amount
|
|
||||||
from
|
|
||||||
game_contract
|
|
||||||
where
|
|
||||||
label_data ->> 'name' = 'Unstashed'
|
|
||||||
) result_balances
|
|
||||||
)
|
|
||||||
SELECT
|
|
||||||
address,
|
|
||||||
currency,
|
|
||||||
amount,
|
|
||||||
FROM
|
|
||||||
withdoraws_total
|
|
||||||
ORDER BY
|
|
||||||
amount DESC
|
|
||||||
""",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def init_tokenomics_queries_handler(args: argparse.Namespace):
|
def init_tokenomics_queries_handler(args: argparse.Namespace):
|
||||||
|
@ -232,64 +127,20 @@ def init_tokenomics_queries_handler(args: argparse.Namespace):
|
||||||
|
|
||||||
client = Moonstream()
|
client = Moonstream()
|
||||||
|
|
||||||
query = """
|
for query in tokenomics_queries:
|
||||||
select
|
|
||||||
sum(value) as volume,
|
|
||||||
time as time,
|
|
||||||
count(*) as activity
|
|
||||||
from (
|
|
||||||
select
|
|
||||||
CASE
|
|
||||||
WHEN :type ='NFT' THEN 1
|
|
||||||
ELSE (label_data->'args'->>'value')::decimal
|
|
||||||
END as value
|
|
||||||
, to_char(to_timestamp(block_timestamp), :time_format) as time from polygon_labels
|
|
||||||
where label='moonworm-alpha'
|
|
||||||
and address=:address
|
|
||||||
and label_data->>'name'='Transfer'
|
|
||||||
and block_timestamp >= extract(epoch from now() - interval :time_range)::int
|
|
||||||
) interval_transfers
|
|
||||||
GROUP BY time
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
# Create
|
|
||||||
client.create_query(
|
|
||||||
token=args.moonstream_token,
|
|
||||||
name="cu-volume",
|
|
||||||
query=query,
|
|
||||||
)
|
|
||||||
except Exception as e:
|
|
||||||
print(e)
|
|
||||||
pass
|
|
||||||
|
|
||||||
# query = """
|
try:
|
||||||
# select
|
created_entry = client.create_query(
|
||||||
# sum(value) as volume,
|
token=args.moonstream_token,
|
||||||
# time as time,
|
name=query["name"],
|
||||||
# count(*) as activity
|
query=query["query"],
|
||||||
# from (
|
)
|
||||||
# select
|
print(
|
||||||
# CASE
|
f"Created query {query['name']} please validate it in the UI url {created_entry.journal_url}/entries/{created_entry.id}/"
|
||||||
# WHEN :type ='NFT' THEN 1
|
)
|
||||||
# ELSE (label_data->'args'->>'value')::decimal
|
except Exception as e:
|
||||||
# END as value
|
print(e)
|
||||||
# , to_char(to_timestamp(block_timestamp), :time_format) as time from polygon_labels
|
pass
|
||||||
# where label='moonworm-alpha'
|
|
||||||
# and address=:address
|
|
||||||
# and label_data->>'name'='Transfer'
|
|
||||||
# and block_timestamp >= extract(epoch from now() - interval :time_range)::int
|
|
||||||
# ) interval_transfers
|
|
||||||
# GROUP BY time
|
|
||||||
# """
|
|
||||||
# try:
|
|
||||||
# # Create
|
|
||||||
# client.create_query(
|
|
||||||
# token=args.moonstream_token,
|
|
||||||
# name="cu-volume",
|
|
||||||
# query=query,
|
|
||||||
# )
|
|
||||||
# except Exception as e:
|
|
||||||
# pass
|
|
||||||
|
|
||||||
|
|
||||||
def run_tokenomics_queries_handler(args: argparse.Namespace):
|
def run_tokenomics_queries_handler(args: argparse.Namespace):
|
||||||
|
@ -300,7 +151,7 @@ def run_tokenomics_queries_handler(args: argparse.Namespace):
|
||||||
# token=args.moonstream_token,
|
# token=args.moonstream_token,
|
||||||
# ).queries:
|
# ).queries:
|
||||||
|
|
||||||
query_name = "cu_voluem"
|
query_name = "erc20_721_volume"
|
||||||
|
|
||||||
### Run voluem query
|
### Run voluem query
|
||||||
|
|
||||||
|
@ -310,61 +161,197 @@ def run_tokenomics_queries_handler(args: argparse.Namespace):
|
||||||
{"time_format": "YYYY-MM-DD", "time_range": "30 days"},
|
{"time_format": "YYYY-MM-DD", "time_range": "30 days"},
|
||||||
]
|
]
|
||||||
|
|
||||||
addresess = {
|
addresess_erc20_721 = {
|
||||||
"0x64060aB139Feaae7f06Ca4E63189D86aDEb51691": "ERC20", # UNIM
|
"0x64060aB139Feaae7f06Ca4E63189D86aDEb51691": "ERC20", # UNIM
|
||||||
"0x431CD3C9AC9Fc73644BF68bF5691f4B83F9E104f": "ERC20", # RBW
|
"0x431CD3C9AC9Fc73644BF68bF5691f4B83F9E104f": "ERC20", # RBW
|
||||||
"0xdC0479CC5BbA033B3e7De9F178607150B3AbCe1f": "NFT", # unicorns
|
"0xdC0479CC5BbA033B3e7De9F178607150B3AbCe1f": "NFT", # unicorns
|
||||||
"0xA2a13cE1824F3916fC84C65e559391fc6674e6e8": "NFT", # lands
|
"0xA2a13cE1824F3916fC84C65e559391fc6674e6e8": "NFT", # lands
|
||||||
|
"0xa7D50EE3D7485288107664cf758E877a0D351725": "NFT", # shadowcorns
|
||||||
}
|
}
|
||||||
|
|
||||||
for address, type in addresess.items():
|
# volume of erc20 and erc721
|
||||||
|
|
||||||
|
for address, type in addresess_erc20_721.items():
|
||||||
for range in ranges:
|
for range in ranges:
|
||||||
|
|
||||||
params = {
|
params: Dict[str, Any] = {
|
||||||
"address": address,
|
"address": address,
|
||||||
"type": type,
|
"type": type,
|
||||||
"time_format": range["time_format"],
|
"time_format": range["time_format"],
|
||||||
"time_range": range["time_range"],
|
"time_range": range["time_range"],
|
||||||
}
|
}
|
||||||
|
|
||||||
keep_going = True
|
generate_report(
|
||||||
|
client=client,
|
||||||
repeat = 0
|
token=args.moonstream_token,
|
||||||
|
query_name=query_name,
|
||||||
if_modified_since_datetime = datetime.datetime.utcnow()
|
params=params,
|
||||||
if_modified_since = if_modified_since_datetime.strftime(
|
bucket_prefix=CUSTOM_CRAWLER_S3_BUCKET_PREFIX,
|
||||||
"%a, %d %b %Y %H:%M:%S GMT"
|
bucket=CUSTOM_CRAWLER_S3_BUCKET,
|
||||||
|
key=f'{query_name}/{address}/{range["time_range"].replace(" ","_")}/data.json',
|
||||||
)
|
)
|
||||||
|
|
||||||
data_url = client.exec_query(
|
query_name = "erc1155_volume"
|
||||||
|
|
||||||
|
# volume of erc1155
|
||||||
|
|
||||||
|
addresess_erc1155 = ["0x99A558BDBdE247C2B2716f0D4cFb0E246DFB697D"]
|
||||||
|
|
||||||
|
for address in addresess_erc1155:
|
||||||
|
for range in ranges:
|
||||||
|
|
||||||
|
params = {
|
||||||
|
"address": address,
|
||||||
|
"time_format": range["time_format"],
|
||||||
|
"time_range": range["time_range"],
|
||||||
|
}
|
||||||
|
|
||||||
|
generate_report(
|
||||||
|
client=client,
|
||||||
token=args.moonstream_token,
|
token=args.moonstream_token,
|
||||||
name=query_name,
|
query_name=query_name,
|
||||||
params=params,
|
params=params,
|
||||||
) # S3 presign_url
|
bucket_prefix=CUSTOM_CRAWLER_S3_BUCKET_PREFIX,
|
||||||
print(f"Data URL: {data_url.url}")
|
bucket=CUSTOM_CRAWLER_S3_BUCKET,
|
||||||
while keep_going:
|
key=f"{query_name}/{address}/{range['time_range'].replace(' ','_')}/data.json",
|
||||||
time.sleep(2)
|
)
|
||||||
data_response = requests.get(
|
|
||||||
data_url.url,
|
# most_recent_sale
|
||||||
headers={"If-Modified-Since": if_modified_since},
|
|
||||||
timeout=10,
|
query_name = "most_recent_sale"
|
||||||
|
|
||||||
|
for address, type in addresess_erc20_721.items():
|
||||||
|
if type == "NFT":
|
||||||
|
for amount in [10, 100]:
|
||||||
|
params = {
|
||||||
|
"address": address,
|
||||||
|
"amount": amount,
|
||||||
|
}
|
||||||
|
|
||||||
|
generate_report(
|
||||||
|
client=client,
|
||||||
|
token=args.moonstream_token,
|
||||||
|
query_name=query_name,
|
||||||
|
params=params,
|
||||||
|
bucket_prefix=CUSTOM_CRAWLER_S3_BUCKET_PREFIX,
|
||||||
|
bucket=CUSTOM_CRAWLER_S3_BUCKET,
|
||||||
|
key=f"{query_name}/{address}/{amount}/data.json",
|
||||||
)
|
)
|
||||||
# push to s3
|
|
||||||
|
|
||||||
if data_response.status_code == 200:
|
# most_active_buyers
|
||||||
# print(json.dumps(data_response.json()))
|
|
||||||
client.upload_query_results(
|
|
||||||
json.dumps(data_response.json()),
|
|
||||||
"data.moonstream.to",
|
|
||||||
f'dev/{query_name}/{address}/{range["time_range"].replace(" ","_")}/data.json',
|
|
||||||
)
|
|
||||||
break
|
|
||||||
|
|
||||||
repeat += 1
|
query_name = "most_active_buyers"
|
||||||
|
|
||||||
if repeat > 20:
|
for address, type in addresess_erc20_721.items():
|
||||||
print("Too many retries")
|
|
||||||
break
|
if type == "NFT":
|
||||||
|
|
||||||
|
for range in ranges:
|
||||||
|
|
||||||
|
params = {
|
||||||
|
"address": address,
|
||||||
|
"time_range": range["time_range"],
|
||||||
|
}
|
||||||
|
|
||||||
|
generate_report(
|
||||||
|
client=client,
|
||||||
|
token=args.moonstream_token,
|
||||||
|
query_name=query_name,
|
||||||
|
params=params,
|
||||||
|
bucket_prefix=CUSTOM_CRAWLER_S3_BUCKET_PREFIX,
|
||||||
|
bucket=CUSTOM_CRAWLER_S3_BUCKET,
|
||||||
|
key=f"{query_name}/{address}/{range['time_range'].replace(' ','_')}/data.json",
|
||||||
|
)
|
||||||
|
|
||||||
|
# most_active_sellers
|
||||||
|
|
||||||
|
query_name = "most_active_sellers"
|
||||||
|
|
||||||
|
for address, type in addresess_erc20_721.items():
|
||||||
|
|
||||||
|
if type == "NFT":
|
||||||
|
|
||||||
|
for range in ranges:
|
||||||
|
|
||||||
|
params = {
|
||||||
|
"address": address,
|
||||||
|
"time_range": range["time_range"],
|
||||||
|
}
|
||||||
|
|
||||||
|
generate_report(
|
||||||
|
client=client,
|
||||||
|
token=args.moonstream_token,
|
||||||
|
query_name=query_name,
|
||||||
|
params=params,
|
||||||
|
bucket_prefix=CUSTOM_CRAWLER_S3_BUCKET_PREFIX,
|
||||||
|
bucket=CUSTOM_CRAWLER_S3_BUCKET,
|
||||||
|
key=f"{query_name}/{address}/{range['time_range'].replace(' ','_')}/data.json",
|
||||||
|
)
|
||||||
|
|
||||||
|
# lagerst_owners
|
||||||
|
|
||||||
|
query_name = "lagerst_owners"
|
||||||
|
for address, type in addresess_erc20_721.items():
|
||||||
|
|
||||||
|
if type == "NFT":
|
||||||
|
|
||||||
|
params = {
|
||||||
|
"address": address,
|
||||||
|
}
|
||||||
|
|
||||||
|
generate_report(
|
||||||
|
client=client,
|
||||||
|
token=args.moonstream_token,
|
||||||
|
query_name=query_name,
|
||||||
|
params=params,
|
||||||
|
bucket_prefix=CUSTOM_CRAWLER_S3_BUCKET_PREFIX,
|
||||||
|
bucket=CUSTOM_CRAWLER_S3_BUCKET,
|
||||||
|
key=f"{query_name}/{address}/data.json",
|
||||||
|
)
|
||||||
|
|
||||||
|
# total_supply_erc721
|
||||||
|
|
||||||
|
query_name = "total_supply_erc721"
|
||||||
|
|
||||||
|
for address, type in addresess_erc20_721.items():
|
||||||
|
|
||||||
|
if type == "NFT":
|
||||||
|
|
||||||
|
params = {
|
||||||
|
"address": address,
|
||||||
|
}
|
||||||
|
|
||||||
|
generate_report(
|
||||||
|
client=client,
|
||||||
|
token=args.moonstream_token,
|
||||||
|
query_name=query_name,
|
||||||
|
params=params,
|
||||||
|
bucket_prefix=CUSTOM_CRAWLER_S3_BUCKET_PREFIX,
|
||||||
|
bucket=CUSTOM_CRAWLER_S3_BUCKET,
|
||||||
|
key=f"{query_name}/{address}/data.json",
|
||||||
|
)
|
||||||
|
|
||||||
|
# total_supply_terminus
|
||||||
|
|
||||||
|
query_name = "total_supply_terminus"
|
||||||
|
|
||||||
|
for address in addresess_erc1155:
|
||||||
|
|
||||||
|
params = {
|
||||||
|
"address": address,
|
||||||
|
}
|
||||||
|
|
||||||
|
generate_report(
|
||||||
|
client=client,
|
||||||
|
token=args.moonstream_token,
|
||||||
|
query_name=query_name,
|
||||||
|
params=params,
|
||||||
|
bucket_prefix=CUSTOM_CRAWLER_S3_BUCKET_PREFIX,
|
||||||
|
bucket=CUSTOM_CRAWLER_S3_BUCKET,
|
||||||
|
key=f"{query_name}/{address}/data.json",
|
||||||
|
)
|
||||||
|
|
||||||
|
print("Done")
|
||||||
|
|
||||||
|
|
||||||
def list_user_queries_handler(args: argparse.Namespace):
|
def list_user_queries_handler(args: argparse.Namespace):
|
||||||
|
@ -491,11 +478,13 @@ def main():
|
||||||
description="Create all predifind query",
|
description="Create all predifind query",
|
||||||
).set_defaults(func=init_tokenomics_queries_handler)
|
).set_defaults(func=init_tokenomics_queries_handler)
|
||||||
|
|
||||||
queries_subparsers.add_parser(
|
generate_report = queries_subparsers.add_parser(
|
||||||
"run-tokenonomics",
|
"run-tokenonomics",
|
||||||
help="Create all predifind query",
|
help="Create all predifind query",
|
||||||
description="Create all predifind query",
|
description="Create all predifind query",
|
||||||
).set_defaults(func=run_tokenomics_queries_handler)
|
)
|
||||||
|
|
||||||
|
generate_report.set_defaults(func=run_tokenomics_queries_handler)
|
||||||
|
|
||||||
delete_query = queries_subparsers.add_parser(
|
delete_query = queries_subparsers.add_parser(
|
||||||
"delete",
|
"delete",
|
||||||
|
@ -515,26 +504,6 @@ def main():
|
||||||
"generate-reports",
|
"generate-reports",
|
||||||
help="Generate cu-bank state reports",
|
help="Generate cu-bank state reports",
|
||||||
)
|
)
|
||||||
# cu_bank_parser.add_argument("--addresses", type=str, required=True)
|
|
||||||
# cu_bank_parser.add_argument(
|
|
||||||
# "--output",
|
|
||||||
# required=True,
|
|
||||||
# type=str,
|
|
||||||
# help="Output file name",
|
|
||||||
# )
|
|
||||||
# cu_bank_parser.add_argument("--blockchain", type=str, help="Blockchain")
|
|
||||||
# cu_bank_parser.add_argument(
|
|
||||||
# "--limit",
|
|
||||||
# type=int,
|
|
||||||
# default=100,
|
|
||||||
# help="Limit of the search results",
|
|
||||||
# )
|
|
||||||
|
|
||||||
# cu_bank_parser.add_argument(
|
|
||||||
# "--",
|
|
||||||
# type=str,
|
|
||||||
# help="Filter by created_at",
|
|
||||||
# )
|
|
||||||
|
|
||||||
cu_bank_parser.set_defaults(func=generate_game_bank_report)
|
cu_bank_parser.set_defaults(func=generate_game_bank_report)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
@ -543,97 +512,3 @@ def main():
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|
||||||
"""
|
|
||||||
Select
|
|
||||||
difference.address,
|
|
||||||
(
|
|
||||||
difference.transfers_in - difference.transfers_out
|
|
||||||
) as owned_nfts,
|
|
||||||
block_timestamp as last_activity,
|
|
||||||
opensea_sales
|
|
||||||
from
|
|
||||||
(
|
|
||||||
SELECT
|
|
||||||
total.address,
|
|
||||||
sum(total.transfer_out) as transfers_out,
|
|
||||||
sum(total.transfer_in) as transfers_in,
|
|
||||||
max(total.block_timestamp) as block_timestamp,
|
|
||||||
sum(total.is_opensea_sale) as opensea_sales
|
|
||||||
from
|
|
||||||
(
|
|
||||||
SELECT
|
|
||||||
label_data -> 'args' ->> 'from' as address,
|
|
||||||
jsonb_array_elements(label_data -> 'args' -> 'values') :: int as transfer_out,
|
|
||||||
0 as transfer_in,
|
|
||||||
block_timestamp as block_timestamp,
|
|
||||||
CASE
|
|
||||||
WHEN to_address in (
|
|
||||||
select
|
|
||||||
addresses
|
|
||||||
from
|
|
||||||
OpenSea_contracts
|
|
||||||
) THEN 1
|
|
||||||
ELSE 0
|
|
||||||
END as is_opensea_sale
|
|
||||||
from
|
|
||||||
erc_1155_721_contracts_transfers_with_trashhold_ethereum,
|
|
||||||
OpenSea_contracts
|
|
||||||
where
|
|
||||||
label_data ->> 'name' = 'TransferBatch'
|
|
||||||
UNION
|
|
||||||
ALL
|
|
||||||
SELECT
|
|
||||||
label_data -> 'args' ->> 'from' as address,
|
|
||||||
(label_data -> 'args' ->> 'value') :: int as transfer_out,
|
|
||||||
0 as transfer_in,
|
|
||||||
block_timestamp as block_timestamp,
|
|
||||||
CASE
|
|
||||||
WHEN to_address in (
|
|
||||||
select
|
|
||||||
addresses
|
|
||||||
from
|
|
||||||
OpenSea_contracts
|
|
||||||
) THEN 1
|
|
||||||
ELSE 0
|
|
||||||
END as is_opensea_sale
|
|
||||||
from
|
|
||||||
erc_1155_721_contracts_transfers_with_trashhold_ethereum,
|
|
||||||
OpenSea_contracts
|
|
||||||
where
|
|
||||||
label_data ->> 'name' = 'TransferSingle'
|
|
||||||
UNION
|
|
||||||
ALL
|
|
||||||
select
|
|
||||||
label_data -> 'args' ->> 'to' as address,
|
|
||||||
0 as transfer_out,
|
|
||||||
(label_data -> 'args' ->> 'value') :: int as transfer_in,
|
|
||||||
block_timestamp as block_timestamp,
|
|
||||||
0 as is_opensea_sale
|
|
||||||
from
|
|
||||||
erc_1155_721_contracts_transfers_with_trashhold_ethereum,
|
|
||||||
OpenSea_contracts
|
|
||||||
where
|
|
||||||
label_data ->> 'name' = 'TransferSingle'
|
|
||||||
UNION
|
|
||||||
ALL
|
|
||||||
select
|
|
||||||
label_data -> 'args' ->> 'to' as address,
|
|
||||||
0 as transfer_out,
|
|
||||||
jsonb_array_elements(label_data -> 'args' -> 'values') :: int as transfer_in,
|
|
||||||
jsonb_array_elements(label_data -> 'args' -> 'ids') ::
|
|
||||||
block_timestamp as block_timestamp,
|
|
||||||
0 as is_opensea_sale
|
|
||||||
from
|
|
||||||
erc_1155_721_contracts_transfers_with_trashhold_ethereum,
|
|
||||||
OpenSea_contracts
|
|
||||||
where
|
|
||||||
label_data ->> 'name' = 'TransferBatch'
|
|
||||||
) as total
|
|
||||||
group by
|
|
||||||
address
|
|
||||||
) difference
|
|
||||||
order by
|
|
||||||
owned_nfts desc
|
|
||||||
"""
|
|
||||||
|
|
|
@ -0,0 +1,647 @@
|
||||||
|
cu_bank_queries = [
|
||||||
|
{
|
||||||
|
"name": "cu-bank-blances",
|
||||||
|
"query": """
|
||||||
|
WITH game_contract as (
|
||||||
|
SELECT
|
||||||
|
*
|
||||||
|
from
|
||||||
|
polygon_labels
|
||||||
|
where
|
||||||
|
address = '0x94f557dDdb245b11d031F57BA7F2C4f28C4A203e'
|
||||||
|
and label = 'moonworm-alpha'
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
address,
|
||||||
|
div(sum(
|
||||||
|
CASE
|
||||||
|
WHEN result_balances.token_address = '0x64060aB139Feaae7f06Ca4E63189D86aDEb51691' THEN amount
|
||||||
|
ELSE 0
|
||||||
|
END
|
||||||
|
), 10^18::decimal) as UNIM_BALANCE,
|
||||||
|
div(sum(
|
||||||
|
CASE
|
||||||
|
WHEN result_balances.token_address = '0x431CD3C9AC9Fc73644BF68bF5691f4B83F9E104f' THEN amount
|
||||||
|
ELSE 0
|
||||||
|
END
|
||||||
|
), 10^18::decimal) as RBW_BALANCE
|
||||||
|
FROM
|
||||||
|
(
|
||||||
|
select
|
||||||
|
transaction_hash,
|
||||||
|
label_data -> 'args' ->> 'player' as address,
|
||||||
|
jsonb_array_elements(label_data -> 'args' -> 'tokenAddresses') ->> 0 as token_address,
|
||||||
|
- jsonb_array_elements(label_data -> 'args' -> 'tokenAmounts') :: decimal as amount
|
||||||
|
from
|
||||||
|
game_contract
|
||||||
|
where
|
||||||
|
label_data ->> 'name' = 'UnstashedMultiple'
|
||||||
|
union
|
||||||
|
ALL
|
||||||
|
select
|
||||||
|
transaction_hash,
|
||||||
|
label_data -> 'args' ->> 'player' as address,
|
||||||
|
label_data -> 'args' ->> 'token' as token_address,
|
||||||
|
-((label_data -> 'args' -> 'amount') :: decimal) as amount
|
||||||
|
from
|
||||||
|
game_contract
|
||||||
|
where
|
||||||
|
label_data ->> 'name' = 'Unstashed'
|
||||||
|
union
|
||||||
|
ALL
|
||||||
|
select
|
||||||
|
transaction_hash,
|
||||||
|
label_data -> 'args' ->> 'player' as address,
|
||||||
|
label_data -> 'args' ->> 'token' as token_address,
|
||||||
|
(label_data -> 'args' ->> 'amount') :: decimal as amount
|
||||||
|
from
|
||||||
|
game_contract
|
||||||
|
where
|
||||||
|
label_data ->> 'name' = 'Stashed'
|
||||||
|
union
|
||||||
|
ALL
|
||||||
|
select
|
||||||
|
transaction_hash,
|
||||||
|
label_data -> 'args' ->> 'player' as address,
|
||||||
|
jsonb_array_elements(label_data -> 'args' -> 'tokenAddresses') ->> 0 as token_address,
|
||||||
|
jsonb_array_elements(label_data -> 'args' -> 'tokenAmounts') :: decimal as amount
|
||||||
|
from
|
||||||
|
game_contract
|
||||||
|
where
|
||||||
|
label_data ->> 'name' = 'StashedMultiple'
|
||||||
|
|
||||||
|
) result_balances
|
||||||
|
group by
|
||||||
|
address
|
||||||
|
ORDER BY
|
||||||
|
UNIM_BALANCE DESC,
|
||||||
|
RBW_BALANCE DESC
|
||||||
|
""",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "cu-bank-withdrawals-total",
|
||||||
|
"query": """
|
||||||
|
WITH game_contract as (
|
||||||
|
SELECT
|
||||||
|
*
|
||||||
|
from
|
||||||
|
polygon_labels
|
||||||
|
where
|
||||||
|
address = '0x94f557dDdb245b11d031F57BA7F2C4f28C4A203e'
|
||||||
|
and label = 'moonworm-alpha'
|
||||||
|
block_timestamp >= :block_timestamp
|
||||||
|
), withdoraws_total as (
|
||||||
|
SELECT
|
||||||
|
address,
|
||||||
|
div(sum(
|
||||||
|
CASE
|
||||||
|
WHEN result_balances.token_address = '0x64060aB139Feaae7f06Ca4E63189D86aDEb51691' THEN amount
|
||||||
|
ELSE 0
|
||||||
|
END
|
||||||
|
), 10^18::decimal) as UNIM_BALANCE,
|
||||||
|
div(sum(
|
||||||
|
CASE
|
||||||
|
WHEN result_balances.token_address = '0x431CD3C9AC9Fc73644BF68bF5691f4B83F9E104f' THEN amount
|
||||||
|
ELSE 0
|
||||||
|
END
|
||||||
|
), 10^18::decimal) as RBW_BALANCE
|
||||||
|
FROM
|
||||||
|
(
|
||||||
|
select
|
||||||
|
transaction_hash,
|
||||||
|
label_data -> 'args' ->> 'player' as address,
|
||||||
|
jsonb_array_elements(label_data -> 'args' -> 'tokenAddresses') ->> 0 as token_address,
|
||||||
|
jsonb_array_elements(label_data -> 'args' -> 'tokenAmounts') :: decimal as amount
|
||||||
|
from
|
||||||
|
game_contract
|
||||||
|
where
|
||||||
|
label_data ->> 'name' = 'UnstashedMultiple'
|
||||||
|
union
|
||||||
|
ALL
|
||||||
|
select
|
||||||
|
transaction_hash,
|
||||||
|
label_data -> 'args' ->> 'player' as address,
|
||||||
|
label_data -> 'args' ->> 'token' as token_address,
|
||||||
|
((label_data -> 'args' -> 'amount') :: decimal) as amount
|
||||||
|
from
|
||||||
|
game_contract
|
||||||
|
where
|
||||||
|
label_data ->> 'name' = 'Unstashed'
|
||||||
|
) result_balances
|
||||||
|
group by
|
||||||
|
address
|
||||||
|
ORDER BY
|
||||||
|
UNIM_BALANCE DESC,
|
||||||
|
RBW_BALANCE DESC
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
address,
|
||||||
|
UNIM_BALANCE,
|
||||||
|
RBW_BALANCE,
|
||||||
|
UNIM_BALANCE + RBW_BALANCE as TOTAL
|
||||||
|
FROM
|
||||||
|
withdoraws_total
|
||||||
|
ORDER BY
|
||||||
|
TOTAL DESC;
|
||||||
|
""",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "cu-bank-withdrawals-events",
|
||||||
|
"query": """
|
||||||
|
WITH game_contract as (
|
||||||
|
SELECT
|
||||||
|
*
|
||||||
|
from
|
||||||
|
polygon_labels
|
||||||
|
where
|
||||||
|
address = '0x94f557dDdb245b11d031F57BA7F2C4f28C4A203e'
|
||||||
|
and label = 'moonworm-alpha'
|
||||||
|
block_timestamp >= :block_timestamp
|
||||||
|
), withdoraws_total as (
|
||||||
|
SELECT
|
||||||
|
address,
|
||||||
|
CASE
|
||||||
|
WHEN result_balances.token_address = '0x64060aB139Feaae7f06Ca4E63189D86aDEb51691' THEN 'UNIM'
|
||||||
|
WHEN result_balances.token_address = '0x431CD3C9AC9Fc73644BF68bF5691f4B83F9E104f' THEN 'RBW'
|
||||||
|
END as currency,
|
||||||
|
div(amount, 10^18::decimal) as amount
|
||||||
|
FROM
|
||||||
|
(
|
||||||
|
select
|
||||||
|
transaction_hash,
|
||||||
|
label_data -> 'args' ->> 'player' as address,
|
||||||
|
jsonb_array_elements(label_data -> 'args' -> 'tokenAddresses') ->> 0 as token_address,
|
||||||
|
jsonb_array_elements(label_data -> 'args' -> 'tokenAmounts') :: decimal as amount
|
||||||
|
from
|
||||||
|
game_contract
|
||||||
|
where
|
||||||
|
label_data ->> 'name' = 'UnstashedMultiple'
|
||||||
|
union
|
||||||
|
ALL
|
||||||
|
select
|
||||||
|
transaction_hash,
|
||||||
|
label_data -> 'args' ->> 'player' as address,
|
||||||
|
label_data -> 'args' ->> 'token' as token_address,
|
||||||
|
((label_data -> 'args' -> 'amount') :: decimal) as amount
|
||||||
|
from
|
||||||
|
game_contract
|
||||||
|
where
|
||||||
|
label_data ->> 'name' = 'Unstashed'
|
||||||
|
) result_balances
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
address,
|
||||||
|
currency,
|
||||||
|
amount,
|
||||||
|
FROM
|
||||||
|
withdoraws_total
|
||||||
|
ORDER BY
|
||||||
|
amount DESC
|
||||||
|
""",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
tokenomics_queries = [
|
||||||
|
{
|
||||||
|
"name": "erc20_721_volume",
|
||||||
|
"query": """
|
||||||
|
with interval_transfers as (
|
||||||
|
select
|
||||||
|
transaction_hash,
|
||||||
|
CASE
|
||||||
|
WHEN :type ='NFT' THEN 1
|
||||||
|
ELSE (label_data->'args'->>'value')::decimal
|
||||||
|
END as value,
|
||||||
|
label_data->'args'->>'to' as buyer,
|
||||||
|
label_data->'args'->>'from' as seller,
|
||||||
|
to_char(to_timestamp(block_timestamp), :time_format) as time
|
||||||
|
from polygon_labels
|
||||||
|
where label='moonworm-alpha'
|
||||||
|
and address= :address
|
||||||
|
and label_data->>'name'='Transfer'
|
||||||
|
and block_timestamp >= extract(epoch from now() - interval :time_range)::int
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
time as time,
|
||||||
|
sum(interval_transfers.value) as value,
|
||||||
|
sum(
|
||||||
|
CASE
|
||||||
|
WHEN to_address in ('0xF715bEb51EC8F63317d66f491E37e7BB048fCc2d','0xfede379e48C873C75F3cc0C81F7C784aD730a8F7','0x00000000006c3852cbef3e08e8df289169ede581')
|
||||||
|
THEN 1
|
||||||
|
else 0
|
||||||
|
END
|
||||||
|
) as os_sales
|
||||||
|
from interval_transfers
|
||||||
|
LEFT JOIN polygon_transactions ON interval_transfers.transaction_hash = polygon_transactions.hash
|
||||||
|
GROUP BY time
|
||||||
|
""",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "erc1155_volume",
|
||||||
|
"query": """
|
||||||
|
with labels_data as (
|
||||||
|
select
|
||||||
|
*
|
||||||
|
from
|
||||||
|
polygon_labels
|
||||||
|
where address= :address
|
||||||
|
AND label='moonworm-alpha'
|
||||||
|
AND block_timestamp >= extract(epoch from now() - interval :time_range)::int
|
||||||
|
),
|
||||||
|
nfts_data as (
|
||||||
|
select
|
||||||
|
transaction_hash,
|
||||||
|
label_data->'args'->>'to' as buyer,
|
||||||
|
label_data->'args'->>'from' as seller,
|
||||||
|
jsonb_array_elements(label_data -> 'args' -> 'values') :: decimal as value,
|
||||||
|
jsonb_array_elements(label_data -> 'args' -> 'ids')->>0 as token_id,
|
||||||
|
to_char(to_timestamp(block_timestamp), :time_format) as time
|
||||||
|
from
|
||||||
|
labels_data
|
||||||
|
where
|
||||||
|
label_data ->> 'name' = 'TransferBatch'
|
||||||
|
UNION ALL
|
||||||
|
select
|
||||||
|
transaction_hash,
|
||||||
|
label_data->'args'->>'to' as buyer,
|
||||||
|
label_data->'args'->>'from' as seller,
|
||||||
|
(label_data -> 'args' ->> 'value') :: decimal as value,
|
||||||
|
label_data -> 'args' ->> 'id' as token_id,
|
||||||
|
to_char(to_timestamp(block_timestamp), :time_format) as time
|
||||||
|
from
|
||||||
|
labels_data
|
||||||
|
where
|
||||||
|
label_data ->> 'name' = 'TransferSingle'
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
time as time,
|
||||||
|
token_id as token_id,
|
||||||
|
sum(nfts_data.value) as value,
|
||||||
|
sum(
|
||||||
|
CASE
|
||||||
|
WHEN to_address in ('0xF715bEb51EC8F63317d66f491E37e7BB048fCc2d','0xfede379e48C873C75F3cc0C81F7C784aD730a8F7','0x00000000006c3852cbef3e08e8df289169ede581')
|
||||||
|
THEN 1
|
||||||
|
else 0
|
||||||
|
END
|
||||||
|
) as os_sales
|
||||||
|
from nfts_data
|
||||||
|
LEFT JOIN polygon_transactions ON nfts_data.transaction_hash = polygon_transactions.hash
|
||||||
|
GROUP BY
|
||||||
|
time,
|
||||||
|
token_id
|
||||||
|
ORDER BY token_id::int, time DESC
|
||||||
|
""",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "most_recent_sale",
|
||||||
|
"query": """
|
||||||
|
with contract_erc721_transfers as (
|
||||||
|
select
|
||||||
|
transaction_hash,
|
||||||
|
label_data->'args'->>'tokenId' as token_id,
|
||||||
|
label_data->'args'->>'to' as buyer,
|
||||||
|
label_data->'args'->>'from' as seller,
|
||||||
|
block_timestamp as block_timestamp
|
||||||
|
from polygon_labels
|
||||||
|
where label='moonworm-alpha'
|
||||||
|
and address= :address
|
||||||
|
and label_data->>'name'='Transfer'
|
||||||
|
order by block_number desc
|
||||||
|
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
polygon_transactions.hash as transaction_hash,
|
||||||
|
contract_erc721_transfers.block_timestamp as block_timestamp,
|
||||||
|
contract_erc721_transfers.token_id as token_id,
|
||||||
|
contract_erc721_transfers.buyer as buyer,
|
||||||
|
contract_erc721_transfers.seller as seller
|
||||||
|
from polygon_transactions
|
||||||
|
inner JOIN contract_erc721_transfers ON contract_erc721_transfers.transaction_hash = polygon_transactions.hash
|
||||||
|
where polygon_transactions.to_address in ('0xF715bEb51EC8F63317d66f491E37e7BB048fCc2d','0xfede379e48C873C75F3cc0C81F7C784aD730a8F7', '0x00000000006c3852cbef3e08e8df289169ede581')
|
||||||
|
limit :amount
|
||||||
|
""",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "most_active_buyers",
|
||||||
|
"query": """
|
||||||
|
with contracts_data as (
|
||||||
|
select
|
||||||
|
*
|
||||||
|
from polygon_labels
|
||||||
|
where label='moonworm-alpha'
|
||||||
|
and address= :address
|
||||||
|
and block_timestamp >= extract(epoch from now() - interval :time_range)::int
|
||||||
|
), contract_nfts_transfers as (
|
||||||
|
select
|
||||||
|
transaction_hash,
|
||||||
|
label_data->'args'->>'to' as buyer,
|
||||||
|
label_data->'args'->>'from' as seller
|
||||||
|
from contracts_data
|
||||||
|
where label_data->>'name'='Transfer'
|
||||||
|
UNION ALL
|
||||||
|
select
|
||||||
|
transaction_hash,
|
||||||
|
label_data->'args'->>'to' as buyer,
|
||||||
|
label_data->'args'->>'from' as seller
|
||||||
|
from
|
||||||
|
contracts_data
|
||||||
|
where
|
||||||
|
label_data ->> 'name' = 'TransferBatch'
|
||||||
|
UNION ALL
|
||||||
|
select
|
||||||
|
transaction_hash,
|
||||||
|
label_data->'args'->>'to' as buyer,
|
||||||
|
label_data->'args'->>'from' as seller
|
||||||
|
from
|
||||||
|
contracts_data
|
||||||
|
where
|
||||||
|
label_data ->> 'name' = 'TransferSingle'
|
||||||
|
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
contract_nfts_transfers.buyer as buyer,
|
||||||
|
count(*) as sale_count
|
||||||
|
from polygon_transactions
|
||||||
|
inner JOIN contract_nfts_transfers ON contract_nfts_transfers.transaction_hash = polygon_transactions.hash
|
||||||
|
where polygon_transactions.to_address in ('0xF715bEb51EC8F63317d66f491E37e7BB048fCc2d','0xfede379e48C873C75F3cc0C81F7C784aD730a8F7','0x00000000006c3852cbEf3e08E8dF289169EdE581')
|
||||||
|
group by contract_nfts_transfers.buyer
|
||||||
|
order by sale_count desc
|
||||||
|
""",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "most_active_sellers",
|
||||||
|
"query": """
|
||||||
|
with contracts_data as (
|
||||||
|
select
|
||||||
|
*
|
||||||
|
from polygon_labels
|
||||||
|
where label='moonworm-alpha'
|
||||||
|
and address= :address
|
||||||
|
and block_timestamp >= extract(epoch from now() - interval :time_range)::int
|
||||||
|
), contract_nfts_transfers as (
|
||||||
|
select
|
||||||
|
transaction_hash,
|
||||||
|
label_data->'args'->>'to' as buyer,
|
||||||
|
label_data->'args'->>'from' as seller
|
||||||
|
from contracts_data
|
||||||
|
where label_data->>'name'='Transfer'
|
||||||
|
UNION ALL
|
||||||
|
select
|
||||||
|
transaction_hash,
|
||||||
|
label_data->'args'->>'to' as buyer,
|
||||||
|
label_data->'args'->>'from' as seller
|
||||||
|
from
|
||||||
|
contracts_data
|
||||||
|
where
|
||||||
|
label_data ->> 'name' = 'TransferBatch'
|
||||||
|
UNION ALL
|
||||||
|
select
|
||||||
|
transaction_hash,
|
||||||
|
label_data->'args'->>'to' as buyer,
|
||||||
|
label_data->'args'->>'from' as seller
|
||||||
|
from
|
||||||
|
contracts_data
|
||||||
|
where
|
||||||
|
label_data ->> 'name' = 'TransferSingle'
|
||||||
|
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
contract_nfts_transfers.seller as seller,
|
||||||
|
count(*) as sale_count
|
||||||
|
from polygon_transactions
|
||||||
|
inner JOIN contract_nfts_transfers ON contract_nfts_transfers.transaction_hash = polygon_transactions.hash
|
||||||
|
where polygon_transactions.to_address in ('0xF715bEb51EC8F63317d66f491E37e7BB048fCc2d','0xfede379e48C873C75F3cc0C81F7C784aD730a8F7','0x00000000006c3852cbEf3e08E8dF289169EdE581')
|
||||||
|
group by contract_nfts_transfers.seller
|
||||||
|
order by sale_count desc
|
||||||
|
""",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "lagerst_owners",
|
||||||
|
"query": """
|
||||||
|
WITH erc_1155_721_contracts_transfers_with_trashhold as (
|
||||||
|
SELECT
|
||||||
|
label_data as label_data,
|
||||||
|
block_timestamp as block_timestamp,
|
||||||
|
address as address
|
||||||
|
from
|
||||||
|
polygon_labels
|
||||||
|
WHERE
|
||||||
|
polygon_labels.label = 'moonworm-alpha'
|
||||||
|
AND polygon_labels.address = :address
|
||||||
|
|
||||||
|
),
|
||||||
|
own_erc_1155_721_count as (
|
||||||
|
Select
|
||||||
|
difference.address,
|
||||||
|
(
|
||||||
|
difference.transfers_in - difference.transfers_out
|
||||||
|
) as owned_nfts
|
||||||
|
from
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
total.address,
|
||||||
|
sum(total.transfer_out) as transfers_out,
|
||||||
|
sum(total.transfer_in) as transfers_in
|
||||||
|
from
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
label_data -> 'args' ->> 'from' as address,
|
||||||
|
jsonb_array_elements(label_data -> 'args' -> 'values') :: decimal as transfer_out,
|
||||||
|
0 as transfer_in
|
||||||
|
from
|
||||||
|
erc_1155_721_contracts_transfers_with_trashhold
|
||||||
|
where
|
||||||
|
label_data ->> 'name' = 'TransferBatch'
|
||||||
|
UNION
|
||||||
|
ALL
|
||||||
|
SELECT
|
||||||
|
label_data -> 'args' ->> 'from' as address,
|
||||||
|
(label_data -> 'args' ->> 'value') :: decimal as transfer_out,
|
||||||
|
0 as transfer_in
|
||||||
|
from
|
||||||
|
erc_1155_721_contracts_transfers_with_trashhold
|
||||||
|
where
|
||||||
|
label_data ->> 'name' = 'TransferSingle'
|
||||||
|
UNION
|
||||||
|
ALL
|
||||||
|
select
|
||||||
|
label_data -> 'args' ->> 'to' as address,
|
||||||
|
0 as transfer_out,
|
||||||
|
(label_data -> 'args' ->>'value') :: decimal as transfer_in
|
||||||
|
from
|
||||||
|
erc_1155_721_contracts_transfers_with_trashhold
|
||||||
|
where
|
||||||
|
label_data ->> 'name' = 'TransferSingle'
|
||||||
|
UNION
|
||||||
|
ALL
|
||||||
|
select
|
||||||
|
label_data -> 'args' ->> 'to' as address,
|
||||||
|
0 as transfer_out,
|
||||||
|
jsonb_array_elements(label_data -> 'args' -> 'values') :: decimal as transfer_in
|
||||||
|
from
|
||||||
|
erc_1155_721_contracts_transfers_with_trashhold
|
||||||
|
where
|
||||||
|
label_data ->> 'name' = 'TransferBatch'
|
||||||
|
UNION
|
||||||
|
ALL
|
||||||
|
select
|
||||||
|
label_data -> 'args' ->> 'from' as address,
|
||||||
|
1 as transfer_out,
|
||||||
|
0 as transfer_in
|
||||||
|
from
|
||||||
|
erc_1155_721_contracts_transfers_with_trashhold
|
||||||
|
|
||||||
|
where
|
||||||
|
label_data ->> 'name' = 'Transfer'
|
||||||
|
UNION
|
||||||
|
ALL
|
||||||
|
select
|
||||||
|
label_data -> 'args' ->> 'to' as address,
|
||||||
|
0 as transfer_out,
|
||||||
|
1 as transfer_in
|
||||||
|
from
|
||||||
|
erc_1155_721_contracts_transfers_with_trashhold
|
||||||
|
|
||||||
|
where
|
||||||
|
label_data ->> 'name' = 'Transfer'
|
||||||
|
) as total
|
||||||
|
group by
|
||||||
|
address
|
||||||
|
) difference
|
||||||
|
order by
|
||||||
|
owned_nfts desc
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
*
|
||||||
|
from
|
||||||
|
own_erc_1155_721_count
|
||||||
|
WHERE
|
||||||
|
address not in (
|
||||||
|
'0x000000000000000000000000000000000000dEaD',
|
||||||
|
'0x0000000000000000000000000000000000000000'
|
||||||
|
)
|
||||||
|
order by
|
||||||
|
owned_nfts desc
|
||||||
|
""",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "total_supply_erc721",
|
||||||
|
"query": """
|
||||||
|
select
|
||||||
|
count(*) as total_supply
|
||||||
|
from(
|
||||||
|
SELECT DISTINCT ON((label_data->'args'->>'tokenId')::INT) (label_data->'args'->>'tokenId')::INT as token_id,
|
||||||
|
label_data->'args'->>'to' as current_owner
|
||||||
|
FROM polygon_labels
|
||||||
|
WHERE address = :address
|
||||||
|
AND (label = 'moonworm' or label = 'moonworm-alpha')
|
||||||
|
AND block_number >= 21418707
|
||||||
|
AND label_data->>'type' = 'event'
|
||||||
|
AND label_data->>'name' = 'Transfer'
|
||||||
|
AND label_data->'args'->>'to' != '0x8d528e98A69FE27b11bb02Ac264516c4818C3942'
|
||||||
|
AND label_data->'args'->>'from' != '0x8d528e98A69FE27b11bb02Ac264516c4818C3942'
|
||||||
|
ORDER BY (label_data->'args'->>'tokenId')::INT ASC,
|
||||||
|
block_number::INT DESC,
|
||||||
|
log_index::INT DESC
|
||||||
|
) as total_supply
|
||||||
|
where current_owner not in ('0x000000000000000000000000000000000000dEaD','0x0000000000000000000000000000000000000000')
|
||||||
|
""",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "total_supply_terminus",
|
||||||
|
"query": """
|
||||||
|
WITH erc_1155_721_contracts_transfers_with_trashhold as (
|
||||||
|
SELECT
|
||||||
|
label_data as label_data,
|
||||||
|
block_timestamp as block_timestamp,
|
||||||
|
address as address
|
||||||
|
from
|
||||||
|
polygon_labels
|
||||||
|
WHERE
|
||||||
|
polygon_labels.label = 'moonworm-alpha'
|
||||||
|
AND polygon_labels.address = :address
|
||||||
|
),
|
||||||
|
own_erc_1155_721_count as (
|
||||||
|
Select
|
||||||
|
|
||||||
|
difference.address,
|
||||||
|
token_id,
|
||||||
|
(
|
||||||
|
difference.transfers_in - difference.transfers_out
|
||||||
|
) as owned_nfts
|
||||||
|
from
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
total.address,
|
||||||
|
token_id,
|
||||||
|
sum(total.transfer_out) as transfers_out,
|
||||||
|
sum(total.transfer_in) as transfers_in
|
||||||
|
from
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
label_data -> 'args' ->> 'from' as address,
|
||||||
|
jsonb_array_elements(label_data -> 'args' -> 'ids')->>0 as token_id,
|
||||||
|
jsonb_array_elements(label_data -> 'args' -> 'values') :: decimal as transfer_out,
|
||||||
|
0 as transfer_in
|
||||||
|
from
|
||||||
|
erc_1155_721_contracts_transfers_with_trashhold
|
||||||
|
where
|
||||||
|
label_data ->> 'name' = 'TransferBatch'
|
||||||
|
UNION
|
||||||
|
ALL
|
||||||
|
SELECT
|
||||||
|
label_data -> 'args' ->> 'from' as address,
|
||||||
|
label_data -> 'args' ->> 'id' as token_id,
|
||||||
|
(label_data -> 'args' ->> 'value') :: decimal as transfer_out,
|
||||||
|
0 as transfer_in
|
||||||
|
from
|
||||||
|
erc_1155_721_contracts_transfers_with_trashhold
|
||||||
|
where
|
||||||
|
label_data ->> 'name' = 'TransferSingle'
|
||||||
|
UNION
|
||||||
|
ALL
|
||||||
|
select
|
||||||
|
label_data -> 'args' ->> 'to' as address,
|
||||||
|
label_data -> 'args' ->> 'id' as token_id,
|
||||||
|
0 as transfer_out,
|
||||||
|
(label_data -> 'args' ->>'value') :: decimal as transfer_in
|
||||||
|
from
|
||||||
|
erc_1155_721_contracts_transfers_with_trashhold
|
||||||
|
where
|
||||||
|
label_data ->> 'name' = 'TransferSingle'
|
||||||
|
UNION
|
||||||
|
ALL
|
||||||
|
select
|
||||||
|
label_data -> 'args' ->> 'to' as address,
|
||||||
|
jsonb_array_elements(label_data -> 'args' -> 'ids')->>0 as token_id,
|
||||||
|
0 as transfer_out,
|
||||||
|
jsonb_array_elements(label_data -> 'args' -> 'values') :: decimal as transfer_in
|
||||||
|
from
|
||||||
|
erc_1155_721_contracts_transfers_with_trashhold
|
||||||
|
where
|
||||||
|
label_data ->> 'name' = 'TransferBatch'
|
||||||
|
) as total
|
||||||
|
group by
|
||||||
|
address, token_id
|
||||||
|
) difference
|
||||||
|
order by
|
||||||
|
owned_nfts desc
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
token_id as token_id,
|
||||||
|
sum(owned_nfts) as total_supply
|
||||||
|
from
|
||||||
|
own_erc_1155_721_count
|
||||||
|
WHERE
|
||||||
|
address not in (
|
||||||
|
'0x000000000000000000000000000000000000dEaD',
|
||||||
|
'0x0000000000000000000000000000000000000000'
|
||||||
|
)
|
||||||
|
group by
|
||||||
|
token_id
|
||||||
|
order by
|
||||||
|
token_id::int desc
|
||||||
|
""",
|
||||||
|
},
|
||||||
|
]
|
|
@ -193,3 +193,9 @@ multicall_contracts: Dict[AvailableBlockchainType, str] = {
|
||||||
AvailableBlockchainType.MUMBAI: "0xe9939e7Ea7D7fb619Ac57f648Da7B1D425832631",
|
AvailableBlockchainType.MUMBAI: "0xe9939e7Ea7D7fb619Ac57f648Da7B1D425832631",
|
||||||
AvailableBlockchainType.ETHEREUM: "0x5BA1e12693Dc8F9c48aAD8770482f4739bEeD696",
|
AvailableBlockchainType.ETHEREUM: "0x5BA1e12693Dc8F9c48aAD8770482f4739bEeD696",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Custom Crawler
|
||||||
|
|
||||||
|
CUSTOM_CRAWLER_S3_BUCKET = os.environ.get("CUSTOM_CRAWLER_S3_BUCKET", "") # S3 bucket for storing custom crawler data
|
||||||
|
CUSTOM_CRAWLER_S3_BUCKET_PREFIX = os.environ.get("CUSTOM_CRAWLER_S3_BUCKET_PREFIX", "dev")
|
Ładowanie…
Reference in New Issue