@toon-protocol/client-mcp 0.10.1 → 0.10.3

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.
@@ -15,7 +15,7 @@ import {
15
15
  isEventExpired,
16
16
  parseIlpPeerInfo,
17
17
  readConfigFile
18
- } from "./chunk-5Z74D23J.js";
18
+ } from "./chunk-XYR3ACYX.js";
19
19
  import {
20
20
  __require
21
21
  } from "./chunk-F22GNSF6.js";
@@ -2170,12 +2170,15 @@ var ClientRunner = class {
2170
2170
  const cumulative = apex.client.getChannelCumulativeAmount(channelId);
2171
2171
  const depositTotal = apex.client.getChannelDepositTotal(channelId);
2172
2172
  const available = depositTotal > cumulative ? depositTotal - cumulative : 0n;
2173
+ const settleableAt = apex.client.getSettleableAt(channelId);
2173
2174
  channels.push({
2174
2175
  channelId,
2175
2176
  nonce: apex.client.getChannelNonce(channelId),
2176
2177
  cumulativeAmount: cumulative.toString(),
2177
2178
  depositTotal: depositTotal.toString(),
2178
- availableBalance: available.toString()
2179
+ availableBalance: available.toString(),
2180
+ closeState: apex.client.getChannelCloseState(channelId),
2181
+ ...settleableAt !== void 0 ? { settleableAt: settleableAt.toString() } : {}
2179
2182
  });
2180
2183
  }
2181
2184
  }
@@ -2198,12 +2201,31 @@ var ClientRunner = class {
2198
2201
  * the client signs its own on-chain tx.
2199
2202
  */
2200
2203
  async depositToChannel(req) {
2204
+ return this.withTrackingApex(
2205
+ req.channelId,
2206
+ (client) => client.depositToChannel(req.channelId, req.amount)
2207
+ );
2208
+ }
2209
+ /** Close a channel to begin the settlement grace period (withdraw, step 1). */
2210
+ async closeChannel(req) {
2211
+ return this.withTrackingApex(req.channelId, (client) => client.closeChannel(req.channelId));
2212
+ }
2213
+ /**
2214
+ * Settle a closed channel to release collateral (withdraw, step 2). The client
2215
+ * enforces the `now >= settleableAt` guard and throws a retryable error if
2216
+ * called early; `mapError` maps that to HTTP 425.
2217
+ */
2218
+ async settleChannel(req) {
2219
+ return this.withTrackingApex(req.channelId, (client) => client.settleChannel(req.channelId));
2220
+ }
2221
+ /** Run `fn` against the apex client that tracks `channelId`, else throw. */
2222
+ async withTrackingApex(channelId, fn) {
2201
2223
  for (const apex of this.apexes.values()) {
2202
- if (apex.client.getTrackedChannels().includes(req.channelId)) {
2203
- return apex.client.depositToChannel(req.channelId, req.amount);
2224
+ if (apex.client.getTrackedChannels().includes(channelId)) {
2225
+ return fn(apex.client);
2204
2226
  }
2205
2227
  }
2206
- throw new Error(`Channel "${req.channelId}" is not tracked by any apex.`);
2228
+ throw new Error(`Channel "${channelId}" is not tracked by any apex.`);
2207
2229
  }
2208
2230
  /** Swap source→target asset against a swap peer via the selected apex. */
2209
2231
  async swap(req) {
@@ -2480,6 +2502,20 @@ function registerRoutes(app, runner) {
2480
2502
  return mapError(reply, err);
2481
2503
  }
2482
2504
  });
2505
+ app.post("/channels/close", async (req, reply) => {
2506
+ try {
2507
+ return await runner.closeChannel(req.body);
2508
+ } catch (err) {
2509
+ return mapError(reply, err);
2510
+ }
2511
+ });
2512
+ app.post("/channels/settle", async (req, reply) => {
2513
+ try {
2514
+ return await runner.settleChannel(req.body);
2515
+ } catch (err) {
2516
+ return mapError(reply, err);
2517
+ }
2518
+ });
2483
2519
  app.post("/swap", async (req, reply) => {
2484
2520
  const body = req.body;
2485
2521
  if (!body || !body.destination || body.amount === void 0 || !body.swapPubkey || !body.pair || !body.chainRecipient) {
@@ -2601,6 +2637,9 @@ function mapError(reply, err) {
2601
2637
  retryable: true
2602
2638
  }) : sendError(reply, 502, "discovery_failed", { detail: err.message });
2603
2639
  }
2640
+ if (err instanceof Error && err.name === "SettleTooEarlyError") {
2641
+ return sendError(reply, 425, "settle_too_early", { detail: err.message, retryable: true });
2642
+ }
2604
2643
  return sendError(reply, 500, "internal_error", {
2605
2644
  detail: err instanceof Error ? err.message : String(err)
2606
2645
  });
@@ -2623,4 +2662,4 @@ export {
2623
2662
  PublishRejectedError,
2624
2663
  registerRoutes
2625
2664
  };
2626
- //# sourceMappingURL=chunk-ZIJNTR5Y.js.map
2665
+ //# sourceMappingURL=chunk-NDIIPZB4.js.map