Validate that the virtual token ledger is compatible with on-chain migration. When SciDEX
moves to blockchain, every ledger entry should map to an on-chain transaction without
data loss. This task prepares the migration path without implementing blockchain yet.
from_account → sender address (deterministic from agent_id)to_account → receiver addressamount → transfer value (18-decimal fixed-point)reason → event log topicreference_type + reference_id → event log datatimestamp → block timestampid → transaction hash (computed from content)
agent_id_to_address(agent_id) → deterministic hex addressexport_ledger_for_chain(since=None) → JSON array of chain-compatible txnsimport_chain_state(chain_state) → sync ledger from on-chain dataEvaluate compatibility with:
exch-cm-01-LEDG — Ledger must be operational to auditAdded to scidex/exchange/token_ledger.py:
1. agent_id_to_address(agent_id, chain="ethereum") (line ~540)
export_ledger_for_chain(since=None, chain="ethereum") (line ~566)
import_chain_state(chain_state, source_chain="ethereum", dry_run=True) (line ~640)
ledger_chain_compatibility_report() (line ~750)
test_export_import_roundtrip() (line ~880)
token_ledger.id → event.topic[0] (keccak256 of entry content, stored as tx_hash)
token_ledger.timestamp → block.timestamp (ISO → epoch conversion on-chain)
token_ledger.from_account → msg.sender (via agent_id_to_address(from_account))
token_ledger.to_account → to address (via agent_id_to_address(to_account))
token_ledger.amount → msg.value (float × 1e18 = wei)
token_ledger.reason → event.topic[1] (keccak256(reason_string))
token_ledger.reference_type → event.data[0] (indexed metadata)
token_ledger.reference_id → event.data[1] (indexed metadata)
token_ledger.memo → event.data[2] (non-indexed data)
token_ledger.balance_after_* → off-chain audit only (not stored on-chain)REAL (float); on-chain must use 18-decimal wei via int(amount * 1e18)system account maps to burn/minter role; consider multisig for this critical roleagent_id_to_address() must use same chain param on export and importimport_chain_state() checks tx_hash before inserting — prevents replay# Export
txns = export_ledger_for_chain(since="2026-01-01T00:00:00", chain="base")
# 32,112 entries exported as chain-compatible JSON
# Import (dry run first)
result = import_chain_state(txns, source_chain="base", dry_run=True)
print(result) # shows what would be imported without committing
# Apply
result = import_chain_state(txns, source_chain="base", dry_run=False)
print(result) # 0 transactions_imported (already present), 0 duplicateswallet_manager.py already handles real keypairs via create_agent_wallet()export_ledger_for_chain() → deploy contracts → import_chain_state()token_ledger writes to also emit on-chain events; reads from on-chain{
"requirements": {
"coding": 8,
"safety": 9
}
}