@payload-exchange/solver-agent 0.0.1 → 0.0.2
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/dist/commands/fulfill.d.ts +3 -0
- package/dist/commands/fulfill.d.ts.map +1 -0
- package/dist/commands/fulfill.js +74 -0
- package/dist/commands/fulfill.js.map +1 -0
- package/dist/commands/listen.d.ts +3 -0
- package/dist/commands/listen.d.ts.map +1 -0
- package/dist/commands/listen.js +88 -0
- package/dist/commands/listen.js.map +1 -0
- package/dist/commands/order.d.ts +3 -0
- package/dist/commands/order.d.ts.map +1 -0
- package/dist/commands/order.js +20 -0
- package/dist/commands/order.js.map +1 -0
- package/dist/commands/register.d.ts +3 -0
- package/dist/commands/register.d.ts.map +1 -0
- package/dist/commands/register.js +49 -0
- package/dist/commands/register.js.map +1 -0
- package/dist/commands/run.d.ts +3 -0
- package/dist/commands/run.d.ts.map +1 -0
- package/dist/commands/run.js +115 -0
- package/dist/commands/run.js.map +1 -0
- package/dist/index.js +14 -156
- package/dist/index.js.map +1 -1
- package/dist/lib/exec.d.ts +6 -0
- package/dist/lib/exec.d.ts.map +1 -0
- package/dist/lib/exec.js +40 -0
- package/dist/lib/exec.js.map +1 -0
- package/dist/lib/output.d.ts +5 -0
- package/dist/lib/output.d.ts.map +1 -0
- package/dist/lib/output.js +14 -0
- package/dist/lib/output.js.map +1 -0
- package/dist/lib/wallet.d.ts +24 -0
- package/dist/lib/wallet.d.ts.map +1 -0
- package/dist/lib/wallet.js +12 -0
- package/dist/lib/wallet.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fulfill.d.ts","sourceRoot":"","sources":["../../src/commands/fulfill.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAMnC,eAAO,MAAM,cAAc,SAqExB,CAAA"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { SolverClient } from "@payload-exchange/solver-sdk";
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
import { log, output } from "../lib/output.js";
|
|
5
|
+
import { resolveWallet } from "../lib/wallet.js";
|
|
6
|
+
export const fulfillCommand = new Command("fulfill")
|
|
7
|
+
.description("Submit a fulfillment result for a matched order")
|
|
8
|
+
.requiredOption("--order <id>", "Order ID")
|
|
9
|
+
.option("--result <json>", "Result as JSON string")
|
|
10
|
+
.option("--result-file <path>", "Path to file containing result JSON")
|
|
11
|
+
.option("--result-stdin", "Read result JSON from stdin")
|
|
12
|
+
.option("--proof <json>", "Proof data as JSON string")
|
|
13
|
+
.option("--proof-file <path>", "Path to file containing proof JSON")
|
|
14
|
+
.option("--execution-time <str>", "Execution time (e.g. '150ms')")
|
|
15
|
+
.option("--seller <address>", "Override seller address")
|
|
16
|
+
.action(async (_opts, cmd) => {
|
|
17
|
+
const opts = _opts;
|
|
18
|
+
const parent = cmd.parent?.opts();
|
|
19
|
+
const { address } = resolveWallet(parent.key, "solver");
|
|
20
|
+
const sellerAddress = opts.seller ?? address;
|
|
21
|
+
// Read result from one of three sources
|
|
22
|
+
let resultData;
|
|
23
|
+
if (opts.resultStdin) {
|
|
24
|
+
const chunks = [];
|
|
25
|
+
for await (const chunk of process.stdin) {
|
|
26
|
+
chunks.push(chunk);
|
|
27
|
+
}
|
|
28
|
+
resultData = JSON.parse(Buffer.concat(chunks).toString("utf-8"));
|
|
29
|
+
}
|
|
30
|
+
else if (opts.resultFile) {
|
|
31
|
+
resultData = JSON.parse(readFileSync(opts.resultFile, "utf-8"));
|
|
32
|
+
}
|
|
33
|
+
else if (opts.result) {
|
|
34
|
+
resultData = JSON.parse(opts.result);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
log("[solver] Error: provide --result, --result-file, or --result-stdin");
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
// Read optional proof
|
|
41
|
+
let proof;
|
|
42
|
+
if (opts.proofFile) {
|
|
43
|
+
proof = JSON.parse(readFileSync(opts.proofFile, "utf-8"));
|
|
44
|
+
}
|
|
45
|
+
else if (opts.proof) {
|
|
46
|
+
proof = JSON.parse(opts.proof);
|
|
47
|
+
}
|
|
48
|
+
const client = new SolverClient(parent.coordinator);
|
|
49
|
+
log(`[solver] Submitting fulfillment for order ${opts.order}...`);
|
|
50
|
+
try {
|
|
51
|
+
const response = await client.submitFulfillment({
|
|
52
|
+
orderId: opts.order,
|
|
53
|
+
sellerId: sellerAddress,
|
|
54
|
+
result: resultData,
|
|
55
|
+
proof,
|
|
56
|
+
executionTime: opts.executionTime,
|
|
57
|
+
});
|
|
58
|
+
if (response.attestation.success) {
|
|
59
|
+
const checks = response.attestation.checks ?? [];
|
|
60
|
+
const passed = checks.filter((c) => c.passed).length;
|
|
61
|
+
log(`[solver] Attestation: PASSED (${passed}/${checks.length} checks)`);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
log(`[solver] Attestation: FAILED — ${response.attestation.reason ?? "unknown"}`);
|
|
65
|
+
}
|
|
66
|
+
log(`[solver] Next step: ${response.nextStep}`);
|
|
67
|
+
output(response, !!parent.json);
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
log(`[solver] Failed: ${err.message}`);
|
|
71
|
+
process.exit(1);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
//# sourceMappingURL=fulfill.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fulfill.js","sourceRoot":"","sources":["../../src/commands/fulfill.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAA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,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAA;YACpD,GAAG,CAAC,iCAAiC,MAAM,IAAI,MAAM,CAAC,MAAM,UAAU,CAAC,CAAA;QACxE,CAAC;aAAM,CAAC;YACP,GAAG,CAAC,kCAAkC,QAAQ,CAAC,WAAW,CAAC,MAAM,IAAI,SAAS,EAAE,CAAC,CAAA;QAClF,CAAC;QACD,GAAG,CAAC,uBAAuB,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAA;QAE/C,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAChC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACd,GAAG,CAAC,oBAAqB,GAAa,CAAC,OAAO,EAAE,CAAC,CAAA;QACjD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IAChB,CAAC;AACF,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listen.d.ts","sourceRoot":"","sources":["../../src/commands/listen.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAMnC,eAAO,MAAM,aAAa,SAsGvB,CAAA"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { SolverClient } from "@payload-exchange/solver-sdk";
|
|
3
|
+
import { log, output } from "../lib/output.js";
|
|
4
|
+
import { execHandler } from "../lib/exec.js";
|
|
5
|
+
import { resolveWallet } from "../lib/wallet.js";
|
|
6
|
+
export const listenCommand = new Command("listen")
|
|
7
|
+
.description("Connect via WebSocket and stream events (pipeable)")
|
|
8
|
+
.option("--tasks <csv>", "Comma-separated task classes to subscribe to")
|
|
9
|
+
.option("--exec <command>", "Shell command to run on match (receives match JSON on stdin, stdout = result)")
|
|
10
|
+
.option("--exec-timeout <ms>", "Timeout for --exec command", "30000")
|
|
11
|
+
.option("--auto-fulfill", "Automatically submit --exec output as fulfillment")
|
|
12
|
+
.option("--seller <address>", "Override seller address")
|
|
13
|
+
.action(async (_opts, cmd) => {
|
|
14
|
+
const opts = _opts;
|
|
15
|
+
const parent = cmd.parent?.opts();
|
|
16
|
+
const { address } = resolveWallet(parent.key, "solver");
|
|
17
|
+
const sellerAddress = opts.seller ?? address;
|
|
18
|
+
const json = !!parent.json;
|
|
19
|
+
const taskClasses = opts.tasks ? opts.tasks.split(",").map((s) => s.trim()) : undefined;
|
|
20
|
+
const client = new SolverClient(parent.coordinator);
|
|
21
|
+
log(`[solver] Connecting to ${parent.coordinator}...`);
|
|
22
|
+
let connection;
|
|
23
|
+
try {
|
|
24
|
+
connection = client.connect({ taskClasses });
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
log(`[solver] WebSocket connection failed: ${err.message}`);
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
process.on("SIGINT", () => {
|
|
31
|
+
log("\n[solver] Shutting down...");
|
|
32
|
+
connection.close();
|
|
33
|
+
process.exit(0);
|
|
34
|
+
});
|
|
35
|
+
process.on("SIGTERM", () => {
|
|
36
|
+
connection.close();
|
|
37
|
+
process.exit(0);
|
|
38
|
+
});
|
|
39
|
+
for await (const event of connection.events) {
|
|
40
|
+
// Always output events
|
|
41
|
+
output({ event: event.event, data: event.data, timestamp: event.timestamp }, json);
|
|
42
|
+
// On match assigned to us, optionally exec
|
|
43
|
+
if (event.event === "order_matched") {
|
|
44
|
+
const data = event.data;
|
|
45
|
+
if (data.seller !== sellerAddress)
|
|
46
|
+
continue;
|
|
47
|
+
log(`[solver] Matched! Order: ${data.orderId} — ${data.intent} ($${data.agreedPrice})`);
|
|
48
|
+
if (opts.exec) {
|
|
49
|
+
const execTimeout = Number.parseInt(opts.execTimeout, 10);
|
|
50
|
+
log(`[solver] Running: ${opts.exec}`);
|
|
51
|
+
try {
|
|
52
|
+
const resultStr = await execHandler(opts.exec, JSON.stringify(data), execTimeout);
|
|
53
|
+
let resultData;
|
|
54
|
+
try {
|
|
55
|
+
resultData = JSON.parse(resultStr);
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
resultData = resultStr;
|
|
59
|
+
}
|
|
60
|
+
if (opts.autoFulfill) {
|
|
61
|
+
log("[solver] Auto-fulfilling...");
|
|
62
|
+
const response = await client.submitFulfillment({
|
|
63
|
+
orderId: data.orderId,
|
|
64
|
+
sellerId: sellerAddress,
|
|
65
|
+
result: resultData,
|
|
66
|
+
});
|
|
67
|
+
if (response.attestation.success) {
|
|
68
|
+
log(`[solver] Attestation: PASSED`);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
log(`[solver] Attestation: FAILED — ${response.attestation.reason ?? "unknown"}`);
|
|
72
|
+
}
|
|
73
|
+
output(response, json);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
log(`[solver] Exec result (use "px-solver fulfill" to submit):`);
|
|
77
|
+
output({ orderId: data.orderId, result: resultData }, json);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
log(`[solver] Exec failed: ${err.message}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
log("[solver] Connection closed.");
|
|
87
|
+
});
|
|
88
|
+
//# sourceMappingURL=listen.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listen.js","sourceRoot":"","sources":["../../src/commands/listen.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAC3D,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CA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C,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"order.d.ts","sourceRoot":"","sources":["../../src/commands/order.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAInC,eAAO,MAAM,YAAY,SAgBtB,CAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { SolverClient } from "@payload-exchange/solver-sdk";
|
|
3
|
+
import { log, output } from "../lib/output.js";
|
|
4
|
+
export const orderCommand = new Command("order")
|
|
5
|
+
.description("Inspect an order's details (constraints, status, etc.)")
|
|
6
|
+
.requiredOption("--order <id>", "Order ID")
|
|
7
|
+
.action(async (_opts, cmd) => {
|
|
8
|
+
const opts = _opts;
|
|
9
|
+
const parent = cmd.parent?.opts();
|
|
10
|
+
const client = new SolverClient(parent.coordinator);
|
|
11
|
+
try {
|
|
12
|
+
const result = await client.getOrder(opts.order);
|
|
13
|
+
output(result, !!parent.json);
|
|
14
|
+
}
|
|
15
|
+
catch (err) {
|
|
16
|
+
log(`[solver] Failed: ${err.message}`);
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
//# sourceMappingURL=order.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"order.js","sourceRoot":"","sources":["../../src/commands/order.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAC3D,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAE9C,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC;KAC9C,WAAW,CAAC,wDAAwD,CAAC;KACrE,cAAc,CAAC,cAAc,EAAE,UAAU,CAAC;KAC1C,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;IAC5B,MAAM,IAAI,GAAG,KAA0B,CAAA;IACvC,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,IAAI,EAA6C,CAAA;IAE5E,MAAM,MAAM,GAAG,IAAI,YAAY,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;IAEnD,IAAI,CAAC;QACJ,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QAChD,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAC9B,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACd,GAAG,CAAC,oBAAqB,GAAa,CAAC,OAAO,EAAE,CAAC,CAAA;QACjD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IAChB,CAAC;AACF,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../src/commands/register.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAOnC,eAAO,MAAM,eAAe,SA6CzB,CAAA"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { SolverClient } from "@payload-exchange/solver-sdk";
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
import { log, output } from "../lib/output.js";
|
|
5
|
+
import { resolveWallet } from "../lib/wallet.js";
|
|
6
|
+
export const registerCommand = new Command("register")
|
|
7
|
+
.description("Register solver capabilities (sell order) with the coordinator")
|
|
8
|
+
.requiredOption("--tasks <csv>", "Comma-separated task classes")
|
|
9
|
+
.requiredOption("--price <n>", "Fee per task in USDC")
|
|
10
|
+
.option("--pricing-model <model>", "Pricing model (fixed, percentage, auction, dynamic)", "fixed")
|
|
11
|
+
.option("--stake <n>", "Stake amount", "0")
|
|
12
|
+
.option("--execution-terms <json>", "Execution terms as JSON string")
|
|
13
|
+
.option("--execution-terms-file <path>", "Path to JSON file with execution terms")
|
|
14
|
+
.option("--seller <address>", "Override seller address (default: derived from --key)")
|
|
15
|
+
.action(async (_opts, cmd) => {
|
|
16
|
+
const opts = _opts;
|
|
17
|
+
const parent = cmd.parent?.opts();
|
|
18
|
+
const { address } = resolveWallet(parent.key, "solver");
|
|
19
|
+
const sellerAddress = opts.seller ?? address;
|
|
20
|
+
const taskClasses = opts.tasks.split(",").map((s) => s.trim());
|
|
21
|
+
let executionTerms;
|
|
22
|
+
if (opts.executionTermsFile) {
|
|
23
|
+
executionTerms = JSON.parse(readFileSync(opts.executionTermsFile, "utf-8"));
|
|
24
|
+
}
|
|
25
|
+
else if (opts.executionTerms) {
|
|
26
|
+
executionTerms = JSON.parse(opts.executionTerms);
|
|
27
|
+
}
|
|
28
|
+
const client = new SolverClient(parent.coordinator);
|
|
29
|
+
log(`[solver] Coordinator: ${parent.coordinator}`);
|
|
30
|
+
log(`[solver] Seller: ${sellerAddress}`);
|
|
31
|
+
log(`[solver] Registering for: ${taskClasses.join(", ")}`);
|
|
32
|
+
try {
|
|
33
|
+
const result = await client.register({
|
|
34
|
+
seller: sellerAddress,
|
|
35
|
+
supportedTaskClasses: taskClasses,
|
|
36
|
+
pricingModel: (opts.pricingModel ?? "fixed"),
|
|
37
|
+
price: Number.parseFloat(opts.price),
|
|
38
|
+
stake: Number.parseFloat(opts.stake ?? "0"),
|
|
39
|
+
executionTerms,
|
|
40
|
+
});
|
|
41
|
+
log(`[solver] Registered: ${result.id} (status: ${result.status})`);
|
|
42
|
+
output(result, !!parent.json);
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
log(`[solver] Failed: ${err.message}`);
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.js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,CAAC,CAAC,CAAC,CAAA;IAChB,CAAC;AACF,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/commands/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAQnC,eAAO,MAAM,UAAU,SAmIpB,CAAA"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { SolverClient } from "@payload-exchange/solver-sdk";
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
import { log, output } from "../lib/output.js";
|
|
5
|
+
import { execHandler } from "../lib/exec.js";
|
|
6
|
+
import { resolveWallet } from "../lib/wallet.js";
|
|
7
|
+
export const runCommand = new Command("run")
|
|
8
|
+
.description("Full lifecycle: register → listen → auto-fulfill via --exec")
|
|
9
|
+
.requiredOption("--tasks <csv>", "Comma-separated task classes")
|
|
10
|
+
.requiredOption("--price <n>", "Fee per task in USDC")
|
|
11
|
+
.requiredOption("--exec <command>", "Shell command to run on match (receives match JSON on stdin)")
|
|
12
|
+
.option("--pricing-model <model>", "Pricing model", "fixed")
|
|
13
|
+
.option("--stake <n>", "Stake amount", "0")
|
|
14
|
+
.option("--execution-terms <json>", "Execution terms as JSON string")
|
|
15
|
+
.option("--execution-terms-file <path>", "Path to JSON file with execution terms")
|
|
16
|
+
.option("--exec-timeout <ms>", "Timeout for --exec command", "30000")
|
|
17
|
+
.option("--seller <address>", "Override seller address")
|
|
18
|
+
.action(async (_opts, cmd) => {
|
|
19
|
+
const opts = _opts;
|
|
20
|
+
const parent = cmd.parent?.opts();
|
|
21
|
+
const { address } = resolveWallet(parent.key, "solver");
|
|
22
|
+
const sellerAddress = opts.seller ?? address;
|
|
23
|
+
const json = !!parent.json;
|
|
24
|
+
const taskClasses = opts.tasks.split(",").map((s) => s.trim());
|
|
25
|
+
let executionTerms;
|
|
26
|
+
if (opts.executionTermsFile) {
|
|
27
|
+
executionTerms = JSON.parse(readFileSync(opts.executionTermsFile, "utf-8"));
|
|
28
|
+
}
|
|
29
|
+
else if (opts.executionTerms) {
|
|
30
|
+
executionTerms = JSON.parse(opts.executionTerms);
|
|
31
|
+
}
|
|
32
|
+
const client = new SolverClient(parent.coordinator);
|
|
33
|
+
// 1. Register
|
|
34
|
+
log(`[solver] Coordinator: ${parent.coordinator}`);
|
|
35
|
+
log(`[solver] Wallet: ${sellerAddress}`);
|
|
36
|
+
log(`[solver] Registering for: ${taskClasses.join(", ")}`);
|
|
37
|
+
try {
|
|
38
|
+
const reg = await client.register({
|
|
39
|
+
seller: sellerAddress,
|
|
40
|
+
supportedTaskClasses: taskClasses,
|
|
41
|
+
pricingModel: (opts.pricingModel ?? "fixed"),
|
|
42
|
+
price: Number.parseFloat(opts.price),
|
|
43
|
+
stake: Number.parseFloat(opts.stake ?? "0"),
|
|
44
|
+
executionTerms,
|
|
45
|
+
});
|
|
46
|
+
log(`[solver] Registered: ${reg.id}`);
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
log(`[solver] Registration failed: ${err.message}`);
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
// 2. Listen + auto-fulfill
|
|
53
|
+
log("[solver] Listening for matches...");
|
|
54
|
+
const connection = client.connect({ taskClasses });
|
|
55
|
+
process.on("SIGINT", () => {
|
|
56
|
+
log("\n[solver] Shutting down...");
|
|
57
|
+
connection.close();
|
|
58
|
+
process.exit(0);
|
|
59
|
+
});
|
|
60
|
+
process.on("SIGTERM", () => {
|
|
61
|
+
connection.close();
|
|
62
|
+
process.exit(0);
|
|
63
|
+
});
|
|
64
|
+
const execTimeout = Number.parseInt(opts.execTimeout ?? "30000", 10);
|
|
65
|
+
for await (const event of connection.events) {
|
|
66
|
+
if (event.event === "subscribed") {
|
|
67
|
+
log(`[solver] Subscribed to ${taskClasses.join(", ")}`);
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (event.event === "order_matched") {
|
|
71
|
+
const data = event.data;
|
|
72
|
+
if (data.seller !== sellerAddress)
|
|
73
|
+
continue;
|
|
74
|
+
log(`[solver] Match: ${data.orderId} — ${data.intent} ($${data.agreedPrice})`);
|
|
75
|
+
log(`[solver] Running: ${opts.exec}`);
|
|
76
|
+
try {
|
|
77
|
+
const resultStr = await execHandler(opts.exec, JSON.stringify(data), execTimeout);
|
|
78
|
+
let resultData;
|
|
79
|
+
try {
|
|
80
|
+
resultData = JSON.parse(resultStr);
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
resultData = resultStr;
|
|
84
|
+
}
|
|
85
|
+
const response = await client.submitFulfillment({
|
|
86
|
+
orderId: data.orderId,
|
|
87
|
+
sellerId: sellerAddress,
|
|
88
|
+
result: resultData,
|
|
89
|
+
});
|
|
90
|
+
if (response.attestation.success) {
|
|
91
|
+
const checks = response.attestation.checks ?? [];
|
|
92
|
+
log(`[solver] Attestation: PASSED (${checks.filter((c) => c.passed).length}/${checks.length})`);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
log(`[solver] Attestation: FAILED — ${response.attestation.reason ?? "unknown"}`);
|
|
96
|
+
}
|
|
97
|
+
output(response, json);
|
|
98
|
+
}
|
|
99
|
+
catch (err) {
|
|
100
|
+
log(`[solver] Exec/fulfill failed: ${err.message}`);
|
|
101
|
+
}
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
if (event.event === "settlement_complete") {
|
|
105
|
+
const data = event.data;
|
|
106
|
+
log(`[solver] Paid! $${data.sellerReceived}${data.txHash ? ` (tx: ${data.txHash})` : ""}`);
|
|
107
|
+
}
|
|
108
|
+
// Stream all events when --json
|
|
109
|
+
if (json) {
|
|
110
|
+
output(event, true);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
log("[solver] Connection closed.");
|
|
114
|
+
});
|
|
115
|
+
//# sourceMappingURL=run.js.map
|
|
@@ -0,0 +1 @@
|
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,CAAC;QAED,IAAI,KAAK,CAAC,KAAK,KAAK,qBAAqB,EAAE,CAAC;YAC3C,MAAM,IAAI,GAAG,KAAK,CAAC,IAAoE,CAAA;YACvF,GAAG,CAAC,mBAAmB,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;QAC3F,CAAC;QAED,gCAAgC;QAChC,IAAI,IAAI,EAAE,CAAC;YACV,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;QACpB,CAAC;IACF,CAAC;IAED,GAAG,CAAC,6BAA6B,CAAC,CAAA;AACnC,CAAC,CAAC,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,163 +1,21 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Command } from "commander";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { registerCommand } from "./commands/register.js";
|
|
4
|
+
import { orderCommand } from "./commands/order.js";
|
|
5
|
+
import { listenCommand } from "./commands/listen.js";
|
|
6
|
+
import { fulfillCommand } from "./commands/fulfill.js";
|
|
7
|
+
import { runCommand } from "./commands/run.js";
|
|
5
8
|
const program = new Command()
|
|
6
9
|
.name("px-solver")
|
|
7
|
-
.description("
|
|
10
|
+
.description("payload.exchange solver CLI — register, listen for matches, fulfill orders")
|
|
11
|
+
.version("0.0.2")
|
|
8
12
|
.option("--coordinator <url>", "Coordinator URL", process.env.COORDINATOR_URL ?? "https://px-test.fly.dev")
|
|
9
13
|
.option("--key <hex>", "Tempo private key (hex)", process.env.TEMPO_PRIVATE_KEY)
|
|
10
|
-
.option("--
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const account = privateKeyToAccount(privateKey);
|
|
18
|
-
const solverAddress = account.address;
|
|
19
|
-
const hasKey = !!opts.key;
|
|
20
|
-
const taskClasses = opts.tasks.split(",").map((s) => s.trim());
|
|
21
|
-
/**
|
|
22
|
-
* Mock price fetcher. Returns simulated price data for any token pair.
|
|
23
|
-
* Replace with real API calls (CoinGecko, Binance, etc.) in production.
|
|
24
|
-
*/
|
|
25
|
-
async function fetchPrices(token) {
|
|
26
|
-
const now = Math.floor(Date.now() / 1000);
|
|
27
|
-
// Simulated prices with small variance
|
|
28
|
-
const base = token.toUpperCase().includes("ETH") ? 3421.5 : 1.0;
|
|
29
|
-
const variance = () => base * (1 + (Math.random() - 0.5) * 0.002);
|
|
30
|
-
const sources = [
|
|
31
|
-
{ name: "binance", price: Number(variance().toFixed(2)), timestamp: now - 2 },
|
|
32
|
-
{ name: "coinbase", price: Number(variance().toFixed(2)), timestamp: now - 5 },
|
|
33
|
-
{ name: "kraken", price: Number(variance().toFixed(2)), timestamp: now - 3 },
|
|
34
|
-
];
|
|
35
|
-
const twap = Number((sources.reduce((sum, s) => sum + s.price, 0) / sources.length).toFixed(2));
|
|
36
|
-
return { twap, sources };
|
|
37
|
-
}
|
|
38
|
-
async function main() {
|
|
39
|
-
const client = new SolverClient(coordinatorUrl);
|
|
40
|
-
// 1. Register as a solver
|
|
41
|
-
console.log(`[solver] Coordinator: ${coordinatorUrl}`);
|
|
42
|
-
console.log(`[solver] Wallet: ${solverAddress}`);
|
|
43
|
-
if (!hasKey) {
|
|
44
|
-
console.log("[solver] No --key set — generated ephemeral wallet");
|
|
45
|
-
}
|
|
46
|
-
console.log(`[solver] Registering for tasks: ${taskClasses.join(", ")}...`);
|
|
47
|
-
let registration;
|
|
48
|
-
try {
|
|
49
|
-
registration = await client.register({
|
|
50
|
-
seller: solverAddress,
|
|
51
|
-
supportedTaskClasses: taskClasses,
|
|
52
|
-
pricingModel: "fixed",
|
|
53
|
-
price: Number.parseFloat(opts.price),
|
|
54
|
-
stake: Number.parseFloat(opts.stake),
|
|
55
|
-
executionTerms: {
|
|
56
|
-
maxLatency: "5s",
|
|
57
|
-
minSources: 3,
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
catch (err) {
|
|
62
|
-
console.error("[solver] Failed to register:", err.message);
|
|
63
|
-
console.error("[solver] Is the coordinator running at", coordinatorUrl, "?");
|
|
64
|
-
process.exit(1);
|
|
65
|
-
}
|
|
66
|
-
console.log(`[solver] Registered: ${registration.id} (stake: $${opts.stake})`);
|
|
67
|
-
// 2. Connect to WebSocket for match notifications
|
|
68
|
-
console.log("[solver] Watching for intents...");
|
|
69
|
-
let connection;
|
|
70
|
-
try {
|
|
71
|
-
connection = client.connect({ taskClasses });
|
|
72
|
-
}
|
|
73
|
-
catch (err) {
|
|
74
|
-
console.error("[solver] WebSocket connection failed:", err.message);
|
|
75
|
-
process.exit(1);
|
|
76
|
-
}
|
|
77
|
-
// Handle graceful shutdown
|
|
78
|
-
process.on("SIGINT", () => {
|
|
79
|
-
console.log("\n[solver] Shutting down...");
|
|
80
|
-
connection.close();
|
|
81
|
-
process.exit(0);
|
|
82
|
-
});
|
|
83
|
-
process.on("SIGTERM", () => {
|
|
84
|
-
console.log("\n[solver] Shutting down...");
|
|
85
|
-
connection.close();
|
|
86
|
-
process.exit(0);
|
|
87
|
-
});
|
|
88
|
-
for await (const event of connection.events) {
|
|
89
|
-
console.log(`[solver] Event: ${event.event}`);
|
|
90
|
-
if (event.event === "subscribed") {
|
|
91
|
-
console.log(`[solver] Subscribed to ${taskClasses.join(", ")} intents`);
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
// Handle new_intent — this means the coordinator broadcast an intent we should look at
|
|
95
|
-
if (event.event === "new_intent") {
|
|
96
|
-
const data = event.data;
|
|
97
|
-
console.log(`[solver] New intent received! Order: ${data.orderId}`);
|
|
98
|
-
console.log(`[solver] Intent: ${data.intent}`);
|
|
99
|
-
console.log(`[solver] Max fee: $${data.maxPrice}`);
|
|
100
|
-
// Wait briefly for the matching engine to process
|
|
101
|
-
await new Promise((resolve) => setTimeout(resolve, 2_000));
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
// Handle match — this means we've been assigned to an order
|
|
105
|
-
if (event.event === "order_matched") {
|
|
106
|
-
const data = event.data;
|
|
107
|
-
// Only act on matches assigned to us
|
|
108
|
-
if (data.seller !== solverAddress)
|
|
109
|
-
continue;
|
|
110
|
-
console.log(`[solver] Match received! Order: ${data.orderId}`);
|
|
111
|
-
console.log(`[solver] Intent: ${data.intent}`);
|
|
112
|
-
console.log(`[solver] Agreed price: $${data.agreedPrice}`);
|
|
113
|
-
// Fetch price data
|
|
114
|
-
console.log("[solver] Fetching prices...");
|
|
115
|
-
const priceData = await fetchPrices(data.intent);
|
|
116
|
-
console.log(`[solver] TWAP: $${priceData.twap} from ${priceData.sources.length} sources`);
|
|
117
|
-
// Submit fulfillment
|
|
118
|
-
console.log("[solver] Submitting fulfillment...");
|
|
119
|
-
try {
|
|
120
|
-
const response = await client.submitFulfillment({
|
|
121
|
-
orderId: data.orderId,
|
|
122
|
-
sellerId: solverAddress,
|
|
123
|
-
result: priceData,
|
|
124
|
-
proof: {
|
|
125
|
-
source_urls: priceData.sources.map((s) => `https://api.${s.name}.com/v1/ticker`),
|
|
126
|
-
timestamps: priceData.sources.map((s) => s.timestamp),
|
|
127
|
-
methodology: "TWAP",
|
|
128
|
-
},
|
|
129
|
-
executionTime: `${Date.now() - event.timestamp}ms`,
|
|
130
|
-
});
|
|
131
|
-
if (response.attestation.success) {
|
|
132
|
-
const checkCount = response.attestation.checks?.length ?? 0;
|
|
133
|
-
const passedCount = response.attestation.checks?.filter((c) => c.passed).length ?? 0;
|
|
134
|
-
console.log(`[solver] Attestation: PASSED (${passedCount}/${checkCount} checks)`);
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
console.log(`[solver] Attestation: FAILED - ${response.attestation.reason ?? "unknown reason"}`);
|
|
138
|
-
}
|
|
139
|
-
console.log(`[solver] Next step: ${response.nextStep}`);
|
|
140
|
-
console.log("[solver] Waiting for buyer payment...");
|
|
141
|
-
}
|
|
142
|
-
catch (err) {
|
|
143
|
-
console.error("[solver] Fulfillment failed:", err.message);
|
|
144
|
-
}
|
|
145
|
-
continue;
|
|
146
|
-
}
|
|
147
|
-
// Log settlement events
|
|
148
|
-
if (event.event === "settlement_complete") {
|
|
149
|
-
const data = event.data;
|
|
150
|
-
console.log(`[solver] Settlement complete for order ${data.orderId}`);
|
|
151
|
-
console.log(`[solver] Received: $${data.sellerReceived}`);
|
|
152
|
-
if (data.txHash) {
|
|
153
|
-
console.log(`[solver] Tx: ${data.txHash}`);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
console.log("[solver] WebSocket connection closed.");
|
|
158
|
-
}
|
|
159
|
-
main().catch((err) => {
|
|
160
|
-
console.error("[solver] Fatal error:", err);
|
|
161
|
-
process.exit(1);
|
|
162
|
-
});
|
|
14
|
+
.option("--json", "Output raw JSON (stdout stays clean for piping)");
|
|
15
|
+
program.addCommand(registerCommand);
|
|
16
|
+
program.addCommand(orderCommand);
|
|
17
|
+
program.addCommand(listenCommand);
|
|
18
|
+
program.addCommand(fulfillCommand);
|
|
19
|
+
program.addCommand(runCommand);
|
|
20
|
+
program.parse();
|
|
163
21
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAE9C,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE;KAC3B,IAAI,CAAC,WAAW,CAAC;KACjB,WAAW,CAAC,4EAA4E,CAAC;KACzF,OAAO,CAAC,OAAO,CAAC;KAChB,MAAM,CAAC,qBAAqB,EAAE,iBAAiB,EAAE,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,yBAAyB,CAAC;KAC1G,MAAM,CAAC,aAAa,EAAE,yBAAyB,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;KAC/E,MAAM,CAAC,QAAQ,EAAE,iDAAiD,CAAC,CAAA;AAErE,OAAO,CAAC,UAAU,CAAC,eAAe,CAAC,CAAA;AACnC,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,CAAA;AAChC,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC,CAAA;AACjC,OAAO,CAAC,UAAU,CAAC,cAAc,CAAC,CAAA;AAClC,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,CAAA;AAE9B,OAAO,CAAC,KAAK,EAAE,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spawn a shell command, pipe `input` to stdin, capture stdout.
|
|
3
|
+
* Returns the stdout string. Rejects on non-zero exit or timeout.
|
|
4
|
+
*/
|
|
5
|
+
export declare function execHandler(command: string, input: string, timeout: number): Promise<string>;
|
|
6
|
+
//# sourceMappingURL=exec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exec.d.ts","sourceRoot":"","sources":["../../src/lib/exec.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAuC5F"}
|
package/dist/lib/exec.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
/**
|
|
3
|
+
* Spawn a shell command, pipe `input` to stdin, capture stdout.
|
|
4
|
+
* Returns the stdout string. Rejects on non-zero exit or timeout.
|
|
5
|
+
*/
|
|
6
|
+
export function execHandler(command, input, timeout) {
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
const child = spawn("sh", ["-c", command], {
|
|
9
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
10
|
+
});
|
|
11
|
+
let stdout = "";
|
|
12
|
+
let stderr = "";
|
|
13
|
+
child.stdout.on("data", (chunk) => {
|
|
14
|
+
stdout += chunk.toString();
|
|
15
|
+
});
|
|
16
|
+
child.stderr.on("data", (chunk) => {
|
|
17
|
+
stderr += chunk.toString();
|
|
18
|
+
});
|
|
19
|
+
const timer = setTimeout(() => {
|
|
20
|
+
child.kill("SIGTERM");
|
|
21
|
+
reject(new Error(`exec timed out after ${timeout}ms`));
|
|
22
|
+
}, timeout);
|
|
23
|
+
child.on("close", (code) => {
|
|
24
|
+
clearTimeout(timer);
|
|
25
|
+
if (code === 0) {
|
|
26
|
+
resolve(stdout.trim());
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
reject(new Error(`exec exited with code ${code}: ${stderr.trim()}`));
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
child.on("error", (err) => {
|
|
33
|
+
clearTimeout(timer);
|
|
34
|
+
reject(err);
|
|
35
|
+
});
|
|
36
|
+
child.stdin.write(input);
|
|
37
|
+
child.stdin.end();
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=exec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exec.js","sourceRoot":"","sources":["../../src/lib/exec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAE1C;;;GAGG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AAC,CAAA;QAEF,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;YACzB,YAAY,CAAC,KAAK,CAAC,CAAA;YACnB,MAAM,CAAC,GAAG,CAAC,CAAA;QACZ,CAAC,CAAC,CAAA;QAEF,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QACxB,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,CAAA;IAClB,CAAC,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Log diagnostic message to stderr (keeps stdout clean for piping) */
|
|
2
|
+
export declare function log(msg: string): void;
|
|
3
|
+
/** Write structured result to stdout */
|
|
4
|
+
export declare function output(data: unknown, json: boolean): void;
|
|
5
|
+
//# sourceMappingURL=output.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/lib/output.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,wBAAgB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAErC;AAED,wCAAwC;AACxC,wBAAgB,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,CAMzD"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Log diagnostic message to stderr (keeps stdout clean for piping) */
|
|
2
|
+
export function log(msg) {
|
|
3
|
+
process.stderr.write(`${msg}\n`);
|
|
4
|
+
}
|
|
5
|
+
/** Write structured result to stdout */
|
|
6
|
+
export function output(data, json) {
|
|
7
|
+
if (json) {
|
|
8
|
+
process.stdout.write(`${JSON.stringify(data)}\n`);
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
process.stdout.write(`${typeof data === "string" ? data : JSON.stringify(data, null, 2)}\n`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.js","sourceRoot":"","sources":["../../src/lib/output.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,MAAM,UAAU,GAAG,CAAC,GAAW;IAC9B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,GAAG,IAAI,CAAC,CAAA;AACjC,CAAC;AAED,wCAAwC;AACxC,MAAM,UAAU,MAAM,CAAC,IAAa,EAAE,IAAa;IAClD,IAAI,IAAI,EAAE,CAAC;QACV,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAClD,CAAC;SAAM,CAAC;QACP,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAA;IAC7F,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare function resolveWallet(key: string | undefined, label: string): {
|
|
2
|
+
privateKey: `0x${string}`;
|
|
3
|
+
account: {
|
|
4
|
+
address: import("abitype").Address;
|
|
5
|
+
nonceManager?: import("viem").NonceManager | undefined;
|
|
6
|
+
sign: (parameters: {
|
|
7
|
+
hash: import("viem").Hash;
|
|
8
|
+
}) => Promise<import("viem").Hex>;
|
|
9
|
+
signAuthorization: (parameters: import("viem").AuthorizationRequest) => Promise<import("viem/accounts").SignAuthorizationReturnType>;
|
|
10
|
+
signMessage: ({ message }: {
|
|
11
|
+
message: import("viem").SignableMessage;
|
|
12
|
+
}) => Promise<import("viem").Hex>;
|
|
13
|
+
signTransaction: <serializer extends import("viem").SerializeTransactionFn<import("viem").TransactionSerializable> = import("viem").SerializeTransactionFn<import("viem").TransactionSerializable>, transaction extends Parameters<serializer>[0] = Parameters<serializer>[0]>(transaction: transaction, options?: {
|
|
14
|
+
serializer?: serializer | undefined;
|
|
15
|
+
} | undefined) => Promise<import("viem").Hex>;
|
|
16
|
+
signTypedData: <const typedData extends import("abitype").TypedData | Record<string, unknown>, primaryType extends keyof typedData | "EIP712Domain" = keyof typedData>(parameters: import("viem").TypedDataDefinition<typedData, primaryType>) => Promise<import("viem").Hex>;
|
|
17
|
+
publicKey: import("viem").Hex;
|
|
18
|
+
source: "privateKey";
|
|
19
|
+
type: "local";
|
|
20
|
+
};
|
|
21
|
+
address: `0x${string}`;
|
|
22
|
+
hasKey: boolean;
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=wallet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/lib/wallet.ts"],"names":[],"mappings":"AAGA,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,MAAM;;;;;;;;;;;;wTAW0gC,CAAC;sBAAsB,CAAC;;;;;;;;;EADrmC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { privateKeyToAccount, generatePrivateKey } from "viem/accounts";
|
|
2
|
+
import { log } from "./output.js";
|
|
3
|
+
export function resolveWallet(key, label) {
|
|
4
|
+
const privateKey = (key ?? generatePrivateKey());
|
|
5
|
+
const account = privateKeyToAccount(privateKey);
|
|
6
|
+
const hasKey = !!key;
|
|
7
|
+
if (!hasKey) {
|
|
8
|
+
log(`[${label}] No --key set — generated ephemeral wallet`);
|
|
9
|
+
}
|
|
10
|
+
return { privateKey, account, address: account.address, hasKey };
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=wallet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../src/lib/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AACvE,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AAEjC,MAAM,UAAU,aAAa,CAAC,GAAuB,EAAE,KAAa;IACnE,MAAM,UAAU,GAAG,CAAC,GAAG,IAAI,kBAAkB,EAAE,CAAkB,CAAA;IACjE,MAAM,OAAO,GAAG,mBAAmB,CAAC,UAAU,CAAC,CAAA;IAC/C,MAAM,MAAM,GAAG,CAAC,CAAC,GAAG,CAAA;IAEpB,IAAI,CAAC,MAAM,EAAE,CAAC;QACb,GAAG,CAAC,IAAI,KAAK,6CAA6C,CAAC,CAAA;IAC5D,CAAC;IAED,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,CAAA;AACjE,CAAC"}
|