dao-treasury 0.0.35__cp311-cp311-win_amd64.whl → 0.0.71__cp311-cp311-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of dao-treasury might be problematic. Click here for more details.
- dao_treasury/.grafana/provisioning/dashboards/breakdowns/Expenses.json +551 -0
- dao_treasury/.grafana/provisioning/dashboards/breakdowns/Revenue.json +551 -0
- dao_treasury/.grafana/provisioning/dashboards/dashboards.yaml +7 -57
- dao_treasury/.grafana/provisioning/dashboards/streams/LlamaPay.json +11 -16
- dao_treasury/.grafana/provisioning/dashboards/summary/Monthly.json +284 -22
- dao_treasury/.grafana/provisioning/dashboards/transactions/Treasury Transactions.json +193 -235
- dao_treasury/.grafana/provisioning/dashboards/treasury/Cashflow (Including Unsorted).json +122 -149
- dao_treasury/.grafana/provisioning/dashboards/treasury/Cashflow.json +87 -100
- dao_treasury/.grafana/provisioning/dashboards/treasury/Current Treasury Assets.json +981 -0
- dao_treasury/.grafana/provisioning/dashboards/treasury/Historical Treasury Balances.json +3060 -0
- dao_treasury/.grafana/provisioning/dashboards/treasury/Operating Cashflow.json +64 -78
- dao_treasury/ENVIRONMENT_VARIABLES.py +12 -0
- dao_treasury/__init__.py +14 -0
- dao_treasury/_docker.cp311-win_amd64.pyd +0 -0
- dao_treasury/_docker.py +38 -21
- dao_treasury/_nicknames.cp311-win_amd64.pyd +0 -0
- dao_treasury/_nicknames.py +15 -0
- dao_treasury/_wallet.cp311-win_amd64.pyd +0 -0
- dao_treasury/constants.cp311-win_amd64.pyd +0 -0
- dao_treasury/constants.py +24 -0
- dao_treasury/db.py +74 -4
- dao_treasury/docker-compose.yaml +1 -1
- dao_treasury/main.py +39 -1
- dao_treasury/sorting/__init__.cp311-win_amd64.pyd +0 -0
- dao_treasury/sorting/_matchers.cp311-win_amd64.pyd +0 -0
- dao_treasury/sorting/_rules.cp311-win_amd64.pyd +0 -0
- dao_treasury/sorting/factory.cp311-win_amd64.pyd +0 -0
- dao_treasury/sorting/rule.cp311-win_amd64.pyd +0 -0
- dao_treasury/sorting/rule.py +8 -10
- dao_treasury/sorting/rules/__init__.cp311-win_amd64.pyd +0 -0
- dao_treasury/sorting/rules/ignore/__init__.cp311-win_amd64.pyd +0 -0
- dao_treasury/sorting/rules/ignore/llamapay.cp311-win_amd64.pyd +0 -0
- dao_treasury/streams/__init__.cp311-win_amd64.pyd +0 -0
- dao_treasury/streams/llamapay.cp311-win_amd64.pyd +0 -0
- dao_treasury/streams/llamapay.py +14 -2
- dao_treasury/treasury.py +37 -16
- dao_treasury/types.cp311-win_amd64.pyd +0 -0
- {dao_treasury-0.0.35.dist-info → dao_treasury-0.0.71.dist-info}/METADATA +18 -3
- dao_treasury-0.0.71.dist-info/RECORD +54 -0
- dao_treasury-0.0.71.dist-info/top_level.txt +2 -0
- dao_treasury__mypyc.cp311-win_amd64.pyd +0 -0
- bf2b4fe1f86ad2ea158b__mypyc.cp311-win_amd64.pyd +0 -0
- dao_treasury/.grafana/provisioning/dashboards/treasury/Treasury.json +0 -2018
- dao_treasury-0.0.35.dist-info/RECORD +0 -51
- dao_treasury-0.0.35.dist-info/top_level.txt +0 -2
- {dao_treasury-0.0.35.dist-info → dao_treasury-0.0.71.dist-info}/WHEEL +0 -0
dao_treasury/db.py
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Database models and utilities for DAO treasury reporting.
|
|
4
4
|
|
|
5
5
|
This module defines Pony ORM entities for:
|
|
6
|
+
|
|
6
7
|
- Blockchain networks (:class:`Chain`)
|
|
7
8
|
- On-chain addresses (:class:`Address`)
|
|
8
9
|
- ERC-20 tokens and native coin placeholder (:class:`Token`)
|
|
@@ -17,27 +18,41 @@ and creating SQL views for reporting.
|
|
|
17
18
|
|
|
18
19
|
import typing
|
|
19
20
|
from asyncio import Semaphore
|
|
21
|
+
from collections import OrderedDict
|
|
20
22
|
from decimal import Decimal, InvalidOperation
|
|
21
23
|
from functools import lru_cache
|
|
22
24
|
from logging import getLogger
|
|
23
25
|
from os import path
|
|
24
26
|
from pathlib import Path
|
|
25
|
-
from typing import
|
|
27
|
+
from typing import (
|
|
28
|
+
TYPE_CHECKING,
|
|
29
|
+
Any,
|
|
30
|
+
Coroutine,
|
|
31
|
+
Dict,
|
|
32
|
+
Final,
|
|
33
|
+
Literal,
|
|
34
|
+
Tuple,
|
|
35
|
+
Union,
|
|
36
|
+
final,
|
|
37
|
+
overload,
|
|
38
|
+
)
|
|
26
39
|
from datetime import date, datetime, time, timezone
|
|
27
40
|
|
|
41
|
+
import eth_portfolio
|
|
28
42
|
from a_sync import AsyncThreadPoolExecutor
|
|
29
43
|
from brownie import chain
|
|
30
44
|
from brownie.convert.datatypes import HexString
|
|
31
45
|
from brownie.exceptions import EventLookupError
|
|
32
46
|
from brownie.network.event import EventDict, _EventItem
|
|
33
47
|
from brownie.network.transaction import TransactionReceipt
|
|
34
|
-
from eth_typing import ChecksumAddress, HexAddress, HexStr
|
|
35
48
|
from eth_portfolio.structs import (
|
|
36
49
|
InternalTransfer,
|
|
37
50
|
LedgerEntry,
|
|
38
51
|
TokenTransfer,
|
|
39
52
|
Transaction,
|
|
40
53
|
)
|
|
54
|
+
from eth_retry import auto_retry
|
|
55
|
+
from eth_typing import ChecksumAddress, HexAddress, HexStr
|
|
41
56
|
from pony.orm import (
|
|
42
57
|
Database,
|
|
43
58
|
InterfaceError,
|
|
@@ -53,6 +68,7 @@ from pony.orm import (
|
|
|
53
68
|
select,
|
|
54
69
|
)
|
|
55
70
|
from y import EEE_ADDRESS, Contract, Network, convert, get_block_timestamp_async
|
|
71
|
+
from y._db.decorators import retry_locked
|
|
56
72
|
from y.contracts import _get_code
|
|
57
73
|
from y.exceptions import ContractNotVerified
|
|
58
74
|
|
|
@@ -60,6 +76,9 @@ from dao_treasury.constants import CHAINID
|
|
|
60
76
|
from dao_treasury.types import TxGroupDbid, TxGroupName
|
|
61
77
|
|
|
62
78
|
|
|
79
|
+
EventItem = _EventItem[_EventItem[OrderedDict[str, Any]]]
|
|
80
|
+
|
|
81
|
+
|
|
63
82
|
SQLITE_DIR = Path(path.expanduser("~")) / ".dao-treasury"
|
|
64
83
|
"""Path to the directory in the user's home where the DAO treasury SQLite database is stored."""
|
|
65
84
|
|
|
@@ -68,6 +87,7 @@ SQLITE_DIR.mkdir(parents=True, exist_ok=True)
|
|
|
68
87
|
|
|
69
88
|
_INSERT_THREAD = AsyncThreadPoolExecutor(1)
|
|
70
89
|
_SORT_THREAD = AsyncThreadPoolExecutor(1)
|
|
90
|
+
_EVENTS_THREADS = AsyncThreadPoolExecutor(16)
|
|
71
91
|
_SORT_SEMAPHORE = Semaphore(50)
|
|
72
92
|
|
|
73
93
|
_UTC = timezone.utc
|
|
@@ -234,6 +254,10 @@ class Address(DbEntity):
|
|
|
234
254
|
def contract(self) -> Contract:
|
|
235
255
|
return Contract(self.address)
|
|
236
256
|
|
|
257
|
+
@property
|
|
258
|
+
def contract_coro(self) -> Coroutine[Any, Any, Contract]:
|
|
259
|
+
return Contract.coroutine(self.address)
|
|
260
|
+
|
|
237
261
|
@staticmethod
|
|
238
262
|
@lru_cache(maxsize=None)
|
|
239
263
|
def get_dbid(address: HexAddress) -> int:
|
|
@@ -294,7 +318,6 @@ class Address(DbEntity):
|
|
|
294
318
|
)
|
|
295
319
|
|
|
296
320
|
commit()
|
|
297
|
-
|
|
298
321
|
return entity # type: ignore [no-any-return]
|
|
299
322
|
|
|
300
323
|
@staticmethod
|
|
@@ -405,6 +428,10 @@ class Token(DbEntity):
|
|
|
405
428
|
def contract(self) -> Contract:
|
|
406
429
|
return Contract(self.address.address)
|
|
407
430
|
|
|
431
|
+
@property
|
|
432
|
+
def contract_coro(self) -> Coroutine[Any, Any, Contract]:
|
|
433
|
+
return Contract.coroutine(self.address.address)
|
|
434
|
+
|
|
408
435
|
@property
|
|
409
436
|
def scale(self) -> int:
|
|
410
437
|
"""Base for division according to `decimals`, e.g., `10**decimals`.
|
|
@@ -719,6 +746,10 @@ class TreasuryTx(DbEntity):
|
|
|
719
746
|
"""Human-readable label for the sender address."""
|
|
720
747
|
return self.from_address.nickname or self.from_address.address # type: ignore [union-attr]
|
|
721
748
|
|
|
749
|
+
@property
|
|
750
|
+
def token_address(self) -> ChecksumAddress:
|
|
751
|
+
return self.token.address.address
|
|
752
|
+
|
|
722
753
|
@property
|
|
723
754
|
def symbol(self) -> str:
|
|
724
755
|
"""Ticker symbol for the transferred token."""
|
|
@@ -729,7 +760,23 @@ class TreasuryTx(DbEntity):
|
|
|
729
760
|
"""Decoded event logs for this transaction."""
|
|
730
761
|
return self._transaction.events
|
|
731
762
|
|
|
732
|
-
def
|
|
763
|
+
async def events_async(self) -> EventDict:
|
|
764
|
+
"""Asynchronously fetch decoded event logs for this transaction."""
|
|
765
|
+
tx = self._transaction
|
|
766
|
+
events = tx._events
|
|
767
|
+
if events is None:
|
|
768
|
+
events = await _EVENTS_THREADS.run(getattr, tx, "events")
|
|
769
|
+
return events
|
|
770
|
+
|
|
771
|
+
@overload
|
|
772
|
+
def get_events(
|
|
773
|
+
self, event_name: str, sync: Literal[False]
|
|
774
|
+
) -> Coroutine[Any, Any, EventItem]: ...
|
|
775
|
+
@overload
|
|
776
|
+
def get_events(self, event_name: str, sync: bool = True) -> EventItem: ...
|
|
777
|
+
def get_events(self, event_name: str, sync: bool = True) -> EventItem:
|
|
778
|
+
if not sync:
|
|
779
|
+
return _EVENTS_THREADS.run(self.get_events, event_name)
|
|
733
780
|
try:
|
|
734
781
|
return self.events[event_name]
|
|
735
782
|
except EventLookupError:
|
|
@@ -746,6 +793,7 @@ class TreasuryTx(DbEntity):
|
|
|
746
793
|
return get_transaction(self.hash)
|
|
747
794
|
|
|
748
795
|
@staticmethod
|
|
796
|
+
@auto_retry
|
|
749
797
|
async def insert(entry: LedgerEntry) -> None:
|
|
750
798
|
"""Asynchronously insert and sort a ledger entry.
|
|
751
799
|
|
|
@@ -923,6 +971,7 @@ class TreasuryTx(DbEntity):
|
|
|
923
971
|
return dbid # type: ignore [no-any-return]
|
|
924
972
|
|
|
925
973
|
@staticmethod
|
|
974
|
+
@retry_locked
|
|
926
975
|
def __set_txgroup(treasury_tx_dbid: int, txgroup_dbid: TxGroupDbid) -> None:
|
|
927
976
|
with db_session:
|
|
928
977
|
TreasuryTx[treasury_tx_dbid].txgroup = txgroup_dbid
|
|
@@ -1382,3 +1431,24 @@ def _validate_integrity_error(
|
|
|
1382
1431
|
)
|
|
1383
1432
|
else None
|
|
1384
1433
|
)
|
|
1434
|
+
|
|
1435
|
+
|
|
1436
|
+
def _drop_shitcoin_txs() -> None:
|
|
1437
|
+
"""
|
|
1438
|
+
Purge any shitcoin txs from the db.
|
|
1439
|
+
|
|
1440
|
+
These should not be frequent, and only occur if a user populated the db before a shitcoin was added to the SHITCOINS mapping.
|
|
1441
|
+
"""
|
|
1442
|
+
shitcoins = eth_portfolio.SHITCOINS[CHAINID]
|
|
1443
|
+
with db_session:
|
|
1444
|
+
shitcoin_txs = select(
|
|
1445
|
+
tx for tx in TreasuryTx if tx.token.address.address in shitcoins
|
|
1446
|
+
)
|
|
1447
|
+
if count := shitcoin_txs.count():
|
|
1448
|
+
logger.info(f"Purging {count} shitcoin txs from the database...")
|
|
1449
|
+
for tx in shitcoin_txs:
|
|
1450
|
+
tx.delete()
|
|
1451
|
+
logger.info("Shitcoin tx purge complete.")
|
|
1452
|
+
|
|
1453
|
+
|
|
1454
|
+
_drop_shitcoin_txs()
|
dao_treasury/docker-compose.yaml
CHANGED
dao_treasury/main.py
CHANGED
|
@@ -97,6 +97,12 @@ parser.add_argument(
|
|
|
97
97
|
help="The time interval between datapoints. default: 1d",
|
|
98
98
|
default="1d",
|
|
99
99
|
)
|
|
100
|
+
parser.add_argument(
|
|
101
|
+
"--concurrency",
|
|
102
|
+
type=int,
|
|
103
|
+
help="The max number of historical blocks to export concurrently. default: 30",
|
|
104
|
+
default=30,
|
|
105
|
+
)
|
|
100
106
|
parser.add_argument(
|
|
101
107
|
"--daemon",
|
|
102
108
|
action="store_true",
|
|
@@ -119,6 +125,18 @@ parser.add_argument(
|
|
|
119
125
|
help="Port for the Grafana rendering service. Default: 8091",
|
|
120
126
|
default=8091,
|
|
121
127
|
)
|
|
128
|
+
parser.add_argument(
|
|
129
|
+
"--custom-bucket",
|
|
130
|
+
type=str,
|
|
131
|
+
action="append",
|
|
132
|
+
help=(
|
|
133
|
+
"Custom bucket mapping for a wallet address. "
|
|
134
|
+
"Specify as 'address:bucket_name'. "
|
|
135
|
+
"Can be used multiple times. Example: "
|
|
136
|
+
"--custom-bucket '0x123:My Bucket' --custom-bucket '0x456:Other Bucket'"
|
|
137
|
+
),
|
|
138
|
+
default=None,
|
|
139
|
+
)
|
|
122
140
|
|
|
123
141
|
args = parser.parse_args()
|
|
124
142
|
|
|
@@ -203,7 +221,27 @@ async def export(args) -> None:
|
|
|
203
221
|
for address in addresses:
|
|
204
222
|
db.Address.set_nickname(address, nickname)
|
|
205
223
|
|
|
206
|
-
|
|
224
|
+
# Parse custom_buckets from --custom-bucket arguments
|
|
225
|
+
custom_buckets = None
|
|
226
|
+
if args.custom_bucket:
|
|
227
|
+
custom_buckets = {}
|
|
228
|
+
for item in args.custom_bucket:
|
|
229
|
+
if ":" not in item:
|
|
230
|
+
parser.error(
|
|
231
|
+
f"Invalid format for --custom-bucket: '{item}'. Must be 'address:bucket_name'."
|
|
232
|
+
)
|
|
233
|
+
address, bucket = item.split(":", 1)
|
|
234
|
+
address = address.strip()
|
|
235
|
+
bucket = bucket.strip()
|
|
236
|
+
if not address or not bucket:
|
|
237
|
+
parser.error(
|
|
238
|
+
f"Invalid format for --custom-bucket: '{item}'. Both address and bucket_name are required."
|
|
239
|
+
)
|
|
240
|
+
custom_buckets[address] = bucket
|
|
241
|
+
|
|
242
|
+
treasury = Treasury(
|
|
243
|
+
wallets, args.sort_rules, custom_buckets=custom_buckets, asynchronous=True
|
|
244
|
+
)
|
|
207
245
|
|
|
208
246
|
# Start only the requested containers
|
|
209
247
|
if args.start_renderer is True:
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
dao_treasury/sorting/rule.py
CHANGED
|
@@ -130,8 +130,6 @@ class _SortRule:
|
|
|
130
130
|
func: Optional[SortFunction] = None
|
|
131
131
|
"""Custom matching function that takes a `TreasuryTx` and returns a bool or an awaitable that returns a bool."""
|
|
132
132
|
|
|
133
|
-
# __instances__: ClassVar[List[Self]] = []
|
|
134
|
-
|
|
135
133
|
def __post_init__(self) -> None:
|
|
136
134
|
"""Validate inputs, checksum addresses, and register the rule.
|
|
137
135
|
|
|
@@ -235,7 +233,7 @@ class _InboundSortRule(_SortRule):
|
|
|
235
233
|
return (
|
|
236
234
|
tx.to_address is not None
|
|
237
235
|
and TreasuryWallet.check_membership(tx.to_address.address, tx.block)
|
|
238
|
-
and await super().match(tx)
|
|
236
|
+
and await super(_InboundSortRule, self).match(tx)
|
|
239
237
|
)
|
|
240
238
|
|
|
241
239
|
|
|
@@ -250,7 +248,7 @@ class _OutboundSortRule(_SortRule):
|
|
|
250
248
|
async def match(self, tx: "TreasuryTx") -> bool:
|
|
251
249
|
return TreasuryWallet.check_membership(
|
|
252
250
|
tx.from_address.address, tx.block
|
|
253
|
-
) and await super().match(tx)
|
|
251
|
+
) and await super(_OutboundSortRule, self).match(tx)
|
|
254
252
|
|
|
255
253
|
|
|
256
254
|
@mypyc_attr(native_class=False)
|
|
@@ -267,7 +265,7 @@ class RevenueSortRule(_InboundSortRule):
|
|
|
267
265
|
def __post_init__(self) -> None:
|
|
268
266
|
"""Prepends `self.txgroup` with 'Revenue:'."""
|
|
269
267
|
object.__setattr__(self, "txgroup", f"Revenue:{self.txgroup}")
|
|
270
|
-
super().__post_init__()
|
|
268
|
+
super(RevenueSortRule, self).__post_init__()
|
|
271
269
|
|
|
272
270
|
|
|
273
271
|
@mypyc_attr(native_class=False)
|
|
@@ -280,7 +278,7 @@ class CostOfRevenueSortRule(_OutboundSortRule):
|
|
|
280
278
|
def __post_init__(self) -> None:
|
|
281
279
|
"""Prepends `self.txgroup` with 'Cost of Revenue:'."""
|
|
282
280
|
object.__setattr__(self, "txgroup", f"Cost of Revenue:{self.txgroup}")
|
|
283
|
-
super().__post_init__()
|
|
281
|
+
super(CostOfRevenueSortRule, self).__post_init__()
|
|
284
282
|
|
|
285
283
|
|
|
286
284
|
@mypyc_attr(native_class=False)
|
|
@@ -293,7 +291,7 @@ class ExpenseSortRule(_OutboundSortRule):
|
|
|
293
291
|
def __post_init__(self) -> None:
|
|
294
292
|
"""Prepends `self.txgroup` with 'Expenses:'."""
|
|
295
293
|
object.__setattr__(self, "txgroup", f"Expenses:{self.txgroup}")
|
|
296
|
-
super().__post_init__()
|
|
294
|
+
super(ExpenseSortRule, self).__post_init__()
|
|
297
295
|
|
|
298
296
|
|
|
299
297
|
@mypyc_attr(native_class=False)
|
|
@@ -306,7 +304,7 @@ class OtherIncomeSortRule(_InboundSortRule):
|
|
|
306
304
|
def __post_init__(self) -> None:
|
|
307
305
|
"""Prepends `self.txgroup` with 'Other Income:'."""
|
|
308
306
|
object.__setattr__(self, "txgroup", f"Other Income:{self.txgroup}")
|
|
309
|
-
super().__post_init__()
|
|
307
|
+
super(OtherIncomeSortRule, self).__post_init__()
|
|
310
308
|
|
|
311
309
|
|
|
312
310
|
@mypyc_attr(native_class=False)
|
|
@@ -319,7 +317,7 @@ class OtherExpenseSortRule(_OutboundSortRule):
|
|
|
319
317
|
def __post_init__(self) -> None:
|
|
320
318
|
"""Prepends `self.txgroup` with 'Other Expenses:'."""
|
|
321
319
|
object.__setattr__(self, "txgroup", f"Other Expenses:{self.txgroup}")
|
|
322
|
-
super().__post_init__()
|
|
320
|
+
super(OtherExpenseSortRule, self).__post_init__()
|
|
323
321
|
|
|
324
322
|
|
|
325
323
|
@mypyc_attr(native_class=False)
|
|
@@ -332,7 +330,7 @@ class IgnoreSortRule(_SortRule):
|
|
|
332
330
|
def __post_init__(self) -> None:
|
|
333
331
|
"""Prepends `self.txgroup` with 'Ignore:'."""
|
|
334
332
|
object.__setattr__(self, "txgroup", f"Ignore:{self.txgroup}")
|
|
335
|
-
super().__post_init__()
|
|
333
|
+
super(IgnoreSortRule, self).__post_init__()
|
|
336
334
|
|
|
337
335
|
|
|
338
336
|
TRule = TypeVar(
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
dao_treasury/streams/llamapay.py
CHANGED
|
@@ -22,7 +22,7 @@ from eth_typing import BlockNumber, ChecksumAddress, HexAddress, HexStr
|
|
|
22
22
|
from tqdm.asyncio import tqdm_asyncio
|
|
23
23
|
|
|
24
24
|
import y
|
|
25
|
-
from y.time import UnixTimestamp
|
|
25
|
+
from y.time import NoBlockFound, UnixTimestamp
|
|
26
26
|
from y.utils.events import decode_logs, get_logs_asap
|
|
27
27
|
|
|
28
28
|
from dao_treasury import constants
|
|
@@ -338,7 +338,19 @@ class LlamaPayProcessor:
|
|
|
338
338
|
check_at = date_obj + timedelta(days=1) - timedelta(seconds=1)
|
|
339
339
|
if check_at > now(tz=_UTC):
|
|
340
340
|
await sleep((check_at - now(tz=_UTC)).total_seconds())
|
|
341
|
-
|
|
341
|
+
|
|
342
|
+
while True:
|
|
343
|
+
try:
|
|
344
|
+
block = await get_block_at_timestamp(check_at, sync=False)
|
|
345
|
+
except NoBlockFound:
|
|
346
|
+
sleep_time = (check_at - now(tz=_UTC)).total_seconds()
|
|
347
|
+
logger.debug(
|
|
348
|
+
"no block found for %s, sleeping %ss", check_at, sleep_time
|
|
349
|
+
)
|
|
350
|
+
await sleep(sleep_time)
|
|
351
|
+
else:
|
|
352
|
+
break
|
|
353
|
+
|
|
342
354
|
price_fut = create_task(get_price(stream_token, block, sync=False))
|
|
343
355
|
start_timestamp = await _get_start_timestamp(stream_id, block)
|
|
344
356
|
if start_timestamp == 0:
|
dao_treasury/treasury.py
CHANGED
|
@@ -1,11 +1,28 @@
|
|
|
1
|
+
"""Treasury orchestration and analytics interface.
|
|
2
|
+
|
|
3
|
+
This module defines the Treasury class, which aggregates DAO wallets, sets up
|
|
4
|
+
sorting rules, and manages transaction ingestion and streaming analytics.
|
|
5
|
+
It coordinates the end-to-end flow from wallet configuration to database
|
|
6
|
+
population and dashboard analytics.
|
|
7
|
+
|
|
8
|
+
Key Responsibilities:
|
|
9
|
+
- Aggregate and manage DAO-controlled wallets.
|
|
10
|
+
- Ingest and process on-chain transactions.
|
|
11
|
+
- Apply sorting/categorization rules.
|
|
12
|
+
- Integrate with streaming protocols (e.g., LlamaPay).
|
|
13
|
+
- Populate the database for analytics and dashboards.
|
|
14
|
+
|
|
15
|
+
This is the main entry point for orchestrating DAO treasury analytics.
|
|
16
|
+
"""
|
|
17
|
+
|
|
1
18
|
from asyncio import create_task, gather
|
|
2
19
|
from logging import getLogger
|
|
3
20
|
from pathlib import Path
|
|
4
|
-
from typing import Final, Iterable, List, Optional, Union
|
|
21
|
+
from typing import Dict, Final, Iterable, List, Optional, Union
|
|
5
22
|
|
|
6
23
|
import a_sync
|
|
7
24
|
from a_sync.a_sync.abstract import ASyncABC
|
|
8
|
-
from eth_typing import BlockNumber
|
|
25
|
+
from eth_typing import BlockNumber, HexAddress
|
|
9
26
|
from eth_portfolio.structs import LedgerEntry
|
|
10
27
|
from eth_portfolio.typing import PortfolioBalances
|
|
11
28
|
from eth_portfolio_scripts._portfolio import ExportablePortfolio
|
|
@@ -35,6 +52,7 @@ class Treasury(a_sync.ASyncGenericBase): # type: ignore [misc]
|
|
|
35
52
|
sort_rules: Optional[Path] = None,
|
|
36
53
|
start_block: int = 0,
|
|
37
54
|
label: str = "your org's treasury",
|
|
55
|
+
custom_buckets: Optional[Dict[HexAddress, str]] = None,
|
|
38
56
|
asynchronous: bool = False,
|
|
39
57
|
) -> None:
|
|
40
58
|
"""Initialize the Treasury singleton for managing DAO funds.
|
|
@@ -59,20 +77,22 @@ class Treasury(a_sync.ASyncGenericBase): # type: ignore [misc]
|
|
|
59
77
|
TypeError: If any item in `wallets` is not a str or TreasuryWallet.
|
|
60
78
|
|
|
61
79
|
Examples:
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
80
|
+
.. code-block:: python
|
|
81
|
+
|
|
82
|
+
# Create a synchronous Treasury
|
|
83
|
+
treasury = Treasury(
|
|
84
|
+
wallets=["0xAbc123...", TreasuryWallet("0xDef456...", start_block=1000)],
|
|
85
|
+
sort_rules=Path("/path/to/rules"),
|
|
86
|
+
start_block=500,
|
|
87
|
+
label="DAO Treasury",
|
|
88
|
+
asynchronous=False
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
# Create an asynchronous Treasury
|
|
92
|
+
treasury_async = Treasury(
|
|
93
|
+
wallets=["0xAbc123..."],
|
|
94
|
+
asynchronous=True
|
|
95
|
+
)
|
|
76
96
|
"""
|
|
77
97
|
global TREASURY
|
|
78
98
|
if TREASURY is not None:
|
|
@@ -105,6 +125,7 @@ class Treasury(a_sync.ASyncGenericBase): # type: ignore [misc]
|
|
|
105
125
|
start_block=start_block,
|
|
106
126
|
label=label,
|
|
107
127
|
load_prices=True,
|
|
128
|
+
custom_buckets=custom_buckets,
|
|
108
129
|
asynchronous=asynchronous,
|
|
109
130
|
)
|
|
110
131
|
"""An eth_portfolio.Portfolio object used for exporting tx and balance history"""
|
|
Binary file
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dao_treasury
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.71
|
|
4
4
|
Summary: Produce comprehensive financial reports for your on-chain org
|
|
5
5
|
Classifier: Development Status :: 3 - Alpha
|
|
6
6
|
Classifier: Intended Audience :: Developers
|
|
@@ -14,7 +14,7 @@ Classifier: Operating System :: OS Independent
|
|
|
14
14
|
Classifier: Topic :: Software Development :: Libraries
|
|
15
15
|
Requires-Python: >=3.10,<3.13
|
|
16
16
|
Description-Content-Type: text/markdown
|
|
17
|
-
Requires-Dist: eth-portfolio-temp
|
|
17
|
+
Requires-Dist: eth-portfolio-temp==0.3.1
|
|
18
18
|
Dynamic: classifier
|
|
19
19
|
Dynamic: description
|
|
20
20
|
Dynamic: description-content-type
|
|
@@ -29,6 +29,7 @@ DAO Treasury is a comprehensive financial reporting and treasury management solu
|
|
|
29
29
|
- **Financial Reporting for DAOs:** Extends core portfolio functionalities to generate detailed reports tailored for on-chain organizations.
|
|
30
30
|
- **Dashboard Provisioning:** Utilizes [Grafana](https://grafana.com/) dashboards—defined in JSON files within the .grafana/provisioning directories—to offer real-time, dynamic visualizations of treasury data.
|
|
31
31
|
- **Automated Data Export:** Features a treasury export tool that, once configured (with a supported [brownie network](https://eth-brownie.readthedocs.io/en/stable/network-management.html) and [Docker](https://www.docker.com/get-started/)), continuously captures financial snapshots at set intervals.
|
|
32
|
+
- **Custom Buckets for Wallets:** Assign custom categories ("buckets") to specific wallet addresses for more granular reporting using the `--custom-bucket` CLI option.
|
|
32
33
|
- **Ease of Contribution:** Non-technical users can easily update or create dashboard visuals using Grafana’s intuitive UI. The [Contributing Guidelines](https://github.com/BobTheBuidler/dao-treasury/blob/master/CONTRIBUTING.md) document provides a step-by-step guide to defining new visuals and dashboards and integrating those changes into the repository, ensuring that anyone can contribute to the visual reporting aspect of the project.
|
|
33
34
|
|
|
34
35
|
## Requirements
|
|
@@ -41,7 +42,7 @@ DAO Treasury is a comprehensive financial reporting and treasury management solu
|
|
|
41
42
|
- First, you will need to bring your own archive node. This can be one you run yourself, or one from one of the common providers (Tenderly, Alchemy, QuickNode, etc.). Your archive node must have tracing enabled (free-tier Alchemy nodes do not support this option).
|
|
42
43
|
- You must configure a [brownie network](https://eth-brownie.readthedocs.io/en/stable/network-management.html) to use your RPC.
|
|
43
44
|
- You will need an auth token for [Etherscan](https://etherscan.io/)'s API. Follow their [guide](https://docs.etherscan.io/etherscan-v2/getting-an-api-key) to get your key, and set env var `ETHERSCAN_TOKEN` with its value.
|
|
44
|
-
- You'll also need [Docker](https://www.docker.com/get-started/) installed on your system. If on MacOS, you will need to leave Docker Desktop open while
|
|
45
|
+
- You'll also need [Docker](https://www.docker.com/get-started/) installed on your system. If on MacOS, you will need to leave Docker Desktop open while DAO Treasury is running.
|
|
45
46
|
|
|
46
47
|
## Installation
|
|
47
48
|
|
|
@@ -63,14 +64,28 @@ For local development (from source installation), use:
|
|
|
63
64
|
poetry run dao-treasury run --wallet 0x123 --network mainnet --interval 12h
|
|
64
65
|
```
|
|
65
66
|
|
|
67
|
+
**Assigning Custom Buckets to Wallets:**
|
|
68
|
+
|
|
69
|
+
You can assign custom categories ("buckets") to specific wallet addresses for more granular reporting. Use the `--custom-bucket` option one or more times, each with the format `address:bucket_name`:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
dao-treasury run --wallet 0x123 --network mainnet --custom-bucket "0x123:Operations" --custom-bucket "0x456:Grants" --custom-bucket "0x789:Investments"
|
|
73
|
+
```
|
|
74
|
+
|
|
66
75
|
**CLI Options:**
|
|
76
|
+
> Only optional arguments are listed here. Required arguments (such as `--wallet` or `--wallets`) are shown in the usage examples above.
|
|
77
|
+
|
|
67
78
|
- `--network`: The id of the brownie network the exporter will connect to (default: mainnet)
|
|
68
79
|
- `--interval`: The time interval between each data snapshot (default: 12h)
|
|
80
|
+
- `--concurrency`: The max number of historical blocks to export concurrently. (default: 30)
|
|
69
81
|
- `--daemon`: Run the export process in the background (default: False) (NOTE: currently unsupported)
|
|
82
|
+
- `--sort-rules`: Directory containing sort rules definitions for transaction categorization.
|
|
83
|
+
- `--nicknames`: File containing address nicknames for reporting.
|
|
70
84
|
- `--grafana-port`: Set the port for the Grafana dashboard where you can view data (default: 3004)
|
|
71
85
|
- `--renderer-port`: Set the port for the report rendering service (default: 8091)
|
|
72
86
|
- `--victoria-port`: Set the port for the Victoria metrics reporting endpoint (default: 8430)
|
|
73
87
|
- `--start-renderer`: If set, both the Grafana and renderer containers will be started for dashboard image export. By default, only the grafana container is started.
|
|
88
|
+
- `--custom-bucket`: Assign a custom bucket/category to a wallet address for reporting. Specify as `address:bucket_name`. Can be used multiple times.
|
|
74
89
|
|
|
75
90
|
After running the command, the export script will run continuously until you close your terminal.
|
|
76
91
|
To view the dashboards, just open your browser and navigate to [http://localhost:3004](http://localhost:3004)!
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
dao_treasury__mypyc.cp311-win_amd64.pyd,sha256=e-BP46HP-JavVWZ6Q8fyzefsj3BZh2sn3dUTKz-6tx0,453120
|
|
2
|
+
dao_treasury/ENVIRONMENT_VARIABLES.py,sha256=LS_D4ALB3BO-vYKyh1tzRHi10QBE6f654Zy8pmJ_xPY,656
|
|
3
|
+
dao_treasury/__init__.py,sha256=ai8iALE_Zv43O9cH1jkNJ39bzhr60kBDX6L7C4Nj9FA,1539
|
|
4
|
+
dao_treasury/_docker.cp311-win_amd64.pyd,sha256=Kn3vaKxqPUn3PczU1ff-ezjwyvfvlzAmGdByYbOnBMk,10752
|
|
5
|
+
dao_treasury/_docker.py,sha256=Rki3eLKOmsNxN3nF-gmbM9UQV49SY7ToEHZboL_HYvA,6118
|
|
6
|
+
dao_treasury/_nicknames.cp311-win_amd64.pyd,sha256=kf40nS73G_h3PGINNg6R_ufaJlg8oxG4ENaluFHhem0,10752
|
|
7
|
+
dao_treasury/_nicknames.py,sha256=n8c-JZhORYymCMv6jsC96IthAzAhpslyEn-KCk_YiSM,1049
|
|
8
|
+
dao_treasury/_wallet.cp311-win_amd64.pyd,sha256=d8A59yYN1FwEFHkPVgaxKawHRWB9daj0qNWRfK7eWz4,10752
|
|
9
|
+
dao_treasury/_wallet.py,sha256=nHBAKFJstdKuYbvpskGVx2KU80YrZHGHsEh5V3TwIHs,10712
|
|
10
|
+
dao_treasury/constants.cp311-win_amd64.pyd,sha256=Ahz2-6EyLk-m-RZPay4UFFfZc4-dS8M6SQcK08s4Lng,10752
|
|
11
|
+
dao_treasury/constants.py,sha256=-T0oPw7lC5YeaiplHAtYL-2ss7knvKrJKQ1LCc8kX8g,1483
|
|
12
|
+
dao_treasury/db.py,sha256=4Vc_U3mmrG8hOpsuDcgCQQuwGyL3pyfYH2jjktDXx48,50734
|
|
13
|
+
dao_treasury/docker-compose.yaml,sha256=wNNE9xmkchcV-nJxzrmUkbUA0CW1qgdGQKJ7uw2P8nU,1350
|
|
14
|
+
dao_treasury/main.py,sha256=_Q-Nhn9WJ6alovqxt8Aa2X24-cxPgH4b25ulj0mEygs,9611
|
|
15
|
+
dao_treasury/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
16
|
+
dao_treasury/treasury.py,sha256=K4XOg-5BHoP5HoRlHNu4afNpYs2-8sjCOOGwdt3M21w,7541
|
|
17
|
+
dao_treasury/types.cp311-win_amd64.pyd,sha256=RvzU28NR4sj9OmJO-omGWCYldXzc-70T04DH6sgQMO4,10752
|
|
18
|
+
dao_treasury/types.py,sha256=KFz4WKPp4t_RBwIT6YGwOcgbzw8tdHIOcXTFsUA0pJA,3818
|
|
19
|
+
dao_treasury/.grafana/provisioning/dashboards/dashboards.yaml,sha256=to_cVfl8X6-5zVskkDxNtTE191TH52XO2peGfHPI5F0,201
|
|
20
|
+
dao_treasury/.grafana/provisioning/dashboards/breakdowns/Expenses.json,sha256=seX4E48q7XTIDYTzwiZzDR_n-vii-MqfT8MJ4mIhpUc,19964
|
|
21
|
+
dao_treasury/.grafana/provisioning/dashboards/breakdowns/Revenue.json,sha256=tdHBpE0gMk3tcVyT2rP4eMNUbTs5c98zjv_hPlMvhmM,19171
|
|
22
|
+
dao_treasury/.grafana/provisioning/dashboards/streams/LlamaPay.json,sha256=rQ3-eFc9vk4AzQfwG5d1NlonyPTlHuBQfr-IdlAI-QE,7724
|
|
23
|
+
dao_treasury/.grafana/provisioning/dashboards/summary/Monthly.json,sha256=EguedPwRdraMQlyj5BOKtWcHaFGwainu-5At5z9uZaM,15448
|
|
24
|
+
dao_treasury/.grafana/provisioning/dashboards/transactions/Treasury Transactions.json,sha256=eQLZMnY4enc7dwdYBxHjgkadjXU_ie4qsWEhAQxDsBo,14557
|
|
25
|
+
dao_treasury/.grafana/provisioning/dashboards/treasury/Cashflow (Including Unsorted).json,sha256=nu_bCHebLAjnz-CUFd6qaU50mokWcjTns2L8AWpeStg,28156
|
|
26
|
+
dao_treasury/.grafana/provisioning/dashboards/treasury/Cashflow.json,sha256=T5jyhDh41PKoZdK-QrcMyGCT6Mg3MZRLnDaIE2-xM1w,20241
|
|
27
|
+
dao_treasury/.grafana/provisioning/dashboards/treasury/Current Treasury Assets.json,sha256=HCzFfESFmLruuKxMKOatkoFcHXgx90dnyuFgHmcocKk,26281
|
|
28
|
+
dao_treasury/.grafana/provisioning/dashboards/treasury/Historical Treasury Balances.json,sha256=Np1oh1Dm_B9oTPFifLDgRYeqa5Lk23nZUGZ50hY0XgY,109466
|
|
29
|
+
dao_treasury/.grafana/provisioning/dashboards/treasury/Operating Cashflow.json,sha256=TSmhQGX_0mHN0-JJebhkUXosD09rMa69oRlUWatHxUk,15951
|
|
30
|
+
dao_treasury/.grafana/provisioning/datasources/datasources.yaml,sha256=gLmJsOkEXNzWRDibShfHFySWeuExW-dSB_U0OSfH868,344
|
|
31
|
+
dao_treasury/sorting/__init__.cp311-win_amd64.pyd,sha256=n1XUYxqtT8PjeL7IAaCWxLKYY498-Yw8J1jhK5LLlt4,10752
|
|
32
|
+
dao_treasury/sorting/__init__.py,sha256=_uxM_FE1paM8oDAhDdHSyhDwnrlxCYX_lGn2DOqCaHU,10666
|
|
33
|
+
dao_treasury/sorting/_matchers.cp311-win_amd64.pyd,sha256=YhVf2kk0CQLeTwJo8ZmunaHyrq-Gp2bbCP8d3L2l-oI,10752
|
|
34
|
+
dao_treasury/sorting/_matchers.py,sha256=ACi6aXZCKW5OTiztsID7CXCGJounj5c6ivhOCg2436M,14392
|
|
35
|
+
dao_treasury/sorting/_rules.cp311-win_amd64.pyd,sha256=EDQRyGo0Fyr1irjExYBDBznpeRsyQ-_o9algkZnZQ8g,10752
|
|
36
|
+
dao_treasury/sorting/_rules.py,sha256=DxhdUgpS0q0LWeLl9W1Bjn5LZz9z4OLA03vQllPMH9k,9229
|
|
37
|
+
dao_treasury/sorting/factory.cp311-win_amd64.pyd,sha256=lqf_aWxj94vcNkDuudTCwi7Ls8Ovf1yIALyMBaJAdUA,10752
|
|
38
|
+
dao_treasury/sorting/factory.py,sha256=zlJ18xlMTxv8ACV6_MimCVIDsw3K5AZcyvKaNYY7R14,10484
|
|
39
|
+
dao_treasury/sorting/rule.cp311-win_amd64.pyd,sha256=76cpAR2rA63NKvv_2wpeE1IECQGBdTXV8BTq37Z7pk4,10752
|
|
40
|
+
dao_treasury/sorting/rule.py,sha256=wbL8s0-6dxcCKghUtEDSkLDBnyvggsJ3gt_RawQ6kB4,11972
|
|
41
|
+
dao_treasury/sorting/rules/__init__.cp311-win_amd64.pyd,sha256=YJUU6IGDQsCOmfBlmBB6U2w4uip_MeEr9L9ziJHXlm4,10752
|
|
42
|
+
dao_treasury/sorting/rules/__init__.py,sha256=hcLfejOEwD8RaM2RE-38Ej6_WkvL9BVGvIIGY848E6E,49
|
|
43
|
+
dao_treasury/sorting/rules/ignore/__init__.cp311-win_amd64.pyd,sha256=98h2mL8oDymHRQM0WqZlFtRNKTyu2yR4DMZ5wOTRR0I,10752
|
|
44
|
+
dao_treasury/sorting/rules/ignore/__init__.py,sha256=16THKoGdj6qfkkytuCFVG_R1M6KSErMI4AVE1p0ukS4,58
|
|
45
|
+
dao_treasury/sorting/rules/ignore/llamapay.cp311-win_amd64.pyd,sha256=4MnFIgT6B33iBJ7_u18qn5wy7rLBa3nJQTbHZSV2h1o,10752
|
|
46
|
+
dao_treasury/sorting/rules/ignore/llamapay.py,sha256=aYyAJRlmv419IeaqkcV5o3ffx0UVfteU0lTl80j0BGo,783
|
|
47
|
+
dao_treasury/streams/__init__.cp311-win_amd64.pyd,sha256=_e7coxdPNR26S3yzz5A-8pwwomOwmlJXkAUKoHK5fp8,10752
|
|
48
|
+
dao_treasury/streams/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
49
|
+
dao_treasury/streams/llamapay.cp311-win_amd64.pyd,sha256=Y6zWFsILViSbWxsw32h03sgDhqXMPpsDxI-KDFCsy0g,10752
|
|
50
|
+
dao_treasury/streams/llamapay.py,sha256=rO1Mh2ndTziR6pnRkKHnQ22a_Yx9PM_-BG7I4dspEZ8,13535
|
|
51
|
+
dao_treasury-0.0.71.dist-info/METADATA,sha256=B9eF09wrzznyPsIct4TkbdfXuUX2WDPOZW-krIL8aDU,8267
|
|
52
|
+
dao_treasury-0.0.71.dist-info/WHEEL,sha256=JLOMsP7F5qtkAkINx5UnzbFguf8CqZeraV8o04b0I8I,101
|
|
53
|
+
dao_treasury-0.0.71.dist-info/top_level.txt,sha256=CV8aYytuSYplDhLVY4n0GphckdysXCd1lHmbqfsPxNk,33
|
|
54
|
+
dao_treasury-0.0.71.dist-info/RECORD,,
|
|
Binary file
|
|
Binary file
|