eth-portfolio 0.5.7__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 eth-portfolio might be problematic. Click here for more details.

Files changed (83) hide show
  1. eth_portfolio/__init__.py +24 -0
  2. eth_portfolio/_argspec.cp312-win32.pyd +0 -0
  3. eth_portfolio/_argspec.py +43 -0
  4. eth_portfolio/_cache.py +119 -0
  5. eth_portfolio/_config.cp312-win32.pyd +0 -0
  6. eth_portfolio/_config.py +4 -0
  7. eth_portfolio/_db/__init__.py +0 -0
  8. eth_portfolio/_db/decorators.py +147 -0
  9. eth_portfolio/_db/entities.py +311 -0
  10. eth_portfolio/_db/utils.py +616 -0
  11. eth_portfolio/_decimal.py +154 -0
  12. eth_portfolio/_decorators.py +84 -0
  13. eth_portfolio/_exceptions.py +65 -0
  14. eth_portfolio/_ledgers/__init__.py +0 -0
  15. eth_portfolio/_ledgers/address.py +924 -0
  16. eth_portfolio/_ledgers/portfolio.py +328 -0
  17. eth_portfolio/_loaders/__init__.py +33 -0
  18. eth_portfolio/_loaders/_nonce.cp312-win32.pyd +0 -0
  19. eth_portfolio/_loaders/_nonce.py +193 -0
  20. eth_portfolio/_loaders/balances.cp312-win32.pyd +0 -0
  21. eth_portfolio/_loaders/balances.py +95 -0
  22. eth_portfolio/_loaders/token_transfer.py +215 -0
  23. eth_portfolio/_loaders/transaction.py +240 -0
  24. eth_portfolio/_loaders/utils.cp312-win32.pyd +0 -0
  25. eth_portfolio/_loaders/utils.py +67 -0
  26. eth_portfolio/_shitcoins.cp312-win32.pyd +0 -0
  27. eth_portfolio/_shitcoins.py +342 -0
  28. eth_portfolio/_stableish.cp312-win32.pyd +0 -0
  29. eth_portfolio/_stableish.py +42 -0
  30. eth_portfolio/_submodules.py +72 -0
  31. eth_portfolio/_utils.py +215 -0
  32. eth_portfolio/_ydb/__init__.py +0 -0
  33. eth_portfolio/_ydb/token_transfers.py +145 -0
  34. eth_portfolio/address.py +396 -0
  35. eth_portfolio/buckets.py +212 -0
  36. eth_portfolio/constants.cp312-win32.pyd +0 -0
  37. eth_portfolio/constants.py +87 -0
  38. eth_portfolio/portfolio.py +662 -0
  39. eth_portfolio/protocols/__init__.py +64 -0
  40. eth_portfolio/protocols/_base.py +107 -0
  41. eth_portfolio/protocols/convex.py +17 -0
  42. eth_portfolio/protocols/dsr.py +50 -0
  43. eth_portfolio/protocols/lending/README.md +6 -0
  44. eth_portfolio/protocols/lending/__init__.py +50 -0
  45. eth_portfolio/protocols/lending/_base.py +56 -0
  46. eth_portfolio/protocols/lending/compound.py +186 -0
  47. eth_portfolio/protocols/lending/liquity.py +108 -0
  48. eth_portfolio/protocols/lending/maker.py +110 -0
  49. eth_portfolio/protocols/lending/unit.py +44 -0
  50. eth_portfolio/protocols/liquity.py +17 -0
  51. eth_portfolio/py.typed +0 -0
  52. eth_portfolio/structs/__init__.py +43 -0
  53. eth_portfolio/structs/modified.py +69 -0
  54. eth_portfolio/structs/structs.py +626 -0
  55. eth_portfolio/typing/__init__.py +1418 -0
  56. eth_portfolio/typing/balance/single.py +176 -0
  57. eth_portfolio-0.5.7.dist-info/METADATA +26 -0
  58. eth_portfolio-0.5.7.dist-info/RECORD +83 -0
  59. eth_portfolio-0.5.7.dist-info/WHEEL +5 -0
  60. eth_portfolio-0.5.7.dist-info/entry_points.txt +2 -0
  61. eth_portfolio-0.5.7.dist-info/top_level.txt +3 -0
  62. eth_portfolio__mypyc.cp312-win32.pyd +0 -0
  63. eth_portfolio_scripts/__init__.py +17 -0
  64. eth_portfolio_scripts/_args.py +26 -0
  65. eth_portfolio_scripts/_logging.py +14 -0
  66. eth_portfolio_scripts/_portfolio.py +209 -0
  67. eth_portfolio_scripts/_utils.py +106 -0
  68. eth_portfolio_scripts/balances.cp312-win32.pyd +0 -0
  69. eth_portfolio_scripts/balances.py +56 -0
  70. eth_portfolio_scripts/docker/.grafana/dashboards/Portfolio/Balances.json +1962 -0
  71. eth_portfolio_scripts/docker/.grafana/dashboards/dashboards.yaml +10 -0
  72. eth_portfolio_scripts/docker/.grafana/datasources/datasources.yml +11 -0
  73. eth_portfolio_scripts/docker/__init__.cp312-win32.pyd +0 -0
  74. eth_portfolio_scripts/docker/__init__.py +16 -0
  75. eth_portfolio_scripts/docker/check.cp312-win32.pyd +0 -0
  76. eth_portfolio_scripts/docker/check.py +66 -0
  77. eth_portfolio_scripts/docker/docker-compose.yaml +61 -0
  78. eth_portfolio_scripts/docker/docker_compose.cp312-win32.pyd +0 -0
  79. eth_portfolio_scripts/docker/docker_compose.py +97 -0
  80. eth_portfolio_scripts/main.py +118 -0
  81. eth_portfolio_scripts/py.typed +1 -0
  82. eth_portfolio_scripts/victoria/__init__.py +72 -0
  83. eth_portfolio_scripts/victoria/types.py +38 -0
