pragma-openclaw 0.1.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.
@@ -0,0 +1,300 @@
1
+ ---
2
+ name: pragma-delegation
3
+ description: Creates, renews, and manages on-chain trading delegations. Use when user needs to authorize trading, delegation expired, user wants to change trading scope, or after initial setup.
4
+ tools:
5
+ - pragma_has_wallet
6
+ - pragma_get_account_info
7
+ - pragma_get_all_balances
8
+ - pragma_check_session_key_balance
9
+ - pragma_setup_session
10
+ - pragma_request_delegation
11
+ - pragma_poll_delegation
12
+ - pragma_retrieve_delegation
13
+ - pragma_wrap
14
+ requires:
15
+ - pragma
16
+ metadata:
17
+ openclaw:
18
+ requires: ["pragma"]
19
+ ---
20
+
21
+ # Pragma Delegation — Trading Authorization
22
+
23
+ > Creates and manages on-chain delegations that authorize the agent to trade on behalf of the user.
24
+
25
+ ## What Is a Delegation?
26
+
27
+ A delegation is a signed on-chain permission from the user that lets you (the agent) trade through their Smart Account. Think of it like a power of attorney with built-in limits.
28
+
29
+ **What the user is signing:**
30
+ - Which actions you can perform (swap, trade perps, buy memecoins, etc.)
31
+ - How long the permission lasts (e.g., 7 days)
32
+ - Maximum MON per single transaction (e.g., 1 MON — this caps any single trade)
33
+ - Total number of transactions allowed (e.g., 100)
34
+ - Who can receive transfers (session key only, by default)
35
+
36
+ **What you cannot do even with a delegation:**
37
+ - Exceed the value limit per transaction
38
+ - Call contracts not in the allowed list
39
+ - Operate after the delegation expires
40
+ - Transfer to addresses not whitelisted
41
+
42
+ The user approves by signing with their passkey at pr4gma.xyz. You cannot bypass or modify the scope after signing.
43
+
44
+ ---
45
+
46
+ ## When This Skill Activates
47
+
48
+ - After initial setup (pragma-setup completed, delegation needed)
49
+ - A `pragma_` tool returns "Delegation expired" or "No delegation found"
50
+ - User wants to change trading scope
51
+ - User explicitly asks to "delegate", "authorize", "set permissions"
52
+
53
+ ---
54
+
55
+ ## Step 0: Check Existing Delegation
56
+
57
+ Before creating a new delegation, check if one already exists. The MCP tools automatically use the stored delegation at `~/.pragma/delegations/root/delegation.json`.
58
+
59
+ **ONLY create a new delegation if:**
60
+ - A `pragma_` tool returns "Delegation expired" or "No delegation found"
61
+ - The user explicitly asks to create or renew a delegation
62
+ - This is the first-time setup flow (no delegation has ever been created)
63
+
64
+ **DO NOT** create a new delegation just because you're about to perform a trade. Try the trade first — the existing delegation is used automatically.
65
+
66
+ ---
67
+
68
+ ## Step 1: Prerequisites
69
+
70
+ ```
71
+ pragma_has_wallet → Must be true (if not, direct to pragma-setup first)
72
+ pragma_get_account_info → Need the Smart Account address
73
+ pragma_check_session_key_balance → Need gas (> 0.1 MON)
74
+ ```
75
+
76
+ If session key gas is low, tell the user:
77
+ "Your session key needs gas to execute transactions.
78
+ Send at least 0.5 MON to: [session key address]"
79
+
80
+ ---
81
+
82
+ ## Step 2: Understand What the User Wants
83
+
84
+ **DO NOT dump a list of presets.** Instead, ask a simple question:
85
+
86
+ > "What would you like me to be able to do? For example: trade memecoins, do leveraged trading, swap tokens, or everything?"
87
+
88
+ Then map the user's intent to the right scope:
89
+
90
+ | User says... | You should use | Why |
91
+ |-------------|----------------|-----|
92
+ | "trade memecoins" / "snipe" / "nad.fun" | `["nadfun", "dex", "wmon"]` | Buying on bonding curve needs nadfun. Selling graduated tokens needs DEX. Wrapping needed for MON→WMON. |
93
+ | "perps" / "leverage" / "leverup" | `["leverup", "dex", "wmon"]` | Perps need leverup. DEX for collateral swaps (MON↔LVUSD). Wrapping for MON. |
94
+ | "swap tokens" / "spot trading" | `["dex", "wmon"]` | DEX for swaps. Wrapping for MON↔WMON. |
95
+ | "everything" / "full access" / no preference | `["dex", "leverup", "nadfun", "wmon"]` | All protocols. |
96
+ | Specific protocol names | Map directly | User knows what they want. |
97
+
98
+ **Important:** `wmon` (wrap/unwrap) should almost always be included — most operations need MON↔WMON conversion at some point.
99
+
100
+ ---
101
+
102
+ ## Step 3: Set Parameters (Smart Defaults)
103
+
104
+ Ask the user about limits using **plain language**, not parameter names. Use their portfolio to suggest smart defaults:
105
+
106
+ ```
107
+ pragma_get_all_balances → Check portfolio size
108
+ ```
109
+
110
+ ### Duration
111
+
112
+ > "How long should this authorization last?"
113
+
114
+ | User says | `expiryDays` value |
115
+ |-----------|-------------------|
116
+ | "a few hours" / "just today" | 1 |
117
+ | "a week" / nothing specified | 7 (default) |
118
+ | "a month" / "longer" | 30 |
119
+
120
+ ### Max value per transaction
121
+
122
+ > "What's the most MON I should be able to use in a single transaction?"
123
+
124
+ **Smart defaults based on portfolio:**
125
+
126
+ | Portfolio MON balance | Suggested `maxValuePerTxMon` |
127
+ |----------------------|------------------------------|
128
+ | < 5 MON | 0.5 |
129
+ | 5–50 MON | 1 (default) |
130
+ | 50–500 MON | 5 |
131
+ | > 500 MON | 10 |
132
+
133
+ Explain it simply:
134
+ > "This caps any single trade at [X] MON. You have [Y] MON in your portfolio, so I'd suggest [Z] as the limit. Sound good?"
135
+
136
+ ### Max transactions
137
+
138
+ > "How many transactions should I be allowed to make?"
139
+
140
+ | Usage pattern | Suggested `maxCalls` |
141
+ |--------------|---------------------|
142
+ | Casual / first time | 50 |
143
+ | Active trading | 100 (default) |
144
+ | Autonomous / long duration | 500 |
145
+ | Heavy usage | 1000 |
146
+
147
+ Explain it simply:
148
+ > "This is the total number of on-chain actions I can take — each swap, trade open/close, or approval counts as one. I'd suggest [X] for [duration] days."
149
+
150
+ ### Transfer recipients
151
+
152
+ Transfers to the session key are enabled by default — this lets the agent fund its own gas. You don't need to ask the user about this unless they specifically want to restrict transfers.
153
+
154
+ If the user asks about transfers to other addresses:
155
+ > "By default, I can only transfer tokens to my own session key (for gas). Want to add other addresses I can send to?"
156
+
157
+ ---
158
+
159
+ ## Step 4: Confirm Before Submitting
160
+
161
+ Summarize in plain language:
162
+
163
+ ```
164
+ "Here's what I'm requesting permission for:
165
+
166
+ What I can do: [plain description, e.g., 'swap tokens, trade perps, and buy memecoins']
167
+ Duration: [X] days (expires [date])
168
+ Max per trade: [X] MON
169
+ Max transactions: [X] total
170
+ Self-funding: Enabled (I can send tokens/MON to my session key for gas)
171
+
172
+ You'll get a link to approve this in your browser.
173
+ Want me to proceed?"
174
+ ```
175
+
176
+ Wait for user confirmation.
177
+
178
+ ---
179
+
180
+ ## Step 5: Submit Delegation Request
181
+
182
+ ```
183
+ pragma_request_delegation({
184
+ sa: "<user's Smart Account address>",
185
+ protocols: ["dex", "leverup", "nadfun", "wmon"],
186
+ expiryDays: 7,
187
+ maxCalls: 100,
188
+ maxValuePerTxMon: 1,
189
+ budgetMon: 1,
190
+ description: "Full trading suite - 7 days"
191
+ })
192
+ → Returns: { requestId, approvalUrl }
193
+ ```
194
+
195
+ Send the approval URL with a clear explanation:
196
+
197
+ ```
198
+ "Please approve this in your browser:
199
+ [approvalUrl]
200
+
201
+ What you're signing: A time-limited permission for me to trade
202
+ on your behalf with the limits we just discussed. I cannot
203
+ exceed these limits — they're enforced on-chain.
204
+
205
+ The link expires in 30 minutes."
206
+ ```
207
+
208
+ ---
209
+
210
+ ## Step 6: Poll for Approval
211
+
212
+ ```
213
+ Poll every 30 seconds (max 30 minutes):
214
+ pragma_poll_delegation({ requestId })
215
+ → "pending": Continue polling silently
216
+ → "approved": Continue to Step 7
217
+ → "rejected": "Delegation rejected. Want to try different settings?"
218
+ → "expired": "The approval link expired. I'll create a new one."
219
+ ```
220
+
221
+ If the user hasn't approved after 5 minutes, send a gentle reminder:
222
+ "Still waiting for your approval. Open this link when ready: [approvalUrl]"
223
+
224
+ ---
225
+
226
+ ## Step 7: Retrieve, Verify, and Activate
227
+
228
+ ```
229
+ pragma_retrieve_delegation({ requestId })
230
+ → Signed delegation stored at ~/.pragma/delegations/root/delegation.json
231
+ ```
232
+
233
+ **Verify the delegation works** with a small test:
234
+
235
+ ```
236
+ pragma_wrap({ amount: "0.001" })
237
+ → If this succeeds, the delegation is working correctly
238
+ → If this fails with "No delegation found", something went wrong with storage
239
+ ```
240
+
241
+ Then show the user:
242
+
243
+ ```
244
+ pragma_get_all_balances → Portfolio snapshot
245
+
246
+ "Delegation active and verified!
247
+
248
+ Valid until: [expiry date]
249
+ Scope: [what you can do]
250
+ Transactions remaining: [maxCalls]
251
+ Portfolio: [summary]
252
+
253
+ You can now ask me to trade. Try: 'what's trending on nad.fun?' or 'show my positions'"
254
+ ```
255
+
256
+ ---
257
+
258
+ ## Delegation Renewal
259
+
260
+ When a delegation is expiring or expired:
261
+
262
+ 1. Check if the user wants the same scope or different
263
+ 2. If same scope, skip Step 2-3 and go straight to Step 5 with the same parameters
264
+ 3. If different scope, go through Steps 2-5
265
+
266
+ ```
267
+ "Your trading authorization expires in [X hours / has expired].
268
+ Want me to renew with the same settings, or change anything?"
269
+ ```
270
+
271
+ For autonomous mode: if the user doesn't respond within 30 minutes and the delegation is about to expire, close any open positions before the delegation expires.
272
+
273
+ ---
274
+
275
+ ## Protocol Reference
276
+
277
+ | Protocol | What it does | Common operations |
278
+ |----------|-------------|-------------------|
279
+ | `dex` | Token swaps via DEX aggregator | Swap MON→USDC, swap any token pair |
280
+ | `leverup` | Leveraged perpetual trading | Open/close positions, set TP/SL, limit orders |
281
+ | `nadfun` | Memecoin trading on bonding curves | Buy/sell memecoins on nad.fun |
282
+ | `wmon` | MON↔WMON wrapping | Convert native MON to wrapped MON and back |
283
+
284
+ **Automatically included in every delegation (no configuration needed):**
285
+ - ERC-20 token approvals (needed before swaps/trades)
286
+ - ERC-20 transfers to session key (for self-funding with tokens)
287
+ - Native MON transfers to session key (for gas self-funding)
288
+
289
+ ---
290
+
291
+ ## Error Handling
292
+
293
+ | Error | What to tell the user |
294
+ |-------|----------------------|
295
+ | "Wallet not configured" | "You need to set up your wallet first. Say 'set up pragma' to get started." |
296
+ | "Session key not registered" | "Your session key needs to be linked to your Smart Account. Let me fix that." → Run `pragma_setup_session` |
297
+ | "Invalid Smart Account" | "That doesn't look like a valid Smart Account address. Can you double-check?" |
298
+ | "Approval link expired" | "The link expired — let me create a fresh one." → Re-run Step 5 |
299
+ | "Delegation rejected" | "No problem. Want to try with different settings, or skip for now?" |
300
+ | "API error" | Retry once silently. If still fails: "Having trouble reaching the server. Let's try again in a moment." |
@@ -0,0 +1,42 @@
1
+ ---
2
+ name: pragma-mode
3
+ description: Switch between BYOK (free, bring your own keys) and x402 (pay per API call) modes.
4
+ tools:
5
+ - pragma_has_providers
6
+ - pragma_set_mode
7
+ requires:
8
+ - pragma
9
+ metadata:
10
+ openclaw:
11
+ requires: ["pragma"]
12
+ ---
13
+
14
+ # Pragma Mode — BYOK / x402 Switching
15
+
16
+ > Switch between free (BYOK) and paid (x402) API modes.
17
+
18
+ ## Modes
19
+
20
+ | Mode | Description | Cost |
21
+ |------|-------------|------|
22
+ | **x402** | All API backends provided by Pragma | Pay per API call |
23
+ | **BYOK** | Bring your own API keys | Free (you provide everything) |
24
+
25
+ ## Switching
26
+
27
+ ```
28
+ User: "switch to byok" / "use free mode" / "bring my own keys"
29
+ → pragma_set_mode({ mode: "byok" })
30
+
31
+ User: "switch to x402" / "use paid mode" / "use convenience mode"
32
+ → pragma_set_mode({ mode: "x402" })
33
+ ```
34
+
35
+ ## After Switching
36
+
37
+ After switching to BYOK, check provider status:
38
+ ```
39
+ pragma_has_providers → Shows which providers are configured
40
+ ```
41
+
42
+ If providers are missing, guide the user to configure them.
@@ -0,0 +1,164 @@
1
+ ---
2
+ name: pragma-setup
3
+ description: First-time onboarding for Pragma. Use when user needs to set up their wallet, configure the plugin, or hasn't used Pragma before.
4
+ tools:
5
+ - pragma_has_wallet
6
+ - pragma_has_providers
7
+ - pragma_setup_wallet
8
+ - pragma_set_mode
9
+ - pragma_get_account_info
10
+ - pragma_get_all_balances
11
+ - pragma_check_session_key_balance
12
+ - pragma_setup_session
13
+ requires:
14
+ - pragma
15
+ metadata:
16
+ openclaw:
17
+ requires: ["pragma"]
18
+ ---
19
+
20
+ # Pragma Setup — Onboarding
21
+
22
+ > First-time setup for Pragma on OpenClaw.
23
+
24
+ ## When This Skill Activates
25
+
26
+ - User says "set up pragma", "configure wallet", "get started"
27
+ - `pragma_has_wallet` returns false
28
+ - First interaction with any pragma tool fails due to missing wallet
29
+
30
+ ---
31
+
32
+ ## Onboarding Flow
33
+
34
+ ### Step 1: Check Current State
35
+
36
+ ```
37
+ pragma_has_wallet
38
+ → true (with SA set): Skip to Step 5 (verify setup)
39
+ → true (no SA): Skip to Step 3 (ask for SA address)
40
+ → false: Continue to Step 2
41
+ ```
42
+
43
+ ### Step 2: Initialize Session Key
44
+
45
+ ```
46
+ pragma_setup_wallet
47
+ → Creates file-based session key at ~/.pragma/session-key.json
48
+ → Creates config at ~/.pragma/config.json
49
+ → Returns: { sessionKeyAddress, smartAccountAddress: "not set" }
50
+ ```
51
+
52
+ The session key is the agent's wallet — it will execute trades on behalf of the user.
53
+
54
+ ### Step 3: Get User's Smart Account Address
55
+
56
+ The user needs a Pragma Smart Account. This is their on-chain wallet that the agent trades through.
57
+
58
+ ```
59
+ Tell user:
60
+ "Session key created: [sessionKeyAddress]
61
+
62
+ Now I need your Smart Account (SA) address to connect.
63
+
64
+ If you already have one, paste the 0x... address here.
65
+
66
+ If you don't have one yet, create it at:
67
+ https://pr4gma.xyz/setup
68
+
69
+ It only takes a minute — just connect with your passkey."
70
+ ```
71
+
72
+ Wait for user to provide their SA address (0x...).
73
+
74
+ ### Step 4: Register Session Key
75
+
76
+ ```
77
+ pragma_setup_session({ sa: "<user's SA address>" })
78
+ → Registers session key with Pragma API
79
+ → Links session key to user's Smart Account
80
+ → Unlocks 50 free bootstrap API calls (x402 mode)
81
+ ```
82
+
83
+ **Important:** Registration gives the session key 50 free x402 API calls. This means the agent can immediately check balances, get quotes, and fetch market data without the user needing to fund anything upfront.
84
+
85
+ Tell the user:
86
+ "Session key registered and linked to your Smart Account.
87
+ You have 50 free API calls to get started."
88
+
89
+ ### Step 5: Verify Setup
90
+
91
+ ```
92
+ pragma_get_all_balances → Portfolio check
93
+ pragma_check_session_key_balance → Gas check
94
+ ```
95
+
96
+ Show the user their portfolio summary and session key gas balance.
97
+
98
+ If session key gas is low (< 0.1 MON):
99
+ "Your session key needs gas to execute transactions.
100
+ Send at least 0.5 MON to: [session key address]"
101
+
102
+ **Gas funding rules for this platform:**
103
+ - **First time (no delegation yet):** User must send MON manually to the session key address. There is no other way.
104
+ - **After delegation is active:** Use `pragma_fund_session_key` to auto-transfer MON from SA → session key via delegation.
105
+ - **Zero gas emergency:** If session key hits 0 MON, self-funding can't work (needs gas to submit the tx). Ask user to send MON manually.
106
+ - **No UserOp on this platform.** Do not mention UserOp or bundler to the user.
107
+
108
+ ### Step 6: Create Trading Delegation
109
+
110
+ If the user already has a delegation stored at `~/.pragma/delegations/root/delegation.json`, skip this step — the MCP tools will use it automatically.
111
+
112
+ The user needs a delegation to authorize trading. Use the **pragma-delegation** skill.
113
+
114
+ The delegation skill will:
115
+ 1. Ask the user what they want to trade (maps to protocol scopes automatically)
116
+ 2. Set duration, limits, and gas budget using smart defaults
117
+ 3. Submit the delegation request with proper on-chain caveats (includes transfer groups for session key self-funding by default)
118
+ 4. Send the user an approval link to sign with their passkey
119
+ 5. Poll for approval and retrieve the signed delegation
120
+ 6. Verify the delegation works with a small test transaction
121
+
122
+ ```
123
+ Tell user:
124
+ "Now let's set up your trading authorization.
125
+ I'll ask you a few questions about what you'd like me to trade."
126
+ ```
127
+
128
+ Follow the pragma-delegation skill flow from Step 2 onward.
129
+
130
+ ### Step 7: Done
131
+
132
+ After delegation is active:
133
+
134
+ ```
135
+ Tell user:
136
+ "Setup complete!
137
+
138
+ Smart Account: [SA address]
139
+ Session Key: [session key address]
140
+ Delegation: Active until [expiry]
141
+ Portfolio: [summary]
142
+
143
+ You can now ask me to trade, check prices, or monitor markets.
144
+ Try: 'show my portfolio' or 'what's trending on nad.fun?'"
145
+ ```
146
+
147
+ ---
148
+
149
+ ## Mode Configuration
150
+
151
+ Default mode is **x402** (paid convenience). The user can switch to BYOK (free, bring your own keys) at any time using the **pragma-mode** skill.
152
+
153
+ ---
154
+
155
+ ## Troubleshooting
156
+
157
+ | Issue | Solution |
158
+ |-------|----------|
159
+ | "Wallet not found" | Run setup from Step 2 |
160
+ | "Session key not registered" | Run `pragma_setup_session` with SA address |
161
+ | "Delegation expired" | Use pragma-delegation skill to create new delegation |
162
+ | "Insufficient gas" | "Send MON to session key: [address]" |
163
+ | "No balance" | "Send tokens to Smart Account: [address]" |
164
+ | "Bootstrap calls exhausted" | User needs to fund session key for x402 payments |