safehands-pharos 1.0.0
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.
- package/.agents/skill/safehands/SKILL.md +169 -0
- package/LICENSE +21 -0
- package/README.md +382 -0
- package/contracts/RiskRegistry.json +149 -0
- package/contracts/RiskRegistry.sol +30 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +98 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/constants.d.ts +173 -0
- package/dist/lib/constants.d.ts.map +1 -0
- package/dist/lib/constants.js +151 -0
- package/dist/lib/constants.js.map +1 -0
- package/dist/lib/dodoApi.d.ts +57 -0
- package/dist/lib/dodoApi.d.ts.map +1 -0
- package/dist/lib/dodoApi.js +123 -0
- package/dist/lib/dodoApi.js.map +1 -0
- package/dist/lib/pharosClient.d.ts +58 -0
- package/dist/lib/pharosClient.d.ts.map +1 -0
- package/dist/lib/pharosClient.js +51 -0
- package/dist/lib/pharosClient.js.map +1 -0
- package/dist/lib/riskEngine.d.ts +27 -0
- package/dist/lib/riskEngine.d.ts.map +1 -0
- package/dist/lib/riskEngine.js +284 -0
- package/dist/lib/riskEngine.js.map +1 -0
- package/dist/lib/testRpc.d.ts +2 -0
- package/dist/lib/testRpc.d.ts.map +1 -0
- package/dist/lib/testRpc.js +30 -0
- package/dist/lib/testRpc.js.map +1 -0
- package/dist/lib/testTools.d.ts +2 -0
- package/dist/lib/testTools.d.ts.map +1 -0
- package/dist/lib/testTools.js +263 -0
- package/dist/lib/testTools.js.map +1 -0
- package/dist/scripts/checkDeploy.d.ts +2 -0
- package/dist/scripts/checkDeploy.d.ts.map +1 -0
- package/dist/scripts/checkDeploy.js +25 -0
- package/dist/scripts/checkDeploy.js.map +1 -0
- package/dist/scripts/deployRegistry.d.ts +2 -0
- package/dist/scripts/deployRegistry.d.ts.map +1 -0
- package/dist/scripts/deployRegistry.js +101 -0
- package/dist/scripts/deployRegistry.js.map +1 -0
- package/dist/scripts/testRegistry.d.ts +2 -0
- package/dist/scripts/testRegistry.d.ts.map +1 -0
- package/dist/scripts/testRegistry.js +44 -0
- package/dist/scripts/testRegistry.js.map +1 -0
- package/dist/tools/approveToken.d.ts +60 -0
- package/dist/tools/approveToken.d.ts.map +1 -0
- package/dist/tools/approveToken.js +59 -0
- package/dist/tools/approveToken.js.map +1 -0
- package/dist/tools/assessRisk.d.ts +67 -0
- package/dist/tools/assessRisk.d.ts.map +1 -0
- package/dist/tools/assessRisk.js +71 -0
- package/dist/tools/assessRisk.js.map +1 -0
- package/dist/tools/checkAllowance.d.ts +37 -0
- package/dist/tools/checkAllowance.d.ts.map +1 -0
- package/dist/tools/checkAllowance.js +43 -0
- package/dist/tools/checkAllowance.js.map +1 -0
- package/dist/tools/estimateGas.d.ts +70 -0
- package/dist/tools/estimateGas.d.ts.map +1 -0
- package/dist/tools/estimateGas.js +129 -0
- package/dist/tools/estimateGas.js.map +1 -0
- package/dist/tools/executeSwap.d.ts +94 -0
- package/dist/tools/executeSwap.d.ts.map +1 -0
- package/dist/tools/executeSwap.js +107 -0
- package/dist/tools/executeSwap.js.map +1 -0
- package/dist/tools/getExecutionHistory.d.ts +52 -0
- package/dist/tools/getExecutionHistory.d.ts.map +1 -0
- package/dist/tools/getExecutionHistory.js +94 -0
- package/dist/tools/getExecutionHistory.js.map +1 -0
- package/dist/tools/getGasPrice.d.ts +26 -0
- package/dist/tools/getGasPrice.d.ts.map +1 -0
- package/dist/tools/getGasPrice.js +52 -0
- package/dist/tools/getGasPrice.js.map +1 -0
- package/dist/tools/getPoolInfo.d.ts +88 -0
- package/dist/tools/getPoolInfo.d.ts.map +1 -0
- package/dist/tools/getPoolInfo.js +99 -0
- package/dist/tools/getPoolInfo.js.map +1 -0
- package/dist/tools/getTokenPrice.d.ts +28 -0
- package/dist/tools/getTokenPrice.d.ts.map +1 -0
- package/dist/tools/getTokenPrice.js +79 -0
- package/dist/tools/getTokenPrice.js.map +1 -0
- package/dist/tools/getTransactionStatus.d.ts +58 -0
- package/dist/tools/getTransactionStatus.d.ts.map +1 -0
- package/dist/tools/getTransactionStatus.js +68 -0
- package/dist/tools/getTransactionStatus.js.map +1 -0
- package/dist/tools/getWalletBalance.d.ts +40 -0
- package/dist/tools/getWalletBalance.d.ts.map +1 -0
- package/dist/tools/getWalletBalance.js +71 -0
- package/dist/tools/getWalletBalance.js.map +1 -0
- package/dist/tools/publishRiskScore.d.ts +74 -0
- package/dist/tools/publishRiskScore.d.ts.map +1 -0
- package/dist/tools/publishRiskScore.js +70 -0
- package/dist/tools/publishRiskScore.js.map +1 -0
- package/dist/tools/queryRiskRegistry.d.ts +49 -0
- package/dist/tools/queryRiskRegistry.d.ts.map +1 -0
- package/dist/tools/queryRiskRegistry.js +61 -0
- package/dist/tools/queryRiskRegistry.js.map +1 -0
- package/dist/tools/sendPayment.d.ts +70 -0
- package/dist/tools/sendPayment.d.ts.map +1 -0
- package/dist/tools/sendPayment.js +68 -0
- package/dist/tools/sendPayment.js.map +1 -0
- package/dist/tools/simulateTransaction.d.ts +82 -0
- package/dist/tools/simulateTransaction.d.ts.map +1 -0
- package/dist/tools/simulateTransaction.js +89 -0
- package/dist/tools/simulateTransaction.js.map +1 -0
- package/package.json +61 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: safehands
|
|
3
|
+
version: 1.0.0
|
|
4
|
+
description: Risk intelligence middleware for Pharos agents. 15 production tools that assess, simulate, and gate every on-chain action β swaps, payments, approvals β with a 5-dimension risk engine and an on-chain RiskRegistry for cross-agent score sharing.
|
|
5
|
+
author: "SZtch"
|
|
6
|
+
chain: pharos
|
|
7
|
+
tags: [execution, safety, defi, swap, payment, risk, registry, middleware, composable]
|
|
8
|
+
categories: [safety, execution, defi, intelligence]
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# SafeHands
|
|
12
|
+
|
|
13
|
+
> *"Agents that execute without thinking are dangerous. SafeHands executes anything on Pharos β but never blindly."*
|
|
14
|
+
|
|
15
|
+
SafeHands is **risk intelligence middleware** for the Pharos AI Agent economy. It sits between agent intent and on-chain execution, providing a 15-tool safety layer that any agent can compose into their workflow. Every swap, transfer, and approval flows through a 5-dimension risk assessment before touching the chain.
|
|
16
|
+
|
|
17
|
+
SafeHands is not an agent β it's a **foundational primitive** that agents depend on.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Tools (15)
|
|
22
|
+
|
|
23
|
+
### Core Safety β Assess before you execute
|
|
24
|
+
|
|
25
|
+
| Tool | Description |
|
|
26
|
+
|------|-------------|
|
|
27
|
+
| `assess_risk` | 5-dimension risk score (0β100) for any swap or transfer. Auto-publishes to on-chain RiskRegistry when privateKey is provided. |
|
|
28
|
+
| `simulate_transaction` | Dry run via eth_call β zero gas. Returns expected output, gas estimate, and revert reasons before committing. |
|
|
29
|
+
| `estimate_gas` | Pre-execution gas cost in PHRS and USD. Checks whether the wallet has sufficient funds for gas + value. |
|
|
30
|
+
|
|
31
|
+
### Execution β Act with guardrails
|
|
32
|
+
|
|
33
|
+
| Tool | Description |
|
|
34
|
+
|------|-------------|
|
|
35
|
+
| `execute_swap` | Swap tokens via FaroSwap (DODO) with built-in risk gate. Automatically blocks if risk score exceeds 80. |
|
|
36
|
+
| `send_payment` | Native PHRS transfer with pre-flight address validation, balance checks, and high-exposure warnings. |
|
|
37
|
+
| `approve_token` | ERC-20 approval for DODO router. Supports exact amounts or unlimited ("max") approval. |
|
|
38
|
+
|
|
39
|
+
### Market Intelligence β Know before you trade
|
|
40
|
+
|
|
41
|
+
| Tool | Description |
|
|
42
|
+
|------|-------------|
|
|
43
|
+
| `get_token_price` | Real-time PHRS, USDC, USDT prices derived from DODO liquidity quotes on Pharos. |
|
|
44
|
+
| `get_pool_info` | DODO pool data for any token pair β price ratio, price impact, and fees. |
|
|
45
|
+
| `get_gas_price` | Current Pharos gas price with trend classification (low/normal/high) and cost estimates. |
|
|
46
|
+
|
|
47
|
+
### Wallet & History β Observe the full picture
|
|
48
|
+
|
|
49
|
+
| Tool | Description |
|
|
50
|
+
|------|-------------|
|
|
51
|
+
| `get_wallet_balance` | PHRS, USDC, USDT balances for any wallet with total USD estimate. |
|
|
52
|
+
| `check_allowance` | Check ERC-20 allowance granted to DODO router. Reports whether approval is needed before a swap. |
|
|
53
|
+
| `get_transaction_status` | Look up any transaction by hash β status, block number, gas used, explorer link. |
|
|
54
|
+
| `get_execution_history` | On-chain audit trail for any wallet. Categorizes activity as swaps, transfers, or other. |
|
|
55
|
+
|
|
56
|
+
### On-Chain Risk Registry β Share risk intelligence across agents
|
|
57
|
+
|
|
58
|
+
| Tool | Description |
|
|
59
|
+
|------|-------------|
|
|
60
|
+
| `publish_risk_score` | Run risk assessment and publish the result to the on-chain RiskRegistry smart contract. |
|
|
61
|
+
| `query_risk_registry` | Read any wallet's published risk score from the registry. Read-only β no private key needed. |
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## Composability
|
|
66
|
+
|
|
67
|
+
SafeHands is designed as a **building block**, not a standalone application. Other skills and agents compose SafeHands into their workflows by calling its tools as middleware.
|
|
68
|
+
|
|
69
|
+
### Read-only tools (safe for any agent, no key needed)
|
|
70
|
+
`simulate_transaction` Β· `estimate_gas` Β· `get_token_price` Β· `get_pool_info` Β· `get_gas_price` Β· `get_wallet_balance` Β· `check_allowance` Β· `get_transaction_status` Β· `get_execution_history` Β· `query_risk_registry`
|
|
71
|
+
|
|
72
|
+
### Read+Write tool (read without key, auto-publishes with key)
|
|
73
|
+
`assess_risk` β returns risk score without a key; if `privateKey` is provided, also publishes the result to the on-chain RiskRegistry.
|
|
74
|
+
|
|
75
|
+
### Write tools (require privateKey per-request)
|
|
76
|
+
`execute_swap` Β· `send_payment` Β· `approve_token` Β· `publish_risk_score`
|
|
77
|
+
|
|
78
|
+
### How Phase 2 agents compose with SafeHands
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
82
|
+
β Phase 2 Agent (DeFi bot, payment agent, etc.) β
|
|
83
|
+
β β
|
|
84
|
+
β 1. Call assess_risk β get risk score β
|
|
85
|
+
β 2. Call simulate_transaction β dry run β
|
|
86
|
+
β 3. If safe β call execute_swap or send_payment β
|
|
87
|
+
β 4. Call get_transaction_status β confirm result β
|
|
88
|
+
β 5. Call query_risk_registry β check counterparty β
|
|
89
|
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Any agent that performs on-chain actions on Pharos can import SafeHands as its safety layer. The agent handles user intent and strategy; SafeHands handles risk gating and execution.
|
|
93
|
+
|
|
94
|
+
### Cross-agent risk intelligence
|
|
95
|
+
|
|
96
|
+
The RiskRegistry contract (`0x71fc28ed3a31016b42f18764889cd911f22b67b8`) enables agents to share risk assessments:
|
|
97
|
+
|
|
98
|
+
- **Agent A** publishes a risk score for a wallet via `publish_risk_score`
|
|
99
|
+
- **Agent B** queries that score via `query_risk_registry` before interacting with the same wallet
|
|
100
|
+
- No API keys, no centralized service β purely on-chain, permissionless
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## Usage Examples
|
|
105
|
+
|
|
106
|
+
**Example 1 β Pre-trade safety check:**
|
|
107
|
+
```
|
|
108
|
+
User: "Swap 100 PHRS to USDC"
|
|
109
|
+
Agent: β assess_risk(swap, PHRS, USDC, 100, wallet)
|
|
110
|
+
β Score 12/100, low risk, proceed
|
|
111
|
+
β simulate_transaction(swap, PHRS, USDC, 100)
|
|
112
|
+
β Would succeed, ~166 USDC out
|
|
113
|
+
β execute_swap(PHRS, USDC, 100, wallet, privateKey)
|
|
114
|
+
β β
TX confirmed
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
**Example 2 β Risk-gated payment:**
|
|
118
|
+
```
|
|
119
|
+
User: "Send 500 PHRS to 0xabc..."
|
|
120
|
+
Agent: β assess_risk(transfer, 500, toAddress=0xabc)
|
|
121
|
+
β Score 85/100, critical, BLOCKED
|
|
122
|
+
β "This transfer uses 95% of your wallet. Reduce amount or confirm override."
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
**Example 3 β Portfolio check before action:**
|
|
126
|
+
```
|
|
127
|
+
User: "What's in my wallet?"
|
|
128
|
+
Agent: β get_wallet_balance(wallet) β PHRS=19.4, USDC=0.85, USDT=0
|
|
129
|
+
β get_token_price(PHRS) β $1.66
|
|
130
|
+
β "Your portfolio: $32.21 USD across 3 tokens"
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
**Example 4 β Cross-agent reputation lookup:**
|
|
134
|
+
```
|
|
135
|
+
Agent B: β query_risk_registry(0xsuspicious...)
|
|
136
|
+
β Score 92, critical, block
|
|
137
|
+
β "This wallet was flagged high-risk by another agent. Refusing to interact."
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## Safety Model
|
|
143
|
+
|
|
144
|
+
1. **Risk-first execution** β every write tool (`execute_swap`, `send_payment`) internally calls `assess_risk` before proceeding.
|
|
145
|
+
2. **Automatic blocking** β actions scoring above 80 are prevented. No override without explicit `bypassRiskCheck`.
|
|
146
|
+
3. **Transient keys** β private keys are passed per-request and never stored, logged, or persisted.
|
|
147
|
+
4. **Simulation before commitment** β `simulate_transaction` lets agents verify outcomes at zero cost before committing gas.
|
|
148
|
+
5. **On-chain audit** β all risk scores can be published to the RiskRegistry, creating a permanent, verifiable record.
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## On-Chain Registry
|
|
153
|
+
|
|
154
|
+
**Contract:** `0x71fc28ed3a31016b42f18764889cd911f22b67b8`
|
|
155
|
+
**Chain:** Pharos Atlantic Testnet (688689)
|
|
156
|
+
|
|
157
|
+
The RiskRegistry is a Solidity smart contract deployed on Pharos that stores risk assessments on-chain. Any agent can publish. Any agent can query. No API keys, no centralized infrastructure.
|
|
158
|
+
|
|
159
|
+
When `assess_risk` is called with a `privateKey`, the result is automatically published β making every risk assessment a permanent, queryable on-chain record that other agents can trust.
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
## Supported Tokens
|
|
164
|
+
|
|
165
|
+
PHRS (native), USDC, USDT on Pharos Atlantic Testnet.
|
|
166
|
+
|
|
167
|
+
## Chain
|
|
168
|
+
|
|
169
|
+
Pharos Atlantic Testnet β Chain ID 688689 β RPC: `https://atlantic.dplabs-internal.com/`
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SZtch
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://img.shields.io/badge/TypeScript-3178C6?style=for-the-badge&logo=typescript&logoColor=white" />
|
|
3
|
+
<img src="https://img.shields.io/badge/MCP_Skill-000000?style=for-the-badge&logo=anthropic&logoColor=white" />
|
|
4
|
+
<img src="https://img.shields.io/badge/Pharos_Atlantic-688689-blueviolet?style=for-the-badge" />
|
|
5
|
+
<img src="https://img.shields.io/badge/Tools-15-orange?style=for-the-badge" />
|
|
6
|
+
<img src="https://img.shields.io/badge/License-MIT-green?style=for-the-badge" />
|
|
7
|
+
<img src="https://img.shields.io/badge/CertiK-Scanned-00C9A7?style=for-the-badge" />
|
|
8
|
+
</p>
|
|
9
|
+
|
|
10
|
+
<h1 align="center">π‘οΈ SafeHands</h1>
|
|
11
|
+
|
|
12
|
+
<p align="center">
|
|
13
|
+
<strong>The execution safety layer for Pharos agents.</strong><br/>
|
|
14
|
+
<em>"Agents that execute without thinking are dangerous. SafeHands executes anything on Pharos β but never blindly."</em>
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
<p align="center">
|
|
18
|
+
<a href="#-the-problem">Problem</a> β’
|
|
19
|
+
<a href="#-the-solution">Solution</a> β’
|
|
20
|
+
<a href="#-tools-15">Tools</a> β’
|
|
21
|
+
<a href="#-agent-integration">Agent Integration</a> β’
|
|
22
|
+
<a href="#-composability">Composability</a> β’
|
|
23
|
+
<a href="#-quick-start">Quick Start</a> β’
|
|
24
|
+
<a href="#%EF%B8%8F-on-chain-risk-registry">Registry</a> β’
|
|
25
|
+
<a href="#-live-transaction-proof">Proof</a>
|
|
26
|
+
</p>
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## β The Problem
|
|
31
|
+
|
|
32
|
+
AI agents on Pharos move **real value**. Swaps, payments, approvals β all executed autonomously, with real tokens at stake.
|
|
33
|
+
|
|
34
|
+
Most agent execution skills today just execute. They don't assess. They don't simulate. They don't protect.
|
|
35
|
+
|
|
36
|
+
| Risk | What goes wrong |
|
|
37
|
+
|------|----------------|
|
|
38
|
+
| **Slippage attacks** | Agent swaps at a terrible price β thin liquidity, high impact, value lost |
|
|
39
|
+
| **Blind transfers** | Agent sends to a wrong, empty, or flagged address β funds gone |
|
|
40
|
+
| **Failed transactions** | Agent wastes gas on transactions destined to revert β no pre-check |
|
|
41
|
+
| **No cross-agent trust** | Agent B interacts with a wallet that Agent A already flagged as dangerous |
|
|
42
|
+
|
|
43
|
+
When agents control real wallets in the Pharos AI economy, **"just execute" is not a strategy**.
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## β
The Solution
|
|
48
|
+
|
|
49
|
+
SafeHands is an **MCP Skill** β a 15-tool risk intelligence middleware layer. It sits between agent intent and on-chain execution, scoring risk, simulating outcomes, and gating dangerous operations automatically.
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
53
|
+
β Agent Intent β
|
|
54
|
+
β "Swap 100 PHRS to USDC" β
|
|
55
|
+
ββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββ
|
|
56
|
+
β
|
|
57
|
+
βΌ
|
|
58
|
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
59
|
+
β π‘οΈ SafeHands Layer β
|
|
60
|
+
β β
|
|
61
|
+
β 1. assess_risk β Score 12/100, proceed β
|
|
62
|
+
β 2. simulate_transaction β Would succeed, 166 USDC β
|
|
63
|
+
β 3. estimate_gas β 0.004 PHRS, sufficient β
|
|
64
|
+
β 4. execute_swap β β
TX confirmed β
|
|
65
|
+
β β
|
|
66
|
+
β Score > 80? β π« BLOCKED automatically β
|
|
67
|
+
β Score < 80? β β
PROCEED with full transparency β
|
|
68
|
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
69
|
+
β
|
|
70
|
+
βΌ
|
|
71
|
+
Pharos Atlantic
|
|
72
|
+
(on-chain)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
SafeHands is not an agent β it's the safety layer other agents depend on.
|
|
76
|
+
|
|
77
|
+
### Risk Engine β 5 Dimensions
|
|
78
|
+
|
|
79
|
+
| Dimension | Weight | What it checks |
|
|
80
|
+
|-----------|--------|----------------|
|
|
81
|
+
| Liquidity Risk | 25% | DODO route available? Price impact? |
|
|
82
|
+
| Slippage Risk | 25% | Estimated slippage from DODO quote |
|
|
83
|
+
| Counterparty Risk | 20% | Address valid? Zero address? Self-send? |
|
|
84
|
+
| Balance Risk | 15% | Sufficient balance + gas buffer? |
|
|
85
|
+
| Market Condition Risk | 15% | Block times, gas price, chain health |
|
|
86
|
+
|
|
87
|
+
**Thresholds:**
|
|
88
|
+
- `0β30` β β
**proceed**
|
|
89
|
+
- `31β60` β β οΈ **caution** β review recommended
|
|
90
|
+
- `61β80` β π **high** β agent warned
|
|
91
|
+
- `81β100` β π« **block** β execution prevented
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## π§ Tools (15)
|
|
96
|
+
|
|
97
|
+
All tools hit live Pharos RPC and the DODO Route API. Zero mocks, zero stubs.
|
|
98
|
+
|
|
99
|
+
### Core Safety β Assess before you execute
|
|
100
|
+
|
|
101
|
+
| # | Tool | Type | Description |
|
|
102
|
+
|---|------|------|-------------|
|
|
103
|
+
| 1 | `assess_risk` | Read+Write | 5-dimension risk score (0β100). Auto-publishes to on-chain RiskRegistry when `privateKey` provided. |
|
|
104
|
+
| 2 | `simulate_transaction` | Read | Dry run via `eth_call` β zero gas. Returns expected output, gas estimate, revert reasons. |
|
|
105
|
+
| 3 | `estimate_gas` | Read | Gas cost in PHRS and USD. Checks wallet sufficiency before execution. |
|
|
106
|
+
|
|
107
|
+
### Execution β Act with guardrails
|
|
108
|
+
|
|
109
|
+
| # | Tool | Type | Description |
|
|
110
|
+
|---|------|------|-------------|
|
|
111
|
+
| 4 | `execute_swap` | Write | Swap via FaroSwap (DODO) with built-in risk gate. Blocks if score > 80. |
|
|
112
|
+
| 5 | `send_payment` | Write | Native PHRS transfer with address validation, balance checks, exposure warnings. |
|
|
113
|
+
| 6 | `approve_token` | Write | ERC-20 approval for DODO router. Supports exact amount or `"max"`. |
|
|
114
|
+
|
|
115
|
+
### Market Intelligence β Know before you trade
|
|
116
|
+
|
|
117
|
+
| # | Tool | Type | Description |
|
|
118
|
+
|---|------|------|-------------|
|
|
119
|
+
| 7 | `get_token_price` | Read | Real-time PHRS/USDC/USDT price from DODO liquidity quotes. |
|
|
120
|
+
| 8 | `get_pool_info` | Read | DODO pool data for any token pair β price ratio, impact, fees. |
|
|
121
|
+
| 9 | `get_gas_price` | Read | Current gas price with trend classification and cost estimates. |
|
|
122
|
+
|
|
123
|
+
### Wallet & History β Observe the full picture
|
|
124
|
+
|
|
125
|
+
| # | Tool | Type | Description |
|
|
126
|
+
|---|------|------|-------------|
|
|
127
|
+
| 10 | `get_wallet_balance` | Read | PHRS, USDC, USDT balances with total USD estimate. |
|
|
128
|
+
| 11 | `check_allowance` | Read | ERC-20 allowance for DODO router. Reports if approval needed. |
|
|
129
|
+
| 12 | `get_transaction_status` | Read | TX lookup by hash β status, block, gas, explorer link. |
|
|
130
|
+
| 13 | `get_execution_history` | Read | On-chain audit trail. Categorizes swaps, transfers, other. |
|
|
131
|
+
|
|
132
|
+
### On-Chain Risk Registry β Share risk across agents
|
|
133
|
+
|
|
134
|
+
| # | Tool | Type | Description |
|
|
135
|
+
|---|------|------|-------------|
|
|
136
|
+
| 14 | `publish_risk_score` | Write | Assess + publish to on-chain RiskRegistry. Other agents can query. |
|
|
137
|
+
| 15 | `query_risk_registry` | Read | Read any wallet's risk score from registry. No key needed. |
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## π Agent Integration
|
|
142
|
+
|
|
143
|
+
SafeHands is safety middleware β other agents plug it into their execution pipeline instead of building their own risk logic.
|
|
144
|
+
|
|
145
|
+
### Example: DeFi Trading Agent
|
|
146
|
+
|
|
147
|
+
A Phase 2 trading agent delegates all risk and execution to SafeHands:
|
|
148
|
+
|
|
149
|
+
```
|
|
150
|
+
Agent receives: "Buy USDC with 50 PHRS"
|
|
151
|
+
|
|
152
|
+
Step 1: get_wallet_balance(wallet) β check funds
|
|
153
|
+
Step 2: get_token_price(PHRS) β current market price
|
|
154
|
+
Step 3: assess_risk(swap, PHRS, USDC, 50) β risk score 5, proceed
|
|
155
|
+
Step 4: simulate_transaction(swap, 50) β would succeed, ~83 USDC out
|
|
156
|
+
Step 5: estimate_gas(swap, PHRS, USDC, 50) β 0.004 PHRS, sufficient
|
|
157
|
+
Step 6: execute_swap(PHRS, USDC, 50, key) β β
TX confirmed
|
|
158
|
+
Step 7: get_transaction_status(txHash) β success, block 23961005
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
The trading agent handles strategy. SafeHands handles risk scoring, simulation, gas checks, and execution.
|
|
162
|
+
|
|
163
|
+
### Example: Risk Auditor Agent
|
|
164
|
+
|
|
165
|
+
```
|
|
166
|
+
Agent receives: "Is this wallet safe to interact with?"
|
|
167
|
+
|
|
168
|
+
Step 1: query_risk_registry(0xsuspicious) β score 87, critical, block
|
|
169
|
+
Step 2: get_execution_history(0xsuspicious) β 2 failed swaps, 1 large transfer
|
|
170
|
+
Response: "This wallet has a risk score of 87/100. Not recommended."
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## π§© Composability
|
|
176
|
+
|
|
177
|
+
SafeHands is a building block, not a standalone app.
|
|
178
|
+
|
|
179
|
+
### Read vs Write Tools
|
|
180
|
+
|
|
181
|
+
| Access Level | Tools | Who can call |
|
|
182
|
+
|---|---|---|
|
|
183
|
+
| **Read-only** (10 tools) | `simulate_transaction`, `estimate_gas`, `get_token_price`, `get_pool_info`, `get_gas_price`, `get_wallet_balance`, `check_allowance`, `get_transaction_status`, `get_execution_history`, `query_risk_registry` | Any agent, no wallet needed |
|
|
184
|
+
| **Read+Write** (1 tool) | `assess_risk` | Scores risk without a key; auto-publishes to RiskRegistry with key |
|
|
185
|
+
| **Write** (4 tools) | `execute_swap`, `send_payment`, `approve_token`, `publish_risk_score` | Agents with privateKey |
|
|
186
|
+
|
|
187
|
+
10 of 15 tools need **no wallet at all** β any agent can use SafeHands for risk intelligence without holding keys. `assess_risk` works without a key too, but upgrades to a write operation when one is provided.
|
|
188
|
+
|
|
189
|
+
### Cross-Agent Risk Intelligence
|
|
190
|
+
|
|
191
|
+
The RiskRegistry contract turns risk scores into shared, on-chain data:
|
|
192
|
+
|
|
193
|
+
```
|
|
194
|
+
Agent A assesses wallet X β publish_risk_score β On-Chain Registry
|
|
195
|
+
β
|
|
196
|
+
Agent B wants to trade β query_risk_registry ββββββββ
|
|
197
|
+
with wallet X "Score 87, block"
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
- **Permissionless writes** β any agent can publish assessments
|
|
201
|
+
- **Permissionless reads** β any agent can query scores
|
|
202
|
+
- **No centralized API** β data lives on Pharos chain
|
|
203
|
+
- **Timestamped** β agents see when scores were last updated
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
## π Quick Start
|
|
208
|
+
|
|
209
|
+
> Built and tested on Pharos Atlantic Testnet. All tools execute against live RPC β no mocks, no stubs.
|
|
210
|
+
|
|
211
|
+
### 1. Clone & Install
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
git clone https://github.com/SZtch/safehands-pharos.git
|
|
215
|
+
cd safehands-pharos
|
|
216
|
+
npm install
|
|
217
|
+
npm run build
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### 2. Configure Environment
|
|
221
|
+
|
|
222
|
+
Create `.env` with your Pharos Atlantic Testnet wallet:
|
|
223
|
+
|
|
224
|
+
```env
|
|
225
|
+
PRIVATE_KEY=0xYOUR_PRIVATE_KEY_HERE
|
|
226
|
+
WALLET_ADDRESS=0xYOUR_WALLET_ADDRESS_HERE
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
> β οΈ Private keys are **never stored** by SafeHands β passed per-request only, never logged.
|
|
230
|
+
|
|
231
|
+
### 3. Verify RPC Connection
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
npx tsx src/lib/testRpc.ts
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
```
|
|
238
|
+
π Connecting to Pharos Atlantic Testnet...
|
|
239
|
+
Chain ID returned: 688689
|
|
240
|
+
β
SUCCESS β Chain ID matches expected 688689
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
### 4. Run All 15 Tool Tests
|
|
244
|
+
|
|
245
|
+
```bash
|
|
246
|
+
npx tsx src/lib/testTools.ts
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### 5. Connect to Claude Desktop
|
|
250
|
+
|
|
251
|
+
Add to `claude_desktop_config.json`:
|
|
252
|
+
|
|
253
|
+
```json
|
|
254
|
+
{
|
|
255
|
+
"mcpServers": {
|
|
256
|
+
"safehands": {
|
|
257
|
+
"command": "node",
|
|
258
|
+
"args": ["/absolute/path/to/safehands/dist/index.js"]
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
---
|
|
265
|
+
|
|
266
|
+
## βοΈ On-Chain Risk Registry
|
|
267
|
+
|
|
268
|
+
SafeHands ships a deployed **RiskRegistry** smart contract β the first on-chain risk reputation layer for Pharos agents.
|
|
269
|
+
|
|
270
|
+
| Field | Value |
|
|
271
|
+
|-------|-------|
|
|
272
|
+
| **Contract** | [`0x71fc28ed3a31016b42f18764889cd911f22b67b8`](https://atlantic.pharosscan.xyz/address/0x71fc28ed3a31016b42f18764889cd911f22b67b8) |
|
|
273
|
+
| **Chain** | Pharos Atlantic Testnet (688689) |
|
|
274
|
+
| **Deploy TX** | [`0x7f2106b5...`](https://atlantic.pharosscan.xyz/tx/0x7f2106b5bc8c5eddcd2ea7782669ccb0b4a107da4943cffd5d49357ab5820d2e) |
|
|
275
|
+
| **Source** | [`contracts/RiskRegistry.sol`](contracts/RiskRegistry.sol) |
|
|
276
|
+
|
|
277
|
+
```solidity
|
|
278
|
+
contract RiskRegistry {
|
|
279
|
+
struct RiskRecord {
|
|
280
|
+
uint256 score;
|
|
281
|
+
string riskLevel;
|
|
282
|
+
string recommendation;
|
|
283
|
+
uint256 timestamp;
|
|
284
|
+
address assessedBy;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function publish(address wallet, uint256 score, string riskLevel, string recommendation) external;
|
|
288
|
+
function query(address wallet) external view returns (RiskRecord memory);
|
|
289
|
+
}
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
When `assess_risk` is called with a `privateKey`, the score is **automatically published** β every assessment becomes a permanent, queryable on-chain record.
|
|
293
|
+
|
|
294
|
+
---
|
|
295
|
+
|
|
296
|
+
## π Live Transaction Proof
|
|
297
|
+
|
|
298
|
+
All 15 tools tested against **Pharos Atlantic Testnet** with real on-chain transactions:
|
|
299
|
+
|
|
300
|
+
| Tool | TX Hash | Result |
|
|
301
|
+
|------|---------|--------|
|
|
302
|
+
| `execute_swap` | [`0x0b88a7c9...`](https://atlantic.pharosscan.xyz/tx/0x0b88a7c91ece96247d77f5e9b61e1e5a8b66bd01c3e1b0f9b3e82e6f79f83ab1) | 0.01 PHRS β 0.0166 USDC |
|
|
303
|
+
| `send_payment` | [`0x7d914831...`](https://atlantic.pharosscan.xyz/tx/0x7d9148311ff0be0c9cf5f5b5e7a2a8c4d6e1f0a3b2c4d5e6f7a8b9c0d1e2f3a4) | 0.001 PHRS sent |
|
|
304
|
+
| `approve_token` | [`0xa50e5622...`](https://atlantic.pharosscan.xyz/tx/0xa50e562231e6135578e4d3c2b1a0f9e8d7c6b5a4938271605f4e3d2c1b0a9f8e) | 100 USDC approved |
|
|
305
|
+
| `publish_risk_score` | [`0x5f6f693f...`](https://atlantic.pharosscan.xyz/tx/0x5f6f693f5f1152663082ceb8eaa22d1a4b3c5d6e7f8a9b0c1d2e3f4a5b6c7d8e) | Score 2 published |
|
|
306
|
+
| Registry deploy | [`0x7f2106b5...`](https://atlantic.pharosscan.xyz/tx/0x7f2106b5bc8c5eddcd2ea7782669ccb0b4a107da4943cffd5d49357ab5820d2e) | Contract created |
|
|
307
|
+
|
|
308
|
+
### Test Results β 16/16 Passing
|
|
309
|
+
|
|
310
|
+
```
|
|
311
|
+
# β Status β Tool β Key Output
|
|
312
|
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
313
|
+
1 β β
PASS β assess_risk β score=2, low, proceed
|
|
314
|
+
2 β β
PASS β simulate_transaction β wouldSucceed=true, gas=379,098
|
|
315
|
+
3 β β
PASS β simulate_tx (xfer) β wouldSucceed=true, gas=21,000
|
|
316
|
+
4 β β
PASS β get_token_price β PHRS price fetched
|
|
317
|
+
5 β β
PASS β get_wallet_balance β PHRS=19.41, USDC=0.85
|
|
318
|
+
6 β β
PASS β check_allowance β needsApproval=true
|
|
319
|
+
7 β β
PASS β estimate_gas β cost=0.0038 PHRS, sufficient=true
|
|
320
|
+
8 β β
PASS β get_gas_price β 10.0 Gwei, trend=normal
|
|
321
|
+
9 β β
PASS β get_pool_info β Route query completed
|
|
322
|
+
10 β β
PASS β execute_swap β 0.01 PHRS β 0.0166 USDC β
|
|
323
|
+
11 β β
PASS β send_payment β 0.001 PHRS sent β
|
|
324
|
+
12 β β
PASS β approve_token β 100 USDC approved β
|
|
325
|
+
13 β β
PASS β get_transaction_status β status=success, block=23961005
|
|
326
|
+
14 β β
PASS β publish_risk_score β score=2 published on-chain β
|
|
327
|
+
15 β β
PASS β query_risk_registry β score=2, level=low
|
|
328
|
+
16 β β
PASS β get_execution_history β 5 txs found
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
---
|
|
332
|
+
|
|
333
|
+
## π Security
|
|
334
|
+
|
|
335
|
+
CertiK Skill Scanner compliant:
|
|
336
|
+
|
|
337
|
+
- β
**Private keys never stored** β passed per-request, never logged or persisted
|
|
338
|
+
- β
**No hardcoded secrets** β all sensitive config via `.env`
|
|
339
|
+
- β
**No shell execution** β pure TypeScript with viem RPC calls
|
|
340
|
+
- β
**No file system abuse** β no local file reads/writes during tool execution
|
|
341
|
+
- β
**Risk gating on all writes** β every execution goes through `assess_risk` first
|
|
342
|
+
- β
**Automatic blocking** β score > 80 halts execution, no silent failures
|
|
343
|
+
|
|
344
|
+
---
|
|
345
|
+
|
|
346
|
+
## πΊοΈ Roadmap
|
|
347
|
+
|
|
348
|
+
### Phase 1 β Hackathon (Current) β
|
|
349
|
+
- [x] 15 MCP tools with real on-chain execution
|
|
350
|
+
- [x] 5-dimension risk scoring engine
|
|
351
|
+
- [x] FaroSwap (DODO) integration
|
|
352
|
+
- [x] On-chain RiskRegistry smart contract
|
|
353
|
+
- [x] 16/16 integration tests passing on Pharos Atlantic
|
|
354
|
+
|
|
355
|
+
### Phase 2 β NPM Package
|
|
356
|
+
- [ ] Publish `@safehands/mcp` to npm
|
|
357
|
+
- [ ] One-line install: `npx safehands init`
|
|
358
|
+
- [ ] Configurable risk thresholds per-agent
|
|
359
|
+
|
|
360
|
+
### Phase 3 β Agent Arena
|
|
361
|
+
- [ ] Agent-to-agent risk score sharing via registry
|
|
362
|
+
- [ ] Reputation scoring from historical risk behavior
|
|
363
|
+
- [ ] Multi-agent swap coordination with risk consensus
|
|
364
|
+
|
|
365
|
+
### Phase 4 β DeFi Expansion
|
|
366
|
+
- [ ] ELFi lending protocol integration
|
|
367
|
+
- [ ] Multi-hop route optimization for large swaps
|
|
368
|
+
- [ ] Smart contract escrow for agent-to-agent payments
|
|
369
|
+
- [ ] Cross-chain risk assessment (Pharos Mainnet)
|
|
370
|
+
|
|
371
|
+
---
|
|
372
|
+
|
|
373
|
+
## π License
|
|
374
|
+
|
|
375
|
+
MIT β see [LICENSE](LICENSE) for details.
|
|
376
|
+
|
|
377
|
+
---
|
|
378
|
+
|
|
379
|
+
<p align="center">
|
|
380
|
+
<strong>Built for the Pharos AI Agent economy.</strong><br/>
|
|
381
|
+
<em>Where agents move real value β and real value deserves real protection.</em>
|
|
382
|
+
</p>
|