Commit e7f540c
feat(roi): include off-chain BalanceTracker pre-deposits in trader ROI cost
Adds the pre-deposit-as-loss term to trader's in-agent ROI calculation.
Every ``BalanceTracker.Deposit(account=safe, ..., amount)`` credit to
the agent's Safe is booked as spent the moment it lands on chain, since
the tracker has no requester-withdraw path so committed funds are
unrecoverable regardless of whether the mech has consumed them yet.
The existing on-chain path stays unchanged:
- ``_get_total_mech_requests`` still reads the marketplace subgraph counter
- ``_get_open_market_requests`` still filters last-4-days requests via
``parsedRequest.questionTitle``
- ``settled_mech_requests = total - open`` unchanged
- ``DEFAULT_MECH_FEE = 0.01`` unchanged
Only the cost formula grows one additive term:
total_costs_usd = totalTradedSettled + totalFeesSettled
+ settled_mech_costs_usd # unchanged
+ offchain_prepaid_usd # new
``offchain_prepaid_usd`` is derived from summing ``Deposit`` events
emitted for the agent's Safe by the BalanceTracker contract. For any
Safe that has never called ``depositFor`` (i.e. every production
on-chain trader today), the event stream is empty and the new term is
zero — the ROI number matches the pre-migration calculation exactly.
Storage:
- New ``OffchainDepositState`` dataclass with ``total_deposited_wei`` and
``last_scanned_block``, persisted under ``agent_performance.json``'s
new ``offchain_deposits`` field. Enables incremental log scans; each
cycle reads only new blocks since the last checkpoint and adds to the
monotonic cumulative sum.
Reader package:
- New trader-local ``valory/mech_prepaid_reader`` contract package. It
reuses the same ABI as the vendored ``valory/balance_tracker`` and
exposes one method (``get_deposit_events_for_requester``) that filters
the ``Deposit`` topic by the requester address and sums the amounts.
Kept trader-local so the vendored ``balance_tracker`` package (pinned
to ``mech-interact``) stays untouched.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 2467a1d commit e7f540c
18 files changed
Lines changed: 934 additions & 32 deletions
File tree
- packages
- valory
- agents/trader
- contracts/mech_prepaid_reader
- build
- tests
- services
- polymarket_trader
- trader_pearl
- skills
- agent_performance_summary_abci
- tests
- chatui_abci
- check_stop_trading_abci
- decision_maker_abci
- trader_abci
- tx_settlement_multiplexer_abci
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | | - | |
13 | | - | |
14 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
15 | 16 | | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
| |||
69 | 70 | | |
70 | 71 | | |
71 | 72 | | |
72 | | - | |
| 73 | + | |
73 | 74 | | |
74 | | - | |
75 | | - | |
| 75 | + | |
| 76 | + | |
76 | 77 | | |
77 | | - | |
| 78 | + | |
78 | 79 | | |
79 | | - | |
80 | | - | |
| 80 | + | |
| 81 | + | |
81 | 82 | | |
82 | 83 | | |
83 | 84 | | |
| |||
Lines changed: 30 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
0 commit comments