dao-treasury 0.0.17__cp312-cp312-win32.whl → 0.0.61__cp312-cp312-win32.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 +526 -0
- dao_treasury/.grafana/provisioning/dashboards/breakdowns/Revenue.json +526 -0
- dao_treasury/.grafana/provisioning/dashboards/dashboards.yaml +76 -2
- dao_treasury/.grafana/provisioning/dashboards/streams/LlamaPay.json +225 -0
- dao_treasury/.grafana/provisioning/dashboards/summary/Monthly.json +13 -17
- dao_treasury/.grafana/provisioning/dashboards/transactions/Treasury Transactions.json +167 -19
- dao_treasury/.grafana/provisioning/dashboards/treasury/Cashflow (Including Unsorted).json +876 -0
- dao_treasury/.grafana/provisioning/dashboards/treasury/Cashflow.json +645 -0
- dao_treasury/.grafana/provisioning/dashboards/treasury/Current Treasury Assets.json +593 -0
- dao_treasury/.grafana/provisioning/dashboards/treasury/Historical Treasury Balances.json +2999 -0
- dao_treasury/.grafana/provisioning/dashboards/treasury/Operating Cashflow.json +513 -0
- dao_treasury/.grafana/provisioning/datasources/datasources.yaml +17 -0
- dao_treasury/ENVIRONMENT_VARIABLES.py +20 -0
- dao_treasury/__init__.py +24 -0
- dao_treasury/_docker.cp312-win32.pyd +0 -0
- dao_treasury/_docker.py +48 -23
- dao_treasury/_nicknames.cp312-win32.pyd +0 -0
- dao_treasury/_nicknames.py +32 -0
- dao_treasury/_wallet.cp312-win32.pyd +0 -0
- dao_treasury/_wallet.py +162 -10
- dao_treasury/constants.cp312-win32.pyd +0 -0
- dao_treasury/constants.py +39 -0
- dao_treasury/db.py +429 -57
- dao_treasury/docker-compose.yaml +6 -5
- dao_treasury/main.py +102 -13
- dao_treasury/sorting/__init__.cp312-win32.pyd +0 -0
- dao_treasury/sorting/__init__.py +181 -105
- dao_treasury/sorting/_matchers.cp312-win32.pyd +0 -0
- dao_treasury/sorting/_rules.cp312-win32.pyd +0 -0
- dao_treasury/sorting/_rules.py +1 -3
- dao_treasury/sorting/factory.cp312-win32.pyd +0 -0
- dao_treasury/sorting/factory.py +2 -6
- dao_treasury/sorting/rule.cp312-win32.pyd +0 -0
- dao_treasury/sorting/rule.py +16 -13
- dao_treasury/sorting/rules/__init__.cp312-win32.pyd +0 -0
- dao_treasury/sorting/rules/__init__.py +1 -0
- dao_treasury/sorting/rules/ignore/__init__.cp312-win32.pyd +0 -0
- dao_treasury/sorting/rules/ignore/__init__.py +1 -0
- dao_treasury/sorting/rules/ignore/llamapay.cp312-win32.pyd +0 -0
- dao_treasury/sorting/rules/ignore/llamapay.py +20 -0
- dao_treasury/streams/__init__.cp312-win32.pyd +0 -0
- dao_treasury/streams/__init__.py +0 -0
- dao_treasury/streams/llamapay.cp312-win32.pyd +0 -0
- dao_treasury/streams/llamapay.py +388 -0
- dao_treasury/treasury.py +75 -28
- dao_treasury/types.cp312-win32.pyd +0 -0
- dao_treasury-0.0.61.dist-info/METADATA +120 -0
- dao_treasury-0.0.61.dist-info/RECORD +54 -0
- dao_treasury-0.0.61.dist-info/top_level.txt +2 -0
- dao_treasury__mypyc.cp312-win32.pyd +0 -0
- 52b51d40e96d4333695d__mypyc.cp312-win32.pyd +0 -0
- dao_treasury/.grafana/provisioning/datasources/sqlite.yaml +0 -10
- dao_treasury-0.0.17.dist-info/METADATA +0 -36
- dao_treasury-0.0.17.dist-info/RECORD +0 -30
- dao_treasury-0.0.17.dist-info/top_level.txt +0 -2
- {dao_treasury-0.0.17.dist-info → dao_treasury-0.0.61.dist-info}/WHEEL +0 -0
dao_treasury/docker-compose.yaml
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
networks:
|
|
2
2
|
dao_treasury:
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
grafana_data: {}
|
|
3
|
+
docker_eth_portfolio:
|
|
4
|
+
external: true
|
|
6
5
|
|
|
7
6
|
services:
|
|
8
7
|
grafana:
|
|
9
|
-
image: grafana/grafana:
|
|
8
|
+
image: grafana/grafana:12.2.1
|
|
10
9
|
ports:
|
|
11
10
|
- 127.0.0.1:${DAO_TREASURY_GRAFANA_PORT:-3004}:3000
|
|
12
11
|
environment:
|
|
13
12
|
- GF_SECURITY_ADMIN_USER=${GF_SECURITY_ADMIN_USER:-admin}
|
|
14
13
|
- GF_SECURITY_ADMIN_PASSWORD=${GF_SECURITY_ADMIN_PASSWORD:-admin}
|
|
15
14
|
- GF_AUTH_ANONYMOUS_ENABLED=true
|
|
15
|
+
- GF_AUTH_ANONYMOUS_ORG_ROLE=Viewer
|
|
16
16
|
- GF_DASHBOARDS_DEFAULT_HOME_DASHBOARD_PATH=/etc/grafana/provisioning/dashboards/summary/Monthly.json
|
|
17
17
|
- GF_SERVER_ROOT_URL
|
|
18
18
|
- GF_RENDERING_SERVER_URL=http://renderer:8091/render
|
|
@@ -21,10 +21,10 @@ services:
|
|
|
21
21
|
- GF_INSTALL_PLUGINS=volkovlabs-variable-panel,frser-sqlite-datasource
|
|
22
22
|
volumes:
|
|
23
23
|
- ~/.dao-treasury/:/app/dao-treasury-data
|
|
24
|
-
- grafana_data:/var/lib/grafana
|
|
25
24
|
- ./.grafana/provisioning/:/etc/grafana/provisioning/
|
|
26
25
|
networks:
|
|
27
26
|
- dao_treasury
|
|
27
|
+
- docker_eth_portfolio
|
|
28
28
|
restart: always
|
|
29
29
|
|
|
30
30
|
renderer:
|
|
@@ -37,4 +37,5 @@ services:
|
|
|
37
37
|
- HTTP_PORT=8091
|
|
38
38
|
networks:
|
|
39
39
|
- dao_treasury
|
|
40
|
+
- docker_eth_portfolio
|
|
40
41
|
restart: always
|
dao_treasury/main.py
CHANGED
|
@@ -27,14 +27,20 @@ import os
|
|
|
27
27
|
from pathlib import Path
|
|
28
28
|
|
|
29
29
|
import brownie
|
|
30
|
+
import yaml
|
|
31
|
+
from a_sync import create_task
|
|
32
|
+
from dao_treasury._wallet import load_wallets_from_yaml
|
|
33
|
+
from eth_portfolio_scripts.balances import export_balances
|
|
30
34
|
from eth_typing import BlockNumber
|
|
31
35
|
|
|
32
|
-
from
|
|
36
|
+
from dao_treasury.constants import CHAINID
|
|
33
37
|
|
|
34
38
|
|
|
35
39
|
logger = logging.getLogger(__name__)
|
|
40
|
+
|
|
36
41
|
logging.basicConfig(level=logging.INFO)
|
|
37
42
|
|
|
43
|
+
|
|
38
44
|
parser = argparse.ArgumentParser(
|
|
39
45
|
description="Run a single DAO Treasury export and populate the database.",
|
|
40
46
|
)
|
|
@@ -49,16 +55,39 @@ parser.add_argument(
|
|
|
49
55
|
type=str,
|
|
50
56
|
help=(
|
|
51
57
|
"DAO treasury wallet address(es) to include in the export. "
|
|
52
|
-
"Specify one or more addresses separated by spaces."
|
|
58
|
+
"Specify one or more addresses separated by spaces. "
|
|
59
|
+
"Check out https://bobthebuidler.github.io/dao-treasury/wallets.html for more info."
|
|
53
60
|
),
|
|
54
61
|
nargs="+",
|
|
55
62
|
)
|
|
63
|
+
parser.add_argument(
|
|
64
|
+
"--wallets",
|
|
65
|
+
type=Path,
|
|
66
|
+
help=(
|
|
67
|
+
"Path to a YAML file mapping wallet addresses to advanced settings. "
|
|
68
|
+
"Each address is a key, with nested 'start' and/or 'end' mappings containing "
|
|
69
|
+
"either 'block' or 'timestamp'. "
|
|
70
|
+
"Check out https://bobthebuidler.github.io/dao-treasury/wallets.html for more info."
|
|
71
|
+
),
|
|
72
|
+
default=None,
|
|
73
|
+
)
|
|
56
74
|
parser.add_argument(
|
|
57
75
|
"--sort-rules",
|
|
58
76
|
type=Path,
|
|
59
77
|
help=(
|
|
60
78
|
"Directory containing sort rules definitions. "
|
|
61
|
-
"If omitted, transactions are exported without custom sorting."
|
|
79
|
+
"If omitted, transactions are exported without custom sorting. "
|
|
80
|
+
"Check out https://bobthebuidler.github.io/dao-treasury/sort_rules.html for more info."
|
|
81
|
+
),
|
|
82
|
+
default=None,
|
|
83
|
+
)
|
|
84
|
+
parser.add_argument(
|
|
85
|
+
"--nicknames",
|
|
86
|
+
type=Path,
|
|
87
|
+
help=(
|
|
88
|
+
"File containing sort address nicknames. "
|
|
89
|
+
"If omitted, transactions are exported without custom sorting. "
|
|
90
|
+
"See https://github.com/BobTheBuidler/yearn-treasury/blob/master/yearn_treasury/addresses.yaml for an example."
|
|
62
91
|
),
|
|
63
92
|
default=None,
|
|
64
93
|
)
|
|
@@ -68,6 +97,12 @@ parser.add_argument(
|
|
|
68
97
|
help="The time interval between datapoints. default: 1d",
|
|
69
98
|
default="1d",
|
|
70
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
|
+
)
|
|
71
106
|
parser.add_argument(
|
|
72
107
|
"--daemon",
|
|
73
108
|
action="store_true",
|
|
@@ -79,6 +114,11 @@ parser.add_argument(
|
|
|
79
114
|
help="Port for the DAO Treasury dashboard web interface. Default: 3000",
|
|
80
115
|
default=3000,
|
|
81
116
|
)
|
|
117
|
+
parser.add_argument(
|
|
118
|
+
"--start-renderer",
|
|
119
|
+
action="store_true",
|
|
120
|
+
help="If set, the Grafana renderer container will be started for dashboard image export. By default, only the grafana container is started.",
|
|
121
|
+
)
|
|
82
122
|
parser.add_argument(
|
|
83
123
|
"--renderer-port",
|
|
84
124
|
type=int,
|
|
@@ -120,16 +160,13 @@ async def export(args) -> None:
|
|
|
120
160
|
|
|
121
161
|
Args:
|
|
122
162
|
args: Parsed command-line arguments containing:
|
|
123
|
-
wallet:
|
|
163
|
+
wallet: List of simple addresses or TreasuryWallet instances.
|
|
124
164
|
sort_rules: Directory of sorting rules.
|
|
125
165
|
interval: Time interval for balance snapshots.
|
|
126
166
|
daemon: Ignored flag.
|
|
127
167
|
grafana_port: Port for Grafana (sets DAO_TREASURY_GRAFANA_PORT).
|
|
128
168
|
renderer_port: Port for renderer (sets DAO_TREASURY_RENDERER_PORT).
|
|
129
|
-
|
|
130
|
-
Note:
|
|
131
|
-
Inside this coroutine, the environment variable GRAFANA_PORT is overridden to "3003"
|
|
132
|
-
to satisfy current dashboard requirements.
|
|
169
|
+
start_renderer: If True, start renderer; otherwise, only start grafana.
|
|
133
170
|
|
|
134
171
|
Example:
|
|
135
172
|
In code::
|
|
@@ -141,20 +178,72 @@ async def export(args) -> None:
|
|
|
141
178
|
:func:`dao_treasury._docker.down`,
|
|
142
179
|
:class:`dao_treasury.Treasury.populate_db`
|
|
143
180
|
"""
|
|
144
|
-
|
|
181
|
+
import eth_portfolio_scripts.docker
|
|
182
|
+
|
|
183
|
+
from dao_treasury import _docker, constants, db, Treasury
|
|
184
|
+
|
|
185
|
+
wallets = getattr(args, "wallet", None)
|
|
186
|
+
wallets_advanced = getattr(args, "wallets", None)
|
|
187
|
+
|
|
188
|
+
# Ensure user does not supply both simple and advanced wallet inputs
|
|
189
|
+
if wallets and wallets_advanced:
|
|
190
|
+
parser.error("Cannot specify both --wallet and --wallets")
|
|
191
|
+
|
|
192
|
+
# Load advanced wallets from YAML if --wallets provided
|
|
193
|
+
if wallets_advanced:
|
|
194
|
+
wallets = load_wallets_from_yaml(wallets_advanced)
|
|
195
|
+
|
|
196
|
+
# Ensure at least one wallet source is provided
|
|
197
|
+
if not wallets:
|
|
198
|
+
parser.error("Must specify either --wallet or --wallets")
|
|
145
199
|
|
|
146
200
|
# TODO: remove this after refactoring eth-port a bit so we arent required to bring up the e-p dashboards
|
|
147
201
|
os.environ["GRAFANA_PORT"] = "3003"
|
|
148
202
|
|
|
149
203
|
# TODO but make the dashboard files more specific to dao treasury-ing
|
|
150
204
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
205
|
+
if args.nicknames:
|
|
206
|
+
parsed: dict = yaml.safe_load(args.nicknames.read_bytes())
|
|
207
|
+
active_network_config: dict = parsed.get(constants.CHAINID, {})
|
|
208
|
+
for nickname, addresses in active_network_config.items():
|
|
209
|
+
for address in addresses:
|
|
210
|
+
db.Address.set_nickname(address, nickname)
|
|
211
|
+
|
|
212
|
+
treasury = Treasury(wallets, args.sort_rules, asynchronous=True)
|
|
213
|
+
|
|
214
|
+
# Start only the requested containers
|
|
215
|
+
if args.start_renderer is True:
|
|
216
|
+
_docker.up()
|
|
217
|
+
else:
|
|
218
|
+
_docker.up("grafana")
|
|
219
|
+
|
|
220
|
+
# eth-portfolio needs this present
|
|
221
|
+
# TODO: we need to update eth-portfolio to honor wallet join and exit times
|
|
222
|
+
if not getattr(args, "wallet", None):
|
|
223
|
+
args.wallet = [
|
|
224
|
+
wallet.address
|
|
225
|
+
for wallet in wallets
|
|
226
|
+
if wallet.networks is None or CHAINID in wallet.networks
|
|
227
|
+
]
|
|
228
|
+
|
|
229
|
+
# TODO: make this user configurable? would require some dynamic grafana dashboard files
|
|
230
|
+
args.label = "Treasury"
|
|
231
|
+
|
|
232
|
+
export_task = create_task(
|
|
233
|
+
asyncio.gather(
|
|
155
234
|
export_balances(args),
|
|
156
235
|
treasury.populate_db(BlockNumber(0), brownie.chain.height),
|
|
157
236
|
)
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
await asyncio.sleep(1)
|
|
240
|
+
|
|
241
|
+
# we don't need these containers since dao-treasury uses its own.
|
|
242
|
+
eth_portfolio_scripts.docker.stop("grafana")
|
|
243
|
+
eth_portfolio_scripts.docker.stop("renderer")
|
|
244
|
+
|
|
245
|
+
try:
|
|
246
|
+
await export_task
|
|
158
247
|
finally:
|
|
159
248
|
_docker.down()
|
|
160
249
|
|
|
Binary file
|
dao_treasury/sorting/__init__.py
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
"""
|
|
2
|
-
This module
|
|
2
|
+
This module provides the core logic for sorting DAO Treasury transactions into transaction groups (categories).
|
|
3
|
+
|
|
4
|
+
Sorting enables comprehensive financial reporting and categorization tailored for on-chain organizations.
|
|
5
|
+
Transactions are matched against either statically defined rules or more advanced dynamic rules based on user-defined matching functions.
|
|
6
|
+
|
|
7
|
+
Sorting works by attempting matches in this order:
|
|
8
|
+
1. Check if the transaction is an internal transfer (within treasury wallets).
|
|
9
|
+
2. Check if the transaction is "Out of Range" (neither sender nor receiver was a treasury wallet at the time of the tx).
|
|
10
|
+
3. Match by transaction hash using registered HashMatchers.
|
|
11
|
+
4. Match by sender address using registered FromAddressMatchers.
|
|
12
|
+
5. Match by recipient address using registered ToAddressMatchers.
|
|
13
|
+
6. Assign "Must Sort Inbound" or "Must Sort Outbound" groups if part of treasury.
|
|
14
|
+
7. Raise an error if no match is found (unexpected case).
|
|
15
|
+
|
|
16
|
+
See the complete [sort rules documentation](https://bobthebuidler.github.io/dao-treasury/sort_rules.html) for detailed explanations
|
|
17
|
+
and examples on defining and registering sort rules.
|
|
18
|
+
|
|
19
|
+
See Also:
|
|
20
|
+
:func:`dao_treasury.sorting.sort_basic`
|
|
21
|
+
:func:`dao_treasury.sorting.sort_basic_entity`
|
|
22
|
+
:func:`dao_treasury.sorting.sort_advanced`
|
|
23
|
+
:class:`dao_treasury.sorting.HashMatcher`
|
|
24
|
+
:class:`dao_treasury.sorting.FromAddressMatcher`
|
|
25
|
+
:class:`dao_treasury.sorting.ToAddressMatcher`
|
|
3
26
|
"""
|
|
4
27
|
|
|
5
28
|
from logging import getLogger
|
|
@@ -7,8 +30,9 @@ from typing import Final, Optional
|
|
|
7
30
|
|
|
8
31
|
from eth_portfolio.structs import LedgerEntry
|
|
9
32
|
from evmspec.data import TransactionHash
|
|
33
|
+
from y.exceptions import ContractNotVerified
|
|
10
34
|
|
|
11
|
-
from dao_treasury import db
|
|
35
|
+
from dao_treasury import constants, db
|
|
12
36
|
from dao_treasury._wallet import TreasuryWallet
|
|
13
37
|
from dao_treasury.sorting._matchers import (
|
|
14
38
|
_Matcher,
|
|
@@ -34,6 +58,7 @@ from dao_treasury.sorting.rule import (
|
|
|
34
58
|
OtherIncomeSortRule,
|
|
35
59
|
RevenueSortRule,
|
|
36
60
|
)
|
|
61
|
+
from dao_treasury.sorting.rules import *
|
|
37
62
|
from dao_treasury.types import TxGroupDbid
|
|
38
63
|
|
|
39
64
|
|
|
@@ -63,30 +88,71 @@ __all__ = [
|
|
|
63
88
|
|
|
64
89
|
# C constants
|
|
65
90
|
TxGroup: Final = db.TxGroup
|
|
66
|
-
|
|
67
|
-
|
|
91
|
+
MUST_SORT_INBOUND_TXGROUP_DBID: Final = db.must_sort_inbound_txgroup_dbid
|
|
92
|
+
MUST_SORT_OUTBOUND_TXGROUP_DBID: Final = db.must_sort_outbound_txgroup_dbid
|
|
93
|
+
|
|
94
|
+
INTERNAL_TRANSFER_TXGROUP_DBID: Final = TxGroup.get_dbid(
|
|
95
|
+
name="Internal Transfer",
|
|
96
|
+
parent=TxGroup.get_dbid("Ignore"),
|
|
97
|
+
)
|
|
98
|
+
"""Database ID for the 'Internal Transfer' transaction group.
|
|
99
|
+
|
|
100
|
+
This group represents transactions that occur internally between treasury-owned wallets.
|
|
101
|
+
Such internal movements of funds within the DAO's treasury do not require separate handling or reporting.
|
|
102
|
+
|
|
103
|
+
See Also:
|
|
104
|
+
:class:`dao_treasury.db.TxGroup`
|
|
105
|
+
"""
|
|
106
|
+
|
|
107
|
+
OUT_OF_RANGE_TXGROUP_DBID = TxGroup.get_dbid(
|
|
108
|
+
name="Out of Range", parent=TxGroup.get_dbid("Ignore")
|
|
109
|
+
)
|
|
110
|
+
"""Database ID for the 'Out of Range' transaction group.
|
|
111
|
+
|
|
112
|
+
This category is assigned to transactions where neither the sender nor the recipient
|
|
113
|
+
wallet are members of the treasury at the time of the transaction.
|
|
114
|
+
|
|
115
|
+
See Also:
|
|
116
|
+
:class:`dao_treasury.db.TxGroup`
|
|
117
|
+
"""
|
|
68
118
|
|
|
69
119
|
|
|
70
120
|
def sort_basic(entry: LedgerEntry) -> TxGroupDbid:
|
|
121
|
+
"""Determine the transaction group ID for a basic ledger entry using static matching.
|
|
122
|
+
|
|
123
|
+
The function attempts to categorize the transaction by testing:
|
|
124
|
+
- If both 'from' and 'to' addresses are treasury wallets (internal transfer).
|
|
125
|
+
- If neither ‘to’ address is a treasury wallet at the time of the transaction (out of range).
|
|
126
|
+
- If the transaction hash matches a known HashMatcher.
|
|
127
|
+
- If the 'from' address matches a FromAddressMatcher.
|
|
128
|
+
- If the 'to' address matches a ToAddressMatcher.
|
|
129
|
+
- Assignment to 'Must Sort Outbound' or 'Must Sort Inbound' groups if applicable.
|
|
130
|
+
- Raises `NotImplementedError` if none of the above conditions are met (should not happen).
|
|
131
|
+
|
|
132
|
+
Args:
|
|
133
|
+
entry: A ledger entry representing a blockchain transaction.
|
|
134
|
+
|
|
135
|
+
Examples:
|
|
136
|
+
>>> from eth_portfolio.structs import Transaction
|
|
137
|
+
>>> entry = Transaction(from_address="0xabc...", to_address="0xdef...", block_number=1234567)
|
|
138
|
+
>>> group_id = sort_basic(entry)
|
|
139
|
+
>>> print(group_id)
|
|
140
|
+
|
|
141
|
+
See Also:
|
|
142
|
+
:func:`sort_basic_entity`
|
|
143
|
+
:func:`sort_advanced`
|
|
144
|
+
:class:`dao_treasury.sorting.HashMatcher`
|
|
145
|
+
"""
|
|
146
|
+
from_address = entry.from_address
|
|
147
|
+
to_address = entry.to_address
|
|
148
|
+
block = entry.block_number
|
|
149
|
+
|
|
71
150
|
txgroup_dbid: Optional[TxGroupDbid] = None
|
|
72
|
-
if
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
end_block_for_wallet is None or entry.block_number <= end_block_for_wallet
|
|
78
|
-
):
|
|
79
|
-
if to_wallet := TreasuryWallet._get_instance(entry.to_address):
|
|
80
|
-
start_block_for_wallet = to_wallet._start_block
|
|
81
|
-
end_block_for_wallet = to_wallet._end_block
|
|
82
|
-
if start_block_for_wallet <= entry.block_number and (
|
|
83
|
-
end_block_for_wallet is None
|
|
84
|
-
or entry.block_number <= end_block_for_wallet
|
|
85
|
-
):
|
|
86
|
-
txgroup_dbid = TxGroup.get_dbid(
|
|
87
|
-
name="Internal Transfer",
|
|
88
|
-
parent=TxGroup.get_dbid("Ignore"),
|
|
89
|
-
)
|
|
151
|
+
if TreasuryWallet.check_membership(from_address, block):
|
|
152
|
+
if TreasuryWallet.check_membership(to_address, block):
|
|
153
|
+
txgroup_dbid = INTERNAL_TRANSFER_TXGROUP_DBID
|
|
154
|
+
elif not TreasuryWallet.check_membership(to_address, block):
|
|
155
|
+
txgroup_dbid = OUT_OF_RANGE_TXGROUP_DBID
|
|
90
156
|
|
|
91
157
|
if txgroup_dbid is None:
|
|
92
158
|
if isinstance(txhash := entry.hash, TransactionHash):
|
|
@@ -94,126 +160,136 @@ def sort_basic(entry: LedgerEntry) -> TxGroupDbid:
|
|
|
94
160
|
txgroup_dbid = HashMatcher.match(txhash)
|
|
95
161
|
|
|
96
162
|
if txgroup_dbid is None:
|
|
97
|
-
txgroup_dbid = FromAddressMatcher.match(
|
|
163
|
+
txgroup_dbid = FromAddressMatcher.match(from_address)
|
|
98
164
|
|
|
99
165
|
if txgroup_dbid is None:
|
|
100
|
-
txgroup_dbid = ToAddressMatcher.match(
|
|
166
|
+
txgroup_dbid = ToAddressMatcher.match(to_address)
|
|
101
167
|
|
|
102
168
|
if txgroup_dbid is None:
|
|
103
|
-
if (
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
and (
|
|
109
|
-
from_wallet._end_block is None
|
|
110
|
-
or from_wallet._end_block >= entry.block_number
|
|
111
|
-
)
|
|
112
|
-
):
|
|
113
|
-
txgroup_dbid = must_sort_outbound_txgroup_dbid
|
|
114
|
-
|
|
115
|
-
elif (
|
|
116
|
-
entry.to_address
|
|
117
|
-
and (to_wallet := TreasuryWallet._get_instance(entry.to_address))
|
|
118
|
-
and to_wallet._start_block <= entry.block_number
|
|
119
|
-
and to_wallet._end_block is None
|
|
120
|
-
or entry.block_number <= to_wallet._end_block # type: ignore [union-attr, operator]
|
|
121
|
-
):
|
|
122
|
-
txgroup_dbid = must_sort_inbound_txgroup_dbid
|
|
169
|
+
if TreasuryWallet.check_membership(from_address, block):
|
|
170
|
+
txgroup_dbid = MUST_SORT_OUTBOUND_TXGROUP_DBID
|
|
171
|
+
|
|
172
|
+
elif TreasuryWallet.check_membership(to_address, block):
|
|
173
|
+
txgroup_dbid = MUST_SORT_INBOUND_TXGROUP_DBID
|
|
123
174
|
|
|
124
175
|
else:
|
|
125
176
|
raise NotImplementedError("this isnt supposed to happen")
|
|
126
177
|
return txgroup_dbid # type: ignore [no-any-return]
|
|
127
178
|
|
|
128
179
|
|
|
129
|
-
def sort_basic_entity(
|
|
180
|
+
def sort_basic_entity(tx: db.TreasuryTx) -> TxGroupDbid:
|
|
181
|
+
"""Determine the transaction group ID for a TreasuryTx database entity using static matching.
|
|
182
|
+
|
|
183
|
+
Similar to :func:`sort_basic` but operates on a TreasuryTx entity from the database.
|
|
184
|
+
It considers additional constants such as `DISPERSE_APP` when determining whether
|
|
185
|
+
a transaction is out of range.
|
|
186
|
+
|
|
187
|
+
Args:
|
|
188
|
+
tx: A TreasuryTx database entity representing a treasury transaction.
|
|
189
|
+
|
|
190
|
+
Examples:
|
|
191
|
+
>>> from dao_treasury.db import TreasuryTx
|
|
192
|
+
>>> tx = TreasuryTx[123]
|
|
193
|
+
>>> group_id = sort_basic_entity(tx)
|
|
194
|
+
>>> print(group_id)
|
|
195
|
+
|
|
196
|
+
See Also:
|
|
197
|
+
:func:`sort_basic`
|
|
198
|
+
:func:`sort_advanced`
|
|
199
|
+
"""
|
|
200
|
+
from_address = tx.from_address.address
|
|
201
|
+
to_address = tx.to_address
|
|
202
|
+
block = tx.block
|
|
203
|
+
|
|
130
204
|
txgroup_dbid: Optional[TxGroupDbid] = None
|
|
131
|
-
if
|
|
132
|
-
if
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
end_block_for_wallet is None or entry.block <= end_block_for_wallet
|
|
140
|
-
)
|
|
141
|
-
and entry.to_address
|
|
142
|
-
):
|
|
143
|
-
if to_wallet := TreasuryWallet._get_instance(entry.to_address.address):
|
|
144
|
-
start_block_for_wallet = to_wallet._start_block
|
|
145
|
-
end_block_for_wallet = to_wallet._end_block
|
|
146
|
-
if start_block_for_wallet <= entry.block and (
|
|
147
|
-
end_block_for_wallet is None
|
|
148
|
-
or entry.block <= end_block_for_wallet
|
|
149
|
-
):
|
|
150
|
-
txgroup_dbid = TxGroup.get_dbid(
|
|
151
|
-
name="Internal Transfer",
|
|
152
|
-
parent=TxGroup.get_dbid("Ignore"),
|
|
153
|
-
)
|
|
205
|
+
if TreasuryWallet.check_membership(from_address, block):
|
|
206
|
+
if TreasuryWallet.check_membership(tx.to_address.address, block):
|
|
207
|
+
txgroup_dbid = INTERNAL_TRANSFER_TXGROUP_DBID
|
|
208
|
+
elif not (
|
|
209
|
+
TreasuryWallet.check_membership(tx.to_address.address, tx.block)
|
|
210
|
+
or from_address in constants.DISPERSE_APP
|
|
211
|
+
):
|
|
212
|
+
txgroup_dbid = OUT_OF_RANGE_TXGROUP_DBID
|
|
154
213
|
|
|
155
214
|
if txgroup_dbid is None:
|
|
156
|
-
txgroup_dbid = HashMatcher.match(
|
|
215
|
+
txgroup_dbid = HashMatcher.match(tx.hash)
|
|
157
216
|
|
|
158
217
|
if txgroup_dbid is None:
|
|
159
|
-
txgroup_dbid = FromAddressMatcher.match(
|
|
218
|
+
txgroup_dbid = FromAddressMatcher.match(from_address)
|
|
160
219
|
|
|
161
|
-
if txgroup_dbid is None and
|
|
162
|
-
txgroup_dbid = ToAddressMatcher.match(
|
|
220
|
+
if txgroup_dbid is None and to_address:
|
|
221
|
+
txgroup_dbid = ToAddressMatcher.match(to_address.address)
|
|
163
222
|
|
|
164
223
|
if txgroup_dbid is None:
|
|
165
|
-
if (
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
txgroup_dbid = must_sort_outbound_txgroup_dbid
|
|
177
|
-
|
|
178
|
-
elif (
|
|
179
|
-
entry.to_address
|
|
180
|
-
and (to_wallet := TreasuryWallet._get_instance(entry.to_address.address))
|
|
181
|
-
and to_wallet._start_block <= entry.block
|
|
182
|
-
and to_wallet._end_block is None
|
|
183
|
-
or entry.block <= to_wallet._end_block # type: ignore [union-attr, operator]
|
|
184
|
-
):
|
|
185
|
-
txgroup_dbid = must_sort_inbound_txgroup_dbid
|
|
224
|
+
if TreasuryWallet.check_membership(from_address, block):
|
|
225
|
+
txgroup_dbid = MUST_SORT_OUTBOUND_TXGROUP_DBID
|
|
226
|
+
|
|
227
|
+
elif TreasuryWallet.check_membership(to_address.address, block):
|
|
228
|
+
txgroup_dbid = MUST_SORT_INBOUND_TXGROUP_DBID
|
|
229
|
+
|
|
230
|
+
elif from_address in constants.DISPERSE_APP:
|
|
231
|
+
txgroup_dbid = MUST_SORT_OUTBOUND_TXGROUP_DBID
|
|
232
|
+
|
|
233
|
+
elif from_address in constants.DISPERSE_APP:
|
|
234
|
+
txgroup_dbid = MUST_SORT_OUTBOUND_TXGROUP_DBID
|
|
186
235
|
|
|
187
236
|
else:
|
|
188
237
|
raise NotImplementedError("this isnt supposed to happen")
|
|
189
238
|
|
|
190
239
|
if txgroup_dbid not in (
|
|
191
|
-
|
|
192
|
-
|
|
240
|
+
MUST_SORT_INBOUND_TXGROUP_DBID,
|
|
241
|
+
MUST_SORT_OUTBOUND_TXGROUP_DBID,
|
|
193
242
|
):
|
|
194
|
-
logger.info("Sorted %s to %s",
|
|
243
|
+
logger.info("Sorted %s to %s", tx, TxGroup.get_fullname(txgroup_dbid))
|
|
195
244
|
|
|
196
245
|
return txgroup_dbid # type: ignore [no-any-return]
|
|
197
246
|
|
|
198
247
|
|
|
199
248
|
async def sort_advanced(entry: db.TreasuryTx) -> TxGroupDbid:
|
|
249
|
+
"""Determine the transaction group ID for a TreasuryTx entity using advanced dynamic rules.
|
|
250
|
+
|
|
251
|
+
Starts with the result of static matching via :func:`sort_basic_entity`, then
|
|
252
|
+
applies advanced asynchronous matching rules registered under :data:`SORT_RULES`.
|
|
253
|
+
Applies rules sequentially until a match is found or all rules are exhausted.
|
|
254
|
+
|
|
255
|
+
If a rule's match attempt raises a `ContractNotVerified` exception, the rule is skipped.
|
|
256
|
+
|
|
257
|
+
Updates the TreasuryTx entity's transaction group in the database when a match
|
|
258
|
+
other than 'Must Sort Inbound/Outbound' is found.
|
|
259
|
+
|
|
260
|
+
Args:
|
|
261
|
+
entry: A TreasuryTx database entity representing a treasury transaction.
|
|
262
|
+
|
|
263
|
+
Examples:
|
|
264
|
+
>>> from dao_treasury.db import TreasuryTx
|
|
265
|
+
>>> import asyncio
|
|
266
|
+
>>> tx = TreasuryTx[123]
|
|
267
|
+
>>> group_id = asyncio.run(sort_advanced(tx))
|
|
268
|
+
>>> print(group_id)
|
|
269
|
+
|
|
270
|
+
See Also:
|
|
271
|
+
:func:`sort_basic_entity`
|
|
272
|
+
:data:`SORT_RULES`
|
|
273
|
+
"""
|
|
200
274
|
txgroup_dbid = sort_basic_entity(entry)
|
|
201
275
|
|
|
202
276
|
if txgroup_dbid in (
|
|
203
|
-
|
|
204
|
-
|
|
277
|
+
MUST_SORT_INBOUND_TXGROUP_DBID,
|
|
278
|
+
MUST_SORT_OUTBOUND_TXGROUP_DBID,
|
|
205
279
|
):
|
|
206
280
|
for rules in SORT_RULES.values():
|
|
207
281
|
for rule in rules:
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
282
|
+
try:
|
|
283
|
+
if await rule.match(entry):
|
|
284
|
+
txgroup_dbid = rule.txgroup_dbid
|
|
285
|
+
break
|
|
286
|
+
except ContractNotVerified:
|
|
287
|
+
continue
|
|
212
288
|
if txgroup_dbid not in (
|
|
213
|
-
|
|
214
|
-
|
|
289
|
+
MUST_SORT_INBOUND_TXGROUP_DBID,
|
|
290
|
+
MUST_SORT_OUTBOUND_TXGROUP_DBID,
|
|
215
291
|
):
|
|
216
292
|
logger.info("Sorted %s to %s", entry, TxGroup.get_fullname(txgroup_dbid))
|
|
217
|
-
entry.
|
|
293
|
+
await entry._set_txgroup(txgroup_dbid)
|
|
218
294
|
|
|
219
295
|
return txgroup_dbid # type: ignore [no-any-return]
|
|
Binary file
|
|
Binary file
|
dao_treasury/sorting/_rules.py
CHANGED
|
@@ -4,8 +4,8 @@ from typing import Final, Type, Union, final
|
|
|
4
4
|
|
|
5
5
|
import yaml
|
|
6
6
|
from pony.orm import db_session
|
|
7
|
-
from y import constants
|
|
8
7
|
|
|
8
|
+
from dao_treasury.constants import CHAINID
|
|
9
9
|
from dao_treasury.sorting import (
|
|
10
10
|
_Matcher,
|
|
11
11
|
FromAddressMatcher,
|
|
@@ -15,8 +15,6 @@ from dao_treasury.sorting import (
|
|
|
15
15
|
from dao_treasury.types import TopLevelCategory, TxGroupDbid
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
CHAINID: Final = constants.CHAINID
|
|
19
|
-
|
|
20
18
|
logger: Final = getLogger("dao_treasury.rules")
|
|
21
19
|
|
|
22
20
|
|
|
Binary file
|
dao_treasury/sorting/factory.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
from typing import Any, Final, Generic, Optional,
|
|
2
|
-
|
|
3
|
-
from y import constants
|
|
1
|
+
from typing import Any, Final, Generic, Optional, Union, final, overload
|
|
4
2
|
|
|
3
|
+
from dao_treasury.constants import CHAINID
|
|
5
4
|
from dao_treasury.sorting.rule import (
|
|
6
5
|
CostOfRevenueSortRule,
|
|
7
6
|
ExpenseSortRule,
|
|
@@ -14,9 +13,6 @@ from dao_treasury.sorting.rule import (
|
|
|
14
13
|
from dao_treasury.types import Networks, SortFunction, TxGroupName
|
|
15
14
|
|
|
16
15
|
|
|
17
|
-
CHAINID: Final = constants.CHAINID
|
|
18
|
-
|
|
19
|
-
|
|
20
16
|
def revenue(
|
|
21
17
|
txgroup: TxGroupName, networks: Networks = CHAINID
|
|
22
18
|
) -> "SortRuleFactory[RevenueSortRule]":
|
|
Binary file
|