kopia lustrzana https://github.com/bugout-dev/moonstream
Add terminus.
rodzic
920c8941ef
commit
e23fd52453
|
@ -1,5 +1,7 @@
|
|||
import argparse
|
||||
import datetime
|
||||
from timeit import repeat
|
||||
from eth_typing import Address
|
||||
from moonstream.client import Moonstream
|
||||
import time
|
||||
import requests
|
||||
|
@ -232,25 +234,62 @@ def init_tokenomics_queries_handler(args: argparse.Namespace):
|
|||
|
||||
query = """
|
||||
select
|
||||
sum(value),
|
||||
time,
|
||||
sum(value) as volume,
|
||||
time as time,
|
||||
count(*) as activity
|
||||
from (
|
||||
select (label_data->'args'->>'value')::decimal as value, to_char(to_timestamp(block_timestamp), :time_format) as time from polygon_labels
|
||||
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='0x64060aB139Feaae7f06Ca4E63189D86aDEb51691'
|
||||
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
|
||||
|
||||
# Create
|
||||
client.create_query(
|
||||
token=args.moonstream_token,
|
||||
name="cu-voluem",
|
||||
query=query,
|
||||
)
|
||||
# query = """
|
||||
# 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:
|
||||
# pass
|
||||
|
||||
|
||||
def run_tokenomics_queries_handler(args: argparse.Namespace):
|
||||
|
@ -261,41 +300,71 @@ def run_tokenomics_queries_handler(args: argparse.Namespace):
|
|||
# token=args.moonstream_token,
|
||||
# ).queries:
|
||||
|
||||
query_name = "cu-volume"
|
||||
params = {}
|
||||
query_name = "cu_voluem"
|
||||
|
||||
# if (
|
||||
# query.name == "cu-bank-withdrawals-total"
|
||||
# or query.name == "cu-bank-withdrawals-events"
|
||||
# ):
|
||||
# blocktimestamp = int(time.time())
|
||||
#
|
||||
params = {"time_format": "YYYY-MM-DD HH24:00:00", "time_range": "24 hours"}
|
||||
### Run voluem query
|
||||
|
||||
keep_going = True
|
||||
ranges = [
|
||||
{"time_format": "YYYY-MM-DD HH24", "time_range": "24 hours"},
|
||||
{"time_format": "YYYY-MM-DD HH24", "time_range": "7 days"},
|
||||
{"time_format": "YYYY-MM-DD", "time_range": "30 days"},
|
||||
]
|
||||
|
||||
if_modified_since_datetime = datetime.datetime.utcnow()
|
||||
if_modified_since = if_modified_since_datetime.strftime("%a, %d %b %Y %H:%M:%S GMT")
|
||||
addresess = {
|
||||
"0x64060aB139Feaae7f06Ca4E63189D86aDEb51691": "ERC20", # UNIM
|
||||
"0x431CD3C9AC9Fc73644BF68bF5691f4B83F9E104f": "ERC20", # RBW
|
||||
"0xdC0479CC5BbA033B3e7De9F178607150B3AbCe1f": "NFT", # unicorns
|
||||
"0xA2a13cE1824F3916fC84C65e559391fc6674e6e8": "NFT", # lands
|
||||
}
|
||||
|
||||
data_url = client.exec_query(
|
||||
token=args.token,
|
||||
query_name=query_name,
|
||||
params=params,
|
||||
) # S3 presign_url
|
||||
while keep_going:
|
||||
data_response = requests.get(
|
||||
data_url,
|
||||
headers={"If-Modified-Since": if_modified_since},
|
||||
timeout=10,
|
||||
)
|
||||
# push to s3
|
||||
for address, type in addresess.items():
|
||||
for range in ranges:
|
||||
|
||||
if data_response.status_code == 200:
|
||||
json.dumps(data_response.json())
|
||||
break
|
||||
else:
|
||||
# You can put a sleep in here if you want
|
||||
continue
|
||||
params = {
|
||||
"address": address,
|
||||
"type": type,
|
||||
"time_format": range["time_format"],
|
||||
"time_range": range["time_range"],
|
||||
}
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
data_url = client.exec_query(
|
||||
token=args.moonstream_token,
|
||||
name=query_name,
|
||||
params=params,
|
||||
) # S3 presign_url
|
||||
print(f"Data URL: {data_url.url}")
|
||||
while keep_going:
|
||||
time.sleep(2)
|
||||
data_response = requests.get(
|
||||
data_url.url,
|
||||
headers={"If-Modified-Since": if_modified_since},
|
||||
timeout=10,
|
||||
)
|
||||
# push to s3
|
||||
|
||||
if data_response.status_code == 200:
|
||||
# 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
|
||||
|
||||
if repeat > 20:
|
||||
print("Too many retries")
|
||||
break
|
||||
|
||||
|
||||
def list_user_queries_handler(args: argparse.Namespace):
|
||||
|
@ -306,7 +375,7 @@ def list_user_queries_handler(args: argparse.Namespace):
|
|||
client = Moonstream()
|
||||
|
||||
queries = client.list_queries(
|
||||
token=args.token,
|
||||
token=args.moonstream_token,
|
||||
)
|
||||
|
||||
for query in queries.queries:
|
||||
|
@ -320,7 +389,7 @@ def delete_user_query(args: argparse.Namespace):
|
|||
client = Moonstream()
|
||||
|
||||
id = client.delete_query(
|
||||
token=args.token,
|
||||
token=args.moonstream_token,
|
||||
name=args.name,
|
||||
)
|
||||
|
||||
|
@ -356,8 +425,9 @@ def generate_game_bank_report(args: argparse.Namespace):
|
|||
)
|
||||
|
||||
data_url = client.exec_query(
|
||||
token=args.token,
|
||||
token=args.moonstream_token,
|
||||
query_name=query.name,
|
||||
params=params,
|
||||
) # S3 presign_url
|
||||
while keep_going:
|
||||
data_response = requests.get(
|
||||
|
@ -473,3 +543,97 @@ def main():
|
|||
|
||||
if __name__ == "__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
|
||||
"""
|
||||
|
|
Ładowanie…
Reference in New Issue