@poincaretrade/mcp 0.0.0-stage → 0.1.1
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/LICENSE +27 -0
- package/README.md +43 -3
- package/dist/chunk-TWNQBRNA.js +460 -0
- package/dist/index.js +26 -0
- package/dist/server.d.ts +18 -0
- package/dist/server.js +6 -0
- package/package.json +60 -3
- package/skills/poincare/SKILL.md +142 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Prakhar Srivastava
|
|
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.
|
|
22
|
+
|
|
23
|
+
-----------------------------------------------------------------------------
|
|
24
|
+
|
|
25
|
+
Poincare was previously licensed under the Business Source License 1.1. It is
|
|
26
|
+
now licensed under the MIT License above, in its entirety, by its sole
|
|
27
|
+
copyright holder. Third-party code under lib/ keeps its own licenses.
|
package/README.md
CHANGED
|
@@ -1,3 +1,43 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# @poincaretrade/mcp
|
|
2
|
+
|
|
3
|
+
An [MCP](https://modelcontextprotocol.io) server that gives Claude, or any MCP client, **Poincaré**'s trend
|
|
4
|
+
regime, swap quotes and spread-aware DCA orders as 15 tools. It reads the live pool on Unichain Sepolia and
|
|
5
|
+
returns **unsigned** transactions; nothing is ever sent unless you add your own key and the agent calls a
|
|
6
|
+
tool with `send: true`.
|
|
7
|
+
|
|
8
|
+
Full docs: **https://www.poincaretrade.in/#/docs/mcp**
|
|
9
|
+
|
|
10
|
+
## Add it
|
|
11
|
+
|
|
12
|
+
**Claude Code**
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
claude mcp add poincare -- npx -y @poincaretrade/mcp
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
**Claude Desktop and other clients** (`mcpServers` in the client's config):
|
|
19
|
+
|
|
20
|
+
```json
|
|
21
|
+
{
|
|
22
|
+
"mcpServers": {
|
|
23
|
+
"poincare": { "command": "npx", "args": ["-y", "@poincaretrade/mcp"] }
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
| Variable | Meaning |
|
|
29
|
+
|---|---|
|
|
30
|
+
| `POINCARE_RPC_URL` | RPC endpoint (default: the public Unichain Sepolia RPC) |
|
|
31
|
+
| `POINCARE_DCA_ADDRESS` | Overrides the live PoincareDCA |
|
|
32
|
+
| `POINCARE_PRIVATE_KEY` | Optional. With it, tools called with `send: true` broadcast from this key, and owner-only tools refuse orders it does not own. Use a testnet key you are happy to delegate |
|
|
33
|
+
|
|
34
|
+
## Tools
|
|
35
|
+
|
|
36
|
+
`get_regime` · `get_regime_history` · `wait_for_regime_change` · `quote` · `dca_plan_order` ·
|
|
37
|
+
`dca_create_order` · `dca_get_order` · `dca_list_orders` · `dca_preview_slice` · `dca_pause_order` ·
|
|
38
|
+
`dca_resume_order` · `dca_edit_order` · `dca_execute_slice` · `dca_cancel_order` · `dca_close_expired`
|
|
39
|
+
|
|
40
|
+
Try: *"Is the Poincaré pool trending right now, and which side pays?"* or *"Plan a DCA that buys 500 USDC
|
|
41
|
+
of WETH over a day without ever paying the trend spread."*
|
|
42
|
+
|
|
43
|
+
**Status:** testnet research preview. MIT licensed (see LICENSE).
|
|
@@ -0,0 +1,460 @@
|
|
|
1
|
+
// src/server.ts
|
|
2
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import {
|
|
4
|
+
DCA_STATUS_TEXT,
|
|
5
|
+
buildOrderParams,
|
|
6
|
+
diffRegime,
|
|
7
|
+
minPriceWadToLimit,
|
|
8
|
+
orderIdFromReceipt,
|
|
9
|
+
planSlice,
|
|
10
|
+
progressOf,
|
|
11
|
+
spentOf,
|
|
12
|
+
formatAmount,
|
|
13
|
+
trendOnsets,
|
|
14
|
+
wadToBpsUp
|
|
15
|
+
} from "@poincaretrade/sdk";
|
|
16
|
+
import { getAddress } from "viem";
|
|
17
|
+
import { z } from "zod";
|
|
18
|
+
|
|
19
|
+
// src/format.ts
|
|
20
|
+
function jsonSafe(v) {
|
|
21
|
+
if (typeof v === "bigint") return v.toString();
|
|
22
|
+
if (Array.isArray(v)) return v.map(jsonSafe);
|
|
23
|
+
if (v && typeof v === "object") return Object.fromEntries(Object.entries(v).map(([k, x]) => [k, jsonSafe(x)]));
|
|
24
|
+
return v;
|
|
25
|
+
}
|
|
26
|
+
function ok(data) {
|
|
27
|
+
const safe = jsonSafe(data);
|
|
28
|
+
return { content: [{ type: "text", text: JSON.stringify(safe, null, 2) }], structuredContent: safe };
|
|
29
|
+
}
|
|
30
|
+
function fail(err) {
|
|
31
|
+
const message = err instanceof Error && err.name === "DcaNotDeployedError" ? "The DCA contract address is not configured: set POINCARE_DCA_ADDRESS in the MCP server's environment." : err instanceof Error ? err.message : String(err);
|
|
32
|
+
return { content: [{ type: "text", text: `Error: ${message}` }], isError: true };
|
|
33
|
+
}
|
|
34
|
+
var pct = (x, dp = 2) => `${(x * 100).toFixed(dp)}%`;
|
|
35
|
+
function describeRegime(r) {
|
|
36
|
+
const trend = r.trend === "none" ? "No confirmed trend" : `Confirmed ${r.trend}-trend (${r.withTrendSide === "buy" ? "buyers" : "sellers"} push with it)`;
|
|
37
|
+
const charge = r.chargedSide === null ? "no side pays a trend spread right now" : `${r.chargedSide === "buy" ? "buys" : "sells"} pay a ${pct(r.spread[r.chargedSide])} spread to LPs and ${r.chargedSide === "buy" ? "sells" : "buys"} trade free`;
|
|
38
|
+
const ev = `evidence ${Math.round(r.evidence.progress * 100)}% of the threshold${r.gated ? " (gated: moves read as chop)" : ""}`;
|
|
39
|
+
return `${trend}; ${charge}; ${ev}. Mid price ${r.price.toFixed(2)} USDC per WETH, base fee ${pct(r.fee)}.`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// src/server.ts
|
|
43
|
+
var side = z.enum(["buy", "sell"]).describe("buy = pay USDC for WETH; sell = pay WETH for USDC");
|
|
44
|
+
var address = z.string().regex(/^0x[0-9a-fA-F]{40}$/, "an 0x address");
|
|
45
|
+
var orderId = z.union([z.number().int().positive(), z.string().regex(/^\d+$/)]).describe("DCA order id");
|
|
46
|
+
var sendFlag = z.boolean().optional().describe("Broadcast with the key configured in POINCARE_PRIVATE_KEY. Omit or false to get unsigned transactions instead.");
|
|
47
|
+
var orderShape = {
|
|
48
|
+
side,
|
|
49
|
+
amount: z.string().regex(/^\d+(\.\d+)?$/).describe('Total budget in the input token (USDC to buy, WETH to sell), e.g. "1000"'),
|
|
50
|
+
slices: z.number().int().min(1).max(1e4).describe("Number of fills"),
|
|
51
|
+
intervalSec: z.number().int().min(60).describe("Seconds between fills (>= 60)"),
|
|
52
|
+
startTime: z.number().int().optional().describe("Unix seconds; omit to start immediately"),
|
|
53
|
+
deadline: z.number().int().optional().describe("Unix seconds; default one spare interval after the last planned fill"),
|
|
54
|
+
maxSpreadBps: z.number().int().min(0).max(1e4).optional().describe("Skip a fill while the trend spread on this side exceeds this (bps). 0 = never pay the spread. Default 10000 (no cap)"),
|
|
55
|
+
pauseOnTrend: z.boolean().optional().describe("Hold fills while a trend runs with this side (the side the pool charges); resume when it ends. Default false"),
|
|
56
|
+
catchUp: z.boolean().optional().describe("Grow later fills to make up skipped ones, so the order completes by the deadline. Default true"),
|
|
57
|
+
maxSlippageBps: z.number().int().min(0).max(1e4).optional().describe("Max shortfall vs the in-transaction quote (bps). Default 50"),
|
|
58
|
+
limitPrice: z.string().regex(/^\d+(\.\d+)?$/).optional().describe("USDC per WETH: the most a buy pays / the least a sell accepts"),
|
|
59
|
+
recipient: address.optional().describe("Receives every fill; default the owner")
|
|
60
|
+
};
|
|
61
|
+
function toInput(a) {
|
|
62
|
+
return {
|
|
63
|
+
side: a.side,
|
|
64
|
+
amount: a.amount,
|
|
65
|
+
slices: a.slices,
|
|
66
|
+
interval: a.intervalSec,
|
|
67
|
+
startTime: a.startTime,
|
|
68
|
+
deadline: a.deadline,
|
|
69
|
+
maxSpreadBps: a.maxSpreadBps,
|
|
70
|
+
pauseOnTrend: a.pauseOnTrend,
|
|
71
|
+
catchUp: a.catchUp,
|
|
72
|
+
maxSlippageBps: a.maxSlippageBps,
|
|
73
|
+
limitPrice: a.limitPrice,
|
|
74
|
+
recipient: a.recipient
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function orderView(o) {
|
|
78
|
+
const tokenIn = o.side === "buy" ? "USDC" : "WETH";
|
|
79
|
+
const tokenOut = o.side === "buy" ? "WETH" : "USDC";
|
|
80
|
+
return {
|
|
81
|
+
...o,
|
|
82
|
+
tokenIn,
|
|
83
|
+
tokenOut,
|
|
84
|
+
amountInFormatted: `${formatAmount(o.amountIn)} ${tokenIn}`,
|
|
85
|
+
remainingFormatted: `${formatAmount(o.remaining)} ${tokenIn}`,
|
|
86
|
+
amountOutFormatted: `${formatAmount(o.amountOut)} ${tokenOut}`,
|
|
87
|
+
spentFormatted: `${formatAmount(spentOf(o))} ${tokenIn}`,
|
|
88
|
+
refundedFormatted: `${formatAmount(o.refunded)} ${tokenIn}`,
|
|
89
|
+
progress: progressOf(o),
|
|
90
|
+
limitPrice: minPriceWadToLimit(o.side, o.minPriceWad),
|
|
91
|
+
startsAt: new Date(Number(o.startTime) * 1e3).toISOString(),
|
|
92
|
+
deadlineAt: new Date(Number(o.deadline) * 1e3).toISOString()
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function createServer(opts) {
|
|
96
|
+
const { poincare, signer } = opts;
|
|
97
|
+
const now = opts.now ?? (() => Math.floor(Date.now() / 1e3));
|
|
98
|
+
const server = new McpServer({ name: "poincare", version: "0.1.1" });
|
|
99
|
+
const run = async (txs, send) => {
|
|
100
|
+
if (!send) return { sent: false, transactions: txs, note: "Unsigned. Sign and send these in order from the owner's wallet." };
|
|
101
|
+
if (!signer) throw new Error("send=true needs POINCARE_PRIVATE_KEY in the MCP server's environment");
|
|
102
|
+
const receipts = [];
|
|
103
|
+
for (const tx of txs) receipts.push(await signer.send(tx));
|
|
104
|
+
return { sent: true, transactions: receipts.map((r) => ({ hash: r.transactionHash, block: r.blockNumber, status: r.status })), receipts };
|
|
105
|
+
};
|
|
106
|
+
const ownerOf = (given) => {
|
|
107
|
+
if (given) return getAddress(given);
|
|
108
|
+
if (signer) return signer.address;
|
|
109
|
+
throw new Error("pass `owner` (no signing key is configured)");
|
|
110
|
+
};
|
|
111
|
+
server.registerTool(
|
|
112
|
+
"get_regime",
|
|
113
|
+
{
|
|
114
|
+
title: "Current trend regime",
|
|
115
|
+
description: "What the next swap on the Poincar\xE9 WETH/USDC pool sees this block: the confirmed trend (CUSUM, data-dependent), evidence toward the threshold, which side pays the trend spread and how much, base fee and mid price. Market orientation: USDC per WETH.",
|
|
116
|
+
annotations: { readOnlyHint: true, openWorldHint: true }
|
|
117
|
+
},
|
|
118
|
+
async () => {
|
|
119
|
+
try {
|
|
120
|
+
const r = await poincare.regime();
|
|
121
|
+
return ok({ summary: describeRegime(r), regime: r });
|
|
122
|
+
} catch (e) {
|
|
123
|
+
return fail(e);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
);
|
|
127
|
+
server.registerTool(
|
|
128
|
+
"get_regime_history",
|
|
129
|
+
{
|
|
130
|
+
title: "Trend history",
|
|
131
|
+
description: "The hook's own detector samples over recent blocks, with where trends started, ended or flipped.",
|
|
132
|
+
inputSchema: { blocks: z.number().int().min(100).max(2e4).optional().describe("How many recent blocks to scan (default 3000)") },
|
|
133
|
+
annotations: { readOnlyHint: true, openWorldHint: true }
|
|
134
|
+
},
|
|
135
|
+
async ({ blocks }) => {
|
|
136
|
+
try {
|
|
137
|
+
const head = await poincare.publicClient.getBlockNumber();
|
|
138
|
+
const from = head - BigInt(blocks ?? 3e3);
|
|
139
|
+
const samples = await poincare.history(from > 0n ? from : 0n, head);
|
|
140
|
+
return ok({ fromBlock: from, toBlock: head, sampleCount: samples.length, onsets: trendOnsets(samples), latest: samples.slice(-10) });
|
|
141
|
+
} catch (e) {
|
|
142
|
+
return fail(e);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
);
|
|
146
|
+
server.registerTool(
|
|
147
|
+
"wait_for_regime_change",
|
|
148
|
+
{
|
|
149
|
+
title: "Wait for a trend onset",
|
|
150
|
+
description: "Block until the regime changes (trend started/ended/flipped, evidence building, spread engaged/released) or the timeout passes. Use it to react to the onset of a trend instead of polling.",
|
|
151
|
+
inputSchema: {
|
|
152
|
+
timeoutSec: z.number().int().min(5).max(300).optional().describe("Give up after this many seconds (default 60)"),
|
|
153
|
+
events: z.array(z.enum(["trend-started", "trend-ended", "trend-flipped", "evidence-building", "spread-engaged", "spread-released"])).optional().describe("Only return on these event types (default: any)")
|
|
154
|
+
},
|
|
155
|
+
annotations: { readOnlyHint: true, openWorldHint: true }
|
|
156
|
+
},
|
|
157
|
+
async ({ timeoutSec, events }) => {
|
|
158
|
+
try {
|
|
159
|
+
let prev = await poincare.regime();
|
|
160
|
+
const deadline = Date.now() + (timeoutSec ?? 60) * 1e3;
|
|
161
|
+
while (Date.now() < deadline) {
|
|
162
|
+
await new Promise((r) => setTimeout(r, 2e3));
|
|
163
|
+
const next = await poincare.regime();
|
|
164
|
+
const hit = diffRegime(prev, next).filter((e) => !events || events.includes(e.type));
|
|
165
|
+
prev = next;
|
|
166
|
+
if (hit.length) return ok({ changed: true, events: hit, summary: describeRegime(next), regime: next });
|
|
167
|
+
}
|
|
168
|
+
return ok({ changed: false, summary: describeRegime(prev), regime: prev });
|
|
169
|
+
} catch (e) {
|
|
170
|
+
return fail(e);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
);
|
|
174
|
+
server.registerTool(
|
|
175
|
+
"quote",
|
|
176
|
+
{
|
|
177
|
+
title: "Quote a swap",
|
|
178
|
+
description: "Exact-input quote from the pool's Lens (matches router execution in the same block to the wei), with the spread and fee this side pays.",
|
|
179
|
+
inputSchema: { side, amount: z.string().regex(/^\d+(\.\d+)?$/).describe("Input amount: USDC to buy, WETH to sell") },
|
|
180
|
+
annotations: { readOnlyHint: true, openWorldHint: true }
|
|
181
|
+
},
|
|
182
|
+
async ({ side: s, amount }) => {
|
|
183
|
+
try {
|
|
184
|
+
const q = await poincare.quote(s, amount);
|
|
185
|
+
return ok({ ...q, amountOutFormatted: `${formatAmount(q.amountOut)} ${s === "buy" ? "WETH" : "USDC"}` });
|
|
186
|
+
} catch (e) {
|
|
187
|
+
return fail(e);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
);
|
|
191
|
+
server.registerTool(
|
|
192
|
+
"dca_plan_order",
|
|
193
|
+
{
|
|
194
|
+
title: "Plan a spread-aware DCA order",
|
|
195
|
+
description: "Validate a DCA order exactly as the contract will, show its schedule, and say what the first fill would do under the current regime. Sends nothing.",
|
|
196
|
+
inputSchema: orderShape,
|
|
197
|
+
annotations: { readOnlyHint: true, openWorldHint: true }
|
|
198
|
+
},
|
|
199
|
+
async (args) => {
|
|
200
|
+
try {
|
|
201
|
+
const t = now();
|
|
202
|
+
const p = buildOrderParams(toInput(args), t);
|
|
203
|
+
const start = p.startTime === 0n ? BigInt(t) : p.startTime;
|
|
204
|
+
const r = await poincare.regime();
|
|
205
|
+
const sideSpread = args.side === "buy" ? r.raw.spreadBuy : r.raw.spreadSell;
|
|
206
|
+
const first = planSlice(
|
|
207
|
+
{
|
|
208
|
+
id: 0n,
|
|
209
|
+
owner: "0x0000000000000000000000000000000000000000",
|
|
210
|
+
recipient: p.recipient,
|
|
211
|
+
side: args.side,
|
|
212
|
+
zeroForOne: p.zeroForOne,
|
|
213
|
+
pauseOnTrend: p.pauseOnTrend,
|
|
214
|
+
catchUp: p.catchUp,
|
|
215
|
+
cancelled: false,
|
|
216
|
+
paused: false,
|
|
217
|
+
maxSpreadBps: p.maxSpreadBps,
|
|
218
|
+
maxSlippageBps: p.maxSlippageBps,
|
|
219
|
+
slices: p.slices,
|
|
220
|
+
interval: p.interval,
|
|
221
|
+
filled: 0,
|
|
222
|
+
startTime: start,
|
|
223
|
+
deadline: p.deadline,
|
|
224
|
+
lastSlotPlusOne: 0n,
|
|
225
|
+
amountIn: p.amountIn,
|
|
226
|
+
remaining: p.amountIn,
|
|
227
|
+
amountOut: 0n,
|
|
228
|
+
minPriceWad: p.minPriceWad,
|
|
229
|
+
scheduleBudget: p.amountIn,
|
|
230
|
+
scheduleFilled: 0,
|
|
231
|
+
refunded: 0n
|
|
232
|
+
},
|
|
233
|
+
{ now: BigInt(t), spreadBps: wadToBpsUp(sideSpread), trendWithSide: r.withTrendSide === args.side }
|
|
234
|
+
);
|
|
235
|
+
const schedule = Array.from({ length: Math.min(p.slices, 12) }, (_, i) => ({
|
|
236
|
+
slice: i + 1,
|
|
237
|
+
opensAt: new Date(Number(start + BigInt(i * p.interval)) * 1e3).toISOString()
|
|
238
|
+
}));
|
|
239
|
+
return ok({
|
|
240
|
+
params: p,
|
|
241
|
+
perSlice: `${formatAmount(p.amountIn / BigInt(p.slices))} ${args.side === "buy" ? "USDC" : "WETH"}`,
|
|
242
|
+
schedule,
|
|
243
|
+
deadlineAt: new Date(Number(p.deadline) * 1e3).toISOString(),
|
|
244
|
+
firstFillNow: { status: first.status, meaning: DCA_STATUS_TEXT[first.status] },
|
|
245
|
+
regime: describeRegime(r)
|
|
246
|
+
});
|
|
247
|
+
} catch (e) {
|
|
248
|
+
return fail(e);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
);
|
|
252
|
+
server.registerTool(
|
|
253
|
+
"dca_create_order",
|
|
254
|
+
{
|
|
255
|
+
title: "Create a DCA order",
|
|
256
|
+
description: "Escrow the budget in the PoincareDCA contract and open the order. Returns the unsigned approve + create transactions, or sends them when send=true and a key is configured.",
|
|
257
|
+
inputSchema: { ...orderShape, owner: address.optional().describe("Order owner; defaults to the configured key's address"), send: sendFlag },
|
|
258
|
+
annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: true }
|
|
259
|
+
},
|
|
260
|
+
async (args) => {
|
|
261
|
+
try {
|
|
262
|
+
const from = ownerOf(args.owner);
|
|
263
|
+
if (args.send && signer && from.toLowerCase() !== signer.address.toLowerCase()) {
|
|
264
|
+
throw new Error("send=true creates the order from the configured key; `owner` must be that address");
|
|
265
|
+
}
|
|
266
|
+
const txs = await poincare.dca.build.create(from, toInput(args));
|
|
267
|
+
const res = await run(txs, args.send);
|
|
268
|
+
if (res.sent) {
|
|
269
|
+
const id = orderIdFromReceipt(poincare.deployment, res.receipts[res.receipts.length - 1]);
|
|
270
|
+
return ok({ sent: true, orderId: id, transactions: res.transactions });
|
|
271
|
+
}
|
|
272
|
+
return ok({ owner: from, ...res });
|
|
273
|
+
} catch (e) {
|
|
274
|
+
return fail(e);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
);
|
|
278
|
+
server.registerTool(
|
|
279
|
+
"dca_get_order",
|
|
280
|
+
{
|
|
281
|
+
title: "Get a DCA order",
|
|
282
|
+
description: "An order's state and progress, plus the contract's own verdict on its next fill.",
|
|
283
|
+
inputSchema: { id: orderId },
|
|
284
|
+
annotations: { readOnlyHint: true, openWorldHint: true }
|
|
285
|
+
},
|
|
286
|
+
async ({ id }) => {
|
|
287
|
+
try {
|
|
288
|
+
const o = await poincare.dca.order(BigInt(id));
|
|
289
|
+
if (!o) return fail(new Error(`no DCA order #${id}`));
|
|
290
|
+
const next = await poincare.dca.preview(BigInt(id));
|
|
291
|
+
return ok({ order: orderView(o), nextFill: { ...next, meaning: DCA_STATUS_TEXT[next.status] } });
|
|
292
|
+
} catch (e) {
|
|
293
|
+
return fail(e);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
);
|
|
297
|
+
server.registerTool(
|
|
298
|
+
"dca_list_orders",
|
|
299
|
+
{
|
|
300
|
+
title: "List DCA orders",
|
|
301
|
+
description: "Every DCA order an address has opened, newest last, with each one's next-fill status.",
|
|
302
|
+
inputSchema: { owner: address.optional().describe("Defaults to the configured key's address") },
|
|
303
|
+
annotations: { readOnlyHint: true, openWorldHint: true }
|
|
304
|
+
},
|
|
305
|
+
async ({ owner }) => {
|
|
306
|
+
try {
|
|
307
|
+
const orders = await poincare.dca.ordersOf(ownerOf(owner));
|
|
308
|
+
const views = await Promise.all(
|
|
309
|
+
orders.slice(-50).map(async (o) => {
|
|
310
|
+
const next = await poincare.dca.preview(o.id);
|
|
311
|
+
return { ...orderView(o), nextFill: next.status };
|
|
312
|
+
})
|
|
313
|
+
);
|
|
314
|
+
return ok({ count: orders.length, orders: views });
|
|
315
|
+
} catch (e) {
|
|
316
|
+
return fail(e);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
);
|
|
320
|
+
server.registerTool(
|
|
321
|
+
"dca_preview_slice",
|
|
322
|
+
{
|
|
323
|
+
title: "Can the next fill run now?",
|
|
324
|
+
description: "PoincareDCA.canExecute: the next fill's size, quote, floor, the spread this block, and why it would be held if it would.",
|
|
325
|
+
inputSchema: { id: orderId },
|
|
326
|
+
annotations: { readOnlyHint: true, openWorldHint: true }
|
|
327
|
+
},
|
|
328
|
+
async ({ id }) => {
|
|
329
|
+
try {
|
|
330
|
+
const p = await poincare.dca.preview(BigInt(id));
|
|
331
|
+
return ok({ ...p, meaning: DCA_STATUS_TEXT[p.status] });
|
|
332
|
+
} catch (e) {
|
|
333
|
+
return fail(e);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
);
|
|
337
|
+
const orderAction = (name, title, description, build, destructive, precheck) => server.registerTool(
|
|
338
|
+
name,
|
|
339
|
+
{ title, description, inputSchema: { id: orderId, send: sendFlag }, annotations: { readOnlyHint: false, destructiveHint: destructive, openWorldHint: true } },
|
|
340
|
+
async ({ id, send }) => {
|
|
341
|
+
try {
|
|
342
|
+
const n = BigInt(id);
|
|
343
|
+
if (precheck) await precheck(n, Boolean(send));
|
|
344
|
+
const res = await run([build(n)], send);
|
|
345
|
+
return ok({ orderId: n, sent: res.sent, transactions: res.transactions, ...res.sent ? {} : { note: res.note } });
|
|
346
|
+
} catch (e) {
|
|
347
|
+
return fail(e);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
);
|
|
351
|
+
orderAction(
|
|
352
|
+
"dca_execute_slice",
|
|
353
|
+
"Fill the next slice now",
|
|
354
|
+
"Fill the current slot's slice of your own order (keepers do this automatically; the owner may too). Checks the contract's verdict first and refuses if the fill would be held.",
|
|
355
|
+
(id) => poincare.dca.build.execute(id),
|
|
356
|
+
false,
|
|
357
|
+
async (id) => {
|
|
358
|
+
const p = await poincare.dca.preview(id);
|
|
359
|
+
if (p.status !== "ready") throw new Error(`not fillable now: ${p.status}. ${DCA_STATUS_TEXT[p.status]}`);
|
|
360
|
+
}
|
|
361
|
+
);
|
|
362
|
+
const openOrder = async (id) => {
|
|
363
|
+
const o = await poincare.dca.order(id);
|
|
364
|
+
if (!o) throw new Error(`no DCA order #${id}`);
|
|
365
|
+
if (o.cancelled || o.remaining === 0n) throw new Error(`DCA order #${id} is closed`);
|
|
366
|
+
return o;
|
|
367
|
+
};
|
|
368
|
+
const ownedOpen = async (id, send) => {
|
|
369
|
+
const o = await openOrder(id);
|
|
370
|
+
if (send && signer && o.owner.toLowerCase() !== signer.address.toLowerCase()) {
|
|
371
|
+
throw new Error(`DCA order #${id} belongs to ${o.owner}, not the configured key`);
|
|
372
|
+
}
|
|
373
|
+
return o;
|
|
374
|
+
};
|
|
375
|
+
orderAction(
|
|
376
|
+
"dca_cancel_order",
|
|
377
|
+
"Cancel a DCA order",
|
|
378
|
+
"Cancel your order and refund its unfilled budget. Only the owner can.",
|
|
379
|
+
(id) => poincare.dca.build.cancel(id),
|
|
380
|
+
true,
|
|
381
|
+
async (id, send) => void await ownedOpen(id, send)
|
|
382
|
+
);
|
|
383
|
+
orderAction(
|
|
384
|
+
"dca_close_expired",
|
|
385
|
+
"Refund an expired order",
|
|
386
|
+
"After the deadline, return an order's unfilled budget to its owner. Anyone may send this; the refund always goes to the owner.",
|
|
387
|
+
(id) => poincare.dca.build.closeExpired(id),
|
|
388
|
+
false,
|
|
389
|
+
async (id) => {
|
|
390
|
+
if (BigInt(now()) <= (await openOrder(id)).deadline) throw new Error(`DCA order #${id} has not expired yet`);
|
|
391
|
+
}
|
|
392
|
+
);
|
|
393
|
+
orderAction(
|
|
394
|
+
"dca_pause_order",
|
|
395
|
+
"Pause a DCA order",
|
|
396
|
+
"Hold your order: no buy fills until you resume it. It can still be cancelled, and with catch-up the buys it misses are made up after resuming. Owner only.",
|
|
397
|
+
(id) => poincare.dca.build.pause(id),
|
|
398
|
+
false,
|
|
399
|
+
async (id, send) => {
|
|
400
|
+
if ((await ownedOpen(id, send)).paused) throw new Error(`DCA order #${id} is already paused`);
|
|
401
|
+
}
|
|
402
|
+
);
|
|
403
|
+
orderAction(
|
|
404
|
+
"dca_resume_order",
|
|
405
|
+
"Resume a DCA order",
|
|
406
|
+
"Let a paused order fill again. Owner only.",
|
|
407
|
+
(id) => poincare.dca.build.resume(id),
|
|
408
|
+
false,
|
|
409
|
+
async (id, send) => {
|
|
410
|
+
if (!(await ownedOpen(id, send)).paused) throw new Error(`DCA order #${id} is not paused`);
|
|
411
|
+
}
|
|
412
|
+
);
|
|
413
|
+
server.registerTool(
|
|
414
|
+
"dca_edit_order",
|
|
415
|
+
{
|
|
416
|
+
title: "Edit a DCA order",
|
|
417
|
+
description: "Re-plan an open order's REMAINING budget from now: a new number of buys and interval, and optionally new protection, slippage, limit and end time. Side, recipient and budget cannot change; a paused order stays paused. Validates like the contract. Owner only.",
|
|
418
|
+
inputSchema: {
|
|
419
|
+
id: orderId,
|
|
420
|
+
slices: z.number().int().min(1).max(1e4).optional().describe("Buys to spread the remaining budget over"),
|
|
421
|
+
intervalSec: z.number().int().min(60).optional().describe("Seconds between buys"),
|
|
422
|
+
durationSec: z.number().int().min(60).optional().describe("Alternative end: the new schedule's window in seconds"),
|
|
423
|
+
deadline: z.number().int().optional().describe("Unix seconds; default one spare interval after the last new buy"),
|
|
424
|
+
maxSpreadBps: z.number().int().min(0).max(1e4).optional(),
|
|
425
|
+
pauseOnTrend: z.boolean().optional(),
|
|
426
|
+
catchUp: z.boolean().optional(),
|
|
427
|
+
maxSlippageBps: z.number().int().min(0).max(1e4).optional(),
|
|
428
|
+
limitPrice: z.union([z.string().regex(/^\d+(\.\d+)?$/), z.literal("none")]).optional().describe('USDC per WETH, or "none" to remove the limit'),
|
|
429
|
+
send: sendFlag
|
|
430
|
+
},
|
|
431
|
+
annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: true }
|
|
432
|
+
},
|
|
433
|
+
async (a) => {
|
|
434
|
+
try {
|
|
435
|
+
const id = BigInt(a.id);
|
|
436
|
+
await ownedOpen(id, Boolean(a.send));
|
|
437
|
+
const tx = await poincare.dca.build.edit(id, {
|
|
438
|
+
slices: a.slices,
|
|
439
|
+
interval: a.intervalSec,
|
|
440
|
+
duration: a.durationSec,
|
|
441
|
+
deadline: a.deadline,
|
|
442
|
+
maxSpreadBps: a.maxSpreadBps,
|
|
443
|
+
pauseOnTrend: a.pauseOnTrend,
|
|
444
|
+
catchUp: a.catchUp,
|
|
445
|
+
maxSlippageBps: a.maxSlippageBps,
|
|
446
|
+
limitPrice: a.limitPrice === "none" ? null : a.limitPrice
|
|
447
|
+
});
|
|
448
|
+
const res = await run([tx], a.send);
|
|
449
|
+
return ok({ orderId: id, sent: res.sent, transactions: res.transactions, ...res.sent ? {} : { note: res.note } });
|
|
450
|
+
} catch (e) {
|
|
451
|
+
return fail(e);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
);
|
|
455
|
+
return server;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
export {
|
|
459
|
+
createServer
|
|
460
|
+
};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
createServer
|
|
4
|
+
} from "./chunk-TWNQBRNA.js";
|
|
5
|
+
|
|
6
|
+
// src/index.ts
|
|
7
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
8
|
+
import { UNICHAIN_SEPOLIA, createPoincareClient, sendTx, withDca } from "@poincaretrade/sdk";
|
|
9
|
+
import { createPublicClient, createWalletClient, getAddress, http } from "viem";
|
|
10
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
11
|
+
import { unichainSepolia } from "viem/chains";
|
|
12
|
+
var rpcUrl = process.env.POINCARE_RPC_URL || UNICHAIN_SEPOLIA.rpcUrl;
|
|
13
|
+
var dcaAddress = process.env.POINCARE_DCA_ADDRESS;
|
|
14
|
+
var deployment = dcaAddress ? withDca(UNICHAIN_SEPOLIA, getAddress(dcaAddress)) : UNICHAIN_SEPOLIA;
|
|
15
|
+
var publicClient = createPublicClient({ chain: unichainSepolia, transport: http(rpcUrl) });
|
|
16
|
+
var poincare = createPoincareClient({ deployment, publicClient });
|
|
17
|
+
var signer;
|
|
18
|
+
var pk = process.env.POINCARE_PRIVATE_KEY?.trim();
|
|
19
|
+
if (pk) {
|
|
20
|
+
const account = privateKeyToAccount(pk.startsWith("0x") ? pk : `0x${pk}`);
|
|
21
|
+
const wallet = createWalletClient({ account, chain: unichainSepolia, transport: http(rpcUrl) });
|
|
22
|
+
signer = { address: account.address, send: (tx) => sendTx(wallet, publicClient, tx) };
|
|
23
|
+
}
|
|
24
|
+
var server = createServer({ poincare, signer });
|
|
25
|
+
await server.connect(new StdioServerTransport());
|
|
26
|
+
console.error(`poincare-mcp ready on ${deployment.name}${signer ? ` (signing as ${signer.address})` : " (read + unsigned txs only)"}`);
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import { PoincareClient, TxRequest } from '@poincaretrade/sdk';
|
|
3
|
+
import { Address, TransactionReceipt } from 'viem';
|
|
4
|
+
|
|
5
|
+
/** The user's own key, if they configured one. Without it every write tool returns unsigned txs. */
|
|
6
|
+
type Signer = {
|
|
7
|
+
address: Address;
|
|
8
|
+
send: (tx: TxRequest) => Promise<TransactionReceipt>;
|
|
9
|
+
};
|
|
10
|
+
type ServerOptions = {
|
|
11
|
+
poincare: PoincareClient;
|
|
12
|
+
signer?: Signer;
|
|
13
|
+
/** Clock override for tests. */
|
|
14
|
+
now?: () => number;
|
|
15
|
+
};
|
|
16
|
+
declare function createServer(opts: ServerOptions): McpServer;
|
|
17
|
+
|
|
18
|
+
export { type ServerOptions, type Signer, createServer };
|
package/dist/server.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,63 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@poincaretrade/mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "MCP server for the Poincaré hook: lets AI agents read the trend regime and create and manage spread-aware DCA orders.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Prakhar Srivastava",
|
|
7
|
+
"homepage": "https://www.poincaretrade.in/#/docs",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/Prakhar-30/POINCARE.git",
|
|
11
|
+
"directory": "packages/mcp"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/Prakhar-30/POINCARE/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"mcp",
|
|
18
|
+
"model-context-protocol",
|
|
19
|
+
"claude",
|
|
20
|
+
"ai-agent",
|
|
21
|
+
"uniswap",
|
|
22
|
+
"uniswap-v4",
|
|
23
|
+
"defi",
|
|
24
|
+
"dca",
|
|
25
|
+
"poincare"
|
|
26
|
+
],
|
|
27
|
+
"type": "module",
|
|
28
|
+
"bin": {
|
|
29
|
+
"poincare-mcp": "./dist/index.js"
|
|
30
|
+
},
|
|
31
|
+
"main": "./dist/server.js",
|
|
32
|
+
"types": "./dist/server.d.ts",
|
|
33
|
+
"files": [
|
|
34
|
+
"dist",
|
|
35
|
+
"skills",
|
|
36
|
+
"README.md",
|
|
37
|
+
"LICENSE"
|
|
38
|
+
],
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@modelcontextprotocol/sdk": "1.32.1",
|
|
41
|
+
"viem": "2.53.1",
|
|
42
|
+
"zod": "4.6.6",
|
|
43
|
+
"@poincaretrade/sdk": "0.1.1"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/node": "22.18.6",
|
|
47
|
+
"tsup": "8.5.1",
|
|
48
|
+
"typescript": "5.9.3",
|
|
49
|
+
"vitest": "4.1.12"
|
|
50
|
+
},
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": ">=18"
|
|
53
|
+
},
|
|
54
|
+
"publishConfig": {
|
|
55
|
+
"access": "public"
|
|
56
|
+
},
|
|
57
|
+
"scripts": {
|
|
58
|
+
"build": "tsup",
|
|
59
|
+
"typecheck": "tsc --noEmit",
|
|
60
|
+
"test": "vitest run",
|
|
61
|
+
"start": "node dist/index.js"
|
|
62
|
+
}
|
|
6
63
|
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: poincare
|
|
3
|
+
description: Read the Poincaré pool's trend regime, quote swaps and run spread-aware DCA orders through the Poincaré MCP server (Uniswap v4 hook on Unichain Sepolia, testnet). Use when the user asks whether the Poincaré WETH/USDC pool is trending, which side pays the trend spread, what a swap would return, or wants to plan, create, check, pause, resume, edit, cancel or refund a Poincaré DCA order, or to wait for a trend onset.
|
|
4
|
+
license: MIT
|
|
5
|
+
metadata:
|
|
6
|
+
version: "0.1.0"
|
|
7
|
+
requires: "@poincaretrade/mcp (MCP server, 15 tools)"
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Poincaré
|
|
11
|
+
|
|
12
|
+
Poincaré is a Uniswap v4 hook on the WETH/USDC pool. A CUSUM detector on the pool's own price
|
|
13
|
+
confirms trends at a data-dependent moment; once one is confirmed, swaps pushing **with** the trend
|
|
14
|
+
pay a spread of up to 5% (kept by liquidity providers), and the other side trades at the plain
|
|
15
|
+
price. PoincareDCA runs DCA orders whose slices can wait that spread out.
|
|
16
|
+
|
|
17
|
+
This skill tells you how to drive the `poincare` MCP server well. Everything is on **Unichain
|
|
18
|
+
Sepolia, a testnet**: test tokens carry no value. Say so when it matters (before any transaction).
|
|
19
|
+
|
|
20
|
+
## Setup
|
|
21
|
+
|
|
22
|
+
The tools below come from the Poincaré MCP server. If they are not available, tell the user to add
|
|
23
|
+
it and restart the client:
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
claude mcp add poincare -- npx -y @poincaretrade/mcp
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
For Claude Desktop or another client, the server is `npx -y @poincaretrade/mcp` (stdio). Optional
|
|
30
|
+
environment: `POINCARE_RPC_URL`, `POINCARE_DCA_ADDRESS`, and `POINCARE_PRIVATE_KEY` (only if the
|
|
31
|
+
user wants the server to broadcast; see Safety).
|
|
32
|
+
|
|
33
|
+
## Orientation (never mix these up)
|
|
34
|
+
|
|
35
|
+
- Prices are **USDC per WETH**; "up" means the chart goes up.
|
|
36
|
+
- `buy` pays USDC for WETH. `sell` pays WETH for USDC.
|
|
37
|
+
- Amounts going in are **decimal strings** in the input token: `"100"` USDC, `"0.05"` WETH.
|
|
38
|
+
- Spreads from tools are fractions (`0.0466` = 4.66%); order caps are basis points (`0` = never pay).
|
|
39
|
+
|
|
40
|
+
## Ground rules
|
|
41
|
+
|
|
42
|
+
1. **Read before you claim.** Every number you state comes from a tool result in this
|
|
43
|
+
conversation. Never estimate a price, spread or fill.
|
|
44
|
+
2. **Unsigned by default.** Write tools return unsigned transactions unless called with
|
|
45
|
+
`send: true`. Only pass `send: true` when the user has explicitly asked you to send *this*
|
|
46
|
+
action in this turn **and** a key is configured. Otherwise, hand back the transactions and say
|
|
47
|
+
they must be signed in order from the owner's wallet.
|
|
48
|
+
3. **Confirm destructive actions.** Before `dca_cancel_order` (or `dca_close_expired` on someone
|
|
49
|
+
else's behalf), restate what will be refunded and ask for a yes.
|
|
50
|
+
4. **One line first, details on request.** Lead with a plain sentence ("Buys are free right now;
|
|
51
|
+
sells pay 4.66% because a down-trend is confirmed."), then the figures.
|
|
52
|
+
|
|
53
|
+
## Workflows
|
|
54
|
+
|
|
55
|
+
### What is the market doing?
|
|
56
|
+
|
|
57
|
+
Call `get_regime`. Report, in one line: the trend (none / up / down), which side pays and how much
|
|
58
|
+
(`spread.buy`, `spread.sell`), and how close the evidence is to the threshold (`evidence.progress`,
|
|
59
|
+
0 to 1). If `gated` is true, explain that the moves read as chop, so nothing is charged. For the
|
|
60
|
+
recent past use `get_regime_history` (`blocks`, 100 to 20,000).
|
|
61
|
+
|
|
62
|
+
### What would a swap give me?
|
|
63
|
+
|
|
64
|
+
Call `quote` with `side` and `amount`. Report what comes out, the spread and the fee. If the user's
|
|
65
|
+
side is the charged side, mention the alternative: a spread-guarded DCA waits the spread out.
|
|
66
|
+
|
|
67
|
+
### Plan a spread-aware DCA
|
|
68
|
+
|
|
69
|
+
1. Translate the request into an order (table below), then call **`dca_plan_order`** first. It
|
|
70
|
+
validates exactly like the contract and says what the first fill would do right now.
|
|
71
|
+
2. Present the plan: total, number of fills, interval, end time, protection, first-fill verdict.
|
|
72
|
+
3. On the user's go-ahead, call **`dca_create_order`** with the same fields plus `owner`
|
|
73
|
+
(their address; omit only if a key is configured). It returns `[approve, createOrder]`
|
|
74
|
+
(exact-amount approval, never unlimited).
|
|
75
|
+
|
|
76
|
+
| The user says | Fields |
|
|
77
|
+
|---|---|
|
|
78
|
+
| "buy 500 USDC of WETH over a day, hourly" | `side: "buy"`, `amount: "500"`, `slices: 24`, `intervalSec: 3600` |
|
|
79
|
+
| "sell 2 WETH evenly over 4 hours" | `side: "sell"`, `amount: "2"`, `slices: 4`, `intervalSec: 3600` |
|
|
80
|
+
| "every 15 minutes, 10 times, 50 USDC each" | `amount: "500"`, `slices: 10`, `intervalSec: 900` |
|
|
81
|
+
| "never pay the trend spread" (default to this) | `maxSpreadBps: 0` |
|
|
82
|
+
| "also wait while a trend runs my way" | `maxSpreadBps: 0`, `pauseOnTrend: true` |
|
|
83
|
+
| "fill every slot whatever the spread" | `maxSpreadBps: 10000` |
|
|
84
|
+
| "don't pay more than 2,400" (buy) / "not below 2,200" (sell) | `limitPrice: "2400"` / `"2200"` |
|
|
85
|
+
|
|
86
|
+
`catchUp` defaults to true (later fills grow so the order still finishes on time); `maxSlippageBps`
|
|
87
|
+
defaults to 50. `intervalSec` must be at least 60.
|
|
88
|
+
|
|
89
|
+
### Check on orders
|
|
90
|
+
|
|
91
|
+
- `dca_list_orders` (`owner`) lists an address's orders with spent, progress and next-fill status.
|
|
92
|
+
- `dca_get_order` (`id`) for one order; `dca_preview_slice` (`id`) for the contract's verdict on
|
|
93
|
+
the next fill.
|
|
94
|
+
|
|
95
|
+
| Status | Say |
|
|
96
|
+
|---|---|
|
|
97
|
+
| `ready` | The next fill is due; the keeper fills it within a minute. |
|
|
98
|
+
| `waiting-for-slot` | This slot is done; the next opens at `nextSlotAt`. |
|
|
99
|
+
| `not-started` | Before the start time. |
|
|
100
|
+
| `spread-too-high` | Held: this side pays more than the order's cap. It fills when the spread drops; later fills catch up. |
|
|
101
|
+
| `trend-against` | Held: trend pause is on and a trend runs with this side. |
|
|
102
|
+
| `below-limit` | Held: the pool price is beyond the order's limit. |
|
|
103
|
+
| `paused` | Paused by the owner; nothing fills until resumed. |
|
|
104
|
+
| `expired` | Past the deadline; the rest can be refunded with `dca_close_expired`. |
|
|
105
|
+
| `filled` / `cancelled` | Closed. If `refunded > 0`, part of the budget was returned, not spent. |
|
|
106
|
+
|
|
107
|
+
### Change an order (owner only)
|
|
108
|
+
|
|
109
|
+
- `dca_pause_order` / `dca_resume_order` (`id`).
|
|
110
|
+
- `dca_edit_order` (`id` plus any of `slices`, `intervalSec`, `durationSec`, `deadline`,
|
|
111
|
+
`maxSpreadBps`, `pauseOnTrend`, `catchUp`, `maxSlippageBps`, `limitPrice`; `limitPrice: "none"`
|
|
112
|
+
removes the limit). It re-plans the **remaining** budget from now; side, recipient and budget are
|
|
113
|
+
fixed, and a paused order stays paused.
|
|
114
|
+
- `dca_cancel_order` (`id`): refunds what is left at once. Confirm first.
|
|
115
|
+
- `dca_close_expired` (`id`): after the deadline, anyone may call it; the refund always goes to the
|
|
116
|
+
owner.
|
|
117
|
+
- `dca_execute_slice` (`id`): the owner can fill their own due slice; refused unless `ready`.
|
|
118
|
+
|
|
119
|
+
### Wait for something to happen
|
|
120
|
+
|
|
121
|
+
`wait_for_regime_change` blocks until one of `events` happens or `timeoutSec` (5 to 300) passes:
|
|
122
|
+
`trend-started`, `trend-ended`, `trend-flipped`, `evidence-building`, `spread-engaged`,
|
|
123
|
+
`spread-released`. For longer watches, call it again in a loop and summarise each event as it
|
|
124
|
+
comes; stop when the user's condition is met.
|
|
125
|
+
|
|
126
|
+
## When a call fails
|
|
127
|
+
|
|
128
|
+
- An invalid order comes back with the contract's own reason: `deadline` (the end leaves no room
|
|
129
|
+
for every fill), `interval` (under 60 s), `slices` (1 to 10,000), `bps` (0 to 10,000),
|
|
130
|
+
`amountIn` (no amount). Explain it in those words and suggest the fix.
|
|
131
|
+
- "needs POINCARE_PRIVATE_KEY": the user asked to send but no key is configured. Return the
|
|
132
|
+
unsigned transactions instead.
|
|
133
|
+
- An action refused because it would revert now (closed order, not yet expired, already paused,
|
|
134
|
+
fill held): report the current status from `dca_get_order` rather than retrying.
|
|
135
|
+
|
|
136
|
+
## Safety
|
|
137
|
+
|
|
138
|
+
- Only suggest configuring `POINCARE_PRIVATE_KEY` with a **testnet** key the user is comfortable
|
|
139
|
+
delegating. Never ask the user to paste a key into the chat.
|
|
140
|
+
- PoincareDCA is unaudited periphery code on a testnet; the hook and Lens it reads were reviewed
|
|
141
|
+
(SFS-Labs scoped review, Olympix pre-audit scan). Say this if the user treats it as production.
|
|
142
|
+
- Docs: https://www.poincaretrade.in/#/docs
|