{"record":{"id":"ae037c0241120b59","repo":"affaan-m/ECC","slug":"single-tx-usd-amount-exceeds-max-max-single-t","errorCode":null,"errorMessage":"Single tx ${usd_amount} exceeds max ${MAX_SINGLE_TX_USD}","messagePattern":"Single tx (.+?) exceeds max (.+?)","errorType":"exception","errorClass":"SpendLimitError","httpStatus":null,"severity":"critical","filePath":"skills/llm-trading-agent-security/SKILL.md","lineNumber":63,"sourceCode":"```\n\nDo not blindly inject token names, pair labels, webhooks, or social feeds into an execution-capable prompt.\n\n### Hard spend limits\n\n```python\nfrom decimal import Decimal\n\nMAX_SINGLE_TX_USD = Decimal(\"500\")\nMAX_DAILY_SPEND_USD = Decimal(\"2000\")\n\nclass SpendLimitError(Exception):\n    pass\n\nclass SpendLimitGuard:\n    def check_and_record(self, usd_amount: Decimal) -> None:\n        if usd_amount > MAX_SINGLE_TX_USD:\n            raise SpendLimitError(f\"Single tx ${usd_amount} exceeds max ${MAX_SINGLE_TX_USD}\")\n\n        daily = self._get_24h_spend()\n        if daily + usd_amount > MAX_DAILY_SPEND_USD:\n            raise SpendLimitError(f\"Daily limit: ${daily} + ${usd_amount} > ${MAX_DAILY_SPEND_USD}\")\n\n        self._record_spend(usd_amount)\n```\n\n### Simulate before sending\n\n```python\nclass SlippageError(Exception):\n    pass\n\nasync def safe_execute(self, tx: dict, expected_min_out: int | None = None) -> str:\n    sim_result = await self.w3.eth.call(tx)\n\n    if expected_min_out is None:","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/skills/llm-trading-agent-security/SKILL.md#L45-L81","documentation":"`SpendLimitGuard.check_and_record` enforces a hard per-transaction USD cap (`MAX_SINGLE_TX_USD = Decimal('500')`). If `usd_amount > MAX_SINGLE_TX_USD` it raises `SpendLimitError(f\"Single tx ${usd_amount} exceeds max ${MAX_SINGLE_TX_USD}\")` before consulting the daily counter. Decimals are used (not float) to avoid rounding on money.","triggerScenarios":"The agent constructs a swap/transfer whose USD value exceeds $500 (e.g. a large DEX trade, a bridge deposit). The guard runs before signing and aborts.","commonSituations":"Configured cap is too low for the intended strategy; user changed `MAX_SINGLE_TX_USD` in one place but not the other; price oracle returned a USD value inflated by a stale feed; agent miscalculated notional (decimals of the token).","solutions":["Confirm the cap should be raised — if so, update `MAX_SINGLE_TX_USD` and redeploy, keeping it as `Decimal`.","Verify the USD conversion: oracle price, token decimals, and amount units (base units vs human units).","If the trade is legitimate but large, split it across multiple sub-cap transactions (and let `check_and_record` track each).","Make sure `usd_amount` is a `Decimal`, not `float` — float comparison on money is a defect."],"exampleFix":"# before\nif usd_amount > MAX_SINGLE_TX_USD:\n    raise SpendLimitError(f\"Single tx ${usd_amount} exceeds max ${MAX_SINGLE_TX_USD}\")\n\n# after — assert Decimal, contextual message\nfrom decimal import Decimal, InvalidOperation\nif not isinstance(usd_amount, Decimal):\n    raise TypeError(\"usd_amount must be Decimal\")\nif usd_amount > MAX_SINGLE_TX_USD:\n    raise SpendLimitError(\n        f\"Single tx ${usd_amount} exceeds max ${MAX_SINGLE_TX_USD}; \"\n        f\"split into <=${MAX_SINGLE_TX_USD} chunks\"\n    )","handlingStrategy":"validation","validationCode":"from decimal import Decimal\ndef within_single_cap(usd: Decimal) -> bool:\n    return isinstance(usd, Decimal) and usd <= MAX_SINGLE_TX_USD","typeGuard":"from decimal import Decimal\nimport numbers\ndef is_usd_amount(x) -> bool:\n    return isinstance(x, Decimal) and x > 0","tryCatchPattern":"try:\n    guard.check_and_record(usd_amount)\nexcept SpendLimitError as e:\n    log.warning(\"single-tx cap hit: %s\", e)\n    split_or_abort(usd_amount)","preventionTips":["Always use `Decimal` for money, never `float`.","Keep the cap in one config source used by both the agent and the UI.","Validate token decimals and oracle price before computing the USD notional."],"tags":["web3","trading","spend-limits","security","agents"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}