@@ -0,0 +1,626 @@
1
+ """
2
+ Defines the data classes used to represent the various types of value-transfer actions on the blockchain. These include transactions, internal transfers, and token transfers.
3
+
4
+ The classes are designed to provide a consistent and flexible interface for working with blockchain data. Instance attributes can be fetched with either dot notation or key lookup. Classes are compatible with the standard dictionary interface.
5
+ """
6
+
7
+ from functools import cached_property
8
+ from typing import Any, ClassVar, Literal, TypeVar, Union, final
9
+
10
+ import evmspec
11
+ from brownie import chain
12
+ from dictstruct import DictStruct
13
+ from evmspec.data import Address, BlockHash, TransactionHash, Wei
14
+ from evmspec.structs.trace import reward
15
+ from evmspec.structs.transaction import AccessListEntry
16
+ from hexbytes import HexBytes
17
+ from msgspec import Struct
18
+ from y import Network
19
+ from y._db.log import Log
20
+ from y._decorators import stuck_coro_debugger
21
+ from y.constants import EEE_ADDRESS
22
+ from y.datatypes import Block
23
+
24
+ from eth_portfolio._decimal import Decimal
25
+ from eth_portfolio._utils import _get_price
26
+ from eth_portfolio.structs.modified import ModifiedTrace, _modified_trace_type_map
27
+
28
+
29
+ class _LedgerEntryBase(DictStruct, kw_only=True, frozen=True, omit_defaults=True, repr_omit_defaults=True): # type: ignore [call-arg]
30
+ """
31
+ The :class:`~structs._LedgerEntryBase` class is a base class for ledger entries representing on-chain actions in a blockchain.
32
+
33
+ Provides common attributes for transactions, internal transfers, and token transfers.
34
+
35
+ Extended by specific ledger entry types :class:`~structs.Transaction`, :class:`~structs.InternalTransfer`, and :class:`~structs.TokenTransfer`.
36
+ """
37
+
38
+ @property
39
+ def _evm_object(self) -> evmspec.Transaction | evmspec.FilterTrace | Log:
40
+ """
41
+ The EVM object associated with {cls_name}, exactly as it was received from the RPC.
42
+ """
43
+ return getattr(self, self.entry_type)
44
+
45
+ @property
46
+ def chainid(self) -> Network:
47
+ """
48
+ The network ID where the {cls_name} occurred.
49
+ """
50
+ try:
51
+ return Network(self._evm_object.chainId)
52
+ except AttributeError:
53
+ return Network(chain.id)
54
+
55
+ @property
56
+ def block_number(self) -> Block:
57
+ """
58
+ The block number where the {cls_name} was included.
59
+ """
60
+ return self._evm_object.block
61
+
62
+ price: Decimal | None = None
63
+ """
64
+ The price of the cryptocurrency at the time of the {cls_name}, if known.
65
+ """
66
+
67
+ value_usd: Decimal | None = None
68
+ """
69
+ The USD value of the cryptocurrency transferred in the {cls_name}, if price is known.
70
+ """
71
+
72
+ def __init_subclass__(cls, **kwargs: Any) -> None:
73
+ super().__init_subclass__(**kwargs)
74
+
75
+ # Replace {cls_name} in attribute-level docstrings
76
+ for key, attr in cls.__dict__.items():
77
+ if attr.__doc__ and "{cls_name}" in attr.__doc__:
78
+ attr.__doc__ = attr.__doc__.replace("{cls_name}", cls.__name__)
79
+
80
+
81
+ def _get_init_kwargs(original_struct: Struct) -> dict[str, Any]:
82
+ kwargs = {}
83
+ for key in original_struct.__struct_fields__:
84
+ try:
85
+ kwargs[key] = getattr(original_struct, key)
86
+ except AttributeError:
87
+ continue
88
+ return kwargs
89
+
90
+
91
+ class _TransactionBase(
92
+ _LedgerEntryBase,
93
+ kw_only=True,
94
+ frozen=True,
95
+ array_like=True,
96
+ forbid_unknown_fields=True,
97
+ omit_defaults=True,
98
+ repr_omit_defaults=True,
99
+ dict=True,
100
+ ):
101
+ """
102
+ The :class:`~structs.Transaction` class represents a complete on-chain blockchain transaction.
103
+
104
+ Contains detailed information about a single executed transaction on the blockchain,
105
+ including gas parameters, signature components, and transaction-specific data.
106
+
107
+ Example:
108
+ >>> tx = Transaction(tx=Transaction1559(...))
109
+ >>> tx.chainid
110
+ Network.Mainnet
111
+ >>> tx.type
112
+ 2
113
+ >>> tx.max_fee_per_gas
114
+ 30000000000
115
+ """
116
+
117
+ entry_type: ClassVar[Literal["transaction"]] = "transaction"
118
+ """
119
+ Constant indicating this value transfer is an on-chain transaction entry.
120
+ """
121
+
122
+ @classmethod
123
+ def from_rpc_response(
124
+ cls,
125
+ transaction: evmspec.Transaction,
126
+ *,
127
+ price: Decimal | None = None,
128
+ value_usd: Decimal | None = None,
129
+ ) -> "Transaction":
130
+ return cls(
131
+ transaction=transaction,
132
+ price=price,
133
+ value_usd=value_usd,
134
+ )
135
+
136
+ @property
137
+ def hash(self) -> TransactionHash:
138
+ """
139
+ The unique transaction hash.
140
+ """
141
+ return self.transaction.hash
142
+
143
+ @property
144
+ def block_hash(self) -> BlockHash:
145
+ """
146
+ The hash of the block that includes this Transaction.
147
+ """
148
+ return self.transaction.blockHash
149
+
150
+ @property
151
+ def transaction_index(self) -> int | None:
152
+ """
153
+ The index of the transaction within its block, if applicable.
154
+ """
155
+ return self.transaction.transactionIndex
156
+
157
+ @property
158
+ def nonce(self) -> int:
159
+ """
160
+ The sender's transaction count at the time of this Transaction.
161
+ """
162
+ return self.transaction.nonce
163
+
164
+ @cached_property
165
+ def type(self) -> int | None:
166
+ """
167
+ The transaction type (e.g., 0 for legacy, 1 for EIP-2930, 2 for EIP-1559).
168
+ None for chains that don't specify transaction types.
169
+ """
170
+ if typ := self.transaction.type:
171
+ return int(typ.hex(), 16)
172
+
173
+ @property
174
+ def from_address(self) -> Address | None:
175
+ """
176
+ The address from which the transaction was sent, if applicable.
177
+ """
178
+ return self.transaction.sender
179
+
180
+ @property
181
+ def to_address(self) -> Address | None:
182
+ """
183
+ The address to which the transaction was sent, if applicable.
184
+ """
185
+ return self.transaction.to
186
+
187
+ @property
188
+ def value(self) -> Decimal:
189
+ """
190
+ The value/amount of cryptocurrency transferred in the transaction, scaled to a human-readable decimal value.
191
+ """
192
+ return Wei(self.transaction.value).scaled
193
+
194
+ @property
195
+ def gas(self) -> int:
196
+ """
197
+ The maximum amount of gas the sender is willing to use for the Transaction.
198
+ """
199
+ return self.transaction.gas
200
+
201
+ @property
202
+ def gas_price(self) -> int:
203
+ """
204
+ The price per unit of gas the sender is willing to pay (for legacy and EIP-2930 transactions).
205
+ """
206
+ return self.transaction.gasPrice
207
+
208
+ @property
209
+ def max_fee_per_gas(self) -> int | None:
210
+ """
211
+ The maximum total fee per gas the sender is willing to pay (for EIP-1559 transactions only).
212
+ """
213
+ return self.transaction.maxFeePerGas
214
+
215
+ @property
216
+ def max_priority_fee_per_gas(self) -> int | None:
217
+ """
218
+ The maximum priority fee per gas the sender is willing to pay (for EIP-1559 transactions only).
219
+ """
220
+ return self.transaction.maxPriorityFeePerGas
221
+
222
+ @property
223
+ def input(self) -> HexBytes:
224
+ """
225
+ The data payload sent with the Transaction, often used for contract interactions.
226
+ """
227
+ return self.transaction.input
228
+
229
+ @property
230
+ def r(self) -> HexBytes:
231
+ """
232
+ The R component of the Transaction's ECDSA signature.
233
+ """
234
+ return self.transaction.r
235
+
236
+ @property
237
+ def s(self) -> HexBytes:
238
+ """
239
+ The S component of the Transaction's ECDSA signature.
240
+ """
241
+ return self.transaction.s
242
+
243
+ @property
244
+ def v(self) -> int:
245
+ """
246
+ The V component of the Transaction's ECDSA signature, used for replay protection.
247
+ """
248
+ return self.transaction.v
249
+
250
+ @property
251
+ def access_list(self) -> tuple[AccessListEntry, ...] | None:
252
+ """
253
+ List of addresses and storage keys the transaction plans to access (for EIP-2930 and EIP-1559 transactions).
254
+ """
255
+ return self.transaction.accessList
256
+
257
+ @property
258
+ def y_parity(self) -> int | None:
259
+ """
260
+ The Y parity of the transaction signature, used in EIP-2718 typed transactions.
261
+ """
262
+ return self.transaction.yParity
263
+
264
+ @property
265
+ def __db_primary_key__(self) -> dict[str, tuple[int, Address] | int]:
266
+ return {"from_address": (chain.id, self.from_address), "nonce": self.nonce}
267
+
268
+
269
+ @final
270
+ class Transaction(
271
+ _TransactionBase,
272
+ kw_only=True,
273
+ frozen=True,
274
+ array_like=True,
275
+ forbid_unknown_fields=True,
276
+ omit_defaults=True,
277
+ repr_omit_defaults=True,
278
+ dict=True,
279
+ ):
280
+
281
+ transaction: evmspec.Transaction
282
+ """
283
+ The transaction object received by calling eth_getTransactionByHash.
284
+ """
285
+
286
+
287
+ @final
288
+ class TransactionRLP(
289
+ _TransactionBase,
290
+ kw_only=True,
291
+ frozen=True,
292
+ array_like=True,
293
+ forbid_unknown_fields=True,
294
+ omit_defaults=True,
295
+ repr_omit_defaults=True,
296
+ dict=True,
297
+ ):
298
+
299
+ transaction: evmspec.TransactionRLP
300
+ """
301
+ The transaction object received by calling eth_getTransactionByHash.
302
+ """
303
+
304
+
305
+ @final
306
+ class InternalTransfer(
307
+ _LedgerEntryBase,
308
+ kw_only=True,
309
+ frozen=True,
310
+ array_like=True,
311
+ forbid_unknown_fields=True,
312
+ omit_defaults=True,
313
+ repr_omit_defaults=True,
314
+ ):
315
+ """
316
+ The :class:`~structs.InternalTransfer`class represents an internal transfer or call within a blockchain transaction.
317
+
318
+ Captures operations that occur during transaction execution, such as contract-to-contract calls,
319
+ contract creations, or self-destructs. These are not separate on-chain transactions but part of
320
+ the execution of a single transaction.
321
+
322
+ Example:
323
+ >>> internal_tx = InternalTransfer(trace=evmspec.FilterTrace(...), ...)
324
+ >>> internal_tx.type
325
+ 'call'
326
+ >>> internal_tx.trace_address
327
+ '0.1'
328
+ >>> internal_tx.gas_used
329
+ 21000
330
+ """
331
+
332
+ @staticmethod
333
+ @stuck_coro_debugger
334
+ async def from_trace(trace: evmspec.FilterTrace, load_prices: bool) -> "InternalTransfer":
335
+ # sourcery skip: simplify-boolean-comparison
336
+ """
337
+ Asynchronously processes a raw internal transfer dictionary into an InternalTransfer object.
338
+
339
+ This function is the core of the internal transfer processing pipeline. It handles
340
+ various types of transfers, including special cases like block and uncle rewards.
341
+ It also filters out certain transfers (e.g., to Gnosis Safe Singleton) and verifies
342
+ transaction success for non-reward transfers.
343
+
344
+ The function performs several data transformations:
345
+ - Value and gas conversions
346
+ - Optional USD price loading
347
+ - Field standardization
348
+
349
+ Args:
350
+ transfer: A dictionary containing the raw internal transfer data. Expected to have keys such as
351
+ 'type', 'transactionHash', 'blockNumber', 'from', 'to', 'value', 'gas', 'gasUsed', 'traceAddress'.
352
+ load_prices: Flag to determine whether to load USD prices for the transfer value.
353
+
354
+ Returns:
355
+ A processed InternalTransfer object.
356
+
357
+ Example:
358
+ >>> transfer = {"type": "call", "transactionHash": "0x123...", "blockNumber": 15537393, "from": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", "to": "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D", "value": "0x10", "gas": "0x5208", "gasUsed": "0x5208", "traceAddress": [0]}
359
+ >>> internal_tx = await load_internal_transfer(transfer=transfer, load_prices=True); print(internal_tx)
360
+
361
+ Note:
362
+ - Transfers to the Gnosis Safe Singleton (0xd9Db270c1B5E3Bd161E8c8503c55cEABeE709552) are filtered out
363
+ as they typically don't represent actual value transfers.
364
+ - The `traceAddress` is converted to a string for consistent representation across different scenarios.
365
+ - For block and uncle rewards, `gas` is set to 0 as these are not regular transactions.
366
+ - When loading prices, the `EEE_ADDRESS` constant is used, which represents the native currency of the chain.
367
+
368
+ Integration with eth_portfolio ecosystem:
369
+ - Uses the InternalTransfer struct from eth_portfolio.structs for standardized output.
370
+ - Utilizes utility functions from eth_portfolio._loaders.utils and eth_portfolio._utils.
371
+ - Interacts with the global 'chain' object from the brownie library for chain ID.
372
+ """
373
+
374
+ modified_cls = _modified_trace_type_map[type(trace)]
375
+ modified_trace = modified_cls(**_get_init_kwargs(trace))
376
+
377
+ if load_prices is False:
378
+ return InternalTransfer(trace=modified_trace)
379
+
380
+ price = await _get_price(EEE_ADDRESS, trace.block)
381
+ value_usd = round(trace.action.value.scaled * price, 18)
382
+ return InternalTransfer(trace=modified_trace, price=price, value_usd=value_usd)
383
+
384
+ entry_type: ClassVar[Literal["internal_transfer"]] = "internal_transfer"
385
+ """
386
+ Constant indicating this value transfer is an internal transfer or call entry.
387
+ """
388
+
389
+ @property
390
+ def _evm_object(self) -> ModifiedTrace:
391
+ return self.trace
392
+
393
+ trace: ModifiedTrace
394
+ """
395
+ The raw trace object associated with this internal transfer.
396
+ """
397
+
398
+ @property
399
+ def block_hash(self) -> HexBytes:
400
+ """
401
+ The hash of the block containing the transaction that includes this InternalTransfer.
402
+ """
403
+ return self.trace.blockHash
404
+
405
+ @property
406
+ def transaction_index(self) -> int | None:
407
+ """
408
+ The index of the transaction within its block, if applicable.
409
+ """
410
+ return self.trace.transactionPosition
411
+
412
+ @property
413
+ def hash(self) -> HexBytes | str:
414
+ """
415
+ The unique hash of the transaction containing this internal transfer.
416
+ """
417
+ return (
418
+ f"{self.trace.action.rewardType.name} reward"
419
+ if isinstance(self.trace, reward.Trace)
420
+ else self.trace.transactionHash
421
+ )
422
+
423
+ @property
424
+ def from_address(self) -> Address:
425
+ """
426
+ The address from which the internal transfer was sent, if applicable.
427
+ """
428
+ return self.trace.action.sender
429
+
430
+ @property
431
+ def to_address(self) -> Address | None:
432
+ """
433
+ The address to which the internal transfer was sent, if applicable.
434
+ """
435
+ action = self.trace.action
436
+ # NOTE: for block reward transfers, the recipient is 'author'
437
+ return action.author if isinstance(action, reward.Action) else action.to
438
+
439
+ @property
440
+ def value(self) -> Decimal:
441
+ """
442
+ The value/amount of cryptocurrency transferred in the internal transfer, scaled to a human-readable decimal value.
443
+ """
444
+ return self.trace.action.value.scaled
445
+
446
+ @property
447
+ def type(self) -> Literal["call", "create", "reward", "suicide"]:
448
+ return self.trace.type
449
+
450
+ @property
451
+ def trace_address(self) -> list[int]:
452
+ """
453
+ The path of sub-calls to reach this InternalTransfer within the transaction,
454
+
455
+ Example:
456
+ - The following trace_address
457
+ ```python
458
+ [0, 1, 2]
459
+ ```
460
+ represents the third sub-call of the second sub-call of the first top-level call.
461
+ """
462
+ return self.trace.traceAddress
463
+
464
+ @property
465
+ def gas(self) -> int:
466
+ """
467
+ The amount of gas allocated for this internal operation.
468
+ """
469
+ return 0 if isinstance(self.trace, reward.Trace) else self.trace.action.gas
470
+
471
+ @property
472
+ def gas_used(self) -> int:
473
+ """
474
+ The amount of gas actually consumed by this internal operation, if known.
475
+ """
476
+ return self.trace.result.gasUsed
477
+
478
+ @property
479
+ def subtraces(self) -> int:
480
+ """
481
+ The number of sub-operations spawned by this InternalTransfer.
482
+ """
483
+ return self.trace.subtraces
484
+
485
+ @property
486
+ def call_type(self) -> str | None:
487
+ """
488
+ The type of call made in this InternalTransfer (e.g., "call", "delegatecall", "staticcall").
489
+ """
490
+ return self.trace.action.callType.name
491
+
492
+ @property
493
+ def reward_type(self) -> str | None:
494
+ """
495
+ The type of the reward, for reward transactions.
496
+ """
497
+ return self.trace.action.rewardType.name
498
+
499
+ @property
500
+ def input(self) -> HexBytes:
501
+ """
502
+ The input data for this internal operation, if any.
503
+ """
504
+ return self.trace.action.input
505
+
506
+ @property
507
+ def output(self) -> HexBytes:
508
+ """
509
+ The output data from this internal operation, if any.
510
+ """
511
+ return self.trace.result.output
512
+
513
+ '''
514
+ init: HexBytes | None = UNSET
515
+ """
516
+ The initialization code for contract creation, if this is a create operation.
517
+ """
518
+
519
+ address: HexBytes | None = UNSET
520
+ """
521
+ The address of the account or contract involved in this InternalTransfer.
522
+ """
523
+
524
+ code: HexBytes | None = UNSET
525
+ """
526
+ The code of the contract involved in this InternalTransfer, if applicable.
527
+ """
528
+ '''
529
+
530
+
531
+ @final
532
+ class TokenTransfer(
533
+ _LedgerEntryBase,
534
+ kw_only=True,
535
+ frozen=True,
536
+ array_like=True,
537
+ forbid_unknown_fields=True,
538
+ omit_defaults=True,
539
+ ):
540
+ """
541
+ The :class:`~structs.TokenTransfer` class represents a token transfer event within a blockchain transaction.
542
+
543
+ Captures the movement of ERC20-like tokens between addresses. These are typically
544
+ emitted as events by token contracts and are not separate transactions but part of
545
+ the execution of a transaction interacting with the token contract.
546
+
547
+ Example:
548
+ >>> token_transfer = TokenTransfer(
549
+ ... log=Log(...),
550
+ ... value=Decimal("1000000"), # 1 USDC (assuming 6 decimals)
551
+ ... token="USDC",
552
+ ... )
553
+ >>> token_transfer.token
554
+ 'USDC'
555
+ >>> token_transfer.value
556
+ Decimal('1000000')
557
+ >>> token_transfer.log_index
558
+ 3
559
+ """
560
+
561
+ entry_type: ClassVar[Literal["token_transfer"]] = "token_transfer"
562
+ """
563
+ Constant indicating this value transfer is a token transfer entry.
564
+ """
565
+
566
+ log: Log
567
+ """
568
+ The log associated with this token transfer.
569
+ """
570
+
571
+ @property
572
+ def from_address(self) -> Address:
573
+ return self.log.topic1.as_address
574
+
575
+ @property
576
+ def to_address(self) -> Address:
577
+ return self.log.topic2.as_address
578
+
579
+ @property
580
+ def _evm_object(self) -> Log:
581
+ return self.log
582
+
583
+ transaction_index: int
584
+
585
+ @property
586
+ def log_index(self) -> int:
587
+ """
588
+ The index of this transfer event within the transaction logs.
589
+ Used to uniquely identify the Transfer event associated with this TokenTransfer within the transaction.
590
+ """
591
+ return self.log.logIndex
592
+
593
+ token: str | None
594
+ """
595
+ The symbol of the token being transferred, if known.
596
+ """
597
+
598
+ @property
599
+ def hash(self) -> HexBytes:
600
+ """
601
+ The unique hash of the transaction containing this token transfer.
602
+ """
603
+ return self.log.transactionHash
604
+
605
+ @property
606
+ def token_address(self) -> Address:
607
+ """
608
+ The contract address of the token being transferred.
609
+ """
610
+ return self.log.address
611
+
612
+ value: Decimal
613
+ """
614
+ The amount of tokens transferred, scaled to a human-readable decimal value.
615
+ """
616
+
617
+
618
+ LedgerEntry = Union[Transaction, InternalTransfer, TokenTransfer]
619
+ """
620
+ Type alias representing any type of ledger entry (:class:`~structs.Transaction`, :class:`~structs.InternalTransfer`, or :class:`~structs.TokenTransfer`).
621
+ """
622
+
623
+ _LE = TypeVar("_LE", Transaction, InternalTransfer, TokenTransfer)
624
+ """
625
+ Type variable for generic operations on ledger entries. Can be :class:`~structs.Transaction`, :class:`~structs.InternalTransfer`, or :class:`~structs.TokenTransfer`.
626
+ """