Skip to content

Commit 736b0fb

Browse files
committed
feat: sort by last_block_number
1 parent 71e2470 commit 736b0fb

3 files changed

Lines changed: 26 additions & 9 deletions

File tree

models/credmark/ledger/transactions.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ class TxAccountsInput(Contract):
99
offset: int = DTOField(
1010
0, ge=0, description="Omit a specified number of holders from beginning of result set"
1111
)
12-
order_by: str = DTOField("most_transactions", description="Sort by count or newest")
12+
order_by: str = DTOField(
13+
"most_transactions",
14+
description="Sort by most_transactions, least_transactions, oldest, newest, most_recent or least_recent",
15+
)
1316
start_block_number: float = DTOField(
1417
-1,
1518
description="Minimum unscaled balance for a holder to be included. Default is -1, \
@@ -52,6 +55,10 @@ def run(self, input: TxAccountsInput) -> TxAccountsOutput:
5255
order_by = q.field("first_block_number").dquote().desc()
5356
elif input.order_by == "oldest":
5457
order_by = q.field("first_block_number").dquote().asc()
58+
elif input.order_by == "most_recent":
59+
order_by = q.field("last_block_number").dquote().desc()
60+
elif input.order_by == "least_recent":
61+
order_by = q.field("last_block_number").dquote().asc()
5562
elif input.order_by == "most_transactions":
5663
order_by = q.field("count").dquote().desc()
5764
elif input.order_by == "least_transactions":

models/credmark/tokens/nft/nft.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
from credmark.cmf.model.errors import ModelInputError
1717
from credmark.cmf.types import Address, Contract, JoinType, Token
1818
from credmark.dto import DTO, DTOField
19-
from web3.exceptions import (ABIFunctionNotFound, BadFunctionCallOutput,
20-
ContractLogicError)
19+
from web3.exceptions import ABIFunctionNotFound, BadFunctionCallOutput, ContractLogicError
2120

2221
AZUKI_NFT = "0xED5AF388653567Af2F388E6224dC7C4b3241C544"
2322
RTFKT_MNLTH_NFT = "0x86825dFCa7A6224cfBd2DA48e85DF2fc3Aa7C4B1"
@@ -123,7 +122,7 @@ def run(self, input: NFTContract) -> dict:
123122
minted_ids_count = minted_ids.shape[0]
124123

125124
self.logger.info(
126-
f'{minted_ids_count=} {set(range(0, minted_ids_count)) - set(df_mint.evt_tokenid.astype("int"))}'
125+
f"{minted_ids_count=} {set(range(0, minted_ids_count)) - set(df_mint.evt_tokenid.astype('int'))}"
127126
)
128127

129128
df_mint["value"] = df_mint["value"].astype("float64") / 1e18
@@ -258,7 +257,8 @@ class NFTHolderInput(NFTContract):
258257
0, ge=0, description="Omit a specified number of holders from beginning of result set"
259258
)
260259
order_by: str = DTOField(
261-
"most_tokens", description="Sort by most_tokens, least_tokens, oldest or newest"
260+
"most_tokens",
261+
description="Sort by most_tokens, least_tokens, oldest, newest, most_recent or least_recent",
262262
)
263263

264264

@@ -307,9 +307,10 @@ async def get_attributes_bulk_async(self, urls: Iterable[str]):
307307
tcp_connection = aiohttp.TCPConnector(
308308
limit=max_workers, force_close=True, enable_cleanup_closed=True
309309
)
310-
async with aiohttp.ClientSession(
311-
connector=tcp_connection
312-
) as session, asyncio.TaskGroup() as tg:
310+
async with (
311+
aiohttp.ClientSession(connector=tcp_connection) as session,
312+
asyncio.TaskGroup() as tg,
313+
):
313314
responses = [tg.create_task(self.get_nft_attributes(session, url)) for url in urls]
314315
responses = await asyncio.gather(*responses)
315316
# await asyncio.sleep(0.250)
@@ -379,6 +380,10 @@ def run(self, input: NFTHolderInput) -> NFTHoldersOutput:
379380
order_by = q.field("first_block_number").dquote().desc()
380381
elif input.order_by == "oldest":
381382
order_by = q.field("first_block_number").dquote().asc()
383+
elif input.order_by == "most_recent":
384+
order_by = q.field("last_block_number").dquote().desc()
385+
elif input.order_by == "least_recent":
386+
order_by = q.field("last_block_number").dquote().asc()
382387
elif input.order_by == "most_tokens":
383388
order_by = q.field("balance").dquote().desc()
384389
elif input.order_by == "least_tokens":

models/credmark/tokens/token.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,8 @@ class TokenHolderInput(Token):
748748
0, ge=0, description="Omit a specified number of holders from beginning of result set"
749749
)
750750
order_by: str = DTOField(
751-
"most_tokens", description="Sort by most_tokens, least_tokens, oldest or newest"
751+
"most_tokens",
752+
description="Sort by most_tokens, least_tokens, oldest, newest, most_recent or least_recent",
752753
)
753754
quote: Currency = DTOField(
754755
FiatCurrency(symbol="USD"), description="Quote token address to count the value"
@@ -802,6 +803,10 @@ def run(self, input: TokenHolderInput) -> TokenHoldersOutput:
802803
order_by = q.field("first_block_number").dquote().desc()
803804
elif input.order_by == "oldest":
804805
order_by = q.field("first_block_number").dquote().asc()
806+
elif input.order_by == "most_recent":
807+
order_by = q.field("last_block_number").dquote().desc()
808+
elif input.order_by == "least_recent":
809+
order_by = q.field("last_block_number").dquote().asc()
805810
elif input.order_by == "most_tokens":
806811
order_by = q.field("balance").dquote().desc()
807812
elif input.order_by == "least_tokens":

0 commit comments

Comments
 (0)