Metadata-Version: 2.4
Name: sra-riskgate
Version: 0.3.5
Summary: Deterministic pre-filter and risk evaluation gate for stablecoin transactions
Author: Sriram Ramakrishnan
License-Expression: Apache-2.0
Project-URL: Homepage, https://huggingface.co/sriram1983007/SRA-RiskGate-4B
Project-URL: Dataset, https://huggingface.co/datasets/sriram1983007/sra-stablecoin-risk-bench
Keywords: stablecoin,payments,compliance,risk,x402,usdc,agentkit
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Classifier: Topic :: Office/Business :: Financial
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: pydantic>=2.0
Provides-Extra: agentkit
Requires-Dist: coinbase-agentkit<0.8,>=0.7.4; extra == "agentkit"
Requires-Dist: solana<0.37,>=0.36.6; extra == "agentkit"
Provides-Extra: test
Requires-Dist: pytest>=7; extra == "test"
Requires-Dist: eth-abi>=5; extra == "test"

# sra-riskgate

Deterministic pre-filter for stablecoin transactions. It runs fast rule checks
(peg-deviation bounds in both directions, a single-transfer ceiling, and payload
validation) **before** you send a transaction to the
[SRA-RiskGate-4B](https://huggingface.co/sriram1983007/SRA-RiskGate-4B) model.

This package does not run the model and does not perform sanctions screening.

```bash
pip install sra-riskgate
```

```python
from sra_riskgate import RulePreFilter, TransactionPayload

gate = RulePreFilter(max_amount=50_000, depeg_hold_pct=1.0, depeg_reject_pct=5.0)
verdict = gate.inspect(TransactionPayload(
    chain_id=1, token="USDC",
    sender="0x" + "a" * 40, recipient="0x" + "b" * 40,
    amount=5000.0, peg_deviation_pct=-1.5,
))
print(verdict.decision.value, verdict.flags, verdict.required_actions)
# hold ['MODERATE_DEPEG'] ['manual_review']
```

| Rule | Decision |
|---|---|
| Peg deviation NaN / infinite | reject |
| abs(peg deviation) >= `depeg_reject_pct` | reject |
| abs(peg deviation) >= `depeg_hold_pct` | hold |
| amount > `max_amount` | hold |
| otherwise | approve |

## Changelog

**0.3.5**: AgentKit integration rewritten: real `ActionProvider` with `@create_action`; sends USDC as an ERC-20 transfer (0.3.3 sent ETH; 0.3.4 was not accepted by AgentKit); chain read from the wallet; reverted transactions reported as failures; optional `peg_feed`; `solana` pinned so the `[agentkit]` extra imports.

**0.3.1**: Unknown constructor arguments now raise `TypeError` instead of being
silently ignored. Legacy `max_allowed_deviation_pct` maps to the hold threshold
again (as in 0.1.x). Non-finite thresholds are rejected. License and author metadata restored.

**0.3.0**: Depeg checks use `abs()` (catches upward depegs). Thresholds validated.

License: Apache-2.0

## Coinbase AgentKit integration

```bash
pip install "sra-riskgate[agentkit]"
```

```python
from coinbase_agentkit import AgentKit, AgentKitConfig, CdpEvmWalletProvider, CdpEvmWalletProviderConfig
from sra_riskgate.integrations.agentkit import RiskGateActionProvider

wallet = CdpEvmWalletProvider(CdpEvmWalletProviderConfig(network_id="base-sepolia"))
agentkit = AgentKit(AgentKitConfig(
    wallet_provider=wallet,
    # Register ONLY the risk-gated provider for payments. Adding AgentKit's
    # wallet or ERC-20 providers gives the agent ungated transfer actions.
    action_providers=[RiskGateActionProvider(max_amount=1000.0, peg_feed=my_usdc_peg_feed)],
))
```

The agent gets one action, `risk_gated_usdc_transfer`. It sends USDC (ERC-20, never the native token)
on Ethereum, Base, and Base Sepolia, and only after the pre-filter approves. Depeg checks need a
`peg_feed(chain_id) -> deviation %`; without one they're reported as disabled. A reverted
transaction is reported as `FAILED`, never as sent.
