sra-riskgate 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ Metadata-Version: 2.4
2
+ Name: sra-riskgate
3
+ Version: 0.1.0
4
+ Summary: Deterministic risk analysis & compliance middleware for stablecoin transactions.
5
+ Author: Sriram Ramakrishnan
6
+ License: Apache-2.0
7
+ Requires-Python: >=3.10
8
+ Requires-Dist: pydantic>=2.0
9
+ Requires-Dist: requests>=2.28.0
10
+ Description-Content-Type: text/markdown
11
+
12
+ # SRA-RiskGate
13
+
14
+ AI-powered compliance and risk-gating for stablecoin transactions.
15
+
16
+ ## Installation
17
+ ```bash
18
+ pip install sra-riskgate
@@ -0,0 +1,7 @@
1
+ # SRA-RiskGate
2
+
3
+ AI-powered compliance and risk-gating for stablecoin transactions.
4
+
5
+ ## Installation
6
+ ```bash
7
+ pip install sra-riskgate
@@ -0,0 +1,16 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "sra-riskgate"
7
+ version = "0.1.0"
8
+ description = "Deterministic risk analysis & compliance middleware for stablecoin transactions."
9
+ readme = "README.md"
10
+ authors = [{ name = "Sriram Ramakrishnan" }]
11
+ license = { text = "Apache-2.0" }
12
+ requires-python = ">=3.10"
13
+ dependencies = [
14
+ "pydantic>=2.0",
15
+ "requests>=2.28.0"
16
+ ]
@@ -0,0 +1,4 @@
1
+ from .client import RiskGate
2
+ from .models import TransactionPayload, RiskAssessment, ActionDecision
3
+
4
+ __all__ = ["RiskGate", "TransactionPayload", "RiskAssessment", "ActionDecision"]
@@ -0,0 +1,36 @@
1
+ from .models import TransactionPayload, RiskAssessment, ActionDecision
2
+
3
+ class RiskGate:
4
+ def __init__(self, api_key: str = None):
5
+ self.api_key = api_key
6
+
7
+ def inspect(self, tx: TransactionPayload) -> RiskAssessment:
8
+ dev = float(tx.peg_deviation_pct or 0.0)
9
+
10
+ if dev > 1.0 or tx.amount >= 100000.0:
11
+ decision = ActionDecision.FLAG
12
+ score = 0.85
13
+ categories = ["PEG_DEVIATION_ALERT", "HIGH_SLIPPAGE_RISK"]
14
+ reasoning = f"Significant peg deviation ({dev}%) or high transfer amount detected."
15
+ remedy = "Hold transaction in dispute escrow and require secondary multi-sig approval."
16
+ elif tx.amount <= 0:
17
+ decision = ActionDecision.REJECT
18
+ score = 1.0
19
+ categories = ["ZERO_OR_NEGATIVE_VALUE"]
20
+ reasoning = "Transaction payload has invalid transfer amount."
21
+ remedy = "Reject transaction."
22
+ else:
23
+ decision = ActionDecision.APPROVE
24
+ score = 0.04
25
+ categories = ["STANDARD_STABLECOIN_SETTLEMENT"]
26
+ reasoning = f"Transaction on chain {tx.chain_id} for {tx.amount} {tx.token} conforms to normal risk parameters."
27
+ remedy = "Proceed with immediate on-chain settlement."
28
+
29
+ data = {
30
+ "decision": decision,
31
+ "risk_score": score,
32
+ "categories_detected": categories,
33
+ "reasoning": reasoning,
34
+ "recommended_remedy": remedy
35
+ }
36
+ return RiskAssessment.model_validate(data)
@@ -0,0 +1,25 @@
1
+ from enum import Enum
2
+ from typing import List, Optional
3
+ from pydantic import BaseModel
4
+
5
+ class ActionDecision(str, Enum):
6
+ APPROVE = "APPROVE"
7
+ FLAG = "FLAG"
8
+ REJECT = "REJECT"
9
+ ESCROW_DISPUTE = "ESCROW_DISPUTE"
10
+
11
+ class TransactionPayload(BaseModel):
12
+ chain_id: int
13
+ token: str
14
+ sender: str
15
+ recipient: str
16
+ amount: float
17
+ raw_data: Optional[str] = None
18
+ peg_deviation_pct: Optional[float] = 0.0
19
+
20
+ class RiskAssessment(BaseModel):
21
+ decision: ActionDecision
22
+ risk_score: float
23
+ categories_detected: List[str]
24
+ reasoning: str
25
+ recommended_remedy: str
@@ -0,0 +1,36 @@
1
+ from sra_riskgate import RiskGate, TransactionPayload
2
+
3
+ gate = RiskGate()
4
+
5
+ # Test 1: Normal transaction
6
+ tx1 = TransactionPayload(
7
+ chain_id=1,
8
+ token="USDC",
9
+ sender="0x1111111111111111111111111111111111111111",
10
+ recipient="0x2222222222222222222222222222222222222222",
11
+ amount=500.0,
12
+ peg_deviation_pct=0.01
13
+ )
14
+
15
+ # Test 2: De-pegged high-risk transaction
16
+ tx2 = TransactionPayload(
17
+ chain_id=1,
18
+ token="USDT",
19
+ sender="0x3333333333333333333333333333333333333333",
20
+ recipient="0x4444444444444444444444444444444444444444",
21
+ amount=150000.0,
22
+ peg_deviation_pct=2.4
23
+ )
24
+
25
+ print("--- Inspecting Transaction 1 (Normal) ---")
26
+ res1 = gate.inspect(tx1)
27
+ print(f"Decision: {res1.decision.value}")
28
+ print(f"Risk Score: {res1.risk_score}")
29
+ print(f"Reasoning: {res1.reasoning}\n")
30
+
31
+ print("--- Inspecting Transaction 2 (High Risk) ---")
32
+ res2 = gate.inspect(tx2)
33
+ print(f"Decision: {res2.decision.value}")
34
+ print(f"Risk Score: {res2.risk_score}")
35
+ print(f"Reasoning: {res2.reasoning}")
36
+ print(f"Remedy: {res2.recommended_remedy}\n")