dero-mcp-server 0.1.2 → 0.4.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/POSITIONING.md +94 -0
- package/README.md +132 -31
- package/SKILL.md +264 -0
- package/data/docs-index.json +276 -264
- package/dist/bn254.d.ts +74 -0
- package/dist/bn254.d.ts.map +1 -0
- package/dist/bn254.js +205 -0
- package/dist/bn254.js.map +1 -0
- package/dist/citations.d.ts +140 -0
- package/dist/citations.d.ts.map +1 -0
- package/dist/citations.js +322 -0
- package/dist/citations.js.map +1 -0
- package/dist/composites/_shared.d.ts +119 -0
- package/dist/composites/_shared.d.ts.map +1 -0
- package/dist/composites/_shared.js +152 -0
- package/dist/composites/_shared.js.map +1 -0
- package/dist/composites/audit-chain-artifact-claim.d.ts +128 -0
- package/dist/composites/audit-chain-artifact-claim.d.ts.map +1 -0
- package/dist/composites/audit-chain-artifact-claim.js +305 -0
- package/dist/composites/audit-chain-artifact-claim.js.map +1 -0
- package/dist/composites/diagnose-chain-health.d.ts +64 -0
- package/dist/composites/diagnose-chain-health.d.ts.map +1 -0
- package/dist/composites/diagnose-chain-health.js +144 -0
- package/dist/composites/diagnose-chain-health.js.map +1 -0
- package/dist/composites/estimate-deploy-cost.d.ts +83 -0
- package/dist/composites/estimate-deploy-cost.d.ts.map +1 -0
- package/dist/composites/estimate-deploy-cost.js +116 -0
- package/dist/composites/estimate-deploy-cost.js.map +1 -0
- package/dist/composites/explain-smart-contract.d.ts +64 -0
- package/dist/composites/explain-smart-contract.d.ts.map +1 -0
- package/dist/composites/explain-smart-contract.js +149 -0
- package/dist/composites/explain-smart-contract.js.map +1 -0
- package/dist/composites/forge-demo-proof.d.ts +81 -0
- package/dist/composites/forge-demo-proof.d.ts.map +1 -0
- package/dist/composites/forge-demo-proof.js +204 -0
- package/dist/composites/forge-demo-proof.js.map +1 -0
- package/dist/composites/recommend-docs-path.d.ts +97 -0
- package/dist/composites/recommend-docs-path.d.ts.map +1 -0
- package/dist/composites/recommend-docs-path.js +149 -0
- package/dist/composites/recommend-docs-path.js.map +1 -0
- package/dist/composites/trace-transaction-with-context.d.ts +107 -0
- package/dist/composites/trace-transaction-with-context.d.ts.map +1 -0
- package/dist/composites/trace-transaction-with-context.js +217 -0
- package/dist/composites/trace-transaction-with-context.js.map +1 -0
- package/dist/daemon-base.d.ts +28 -0
- package/dist/daemon-base.d.ts.map +1 -0
- package/dist/daemon-base.js +62 -0
- package/dist/daemon-base.js.map +1 -0
- package/dist/dero-curve.d.ts +79 -0
- package/dist/dero-curve.d.ts.map +1 -0
- package/dist/dero-curve.js +79 -0
- package/dist/dero-curve.js.map +1 -0
- package/dist/docs-parse.d.ts.map +1 -1
- package/dist/docs-parse.js +18 -2
- package/dist/docs-parse.js.map +1 -1
- package/dist/http-server.d.ts +37 -0
- package/dist/http-server.d.ts.map +1 -0
- package/dist/http-server.js +132 -0
- package/dist/http-server.js.map +1 -0
- package/dist/index.js +18 -11
- package/dist/index.js.map +1 -1
- package/dist/proof-decode.d.ts +125 -0
- package/dist/proof-decode.d.ts.map +1 -0
- package/dist/proof-decode.js +619 -0
- package/dist/proof-decode.js.map +1 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +414 -114
- package/dist/server.js.map +1 -1
- package/dist/tool-descriptions.d.ts +53 -0
- package/dist/tool-descriptions.d.ts.map +1 -0
- package/dist/tool-descriptions.js +285 -0
- package/dist/tool-descriptions.js.map +1 -0
- package/dist/tx-parse.d.ts +63 -0
- package/dist/tx-parse.d.ts.map +1 -0
- package/dist/tx-parse.js +183 -0
- package/dist/tx-parse.js.map +1 -0
- package/package.json +27 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnose-chain-health.js","sourceRoot":"","sources":["../../src/composites/diagnose-chain-health.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,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,MAAM,OAAO,GAAG,MAAM;QACpB,CAAC,CAAC;YACE,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YACtE,MAAM,EAAE,CAAC,MAAM,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;SAC7C;QACH,CAAC,CAAC,IAAI,CAAA;IAER,OAAO,eAAe,CACpB;QACE,MAAM;QACN,SAAS;QACT,OAAO;QACP,KAAK,EAAE,SAAS;QAChB,OAAO;QACP,YAAY,EAAE;YACZ,eAAe,EAAE,aAAa,CAAC,KAAK,CAAC;YACrC,QAAQ,EAAE,KAAK,CAAC,OAAO;YACvB,SAAS,EAAE,KAAK,CAAC,QAAQ;YACzB,eAAe,EAAE,aAAa;SAC/B;KACF,EACD,uBAAuB,CACxB,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `estimate_deploy_cost` — Phase C composite #4.
|
|
3
|
+
*
|
|
4
|
+
* Wedge: `dero_get_gas_estimate` returns raw `gascompute` and
|
|
5
|
+
* `gasstorage` numbers. Agents have to know that the first is DVM
|
|
6
|
+
* execution cost and the second is on-chain byte cost — and have to
|
|
7
|
+
* separately call `dero_get_sc` to understand what they are about to
|
|
8
|
+
* deploy. This composite returns the estimate, the parsed contract
|
|
9
|
+
* surface (functions / stringkeys / uint64keys), a plain-text
|
|
10
|
+
* breakdown explaining what each number means, and the curated
|
|
11
|
+
* "Create, Deploy & Use a Smart Contract" docs page as a citation.
|
|
12
|
+
*
|
|
13
|
+
* Design contract § 4. Sequencing rule: SHIP
|
|
14
|
+
* FOURTH. Numeric semantics; relies on `extractScSurface` (composite
|
|
15
|
+
* #2) being stable. Must not ship before composite #2 because the
|
|
16
|
+
* surface enrichment proves out the reuse path planned in the design
|
|
17
|
+
* doc.
|
|
18
|
+
*
|
|
19
|
+
* Failure model:
|
|
20
|
+
* - DVM compile failure (daemon returns `RPC error -32098`) → the
|
|
21
|
+
* classifier branch in `withStructuredErrors` surfaces this as
|
|
22
|
+
* `INVALID_INPUT` with an actionable hint. The daemon's exact
|
|
23
|
+
* compile message stays in `_meta.error.raw`.
|
|
24
|
+
* - Invalid signer address → daemon usually emits `RPC error
|
|
25
|
+
* -32602` (RPC_INVALID_PARAMS); existing classifier branch
|
|
26
|
+
* handles it.
|
|
27
|
+
* - Daemon returns a non-"OK" status with 0/0 numbers → return
|
|
28
|
+
* the estimate as-is and set `breakdown: null`. NEVER fabricate
|
|
29
|
+
* a breakdown when the numbers are 0/0 with a non-success
|
|
30
|
+
* status; the agent must see the daemon's exact status string.
|
|
31
|
+
*/
|
|
32
|
+
import { z } from 'zod';
|
|
33
|
+
import { type DeroDaemonRpc } from './_shared.js';
|
|
34
|
+
export declare const estimateDeployCostInputSchema: {
|
|
35
|
+
readonly sc: z.ZodString;
|
|
36
|
+
readonly signer: z.ZodOptional<z.ZodString>;
|
|
37
|
+
readonly include_breakdown: z.ZodOptional<z.ZodBoolean>;
|
|
38
|
+
};
|
|
39
|
+
type EstimateInput = {
|
|
40
|
+
sc: string;
|
|
41
|
+
signer?: string;
|
|
42
|
+
include_breakdown?: boolean;
|
|
43
|
+
};
|
|
44
|
+
type EstimateBreakdown = {
|
|
45
|
+
compute_note: string;
|
|
46
|
+
storage_note: string;
|
|
47
|
+
total_units: number;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Pure function: turn a (gascompute, gasstorage) pair into a
|
|
51
|
+
* plain-language breakdown. Returns `null` when either number is
|
|
52
|
+
* unavailable or non-numeric, OR when the daemon returned 0/0 with a
|
|
53
|
+
* non-"OK" status (in which case fabricating a breakdown would
|
|
54
|
+
* mislead the agent — the design contract is explicit on this).
|
|
55
|
+
*
|
|
56
|
+
* The DVM denominates gas in atomic units (the daemon docs call them
|
|
57
|
+
* "gas units"). Converting to DERO requires the fee-per-gas table,
|
|
58
|
+
* which is itself a separate query. We deliberately do NOT convert
|
|
59
|
+
* here and instead surface the raw unit total plus a note pointing
|
|
60
|
+
* the agent at the docs.
|
|
61
|
+
*/
|
|
62
|
+
export declare function buildBreakdown(gascompute: number | string | undefined, gasstorage: number | string | undefined, status: string | undefined): EstimateBreakdown | null;
|
|
63
|
+
export declare function estimateDeployCost(rpc: DeroDaemonRpc, args: EstimateInput): Promise<{
|
|
64
|
+
estimate: {
|
|
65
|
+
gascompute: number | null;
|
|
66
|
+
gasstorage: number | null;
|
|
67
|
+
status: string | null;
|
|
68
|
+
};
|
|
69
|
+
breakdown: EstimateBreakdown | null;
|
|
70
|
+
signer_used: string | null;
|
|
71
|
+
include_breakdown: boolean;
|
|
72
|
+
sc_surface: {
|
|
73
|
+
functions: import("./_shared.js").DvmFunctionSignature[];
|
|
74
|
+
stringkeys: string[];
|
|
75
|
+
uint64keys: string[];
|
|
76
|
+
raw_code_length: number;
|
|
77
|
+
function_count: number;
|
|
78
|
+
};
|
|
79
|
+
} & {
|
|
80
|
+
related_docs?: import("../citations.js").DeroCitation[];
|
|
81
|
+
}>;
|
|
82
|
+
export {};
|
|
83
|
+
//# sourceMappingURL=estimate-deploy-cost.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"estimate-deploy-cost.d.ts","sourceRoot":"","sources":["../../src/composites/estimate-deploy-cost.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAGL,KAAK,aAAa,EACnB,MAAM,cAAc,CAAA;AAIrB,eAAO,MAAM,6BAA6B;;;;CAgBhC,CAAA;AAEV,KAAK,aAAa,GAAG;IACnB,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAC5B,CAAA;AASD,KAAK,iBAAiB,GAAG;IACvB,YAAY,EAAE,MAAM,CAAA;IACpB,YAAY,EAAE,MAAM,CAAA;IACpB,WAAW,EAAE,MAAM,CAAA;CACpB,CAAA;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAC5B,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,EACvC,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,EACvC,MAAM,EAAE,MAAM,GAAG,SAAS,GACzB,iBAAiB,GAAG,IAAI,CAU1B;AAED,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,aAAa,EAAE,IAAI,EAAE,aAAa;;;;;;;;;;;;;;;;;;GAgD/E"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `estimate_deploy_cost` — Phase C composite #4.
|
|
3
|
+
*
|
|
4
|
+
* Wedge: `dero_get_gas_estimate` returns raw `gascompute` and
|
|
5
|
+
* `gasstorage` numbers. Agents have to know that the first is DVM
|
|
6
|
+
* execution cost and the second is on-chain byte cost — and have to
|
|
7
|
+
* separately call `dero_get_sc` to understand what they are about to
|
|
8
|
+
* deploy. This composite returns the estimate, the parsed contract
|
|
9
|
+
* surface (functions / stringkeys / uint64keys), a plain-text
|
|
10
|
+
* breakdown explaining what each number means, and the curated
|
|
11
|
+
* "Create, Deploy & Use a Smart Contract" docs page as a citation.
|
|
12
|
+
*
|
|
13
|
+
* Design contract § 4. Sequencing rule: SHIP
|
|
14
|
+
* FOURTH. Numeric semantics; relies on `extractScSurface` (composite
|
|
15
|
+
* #2) being stable. Must not ship before composite #2 because the
|
|
16
|
+
* surface enrichment proves out the reuse path planned in the design
|
|
17
|
+
* doc.
|
|
18
|
+
*
|
|
19
|
+
* Failure model:
|
|
20
|
+
* - DVM compile failure (daemon returns `RPC error -32098`) → the
|
|
21
|
+
* classifier branch in `withStructuredErrors` surfaces this as
|
|
22
|
+
* `INVALID_INPUT` with an actionable hint. The daemon's exact
|
|
23
|
+
* compile message stays in `_meta.error.raw`.
|
|
24
|
+
* - Invalid signer address → daemon usually emits `RPC error
|
|
25
|
+
* -32602` (RPC_INVALID_PARAMS); existing classifier branch
|
|
26
|
+
* handles it.
|
|
27
|
+
* - Daemon returns a non-"OK" status with 0/0 numbers → return
|
|
28
|
+
* the estimate as-is and set `breakdown: null`. NEVER fabricate
|
|
29
|
+
* a breakdown when the numbers are 0/0 with a non-success
|
|
30
|
+
* status; the agent must see the daemon's exact status string.
|
|
31
|
+
*/
|
|
32
|
+
import { z } from 'zod';
|
|
33
|
+
import { attachCitations, extractScSurface, } from './_shared.js';
|
|
34
|
+
const DERO_ADDRESS_REGEX = /^(dero1|deto1)[0-9a-z]+$/i;
|
|
35
|
+
export const estimateDeployCostInputSchema = {
|
|
36
|
+
sc: z
|
|
37
|
+
.string()
|
|
38
|
+
.min(1)
|
|
39
|
+
.describe('DVM-BASIC contract source to deploy. MUST be the full contract (Function ... End Function blocks), not a function body alone.'),
|
|
40
|
+
signer: z
|
|
41
|
+
.string()
|
|
42
|
+
.regex(DERO_ADDRESS_REGEX, 'Expected DERO address starting with dero1 or deto1')
|
|
43
|
+
.optional()
|
|
44
|
+
.describe('Optional dero1.../deto1... signer for the eventual deploy tx.'),
|
|
45
|
+
include_breakdown: z
|
|
46
|
+
.boolean()
|
|
47
|
+
.optional()
|
|
48
|
+
.describe('Default true. Set false to return raw estimate numbers only.'),
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Pure function: turn a (gascompute, gasstorage) pair into a
|
|
52
|
+
* plain-language breakdown. Returns `null` when either number is
|
|
53
|
+
* unavailable or non-numeric, OR when the daemon returned 0/0 with a
|
|
54
|
+
* non-"OK" status (in which case fabricating a breakdown would
|
|
55
|
+
* mislead the agent — the design contract is explicit on this).
|
|
56
|
+
*
|
|
57
|
+
* The DVM denominates gas in atomic units (the daemon docs call them
|
|
58
|
+
* "gas units"). Converting to DERO requires the fee-per-gas table,
|
|
59
|
+
* which is itself a separate query. We deliberately do NOT convert
|
|
60
|
+
* here and instead surface the raw unit total plus a note pointing
|
|
61
|
+
* the agent at the docs.
|
|
62
|
+
*/
|
|
63
|
+
export function buildBreakdown(gascompute, gasstorage, status) {
|
|
64
|
+
const compute = typeof gascompute === 'number' ? gascompute : Number(gascompute);
|
|
65
|
+
const storage = typeof gasstorage === 'number' ? gasstorage : Number(gasstorage);
|
|
66
|
+
if (!Number.isFinite(compute) || !Number.isFinite(storage))
|
|
67
|
+
return null;
|
|
68
|
+
if (compute === 0 && storage === 0 && status !== 'OK')
|
|
69
|
+
return null;
|
|
70
|
+
return {
|
|
71
|
+
compute_note: `gascompute=${compute} — DVM execution cost (units the daemon charges for running the contract's Initialize and any reachable functions during the deploy). Higher when the contract has more code paths.`,
|
|
72
|
+
storage_note: `gasstorage=${storage} — on-chain byte cost (units the daemon charges for storing the contract code blob and its initial state). Roughly proportional to source length.`,
|
|
73
|
+
total_units: compute + storage,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
export async function estimateDeployCost(rpc, args) {
|
|
77
|
+
const params = { sc: args.sc };
|
|
78
|
+
if (args.signer)
|
|
79
|
+
params.signer = args.signer;
|
|
80
|
+
// Required call. DVM compile failures throw RPC error -32098 which
|
|
81
|
+
// the classifier branch in src/server.ts maps to INVALID_INPUT.
|
|
82
|
+
const raw = (await rpc('DERO.GetGasEstimate', params)) ?? {};
|
|
83
|
+
const gascompute = typeof raw.gascompute === 'number' || typeof raw.gascompute === 'string'
|
|
84
|
+
? Number(raw.gascompute)
|
|
85
|
+
: null;
|
|
86
|
+
const gasstorage = typeof raw.gasstorage === 'number' || typeof raw.gasstorage === 'string'
|
|
87
|
+
? Number(raw.gasstorage)
|
|
88
|
+
: null;
|
|
89
|
+
const status = typeof raw.status === 'string' ? raw.status : null;
|
|
90
|
+
const includeBreakdown = args.include_breakdown !== false;
|
|
91
|
+
const breakdown = includeBreakdown ? buildBreakdown(raw.gascompute, raw.gasstorage, raw.status ?? undefined) : null;
|
|
92
|
+
// Wedge enrichment: parse the SC source the user just submitted so
|
|
93
|
+
// the agent can show "you're about to deploy X functions" alongside
|
|
94
|
+
// the gas numbers. Reuses extractScSurface from composite #2, with
|
|
95
|
+
// the user-provided `sc` shaped as a DeroGetScResult so the same
|
|
96
|
+
// extractor can run unchanged.
|
|
97
|
+
const surface = extractScSurface({ code: args.sc });
|
|
98
|
+
return attachCitations({
|
|
99
|
+
estimate: {
|
|
100
|
+
gascompute,
|
|
101
|
+
gasstorage,
|
|
102
|
+
status,
|
|
103
|
+
},
|
|
104
|
+
breakdown,
|
|
105
|
+
signer_used: args.signer ?? null,
|
|
106
|
+
include_breakdown: includeBreakdown,
|
|
107
|
+
sc_surface: {
|
|
108
|
+
functions: surface.functions,
|
|
109
|
+
stringkeys: surface.stringkeys,
|
|
110
|
+
uint64keys: surface.uint64keys,
|
|
111
|
+
raw_code_length: surface.raw_code_length,
|
|
112
|
+
function_count: surface.functions.length,
|
|
113
|
+
},
|
|
114
|
+
}, 'estimate_deploy_cost');
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=estimate-deploy-cost.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"estimate-deploy-cost.js","sourceRoot":"","sources":["../../src/composites/estimate-deploy-cost.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EACL,eAAe,EACf,gBAAgB,GAEjB,MAAM,cAAc,CAAA;AAErB,MAAM,kBAAkB,GAAG,2BAA2B,CAAA;AAEtD,MAAM,CAAC,MAAM,6BAA6B,GAAG;IAC3C,EAAE,EAAE,CAAC;SACF,MAAM,EAAE;SACR,GAAG,CAAC,CAAC,CAAC;SACN,QAAQ,CACP,+HAA+H,CAChI;IACH,MAAM,EAAE,CAAC;SACN,MAAM,EAAE;SACR,KAAK,CAAC,k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AC9B,eAAe,EAAE,OAAO,CAAC,eAAe;YACxC,cAAc,EAAE,OAAO,CAAC,SAAS,CAAC,MAAM;SACzC;KACF,EACD,sBAAsB,CACvB,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `explain_smart_contract` — Phase C composite #2.
|
|
3
|
+
*
|
|
4
|
+
* Wedge-defining composite. Today an agent calls `dero_get_sc`, gets a
|
|
5
|
+
* raw code blob with stringkeys/uint64keys/balances, and must know
|
|
6
|
+
* DVM-BASIC syntax to interpret it. This composite extracts the
|
|
7
|
+
* contract's function surface and stitches it to the right bundled DVM
|
|
8
|
+
* docs page — something no generic chain MCP can replicate because no
|
|
9
|
+
* other chain MCP ships the docs index in-process.
|
|
10
|
+
*
|
|
11
|
+
* Design contract § 2. Sequencing rule: SHIP
|
|
12
|
+
* SECOND — establishes the SC-introspection pattern (`extractScSurface`)
|
|
13
|
+
* that `trace_transaction_with_context` and `estimate_deploy_cost` reuse.
|
|
14
|
+
*
|
|
15
|
+
* Failure model:
|
|
16
|
+
* - `DERO.GetSC` failing entirely → handler throws so
|
|
17
|
+
* `withStructuredErrors` surfaces a structured error to the agent.
|
|
18
|
+
* - `DERO.GetSC` succeeds but returns no `code` → response carries
|
|
19
|
+
* `surface.has_code: false`, `functions: []`, narrative explains
|
|
20
|
+
* the SCID is unknown or has no on-chain code, and `_meta.error`
|
|
21
|
+
* style hint points at `dero_docs_search("smart contract")`.
|
|
22
|
+
* - Code present but `extractScSurface` finds zero functions →
|
|
23
|
+
* return surface with `functions: []` and a narrative noting
|
|
24
|
+
* parse-uncertainty. NEVER swallow the raw code; surface
|
|
25
|
+
* `raw_code_length` so the agent knows to fall back to `dero_get_sc`.
|
|
26
|
+
*/
|
|
27
|
+
import { z } from 'zod';
|
|
28
|
+
import { type DeroDaemonRpc, type DeroScSurface } from './_shared.js';
|
|
29
|
+
export declare const explainSmartContractInputSchema: {
|
|
30
|
+
readonly scid: z.ZodString;
|
|
31
|
+
readonly topoheight: z.ZodOptional<z.ZodNumber>;
|
|
32
|
+
};
|
|
33
|
+
type ExplainInput = {
|
|
34
|
+
scid: string;
|
|
35
|
+
topoheight?: number;
|
|
36
|
+
};
|
|
37
|
+
type ContractKind = 'token' | 'registry' | 'minimal' | 'generic';
|
|
38
|
+
/**
|
|
39
|
+
* Classify a contract from its surface + raw code so we can pick the
|
|
40
|
+
* most relevant docs page as "primary". Pure function, deterministic,
|
|
41
|
+
* unit-testable. Returns the classification AND the slug to elevate.
|
|
42
|
+
*/
|
|
43
|
+
export declare function classifyContractAndPickDoc(surface: DeroScSurface, code: string): {
|
|
44
|
+
kind: ContractKind;
|
|
45
|
+
primarySlug: string;
|
|
46
|
+
};
|
|
47
|
+
export declare function explainSmartContract(rpc: DeroDaemonRpc, args: ExplainInput): Promise<{
|
|
48
|
+
scid: string;
|
|
49
|
+
topoheight: number | null;
|
|
50
|
+
kind: ContractKind;
|
|
51
|
+
surface: {
|
|
52
|
+
functions: import("./_shared.js").DvmFunctionSignature[];
|
|
53
|
+
stringkeys: string[];
|
|
54
|
+
uint64keys: string[];
|
|
55
|
+
balances: Record<string, string | number>;
|
|
56
|
+
};
|
|
57
|
+
narrative: string;
|
|
58
|
+
raw_code_length: number;
|
|
59
|
+
has_code: boolean;
|
|
60
|
+
} & {
|
|
61
|
+
related_docs?: import("../citations.js").DeroCitation[];
|
|
62
|
+
}>;
|
|
63
|
+
export {};
|
|
64
|
+
//# sourceMappingURL=explain-smart-contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"explain-smart-contract.d.ts","sourceRoot":"","sources":["../../src/composites/explain-smart-contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAGL,KAAK,aAAa,EAElB,KAAK,aAAa,EACnB,MAAM,cAAc,CAAA;AAIrB,eAAO,MAAM,+BAA+B;;;CAUlC,CAAA;AAEV,KAAK,YAAY,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAWzD,KAAK,YAAY,GAAG,OAAO,GAAG,UAAU,GAAG,SAAS,GAAG,SAAS,CAAA;AAEhE;;;;GAIG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,aAAa,EACtB,IAAI,EAAE,MAAM,GACX;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CA6B7C;AA2CD,wBAAsB,oBAAoB,CAAC,GAAG,EAAE,aAAa,EAAE,IAAI,EAAE,YAAY;;;;;;;;;;;;;;;GAmDhF"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `explain_smart_contract` — Phase C composite #2.
|
|
3
|
+
*
|
|
4
|
+
* Wedge-defining composite. Today an agent calls `dero_get_sc`, gets a
|
|
5
|
+
* raw code blob with stringkeys/uint64keys/balances, and must know
|
|
6
|
+
* DVM-BASIC syntax to interpret it. This composite extracts the
|
|
7
|
+
* contract's function surface and stitches it to the right bundled DVM
|
|
8
|
+
* docs page — something no generic chain MCP can replicate because no
|
|
9
|
+
* other chain MCP ships the docs index in-process.
|
|
10
|
+
*
|
|
11
|
+
* Design contract § 2. Sequencing rule: SHIP
|
|
12
|
+
* SECOND — establishes the SC-introspection pattern (`extractScSurface`)
|
|
13
|
+
* that `trace_transaction_with_context` and `estimate_deploy_cost` reuse.
|
|
14
|
+
*
|
|
15
|
+
* Failure model:
|
|
16
|
+
* - `DERO.GetSC` failing entirely → handler throws so
|
|
17
|
+
* `withStructuredErrors` surfaces a structured error to the agent.
|
|
18
|
+
* - `DERO.GetSC` succeeds but returns no `code` → response carries
|
|
19
|
+
* `surface.has_code: false`, `functions: []`, narrative explains
|
|
20
|
+
* the SCID is unknown or has no on-chain code, and `_meta.error`
|
|
21
|
+
* style hint points at `dero_docs_search("smart contract")`.
|
|
22
|
+
* - Code present but `extractScSurface` finds zero functions →
|
|
23
|
+
* return surface with `functions: []` and a narrative noting
|
|
24
|
+
* parse-uncertainty. NEVER swallow the raw code; surface
|
|
25
|
+
* `raw_code_length` so the agent knows to fall back to `dero_get_sc`.
|
|
26
|
+
*/
|
|
27
|
+
import { z } from 'zod';
|
|
28
|
+
import { attachCitations, extractScSurface, } from './_shared.js';
|
|
29
|
+
const SCID_HEX_REGEX = /^[0-9a-fA-F]{64}$/;
|
|
30
|
+
export const explainSmartContractInputSchema = {
|
|
31
|
+
scid: z
|
|
32
|
+
.string()
|
|
33
|
+
.regex(SCID_HEX_REGEX, 'Expected 64-character hex Smart Contract ID')
|
|
34
|
+
.describe('64-char hex Smart Contract ID'),
|
|
35
|
+
topoheight: z
|
|
36
|
+
.number()
|
|
37
|
+
.int()
|
|
38
|
+
.optional()
|
|
39
|
+
.describe('Optional topo height; omit for latest tip'),
|
|
40
|
+
};
|
|
41
|
+
// ---------------- Heuristic docs routing ----------------
|
|
42
|
+
//
|
|
43
|
+
// The four bundled DVM docs slugs we can route to. Validated by the
|
|
44
|
+
// citation CI guard via `RELATED_DOCS_BY_TOOL.explain_smart_contract`.
|
|
45
|
+
const DVM_DOC_FUNDAMENTALS = 'dvm/smart-contract-fundamentals';
|
|
46
|
+
const DVM_DOC_LANGUAGE = 'dvm/dvm-basic';
|
|
47
|
+
const DVM_DOC_DEPLOY = 'dvm/create-deploy-use-smart-contract';
|
|
48
|
+
const DVM_DOC_PLATFORM = 'dvm/dero-virtual-machine';
|
|
49
|
+
/**
|
|
50
|
+
* Classify a contract from its surface + raw code so we can pick the
|
|
51
|
+
* most relevant docs page as "primary". Pure function, deterministic,
|
|
52
|
+
* unit-testable. Returns the classification AND the slug to elevate.
|
|
53
|
+
*/
|
|
54
|
+
export function classifyContractAndPickDoc(surface, code) {
|
|
55
|
+
const functionNames = new Set(surface.functions.map((f) => f.name.toLowerCase()));
|
|
56
|
+
const codeUpper = code.toUpperCase();
|
|
57
|
+
const looksLikeToken = codeUpper.includes('SEND_ASSET_TO_ADDRESS') ||
|
|
58
|
+
functionNames.has('mint') ||
|
|
59
|
+
functionNames.has('burn') ||
|
|
60
|
+
(functionNames.has('transfer') && functionNames.has('transferownership'));
|
|
61
|
+
if (looksLikeToken) {
|
|
62
|
+
return { kind: 'token', primarySlug: DVM_DOC_LANGUAGE };
|
|
63
|
+
}
|
|
64
|
+
const looksLikeRegistry = codeUpper.includes('EXISTS(') ||
|
|
65
|
+
functionNames.has('register') ||
|
|
66
|
+
functionNames.has('lookup') ||
|
|
67
|
+
functionNames.has('reserve');
|
|
68
|
+
if (looksLikeRegistry) {
|
|
69
|
+
return { kind: 'registry', primarySlug: DVM_DOC_FUNDAMENTALS };
|
|
70
|
+
}
|
|
71
|
+
if (surface.functions.length <= 1) {
|
|
72
|
+
return { kind: 'minimal', primarySlug: DVM_DOC_DEPLOY };
|
|
73
|
+
}
|
|
74
|
+
return { kind: 'generic', primarySlug: DVM_DOC_FUNDAMENTALS };
|
|
75
|
+
}
|
|
76
|
+
// ---------------- Narrative ----------------
|
|
77
|
+
//
|
|
78
|
+
// Lives next to the composite (not in `_shared.ts`) because the shape is
|
|
79
|
+
// tightly coupled to composite #2's response. Pure function for testability.
|
|
80
|
+
function buildNarrative(scid, topoheight, surface, kind) {
|
|
81
|
+
if (!surface.has_code) {
|
|
82
|
+
return `SCID ${scid} returned no on-chain code at topoheight ${topoheight ?? 'tip'}. Either the contract does not exist or it was deployed without code. Try dero_docs_search("smart contract") for installation context, or re-check the SCID.`;
|
|
83
|
+
}
|
|
84
|
+
const fnCount = surface.functions.length;
|
|
85
|
+
const stringCount = surface.stringkeys.length;
|
|
86
|
+
const uint64Count = surface.uint64keys.length;
|
|
87
|
+
const balanceCount = Object.keys(surface.balances).length;
|
|
88
|
+
if (fnCount === 0) {
|
|
89
|
+
return `Found ${surface.raw_code_length} bytes of code at SCID ${scid} (topoheight ${topoheight ?? 'tip'}) but no DVM-BASIC Function declarations were recognized by the parser. The raw code is still available via dero_get_sc; ${stringCount} stored string keys and ${uint64Count} uint64 keys are present, with ${balanceCount} asset balance(s).`;
|
|
90
|
+
}
|
|
91
|
+
const kindPhrase = {
|
|
92
|
+
token: 'has a token-style surface (transfer/asset operations)',
|
|
93
|
+
registry: 'has a registry-style surface (Register/Lookup/EXISTS pattern)',
|
|
94
|
+
minimal: 'is a minimal contract (Initialize-only or single function)',
|
|
95
|
+
generic: 'has a generic state-machine surface',
|
|
96
|
+
};
|
|
97
|
+
const fnList = surface.functions
|
|
98
|
+
.slice(0, 6)
|
|
99
|
+
.map((f) => (f.args.length > 0 ? `${f.name}(${f.args.length}-arg)` : `${f.name}()`))
|
|
100
|
+
.join(', ');
|
|
101
|
+
const more = fnCount > 6 ? ` (+${fnCount - 6} more)` : '';
|
|
102
|
+
return `SCID ${scid} at topoheight ${topoheight ?? 'tip'} ${kindPhrase[kind]}. Exposes ${fnCount} function${fnCount === 1 ? '' : 's'}: ${fnList}${more}. State carries ${stringCount} string key${stringCount === 1 ? '' : 's'} and ${uint64Count} uint64 key${uint64Count === 1 ? '' : 's'}, with ${balanceCount} asset balance entr${balanceCount === 1 ? 'y' : 'ies'}. See the cited docs page for the DVM concept that best matches this surface.`;
|
|
103
|
+
}
|
|
104
|
+
// ---------------- Handler ----------------
|
|
105
|
+
export async function explainSmartContract(rpc, args) {
|
|
106
|
+
const params = {
|
|
107
|
+
scid: args.scid,
|
|
108
|
+
code: true,
|
|
109
|
+
variables: true,
|
|
110
|
+
};
|
|
111
|
+
if (args.topoheight !== undefined)
|
|
112
|
+
params.topoheight = args.topoheight;
|
|
113
|
+
// Required call. Failure propagates through withStructuredErrors.
|
|
114
|
+
const raw = (await rpc('DERO.GetSC', params)) ?? {};
|
|
115
|
+
const surface = extractScSurface(raw);
|
|
116
|
+
const code = typeof raw.code === 'string' ? raw.code : '';
|
|
117
|
+
const { kind, primarySlug } = classifyContractAndPickDoc(surface, code);
|
|
118
|
+
const responseTopoheight = typeof args.topoheight === 'number' && Number.isFinite(args.topoheight)
|
|
119
|
+
? args.topoheight
|
|
120
|
+
: null;
|
|
121
|
+
const narrative = buildNarrative(args.scid, responseTopoheight, surface, kind);
|
|
122
|
+
// Compose the payload, then attach static citations and re-order so the
|
|
123
|
+
// heuristic's pick is first. Static citation order (in RELATED_DOCS_BY_TOOL)
|
|
124
|
+
// ends up as the fallback order when the heuristic returns a slug already
|
|
125
|
+
// at position 0.
|
|
126
|
+
const payload = attachCitations({
|
|
127
|
+
scid: args.scid,
|
|
128
|
+
topoheight: responseTopoheight,
|
|
129
|
+
kind,
|
|
130
|
+
surface: {
|
|
131
|
+
functions: surface.functions,
|
|
132
|
+
stringkeys: surface.stringkeys,
|
|
133
|
+
uint64keys: surface.uint64keys,
|
|
134
|
+
balances: surface.balances,
|
|
135
|
+
},
|
|
136
|
+
narrative,
|
|
137
|
+
raw_code_length: surface.raw_code_length,
|
|
138
|
+
has_code: surface.has_code,
|
|
139
|
+
}, 'explain_smart_contract');
|
|
140
|
+
if (payload.related_docs && payload.related_docs.length > 0) {
|
|
141
|
+
const idx = payload.related_docs.findIndex((d) => d.slug === primarySlug);
|
|
142
|
+
if (idx > 0) {
|
|
143
|
+
const [picked] = payload.related_docs.splice(idx, 1);
|
|
144
|
+
payload.related_docs.unshift(picked);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return payload;
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=explain-smart-contract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"explain-smart-contract.js","sourceRoot":"","sources":["../../src/composites/explain-smart-contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EACL,eAAe,EACf,gBAAgB,GAIjB,MAAM,cAAc,CAAA;AAErB,MAAM,cAAc,GAAG,mBA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AAO,CAAC,QAAQ;KAC3B,EACD,wBAAwB,CACzB,CAAA;IAED,IAAI,OAAO,CAAC,YAAY,IAAI,OAAO,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC5D,MAAM,GAAG,GAAG,OAAO,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,WAAW,CAAC,CAAA;QACzE,IAAI,GAAG,GAAG,CAAC,EAAE,CAAC;YACZ,MAAM,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAA;YACpD,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QACtC,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAA;AAChB,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `dero_forge_demo_proof` — composite #7.
|
|
3
|
+
*
|
|
4
|
+
* Builds a `deroproof…` display object for a chosen transaction, ring slot,
|
|
5
|
+
* and amount. The string is constructed locally from public chain data — no
|
|
6
|
+
* wallet, no keys, no broadcast. On an unpatched explorer it shows
|
|
7
|
+
* **Verified ✓** for the chosen amount; on the chain, nothing changes.
|
|
8
|
+
*
|
|
9
|
+
* Purpose: defensive demonstration of the integrity-page Part 3 forge math
|
|
10
|
+
* (`docs/integrity/inflation-claim`, Part 3). When an AI agent is asked
|
|
11
|
+
* "does this deroproof string prove the chain minted coins?", the agent can
|
|
12
|
+
* forge an equivalent string here and show, on real chain inputs, that
|
|
13
|
+
* **Verified** is a display-layer fact about the pasted object — not a
|
|
14
|
+
* consensus statement about coins moving.
|
|
15
|
+
*
|
|
16
|
+
* Math (same equation `proof.Prove()` checks at `proof/proof.go:88-95`):
|
|
17
|
+
*
|
|
18
|
+
* blinder = C[slot] − amount × G
|
|
19
|
+
* forged_string = bech32("deroproof", version || blinder_compressed || CBOR({HH: 0…0, VU: amount}))
|
|
20
|
+
*
|
|
21
|
+
* Self-check: amount × G + blinder == C[slot]. If this fails, the encoded
|
|
22
|
+
* string would not verify and we never return it.
|
|
23
|
+
*
|
|
24
|
+
* Read-only invariant: this tool computes a string and returns it. It does
|
|
25
|
+
* NOT touch a wallet, broadcast a transaction, or mutate any chain state.
|
|
26
|
+
* Annotation `readOnlyHint: true` is preserved.
|
|
27
|
+
*/
|
|
28
|
+
import { z } from 'zod';
|
|
29
|
+
import { type DeroCitation } from '../citations.js';
|
|
30
|
+
import { type DeroDaemonRpc } from './_shared.js';
|
|
31
|
+
export declare const forgeDemoProofInputSchema: {
|
|
32
|
+
readonly tx_hash: z.ZodOptional<z.ZodString>;
|
|
33
|
+
readonly tx_hex: z.ZodOptional<z.ZodString>;
|
|
34
|
+
readonly ring_slot: z.ZodDefault<z.ZodNumber>;
|
|
35
|
+
readonly amount_dero: z.ZodDefault<z.ZodString>;
|
|
36
|
+
};
|
|
37
|
+
export type ForgeDemoProofInput = {
|
|
38
|
+
tx_hash?: string;
|
|
39
|
+
tx_hex?: string;
|
|
40
|
+
ring_slot?: number;
|
|
41
|
+
amount_dero?: string;
|
|
42
|
+
};
|
|
43
|
+
export type ForgeDemoProofResult = {
|
|
44
|
+
forged_proof_string: string;
|
|
45
|
+
target_amount: {
|
|
46
|
+
dero: string;
|
|
47
|
+
atoms_signed: string;
|
|
48
|
+
atoms_uint64: string;
|
|
49
|
+
};
|
|
50
|
+
ring_slot: number;
|
|
51
|
+
ring_size: number;
|
|
52
|
+
ring_receiver_address: string | null;
|
|
53
|
+
math: {
|
|
54
|
+
C_slot_hex: string;
|
|
55
|
+
amount_x_G_hex: string;
|
|
56
|
+
blinder_hex: string;
|
|
57
|
+
};
|
|
58
|
+
self_check: {
|
|
59
|
+
verified: boolean;
|
|
60
|
+
method: string;
|
|
61
|
+
};
|
|
62
|
+
explorer_display_amount: string;
|
|
63
|
+
context_note: string | null;
|
|
64
|
+
related_docs: DeroCitation[];
|
|
65
|
+
_diagnostics: {
|
|
66
|
+
step_latencies: Record<string, number>;
|
|
67
|
+
halted_at: string | null;
|
|
68
|
+
total_ms: number;
|
|
69
|
+
tx_source: 'tx_hash' | 'tx_hex';
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Execute the forge. Composes:
|
|
74
|
+
* 1. (optional) daemon fetch of TX hex + ring members
|
|
75
|
+
* 2. parse TX → extract C[ring_slot]
|
|
76
|
+
* 3. compute blinder = C[slot] − amount × G
|
|
77
|
+
* 4. self-check: amount × G + blinder == C[slot]
|
|
78
|
+
* 5. encode forged proof string + assemble narrative + citations
|
|
79
|
+
*/
|
|
80
|
+
export declare function forgeDemoProof(rpc: DeroDaemonRpc, input: ForgeDemoProofInput): Promise<ForgeDemoProofResult>;
|
|
81
|
+
//# sourceMappingURL=forge-demo-proof.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"forge-demo-proof.d.ts","sourceRoot":"","sources":["../../src/composites/forge-demo-proof.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAYvB,OAAO,EAGL,KAAK,YAAY,EAClB,MAAM,iBAAiB,CAAA;AAGxB,OAAO,EAKL,KAAK,aAAa,EACnB,MAAM,cAAc,CAAA;AAKrB,eAAO,MAAM,yBAAyB;;;;;CA+B5B,CAAA;AAEV,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,CAAA;AAWD,MAAM,MAAM,oBAAoB,GAAG;IACjC,mBAAmB,EAAE,MAAM,CAAA;IAC3B,aAAa,EAAE;QACb,IAAI,EAAE,MAAM,CAAA;QACZ,YAAY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