Skip to content

Commit e7f540c

Browse files
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/packages.json

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@
77
"contract/valory/relayer/0.1.0": "bafybeifrvzmwkumdachm7wuesfdqvz52xsybpnvdlelltm3qowosgd6tp4",
88
"contract/valory/market_maker/0.1.0": "bafybeiaogkujiilubosloromkikuhltgiiadjvtzw2b5p5hc3klzi4m4nq",
99
"contract/valory/deposit_wallet/0.1.0": "bafybeifmw77pznzla6zwq7mfncdzboxmlmm5ffmkvlxlqfg442oypfqjje",
10+
"contract/valory/mech_prepaid_reader/0.1.0": "bafybeihy66fulkrsc4fxucrpunnr5ulwzudvnzxw5xtwjc7zqarf6bj3mi",
1011
"connection/valory/polymarket_client/0.1.0": "bafybeid4eo37pka4tfhsjs6rb3knrugmokcvihust2dpfrgob56y77xd44",
1112
"skill/valory/market_manager_abci/0.1.0": "bafybeig3ak2eoimxwuupybde4napyi2jlf7pxk35se2zclikete2ni5hti",
12-
"skill/valory/decision_maker_abci/0.1.0": "bafybeib67kekwmnprt44es47lg4oecy6prxqmv6m5k5zqw4hvrskawlifu",
13-
"skill/valory/trader_abci/0.1.0": "bafybeie2mant7aierij5zcq57iyiizbdpqoj7pkodvt2n5m2mvwrtmewca",
14-
"skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeic67t7ndzwzekacof7nvk7zgr6dhl6yrqqcashqq3pxjjhhwcilju",
13+
"skill/valory/decision_maker_abci/0.1.0": "bafybeidel24uozve2ndxmwshhyrzsyv7itcodzqjcfzgqqikr4khpn4eiu",
14+
"skill/valory/trader_abci/0.1.0": "bafybeiarobiv2d5l6teaslt7s4o36gni3bkwr75nub253mypms56dqzn7y",
15+
"skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeibyonzs6wyvbcks5bztmc7rmdooynxmlfhiaub2cmuamqbtijv3ou",
1516
"skill/valory/staking_abci/0.1.0": "bafybeia6csjgex5zxdt6vymiaengu75lyzjdgfrnp65ewlghthiniquhje",
16-
"skill/valory/agent_performance_summary_abci/0.1.0": "bafybeibdudllr3t7lpxwqtipqjpygk5kg64cohpdd5pafr7vcfjcocow6y",
17-
"skill/valory/check_stop_trading_abci/0.1.0": "bafybeie5ag4baxeqvp4impypnkcxi2wgmoym2udchei45ovqcydauoyyje",
18-
"skill/valory/chatui_abci/0.1.0": "bafybeiddfs7fy23e7lidopd67fcvwzul5invz5ngkufbrlh757inmm2a5e",
19-
"agent/valory/trader/0.1.0": "bafybeibistsq3fvrfei6ypqom37y7a4ioxeoob6xbniduukyh2qtyssp24",
20-
"service/valory/trader_pearl/0.1.0": "bafybeif6ed2k4m5ec5t6seyycifathbrytamdguwhmbvmdch2kra5yif3e",
21-
"service/valory/polymarket_trader/0.1.0": "bafybeihw7p7ezqxytbzlicutcna6ytc33e5xja4yxh6qyeoefhwocuob3a"
17+
"skill/valory/agent_performance_summary_abci/0.1.0": "bafybeicejhpfa6cth6hmz5yxbpbp3awbaxk26sulw6xk3lkzp7ruxov3ni",
18+
"skill/valory/check_stop_trading_abci/0.1.0": "bafybeidzz3x3m3cc2z76lqdhwacgrswjgbenc53ljx6ihmra2nnkg2khjm",
19+
"skill/valory/chatui_abci/0.1.0": "bafybeic6isfmqxmwswrgiuwzlyvmivnxkmwfhkgwzoc226753hcij6c3f4",
20+
"agent/valory/trader/0.1.0": "bafybeihmsgrivxffvdzr46dm4pftc4erf7v5j4vxdzl3q5blaysbeknree",
21+
"service/valory/trader_pearl/0.1.0": "bafybeic3peosuizvdyqeu6bycpy6le2ssl3vqlzopj6sl7ixs77uscr4ea",
22+
"service/valory/polymarket_trader/0.1.0": "bafybeifkpi37hfv5pvo4yncfk5ja6bhd4ee5j5iydnizmgvufyyvvgeu5q"
2223
},
2324
"third_party": {
2425
"protocol/valory/acn_data_share/0.1.0": "bafybeieqisfr6lhaaesq37lk7vyaxza2h6nucshksgyo2djqfyf2saqo4i",

packages/valory/agents/trader/aea-config.yaml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ contracts:
4343
- valory/mech_marketplace:0.1.0:bafybeigrcnjaycggulxyx2tsjub4ssjij66d7nfzsavo6gd54hm7beliiu
4444
- valory/balance_tracker:0.1.0:bafybeiayyxl643qfpw57vopytxgyd6flxxmwassswuxen7myekqaxdxxvi
4545
- valory/balance_tracker_fixed_price_native:0.1.0:bafybeihyaxqkyw2ulroqlhpfcgkrwtrwkhshn35fdq2ystraezwyco3k4u
46+
- valory/mech_prepaid_reader:0.1.0:bafybeihy66fulkrsc4fxucrpunnr5ulwzudvnzxw5xtwjc7zqarf6bj3mi
4647
- valory/escrow_payment_condition:0.1.0:bafybeifghaewxrhssktvscpxpvydq3xvjd5rxx37oz54lhzsg2kelmwkai
4748
- valory/did_registry:0.1.0:bafybeianxf7gjparfype4xesfdep362odimhgriviweluinnexwuglm2ku
4849
- valory/nft_sales:0.1.0:bafybeidlzxmxpx25zcn5nhi3lb4kvfhfjsaw2dul2hogghshnxzmurfiom
@@ -69,15 +70,15 @@ skills:
6970
- valory/reset_pause_abci:0.1.0:bafybeifrnmlscfiki7wojs6zasppefupd2wkjyq6orhdllfppjud7isrxi
7071
- valory/termination_abci:0.1.0:bafybeih6sa2ttcvvjk7rcfn7ure2ws23kcfufssb4qmluzcfvednkfpvoi
7172
- valory/transaction_settlement_abci:0.1.0:bafybeihizaapype5sz7vlosms3nfo6jzfj4ujycuf5uthviq2otvmw6f6m
72-
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeic67t7ndzwzekacof7nvk7zgr6dhl6yrqqcashqq3pxjjhhwcilju
73+
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeibyonzs6wyvbcks5bztmc7rmdooynxmlfhiaub2cmuamqbtijv3ou
7374
- valory/market_manager_abci:0.1.0:bafybeig3ak2eoimxwuupybde4napyi2jlf7pxk35se2zclikete2ni5hti
74-
- valory/decision_maker_abci:0.1.0:bafybeib67kekwmnprt44es47lg4oecy6prxqmv6m5k5zqw4hvrskawlifu
75-
- valory/trader_abci:0.1.0:bafybeie2mant7aierij5zcq57iyiizbdpqoj7pkodvt2n5m2mvwrtmewca
75+
- valory/decision_maker_abci:0.1.0:bafybeidel24uozve2ndxmwshhyrzsyv7itcodzqjcfzgqqikr4khpn4eiu
76+
- valory/trader_abci:0.1.0:bafybeiarobiv2d5l6teaslt7s4o36gni3bkwr75nub253mypms56dqzn7y
7677
- valory/staking_abci:0.1.0:bafybeia6csjgex5zxdt6vymiaengu75lyzjdgfrnp65ewlghthiniquhje
77-
- valory/check_stop_trading_abci:0.1.0:bafybeie5ag4baxeqvp4impypnkcxi2wgmoym2udchei45ovqcydauoyyje
78+
- valory/check_stop_trading_abci:0.1.0:bafybeidzz3x3m3cc2z76lqdhwacgrswjgbenc53ljx6ihmra2nnkg2khjm
7879
- valory/mech_interact_abci:0.1.0:bafybeici5tsgtlypnyrnp5colj7katnsyjfdzt6js4xdbnpdms4232muje
79-
- valory/chatui_abci:0.1.0:bafybeiddfs7fy23e7lidopd67fcvwzul5invz5ngkufbrlh757inmm2a5e
80-
- valory/agent_performance_summary_abci:0.1.0:bafybeibdudllr3t7lpxwqtipqjpygk5kg64cohpdd5pafr7vcfjcocow6y
80+
- valory/chatui_abci:0.1.0:bafybeic6isfmqxmwswrgiuwzlyvmivnxkmwfhkgwzoc226753hcij6c3f4
81+
- valory/agent_performance_summary_abci:0.1.0:bafybeicejhpfa6cth6hmz5yxbpbp3awbaxk26sulw6xk3lkzp7ruxov3ni
8182
- valory/funds_manager:0.1.0:bafybeicfw7qjtnlcbw6awsvxdahqu42fxsfsd3wy7mbyhcbls4l5pee3by
8283
customs:
8384
- valory/kelly_criterion:0.1.0:bafybeidme2uybzyzagky3jtosheqmpgc6b6w4rum7cdxw2fc35nnpwblfe
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# -*- coding: utf-8 -*-
2+
# ------------------------------------------------------------------------------
3+
#
4+
# Copyright 2026 Valory AG
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
# ------------------------------------------------------------------------------
19+
20+
"""Trader-local reader for BalanceTracker.Deposit events.
21+
22+
Adds a helper on top of the same ABI as the vendored balance_tracker
23+
contract, kept trader-local so trader's off-chain ROI accounting can read
24+
per-Safe pre-deposit history without modifying the third-party vendored
25+
package.
26+
"""
27+
28+
from aea.configurations.base import PublicId
29+
30+
PUBLIC_ID = PublicId.from_str("valory/mech_prepaid_reader:0.1.0")

0 commit comments

Comments
 (0)